tycho-simulation 0.525.0

Provides tools for interacting with protocol states, calculating spot prices, and quoting token swaps.
Documentation
//! [`Constants.sol`](https://github.com/pancakeswap/infinity-core/blob/7c04695f/src/pool-bin/libraries/Constants.sol#L6-L18),
//! plus the two the price and fee helpers keep private.

use alloy::primitives::U256;

/// Bin prices are 128.128 fixed point.
pub const SCALE_OFFSET: u8 = 128;

/// 1.0 in 128.128.
pub const SCALE: U256 = U256::from_limbs([0, 0, 1, 0]);

/// Fee denominator. Fees reach this scale as `fee_pips * 1e12`.
pub const PRECISION: U256 = U256::from_limbs([1_000_000_000_000_000_000, 0, 0, 0]);

/// Scales pips to `PRECISION`: `1e18 / 1e6`. The fee helpers take pips and scale internally.
pub const PIPS_TO_PRECISION: U256 = U256::from_limbs([1_000_000_000_000, 0, 0, 0]);

/// Bin ids are `uint24` on chain: `0 .. BIN_ID_COUNT`.
pub const BIN_ID_COUNT: u32 = 1 << 24;

/// `bin_step` denominator: step 25 is a 0.25% ratio between neighbouring bins.
pub const BASIS_POINT_MAX: u64 = 10_000;

/// Bin id of price 1.0. Ids are u24, so real exponents run `[-2^23, 2^23)`.
pub const REAL_ID_SHIFT: u32 = 1 << 23;

/// `(2^256 - 1) / (2 * log(2^128) / log(1.0001))`. `BinPool.swap` re-checks it after crediting a
/// bin.
pub const MAX_LIQUIDITY_PER_BIN: U256 = U256::from_limbs([
    0x6d336ca2a775b611,
    0xca44773dd596d31a,
    0xe0d0f4e400fce79a,
    0x000009745258e83d,
]);