Crates.io | pool-sync |
lib.rs | pool-sync |
version | 3.0.0 |
source | src |
created_at | 2024-06-30 16:00:00.100963 |
updated_at | 2024-11-11 00:35:36.049349 |
description | A library for synchronizing and managing various types of liquidity pools across different blockchains |
homepage | |
repository | https://github.com/Zacholme7/PoolSync |
max_upload_size | |
id | 1288070 |
size | 1,594,187 |
PoolSync is a utility crate for efficiently synchronizing DeFi pools from various protocols on EVM-compatible blockchains. This crate streamlines the process of pool synchronization, eliminating the need for repetitive boilerplate code in DeFi projects.
Add this to your Cargo.toml
:
[dependencies]
pool-sync = "3.0.0"
Configure your .env with a full node and a archive node. Archive must be an archive node. The full node can be either. It is designed this way due to the fact the fact that is it much more accessible to host full nodes due to the storage requirements. The typical workflow is to use a paid archive endpoint for the initial intensive sync and let the fullnode take it from there. After the initial sync, all information will be cached and the strain on the endpoints is reduced immensely.
FULL = "full node endpoint"
ARCHIVE = "archive node endpoint"
use pool_sync::{PoolSync, PoolType, Chain, PoolInfo};
#[tokio::main]
async fn main() -> Result<()> {
// Configure and build the PoolSync instance
let pool_sync = PoolSync::builder()
.add_pool(PoolType::UniswapV2)
.chain(Chain::Ethereum)
.build()?;
// Synchronize pools
let (pools, last_synced_block) = pool_sync.sync_pools().await?;
// Common Info
for pool in &pools {
println!("Pool Address {:?}, Token 0: {:?}, Token 1: {:?}", pool.address(), pool.token0_name(), pool.token1_name());
}
println!("Synced {} pools!", pools.len());
Ok(())
}
pools/pool_fetchers
chain.rs
to reflect it.Add the pool abi to pools/abi
Create a new directory in pools/pool_fetchers
with the relevant pool files. Implement the PoolFetcher
trait. This is very simple to implement and is used for event parsing. Use other implementations as an example.
Most pools will fit into the structures defined in pools/pool_structures
. In the case that it is not, create a new file for your pool type, define the structure of the pool, and implement From<&DynSolValue]> for the pool.
Go through pools/mod.rs
and add your new pool variant to all relevant sections. Very straighforward
Include your fetcher in builder.rs
Add the pool type to the proper chain in chain.rs
pools/mod.rs
Took a ton of inspiration from amm-rs. Make sure to check them out, super great work there! :)