diff --git a/packages/xchain-avax/CHANGELOG.md b/packages/xchain-avax/CHANGELOG.md index f1284f613..9a14549ca 100644 --- a/packages/xchain-avax/CHANGELOG.md +++ b/packages/xchain-avax/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.3.4 (2023-11-02) + +## Update + +- Estimations can be done with data provider + # v0.3.3 (2023-10-26) ## Update diff --git a/packages/xchain-avax/package.json b/packages/xchain-avax/package.json index 9ef39abf9..fd29991ec 100644 --- a/packages/xchain-avax/package.json +++ b/packages/xchain-avax/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-avax", - "version": "0.3.3", + "version": "0.3.4", "description": "Avax EVM client for XChainJS", "keywords": [ "XChain", @@ -35,20 +35,20 @@ "access": "public" }, "devDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" }, "peerDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" } diff --git a/packages/xchain-bsc/CHANGELOG.md b/packages/xchain-bsc/CHANGELOG.md index 6e5aa0e5e..8b0d8da70 100644 --- a/packages/xchain-bsc/CHANGELOG.md +++ b/packages/xchain-bsc/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.3.4 (2023-11-02) + +## Update + +- Estimations can be done with data provider + # v0.3.3 (2023-10-26) ## Update diff --git a/packages/xchain-bsc/package.json b/packages/xchain-bsc/package.json index 9a60fae94..ee858671b 100644 --- a/packages/xchain-bsc/package.json +++ b/packages/xchain-bsc/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-bsc", - "version": "0.3.3", + "version": "0.3.4", "description": "Binance Smart Chain EVM client for XChainJS", "keywords": [ "XChain", @@ -35,20 +35,20 @@ "access": "public" }, "devDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" }, "peerDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" } diff --git a/packages/xchain-client/CHANGELOG.md b/packages/xchain-client/CHANGELOG.md index f4732545b..9c64df5ca 100644 --- a/packages/xchain-client/CHANGELOG.md +++ b/packages/xchain-client/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.15.2 (2023-11-02) + +## Update + +- EVMOnlineDataProvider interface + # v0.15.1 (2023-10-26) ## Update diff --git a/packages/xchain-client/package.json b/packages/xchain-client/package.json index 005b9ea65..876254d99 100644 --- a/packages/xchain-client/package.json +++ b/packages/xchain-client/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-client", - "version": "0.15.1", + "version": "0.15.2", "license": "MIT", "main": "lib/index.js", "module": "lib/index.esm.js", diff --git a/packages/xchain-client/src/provider-types.ts b/packages/xchain-client/src/provider-types.ts index 987203729..71effb2d8 100644 --- a/packages/xchain-client/src/provider-types.ts +++ b/packages/xchain-client/src/provider-types.ts @@ -1,7 +1,7 @@ import { Address, Asset } from '@xchainjs/xchain-util' import { ExplorerProvider } from './explorer-provider' -import { Balance, Network, Tx, TxHash, TxHistoryParams, TxsPage } from './types' +import { Balance, FeeRates, Network, Tx, TxHash, TxHistoryParams, TxsPage } from './types' export type Witness = { value: number @@ -27,6 +27,11 @@ export interface UtxoOnlineDataProvider extends OnlineDataProvider { broadcastTx(txHex: string): Promise } +export interface EvmOnlineDataProvider extends OnlineDataProvider { + getFeeRates(): Promise +} + export type ExplorerProviders = Record export type OnlineDataProviders = Record export type UtxoOnlineDataProviders = Record +export type EvmOnlineDataProviders = Record diff --git a/packages/xchain-ethereum/CHANGELOG.md b/packages/xchain-ethereum/CHANGELOG.md index b6e710690..e14c7fb99 100644 --- a/packages/xchain-ethereum/CHANGELOG.md +++ b/packages/xchain-ethereum/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.30.5 (2023-11-02) + +## Update + +- Estimations can be done with data provider + # v0.30.4 (2023-10-26) ## Update diff --git a/packages/xchain-ethereum/__e2e__/eth-client.e2e.ts b/packages/xchain-ethereum/__e2e__/eth-client.e2e.ts index 75bd8d85d..248afc17d 100644 --- a/packages/xchain-ethereum/__e2e__/eth-client.e2e.ts +++ b/packages/xchain-ethereum/__e2e__/eth-client.e2e.ts @@ -1,5 +1,5 @@ -import { Balance, Network, TxType } from '@xchainjs/xchain-client' -import { ApproveParams, EstimateApproveParams, IsApprovedParams } from '@xchainjs/xchain-evm' +import { Balance, FeeOption, Network, TxType } from '@xchainjs/xchain-client' +import { ApproveParams, EstimateApproveParams, IsApprovedParams, Protocol } from '@xchainjs/xchain-evm' import { Asset, assetAmount, assetToBase, assetToString } from '@xchainjs/xchain-util' import Client from '../src/client' @@ -207,4 +207,55 @@ describe('xchain-evm (Eth) Integration Tests', () => { fail() } }) + // Can not retrieve this info over testnet network, sepolia api in etherscan do not support gas Oracle endpoint and there is no testnet for thorchain + it('should estimate feeRates with default values', async () => { + try { + const feeRates = await clientTestnet.estimateGasPrices() + console.log({ + [FeeOption.Average]: feeRates.average.amount().toString(), + [FeeOption.Fast]: feeRates.fast.amount().toString(), + [FeeOption.Fastest]: feeRates.fastest.amount().toString(), + }) + expect(feeRates.fast.gte(feeRates.average)).toBe(true) + expect(feeRates.fastest.gte(feeRates.average)).toBe(true) + expect(feeRates.fastest.gte(feeRates.fast)).toBe(true) + } catch (err) { + console.error('ERR running test', err) + fail() + } + }) + it('should estimate feeRates using data providers', async () => { + try { + const client = new Client({ ...defaultEthParams, network: Network.Mainnet }) + const feeRates = await client.estimateGasPrices() + console.log({ + [FeeOption.Average]: feeRates.average.amount().toString(), + [FeeOption.Fast]: feeRates.fast.amount().toString(), + [FeeOption.Fastest]: feeRates.fastest.amount().toString(), + }) + expect(feeRates.fast.gte(feeRates.average)).toBe(true) + expect(feeRates.fastest.gte(feeRates.average)).toBe(true) + expect(feeRates.fastest.gte(feeRates.fast)).toBe(true) + } catch (err) { + console.error('ERR running test', err) + fail() + } + }) + it('should estimate feeRates to interact with Thorchain', async () => { + try { + const client = new Client({ ...defaultEthParams, network: Network.Mainnet }) + const feeRates = await client.estimateGasPrices(Protocol.THORCHAIN) + console.log({ + [FeeOption.Average]: feeRates.average.amount().toString(), + [FeeOption.Fast]: feeRates.fast.amount().toString(), + [FeeOption.Fastest]: feeRates.fastest.amount().toString(), + }) + expect(feeRates.fast.gte(feeRates.average)).toBe(true) + expect(feeRates.fastest.gte(feeRates.average)).toBe(true) + expect(feeRates.fastest.gte(feeRates.fast)).toBe(true) + } catch (err) { + console.error('ERR running test', err) + fail() + } + }) }) diff --git a/packages/xchain-ethereum/package.json b/packages/xchain-ethereum/package.json index 4994ddf9a..7ce77be5d 100644 --- a/packages/xchain-ethereum/package.json +++ b/packages/xchain-ethereum/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-ethereum", - "version": "0.30.4", + "version": "0.30.5", "description": "Ethereum EVM client for XChainJS", "keywords": [ "XChain", @@ -35,20 +35,20 @@ "access": "public" }, "devDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" }, "peerDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" } diff --git a/packages/xchain-evm-providers/CHANGELOG.md b/packages/xchain-evm-providers/CHANGELOG.md index 331e1d861..b682e8e31 100644 --- a/packages/xchain-evm-providers/CHANGELOG.md +++ b/packages/xchain-evm-providers/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.1.2 (2023-11-02) + +## Update + +- GetFeeRates + # v0.1.1 (2023-09-11) ## Update diff --git a/packages/xchain-evm-providers/package.json b/packages/xchain-evm-providers/package.json index 7d286d67d..0ca9331f3 100644 --- a/packages/xchain-evm-providers/package.json +++ b/packages/xchain-evm-providers/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-evm-providers", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "main": "lib/index.js", "module": "lib/index.esm.js", @@ -27,13 +27,13 @@ "access": "public" }, "devDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", "@xchainjs/xchain-util": "^0.13.1", "axios": "^1.3.6" }, "peerDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", "@xchainjs/xchain-util": "^0.13.1", "axios": "^1.3.6" @@ -41,4 +41,4 @@ "dependencies": { "@supercharge/promise-pool": "^2.4.0" } -} +} \ No newline at end of file diff --git a/packages/xchain-evm-providers/src/providers/covalent/covalent-data-provider.ts b/packages/xchain-evm-providers/src/providers/covalent/covalent-data-provider.ts index a03e687ca..d84b5bbec 100644 --- a/packages/xchain-evm-providers/src/providers/covalent/covalent-data-provider.ts +++ b/packages/xchain-evm-providers/src/providers/covalent/covalent-data-provider.ts @@ -1,9 +1,7 @@ import { Balance, - FeeOption, - FeeType, - Fees, - OnlineDataProvider, + EvmOnlineDataProvider, + FeeRates, Tx, TxFrom, TxHistoryParams, @@ -25,7 +23,7 @@ import { const AVAXChain: Chain = 'AVAX' const AssetAVAX: Asset = { chain: AVAXChain, symbol: 'AVAX', ticker: 'AVAX', synth: false } -export class CovalentProvider implements OnlineDataProvider { +export class CovalentProvider implements EvmOnlineDataProvider { private baseUrl = 'https://api.covalenthq.com' private apiKey: string private chainId: number @@ -203,12 +201,8 @@ export class CovalentProvider implements OnlineDataProvider { hash: '', } } - async getFees(): Promise { - return { - [FeeOption.Average]: baseAmount(1), - [FeeOption.Fast]: baseAmount(1), - [FeeOption.Fastest]: baseAmount(1), - type: FeeType.PerByte, - } + + getFeeRates(): Promise { + throw new Error('Method not implemented.') } } diff --git a/packages/xchain-evm-providers/src/providers/etherscan/etherscan-api.ts b/packages/xchain-evm-providers/src/providers/etherscan/etherscan-api.ts index 0be9226f7..5120fec56 100644 --- a/packages/xchain-evm-providers/src/providers/etherscan/etherscan-api.ts +++ b/packages/xchain-evm-providers/src/providers/etherscan/etherscan-api.ts @@ -116,8 +116,11 @@ export const getTxFromTokenTransaction = (tx: TokenTransactionInfo, chain: Chain */ export const getGasOracle = async (baseUrl: string, apiKey?: string): Promise => { const url = baseUrl + '/api?module=gastracker&action=gasoracle' + const result = (await axios.get(url + getApiKeyQueryParameter(apiKey))).data.result - return (await axios.get(url + getApiKeyQueryParameter(apiKey))).data.result + if (typeof result === 'string') throw Error(`Can not retrieve gasOracle: ${result}`) + + return result } /** diff --git a/packages/xchain-evm-providers/src/providers/etherscan/etherscan-data-provider.ts b/packages/xchain-evm-providers/src/providers/etherscan/etherscan-data-provider.ts index 5ed69253a..b4b11cfd4 100644 --- a/packages/xchain-evm-providers/src/providers/etherscan/etherscan-data-provider.ts +++ b/packages/xchain-evm-providers/src/providers/etherscan/etherscan-data-provider.ts @@ -1,5 +1,13 @@ import { Provider } from '@ethersproject/abstract-provider' -import { Balance, OnlineDataProvider, Tx, TxHistoryParams, TxsPage } from '@xchainjs/xchain-client' +import { + Balance, + EvmOnlineDataProvider, + FeeOption, + FeeRates, + Tx, + TxHistoryParams, + TxsPage, +} from '@xchainjs/xchain-client' import { Address, Asset, Chain, assetToString, baseAmount } from '@xchainjs/xchain-util' import axios from 'axios' import { BigNumber, ethers } from 'ethers' @@ -8,7 +16,7 @@ import erc20ABI from './erc20.json' import * as etherscanAPI from './etherscan-api' import { ERC20Tx, GetERC20TxsResponse } from './types' -export class EtherscanProvider implements OnlineDataProvider { +export class EtherscanProvider implements EvmOnlineDataProvider { private provider: Provider private baseUrl: string private apiKey: string @@ -184,4 +192,14 @@ export class EtherscanProvider implements OnlineDataProvider { return tx } + + async getFeeRates(): Promise { + const gasOracleResponse = await etherscanAPI.getGasOracle(this.baseUrl, this.apiKey) + + return { + [FeeOption.Average]: Number(gasOracleResponse.SafeGasPrice) * 10 ** 9, + [FeeOption.Fast]: Number(gasOracleResponse.ProposeGasPrice) * 10 ** 9, + [FeeOption.Fastest]: Number(gasOracleResponse.FastGasPrice) * 10 ** 9, + } + } } diff --git a/packages/xchain-evm/CHANGELOG.md b/packages/xchain-evm/CHANGELOG.md index 6d2f2767e..cc462c840 100644 --- a/packages/xchain-evm/CHANGELOG.md +++ b/packages/xchain-evm/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.3.5 (2023-11-02) + +## Update + +- estimateGasPrices can difference between protocols and non-protocol interactions + # v0.3.4 (2023-10-26) ## Update diff --git a/packages/xchain-evm/package.json b/packages/xchain-evm/package.json index 47eb5fed3..5fc3308a4 100644 --- a/packages/xchain-evm/package.json +++ b/packages/xchain-evm/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-evm", - "version": "0.3.4", + "version": "0.3.5", "description": "Genereic EVM client for XChainJS", "keywords": [ "XChain", @@ -34,18 +34,18 @@ "access": "public" }, "devDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", "@xchainjs/xchain-util": "^0.13.1", - "@xchainjs/xchain-evm-providers": "^0.1.1", + "@xchainjs/xchain-evm-providers": "^0.1.2", "axios": "^1.3.6", "ethers": "^5.7.2" }, "peerDependencies": { - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-crypto": "^0.3.0", "@xchainjs/xchain-util": "^0.13.1", "axios": "^1.3.6", "ethers": "^5.7.2" } -} +} \ No newline at end of file diff --git a/packages/xchain-evm/src/client.ts b/packages/xchain-evm/src/client.ts index 43e3619b5..4df57cdcb 100644 --- a/packages/xchain-evm/src/client.ts +++ b/packages/xchain-evm/src/client.ts @@ -3,13 +3,13 @@ import { AssetInfo, Balance, BaseXChainClient, + EvmOnlineDataProviders, ExplorerProviders, FeeOption, FeeRates, FeeType, Fees, Network, - OnlineDataProviders, PreparedTx, Tx, TxHash, @@ -47,6 +47,9 @@ import { validateAddress, } from './utils' +export enum Protocol { + THORCHAIN = 1, +} /** * Interface for custom EVM client */ @@ -78,7 +81,7 @@ export type EVMClientParams = XChainClientParams & { defaults: Record providers: Record explorerProviders: ExplorerProviders - dataProviders: OnlineDataProviders[] + dataProviders: EvmOnlineDataProviders[] } /** @@ -91,7 +94,7 @@ export default class Client extends BaseXChainClient implements XChainClient { private hdNode?: HDNode private defaults: Record private explorerProviders: ExplorerProviders - private dataProviders: OnlineDataProviders[] + private dataProviders: EvmOnlineDataProviders[] private providers: Record /** * Constructor @@ -556,43 +559,48 @@ export default class Client extends BaseXChainClient implements XChainClient { /** * Estimate gas price. - * @see https://etherscan.io/apis#gastracker + * @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers * * @returns {GasPrices} The gas prices (average, fast, fastest) in `Wei` (`BaseAmount`) */ - async estimateGasPrices(): Promise { - try { - // Note: `rates` are in `gwei` - // @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/querier.go#L416-420 - // To have all values in `BaseAmount`, they needs to be converted into `wei` (1 gwei = 1,000,000,000 wei = 1e9) - const ratesInGwei: FeeRates = standardFeeRates(await this.getFeeRateFromThorchain()) - return { - [FeeOption.Average]: baseAmount(ratesInGwei[FeeOption.Average] * 10 ** 9, this.gasAssetDecimals), - [FeeOption.Fast]: baseAmount(ratesInGwei[FeeOption.Fast] * 10 ** 9, this.gasAssetDecimals), - [FeeOption.Fastest]: baseAmount(ratesInGwei[FeeOption.Fastest] * 10 ** 9, this.gasAssetDecimals), + async estimateGasPrices(protocol?: Protocol): Promise { + if (!protocol) { + try { + const feeRates = await this.roundRobinGetFeeRates() + return { + [FeeOption.Average]: baseAmount(feeRates.average, this.gasAssetDecimals), + [FeeOption.Fast]: baseAmount(feeRates.fast, this.gasAssetDecimals), + [FeeOption.Fastest]: baseAmount(feeRates.fastest, this.gasAssetDecimals), + } + } catch (error) { + console.warn(`Can not round robin over GetFeeRates: ${error}`) } - } catch (error) { - console.warn(error) } - try { - const feeRateInWei = await this.providers[this.network].getGasPrice() - const feeRateInGWei = feeRateInWei.div(10 ** 9) - const ratesInGwei: FeeRates = standardFeeRates(feeRateInGWei.toNumber()) - return { - [FeeOption.Average]: baseAmount(ratesInGwei[FeeOption.Average] * 10 ** 9, this.gasAssetDecimals), - [FeeOption.Fast]: baseAmount(ratesInGwei[FeeOption.Fast] * 10 ** 9, this.gasAssetDecimals), - [FeeOption.Fastest]: baseAmount(ratesInGwei[FeeOption.Fastest] * 10 ** 9, this.gasAssetDecimals), - } - } catch (error) { - console.warn(error) - const defaultRatesInGwei: FeeRates = standardFeeRates(this.defaults[this.network].gasPrice.toNumber()) - return { - [FeeOption.Average]: baseAmount(defaultRatesInGwei[FeeOption.Average] * 10 ** 9, this.gasAssetDecimals), - [FeeOption.Fast]: baseAmount(defaultRatesInGwei[FeeOption.Fast] * 10 ** 9, this.gasAssetDecimals), - [FeeOption.Fastest]: baseAmount(defaultRatesInGwei[FeeOption.Fastest] * 10 ** 9, this.gasAssetDecimals), + // If chain data providers fail, THORCHAIN as fallback + if (!protocol || protocol === Protocol.THORCHAIN) { + try { + // Note: `rates` are in `gwei` + // @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/querier.go#L416-420 + // To have all values in `BaseAmount`, they needs to be converted into `wei` (1 gwei = 1,000,000,000 wei = 1e9) + const ratesInGwei: FeeRates = standardFeeRates(await this.getFeeRateFromThorchain()) + return { + [FeeOption.Average]: baseAmount(ratesInGwei[FeeOption.Average] * 10 ** 9, this.gasAssetDecimals), + [FeeOption.Fast]: baseAmount(ratesInGwei[FeeOption.Fast] * 10 ** 9, this.gasAssetDecimals), + [FeeOption.Fastest]: baseAmount(ratesInGwei[FeeOption.Fastest] * 10 ** 9, this.gasAssetDecimals), + } + } catch (error) { + console.warn(error) } } + + // Default fee rates if everything else fails + const defaultRatesInGwei: FeeRates = standardFeeRates(this.defaults[this.network].gasPrice.toNumber()) + return { + [FeeOption.Average]: baseAmount(defaultRatesInGwei[FeeOption.Average] * 10 ** 9, this.gasAssetDecimals), + [FeeOption.Fast]: baseAmount(defaultRatesInGwei[FeeOption.Fast] * 10 ** 9, this.gasAssetDecimals), + [FeeOption.Fastest]: baseAmount(defaultRatesInGwei[FeeOption.Fastest] * 10 ** 9, this.gasAssetDecimals), + } } /** @@ -717,6 +725,18 @@ export default class Client extends BaseXChainClient implements XChainClient { throw Error('no provider able to GetTransactions') } + protected async roundRobinGetFeeRates(): Promise { + for (const provider of this.dataProviders) { + try { + const prov = provider[this.network] + if (prov) return await prov.getFeeRates() + } catch (error) { + console.warn(error) + } + } + throw Error('No provider available to getFeeRates') + } + /** * Prepare transfer. * diff --git a/packages/xchain-thorchain-amm/CHANGELOG.md b/packages/xchain-thorchain-amm/CHANGELOG.md index 07f61ff7c..1a367f04c 100644 --- a/packages/xchain-thorchain-amm/CHANGELOG.md +++ b/packages/xchain-thorchain-amm/CHANGELOG.md @@ -1,3 +1,8 @@ +# v0.7.10 (2023-11-02) + +## Update + +- Force Thorchain estimations # v0.7.9 (2023-11-03) ## Update diff --git a/packages/xchain-thorchain-amm/package.json b/packages/xchain-thorchain-amm/package.json index 82f48d8f8..9f1cdcf23 100644 --- a/packages/xchain-thorchain-amm/package.json +++ b/packages/xchain-thorchain-amm/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-thorchain-amm", - "version": "0.7.9", + "version": "0.7.10", "description": "module that exposes estimating & swappping cryptocurrency assets on thorchain", "keywords": [ "THORChain", @@ -39,19 +39,19 @@ "@binance-chain/javascript-sdk": "^4.2.0", "@cosmos-client/core": "0.46.1", "@psf/bitcoincashjs-lib": "^4.0.3", - "@xchainjs/xchain-avax": "^0.3.3", + "@xchainjs/xchain-avax": "^0.3.4", "@xchainjs/xchain-binance": "^5.7.4", "@xchainjs/xchain-bitcoin": "^0.23.2", "@xchainjs/xchain-bitcoincash": "^0.17.2", - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-cosmos": "^0.21.5", - "@xchainjs/xchain-bsc": "^0.3.3", + "@xchainjs/xchain-bsc": "^0.3.4", "@xchainjs/xchain-crypto": "^0.3.0", "@xchainjs/xchain-doge": "^0.7.3", - "@xchainjs/xchain-ethereum": "^0.30.4", + "@xchainjs/xchain-ethereum": "^0.30.5", "@xchainjs/xchain-thornode": "^0.3.8", "@xchainjs/xchain-thorchain-query": "^0.6.7", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-litecoin": "^0.13.2", "@xchainjs/xchain-mayachain": "^0.2.8", "@xchainjs/xchain-midgard": "^0.5.2", @@ -75,19 +75,19 @@ "@binance-chain/javascript-sdk": "^4.2.0", "@cosmos-client/core": "0.46.1", "@psf/bitcoincashjs-lib": "^4.0.3", - "@xchainjs/xchain-avax": "^0.3.3", + "@xchainjs/xchain-avax": "^0.3.4", "@xchainjs/xchain-binance": "^5.7.4", "@xchainjs/xchain-bitcoin": "^0.23.2", "@xchainjs/xchain-bitcoincash": "^0.17.2", - "@xchainjs/xchain-client": "^0.15.1", + "@xchainjs/xchain-client": "^0.15.2", "@xchainjs/xchain-cosmos": "^0.21.5", - "@xchainjs/xchain-bsc": "^0.3.3", + "@xchainjs/xchain-bsc": "^0.3.4", "@xchainjs/xchain-crypto": "^0.3.0", "@xchainjs/xchain-doge": "^0.7.3", - "@xchainjs/xchain-ethereum": "^0.30.4", + "@xchainjs/xchain-ethereum": "^0.30.5", "@xchainjs/xchain-thornode": "^0.3.8", "@xchainjs/xchain-thorchain-query": "^0.6.7", - "@xchainjs/xchain-evm": "^0.3.4", + "@xchainjs/xchain-evm": "^0.3.5", "@xchainjs/xchain-litecoin": "^0.13.2", "@xchainjs/xchain-mayachain": "^0.2.8", "@xchainjs/xchain-midgard": "^0.5.2", diff --git a/packages/xchain-thorchain-amm/src/utils/evm-helper.ts b/packages/xchain-thorchain-amm/src/utils/evm-helper.ts index a3771b341..8544b1e70 100644 --- a/packages/xchain-thorchain-amm/src/utils/evm-helper.ts +++ b/packages/xchain-thorchain-amm/src/utils/evm-helper.ts @@ -1,5 +1,5 @@ import { TxHash, XChainClient } from '@xchainjs/xchain-client' -import { ApproveParams, Client as EvmClient, MAX_APPROVAL, abi } from '@xchainjs/xchain-evm' +import { ApproveParams, Client as EvmClient, MAX_APPROVAL, Protocol, abi } from '@xchainjs/xchain-evm' import { ThorchainCache } from '@xchainjs/xchain-thorchain-query' import { Asset, BaseAmount, baseAmount, eqAsset, getContractAddressFromAsset } from '@xchainjs/xchain-util' import { ethers } from 'ethers' @@ -40,16 +40,17 @@ export class EvmHelper { } const address = this.client.getAddress(params.walletIndex) - const gasPrice = await this.evmClient.estimateGasPrices() + const gasPrice = await this.evmClient.estimateGasPrices(Protocol.THORCHAIN) if (eqAsset(params.asset, this.evmClient.config.gasAsset)) { // simple transfer - return await this.client.transfer({ + return await this.evmClient.transfer({ walletIndex: params.walletIndex || 0, asset: params.asset, amount: params.amount, recipient: inboundAsgard.address, memo: params.memo, + gasPrice: gasPrice.fast, }) } else { //erc-20 must be depsited to the router