QTube LearnDeFi and markets Intermediate

Automated market makers

In DeFi, an AMM is one **DEX architecture**, not the definition of a DEX (see Batch C). This article focuses on pool-based constant-function market makers. The best-known rule is Uniswap v2’s constant product \(x \cdot y = k\). Trades move the price because they change \(x\) and \(y\). Arbitrage leans the pool back toward other markets. LPs earn fees and take inventory risk. **Price impact** is the change attributable to this trade’s size; **slippage** is expected versus executed price (next article). Other designs include concentrated liquidity, StableSwap and weighted pools. MEV can sandwich a trade. None of this is a full derivation.

Published
Last reviewed

In brief

In DeFi, an AMM is one DEX architecture, not the definition of a DEX (see Batch C). This article focuses on pool-based constant-function market makers. The best-known rule is Uniswap v2’s constant product (x \cdot y = k). Trades move the price because they change (x) and (y). Arbitrage leans the pool back toward other markets. LPs earn fees and take inventory risk. Price impact is the change attributable to this trade’s size; slippage is expected versus executed price (next article). Other designs include concentrated liquidity, StableSwap and weighted pools. MEV can sandwich a trade. None of this is a full derivation.

Algorithmic price versus a book

A traditional or on-chain order book matches a buyer’s bid with a seller’s ask. Prices exist only where someone posted.

A pool-based AMM computes a price from the state of a liquidity pool. In Uniswap, you trade with the pool rather than another user’s resting order. That is the design contrast in Uniswap’s own docs.

Both can live on the same chain. OpenBook-style books on Solana and Uniswap-style pools on Ethereum are both DEXs. Calling every DEX an AMM erases that.

Constant product, conceptually

Uniswap v2’s whitepaper: each pair stores reserves of two ERC-20s and keeps the product of reserves from decreasing (fees can make it rise). In the usual notation:

[ x \cdot y = k ]

If you take (\Delta y) of token Y out, you must put in a (\Delta x) large enough that ((x+\Delta x)(y-\Delta y)) is at least (k) after fees. When (y) shrinks, each extra unit of Y costs more X. That is why larger trades, relative to the pot, move the price more. The move is the mechanism, not a glitch.

v1 only paired tokens with ETH. v2 allowed arbitrary ERC-20 pairs. Later versions keep the AMM idea and change where liquidity sits.

You do not need the calculus. You need: while usable liquidity remains, the rule can quote; the quote depends on how scarce that side of the pot is.

Why the price moves, and who puts it back

A trade changes reserves, so the implied spot (x/y) changes (price impact). If that spot is away from an external venue or another pool, an arbitrageur trades the cheap side until the difference no longer covers fees and transaction costs.

LPs feel that as their basket changing. The AMM is doing inventory management by formula.

Liquidity providers and fees

LPs supply the robot’s inventory. Uniswap v2: traders pay 30 basis points; by default it all accrues to LPs, while an optional protocol fee redirects one-sixth of that fee (5 bp of trade value). v3/v4 use fee tiers and range positions.

Fees are income. They are not a hedge that always beats holding (see Liquidity pools on impermanent loss).

Concentrated liquidity

Uniswap’s concentrated-liquidity docs: v3 (and v4) let an LP choose a price interval. Capital is active only inside that interval. Outside, the position is a single asset and earns nothing until price returns.

Ticks discretize price space (a 1-tick step is a 0.01% price step in their description). Tighter ticks help stable pairs; crossing many active ticks costs more gas.

Same product formula, applied inside the range. Not a new venue type — a more precise pot.

Stable-swap and other invariants

Michael Egorov’s 2019 StableSwap paper describes a curve meant for assets that should trade near parity — “Uniswap with leverage” in the abstract’s phrase — so stablecoin-to-stablecoin swaps do not suffer as much impact as a raw (x \cdot y = k) pool of the same size. Curve popularized that family. This article does not reproduce the invariant.

Weighted pools (Balancer) use a product of token balances raised to chosen weights, allowing more than two assets and allocations other than 50/50. Pool mechanisms governed by an invariant are often called constant-function market makers (CFMMs) in research. “AMM” is the broader label, so it should not be treated as a universal synonym for “liquidity pool.”

Price impact, slippage, MEV

  • Price impact — the pool’s price after your trade versus before, from the formula and your size.
  • Slippage — the gap between the expected price and the executed price. It can reflect other trades, ordering, or an incomplete quote/model before execution. A slippage tolerance is a limit, while a swap fee is a separate charge (next article).
  • MEV / sandwiches — a searcher buys before you, lets your trade push the price, sells after (EEA; Batch C DEX). AMMs that expose a pending trade in a public mempool are easy to sandwich. Private orderflow and tight tolerances are mitigations, not magic.

Benefits and limits

Benefits. Continuous formula-based quotes while usable liquidity remains; permissionless pool creation; no need to host a matching engine; composable with other contracts in one transaction.

Limits. LPs take directional inventory risk; stale or thin pools give terrible prices; the spot is a bad oracle; MEV; the curve may be a poor fit (using constant product for two dollars); smart-contract and token risk; a website can still lie about the route.

An AMM is one way to build a DEX. It is not “how decentralized trading works.”

Sources & further reading

  1. How Uniswap Works Uniswap Primary · Documentation

    AMM vs order book; constant product; LPs; permissionless markets.

  2. Uniswap v2 Core Hayden Adams, Noah Zinsmeister, Dan Robinson Primary · Paper

    \(x \cdot y = k\); 30 bp; oracle warning; flash swaps.

  3. Concentrated Liquidity Uniswap Primary · Documentation

    Ranges, ticks, idle liquidity.

  4. Michael Egorov, *StableSwap Primary · Paper

    efficient mechanism for Stablecoin liquidity*, 10 November 2019. — Alternative invariant for like-priced assets (“Uniswap with leverage” in the abstract).

  5. Balancer: A Non-Custodial Portfolio Manager, Liquidity Provider, and Price Sensor Fernando Martinelli and Nikolai Mushegian Primary · Paper

    Primary support for the weighted invariant, custom allocations and multi-asset pools.

  6. Version 1*, 17 July 2024. — MEV sandwiches; impermanent loss Enterprise Ethereum Alliance Primary · Documentation
  7. Glossary Uniswap Primary · Documentation

    AMM, constant product, price impact versus slippage, impermanent loss, protocol fees.

  8. The Technology of Decentralized Finance (DeFi) Raphael Auer, Bernhard Haslhofer, Stefan Kitzler, Pietro Saggese and Friedhelm Victor Secondary · Paper

    Independent cross-check for AMMs versus order books, pool reserves, \(x \cdot y = k\), LP shares, fees, impact and arbitrage.