When swapping tokens on a decentralized exchange, there are no orders to place and no counterparty filling each trade one by one, yet prices can still be calculated instantly. This is made possible by AMMs (automated market makers).

$UNI is the governance token of Uniswap, which popularized AMMs. Currently 6.428 (24h -11.68%).

📌 How is it different from an order book?

Most centralized exchanges use order books: buyers and sellers place orders at their desired prices, and a matching engine pairs orders with compatible prices to execute trades.

AMMs take a different approach: a liquidity pool containing two tokens is prepared in advance, and traders swap directly with the pool. A formula automatically determines the price.

📌 The constant product formula

Uniswap V2 uses the constant product formula x × y = k: ignoring fees, the product of the quantities of the two tokens in the pool remains unchanged before and after a trade.

The more of a token is bought from the pool, the less remains, and the higher its price becomes. So the more you buy in a single trade, the higher the average execution price—this is the source of price impact (slippage).

📌 Who provides funds to the pool

The funds in a pool come from liquidity providers (LPs): they deposit two tokens in the proportions set by the pool’s current price and earn a share of trading fees. Uniswap V2 charges a 0.3% fee on each trade, which historically all went to LPs. Later, governance enabled a protocol fee, so the protocol takes a portion from Ethereum mainnet V2 pools (since the end of 2025, 0.25% goes to LPs and 0.05% to the protocol).

Uniswap V3 introduced concentrated liquidity, allowing LPs to provide liquidity only within a price range they choose, making more efficient use of the same funds. But once the price moves outside that range, they stop earning fees.

📌 How prices stay in line with the outside market

An AMM itself has no idea what the price is elsewhere; its quotes are determined solely by the ratio of the two tokens in the pool. When a price difference emerges with other markets, arbitrage traders buy low and sell high, pushing the price back toward alignment.

📌 In a nutshell

Once you understand AMMs, concepts like slippage, pool depth, and impermanent loss all fit together: they’re really just different ways the same formula behaves under different conditions. Every return comes with a corresponding risk, so first understand how much you could lose in the worst case.

Which topic would you like to learn about? Let me know in the comments.