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