rust-sdk crate when you need Rust tooling around DAMM v2 quotes and initial pool math.
Install
If your project is in the same workspace asdamm-v2, depend on the local crate by path:
rust-sdk and cp-amm revisions aligned so account structs, fee logic, and quote math match. The Rust library reads cp-amm account structs and math directly.
What It Provides
| Module | Purpose |
|---|---|
quote_exact_in::get_quote | Quote exact- input swaps from a Pool state |
quote_exact_out::get_quote | Quote exact-output swaps |
quote_partial_fill_in::get_quote | Quote partial-fill exact-input swaps |
calculate_initial_sqrt_price::calculate_concentrated_initial_sqrt_price | Calculate concentrated pool initial square-root price |
calculate_initial_sqrt_price::calculate_compounding_initial_sqrt_price_and_liquidity | Calculate compounding pool initial square-root price and liquidity |
utils | Activation and swap-enabled helpers |
Program ID
The public DAMM v2 program ID is the same on mainnet and devnet:cp-amm 0.2.0.
Quote Inputs
Rust quote helpers expect a deserializedcp_amm::state::Pool and current chain context:
| Input | Why it matters |
|---|---|
Pool | Contains price, liquidity, reserves, fee state, activation settings, and collect fee mode |
| Current timestamp | Used by timestamp-activated fees and dynamic fee updates |
| Current slot | Used by slot-activated fees |
| Swap amount and direction | Determines exact-in, partial-fill, or exact-out result |
| Referral flag | Changes protocol/referral fee split |
SwapResult2 shape used by the program and TypeScript SDK, including claiming_fee, compounding_fee, protocol_fee, referral_fee, included_fee_input_amount, excluded_fee_input_amount, output_amount, next_sqrt_price, and amount_left.
Initial Price Helpers
Use the initial-price helpers when preparing pool creation inputs in Rust:| Function | Use |
|---|---|
calculate_concentrated_initial_sqrt_price(token_a_amount, token_b_amount, min_sqrt_price, max_sqrt_price) | Computes a concentrated pool initial square-root price from initial token amounts and price bounds. |
calculate_compounding_initial_sqrt_price_and_liquidity(token_a_amount, token_b_amount) | Computes compounding pool initial square-root price and liquidity from full-range reserves. |
Tests
The public repository includes Rust tests and fixtures for quote paths and initial price calculations:Rust SDK Or CPI
| Need | Use |
|---|---|
| Off-chain Rust quote engine | Rust library |
| On-chain program composing swaps or liquidity | Rust CPI |
| Full transaction construction from an app | TypeScript SDK |

