Files
proxmox/scripts/archive/consolidated/deploy/deploy-bridges-direct-cast.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

273 lines
9.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy Phase 3 Bridges using cast send directly (bypassing forge script issues)
# Handles stuck transactions and decimal precision issues
set -euo pipefail
# Load IP configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
# Load environment
set +e
if [ -f "$PROJECT_ROOT/.env" ]; then
source "$PROJECT_ROOT/.env" 2>/dev/null || true
fi
if [ -f "$PROJECT_ROOT/smom-dbis-138/.env" ]; then
source "$PROJECT_ROOT/smom-dbis-138/.env" 2>/dev/null || true
fi
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
log_error() { echo -e "${RED}[✗]${NC} $1"; }
log_section() { echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"; echo -e "${CYAN}$1${NC}"; echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"; }
# Required variables
PRIVATE_KEY="${PRIVATE_KEY:-}"
RPC_URL="${RPC_URL_138:-http://${RPC_CORE_1}:8545}"
CCIP_ROUTER="${CCIP_ROUTER:-0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e}"
CCIP_FEE_TOKEN="${CCIP_FEE_TOKEN:-0xb7721dD53A8c629d9f1Ba31a5819AFe250002b03}"
WETH9_ADDRESS="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
WETH10_ADDRESS="0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9f"
if [ -z "$PRIVATE_KEY" ]; then
log_error "PRIVATE_KEY not found"
exit 1
fi
DEPLOYER=$(cast wallet address "$PRIVATE_KEY" 2>/dev/null || echo "")
if [ -z "$DEPLOYER" ]; then
log_error "Failed to derive deployer address"
exit 1
fi
# Calculate optimal gas price
log_section "Calculate Optimal Gas Price"
GAS_PRICE=$(bash "$PROJECT_ROOT/scripts/calculate-chain138-gas-price.sh" 2>/dev/null || echo "1100000000")
# Check EIP-1559 status
BASE_FEE_HEX=$(cast rpc eth_getBlockByNumber latest false --rpc-url "$RPC_URL" 2>/dev/null | grep -o '"baseFeePerGas":"[^"]*"' | cut -d'"' -f4 || echo "0x0")
BASE_FEE=$(cast --to-dec "$BASE_FEE_HEX" 2>/dev/null || echo "0")
USE_EIP1559=false
if [ "$BASE_FEE" != "0" ] && [ -n "$BASE_FEE_HEX" ] && [ "$BASE_FEE_HEX" != "null" ]; then
USE_EIP1559=true
MAX_FEE="$GAS_PRICE"
AVAILABLE=$((MAX_FEE - BASE_FEE))
PRIORITY_FEE=$((AVAILABLE / 10))
if [ "$PRIORITY_FEE" -lt "10000000" ]; then
PRIORITY_FEE="10000000" # 0.01 gwei minimum
fi
TOTAL=$((BASE_FEE + PRIORITY_FEE))
if [ "$TOTAL" -gt "$MAX_FEE" ]; then
PRIORITY_FEE=$((MAX_FEE - BASE_FEE - 1000000))
fi
log_success "EIP-1559 enabled: Max Fee: $MAX_FEE wei, Priority: $PRIORITY_FEE wei"
else
log_info "Legacy transactions: Gas Price: $GAS_PRICE wei"
fi
cd "$PROJECT_ROOT/smom-dbis-138"
# Build contracts
log_section "Build Contracts"
forge build --force >/dev/null 2>&1 || true
# Deploy WETH9 Bridge
log_section "Deploy WETH9 Bridge via Cast Send"
# Get bytecode
BYTECODE=$(forge inspect contracts/ccip/CCIPWETH9Bridge.sol:CCIPWETH9Bridge bytecode 2>/dev/null || echo "")
if [ -z "$BYTECODE" ]; then
log_error "Failed to get WETH9 Bridge bytecode"
exit 1
fi
# Encode constructor: constructor(address router, address weth9, address feeToken)
CONSTRUCTOR_ARGS=$(cast abi-encode "constructor(address,address,address)" "$CCIP_ROUTER" "$WETH9_ADDRESS" "$CCIP_FEE_TOKEN" 2>/dev/null || echo "")
if [ -z "$CONSTRUCTOR_ARGS" ]; then
log_error "Failed to encode constructor arguments"
exit 1
fi
# Combine bytecode and constructor args
DEPLOY_BYTECODE="${BYTECODE}${CONSTRUCTOR_ARGS#0x}"
# Get current nonce
NONCE=$(cast nonce "$DEPLOYER" --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
log_info "Using nonce: $NONCE"
# Estimate gas
GAS_LIMIT=$(cast estimate --create "$DEPLOY_BYTECODE" --rpc-url "$RPC_URL" 2>/dev/null || echo "3000000")
log_info "Estimated gas: $GAS_LIMIT"
# Deploy using cast send
log_info "Deploying WETH9 Bridge..."
if [ "$USE_EIP1559" = true ]; then
TX_OUTPUT=$(cast send --create "$DEPLOY_BYTECODE" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--gas "$GAS_LIMIT" \
--max-fee-per-gas "$MAX_FEE" \
--priority-fee-per-gas "$PRIORITY_FEE" \
--nonce "$NONCE" \
-vv 2>&1 || true)
else
TX_OUTPUT=$(cast send --create "$DEPLOY_BYTECODE" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--gas "$GAS_LIMIT" \
--gas-price "$GAS_PRICE" \
--nonce "$NONCE" \
--legacy \
-vv 2>&1 || true)
fi
echo "$TX_OUTPUT"
# Extract contract address
WETH9_BRIDGE=$(echo "$TX_OUTPUT" | grep -oE "contractAddress[[:space:]]+0x[0-9a-fA-F]{40}" | awk '{print $2}' || echo "")
if [ -z "$WETH9_BRIDGE" ]; then
WETH9_BRIDGE=$(echo "$TX_OUTPUT" | grep -oE "0x[0-9a-fA-F]{40}" | head -1 || echo "")
fi
if [ -n "$WETH9_BRIDGE" ]; then
log_success "WETH9 Bridge deployed at: $WETH9_BRIDGE"
# Wait and verify
sleep 5
CODE_SIZE=$(cast code "$WETH9_BRIDGE" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 1000 ]; then
log_success "Verification: Contract deployed ($CODE_SIZE bytes)"
else
log_warn "Verification: Code size small ($CODE_SIZE bytes) - may still be deploying"
fi
else
log_error "Could not extract WETH9 Bridge address"
TX_HASH=$(echo "$TX_OUTPUT" | grep -oE "0x[0-9a-fA-F]{64}" | head -1 || echo "")
if [ -n "$TX_HASH" ]; then
log_info "Transaction hash: $TX_HASH"
log_info "Check transaction status with: cast tx $TX_HASH --rpc-url $RPC_URL"
fi
fi
# Deploy WETH10 Bridge
log_section "Deploy WETH10 Bridge via Cast Send"
# Get bytecode
BYTECODE=$(forge inspect contracts/ccip/CCIPWETH10Bridge.sol:CCIPWETH10Bridge bytecode 2>/dev/null || echo "")
if [ -z "$BYTECODE" ]; then
log_error "Failed to get WETH10 Bridge bytecode"
exit 1
fi
# Encode constructor: constructor(address router, address weth10, address feeToken)
CONSTRUCTOR_ARGS=$(cast abi-encode "constructor(address,address,address)" "$CCIP_ROUTER" "$WETH10_ADDRESS" "$CCIP_FEE_TOKEN" 2>/dev/null || echo "")
if [ -z "$CONSTRUCTOR_ARGS" ]; then
log_error "Failed to encode constructor arguments"
exit 1
fi
# Combine bytecode and constructor args
DEPLOY_BYTECODE="${BYTECODE}${CONSTRUCTOR_ARGS#0x}"
# Get next nonce
NONCE=$(cast nonce "$DEPLOYER" --rpc-url "$RPC_URL" 2>/dev/null || echo "$((NONCE + 1))")
log_info "Using nonce: $NONCE"
# Estimate gas
GAS_LIMIT=$(cast estimate --create "$DEPLOY_BYTECODE" --rpc-url "$RPC_URL" 2>/dev/null || echo "3000000")
log_info "Estimated gas: $GAS_LIMIT"
# Deploy using cast send
log_info "Deploying WETH10 Bridge..."
if [ "$USE_EIP1559" = true ]; then
TX_OUTPUT=$(cast send --create "$DEPLOY_BYTECODE" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--gas "$GAS_LIMIT" \
--max-fee-per-gas "$MAX_FEE" \
--priority-fee-per-gas "$PRIORITY_FEE" \
--nonce "$NONCE" \
-vv 2>&1 || true)
else
TX_OUTPUT=$(cast send --create "$DEPLOY_BYTECODE" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--gas "$GAS_LIMIT" \
--gas-price "$GAS_PRICE" \
--nonce "$NONCE" \
--legacy \
-vv 2>&1 || true)
fi
echo "$TX_OUTPUT"
# Extract contract address
WETH10_BRIDGE=$(echo "$TX_OUTPUT" | grep -oE "contractAddress[[:space:]]+0x[0-9a-fA-F]{40}" | awk '{print $2}' || echo "")
if [ -z "$WETH10_BRIDGE" ]; then
WETH10_BRIDGE=$(echo "$TX_OUTPUT" | grep -oE "0x[0-9a-fA-F]{40}" | head -1 || echo "")
fi
if [ -n "$WETH10_BRIDGE" ]; then
log_success "WETH10 Bridge deployed at: $WETH10_BRIDGE"
# Wait and verify
sleep 5
CODE_SIZE=$(cast code "$WETH10_BRIDGE" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 1000 ]; then
log_success "Verification: Contract deployed ($CODE_SIZE bytes)"
else
log_warn "Verification: Code size small ($CODE_SIZE bytes) - may still be deploying"
fi
else
log_error "Could not extract WETH10 Bridge address"
TX_HASH=$(echo "$TX_OUTPUT" | grep -oE "0x[0-9a-fA-F]{64}" | head -1 || echo "")
if [ -n "$TX_HASH" ]; then
log_info "Transaction hash: $TX_HASH"
log_info "Check transaction status with: cast tx $TX_HASH --rpc-url $RPC_URL"
fi
fi
# Summary
log_section "Deployment Summary"
if [ -n "$WETH9_BRIDGE" ]; then
log_success "✓ WETH9 Bridge: $WETH9_BRIDGE"
else
log_error "✗ WETH9 Bridge: Deployment failed"
fi
if [ -n "$WETH10_BRIDGE" ]; then
log_success "✓ WETH10 Bridge: $WETH10_BRIDGE"
else
log_error "✗ WETH10 Bridge: Deployment failed"
fi
if [ -n "$WETH9_BRIDGE" ] && [ -n "$WETH10_BRIDGE" ]; then
log_success "\nPhase 3.2 Bridge Deployment Complete!"
log_info "\nNext steps:"
log_info "1. Configure destinations (Phase 3.4)"
log_info "2. Deploy CREATE2 LINK (if needed)"
log_info "3. Test bidirectional transfers (Phase 3.5)"
exit 0
else
log_error "\nPhase 3.2 Bridge Deployment Incomplete"
exit 1
fi