This is the interactive companion to UniswapV2 — The Math Behind AMMs. That post derives all the formulas. This one lets you feel them.
The best way to understand x·y=k is not to read about it — it’s to move the sliders and watch the pool rebalance. Below are three tools with increasing depth.
How to use this
Trade Simulator (Tab 1): Configure reserves and trade direction, then execute swaps. Watch the reserve bar shift, the price impact meter change colour, and the effective price diverge from spot. Dial up the trade size toward 50% of pool liquidity to see non-linear price impact.
x·y=k Curve (Tab 2): Hover anywhere on the hyperbola to see what combination of reserves would produce that point while keeping k constant. The orange dot is your current pool state.
Contract Internals (Tab 3): Everything the Solidity pair contract stores on-chain — slot by slot. Execute several trades and come back here to see how price0CumulativeLast (the TWAP accumulator) advances.
What to try
1. Price impact is non-linear. Set trade size to 1 ETH (0.2% of pool): impact is ~0.2%. Now try 50 ETH: impact is ~9%. The formula is Δx / (x + Δx) — roughly linear for small trades, then grows sublinearly and asymptotically approaches 100% for very large ones.
2. Reset the pool to 100 ETH / 200,000 USDC. That’s a smaller pool (same 2000 USDC/ETH price). Same trade of 10 ETH now shows ~9% impact vs ~1% in the 500 ETH pool. Depth matters more than price.
3. Execute 5 trades in sequence. After each one, check the Contract Internals tab. The TWAP accumulator (price0CumulativeLast) grows monotonically — it records the time-weighted price across every block. An attacker would need to sustain a manipulated price for many blocks to skew a 30-minute TWAP — economically prohibitive.
4. Trade size at exactly 50% of pool liquidity. The formula gives you a ~33% price impact. Try to buy more than 100% of the Y reserve — you’ll notice the simulator clamps (in reality, the contract reverts if output ≥ reserve).
The key insight
The constant product formula isn’t about keeping the price stable — it’s about keeping k constant. When you buy ETH, k stays the same but reserves shift. The price you pay is determined by where on the hyperbola your trade lands, not by an order book. There are no limit orders, no market makers, no counterparties — just math.
For the full derivation of the formulas behind this simulator, read UniswapV2 — The Math Behind AMMs.
For how V3 makes this dramatically more capital-efficient with concentrated liquidity, see the UniswapV3 Interactive Explorer.