Skip to content

Commit 53f48a3

Browse files
committed
Add MegaETH deployment and verification support
- foundry.toml: megaeth rpc_endpoints and etherscan (chain 4326) - script/bao-factory: - MegaETH verify via Etherscan API v2 (direct API, chainid=4326) - --verify: verify-only for bootstrap implementation - --verify-contract <addr> <path>: verify any contract (e.g. after impl deploy) - PATH handling for Foundry (cast/forge) when not on PATH - Portable grep (-oE) for macOS/BSD - NEXT STEPS: explorer URLs for megaeth, typos fixed, verify-contract hint - README: prerequisites (git submodules), MegaETH env vars and verify flow, verify-only and implementation upgrade for megaeth, ./script/bao-factory in examples Made-with: Cursor
1 parent b49a45f commit 53f48a3

File tree

3 files changed

+337
-30
lines changed

3 files changed

+337
-30
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ Canonical Bao Factory contracts plus deterministic deployment helpers. We keep t
66

77
[![CI](https://github.com/baofinance/bao-factory/actions/workflows/CI-test-foundry-stable.yml/badge.svg)](https://github.com/baofinance/bao-base/actions/workflows/CI-test-foundry-stable.yml)
88

9+
## Prerequisites
10+
11+
**Initialize git submodules** before building, deploying, or verifying (the repo uses `lib/solady` and `lib/forge-std` as submodules):
12+
13+
```bash
14+
git submodule update --init --recursive
15+
```
16+
17+
Without this, `forge build` and verification will fail with missing file errors for `lib/solady` and `lib/forge-std`.
18+
919
## Production Deployment Guide
1020

11-
The `script/bao-factory` CLI handles all deployment operations. Run `--help` for full options.
21+
The `script/bao-factory` CLI handles all deployment operations. From the repo root, run `./script/bao-factory --help` for full options. (Use the path to the script; it is not installed on your PATH.)
1222

1323
### Initial Factory Deployment
1424

@@ -19,9 +29,25 @@ This installs a non-functional, but upgradeable, factory. It does it by:
1929

2030
```bash
2131
# Deploy the bootstrap factory via Nick's Factory (deterministic address)
22-
bao-factory --deploy --network mainnet --account <deployer> --etherscan <API_KEY>
32+
./script/bao-factory --deploy --network mainnet --account <deployer> --etherscan <API_KEY>
2333
```
2434

35+
For **MegaETH** (chain ID 4326), set in your environment and use `--network megaeth`:
36+
37+
- `MEGAETH_RPC_URL` (e.g. `https://mainnet.megaeth.com/rpc`)
38+
- `MEGAETH_ETHERSCAN_API_URL` (e.g. `https://api.etherscan.io/v2/api`)
39+
- `ETHERSCAN_API_KEY` (for contract verification)
40+
41+
**MegaETH verification differs from mainnet Ethereum:** mainnet uses `forge verify-contract` against the standard Etherscan API. MegaETH uses Etherscan API **v2** with `chainid=4326`; the script calls that API directly (same approach as harbor-price-aggregators’ verify-megaeth-direct-api.sh) when you use `--network megaeth`, so verification works correctly on [mega.etherscan.io](https://mega.etherscan.io/).
42+
43+
To **verify only** (e.g. after a deploy when verification was skipped or failed):
44+
45+
```bash
46+
./script/bao-factory --verify --network megaeth --etherscan "$ETHERSCAN_API_KEY"
47+
```
48+
49+
Verification is asynchronous; check https://mega.etherscan.io/address/<implementation_address> in 1–2 minutes. To have the script wait and poll the result, set `BAO_FACTORY_VERIFY_WAIT=120`. If verification never appears, use **manual verification** on mega.etherscan.io: open the contract → "Contract" tab → "Verify & Publish" → choose "Solidity (Standard-Json-Input)" and paste the compiler settings (Compiler 0.8.30, Optimizer 10000, via-IR, EVM Prague); use `forge verify-contract --show-standard-json-input ...` (with same args as the script) to obtain the JSON to paste.
50+
2551
So now we have a factory deployed at a predictable address but it has no factory functionality. Factory functionality comes with the next step.
2652

2753
See https://etherscan.io/address/0xD696E56b3A054734d4C6DCBD32E11a278b0EC458 for the harbor factory
@@ -32,14 +58,16 @@ The bootstrap factory must be upgraded to `BaoFactory_v1` before use:
3258

3359
```bash
3460
# 1. Deploy the implementation and get upgrade instructions
35-
bao-factory --implementation src/BaoFactory_v1.sol:BaoFactory_v1 \
61+
./script/bao-factory --implementation src/BaoFactory_v1.sol:BaoFactory_v1 \
3662
--network mainnet --account <deployer> --etherscan <API_KEY>
3763

3864
# 2. The script outputs cast commands for the owner multisig to execute:
3965
# - upgradeToAndCall(address,bytes) to point proxy at new implementation
4066
# - setOperator(address,uint256) to authorize deployers
4167
```
4268

69+
For **MegaETH**, use `--network megaeth` with `MEGAETH_RPC_URL` and `MEGAETH_ETHERSCAN_API_URL` set; the implementation is deployed and verified via the MegaETH Etherscan API (same as the bootstrap verify flow).
70+
4371
The functional factory implementation is now deployed and verified on etherscan. The proxy needs to be upgraded to point to this new implementation. This is done by the upgradeToAndCall call sent to it which can only be done via the Bao Harbor multisig.
4472

4573
In order to use the BaoFactory_v1 you need to be an operator. So make the setOperator call on the BaoHarbor multisig

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ number_underscore = "thousands"
3131

3232
[etherscan]
3333
mainnet = { key = "${ETHERSCAN_KEY}" }
34+
megaeth = { key = "${ETHERSCAN_API_KEY}", url = "${MEGAETH_ETHERSCAN_API_URL}" }
3435

3536
[rpc_endpoints]
3637
sepolia = "${SEPOLIA_RPC_URL}"
3738
mainnet = "${MAINNET_RPC_URL}"
39+
megaeth = "${MEGAETH_RPC_URL}"
3840
local = "http://localhost:8545"

0 commit comments

Comments
 (0)