Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve deployment instructions #413

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ $ forge snapshot
$ anvil
```

### Deploy using script
### Deploy

```shell
$ forge script script/<DeployScript>.s.sol:<DeployScript> --rpc-url <your_rpc_url> --private-key <your_private_key>
```

##### More detailed instructions

To view detailed instructions on how to deploy the contracts, please refer to the [Deployment Guide](./scripts/deploy/readme.md).

This guide covers all steps required to deploy the contracts, including environment setup, commands, and best practices.
lumtis marked this conversation as resolved.
Show resolved Hide resolved

### Cast

```shell
Expand Down
4 changes: 2 additions & 2 deletions v2/scripts/deploy/deterministic/DeployERC20Custody.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ contract DeployERC20Custody is Script {
address expectedImplAddress;
address expectedProxyAddress;

bytes32 implSalt = keccak256("ERC20Custody");
bytes32 proxySalt = keccak256("ERC20CustodyProxy");
bytes32 implSalt = keccak256("ERC20Custody-2");
lumtis marked this conversation as resolved.
Show resolved Hide resolved
bytes32 proxySalt = keccak256("ERC20CustodyProxy-2");

vm.startBroadcast();

Expand Down
4 changes: 2 additions & 2 deletions v2/scripts/deploy/deterministic/DeployGatewayEVM.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ contract DeployGatewayEVM is Script {
address expectedImplAddress;
address expectedProxyAddress;

bytes32 implSalt = keccak256("GatewayEVM");
bytes32 proxySalt = keccak256("GatewayEVMProxy");
bytes32 implSalt = keccak256("GatewayEVM-2");
lumtis marked this conversation as resolved.
Show resolved Hide resolved
bytes32 proxySalt = keccak256("GatewayEVMProxy-2");

vm.startBroadcast();

Expand Down
36 changes: 0 additions & 36 deletions v2/scripts/deploy/deterministic/readme.md

This file was deleted.

107 changes: 102 additions & 5 deletions v2/scripts/deploy/readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,107 @@
## Deployment scripts
# Deployment

Note: `.env` file should be set up and updated during deployments according to expected env variables in scripts, check `.env.sample` for example on how it should look like.
Currently, `.env.sample` is set with test env variables that can be used to test scripts locally with `anvil` using first account private key.
This directory contains script to deploy the protocol contracts on ZetaChain and connected chains.

To execute deployment script, following format is needed:
To execute a deployment script, the general format is:

```
forge script scripts/deploy/<Script>.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast
```
```

A `.env` file should be set up and updated during deployments according to expected env variables in scripts, check `.env.sample` for example on how it should look like.
Currently, `.env.sample` is set with test env variables that can be used to test scripts locally with `anvil` using first account private key.
lumtis marked this conversation as resolved.
Show resolved Hide resolved


## Deploying the protocol contracts on connected chains

The GatewayEVM and ERC20Custody contracts must be deploy to setup a new environment on a connected chains.
lumtis marked this conversation as resolved.
Show resolved Hide resolved

lumtis marked this conversation as resolved.
Show resolved Hide resolved
**GatewayEVM**

The following environment variable must be set in the `.env` file:
lumtis marked this conversation as resolved.
Show resolved Hide resolved

- `TSS_ADDRESS`: address of the TSS used on the network
- `GATEWAY_ADMIN_ADDRESS_EVM`: address of the admin
- `ZETA_ERC20_EVM`: address of the ZETA token on the network

Once setup, the contract can be deployed:

```
forge script scripts/deploy/deterministic/DeployGatewayEVM.s.sol \
--private-key <PRIVATE_KEY> \
--rpc-url <RPC_URL> \
--verify \
--etherscan-api-key <ETHERSCAN_API_KEY> \
--chain-id <CHAIN_ID> \
--broadcast
```

Note: `verify` and `etherscan-api-key` options are optional for the contract deployment itself.
lumtis marked this conversation as resolved.
Show resolved Hide resolved

**ERC20Custody**

In addition to the previous environment variables, the following environment variables must be set:

- `ERC20_CUSTODY_ADMIN_ADDRESS_EVM`: address of the admin
- `GATEWAY_PROXY_EVM`: address of the **proxy** gateway contract deployed in previous step

Once setup, the contract can be deployed:

```
forge script scripts/deploy/deterministic/DeployERC20Custody.s.sol \
--private-key <PRIVATE_KEY> \
--rpc-url <RPC_URL> \
--verify \
--etherscan-api-key <ETHERSCAN_API_KEY> \
--chain-id <CHAIN_ID> \
--broadcast
```

## Deploying the protocol contracts on ZetaChain

Since ZRC20s are deployed by the protocol, only the `GatewayZEVM` contract needs to be deployed manually on ZetaChain.

The following environment variable must be set in the `.env` file:
lumtis marked this conversation as resolved.
Show resolved Hide resolved

- `GATEWAY_ADMIN_ADDRESS_ZEVM`: address of the admin
- `WZETA`: wrapped ZETA contract address

Once setup, the contract can be deployed:

```
forge script scripts/deploy/deterministic/DeployGatewayZEVM.s.sol \
--private-key <PRIVATE_KEY> \
--rpc-url <RPC_URL> \
--verify \
--verifier blockscout \
--verifier-url <VERIFIER_URL> \
--chain-id <CHAIN_ID> \
--broadcast
```

## Deterministic deployments

Deployment scripts in `deterministic` uses create2 with Foundry (https://book.getfoundry.sh/tutorials/create2-tutorial) to perform deterministic deployment of contracts.
lumtis marked this conversation as resolved.
Show resolved Hide resolved
This ensures that on every EVM chain `GatewayEVM` contract will be on same address.
lumtis marked this conversation as resolved.
Show resolved Hide resolved

lumtis marked this conversation as resolved.
Show resolved Hide resolved
Since UUPS proxy is used for the contracts, both implementation and `ERC1967Proxy` are deployed using above technique:

- calculate expected address
- adding a salt to deployment
- basic assertions to verify that deployed address is same as expected

The contract can be upgraded with the following documentation: https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades. It requires:

- deploy new implementation (doesn't need to be deterministic since proxy address doesn't change)
- use plugin to upgrade proxy
lumtis marked this conversation as resolved.
Show resolved Hide resolved


## All deployment scripts

- `deterministic/DeployERC20Custody.s.sol`: deploy the ERC20 custody contract on a connected chain
- `deterministic/DeployGatewayEVM.s.sol`: deploy the gateway contract on a connected chain
- `deterministic/DeployGatewayZEVM.s.sol`: deploy the gateway contract on ZetaChain
- `deterministic/TestERC20.s.sol`: deploy a ERC20 for test purpose
- `deterministic/ZetaConnectorNonNative.s.sol`: deploy the ZETA connector contract on a connected chain, currently not used
- `deterministic/UpgradeGatewayEVM.s.sol`: upgrade the GatewayEVM contract to a test contract implementation, used for test purposes only
- `DeployZRC20.s.sol`: deploy a ZRC20 for test purpose
Loading