Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Constant Function Market Maker

A Constant Function Market Maker (CFMM) is an automated market maker (AMM) where the product of the reserves of two assets in a liquidity pool remains constant, defining its pricing curve.
Chainscore © 2026
definition
DEFINITION

What is a Constant Function Market Maker?

A technical breakdown of the automated market maker algorithm that powers decentralized exchanges.

A Constant Function Market Maker (CFMM) is a type of automated market maker (AMM) algorithm that determines asset prices based on a mathematical formula, specifically a constant function, which ensures the product of the reserves of two or more assets in a liquidity pool remains unchanged after each trade. This model, most famously implemented by the x * y = k formula for two-asset pools, allows for permissionless, non-custodial trading without the need for traditional order books. It is the foundational mechanism behind major decentralized exchanges (DEXs) like Uniswap, Curve, and Balancer.

The core innovation of a CFMM is its reliance on liquidity pools rather than counterparties. Users, called liquidity providers (LPs), deposit pairs of tokens into a smart contract to create a market. The price of an asset is derived algorithmically from the ratio of the reserves in the pool. For example, in a pool with ETH and DAI, if a trader buys ETH with DAI, the pool's ETH reserve decreases while its DAI reserve increases, causing the price of ETH to rise according to the constant product formula. This automated pricing mechanism eliminates the need for a centralized matching engine.

CFMMs introduce the critical concept of impermanent loss, a divergence loss experienced by LPs when the price of the deposited assets changes compared to simply holding them. This occurs because the AMM algorithm automatically rebalances the pool against market movements. Different CFMMs use varied constant functions optimized for specific use cases: the constant product formula (x * y = k) is best for uncorrelated assets, while the constant sum formula (x + y = k) or hybrid models like Curve's StableSwap are designed for stablecoin pairs to minimize slippage and impermanent loss.

The development of CFMMs has been pivotal for decentralized finance (DeFi), enabling core functions like spot trading, liquidity provisioning, and on-chain price oracles. Their permissionless nature allows anyone to create a market for any token pair, fostering immense innovation and liquidity for long-tail assets. However, they also present challenges, including high gas costs for small trades, vulnerability to front-running via MEV (Maximal Extractable Value), and reliance on external liquidity to maintain accurate prices during volatile market conditions.

how-it-works
MECHANISM

How a Constant Function Market Maker Works

A technical breakdown of the automated market maker (AMM) algorithm that powers decentralized exchanges like Uniswap, enabling permissionless trading without order books.

A Constant Function Market Maker (CFMM) is a type of Automated Market Maker (AMM) that algorithmically sets asset prices based on a predetermined mathematical formula, most commonly x * y = k. In this model, x and y represent the reserves of two assets in a liquidity pool, and k is a constant product that must remain invariant after any trade. This formula ensures that the product of the two reserve quantities is always constant, creating a predictable and automated pricing curve where the price of an asset increases as its available supply in the pool decreases.

The core mechanism relies on liquidity providers (LPs) who deposit equal value of both assets into a pool, creating the reserves that traders interact with. When a trader swaps Asset A for Asset B, they add Δx of A to the pool and remove Δy of B. The smart contract calculates the exact amount of Δy the trader receives based on the constant product formula, ensuring (x + Δx) * (y - Δy) = k. This creates slippage: the execution price diverges from the initial quoted price, especially for large trades relative to the pool's size, which is a form of impermanent loss risk for LPs.

Beyond the basic constant product model (x * y = k), other CFMM functions exist. The constant sum formula (x + y = k) creates a stable, 1:1 price peg but is vulnerable to reserve depletion. Hybrid models like the Stableswap invariant (used by Curve Finance) combine constant product and constant sum to create a "flatter" curve for stablecoin pairs, minimizing slippage for trades near the peg while retaining the product formula's robustness for larger deviations.

The CFMM's operation is entirely non-custodial and driven by on-chain smart contracts, removing the need for traditional order books and centralized market makers. Key parameters set by pool creators, such as the swap fee (e.g., 0.3% in Uniswap V2) and the specific bonding curve, directly influence LP returns and trader costs. This design enables 24/7 market functionality and permissionless listing of any asset pair, forming the foundational liquidity layer for Decentralized Finance (DeFi).

While revolutionary, CFMMs have inherent trade-offs. The simplicity of the constant product formula can lead to significant capital inefficiency, as liquidity is spread thinly across all price ranges. This has led to innovations like concentrated liquidity (Uniswap V3), where LPs can allocate capital to specific price intervals, effectively creating a more capital-efficient, piecewise approximation of the classic CFMM curve. These evolutions maintain the core invariant principle while optimizing for specific use cases.

key-features
MECHANISM BREAKDOWN

Key Features of a CFMM

A Constant Function Market Maker (CFMM) is a type of automated market maker (AMM) that uses a mathematical formula to price assets. Its core features enable permissionless, algorithmic trading and liquidity provision.

01

Invariant Function

The defining rule that maintains a constant relationship between the quantities of assets in a liquidity pool. The most common functions are:

  • Constant Product (x * y = k): Used by Uniswap, where the product of two token reserves must remain constant.
  • Constant Sum (x + y = k): Used for stablecoin pairs, aiming for a fixed price.
  • Stableswap Invariant: A hybrid (like Curve's) that approximates constant sum near the peg and constant product elsewhere for low slippage.
02

Automated Pricing

Prices are determined algorithmically by the pool's reserve ratios, not by an order book. The price of Token A in terms of Token B is simply Reserve B / Reserve A. This price changes with every trade, creating slippage: larger trades execute at progressively worse rates as they move the ratio away from the pre-trade state.

03

Liquidity Providers (LPs)

Users who deposit an equal value of two assets into the pool to enable trading. In return, they receive LP tokens, which represent their share of the pool and entitle them to a portion of the trading fees. LPs face impermanent loss, a divergence loss that occurs when the price ratio of the deposited assets changes compared to simply holding them.

04

Slippage & Price Impact

Slippage is the difference between the expected price of a trade and the executed price. Price impact measures how much a trade moves the market price within the pool. Both are functions of trade size relative to liquidity; larger trades in smaller pools cause higher slippage. Traders set slippage tolerance to protect against front-running and volatile swings.

05

Fee Structure

A small percentage fee (e.g., 0.01%, 0.3%, 1%) is charged on every swap and is added directly to the liquidity pool reserves. This increases the value of the pool, rewarding Liquidity Providers proportionally to their share. Fees are the primary incentive for LPs, compensating them for capital commitment and impermanent loss risk.

06

Composability & Permissionlessness

CFMMs are permissionless smart contracts; anyone can add liquidity or execute a swap. Their standardized interfaces make them highly composable, acting as primitive building blocks ("money legos") for DeFi. They are integrated into DEX aggregators, lending protocols, and yield strategies, enabling complex financial operations in a single transaction.

common-formulas
MECHANICS

Common CFMM Invariant Formulas

These mathematical formulas define the core trading logic of Constant Function Market Makers, ensuring the product or sum of token reserves remains constant after each swap.

01

Constant Product (x * y = k)

The foundational invariant used by Uniswap V2 and many AMMs. It states that the product of the quantities of two tokens in a pool (x and y) must equal a constant k after any trade. This creates hyperbolic price curves and infinite liquidity depth.

  • Price Impact: Price changes are continuous and non-linear.
  • Impermanent Loss: LPs are exposed to divergence loss when asset prices change.
  • Example: A pool with 100 ETH (x) and 300,000 USDC (y) has k = 30,000,000. Swapping 1 ETH will add to x and subtract from y, recalculating the new price.
02

Constant Sum (x + y = k)

A simpler invariant that maintains a fixed, linear exchange rate (e.g., 1:1). It is used for stablecoin pairs or wrapped asset pools where assets are intended to maintain parity.

  • Zero Slippage: Trades occur at a constant price as long as both assets are in the pool.
  • Risk of Depletion: The pool can be completely drained of one asset if the external market price diverges, requiring external arbitrage to rebalance.
  • Limited Use: Primarily for pegged assets like stablecoin-stablecoin pairs (e.g., USDC/DAI).
03

StableSwap / Curve (χ * D^n + D = χ * A * (Σ x_i) + Π x_i)

A hybrid invariant pioneered by Curve Finance that combines constant sum and constant product. It creates a "flatter" curve within a target price range (for stablecoins) and a steeper curve outside it.

  • Low Slippage for Pegged Assets: Enables efficient trading of similarly priced assets (e.g., USDC, USDT, DAI).
  • Amplification Coefficient (A): A tunable parameter that controls the "flatness" of the curve; a higher A makes it more like constant sum.
  • Dominant for Stables: Captures the majority of stablecoin trading volume due to minimal impermanent loss near peg.
04

Weighted Geometric Mean (Π x_i^w_i = k)

A generalization of the constant product formula used by Balancer. It allows for pools with more than two assets and customizable weightings for each asset.

  • Multi-Asset Pools: Can hold up to 8 tokens in a single pool (e.g., 50% ETH, 30% WBTC, 20% LINK).
  • Custom Weights (w_i): Token weights determine price sensitivity and pool composition; a 90/10 pool behaves very differently than a 50/50 pool.
  • Flexible Indices: Enables the creation of automated, self-balancing token portfolios.
05

Concentrated Liquidity (x * y = L²)

Introduced by Uniswap V3, this reparameterizes the constant product formula to allow liquidity providers to concentrate their capital within custom price ranges.

  • Virtual Reserves: Uses the concept of liquidity (L) and a price range to calculate virtual reserves x and y.
  • Capital Efficiency: LPs can achieve higher fees by providing liquidity where most trading occurs.
  • Active Management: Requires LPs to actively manage their price ranges, shifting the impermanent loss profile.
06

Invariant Properties & Implications

All CFMM invariants share key properties that define their economic behavior and risks.

  • Path Independence: The final state of the pool depends only on the net amount swapped, not the path of intermediate trades.
  • Slippage: The price impact of a trade is a direct function of the invariant and pool depth.
  • Arbitrage: The invariant-determined pool price must be kept in line with external market prices by arbitrageurs, which is the primary mechanism for price discovery.
  • Fee Integration: Trading fees are typically added to the pool's reserves, slowly increasing the constant k and rewarding LPs.
examples
IMPLEMENTATIONS

CFMM Protocol Examples

Constant Function Market Makers (CFMMs) are implemented through various protocols, each with distinct bonding curves, fee structures, and capital efficiency models. These examples showcase the evolution from foundational to specialized designs.

advantages
KEY FEATURES

Advantages of Constant Function Market Makers

Constant Function Market Makers (CFMMs) revolutionized decentralized trading by introducing automated, liquidity-provider-driven exchanges. Their core advantages stem from algorithmic pricing and permissionless participation.

01

Continuous Liquidity

CFMMs provide 24/7 liquidity without relying on traditional order books or market makers. Liquidity is supplied by users who deposit assets into a liquidity pool, creating a permanent on-chain market. This ensures trades can be executed at any time, a critical feature for permissionless, global finance.

  • Key Mechanism: The pool's bonding curve algorithmically determines prices based on the ratio of assets in the reserve.
02

Permissionless & Non-Custodial

Anyone can become a liquidity provider (LP) by depositing assets into a pool, earning a share of the trading fees. This removes gatekeepers and custodians, aligning with core DeFi principles. Traders interact directly with the smart contract, maintaining control of their assets until the moment of swap.

  • Example: Uniswap v2 popularized this model, allowing users to create markets for any ERC-20 token pair.
03

Price Discovery via Algorithm

Prices are determined deterministically by a constant function, most commonly x * y = k (for Uniswap's constant product formula). The price of an asset moves inversely with its available supply in the pool, creating automated market making. This eliminates the need for centralized price feeds for basic operation, though oracles are often used for external information.

04

Capital Efficiency for Swaps

For common, high-volume trading pairs, CFMMs can offer extremely efficient swaps with minimal slippage when pools are deep. The model aggregates liquidity into a single shared reserve, which can be more efficient than fragmented order books for long-tail assets.

  • Trade-off: This efficiency is balanced against impermanent loss risk for LPs during high volatility.
05

Composability & Integration

CFMM smart contracts are public and programmable, making them fundamental DeFi primitives. Their prices and liquidity can be seamlessly integrated into other protocols for lending, derivatives, and automated strategies. This composability is a cornerstone of the DeFi "money Lego" ecosystem.

06

Mitigating Front-Running

While not immune, CFMM design can mitigate certain market manipulation. Transactions are processed in the block they are included, reducing traditional front-running opportunities. Advanced mechanisms like time-weighted average prices (TWAPs) and chain-specific order flow (e.g., Flashbots on Ethereum) provide further protection against Maximal Extractable Value (MEV).

limitations-considerations
CONSTANT FUNCTION MARKET MAKER

Limitations & Considerations

While CFMMs power the majority of DeFi liquidity, their automated design introduces specific constraints and risks that users and developers must understand.

01

Impermanent Loss

The primary risk for liquidity providers (LPs) is impermanent loss (divergence loss), which occurs when the price of deposited assets changes relative to each other after deposit. The AMM automatically rebalances the pool, selling the appreciating asset and buying the depreciating one, resulting in a lower dollar value than simply holding the assets. This loss becomes permanent upon withdrawal.

  • Magnitude: Loss increases with the size of the price divergence.
  • Mitigation: LPs rely on trading fees to offset this risk, which requires high volume.
02

Slippage & Price Impact

CFMMs do not have an order book; price is a function of the pool's reserves. Large trades cause significant price impact, moving the price unfavorably for the trader. Slippage is the difference between the expected and executed price.

  • Consequence: Makes large trades expensive and inefficient, creating an upper bound on trade size.
  • Solution: Traders use slippage tolerance settings, and protocols employ batch auctions or route trades across multiple pools.
03

Oracle Reliance & Manipulation

Many DeFi protocols use CFMM pool prices as oracles for asset values. However, these are spot oracles vulnerable to manipulation via flash loans or large, one-sided trades.

  • Risk: A manipulated price can trigger faulty liquidations or incorrect loan valuations in lending protocols.
  • Defense: Advanced oracles use time-weighted average prices (TWAPs) calculated from CFMM reserves over a period, making manipulation cost-prohibitive.
04

Capital Inefficiency

CFMMs require large amounts of capital to be locked (Total Value Locked - TVL) to facilitate trading with low slippage. This capital is spread across the entire price range (0, ∞), much of which is rarely used.

  • Problem: For stablecoin pairs (e.g., USDC/USDT), liquidity is only needed near the 1:1 price point.
  • Innovation: Concentrated Liquidity (e.g., Uniswap v3) allows LPs to allocate capital to specific price ranges, dramatically improving capital efficiency.
05

Composability & Systemic Risk

CFMMs are money legos, freely composable within DeFi. While powerful, this creates systemic risk.

  • Example: A flash loan can drain a vulnerable lending protocol, use the funds to manipulate a CFMM's price oracle, and trigger cascading liquidations across interconnected systems.
  • Consideration: Security depends on the weakest link in the composed transaction.
06

Multi-Asset Pool Limitations

While the Constant Product Formula (x*y=k) works for two assets, generalized CFMMs for 3+ asset pools (e.g., Balancer) use different invariant functions.

  • Challenge: More complex math can lead to unexpected slippage surfaces and less intuitive LP positions.
  • Trade-off: Enables efficient index-like pools but requires deeper analysis for LPs to understand their risk exposure across multiple correlated or uncorrelated assets.
CONSTANT FUNCTION MARKET MAKER

Frequently Asked Questions (FAQ)

Essential questions and answers about the automated market maker (AMM) model that powers decentralized exchanges like Uniswap.

A Constant Function Market Maker (CFMM) is a type of Automated Market Maker (AMM) that algorithmically sets and adjusts asset prices based on a mathematical formula, specifically a constant product function like x * y = k. This model, pioneered by Uniswap, allows for permissionless, non-custodial trading by using liquidity pools instead of traditional order books. The invariant k remains constant for a trade, meaning the product of the quantities of two assets in a pool (x and y) must stay the same before and after a swap, which automatically determines the exchange rate and imposes a price impact based on the trade size relative to the pool's liquidity.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team