From 0a1351ae086634c04fb9baba9cde3fdcfee04658 Mon Sep 17 00:00:00 2001 From: gzeon Date: Mon, 18 Nov 2024 22:44:40 +0800 Subject: [PATCH 01/16] feat: bold upgrader --- boldupgrader/Dockerfile | 14 ++++++++++++++ docker-compose-ci-cache.json | 11 +++++++++++ docker-compose.yaml | 21 +++++++++++++++++++++ test-node.bash | 24 ++++++++++++++++++++---- 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 boldupgrader/Dockerfile diff --git a/boldupgrader/Dockerfile b/boldupgrader/Dockerfile new file mode 100644 index 00000000..89f51e85 --- /dev/null +++ b/boldupgrader/Dockerfile @@ -0,0 +1,14 @@ +FROM node:18-bullseye-slim +RUN apt-get update && \ + apt-get install -y git docker.io python3 make gcc g++ curl jq +ARG BOLD_CONTRACTS_BRANCH=bold-merge-script +WORKDIR /workspace +RUN git clone --no-checkout https://github.com/OffchainLabs/nitro-contracts.git ./ +RUN git checkout ${BOLD_CONTRACTS_BRANCH} +RUN yarn install && yarn cache clean +RUN curl -L https://foundry.paradigm.xyz | bash +ENV PATH="${PATH}:/root/.foundry/bin" +RUN foundryup +RUN touch scripts/config.ts +RUN yarn build:all +ENTRYPOINT ["yarn"] \ No newline at end of file diff --git a/docker-compose-ci-cache.json b/docker-compose-ci-cache.json index 0fee603d..8a9dacb6 100644 --- a/docker-compose-ci-cache.json +++ b/docker-compose-ci-cache.json @@ -22,6 +22,17 @@ "type=docker" ] }, + "boldupgrader": { + "cache-from": [ + "type=local,src=/tmp/.buildx-cache" + ], + "cache-to": [ + "type=local,dest=/tmp/.buildx-cache,mode=max" + ], + "output": [ + "type=docker" + ] + }, "tokenbridge": { "cache-from": [ "type=local,src=/tmp/.buildx-cache" diff --git a/docker-compose.yaml b/docker-compose.yaml index c3cbf4cf..1a769ee4 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -354,6 +354,26 @@ services: - "tokenbridge-data:/workspace" - /var/run/docker.sock:/var/run/docker.sock + boldupgrader: + depends_on: + - geth + - sequencer + pid: host + build: + context: boldupgrader/ + args: + BOLD_CONTRACTS_BRANCH: ${BOLD_CONTRACTS_BRANCH:-} + environment: + - L1_RPC_URL=http://geth:8545 + - L1_PRIV_KEY=0xdc04c5399f82306ec4b4d654a342f40e2e0620fe39950d967e1e574b32d4dd36 + - CONFIG_NETWORK_NAME=local + - DEPLOYED_CONTRACTS_DIR=./scripts/files/ + - DISABLE_VERIFICATION=true + volumes: + - "config:/config" + - "boldupgrader-data:/workspace" + - /var/run/docker.sock:/var/run/docker.sock + rollupcreator: depends_on: - geth @@ -383,3 +403,4 @@ volumes: config: postgres-data: tokenbridge-data: + boldupgrader-data: diff --git a/test-node.bash b/test-node.bash index 91945e0e..035dc0de 100755 --- a/test-node.bash +++ b/test-node.bash @@ -6,16 +6,21 @@ NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 # This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor -DEFAULT_NITRO_CONTRACTS_VERSION="99c07a7db2fcce75b751c5a2bd4936e898cda065" +DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" +DEFAULT_BOLD_CONTRACTS_VERSION="a6e2e598" +# bold-merge-script DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" # Set default versions if not overriden by provided env vars : ${NITRO_CONTRACTS_BRANCH:=$DEFAULT_NITRO_CONTRACTS_VERSION} +: ${BOLD_CONTRACTS_BRANCH:=$DEFAULT_BOLD_CONTRACTS_VERSION} : ${TOKEN_BRIDGE_BRANCH:=$DEFAULT_TOKEN_BRIDGE_VERSION} export NITRO_CONTRACTS_BRANCH +export BOLD_CONTRACTS_BRANCH export TOKEN_BRIDGE_BRANCH echo "Using NITRO_CONTRACTS_BRANCH: $NITRO_CONTRACTS_BRANCH" +echo "Using BOLD_CONTRACTS_BRANCH: $BOLD_CONTRACTS_BRANCH" echo "Using TOKEN_BRIDGE_BRANCH: $TOKEN_BRIDGE_BRANCH" mydir=`dirname $0` @@ -44,6 +49,7 @@ blockscout=false tokenbridge=false l3node=false consensusclient=false +boldupgrade=false redundantsequencers=0 l3_custom_fee_token=false l3_token_bridge=false @@ -203,6 +209,10 @@ while [[ $# -gt 0 ]]; do l1chainid=1337 shift ;; + --bold-upgrade) + boldupgrade=true + shift + ;; --l3node) l3node=true shift @@ -282,8 +292,8 @@ while [[ $# -gt 0 ]]; do echo --no-build-dev-nitro don\'t rebuild dev nitro docker image echo --build-dev-blockscout rebuild dev blockscout docker image echo --no-build-dev-blockscout don\'t rebuild dev blockscout docker image - echo --build-utils rebuild scripts, rollupcreator, token bridge docker images - echo --no-build-utils don\'t rebuild scripts, rollupcreator, token bridge docker images + echo --build-utils rebuild scripts, rollupcreator, boldupgrader, token bridge docker images + echo --no-build-utils don\'t rebuild scripts, rollupcreator, boldupgrader, token bridge docker images echo --force-build-utils force rebuilding utils, useful if NITRO_CONTRACTS_ or TOKEN_BRIDGE_BRANCH changes echo echo script runs inside a separate docker. For SCRIPT-ARGS, run $0 script --help @@ -352,7 +362,7 @@ if $dev_blockscout && $build_dev_blockscout; then fi if $build_utils; then - LOCAL_BUILD_NODES="scripts rollupcreator" + LOCAL_BUILD_NODES="scripts rollupcreator boldupgrader" # always build tokenbridge in CI mode to avoid caching issues if $tokenbridge || $l3_token_bridge || $ci; then LOCAL_BUILD_NODES="$LOCAL_BUILD_NODES tokenbridge" @@ -486,6 +496,12 @@ if $force_init; then echo == Deploy CacheManager on L2 docker compose run -e CHILD_CHAIN_RPC="http://sequencer:8547" -e CHAIN_OWNER_PRIVKEY=$l2ownerKey rollupcreator deploy-cachemanager-testnode + if $boldupgrade; then + echo == Preparing BOLD upgrade + docker compose run boldupgrader script:bold-prepare + docker compose run boldupgrader script:bold-populate-lookup + docker compose run boldupgrader script:bold-local-execute + fi if $l3node; then echo == Funding l3 users From 11ec55f608622fc549a992dffacaa2688747a8cf Mon Sep 17 00:00:00 2001 From: gzeon Date: Mon, 18 Nov 2024 23:53:51 +0800 Subject: [PATCH 02/16] chore: update bold upgrader --- test-node.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index 035dc0de..f1f23648 100755 --- a/test-node.bash +++ b/test-node.bash @@ -7,7 +7,7 @@ BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 # This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" -DEFAULT_BOLD_CONTRACTS_VERSION="a6e2e598" +DEFAULT_BOLD_CONTRACTS_VERSION="ef08baca" # bold-merge-script DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" From 00dd5490b1e156cd0a0830884c5bca971eb649a6 Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 00:09:27 +0800 Subject: [PATCH 03/16] fix: retry populate lookup --- test-node.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index f1f23648..7d6449d9 100755 --- a/test-node.bash +++ b/test-node.bash @@ -499,7 +499,12 @@ if $force_init; then if $boldupgrade; then echo == Preparing BOLD upgrade docker compose run boldupgrader script:bold-prepare - docker compose run boldupgrader script:bold-populate-lookup + # retry this 10 times because the staker might not have made a node yet + for i in {1..10}; do + docker compose run boldupgrader script:bold-populate-lookup && break || true + echo "Failed to populate lookup table, retrying..." + sleep 10 + done docker compose run boldupgrader script:bold-local-execute fi From c450c5c2a7888f3d9a822fe5888fe5ba1e3b8e03 Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 00:51:29 +0800 Subject: [PATCH 04/16] ci: test bold upgrade --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b827ccd..9052a740 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,3 +40,20 @@ jobs: - name: Startup Nitro testnode run: ${{ github.workspace }}/.github/workflows/testnode.bash --init-force ${{ (matrix.l3node == 'l3node' && '--l3node') || (matrix.l3node == 'l3node-token-6' && '--l3node --l3-fee-token --l3-token-bridge --l3-fee-token-decimals 6') || '' }} ${{ matrix.tokenbridge == 'tokenbridge' && '--tokenbridge' || '--no-tokenbridge' }} --detach ${{ matrix.pos == 'pos' && '--pos' || '' }} --simple ${{ (matrix.simple == 'simple' && '--simple') || (matrix.simple == 'no-simple' && '--no-simple') || '' }} + + bold_upgrade: + runs-on: ubuntu-8 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + + - name: Startup Nitro testnode + run: ${{ github.workspace }}/.github/workflows/testnode.bash --init-force --bold-upgrade --simple From 39821b8cbca48865d241ebf29cbc0f65b07ee95d Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 01:12:42 +0800 Subject: [PATCH 05/16] debug: rollup config --- test-node.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index 7d6449d9..e36c2ca0 100755 --- a/test-node.bash +++ b/test-node.bash @@ -6,7 +6,7 @@ NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 # This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor -DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" +DEFAULT_NITRO_CONTRACTS_VERSION="d76f3a11" DEFAULT_BOLD_CONTRACTS_VERSION="ef08baca" # bold-merge-script DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" From 89091798b89c7e16196cd5e4f2aded6183e31bb9 Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 01:19:43 +0800 Subject: [PATCH 06/16] debug: deployParams --- test-node.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index e36c2ca0..b8018597 100755 --- a/test-node.bash +++ b/test-node.bash @@ -6,7 +6,7 @@ NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 # This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor -DEFAULT_NITRO_CONTRACTS_VERSION="d76f3a11" +DEFAULT_NITRO_CONTRACTS_VERSION="7fd211e9" DEFAULT_BOLD_CONTRACTS_VERSION="ef08baca" # bold-merge-script DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" From 7b088573480c5021b52ef263f5812ef1a3b1b3b1 Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 01:27:00 +0800 Subject: [PATCH 07/16] debug: 984aff18 --- test-node.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index b8018597..8944d6e6 100755 --- a/test-node.bash +++ b/test-node.bash @@ -6,7 +6,7 @@ NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 # This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor -DEFAULT_NITRO_CONTRACTS_VERSION="7fd211e9" +DEFAULT_NITRO_CONTRACTS_VERSION="984aff18" DEFAULT_BOLD_CONTRACTS_VERSION="ef08baca" # bold-merge-script DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" From 82c8403f1a90e518580b8e64d0fc797de1c7953a Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 01:46:20 +0800 Subject: [PATCH 08/16] fix: rollupAddress issue --- test-node.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test-node.bash b/test-node.bash index 8944d6e6..fbe3e561 100755 --- a/test-node.bash +++ b/test-node.bash @@ -6,8 +6,8 @@ NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 # This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor -DEFAULT_NITRO_CONTRACTS_VERSION="984aff18" -DEFAULT_BOLD_CONTRACTS_VERSION="ef08baca" +DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" +DEFAULT_BOLD_CONTRACTS_VERSION="7d028430" # bold-merge-script DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" @@ -483,11 +483,11 @@ if $force_init; then docker compose up --wait $INITIAL_SEQ_NODES docker compose run scripts bridge-funds --ethamount 100000 --wait docker compose run scripts send-l2 --ethamount 100 --to l2owner --wait + rollupAddress=`docker compose run --entrypoint sh poster -c "jq -r '.[0].rollup.rollup' /config/deployed_chain_info.json | tail -n 1 | tr -d '\r\n'"` if $tokenbridge; then echo == Deploying L1-L2 token bridge sleep 10 # no idea why this sleep is needed but without it the deploy fails randomly - rollupAddress=`docker compose run --entrypoint sh poster -c "jq -r '.[0].rollup.rollup' /config/deployed_chain_info.json | tail -n 1 | tr -d '\r\n'"` docker compose run -e ROLLUP_OWNER_KEY=$l2ownerKey -e ROLLUP_ADDRESS=$rollupAddress -e PARENT_KEY=$devprivkey -e PARENT_RPC=http://geth:8545 -e CHILD_KEY=$devprivkey -e CHILD_RPC=http://sequencer:8547 tokenbridge deploy:local:token-bridge docker compose run --entrypoint sh tokenbridge -c "cat network.json && cp network.json l1l2_network.json && cp network.json localNetwork.json" echo @@ -498,14 +498,14 @@ if $force_init; then if $boldupgrade; then echo == Preparing BOLD upgrade - docker compose run boldupgrader script:bold-prepare + docker compose run -e ROLLUP_ADDRESS=$rollupAddress boldupgrader script:bold-prepare # retry this 10 times because the staker might not have made a node yet for i in {1..10}; do - docker compose run boldupgrader script:bold-populate-lookup && break || true + docker compose run -e ROLLUP_ADDRESS=$rollupAddress boldupgrader script:bold-populate-lookup && break || true echo "Failed to populate lookup table, retrying..." sleep 10 done - docker compose run boldupgrader script:bold-local-execute + docker compose run -e ROLLUP_ADDRESS=$rollupAddress boldupgrader script:bold-local-execute fi if $l3node; then From 7eaac1ef77ad8a32d3a9aa5dc08dac1a39d4e246 Mon Sep 17 00:00:00 2001 From: gzeon Date: Tue, 19 Nov 2024 02:02:47 +0800 Subject: [PATCH 09/16] ci: bold upgrade detach --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9052a740..807b5c29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,4 +56,4 @@ jobs: driver-opts: network=host - name: Startup Nitro testnode - run: ${{ github.workspace }}/.github/workflows/testnode.bash --init-force --bold-upgrade --simple + run: ${{ github.workspace }}/.github/workflows/testnode.bash --init-force --bold-upgrade --simple --detach From b48c399633dc8ed5a3b79d35e55ff5c860b7926b Mon Sep 17 00:00:00 2001 From: gzeon Date: Thu, 21 Nov 2024 20:01:22 +0800 Subject: [PATCH 10/16] chore: contract versions --- test-node.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test-node.bash b/test-node.bash index fbe3e561..fd3bfde3 100755 --- a/test-node.bash +++ b/test-node.bash @@ -5,12 +5,12 @@ set -eu NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 -# This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor -DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" -DEFAULT_BOLD_CONTRACTS_VERSION="7d028430" -# bold-merge-script +DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.0" DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" +# The is the latest bold-merge commit in nitro-contracts at the time +DEFAULT_BOLD_CONTRACTS_VERSION="59d3cbd" + # Set default versions if not overriden by provided env vars : ${NITRO_CONTRACTS_BRANCH:=$DEFAULT_NITRO_CONTRACTS_VERSION} : ${BOLD_CONTRACTS_BRANCH:=$DEFAULT_BOLD_CONTRACTS_VERSION} From 4c46f041131a08c7219e525b0a37afb6a5b18987 Mon Sep 17 00:00:00 2001 From: gzeon Date: Thu, 21 Nov 2024 20:03:05 +0800 Subject: [PATCH 11/16] fix: use v2.1.1-beta.0 --- test-node.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index fd3bfde3..ee9da445 100755 --- a/test-node.bash +++ b/test-node.bash @@ -5,7 +5,7 @@ set -eu NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 -DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.0" +DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" # The is the latest bold-merge commit in nitro-contracts at the time From 1c2ba50477a6c12c02c21a4bce47083dfabdacbb Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 23 Nov 2024 01:05:24 +0800 Subject: [PATCH 12/16] feat: stake token deploy --- test-node.bash | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test-node.bash b/test-node.bash index ee9da445..9cb2b97c 100755 --- a/test-node.bash +++ b/test-node.bash @@ -9,7 +9,7 @@ DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" # The is the latest bold-merge commit in nitro-contracts at the time -DEFAULT_BOLD_CONTRACTS_VERSION="59d3cbd" +DEFAULT_BOLD_CONTRACTS_VERSION="2f1d58dc" # Set default versions if not overriden by provided env vars : ${NITRO_CONTRACTS_BRANCH:=$DEFAULT_NITRO_CONTRACTS_VERSION} @@ -497,15 +497,19 @@ if $force_init; then docker compose run -e CHILD_CHAIN_RPC="http://sequencer:8547" -e CHAIN_OWNER_PRIVKEY=$l2ownerKey rollupcreator deploy-cachemanager-testnode if $boldupgrade; then + echo == Deploying BOLD stake token + stakeTokenAddress=`docker compose run scripts create-erc20 --deployer l2owner --decimals 18 | tail -n 1 | awk '{ print $NF }'` + echo BOLD stake token address: $stakeTokenAddress + docker compose run scripts transfer-erc20 --token $stakeTokenAddress --amount 10000 --from l2owner --to validator echo == Preparing BOLD upgrade - docker compose run -e ROLLUP_ADDRESS=$rollupAddress boldupgrader script:bold-prepare + docker compose run -e TESTNODE_MODE=true -e ROLLUP_ADDRESS=$rollupAddress -e STAKE_TOKEN=$stakeTokenAddress boldupgrader script:bold-prepare # retry this 10 times because the staker might not have made a node yet for i in {1..10}; do - docker compose run -e ROLLUP_ADDRESS=$rollupAddress boldupgrader script:bold-populate-lookup && break || true + docker compose run -e TESTNODE_MODE=true -e ROLLUP_ADDRESS=$rollupAddress -e STAKE_TOKEN=$stakeTokenAddress boldupgrader script:bold-populate-lookup && break || true echo "Failed to populate lookup table, retrying..." sleep 10 done - docker compose run -e ROLLUP_ADDRESS=$rollupAddress boldupgrader script:bold-local-execute + docker compose run -e TESTNODE_MODE=true -e ROLLUP_ADDRESS=$rollupAddress -e STAKE_TOKEN=$stakeTokenAddress boldupgrader script:bold-local-execute fi if $l3node; then From fb40407a8d122c977fd051f5ef1d47bc7225523a Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 23 Nov 2024 01:15:38 +0800 Subject: [PATCH 13/16] feat: allow deploy erc20 on l1 only --- scripts/ethcommands.ts | 25 ++++++++++++++++--------- test-node.bash | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index ac85ed69..8f318049 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -299,6 +299,10 @@ export const createERC20Command = { boolean: true, describe: "if true, deploy on L1 and bridge to L2", }, + l1: { + boolean: true, + describe: "if true, deploy on L1 only", + }, decimals: { string: true, describe: "number of decimals for token", @@ -308,17 +312,10 @@ export const createERC20Command = { handler: async (argv: any) => { console.log("create-erc20"); - if (argv.bridgeable) { - // deploy token on l1 and bridge to l2 - const l1l2tokenbridge = JSON.parse( - fs - .readFileSync(path.join(consts.tokenbridgedatapath, "l1l2_network.json")) - .toString() - ); + if (argv.bridgeable || argv.l1) { + // deploy token on l1 const l1provider = new ethers.providers.WebSocketProvider(argv.l1url); - const l2provider = new ethers.providers.WebSocketProvider(argv.l2url); - const deployerWallet = new Wallet( ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), l1provider @@ -328,6 +325,16 @@ export const createERC20Command = { const token = new ethers.Contract(tokenAddress, ERC20.abi, deployerWallet); console.log("Contract deployed at L1 address:", token.address); + if (!argv.bridgeable) return; + + // bridge to l2 + const l2provider = new ethers.providers.WebSocketProvider(argv.l2url); + const l1l2tokenbridge = JSON.parse( + fs + .readFileSync(path.join(consts.tokenbridgedatapath, "l1l2_network.json")) + .toString() + ); + const l1GatewayRouter = new ethers.Contract(l1l2tokenbridge.l2Network.tokenBridge.l1GatewayRouter, L1GatewayRouter.abi, deployerWallet); await (await token.functions.approve(l1l2tokenbridge.l2Network.tokenBridge.l1ERC20Gateway, ethers.constants.MaxUint256)).wait(); const supply = await token.totalSupply(); diff --git a/test-node.bash b/test-node.bash index 9cb2b97c..a11f7d94 100755 --- a/test-node.bash +++ b/test-node.bash @@ -498,7 +498,7 @@ if $force_init; then if $boldupgrade; then echo == Deploying BOLD stake token - stakeTokenAddress=`docker compose run scripts create-erc20 --deployer l2owner --decimals 18 | tail -n 1 | awk '{ print $NF }'` + stakeTokenAddress=`docker compose run scripts create-erc20 --l1 --deployer l2owner --decimals 18 | tail -n 1 | awk '{ print $NF }'` echo BOLD stake token address: $stakeTokenAddress docker compose run scripts transfer-erc20 --token $stakeTokenAddress --amount 10000 --from l2owner --to validator echo == Preparing BOLD upgrade From fdf19b20f63bf5033a12e46927a8a21ecfeb2e2e Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 23 Nov 2024 01:26:08 +0800 Subject: [PATCH 14/16] feat: transfer erc20 on l1 --- scripts/ethcommands.ts | 20 +++++++++++--------- test-node.bash | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 8f318049..533f9471 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -316,10 +316,7 @@ export const createERC20Command = { // deploy token on l1 const l1provider = new ethers.providers.WebSocketProvider(argv.l1url); - const deployerWallet = new Wallet( - ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), - l1provider - ); + const deployerWallet = namedAccount(argv.deployer).connect(l1provider); const tokenAddress = await deployERC20Contract(deployerWallet, argv.decimals); const token = new ethers.Contract(tokenAddress, ERC20.abi, deployerWallet); @@ -368,10 +365,7 @@ export const createERC20Command = { // no l1-l2 token bridge, deploy token on l2 directly argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); - const deployerWallet = new Wallet( - ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), - argv.provider - ); + const deployerWallet = namedAccount(argv.deployer).connect(argv.provider); const tokenAddress = await deployERC20Contract(deployerWallet, argv.decimals); console.log("Contract deployed at address:", tokenAddress); @@ -399,11 +393,19 @@ export const transferERC20Command = { string: true, describe: "address (see general help)", }, + l1: { + boolean: true, + describe: "if true, transfer on L1", + }, }, handler: async (argv: any) => { console.log("transfer-erc20"); - argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); + if (argv.l1) { + argv.provider = new ethers.providers.WebSocketProvider(argv.l1url); + } else { + argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); + } const account = namedAccount(argv.from).connect(argv.provider); const tokenContract = new ethers.Contract(argv.token, ERC20.abi, account); const tokenDecimals = await tokenContract.decimals(); diff --git a/test-node.bash b/test-node.bash index a11f7d94..32b54275 100755 --- a/test-node.bash +++ b/test-node.bash @@ -500,7 +500,7 @@ if $force_init; then echo == Deploying BOLD stake token stakeTokenAddress=`docker compose run scripts create-erc20 --l1 --deployer l2owner --decimals 18 | tail -n 1 | awk '{ print $NF }'` echo BOLD stake token address: $stakeTokenAddress - docker compose run scripts transfer-erc20 --token $stakeTokenAddress --amount 10000 --from l2owner --to validator + docker compose run scripts transfer-erc20 --token $stakeTokenAddress --l1 --amount 10000 --from l2owner --to validator echo == Preparing BOLD upgrade docker compose run -e TESTNODE_MODE=true -e ROLLUP_ADDRESS=$rollupAddress -e STAKE_TOKEN=$stakeTokenAddress boldupgrader script:bold-prepare # retry this 10 times because the staker might not have made a node yet From 1c2d0ab8a49c07338abf2053b96d7ec08c10dd2f Mon Sep 17 00:00:00 2001 From: gzeon Date: Sat, 23 Nov 2024 01:30:51 +0800 Subject: [PATCH 15/16] chore: update bold contract pin --- test-node.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index 32b54275..678e65c8 100755 --- a/test-node.bash +++ b/test-node.bash @@ -9,7 +9,7 @@ DEFAULT_NITRO_CONTRACTS_VERSION="v2.1.1-beta.0" DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" # The is the latest bold-merge commit in nitro-contracts at the time -DEFAULT_BOLD_CONTRACTS_VERSION="2f1d58dc" +DEFAULT_BOLD_CONTRACTS_VERSION="42d80e40" # Set default versions if not overriden by provided env vars : ${NITRO_CONTRACTS_BRANCH:=$DEFAULT_NITRO_CONTRACTS_VERSION} From ddbfb348623ce75ee42cb38caaceabbbf4c7dc7f Mon Sep 17 00:00:00 2001 From: gzeon Date: Mon, 25 Nov 2024 17:28:31 +0800 Subject: [PATCH 16/16] feat: use weth as bold stake token --- scripts/ethcommands.ts | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/index.ts | 2 ++ test-node.bash | 6 +++--- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 533f9471..aa5b333d 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -5,6 +5,7 @@ import { namedAccount, namedAddress } from "./accounts"; import * as L1GatewayRouter from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol/L1GatewayRouter.json"; import * as L1AtomicTokenBridgeCreator from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json"; import * as ERC20 from "@openzeppelin/contracts/build/contracts/ERC20.json"; +import * as TestWETH9 from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/test/TestWETH9.sol/TestWETH9.json"; import * as fs from "fs"; import { ARB_OWNER } from "./consts"; const path = require("path"); @@ -139,6 +140,14 @@ async function deployERC20Contract(deployerWallet: Wallet, decimals: number): Pr return token.address; } +async function deployWETHContract(deployerWallet: Wallet): Promise { + const wethFactory = new ContractFactory(TestWETH9.abi, TestWETH9.bytecode, deployerWallet); + const weth = await wethFactory.deploy("Wrapped Ether", "WETH"); + await weth.deployTransaction.wait(); + + return weth.address; +} + export const bridgeFundsCommand = { command: "bridge-funds", describe: "sends funds from l1 to l2", @@ -415,6 +424,38 @@ export const transferERC20Command = { }, }; +export const createWETHCommand = { + command: "create-weth", + describe: "creates WETH on L1", + builder: { + deployer: { + string: true, + describe: "account (see general help)" + }, + deposit: { + number: true, + describe: "amount of weth to deposit", + default: 100, + } + }, + handler: async (argv: any) => { + console.log("create-weth"); + + const l1provider = new ethers.providers.WebSocketProvider(argv.l1url); + const deployerWallet = namedAccount(argv.deployer).connect(l1provider); + + const wethAddress = await deployWETHContract(deployerWallet); + const weth = new ethers.Contract(wethAddress, TestWETH9.abi, deployerWallet); + console.log("WETH deployed at L1 address:", weth.address); + + if (argv.deposit > 0) { + const amount = ethers.utils.parseEther(argv.deposit.toString()); + const depositTx = await deployerWallet.sendTransaction({ to: wethAddress, value: amount, data:"0xd0e30db0" }); // deposit() + await depositTx.wait(); + } + }, +}; + export const sendL1Command = { command: "send-l1", describe: "sends funds between l1 accounts", diff --git a/scripts/index.ts b/scripts/index.ts index 69cfe156..46066f07 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -14,6 +14,7 @@ import { bridgeNativeTokenToL3Command, bridgeToL3Command, createERC20Command, + createWETHCommand, transferERC20Command, sendL1Command, sendL2Command, @@ -38,6 +39,7 @@ async function main() { .command(bridgeToL3Command) .command(bridgeNativeTokenToL3Command) .command(createERC20Command) + .command(createWETHCommand) .command(transferERC20Command) .command(sendL1Command) .command(sendL2Command) diff --git a/test-node.bash b/test-node.bash index 678e65c8..ee988620 100755 --- a/test-node.bash +++ b/test-node.bash @@ -497,10 +497,10 @@ if $force_init; then docker compose run -e CHILD_CHAIN_RPC="http://sequencer:8547" -e CHAIN_OWNER_PRIVKEY=$l2ownerKey rollupcreator deploy-cachemanager-testnode if $boldupgrade; then - echo == Deploying BOLD stake token - stakeTokenAddress=`docker compose run scripts create-erc20 --l1 --deployer l2owner --decimals 18 | tail -n 1 | awk '{ print $NF }'` + echo == Deploying WETH as BOLD stake token + stakeTokenAddress=`docker compose run scripts create-weth --deployer l2owner --deposit 100 | tail -n 1 | awk '{ print $NF }'` echo BOLD stake token address: $stakeTokenAddress - docker compose run scripts transfer-erc20 --token $stakeTokenAddress --l1 --amount 10000 --from l2owner --to validator + docker compose run scripts transfer-erc20 --token $stakeTokenAddress --l1 --amount 100 --from l2owner --to validator echo == Preparing BOLD upgrade docker compose run -e TESTNODE_MODE=true -e ROLLUP_ADDRESS=$rollupAddress -e STAKE_TOKEN=$stakeTokenAddress boldupgrader script:bold-prepare # retry this 10 times because the staker might not have made a node yet