CFMM math: x·y=k, price impact, and fees
1. TL;DR
Section titled “1. TL;DR”A constant-function market maker (CFMM) is a pool of two or more tokens that accepts any trade which leaves a fixed function of its reserves unchanged; Uniswap’s rule is that the product of the reserves, , never falls. Because the pool never looks at outside prices, its quote is simply the reserve ratio, and arbitrageurs are the only thing that keeps that quote near the world price—within a band whose width is set by the fee. Price impact grows roughly linearly with trade size relative to pool size, so the same formula that makes CFMMs simple and un-drainable also makes large trades expensive.
2. Explain it simply
Section titled “2. Explain it simply”Analogy
Section titled “Analogy”Picture a lemonade stand with one strange rule: the number of lemons on the counter multiplied by the dollars in the till must always equal 1,000. With 10 lemons and $100 in the till, the first lemon costs about $10. But if you want 5 lemons, you must leave enough dollars that lemons × dollars still equals 1,000: 5 lemons × $200, so you pay $100 for 5 lemons, or $20 each. Every extra lemon costs more because the stand is running low. The stand never checks the grocery store’s price; if lemons are cheaper at the store, someone will buy them there and sell them to the stand until the stand’s implied price matches the store.
A swap pool is a box holding two kinds of coins, say gold and silver. The box follows one rule: the number of gold coins multiplied by the number of silver coins must never go down. Put silver in and the box gives you gold, but only as much as keeps the multiplication the same. The more you take, the stingier the box gets, because it is running low on gold. The box never checks prices anywhere else. If gold is cheaper at the market than in the box, traders buy gold at the market and sell it to the box until the box’s price matches. A small fee on every trade pays the people who filled the box.
Step-by-step walkthrough
Section titled “Step-by-step walkthrough”Scenario: an ETH/USDC pool holds 1,000 ETH and 2,000,000 USDC, so and the spot price is 2,000 USDC per ETH. The fee is 0.30%. A trader sells 10 ETH.
- Before: reserves (1,000 ETH, 2,000,000 USDC); spot 2,000; .
- Fee taken: 0.03 ETH is set aside; 9.97 ETH enters the pricing formula. The pool pays out USDC. After: (1,010 ETH, 1,980,256.8 USDC).
- Trader’s fill: 1,974.3 USDC per ETH on average, 1.28% below spot—0.30% is the fee, the remaining 0.99% is price impact. New spot = 1,980,256.8 / 1,010 = 1,960.7. The product is now : it grew by the fee.
- Arbitrage: the world price is still 2,000, so the pool’s ETH is cheap. An arbitrageur buys about 8.5 ETH for about 16,820 USDC, pushing the pool’s spot back to about 1,994—the lower edge of the fee band. After: roughly (1,001.5 ETH, 1,997,080 USDC). The arbitrageur pockets about USDC.
- LP position: liquidity providers hold a slightly larger product than before; their fee income is the growth of over time.
Common misconceptions
Section titled “Common misconceptions”- Myth: the pool “knows” the market price. Reality: it only knows its own reserve ratio; arbitrageurs import the price, and only within a band as wide as the fee (Angeris et al. 2019, §2.1).
- Myth: slippage and price impact are the same thing. Reality: Hasu separates price impact (a deterministic function of your size versus the pool) from slippage (the gap between the quote you saw and the fill you got because other transactions landed first).
- Myth: splitting a trade into several pieces in the same block reduces its cost. Reality: with a nonzero fee, splitting is strictly worse (Angeris et al. 2019, §2.3); splitting only helps when arbitrageurs reset the price between the pieces, which is the idea behind TWAMM.
- Myth: a large enough trade can drain the pool. Reality: total reserves can never fall below (the no-depletion property).
- Myth: LPs earn the fee as pure profit. Reality: with zero fees the LP’s portfolio value is , a concave function of price that lags simply holding; see IL vs LVR.
If you only remember one thing
Section titled “If you only remember one thing”A CFMM is a dumb but honest counterparty: its price is its reserve ratio, arbitrageurs keep that within a fee-wide band of the world price, and the cost of a trade is roughly twice its share of the pool.
3. How it works
Section titled “3. How it works”The trading function
Section titled “The trading function”A CFMM holds reserves of token X and of token Y and accepts any trade that keeps a trading function fixed, . Uniswap v1/v2 use the constant product . Balancer generalises to a constant (weighted geometric) mean over assets, with weights , ; the constant product is the special case , (Angeris et al. 2019, §3). Curve’s StableSwap interpolates between a constant sum and a constant product (see stable pools), and Uniswap v3 translates the constant-product curve so that it is solvent only within a price range (see concentrated liquidity).
Spot price
Section titled “Spot price”Differentiating implicitly gives the marginal (spot) price of X in units of Y:
Angeris et al. write this as and note that with a fee the marginal price of an infinitesimal purchase is , where is the fee rate. Hasu’s example: with 2,700 WBTC and 86,000 ETH in the Uniswap v2 ETH/WBTC pool, the implied ETH price was WBTC (as of 2021-04).
Executing a trade
Section titled “Executing a trade”Selling of X (no fee) must satisfy , so the output is
The average execution price and the marginal price after the trade are
$$p_{\text{exec}} = \frac{\Delta y}{\Delta x} = \frac{p}{1 + \Delta x / x}, \qquad p’ = \frac{y - \Delta y}{x + \Delta x} = \frac{p}{(1 + \Delta x / x)^2}.$$
Price impact is the shortfall of the execution price from spot: for small trades. At spot, both reserves have equal value, so if the order is a fraction of the total pool value then and the impact is about . This is Hasu’s rule of thumb: “the price impact of your order is about twice the size of your order relative to the pool” (as of 2021-04, Uniswap v2 examples of 0.19%, 1.85% and 18.52% of pool size).
With fee rate (Uniswap v2: ), only counts toward the invariant:
Because all of is deposited, the new product is strictly larger than : the constant is non-decreasing on every trade and strictly increasing whenever (Angeris et al. 2019, eq. 5). Hasu points out that a 0.30% fee is a 0.60% spread between best bid and best ask inside which the pool quotes nothing, so “even the most liquid AMM trade has an implicit 0.3% price impact.”
No-arbitrage band
Section titled “No-arbitrage band”Let be the price on an infinitely liquid reference market. An arbitrageur can profit whenever the pool’s fee-adjusted marginal price is on the wrong side of . Ruling this out in both directions gives (Angeris et al. 2019, eq. 3):
or, for small fee , . The optimal arbitrage trade is the solution of a convex problem, (Appendix A), which is why arbitrage is cheap to compute and, empirically, why AMM prices “closely track the reference market price.” Convexity extends to routing a trade across many pools and assets (Angeris, Agrawal, Evans, Chitra, Boyd 2021), the basis of aggregators.
Structural properties (Angeris et al. 2019, §2.3)
Section titled “Structural properties (Angeris et al. 2019, §2.3)”- No depletion. By the AM–GM inequality , and never decreases, so no sequence of swaps can empty the pool.
- Splitting is more expensive. With , trading then yields less than trading at once (path dependence).
- Liquidity scales with reserves. The marginal cost curvature is (eq. 6): doubling reserves at the same price halves the second-order cost of a trade.
- Cost of manipulation. Moving the pool price to for one period costs at least (eq. 8): linear in reserves, but only quadratic in for small moves, so contracts that read a CFMM spot price as an oracle “should not be extremely sensitive to small price fluctuations” (see the AMM oracles page).
- LP value without fees. Under no-arbitrage the reserves satisfy , so the pool’s portfolio value is (eq. 10) and its return between two times is . Under geometric Brownian motion with volatility this value grows a factor slower than the asset’s expectation (Appendix C, eq. 17)—the seed of the LVR result covered in IL vs LVR.
Slippage, routing, and the four costs
Section titled “Slippage, routing, and the four costs”Hasu decomposes a trade’s cost into price impact, fees, slippage, and chain transaction fees. Because the output function is concave in trade size, it is cheaper to spread a large order across pools than to hit one pool (the “smart order routing” that 1inch, Matcha and Jupiter automate), and sometimes cheaper to route through a bridge asset than to use a direct pair (see routing and aggregation).
4. Worked numeric example
Section titled “4. Worked numeric example”Same pool as §2: 1,000 ETH, 2,000,000 USDC, , fee 0.30%.
| Step | Quantity | Value |
|---|---|---|
| Spot before | 2,000.00 USDC/ETH | |
| Sell 10 ETH, no fee | 19,801.98 USDC (avg 1,980.20; impact 0.99%) | |
| Sell 10 ETH, 0.30% fee | 19,743.16 USDC (avg 1,974.32; 1.28% below spot) | |
| Spot after | 1,960.65 USDC/ETH | |
| New product | (+0.003%) | |
| Rule-of-thumb check | order of pool | predicted impact ✓ |
Arbitrage back to the world price of 2,000: the pool’s spot (1,960.65) is below , so the optimal purchase of ETH from the pool is ETH, costing about 16,820 USDC (about 1,984 per ETH) and leaving the pool at about 1,994—the band edge. Selling 8.5 ETH at 2,000 elsewhere nets about 140 USDC.
Scaling up: selling 100 ETH (5% of the pool’s value) pays out USDC, an average of 1,813.2, i.e. 9.3% below spot—again close to twice the order’s share of the pool. Hasu’s advice follows directly: find the deepest pool, split across venues or over time, and question any on-chain fill with more than 2–3% impact when a deeper market exists.
5. Where it’s used
Section titled “5. Where it’s used”Ethereum
Section titled “Ethereum”- Uniswap v2 — canonical with a 30 bp fee, arbitrary ERC-20 pairs, a time-weighted price accumulator and flash swaps; the whitepaper explicitly relies on Angeris et al. for the claim that the pool price tracks the market. Uniswap Labs reported “over $135bn in trading volume” for v2 in under a year (as of 2021-03). whitepaper
- Uniswap v3 / v4 — the same curve inside each tick range; v3’s launch post noted that the v2 DAI/USDC pair reserved only ~0.50% of its capital for prices between $0.99 and $1.01 (as of 2021-03), the motivation for concentrated liquidity.
- Balancer — constant-mean pools with up to assets and custom weights (Angeris et al. 2019, §3).
- Curve — StableSwap and crypto pools; stable pools.
- Batch and intent venues (CoW, UniswapX) still settle against CFMM liquidity; batch auctions.
Solana
Section titled “Solana”- Raydium AMM v4 and CPMM — both use ; the OpenBook order-book integration of AMM v4 has been deactivated, CPMM is the recommended default with Token-2022 support. Raydium reports ~$1.8B TVL (as of 2026-04, citing DefiLlama), ~$300M of it in AMM v4, and that ~60% of Jupiter-routed volume hits Raydium pools (as of 2026-04). docs
- Orca Whirlpools — concentrated liquidity (the v3 model) rather than full-range constant product. docs
- Meteora DAMM v1/v2 — constant-product pools (v1 “infinite price range”, v2 with optional concentrated ranges); DLMM uses discrete bins instead. docs
- Jupiter — the aggregator that routes across all of the above; its Metis engine does multi-hop, multi-split swaps, and its RFQ engine “often beats onchain by 5-20bps on major pairs” (as of 2026-08 docs). docs
- Proprietary AMMs (SolFi, HumidiFi, ZeroFi, Tessera V, Obric, Lifinity) — replace the passive curve with an oracle-anchored curve whose parameters the operator updates several times a second; Helius reports they captured more than 60% of SOL/USDC volume over three months, peaking at 86% on 2025-07-05, with daily volume above $1B for 60 days (as of 2025-08). Helius
6. Risks, attacks, and incidents
Section titled “6. Risks, attacks, and incidents”- Front-running and sandwiches. Vitalik Buterin’s 2018 post identified the flaw before Uniswap launched: with state (10, 10), a miner wrapping a 1-unit buy with its own buy and sell earns 0.151515 units “with zero risk, all of which comes out of my pocket.” Public mempools make this routine on Ethereum; see MEV taxonomy.
- Spot price as an oracle. The v2 whitepaper warns that v1’s instantaneous price “is very easy to manipulate” within one transaction. The bZx attacks of February 2020 (~$1M across two incidents) used exactly this: draining Kyber’s sUSD reserves to inflate collateral value (samczsun, Paradigm, 2020-11). The Angeris bound shows why: small price moves are only quadratically expensive. See the oracle manipulation page.
- Adverse selection of LPs. Angeris et al.’s agent simulation found that “in almost all of our simulations, initial liquidity providers end up having negative utility” relative to holding; the mechanism is formalised as LVR in IL vs LVR.
- Implementation bugs in curve arithmetic. KyberSwap Elastic lost about $48.7M on 2023-11-22 when a double-rounding error in
computeSwapStep()let the pool believe a tick had not been crossed, double-counting liquidity (KyberSwap post-mortem). The math was fine; the fixed-point implementation was not. - Admin keys over pools. On 2022-12-16 an attacker who obtained Raydium’s AMM v4 pool-owner key drained about $4.4M from eight constant-product pools (Raydium post-mortem, reported by Unchained). The invariant protects against trades, not against privileged parameter changes.
7. Open problems
Section titled “7. Open problems”- What fee is right? In an all-arbitrage, geometric-Brownian model, Robinson, White, Noyes and Tassy (2020) find LPs beat holding only when volatility is high relative to drift and should then set the fee “as low as possible without being zero”; Evans, Angeris and Chitra (2021) derive optimal fees for geometric-mean pools; Milionis, Moallemi and Roughgarden (2023) show lower fees raise arbitrage profits. The answer depends on the mix of informed and uninformed flow, which is unobservable ex ante.
- Which functions are legitimate? Schlegel, Kwaśnicki and Mamageishvili (2022) give an axiomatic characterisation of CFMMs; Angeris, Evans and Chitra (2020) show curvature trades off price stability against manipulation resistance and LP returns.
- No privacy. Angeris, Evans and Chitra (2021) show that anyone who can query the pool before and after a trade can recover its size, so CFMMs cannot hide order flow; see the ZK DEX limits page.
- Passive curves versus active quoting. Helius argues that on Solana oracle-updated proprietary AMMs “in many cases outperform passive liquidity models”; whether passive liquidity survives on sub-second chains except as a fallback for long-tail assets is unresolved (Helius, 2025-08; an opinion, not a theorem).
- Multi-block manipulation. The Angeris manipulation bound is per period; a proposer controlling consecutive blocks faces a lower cost, which is the setting studied in the AMM oracles page.
8. Ethereum vs Solana
Section titled “8. Ethereum vs Solana”| Aspect | Ethereum | Solana |
|---|---|---|
| Canonical CFMM | Uniswap v2 (x·y=k, 30 bp), v3/v4 ranges | Raydium AMM v4 / CPMM (x×y=k), Orca and Raydium CLMM, Meteora DLMM |
| Block cadence relevant to arbitrage | ~12 s slots | ~400 ms slots; Raydium docs quote “~1 second” finality vs “~12 seconds” (as of 2026-04) |
| Typical swap cost | “$5–50” per Raydium’s comparison (as of 2026-04) | “$0.001–0.01” (as of 2026-04) |
| Mempool | public; sandwiches via builders | none public; ordering via leader and Jito bundles |
| Aggregator structure | diversified: CoW 29.2%, 1inch 24.8%, Kyber 12.1% of $31.09B (2025-07, Helius citing The Block) | Jupiter 86.4% of $64.1B aggregator volume (2025-07, Helius citing Blockworks) |
| Active liquidity | am-AMM and hook designs, mostly research | proprietary AMMs >60% of SOL/USDC volume (2025-07) |
| Token semantics | ERC-20; fee-on-transfer tokens break naive invariants | Token-2022 transfer fees/hooks supported natively by Raydium CPMM |
The math is identical on both chains; what differs is the environment around the curve. Ethereum’s slow blocks and public mempool mean the constant-product pool is arbitraged in discrete, visible jumps, and the no-arbitrage band is only re-established every 12 seconds. Solana’s sub-second slots, cheap oracle updates and single dominant aggregator have pushed liquidity toward curves whose parameters are re-quoted continuously, so the passive pool increasingly serves long-tail launches (Raydium CPMM, Meteora DAMM v2) while major pairs trade on actively managed curves.
9. Reference doc
Section titled “9. Reference doc”The reference
Section titled “The reference”An analysis of Uniswap markets — Guillermo Angeris, Hsien-Tang Kao, Rei Chiang, Charlie Noyes, Tarun Chitra, November 2019 (arXiv v7, February 2021). https://arxiv.org/abs/1911.03380
Summary of the reference
Section titled “Summary of the reference”The paper gives the first formal treatment of constant product markets. §1 motivates AMMs against order books (state is expensive on-chain, matching logic complex, off-chain books enable front-running) and situates Uniswap between Hanson’s LMSR and Bancor-style bonding curves. §2 defines the market: reserves , constant , fee , and the trade condition (eq. 1). §2.1 poses optimal arbitrage against an infinitely liquid reference market as maximising subject to eq. 1, shows it is convex, and derives the no-arbitrage band (eq. 3), where —the headline result that a CFMM price must track the market up to the fee. §2.2 adds convex risk penalties for arbitrageurs. §2.3 collects properties: is non-decreasing (eq. 5); splitting trades is more expensive; the second-order price sensitivity is (eq. 6); the cost of manipulating the price by a factor is at least (eq. 8); and in the no-fee case the pool’s value is (eq. 10) with return (eq. 9). §3 extends the analysis to Balancer-style constant mean markets, , showing the same properties hold except that closed-form no-arbitrage bounds are unclear. §4 describes an agent-based simulation in the Gauntlet DSL with arbitrageurs (quadratic risk), rational LPs (Markowitz optimisers), and noise traders, against a reference price with power-law impact and lognormal shocks; Figures 1–3 show the Uniswap price stays inside the predicted band even with drift and noise, while Figure 4 shows initial LPs have negative utility versus holding except when mean return is near zero. §5 concludes that constant product markets are sound price oracles when a liquid external market exists. Appendices prove convexity (A), the price gap formula (B), the Brownian portfolio value (C, eq. 17), path dependence (D), and the manipulation bound (E).
Key quotes
Section titled “Key quotes”- “Uniswap—and other constant product markets—appear to work well in practice despite their simplicity.” (Abstract)
- “This suggests that, in practice, the larger the trade fees are, the larger the gap between the true market price and the Uniswap market price may be.” (§2.1, after eq. 3)
- “This result implies that the cost of manipulation scales linearly with the reserve amounts, marking the importance of having large reserve pools.” (§2.3, cost of manipulation)
- “we find that in almost all of our simulations, initial liquidity providers end up having negative utility (using this definition), over most varying conditions.” (§4.3)
- “These results help us conclude that Uniswap serves as a censorship resistant price oracle for smart contracts, provided that there exists an external reference market with sufficient liquidity.” (§1, Summary)
How to read the original
Section titled “How to read the original”Background: one-variable calculus (implicit differentiation), the AM–GM inequality, and the idea of a convex optimisation problem. Read §2.1 and §2.3 first; they contain everything most practitioners need. Skip §2.2 (risk models) and the simulation details of §4.1–4.2 on a first pass. The hardest paragraph is the derivation of the no-arbitrage band in §2.1: the key move is that the fee makes the pool’s buy marginal price and its sell marginal price , so an arbitrageur can only profit if the market price lies outside ; inverting that interval gives eq. 3. Appendix C is worth a second read because the factor is exactly the constant-product LVR rate derived independently three years later.
What changed since
Section titled “What changed since”- 2020-03: Uniswap v2 whitepaper cites the paper as justification for its TWAP oracle.
- 2020-12: Robinson, White, Noyes and Tassy (“Uniswap’s Financial Alchemy”) solve the optimal-fee problem the paper leaves open, finding low-but-nonzero fees can beat holding via volatility harvesting.
- 2021-03: Uniswap v3 replaces the single global curve with range positions; the properties here hold per tick range.
- 2021-07: Angeris, Agrawal, Evans, Chitra and Boyd generalise the convex arbitrage problem to multi-asset routing.
- 2022-08: Milionis, Moallemi, Roughgarden and Zhang define LVR, sharpening Appendix C into a path-by-path decomposition.
- 2022-09: Schlegel, Kwaśnicki and Mamageishvili provide axioms characterising CFMMs.
- 2024–2025: on Solana, oracle-updated proprietary AMMs displace passive constant-product liquidity on major pairs (Helius, 2025-08).
Secondary references
Section titled “Secondary references”- Hasu, Understanding AMMs Part 1: Price Impact (Paradigm, 2021-04) — read if you want the trader’s view and the “2× your share of the pool” rule.
- Uniswap v2 Core whitepaper (2020-03) — read if you need the contract mechanics: fee accounting, TWAP oracle, flash swaps.
- Vitalik Buterin, Improving front running resistance of xy=k market makers* (ethresear.ch, 2018-03) — read if you want the origin story and the first sandwich example.
- Angeris, Evans, Chitra, When does the tail wag the dog? Curvature and market making (2020-12) — read if you want the geometry behind why curvature matters.
- Schlegel, Kwaśnicki, Mamageishvili, Axioms for CFMMs (2022-09) — read if you want to know which trading functions are “allowed.”
10. Sources
Section titled “10. Sources”- An analysis of Uniswap markets — Angeris, Kao, Chiang, Noyes, Chitra — 2019-11-08 — https://arxiv.org/abs/1911.03380
- Understanding Automated Market-Makers, Part 1: Price Impact — Hasu (Paradigm) — 2021-04-19 — https://www.paradigm.xyz/writing/understanding-automated-market-makers-part-1-price-impact
- Uniswap v2 Core whitepaper — Adams, Zinsmeister, Robinson — 2020-03 — https://app.uniswap.org/whitepaper.pdf
- Introducing Uniswap v3 — Uniswap Labs — 2021-03-23 — https://blog.uniswap.org/uniswap-v3
- Improving front running resistance of x*y=k market makers — Vitalik Buterin — 2018-03-02 — https://ethresear.ch/t/improving-front-running-resistance-of-x-y-k-market-makers/1281
- So you want to use a price oracle — samczsun (Paradigm) — 2020-11-09 — https://www.paradigm.xyz/writing/so-you-want-to-use-a-price-oracle
- Uniswap’s Financial Alchemy — Robinson, White, Noyes, Tassy — 2020-12-01 — https://www.paradigm.xyz/writing/uniswaps-alchemy
- Constant Function Market Makers: Multi-Asset Trades via Convex Optimization — Angeris, Agrawal, Evans, Chitra, Boyd — 2021-07-26 — https://arxiv.org/abs/2107.12484
- When does the tail wag the dog? Curvature and market making — Angeris, Evans, Chitra — 2020-12-15 — https://arxiv.org/abs/2012.08040
- Axioms for Constant Function Market Makers — Schlegel, Kwaśnicki, Mamageishvili — 2022-09-30 — https://arxiv.org/abs/2210.00048
- A Note on Privacy in Constant Function Market Makers — Angeris, Evans, Chitra — 2021-03-01 — https://arxiv.org/abs/2103.01193
- Optimal Fees for Geometric Mean Market Makers — Evans, Angeris, Chitra — 2021-04-01 — https://arxiv.org/abs/2104.00446
- Automated Market Making and Loss-Versus-Rebalancing — Milionis, Moallemi, Roughgarden, Zhang — 2022-08-11 — https://arxiv.org/abs/2208.06046
- Automated Market Making and Arbitrage Profits in the Presence of Fees — Milionis, Moallemi, Roughgarden — 2023-05-24 — https://arxiv.org/abs/2305.14604
- What is Raydium — Raydium docs — accessed 2026-08-29 — https://docs.raydium.io/introduction/what-is-raydium
- Orca Documentation — Orca — accessed 2026-08-29 — https://docs.orca.so/
- We Build Liquidity Pools — Meteora docs — accessed 2026-08-29 — https://docs.meteora.ag/
- Swap API — Jupiter developer docs — accessed 2026-08-29 — https://developers.jup.ag/docs/swap
- Solana’s Proprietary AMM Revolution — Helius — 2025-08 — https://www.helius.dev/blog/solanas-proprietary-amm-revolution
- Post Mortem: KyberSwap Elastic Exploit — KyberSwap — 2023-11 — https://blog.kyberswap.com/post-mortem-kyberswap-elastic-exploit/
- Solana DEX Raydium Shares Next Steps After $4.4M Exploit — Unchained (secondary, reporting Raydium’s post-mortem) — 2022-12 — https://unchainedcrypto.com/solana-dex-raydium-shares-next-steps-after-4-4m-exploit/