Files
mev-beta/docs/master-plan/02-common-interfaces.md
Krypto Kajun 850223a953 fix(multicall): resolve critical multicall parsing corruption issues
- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing
- Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives
- Added LRU caching system for address validation with 10-minute TTL
- Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures
- Fixed duplicate function declarations and import conflicts across multiple files
- Added error recovery mechanisms with multiple fallback strategies
- Updated tests to handle new validation behavior for suspicious addresses
- Fixed parser test expectations for improved validation system
- Applied gofmt formatting fixes to ensure code style compliance
- Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot
- Resolved critical security vulnerabilities in heuristic address extraction
- Progress: Updated TODO audit from 10% to 35% complete

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 00:12:55 -05:00

92 lines
2.5 KiB
Markdown

# Common Interfaces for Exchange Modules
## Overview
This document defines the common interfaces that all exchange-specific modules should implement to ensure consistency across the MEV bot.
## Core Interface
```go
type Exchange interface {
// Swap operations
Swap(fromToken, toToken string, amount *big.Int) (*SwapResult, error)
SwapExactIn(fromToken, toToken string, amountIn *big.Int) (*SwapResult, error)
SwapExactOut(fromToken, toToken string, amountOut *big.Int) (*SwapResult, error)
// Liquidity operations
AddLiquidity(tokenA, tokenB string, amountADesired, amountBDesired *big.Int) (*LiquidityResult, error)
RemoveLiquidity(tokenA, tokenB string, liquidity *big.Int) (*LiquidityResult, error)
// Pricing functions
GetPrice(fromToken, toToken string, amount *big.Int) (*big.Int, error)
GetAmountsOut(amountIn *big.Int, path []string) ([]*big.Int, error)
GetAmountsIn(amountOut *big.Int, path []string) ([]*big.Int, error)
// Pool information
GetPoolReserves(tokenA, tokenB string) (*big.Int, *big.Int, error)
GetPair(tokenA, tokenB string) (common.Address, error)
// Pool management
GetAllPools() []Pool
GetPoolByAddress(address common.Address) (Pool, error)
// Fee calculations
GetSwapFee() (*big.Int, error)
CalculateSlippage(amount *big.Int, slippagePercent float64) (*big.Int, error)
}
```
## Swap Result Structure
```go
type SwapResult struct {
FromToken string
ToToken string
AmountIn *big.Int
AmountOut *big.Int
ExpectedAmount *big.Int
GasEstimate *big.Int
Route []string
}
```
## Liquidity Result Structure
```go
type LiquidityResult struct {
TokenA string
TokenB string
AmountA *big.Int
AmountB *big.Int
Liquidity *big.Int
GasEstimate *big.Int
}
```
## Pool Structure
```go
type Pool struct {
Address common.Address
Token0 string
Token1 string
Reserve0 *big.Int
Reserve1 *big.Int
Fee *big.Int
}
```
## Error Handling
- All functions should return standardized errors
- Network-related errors should be distinguishable
- Invalid input errors should be clearly identified
- Slippage tolerance exceeded errors should be handled
## Implementation Guidelines
1. All external calls should be properly validated
2. Input parameters should be sanitized before use
3. Gas estimation should be performed where possible
4. Proper timeout handling for external calls
5. Fallback mechanisms for critical operations