Home / Wiki / F / Formulas for Automated Market Makers (AMMs)

Formulas for Automated Market Makers (AMMs)

Cryptocurrency and Digital AssetsUpdated 05 Nov 2026

Formulas for automated market makers are the pricing rules that liquidity pools on a decentralized exchange (DEX) use to decide how much of one token a trader receives for another. Instead of relying on a human market maker or matching buyers and sellers in an order book, the pool's smart contract holds reserves of two or more tokens and only accepts trades that keep a chosen mathematical quantity, the invariant, unchanged after fees.

This entry covers the maths. The broader idea, history and risks of automated market makers (AMMs) are covered in their own entry. The choice of formula decides how prices move with trade size, how efficiently liquidity providers use their capital, and how exposed they are to impermanent loss. The best-known designs come from Uniswap, Curve and Balancer on the Ethereum blockchain, and have been copied across decentralized finance (DeFi) on most other chains.

01

AMM formulas in plain terms

Picture a market stall that sells apples for oranges and keeps two crates behind the counter. The stallholder follows one rule: after every swap, the number of apples multiplied by the number of oranges must stay the same. When apples get scarce, each extra apple costs more oranges, so the price rises on its own without anyone posting a new price tag.

Other stalls use different rules. One might always swap one for one, which suits two things that should be worth the same. Another might bend the curve so that small swaps near a fair price are cheap but big ones become expensive. The rule written on the counter is the AMM formula.

02

The constant product formula

The most widely used design, introduced by Uniswap in 2018, keeps the product of the two reserves constant:

x×y=kx \times y = k
  • xx is the pool's reserve of token X.
  • yy is the pool's reserve of token Y.
  • kk is the constant, which only changes when liquidity is added or removed (or, slightly, when fees accrue).

The spot price of X in terms of Y is y÷xy \div x. With a fee ff charged on the input, a trader who puts in Δy\Delta y of token Y receives:

Δx=x×Δy(1−f)y+Δy(1−f)\Delta x = \frac{x \times \Delta y (1 - f)}{y + \Delta y (1 - f)}

Worked example: a pool holds 100 ETH and 300,000 USDC, so the spot price is $3,000 per ETH. A trader swaps 30,000 USDC with a 0.3 percent fee. The amount counted after the fee is 30,000×0.997=29,91030{,}000 \times 0.997 = 29{,}910. The trader receives 100×29,910÷(300,000+29,910)≈9.066100 \times 29{,}910 \div (300{,}000 + 29{,}910) \approx 9.066 ETH, an average price of about $3,309. After the trade the pool holds about 90.93 ETH and 330,000 USDC, so the new spot price is roughly $3,629. The gap between $3,000 and the $3,309 actually paid is the price impact, a large part of what traders experience as slippage. The curve never runs out of either token, but large trades against small pools become very expensive.

03

Constant sum and weighted pools

The simplest alternative keeps the sum constant:

x+y=kx + y = k

Every trade happens at a fixed one-to-one price with no price impact, which seems ideal for two stablecoins. The flaw is that if the outside market price moves even slightly, arbitrageurs can drain one side of the pool completely, so pure constant sum pools are rarely used.

Balancer generalised the product rule to pools of up to eight tokens with custom weights:

∏iBiwi=k\prod_{i} B_i^{w_i} = k

Here BiB_i is the balance of token ii and wiw_i its weight, with the weights adding up to 1. An 80/20 pool lets a project hold mostly its own token while still offering a market, and behaves like a self-rebalancing index fund.

04

StableSwap and concentrated liquidity

Curve's StableSwap design, published by Michael Egorov in 2019, blends the sum and product rules. For a pool of nn tokens with balances xix_i, total value DD at equal prices, and an amplification coefficient AA, the invariant is:

Ann∑ixi+D=ADnn+Dn+1nn∏ixiA n^{n} \sum_{i} x_i + D = A D n^{n} + \frac{D^{n+1}}{n^{n} \prod_{i} x_i}

When the pool is balanced it behaves almost like the constant sum line, giving very low slippage for like-priced assets. As it becomes lopsided it bends towards the constant product curve, so it cannot be drained. A higher AA keeps the flat region wider. The design underpins Curve DAO (CRV) and many stablecoin pools.

Uniswap v3, launched in May 2021, introduced concentrated liquidity. Each provider chooses a price range from pap_a to pbp_b, and within that range their position follows a shifted product curve:

(x+Lpb)(y+Lpa)=L2\left( x + \frac{L}{\sqrt{p_b}} \right) \left( y + L \sqrt{p_a} \right) = L^{2}

LL measures the position's liquidity. Concentrating capital near the current price gives traders deeper markets with the same money, but a provider whose range is left behind earns no fees and ends up holding only one token.

05

How formula choice shapes the market

No formula knows the "true" price. Pools rely on arbitrage: when a pool's price drifts from prices elsewhere, traders buy the cheap side until the gap closes, and the profit they take is a cost borne by liquidity providers. Flatter curves suit assets meant to trade at par; wider curves suit volatile pairs. Fee tiers, gas fees and the depth of the liquidity pool all change the result for a given trade. Providers receive LP tokens or position NFTs that track their share, and their return is fees earned minus the loss from price moves. Later designs, such as Uniswap v4 hooks and dynamic fees, keep these core invariants and add rules around them.

Last updated 05 Nov 2026