Files
proxmox/scripts/phase1-check-bridge-event-logs.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

172 lines
6.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Phase 1.2: Check Event Logs for Existing Bridge Configuration
# This script checks for DestinationAdded events on ChainID 138 bridges
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)"
# 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_detail() { echo -e "${CYAN}[DETAIL]${NC} $1"; }
log_section() { echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"; echo -e "${CYAN}$1${NC}"; echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"; }
# Configuration from resolution plan
CHAIN138_RPC="http://${RPC_CORE_1}:8545"
WETH9_BRIDGE="0x3304b747E565a97ec8AC220b0B6A1f6ffDB837e6"
WETH10_BRIDGE="0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e"
MAINNET_SELECTOR="5009297550715157269"
log_section "Phase 1.2: Check Event Logs for Existing Configuration"
log_info "Configuration:"
log_info " ChainID 138 RPC: $CHAIN138_RPC"
log_info " WETH9 Bridge: $WETH9_BRIDGE"
log_info " WETH10 Bridge: $WETH10_BRIDGE"
log_info " Mainnet Chain Selector: $MAINNET_SELECTOR"
log_info ""
# Check if cast is available
if ! command -v cast &> /dev/null; then
log_error "cast command not found. Please install foundry."
exit 1
fi
# Test RPC connection
log_info "Testing RPC connection..."
CHAIN_ID=$(cast chain-id --rpc-url "$CHAIN138_RPC" 2>/dev/null || echo "")
if [ -z "$CHAIN_ID" ]; then
log_error "Failed to connect to RPC endpoint: $CHAIN138_RPC"
log_warn "Trying alternative RPC: http://${RPC_PUBLIC_1:-192.168.11.221}:8545"
CHAIN138_RPC="http://${RPC_PUBLIC_1:-192.168.11.221}:8545"
CHAIN_ID=$(cast chain-id --rpc-url "$CHAIN138_RPC" 2>/dev/null || echo "")
if [ -z "$CHAIN_ID" ]; then
log_error "Failed to connect to alternative RPC endpoint"
exit 1
fi
log_info "Using alternative RPC: $CHAIN138_RPC"
fi
log_success "RPC connection successful (ChainID: $CHAIN_ID)"
log_info ""
# Get latest block number
log_info "Getting latest block number..."
LATEST_BLOCK=$(cast block-number --rpc-url "$CHAIN138_RPC" 2>/dev/null || echo "0")
log_info "Latest block: $LATEST_BLOCK"
log_info ""
# Function to check events for a bridge
check_bridge_events() {
local BRIDGE_ADDRESS=$1
local BRIDGE_NAME=$2
log_section "Checking $BRIDGE_NAME Bridge Events"
log_info "Bridge Address: $BRIDGE_ADDRESS"
log_info "Searching for DestinationAdded events from block 0 to $LATEST_BLOCK..."
log_info ""
# Get events
# Event signature: DestinationAdded(uint64,address)
EVENT_SIG="0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0" # keccak256("DestinationAdded(uint64,address)") first 4 bytes
# Note: cast logs requires the full event signature with indexed params
log_info "Querying DestinationAdded events..."
# Try to get events using cast logs
# DestinationAdded(uint64 indexed chainSelector, address indexed receiverBridge)
EVENTS=$(cast logs \
--from-block 0 \
--to-block "$LATEST_BLOCK" \
--address "$BRIDGE_ADDRESS" \
"DestinationAdded(uint64,address)" \
--rpc-url "$CHAIN138_RPC" 2>&1 || echo "")
if echo "$EVENTS" | grep -qE "error|Error|ERROR"; then
log_warn "Error querying events (this is expected if function doesn't exist)"
log_detail "Error output: $EVENTS"
log_info ""
return 1
fi
if [ -z "$EVENTS" ] || [ "$EVENTS" = "[]" ]; then
log_warn "No DestinationAdded events found for $BRIDGE_NAME bridge"
log_info "This means destinations may not be configured via events"
log_info ""
return 1
fi
# Parse events if found
log_success "Events found for $BRIDGE_NAME bridge:"
echo "$EVENTS" | jq -r '.[] | "Block: \(.blockNumber) | Chain Selector: \(.topics[1]) | Receiver Bridge: \(.topics[2])"' 2>/dev/null || echo "$EVENTS"
log_info ""
# Check if Mainnet selector is in events
if echo "$EVENTS" | grep -qi "$MAINNET_SELECTOR"; then
log_success "✓ Mainnet destination found in events for $BRIDGE_NAME bridge!"
return 0
else
log_warn "Mainnet destination not found in events for $BRIDGE_NAME bridge"
return 1
fi
}
# Check both bridges
WETH9_EVENTS_FOUND=0
WETH10_EVENTS_FOUND=0
check_bridge_events "$WETH9_BRIDGE" "WETH9" && WETH9_EVENTS_FOUND=1 || WETH9_EVENTS_FOUND=0
check_bridge_events "$WETH10_BRIDGE" "WETH10" && WETH10_EVENTS_FOUND=1 || WETH10_EVENTS_FOUND=0
# Summary
log_section "Phase 1.2 Summary - Event Log Analysis"
if [ "$WETH9_EVENTS_FOUND" -eq 1 ] && [ "$WETH10_EVENTS_FOUND" -eq 1 ]; then
log_success "✓ Both bridges have DestinationAdded events with Mainnet selector"
log_success "Conclusion: Destinations may already be configured!"
log_info ""
log_info "Next Step: Proceed to Phase 1.1 to test actual bridge transfer"
echo "EVENT_STATUS=CONFIGURED" > "$PROJECT_ROOT/.phase1-event-status"
elif [ "$WETH9_EVENTS_FOUND" -eq 1 ] || [ "$WETH10_EVENTS_FOUND" -eq 1 ]; then
log_warn "⚠ Partial configuration detected"
if [ "$WETH9_EVENTS_FOUND" -eq 1 ]; then
log_info " - WETH9 bridge: Events found"
else
log_warn " - WETH9 bridge: No events"
fi
if [ "$WETH10_EVENTS_FOUND" -eq 1 ]; then
log_info " - WETH10 bridge: Events found"
else
log_warn " - WETH10 bridge: No events"
fi
echo "EVENT_STATUS=PARTIAL" > "$PROJECT_ROOT/.phase1-event-status"
else
log_warn "⚠ No DestinationAdded events found for either bridge"
log_info "This suggests:"
log_info " 1. Destinations were not configured via events, OR"
log_info " 2. Events were emitted before current block range, OR"
log_info " 3. Contract uses different event signature"
log_info ""
log_info "Next Step: Proceed to Phase 1.1 to test if bridge works anyway"
echo "EVENT_STATUS=NOT_FOUND" > "$PROJECT_ROOT/.phase1-event-status"
fi
log_info ""
log_success "Phase 1.2 Complete - Event log analysis saved to .phase1-event-status"