Skip to content

Commit

Permalink
Stable 7722 v2 deployment scripts (circlefin#43)
Browse files Browse the repository at this point in the history
# Overview

Updated deployment scripts and process documentation for V2 contracts as
[documented](https://docs.google.com/document/d/1ayFWGNVmaO6jlLwgZsa0Yk-490CTBdiFASuY4jJzkE0/edit?usp=sharing).

# Changes

 - Added new scripts for deploying and configuring the V2 contracts.
 - Added tests for the new scripts.
 - Updated the readme and Makefile for V2 deployment process.
 
 # Tests

 - Added new script tests.
 - Manually followed the deployment process locally.

# Review

- Help take a look to make sure all the env vars make sense. (Especially
regarding all the owners/pks.)
 - Optionally, run through the process locally.
  • Loading branch information
epoon-circle authored and grantmike committed Jan 23, 2025
1 parent 6c1cda4 commit 3e82d1f
Show file tree
Hide file tree
Showing 19 changed files with 1,433 additions and 988 deletions.
46 changes: 26 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,41 @@ simulate-deploy:
deploy:
forge script scripts/v1/deploy.s.sol:DeployScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

simulate-deploy-proxy-factory:
forge script scripts/DeployProxyFactory.s.sol:DeployProxyFactoryScript --rpc-url ${RPC_URL} --sender ${SENDER}
simulate-deploy-implementations-v2:
forge script scripts/v2/DeployImplementationsV2.s.sol:DeployImplementationsV2Script --rpc-url ${RPC_URL} --sender ${SENDER}

deploy-proxy-factory:
forge script scripts/DeployProxyFactory.s.sol:DeployProxyFactoryScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast
deploy-implementations-v2:
forge script scripts/v2/DeployImplementationsV2.s.sol:DeployImplementationsV2Script --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

simulate-deployv2:
forge script scripts/v2/1_deploy.s.sol:DeployV2Script --rpc-url ${RPC_URL} --sender ${SENDER}
simulate-deploy-create2-factory:
forge script scripts/DeployCreate2Factory.s.sol:DeployCreate2FactoryScript --rpc-url ${RPC_URL} --sender ${SENDER}

deployv2:
forge script scripts/v2/1_deploy.s.sol:DeployV2Script --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast
deploy-create2-factory:
forge script scripts/DeployCreate2Factory.s.sol:DeployCreate2FactoryScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

simulate-setup-second-attester:
forge script scripts/v2/2_setupSecondAttester.s.sol:SetupSecondAttesterScript --rpc-url ${RPC_URL} --sender ${SENDER}
simulate-deploy-proxies-v2:
forge script scripts/v2/DeployProxiesV2.s.sol:DeployProxiesV2Script --rpc-url ${RPC_URL} --sender ${SENDER}

setup-second-attester:
forge script scripts/v2/2_setupSecondAttester.s.sol:SetupSecondAttesterScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast
deploy-proxies-v2:
forge script scripts/v2/DeployProxiesV2.s.sol:DeployProxiesV2Script --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

simulate-setup-remote-resources:
forge script scripts/v2/3_setupRemoteResources.s.sol:SetupRemoteResourcesScript --rpc-url ${RPC_URL} --sender ${SENDER}
simulate-setup-remote-resources-v2:
forge script scripts/v2/SetupRemoteResourcesV2.s.sol:SetupRemoteResourcesV2Script --rpc-url ${RPC_URL} --sender ${SENDER}

setup-remote-resources:
forge script scripts/v2/3_setupRemoteResources.s.sol:SetupRemoteResourcesScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast
setup-remote-resources-v2:
forge script scripts/v2/SetupRemoteResourcesV2.s.sol:SetupRemoteResourcesV2Script --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

simulate-rotate-keys:
forge script scripts/v2/4_rotateKeys.s.sol:RotateKeysScript --rpc-url ${RPC_URL} --sender ${SENDER}
simulate-rotate-keys-v2:
forge script scripts/v2/RotateKeysV2.s.sol:RotateKeysV2Script --rpc-url ${RPC_URL} --sender ${SENDER}

rotate-keys:
forge script scripts/v2/4_rotateKeys.s.sol:RotateKeysScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast
rotate-keys-v2:
forge script scripts/v2/RotateKeysV2.s.sol:RotateKeysV2Script --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

simulate-deploy-address-utils-external:
forge script scripts/v2/DeployAddressUtilsExternal.s.sol:DeployAddressUtilsExternalScript --rpc-url ${RPC_URL} --sender ${SENDER}

deploy-address-utils-external:
forge script scripts/v2/DeployAddressUtilsExternal.s.sol:DeployAddressUtilsExternalScript --rpc-url ${RPC_URL} --sender ${SENDER} --broadcast

anvil:
docker rm -f anvil || true
Expand Down
175 changes: 93 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,117 +96,128 @@ The contracts are deployed using [Forge Scripts](https://book.getfoundry.sh/tuto

### V2

#### Create2Factory

Deploy Create2Factory first if not yet deployed.

<ol type="a">
<li>

Add the below environment variable to your [env](.env) file:
- `CREATE2_FACTORY_DEPLOYER_KEY`</li>
<li>

Run `make simulate-deploy-create2-factory RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run.</li>
<li>

Run
1. Add the environment variable `CREATE2_FACTORY_DEPLOYER_KEY` to your [env](.env) file.
2. Run `make simulate-deploy-create2-factory RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run.
3. Run
```make deploy-create2-factory RPC_URL=<RPC_URL> SENDER=<SENDER>```
to deploy the Create2Factory.</li>
</ol>
to deploy the Create2Factory.

The contracts are deployed via `CREATE2` through Create2Factory. Follow the below steps to deploy the contracts:
#### V2 Implementation Contracts

1. Replace the environment variables in your [env](.env) file with the following:
Deploy the implementation contracts.

- `MESSAGE_TRANSMITTER_DEPLOYER_KEY`
- `TOKEN_MESSENGER_DEPLOYER_KEY`
- `TOKEN_MINTER_DEPLOYER_KEY`
- `TOKEN_CONTROLLER_DEPLOYER_KEY`
- `ATTESTER_ADDRESS`
- `USDC_CONTRACT_ADDRESS`
- `REMOTE_USDC_CONTRACT_ADDRESS`
- `MESSAGE_TRANSMITTER_PAUSER_ADDRESS`
- `TOKEN_MINTER_PAUSER_ADDRESS`
- `MESSAGE_TRANSMITTER_RESCUER_ADDRESS`
- `TOKEN_MESSENGER_RESCUER_ADDRESS`
- `TOKEN_MINTER_RESCUER_ADDRESS`
- `TOKEN_CONTROLLER_ADDRESS`
- `DOMAIN`
- `REMOTE_DOMAIN`
- `BURN_LIMIT_PER_MESSAGE`
- `CREATE2_FACTORY_ADDRESS`
1. Add the following [env](.env) variables

- `CREATE2_FACTORY_CONTRACT_ADDRESS`
- `TOKEN_CONTROLLER_ADDRESS`
- `DOMAIN`
- `MESSAGE_BODY_VERSION`
- `VERSION`
- `IMPLEMENTATION_DEPLOYER_PRIVATE_KEY`

2. Run `make simulate-deploy-implementations-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run.

In addition, to link the remote bridge, one of two steps needs to be followed:
3. Run
```make deploy-implementations-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>```
to deploy MessageTransmitterV2, TokenMinterV2, and TokenMessengerV2.

- 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.
#### V2 Proxies

2. Run `make simulate-deployv2 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_
3. Run `make deployv2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to deploy the contracts
The proxies are deployed via `CREATE2` through Create2Factory. The scripts assumes the remote chains are EVM compatible and predicts that remote contracts will be deployed at the same addresses. Follow the below steps to deploy the contracts:

1. Replace the environment variables in your [env](.env) file with the following:

Note: `REMOTE_DOMAINS`, `REMOTE_USDC_CONTRACT_ADDRESSES`, and `REMOTE_TOKEN_MESSENGER_V2_ADDRESSES` must all correspond 1:1:1 in order.

- `USDC_CONTRACT_ADDRESS`
- `TOKEN_CONTROLLER_ADDRESS`
- `REMOTE_DOMAINS`
- `REMOTE_USDC_CONTRACT_ADDRESSES`
- `REMOTE_TOKEN_MESSENGER_V2_ADDRESSES`
- `CREATE2_FACTORY_CONTRACT_ADDRESS`

- `MESSAGE_TRANSMITTER_V2_IMPLEMENTATION_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_OWNER_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_PAUSER_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_RESCUER_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_ATTESTER_MANAGER_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_ATTESTER_1_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_ATTESTER_2_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_PROXY_ADMIN_ADDRESS`

- `TOKEN_MINTER_V2_CONTRACT_ADDRESS`
- `TOKEN_MINTER_V2_PAUSER_ADDRESS`
- `TOKEN_MINTER_V2_RESCUER_ADDRESS`

- `TOKEN_MESSENGER_V2_IMPLEMENTATION_ADDRESS`
- `TOKEN_MESSENGER_V2_OWNER_ADDRESS`
- `TOKEN_MESSENGER_V2_RESCUER_ADDRESS`
- `TOKEN_MESSENGER_V2_FEE_RECIPIENT_ADDRESS`
- `TOKEN_MESSENGER_V2_DENYLISTER_ADDRESS`
- `TOKEN_MESSENGER_V2_PROXY_ADMIN_ADDRESS`

- `DOMAIN`
- `BURN_LIMIT_PER_MESSAGE`

4. Replace the environment variables in your [env](.env) file with:
- `CREATE2_FACTORY_OWNER_KEY`
- `TOKEN_MINTER_V2_DEPLOYER_KEY`
- `TOKEN_CONTROLLER_KEY`

- `MESSAGE_TRANSMITTER_CONTRACT_ADDRESS`
- `MESSAGE_TRANSMITTER_DEPLOYER_KEY`
- `NEW_ATTESTER_MANAGER_ADDRESS`
- `SECOND_ATTESTER_ADDRESS`
2. Run `make simulate-deploy-proxies-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run.

5. Run `make simulate-setup-second-attester RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run of setting up the second attester.
3. Run `make deploy-proxies-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to deploy the contracts

6. Run `make setup-second-attester RPC_URL=<RPC_URL> SENDER=<SENDER>` to setup the second attester.
4. ONLY perform steps 5-7 for additional remote resources NOT already configured above.

7. Replace the environment variables in your [env](.env) file with the following. We'll just add one remote resource (e.g. adding remote token messenger and remote usdc contract addresses) at a time, so just pick any and then repeat these steps. This will need to be repeated for each remote chain:
5. Replace the environment variables in your [env](.env) file with the following. We'll just add one remote resource (e.g. adding remote token messenger and remote usdc contract addresses) at a time, so just pick any and then repeat these steps. This will need to be repeated for each remote chain:

- `TOKEN_MESSENGER_DEPLOYER_KEY`
- `TOKEN_MESSENGER_V2_OWNER_KEY`
- `TOKEN_CONTROLLER_KEY`
- `REMOTE_TOKEN_MESSENGER_ADDRESS`
- `TOKEN_MINTER_CONTRACT_ADDRESS`
- `TOKEN_MESSENGER_CONTRACT_ADDRESS`
- `REMOTE_USDC_CONTRACT_ADDRESS`
- `TOKEN_MESSENGER_V2_CONTRACT_ADDRESS`
- `TOKEN_MINTER_V2_CONTRACT_ADDRESS`
- `USDC_CONTRACT_ADDRESS`
- `REMOTE_USDC_CONTRACT_ADDRESS`
- `REMOTE_DOMAIN`

8. Run `make simulate-setup-remote-resources RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run of adding remote resources.
6. Run `make simulate-setup-remote-resources-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run of adding remote resources.

9. Run `make setup-remote-resources RPC_URL=<RPC_URL> SENDER=<SENDER>` to setup the remote resources.
7. Run `make setup-remote-resources-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to setup the remote resources.

10. Repeat steps 7-9 for all remote resources. This needs to be done for all existing remote chains at
contract setup except for the initial remote chain used in `1_deploy.s.sol`.
**[Remaining steps are only for mainnet]**

**[Only execute the following if replacing remote resources for an existing chain]**
8. Replace the environment variables in your [env](.env) file with:

- `MESSAGE_TRANSMITTER_V2_CONTRACT_ADDRESS`
- `TOKEN_MESSENGER_V2_CONTRACT_ADDRESS`
- `TOKEN_MINTER_V2_CONTRACT_ADDRESS`
- `MESSAGE_TRANSMITTER_V2_OWNER_KEY`
- `TOKEN_MESSENGER_V2_OWNER_KEY`
- `TOKEN_MINTER_V2_OWNER_KEY`
- `MESSAGE_TRANSMITTER_V2_NEW_OWNER_ADDRESS`
- `TOKEN_MESSENGER_V2_NEW_OWNER_ADDRESS`
- `TOKEN_MINTER_V2_NEW_OWNER_ADDRESS`
- `NEW_TOKEN_CONTROLLER_ADDRESS`

11. Replace the environment variables in your [env](.env) file with the following. We'll replace one set of remote resources for a given chain (e.g. changing the remote token messenger and remote usdc contract addresses) at a time so it will need to be repeated for each applicable chain.
- `TOKEN_MESSENGER_DEPLOYER_KEY`
- `TOKEN_CONTROLLER_KEY`
- `REMOTE_TOKEN_MESSENGER_ADDRESS`
- `REMOTE_TOKEN_MESSENGER_ADDRESS_DEPRECATED`
- `TOKEN_MINTER_CONTRACT_ADDRESS`
- `TOKEN_MESSENGER_CONTRACT_ADDRESS`
- `REMOTE_USDC_CONTRACT_ADDRESS`
- `REMOTE_USDC_CONTRACT_ADDRESS_DEPRECATED`
- `USDC_CONTRACT_ADDRESS`
- `REMOTE_DOMAIN`
12. Run `make simulate-replace-remote-resources RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run of replacing remote resources.
9. Run `make simulate-rotate-keys-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run of rotating the keys.

13. Run `make replace-remote-resources RPC_URL=<RPC_URL> SENDER=<SENDER>` to replace the remote resources.
10. Run `make rotate-keys-v2 RPC_URL=<RPC_URL> SENDER=<SENDER>` to rotate keys.

**[Remaining steps are only for mainnet]**
#### AddressUtilsExternal

14. Replace the environment variables in your [env](.env) file with:
Use Create2Factory to deploy the helper library to a deterministic address for easy integration.

- `MESSAGE_TRANSMITTER_CONTRACT_ADDRESS`
- `TOKEN_MESSENGER_CONTRACT_ADDRESS`
- `TOKEN_MINTER_CONTRACT_ADDRESS`
- `MESSAGE_TRANSMITTER_DEPLOYER_KEY`
- `TOKEN_MESSENGER_DEPLOYER_KEY`
- `TOKEN_MINTER_DEPLOYER_KEY`
- `MESSAGE_TRANSMITTER_NEW_OWNER_ADDRESS`
- `TOKEN_MESSENGER_NEW_OWNER_ADDRESS`
- `TOKEN_MINTER_NEW_OWNER_ADDRESS`
- `NEW_TOKEN_CONTROLLER_ADDRESS`
1. Set the following [env](.env) variables:

- `CREATE2_FACTORY_CONTRACT_ADDRESS`
- `CREATE2_FACTORY_OWNER_KEY`

15. Run `make simulate-rotate-keys RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run of rotating the keys.
2. Run `make simulate-deploy-address-utils-external RPC_URL=<RPC_URL> SENDER=<SENDER>` to perform a dry run.

16. Run `make rotate-keys RPC_URL=<RPC_URL> SENDER=<SENDER>` to rotate keys.
3. Run `make deploy-address-utils-external RPC_URL=<RPC_URL> SENDER=<SENDER>` to deploy.

## License

Expand Down
Loading

0 comments on commit 3e82d1f

Please sign in to comment.