Skip to content

Commit

Permalink
Adding deploy script for TeleporterRegistry (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
minghinmatthewlam authored Mar 5, 2024
1 parent 4a6aad7 commit 6ba4656
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 24 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -71,4 +73,4 @@ jobs:
${{ env.deployer_addr_fn }}
${{ env.contract_addr_fn }}
${{ env.teleporter_messenger_bytecode_fn }}
${{ env.teleporter_registry_bytecode_fn}}
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,37 @@ 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 <options>
./scripts/deploy_teleporter.sh --version <version> --rpc-url <url> [OPTIONS]
```
Options for this script:
Required arguments:
- `--version <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 <url>` Required. Specify the rpc url of the node to use.
- `--fund-deployer <private_key>` Optional. Funds the deployer address with the account held by `<private_key>`
- `--version <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 <url>` Specify the rpc url of the node to use.
Options:
- `--private-key <private_key>` Funds the deployer address with the account held by `<private_key>`
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.
`deploy_teleporter.sh` will send the necessary native tokens to the deployer address if it is provided with a private key for an account with sufficient funds. Alternatively, the deployer address can be funded externally. The deployer address for each version can be found by looking up the appropriate version at https://github.com/ava-labs/teleporter/releases and downloading `TeleporterMessenger_Deployer_Address_<VERSION>.txt`.
## 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 <version> --rpc-url <url> --private-key <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 <version>` Specify the release version to deploy. These will all be of the form `v1.X.0`.
- `--rpc-url <url>` Specify the rpc url of the node to use.
- `--private-key <private_key>` Funds the deployer address with the account held by `<private_key>`
`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
Expand Down
106 changes: 106 additions & 0 deletions scripts/deploy_registry.sh
Original file line number Diff line number Diff line change
@@ -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 <version> --rpc-url <url> --private-key <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 <version> Specify the release version to deploy.
--rpc-url <url> Specify the rpc url of the node to use
--private-key <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
22 changes: 15 additions & 7 deletions scripts/deploy_teleporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version> --rpc-url <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 <version> Required. Specify the release version to deploy"
echo " --rpc-url <url> Required. Specify the rpc url of the node to use"
echo " --private-key <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 <version> Specify the release version to deploy
--rpc-url <url> Specify the rpc url of the node to use
Options:
--private-key <private_key> Private key of account to use to fund the Teleporter deployer address, if necessary.
--help Print this help message
EOF
}

teleporter_version=
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6ba4656

Please sign in to comment.