# Curve Integration Plan ## Overview This document outlines the implementation plan for Curve exchange support in the MEV bot. Curve specializes in stablecoin and pegged-asset swaps with low slippage and low fees. ## Contract Architecture ### Core Contracts - Main Registry: `0x7D86446dDb609eD0F5f8684AcF3037Ffb6149cC6` - Factory Registry: `0xF1815bdCbcC67D79Cbb7B3C7b2E6d9992E6C1e86` - Router: `0x8474DdbE98F5aC77e0C38b3C97ad441436D69d2C` - Exchange Proxy: `0xD152CC3E6A9Ca3Cd5085767eD16a8921152B6867` ### Pool Types - StableSwap pools (3pool, 4pool, etc.) - CryptoSwap pools (tricrypto, etc.) - MetaStable pools - Lending pools - Factory pools ## Core Functions ### Swap Functions - `exchange` (basic swap) - `exchange_underlying` (swap underlying assets) - `get_dy` (calculate output without executing) - `get_dx` (calculate input without executing) - `exchange_extra` (swap with additional features) ### Pool Management - `add_liquidity` - `remove_liquidity` - `remove_liquidity_one_coin` - `calc_token_amount` (estimate LP token amount) - `calc_withdraw_one_coin` (estimate withdrawal amount) ### Pool-Specific Functions - Pool-specific swap functions for different curve types - Virtual price calculations - Fee distribution functions - Pool parameter modifications ## Implementation Steps 1. Create Curve struct implementing the Exchange interface 2. Implement adapter for different pool types 3. Handle curve's unique pricing mechanism (constant function AMM optimized for similar assets) 4. Implement multi-hop swaps between different pool types 5. Add support for underlying asset swaps 6. Implement virtual price calculations 7. Add support for factory-deployed pools 8. Create pool discovery and indexing functions ## Pricing Mechanisms ### Curve-Specific Pricing - Use Curve's mathematical formula for stablecoin swaps - Account for amplification coefficient (A) - Consider fee structure (dynamic based on trade size) - Handle different pool types with varying parameters - Calculate virtual price for accurate pricing ### Multi-Asset Pools - Support for pools with 2, 3, 4+ assets - Handle asymmetric deposits/withdrawals - Calculate effective rates between different asset pairs ## Testing Plan 1. Unit tests for stablecoin swap functions 2. Testing with different amplification coefficients 3. Virtual price calculation verification 4. Multi-asset pool testing 5. Factory pool integration tests 6. Edge case testing (extreme amounts, pool imbalance) 7. Price accuracy verification across different pool types 8. Gas optimization testing ## Performance Considerations - Optimize for low slippage stablecoin swaps - Cache pool parameters to reduce external calls - Implement efficient multi-hop routing - Consider pool liquidity depth for trade execution - Batch operations where possible ## Security Considerations - Validate curve pool addresses and parameters - Implement proper slippage protection despite low slippage - Handle emergency pause functions - Verify gauge contracts for liquidity mining - Sanitize data from external curve contracts ## Integration with MEV Bot - Identify curve-specific arbitrage opportunities - Monitor stablecoin pools for profitable swaps - Track meta-stable pools for cross-chain opportunities - Include lending pools in yield farming strategies - Coordinate with other exchanges for maximum profit