An automated market maker (AMM) like Uniswap sets prices with a formula instead of an order book. A pool holds two tokens, and in the classic design the product of the two balances must stay constant: x * y = k. The price is simply the ratio of the balances, and every trade shifts that ratio, so the price moves as you buy or sell. Arbitrage traders then keep the pool's price close to prices elsewhere.
Why not just use an order book?
Traditional exchanges match buyers and sellers through an order book, a list of bids and offers. Running one fully on-chain is costly on Ethereum. Every new order, change and cancellation is a transaction that costs gas, and market makers need to update quotes constantly.
An AMM removes the need for anyone to post quotes. Liquidity providers (LPs) deposit both tokens into a smart contract called a liquidity pool. Traders swap against the pool directly, and the contract works out the price from its own balances. It is always open, and anyone can trade against it or add liquidity.
The constant product formula
Uniswap v2, and the original idea behind v1, uses the constant product rule. If a pool holds x units of token A and y units of token B:
x * y = k
A trade must leave the product k unchanged, ignoring fees. The spot price, the price for a tiny trade, is the ratio of the reserves:
price of A (in B) = y / x
When you add token B and remove token A, x goes down and y goes up, so A gets more expensive. The curve never runs out: as one balance approaches zero, its price rises toward infinity.
A worked example
Take an ETH/USDC pool with 100 ETH and 300,000 USDC.
k = 100 * 300,000 = 30,000,000- Spot price of ETH = 300,000 / 100 = 3,000 USDC
Now a trader wants to buy 10 ETH. After the trade the pool will have 90 ETH, so the USDC balance must satisfy 90 * y = 30,000,000:
- New USDC balance = 333,333.33
- USDC the trader pays = 333,333.33 − 300,000 = 33,333.33 (before fees)

