#!/bin/bash # MEV Bot V2 - Phase 1 Deployment Script (Mainnet Dry-Run) # This script deploys the bot in monitoring-only mode to validate arbitrage detection set -e # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color echo -e "${GREEN}========================================${NC}" echo -e "${GREEN}MEV Bot V2 - Phase 1 Deployment${NC}" echo -e "${GREEN}Mode: Mainnet Dry-Run (48 hours)${NC}" echo -e "${GREEN}========================================${NC}" echo "" # Check if .env exists if [ ! -f .env ]; then echo -e "${RED}ERROR: .env file not found${NC}" echo "Please create .env file with required configuration" exit 1 fi # Check for PRIVATE_KEY if ! grep -q "^PRIVATE_KEY=" .env || grep -q "^PRIVATE_KEY=$" .env || grep -q "^PRIVATE_KEY=???$" .env; then echo -e "${YELLOW}WARNING: PRIVATE_KEY not configured in .env${NC}" echo "" echo "To generate a new wallet:" echo " cast wallet new" echo "" echo "To use existing wallet, add to .env:" echo " PRIVATE_KEY=" echo "" read -p "Continue without private key? (bot will not be able to execute trades) [y/N]: " confirm if [[ ! $confirm =~ ^[Yy]$ ]]; then exit 1 fi fi # Verify RPC connectivity echo -e "${YELLOW}Verifying RPC connectivity...${NC}" RPC_URL=$(grep "^ARBITRUM_RPC_ENDPOINT=" .env | cut -d'=' -f2) if [ -z "$RPC_URL" ]; then RPC_URL="https://arb1.arbitrum.io/rpc" fi if command -v cast &> /dev/null; then if cast block-number --rpc-url "$RPC_URL" &> /dev/null; then BLOCK=$(cast block-number --rpc-url "$RPC_URL") echo -e "${GREEN}✓ RPC connected - Block: $BLOCK${NC}" else echo -e "${RED}✗ RPC connection failed${NC}" echo "Please verify ARBITRUM_RPC_ENDPOINT in .env" exit 1 fi else echo -e "${YELLOW}⚠ Cannot verify RPC (cast not installed)${NC}" fi # Stop existing container if running echo "" echo -e "${YELLOW}Checking for existing deployment...${NC}" if podman ps -a | grep -q "mev-bot-v2-phase1"; then echo "Stopping existing container..." podman stop mev-bot-v2-phase1 2>/dev/null || true podman rm mev-bot-v2-phase1 2>/dev/null || true fi # Create Phase 1 environment file echo "" echo -e "${YELLOW}Creating Phase 1 configuration...${NC}" cat > .env.phase1 << 'EOF' # Phase 1: Mainnet Dry-Run Configuration # Duration: 48 hours minimum # Risk: NONE (monitoring only, no execution) # === SAFETY SETTINGS (ULTRA-CONSERVATIVE) === ENABLE_EXECUTION=false DRY_RUN_MODE=true ENABLE_SIMULATION=true ENABLE_FRONT_RUNNING=false # === DETECTION THRESHOLDS === MIN_PROFIT_THRESHOLD=0.001 # 0.1% minimum (detect more opportunities) MAX_SLIPPAGE_TOLERANCE=0.005 # 0.5% max slippage # === RISK LIMITS (NOT USED IN DRY-RUN BUT LOGGED) === MAX_POSITION_SIZE_ETH=0.01 # 0.01 ETH MAX_DAILY_VOLUME_ETH=0.1 # 0.1 ETH MAX_CONSECUTIVE_LOSSES=1 # Stop after 1 loss MAX_HOURLY_LOSS_ETH=0.01 # 0.01 ETH hourly MAX_DAILY_LOSS_ETH=0.05 # 0.05 ETH daily # === MONITORING === METRICS_ENABLED=true METRICS_PORT=9090 LOG_LEVEL=info EOF # Merge with base .env cp .env .env.phase1.bak cat .env .env.phase1 > .env.phase1.merged mv .env.phase1.merged .env.phase1 echo -e "${GREEN}✓ Phase 1 configuration created: .env.phase1${NC}" # Deploy container echo "" echo -e "${YELLOW}Deploying MEV Bot V2 (Phase 1)...${NC}" podman run -d \ --name mev-bot-v2-phase1 \ --network host \ --restart unless-stopped \ --env-file .env.phase1 \ -v $(pwd)/logs:/app/logs:z \ mev-bot-v2:phase1-ready # Wait for startup echo "" echo -e "${YELLOW}Waiting for bot to initialize...${NC}" sleep 5 # Check if container is running if ! podman ps | grep -q "mev-bot-v2-phase1"; then echo -e "${RED}✗ Container failed to start${NC}" echo "" echo "Logs:" podman logs mev-bot-v2-phase1 exit 1 fi echo -e "${GREEN}✓ Bot deployed successfully${NC}" # Display initial logs echo "" echo -e "${GREEN}========================================${NC}" echo -e "${GREEN}Initial Bot Logs${NC}" echo -e "${GREEN}========================================${NC}" podman logs --tail 50 mev-bot-v2-phase1 # Display monitoring instructions echo "" echo -e "${GREEN}========================================${NC}" echo -e "${GREEN}Phase 1 Deployment Complete${NC}" echo -e "${GREEN}========================================${NC}" echo "" echo -e "${YELLOW}Container:${NC} mev-bot-v2-phase1" echo -e "${YELLOW}Mode:${NC} Dry-Run (monitoring only, NO trades)" echo -e "${YELLOW}Duration:${NC} 48 hours minimum" echo "" echo -e "${GREEN}Monitoring Commands:${NC}" echo " # View real-time logs" echo " podman logs -f mev-bot-v2-phase1" echo "" echo " # Check for opportunities" echo " podman logs mev-bot-v2-phase1 | grep -i 'opportunity'" echo "" echo " # Check for errors" echo " podman logs mev-bot-v2-phase1 | grep -i 'error'" echo "" echo " # View safety configuration" echo " podman logs mev-bot-v2-phase1 | grep -A20 'SAFETY CONFIGURATION'" echo "" echo -e "${GREEN}Emergency Stop:${NC}" echo " # Method 1: Graceful shutdown" echo " podman exec mev-bot-v2-phase1 touch /tmp/mev-bot-emergency-stop" echo "" echo " # Method 2: Immediate stop" echo " podman stop mev-bot-v2-phase1" echo "" echo -e "${YELLOW}Next Steps:${NC}" echo "1. Monitor logs every 4 hours" echo "2. Look for arbitrage opportunities being detected" echo "3. Verify no crashes or connection issues" echo "4. After 48 hours, review logs and assess if opportunities exist" echo "5. If successful, proceed to Phase 3 (minimal capital test)" echo "" echo -e "${RED}IMPORTANT: DO NOT enable ENABLE_EXECUTION until Phase 1 validates opportunities${NC}" echo ""