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: add new deploy script to docs #72

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,12 @@ $ forge test

### Deploy

Deploy to Anvil:
To deploy the contracts to the testnet:

```sh
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
$ bun run deploy:testnet
```

For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
[BIP39 mnemonic](https://iancoleman.io/bip39/).

For instructions on how to deploy to a testnet or mainnet, check out the
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial.

### Run Root Propagator

To run the root propagator on testnet:
Expand Down
152 changes: 152 additions & 0 deletions docs/deployments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Deployment Guide

The deployment logic for the Worldcoin Bridge on Linea is implemented in
[`src/script/deploy.js`](../src/script/deploy.js). The script is intended to be run via the `bun run deploy`,
`bun run deploy:testnet`, and `bun run deploy:mainnet` commands. Below is a detailed description of what each deployment
command does and the corresponding Forge scripts that are executed:

---

## Deployment Commands

### `bun run deploy:mainnet`

This command interactively deploys the WorldID state bridge on the Linea mainnet.

#### Steps Executed:

1. **Configuration Setup**:

- Generates the `src/script/.deploy-config.json` file to store deployment configurations.
- Prompts for the following information:
- **Deployer Private Key** (`PRIVATE_KEY`): Your wallet's private key used for deploying contracts.
- **Ethereum RPC URL** (`ETH_RPC_URL`): The RPC URL for Ethereum mainnet.
- **Linea RPC URL** (`LINEA_RPC_URL`): The RPC URL for Linea mainnet. Default is `http://localhost:8545`.
- **Ethereum Etherscan API Key** (`ETHERSCAN_API_KEY`): For contract verification on Etherscan.
- **Lineascan API Key** (`LINEA_SCAN_API_KEY`): For contract verification on Lineascan.
- **Lineascan Verifier URL** (`LINEA_SCAN_VERIFIER_URL`): The verifier URL for Lineascan.
- **WorldID Tree Depth** (`treeDepth`): The Merkle tree depth for WorldID. Default is `30`.
- **Message Service Addresses**:
- **L1 Message Service Address** (`MESSAGE_SERVICE_ADDRESS_L1`): Address of the message service on L1.
- **L2 Message Service Address** (`MESSAGE_SERVICE_ADDRESS_L2`): Address of the message service on L2.
- Saves these configurations to `.deploy-config.json`.

2. **Deploy `LineaWorldID.sol` to Linea Mainnet**:

- Executes the Forge script [`DeployLineaWorldID.s.sol`](../src/script/DeployLineaWorldID.s.sol) to deploy the
`LineaWorldID` contract on Linea mainnet.

- **Command Executed**:

```bash
forge script src/script/DeployLineaWorldID.s.sol:DeployLineaWorldID --fork-url <LINEA_RPC_URL> --broadcast --json
```

- Extracts the deployed contract address from the logs and saves it to `.deploy-config.json`.
- If a Lineascan API key is provided, proceeds to verify the contract.

3. **Verify `LineaWorldID` Contract on Lineascan** (Optional):

- Uses the `forge verify-contract` command to verify the `LineaWorldID` contract on Lineascan.

- **Command Executed**:

```bash
forge verify-contract <LINEA_WORLD_ID_ADDRESS> src/LineaWorldID.sol:LineaWorldID --etherscan-api-key <LINEA_SCAN_API_KEY> --verifier-url <LINEA_SCAN_VERIFIER_URL> --watch
```

4. **Deploy `LineaStateBridge.sol` to Ethereum Mainnet**:

- Prompts for the `WorldIDIdentityManager` address (`WORLD_ID_IDENTITY_MANAGER_ADDRESS`).
- Executes the Forge script [`DeployLineaStateBridge.s.sol`](../src/script/DeployLineaStateBridge.s.sol) to deploy
the `LineaStateBridge` contract on Ethereum mainnet.

- **Command Executed**:

```bash
forge script src/script/DeployLineaStateBridge.s.sol:DeployLineaStateBridge --fork-url <ETH_RPC_URL> --broadcast --json
```

- If an Ethereum Etherscan API key is provided, adds `--etherscan-api-key` and `--verify` flags for automatic
verification.

- Extracts the deployed contract address from the logs and saves it to `.deploy-config.json`.

5. **Initialize `LineaWorldID` Contract**:

- Executes the Forge script [`InitializeLineaWorldID.s.sol`](../src/script/InitializeLineaWorldID.s.sol) to transfer
ownership of `LineaWorldID` to `LineaStateBridge`.

- **Command Executed**:

```bash
forge script src/script/InitializeLineaWorldID.s.sol:InitializeLineaWorldID --fork-url <LINEA_RPC_URL> --broadcast --legacy --json
```

- Confirms the ownership transfer and updates the configuration file.

---

### `bun run deploy:testnet`

This command deploys the WorldID state bridge on the Linea testnet (Linea Sepolia and Ethereum Sepolia).

#### Steps Executed:

1. **Configuration Setup**:

- Similar to `bun run deploy:mainnet`, but uses testnet configurations.
- Prompts for testnet-specific RPC URLs and API keys.

2. **Deploy `LineaWorldID.sol` to Linea Sepolia**:

- Deploys the `LineaWorldID` contract to Linea Sepolia using the same Forge script but with testnet parameters.

3. **Verify `LineaWorldID` Contract on Lineascan** (Optional):

- Verifies the contract on the Linea testnet explorer if API keys are provided.

4. **Deploy `LineaStateBridge.sol` to Ethereum Sepolia**:

- Deploys the `LineaStateBridge` contract to Ethereum Sepolia.

5. **Initialize `LineaWorldID` Contract**:
- Transfers ownership to `LineaStateBridge` on the testnet.

---

### `bun run deploy`

This command is a generic deployment script that can be used for both mainnet and testnet deployments, depending on the
environment specified.

---

## Addresses of the Deployments

### Testnet Deployments on Ethereum Sepolia and Linea Sepolia

- **LineaStateBridge (Ethereum Sepolia)**:
[0x64A96eED1dA15FCFb0874D82F7D7C6ea3Fda6aEf](https://sepolia.etherscan.io/address/0x64A96eED1dA15FCFb0874D82F7D7C6ea3Fda6aEf)

- **LineaWorldID (Linea Sepolia)**:
[0x5d676D93ffE4dC07805a780531a559b08cC3564d](https://sepolia.lineascan.build/address/0x5d676D93ffE4dC07805a780531a559b08cC3564d)

---

## Additional Notes

- **Forge Version**: Ensure you are using a compatible version of Forge and Foundry to run the scripts.
- **Private Key**: The deployer private key must have sufficient funds on the target network to cover deployment costs.
- **Environment Variables**: You can create environment-specific files (e.g., `mainnet.env`, `testnet.env`) to store
environment variables used in the deployment scripts.
- **Configuration File**: The `.deploy-config.json` file stores all deployment configurations and deployed contract
addresses. It's used for subsequent runs to reuse configurations.
- **Verification Issue**: Due to a known issue
([foundry-rs/foundry#7466](https://github.com/foundry-rs/foundry/issues/7466)), contracts cannot be verified and
deployed simultaneously. The script handles verification in a separate step.

---

By following this guide, you should be able to deploy the Worldcoin Bridge contracts to either the mainnet or testnet
environment. Make sure to replace placeholders with actual values and update explorer URLs as necessary.
Loading