waterpump-evm-pool-sdk 0.1.0

EVM pool SDK — viewers, infusers, harvesters, swappers for Uniswap V3/V4, PancakeSwap, Slipstream, Shadow, Algebra
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use alloy::primitives::aliases::U160;
use tracing::debug;
use uniswap_sdk_core::prelude::{Currency, Price, ToBig};
use uniswap_v3_sdk::prelude::Q192;

/// Convert sqrt_price_x96 to Price
#[inline]
pub(crate) fn sqrt_price_x96_to_price(
    token_a: Currency,
    token_b: Currency,
    sqrt_price_x96: U160,
) -> Price<Currency, Currency> {
    let sqrt_price_x96_big = sqrt_price_x96.to_big_int();
    let price =
        Price::new(token_a, token_b, Q192.to_big_int(), sqrt_price_x96_big * sqrt_price_x96_big);
    debug!("Price calculated from sqrt_price_x96");
    price
}