# 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