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 Product Market Maker (CPMM)

An Automated Market Maker (AMM) algorithm that maintains a constant product of the reserves of two assets in a liquidity pool, following the invariant x*y=k.
Chainscore Β© 2026
definition
DEFINITION

What is a Constant Product Market Maker (CPMM)?

A Constant Product Market Maker (CPMM) is the foundational automated market maker (AMM) model that powers decentralized exchanges like Uniswap, using a mathematical formula to set asset prices algorithmically.

A Constant Product Market Maker (CPMM) is an automated market maker (AMM) model that determines the price of two assets in a liquidity pool by maintaining a constant product of their quantities. The core formula is x * y = k, where x and y represent the reserves of two tokens in the pool, and k is a constant. This invariant ensures that any trade increases the supply of the purchased asset and decreases the supply of the sold asset, with the price shifting along a bonding curve to keep k unchanged. This mechanism allows for permissionless, continuous trading without order books.

The CPMM model introduces the critical concept of liquidity providers (LPs) who deposit equal values of both assets into the pool to enable trading, earning fees from swaps in return. A key characteristic is impermanent loss, which occurs when the price ratio of the deposited assets changes compared to when they were deposited; LPs may suffer a loss relative to simply holding the assets, though fee revenue can offset this. The simplicity and predictability of the x * y = k formula make CPMMs highly composable and secure, forming the backbone of decentralized finance (DeFi).

While foundational, the basic CPMM has limitations, notably high slippage for large trades relative to pool size and capital inefficiency. This has led to innovations like concentrated liquidity, used by Uniswap V3, where LPs can allocate capital within specific price ranges to increase capital efficiency. Other AMM models, such as Constant Sum Market Makers (CSMM) for stablecoin pairs or Hybrid Function Market Makers, have evolved to address different use cases, but the CPMM remains the most widely adopted and influential design in the DeFi ecosystem.

how-it-works
MECHANISM

How a Constant Product Market Maker Works

An explanation of the core mathematical model and automated pricing logic that powers decentralized exchanges like Uniswap.

A Constant Product Market Maker (CPMM) is an automated liquidity protocol that uses the formula x * y = k to determine asset prices, where x and y represent the reserves of two tokens in a pool, and k is a constant product. This invariant ensures that the product of the two reserve quantities remains unchanged by any trade, creating a predictable, algorithmic relationship between price and available liquidity. The price of an asset is simply the ratio of the two reserves, and as one reserve diminishes through purchases, its price increases non-linearly to maintain the constant k.

The core mechanism creates slippage and price impact. When a trader swaps a large amount of Token A for Token B, they significantly reduce the reserve of Token B and increase the reserve of Token A. To keep k constant, each subsequent unit of Token B becomes exponentially more expensive in terms of Token A. This built-in price curve acts as a liquidity fee, rewarding liquidity providers (LPs) who supply both assets to the pool. The depth of the liquidity pool, determined by the size of k, directly influences the slippage for a given trade size.

This model enables permissionless and non-custodial trading without order books. Anyone can create a market by depositing an equivalent value of two tokens, seeding the initial x and y. The CPMM automatically quotes prices and executes swaps via smart contracts. Its simplicity and robustness make it the foundational model for Automated Market Makers (AMMs) like Uniswap V2 and many others. However, it can lead to impermanent loss for LPs when the price ratio of the deposited assets diverges significantly from the ratio at the time of deposit.

Developers and analysts must understand that the x * y = k invariant defines a specific bonding curve. The marginal price is given by the derivative dy/dx = -y/x. This relationship means liquidity is spread across all prices between zero and infinity, ensuring the pool never runs "dry" of either asset, though prices can become astronomically high. This is a key differentiator from order book systems, which can have gaps in liquidity.

In practice, most CPMM implementations, such as Uniswap, incorporate a protocol fee (e.g., 0.30%) that is deducted from each trade. This fee is added to the liquidity reserves, incrementally increasing the constant k and thus the value of the LP shares. The fee mitigates impermanent loss for providers and funds protocol development. The deterministic, on-chain nature of this system allows for seamless integration into other DeFi applications for arbitrage, lending, and leveraged trading.

key-features
MECHANICAL PRINCIPLES

Key Features of CPMMs

Constant Product Market Makers (CPMMs) are a foundational DeFi primitive that enable permissionless, automated trading by algorithmically setting prices based on a simple mathematical invariant.

01

The Constant Product Invariant

The core mechanism of a CPMM is the formula x * y = k, where x and y are the reserves of two assets in a liquidity pool, and k is a constant. This invariant ensures that the product of the reserves remains unchanged after any trade, which automatically determines the price. For example, if a trader buys asset x, its reserve decreases, causing its price to increase relative to y to maintain the constant k.

02

Automated Price Discovery

Prices are not set by an order book but are derived from the ratio of the two reserves in the pool. The spot price of asset X in terms of Y is given by Price_X = y / x. This price changes with every trade, creating slippage: larger trades execute at progressively worse average prices as they move the ratio, protecting liquidity providers from large, imbalanced swaps.

03

Impermanent Loss (Divergence Loss)

A key risk for liquidity providers (LPs). It occurs when the price of the deposited assets changes compared to when they were supplied. If the price ratio diverges, LPs would have been better off simply holding the assets. The loss is "impermanent" because it is only realized if the LP withdraws during the price divergence; it can reverse if prices return to the original ratio.

04

Liquidity Provision & Fees

Anyone can become a market maker by depositing an equal value of two tokens into a pool, receiving liquidity provider tokens (LP tokens) in return. Traders pay a fee (e.g., 0.3%) on each swap, which is distributed pro-rata to all LPs. This provides a passive income stream, compensating for the risk of impermanent loss.

05

Concentrated Liquidity

An innovation built on the CPMM model (e.g., Uniswap V3). Instead of distributing liquidity across the entire price curve from 0 to ∞, LPs can concentrate their capital within a specific price range. This dramatically increases capital efficiency, allowing for deeper liquidity and lower slippage around the current market price, but requires active management of the chosen range.

06

Composability & Permissionlessness

CPMM pools are open, on-chain smart contracts. This allows any other application (like lending protocols, aggregators, or DAOs) to interact with them directly without permission. This composability is a cornerstone of DeFi, enabling complex financial products to be built by stacking these simple, reliable primitives.

visual-explainer
CONSTANT PRODUCT MARKET MAKER (CPMM)

Visualizing the x*y=k Curve

A graphical and mathematical exploration of the foundational invariant that powers automated liquidity pools in decentralized exchanges.

The x*y=k curve is the mathematical invariant at the core of a Constant Product Market Maker (CPMM), where x and y represent the reserves of two assets in a liquidity pool, and k is a constant product. This relationship dictates that for any trade, the product of the two reserve amounts must remain unchanged (k). When visualized on a Cartesian plane, this equation produces a rectangular hyperbola, a smooth, concave curve that illustrates the fundamental trade-off between the two assets: as the quantity of one asset (x) increases, the quantity of the other (y) must decrease non-linearly to keep k constant.

The shape of this curve directly models price impact and slippage. The price of asset X in terms of Y at any point is given by the negative slope of the tangent line to the curve, which is dy/dx = -y/x. As you move along the curve, this slope changes. A large purchase of X significantly depletes its reserve, moving the price point far up the steep part of the curve, resulting in higher slippage for the trader. This non-linear pricing ensures the pool never runs out of liquidity for either asset, though prices can become impractical at extreme reserve imbalances.

This model, first popularized by Uniswap V1 and V2, provides several key properties: permanent liquidity (the pool always quotes a price), simplicity (easy to compute and audit), and path independence (price depends only on the current reserves, not trade history). However, it also leads to impermanent loss for liquidity providers when prices diverge significantly from the deposit point, as the pool automatically rebalances against the market trend. The curve's elegance lies in its ability to facilitate trustless trading without order books, using a deterministic, algorithmic pricing rule.

examples
CONSTANT PRODUCT MARKET MAKER

Protocol Examples & Implementations

The Constant Product Market Maker (CPMM) is a foundational DeFi primitive. This section explores its canonical implementations, key variations, and the core mechanisms that power decentralized exchanges.

04

The Core Invariant: x * y = k

The invariant k is the product of the reserves of two assets (X and Y) in a pool and must remain constant before and after any trade. This mechanic determines pricing and slippage.

  • Pricing: The spot price is the ratio of the reserves, Price_X = y / x.
  • Slippage: The executed price diverges from the spot price as trade size increases relative to liquidity, governed by the invariant.
  • Impermanent Loss: If the external market price ratio changes, LP holdings are worth less than simply holding the assets, a direct result of rebalancing to maintain k.
06

Automated Portfolio Management

CPMMs inherently perform passive portfolio rebalancing. Every trade moves the pool's price and composition, automatically adjusting the LP's position.

  • When asset X appreciates, arbitrageurs buy it from the pool, reducing X reserves and increasing Y reserves.
  • This sells the appreciated asset (X) and buys the depreciated asset (Y), rebalancing the portfolio toward the underperforming asset.
  • LPs are therefore always selling the winning asset and buying the losing asset, a counter-intuitive but mechanized strategy.
COMPARISON

CPMM vs. Other AMM Models

A technical comparison of the core mechanisms, liquidity characteristics, and trade-offs of different Automated Market Maker designs.

Feature / MechanismConstant Product (CPMM)Constant Sum (CSMM)Concentrated Liquidity (CLMM)Hybrid / Curve (Stableswap)

Pricing Function

x * y = k

x + y = k

x * y = k (within a price range)

Combined CPMM & CSMM invariant

Primary Use Case

General-purpose, volatile assets

Perfectly pegged assets (theoretical)

Capital efficiency for correlated pairs

Stablecoin & similarly priced assets

Impermanent Loss Profile

High for volatile pairs

None (if peg holds)

Customizable by LP

Very low for tight pegs

Liquidity Distribution

Uniform across all prices

Concentrated at a single price

Concentrated within a custom price range

Extremely concentrated near 1:1 peg

Capital Efficiency

Low

High (for target price)

High

Very High (for target price)

Price Slippage Function

Increases with trade size

Constant (zero slippage)

Low within range, high outside

Very low near peg, increases sharply

Example Implementation

Uniswap v2

Theoretical ideal

Uniswap v3, PancakeSwap v3

Curve Finance

security-considerations
CONSTANT PRODUCT MARKET MAKER (CPMM)

Security Considerations & Risks

While CPMMs provide a foundational mechanism for decentralized trading, their design introduces specific security and financial risks that users and developers must understand.

01

Impermanent Loss

The primary financial risk for liquidity providers (LPs). It occurs when the price of deposited assets changes compared to when they were deposited. The CPMM's constant product formula automatically rebalances the pool, causing LPs to end up with more of the depreciating asset and less of the appreciating one. Losses are 'impermanent' only if prices return to their original ratio.

02

Smart Contract Risk

The CPMM logic is encoded in immutable smart contracts, which are vulnerable to bugs and exploits. Historical examples include:

  • Reentrancy attacks (e.g., early DEX exploits)
  • Logic errors in fee calculations or pool initialization
  • Governance attacks on upgradeable contracts LPs and traders are exposed to the risk of total fund loss if the underlying contract is compromised.
03

Oracle Manipulation & MEV

CPMM prices can be manipulated, affecting integrated systems:

  • On-chain oracles that read DEX prices can be skewed by a large, flash-loan-fueled trade, leading to faulty price feeds for lending protocols.
  • Maximal Extractable Value (MEV) bots exploit this by sandwiching user transactions, causing front-running and worse execution prices. This creates systemic risk beyond the individual pool.
04

Concentrated Liquidity & Tick Math

Advanced CPMMs (e.g., Uniswap v3) allow LPs to concentrate capital within specific price ranges (ticks). This introduces new risks:

  • Liquidity fragmentation can lead to higher slippage if price moves outside the set range.
  • Increased complexity in tick math and fee accounting raises the potential for subtle calculation errors.
  • Active management is required, shifting risk from passive to operational.
05

Composability & Dependency Risk

CPMMs are foundational DeFi 'money legos'. A failure or pause in a major DEX (like Uniswap) can cascade:

  • Lending protocols may become unable to liquidate positions.
  • Derivative and yield platforms that rely on DEX prices may malfunction.
  • Bridge and cross-chain protocols often use DEXs for destination-side liquidity, creating interdependency risks.
06

Economic & Governance Attacks

Protocols with governance tokens face additional vectors:

  • Tokenomics attacks: A malicious actor could acquire enough governance tokens to pass proposals that drain treasury funds or manipulate fees.
  • Vote manipulation through bribery or exploiting delegation mechanisms.
  • Fee switch risks: The ability for governance to turn on protocol fees could disincentivize LPs if not calibrated correctly.
evolution
THE CPMM REVOLUTION

Evolution and Impact

The Constant Product Market Maker (CPMM) is the foundational automated market maker (AMM) model that powers decentralized exchanges like Uniswap, enabling permissionless token swaps without order books.

A Constant Product Market Maker (CPMM) is an automated market maker (AMM) model that determines asset prices algorithmically based on the invariant x * y = k, where x and y represent the reserves of two tokens in a liquidity pool, and k is a constant product. This formula ensures that the product of the two reserves remains constant after every trade, creating a predictable and continuous price curve. The model was popularized by Uniswap V1 and V2, introducing the concept of liquidity providers (LPs) who deposit paired assets to earn fees, fundamentally shifting decentralized finance (DeFi) from order-book to liquidity-pool-based trading.

The CPMM's core mechanism, while elegantly simple, introduces the critical concept of impermanent loss. This occurs when the price of the pooled assets diverges significantly from the price at deposit, as the AMM automatically rebalances the pool to maintain the constant product. The model's pricing is most efficient near the current reserve ratio, but slippage increases for larger trades as they move the price along the hyperbolic curve. To mitigate this, concentrated liquidity models (like Uniswap V3) were later developed, allowing LPs to provide capital within specific price ranges, dramatically improving capital efficiency.

The impact of the CPMM extends far beyond simple swaps. It enabled the composability of DeFi by providing a universal, on-chain price oracle (through time-weighted average prices, or TWAPs) and a foundational primitive for other protocols. Its permissionless nature allowed for the explosive growth of token launches and long-tail asset markets that would be illiquid on traditional exchanges. The model's reliance on liquidity incentives also pioneered yield farming and liquidity mining as core DeFi growth mechanisms, creating new economic models for bootstrapping networks.

CONSTANT PRODUCT MARKET MAKER (CPMM)

Frequently Asked Questions (FAQ)

Essential questions and answers about the foundational Automated Market Maker (AMM) model that powers decentralized exchanges like Uniswap.

A Constant Product Market Maker (CPMM) is a type of Automated Market Maker (AMM) that uses the mathematical formula x * y = k to determine asset prices and facilitate trades without order books. In this formula, x and y represent the reserves of two assets in a liquidity pool, and k is a constant product that must remain unchanged after any trade. The mechanism works by increasing the supply of the asset being sold and decreasing the supply of the asset being bought, which automatically adjusts the price based on the new ratio of reserves. This creates slippage, where larger trades execute at progressively worse rates. The model ensures the pool never runs out of liquidity, as the price of an asset approaches infinity as its reserve nears zero.

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
Constant Product Market Maker (CPMM) | Blockchain Glossary | ChainScore Glossary