~/defi/dex $ cat amm-kak-rabotaet-uniswap.md
AMMs on fingers: how Uniswap trades without an order book or a seller
A classic exchange matches buyer with seller through an order book. The AMM (automated market maker) threw out both the book and the seller: you trade with a pool - a smart contract holding two tokens.
The formula everything stands on
Uniswap's base invariant: x × y = k, where x and y are the amounts of the two tokens in the pool. Buying token X, you take it out of the pool and top up Y - and the product must stay the same. Hence the price: the more X is taken, the more expensive each next unit. The price is not "set" - it is the geometry of the pool's reserves.
Consequences you need to feel
- Slippage: a large swap in a small pool moves the price against you by the formula - up to insane percentages. Always check the price impact.
- Liquidity = pool depth: the "price" of a token with a $10k pool is a fiction: nothing substantial can be sold at it.
- Arbitrage is the price glue: the pool does not know world prices; arbitrageurs level it, and their profit is a hidden tax on liquidity providers.
- The pool is always positioned against you: the AMM will sell you the token on a pump and buy it on a dump - it is a mechanical counterparty without an opinion.
Concentrated liquidity (v3+) complicated the formula, but the essence is the same: price = the pool's state. Understanding AMMs is the base for all of DeFi; next - yield and its dark side, impermanent loss.