Skip to main content

llamma_math/
lib.rs

1//! Pure Rust implementation of Curve Finance
2//! [LLAMMA](https://docs.curve.finance/crvUSD/amm/) (Lending-Liquidating AMM Algorithm) math.
3//!
4//! Exact on-chain match — no tolerances, no approximations, wei-level precision.
5//! Differentially fuzz-tested against on-chain `get_dy` for 74 pools across 2 chains.
6//!
7//! # Architecture
8//!
9//! - **`constants`** — protocol constants (`WAD`, `MAX_TICKS`, etc.).
10//! - **`core`** — stateless math functions (`wad_exp`, `get_y0`, `get_p`,
11//!   band pricing, dynamic fees). Always available, zero dependencies beyond
12//!   `alloy-primitives`.
13//! - **`swap`** + **`LlammaPool`** — pool simulation with band traversal,
14//!   fee computation, and precision scaling. Requires the `swap` feature.
15//!
16//! # Quick start
17//!
18//! ```ignore
19//! use llamma_math::pool::LlammaPool;
20//!
21//! // Build a pool (or use llamma-adapter to read from chain)
22//! let pool = LlammaPool { /* ... */ };
23//!
24//! // Quote a swap: crvUSD → collateral
25//! let dy = pool.get_amount_out(0, 1, dx)?;
26//!
27//! // Spot price in active band
28//! let price = pool.spot_price()?;
29//! ```
30//!
31//! # Source
32//!
33//! Ported line-by-line from:
34//! - [`AMM.vy`](https://github.com/curvefi/curve-stablecoin/blob/master/curve_stablecoin/AMM.vy)
35
36#![allow(clippy::too_many_arguments)]
37
38pub mod constants;
39pub mod core;
40
41#[cfg(feature = "swap")]
42pub mod swap;
43
44#[cfg(feature = "swap")]
45pub mod pool;