diff --git a/.github/workflows/contracts-compile-and-deploy-to-devenv.yml b/.github/workflows/contracts-compile-and-deploy-to-testnet.yml similarity index 70% rename from .github/workflows/contracts-compile-and-deploy-to-devenv.yml rename to .github/workflows/contracts-compile-and-deploy-to-testnet.yml index bea222e6..76a0985e 100644 --- a/.github/workflows/contracts-compile-and-deploy-to-devenv.yml +++ b/.github/workflows/contracts-compile-and-deploy-to-testnet.yml @@ -1,9 +1,21 @@ --- -name: Devenv - deploy contracts (on demand) +name: Deploy MOST L1 contracts to Testnet on: workflow_dispatch: + inputs: + deploy-contracts: + description: Set to true to deploy contracts to Testnet + type: boolean + required: false + default: false workflow_call: + inputs: + deploy-contracts: + description: Set to true to deploy contracts to Testnet + type: boolean + required: false + default: false concurrency: group: "${{ github.ref }}-${{ github.workflow }}" @@ -15,13 +27,12 @@ jobs: uses: ./.github/workflows/_check-vars-and-secrets.yml secrets: inherit - deploy-contracts: - name: Deploy and setup contracts - runs-on: [self-hosted, Linux, X64, large] + compile-contracts: + name: Compile ink and solidity contracts + runs-on: ubuntu-latest needs: [check-vars-and-secrets] outputs: artifact-matrix-json: ${{ steps.get-artifact-matrix.outputs.artifact-matrix }} - steps: - name: Checkout code uses: actions/checkout@v4 @@ -29,91 +40,44 @@ jobs: - name: Setup node uses: asdf-vm/actions/install@v3 - - name: Create azero env file - shell: bash - env: - AZERO1: ${{ secrets.DEVENV_TESTNET_AZERO1_ACCOUNT_NUMBER }} - AZERO2: ${{ secrets.DEVENV_TESTNET_AZERO2_ACCOUNT_NUMBER }} - AZERO3: ${{ secrets.DEVENV_TESTNET_AZERO3_ACCOUNT_NUMBER }} - AZERO1_SEED: ${{ secrets.DEVENV_TESTNET_AZERO1_KEY }} - run: | - cat azero/env/testnet.json | \ - jq '.relayers = ["${{ env.AZERO1 }}", "${{ env.AZERO2 }}", "${{ env.AZERO3 }}"]' | \ - jq '.deployer_seed = "${{ env.AZERO1_SEED }}"' | jq '.dev = true' > azero/env/testnet.json.tmp - mv azero/env/testnet.json.tmp azero/env/testnet.json - - - name: Get latest eth block - shell: bash - env: - SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} - SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} - SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" - run: | - make eth-deps - cd eth - npx hardhat run --network sepolia scripts/get_latest_block.js - - - name: Get latest azero block + - name: Compile solidity contracts shell: bash run: | - make azero-deps - cd azero - AZERO_ENV=testnet npm run get-latest-block + make compile-eth - - name: Deploy eth contracts + - name: Compile ink! contracts shell: bash - env: - SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} - SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} - SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" run: | - make deploy-eth NETWORK=sepolia + make compile-azero-docker - - name: Deploy eth contracts (TransferLimit) - shell: bash - env: - SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} - SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} - SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" - run: | - make deploy-eth-transfer-limit NETWORK=sepolia - - - name: Deploy azero contracts + - name: Compile azero JS types contracts shell: bash run: | - AZERO_ENV=testnet make deploy-azero-docker - - - name: Setup eth contracts - shell: bash - env: - SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} - SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} - SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" - run: make setup-eth NETWORK=sepolia - - - name: Setup azero contracts - shell: bash - run: AZERO_ENV=testnet make setup-azero-docker + make typechain-azero - uses: actions/upload-artifact@v4 with: - name: eth-deployed-contracts + name: eth-compiled-contracts if-no-files-found: error retention-days: 1 path: | eth/artifacts - eth/addresses.json - eth/block_latest.json - uses: actions/upload-artifact@v4 with: - name: azero-deployed-contracts + name: azero-compiled-contracts if-no-files-found: error retention-days: 1 path: | azero/artifacts - azero/addresses.json - azero/block_latest.json + + - uses: actions/upload-artifact@v4 + with: + name: azero-compiled-contracts-types + if-no-files-found: error + retention-days: 1 + path: | + azero/types - name: Get list of contract artifacts shell: bash @@ -146,25 +110,30 @@ jobs: echo "artifact-matrix=$(cat tmp-artifacts-matrix.json)" >> $GITHUB_OUTPUT - upload-contract-artifacts: + upload-contract-artifacts-to-s3: name: Upload contract artifacts to S3 runs-on: [self-hosted, Linux, X64, small] - needs: [deploy-contracts] + needs: [compile-contracts] strategy: - matrix: ${{ fromJson(needs.deploy-contracts.outputs.artifact-matrix-json) }} + matrix: ${{ fromJson(needs.compile-contracts.outputs.artifact-matrix-json) }} steps: - name: Checkout code uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: - name: azero-deployed-contracts - path: azero + name: azero-compiled-contracts + path: azero/artifacts - uses: actions/download-artifact@v4 with: - name: eth-deployed-contracts - path: eth + name: azero-compiled-contracts-types + path: azero/types + + - uses: actions/download-artifact@v4 + with: + name: eth-compiled-contracts + path: eth/artifacts - name: Store artifact in S3 bucket shell: bash @@ -175,8 +144,135 @@ jobs: run: | aws s3 cp ${{ matrix.from }} s3://${{ secrets.CONTRACTS_S3BUCKET_NAME }}/most/artifacts/${{ github.sha }}/${{ matrix.to }}/ + deploy-contracts: + name: Deploy and setup contracts + if: ${{ inputs.deploy-contracts }} + runs-on: [self-hosted, Linux, X64, large] + needs: [compile-contracts] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: azero-compiled-contracts + path: azero/artifacts + + - uses: actions/download-artifact@v4 + with: + name: eth-compiled-contracts + path: eth/artifacts + + - uses: actions/download-artifact@v4 + with: + name: azero-compiled-contracts-types + path: azero/types + + - name: Setup node + uses: asdf-vm/actions/install@v3 + + - name: Create azero env file + shell: bash + env: + AZERO1: ${{ secrets.DEVENV_TESTNET_AZERO1_ACCOUNT_NUMBER }} + AZERO2: ${{ secrets.DEVENV_TESTNET_AZERO2_ACCOUNT_NUMBER }} + AZERO3: ${{ secrets.DEVENV_TESTNET_AZERO3_ACCOUNT_NUMBER }} + AZERO1_SEED: ${{ secrets.DEVENV_TESTNET_AZERO1_KEY }} + run: | + cat azero/env/testnet.json | \ + jq '.relayers = ["${{ env.AZERO1 }}", "${{ env.AZERO2 }}", "${{ env.AZERO3 }}"]' | \ + jq '.deployer_seed = "${{ env.AZERO1_SEED }}"' | jq '.dev = true' > azero/env/testnet.json.tmp + mv azero/env/testnet.json.tmp azero/env/testnet.json + + - name: Get latest eth block + shell: bash + env: + SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} + SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} + SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" + NETWORK: "sepolia" + run: | + make get-latest-eth-block + + - name: Get latest azero block + shell: bash + env: + AZERO_ENV: "testnet" + run: | + make get-latest-azero-block + + - name: Deploy eth contracts + shell: bash + env: + SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} + SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} + SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" + NETWORK: "sepolia" + COMPILE_ETH_CONTRACTS_WHEN_DEPLOYING: "no-compile" + run: | + make deploy-eth + + - name: Deploy eth contracts (TransferLimit) + shell: bash + env: + SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} + SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} + SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" + NETWORK: "sepolia" + COMPILE_ETH_CONTRACTS_WHEN_DEPLOYING: "no-compile" + run: | + make deploy-eth-transfer-limit + + - name: Deploy azero contracts + shell: bash + env: + AZERO_ENV: "testnet" + COMPILE_AZERO_CONTRACTS_WHEN_DEPLOYING: "no-compile" + run: | + make deploy-azero-docker + + - name: Setup eth contracts + shell: bash + env: + SEPOLIA_MNEMONIC: ${{ secrets.DEVENV_TESTNET_SEPOLIA_KEY }} + SEPOLIA_ACCOUNT_NUMBER: ${{ secrets.DEVENV_TESTNET_SEPOLIA_ACCOUNT_NUMBER }} + SEPOLIA_TOKEN_CONFIG_PATH: "../cfg/tokens_testnet.json" + NETWORK: "sepolia" + COMPILE_ETH_CONTRACTS_WHEN_SETUP: "no-compile" + run: | + make setup-eth + + - name: Setup azero contracts + shell: bash + env: + AZERO_ENV: "testnet" + COMPILE_AZERO_CONTRACTS_WHEN_SETUP: "no-compile" + run: | + make setup-azero-docker + + - uses: actions/upload-artifact@v4 + with: + name: eth-deployed-contracts + if-no-files-found: error + retention-days: 1 + path: | + eth/addresses.json + eth/block_latest.json + + - uses: actions/upload-artifact@v4 + with: + name: azero-deployed-contracts + if-no-files-found: error + retention-days: 1 + path: | + azero/addresses.json + azero/block_latest.json + + upload-contract-addresses: name: Upload contract addresses to S3 + if: ${{ inputs.deploy-contracts }} runs-on: [self-hosted, Linux, X64, small] needs: [deploy-contracts] steps: diff --git a/.github/workflows/on-master-branch-commit.yml b/.github/workflows/on-master-branch-commit.yml index 6f267479..2fd9a5ac 100644 --- a/.github/workflows/on-master-branch-commit.yml +++ b/.github/workflows/on-master-branch-commit.yml @@ -15,7 +15,7 @@ jobs: compile-contracts-and-deploy-to-devenv: needs: [check-vars-and-secrets] name: Compile contracts and deploy to devenv - uses: ./.github/workflows/contracts-compile-and-deploy-to-devenv.yml + uses: ./.github/workflows/contracts-compile-and-deploy-to-testnet.yml secrets: inherit test-azero-contracts: @@ -70,4 +70,4 @@ jobs: with: notify-on: "failure" env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEV_ONDUTY }} \ No newline at end of file + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEV_ONDUTY }} diff --git a/Makefile b/Makefile index 92aa6b6f..9cb605e4 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,10 @@ AZERO_ENV ?= dev DOCKER_RELAYER_NAME ?= most-relayer DOCKER_RELAYER_COPY_ADDRESSES ?= copy DOCKER_RELAYER_COMPILE_CONTRACTS ?= compile +COMPILE_ETH_CONTRACTS_WHEN_DEPLOYING ?= compile +COMPILE_AZERO_CONTRACTS_WHEN_DEPLOYING ?= compile +COMPILE_ETH_CONTRACTS_WHEN_SETUP ?= compile +COMPILE_AZERO_CONTRACTS_WHEN_SETUP ?= compile DOCKER_SIGNER_NAME ?= most-signer L2 ?= false @@ -97,13 +101,17 @@ compile-eth: eth-deps .PHONY: deploy-eth deploy-eth: # Deploy eth contracts +ifeq ($(COMPILE_ETH_CONTRACTS_WHEN_DEPLOYING),compile) deploy-eth: compile-eth +endif cd eth && \ npx hardhat run --network $(NETWORK) scripts/0_deploy_bridge_contracts.js .PHONY: deploy-eth-transfer-limit deploy-eth-transfer-limit: # Deploy TransferLimit eth contract +ifeq ($(COMPILE_ETH_CONTRACTS_WHEN_DEPLOYING),compile) deploy-eth-transfer-limit: compile-eth +endif cd eth && \ npx hardhat run --network $(NETWORK) scripts/deploy_transfer_limit.js @@ -125,7 +133,9 @@ verify-eth: .PHONY: setup-eth setup-eth: # Setup eth contracts +ifeq ($(COMPILE_ETH_CONTRACTS_WHEN_SETUP),compile) setup-eth: compile-eth +endif cd eth && \ npx hardhat run --network $(NETWORK) scripts/1_setup_bridge_contracts.js @@ -165,12 +175,16 @@ print-azero-codehashes: compile-azero-docker .PHONY: deploy-azero-docker deploy-azero-docker: # Deploy azero contracts compiling in docker +ifeq ($(COMPILE_AZERO_CONTRACTS_WHEN_DEPLOYING),compile) deploy-azero-docker: azero-deps compile-azero-docker typechain-azero +endif cd azero && AZERO_ENV=$(AZERO_ENV) npm run deploy .PHONY: setup-azero-docker setup-azero-docker: # Setup azero contracts compiling in docker +ifeq ($(COMPILE_AZERO_CONTRACTS_WHEN_SETUP),compile) setup-azero-docker: azero-deps compile-azero-docker +endif cd azero && AZERO_ENV=$(AZERO_ENV) npm run setup .PHONY: azero-deps @@ -200,7 +214,7 @@ compile-azero: azero-deps make compile-azero-single-contract CONTRACT_DIR=gas-price-oracle/contract CONTRACT_NAME=oracle cd azero && cp external_artifacts/wrapped_azero.contract artifacts/ cd azero && cp external_artifacts/wrapped_azero.json artifacts/ - cd azero && cp external_artifacts/wrapped_azero.wasm artifacts/ + cd azero && cp external_artifacts/wrapped_azero.wasm artifacts/14 .PHONY: typechain-azero typechain-azero: # Generate typechain typings for azero contracts @@ -209,7 +223,9 @@ typechain-azero: .PHONY: deploy-azero deploy-azero: # Deploy azero contracts +ifeq ($(COMPILE_AZERO_CONTRACTS_WHEN_DEPLOYING),compile) deploy-azero: compile-azero typechain-azero +endif cd azero && AZERO_ENV=$(AZERO_ENV) npm run deploy .PHONY: upload-azero @@ -219,7 +235,9 @@ upload-azero: compile-azero-docker typechain-azero .PHONY: setup-azero setup-azero: # Setup azero contracts +ifeq ($(COMPILE_AZERO_CONTRACTS_WHEN_SETUP),compile) setup-azero: compile-azero typechain-azero +endif cd azero && AZERO_ENV=$(AZERO_ENV) npm run setup .PHONY: deploy @@ -457,3 +475,13 @@ build-docker-signer: cd relayer && cargo build -p signer --release cp relayer/target/release/signer relayer/signer_docker cd relayer/signer_docker && docker build -t $(DOCKER_SIGNER_NAME) . + +.PHONY: get-latest-eth-block +get-latest-eth-block: # Get latest eth block +get-latest-eth-block: eth-deps + cd eth && npx hardhat run --network $(NETWORK) scripts/get_latest_block.js + +.PHONY: get-latest-azero-block +get-latest-azero-block: # Get latest eth block +get-latest-azero-block: azero-deps + cd azero && AZERO_ENV=$(AZERO_ENV) npm run get-latest-block \ No newline at end of file diff --git a/eth/hardhat.config.js b/eth/hardhat.config.js index eb25f88a..4fc31563 100644 --- a/eth/hardhat.config.js +++ b/eth/hardhat.config.js @@ -44,7 +44,7 @@ var config = { }, gas: 25e6, // Gas limit gasPrice: 20e9, - dev: true, // whether to deploys wrapped tokens or not + dev: true, deploymentConfig: { guardianIds: [ "0x05501355922a6529670DB49158676D98D6c34245", @@ -106,9 +106,9 @@ if (SEPOLIA_MNEMONIC || SEPOLIA_PRIVATE_KEY) { mnemonic: SEPOLIA_MNEMONIC, } : [SEPOLIA_PRIVATE_KEY], - gasPrice: 10e9, // 10 Gwei; it's set to have an upper bound for contract deployment costs + gasPrice: 20e9, // 20 Gwei timeout: 20000, // 20s; if gas prices are higher than 20 Gwei, any tx would likely - // become stuck in the mempool, hence we need a timeout for a deployment script to finish + // stuck in the mempool, hence we need a timeout deploymentConfig: { guardianIds: [ typeof SEPOLIA_ACCOUNT_NUMBER == "undefined" ||