Skip to content

Commit cb963d7

Browse files
authored
Routescan returns gas prices in wei (not gwei) and should not inheri… (#1589)
* Routescan returns gas prices in wei (not gwei) and should not inherit parent function * update Goerli chain ID
1 parent 0177414 commit cb963d7

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

.changeset/angry-drinks-boil.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@xchainjs/xchain-evm-providers': patch
3+
'@xchainjs/xchain-arbitrum': patch
4+
---
5+
6+
Routescan returns gas prices in wei (not gwei) and should not inherit parent function

packages/xchain-arbitrum/src/const.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Import necessary modules and classes from external packages and files
22
import { ExplorerProvider, Network } from '@xchainjs/xchain-client'
33
import { EVMClientParams } from '@xchainjs/xchain-evm'
4-
import { EtherscanProviderV2 } from '@xchainjs/xchain-evm-providers'
4+
import { RoutescanProvider } from '@xchainjs/xchain-evm-providers'
55
import { Asset, AssetType, TokenAsset } from '@xchainjs/xchain-util'
66
import { JsonRpcProvider } from 'ethers'
77
import BigNumber from 'bignumber.js'
@@ -24,7 +24,6 @@ export const AssetARB: TokenAsset = {
2424
}
2525

2626
// Define JSON-RPC providers for mainnet and testnet
27-
// Ankr api key
2827
const ARBITRUM_MAINNET_ETHERS_PROVIDER = new JsonRpcProvider('https://arb1.arbitrum.io/rpc')
2928
const ARBITRUM_TESTNET_ETHERS_PROVIDER = new JsonRpcProvider('https://goerli-rollup.arbitrum.io/rpc')
3029

@@ -35,32 +34,29 @@ const ethersJSProviders = {
3534
[Network.Stagenet]: ARBITRUM_MAINNET_ETHERS_PROVIDER,
3635
}
3736

38-
// Define online providers (Etherscan) for mainnet and testnet
39-
const ARB_ONLINE_PROVIDER_MAINNET = new EtherscanProviderV2(
37+
// Etherscan providers removed - Etherscan's gas oracle doesn't support Arbitrum
38+
39+
const ROUTESCAN_PROVIDER_MAINNET = new RoutescanProvider(
4040
ARBITRUM_MAINNET_ETHERS_PROVIDER,
41-
'https://api.etherscan.io/v2',
42-
process.env.ETHERSCAN_API_KEY || '',
43-
ARBChain,
44-
AssetAETH,
45-
18,
41+
'https://api.routescan.io',
4642
42161,
43+
AssetAETH,
44+
ARB_DECIMAL,
4745
)
4846

49-
const ARB_ONLINE_PROVIDER_TESTNET = new EtherscanProviderV2(
47+
const ROUTESCAN_PROVIDER_TESTNET = new RoutescanProvider(
5048
ARBITRUM_TESTNET_ETHERS_PROVIDER,
51-
'https://api.etherscan.io/v2',
52-
process.env.ETHERSCAN_API_KEY || '',
53-
ARBChain,
49+
'https://api.routescan.io',
50+
421613,
5451
AssetAETH,
55-
18,
56-
421614,
52+
ARB_DECIMAL,
53+
true,
5754
)
5855

59-
// Define providers for different networks
60-
const arbProviders = {
61-
[Network.Mainnet]: ARB_ONLINE_PROVIDER_MAINNET,
62-
[Network.Testnet]: ARB_ONLINE_PROVIDER_TESTNET,
63-
[Network.Stagenet]: ARB_ONLINE_PROVIDER_MAINNET,
56+
const routescanProviders = {
57+
[Network.Mainnet]: ROUTESCAN_PROVIDER_MAINNET,
58+
[Network.Testnet]: ROUTESCAN_PROVIDER_TESTNET,
59+
[Network.Stagenet]: ROUTESCAN_PROVIDER_MAINNET,
6460
}
6561

6662
// Define explorer providers for mainnet and testnet
@@ -120,7 +116,7 @@ export const defaultArbParams: EVMClientParams = {
120116
defaults,
121117
providers: ethersJSProviders,
122118
explorerProviders: arbExplorerProviders,
123-
dataProviders: [arbProviders],
119+
dataProviders: [routescanProviders],
124120
network: Network.Mainnet,
125121
feeBounds: {
126122
lower: LOWER_FEE_BOUND,

packages/xchain-evm-providers/src/providers/etherscan/etherscan-data-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ERC20Tx, GetERC20TxsResponse } from './types'
2121

2222
export class EtherscanProvider implements EvmOnlineDataProvider {
2323
private provider: Provider
24-
private apiKey: string
24+
protected apiKey: string
2525
protected baseUrl: string
2626
protected chain: Chain
2727
protected nativeAsset: Asset

packages/xchain-evm-providers/src/providers/routescan/routescan-data-provider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Provider } from 'ethers'
2-
import { TxHistoryParams } from '@xchainjs/xchain-client'
2+
import { FeeOption, FeeRates, TxHistoryParams } from '@xchainjs/xchain-client'
33
import { Asset } from '@xchainjs/xchain-util'
44

55
import { Tx, TxsPage } from '../../types'
@@ -79,4 +79,20 @@ export class RoutescanProvider extends EtherscanProvider {
7979
txs: transactions.filter((_, index) => index >= offset && index < offset + limit),
8080
}
8181
}
82+
83+
/**
84+
* Override getFeeRates to handle Routescan's API response format correctly.
85+
* Routescan returns gas prices in wei (not gwei), so we don't multiply by 10^9.
86+
*
87+
* @returns {Promise<FeeRates>} The fee rates in wei
88+
*/
89+
async getFeeRates(): Promise<FeeRates> {
90+
const gasOracleResponse = await etherscanAPI.getGasOracle(this.baseUrl, this.apiKey)
91+
92+
return {
93+
[FeeOption.Average]: Number(gasOracleResponse.SafeGasPrice),
94+
[FeeOption.Fast]: Number(gasOracleResponse.ProposeGasPrice),
95+
[FeeOption.Fastest]: Number(gasOracleResponse.FastGasPrice),
96+
}
97+
}
8298
}

0 commit comments

Comments
 (0)