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:
Administrator
2025-11-10 18:52:56 +01:00
parent 0a7a07c896
commit 65c1005d91
11 changed files with 1902 additions and 0 deletions

55
Dockerfile Normal file
View File

@@ -0,0 +1,55 @@
# Multi-stage build for MEV Bot V2
# Stage 1: Build
FROM golang:1.21-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git make gcc musl-dev linux-headers
# Set working directory
WORKDIR /build
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN go build -o mev-bot-v2 -ldflags="-w -s" ./cmd/mev-bot-v2
# Stage 2: Runtime
FROM alpine:latest
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user
RUN addgroup -g 1000 mevbot && \
adduser -D -u 1000 -G mevbot mevbot
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /build/mev-bot-v2 .
# Create directories
RUN mkdir -p /app/logs /app/data && \
chown -R mevbot:mevbot /app
# Switch to non-root user
USER mevbot
# Expose metrics port
EXPOSE 9090
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:9090/metrics || exit 1
# Run the application
ENTRYPOINT ["/app/mev-bot-v2"]