9.6 KiB
9.6 KiB
MEV Bot V2 - Production Deployment Guide
Last Updated: 2025-11-11 Status: Ready for Mainnet Dry-Run Testing Test Results: 12/12 Passing (100%)
⚠️ Pre-Deployment Checklist
Critical Requirements
- Private key configured and secured
- Wallet funded (minimum 0.1 ETH for gas)
- RPC endpoints verified (mainnet Arbitrum)
- Emergency stop procedure documented and tested
- Monitoring alerts configured
- Team member available for 24h monitoring
Safety Verification
- All 12 safety tests passing
- Emergency stop mechanism tested (8s detection)
- Configuration values correct (no negative values)
- Dry-run mode verified (0 transactions executed)
- Circuit breaker configured (3 losses, 0.1 ETH hourly)
- Position limits set (10 ETH max position, 100 ETH daily volume)
📋 Deployment Phases
Phase 1: Mainnet Dry-Run (48 hours)
Goal: Validate arbitrage detection without executing trades
Configuration:
# .env settings for Phase 1
ENABLE_EXECUTION=false
DRY_RUN_MODE=true
ENABLE_SIMULATION=true
MIN_PROFIT_THRESHOLD=0.001 # 0.1%
Success Criteria:
- Bot runs stable for 48 hours
- Arbitrage opportunities detected
- No crashes or errors
- Profit calculations appear reasonable
Monitoring:
- Check logs every 4 hours
- Verify opportunities being detected
- Monitor resource usage (CPU, memory)
Phase 2: Testnet Deployment (7 days)
Status: NOT READY - User requested Anvil fork only
Note: User specified deployments will be on Anvil fork of Arbitrum mainnet, not testnet.
Phase 3: Minimal Capital Test (24-48 hours)
Goal: Execute real trades with minimal risk
Configuration:
# .env settings for Phase 3
ENABLE_EXECUTION=true
DRY_RUN_MODE=false
ENABLE_SIMULATION=true
# ULTRA-CONSERVATIVE LIMITS
MIN_PROFIT_THRESHOLD=0.01 # 1% minimum profit
MAX_POSITION_SIZE_ETH=0.01 # 0.01 ETH maximum
MAX_DAILY_VOLUME_ETH=0.1 # 0.1 ETH daily limit
MAX_CONSECUTIVE_LOSSES=1 # Stop after 1 loss
MAX_HOURLY_LOSS_ETH=0.01 # 0.01 ETH hourly loss limit
Wallet Setup:
- Use dedicated wallet (not primary funds)
- Fund with 0.1 ETH only
- Monitor balance every hour
Success Criteria:
- First trade executes successfully
- Profit/loss calculations accurate
- Circuit breaker triggers correctly if loss occurs
- Gas estimation within 10% of actual
Phase 4: Gradual Scale-Up (1-2 weeks)
Only proceed if Phase 3 succeeds
Week 1 Limits:
MAX_POSITION_SIZE_ETH=0.1 # 0.1 ETH
MAX_DAILY_VOLUME_ETH=1.0 # 1.0 ETH
MAX_CONSECUTIVE_LOSSES=2 # 2 losses
Week 2 Limits (if profitable):
MAX_POSITION_SIZE_ETH=1.0 # 1 ETH
MAX_DAILY_VOLUME_ETH=10.0 # 10 ETH
MAX_CONSECUTIVE_LOSSES=3 # 3 losses
🔧 Production Configuration
Environment Variables
Required:
# Wallet
PRIVATE_KEY=<your_private_key_hex> # 64-character hex (no 0x prefix)
# Arbitrum Mainnet RPC
ARBITRUM_RPC_ENDPOINT=wss://arbitrum-mainnet.core.chainstack.com/YOUR_KEY
ARBITRUM_WS_ENDPOINT=wss://arbitrum-mainnet.core.chainstack.com/YOUR_KEY
# Smart Contracts (Deployed)
CONTRACT_ARBITRAGE_EXECUTOR=0xec2a16d5f8ac850d08c4c7f67efd50051e7cfc0b
CONTRACT_FLASH_SWAPPER=0x5801ee5c2f6069e0f11cce7c0f27c2ef88e79a95
CONTRACT_UNISWAP_V2_FLASH_SWAPPER=0xc0b8c3e9a976ec67d182d7cb0283fb4496692593
# Arbiscan API
ARBISCAN_API_KEY=H8PEIY79385F4UKYU7MRV5IAT1BI1WYIVY
Safety Settings:
# Execution Control
ENABLE_EXECUTION=false # Start with false (dry-run)
DRY_RUN_MODE=true # Start with true
ENABLE_SIMULATION=true
ENABLE_FRONT_RUNNING=false
# Risk Limits (Conservative for Phase 1)
MIN_PROFIT_THRESHOLD=0.01 # 1% minimum
MAX_POSITION_SIZE_ETH=0.01 # 0.01 ETH
MAX_DAILY_VOLUME_ETH=0.1 # 0.1 ETH
MAX_SLIPPAGE_TOLERANCE=0.005 # 0.5%
# Circuit Breaker
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
# Emergency Stop
EMERGENCY_STOP_FILE=/tmp/mev-bot-emergency-stop
🚀 Deployment Commands
Build Production Image
podman build -t mev-bot-v2:production -f Dockerfile .
Run with Production Config
podman run -d \
--name mev-bot-v2-prod \
--network host \
--restart unless-stopped \
--env-file .env \
-v $(pwd)/logs:/app/logs:z \
mev-bot-v2:production
Monitor Logs
# Real-time logs
podman logs -f mev-bot-v2-prod
# Filter for opportunities
podman logs mev-bot-v2-prod 2>&1 | grep -i "opportunity"
# Filter for errors
podman logs mev-bot-v2-prod 2>&1 | grep -i "error"
# Check safety configuration
podman logs mev-bot-v2-prod 2>&1 | grep -A10 "SAFETY CONFIGURATION"
🚨 Emergency Procedures
Immediate Stop
# Method 1: Emergency stop file (graceful, 10-second detection)
podman exec mev-bot-v2-prod touch /tmp/mev-bot-emergency-stop
# Method 2: Container stop (immediate)
podman stop mev-bot-v2-prod
# Method 3: Force kill (if unresponsive)
podman kill mev-bot-v2-prod
Verification
# Check bot stopped
podman ps | grep mev-bot-v2-prod
# Check last logs
podman logs --tail 50 mev-bot-v2-prod
# Check wallet balance
cast balance <YOUR_WALLET_ADDRESS> --rpc-url https://arb1.arbitrum.io/rpc
📊 Monitoring Checklist
Every 4 Hours
- Check bot is running:
podman ps - Review recent logs for errors
- Verify opportunities being detected
- Check wallet balance hasn't decreased unexpectedly
Daily
- Review full logs:
podman logs mev-bot-v2-prod > daily_$(date +%Y%m%d).log - Analyze profit/loss
- Check gas usage vs profit
- Verify circuit breaker hasn't triggered
- Review arbitrage opportunity quality
Weekly
- Full system health check
- Update RPC endpoints if needed
- Review and adjust risk parameters
- Backup logs and configuration
- Test emergency stop procedure
⚡ Performance Metrics
Expected Behavior
- Opportunities detected: 1-10 per hour (highly variable)
- Profitable opportunities: 0.1-1% of all opportunities
- Execution success rate: >95% (when enabled)
- Average profit per trade: 0.01-0.1 ETH
- Gas cost per trade: 0.001-0.01 ETH
Red Flags
- ⚠️ No opportunities detected for >6 hours
- ⚠️ Execution success rate <80%
- ⚠️ Average gas cost > average profit
- ⚠️ Circuit breaker triggering repeatedly
- ⚠️ Memory usage increasing over time
🔐 Security Best Practices
Wallet Security
- Use dedicated wallet (not primary funds)
- Never expose private key in logs
- Store private key in secure vault
- Limit wallet balance to maximum daily volume + 10%
- Use hardware wallet for large deployments
RPC Security
- Use private RPC endpoints (not public)
- Rotate API keys periodically
- Monitor RPC usage and rate limits
- Have backup RPC endpoints configured
Container Security
- Run as non-root user (already configured)
- Limit container resources:
podman run --memory=2g --cpus=2 ... - Mount logs as read-only from host
- Regular security updates
📝 Troubleshooting
Bot Not Starting
# Check logs
podman logs mev-bot-v2-prod
# Common issues:
# 1. Missing PRIVATE_KEY → Add to .env
# 2. Invalid RPC endpoint → Test with: wscat -c wss://...
# 3. Port conflict → Check: netstat -tlnp | grep 9090
No Opportunities Detected
# Verify RPC connection
cast block-number --rpc-url $ARBITRUM_RPC_ENDPOINT
# Check pool discovery
podman logs mev-bot-v2-prod 2>&1 | grep "pools_discovered"
# Lower profit threshold temporarily for testing
# Edit .env: MIN_PROFIT_THRESHOLD=0.001
Circuit Breaker Triggered
# Check recent trades
podman logs mev-bot-v2-prod 2>&1 | grep -A5 "circuit breaker"
# Analyze why:
# 1. Real market losses → Normal, bot protecting you
# 2. Gas estimation errors → Adjust MAX_GAS_PRICE
# 3. Slippage issues → Increase MAX_SLIPPAGE_TOLERANCE slightly
# Reset circuit breaker by restarting:
podman restart mev-bot-v2-prod
📈 Success Criteria
Phase 1 Success (Dry-Run)
- ✅ 48 hours of stable operation
- ✅ 10+ opportunities detected
- ✅ No crashes or errors
- ✅ Reasonable profit calculations
Phase 3 Success (Live Trading)
- ✅ First trade profitable or break-even
- ✅ Circuit breaker working correctly
- ✅ Gas costs < 50% of gross profit
- ✅ No unexpected losses
Long-term Success (1 month)
- ✅ Net positive profit after gas
- ✅ <5% of trades result in loss
- ✅ No emergency stops triggered
- ✅ Stable performance over time
🎯 Current Status: Phase 1 Ready
What's Working:
- ✅ All safety mechanisms tested (12/12 tests)
- ✅ Emergency stop verified (8-second detection)
- ✅ Configuration values correct
- ✅ Dry-run mode confirmed working
Blockers to Production:
- ⚠️ Need to configure production wallet (PRIVATE_KEY)
- ⚠️ Need to verify RPC endpoint connectivity
- ⚠️ Need 48h dry-run validation on mainnet
- ⚠️ Need to verify arbitrage opportunities exist
Next Steps:
- Configure production wallet in .env
- Start Phase 1 (48h dry-run on mainnet)
- Monitor and validate opportunity detection
- If successful, proceed to Phase 3 (minimal capital test)
📞 Support & Resources
- Emergency Contact: [Your contact info]
- Logs Location:
/docker/mev-beta/logs/ - Documentation:
README.md,SAFETY_TEST_RESULTS.md - Test Scripts:
scripts/test_safety_mechanisms.sh
⚠️ WARNING: DO NOT deploy to mainnet with ENABLE_EXECUTION=true until Phase 1 dry-run is complete and validated.