AMM Math: Constant Product, StableSwap, Concentrated Liquidity
How x·y=k, Curve's StableSwap invariant, and Uniswap V3/V4 ticks actually price trades — and why each design exists.
40 min · advanced · part of DeFi Deep Dive: Lending, AMMs & Yield
From Order Books to Curves
Centralized exchanges price assets with order books: buyers post bids, sellers post asks, the highest bid and lowest ask define the market, and a matching engine pairs them. That model assumes someone is always present to provide liquidity at any specific price. On chain, the round-trip cost of posting and modifying orders against the persistent state of a blockchain made order-book trading prohibitively expensive in the early Ethereum era. Automated Market Makers (AMMs) were the response.
An AMM is, in the simplest description, a smart contract holding a reserve of two (or more) assets and a deterministic pricing function that defines what trade prices are allowed. Anyone can swap into or out of the pool at whatever price the function dictates, as long as the resulting reserves still satisfy an algebraic constraint called the **invariant**. The genius of the design is that the AMM is always available to trade — no order book to keep alive, no market maker to babysit it — and the price moves automatically as the reserves change.
The simplest AMM is the **constant-product** market maker (CPMM), defined by the invariant **x · y = k**, where x and y are the two reserve quantities and k is a constant. This is Uniswap V1 and V2 in one equation. Every variant that came after — StableSwap, Uniswap V3/V4, Balancer's weighted pools, Curve's metapools — is some modification of the basic invariant idea, tuned for different asset classes and capital-efficiency goals. The rest of this lesson walks through each, with concrete intuition about why they exist.
Also in this lesson
- Constant Product: x · y = k
- StableSwap: Curve's Hybrid Invariant
- Uniswap V3: Concentrated Liquidity and Ticks
- Uniswap V4: Hooks and the DEX Landscape
- What to Remember
Key terms
- AMM (Automated Market Maker)
- A smart contract that holds reserves of multiple assets and uses a deterministic pricing function (invariant) to allow swaps without an order book.
- Constant-product invariant
- The pricing function x · y = k used by Uniswap V1 and V2. Reserves of two assets multiply to a constant; the curve is a hyperbola.
- StableSwap invariant
- Curve's hybrid pricing function that behaves like constant-sum near the peg (low slippage) and transitions to constant-product as the pool becomes imbalanced. Designed for pegged or highly correlated assets.
- Amplification coefficient (A)
- A parameter in Curve's StableSwap that controls how flat the curve is around the peg. Higher A means lower slippage but greater vulnerability to depeg events.
- Concentrated liquidity
- A Uniswap V3/V4 feature where LPs allocate capital only to a specific price range. In-range capital is dramatically more efficient; out-of-range capital earns nothing.
- Tick
- A discrete price increment (0.01% / 1 basis point) used by Uniswap V3 and V4 to discretize the price space and make concentrated liquidity computable on-chain.
- Fee tier
- A configurable swap fee level (0.01%, 0.05%, 0.30%, 1.00% in standard Uniswap V3) chosen per pool. LPs and traders self-sort across tiers based on volatility and trade size.
- Hook (Uniswap V4)
- A smart contract attached to a V4 pool that runs custom logic at lifecycle events (before/after swap, on position change, on initialization). Enables dynamic fees, limit orders, custom MEV protection, and more.
- Singleton architecture
- Uniswap V4's design where one contract holds the state of all pools, dramatically reducing gas costs for multi-hop swaps and pool creation versus V3.
- Curve Wars
- The competitive bribing of veCRV holders (and later Convex/Aura holders) to direct CRV emissions toward specific pools. A central economic game in DeFi 2021-2024 and still relevant in muted form.
Continue this lesson — 5 more sections in the CryptoBipto app.
Open lessonEducational only — not financial advice.
