Constant-Product AMM — x · y = k

Interactive front end for the Lean model in Poc/Amm.lean.

Proven in Lean (Poc/Amm.lean)

swap_k_nondecreasing — after any swap, r0′·r1′ ≥ r0·r1: fees and rounding only ever grow k.

swap_out_lt_reserve — a swap can never pay out the whole output reserve: the pool can't be drained.

removeLiq_le_reserves — liquidity removal never pays out more than the reserves.

addLiq_shares_positive — a positive first deposit mints a positive number of shares.

Pool state

Reserve token0 (r0)
0
Reserve token1 (r1)
0
LP shares
0
Fee
30 bps
k = r0 · r1
0

k history (swaps only — k only ever grows)

no swaps yet

x · y = k curve

Axes are the reserves. The curve is the hyperbola for the current k; the dot is the current (r0, r1). After a swap, the pre-swap point is shown ghosted.

Add liquidity

Swap (exact-in)

Quote: you receive 0 token1

Remove liquidity

Lean demo replay

Demo sequence: addLiq 1000000/1000000 → addLiq 100000/100000 → swap 10000 token0 in → swap 5000 token1 in → swap 50000 token0 in → removeLiq 100000 shares. Note: k after the two deposits is 1.210e12, and each swap grows it further — the withheld fees accrue to LPs.

Operation log

pool is empty — add liquidity or replay the demo.