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

AMM Invariant

An AMM invariant is a mathematical function, such as the constant product formula x*y=k, that defines the relationship between the reserves of assets in a liquidity pool and must remain constant during trades, governing price discovery and slippage.
Chainscore © 2026
definition
DEFINITION

What is an AMM Invariant?

The mathematical constant that defines the relationship between asset reserves in an Automated Market Maker (AMM) pool.

An AMM invariant is the constant-value mathematical function that governs the trading logic of an Automated Market Maker (AMM). The most famous example is the constant product formula, x * y = k, used by protocols like Uniswap V2, where x and y represent the reserves of two tokens in a pool and k is the invariant. This formula ensures that the product of the reserves remains constant before and after any trade, which automatically determines the price of an asset based on the ratio of the two reserves. The invariant is the core rule that enables permissionless, algorithmic trading without order books.

The specific form of the invariant defines the AMM's bonding curve and its economic properties. While the constant product (x * y = k) creates a hyperbolic curve that provides infinite liquidity, other models use different invariants. For example, a constant sum invariant (x + y = k) creates a stable, fixed-price curve, while a Stableswap invariant (like Curve's) combines multiple functions to create a flatter curve within a price range for stablecoin pairs. The choice of invariant directly impacts price impact, impermanent loss for liquidity providers, and the pool's efficiency for specific asset types.

Maintaining the invariant is the fundamental constraint for every swap. When a trader deposits Δx tokens to receive Δy, the AMM smart contract calculates the required output such that (x + Δx) * (y - Δy) = k. This calculation, performed on-chain, yields the new reserve amounts and the resulting spot price. The invariant also protects the pool from being drained; as the reserve of one token approaches zero, the price of the remaining token approaches infinity, making complete depletion economically impossible under normal market conditions.

Beyond the classic two-asset pool, invariants can be generalized for multi-asset pools. For instance, a Balancer pool with n tokens might use the constant mean invariant, x1^w1 * x2^w2 * ... * xn^wn = k, where each asset has a customizable weight (w). This allows for complex, multi-token liquidity pools with tailored risk and exposure profiles. The invariant remains the unifying principle: it is the immutable rule that defines all possible states of the pool's reserves and ensures the system remains solvent and functional.

Understanding the invariant is crucial for liquidity providers (LPs) and traders. LPs deposit assets in a ratio that satisfies the current invariant, minting LP tokens representing their share of the constant k. Traders must model how their swaps will change the reserve ratio and thus the price, a calculation derived directly from the invariant's formula. In essence, the AMM invariant is the foundational algorithm that replaces the traditional market maker, enabling decentralized, predictable, and composable financial infrastructure.

how-it-works
MECHANICS

How the AMM Invariant Works

An explanation of the mathematical constant that governs liquidity and pricing in automated market makers.

An AMM invariant is a mathematical function, typically a constant product, that defines the relationship between the reserves of two or more assets in a liquidity pool, ensuring that the product of their quantities remains unchanged by trades. The most famous example is the Constant Product Market Maker (CPMM) formula, x * y = k, where x and y represent the reserve amounts of two tokens and k is the invariant constant. This simple rule autonomously determines the price of each asset based on the ratio of the reserves, creating a predictable and automated pricing mechanism without the need for traditional order books.

The invariant's constancy is what enables the core AMM function of automated price discovery. When a trader buys asset x from the pool, its reserve decreases. To keep k constant, the reserve of asset y must increase proportionally, which from the trader's perspective is the price paid. This results in the characteristic price slippage: larger trades cause greater movement along the bonding curve, executing at progressively worse rates. The invariant ensures the pool never runs out of liquidity, as the price of an asset approaches infinity as its reserve approaches zero.

Beyond the basic x * y = k model, other invariant functions exist for different purposes. The StableSwap invariant (e.g., used by Curve Finance) is designed for pegged assets like stablecoins, creating a flatter curve within a certain price range to minimize slippage for like-valued assets. Concentrated Liquidity models, as seen in Uniswap V3, allow liquidity providers to set a custom price range, effectively making the invariant k active only within that specific interval, dramatically increasing capital efficiency for the same level of liquidity.

key-features
MECHANICAL CORE

Key Features of the AMM Invariant

The invariant is the mathematical rule that defines the relationship between token reserves in an Automated Market Maker (AMM) pool, ensuring liquidity and determining prices algorithmically.

01

Constant Product Formula (x * y = k)

The most common AMM invariant, used by protocols like Uniswap V2. It states that the product of the quantities of two tokens in a pool (x and y) must remain constant (k). This creates a hyperbolic bonding curve where price changes are continuous and liquidity is theoretically infinite.

  • Price is the slope of the curve at any point.
  • Impermanent Loss occurs because the formula rebalances reserves as trades execute.
02

StableSwap Invariant (Curve Finance)

A hybrid invariant designed for trading pegged assets (e.g., stablecoins). It combines the constant product formula with a constant sum formula (x + y = k) to create a flatter curve within a defined price range.

  • Low Slippage: Enables large trades with minimal price impact for correlated assets.
  • Concentrated Liquidity: The invariant allows liquidity providers to focus capital where it's most effective.
03

Concentrated Liquidity (Uniswap V3)

An evolution where liquidity providers can set custom price ranges for their capital, making the invariant active only within those bounds. This increases capital efficiency.

  • Virtual Reserves: The invariant x * y = k is calculated using virtual reserves, not the real token amounts in the pool.
  • Tick System: Prices are discretized into ticks, each with its own liquidity depth and local invariant state.
04

Fee Mechanism Integration

Transaction fees are integrated into the invariant's operation. For a constant product pool, fees are typically taken in the incoming asset, which slightly increases the constant k after a trade.

  • Protocol Fee: A portion may be directed to governance or treasury.
  • Dynamic k: The invariant's constant grows over time as fees accumulate, rewarding liquidity providers.
05

Oracle Functionality

AMM invariants provide a built-in price oracle. The instantaneous price is derived directly from the reserve ratio. For manipulation resistance, protocols like Uniswap V2 use the time-weighted average price (TWAP) calculated from cumulative price data stored by the invariant's state.

  • On-Chain Data: The invariant's state is the single source of truth for these price feeds.
06

Generalized Invariant (Balancer)

Extends the concept to pools with N tokens and customizable weights. The invariant is ∏ (balance_i ^ weight_i) = k (the product of each reserve raised to its weight).

  • Weighted Pools: Allows for pools with non-50/50 distributions (e.g., 80/20).
  • Multi-Asset Exposure: A single pool can hold many tokens, with the invariant governing all pairwise relationships.
common-invariant-models
AMM INVARIANT

Common Invariant Models

An Automated Market Maker's (AMM) invariant is the mathematical constant that defines the relationship between the reserves of two or more assets in a liquidity pool, enabling permissionless trading without order books.

01

Constant Product (x*y=k)

The foundational AMM model where the product of the quantities of two tokens in a pool must remain constant. This creates a hyperbolic bonding curve, meaning price impact increases as liquidity is depleted.

  • Key Feature: Price = Reserve Y / Reserve X.
  • Example: Uniswap V2 and many early AMMs use this model.
  • Trade-off: Provides infinite liquidity but can suffer from high slippage for large trades.
02

Constant Sum (x + y = k)

A model where the sum of the reserves remains constant, resulting in a fixed price (e.g., 1:1) between the two assets. It is only viable for pegged assets like stablecoins.

  • Key Feature: Zero slippage within the pool's reserves.
  • Limitation: Prone to complete depletion of one asset if the external market price diverges, requiring frequent rebalancing.
03

StableSwap / Curve (x*y=k & x+y=k Hybrid)

A hybrid invariant developed by Curve Finance that combines the constant product and constant sum models. It creates a flatter curve within a price range (e.g., $0.99-$1.01 for stablecoins), offering extremely low slippage for correlated assets.

  • Key Feature: Low slippage for trades between pegged assets.
  • Mechanism: Dynamically weights the two invariants based on pool balance.
04

Concentrated Liquidity (Uniswap V3)

An evolution where liquidity providers (LPs) can allocate capital within a custom price range, rather than across the entire curve (0, ∞). This creates multiple, individualized constant product curves.

  • Key Feature: Capital efficiency is dramatically increased.
  • Invariant: The core x*y=k formula is maintained within each discrete price tick.
05

Weighted Pools (Balancer)

A generalized constant product model for pools with two or more assets and uneven weightings. The invariant is the product of each token reserve raised to its weight, which must remain constant.

  • Formula: ∏ (Balance_token ^ Weight_token) = k.
  • Use Case: Allows for pools with assets like 80% ETH / 20% USDC, enabling custom portfolio exposure and trading pairs.
06

Oracle-Based Invariants

Models that incorporate external price data (oracles) to adjust the pool's internal pricing curve, reducing arbitrage lag and loss-versus-rebalancing for LPs.

  • Purpose: Mitigate impermanent loss by aligning the pool price more closely with the broader market.
  • Example: DEXs like DODO use a Proactive Market Maker (PMM) model that shifts the curve based on an oracle price.
price-impact-slippage
AMM MECHANICS

Price Impact & Slippage

An explanation of the core mechanics governing trade execution and pricing in Automated Market Makers (AMMs), focusing on the relationship between trade size, liquidity depth, and the resulting execution price.

Price impact is the measurable change in an asset's price within an Automated Market Maker (AMM) pool caused by executing a trade, directly resulting from the AMM's constant function market maker (CFMM) invariant. Unlike order book markets where price is set by discrete bids and asks, an AMM's price is a continuous function of its reserve ratios; a large trade significantly shifts these reserves, moving the price along the bonding curve. This is not a fee but an inherent cost of trading against a liquidity pool, calculated as the difference between the mid-price before the trade and the effective execution price received.

Slippage is the difference between the expected price of a trade and the price at which it is actually executed, encompassing both price impact and broader market movements. In the context of AMMs, traders set a slippage tolerance (e.g., 0.5%) as a maximum acceptable price deviation; if the execution price, including impact, exceeds this tolerance, the transaction will revert. This protects users from front-running and extreme volatility. Slippage can be positive (getting a better price than expected) or, more commonly, negative (getting a worse price).

The fundamental driver of both phenomena is the AMM invariant, most commonly the constant product formula x * y = k. This mathematical rule dictates that the product of the quantities of two assets in a pool (x and y) must remain constant (k) before and after a trade. To withdraw Δy tokens, a trader must deposit Δx tokens such that (x + Δx) * (y - Δy) = k. The larger the Δy relative to y, the more Δx must increase non-linearly, resulting in higher price impact. The marginal price changes with each infinitesimal unit traded.

Liquidity depth is the primary factor mitigating price impact. A pool with a large total value locked (TVL) has deeper reserves, meaning a trade of a given size represents a smaller percentage of the pool, causing less reserve ratio distortion. Conversely, trading in a shallow pool leads to severe impact. Price impact is therefore always expressed as a percentage and can be estimated before trading: Price Impact ≈ (Trade Size / Liquidity Depth). This is why major trades are often split across multiple pools or protocols using DEX aggregators, which perform route optimization to minimize overall impact and slippage.

Understanding these mechanics is crucial for developers building on AMMs, analysts modeling trade costs, and users optimizing their DeFi strategies. Advanced AMM designs like concentrated liquidity (Uniswap v3) allow liquidity providers to allocate capital within specific price ranges, creating deeper liquidity around the current price and reducing impact for common trades, though this introduces more complex management. Ultimately, price impact and slippage represent the fundamental trade-off in AMMs: the cost of permissionless, automated liquidity versus the precision of traditional order books.

ecosystem-usage
AMM INVARIANT

Protocols & Ecosystem Usage

The AMM invariant is the mathematical rule that defines the relationship between the reserves in a liquidity pool, determining how prices are set and trades are executed without an order book.

01

Constant Product Formula (x*y=k)

The most common invariant, used by Uniswap v2 and others. It states that the product of the quantities of two tokens in a pool (x * y) must remain constant (k) before and after a trade. This creates a hyperbolic bonding curve where price changes are continuous and liquidity is always available, but slippage increases with trade size. The spot price of Asset A in terms of Asset B is given by Price_A = y / x.

02

Stableswap Invariant (Curve Finance)

A hybrid invariant designed for low-slippage swaps between pegged assets like stablecoins. It combines the constant product formula with a constant sum formula (x + y = k), creating a flatter curve within a defined price range. This allows for extremely efficient trades near the peg, while the constant product component ensures liquidity and acts as a fallback if the price deviates significantly.

03

Concentrated Liquidity (Uniswap v3)

An evolution where liquidity providers (LPs) can allocate capital to a specific price range, rather than the full (0, ∞) curve. The invariant becomes x * y = L², where L represents liquidity. This increases capital efficiency for LPs and reduces slippage for traders within the active range. The pool's overall curve is the aggregation of all individual, segmented liquidity positions.

04

Invariant & Impermanent Loss

The invariant is the direct cause of impermanent loss (divergence loss). When the market price of the pooled assets changes, the AMM's rebalancing mechanism—enforced by the invariant—causes the pool's value to diverge from simply holding the assets. For a constant product pool, the loss is greater the larger the price movement. This is the fundamental risk-reward trade-off for liquidity providers.

05

Beyond Two-Asset Pools

Invariants can be generalized for pools with more than two assets. For example, a Balancer pool with n tokens and weights w_i uses the invariant: ∏ (balance_i)^{w_i} = k. This allows for customizable, multi-token pools where the invariant ensures the weighted geometric mean of the balances remains constant, enabling complex portfolio-like liquidity provision.

06

Oracle Prices Derived from Invariants

AMM reserves, governed by their invariant, provide a decentralized source of price data. The time-weighted average price (TWAP) oracle, pioneered by Uniswap, reads cumulative price data from the pool state over an interval. This mitigates manipulation, as attacking the price requires moving the pool's reserves against the invariant, which becomes prohibitively expensive over longer time windows.

AMM INVARIANT

Technical Details & Mechanics

An Automated Market Maker (AMM) invariant is a mathematical formula that defines the relationship between the quantities of assets in a liquidity pool, ensuring that the product or sum of these quantities remains constant during trades. This core mechanism enables decentralized, algorithmic price discovery without order books.

An AMM invariant is a constant mathematical function that governs the relationship between the reserves of two or more assets in a liquidity pool, determining the price at which trades are executed. The most common is the Constant Product Formula (x * y = k), used by protocols like Uniswap V2. When a trader swaps asset X for asset Y, the quantity of X in the pool increases, and the quantity of Y decreases, but the product (k) of their reserves must remain constant. This relationship automatically adjusts the price based on the ratio of the reserves, creating slippage as trade size increases relative to the pool's liquidity.

security-considerations
AMM INVARIANT

Security & Economic Considerations

The AMM invariant is the mathematical formula that defines the relationship between asset reserves in a liquidity pool, governing price discovery and impermanent loss.

01

Constant Product Formula (x*y=k)

The most common AMM invariant, used by Uniswap V2 and others. It states that the product of the quantities of two tokens in a pool (x and y) must remain constant (k).

  • Price is determined by the ratio of the reserves: Price of X = y / x.
  • Slippage increases with trade size because each trade moves the price along a hyperbolic curve.
  • This model provides infinite liquidity but bounded reserves, ensuring a price for any trade size.
02

Impermanent Loss (Divergence Loss)

The opportunity cost liquidity providers (LPs) face when the price of deposited assets changes compared to simply holding them. It is a direct consequence of the invariant's rebalancing mechanism.

  • Mechanism: When the external market price diverges, arbitrageurs trade against the pool to re-align it, changing the reserve ratios. LPs end up with more of the depreciating asset and less of the appreciating one.
  • Maximized during high volatility; it is 'impermanent' only if prices return to their original ratio.
03

StableSwap Invariants (Curve Finance)

A hybrid invariant designed for stablecoin pairs (e.g., USDC/DAI) that approximates a constant sum formula (x + y = k) near parity but reverts to a constant product curve at extreme prices.

  • Benefit: Drastically reduces slippage and impermanent loss for pegged assets within a defined 'amplification coefficient' range.
  • Trade-off: Higher complexity and vulnerability if the peg breaks, as the pool can be drained along the flatter curve.
04

Oracle Manipulation Risks

AMM prices are often used as on-chain oracles. The invariant's continuous pricing can be exploited if an attacker can move the pool price significantly within a single transaction.

  • Flash Loan Attack: A borrower uses a flash loan to perform a large, imbalanced swap, skewing the price, triggering downstream contracts (like lending protocols) at the manipulated rate, and then arbitraging the price back.
  • Mitigations: Use time-weighted average prices (TWAPs), as implemented by Uniswap V3 oracles, which are costly to manipulate over longer time intervals.
05

Concentrated Liquidity (Uniswap V3)

An evolution where LPs can allocate capital within custom price ranges, making the invariant active only within those bounds.

  • Mechanism: The global x*y=k curve is replaced by many virtual curves over segmented price intervals. Liquidity becomes a 'liquidity density' function.
  • Impact: Greatly increases capital efficiency for LPs who accurately predict price ranges, but introduces more active management and the risk of liquidity being 'out of range' and earning no fees.
06

Invariant as a Security Guarantee

The invariant is a core smart contract security property; its immutability ensures the pool cannot be drained through standard swaps.

  • Verification: Protocol audits rigorously check that all state-changing functions (swaps, adds, removes) preserve the invariant.
  • Rounding Direction: A critical implementation detail. Swaps must always round in favor of the pool (increase k slightly) to prevent gradual reserve depletion from many small trades.
  • A broken invariant represents a critical failure, potentially allowing infinite minting or draining of assets.
AMM INVARIANT

Common Misconceptions

The Automated Market Maker (AMM) invariant is a core mathematical formula that governs liquidity pools, yet its function is often misunderstood. This section clarifies how it truly works, dispelling myths about impermanent loss, price discovery, and pool behavior.

An AMM invariant is a constant mathematical function that defines the relationship between the quantities of assets in a liquidity pool. The most common is the Constant Product Market Maker (CPMM) formula, x * y = k, where x and y are the reserves of two tokens and k is a constant. This formula ensures that the product of the reserves remains unchanged by trades, automatically determining the price as the ratio of the reserves. It is not a price oracle but a bonding curve that provides continuous liquidity, with prices shifting along the curve as trades occur.

AMM INVARIANT

Frequently Asked Questions (FAQ)

Common questions about the core mathematical rule that governs automated market makers (AMMs) and determines asset pricing.

An Automated Market Maker (AMM) invariant is a constant mathematical function that defines the relationship between the quantities of assets in a liquidity pool, determining their price and ensuring the pool's value is preserved. The most common is the constant product formula, x * y = k, where x and y are the reserves of two tokens and k is a constant. This formula ensures that for any trade, the product of the reserves must remain equal to k. As a user sells token x to the pool, the reserve of x increases, forcing the reserve of y to decrease to maintain the constant product, which defines the new price. This mechanism allows for permissionless, algorithmic price discovery without order books.

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
AMM Invariant: Definition & Function in DeFi | ChainScore Glossary