feat: restore operator WIP — PMM JSON sync entrypoint, dotenv RPC trim + secrets, pool env alignment
- Resolve stash: merge load_deployment_env path with secure-secrets and CR/LF RPC strip - create-pmm-full-mesh-chain138.sh delegates to sync-chain138-pmm-pools-from-json.sh - env.additions.example: canonical PMM pool defaults (cUSDT/USDT per crosscheck) - Include Chain138 scripts, official mirror deploy scaffolding, and prior staged changes Made-with: Cursor
This commit is contained in:
@@ -1,107 +1,123 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# Configure Chain 138 ↔ Ethereum mainnet CCIP WETH bridge destinations.
|
||||
# Uses CCIPWETH9Bridge / CCIPWETH10Bridge addDestination(uint64,address) (receiver = peer bridge on the other chain).
|
||||
# For Gnosis/Cronos/Celo/Wemix, use complete-config-ready-chains.sh instead.
|
||||
#
|
||||
# Env: PRIVATE_KEY; bridge addresses (see below); RPC_URL_138; ETHEREUM_MAINNET_RPC or RPC_URL_MAINNET.
|
||||
#
|
||||
# shellcheck disable=SC1090
|
||||
|
||||
# Configure Bridge Destinations Script
|
||||
# Configures ChainID 138 ↔ Mainnet bidirectional bridge destinations
|
||||
set -euo pipefail
|
||||
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
if [[ -f "$SCRIPT_DIR/../lib/deployment/dotenv.sh" ]]; then
|
||||
source "$SCRIPT_DIR/../lib/deployment/dotenv.sh"
|
||||
load_deployment_env --repo-root "$PROJECT_ROOT"
|
||||
fi
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
NC='\033[0m'
|
||||
|
||||
# Configuration
|
||||
PRIVATE_KEY="${PRIVATE_KEY:-}"
|
||||
RPC_URL_138="${RPC_URL_138:-http://192.168.11.175:8545}"
|
||||
RPC_URL_MAINNET="${RPC_URL_MAINNET:-https://eth.llamarpc.com}"
|
||||
|
||||
# Chain Selectors
|
||||
MAINNET_CHAIN_SELECTOR="5009297550715157269"
|
||||
CHAIN138_CHAIN_SELECTOR="${CHAIN138_CHAIN_SELECTOR:-}" # To be determined
|
||||
|
||||
# Contract Addresses (set these after deployment)
|
||||
WETH9_BRIDGE_138="${WETH9_BRIDGE_138:-}"
|
||||
WETH10_BRIDGE_138="${WETH10_BRIDGE_138:-}"
|
||||
WETH9_MAINNET="${WETH9_MAINNET:-0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2}"
|
||||
WETH10_MAINNET="${WETH10_MAINNET:-0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f}"
|
||||
|
||||
echo -e "${GREEN}=== Bridge Destination Configuration ===${NC}\n"
|
||||
|
||||
# Check prerequisites
|
||||
if [ -z "$PRIVATE_KEY" ]; then
|
||||
echo -e "${RED}ERROR: PRIVATE_KEY environment variable not set${NC}"
|
||||
exit 1
|
||||
if [[ -n "$PRIVATE_KEY" && ! "$PRIVATE_KEY" =~ ^0x ]]; then
|
||||
PRIVATE_KEY="0x$PRIVATE_KEY"
|
||||
fi
|
||||
|
||||
if [ -z "$WETH9_BRIDGE_138" ] || [ -z "$WETH10_BRIDGE_138" ]; then
|
||||
echo -e "${YELLOW}WARNING: Bridge addresses not set. Please set WETH9_BRIDGE_138 and WETH10_BRIDGE_138${NC}"
|
||||
exit 1
|
||||
RPC_URL_138="${RPC_URL_138:-http://192.168.11.211:8545}"
|
||||
RPC_URL_138="${RPC_URL_138%$'\r'}"
|
||||
RPC_URL_138="${RPC_URL_138%$'\n'}"
|
||||
RPC_URL_MAINNET="${RPC_URL_MAINNET:-${ETHEREUM_MAINNET_RPC:-https://eth.llamarpc.com}}"
|
||||
RPC_URL_MAINNET="${RPC_URL_MAINNET%$'\r'}"
|
||||
RPC_URL_MAINNET="${RPC_URL_MAINNET%$'\n'}"
|
||||
|
||||
MAINNET_CHAIN_SELECTOR="${MAINNET_CHAIN_SELECTOR:-5009297550715157269}"
|
||||
CHAIN138_CHAIN_SELECTOR="${CHAIN138_CHAIN_SELECTOR:-${CHAIN138_SELECTOR:-}}"
|
||||
|
||||
# 138-side bridges (aliases match .env CCIP* names)
|
||||
WETH9_BRIDGE_138="${WETH9_BRIDGE_138:-${CCIPWETH9_BRIDGE_CHAIN138:-}}"
|
||||
WETH10_BRIDGE_138="${WETH10_BRIDGE_138:-${CCIPWETH10_BRIDGE_CHAIN138:-}}"
|
||||
# Mainnet peer *bridge* contracts (not WETH token addresses)
|
||||
WETH9_MAINNET="${WETH9_MAINNET:-${MAINNET_CCIP_WETH9_BRIDGE:-}}"
|
||||
WETH10_MAINNET="${WETH10_MAINNET:-${MAINNET_CCIP_WETH10_BRIDGE:-}}"
|
||||
|
||||
echo -e "${GREEN}=== Bridge destination configuration (138 ↔ Mainnet) ===${NC}\n"
|
||||
|
||||
if [[ -z "$PRIVATE_KEY" ]]; then
|
||||
echo -e "${RED}ERROR: PRIVATE_KEY not set (env or .env)${NC}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$WETH9_BRIDGE_138" || -z "$WETH10_BRIDGE_138" ]]; then
|
||||
echo -e "${RED}ERROR: Set WETH9_BRIDGE_138 / WETH10_BRIDGE_138 or CCIPWETH9_BRIDGE_CHAIN138 / CCIPWETH10_BRIDGE_CHAIN138${NC}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$WETH9_MAINNET" || -z "$WETH10_MAINNET" ]]; then
|
||||
echo -e "${RED}ERROR: Set mainnet peer bridge addresses: WETH9_MAINNET / WETH10_MAINNET${NC}" >&2
|
||||
echo -e " (or MAINNET_CCIP_WETH9_BRIDGE / MAINNET_CCIP_WETH10_BRIDGE). These must be the CCIP bridge contracts on Ethereum, not WETH token addresses.${NC}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to add destination
|
||||
add_destination() {
|
||||
local bridge_address=$1
|
||||
local chain_selector=$2
|
||||
local destination_token=$3
|
||||
local rpc_url=$4
|
||||
local network_name=$5
|
||||
local bridge_address=$1
|
||||
local chain_selector=$2
|
||||
local receiver_bridge=$3
|
||||
local rpc_url=$4
|
||||
local network_name=$5
|
||||
|
||||
echo -e "${GREEN}Adding destination to $network_name bridge...${NC}"
|
||||
|
||||
cast send "$bridge_address" \
|
||||
"addDestination(uint64,address,address)" \
|
||||
"$chain_selector" \
|
||||
"$destination_token" \
|
||||
"0x0000000000000000000000000000000000000000" \
|
||||
--rpc-url "$rpc_url" \
|
||||
--private-key "$PRIVATE_KEY" \
|
||||
--legacy
|
||||
echo -e "${GREEN}Adding destination on $network_name bridge...${NC}"
|
||||
cast send "${bridge_address,,}" \
|
||||
"addDestination(uint64,address)" \
|
||||
"$chain_selector" \
|
||||
"${receiver_bridge,,}" \
|
||||
--rpc-url "$rpc_url" \
|
||||
--private-key "$PRIVATE_KEY" \
|
||||
--legacy \
|
||||
--gas-limit 250000 \
|
||||
--gas-price 2000000000
|
||||
|
||||
echo -e "${GREEN}✓ Destination added${NC}\n"
|
||||
echo -e "${GREEN}✓ Destination added${NC}\n"
|
||||
}
|
||||
|
||||
# Function to verify destinations
|
||||
verify_destinations() {
|
||||
local bridge_address=$1
|
||||
local rpc_url=$2
|
||||
local network_name=$3
|
||||
local bridge_address=$1
|
||||
local rpc_url=$2
|
||||
local network_name=$3
|
||||
|
||||
echo -e "${GREEN}Verifying destinations on $network_name...${NC}"
|
||||
|
||||
local chains=$(cast call "$bridge_address" \
|
||||
"getDestinationChains()(uint64[])" \
|
||||
--rpc-url "$rpc_url")
|
||||
|
||||
echo -e "${GREEN}Verifying destinations on $network_name...${NC}"
|
||||
local chains
|
||||
if chains=$(cast call "${bridge_address,,}" \
|
||||
"getDestinationChains()(uint64[])" \
|
||||
--rpc-url "$rpc_url" 2>/dev/null); then
|
||||
echo -e "${GREEN}Destination chains: $chains${NC}\n"
|
||||
else
|
||||
echo -e "${YELLOW}Could not read getDestinationChains (cast/RPC). Try cast rpc eth_call or another RPC.${NC}\n"
|
||||
fi
|
||||
}
|
||||
|
||||
# Configure ChainID 138 → Mainnet
|
||||
echo -e "${YELLOW}=== Configuring ChainID 138 → Mainnet ===${NC}\n"
|
||||
echo -e "${YELLOW}=== Chain 138 → Mainnet ===${NC}\n"
|
||||
|
||||
echo -e "${GREEN}1. Configuring WETH9 Bridge (ChainID 138 → Mainnet)${NC}"
|
||||
add_destination "$WETH9_BRIDGE_138" "$MAINNET_CHAIN_SELECTOR" "$WETH9_MAINNET" "$RPC_URL_138" "ChainID 138"
|
||||
echo -e "${GREEN}1. WETH9 bridge on 138 → Mainnet peer${NC}"
|
||||
add_destination "$WETH9_BRIDGE_138" "$MAINNET_CHAIN_SELECTOR" "$WETH9_MAINNET" "$RPC_URL_138" "Chain 138 WETH9"
|
||||
|
||||
echo -e "${GREEN}2. Configuring WETH10 Bridge (ChainID 138 → Mainnet)${NC}"
|
||||
add_destination "$WETH10_BRIDGE_138" "$MAINNET_CHAIN_SELECTOR" "$WETH10_MAINNET" "$RPC_URL_138" "ChainID 138"
|
||||
echo -e "${GREEN}2. WETH10 bridge on 138 → Mainnet peer${NC}"
|
||||
add_destination "$WETH10_BRIDGE_138" "$MAINNET_CHAIN_SELECTOR" "$WETH10_MAINNET" "$RPC_URL_138" "Chain 138 WETH10"
|
||||
|
||||
# Verify ChainID 138 bridges
|
||||
echo -e "${YELLOW}=== Verifying ChainID 138 Bridges ===${NC}\n"
|
||||
echo -e "${YELLOW}=== Verify 138 bridges ===${NC}\n"
|
||||
verify_destinations "$WETH9_BRIDGE_138" "$RPC_URL_138" "WETH9 Bridge"
|
||||
verify_destinations "$WETH10_BRIDGE_138" "$RPC_URL_138" "WETH10 Bridge"
|
||||
|
||||
# Note: Mainnet → ChainID 138 requires ChainID 138 selector
|
||||
if [ -z "$CHAIN138_CHAIN_SELECTOR" ]; then
|
||||
echo -e "${YELLOW}NOTE: ChainID 138 chain selector not set.${NC}"
|
||||
echo -e "${YELLOW}To configure Mainnet → ChainID 138, first determine the ChainID 138 selector.${NC}"
|
||||
echo -e "${YELLOW}You can find it using: cast call <CCIP_ROUTER> 'getChainSelector()(uint64)' --rpc-url $RPC_URL_138${NC}\n"
|
||||
if [[ -z "$CHAIN138_CHAIN_SELECTOR" ]]; then
|
||||
echo -e "${YELLOW}NOTE: CHAIN138_CHAIN_SELECTOR / CHAIN138_SELECTOR not set.${NC}"
|
||||
echo -e "${YELLOW}To add Chain 138 as a destination on Mainnet bridges, set the selector then run addDestination on mainnet (see complete-config-ready-chains.sh pattern).${NC}"
|
||||
echo -e "${YELLOW}Router getChainSelector() may revert on custom routers; see docs/deployment/CHAIN138_SELECTOR_NOTES.md${NC}\n"
|
||||
else
|
||||
echo -e "${YELLOW}=== Configuring Mainnet → ChainID 138 ===${NC}\n"
|
||||
echo -e "${YELLOW}NOTE: This requires deploying bridges on Mainnet first.${NC}\n"
|
||||
echo -e "${YELLOW}=== Mainnet → Chain 138 ===${NC}"
|
||||
echo -e "${YELLOW}CHAIN138_CHAIN_SELECTOR=$CHAIN138_CHAIN_SELECTOR — run addDestination on each Mainnet bridge with this selector and the 138 peer bridge address (not automated here).${NC}\n"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}=== Configuration Complete ===${NC}\n"
|
||||
echo -e "Next Steps:"
|
||||
echo -e " 1. Test bidirectional transfers"
|
||||
echo -e " 2. Monitor bridge activity"
|
||||
echo -e " 3. Verify LINK token balances for CCIP fees"
|
||||
echo -e "${GREEN}=== Done ===${NC}\n"
|
||||
echo -e "Next: fund bridges with LINK; test transfers; monitor fees."
|
||||
|
||||
Reference in New Issue
Block a user