Skip to content

Commit

Permalink
feat: add function to obtain eth bridge contracts (#260)
Browse files Browse the repository at this point in the history
Co-authored-by: spsjvc <[email protected]>
  • Loading branch information
TucksonDev and spsjvc authored Jun 8, 2023
1 parent 2c5504c commit ef76725
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
workflow_dispatch:

env:
MAINNET_RPC: ${{ secrets.MAINNET_RPC }}

jobs:
install:
name: 'Install'
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const deployErc20L1 = async (deployer: Signer) => {

const multicall = await new Multicall2__factory().connect(deployer).deploy()
await multicall.deployed()
console.log('multicall', weth.address)
console.log('multicall', multicall.address)

return {
proxyAdmin,
Expand Down
32 changes: 32 additions & 0 deletions src/lib/dataEntities/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { SignerOrProvider, SignerProviderUtils } from './signerOrProvider'
import { ArbSdkError } from '../dataEntities/errors'
import { SEVEN_DAYS_IN_SECONDS } from './constants'
import { RollupAdminLogic__factory } from '../abi/factories/RollupAdminLogic__factory'

export interface L1Network extends Network {
partnerChainIDs: number[]
Expand Down Expand Up @@ -282,6 +283,37 @@ export const getL2Network = (
return getNetwork(signerOrProviderOrChainID, 2) as Promise<L2Network>
}

/**
* Returns the addresses of all contracts that make up the ETH bridge
* @param rollupContractAddress Address of the Rollup contract
* @param l1SignerOrProvider An L1 signer or provider
* @returns EthBridge object with all information about the ETH bridge
*/
export const getEthBridgeInformation = async (
rollupContractAddress: string,
l1SignerOrProvider: SignerOrProvider
): Promise<EthBridge> => {
const rollup = RollupAdminLogic__factory.connect(
rollupContractAddress,
l1SignerOrProvider
)

const [bridge, inbox, sequencerInbox, outbox] = await Promise.all([
rollup.bridge(),
rollup.inbox(),
rollup.sequencerInbox(),
rollup.outbox(),
])

return {
bridge,
inbox,
sequencerInbox,
outbox,
rollup: rollupContractAddress,
}
}

export const addCustomNetwork = ({
customL1Network,
customL2Network,
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/ethBridgeAddresses.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { JsonRpcProvider } from '@ethersproject/providers'
import { expect } from 'chai'
import {
EthBridge,
getEthBridgeInformation,
getL2Network,
} from '../../src/lib/dataEntities/networks'
import dotenv from 'dotenv'
dotenv.config()

/**
* Tests the getEthBridgeInformation function against the information
* of Arbitrum One network (42161)
*/
describe('Obtain deployed bridge addresses', () => {
it('obtains deployed ETH Bridge addresses', async () => {
const arbOneL2Network = await getL2Network(42161)
const ethProvider = new JsonRpcProvider(
process.env['MAINNET_RPC'] as string
)

// Obtain on-chain information
const ethBridge: EthBridge = await getEthBridgeInformation(
arbOneL2Network.ethBridge.rollup,
ethProvider
)

// Obtained addresses should equal the addresses
// available in Arbitrum One's l2Network configuration
expect(
arbOneL2Network.ethBridge.bridge,
'Bridge contract is not correct'
).to.eq(ethBridge.bridge)
expect(
arbOneL2Network.ethBridge.inbox,
'Inbox contract is not correct'
).to.eq(ethBridge.inbox)
expect(
arbOneL2Network.ethBridge.sequencerInbox,
'SequencerInbox contract is not correct'
).to.eq(ethBridge.sequencerInbox)
expect(
arbOneL2Network.ethBridge.outbox,
'Outbox contract is not correct'
).to.eq(ethBridge.outbox)
})
})

0 comments on commit ef76725

Please sign in to comment.