feat(scripts): CCIP destination matrix + ccip-destinations helper

- Add config/ccip-destination-matrix.json (selectors, bridges, public RPCs)
- Drive configure-all-*-destinations scripts from matrix via jq
- Extend config/README; wire check-bridge-config and pre-flight-check

Made-with: Cursor
This commit is contained in:
defiQUG
2026-03-27 22:17:12 -07:00
parent d0f6044b9b
commit 0463dbf889
7 changed files with 149 additions and 121 deletions

View File

@@ -7,6 +7,8 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "$PROJECT_ROOT/scripts/lib/address-inventory.sh"
source "$PROJECT_ROOT/scripts/lib/ccip-destinations.sh"
# Colors
RED='\033[0;31m'
@@ -20,12 +22,7 @@ log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Load environment variables if .env exists
if [ -f "$PROJECT_ROOT/.env" ]; then
source "$PROJECT_ROOT/.env"
elif [ -f "$PROJECT_ROOT/../.env" ]; then
source "$PROJECT_ROOT/../.env"
fi
load_explorer_runtime_env
# Configuration
RPC_URL="${RPC_URL_138:-http://192.168.11.250:8545}"
@@ -70,10 +67,10 @@ fi
log_info ""
log_info "2. PRIVATE_KEY Configuration"
if [ -z "${PRIVATE_KEY:-}" ]; then
check_fail "PRIVATE_KEY not set in .env file"
log_info " Add to .env: PRIVATE_KEY=0x..."
check_fail "PRIVATE_KEY not available in effective environment"
log_info " Export PRIVATE_KEY=0x... before running"
else
check_pass "PRIVATE_KEY found in .env"
check_pass "PRIVATE_KEY available in effective environment"
# Validate private key format
if ! echo "$PRIVATE_KEY" | grep -qE "^0x[0-9a-fA-F]{64}$"; then
@@ -130,10 +127,10 @@ fi
log_info ""
log_info "5. Contract Deployments"
ROUTER="0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e"
ROUTER="$(resolve_address_value CCIP_ROUTER_ADDRESS CCIP_ROUTER_ADDRESS 0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e)"
SENDER="0x105F8A15b819948a89153505762444Ee9f324684"
WETH9_BRIDGE="0x971cD9D156f193df8051E48043C476e53ECd4693"
WETH10_BRIDGE="0xe0E93247376aa097dB308B92e6Ba36bA015535D0"
WETH9_BRIDGE="$(resolve_address_value CCIPWETH9_BRIDGE CCIPWETH9_BRIDGE 0x971cD9D156f193df8051E48043C476e53ECd4693)"
WETH10_BRIDGE="$(resolve_address_value CCIPWETH10_BRIDGE CCIPWETH10_BRIDGE 0xe0E93247376aa097dB308B92e6Ba36bA015535D0)"
ROUTER_BYTECODE=$(cast code "$ROUTER" --rpc-url "$RPC_URL" 2>/dev/null || echo "")
if [ -n "$ROUTER_BYTECODE" ] && [ "$ROUTER_BYTECODE" != "0x" ]; then
@@ -167,30 +164,19 @@ fi
log_info ""
log_info "6. Destination Address Validation"
declare -A DESTINATIONS=(
["BSC"]="11344663589394136015:0x8078a09637e47fa5ed34f626046ea2094a5cde5e:0x105f8a15b819948a89153505762444ee9f324684"
["Polygon"]="4051577828743386545:0xa780ef19a041745d353c9432f2a7f5a241335ffe:0xdab0591e5e89295ffad75a71dcfc30c5625c4fa2"
["Avalanche"]="6433500567565415381:0x8078a09637e47fa5ed34f626046ea2094a5cde5e:0x105f8a15b819948a89153505762444ee9f324684"
["Base"]="15971525489660198786:0x8078a09637e47fa5ed34f626046ea2094a5cde5e:0x105f8a15b819948a89153505762444ee9f324684"
["Arbitrum"]="4949039107694359620:0x8078a09637e47fa5ed34f626046ea2094a5cde5e:0x105f8a15b819948a89153505762444ee9f324684"
["Optimism"]="3734403246176062136:0x8078a09637e47fa5ed34f626046ea2094a5cde5e:0x105f8a15b819948a89153505762444ee9f324684"
["Ethereum"]="5009297550715157269:0x2A0840e5117683b11682ac46f5CF5621E67269E3:0xb7721dD53A8c629d9f1Ba31a5819AFe250002b03"
)
VALID_DESTINATIONS=0
for CHAIN_NAME in "${!DESTINATIONS[@]}"; do
IFS=':' read -r SELECTOR WETH9_ADDR WETH10_ADDR <<< "${DESTINATIONS[$CHAIN_NAME]}"
TOTAL_DESTINATIONS="$(ccip_destination_count)"
while IFS=$'\t' read -r _chain_name SELECTOR WETH9_ADDR WETH10_ADDR _rpc_url; do
if echo "$WETH9_ADDR" | grep -qE "^0x[0-9a-fA-F]{40}$" && \
echo "$WETH10_ADDR" | grep -qE "^0x[0-9a-fA-F]{40}$"; then
((VALID_DESTINATIONS++)) || true
fi
done
done < <(ccip_destination_rows)
if [ $VALID_DESTINATIONS -eq 7 ]; then
check_pass "All 7 destination addresses valid"
if [ "$VALID_DESTINATIONS" -eq "$TOTAL_DESTINATIONS" ]; then
check_pass "All $TOTAL_DESTINATIONS destination addresses valid"
else
check_fail "Some destination addresses invalid ($VALID_DESTINATIONS/7 valid)"
check_fail "Some destination addresses invalid ($VALID_DESTINATIONS/$TOTAL_DESTINATIONS valid)"
fi
# Check 7: Current Configuration Status
@@ -200,9 +186,7 @@ log_info "7. Current Configuration Status"
WETH9_CONFIGURED=0
WETH10_CONFIGURED=0
for CHAIN_NAME in "${!DESTINATIONS[@]}"; do
IFS=':' read -r SELECTOR WETH9_ADDR WETH10_ADDR <<< "${DESTINATIONS[$CHAIN_NAME]}"
while IFS=$'\t' read -r _chain_name SELECTOR _weth9 _weth10 _rpc_url; do
DEST_WETH9=$(cast call "$WETH9_BRIDGE" "destinations(uint64)" "$SELECTOR" --rpc-url "$RPC_URL" 2>/dev/null || echo "")
DEST_WETH9_CLEAN=$(echo "$DEST_WETH9" | grep -oE "^0x[0-9a-fA-F]{40}$" | head -1 || echo "")
if [ -n "$DEST_WETH9_CLEAN" ] && ! echo "$DEST_WETH9_CLEAN" | grep -qE "^0x0+$"; then
@@ -214,12 +198,12 @@ for CHAIN_NAME in "${!DESTINATIONS[@]}"; do
if [ -n "$DEST_WETH10_CLEAN" ] && ! echo "$DEST_WETH10_CLEAN" | grep -qE "^0x0+$"; then
((WETH10_CONFIGURED++)) || true
fi
done
done < <(ccip_destination_rows)
log_info " WETH9 Bridge: $WETH9_CONFIGURED/7 destinations configured"
log_info " WETH10 Bridge: $WETH10_CONFIGURED/7 destinations configured"
log_info " WETH9 Bridge: $WETH9_CONFIGURED/$TOTAL_DESTINATIONS destinations configured"
log_info " WETH10 Bridge: $WETH10_CONFIGURED/$TOTAL_DESTINATIONS destinations configured"
if [ $WETH9_CONFIGURED -eq 7 ] && [ $WETH10_CONFIGURED -eq 7 ]; then
if [ "$WETH9_CONFIGURED" -eq "$TOTAL_DESTINATIONS" ] && [ "$WETH10_CONFIGURED" -eq "$TOTAL_DESTINATIONS" ]; then
check_pass "All destinations already configured"
elif [ $WETH9_CONFIGURED -gt 0 ] || [ $WETH10_CONFIGURED -gt 0 ]; then
check_warn "Partial configuration ($WETH9_CONFIGURED WETH9, $WETH10_CONFIGURED WETH10)"
@@ -251,7 +235,7 @@ else
log_info ""
log_info "Next steps:"
if [ -z "${PRIVATE_KEY:-}" ]; then
log_info " 1. Add PRIVATE_KEY to .env file"
log_info " 1. Export PRIVATE_KEY before rerunning"
fi
if [ -n "${ACCOUNT:-}" ] && [ -n "${ETH_BALANCE_ETH:-}" ]; then
if (( $(echo "$ETH_BALANCE_ETH < 0.02" | bc -l 2>/dev/null || echo 1) )); then
@@ -260,4 +244,3 @@ else
fi
exit 1
fi