CFMM (Constant Function Market Maker)
A pool that prices trades from an invariant, so it always quotes a price without needing a counterparty.
Basically
A constant function market maker uses a fixed mathematical rule to set prices in a shared pool of tokens. You trade with the pool instead of using an order book.
Key Takeaways
- A constant function market maker (CFMM) is a type of automated market maker that uses a mathematical invariant function to set asset prices. Every valid trade must preserve the function's value, so the pool always offers liquidity at some price.
- The three foundational CFMM variants are the constant product (x · y = k, used by Uniswap), the constant sum (x + y = k, useful for pegged assets), and the constant mean (weighted geometric mean, used by Balancer for multi-asset pools).
- Innovations such as StableSwap (Curve) and concentrated liquidity (Uniswap V3) change the effective invariant to improve capital efficiency. They reduce slippage for traders and increase returns for liquidity providers.
What Is a Constant Function Market Maker?
A constant function market maker (CFMM) is a class of automated market maker defined by a trading function φ that maps pool reserves to a single value. The CFMM smart contract accepts a proposed trade only if the trading function remains constant after the reserves change. The invariant function replaces the traditional order book and determines prices itself, rather than matching buyers with sellers.
The term “constant function” describes the rule that φ(x, y) = φ(x′, y′) after any valid swap, where (x, y) are the reserves for two tokens and (x′, y′) are the new reserves. Different choices of φ produce different pricing behaviours, slippage curves and capital efficiency profiles. CFMMs therefore provide a general mathematical framework, with protocols such as Uniswap, Curve and Balancer each selecting an invariant function optimised for their use case.
CFMMs power the majority of on-chain trading volume across decentralised finance. Their permissionless design lets anyone create a liquidity pool or provide liquidity without approval, while deterministic pricing makes every trade execute transparently on-chain.
How It Works
A CFMM operates as a smart contract holding reserves of two or more tokens. You deposit token A into the pool and withdraw token B when you want to swap A for B. The smart contract calculates the valid withdrawal amount by solving for the value that keeps the invariant function constant.
The invariant requires larger trades to cause greater price impact. A trade representing a large fraction of the pool's reserves pushes the price further along the invariant curve and produces worse execution. The self-adjusting design means CFMMs always offer liquidity at some price, although that price may be unfavourable for large orders.
Constant Product (x · y = k)
The constant product formula is the most widely deployed CFMM variant. Uniswap V1 and V2 use this invariant, which requires the product of the two reserve balances to remain constant after every trade.
The curve defined by x · y = k is a hyperbola that approaches both axes asymptotically but never reaches zero. Neither reserve can ever be fully depleted, regardless of trade size. Large trades still cause significant price deterioration, so constant product pools are best suited to volatile asset pairs whose prices fluctuate widely across the full range.
Constant Sum (x + y = k)
The constant sum invariant maintains a fixed total of reserves: x + y = k. The result is a linear pricing curve with zero slippage, so every unit trades at the same price regardless of trade size.
Constant sum pools have a critical flaw despite their zero slippage: they can be completely drained. An arbitrageur can buy the underpriced token until one side is empty if the market price deviates from the pool's fixed 1:1 rate, so pure constant sum pools are not used in practice. The constant sum concept remains an important building block in hybrid designs like StableSwap.
Constant Mean (Weighted Geometric Mean)
Constant mean market makers, popularised by Balancer, generalise the constant product formula by introducing weights. A pool with n tokens and weights w₁, w₂,..., wₙ uses these weights in its invariant, and all weights sum to 1.
Weighted pools let liquidity providers maintain custom portfolio exposures. An 80/20 ETH/USDC pool gives the LP 80% exposure to ETH price movements, compared with the 50/50 split in a standard constant product pool. Balancer supports up to 8 tokens in a single pool, enabling index-fund-like products on-chain.
StableSwap (Curve Hybrid Invariant)
Curve Finance introduced the StableSwap invariant in 2019. It combines the constant product and constant sum curves using an amplification coefficient A.
The StableSwap curve approximates a constant sum near equilibrium, where both reserves are balanced, and provides extremely low slippage. The curve moves towards constant product behaviour as reserves become imbalanced, preventing either reserve from being depleted. StableSwap is therefore approximately 100x more capital efficient than a standard constant product pool for assets trading near a 1:1 peg, such as stablecoin pairs (USDC/USDT) or wrapped asset pairs (ETH/stETH).
Concentrated Liquidity
Uniswap V3 introduced concentrated liquidity, which modifies the effective CFMM invariant by letting liquidity providers allocate capital within specific price ranges rather than across the entire curve. Within each range, the pool uses “virtual reserves” that follow the constant product formula (x · y = L², where L is the concentrated liquidity), but the actual capital required is only a fraction of what a full-range position would need.
The approach creates a piecewise CFMM: each price tick has its own liquidity depth, and the aggregate curve can approximate any shape depending on how LPs distribute their positions. Concentrated liquidity around the current price behaves similarly to StableSwap for active ranges in practice, with dramatically improved capital efficiency. A position concentrated within a narrow range can earn hundreds of times the fee revenue of a full-range position with the same capital.
Why It Matters
CFMMs fundamentally changed how markets operate by replacing human market makers and order books with deterministic mathematical functions. Traditional market making requires sophisticated firms with large balance sheets and low-latency infrastructure. CFMMs democratise this role: anyone with capital can provide liquidity and earn fees.
The design space for CFMMs continues to expand, with protocols experimenting with dynamic fee adjustment, oracle-informed pricing and custom invariant curves tailored to specific asset types. Each new variant explores a different trade-off between capital efficiency, slippage and impermanent loss for liquidity providers. CFMMs serve as the foundational primitive for most other DeFi protocols as DeFi matures: lending markets use CFMM prices for liquidation triggers, stablecoin arbitrage relies on CFMM pools to restore pegs, and aggregators route through multiple CFMM pools to find optimal execution.
Research on sustainable DeFi revenue models offers a deeper exploration of these trading mechanisms. It also places them within the wider DeFi system.
Impermanent Loss
All CFMM liquidity providers face impermanent loss: when the relative price of pooled assets changes, the LP's position becomes worth less than if they had simply held the tokens. The invariant function mechanically sells the appreciating asset and buys the depreciating one as prices move, causing the loss. The loss is “impermanent” only if prices revert; otherwise, it is realised upon withdrawal.
Price Manipulation
CFMM prices depend solely on reserve ratios, so flash loans can manipulate them within a single transaction. An attacker can borrow a large amount, push the CFMM price to an extreme, exploit another protocol that reads this price, then repay the loan. Protocols typically use time-weighted average prices (TWAPs) rather than spot CFMM prices for critical operations because of this oracle manipulation risk.
MEV Extraction
CFMM trades broadcast to a public mempool are vulnerable to maximal extractable value strategies. Sandwich attacks place transactions before and after a victim's swap to profit from the predictable price movement, effectively extracting value from traders. Front-running and back-running also exploit the deterministic nature of CFMM pricing.
Smart Contract Risk
CFMMs rely entirely on smart contract code for custody and execution. Bugs in the invariant logic, rounding errors or reentrancy vulnerabilities can lead to pool draining. Major protocols undergo extensive auditing and formal verification, but DeFi's composable nature means interactions between protocols can create emergent risks not present in any single contract.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. You should always do your own research before using any protocol or technology.