#!/bin/bash # Pre-Run Validation Script # Validates environment before starting MEV bot set -e echo "=========================================" echo "MEV Bot Pre-Run Validation" echo "=========================================" ERRORS=0 # Check RPC endpoints echo "[1/5] Checking RPC endpoints..." if [ -z "$ARBITRUM_RPC_ENDPOINT" ]; then echo "❌ ARBITRUM_RPC_ENDPOINT not set" ERRORS=$((ERRORS + 1)) else echo "✅ ARBITRUM_RPC_ENDPOINT: $ARBITRUM_RPC_ENDPOINT" fi # Check for wss:// or https:// prefix echo "[2/5] Validating endpoint format..." if [[ "$ARBITRUM_RPC_ENDPOINT" == wss://* ]] || [[ "$ARBITRUM_RPC_ENDPOINT" == https://* ]]; then echo "✅ Endpoint format valid" else echo "❌ Endpoint must start with wss:// or https://" ERRORS=$((ERRORS + 1)) fi # Check log directory echo "[3/5] Checking log directory..." if [ -d "logs" ]; then echo "✅ Log directory exists" # Check for excessive zero addresses in recent logs if [ -f "logs/liquidity_events_$(date +%Y-%m-%d).jsonl" ]; then ZERO_COUNT=$(grep -c "0x0000000000000000000000000000000000000000" "logs/liquidity_events_$(date +%Y-%m-%d).jsonl" 2>/dev/null || echo 0) echo "Zero addresses in today's events: $ZERO_COUNT" if [ "$ZERO_COUNT" -gt 10 ]; then echo "⚠️ WARNING: High zero address count detected" fi fi else mkdir -p logs echo "✅ Created log directory" fi # Check binary exists echo "[4/5] Checking binary..." if [ -f "./mev-bot" ] || [ -f "./bin/mev-bot" ]; then echo "✅ MEV bot binary found" else echo "❌ MEV bot binary not found. Run 'make build' first" ERRORS=$((ERRORS + 1)) fi # Check for port conflicts echo "[5/5] Checking for port conflicts..." if lsof -Pi :9090 -sTCP:LISTEN -t >/dev/null 2>&1; then echo "⚠️ WARNING: Port 9090 (metrics) already in use" fi if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null 2>&1; then echo "⚠️ WARNING: Port 8080 (dashboard) already in use" fi echo "" echo "=========================================" if [ $ERRORS -eq 0 ]; then echo "✅ Validation PASSED - Safe to start" exit 0 else echo "❌ Validation FAILED - $ERRORS error(s) found" exit 1 fi