diff --git a/src/lib/dataEntities/networks.ts b/src/lib/dataEntities/networks.ts index f3618b0af..e9355bd60 100644 --- a/src/lib/dataEntities/networks.ts +++ b/src/lib/dataEntities/networks.ts @@ -24,6 +24,7 @@ import { ArbSdkError } from '../dataEntities/errors' import { ARB1_NITRO_GENESIS_L2_BLOCK } from './constants' import { RollupAdminLogic__factory } from '../abi/factories/RollupAdminLogic__factory' import { Prettify } from '../utils/types' +import { IERC20Bridge__factory } from '../abi/factories/IERC20Bridge__factory' /** * Represents an Arbitrum chain, e.g. Arbitrum One, Arbitrum Sepolia, or an L3 chain. @@ -341,6 +342,17 @@ async function getArbitrumNetworkBySignerOrProvider( return getArbitrumNetworkByChainId(chainId) } +async function getNativeToken( + bridge: string, + provider: Provider +): Promise { + try { + return await IERC20Bridge__factory.connect(bridge, provider).nativeToken() + } catch (err) { + return constants.AddressZero + } +} + /** * Returns all Arbitrum networks registered in the SDK, both default and custom. */ @@ -350,7 +362,7 @@ export function getArbitrumNetworks(): ArbitrumNetwork[] { export type ArbitrumNetworkInformationFromRollup = Pick< ArbitrumNetwork, - 'parentChainId' | 'confirmPeriodBlocks' | 'ethBridge' + 'parentChainId' | 'confirmPeriodBlocks' | 'ethBridge' | 'nativeToken' > /** @@ -389,6 +401,7 @@ export async function getArbitrumNetworkInformationFromRollup( outbox, rollup: rollupAddress, }, + nativeToken: await getNativeToken(bridge, parentProvider), } } diff --git a/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts b/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts index f6ed3b913..92f256993 100644 --- a/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts +++ b/tests/integration/getArbitrumNetworkInformationFromRollup.test.ts @@ -1,6 +1,8 @@ import dotenv from 'dotenv' import { JsonRpcProvider } from '@ethersproject/providers' +import { constants } from 'ethers' import { expect } from 'chai' + import { getArbitrumNetwork, getArbitrumNetworkInformationFromRollup, @@ -8,14 +10,14 @@ import { dotenv.config() -describe('getArbitrumNetworkInformationFromRollup.test', () => { +describe('getArbitrumNetworkInformationFromRollup', () => { it('fetches information about arbitrum one', async () => { - const arb1 = await getArbitrumNetwork(42161) + const arb1 = getArbitrumNetwork(42161) const ethProvider = new JsonRpcProvider( process.env['MAINNET_RPC'] as string ) - const { parentChainId, confirmPeriodBlocks, ethBridge } = + const { parentChainId, confirmPeriodBlocks, ethBridge, nativeToken } = await getArbitrumNetworkInformationFromRollup( arb1.ethBridge.rollup, ethProvider @@ -39,5 +41,45 @@ describe('getArbitrumNetworkInformationFromRollup.test', () => { ) expect(outbox, 'Outbox contract is not correct').to.eq(arb1EthBridge.outbox) expect(rollup, 'Rollup contract is not correct').to.eq(arb1EthBridge.rollup) + + expect(nativeToken, 'Native token is not correct').to.eq( + constants.AddressZero + ) + }) + + it('fetches information about xai', async () => { + const { parentChainId, confirmPeriodBlocks, ethBridge, nativeToken } = + await getArbitrumNetworkInformationFromRollup( + '0xC47DacFbAa80Bd9D8112F4e8069482c2A3221336', + new JsonRpcProvider('https://arb1.arbitrum.io/rpc') + ) + + expect(parentChainId, 'parentChainId is not correct').to.eq(42161) + + expect(confirmPeriodBlocks, 'confirmPeriodBlocks is not correct').to.eq( + 45818 + ) + + const { bridge, inbox, sequencerInbox, outbox, rollup } = ethBridge + + expect(bridge, 'Bridge contract is not correct').to.eq( + '0x7dd8A76bdAeBE3BBBaCD7Aa87f1D4FDa1E60f94f' + ) + expect(inbox, 'Inbox contract is not correct').to.eq( + '0xaE21fDA3de92dE2FDAF606233b2863782Ba046F9' + ) + expect(sequencerInbox, 'SequencerInbox contract is not correct').to.eq( + '0x995a9d3ca121D48d21087eDE20bc8acb2398c8B1' + ) + expect(outbox, 'Outbox contract is not correct').to.eq( + '0x1E400568AD4840dbE50FB32f306B842e9ddeF726' + ) + expect(rollup, 'Rollup contract is not correct').to.eq( + '0xC47DacFbAa80Bd9D8112F4e8069482c2A3221336' + ) + + expect(nativeToken, 'Native token is not correct').to.eq( + '0x4Cb9a7AE498CEDcBb5EAe9f25736aE7d428C9D66' + ) }) })