Files
mev-beta/scripts/start-24h-test.sh
Krypto Kajun 432bcf0819 docs: add flash loan, binding, and testing documentation
Additional documentation and testing infrastructure:

## Documentation Added
- PROFIT_ROADMAP.md - 4-week profitability roadmap
- PRODUCTION_DEPLOYMENT.md - Production deployment guide
- docs/FLASH_LOAN_DEPLOYMENT_GUIDE.md - Flash loan implementation
- docs/FLASH_LOAN_IMPLEMENTATION_SUMMARY.md - Flash loan summary
- docs/BINDING_CONSISTENCY_GUIDE.md - Contract binding guidelines
- docs/BINDING_QUICK_START.md - Quick start for bindings
- docs/COMPLETE_FORK_TESTING_GUIDE.md - Fork testing guide

## Testing Scripts Added
- scripts/generate-test-report.sh - Generate test reports
- scripts/monitor-24h-test.sh - 24-hour monitoring
- scripts/start-24h-test.sh - Start long-running tests
- scripts/stop-24h-test.sh - Stop test runs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-27 05:51:44 -05:00

196 lines
4.9 KiB
Bash
Executable File

#!/bin/bash
# 24-Hour MEV Bot Validation Test
# Starts bot in background with comprehensive logging
set -e
echo "🚀 Starting 24-Hour MEV Bot Validation Test"
echo "Time: $(date)"
echo "============================================"
# Configuration
LOG_DIR="logs/24h_test"
MAIN_LOG="${LOG_DIR}/test_$(date +%Y%m%d_%H%M%S).log"
PID_FILE="${LOG_DIR}/mev-bot.pid"
MONITOR_LOG="${LOG_DIR}/monitor.log"
# Create log directory
mkdir -p "${LOG_DIR}"
# Check if already running
if [ -f "${PID_FILE}" ]; then
PID=$(cat "${PID_FILE}")
if ps -p "${PID}" > /dev/null 2>&1; then
echo "❌ MEV bot already running with PID ${PID}"
echo "Stop it first with: kill ${PID}"
exit 1
else
echo "⚠️ Removing stale PID file"
rm -f "${PID_FILE}"
fi
fi
# Start MEV bot in background
echo "📊 Starting MEV bot..."
PROVIDER_CONFIG_PATH=$PWD/config/providers_runtime.yaml \
nohup ./bin/mev-bot start > "${MAIN_LOG}" 2>&1 &
BOT_PID=$!
echo ${BOT_PID} > "${PID_FILE}"
# Wait a moment for startup
sleep 3
# Check if still running
if ! ps -p ${BOT_PID} > /dev/null 2>&1; then
echo "❌ Bot failed to start. Check logs:"
tail -50 "${MAIN_LOG}"
rm -f "${PID_FILE}"
exit 1
fi
echo "✅ MEV bot started successfully"
echo " PID: ${BOT_PID}"
echo " Log: ${MAIN_LOG}"
echo ""
echo "📊 Test will run for 24 hours"
echo " Started: $(date)"
echo " Expected end: $(date -d '+24 hours' 2>/dev/null || date -v +24H 2>/dev/null || echo 'in 24 hours')"
echo ""
echo "📝 Monitor with:"
echo " tail -f ${MAIN_LOG}"
echo " ./scripts/monitor-24h-test.sh"
echo ""
echo "🛑 Stop with:"
echo " kill ${BOT_PID}"
echo " # or"
echo " ./scripts/stop-24h-test.sh"
echo ""
# Create monitoring script
cat > ./scripts/monitor-24h-test.sh << 'EOF'
#!/bin/bash
# Monitor 24-hour test progress
LOG_DIR="logs/24h_test"
PID_FILE="${LOG_DIR}/mev-bot.pid"
if [ ! -f "${PID_FILE}" ]; then
echo "❌ No test running (PID file not found)"
exit 1
fi
PID=$(cat "${PID_FILE}")
if ! ps -p "${PID}" > /dev/null 2>&1; then
echo "❌ Bot not running (PID ${PID} not found)"
exit 1
fi
# Find latest log
LATEST_LOG=$(ls -t ${LOG_DIR}/test_*.log 2>/dev/null | head -1)
if [ -z "${LATEST_LOG}" ]; then
echo "❌ No log file found"
exit 1
fi
echo "📊 MEV Bot 24-Hour Test Monitor"
echo "================================"
echo "PID: ${PID}"
echo "Log: ${LATEST_LOG}"
echo "Running since: $(ps -o lstart= -p ${PID})"
echo ""
# Stats
echo "📈 Statistics:"
BLOCKS=$(grep -c "Processing.*transactions" "${LATEST_LOG}" 2>/dev/null || echo "0")
DEX=$(grep -c "DEX Transaction detected" "${LATEST_LOG}" 2>/dev/null || echo "0")
OPPS=$(grep -c "ARBITRAGE OPPORTUNITY" "${LATEST_LOG}" 2>/dev/null || echo "0")
PROFITABLE=$(grep "ARBITRAGE OPPORTUNITY" "${LATEST_LOG}" 2>/dev/null | grep -c "isExecutable:true" || echo "0")
echo " Blocks processed: ${BLOCKS}"
echo " DEX transactions: ${DEX}"
echo " Opportunities: ${OPPS}"
echo " Profitable: ${PROFITABLE}"
echo ""
# Recent activity
echo "🔍 Recent Activity (last 10 opportunities):"
grep "ARBITRAGE OPPORTUNITY" "${LATEST_LOG}" 2>/dev/null | tail -10 | while read line; do
echo " $(echo $line | grep -o 'netProfitETH:[^ ]*' || echo 'N/A')"
done
echo ""
# Cache metrics
echo "💾 Cache Metrics:"
grep "Reserve cache metrics" "${LATEST_LOG}" 2>/dev/null | tail -1 || echo " Not available yet"
echo ""
# Errors
ERRORS=$(grep -c "\[ERROR\]" "${LATEST_LOG}" 2>/dev/null || echo "0")
echo "⚠️ Errors: ${ERRORS}"
if [ "${ERRORS}" -gt "0" ]; then
echo " Recent errors:"
grep "\[ERROR\]" "${LATEST_LOG}" 2>/dev/null | tail -3 | sed 's/^/ /'
fi
echo ""
echo "📝 Live monitoring:"
echo " tail -f ${LATEST_LOG} | grep -E 'ARBITRAGE|ERROR|Reserve cache'"
EOF
chmod +x ./scripts/monitor-24h-test.sh
# Create stop script
cat > ./scripts/stop-24h-test.sh << 'EOF'
#!/bin/bash
# Stop 24-hour test
LOG_DIR="logs/24h_test"
PID_FILE="${LOG_DIR}/mev-bot.pid"
if [ ! -f "${PID_FILE}" ]; then
echo "❌ No test running (PID file not found)"
exit 1
fi
PID=$(cat "${PID_FILE}")
echo "🛑 Stopping MEV bot (PID ${PID})..."
if ps -p "${PID}" > /dev/null 2>&1; then
kill "${PID}"
echo " Waiting for graceful shutdown..."
# Wait up to 10 seconds
for i in {1..10}; do
if ! ps -p "${PID}" > /dev/null 2>&1; then
echo "✅ Bot stopped successfully"
rm -f "${PID_FILE}"
exit 0
fi
sleep 1
done
# Force kill if still running
echo "⚠️ Forcing shutdown..."
kill -9 "${PID}" 2>/dev/null
rm -f "${PID_FILE}"
echo "✅ Bot forcefully stopped"
else
echo "⚠️ Bot not running, cleaning up PID file"
rm -f "${PID_FILE}"
fi
# Generate final report
echo ""
echo "📊 Generating final report..."
./scripts/generate-test-report.sh
EOF
chmod +x ./scripts/stop-24h-test.sh
echo "✅ 24-hour test started successfully!"
echo ""
echo "🎯 Next: Run monitoring script to track progress"
echo " ./scripts/monitor-24h-test.sh"