diff --git a/scripts/bootstrap-common.sh b/scripts/bootstrap-common.sh index 2ee8bf8..c4df644 100755 --- a/scripts/bootstrap-common.sh +++ b/scripts/bootstrap-common.sh @@ -17,7 +17,9 @@ set -euo pipefail # ── Constants ────────────────────────────────────────────────────────── FEE_DEST=0xf6a3eef9088A255c32b6aD2025f83E57291D9011 WETH=0x4200000000000000000000000000000000000006 -SWAP_ROUTER=0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4 +SWAP_ROUTER_SEPOLIA=0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4 +SWAP_ROUTER_MAINNET=0x2626664c2603336E57B271c5C0b26F421741e481 +SWAP_ROUTER="" # resolved lazily by detect_swap_router() MAX_UINT=0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff DEFAULT_DEPLOYER_PK=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 @@ -39,6 +41,22 @@ bootstrap_log() { # ── Functions ────────────────────────────────────────────────────────── +detect_swap_router() { + # Idempotency: only detect once + if [[ -n "$SWAP_ROUTER" ]]; then + return 0 + fi + local chain_id + chain_id="$(cast chain-id --rpc-url "$ANVIL_RPC" 2>/dev/null || echo "")" + if [[ "$chain_id" == "8453" ]]; then + SWAP_ROUTER="$SWAP_ROUTER_MAINNET" + bootstrap_log "Detected Base mainnet (chain ID 8453) — using mainnet SwapRouter" + else + SWAP_ROUTER="$SWAP_ROUTER_SEPOLIA" + bootstrap_log "Using Base Sepolia SwapRouter (chain ID: ${chain_id:-unknown})" + fi +} + wait_for_rpc() { for _ in {1..120}; do if cast chain-id --rpc-url "$ANVIL_RPC" >/dev/null 2>&1; then @@ -102,6 +120,7 @@ fund_liquidity_manager() { bootstrap_vwap() { + detect_swap_router # Idempotency guard: if a previous run already bootstrapped VWAP, skip. local cumvol cumvol="$(cast call --rpc-url "$ANVIL_RPC" \ @@ -169,6 +188,7 @@ bootstrap_vwap() { } seed_application_state() { + detect_swap_router bootstrap_log "Wrapping ETH to WETH" cast send --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \ "$WETH" "deposit()" --value 2ether >>"$LOG_FILE" 2>&1