Skip to content

Commit

Permalink
feat: refactor deployment scripts to use same script for single and m…
Browse files Browse the repository at this point in the history
…ulti-chain deployments (#45)
  • Loading branch information
tremarkley authored Nov 5, 2024
1 parent 66554e0 commit 88684d4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 97 deletions.
46 changes: 9 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
- [Deployment config](#deployment-config)
- [`[deploy-config]`](#deploy-config)
- [`[token]`](#token)
- [`[single_chain_deploy_config]`](#single_chain_deploy_config)
- [`[multi_chain_deploy_config]`](#multi_chain_deploy_config)
- [Deploying to multiple chains](#deploying-to-multiple-chains)
- [Deploying to single chain](#deploying-to-single-chain)
- [Deploying a token](#deploying-a-token)
- [Best practices for deploying SuperchainERC20](#best-practices-for-deploying-superchainerc20)
- [Use Create2 to deploy SuperchainERC20](#use-create2-to-deploy-superchainerc20)
- [`crosschainMint` and `crosschainBurn` permissions](#crosschainmint-and-crosschainburn-permissions)
Expand Down Expand Up @@ -105,14 +102,16 @@ pnpm contracts:update:rpcs

### Deployment config

The deployment configuration for token deployments is managed through the `deploy-config.toml` file. The options available in this file allow you to customize both single and multi-chain deployments. Below is a detailed breakdown of each configuration section:
The deployment configuration for token deployments is managed through the `deploy-config.toml` file. Below is a detailed breakdown of each configuration section:

#### `[deploy-config]`

This section defines parameters for deploying token contracts across both single and multi-chain environments.
This section defines parameters for deploying token contracts.

- `salt`: A unique identifier used for deploying token contracts via [`Create2`]. This value along with the contract bytecode ensures that contract deployments are deterministic.
- example: `salt = "ethers phoenix"`
- `chains`: Lists the chains where the token will be deployed. Each chain must correspond to an entry in the `[rpc_endpoints]` section of `foundry.toml`.
- example: `chains = ["op_chain_a","op_chain_b"]`

#### `[token]`

Expand All @@ -128,43 +127,16 @@ Deployment configuration for the token that will be deployed.
- `decimals`: the number of decimal places the token supports.
- example: `decimals = 18`

#### `[single_chain_deploy_config]`

This section contains configuration settings specific to single chain deployments via the `SingleChainSuperchainERC20Deployment.s.sol` script.

- `chain`: specifies the chain where the token will be deployed. This value must correspond to a chain in the `[rpc_endpoints]` section of `foundry.toml`.
- example: `chain = "op/mainnet"`

#### `[multi_chain_deploy_config]`

This section contains configuration settings specific to multi-chain deployments via the `MultiChainSuperchainERC20Deployment.s.sol` script.

- `chains`: Lists the chains where the token will be deployed. Each chain must correspond to an entry in the `[rpc_endpoints]` section of `foundry.toml`.
- example: `chains = ["op_chain_a","op_chain_b"]`

### Deploying to multiple chains

Before proceeding with this section, ensure that your `deploy-config.toml` file is fully configured (see the [Deployment config](#deployment-config) section for more details on setup). Additionally, confirm that the `[rpc_endpoints]` section in `foundry.toml` is properly set up by following the instructions in [Configuring RPC urls](#configuring-rpc-urls).

Multi-chain deployments are executed through the `MultiChainSuperchainERC20Deployment.s.sol` script. This script deploys tokens across each specified chain in the deployment configuration using `Create2`, ensuring deterministic contract addresses for each deployment. The script targets the `L2NativeSuperchainERC20.sol` contract by default. If you need to modify the token being deployed, either update this file directly or point the script to a custom token contract of your choice.

To execute a multi-chain deployment run:

```sh
pnpm contracts:deploy:multichain

```

### Deploying to single chain
### Deploying a token

Before proceeding with this section, ensure that your `deploy-config.toml` file is fully configured (see the [Deployment config](#deployment-config) section for more details on setup). Additionally, confirm that the `[rpc_endpoints]` section in `foundry.toml` is properly set up by following the instructions in [Configuring RPC urls](#configuring-rpc-urls).

A single chain deployment is executed through the `SingleChainSuperchainERC20Deployment.s.sol` script. This script deploys a token on the specified chain in the deployment configuration using `Create2`, ensuring deterministic contract addresses for the deployment. The script targets the `L2NativeSuperchainERC20.sol` contract by default. If you need to modify the token being deployed, either update this file directly or point the script to a custom token contract of your choice.
Deployments are executed through the `SuperchainERC20Deployer.s.sol` script. This script deploys tokens across each specified chain in the deployment configuration using `Create2`, ensuring deterministic contract addresses for each deployment. The script targets the `L2NativeSuperchainERC20.sol` contract by default. If you need to modify the token being deployed, either update this file directly or point the script to a custom token contract of your choice.

To execute a single chain deployment run:
To execute a token deployment run:

```sh
pnpm contracts:deploy:singlechain
pnpm contracts:deploy:token

```

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
"dev": "mprocs",
"install:contracts": "cd packages/contracts && forge install",
"contracts:update:rpcs": "pnpm nx run @superchainerc20-starter/contracts:update:rpcs",
"contracts:deploy:multichain": "pnpm nx run @superchainerc20-starter/contracts:deploy:multichain",
"contracts:deploy:singlechain": "pnpm nx run @superchainerc20-starter/contracts:deploy:singlechain",
"contracts:deploy:token": "pnpm nx run @superchainerc20-starter/contracts:deploy:token",
"update:toc": "doctoc README.md",
"e2e-test": "mprocs -c mprocs-e2e-test.yaml",
"init:env": "pnpm nx run-many --target=init:env",
"deploy:contracts:ci": "wait-port http://:8420/ready && cd packages/contracts && forge install && forge script scripts/MultiChainSuperchainERC20Deployment.s.sol --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"deploy:contracts:ci": "wait-port http://:8420/ready && cd packages/contracts && forge install && forge script scripts/SuperchainERC20Deployer.s.sol --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"e2e-test:ci": "pnpm nx run @superchainerc20-starter/e2e-test:test"
},
"license": "MIT",
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ This repository contains contracts and tooling for deploying and managing Superc

### scripts/

- `MultiChainSuperchainERC20Deployment.s.sol` - Script for deploying the L2NativeSuperchainERC20 token to multiple chains in sequence, reading chain configuration from TOML.
- `SingleChainSuperchainERC20Deployment.s.sol` - Script for deploying the L2NativeSuperchainERC20 token to a single chain, reading chain configuration from TOML.
- `SuperchainERC20Deployer.sol` - Base deployment logic used by both single and multi-chain deployment scripts.
- `SuperchainERC20Deployer.s.sol` - Script for deploying the L2NativeSuperchainERC20 token to the configured chains in sequence, reading chain configuration from TOML.

## Deploying

Expand Down
5 changes: 0 additions & 5 deletions packages/contracts/configs/deploy-config.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
[deploy_config]
salt = "ethers phoenix"

[single_chain_deploy_config]
chain = "op_chain_a"

[multi_chain_deploy_config]
chains = ["op_chain_a","op_chain_b"]

[token]
Expand Down
5 changes: 2 additions & 3 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "@superchainerc20-starter/contracts",
"scripts": {
"deploy:dev": "source .env && wait-port http://:8420/ready && forge script scripts/MultiChainSuperchainERC20Deployment.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
"deploy:multichain": "source .env && forge script scripts/MultiChainSuperchainERC20Deployment.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
"deploy:singlechain": "source .env && forge script scripts/SingleChainSuperchainERC20Deployment.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
"deploy:dev": "source .env && wait-port http://:8420/ready && forge script scripts/SuperchainERC20Deployer.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
"deploy:token": "source .env && forge script scripts/SuperchainERC20Deployer.s.sol --broadcast --private-key $DEPLOYER_PRIVATE_KEY",
"update:rpcs": "cd ../.. && ./scripts/fetch-superchain-rpc-urls.sh",
"install": "forge install",
"build": "forge build",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {console} from "forge-std/Script.sol";
import {Script, console} from "forge-std/Script.sol";
import {Vm} from "forge-std/Vm.sol";
import {L2NativeSuperchainERC20} from "../src/L2NativeSuperchainERC20.sol";

contract SuperchainERC20Deployer {
contract SuperchainERC20Deployer is Script {
string deployConfig;

constructor() {
Expand All @@ -20,17 +20,30 @@ contract SuperchainERC20Deployer {
vm.stopBroadcast();
}

/// @notice Foundry cheatcode VM.
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
function setUp() public {}

function run() public {
string[] memory chainsToDeployTo = vm.parseTomlStringArray(deployConfig, ".deploy_config.chains");

for (uint256 i = 0; i < chainsToDeployTo.length; i++) {
string memory chainToDeployTo = chainsToDeployTo[i];

console.log("Deploying to chain: ", chainToDeployTo);

vm.createSelectFork(chainToDeployTo);
deployL2NativeSuperchainERC20();
}
}

function deployL2NativeSuperchainERC20() public broadcast returns (address addr_) {
address owner = vm.parseTomlAddress(deployConfig, ".token.owner_address");
string memory name = vm.parseTomlString(deployConfig, ".token.name");
string memory symbol = vm.parseTomlString(deployConfig, ".token.symbol");
uint256 decimals = vm.parseTomlUint(deployConfig, ".token.decimals");
require(decimals <= type(uint8).max, "decimals exceeds uint8 range");
bytes memory initCode =
abi.encodePacked(type(L2NativeSuperchainERC20).creationCode, abi.encode(owner, name, symbol, uint8(decimals)));
bytes memory initCode = abi.encodePacked(
type(L2NativeSuperchainERC20).creationCode, abi.encode(owner, name, symbol, uint8(decimals))
);
address preComputedAddress = vm.computeCreate2Address(_implSalt(), keccak256(initCode));
if (preComputedAddress.code.length > 0) {
console.log(
Expand Down

0 comments on commit 88684d4

Please sign in to comment.