Swapping and slippage
On-chain, a swap works in a genuinely new way. Price discovery became a public utility running on math — and slippage is the visible cost of that openness.
A swap is trading one token for another. On a centralized exchange it feels like a brokerage; on-chain, via a decentralized exchange (DEX), it works in a genuinely new way that affects the price you get.
The Automated Market Maker
Most DEXs don't use an order book. They use an Automated Market Maker (AMM): a smart contract holding a liquidity pool of two tokens, with a formula that sets the price algorithmically. The classic design is the constant product formula, x × y = k, where x and y are the token quantities and k stays constant. When you buy token X out of the pool, X's quantity falls and Y's rises to keep k fixed — which automatically makes X more expensive with each unit you take. Price emerges from the ratio of reserves, not from a counterparty.
Price impact and slippage
This produces two effects.
- Price impact: because the formula is a curve, a large trade moves the price against you as it executes. The bigger your order relative to the pool, the worse your average price — and a small ("low liquidity") pool moves sharply.
- Slippage: the difference between the price you expected and the price you actually got when the transaction settled, because between your click and on-chain confirmation, other trades may have shifted the pool.
Wallets let you set a slippage tolerance (say 0.5%) — the maximum adverse move you'll accept before the transaction cancels instead of filling.
Setting tolerance is a balance
Too low on a volatile or thin token and your transactions keep failing (and you still pay gas). Too high and you invite sandwich attacks, where a bot spots your pending trade, jumps in front to push the price up, lets you fill at the worse price, then sells right after.
Deep, liquid pairs (a major coin against a major stablecoin) need very little tolerance; small tokens need more — and that need is itself a warning about what you're trading.
Why it matters. The AMM replaced an entire profession — the market maker — with a public formula anyone can trade against or supply. Price discovery became a public utility running on math, with no privileged access and no closing bell. Slippage is simply the visible cost of that openness.
