Pricing without a list of orders
A traditional exchange matches buyers and sellers through an order book. Many decentralized platforms work differently: they hold a pool of two assets, and a rule built into a smart contract sets the price from the amounts in that pool. Anyone can trade against the pool at any time, with no counterparty needing to be online. This design is usually called an automated market maker, or AMM.
The idea is that liquidity comes from people who deposit pairs of assets into the pool, rather than from traders posting orders at specific prices. Traders then swap one asset for the other, and the pool’s balances shift with each swap.
The constant product rule
The best-known formula keeps the product of the two token quantities constant. If a pool holds x units of one token and y units of another, the rule is:
x * y = k
where k stays the same during a swap (ignoring fees). The price of one token in terms of the other is roughly the ratio of the balances, y divided by x.
Here is an illustration with deliberately simple numbers. Suppose a pool holds 10 units of token A and 20,000 units of a dollar-pegged token. Then k = 10 * 20,000 = 200,000, and the pool’s price for token A is 20,000 / 10 = 2,000 dollar tokens.
A trader wants to buy 1 unit of token A. After the trade, the pool will hold 9 units of A. To keep k at 200,000, the pool must then hold 200,000 / 9 = 22,222.22 dollar tokens (rounded). The trader therefore pays 22,222.22 - 20,000 = 2,222.22 dollar tokens, before any fee.
Two points come out of this:
- The average price paid was 2,222.22 per unit, about 11.1% above the starting price of 2,000 (2,222.22 / 2,000 = 1.1111).
- After the trade, the pool’s price is 22,222.22 / 9 = 2,469.14, so the quoted price has moved up about 23.5% from 2,000.
These numbers are illustrations, not real market data.
Why bigger trades cost more
The curve implied by x * y = k gets steeper as you take more of one side. Removing a small fraction of the pool shifts the price slightly; removing a large fraction shifts it a lot. In the example above, buying 1 unit out of 10 (10% of the pool’s token A) moved the price by more than a fifth. Buying 5 units would require the pool to hold 5 units of A and 200,000 / 5 = 40,000 dollar tokens, so the trader would pay 20,000 and the average price would be 4,000 per unit, double the starting price.
This effect, where your own trade moves the price you receive, is often called price impact. It is a close cousin of slippage, which is the broader gap between the expected and the executed price. Pools that are large relative to your trade show much smaller impact than shallow pools, which is why market liquidity matters so much for these venues.
Where the pool price comes from
A pool does not know what the “real” price is. It only knows its own balances. If the wider market price of token A rises to 2,500 while the pool still quotes 2,000, traders can buy cheap token A from the pool and sell it elsewhere. Their purchases reduce the pool’s A balance and raise its price until the gap closes. In this way, arbitrageurs keep pool prices broadly in line with other venues, and the pool effectively learns the market price from their trades. The same process is part of why the same coin has slightly different prices on different venues.
This also means the pool’s quote can lag during fast moves, and the people providing liquidity bear the consequences.
Fees and liquidity providers
Most pools charge a small fee on each swap, which is added to the pool and shared among the people who supplied liquidity. Fee levels vary by platform and by pool, so check the one you use rather than assuming.
Liquidity providers face a trade-off often called impermanent loss. When the relative price of the two tokens changes after deposit, the pool’s rebalancing means a provider can end up with less value than if they had simply held both tokens. Fee income may offset this or may not, depending on trading activity and price movement. It is called “impermanent” because it can shrink if the price returns, but it becomes real if the provider withdraws while the price is different.
Other things to know
- Network costs. Every swap is a blockchain transaction, so gas fees apply. On busy networks these can be significant for small trades, and some platforms run on layer two networks to reduce them.
- Order of execution. Because pending transactions can be seen before they are confirmed, other participants may place trades around yours. Platforms usually let you set a maximum acceptable price movement; if the price moves beyond it, the swap fails rather than filling badly.
- Smart contract risk. Code can contain bugs, and pools can be targeted by exploits. Newly created pools with little history deserve extra caution, and some tokens are created specifically to trap buyers.
- Variants. Constant product is just one design. Some pools use different curves, for example ones tuned for assets expected to trade near the same price, or ones that concentrate liquidity within chosen price ranges. The core idea is the same: a formula, not a list of orders, determines the price.
Reading the comparison with an order book
In an order book, the price changes as particular orders are consumed. In a pool, the price changes continuously along a curve with every unit traded. Neither approach is universally better. Order books can offer tight quotes when many participants compete, while pools make it possible to trade assets that have few active market makers.
Cryptocurrency prices are volatile, and providing liquidity or swapping tokens can lead to losses. This article is a general explanation, not financial, tax or legal advice.