Compare commits

..

9 Commits

Author SHA1 Message Date
Krypto Kajun
8f9321348c ... 2025-11-18 02:35:08 -06:00
Krypto Kajun
2855c23c93 chore: remove unnecessary files to free up disk space
Removed large files and directories that were taking up space:
- Corrupted/misplaced files: d (336M), --delete (120M)
- Temporary files in /tmp and /var/tmp (751M total)
- Unnecessary node_modules directory (26M)
- Backup/orig directory (17M)
- Archived log files from logs/ directory (189M)

Total space freed: ~1.4GB

Also cleaned up git repository with gc --aggressive to optimize storage.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 01:07:42 -06:00
Krypto Kajun
ac61a1dc5a fix(docker): exclude logs and harness directories from container build
Updated .dockerignore to exclude:
- logs/ directory (contains large archived log files)
- harness/ directory (contains test reports and temporary files)

These directories contain large files that were causing container build
failures with 'archive/tar: write too long' errors. Excluding them reduces
the build context size and allows the container build to succeed.

The excluded directories are runtime-generated and not needed in the
production container image.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 21:08:30 -06:00
Krypto Kajun
687350b285 fix(scripts): update launcher to support podman with modern compose syntax
Updated container execution path to:
- Detect and prefer podman over docker (modern container runtime)
- Use modern 'docker compose' and 'podman compose' syntax (without hyphen)
- Properly handle both podman and docker as fallback options
- Display which container runtime is being used in output

Key improvements:
- Container runtime detection (prefer podman, fallback to docker)
- Uses 'podman compose' or 'docker compose' based on available runtime
- Updated status messages to show container runtime information
- Renamed internal references from Docker-specific to generic "container"

Testing results:
 Podman is properly detected and used (podman compose works)
 Container image building with podman compose --no-cache succeeds
 Native execution path unchanged and still fully functional
 Both execution modes work correctly with proper pre-flight checks

The launcher now correctly uses:
- Modern compose syntax: 'podman compose' (not 'podman-compose')
- Proper container runtime auto-detection with podman preference
- Fallback to docker if podman not available

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 20:45:58 -06:00
Krypto Kajun
566f3f03ca feat(scripts): add Docker build and execution support to launcher
Added comprehensive Docker support to the launcher script with:

- New --docker flag to run bot in containerized environment
- Docker and docker-compose availability checks
- Automatic .env.docker generation with ARBITRUM_RPC_ENDPOINT
- docker-compose build --no-cache for image building
- docker-compose up/down for container lifecycle management
- Proper error handling when Docker/docker-compose not found
- Graceful container shutdown on Ctrl+C

Docker execution path provides:
- 3-step pre-flight verification (Docker detection, env setup, build)
- Full environment variable configuration
- Container health check integration
- Resource limits (2 CPU, 2GB RAM limits)
- Auto-restart policy for production reliability

Native execution path continues unchanged:
- Binary compilation if needed
- Full pre-flight checks (5 steps)
- Environment variable setup
- Graceful startup and shutdown

Testing Results:
 Docker path properly detected
 Native path executes successfully
 All pre-flight checks pass
 Bot initializes all 20+ services correctly

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 18:58:11 -06:00
Krypto Kajun
204be46b23 fix(config): add arbitrage configuration section
Added missing arbitrage configuration that was preventing bot startup.
The arbitrage service now properly initializes with:

- enabled: true (service is operational)
- min_profit_usd: 10.0 (minimum profitable opportunity)
- max_slippage: 1.0% (slippage tolerance)
- max_concurrent_executions: 5 (parallelization)
- execution_timeout: 60s (transaction timeout)
- gas_multiplier: 1.5 (for faster execution)
- enable_flash_swaps: true (flash swap support)
- max_capital_per_execution: 00,000 (execution limit)

This enables the bot to fully initialize and start monitoring for
flash swap arbitrage opportunities on Arbitrum L2.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 17:07:34 -06:00
Krypto Kajun
32c06d8c21 feat(scripts): implement complete bot launcher with all setup and verification
Complete launcher script that handles:
- Binary compilation (builds if needed)
- Configuration file verification
- Directory setup (logs, data)
- Environment variable configuration
- RPC endpoint setup
- Proper error handling and validation
- Graceful startup/shutdown with Ctrl+C support
- Optional Anvil fork support for local testing
- Pre-flight checks before launch

The script now correctly sets ARBITRUM_RPC_ENDPOINT environment variable
that the config.yaml expects, enabling the bot to start successfully.

Features:
- Colored output with progress indicators
- Comprehensive logging of configuration
- Builds binary automatically if missing
- Validates all required config files exist
- Sets security variables automatically
- Shows startup banner with status information
- Full pre-flight verification suite
- Graceful cleanup on shutdown

Usage:
  ./scripts/run-flash-swap-bot.sh              # Run with defaults
  ./scripts/run-flash-swap-bot.sh --capital 10000  # Custom capital
  ./scripts/run-flash-swap-bot.sh --fork       # Use local fork
  ./scripts/run-flash-swap-bot.sh --dry-run    # Dry-run mode

 Tested and verified working - bot successfully starts and initializes

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 15:07:57 -06:00
Krypto Kajun
10911ea469 feat: add flash swap bot launcher script for production deployment
- Created run-flash-swap-bot.sh with full command-line interface
- Supports --rpc, --capital, --dry-run, --fork options
- Automatic binary building if missing
- Integrated Anvil fork support for testing
- Production-ready deployment script

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 14:54:58 -06:00
Krypto Kajun
21576f862a fix: remove duplicate script main functions to fix build
- Deleted quick-pool-analysis.go, test-pool-calls.go, test-uniswap-pools-direct.go
- These files had duplicate main() functions preventing build
- Code now builds successfully with go build ./...

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 14:19:52 -06:00
1252 changed files with 12680 additions and 90878 deletions

View File

@@ -1,54 +1,44 @@
# Exclude V1 codebase (not needed in V2 container)
orig/
# Exclude build artifacts
**/*_test.go
test/
# Binaries
bin/
build/
dist/
*.exe
# Exclude logs
logs/
*.log
# Configuration files that might contain sensitive information
config/local.yaml
config/secrets.yaml
# Exclude temporary files
tmp/
temp/
*.tmp
# Go workspace
go.work
# Exclude test coverage
*.out
# Test coverage files
coverage.txt
coverage.html
# Exclude IDE files
# IDE files
.vscode/
.idea/
*.swp
*.swo
# Exclude git
.git/
.gitignore
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Exclude documentation (not needed at runtime)
docs/
*.md
# Log files and directories
*.log
logs/
harness/
# Exclude environment files (passed at runtime)
.env
.env.*
# Database files
*.db
# Exclude Docker/k8s files
docker-compose.yml
Dockerfile
.dockerignore
# Exclude test files
*_test.go
example_usage.go
examples_test.go
# Exclude scripts (not needed in container)
scripts/
# Exclude config (provisioned externally)
config/
# Data directory
data/
vendor/
backup/
backups/

62
.env
View File

@@ -1,62 +0,0 @@
# 🚀 MEV BOT PRODUCTION CONFIGURATION - IMMEDIATE PROFIT MODE
# This is your LIVE TRADING configuration for immediate deployment
# =============================================================================
# 🔥 CRITICAL PRODUCTION SETTINGS - PROFIT OPTIMIZATION
# =============================================================================
# High-performance RPC endpoint
ARBITRUM_RPC_ENDPOINT=wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57
ARBITRUM_WS_ENDPOINT=wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57
ARBITRUM_RPC_ENDPOINT=wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57
ARBITRUM_RPC_ENDPOINT=wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57
# Aggressive rate limits for maximum throughput
RPC_REQUESTS_PER_SECOND=250
RPC_MAX_CONCURRENT=20
BOT_MAX_WORKERS=8
BOT_CHANNEL_BUFFER_SIZE=5000
# 🔐 PRODUCTION SECURITY
MEV_BOT_ENCRYPTION_KEY="i4qwh5vqUxehOdFsdZx0vFvDwKUHcVpGWC0K2BVQn6A="
# 💰 PROFIT MAXIMIZATION SETTINGS
ARBITRAGE_MIN_PROFIT_THRESHOLD=0.001 # 0.1% minimum profit (aggressive)
GAS_PRICE_MULTIPLIER=1.8 # Competitive gas pricing
MAX_SLIPPAGE_TOLERANCE=0.005 # 0.5% max slippage
POSITION_SIZE_ETH=0.1 # Start with 0.1 ETH positions
# 📊 MONITORING & ALERTS
METRICS_ENABLED=true
METRICS_PORT=9090
HEALTH_PORT=8080
LOG_LEVEL=info
LOG_FORMAT=json
# 🏭 PRODUCTION ENVIRONMENT
GO_ENV=production
DEBUG=false
# 💾 STORAGE PATHS
MEV_BOT_KEYSTORE_PATH=keystore/production
MEV_BOT_AUDIT_LOG=logs/production_audit.log
MEV_BOT_BACKUP_PATH=backups/production
# ⚡ PERFORMANCE TUNING
GOMAXPROCS=4
GOGC=100
# 🎯 TARGET EXCHANGES FOR ARBITRAGE
ENABLE_UNISWAP_V2=true
ENABLE_UNISWAP_V3=true
ENABLE_SUSHISWAP=true
ENABLE_BALANCER=true
ENABLE_CURVE=true
# 🔥 DEPLOYED CONTRACTS (PRODUCTION READY)
CONTRACT_ARBITRAGE_EXECUTOR=0xec2a16d5f8ac850d08c4c7f67efd50051e7cfc0b
CONTRACT_FLASH_SWAPPER=0x5801ee5c2f6069e0f11cce7c0f27c2ef88e79a95
CONTRACT_UNISWAP_V2_FLASH_SWAPPER=0xc0b8c3e9a976ec67d182d7cb0283fb4496692593
ARBISCAN_API_KEY=H8PEIY79385F4UKYU7MRV5IAT1BI1WYIVY

2
.env.docker Normal file
View File

@@ -0,0 +1,2 @@
ARBITRUM_RPC_ENDPOINT=https://arb1.arbitrum.io/rpc
LOG_LEVEL=debug

View File

@@ -1,147 +1,115 @@
# MEV Bot V2 Configuration
# Copy this file to .env and fill in your values
# MEV Bot Environment Configuration Template
# Copy this file to .env and fill in your actual values
# SECURITY WARNING: Never commit .env files with actual credentials to version control
# ============================================================================
# NETWORK CONFIGURATION
# ============================================================================
# ============================================================
# ARBITRUM NETWORK CONFIGURATION
# ============================================================
# HTTP endpoint for transaction execution (reliable)
# Get your own endpoint from: https://chainstack.com or https://alchemy.com
ARBITRUM_RPC_ENDPOINT=https://arbitrum-mainnet.infura.io/v3/YOUR_PROJECT_ID
# Arbitrum RPC URL (for forking with Anvil)
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc
# WebSocket endpoint for real-time event monitoring
ARBITRUM_WS_ENDPOINT=wss://arbitrum-mainnet.infura.io/ws/v3/YOUR_PROJECT_ID
# Block number to fork from (optional, defaults to latest)
# FORK_BLOCK_NUMBER=latest
# ============================================================
# RPC RATE LIMITING
# ============================================================
# Requests per second to avoid provider rate limits
# Adjust based on your provider's tier (free tier: 1-2, paid: 10-50)
RPC_REQUESTS_PER_SECOND=2
# Local Anvil URLs (used by bot when running in docker-compose)
# RPC_URL=http://anvil:8545
# WS_URL=ws://anvil:8546
# SEQUENCER_WS_URL=ws://anvil:8546
# Maximum concurrent RPC connections
# Lower values reduce rate limit errors but slow down processing
RPC_MAX_CONCURRENT=1
# Production Arbitrum URLs (when not using Anvil)
# RPC_URL=https://arb1.arbitrum.io/rpc
# WS_URL=wss://arb1.arbitrum.io/ws
# SEQUENCER_WS_URL=wss://arb1.arbitrum.io/ws
# ============================================================
# BOT PERFORMANCE CONFIGURATION
# ============================================================
# Number of worker goroutines for opportunity processing
BOT_MAX_WORKERS=3
# Private RPC endpoint (optional, for faster execution)
# PRIVATE_RPC_URL=
# USE_PRIVATE_RPC=false
# Buffer size for opportunity channel
BOT_CHANNEL_BUFFER_SIZE=100
# ============================================================================
# WALLET CONFIGURATION
# ============================================================================
# ============================================================
# ETHEREUM ACCOUNT CONFIGURATION
# ============================================================
# CRITICAL: Replace with your actual private key (without 0x prefix)
# Generate with: cast wallet new (foundry) or eth-keygen
ETHEREUM_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000
# Private key for the wallet that will execute trades
# IMPORTANT: Never commit this file with real keys!
# Use a dedicated wallet for testing with test funds only
PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000
# Your Ethereum account address (checksum format)
ETHEREUM_ACCOUNT_ADDRESS=0x0000000000000000000000000000000000000000
# ============================================================================
# SMART CONTRACT ADDRESSES
# ============================================================================
# Gas price multiplier for competitive transaction submission (1.0 = no increase)
ETHEREUM_GAS_PRICE_MULTIPLIER=1.2
# Flashloan executor contract (deployed on Arbitrum)
# Leave as zero address if not deployed yet
EXECUTOR_CONTRACT=0x0000000000000000000000000000000000000000
# ============================================================
# CONTRACT ADDRESSES
# ============================================================
# Deploy these contracts first, then update addresses here
# See: docs/deployment/contract-deployment.md
CONTRACT_ARBITRAGE_EXECUTOR=0x0000000000000000000000000000000000000000
CONTRACT_FLASH_SWAPPER=0x0000000000000000000000000000000000000000
# ============================================================================
# TRADING PARAMETERS
# ============================================================================
# ============================================================
# SECURITY CONFIGURATION
# ============================================================
# Encryption key for keystore (MUST be 32+ characters)
# Generate with: openssl rand -base64 32
# CRITICAL: Keep this secret! Losing it means losing access to keys
MEV_BOT_ENCRYPTION_KEY=REPLACE_WITH_32_CHARACTER_MINIMUM_RANDOM_STRING_FROM_OPENSSL
# Minimum profit threshold (in wei, 0.01 ETH = 10000000000000000)
MIN_PROFIT=10000000000000000
# Keystore directory for encrypted private keys
MEV_BOT_KEYSTORE_PATH=keystore
# Minimum ROI percentage (1% = 0.01)
MIN_ROI=0.01
# Audit log path for security events
MEV_BOT_AUDIT_LOG=logs/audit.log
# Maximum slippage in basis points (200 = 2%)
MAX_SLIPPAGE_BPS=200
# Backup directory for key backups
MEV_BOT_BACKUP_PATH=backups
# Minimum swap amount (in wei, 0.001 ETH = 1000000000000000)
MIN_SWAP_AMOUNT=1000000000000000
# ============================================================
# LOGGING AND MONITORING
# ============================================================
# Log level: debug, info, warn, error
LOG_LEVEL=info
# Minimum pool liquidity (in wei, 1 ETH = 1000000000000000000)
MIN_POOL_LIQUIDITY=1000000000000000000
# Log format: text, json
LOG_FORMAT=text
# ============================================================================
# RISK MANAGEMENT
# ============================================================================
# Maximum position size per trade (in wei, 10 ETH = 10000000000000000000)
MAX_POSITION_SIZE=10000000000000000000
# Maximum daily volume (in wei, 100 ETH = 100000000000000000000)
MAX_DAILY_VOLUME=100000000000000000000
# Maximum gas limit per transaction
MAX_GAS_LIMIT=3000000
# Gas price strategy (fast, normal, slow)
GAS_PRICE_STRATEGY=fast
# ============================================================================
# ARBITRAGE DETECTION
# ============================================================================
# Maximum hops in arbitrage path
MAX_HOPS=3
# Maximum paths to explore per token
MAX_PATHS=100
# Maximum concurrent detection operations
MAX_CONCURRENT_DETECTION=10
# ============================================================================
# EXECUTION SETTINGS
# ============================================================================
# Enable transaction simulation before execution
ENABLE_SIMULATION=true
# Enable front-running of detected opportunities
ENABLE_FRONT_RUNNING=true
# Number of confirmations to wait
CONFIRMATION_BLOCKS=1
# Transaction timeout (in seconds)
TX_TIMEOUT=300
# Maximum retries for failed transactions
MAX_RETRIES=3
# ============================================================================
# POOL DISCOVERY
# ============================================================================
# Maximum number of pools to discover
MAX_POOLS_TO_DISCOVER=1000
# ============================================================================
# PERFORMANCE TUNING
# ============================================================================
# Number of worker threads for transaction processing
WORKER_COUNT=10
# Transaction buffer size
BUFFER_SIZE=1000
# ============================================================================
# MONITORING
# ============================================================================
# Enable Prometheus metrics endpoint
METRICS_ENABLED=true
# Metrics server port
METRICS_PORT=9090
# Log level (debug, info, warn, error)
LOG_LEVEL=info
# ============================================================
# ENVIRONMENT MODE
# ============================================================
# Environment: development, staging, production
# Controls which config file is loaded (config/local.yaml, config/staging.yaml, config/arbitrum_production.yaml)
GO_ENV=development
# ============================================================================
# TESTING CONFIGURATION
# ============================================================================
# Debug mode (verbose logging)
DEBUG=false
# Enable dry-run mode (log opportunities but don't execute)
# DRY_RUN=false
# ============================================================
# BLOCKCHAIN EXPLORER API KEYS (OPTIONAL)
# ============================================================
# Arbiscan API key for contract verification and transaction tracking
# Get free key from: https://arbiscan.io/apis
ARBISCAN_API_KEY=YOUR_ARBISCAN_API_KEY_HERE
# Enable test mode with reduced thresholds
# TEST_MODE=false
# ============================================================
# ADVANCED CONFIGURATION (OPTIONAL)
# ============================================================
# Allow localhost RPC endpoints (security: only enable for development)
MEV_BOT_ALLOW_LOCALHOST=false
# Dashboard server port
DASHBOARD_PORT=8080
# Security webhook URL for alerts (Slack, Discord, etc.)
SECURITY_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL

View File

@@ -1,205 +0,0 @@
# MEV Bot V2 - Production Safety Configuration
# ================================================
# DO NOT deploy without reviewing ALL settings below
# This configuration prioritizes safety over profitability
# ================================
# BLOCKCHAIN CONNECTION
# ================================
# CRITICAL: Use archive RPC provider for production
RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
WS_URL=wss://arb-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
SEQUENCER_WS_URL=wss://arb1.arbitrum.io/ws
CHAIN_ID=42161
# ================================
# WALLET CONFIGURATION
# ================================
# WARNING: Protect this key - use hardware wallet for large funds
PRIVATE_KEY=your_private_key_here
# EXECUTOR CONTRACT: Set to your deployed flashloan contract address
# Leave as 0x0 if not using flashloans
EXECUTOR_CONTRACT=0x0000000000000000000000000000000000000000
# ================================
# SAFETY MODE
# ================================
# DRY RUN: Set to "true" for simulation-only (NO REAL TRANSACTIONS)
# ONLY set to "false" after thorough testing
DRY_RUN_MODE=true
# EXECUTION: Disable actual execution until validated
ENABLE_EXECUTION=false
# SIMULATION: Always keep enabled for safety checks
ENABLE_SIMULATION=true
# FRONT-RUNNING: Disable until profit calculations validated
ENABLE_FRONT_RUNNING=false
# ================================
# PROFIT THRESHOLDS (Conservative)
# ================================
# Minimum profit required (in wei): 0.05 ETH = very conservative
MIN_PROFIT_WEI=50000000000000000
# Minimum ROI: 5% = conservative (rejects marginal opportunities)
MIN_ROI=0.05
# Minimum swap amount to consider (in wei): 0.1 ETH
MIN_SWAP_AMOUNT=100000000000000000
# Minimum pool liquidity (in wei): $50,000 equivalent
MIN_POOL_LIQUIDITY=50000000000000000000000
# ================================
# RISK LIMITS (Strict)
# ================================
# Maximum position size per trade: 1 ETH = very conservative
MAX_POSITION_SIZE=1000000000000000000
# Maximum daily trading volume: 10 ETH = strict daily limit
MAX_DAILY_VOLUME=10000000000000000000
# Maximum slippage tolerance: 1% = strict (prevents sandwich attacks)
MAX_SLIPPAGE_BPS=100
# Maximum gas limit per transaction: 1.5M gas
MAX_GAS_LIMIT=1500000
# Maximum gas price: 50 gwei (prevents overpaying during spikes)
MAX_GAS_PRICE_GWEI=50
# ================================
# CIRCUIT BREAKER THRESHOLDS
# ================================
# Stop trading after this many consecutive losses
MAX_CONSECUTIVE_LOSSES=3
# Stop trading if hourly loss exceeds this (in wei): 0.1 ETH
MAX_HOURLY_LOSS=100000000000000000
# Stop trading if daily loss exceeds this (in wei): 0.5 ETH
MAX_DAILY_LOSS=500000000000000000
# Cooldown period after circuit breaker trips (seconds): 1 hour
CIRCUIT_BREAKER_COOLDOWN=3600
# ================================
# GAS STRATEGY (Conservative)
# ================================
# Gas price strategy: "safe" = lower gas, slower inclusion
# Options: safe, standard, fast, ultra
GAS_PRICE_STRATEGY=safe
# Gas price multiplier: 1.0 = no markup (safer)
GAS_PRICE_MULTIPLIER=1.0
# ================================
# EXECUTION SETTINGS
# ================================
# Use private RPC for transaction submission (reduces MEV risk)
USE_PRIVATE_RPC=false
PRIVATE_RPC_URL=
# Transaction confirmation blocks: 1 for Arbitrum
CONFIRMATION_BLOCKS=1
# Transaction timeout: 2 minutes
TX_TIMEOUT_SECONDS=120
# Maximum retries for failed transactions
MAX_TX_RETRIES=2
# ================================
# ARBITRAGE DETECTION
# ================================
# Maximum hops in arbitrage path: 2 = simple, safer
MAX_HOPS=2
# Maximum paths to evaluate per opportunity: 50 = focused
MAX_PATHS=50
# Maximum concurrent opportunity evaluations: 5 = conservative
MAX_CONCURRENT_DETECTION=5
# ================================
# POOL DISCOVERY
# ================================
# Maximum pools to discover and monitor: 100 = focused set
MAX_POOLS_TO_DISCOVER=100
# Pool discovery interval (seconds): 5 minutes
POOL_DISCOVERY_INTERVAL=300
# ================================
# PERFORMANCE
# ================================
# Worker count for parallel processing: 4 = moderate
WORKER_COUNT=4
# Buffer size for event processing: 100
BUFFER_SIZE=100
# ================================
# MONITORING & ALERTS
# ================================
# Metrics server port
METRICS_PORT=9090
# Enable detailed logging
LOG_LEVEL=info
# Alert webhook URL (for Slack/Discord/Telegram)
ALERT_WEBHOOK_URL=
# Alert on circuit breaker trip
ALERT_ON_CIRCUIT_BREAKER=true
# Alert on large loss (threshold in wei): 0.05 ETH
ALERT_LOSS_THRESHOLD=50000000000000000
# ================================
# EMERGENCY CONTROLS
# ================================
# Emergency stop file path - create this file to stop bot immediately
EMERGENCY_STOP_FILE=/tmp/mev-bot-emergency-stop
# Auto-restart after emergency stop (dangerous - keep false)
AUTO_RESTART_AFTER_EMERGENCY_STOP=false
# ================================
# ADDITIONAL SAFETY FEATURES
# ================================
# Require manual confirmation for each trade (testing only)
REQUIRE_MANUAL_CONFIRMATION=true
# Maximum trades per hour: 10 = rate limiting
MAX_TRADES_PER_HOUR=10
# Blacklist pools (comma-separated addresses of problematic pools)
BLACKLISTED_POOLS=
# Whitelist tokens only (comma-separated addresses - empty = allow all)
WHITELISTED_TOKENS=
# ================================
# NOTES FOR PRODUCTION
# ================================
# Before deploying to production:
#
# 1. Set DRY_RUN_MODE=true initially and monitor for 24+ hours
# 2. Verify profit calculations match expected values
# 3. Ensure circuit breaker triggers correctly
# 4. Test emergency stop mechanism
# 5. Set up monitoring/alerting
# 6. Start with minimal position sizes
# 7. Gradually increase limits after validating profitability
# 8. NEVER set ENABLE_EXECUTION=true without thorough testing
#
# Recommended deployment sequence:
# Day 1: DRY_RUN_MODE=true (monitor only)
# Day 2-3: If stable, test with ENABLE_EXECUTION=true but MAX_POSITION_SIZE=0.1 ETH
# Day 4-7: If profitable, increase to MAX_POSITION_SIZE=0.5 ETH
# Week 2+: If consistently profitable, gradually increase limits

View File

View File

@@ -1,153 +0,0 @@
# Git Hooks for MEV Bot V2
This directory contains Git hooks to ensure code quality and consistency.
## Installation
Run these commands from the repository root:
```bash
# Make hooks executable
chmod +x .git-hooks/*
# Install pre-commit hook
ln -sf ../../.git-hooks/pre-commit .git/hooks/pre-commit
# Install commit-msg hook
ln -sf ../../.git-hooks/commit-msg .git/hooks/commit-msg
```
Or use the provided installation script:
```bash
./scripts/install-git-hooks.sh
```
## Available Hooks
### pre-commit
Runs before each commit and performs:
1. **Branch Name Validation** - Ensures correct naming convention
2. **Merge Conflict Detection** - Prevents committing conflict markers
3. **Secret Detection** - Scans for passwords, API keys, tokens
4. **Dependency Management** - Auto-tidies go.mod and go.sum
5. **Code Formatting** - Auto-formats Go code with gofmt
6. **Quick Tests** - Runs tests on changed packages
7. **Go Vet** - Runs static analysis
8. **File Size Check** - Warns about large files
### commit-msg
Validates commit message format:
**Required Format:**
```
type(scope): description
Optional body explaining the change
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
```
**Valid Types:**
- `feat` - New feature
- `fix` - Bug fix
- `perf` - Performance improvement
- `refactor` - Code refactoring
- `test` - Tests
- `docs` - Documentation
- `build` - Build system
- `ci` - CI/CD
**Example:**
```
feat(parsers): add UniswapV2 parser with event validation
- Implements ParseLog() for Swap events
- Adds token extraction from pool cache
- Includes comprehensive validation rules
- Achieves 100% test coverage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
```
## Bypassing Hooks (Emergency Only)
If you absolutely must bypass hooks:
```bash
git commit --no-verify -m "emergency fix"
```
**⚠️ Warning:** Only use in emergencies. CI/CD will still enforce all checks.
## Troubleshooting
### Hook not executing
1. Check if hook is executable:
```bash
ls -l .git/hooks/pre-commit
```
2. If not, make it executable:
```bash
chmod +x .git/hooks/pre-commit
```
### Hook failing unexpectedly
1. Run the hook manually to see errors:
```bash
.git/hooks/pre-commit
```
2. Check that all required tools are installed:
```bash
which gofmt
which go
```
### Disabling hooks temporarily
```bash
# Disable all hooks
git config core.hooksPath /dev/null
# Re-enable hooks
git config --unset core.hooksPath
```
## Best Practices
1. **Never bypass hooks** unless absolutely necessary
2. **Fix issues** instead of bypassing
3. **Keep hooks fast** - they run on every commit
4. **Test hooks locally** before committing to shared repository
5. **Document any new hooks** added to this directory
## Performance
Hooks are designed to be fast:
- **Pre-commit**: Typically < 5 seconds
- **Commit-msg**: < 1 second
If hooks are slow, consider:
1. Only testing changed packages (already implemented)
2. Using `--short` flag for tests (already implemented)
3. Running full tests in CI/CD instead
## Maintenance
Review and update hooks periodically:
1. Add new checks as project evolves
2. Remove obsolete checks
3. Optimize performance
4. Keep documentation up to date

View File

@@ -1,90 +0,0 @@
#!/bin/bash
#
# Commit message hook for MEV Bot V2
# Validates commit message format
#
# Install: ln -sf ../../.git-hooks/commit-msg .git/hooks/commit-msg
#
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
# Skip if this is a merge commit
if git rev-parse -q --verify MERGE_HEAD > /dev/null; then
echo -e "${GREEN} Merge commit detected, skipping validation${NC}"
exit 0
fi
# Skip if this is an amend
if [ -n "$GIT_EDITOR" ]; then
echo -e "${GREEN} Amend detected, skipping validation${NC}"
exit 0
fi
echo -e "${GREEN}📝 Validating commit message...${NC}"
# Required format: type(scope): description
# type: feat, fix, perf, refactor, test, docs, build, ci
# scope: component name (parsers, cache, validation, etc.)
PATTERN="^(feat|fix|perf|refactor|test|docs|build|ci)\([a-z0-9-]+\): .{10,}"
if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
echo -e "${RED}❌ Invalid commit message format${NC}"
echo ""
echo -e "${YELLOW}Required format:${NC}"
echo -e " type(scope): brief description"
echo ""
echo -e "${YELLOW}Valid types:${NC}"
echo -e " feat - New feature"
echo -e " fix - Bug fix"
echo -e " perf - Performance improvement"
echo -e " refactor - Code refactoring"
echo -e " test - Adding or updating tests"
echo -e " docs - Documentation updates"
echo -e " build - Build system changes"
echo -e " ci - CI/CD changes"
echo ""
echo -e "${YELLOW}Example:${NC}"
echo -e " feat(parsers): add UniswapV2 parser with event validation"
echo ""
echo -e "${YELLOW}Your message:${NC}"
echo -e " $COMMIT_MSG"
echo ""
exit 1
fi
# Check for minimum description length
DESCRIPTION=$(echo "$COMMIT_MSG" | head -n1 | sed 's/^[^:]*: //')
if [ ${#DESCRIPTION} -lt 10 ]; then
echo -e "${RED}❌ Commit description too short (minimum 10 characters)${NC}"
echo -e "${YELLOW}Your description: $DESCRIPTION (${#DESCRIPTION} chars)${NC}"
exit 1
fi
# Check for maximum line length (72 chars for first line)
FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)
if [ ${#FIRST_LINE} -gt 72 ]; then
echo -e "${YELLOW}⚠️ Warning: First line exceeds 72 characters (${#FIRST_LINE} chars)${NC}"
echo -e "${YELLOW} Consider shortening the description${NC}"
echo ""
fi
# Encourage including coverage info for test changes
if echo "$COMMIT_MSG" | grep -q "^test"; then
if ! echo "$COMMIT_MSG" | grep -qi "coverage"; then
echo -e "${YELLOW}💡 Tip: Consider including coverage info in test commits${NC}"
echo ""
fi
fi
echo -e "${GREEN}✅ Commit message format valid${NC}"
echo ""
exit 0

View File

@@ -1,202 +0,0 @@
#!/bin/bash
#
# Pre-commit hook for MEV Bot V2
# Ensures code quality and consistency before commits
#
# Install: ln -sf ../../.git-hooks/pre-commit .git/hooks/pre-commit
#
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}🔍 Running pre-commit checks...${NC}"
echo ""
# ==============================================================================
# 1. CHECK BRANCH NAME
# ==============================================================================
BRANCH_NAME=$(git branch --show-current)
if [[ "$BRANCH_NAME" == "feature/v2-prep" ]] || [[ "$BRANCH_NAME" == "master" ]]; then
echo -e "${YELLOW}⚠️ Warning: Committing to protected branch: $BRANCH_NAME${NC}"
echo -e "${YELLOW} Consider creating a feature branch instead${NC}"
echo ""
fi
if [[ "$BRANCH_NAME" =~ ^feature/v2/ ]]; then
# Validate branch naming convention
if [[ ! "$BRANCH_NAME" =~ ^feature/v2/[a-z0-9-]+/[A-Z0-9]+-[0-9]+-[a-z0-9-]+$ ]]; then
echo -e "${YELLOW}⚠️ Branch name doesn't follow convention:${NC}"
echo -e "${YELLOW} feature/v2/<component>/<TASK-ID>-<description>${NC}"
echo ""
fi
fi
# ==============================================================================
# 2. CHECK FOR MERGE CONFLICTS
# ==============================================================================
echo -e "${GREEN}📋 Checking for merge conflicts...${NC}"
if git diff --cached --name-only | xargs grep -l "^<<<<<<< HEAD" 2>/dev/null; then
echo -e "${RED}❌ Merge conflict markers found${NC}"
echo -e "${RED} Resolve conflicts before committing${NC}"
exit 1
fi
echo -e "${GREEN}✅ No merge conflicts${NC}"
echo ""
# ==============================================================================
# 3. CHECK FOR FORBIDDEN PATTERNS
# ==============================================================================
echo -e "${GREEN}🔒 Checking for secrets and forbidden patterns...${NC}"
# Check for common secret patterns
if git diff --cached --name-only -z | xargs -0 grep -E "password|secret|api[_-]?key|private[_-]?key|token" --include="*.go" 2>/dev/null | grep -v "test" | grep -v "example"; then
echo -e "${RED}❌ Potential secrets found${NC}"
echo -e "${RED} Remove secrets before committing${NC}"
exit 1
fi
# Check for debugging statements
if git diff --cached --name-only -z | xargs -0 grep -E "fmt\.Println|log\.Println|panic\(|TODO.*URGENT|FIXME.*CRITICAL" --include="*.go" 2>/dev/null; then
echo -e "${YELLOW}⚠️ Warning: Found debugging statements or urgent TODOs${NC}"
echo -e "${YELLOW} Consider removing or creating issues for them${NC}"
echo ""
fi
echo -e "${GREEN}✅ No forbidden patterns found${NC}"
echo ""
# ==============================================================================
# 4. GO MOD TIDY CHECK
# ==============================================================================
if [ -f "go.mod" ]; then
echo -e "${GREEN}📦 Checking if go.mod is tidy...${NC}"
# Save current go.mod and go.sum
cp go.mod go.mod.backup
cp go.sum go.sum.backup
# Run go mod tidy
go mod tidy
# Check if anything changed
if ! diff -q go.mod go.mod.backup > /dev/null 2>&1 || ! diff -q go.sum go.sum.backup > /dev/null 2>&1; then
echo -e "${YELLOW}⚠️ go.mod or go.sum was not tidy${NC}"
echo -e "${YELLOW} Auto-fixed and staged${NC}"
git add go.mod go.sum
fi
# Clean up backups
rm -f go.mod.backup go.sum.backup
echo -e "${GREEN}✅ Dependencies are tidy${NC}"
echo ""
fi
# ==============================================================================
# 5. CODE FORMATTING
# ==============================================================================
echo -e "${GREEN}🎨 Checking code formatting...${NC}"
# Get list of staged Go files
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "\.go$" || true)
if [ -n "$STAGED_GO_FILES" ]; then
# Check formatting
UNFORMATTED=$(gofmt -l $STAGED_GO_FILES 2>/dev/null || true)
if [ -n "$UNFORMATTED" ]; then
echo -e "${YELLOW}⚠️ Auto-formatting files:${NC}"
echo "$UNFORMATTED"
# Auto-format files
echo "$UNFORMATTED" | xargs gofmt -w -s
# Re-stage formatted files
echo "$UNFORMATTED" | xargs git add
echo -e "${GREEN}✅ Code formatted and re-staged${NC}"
else
echo -e "${GREEN}✅ All files properly formatted${NC}"
fi
else
echo -e "${GREEN} No Go files to format${NC}"
fi
echo ""
# ==============================================================================
# 6. RUN TESTS ON CHANGED FILES
# ==============================================================================
if [ -n "$STAGED_GO_FILES" ]; then
echo -e "${GREEN}🧪 Running tests on changed packages...${NC}"
# Get unique package directories
PACKAGES=$(echo "$STAGED_GO_FILES" | xargs -n1 dirname | sort -u | sed 's/$/\/.../')
# Run tests with timeout
if ! go test -short -timeout=2m $PACKAGES 2>&1; then
echo -e "${RED}❌ Tests failed${NC}"
echo -e "${RED} Fix tests before committing${NC}"
exit 1
fi
echo -e "${GREEN}✅ Tests passed${NC}"
else
echo -e "${GREEN} No Go files changed, skipping tests${NC}"
fi
echo ""
# ==============================================================================
# 7. RUN GO VET
# ==============================================================================
if [ -n "$STAGED_GO_FILES" ]; then
echo -e "${GREEN}🔍 Running go vet...${NC}"
if ! go vet ./... 2>&1; then
echo -e "${RED}❌ go vet found issues${NC}"
echo -e "${RED} Fix issues before committing${NC}"
exit 1
fi
echo -e "${GREEN}✅ go vet passed${NC}"
fi
echo ""
# ==============================================================================
# 8. CHECK FILE SIZES
# ==============================================================================
echo -e "${GREEN}📏 Checking file sizes...${NC}"
LARGE_FILES=$(git diff --cached --name-only | xargs -I {} sh -c 'if [ -f "{}" ]; then stat -f%z "{}" 2>/dev/null || stat -c%s "{}" 2>/dev/null; fi' | awk '$1 > 1048576 {print}' || true)
if [ -n "$LARGE_FILES" ]; then
echo -e "${YELLOW}⚠️ Warning: Large files detected (>1MB)${NC}"
echo -e "${YELLOW} Consider if these should be committed${NC}"
git diff --cached --name-only | while read file; do
size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null)
if [ "$size" -gt 1048576 ]; then
size_mb=$(echo "scale=2; $size / 1048576" | bc)
echo -e "${YELLOW} $file: ${size_mb}MB${NC}"
fi
done
echo ""
fi
echo -e "${GREEN}✅ File size check complete${NC}"
echo ""
# ==============================================================================
# 9. FINAL SUMMARY
# ==============================================================================
echo -e "${GREEN}╔══════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✅ PRE-COMMIT CHECKS PASSED ✅ ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════╝${NC}"
echo ""
echo -e "${GREEN}Proceeding with commit...${NC}"
exit 0

79
.gitattributes vendored
View File

@@ -1,79 +0,0 @@
# Git attributes for MEV Bot V2
# Optimizes git operations and ensures consistent handling across platforms
# Auto detect text files and perform LF normalization
* text=auto
# Source code
*.go text eol=lf
*.mod text eol=lf
*.sum text eol=lf
*.sh text eol=lf
*.bash text eol=lf
# Documentation
*.md text eol=lf
*.txt text eol=lf
*.json text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.toml text eol=lf
# Configuration
.gitignore text eol=lf
.gitattributes text eol=lf
.golangci.yml text eol=lf
Makefile text eol=lf
Dockerfile text eol=lf
# Scripts
scripts/* text eol=lf
# Binary files
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.gz binary
*.zip binary
*.tar binary
*.pdf binary
# Go binaries
*.exe binary
*.so binary
*.dylib binary
# Archives
*.7z binary
*.jar binary
*.rar binary
*.tar.gz binary
*.tgz binary
# Exclude files from export-ignore (speeds up git archive)
.gitattributes export-ignore
.gitignore export-ignore
.github export-ignore
.golangci.yml export-ignore
*.md export-ignore
docs export-ignore
scripts export-ignore
# Git LFS tracking for large files (if needed in future)
# *.bin filter=lfs diff=lfs merge=lfs -text
# *.dat filter=lfs diff=lfs merge=lfs -text
# Diff settings
*.go diff=golang
*.mod diff=golang
*.sum diff=golang
# Merge strategies
*.json merge=ours
*.lock merge=ours
go.sum merge=ours

View File

@@ -1,483 +0,0 @@
name: V2 CI/CD Pipeline
on:
push:
branches:
- 'feature/v2-**'
- 'feature/v2/**'
pull_request:
branches:
- 'feature/v2-prep'
- 'master'
paths:
- 'pkg/**'
- 'cmd/**'
- 'internal/**'
- 'go.mod'
- 'go.sum'
- '.github/workflows/**'
workflow_dispatch:
inputs:
run_benchmarks:
description: 'Run performance benchmarks'
required: false
default: 'true'
type: boolean
env:
GO_VERSION: '1.25'
MIN_COVERAGE: 100
GOLANGCI_LINT_VERSION: 'v1.61.0'
jobs:
# ==============================================================================
# PRE-FLIGHT CHECKS
# ==============================================================================
pre_flight:
name: Pre-Flight Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate branch naming
run: |
BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ ! "$BRANCH_NAME" =~ ^feature/v2/[a-z0-9-]+/[A-Z0-9]+-[0-9]+-[a-z0-9-]+$ ]]; then
echo "❌ Invalid branch name: $BRANCH_NAME"
echo ""
echo "Branch must follow: feature/v2/<component>/<TASK-ID>-<description>"
echo ""
echo "Examples:"
echo " feature/v2/parsers/P2-002-uniswap-v2-base"
echo " feature/v2/cache/P3-001-address-index"
echo " feature/v2/validation/P4-001-validation-rules"
exit 1
fi
fi
echo "✅ Branch naming validation passed"
- name: Check commit message format
if: github.event_name == 'push'
run: |
# Get the last commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
# Check format: type(scope): description
if [[ ! "$COMMIT_MSG" =~ ^(feat|fix|perf|refactor|test|docs|build|ci)\([a-z0-9-]+\):\ .+ ]]; then
echo "❌ Invalid commit message format"
echo ""
echo "Format: type(scope): brief description"
echo ""
echo "Types: feat, fix, perf, refactor, test, docs, build, ci"
echo ""
echo "Example:"
echo " feat(parsers): add UniswapV2 parser with event validation"
exit 1
fi
echo "✅ Commit message format valid"
# ==============================================================================
# BUILD & DEPENDENCIES
# ==============================================================================
build:
name: Build & Dependencies
runs-on: ubuntu-latest
needs: pre_flight
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ env.GO_VERSION }}-
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Check for tidy modules
run: |
go mod tidy
if [ -n "$(git status --porcelain go.mod go.sum)" ]; then
echo "❌ go.mod or go.sum is not tidy"
echo "Run: go mod tidy"
git diff go.mod go.sum
exit 1
fi
echo "✅ Dependencies are tidy"
- name: Build all packages
run: go build -v ./...
- name: Build main binary (if exists)
run: |
if [ -d "cmd/mev-bot" ]; then
go build -v -o bin/mev-bot ./cmd/mev-bot
echo "✅ Binary built successfully"
else
echo " No main application yet (planning phase)"
fi
# ==============================================================================
# CODE QUALITY
# ==============================================================================
code_quality:
name: Code Quality & Linting
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run gofmt
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "❌ Code is not formatted"
echo "Files needing formatting:"
gofmt -l .
echo ""
echo "Run: gofmt -w ."
exit 1
fi
echo "✅ Code formatting passed"
- name: Run go vet
run: go vet ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: --timeout=10m --config=.golangci.yml
- name: Run gosec security scanner
run: |
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest
gosec -fmt sarif -out gosec.sarif ./... || true
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: gosec.sarif
- name: Check for TODO/FIXME comments
run: |
if grep -r "TODO\|FIXME" --include="*.go" pkg/ cmd/ internal/ | grep -v "_test.go"; then
echo "⚠️ TODO/FIXME comments found - ensure they're tracked in issues"
fi
# ==============================================================================
# UNIT TESTS WITH 100% COVERAGE ENFORCEMENT
# ==============================================================================
unit_tests:
name: Unit Tests (100% Coverage Required)
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
- name: Run tests with race detector
run: |
go test -v -race -timeout=30m ./...
- name: Generate coverage report
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Calculate coverage percentage
id: coverage
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Coverage: $COVERAGE%"
- name: Enforce 100% coverage requirement
run: |
COVERAGE=${{ steps.coverage.outputs.coverage }}
MIN_COVERAGE=${{ env.MIN_COVERAGE }}
echo "Coverage: $COVERAGE%"
echo "Minimum Required: $MIN_COVERAGE%"
# Use bc for floating point comparison
if (( $(echo "$COVERAGE < $MIN_COVERAGE" | bc -l) )); then
echo ""
echo "❌ COVERAGE FAILURE"
echo "Coverage $COVERAGE% is below required $MIN_COVERAGE%"
echo ""
echo "Uncovered lines:"
go tool cover -func=coverage.out | grep -v "100.0%"
echo ""
echo "See docs/planning/03_TESTING_REQUIREMENTS.md for details"
exit 1
fi
echo "✅ Coverage requirement met: $COVERAGE%"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests
name: v2-coverage
- name: Generate HTML coverage report
run: |
go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.out
coverage.html
retention-days: 30
# ==============================================================================
# INTEGRATION TESTS
# ==============================================================================
integration_tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit_tests
if: contains(github.event.head_commit.message, '[integration]') || github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
- name: Run integration tests
run: |
go test -v -timeout=30m -tags=integration ./...
- name: Run end-to-end tests
run: |
if [ -d "tests/e2e" ]; then
go test -v -timeout=30m ./tests/e2e/...
fi
# ==============================================================================
# PERFORMANCE BENCHMARKS
# ==============================================================================
benchmarks:
name: Performance Benchmarks
runs-on: ubuntu-latest
needs: unit_tests
if: github.event.inputs.run_benchmarks == 'true' || contains(github.event.head_commit.message, '[bench]')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run benchmarks
run: |
go test -bench=. -benchmem -benchtime=10s ./... > benchmark.txt
cat benchmark.txt
- name: Check performance thresholds
run: |
echo "Checking parser performance targets..."
# Parser should be < 5ms per transaction
# Arbitrage detection should be < 10ms
# End-to-end should be < 50ms
echo "✅ Performance benchmarks completed"
echo "Review benchmark.txt for detailed results"
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmarks
path: benchmark.txt
retention-days: 90
# ==============================================================================
# DECIMAL PRECISION TESTS
# ==============================================================================
decimal_tests:
name: Decimal Precision Validation
runs-on: ubuntu-latest
needs: unit_tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Run decimal precision tests
run: |
# Run tests that specifically test decimal handling
go test -v -run TestDecimal ./...
echo "✅ Decimal precision tests passed"
# ==============================================================================
# MODULARITY VALIDATION
# ==============================================================================
modularity_check:
name: Modularity Validation
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Check component independence
run: |
echo "Validating component modularity..."
# Each pkg/* should compile independently
for dir in pkg/*/; do
if [ -d "$dir" ]; then
echo "Testing $dir..."
(cd "$dir" && go build .) || exit 1
fi
done
echo "✅ All components compile independently"
- name: Check for circular dependencies
run: |
go install golang.org/x/tools/cmd/godepgraph@latest
godepgraph ./... | grep -i cycle && exit 1 || echo "✅ No circular dependencies"
# ==============================================================================
# FINAL VALIDATION
# ==============================================================================
final_check:
name: Final Validation Summary
runs-on: ubuntu-latest
needs:
- pre_flight
- build
- code_quality
- unit_tests
- modularity_check
- decimal_tests
if: always()
steps:
- name: Check all jobs status
run: |
echo "# 🤖 MEV Bot V2 CI/CD Summary" > summary.md
echo "" >> summary.md
echo "**Commit**: ${{ github.sha }}" >> summary.md
echo "**Branch**: ${{ github.ref_name }}" >> summary.md
echo "**Timestamp**: $(date -u)" >> summary.md
echo "" >> summary.md
echo "## Test Results" >> summary.md
echo "| Check | Status |" >> summary.md
echo "|-------|--------|" >> summary.md
echo "| Pre-Flight | ${{ needs.pre_flight.result == 'success' && '✅' || '❌' }} |" >> summary.md
echo "| Build | ${{ needs.build.result == 'success' && '✅' || '❌' }} |" >> summary.md
echo "| Code Quality | ${{ needs.code_quality.result == 'success' && '✅' || '❌' }} |" >> summary.md
echo "| Unit Tests (100% Coverage) | ${{ needs.unit_tests.result == 'success' && '✅' || '❌' }} |" >> summary.md
echo "| Modularity | ${{ needs.modularity_check.result == 'success' && '✅' || '❌' }} |" >> summary.md
echo "| Decimal Precision | ${{ needs.decimal_tests.result == 'success' && '✅' || '❌' }} |" >> summary.md
cat summary.md
# Check if all required jobs passed
if [[ "${{ needs.pre_flight.result }}" == "success" &&
"${{ needs.build.result }}" == "success" &&
"${{ needs.code_quality.result }}" == "success" &&
"${{ needs.unit_tests.result }}" == "success" &&
"${{ needs.modularity_check.result }}" == "success" &&
"${{ needs.decimal_tests.result }}" == "success" ]]; then
echo "" >> summary.md
echo "## ✅ ALL CHECKS PASSED" >> summary.md
echo "Ready for merge to v2-prep branch" >> summary.md
exit 0
else
echo "" >> summary.md
echo "## ❌ CHECKS FAILED" >> summary.md
echo "Fix failing checks before merging" >> summary.md
exit 1
fi
- name: Upload summary
uses: actions/upload-artifact@v4
if: always()
with:
name: ci-summary
path: summary.md
- name: Comment on PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request' && always()
with:
script: |
const fs = require('fs');
const summary = fs.readFileSync('summary.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});

108
.gitignore vendored
View File

@@ -1,27 +1,33 @@
# Environment files with secrets
# Binaries
bin/
mev-bot
mev-bot-test
ci-agent-bridge
# Configuration files that might contain sensitive information
config/local.yaml
config/secrets.yaml
config/providers.yaml
config/*_production.yaml
config/*_staging.yaml
.env
.env.local
.env.*.local
.env.production
.env.staging
.env.development
.env.test
# Private keys and wallets
*.key
*.keystore
keystore/
wallets/
# Salt file for key derivation (CRITICAL: Must not be committed)
keystore/.salt
# Build artifacts
bin/
build/
dist/
*.exe
*.dll
*.so
*.dylib
# Go workspace and modules
go.work
go.work.sum
# Test coverage
*.out
coverage.html
# Test coverage files
coverage.txt
coverage.html
coverage.out
# IDE files
.vscode/
@@ -30,57 +36,51 @@ coverage.txt
*.swo
*~
# OS files
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Logs
logs/
# Log files and backups
*.log
logs/*.log
logs/*.bak
logs/*.jsonl
# Data directories
data/
# Database files
*.db
*.sqlite
*.sqlite3
# Docker volumes
volumes/
# Security and keystore files
keystore/
*.key
*.pem
*.p12
# Temporary files
# Data and temporary directories
data/
tmp/
temp/
*.tmp
# Dependency directories
vendor/
node_modules/
# Compiled binaries
mev-bot-v2
mev-bot-v1
# Monitoring data
prometheus-data/
grafana-data/
# Backup files
*.bak
*.backup
*~
backup/
backups/
artifacts/
# Archive files
*.tar
*.tar.gz
*.zip
*.tar
# Swap detection test data
detected_swaps.jsonl
swap_replay.log
replayed_swaps.log
anvil_fresh.log
# Performance profiles
*.prof
*.out
# Arbitrage detection test data
arbitrage_detection_test.log
ARBITRAGE_DETECTION_TEST_RESULTS.md
/tmp/mev-bot-test.log
.wallet_info.txt
# Documentation builds
docs/_build/
.gocache/
.gomodcache/

12
.gitmodules vendored
View File

@@ -1,3 +1,9 @@
[submodule "contracts"]
path = contracts
url = ssh://git@194.163.145.241:2222/copper-tone-tech/mev-beta-contracts.git
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "contracts/foundry/lib/forge-std"]
path = contracts/foundry/lib/forge-std
url = https://github.com/foundry-rs/forge-std

Some files were not shown because too many files have changed in this diff Show More