UNPKG

@xchainjs/xchain-arbitrum

Version:
129 lines (122 loc) 6.09 kB
'use strict'; var xchainClient = require('@xchainjs/xchain-client'); var xchainEvm = require('@xchainjs/xchain-evm'); var xchainEvmProviders = require('@xchainjs/xchain-evm-providers'); var xchainUtil = require('@xchainjs/xchain-util'); var ethers = require('ethers'); var BigNumber = require('bignumber.js'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var BigNumber__default = /*#__PURE__*/_interopDefault(BigNumber); // Import necessary modules and classes from external packages and files // Define constants related to Arbitrum const ARB_DECIMAL = 18; const LOWER_FEE_BOUND = 10000000; const UPPER_FEE_BOUND = 1000000000; const ARB_GAS_ASSET_DECIMAL = 18; const ARBChain = 'ARB'; // ARB ETH Gas asset const AssetAETH = { chain: ARBChain, symbol: 'ETH', ticker: 'ETH', type: xchainUtil.AssetType.NATIVE }; // ARB const AssetARB = { chain: ARBChain, symbol: 'ARB-0x912ce59144191c1204e64559fe8253a0e49e6548', ticker: 'ARB', type: xchainUtil.AssetType.TOKEN, }; // Define JSON-RPC providers for mainnet and testnet // Ankr api key const ARBITRUM_MAINNET_ETHERS_PROVIDER = new ethers.JsonRpcProvider('https://arb1.arbitrum.io/rpc'); const ARBITRUM_TESTNET_ETHERS_PROVIDER = new ethers.JsonRpcProvider('https://goerli-rollup.arbitrum.io/rpc'); // Define ethers providers for different networks const ethersJSProviders = { [xchainClient.Network.Mainnet]: ARBITRUM_MAINNET_ETHERS_PROVIDER, [xchainClient.Network.Testnet]: ARBITRUM_TESTNET_ETHERS_PROVIDER, [xchainClient.Network.Stagenet]: ARBITRUM_MAINNET_ETHERS_PROVIDER, }; // Define online providers (Etherscan) for mainnet and testnet const ARB_ONLINE_PROVIDER_MAINNET = new xchainEvmProviders.EtherscanProviderV2(ARBITRUM_MAINNET_ETHERS_PROVIDER, 'https://api.etherscan.io/v2', process.env.ETHERSCAN_API_KEY || '', ARBChain, AssetAETH, 18, 42161); const ARB_ONLINE_PROVIDER_TESTNET = new xchainEvmProviders.EtherscanProviderV2(ARBITRUM_TESTNET_ETHERS_PROVIDER, 'https://api.etherscan.io/v2', process.env.ETHERSCAN_API_KEY || '', ARBChain, AssetAETH, 18, 421614); // Define providers for different networks const arbProviders = { [xchainClient.Network.Mainnet]: ARB_ONLINE_PROVIDER_MAINNET, [xchainClient.Network.Testnet]: ARB_ONLINE_PROVIDER_TESTNET, [xchainClient.Network.Stagenet]: ARB_ONLINE_PROVIDER_MAINNET, }; // Define explorer providers for mainnet and testnet const ARB_MAINNET_EXPLORER = new xchainClient.ExplorerProvider('https://arbiscan.io/', 'https://arbiscan.io/address/%%ADDRESS%%', 'https://arbiscan.io/tx/%%TX_ID%%'); const ARB_TESTNET_EXPLORER = new xchainClient.ExplorerProvider('https://goerli.arbiscan.io', 'https://goerli.arbiscan.io/address/%%ADDRESS%%', 'https://goerli.arbiscan.io/tx/%%TX_ID%%'); // Define explorer providers for different networks const arbExplorerProviders = { [xchainClient.Network.Mainnet]: ARB_MAINNET_EXPLORER, [xchainClient.Network.Testnet]: ARB_TESTNET_EXPLORER, [xchainClient.Network.Stagenet]: ARB_MAINNET_EXPLORER, }; // Define root derivation paths for different networks const ethRootDerivationPaths = { [xchainClient.Network.Mainnet]: `m/44'/60'/0'/0/`, [xchainClient.Network.Testnet]: `m/44'/60'/0'/0/`, [xchainClient.Network.Stagenet]: `m/44'/60'/0'/0/`, }; // Define default parameters for the Arbitrum client const defaults = { [xchainClient.Network.Mainnet]: { approveGasLimit: new BigNumber__default.default(200000), transferGasAssetGasLimit: new BigNumber__default.default(23000), transferTokenGasLimit: new BigNumber__default.default(100000), gasPrice: new BigNumber__default.default(0.2 * Math.pow(10, 9)), }, [xchainClient.Network.Testnet]: { approveGasLimit: new BigNumber__default.default(200000), transferGasAssetGasLimit: new BigNumber__default.default(23000), transferTokenGasLimit: new BigNumber__default.default(100000), gasPrice: new BigNumber__default.default(0.2 * Math.pow(10, 9)), }, [xchainClient.Network.Stagenet]: { approveGasLimit: new BigNumber__default.default(200000), transferGasAssetGasLimit: new BigNumber__default.default(23000), transferTokenGasLimit: new BigNumber__default.default(100000), gasPrice: new BigNumber__default.default(0.2 * Math.pow(10, 9)), }, }; // Define the default parameters for the Arbitrum client const defaultArbParams = { chain: ARBChain, gasAsset: AssetAETH, gasAssetDecimals: ARB_GAS_ASSET_DECIMAL, defaults, providers: ethersJSProviders, explorerProviders: arbExplorerProviders, dataProviders: [arbProviders], network: xchainClient.Network.Mainnet, feeBounds: { lower: LOWER_FEE_BOUND, upper: UPPER_FEE_BOUND, }, rootDerivationPaths: ethRootDerivationPaths, }; // Import the Client class from '@xchainjs/xchain-evm' module // Create a class called Client that extends the XchainEvmClient class class Client extends xchainEvm.Client { // Constructor function that takes an optional config parameter, defaulting to defaultArbParams constructor(config = defaultArbParams) { // Call the constructor of the parent class (XchainEvmClient) with the provided config super(Object.assign(Object.assign({}, config), { signer: config.phrase ? new xchainEvm.KeystoreSigner({ phrase: config.phrase, provider: config.providers[config.network || xchainClient.Network.Mainnet], derivationPath: config.rootDerivationPaths ? config.rootDerivationPaths[config.network || xchainClient.Network.Mainnet] : '', }) : undefined })); } } exports.ARBChain = ARBChain; exports.ARB_DECIMAL = ARB_DECIMAL; exports.ARB_GAS_ASSET_DECIMAL = ARB_GAS_ASSET_DECIMAL; exports.AssetAETH = AssetAETH; exports.AssetARB = AssetARB; exports.Client = Client; exports.LOWER_FEE_BOUND = LOWER_FEE_BOUND; exports.UPPER_FEE_BOUND = UPPER_FEE_BOUND; exports.defaultArbParams = defaultArbParams;