Skip to content

Commit

Permalink
feat(deployment): fund L1 bridge (#400)
Browse files Browse the repository at this point in the history
* feat(deployment): fund L1 bridge

* doc: update comments

* test: update test config

Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com>
  • Loading branch information
davidtaikocha and dantaik committed Dec 10, 2022
1 parent 0fb5b89 commit e7ef53e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"generate:genesis": "ts-node ./utils/generate_genesis/main.ts",
"test:genesis": "./test/genesis/generate_genesis.test.sh",
"test:integration": "./test/test_integration.sh",
"deploy:hardhat": "LOG_LEVEL=debug pnpm hardhat deploy_L1 --network hardhat --dao-vault 0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39 --team-vault 0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39 --l2-genesis-block-hash 0xee1950562d42f0da28bd4550d88886bc90894c77c9c9eaefef775d4c8223f259 --confirmations 1",
"deploy:hardhat": "LOG_LEVEL=debug pnpm hardhat deploy_L1 --network hardhat --dao-vault 0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39 --team-vault 0xdf08f82de32b8d460adbe8d72043e3a7e25a3b39 --l2-genesis-block-hash 0xee1950562d42f0da28bd4550d88886bc90894c77c9c9eaefef775d4c8223f259 --bridge-funder-private-key ddbf12f72c946bb1e6de5eaf580c51db51828ba198d9b0dba9c7d48ec748dc04 --bridge-fund 0xff --confirmations 1",
"lint-staged": "lint-staged --allow-empty"
},
"lint-staged": {
Expand Down Expand Up @@ -81,4 +81,4 @@
"@openzeppelin/contracts": "^4.5.0",
"@openzeppelin/contracts-upgradeable": "^4.5.1"
}
}
}
41 changes: 41 additions & 0 deletions packages/protocol/tasks/deploy_L1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ task("deploy_L1")
ethers.constants.HashZero
)
.addOptionalParam("l2ChainId", "L2 chain id", config.K_CHAIN_ID, types.int)
.addOptionalParam(
"bridgeFunderPrivateKey",
"Private key of the L1 bridge funder",
"",
types.string
)
.addOptionalParam(
"bridgeFund",
"L1 bridge's initial fund in hex",
"",
types.string
)
.addOptionalParam(
"confirmations",
"Number of confirmations to wait for deploy transaction.",
Expand Down Expand Up @@ -51,6 +63,8 @@ export async function deployContracts(hre: any) {
const l2GenesisBlockHash = hre.args.l2GenesisBlockHash
const taikoL2Address = hre.args.taikoL2
const l2ChainId = hre.args.l2ChainId
const bridgeFunderPrivateKey = hre.args.bridgeFunderPrivateKey
const bridgeFund = hre.args.bridgeFund

log.debug(`network: ${network}`)
log.debug(`chainId: ${chainId}`)
Expand All @@ -59,6 +73,8 @@ export async function deployContracts(hre: any) {
log.debug(`l2GenesisBlockHash: ${l2GenesisBlockHash}`)
log.debug(`taikoL2Address: ${taikoL2Address}`)
log.debug(`l2ChainId: ${l2ChainId}`)
log.debug(`bridgeFunderPrivateKey: ${bridgeFunderPrivateKey}`)
log.debug(`bridgeFund: ${bridgeFund}`)
log.debug(`confirmations: ${hre.args.confirmations}`)
log.debug()

Expand Down Expand Up @@ -131,6 +147,31 @@ export async function deployContracts(hre: any) {
await AddressManager.setAddress(`${chainId}.bridge`, Bridge.address)
)

// Fund L1 bridge, which is necessary when there is a L2 faucet
if (
bridgeFunderPrivateKey.length &&
hre.ethers.utils.isHexString(bridgeFund)
) {
const funder = new hre.ethers.Wallet(
bridgeFunderPrivateKey,
hre.ethers.provider
)

await utils.waitTx(
hre,
await funder.sendTransaction({
to: Bridge.address,
value: hre.ethers.BigNumber.from(bridgeFund),
})
)

log.debug(
`L1 bridge balance: ${hre.ethers.utils.hexlify(
await hre.ethers.provider.getBalance(Bridge.address)
)}`
)
}

// save deployments
const deployments = {
network,
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/test/genesis/test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"TokenVault": "0x0000777700000000000000000000000000000002",
"EtherVault": "0x0000777700000000000000000000000000000003",
"Bridge": "0x0000777700000000000000000000000000000004",
"TestERC20": "0x0000777700000000000000000000000000000005"
"TestERC20": "0x0000777700000000000000000000000000000005",
"AddressManager": "0x0000777700000000000000000000000000000006"
},
"predeployERC20": true
}
}

0 comments on commit e7ef53e

Please sign in to comment.