From 210c89e71ba3322d299f7745f8ddd720660aeecb Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 14:41:42 +0200 Subject: [PATCH 01/17] ci: test bridge operations in ci --- .github/scripts/bridge.sh | 92 ++++++++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 8 ++++ 2 files changed, 100 insertions(+) create mode 100755 .github/scripts/bridge.sh diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh new file mode 100755 index 00000000..04594f7d --- /dev/null +++ b/.github/scripts/bridge.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# This script bridges tokens from L1 to L2 and vice versa. + +# Function to display usage information. +usage() { + echo "Usage: $0 --l2-rpc-url " + echo " --l2-rpc-url: The L2 RPC URL to query." + exit 1 +} + +# Initialize variables. +l2_rpc_url="" + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + --l2-rpc-url) + l2_rpc_url="$2" + shift 2 + ;; + *) + usage + ;; + esac +done + +# Check if the required argument is provided. +if [ -z "$l2_rpc_url" ]; then + echo "Error: L2 RPC URL is required." + usage +fi + +# Set universal parameters. +address="$(yq --raw-output .args.zkevm_l2_admin_address params.yml)" +pk="$(yq --raw-output .args.zkevm_l2_admin_private_key params.yml)" + +zkevm_bridge_address="$(kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq --raw-output .polygonZkEVMBridgeAddress)" +zkevm_bridge_service_url="$(kurtosis port print cdk-v1 zkevm-bridge-service-001 rpc)" + +l1_rpc_url="$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" +l1_chain_id="$(yq --raw-output .args.l1_chain_id params.yml)" +l2_chain_id="$(yq --raw-output .args.zkevm_rollup_chain_id params.yml)" + +echo "Running script with values:" +echo "- Address: $address" +echo "- Private Key: ${pk#0x}" +echo "- zkEVM Bridge Address: $zkevm_bridge_address" +echo "- zkEVM Bridge Service URL: $zkevm_bridge_service_url" +echo "- L1 RPC URL: $l1_rpc_url" +echo "- L1 Chain ID: $l1_chain_id" +echo "- L2 RPC URL: $l2_rpc_url" +echo "- L2 Chain ID: $l2_chain_id" +echo + +# Show balances. +l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" $address)" +l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" $address)" +echo "Balances before bridging: $l1_balance (L1) / $l2_balance (L2)" + +# Bridge from L1 to L2. +echo "Bridging from L1 to L2..." +polycli ulxly deposit-new \ + --private-key "${pk#0x}" \ + --rpc-url "$l1_rpc_url" \ + --chain-id "$l1_chain_id" \ + --bridge-address "$zkevm_bridge_address" \ + --destination-network 1 \ + --destination-address "$address" \ + --amount 1000 \ + --verbosity 700 + +# Claim on L2. +echo "Claiming on L2..." +polycli ulxly deposit-claim \ + --private-key "${pk#0x}" \ + --rpc-url "$l2_rpc_url" \ + --chain-id "$l2_chain_id" \ + --bridge-address "$zkevm_bridge_address" \ + --bridge-service-url "$zkevm_bridge_service_url" \ + --origin-network 0 \ + --destination-network 1 \ + --claim-address "$address" \ + --claim-index 0 + +# Show balances. +l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" $address)" +l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" $address)" +echo "Balances after bridging: $l1_balance (L1) / $l2_balance (L2)" + +# TODO: Bridge from L2 to L1 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4f4210fe..770ec201 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,6 +47,10 @@ jobs: with: rpc_service: zkevm-node-rpc-pless-001 + - name: Bridge tokens from L1 to L2 and vice versa + working-directory: .github/scripts + run: ./bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)" + zkevm: runs-on: ubuntu-latest steps: @@ -82,3 +86,7 @@ jobs: rpc_service: zkevm-node-rpc-pless-001 # TODO(nit): Deploy a CDK Erigon Permissionless RPC and check that it can sync. + + - name: Bridge tokens from L1 to L2 and vice versa + working-directory: .github/scripts + run: ./bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" From fba72cf5fe9563810a6ec70b7ea9bbf29e962935 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 14:44:52 +0200 Subject: [PATCH 02/17] fix: lint --- .github/scripts/bridge.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index 04594f7d..4327eb43 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -55,8 +55,8 @@ echo "- L2 Chain ID: $l2_chain_id" echo # Show balances. -l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" $address)" -l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" $address)" +l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" "$address")" +l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" "$address")" echo "Balances before bridging: $l1_balance (L1) / $l2_balance (L2)" # Bridge from L1 to L2. @@ -85,8 +85,8 @@ polycli ulxly deposit-claim \ --claim-index 0 # Show balances. -l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" $address)" -l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" $address)" +l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" "$address")" +l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" "$address")" echo "Balances after bridging: $l1_balance (L1) / $l2_balance (L2)" # TODO: Bridge from L2 to L1 From 7ed038d915dbad165c7e862451568d30b1bd8032 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 15:16:59 +0200 Subject: [PATCH 03/17] fix: path --- .github/workflows/deploy.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 770ec201..d8cecebd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -48,8 +48,7 @@ jobs: rpc_service: zkevm-node-rpc-pless-001 - name: Bridge tokens from L1 to L2 and vice versa - working-directory: .github/scripts - run: ./bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)" + run: ./.github/scripts/bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)" zkevm: runs-on: ubuntu-latest @@ -88,5 +87,4 @@ jobs: # TODO(nit): Deploy a CDK Erigon Permissionless RPC and check that it can sync. - name: Bridge tokens from L1 to L2 and vice versa - working-directory: .github/scripts - run: ./bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" + run: ./.github/scripts/bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" From 74b243b298e009cf13d9a2b4a27dd163112bec05 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 15:17:46 +0200 Subject: [PATCH 04/17] chore: nit --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d8cecebd..7fd0f1d4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,7 +47,7 @@ jobs: with: rpc_service: zkevm-node-rpc-pless-001 - - name: Bridge tokens from L1 to L2 and vice versa + - name: Bridge tokens run: ./.github/scripts/bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)" zkevm: @@ -86,5 +86,5 @@ jobs: # TODO(nit): Deploy a CDK Erigon Permissionless RPC and check that it can sync. - - name: Bridge tokens from L1 to L2 and vice versa + - name: Bridge tokens run: ./.github/scripts/bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" From 3d480a4901d6ea82f2a5e92f26d1bea82e6f2091 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 16:31:28 +0200 Subject: [PATCH 05/17] fix: install `polycli` --- .github/workflows/deploy.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7fd0f1d4..788c6874 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,6 +12,9 @@ concurrency: group: deploy-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +env: + POLYCLI_VERSION: "0.1.52" + jobs: cdk: runs-on: ubuntu-latest @@ -21,6 +24,14 @@ jobs: - name: Install Kurtosis CDK tools uses: ./.github/actions/setup-kurtosis-cdk + - name: Install polycli + run: | + curl -L -o /tmp/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz https://github.com/0xPolygon/polygon-cli/releases/download/v${{ env.POLYCLI_VERSION }}/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz + pushd /tmp + tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz + sudo mv polycli /usr/local/bin/ + polycli --version + # Deploy the CDK environment with cdk-erigon, serving as the sequencer. # Set up the cdk-node for the remaining components. # Additionally, deploy cdk-erigon and zkevm-node as permissionless nodes or RPCs. @@ -58,6 +69,14 @@ jobs: - name: Install Kurtosis CDK tools uses: ./.github/actions/setup-kurtosis-cdk + - name: Install polycli + run: | + curl -L -o /tmp/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz https://github.com/0xPolygon/polygon-cli/releases/download/v${{ env.POLYCLI_VERSION }}/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz + pushd /tmp + tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz + sudo mv polycli /usr/local/bin/ + polycli --version + # Deploy the CDK environment with zkevm-node, serving as the sequencer. # Also set up the zkevm-node for the remaining components. # Additionally, deploy zkevm-node as permissionless node or RPC. From 9edb0f78178bedea344f3d227f19099ac6ce8e8f Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 16:34:44 +0200 Subject: [PATCH 06/17] fix: `polycli` install --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 788c6874..f9d66953 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,7 +29,7 @@ jobs: curl -L -o /tmp/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz https://github.com/0xPolygon/polygon-cli/releases/download/v${{ env.POLYCLI_VERSION }}/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz pushd /tmp tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz - sudo mv polycli /usr/local/bin/ + sudo mv polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64 /usr/local/bin/polycli polycli --version # Deploy the CDK environment with cdk-erigon, serving as the sequencer. @@ -74,7 +74,7 @@ jobs: curl -L -o /tmp/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz https://github.com/0xPolygon/polygon-cli/releases/download/v${{ env.POLYCLI_VERSION }}/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz pushd /tmp tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz - sudo mv polycli /usr/local/bin/ + sudo mv polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64 /usr/local/bin/polycli polycli --version # Deploy the CDK environment with zkevm-node, serving as the sequencer. From be73384f8ec36948d34803d0c134feb9baeb1808 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 16:54:11 +0200 Subject: [PATCH 07/17] fix: `polycli version` --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f9d66953..77a26e7d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -30,7 +30,7 @@ jobs: pushd /tmp tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz sudo mv polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64 /usr/local/bin/polycli - polycli --version + polycli version # Deploy the CDK environment with cdk-erigon, serving as the sequencer. # Set up the cdk-node for the remaining components. @@ -75,7 +75,7 @@ jobs: pushd /tmp tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz sudo mv polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64 /usr/local/bin/polycli - polycli --version + polycli version # Deploy the CDK environment with zkevm-node, serving as the sequencer. # Also set up the zkevm-node for the remaining components. From 31b071baa640ac10ca5863dd0d02704aeb6a785f Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 17:12:37 +0200 Subject: [PATCH 08/17] feat: loop until there is a claimable tx --- .github/scripts/bridge.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index 4327eb43..b0f89793 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -57,7 +57,10 @@ echo # Show balances. l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" "$address")" l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" "$address")" -echo "Balances before bridging: $l1_balance (L1) / $l2_balance (L2)" +echo "Balances before bridging:" +echo "- L1: $l1_balance ETH" +echo "- L2: $l2_balance ETH" +echo # Bridge from L1 to L2. echo "Bridging from L1 to L2..." @@ -71,6 +74,21 @@ polycli ulxly deposit-new \ --amount 1000 \ --verbosity 700 +# Loop until at least one claimable transaction is found. +echo "Waiting for the bridge service to detect the bridge event..." +while true; do + # Query the bridge service and filter for claimable transactions on L2. + claimable_count=$(curl -s "$zkevm_bridge_service_url/bridges/$address" | + jq '[.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .dest_net == 1)] | length') + if [ "$claimable_count" -gt 0 ]; then + echo "Claimable transaction found. Proceeding with further actions..." + break + else + echo "No claimable transactions found. Retrying in 10 seconds..." + fi + sleep 10 +done + # Claim on L2. echo "Claiming on L2..." polycli ulxly deposit-claim \ @@ -87,6 +105,9 @@ polycli ulxly deposit-claim \ # Show balances. l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" "$address")" l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" "$address")" -echo "Balances after bridging: $l1_balance (L1) / $l2_balance (L2)" +echo "Balances before bridging:" +echo "- L1: $l1_balance ETH" +echo "- L2: $l2_balance ETH" +echo # TODO: Bridge from L2 to L1 From d804da7f7d5995d824a1ba65760baa431aa9fa8e Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 17:16:57 +0200 Subject: [PATCH 09/17] ci: install `polycli` in local action --- .github/actions/setup-kurtosis-cdk/action.yml | 16 +++++++++++++++- .github/workflows/deploy.yml | 19 ------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/.github/actions/setup-kurtosis-cdk/action.yml b/.github/actions/setup-kurtosis-cdk/action.yml index 01882db2..9e4d9d92 100644 --- a/.github/actions/setup-kurtosis-cdk/action.yml +++ b/.github/actions/setup-kurtosis-cdk/action.yml @@ -6,7 +6,11 @@ inputs: kurtosis-version: description: The version of kurtosis required: false - default: '1.0.0' # https://github.com/kurtosis-tech/kurtosis/releases + default: "1.0.0" # https://github.com/kurtosis-tech/kurtosis/releases + polycli-version: + description: The version of polygon-cli + required: false + default: "v0.1.52" # https://github.com/0xPolygon/polygon-cli/releases runs: using: "composite" @@ -38,3 +42,13 @@ runs: - name: Install foundry uses: foundry-rs/foundry-toolchain@v1 + + - name: Install polycli + shell: bash + run: | + curl -L --output /tmp/polycli_${{ inputs.polycli-version }}_linux_amd64.tar.gz \ + https://github.com/0xPolygon/polygon-cli/releases/download/${{ inputs.polycli-version }}/polycli_${{ inputs.polycli-version }}_linux_amd64.tar.gz + pushd /tmp + tar -xvzf polycli_${{ inputs.polycli-version }}_linux_amd64.tar.gz + sudo mv polycli_${{ inputs.polycli-version }}_linux_amd64 /usr/local/bin/polycli + polycli version diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 77a26e7d..7fd0f1d4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,9 +12,6 @@ concurrency: group: deploy-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true -env: - POLYCLI_VERSION: "0.1.52" - jobs: cdk: runs-on: ubuntu-latest @@ -24,14 +21,6 @@ jobs: - name: Install Kurtosis CDK tools uses: ./.github/actions/setup-kurtosis-cdk - - name: Install polycli - run: | - curl -L -o /tmp/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz https://github.com/0xPolygon/polygon-cli/releases/download/v${{ env.POLYCLI_VERSION }}/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz - pushd /tmp - tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz - sudo mv polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64 /usr/local/bin/polycli - polycli version - # Deploy the CDK environment with cdk-erigon, serving as the sequencer. # Set up the cdk-node for the remaining components. # Additionally, deploy cdk-erigon and zkevm-node as permissionless nodes or RPCs. @@ -69,14 +58,6 @@ jobs: - name: Install Kurtosis CDK tools uses: ./.github/actions/setup-kurtosis-cdk - - name: Install polycli - run: | - curl -L -o /tmp/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz https://github.com/0xPolygon/polygon-cli/releases/download/v${{ env.POLYCLI_VERSION }}/polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz - pushd /tmp - tar -xvzf polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64.tar.gz - sudo mv polycli_v${{ env.POLYCLI_VERSION }}_linux_amd64 /usr/local/bin/polycli - polycli version - # Deploy the CDK environment with zkevm-node, serving as the sequencer. # Also set up the zkevm-node for the remaining components. # Additionally, deploy zkevm-node as permissionless node or RPC. From f3710cd7f14d4389334ef5e13e20a92523bf3e25 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 17:41:33 +0200 Subject: [PATCH 10/17] chore: better output --- .github/scripts/bridge.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index b0f89793..7ccab575 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -73,6 +73,7 @@ polycli ulxly deposit-new \ --destination-address "$address" \ --amount 1000 \ --verbosity 700 +echo # Loop until at least one claimable transaction is found. echo "Waiting for the bridge service to detect the bridge event..." @@ -81,13 +82,14 @@ while true; do claimable_count=$(curl -s "$zkevm_bridge_service_url/bridges/$address" | jq '[.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .dest_net == 1)] | length') if [ "$claimable_count" -gt 0 ]; then - echo "Claimable transaction found. Proceeding with further actions..." + echo "Claimable transaction found!" break else echo "No claimable transactions found. Retrying in 10 seconds..." fi sleep 10 done +echo # Claim on L2. echo "Claiming on L2..." @@ -101,6 +103,7 @@ polycli ulxly deposit-claim \ --destination-network 1 \ --claim-address "$address" \ --claim-index 0 +echo # Show balances. l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" "$address")" From 84dec2f7d16d6bc77851e4debdc6137090c48c54 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 17:45:48 +0200 Subject: [PATCH 11/17] feat: bridge from L2 to L1 --- .github/scripts/bridge.sh | 51 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index 7ccab575..dcc81e53 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -113,4 +113,53 @@ echo "- L1: $l1_balance ETH" echo "- L2: $l2_balance ETH" echo -# TODO: Bridge from L2 to L1 +# Bridge from L2 to L1. +echo "Bridging from L2 to L1..." +polycli ulxly deposit-new \ + --private-key "${pk#0x}" \ + --rpc-url "$l2_rpc_url" \ + --chain-id "$l2_chain_id" \ + --bridge-address "$zkevm_bridge_address" \ + --destination-network 0 \ + --destination-address "$address" \ + --amount 500 \ + --verbosity 700 +echo + +# Loop until at least one claimable transaction is found. +echo "Waiting for the bridge service to detect the bridge event..." +while true; do + # Query the bridge service and filter for claimable transactions on L2. + claimable_count=$(curl -s "$zkevm_bridge_service_url/bridges/$address" | + jq '[.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .dest_net == 0)] | length') + if [ "$claimable_count" -gt 0 ]; then + echo "Claimable transaction found!" + break + else + echo "No claimable transactions found. Retrying in 10 seconds..." + fi + sleep 10 +done +echo + +# Claim on L1. +echo "Claiming on L1..." +polycli ulxly deposit-claim \ + --private-key "${pk#0x}" \ + --rpc-url "$l1_rpc_url" \ + --chain-id "$l1_chain_id" \ + --bridge-address "$zkevm_bridge_address" \ + --bridge-service-url "$zkevm_bridge_service_url" \ + --origin-network 1 \ + --destination-network 0 \ + --claim-address "$address" \ + --claim-index 1 +echo + +# Show balances. +l1_balance="$(cast balance --ether --rpc-url "$l1_rpc_url" "$address")" +l2_balance="$(cast balance --ether --rpc-url "$l2_rpc_url" "$address")" +echo "Balances before bridging:" +echo "- L1: $l1_balance ETH" +echo "- L2: $l2_balance ETH" +echo From e6db46e02c8c944d6af9f7d859ff293cdaf8d8c1 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 18:00:25 +0200 Subject: [PATCH 12/17] chore: minor --- .github/scripts/bridge.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index dcc81e53..df1a1f69 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -33,6 +33,7 @@ if [ -z "$l2_rpc_url" ]; then fi # Set universal parameters. +echo "Retrieving script parameters..." address="$(yq --raw-output .args.zkevm_l2_admin_address params.yml)" pk="$(yq --raw-output .args.zkevm_l2_admin_private_key params.yml)" From d1c66f621c3823c8ddf7968814f884fce5e0a690 Mon Sep 17 00:00:00 2001 From: leovct Date: Wed, 14 Aug 2024 18:01:37 +0200 Subject: [PATCH 13/17] chore: exit script on error --- .github/scripts/bridge.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index df1a1f69..48c5c409 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -2,6 +2,8 @@ # This script bridges tokens from L1 to L2 and vice versa. +set -e # Exit immediately if a command exits with a non-zero status + # Function to display usage information. usage() { echo "Usage: $0 --l2-rpc-url " From 8d2bdff6e96d5d162cf5b71f2e40d195829eb5dc Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 16 Aug 2024 12:32:36 +0200 Subject: [PATCH 14/17] ci: bump to new `polycli` version --- .github/actions/setup-kurtosis-cdk/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-kurtosis-cdk/action.yml b/.github/actions/setup-kurtosis-cdk/action.yml index 9e4d9d92..4d5c6fe5 100644 --- a/.github/actions/setup-kurtosis-cdk/action.yml +++ b/.github/actions/setup-kurtosis-cdk/action.yml @@ -10,7 +10,7 @@ inputs: polycli-version: description: The version of polygon-cli required: false - default: "v0.1.52" # https://github.com/0xPolygon/polygon-cli/releases + default: "v0.1.53" # https://github.com/0xPolygon/polygon-cli/releases runs: using: "composite" From 0360f9c42e7b9075c109a34ccc12545cb256054f Mon Sep 17 00:00:00 2001 From: leovct Date: Mon, 19 Aug 2024 09:57:22 +0200 Subject: [PATCH 15/17] fix: enclave name --- .github/scripts/bridge.sh | 20 +++++++++++++++----- .github/workflows/deploy.yml | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index 48c5c409..f0361ee6 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -6,13 +6,15 @@ set -e # Exit immediately if a command exits with a non-zero status # Function to display usage information. usage() { - echo "Usage: $0 --l2-rpc-url " + echo "Usage: $0 --l2-rpc-url --enclave " echo " --l2-rpc-url: The L2 RPC URL to query." + echo " --enclave: The name of the Kurtosis enclave." exit 1 } # Initialize variables. l2_rpc_url="" +enclave="" # Parse command line arguments while [[ $# -gt 0 ]]; do @@ -22,6 +24,10 @@ while [[ $# -gt 0 ]]; do l2_rpc_url="$2" shift 2 ;; + --enclave) + enclave="$2" + shift 2 + ;; *) usage ;; @@ -33,20 +39,24 @@ if [ -z "$l2_rpc_url" ]; then echo "Error: L2 RPC URL is required." usage fi +if [ -z "$enclave" ]; then + echo "Error: Enclave name is required." + usage +fi # Set universal parameters. echo "Retrieving script parameters..." address="$(yq --raw-output .args.zkevm_l2_admin_address params.yml)" pk="$(yq --raw-output .args.zkevm_l2_admin_private_key params.yml)" +zkevm_bridge_address="$(kurtosis service exec "$enclave" contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq --raw-output .polygonZkEVMBridgeAddress)" +zkevm_bridge_service_url="$(kurtosis port print "$enclave" zkevm-bridge-service-001 rpc)" -zkevm_bridge_address="$(kurtosis service exec cdk-v1 contracts-001 "cat /opt/zkevm/combined.json" | tail -n +2 | jq --raw-output .polygonZkEVMBridgeAddress)" -zkevm_bridge_service_url="$(kurtosis port print cdk-v1 zkevm-bridge-service-001 rpc)" - -l1_rpc_url="$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" +l1_rpc_url="$(kurtosis port print "$enclave" el-1-geth-lighthouse rpc)" l1_chain_id="$(yq --raw-output .args.l1_chain_id params.yml)" l2_chain_id="$(yq --raw-output .args.zkevm_rollup_chain_id params.yml)" echo "Running script with values:" +echo "- Enclave: $enclave" echo "- Address: $address" echo "- Private Key: ${pk#0x}" echo "- zkEVM Bridge Address: $zkevm_bridge_address" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f0bb00b0..0f69d970 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -57,7 +57,7 @@ jobs: run: ./monitor-verified-batches.sh --rpc-url "$(kurtosis port print ${{ env.ENCLAVE_NAME }} zkevm-node-rpc-pless-001 http-rpc)" - name: Bridge tokens - run: ./.github/scripts/bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 http-rpc)" + run: ./.github/scripts/bridge.sh --l2-rpc-url $(kurtosis port print ${{ env.ENCLAVE_NAME }} cdk-erigon-node-001 http-rpc) zkevm: runs-on: ubuntu-latest @@ -102,4 +102,4 @@ jobs: # TODO(nit): Deploy a CDK Erigon Permissionless RPC and check that it can sync. - name: Bridge tokens - run: ./.github/scripts/bridge.sh --l2-rpc-url "$(kurtosis port print cdk-v1 zkevm-node-rpc-001 http-rpc)" + run: ./.github/scripts/bridge.sh --l2-rpc-url $(kurtosis port print ${{ env.ENCLAVE_NAME }} zkevm-node-rpc-001 http-rpc) From 799b1f0c6b82b50dd3e3671e5b4e8ef1462d22bd Mon Sep 17 00:00:00 2001 From: leovct Date: Mon, 19 Aug 2024 10:05:48 +0200 Subject: [PATCH 16/17] fix: claim index when claiming on L1 --- .github/scripts/bridge.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/bridge.sh b/.github/scripts/bridge.sh index f0361ee6..41bab2f0 100755 --- a/.github/scripts/bridge.sh +++ b/.github/scripts/bridge.sh @@ -166,7 +166,7 @@ polycli ulxly deposit-claim \ --origin-network 1 \ --destination-network 0 \ --claim-address "$address" \ - --claim-index 1 + --claim-index 0 echo # Show balances. From 3fdcbdc2ee91391260f18af8c72bbbcd5835c390 Mon Sep 17 00:00:00 2001 From: leovct Date: Mon, 19 Aug 2024 10:21:06 +0200 Subject: [PATCH 17/17] fix --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0f69d970..ad88b9f5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -57,7 +57,7 @@ jobs: run: ./monitor-verified-batches.sh --rpc-url "$(kurtosis port print ${{ env.ENCLAVE_NAME }} zkevm-node-rpc-pless-001 http-rpc)" - name: Bridge tokens - run: ./.github/scripts/bridge.sh --l2-rpc-url $(kurtosis port print ${{ env.ENCLAVE_NAME }} cdk-erigon-node-001 http-rpc) + run: ./.github/scripts/bridge.sh --l2-rpc-url $(kurtosis port print ${{ env.ENCLAVE_NAME }} cdk-erigon-node-001 http-rpc) --enclave ${{ env.ENCLAVE_NAME }} zkevm: runs-on: ubuntu-latest @@ -102,4 +102,4 @@ jobs: # TODO(nit): Deploy a CDK Erigon Permissionless RPC and check that it can sync. - name: Bridge tokens - run: ./.github/scripts/bridge.sh --l2-rpc-url $(kurtosis port print ${{ env.ENCLAVE_NAME }} zkevm-node-rpc-001 http-rpc) + run: ./.github/scripts/bridge.sh --l2-rpc-url $(kurtosis port print ${{ env.ENCLAVE_NAME }} zkevm-node-rpc-001 http-rpc) --enclave ${{ env.ENCLAVE_NAME }}