Constant-product AMM lab
A constant-product automated market maker quotes swaps from two token reserves constrained by x × y = k. Change a scenario to see how input size, fee retention, inventory, and price impact connect.
This educational model uses exact decimal arithmetic. It does not model concentrated liquidity, integer rounding, transfer taxes, hooks, or a named protocol implementation.
Reserve geometry
Constant-product price curve
- Before trade
- After trade
The pool moves from 10,000.000000 X and 20,000.000000 Y to 11,500.000000 X and 17,398.112305 Y along the constant-product reserve curve.
Inspect all curve data points
| Point | X reserve | Y reserve |
|---|---|---|
| 1 | 4,500.000000 X | 44,444.444444 Y |
| 2 | 4,833.125000 X | 41,381.094013 Y |
| 3 | 5,166.250000 X | 38,712.799419 Y |
| 4 | 5,499.375000 X | 36,367.769065 Y |
| 5 | 5,832.500000 X | 34,290.612945 Y |
| 6 | 6,165.625000 X | 32,437.911809 Y |
| 7 | 6,498.750000 X | 30,775.149067 Y |
| 8 | 6,831.875000 X | 29,274.540298 Y |
| 9 | 7,165.000000 X | 27,913.468248 Y |
| 10 | 7,498.125000 X | 26,673.335000 Y |
| 11 | 7,831.250000 X | 25,538.707103 Y |
| 12 | 8,164.375000 X | 24,496.669984 Y |
| 13 | 8,497.500000 X | 23,536.334216 Y |
| 14 | 8,830.625000 X | 22,648.453535 Y |
| 15 | 9,163.750000 X | 21,825.126177 Y |
| 16 | 9,496.875000 X | 21,059.559065 Y |
| 17 | 9,830.000000 X | 20,345.879959 Y |
| 18 | 10,163.125000 X | 19,678.986532 Y |
| 19 | 10,496.250000 X | 19,054.424199 Y |
| 20 | 10,829.375000 X | 18,468.286489 Y |
| 21 | 11,162.500000 X | 17,917.133259 Y |
| 22 | 11,495.625000 X | 17,397.923123 Y |
| 23 | 11,828.750000 X | 16,907.957307 Y |
| 24 | 12,161.875000 X | 16,444.832725 Y |
| 25 | 12,495.000000 X | 16,006.402561 Y |
| 26 | 12,828.125000 X | 15,590.742996 Y |
| 27 | 13,161.250000 X | 15,196.124988 Y |
| 28 | 13,494.375000 X | 14,820.990227 Y |
| 29 | 13,827.500000 X | 14,463.930573 Y |
| 30 | 14,160.625000 X | 14,123.670389 Y |
| 31 | 14,493.750000 X | 13,799.051315 Y |
| 32 | 14,826.875000 X | 13,489.019095 Y |
| 33 | 15,160.000000 X | 13,192.612137 Y |
| 34 | 15,493.125000 X | 12,908.951551 Y |
| 35 | 15,826.250000 X | 12,637.232446 Y |
| 36 | 16,159.375000 X | 12,376.716302 Y |
| 37 | 16,492.500000 X | 12,126.724269 Y |
| 38 | 16,825.625000 X | 11,886.631254 Y |
| 39 | 17,158.750000 X | 11,655.860712 Y |
| 40 | 17,491.875000 X | 11,433.880016 Y |
| 41 | 17,825.000000 X | 11,220.196353 Y |
Scenario explanation
What is happening
You send 1,500.000000 X to the pool and receive 2,601.887695 Y. That adds X and removes Y, moving the pool price from 2.000000 to 1.512879 Y per X. The average execution price is 1.734592 Y per X, with 13.2704% price impact. The 4.500000 X fee remains in pool inventory for LP claim holders.
- Capital flow
- Claim flow
- Return flow
- Risk flow
Deterministic output
Results
| Metric | Value | Unit | Meaning |
|---|---|---|---|
| Spot price before | 2.000000 | Y per X | Y reserve ÷ X reserve |
| Quoted output | 2,601.887695 | Y | Amount sent from the pool |
| Average execution price | 1.734592 | Y per X | Gross-input execution price |
| Price impact | 13.2704% | percent | Deterioration from spot |
| Fee paid | 4.500000 | X | Retained in the pool |
| X reserve after | 11,500.000000 | X | Post-trade pool inventory |
| Y reserve after | 17,398.112305 | Y | Post-trade pool inventory |
| Invariant before | 200,000,000.000000 | X·Y | x × y before |
| Invariant after | 200,078,291.505372 | X·Y | Includes retained fee |
| Pool price after | 1.512879 | Y per X | Post-trade Y ÷ X |
| Arbitrage direction | Sell Y, receive X | trade direction | Moves pool toward market |
| LP inventory change | +1,500.000000 X; -2,601.887695 Y | token amounts | Capital flow, not LP profit |
Balance-sheet view
Pool state transition
| Pool account | Before trade | Trader flow | Fee attribution | After trade |
|---|---|---|---|---|
| Token X asset | 10,000.000000 X | +1,500.000000 X | 4.500000 X retained | 11,500.000000 X |
| Token Y asset | 20,000.000000 Y | -2,601.887695 Y | — | 17,398.112305 Y |
| LP share claims | Pro-rata claim on pool assets | No shares minted or burned | Fee accrues inside pool assets | Supply unchanged; asset mix changed |
| Invariant (x × y) | 200,000,000.000000 X·Y | Pricing curve applied | Retained input fee can increase k | 200,078,291.505372 X·Y |
| Pool price | 2.000000 Y per X | Moves against the trade | Fee included in execution | 1.512879 Y per X |
Guided comparison
Guided scenarios
Load a scenario, then compare its execution price, reserve movement, and invariant.