From 6ba46565a72a7dabb159d74963d7abc525fb6486 Mon Sep 17 00:00:00 2001 From: minghinmatthewlam Date: Tue, 5 Mar 2024 14:00:35 -0800 Subject: [PATCH] Adding deploy script for TeleporterRegistry (#323) --- .github/workflows/release.yml | 10 ++-- README.md | 30 +++++----- scripts/deploy_registry.sh | 106 ++++++++++++++++++++++++++++++++++ scripts/deploy_teleporter.sh | 22 ++++--- 4 files changed, 144 insertions(+), 24 deletions(-) create mode 100755 scripts/deploy_registry.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8799505af..46abc40a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,12 +17,13 @@ jobs: deployer_addr_fn: TeleporterMessenger_Deployer_Address_${{ github.ref_name }}.txt contract_addr_fn: TeleporterMessenger_Contract_Address_${{ github.ref_name }}.txt teleporter_messenger_bytecode_fn: TeleporterMessenger_Bytecode_${{ github.ref_name }}.txt + teleporter_registry_bytecode_fn: TeleporterRegistry_Bytecode_${{ github.ref_name }}.txt steps: - name: Check out the repo uses: actions/checkout@v4 with: submodules: recursive - + - name: Set Go version run: | source ./scripts/versions.sh @@ -31,11 +32,11 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: ${{ env.GO_VERSION }} + go-version: ${{ env.GO_VERSION }} - name: Install Foundry run: ./scripts/install_foundry.sh - + - name: Build Contracts run: | export PATH=$PATH:$HOME/.foundry/bin @@ -58,6 +59,7 @@ jobs: mv UniversalTeleporterDeployerAddress.txt ${{ env.deployer_addr_fn }} mv UniversalTeleporterMessengerContractAddress.txt ${{ env.contract_addr_fn }} mv contracts/out/TeleporterMessenger.sol/TeleporterMessenger.bin ${{ env.teleporter_messenger_bytecode_fn }} + mv contracts/out/TeleporterRegistry.sol/TeleporterRegistry.bin ${{ env.teleporter_registry_bytecode_fn }} - name: Create release uses: softprops/action-gh-release@v1 @@ -71,4 +73,4 @@ jobs: ${{ env.deployer_addr_fn }} ${{ env.contract_addr_fn }} ${{ env.teleporter_messenger_bytecode_fn }} - \ No newline at end of file + ${{ env.teleporter_registry_bytecode_fn}} diff --git a/README.md b/README.md index 6e79c0214..eb467ff3d 100644 --- a/README.md +++ b/README.md @@ -178,14 +178,17 @@ For more information on the registry and how to integrate with Teleporter dApps, From the root of the repo, the TeleporterMessenger contract can be deployed by calling ```bash -./scripts/deploy_teleporter.sh +./scripts/deploy_teleporter.sh --version --rpc-url [OPTIONS] ``` -Options for this script: +Required arguments: -- `--version ` Required. Specify the release version to deploy. These will all be of the form `v1.X.0`. Each Teleporter version can only send and receive messages from the **same** Teleporter version on another chain. You can see a list of released versions at https://github.com/ava-labs/teleporter/releases. -- `--rpc-url ` Required. Specify the rpc url of the node to use. -- `--fund-deployer ` Optional. Funds the deployer address with the account held by `` +- `--version ` Specify the release version to deploy. These will all be of the form `v1.X.0`. Each Teleporter version can only send and receive messages from the **same** Teleporter version on another chain. You can see a list of released versions at https://github.com/ava-labs/teleporter/releases. +- `--rpc-url ` Specify the rpc url of the node to use. + +Options: + +- `--private-key ` Funds the deployer address with the account held by `` To ensure that Teleporter can be deployed to the same address on every EVM based chain, it uses [Nick's Method](https://yamenmerhi.medium.com/nicks-method-ethereum-keyless-execution-168a6659479c) to deploy from a static deployer address. Teleporter costs exactly `10eth` in the subnet's native gas token to deploy, which must be sent to the deployer address. @@ -193,18 +196,19 @@ To ensure that Teleporter can be deployed to the same address on every EVM based ## Deploy TeleporterRegistry to a Subnet -There should only be one canonical `TeleporterRegistry` deployed for each chain, but if one does not exist, it is recommended to deploy the registry so Teleporter dApps can always use the most recent Teleporter version available. Since the registry does not need to be deployed to the same address on every chain, it does not need a Nick's method deployment, and can be deployed using `forge create` from the root of the repo: +There should only be one canonical `TeleporterRegistry` deployed for each chain, but if one does not exist, it is recommended to deploy the registry so Teleporter dApps can always use the most recent Teleporter version available. The registry does not need to be deployed to the same address on every chain, and therefore does not need a Nick's method transaction. To deploy, run the following command from the root of the repository: ```bash -cd contracts -forge create --private-key $user_private_key \ - --rpc-url $subnet_rpc_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[($teleporter_version,$teleporter_contract_address)]" +./scripts/deploy_registry.sh --version --rpc-url --private-key [OPTIONS] ``` -- `$user_private_key`: private key of the user deploying the contract. -- `$subnet_rpc_url`: RPC URL of the subnet where the contract will be deployed. -- `$teleporter_version`: version number of the `TeleporterMessenger` contract being registered on this blockchain. For example, if it's the first `TeleporterMessenger` contract being registered, the version number would be 1. -- `$teleporter_contract_address`: address of the `TeleporterMessenger` contract being registered on this blockchain. +Required arguments: + +- `--version ` Specify the release version to deploy. These will all be of the form `v1.X.0`. +- `--rpc-url ` Specify the rpc url of the node to use. +- `--private-key ` Funds the deployer address with the account held by `` + +`deploy_registry.sh` will deploy a new `TeleporterRegistry` contract for the intended release version, and will also have the corresponding `TeleporterMessenger` contract registered as the initial protocol version. ## ABI Bindings diff --git a/scripts/deploy_registry.sh b/scripts/deploy_registry.sh new file mode 100755 index 000000000..dc69b70f1 --- /dev/null +++ b/scripts/deploy_registry.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# Copyright (C) 2023, Ava Labs, Inc. All rights reserved. +# See the file LICENSE for licensing terms. + +set -e + +TELEPORTER_PATH=$( + cd "$(dirname "${BASH_SOURCE[0]}")" + cd .. && pwd +) + +# Check that foundry (specifically cast) is installed. +if ! command -v cast &> /dev/null; then + echo "cast not found. You can install by calling $TELEPORTER_PATH/scripts/install_foundry.sh" && exit 1 +fi + +# Check that jq is installed. +if ! command -v jq &> /dev/null; then + echo "jq not found. It is required to be installed before proceeding." && exit 1 +fi + +function printHelp() { + echo "Usage: ./scripts/deploy_registry.sh --version --rpc-url --private-key [OPTIONS]" + echo "" + echo "Deploys a selected TeleporterRegistry contract to the specified chain" + echo "For a list of releases, go to https://github.com/ava-labs/teleporter/releases" + printUsage +} + +function printUsage() { + cat << EOF +Arguments: + --version Specify the release version to deploy. + --rpc-url Specify the rpc url of the node to use + --private-key Private key of account to deploy TeleporterRegistry +Options: + --help Print this help message +EOF +} + +teleporter_version= +user_private_key= +rpc_url= + +while [ $# -gt 0 ]; do + case "$1" in + --version) + if [[ $2 != --* ]]; then + teleporter_version=$2 + else + echo "Invalid Teleporter version $2" && printHelp && exit 1 + fi + shift;; + --rpc-url) + if [[ $2 != --* ]]; then + rpc_url=$2 + else + echo "Invalid rpc url $2" && printHelp && exit 1 + fi + shift;; + --private-key) + if [[ $2 != --* ]]; then + user_private_key=$2 + else + echo "Invalid private key $2" && printHelp && exit 1 + fi + shift;; + --help) + printHelp && exit 0 ;; + *) + echo "Invalid option: $1" && printHelp && exit 1;; + esac + shift +done + +if [[ $teleporter_version == "" || $rpc_url == "" || $user_private_key == "" ]]; then + echo "Invalid usage. Missing required command line arguments." + printHelp && exit 1 +fi + +teleporter_registry_bytecode=$(curl -sL https://github.com/ava-labs/teleporter/releases/download/$teleporter_version/TeleporterRegistry_Bytecode_$teleporter_version.txt) +teleporter_contract_address=$(curl -sL https://github.com/ava-labs/teleporter/releases/download/$teleporter_version/TeleporterMessenger_Contract_Address_$teleporter_version.txt) +if [ "$teleporter_registry_bytecode" == "Not Found" ]; then + echo "Error: TeleporterRegistry $teleporter_version byte code not found." + exit 1 +fi + +# Encode the constructor arguments +# TODO: Update to iterate through all release major versions once we have multiple Teleporter versions. +constructor_encoding=$(cast abi-encode "constructor((uint256,address)[])" "[(1, $teleporter_contract_address)]") + +# remove the 0x prefix +constructor_encoding=${constructor_encoding:2} + +# Deploy the TeleporterRegistry contract +deployment_result=$(cast send --private-key $user_private_key --rpc-url $rpc_url --json --create $teleporter_registry_bytecode$constructor_encoding) +teleporter_registry_address=$(echo $deployment_result | jq -r .contractAddress) +deployment_status=$(echo $deployment_result | jq -r .status) +deployment_tx_id=$(echo $deployment_result | jq -r .transactionHash) +if [[ $deployment_status != "0x1" ]]; then + echo "TeleporterRegistry deployment transaction failed. Transaction ID: $deployment_tx_id" + exit 1 +fi +echo "Success! TeleporterRegistry deployed to $teleporter_registry_address in transaction $deployment_tx_id." + +exit 0 diff --git a/scripts/deploy_teleporter.sh b/scripts/deploy_teleporter.sh index 37cdb28e1..f96564bec 100755 --- a/scripts/deploy_teleporter.sh +++ b/scripts/deploy_teleporter.sh @@ -20,18 +20,22 @@ if ! command -v jq &> /dev/null; then fi function printHelp() { - echo "Usage: ./scripts/deploy_teleporter.sh [OPTIONS]" + echo "Usage: ./scripts/deploy_teleporter.sh --version --rpc-url [OPTIONS]" + echo "" echo "Deploys a selected TeleporterMessenger contract to the specified chain" echo "For a list of releases, go to https://github.com/ava-labs/teleporter/releases" printUsage } function printUsage() { - echo "Options:" - echo " --version Required. Specify the release version to deploy" - echo " --rpc-url Required. Specify the rpc url of the node to use" - echo " --private-key Optional. Private key of account to use to fund the Teleporter deployer address, if necessary." - echo " --help Print this help message" + cat << EOF +Arguments: + --version Specify the release version to deploy + --rpc-url Specify the rpc url of the node to use +Options: + --private-key Private key of account to use to fund the Teleporter deployer address, if necessary. + --help Print this help message +EOF } teleporter_version= @@ -44,7 +48,7 @@ while [ $# -gt 0 ]; do if [[ $2 != --* ]]; then teleporter_version=$2 else - echo "Invalid teleporter version $2" && printHelp && exit 1 + echo "Invalid Teleporter version $2" && printHelp && exit 1 fi shift;; --rpc-url) @@ -86,6 +90,10 @@ teleporter_deployer_address=$(curl -sL https://github.com/ava-labs/teleporter/re echo "TeleporterMessenger $teleporter_version deployer address: $teleporter_deployer_address" teleporter_deploy_tx=$(curl -sL https://github.com/ava-labs/teleporter/releases/download/$teleporter_version/TeleporterMessenger_Deployment_Transaction_$teleporter_version.txt) teleporter_messenger_bytecode=$(curl -sL https://github.com/ava-labs/teleporter/releases/download/$teleporter_version/TeleporterMessenger_Bytecode_$teleporter_version.txt) +if [ "$teleporter_contract_address" == "Not Found" ]; then + echo "Error: TeleporterMessenger $teleporter_version contract address not found." + exit 1 +fi # Check if this TeleporterMessenger version has already been deployed on this chain. teleporter_contract_code=$(cast codesize $teleporter_contract_address --rpc-url $rpc_url)