Complete local testing setup with Anvil fork of Arbitrum mainnet: Infrastructure: - Docker Compose orchestration (Anvil, MEV Bot, Prometheus, Grafana) - Anvil fork configuration with 1-second blocks - Multi-stage Dockerfile for optimized builds - Health checks and auto-restart policies Configuration: - Comprehensive .env.example with all parameters - Prometheus metrics collection setup - Grafana datasource provisioning - .gitignore to prevent committing secrets Testing Scripts: - setup-local-fork.sh: Initialize fork and fund test wallet - create-test-swap.sh: Generate test swaps for bot detection - Both scripts include validation and helpful output Integration Components: - pkg/sequencer/reader.go: WebSocket reader for pending transactions - Worker pool pattern (10 workers) - <50ms processing target - Front-running capability - Auto-reconnection with exponential backoff - pkg/pools/discovery.go: Pool discovery service - UniswapV2-style pools (SushiSwap, Camelot) - UniswapV3 pools (multiple fee tiers) - Factory contract queries - Liquidity filtering Documentation: - TESTING.md: Complete testing guide - Quick start instructions - Testing scenarios - Monitoring and debugging - Performance benchmarks - Troubleshooting guide This enables safe local testing without deploying to public testnet, using real Arbitrum mainnet state forked locally with Anvil. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
87 lines
2.9 KiB
Bash
Executable File
87 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# MEV Bot V2 - Local Fork Setup Script
|
|
# This script sets up the Anvil fork with test liquidity and scenarios
|
|
|
|
echo "🚀 Setting up MEV Bot V2 local testing environment..."
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Check if .env exists
|
|
if [ ! -f .env ]; then
|
|
echo -e "${YELLOW}⚠️ No .env file found. Copying from .env.example...${NC}"
|
|
cp .env.example .env
|
|
echo -e "${RED}⚠️ IMPORTANT: Edit .env and set your PRIVATE_KEY before continuing!${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Load environment variables
|
|
source .env
|
|
|
|
# Check if private key is set
|
|
if [ "$PRIVATE_KEY" == "0000000000000000000000000000000000000000000000000000000000000000" ]; then
|
|
echo -e "${RED}❌ Error: PRIVATE_KEY not set in .env file${NC}"
|
|
echo -e "${YELLOW}Please set a test private key in .env${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✅ Configuration loaded${NC}"
|
|
|
|
# Start Anvil fork
|
|
echo "🔧 Starting Anvil fork of Arbitrum..."
|
|
docker-compose up -d anvil
|
|
|
|
# Wait for Anvil to be ready
|
|
echo "⏳ Waiting for Anvil to be ready..."
|
|
max_attempts=30
|
|
attempt=0
|
|
while [ $attempt -lt $max_attempts ]; do
|
|
if docker-compose exec -T anvil cast block-number --rpc-url http://localhost:8545 &>/dev/null; then
|
|
echo -e "${GREEN}✅ Anvil is ready${NC}"
|
|
break
|
|
fi
|
|
attempt=$((attempt + 1))
|
|
sleep 2
|
|
done
|
|
|
|
if [ $attempt -eq $max_attempts ]; then
|
|
echo -e "${RED}❌ Anvil failed to start${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Get current block number
|
|
BLOCK_NUMBER=$(docker-compose exec -T anvil cast block-number --rpc-url http://localhost:8545)
|
|
echo -e "${GREEN}📦 Forked at block: $BLOCK_NUMBER${NC}"
|
|
|
|
# Get wallet address from private key
|
|
WALLET_ADDRESS=$(docker-compose exec -T anvil cast wallet address $PRIVATE_KEY)
|
|
echo -e "${GREEN}💼 Wallet address: $WALLET_ADDRESS${NC}"
|
|
|
|
# Fund the wallet with test ETH
|
|
echo "💰 Funding wallet with 100 test ETH..."
|
|
docker-compose exec -T anvil cast send --value 100ether --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 $WALLET_ADDRESS --rpc-url http://localhost:8545
|
|
|
|
# Get wallet balance
|
|
BALANCE=$(docker-compose exec -T anvil cast balance $WALLET_ADDRESS --rpc-url http://localhost:8545)
|
|
echo -e "${GREEN}💵 Wallet balance: $(echo "scale=4; $BALANCE / 1000000000000000000" | bc) ETH${NC}"
|
|
|
|
echo ""
|
|
echo -e "${GREEN}✨ Local fork setup complete!${NC}"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Start the full stack: docker-compose up -d"
|
|
echo " 2. View logs: docker-compose logs -f mev-bot"
|
|
echo " 3. View metrics: http://localhost:9090"
|
|
echo " 4. View Grafana: http://localhost:3000 (admin/admin)"
|
|
echo ""
|
|
echo "Testing commands:"
|
|
echo " - Check Anvil: docker-compose exec anvil cast block-number --rpc-url http://localhost:8545"
|
|
echo " - Get balance: docker-compose exec anvil cast balance $WALLET_ADDRESS --rpc-url http://localhost:8545"
|
|
echo " - Create test swap: ./scripts/create-test-swap.sh"
|
|
echo ""
|