fix: bootstrap-common.sh has no network-aware SWAP_ROUTER selection (#948)
Add detect_swap_router() that queries chain ID from $ANVIL_RPC and selects the Base mainnet SwapRouter (0x2626...e481) for chain ID 8453, falling back to Base Sepolia (0x94cC...2bc4) for all other networks. Called lazily with idempotency from bootstrap_vwap() and seed_application_state(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9875257d91
commit
5156c607b2
1 changed files with 21 additions and 1 deletions
|
|
@ -17,7 +17,9 @@ set -euo pipefail
|
||||||
# ── Constants ──────────────────────────────────────────────────────────
|
# ── Constants ──────────────────────────────────────────────────────────
|
||||||
FEE_DEST=0xf6a3eef9088A255c32b6aD2025f83E57291D9011
|
FEE_DEST=0xf6a3eef9088A255c32b6aD2025f83E57291D9011
|
||||||
WETH=0x4200000000000000000000000000000000000006
|
WETH=0x4200000000000000000000000000000000000006
|
||||||
SWAP_ROUTER=0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4
|
SWAP_ROUTER_SEPOLIA=0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4
|
||||||
|
SWAP_ROUTER_MAINNET=0x2626664c2603336E57B271c5C0b26F421741e481
|
||||||
|
SWAP_ROUTER="" # resolved lazily by detect_swap_router()
|
||||||
MAX_UINT=0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
MAX_UINT=0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||||
|
|
||||||
DEFAULT_DEPLOYER_PK=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
|
DEFAULT_DEPLOYER_PK=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
|
||||||
|
|
@ -39,6 +41,22 @@ bootstrap_log() {
|
||||||
|
|
||||||
# ── Functions ──────────────────────────────────────────────────────────
|
# ── 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() {
|
wait_for_rpc() {
|
||||||
for _ in {1..120}; do
|
for _ in {1..120}; do
|
||||||
if cast chain-id --rpc-url "$ANVIL_RPC" >/dev/null 2>&1; then
|
if cast chain-id --rpc-url "$ANVIL_RPC" >/dev/null 2>&1; then
|
||||||
|
|
@ -102,6 +120,7 @@ fund_liquidity_manager() {
|
||||||
|
|
||||||
|
|
||||||
bootstrap_vwap() {
|
bootstrap_vwap() {
|
||||||
|
detect_swap_router
|
||||||
# Idempotency guard: if a previous run already bootstrapped VWAP, skip.
|
# Idempotency guard: if a previous run already bootstrapped VWAP, skip.
|
||||||
local cumvol
|
local cumvol
|
||||||
cumvol="$(cast call --rpc-url "$ANVIL_RPC" \
|
cumvol="$(cast call --rpc-url "$ANVIL_RPC" \
|
||||||
|
|
@ -169,6 +188,7 @@ bootstrap_vwap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
seed_application_state() {
|
seed_application_state() {
|
||||||
|
detect_swap_router
|
||||||
bootstrap_log "Wrapping ETH to WETH"
|
bootstrap_log "Wrapping ETH to WETH"
|
||||||
cast send --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \
|
cast send --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \
|
||||||
"$WETH" "deposit()" --value 2ether >>"$LOG_FILE" 2>&1
|
"$WETH" "deposit()" --value 2ether >>"$LOG_FILE" 2>&1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue