feat: create v2-prep branch with comprehensive planning

Restructured project for V2 refactor:

**Structure Changes:**
- Moved all V1 code to orig/ folder (preserved with git mv)
- Created docs/planning/ directory
- Added orig/README_V1.md explaining V1 preservation

**Planning Documents:**
- 00_V2_MASTER_PLAN.md: Complete architecture overview
  - Executive summary of critical V1 issues
  - High-level component architecture diagrams
  - 5-phase implementation roadmap
  - Success metrics and risk mitigation

- 07_TASK_BREAKDOWN.md: Atomic task breakdown
  - 99+ hours of detailed tasks
  - Every task < 2 hours (atomic)
  - Clear dependencies and success criteria
  - Organized by implementation phase

**V2 Key Improvements:**
- Per-exchange parsers (factory pattern)
- Multi-layer strict validation
- Multi-index pool cache
- Background validation pipeline
- Comprehensive observability

**Critical Issues Addressed:**
- Zero address tokens (strict validation + cache enrichment)
- Parsing accuracy (protocol-specific parsers)
- No audit trail (background validation channel)
- Inefficient lookups (multi-index cache)
- Stats disconnection (event-driven metrics)

Next Steps:
1. Review planning documents
2. Begin Phase 1: Foundation (P1-001 through P1-010)
3. Implement parsers in Phase 2
4. Build cache system in Phase 3
5. Add validation pipeline in Phase 4
6. Migrate and test in Phase 5

🤖 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 10:14:26 +01:00
parent 1773daffe7
commit 803de231ba
411 changed files with 20390 additions and 8680 deletions

View File

@@ -0,0 +1,137 @@
# MEV Bot Exchange Support
## Overview
This directory contains implementations for various decentralized exchange (DEX) protocols in the MEV Bot. Each exchange protocol is implemented with a consistent interface to allow for cross-exchange arbitrage opportunities.
## Supported Exchanges
### Core V2-style AMMs
- **Uniswap V2**: Standard constant product AMM
- **SushiSwap**: Fork of Uniswap V2 with additional features
- **PancakeSwap**: Binance Smart Chain implementation similar to Uniswap V2
### V3-style Concentrated Liquidity
- **Uniswap V3**: Concentrated liquidity with ticks and fee tiers
- **Uniswap V4**: Next-generation AMM with hooks and more flexibility
- **Kyber**: Elastic AMM with concentrated liquidity and custom hooks
- **Camelot**: Arbitrum-focused AMM with concentrated liquidity
### StableSwap AMMs
- **Curve**: Stableswap algorithm for similar-asset swaps
- **Balancer**: Weighted and stable pool implementations
### Multi-Asset AMMs
- **Balancer**: Weighted, stable, and composable stable pools
- **Dex Aggregators**: Integration with 1inch, ParaSwap, etc.
## Architecture
Each exchange implementation follows the same interface pattern with three primary components:
### 1. PoolDetector
- Discovers pools for token pairs
- Handles multiple fee tiers
- Identifies pool types
### 2. LiquidityFetcher
- Fetches pool reserves and data
- Calculates spot prices
- Estimates liquidity depth
### 3. SwapRouter
- Calculates swap amounts
- Generates transaction data
- Validates swaps
## Exchange-Specific Features
### Uniswap V4
- Hooks support for custom logic
- Concentrated liquidity model
- Flexible fees and parameters
### Kyber
- Elastic AMM architecture
- Concentrated liquidity
- Customizable parameters
### Curve
- Stableswap invariant
- Multi-asset support
- Amplification coefficients
### Balancer
- Weighted pools
- Stable pools
- Composable stable pools
- Managed pools
### Aggregators
- Multi-DEX routing
- Gas optimization
- Price comparison across exchanges
## Common Interface Usage
All exchanges implement the following interfaces:
```go
type PoolDetector interface {
GetAllPools(token0, token1 common.Address) ([]common.Address, error)
GetPoolForPair(token0, token1 common.Address) (common.Address, error)
GetSupportedFeeTiers() []int64
GetPoolType() string
}
type LiquidityFetcher interface {
GetPoolData(poolAddress common.Address) (*math.PoolData, error)
GetTokenReserves(poolAddress, token0, token1 common.Address) (*big.Int, *big.Int, error)
GetPoolPrice(poolAddress common.Address) (*big.Float, error)
GetLiquidityDepth(poolAddress, tokenIn common.Address, amount *big.Int) (*big.Int, error)
}
type SwapRouter interface {
CalculateSwap(tokenIn, tokenOut common.Address, amountIn *big.Int) (*big.Int, error)
GenerateSwapData(tokenIn, tokenOut common.Address, amountIn, minAmountOut *big.Int, deadline *big.Int) ([]byte, error)
GetSwapRoute(tokenIn, tokenOut common.Address) ([]common.Address, error)
ValidateSwap(tokenIn, tokenOut common.Address, amountIn *big.Int) error
}
```
## Cross-Exchange Arbitrage
The system supports identifying and executing arbitrage opportunities across all supported exchanges. The `CrossExchangeArbitrageFinder` component:
- Monitors prices across all exchanges
- Identifies profitable opportunities
- Considers gas costs and slippage
- Executes arbitrage when profitable
## Configuration
Each exchange has specific configuration parameters including:
- Contract addresses (factory, router)
- Chain ID
- Default slippage tolerance
- Gas estimation parameters
- Pool initialization code hash
- Supported fee tiers
## Math Support
The system includes exchange-specific pricing models via the `ExchangePricingEngine`:
- Uniswap V2: Constant product formula
- Uniswap V3/V4: Concentrated liquidity with ticks
- Curve: Stableswap invariant
- Balancer: Weighted and stable pool formulas
- Kyber: Elastic concentrated liquidity
## Performance Considerations
- Efficient pool discovery mechanisms
- Cached price calculations
- Optimized route finding
- Gas cost estimation
- Slippage protection