A simple library to get all pairs from any Dex and sync reserves.

Overview

pair_sync

A simple library to get all pairs from any supported Dex and sync reserves.

Filename: examples/sync-pairs.rs

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    //Create a new provider
    let provider = Arc::new(Provider::<Http>::try_from("rpc_endpoint_here").unwrap());
    
    //Initialize a new vec of Dexes
    let mut dexes = vec![];

    //Add UniswapV2
    dexes.push(Dex::new(
        //Specify the factory address
        H160::from_str("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f").unwrap(),
        //Specify the dex variant
        PoolVariant::UniswapV2,
        //Specify the factory contract's creation block number
        2638438,
    ));

    //Add Sushiswap
    dexes.push(Dex::new(
        H160::from_str("0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac").unwrap(),
        PoolVariant::UniswapV2,
        10794229,
    ));

    //Add UniswapV3
    dexes.push(Dex::new(
        H160::from_str("0x1F98431c8aD98523631AE4a59f267346ea31F984").unwrap(),
        PoolVariant::UniswapV3,
        12369621,
    ));

    //Sync pairs
    let pools: Vec<Pool> = sync::sync_pairs(dexes, provider).await?;


    Ok(())
}

Supported Dexes

Dex Status
UniswapV2 variants
UniswapV3

Running Examples

To run any of the examples, supply your node endpoint to the endpoint variable in each example file. For example in sync-pairs.rs:

    //Add rpc endpoint here:
    let rpc_endpoint = "";

Once you have supplied a node endpoint, you can simply run cargo run --example <example_name>.

Filters

filter_blacklisted_tokens

  • Removes any pair from a Vec<Pair> where either token_a or token_b matches a blacklisted address.

filter_blacklisted_pools

  • Removes any pair from a Vec<Pair> where the pair_address matches a blacklisted address.

filter_blacklisted_addresses

  • Removes any pair from a Vec<Pair> where either token_a, token_b or the pair_address matches a blacklisted address.

filter_pools_below_usd_threshold

  • Removes any pair where the USD value of the pool is below the specified USD threshold.

filter_pools_below_weth_threshold

  • Removes any pair where the USD value of the pool is below the specified WETH threshold.

Upcoming Filters

filter_fee_tokens

  • Removes any pair where where either token_a or token_b is a token with fee on transfer.
Comments
  • Use `Middlewear` instead of `Arc<Provider<P>>`

    Use `Middlewear` instead of `Arc>`

    Update the functions to take middleware instead of a provider. This allows for greater flexibility like using the NonceManagerMiddleware, FlashbotsMiddleware or some custom Middlewear.

    enhancement 
    opened by 0xKitsune 0
  • Remove magic numbers

    Remove magic numbers

    A contant value should be used anywhere there is a U256 value that never changes.

    For example:

          //Set sqrt_price_limit_x_96 to the max or min sqrt price in the pool depending on zero_for_one
            let sqrt_price_limit_x_96 = if zero_for_one {
                U256::from("4295128739") + 1
            } else {
                U256::from("0xFFFD8963EFD1FC6A506488495D951D5263988D26") - 1
            };
    
    

    All of these values should be changed to match this format:

    
    pub const MIN_SQRT_RATIO: U256 = U256([285968860985, 0, 0, 0]);
    pub const MAX_SQRT_RATIO: U256 = U256([
        9809463991923573570,
        227557619515130776,
        5049738529920590081,
        1,
    ]);
    
    enhancement good first issue 
    opened by 0xKitsune 0
  • Liquidity Provisioning Utilities for Liquidity Providors + JIT Exploitation

    Liquidity Provisioning Utilities for Liquidity Providors + JIT Exploitation

    I think adding liquidity provision helpers on the pools could be very appealing to liquidity providers monitoring and moving around large amounts of liquidity across CFMMs. This would allow liquidity providers to seamlessly automate their liquidity provision, and analytically optimize the profitability of their positions.

    For Starters:

    Mint Liquidity

    function mint(
            address recipient,
            int24 tickLower,
            int24 tickUpper,
            uint128 amount,
            bytes calldata data
        ) external returns (uint256 amount0, uint256 amount1);
    

    Collect Fees

    function collect(
            address recipient,
            int24 tickLower,
            int24 tickUpper,
            uint128 amount0Requested,
            uint128 amount1Requested
        ) external returns (uint128 amount0, uint128 amount1);
    

    Remove Liquidity from a position

    function burn(
            int24 tickLower,
            int24 tickUpper,
            uint128 amount
        ) external returns (uint256 amount0, uint256 amount1);
    

    Ranged Liquidity or Time Weighted Average price

    function observe(uint32[] calldata secondsAgos)
            external
            view
            returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
    

    Seconds per Liquidity & Seconds inside a tick range

    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
            external
            view
            returns (
                int56 tickCumulativeInside,
                uint160 secondsPerLiquidityInsideX128,
                uint32 secondsInside
            );
    

    The above function would also be helpful for calculating optimal JIT positions and amounts.

    Feature 
    opened by 0xOsiris 1
  • Feature: Get all pools with a specific token.

    Feature: Get all pools with a specific token.

    Implement a function within the dex mod that gets all of the pools containing a target token address.

    pub fn get_all_pools_containing_token(target_token: H160, dexes: Vec<Dex>, provider: Arc<Provider<P>>, ) -> Result<Vec<Pool>, CFFMError<P>>{
        for dex in dexes{
            //Get all pools starting from the dex creation block,
            //Filter out pools that do not have the target token
           //For all pools containing the target token, sync the pools 
    
        }
    
        // --snip--
    }
    
    Feature 
    opened by 0xKitsune 0
  • CFFM book

    CFFM book

    Opening this issue to start brainstorming around what the CFFM book might look like. I think the book should look something like the Foundry book, walking through the different mods in the lib and how to use them.

    CFFM Book 
    opened by 0xKitsune 3
Owner
null
This rust library is to get lottery monthly result loto6, numbers3 and numbers4

Scraping Japanese Lottery Site this library is to get lottery monthly result loto6, numbers3 and numbers4. scraping japanese lottery site from https:/

kubocker 5 Aug 14, 2023
Simple rust interface to get derived analytical information of algorithmic market making models (M3).

af-rs Interact with the Portfolio protocol using Rust models to abstract the underlying pools. What we want: Given a uniswap pool with two tokens and

Primitive 5 Jul 11, 2023
:crab: Small exercises to get you used to reading and writing Rust code!

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

The Rust Programming Language 33.1k Jan 2, 2023
This project contains small exercises to get you used to reading and writing Rust code

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

Cynthia Tran 1 May 24, 2022
Tiny HTTP client for GET

tinyget a tiny fork of minreq. Simple, minimal-dependency HTTP client. Optional features for https with native-tls TLS implementations. Documentation

迷渡 19 Dec 31, 2022
TUI (Text User Interface) - Get Instant feedback for your sh commands

Bashtastic Visualizer TUI (Text User Interface) - Get Instant feedback for your sh commands. Explore and play with your queries ??. The idea of this p

Alfredo Suarez 7 Nov 26, 2023
A Rust trait to convert numbers of any type and size to their English representation.

num2english This Rust crate provides the NumberToEnglish trait which can be used to convert any* number to its string representation in English. It us

Travis A. Wagner 6 Mar 8, 2023
An expression based data notation, aimed at transpiling itself to any cascaded data notation.

Lala An expression oriented data notation, aimed at transpiling itself to any cascaded data notation. Lala is separated into three components: Nana, L

null 37 Mar 9, 2022
A special rope, designed to work with any data type that is not String

AnyRope AnyRope is an arbitrary data type rope for Rust, designed for similar operations that a rope would do, but targeted at data types that are not

ahoyiski 27 Mar 22, 2023
A highly extensible runner that can execute any workflow.

Astro run Astro Run is a highly extensible runner that can execute any workflow. Features Workflow runtime for Docker Support for gRPC server to coord

Panghu 3 Aug 19, 2023
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

Domagoj Ratko 5 Nov 5, 2022
Rust Programming Fundamentals - one course to rule them all, one course to find them...

Ultimate Rust Crash Course This is the companion repository for the Ultimate Rust Crash Course published online, presented live at O'Reilly virtual ev

Nathan Stocks 1.3k Jan 8, 2023
OOLANG - an esoteric stack-based programming language where all instructions/commands are differnet unicode O characters

OOLANG is an esoteric stack-based programming language where all instructions/commands are differnet unicode O characters

RNM Enterprises 2 Mar 20, 2022
Type erased vector. All elements have the same type.

Type erased vector. All elements have the same type. Designed to be type-erased as far as possible - most of the operations does not know about concre

null 7 Dec 3, 2022
A simple thread schedule and priority library for rust

thread-priority A simple library to control thread schedule policies and thread priority. If your operating system isn't yet supported, please, create

Victor Polevoy 62 Dec 5, 2022
Simple and customizable procedural noise generation library written in Rust.

libnoise A simple, performant, and customizable procedural noise generation library inspired by libnoise for C++ featuring: Easy coherent noise genera

SpoogieOogie 29 Aug 13, 2023
A typesafe, flexible, simple, and user-friendly unit system library for Rust that has good error messages.

uy A typesafe, flexible, simple, and user-friendly unit system library for Rust that has good error messages. Usage uy not only stores the unit of a v

Lachlan Sneff 19 Aug 8, 2023
Rust 核心库和标准库的源码级中文翻译,可作为 IDE 工具的智能提示 (Rust core library and standard library translation. can be used as IntelliSense for IDE tools)

Rust 标准库中文版 这是翻译 Rust 库 的地方, 相关源代码来自于 https://github.com/rust-lang/rust。 如果您不会说英语,那么拥有使用中文的文档至关重要,即使您会说英语,使用母语也仍然能让您感到愉快。Rust 标准库是高质量的,不管是新手还是老手,都可以从中

wtklbm 493 Jan 4, 2023
A simple /proc//{mem,maps} library for Rust

Summary A very simple library that wraps around /proc/pid/mem and /proc/pid/maps to read memory out of a running process on Linux. Usage Basic usage l

null 6 Jul 27, 2022