- 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>
3.3 KiB
3.3 KiB
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_liquidityremove_liquidityremove_liquidity_one_coincalc_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
- Create Curve struct implementing the Exchange interface
- Implement adapter for different pool types
- Handle curve's unique pricing mechanism (constant function AMM optimized for similar assets)
- Implement multi-hop swaps between different pool types
- Add support for underlying asset swaps
- Implement virtual price calculations
- Add support for factory-deployed pools
- 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
- Unit tests for stablecoin swap functions
- Testing with different amplification coefficients
- Virtual price calculation verification
- Multi-asset pool testing
- Factory pool integration tests
- Edge case testing (extreme amounts, pool imbalance)
- Price accuracy verification across different pool types
- 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