Adapter

Arbitrum Transaction Fees

Arbitrum is an Optimistic Rollup that aims to feel exactly like interacting with Ethereum, but with transactions costing a fraction of what they do on L1.

Sub-Adapters 1

Preview and test each sub adapter.

Arbitrum One (arbitrum-one)

Metadata

ID
arbitrum-one
icon
category

"l2"

name

"Arbitrum One"

description

"Arbitrum is an Optimistic Rollup that aims to feel exactly like interacting with Ethereum, but with transactions costing a fraction of what they do on L1."

l2BeatSlug

"arbitrum"

website

"https://offchainlabs.com"

flags

{ "throtle": "Arbitrum One is throttled while in beta. Fees will decrease as this throttle is lifted." }

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Arbitrum Transaction Fees';
2export const version = '1.0.0';
3export const license = 'MIT';
4
5const ARB_GAS_PRECOMPILE = '0x000000000000000000000000000000000000006C';
6
7const ARB_GAS_ABI = [
8  'function getPricesInWei() external view returns (uint256,uint256,uint256,uint256,uint256,uint256)',
9];
10
11const ONE_ADDR = '0x0000000000000000000000000000000000000001';
12const BEEF_ADDR = '0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef';
13const USDC_ADDR = '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8';
14const DAI_ADDR = '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1';
15const UNISWAP_ROUTER = '0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45';
16const USDC_HODLER = '0x3525f734fcE1a26a6CEffFca43538290DC239771';
17type TxType = 'EthTransfer' | 'ERC20Transfer' | 'ERC20Swap';
18
19const SEC_IN_DAY = 86400;
20
21export function setup(sdk: Context) {
22  const getFeeForCost = async (gasAmt: number) => {
23    const gasPrecompileContract = sdk.ethers.getContract(
24      ARB_GAS_PRECOMPILE,
25      ARB_GAS_ABI,
26      'arbitrum-one'
27    );
28    const weiPerArbGas = (await gasPrecompileContract.getPricesInWei())[5];
29
30    const ethPrice = await sdk.coinGecko.getCurrentPrice('ethereum');
31
32    return (weiPerArbGas * gasAmt * ethPrice) / 1e18;
33  };
34
35  const getGasAmount = async (txType: TxType): Promise<number> => {
36    const provider = sdk.ethers.getProvider('arbitrum-one');
37
38    if(txType === 'EthTransfer') {
39      return provider.estimateGas({
40        from: ONE_ADDR,
41        to: BEEF_ADDR,
42        value: '0x1',
43        data: '0x'
44      });
45    } else if(txType === 'ERC20Transfer') {
46      // transfer 1 usdc
47      return provider.estimateGas({
48        from: USDC_HODLER,
49        to: USDC_ADDR,
50        data: `0xa9059cbb000000000000000000000000${USDC_HODLER.substr(2)}0000000000000000000000000000000000000000000000000000000000000001`
51      });
52    } else { // txType === 'ERC20Swap'
53      // swap 9 usdc to at least 1 dai using Uniswap V3
54      return provider.estimateGas({
55        from: USDC_HODLER,
56        to: UNISWAP_ROUTER,
57        data: `0x04e45aaf000000000000000000000000${USDC_ADDR.substr(2)}000000000000000000000000${DAI_ADDR.substr(2)}00000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000${USDC_HODLER.substr(2)}000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000`
58      });
59    }
60  };
61
62  const getAverageSwapFee = async (date: string) => {
63    const dayId = Math.floor(sdk.date.dateToTimestamp(date) / SEC_IN_DAY);
64
65    const query = `{
66      dayStat(id: "${dayId}") {
67        averageCostUSD
68      }
69      nextDay: dayStat(id: "${dayId + 1}") {
70        averageCostUSD
71      }
72    }`;
73
74    const result = await sdk.graph.query('dmihal/arbitrum-average-fees', query);
75
76    if (!result.dayStat) {
77      throw new Error('Data unavailable');
78    }
79    if (!result.nextDay) {
80      throw new Error('Day incomplete');
81    }
82    return parseFloat(result.dayStat.averageCostUSD);
83  }
84
85  sdk.register({
86    id: 'arbitrum-one',
87    queries: {
88      feeTransferEth: async () => getFeeForCost(await getGasAmount('EthTransfer')),
89      feeTransferERC20: async () => getFeeForCost(await getGasAmount('ERC20Transfer')),
90      feeTransferToken: async () => getFeeForCost(await getGasAmount('ERC20Transfer')),
91      feeSwap: async () => getFeeForCost(await getGasAmount('ERC20Swap')),
92      oneDayAverageFeeSwap: getAverageSwapFee,
93    },
94    metadata: {
95      icon: sdk.ipfs.getDataURILoader('QmeRunQGxv3haLoMfgwD2VjKwScf7gDQiA1DCYd1HNBCG6', 'image/svg+xml'),
96      category: 'l2',
97      name: 'Arbitrum One',
98      description: 'Arbitrum is an Optimistic Rollup that aims to feel exactly like interacting with Ethereum, but with transactions costing a fraction of what they do on L1.',
99      l2BeatSlug: 'arbitrum',
100      website: 'https://offchainlabs.com',
101      flags: {
102        throtle:
103          'Arbitrum One is throttled while in beta. Fees will decrease as this throttle is lifted.',
104      },
105    },
106  });
107}
108

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

1.0.0

License

MIT

IPFS CID

Qme34g7jUoWaFKnzKudcTbjKieBLNjmnXy8ZvniW4aLoTJ

CID (source)

QmdxJd4j3BWFgqWTrW8ZvG1P8dAz7rUBAtD7LVm6i52Zq2

Author

mihal.eth