PoolSync For Mantle
PoolSync is a comprehensive utility crate for efficiently synchronizing DeFi pools from multiple protocols on the Mantle blockchain. This crate streamlines the process of pool synchronization with support for both V2 and V3 style AMMs, intelligent caching, and rate limiting, eliminating the need for repetitive boilerplate code in DeFi projects targeting the Mantle ecosystem.
Features
- 🏊♂️ Multi-Protocol Support - UniswapV3, Agni (V3-style), and MerchantMoe (V2-style)
- 🚀 Smart Caching System - Persistent cache for each protocol with automatic management
- ⚡ Dual-Node Architecture - Archive + Full node setup for optimal performance and cost efficiency
- 🔄 Rate Limiting - Built-in rate limiting for public endpoints
- 📦 Flexible Configuration - Builder pattern with block range support
- 🔍 Automatic Token Resolution - Fetches token names and metadata automatically
- 🛠️ Extensible Architecture - Easy to add new protocols with trait-based design
- 📊 Progress Tracking - Built-in logging and progress indicators
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
= "1.0.82"
= { = "1.37.0", = ["rt-multi-thread", "macros"]}
= "0.15.0"
= "0.11.4"
Configure your .env with both a full node and an archive node. The archive endpoint must be an archive node, while the full node can be either type. This dual-node design optimizes costs - use a paid archive endpoint for the initial intensive sync, then let the full node handle ongoing synchronization. After initial sync, all data is cached locally, dramatically reducing endpoint strain.
FULL = "full node endpoint"
ARCHIVE = "archive node endpoint"
Supported Protocols
Mantle Network
- Uniswap V3 - Advanced AMM with concentrated liquidity and tick-based pricing
- Agni Finance - V3-style AMM (Uniswap V3 fork) with concentrated liquidity
- Merchant Moe - V2-style constant product AMM with pair-based liquidity
Example Usage
Basic Pool Synchronization
use Result;
use ;
use env_logger;
async
Quick Start Example
use Result;
use ;
async
Architecture
Caching System
PoolSync uses an intelligent caching system that creates separate cache files for each protocol:
cache/Mantle_UniswapV3_cache.jsoncache/Mantle_Agni_cache.jsoncache/Mantle_MerchantMoe_cache.json
The cache stores the last synced block number and pool data, enabling efficient incremental updates on subsequent runs.
Pool Structures
The library supports both V2 and V3 style pools through a unified interface:
- V3 Pools (UniswapV3, Agni): Concentrated liquidity with tick-based pricing
- V2 Pools (MerchantMoe): Constant product formula with pair-based liquidity
All pools implement the PoolInfo trait providing consistent access to:
- Pool and token addresses
- Token names, decimals, and symbols
- Pool type identification
- Fee information
- Stability flags
Modular Fetcher System
Each protocol implements the PoolFetcher trait, providing:
- Factory address for pool discovery
- Event signature for pool creation events
- Pool data parsing and structure creation
- Chain-specific configuration
Advanced Usage
Performance Optimization
use Result;
use ;
async
Working with Different Pool Types
use ;
Adding New Protocols
This codebase focuses specifically on Mantle network. To add a new DEX protocol:
1. Add Pool ABI
Add the factory ABI to src/pools/abis/YourProtocol.json
2. Create Pool Fetcher
Create src/pools/pool_fetchers/yourprotocol/yourprotocol_fetcher.rs:
use cratePoolFetcher;
use Address;
;
3. Update Pool Types
Add your protocol to src/pools/mod.rs:
4. Register in Builder
Update src/builder.rs to include your fetcher
5. Add to Chain Support
Update src/chain.rs to map your protocol to Mantle
Refer to existing implementations (Agni, MerchantMoe) as examples.
Troubleshooting
Common Issues
Cache Corruption: Delete the cache files in cache/ directory to force a full resync
Rate Limiting: Increase the rate limit value or upgrade to a paid RPC endpoint
Memory Usage: For large block ranges, consider syncing in smaller chunks
Archive Node Requirement: The initial sync requires an archive node for historical data access
Roadmap
- Enhanced Protocol Support - Add more Mantle-native DEXs
- Database Integration - Optional PostgreSQL/SQLite backend
- Real-time Updates - WebSocket subscriptions for live pool updates
- Cross-chain Support - Extend beyond Mantle to other networks
- Pool Analytics - Built-in TVL, volume, and liquidity analysis
- Batch Operations - Bulk token resolution and metadata fetching
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Acknowledgments
Took inspiration from amm-rs - an excellent AMM library worth checking out!