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
use alloy::primitives::aliases::U160;
use uniswap_sdk_core::prelude::{Currency, Price, ToBig};
use uniswap_v3_sdk::prelude::Q192;

/// Calculate price from sqrt_price_x96 value
pub fn calculate_price_from_sqrt_price_x96(
    sqrt_price_x96: U160,
    token_a: Currency,
    token_b: Currency,
) -> Price<Currency, Currency> {
    let sqrt_price_x96_big = sqrt_price_x96.to_big_int();
    Price::new(token_a, token_b, Q192.to_big_int(), sqrt_price_x96_big * sqrt_price_x96_big)
}