---
title: "How AMMs Work"
type: concept
tags: [amm, constant-product, pricing, price-impact]
updated: 2026-06-19
confidence: high
sources: [raw/llms_txt_doc-how-uniswap-works.md, raw/llms_txt_doc-swaps.md, raw/llms_txt_doc-pricing.md]
---

# How AMMs Work

Uniswap replaces an order book with an **automated market maker**: a pool holds reserves of two tokens, and a formula sets the price.

## Constant product (x·y=k)

The classic Uniswap v2 invariant: a pool holds reserves `x` and `y` of two tokens, and trades must keep **`x · y = k`** constant (minus fees). Buying token Y removes it from the pool and adds token X, which **moves the price** — the more you buy relative to reserves, the worse the price. There's always liquidity at *some* price (the curve never empties), but large trades pay more.

## Price, price impact, slippage

- **Price** is the ratio of reserves at the margin.
- **Price impact** — how much your trade moves the pool price (a function of trade size vs liquidity). Big trade in a shallow pool = large impact.
- **Slippage tolerance** — the max adverse price move you'll accept between submitting and execution; the trade reverts if exceeded (protects against front-running and volatility).

## LP shares

Depositing both tokens earns you a share of the pool and its [fees](fees.md). How shares are tracked **differs by version**: v2 mints fungible pool tokens for a proportional share of reserves; v3/v4 use **concentrated liquidity** where each position is a chosen price range ([concentrated-liquidity](concentrated-liquidity.md), [protocol-versions](protocol-versions.md)).

## Swapping is permissionless

Anyone can swap any listed token directly against pools; routing across multiple pools/hops to get the best price is handled by routers and the [API/SDK](../entities/sdks-and-api.md) ([swaps-and-routing](swaps-and-routing.md)). Arbitrage keeps Uniswap prices aligned with the broader market.
