feat(testing): add Anvil fork local testing infrastructure
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>
This commit is contained in:
104
docker-compose.yml
Normal file
104
docker-compose.yml
Normal file
@@ -0,0 +1,104 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# Anvil fork of Arbitrum for local testing
|
||||
anvil:
|
||||
image: ghcr.io/foundry-rs/foundry:latest
|
||||
container_name: mev-bot-anvil
|
||||
ports:
|
||||
- "8545:8545"
|
||||
- "8546:8546"
|
||||
command: >
|
||||
anvil
|
||||
--fork-url ${ARBITRUM_RPC_URL:-https://arb1.arbitrum.io/rpc}
|
||||
--fork-block-number ${FORK_BLOCK_NUMBER:-latest}
|
||||
--host 0.0.0.0
|
||||
--port 8545
|
||||
--chain-id 42161
|
||||
--accounts 10
|
||||
--balance 10000
|
||||
--gas-limit 30000000
|
||||
--gas-price 0
|
||||
--base-fee 0
|
||||
--no-mining
|
||||
--block-time 1
|
||||
networks:
|
||||
- mev-network
|
||||
healthcheck:
|
||||
test: ["CMD", "cast", "block-number", "--rpc-url", "http://localhost:8545"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
|
||||
# MEV Bot V2
|
||||
mev-bot:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: mev-bot-v2
|
||||
depends_on:
|
||||
anvil:
|
||||
condition: service_healthy
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
# Override RPC URLs to point to local Anvil fork
|
||||
- RPC_URL=http://anvil:8545
|
||||
- WS_URL=ws://anvil:8546
|
||||
- SEQUENCER_WS_URL=ws://anvil:8546
|
||||
# Testing configuration
|
||||
- ENABLE_SIMULATION=true
|
||||
- ENABLE_FRONT_RUNNING=true
|
||||
- LOG_LEVEL=debug
|
||||
networks:
|
||||
- mev-network
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
- ./data:/app/data
|
||||
|
||||
# Prometheus for metrics collection
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
container_name: mev-bot-prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
- prometheus-data:/prometheus
|
||||
command:
|
||||
- '--config.file=/etc/prometheus/prometheus.yml'
|
||||
- '--storage.tsdb.path=/prometheus'
|
||||
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
|
||||
- '--web.console.templates=/usr/share/prometheus/consoles'
|
||||
networks:
|
||||
- mev-network
|
||||
restart: unless-stopped
|
||||
|
||||
# Grafana for metrics visualization
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
container_name: mev-bot-grafana
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- GF_INSTALL_PLUGINS=
|
||||
volumes:
|
||||
- grafana-data:/var/lib/grafana
|
||||
- ./config/grafana/dashboards:/etc/grafana/provisioning/dashboards
|
||||
- ./config/grafana/datasources:/etc/grafana/provisioning/datasources
|
||||
networks:
|
||||
- mev-network
|
||||
depends_on:
|
||||
- prometheus
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
mev-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
prometheus-data:
|
||||
grafana-data:
|
||||
Reference in New Issue
Block a user