Skip to content

Commit

Permalink
[NoStory] Parameterize precomputeRemoteMessengerAddress.py (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbere authored Nov 17, 2022
1 parent e868248 commit d415cd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The contracts are deployed using [Forge Scripts](https://book.getfoundry.sh/tuto
- `BURN_LIMIT_PER_TRANSACTION`

In addition, to link the remote bridge, one of two steps needs to be followed:
- Add the `REMOTE_TOKEN_MESSENGER_DEPLOYER` address to your [env](.env) file and run [scripts/precomputeRemoteMessengerAddress.py](/scripts/precomputeRemoteMessengerAddress.py) to automatically add the `REMOTE_TOKEN_MESSENGER_ADDRESS` to the .env file
- Add the `REMOTE_TOKEN_MESSENGER_DEPLOYER` address to your [env](.env) file and run [scripts/precomputeRemoteMessengerAddress.py](/scripts/precomputeRemoteMessengerAddress.py) with argument `--REMOTE_RPC_URL` for the remote chain, which will automatically add the `REMOTE_TOKEN_MESSENGER_ADDRESS` to the .env file
- Manually add the `REMOTE_TOKEN_MESSENGER_ADDRESS` to your .env file.

2. Run `make simulate RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run. *Note: Use address from one of the private keys (used for deploying) above as `sender`. It is used to deploy the shared libraries that contracts use*
Expand Down
23 changes: 11 additions & 12 deletions scripts/precomputeRemoteMessengerAddress.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from dotenv import load_dotenv
from web3 import Web3

import argparse
import os
import rlp

rpc_urls = {
'0': "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", # Ethereum
'1': "https://api.avax-test.network/ext/bc/C/rpc" # Avalanche
}

def compute_address(sender, nonce):
"""
Computes the address for a deployed contract given the address
Expand All @@ -18,15 +14,14 @@ def compute_address(sender, nonce):
contract_address = Web3.toHex(Web3.keccak(rlp.encode([sender_as_bytes, nonce])))[-40:]
return contract_address

def precompute_remote_token_messenger_address():
def precompute_remote_token_messenger_address(remote_rpc_url):
"""
Computes expected address for remote token messenger contract and writes to
the .env file. Requires REMOTE_DOMAIN and REMOTE_TOKEN_MESSENGER_DEPLOYER
to be defined in the .env file.
Computes expected address for remote token messenger contract on the
input remote_rpc_url and writes to the .env file. Requires
REMOTE_TOKEN_MESSENGER_DEPLOYER to be defined in the .env file.
"""
remote_domain = os.getenv("REMOTE_DOMAIN")
remote_token_messenger_deployer = os.getenv(f"REMOTE_TOKEN_MESSENGER_DEPLOYER")
remote_domain_node = Web3(Web3.HTTPProvider(rpc_urls[remote_domain]))
remote_domain_node = Web3(Web3.HTTPProvider(remote_rpc_url))

remote_token_messenger_deployer_nonce = remote_domain_node.eth.get_transaction_count(remote_token_messenger_deployer)
remote_token_messenger_address = compute_address(remote_token_messenger_deployer, remote_token_messenger_deployer_nonce)
Expand All @@ -35,4 +30,8 @@ def precompute_remote_token_messenger_address():
env_file.write(f"REMOTE_TOKEN_MESSENGER_ADDRESS=0x{remote_token_messenger_address}\n")

load_dotenv()
precompute_remote_token_messenger_address()
parser = argparse.ArgumentParser()
parser.add_argument("--REMOTE_RPC_URL", required=True, help="RPC URL for the remote chain")
args = parser.parse_args()
remote_rpc_url = args.REMOTE_RPC_URL
precompute_remote_token_messenger_address(remote_rpc_url)

0 comments on commit d415cd0

Please sign in to comment.