Files
smom-dbis-138/docs/WETH_CREATE2_DEPLOYMENT.md
defiQUG 1fb7266469 Add Oracle Aggregator and CCIP Integration
- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control.
- Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities.
- Created .gitmodules to include OpenZeppelin contracts as a submodule.
- Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment.
- Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks.
- Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring.
- Created scripts for resource import and usage validation across non-US regions.
- Added tests for CCIP error handling and integration to ensure robust functionality.
- Included various new files and directories for the orchestration portal and deployment scripts.
2025-12-12 14:57:48 -08:00

5.4 KiB

WETH9 and WETH10 CREATE2 Deployment Guide

Overview

This guide explains how to deploy WETH9 and WETH10 contracts to the exact addresses specified in genesis.json using CREATE2.

Target Addresses

From genesis.json:

  • WETH9: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
  • WETH10: 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f

These addresses are pre-allocated in the genesis block with balance 0x0 and no code.

CREATE2 Address Calculation

The CREATE2 address is calculated using:

address = keccak256(0xff ++ deployer ++ salt ++ keccak256(bytecode))[12:]

To deploy to the exact target addresses, we need:

  1. Contract Bytecode: Must match exactly (we compile our contracts)
  2. Deployer Address: Must match the address used when calculating the genesis addresses
  3. Salt: Must match the salt used when calculating the genesis addresses

Deployment Scripts

1. script/DeployWETH9ToExactAddress.s.sol

  • Attempts to find the salt that produces the WETH9 target address
  • Uses CREATE2Factory to deploy
  • Tries common salts first, then brute forces if needed

2. script/DeployWETH10ToExactAddress.s.sol

  • Attempts to find the salt that produces the WETH10 target address
  • Uses CREATE2Factory to deploy
  • Tries common salts first, then brute forces if needed

3. scripts/deployment/calculate-create2-salt.js

  • Node.js utility to calculate CREATE2 salt
  • Can be used to find the salt that produces a target address
  • Supports brute-force search

4. scripts/deployment/deploy-weth-create2.sh

  • Main deployment script
  • Compiles contracts
  • Checks if contracts already exist
  • Deploys WETH9 and WETH10 sequentially

Deployment Process

Prerequisites

  1. Environment Variables (in .env):

    PRIVATE_KEY=0x...
    RPC_URL=http://localhost:8545
    
  2. Compiled Contracts:

    forge build
    

Step 1: Calculate Salt (Optional)

If you know the deployer address used when creating genesis.json:

node scripts/deployment/calculate-create2-salt.js WETH <deployer-address>
node scripts/deployment/calculate-create2-salt.js WETH10 <deployer-address>

This will find the salt that produces the target addresses.

Step 2: Deploy Contracts

Option A: Use the automated script

./scripts/deployment/deploy-weth-create2.sh

Option B: Deploy manually using Foundry

# Deploy WETH9
forge script script/DeployWETH9ToExactAddress.s.sol:DeployWETH9ToExactAddress \
    --rpc-url $RPC_URL \
    --broadcast \
    --private-key $PRIVATE_KEY \
    --legacy

# Deploy WETH10
forge script script/DeployWETH10ToExactAddress.s.sol:DeployWETH10ToExactAddress \
    --rpc-url $RPC_URL \
    --broadcast \
    --private-key $PRIVATE_KEY \
    --legacy

Troubleshooting

Issue: Salt not found

If the scripts cannot find a salt that produces the target address:

  1. Check Deployer Address: The deployer address must match the one used when calculating the genesis addresses
  2. Verify Bytecode: Ensure the compiled bytecode matches what was used in genesis.json
  3. Try Different Deployer: If genesis.json used a different deployer, you may need to use that address

Issue: Address mismatch

If the deployed address doesn't match the target:

  1. Verify Salt: Double-check the salt calculation
  2. Check Factory Address: If using CREATE2Factory, ensure the factory address matches
  3. Review Genesis: Confirm the target addresses in genesis.json are correct

Issue: Contract already exists

If the contract already exists at the target address:

  1. Verify Deployment: Check if the contract is already deployed
  2. Check Code: Verify the existing code matches what you expect
  3. Skip Deployment: The scripts will skip deployment if contracts already exist

Alternative Approaches

Approach 1: Direct Deployment to Pre-allocated Addresses

If genesis.json pre-allocates these addresses, you might be able to deploy directly to them without CREATE2, depending on the blockchain client's implementation.

Approach 2: Use Known CREATE2 Deployer

Use a well-known CREATE2 deployer (like 0x4e59b44847b379578588920cA78FbF26c0B4956C) and calculate the appropriate salt.

Approach 3: Genesis Pre-deployment

If the blockchain client supports it, you can include the contract bytecode directly in genesis.json instead of deploying via CREATE2.

Verification

After deployment, verify the contracts:

# Check WETH9
cast code 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 --rpc-url $RPC_URL

# Check WETH10
cast code 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f --rpc-url $RPC_URL

# Interact with contracts
cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 "name()" --rpc-url $RPC_URL
cast call 0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f "name()" --rpc-url $RPC_URL

Important Notes

  1. Gas Costs: CREATE2 deployment with salt finding can be gas-intensive, especially if brute-force is needed
  2. Deployer Balance: Ensure the deployer account has sufficient balance for deployment
  3. Network: Make sure you're deploying to the correct network (ChainID 138)
  4. Genesis Alignment: The addresses in genesis.json must match the CREATE2 calculation for deployment to work

References