Files
proxmox/scripts/archive/consolidated/deploy/deploy-phase3-bridges-besu-complete.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

293 lines
10 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy Phase 3 Bridge Contracts - Complete Besu Pre-Flight Checks
# Handles EIP-1559 (London fork), QBFT consensus, permissioning checks
#
# Usage:
# ./scripts/deploy-phase3-bridges-besu-complete.sh
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"
# 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"; }
# Load environment
if [ -f "$PROJECT_ROOT/.env" ]; then
set +e
source "$PROJECT_ROOT/.env" 2>/dev/null || true
set -e
fi
if [ -f "$PROJECT_ROOT/smom-dbis-138/.env" ]; then
set +e
source "$PROJECT_ROOT/smom-dbis-138/.env" 2>/dev/null || true
set -e
fi
# Required variables
PRIVATE_KEY="${PRIVATE_KEY:-}"
RPC_URL="${RPC_URL_138:-http://${RPC_CORE_1}:8545}"
CCIP_ROUTER="${CCIP_ROUTER:-}"
CCIP_FEE_TOKEN="${CCIP_FEE_TOKEN:-}"
# Validate required variables
if [ -z "$PRIVATE_KEY" ]; then
log_error "PRIVATE_KEY not found in environment"
exit 1
fi
if [ -z "$CCIP_ROUTER" ]; then
log_error "CCIP_ROUTER not found in environment"
exit 1
fi
if [ -z "$CCIP_FEE_TOKEN" ]; then
log_error "CCIP_FEE_TOKEN not found in environment"
exit 1
fi
DEPLOYER=$(cast wallet address "$PRIVATE_KEY" 2>/dev/null || echo "")
if [ -z "$DEPLOYER" ]; then
log_error "Failed to derive deployer address from private key"
exit 1
fi
log_section "Besu Network Pre-Flight Checks"
# 1. Check RPC connectivity
log_info "1. Checking RPC connectivity..."
CHAIN_ID=$(cast chain-id --rpc-url "$RPC_URL" 2>/dev/null || echo "")
if [ -z "$CHAIN_ID" ]; then
log_error "Cannot connect to RPC endpoint: $RPC_URL"
exit 1
fi
log_success "RPC connected - Chain ID: $CHAIN_ID"
# 2. Check if blocks are being produced
log_info "2. Checking block production..."
BLOCK1=$(cast block-number --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
sleep 3
BLOCK2=$(cast block-number --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
if [ "$BLOCK2" -gt "$BLOCK1" ]; then
log_success "Blocks are being produced (Block $BLOCK1 -> $BLOCK2)"
else
log_warn "Block production may be stalled (Block: $BLOCK1)"
fi
# 3. Check EIP-1559 (London fork) status
log_info "3. Checking EIP-1559 (London fork) status..."
BASE_FEE=$(cast rpc eth_getBlockByNumber latest false --rpc-url "$RPC_URL" 2>/dev/null | grep -o '"baseFeePerGas":"[^"]*"' | cut -d'"' -f4 || echo "")
if [ -n "$BASE_FEE" ] && [ "$BASE_FEE" != "null" ] && [ "$BASE_FEE" != "0x" ]; then
BASE_FEE_DEC=$(cast --to-dec "0x$BASE_FEE" 2>/dev/null || echo "$BASE_FEE")
log_success "EIP-1559 enabled - baseFeePerGas: $BASE_FEE_DEC wei"
USE_EIP1559=true
else
log_info "EIP-1559 not enabled - using legacy transactions"
USE_EIP1559=false
fi
# 4. Check deployer balance
log_info "4. Checking deployer balance..."
BALANCE=$(cast balance "$DEPLOYER" --rpc-url "$RPC_URL" 2>/dev/null || echo "0")
BALANCE_ETH=$(echo "scale=4; $BALANCE / 1000000000000000000" | bc 2>/dev/null || echo "0")
if [ "$BALANCE" -gt "1000000000000000000" ]; then
log_success "Deployer balance: $BALANCE_ETH ETH"
else
log_error "Insufficient deployer balance: $BALANCE_ETH ETH"
exit 1
fi
# 5. Calculate optimal gas price
log_info "5. Calculating optimal gas price..."
GAS_PRICE=$(bash "$PROJECT_ROOT/scripts/calculate-chain138-gas-price.sh" 2>/dev/null || echo "1100000000")
# For EIP-1559: maxFeePerGas should be higher than baseFeePerGas + priorityFeePerGas
if [ "$USE_EIP1559" = true ]; then
# Use calculated gas price as maxFeePerGas
MAX_FEE_PER_GAS="$GAS_PRICE"
# Get base fee from latest block
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_DEC=$(cast --to-dec "$BASE_FEE_HEX" 2>/dev/null || echo "7")
# Calculate available fee space: maxFee - baseFee
AVAILABLE_FEE=$((MAX_FEE_PER_GAS - BASE_FEE_DEC))
# Priority fee: 10% of available fee space (but minimum 0.01 gwei = 10,000,000 wei)
# This ensures priority fee doesn't exceed max fee
PRIORITY_FEE=$((AVAILABLE_FEE / 10))
MIN_PRIORITY="10000000" # 0.01 gwei minimum
if [ "$PRIORITY_FEE" -lt "$MIN_PRIORITY" ]; then
PRIORITY_FEE="$MIN_PRIORITY"
fi
# Verify: priority fee + base fee <= max fee
TOTAL_CHECK=$((BASE_FEE_DEC + PRIORITY_FEE))
if [ "$TOTAL_CHECK" -gt "$MAX_FEE_PER_GAS" ]; then
# Adjust priority fee to fit within max fee
PRIORITY_FEE=$((MAX_FEE_PER_GAS - BASE_FEE_DEC - 1000000)) # Leave small buffer
if [ "$PRIORITY_FEE" -lt "$MIN_PRIORITY" ]; then
PRIORITY_FEE="$MIN_PRIORITY"
fi
fi
log_success "EIP-1559 gas settings:"
log_info " Base Fee Per Gas: $BASE_FEE_DEC wei ($(echo "scale=9; $BASE_FEE_DEC / 1000000000" | bc 2>/dev/null || echo "0.000000007") gwei)"
log_info " Max Fee Per Gas: $MAX_FEE_PER_GAS wei ($(echo "scale=2; $MAX_FEE_PER_GAS / 1000000000" | bc 2>/dev/null || echo "1.1") gwei)"
log_info " Priority Fee: $PRIORITY_FEE wei ($(echo "scale=9; $PRIORITY_FEE / 1000000000" | bc 2>/dev/null || echo "0.11") gwei)"
log_info " Total: $((BASE_FEE_DEC + PRIORITY_FEE)) wei ($(echo "scale=2; ($BASE_FEE_DEC + $PRIORITY_FEE) / 1000000000" | bc 2>/dev/null || echo "1.11") gwei) <= Max: $MAX_FEE_PER_GAS wei ✓"
else
log_success "Legacy gas price: $GAS_PRICE wei ($(echo "scale=2; $GAS_PRICE / 1000000000" | bc 2>/dev/null || echo "1.1") gwei)"
fi
# 6. Check account permissioning (if txpool API available)
log_info "6. Checking account permissioning..."
TXPOOL_STATUS=$(cast rpc txpool_status --rpc-url "$RPC_URL" 2>/dev/null || echo "")
if [ -n "$TXPOOL_STATUS" ]; then
log_success "TxPool API available - account permissioning check passed"
else
log_info "TxPool API not available - assuming no account-level permissioning"
fi
log_section "Deploy WETH9 Bridge"
cd "$PROJECT_ROOT/smom-dbis-138"
if [ "$USE_EIP1559" = true ]; then
log_info "Deploying with EIP-1559 format..."
DEPLOY_OUTPUT=$(forge script script/DeployCCIPWETH9Bridge.s.sol:DeployCCIPWETH9Bridge \
--rpc-url "$RPC_URL" \
--broadcast \
--private-key "$PRIVATE_KEY" \
--with-gas-price "$MAX_FEE_PER_GAS" \
--priority-gas-price "$PRIORITY_FEE" \
--slow \
-vvv 2>&1 || true)
else
log_info "Deploying with legacy format..."
DEPLOY_OUTPUT=$(forge script script/DeployCCIPWETH9Bridge.s.sol:DeployCCIPWETH9Bridge \
--rpc-url "$RPC_URL" \
--broadcast \
--private-key "$PRIVATE_KEY" \
--with-gas-price "$GAS_PRICE" \
--legacy \
--slow \
-vvv 2>&1 || true)
fi
echo "$DEPLOY_OUTPUT" | tail -30
# Extract deployed address
WETH9_BRIDGE=$(echo "$DEPLOY_OUTPUT" | grep -oP "CCIPWETH9Bridge deployed at: \K0x[a-fA-F0-9]+" | tail -1 || echo "")
if [ -z "$WETH9_BRIDGE" ]; then
WETH9_BRIDGE=$(echo "$DEPLOY_OUTPUT" | grep -oP "0x[a-fA-F0-9]{40}" | tail -1 || echo "")
fi
if [ -n "$WETH9_BRIDGE" ]; then
log_success "WETH9 Bridge deployed at: $WETH9_BRIDGE"
# Verify deployment
sleep 2
CODE_SIZE=$(cast code "$WETH9_BRIDGE" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 100 ]; then
log_success "Verification: Contract code deployed ($CODE_SIZE bytes)"
else
log_warn "Verification: Contract code size seems small ($CODE_SIZE bytes)"
fi
else
log_error "Could not extract WETH9 Bridge address"
log_info "Check deployment output above for errors"
fi
log_section "Deploy WETH10 Bridge"
if [ "$USE_EIP1559" = true ]; then
DEPLOY_OUTPUT=$(forge script script/DeployCCIPWETH10Bridge.s.sol:DeployCCIPWETH10Bridge \
--rpc-url "$RPC_URL" \
--broadcast \
--private-key "$PRIVATE_KEY" \
--with-gas-price "$MAX_FEE_PER_GAS" \
--priority-gas-price "$PRIORITY_FEE" \
--slow \
-vvv 2>&1 || true)
else
DEPLOY_OUTPUT=$(forge script script/DeployCCIPWETH10Bridge.s.sol:DeployCCIPWETH10Bridge \
--rpc-url "$RPC_URL" \
--broadcast \
--private-key "$PRIVATE_KEY" \
--with-gas-price "$GAS_PRICE" \
--legacy \
--slow \
-vvv 2>&1 || true)
fi
echo "$DEPLOY_OUTPUT" | tail -30
WETH10_BRIDGE=$(echo "$DEPLOY_OUTPUT" | grep -oP "CCIPWETH10Bridge deployed at: \K0x[a-fA-F0-9]+" | tail -1 || echo "")
if [ -z "$WETH10_BRIDGE" ]; then
WETH10_BRIDGE=$(echo "$DEPLOY_OUTPUT" | grep -oP "0x[a-fA-F0-9]{40}" | tail -1 || echo "")
fi
if [ -n "$WETH10_BRIDGE" ]; then
log_success "WETH10 Bridge deployed at: $WETH10_BRIDGE"
# Verify deployment
sleep 2
CODE_SIZE=$(cast code "$WETH10_BRIDGE" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 100 ]; then
log_success "Verification: Contract code deployed ($CODE_SIZE bytes)"
else
log_warn "Verification: Contract code size seems small ($CODE_SIZE bytes)"
fi
else
log_error "Could not extract WETH10 Bridge address"
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
log_info ""
log_info "Next 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)"
if [ -n "$WETH9_BRIDGE" ] && [ -n "$WETH10_BRIDGE" ]; then
log_success "\nPhase 3.2 Bridge Deployment Complete!"
exit 0
else
log_error "\nPhase 3.2 Bridge Deployment Incomplete - Check errors above"
exit 1
fi