Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

pool

AMM Pool Math (f64)

Constant product (x×y=k) AMM formulas for 32.32 fixed-point. Gas-optimized versions of the f128 pool functions.

Swap Functions

  • constant_product_out - Calculate output for given input
  • constant_product_in - Calculate input for desired output

Price & Slippage

  • price_from_reserves - Get spot price from reserves
  • slippage - Calculate execution slippage

Liquidity Functions

  • initial_lp_tokens - LP tokens for initial deposit
  • mint_lp_tokens - LP tokens for subsequent deposits
  • liquidity_share - User’s share of reserves
  • remove_liquidity - Amounts returned on withdrawal

Fully qualified path: cairo_fp::f64::math::pool

Free functions

constant_product_outCalculates output amount for a constant product swap. Given reserves x, y and input dx, returns dy such that (x+dx)(y-dy) = xy. Formula: dy = y × dx / (x + dx)
constant_product_in
price_from_reserves
slippage
liquidity_share
calculate_k
initial_lp_tokens
remove_liquidity