Without an Order Book, the Pool Is the Counterparty
Use one swap to see how reserves move, where impact comes from, and why LPs provide depth.
- Explain an AMM quote with reserves and a constant product
- Observe how size, fees, and impact interact
- Explain why LPs earn fees while carrying inventory risk
- PREVIOUSCourse introduction
- CURRENTWithout an Order Book, the Pool Is the Counterparty
Use one swap to see how reserves move, where impact comes from, and why LPs provide depth.
- NEXTWhy Does the Quote Get Worse?
Think about these questions first.
Choose an answer before opening the explanation. You can add anything unexpected to your review list.
Q01With no posted seller, why can a pool keep trading with me?+
LPs pre-deposit both assets and a curve turns inventory into continuous quotes. Liquidity is not infinite: as you remove one asset, each next unit becomes more expensive.
An order book needs another person to stand on the other side. An AMM rewrites that problem: put two assets in a public pool, then let the reserve ratio quote the next swap.
Forget “finding a counterparty”
An AMM has no best bid, no best ask, and no Alice who must be online. The pool owns both reserves and anyone can swap against the same rule. In this lab they are credits and TOKEN: 120,000 credits and 1,000 TOKEN imply a spot price near 120 credits per TOKEN.
Credits / TOKEN
The pool does not wait for another order. Its reserve ratio produces the next quote.
Swap fees stay in the pool and slowly grow k; adding or removing liquidity also changes the reserve scale.
Start with the two reserves, then drag the swap size. Small trades stay near the spot price; large trades travel farther along the curve.
- 01
Pool created: 120,000 credits + 1,000 TOKEN,initial price 120 credits / TOKEN。
Use the slider to return to an earlier step. Continuing from there replaces the later history with a new sequence.
x · y = k is a state constraint
For a constant-product pool, the product of the reserves describes the current state:
x = 120,000 credits
y = 1,000 TOKEN
k = x · y = 120,000,000
When you buy TOKEN with credits, the pool receives X and sends out Y. The new reserves must still satisfy the constraint, so output cannot simply use the old price. The more you buy, the scarcer TOKEN becomes and the next unit costs more.
Why fees make k grow
With a 0.30% fee, a 12,000-credit input leaves 36 credits in the pool and only 11,964 credits enter the curve calculation. The trader receives less output, while the fee remains in reserves and slowly grows x · y for LPs.
Expand: how this step works
fee = amountIn × 30 / 10,000
usableIn = amountIn - fee
amountOut = reserveOut × usableIn / (reserveIn + usableIn)
reserveIn += amountIn
reserveOut -= amountOut
The simulator uses integer units and floors every division. Production contracts also need rounding policies, minimum output, extreme-reserve checks, and reentrancy protection.
Why does a large swap usually execute worse than the spot price?
Read an AMM as four questions
After this experiment, ask: how much X and Y are in the pool, how far average execution moved from spot, who receives the fee, and what an LP would withdraw after the reserves move. The formula is a compressed rule; the mechanism is the asset flow between pool, trader, and LP.