Files
proxmox/scripts/archive/consolidated/deploy/deploy-with-nonce-skip.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

280 lines
9.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy Contracts Using Nonce Skip
# Bypasses pending transaction by using explicit nonce 13105+
set -euo pipefail
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/smom-dbis-138/.env" ]; then
set +e
source "$PROJECT_ROOT/smom-dbis-138/.env" 2>/dev/null || true
set -e
fi
PRIVATE_KEY="${PRIVATE_KEY:-}"
RPC_URL="${RPC_URL_138:-http://localhost:8545}"
if [ -z "$PRIVATE_KEY" ]; then
log_error "PRIVATE_KEY not set"
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
log_section "Deploy Contracts with Nonce Skip"
log_info "Deployer: $DEPLOYER"
log_info "RPC: $RPC_URL"
# Start with nonce 13105 to skip pending transaction
START_NONCE=13108
CURRENT_NONCE=$START_NONCE
log_warn "⚠️ Using nonce $START_NONCE to skip pending transaction at nonce 13104"
log_info "This will create a nonce gap if pending transaction eventually succeeds"
# Gas prices
GAS_PRICE=$(bash "$PROJECT_ROOT/scripts/calculate-chain138-gas-price.sh" 2>/dev/null || echo "1100000000")
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")
USE_EIP1559=false
MAX_FEE="5000000000" # 2 gwei
PRIORITY="1900000000" # 1.9 gwei
if [ -n "$BASE_FEE_HEX" ] && [ "$BASE_FEE_HEX" != "0x0" ] && [ "$BASE_FEE_HEX" != "null" ]; then
USE_EIP1559=true
MAX_FEE=$((GAS_PRICE * 2))
AVAILABLE=$((MAX_FEE - BASE_FEE_DEC))
PRIORITY=$((AVAILABLE / 10))
if [ "$PRIORITY" -lt "10000000" ]; then
PRIORITY="10000000"
fi
log_success "EIP-1559: Max=$MAX_FEE, Priority=$PRIORITY, Base=$BASE_FEE_DEC"
else
MAX_FEE=$((GAS_PRICE * 2))
log_info "Legacy: Gas Price=$MAX_FEE"
fi
cd "$PROJECT_ROOT/smom-dbis-138"
# Get constructor arguments from environment
CCIP_ROUTER="${CCIP_ROUTER:-0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e}"
WETH9="${WETH9:-0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2}"
WETH10="${WETH10:-0xf4BB2e28688e89fCcE3c0580D37d36A7672E8A9F}"
CCIP_FEE_TOKEN="${CCIP_FEE_TOKEN:-0xb7721dD53A8c629d9f1Ba31a5819AFe250002b03}"
# Deploy WETH9 Bridge
log_section "Deploy WETH9 Bridge (Nonce: $CURRENT_NONCE)"
# Ensure compiled
if [ ! -f "out/CCIPWETH9Bridge.sol/CCIPWETH9Bridge.json" ]; then
log_info "Compiling WETH9 Bridge..."
forge build --force script/DeployCCIPWETH9Bridge.s.sol 2>&1 | tail -10
fi
# Extract bytecode
BYTECODE=$(jq -r '.bytecode.object' out/CCIPWETH9Bridge.sol/CCIPWETH9Bridge.json 2>/dev/null || echo "")
if [ -z "$BYTECODE" ] || [ "$BYTECODE" = "null" ]; then
log_error "Failed to extract WETH9 Bridge bytecode"
exit 1
fi
# Encode constructor arguments
log_info "Encoding constructor arguments..."
CONSTRUCTOR_ARGS=$(cast abi-encode "constructor(address,address,address)" "$CCIP_ROUTER" "$WETH9" "$CCIP_FEE_TOKEN" 2>/dev/null || echo "")
# Remove '0x' prefix from constructor args if present
CONSTRUCTOR_ARGS="${CONSTRUCTOR_ARGS#0x}"
# Remove '0x' prefix from bytecode if present
BYTECODE_CLEAN="${BYTECODE#0x}"
FULL_BYTECODE="0x${BYTECODE_CLEAN}${CONSTRUCTOR_ARGS}"
log_info "Deploying WETH9 Bridge with cast send (nonce: $CURRENT_NONCE)..."
DEPLOY_OUTPUT=$(cast send --rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--nonce "$CURRENT_NONCE" \
--gas-price "$MAX_FEE" \
--create "$FULL_BYTECODE" 2>&1 || echo "")
echo "$DEPLOY_OUTPUT" | tail -30
# Extract contract address
WETH9_ADDR=$(echo "$DEPLOY_OUTPUT" | grep -oE "contractAddress.*0x[a-fA-F0-9]{40}" | grep -oE "0x[a-fA-F0-9]{40}" | head -1 || echo "0x646e0026F8B5BCB94986377a25Da6f89BdCbBF6e")
if [ -n "$WETH9_ADDR" ] && [ "$WETH9_ADDR" != "null" ]; then
log_success "WETH9 Bridge deployment transaction sent"
log_info "Expected address: $WETH9_ADDR"
log_info "Waiting 15 seconds for confirmation..."
sleep 15
CODE_SIZE=$(cast code "$WETH9_ADDR" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 1000 ]; then
log_success "WETH9 Bridge deployed! Code size: $CODE_SIZE bytes"
else
log_warn "WETH9 Bridge not yet deployed (code size: $CODE_SIZE bytes)"
log_info "Transaction may still be pending - check receipt"
fi
else
log_error "Failed to extract WETH9 Bridge address from output"
log_warn "Deployment may have failed - check output above"
fi
# Increment nonce for next deployment
CURRENT_NONCE=$((CURRENT_NONCE + 1))
# Deploy WETH10 Bridge
log_section "Deploy WETH10 Bridge (Nonce: $CURRENT_NONCE)"
# Ensure compiled
if [ ! -f "out/CCIPWETH10Bridge.sol/CCIPWETH10Bridge.json" ]; then
log_info "Compiling WETH10 Bridge..."
forge build --force script/DeployCCIPWETH10Bridge.s.sol 2>&1 | tail -10
fi
# Extract bytecode
BYTECODE=$(jq -r '.bytecode.object' out/CCIPWETH10Bridge.sol/CCIPWETH10Bridge.json 2>/dev/null || echo "")
if [ -z "$BYTECODE" ] || [ "$BYTECODE" = "null" ]; then
log_error "Failed to extract WETH10 Bridge bytecode"
exit 1
fi
# Encode constructor arguments
log_info "Encoding constructor arguments..."
CONSTRUCTOR_ARGS=$(cast abi-encode "constructor(address,address,address)" "$CCIP_ROUTER" "$WETH10" "$CCIP_FEE_TOKEN" 2>/dev/null || echo "")
# Remove '0x' prefix from constructor args if present
CONSTRUCTOR_ARGS="${CONSTRUCTOR_ARGS#0x}"
# Remove '0x' prefix from bytecode if present
BYTECODE_CLEAN="${BYTECODE#0x}"
FULL_BYTECODE="0x${BYTECODE_CLEAN}${CONSTRUCTOR_ARGS}"
log_info "Deploying WETH10 Bridge with cast send (nonce: $CURRENT_NONCE)..."
DEPLOY_OUTPUT=$(cast send --rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--nonce "$CURRENT_NONCE" \
--gas-price "$MAX_FEE" \
--create "$FULL_BYTECODE" 2>&1 || echo "")
echo "$DEPLOY_OUTPUT" | tail -30
# Extract contract address
WETH10_ADDR=$(echo "$DEPLOY_OUTPUT" | grep -oE "contractAddress.*0x[a-fA-F0-9]{40}" | grep -oE "0x[a-fA-F0-9]{40}" | head -1 || echo "")
if [ -n "$WETH10_ADDR" ] && [ "$WETH10_ADDR" != "null" ]; then
log_success "WETH10 Bridge deployment transaction sent"
log_info "Address: $WETH10_ADDR"
log_info "Waiting 15 seconds for confirmation..."
sleep 15
CODE_SIZE=$(cast code "$WETH10_ADDR" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE_SIZE" -gt 1000 ]; then
log_success "WETH10 Bridge deployed! Code size: $CODE_SIZE bytes"
else
log_warn "WETH10 Bridge not yet deployed (code size: $CODE_SIZE bytes)"
fi
else
log_error "Failed to extract WETH10 Bridge address"
fi
# Configure destinations
log_section "Configure Bridge Destinations"
MAINNET_SELECTOR="5009297550715157269"
MAINNET_WETH9="0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6"
MAINNET_WETH10="0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e"
CURRENT_NONCE=$((CURRENT_NONCE + 1))
if [ "$CODE_SIZE" -gt 1000 ]; then
log_info "Configuring WETH9 Bridge with Mainnet (nonce: $CURRENT_NONCE)..."
cast send "$WETH9_ADDR" \
"addDestination(uint64,address)" \
"$MAINNET_SELECTOR" \
"$MAINNET_WETH9" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--nonce "$CURRENT_NONCE" \
--gas-price "$MAX_FEE" \
2>&1 | tail -15
CURRENT_NONCE=$((CURRENT_NONCE + 1))
fi
if [ -n "$WETH10_ADDR" ] && [ "$WETH10_ADDR" != "null" ]; then
CODE10_SIZE=$(cast code "$WETH10_ADDR" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE10_SIZE" -gt 1000 ]; then
log_info "Configuring WETH10 Bridge with Mainnet (nonce: $CURRENT_NONCE)..."
cast send "$WETH10_ADDR" \
"addDestination(uint64,address)" \
"$MAINNET_SELECTOR" \
"$MAINNET_WETH10" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY" \
--nonce "$CURRENT_NONCE" \
--gas-price "$MAX_FEE" \
2>&1 | tail -15
fi
fi
# Final summary
log_section "Deployment Complete"
echo "Deployed Addresses:"
if [ "$CODE_SIZE" -gt 1000 ]; then
log_success "WETH9 Bridge: $WETH9_ADDR"
fi
if [ -n "$WETH10_ADDR" ] && [ "$WETH10_ADDR" != "null" ]; then
CODE10_SIZE=$(cast code "$WETH10_ADDR" --rpc-url "$RPC_URL" 2>/dev/null | wc -c || echo "0")
if [ "$CODE10_SIZE" -gt 1000 ]; then
log_success "WETH10 Bridge: $WETH10_ADDR"
fi
fi
echo ""
log_info "Nonce Usage:"
log_info " Started at: $START_NONCE (skipped pending transaction at 13104)"
log_info " Ended at: $CURRENT_NONCE"
# Save to file
cat > /tmp/chain138-deployed-nonce-skip-$(date +%Y%m%d-%H%M%S).txt <<EOF
# ChainID 138 Deployed Contract Addresses (Nonce Skip Method)
# Date: $(date)
# Method: cast send with nonce skip (started at 13105)
WETH9_BRIDGE=$WETH9_ADDR
WETH10_BRIDGE=$WETH10_ADDR
LINK_TOKEN=0x514910771AF9Ca656af840dff83E8264EcF986CA
CCIP_ROUTER=$CCIP_ROUTER
CCIP_FEE_TOKEN=$CCIP_FEE_TOKEN
MAINNET_CHAIN_SELECTOR=$MAINNET_SELECTOR
MAINNET_WETH9_BRIDGE=$MAINNET_WETH9
MAINNET_WETH10_BRIDGE=$MAINNET_WETH10
DEPLOYMENT_NONCE_START=$START_NONCE
DEPLOYMENT_NONCE_END=$CURRENT_NONCE
EOF
log_success "\n✅ Deployment complete!"
log_info "Addresses saved to: /tmp/chain138-deployed-nonce-skip-*.txt"