Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for local L3 in testSetup #346

Closed
wants to merge 15 commits into from
2 changes: 2 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
L3_URL="http://localhost:3347"
ARB_URL="http://localhost:8547"
ETH_URL="http://localhost:8545"
ARB_KEY="b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"
ETH_KEY="b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"
L3_KEY="b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"

INFURA_KEY="2323232323232323232"
SHOULD_FORK="0"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ jobs:
uses: OffchainLabs/actions/node-modules/restore@main

- name: Set up the local node
uses: OffchainLabs/actions/run-nitro-test-node@main
uses: OffchainLabs/actions/run-nitro-test-node@wait-for-l3
with:
no-token-bridge: true
l3-node: true

- name: Copy .env
run: cp ./.env-sample ./.env
Expand Down
18 changes: 17 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@
// Undici's cookie header not cleared on cross-origin redirect in fetch
// from: hardhat>undici
// hardhat is only used in dev
"GHSA-wqq4-5wpv-mx2g"
"GHSA-wqq4-5wpv-mx2g",
// https://github.com/advisories/GHSA-wf5p-g6vw-rhxx
// axios inadvertently reveals the confidential XSRF-TOKEN stored in cookies
// we don't use cookies with axios in the sdk
// from: @arbitrum/nitro-contracts>sol2uml>axios
// from: axios
"GHSA-wf5p-g6vw-rhxx",
// https://github.com/advisories/GHSA-wprv-93r4-jj2p
// OpenZeppelin Contracts using MerkleProof multiproofs may allow proving arbitrary leaves for specific trees.
// We don't use multiproofs.
// from: @arbitrum/token-bridge-contracts>@offchainlabs/upgrade-executor>@openzeppelin/contracts-upgradeable
// from: @arbitrum/token-bridge-contracts>@arbitrum/nitro-contracts>@offchainlabs/upgrade-executor>@openzeppelin/contracts-upgradeable
// from: @arbitrum/token-bridge-contracts>@openzeppelin/contracts-upgradeable
// from: @arbitrum/token-bridge-contracts>@offchainlabs/upgrade-executor>@openzeppelin/contracts
// from: @arbitrum/token-bridge-contracts>@arbitrum/nitro-contracts>@offchainlabs/upgrade-executor>@openzeppelin/contracts
// from: @arbitrum/token-bridge-contracts>@openzeppelin/contracts
"GHSA-wprv-93r4-jj2p"
]
}
17 changes: 17 additions & 0 deletions hardhat-abigen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: '0.8.16',
settings: {
optimizer: {
enabled: true,
runs: 100,
},
},
},
paths: {
artifacts: './build/contracts',
},
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"devDependencies": {
"@arbitrum/nitro-contracts": "1.0.1",
"@arbitrum/token-bridge-contracts": "1.1.0",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@typechain/ethers-v5": "9.0.0",
"@types/chai": "^4.2.11",
Expand All @@ -63,7 +64,6 @@
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.27.1",
"@typescript-eslint/parser": "^5.14.0",
"arb-bridge-peripherals": "1.0.10",
"audit-ci": "^6.3.0",
"axios": "^0.21.3",
"chai": "^4.2.0",
Expand Down
208 changes: 126 additions & 82 deletions scripts/deployBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const deployBehindProxy = async <
return instance.attach(proxy.address)
}

export const deployErc20L1 = async (deployer: Signer) => {
export const deployErc20Parent = async (deployer: Signer) => {
const proxyAdmin = await new ProxyAdmin__factory().connect(deployer).deploy()
await proxyAdmin.deployed()
console.log('proxyAdmin', proxyAdmin.address)
Expand Down Expand Up @@ -93,7 +93,7 @@ export const deployErc20L1 = async (deployer: Signer) => {
}
}

export const deployErc20L2 = async (deployer: Signer) => {
export const deployErc20Child = async (deployer: Signer) => {
const proxyAdmin = await new ProxyAdmin__factory().connect(deployer).deploy()
await proxyAdmin.deployed()
console.log('proxyAdmin', proxyAdmin.address)
Expand Down Expand Up @@ -170,85 +170,129 @@ export const deployErc20L2 = async (deployer: Signer) => {
export const deployErc20AndInit = async (
l1Signer: Signer,
l2Signer: Signer,
inboxAddress: string
l3Signer: Signer,
l1InboxAddress: string, // inbox for L2 on L1
l2InboxAddress: string // inbox for L3 on L2
) => {
console.log('deploying l1')
const l1 = await deployErc20L1(l1Signer)

console.log('deploying l2')
const l2 = await deployErc20L2(l2Signer)

console.log('initialising L2')
await l2.router.initialize(l1.router.address, l2.standardGateway.address)
await l2.beaconProxyFactory.initialize(l2.beacon.address)
await (
await l2.standardGateway.initialize(
l1.standardGateway.address,
l2.router.address,
l2.beaconProxyFactory.address
)
).wait()
await (
await l2.customGateway.initialize(
l1.customGateway.address,
l2.router.address
)
).wait()
await (
await l2.weth.initialize(
'WETH',
'WETH',
18,
l2.wethGateway.address,
l1.weth.address
)
).wait()
await (
await l2.wethGateway.initialize(
l1.wethGateway.address,
l2.router.address,
l1.weth.address,
l2.weth.address
)
).wait()

console.log('initialising L1')
await (
await l1.router.initialize(
await l1Signer.getAddress(),
l1.standardGateway.address,
constants.AddressZero,
l2.router.address,
inboxAddress
)
).wait()

await (
await l1.standardGateway.initialize(
l2.standardGateway.address,
l1.router.address,
inboxAddress,
await l2.beaconProxyFactory.cloneableProxyHash(),
l2.beaconProxyFactory.address
)
).wait()
await (
await l1.customGateway.initialize(
l2.customGateway.address,
l1.router.address,
inboxAddress,
await l1Signer.getAddress()
)
).wait()
await (
await l1.wethGateway.initialize(
l2.wethGateway.address,
l1.router.address,
inboxAddress,
l1.weth.address,
l2.weth.address
)
).wait()

return { l1, l2 }
console.log('deploying l1 parent')
const l1Parent = await deployErc20Parent(l1Signer)

console.log('deploying l2 child')
const l2Child = await deployErc20Child(l2Signer)

console.log('deploying l2 parent')
const l2Parent = await deployErc20Parent(l2Signer)

console.log('deploying l3 child')
const l3Child = await deployErc20Child(l3Signer)

type Unwrap<T> = T extends Promise<infer U> ? U : T
const initializeParentChild = async (
parent: Unwrap<ReturnType<typeof deployErc20Parent>>,
child: Unwrap<ReturnType<typeof deployErc20Child>>,
inboxAddress: string,
parentSigner: Signer,
parentWethAddressOverride?: string
) => {
// initialize child
await (
await child.router.initialize(
parent.router.address,
child.standardGateway.address
)
).wait()
await (
await child.beaconProxyFactory.initialize(child.beacon.address)
).wait()
await (
await child.standardGateway.initialize(
parent.standardGateway.address,
child.router.address,
child.beaconProxyFactory.address
)
).wait()
await (
await child.customGateway.initialize(
parent.customGateway.address,
child.router.address
)
).wait()
await (
await child.weth.initialize(
'WETH',
'WETH',
18,
child.wethGateway.address,
parentWethAddressOverride || parent.weth.address
)
).wait()
await (
await child.wethGateway.initialize(
parent.wethGateway.address,
child.router.address,
parentWethAddressOverride || parent.weth.address,
child.weth.address
)
).wait()

// initialize parent
await (
await parent.router.initialize(
await parentSigner.getAddress(),
parent.standardGateway.address,
constants.AddressZero,
child.router.address,
inboxAddress
)
).wait()

await (
await parent.standardGateway.initialize(
child.standardGateway.address,
parent.router.address,
inboxAddress,
await child.beaconProxyFactory.cloneableProxyHash(),
child.beaconProxyFactory.address
)
).wait()
await (
await parent.customGateway.initialize(
child.customGateway.address,
parent.router.address,
inboxAddress,
await parentSigner.getAddress()
)
).wait()
await (
await parent.wethGateway.initialize(
child.wethGateway.address,
parent.router.address,
inboxAddress,
parentWethAddressOverride || parent.weth.address,
child.weth.address
)
).wait()
}

console.log('initialising L1 <-> L2')
await initializeParentChild(l1Parent, l2Child, l1InboxAddress, l1Signer)

console.log('initialising L2 <-> L3')
await initializeParentChild(
l2Parent,
l3Child,
l2InboxAddress,
l2Signer,
l2Child.weth.address
)

return {
l1Parent,
l2Child,
l2Parent: {
...l2Parent,
weth: l2Child.weth,
},
l3Child,
}
}
13 changes: 8 additions & 5 deletions scripts/genAbi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
const cwd = process.cwd()

const nitroPath = getPackagePath('@arbitrum/nitro-contracts')
const peripheralsPath = getPackagePath('arb-bridge-peripherals')
const tokenBridgePath = getPackagePath('@arbitrum/token-bridge-contracts')

console.log('Compiling paths.')

Expand All @@ -32,15 +32,18 @@ async function main() {
cwd: nitroPath,
})

console.log('building peripherals')
execSync(`${npmExec} run hardhat:prod compile`, {
cwd: peripheralsPath,
// copy the hardhat config to the token-bridge-contracts package
execSync(`cp ${cwd}/hardhat-abigen.ts ${tokenBridgePath}/hardhat-abigen.ts`)

console.log('building token bridge contracts')
execSync(`${npmExec} run build --config hardhat-abigen.ts`, {
cwd: tokenBridgePath,
})

console.log('Done compiling')

const nitroFiles = glob(cwd, [
`${peripheralsPath}/build/contracts/!(build-info)/**/+([a-zA-Z0-9_]).json`,
`${tokenBridgePath}/build/contracts/!(build-info)/**/+([a-zA-Z0-9_]).json`,
`${nitroPath}/build/contracts/!(build-info)/**/+([a-zA-Z0-9_]).json`,
])

Expand Down
10 changes: 7 additions & 3 deletions scripts/genNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import * as fs from 'fs'
async function main() {
const ethProvider = new ethers.providers.JsonRpcProvider(config.ethUrl)
const arbProvider = new ethers.providers.JsonRpcProvider(config.arbUrl)
const l3Provider = new ethers.providers.JsonRpcProvider(config.l3Url)

const ethDeployer = getSigner(ethProvider, config.ethKey)
const arbDeployer = getSigner(arbProvider, config.arbKey)
const l3Deployer = getSigner(l3Provider, config.l3Key)

const { l1Network, l2Network } = await setupNetworks(
const { l1Network, l2Network, l3Network } = await setupNetworks(
ethDeployer,
arbDeployer,
l3Deployer,
config.ethUrl,
config.arbUrl
config.arbUrl,
config.l3Url
)

fs.writeFileSync(
'localNetwork.json',
JSON.stringify({ l1Network, l2Network }, null, 2)
JSON.stringify({ l1Network, l2Network, l3Network }, null, 2)
)
console.log('localnetwork.json updated')
}
Expand Down
Loading
Loading