waterpump-solana-amm-math
Protocol-agnostic AMM math library for Solana concentrated-liquidity pools (CLMM and DLMM).
Modules
| Module | Description |
|---|---|
tick_math |
Tick-to-sqrt-price conversion, tick array helpers, bounds checks |
price_math |
Human-readable price conversion (Q64.64 to decimal/f64) |
swap_math |
Single-step swap computation (next price, amounts in/out, fees) |
liquidity_math |
Liquidity deposit/withdraw quotes for CLMM positions |
fee_math |
Fee growth and fee-owed calculations |
fixed_point |
Q64.64 fixed-point arithmetic (mul, div, pow, rounding) |
bin_price |
Meteora DLMM bin-to-price conversion |
slippage |
Slippage tolerances and transfer fee helpers |
full_math |
U256-backed mul_div_floor / mul_div_ceil |
Quick start
use ;
use tick_to_sqrt_price_x64;
// Compute a single swap step
let sqrt_price = tick_to_sqrt_price_x64.unwrap;
let sqrt_target = tick_to_sqrt_price_x64.unwrap;
let step = compute_swap_step;
// Quote a liquidity deposit
let lower = tick_to_sqrt_price_x64.unwrap;
let upper = tick_to_sqrt_price_x64.unwrap;
let quote = increase_liquidity_quote;
Meteora DLMM support
The bin_price and fixed_point modules provide bin-to-price conversion for
Meteora DLMM pools. Bin pricing uses a different model (geometric bins with a
configurable base factor) rather than the tick-based 1.0001^tick formula used
by CLMM protocols.
Design notes
This is a pure math library with no Solana SDK dependency. It can be used
in off-chain tooling, bots, and simulations without pulling in the full Solana
runtime. The only dependencies are ethnum (U256 arithmetic), rust_decimal
(precise decimal conversion), and thiserror (error types).