- 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>
2.5 KiB
2.5 KiB
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
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
type SwapResult struct {
FromToken string
ToToken string
AmountIn *big.Int
AmountOut *big.Int
ExpectedAmount *big.Int
GasEstimate *big.Int
Route []string
}
Liquidity Result Structure
type LiquidityResult struct {
TokenA string
TokenB string
AmountA *big.Int
AmountB *big.Int
Liquidity *big.Int
GasEstimate *big.Int
}
Pool Structure
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
- All external calls should be properly validated
- Input parameters should be sanitized before use
- Gas estimation should be performed where possible
- Proper timeout handling for external calls
- Fallback mechanisms for critical operations