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

Stableswap Invariant

A hybrid Automated Market Maker (AMM) curve that combines a constant sum formula for low slippage near parity with a constant product formula to manage risk at extreme prices.
Chainscore Β© 2026
definition
DEFINITION

What is the Stableswap Invariant?

A mathematical formula designed for automated market makers (AMMs) to facilitate efficient trading between assets intended to maintain a stable price ratio, such as stablecoins.

The Stableswap Invariant is a specialized bonding curve formula, most famously implemented in Curve Finance, that combines elements of a constant sum and a constant product market maker. Unlike the standard Constant Product Market Maker (CPMM) used by protocols like Uniswap (x * y = k), which creates significant price slippage for stable assets, the Stableswap invariant creates an extended "flat" region in the middle of its curve. Within this region, trades between pegged assets experience minimal slippage and low fee arbitrage, as the price remains very close to 1:1. Outside this region, the curve smoothly transitions to behave like a CPMM to provide infinite liquidity and protect liquidity providers from depletion.

The core innovation is the amplification coefficient (A), a tunable parameter that controls the curvature's flatness. A higher A value makes the stable region wider and flatter, optimizing for extremely low slippage when the pool is balanced. This parameter allows the invariant to be adapted for different asset pairs, from perfectly correlated stablecoins (high A) to correlated assets like wrapped versions of the same token (lower A). The mathematical expression, often represented as a hybrid of the constant sum (x + y = D) and constant product (x * y = (D/2)^2) equations, is solved to find the invariant D (total deposits) and execute trades.

This design creates powerful economic effects. It concentrates liquidity around the peg, making it the most capital-efficient AMM for stablecoin and similar asset swaps. The low slippage attracts high-volume arbitrageurs who efficiently correct minor price deviations, which in turn generates substantial fee revenue for liquidity providers from routine rebalancing activity. However, the reliance on the peg holding is a key risk; if one asset depegs significantly, the invariant's flat region can lead to a one-sided drain of the better-performing asset from the pool, a scenario known as loss-versus-rebalancing.

The Stableswap invariant has become a foundational primitive in DeFi, enabling efficient on-chain forex markets, liquid staking derivative trading, and the backbone of many stablecoin liquidity pools. Its success has spurred further research into Curve V2 and other "dynamic curvature" AMMs that can efficiently manage liquidity for volatile, non-pegged asset pairs by automatically adjusting parameters like A based on market conditions.

how-it-works
DEEP DIVE

How the Stableswap Invariant Works

An exploration of the mathematical core powering efficient stablecoin and pegged asset exchanges in decentralized finance.

The Stableswap Invariant is a hybrid automated market maker (AMM) bonding curve algorithm, pioneered by Curve Finance, designed to facilitate extremely low-slippage trades between assets intended to maintain a stable 1:1 price ratio, such as different stablecoins or wrapped versions of the same asset. Unlike the constant product formula (x * y = k) used by platforms like Uniswap, which creates significant price divergence even for small trades, the Stableswap invariant dynamically adjusts its curve based on the composition of the liquidity pool. When the pool is balanced, it behaves like a constant sum curve (x + y = C), enabling near-zero slippage for trades that keep the assets near their peg. As the pool becomes imbalanced, the curve smoothly transitions to behave more like a constant product curve, introducing higher slippage to incentivize arbitrageurs to restore balance and protect liquidity providers from impermanent loss.

The mathematical formula combines the constant sum and constant product invariants using a weighting factor, Ο‡ (chi), which represents the "leverage" or amplification coefficient. This coefficient is not a fixed parameter but is derived from the pool's composition. The core invariant is expressed as: A * (x + y) + D = A * D * (x + y) / (x * y) + D, where A is a tunable amplification parameter set by the pool creator, x and y are the reserves of the two assets, and D is the total liquidity invariant. A high A value (e.g., 1000) makes the curve flatter and more like a constant sum over a wider range, optimizing for low slippage. The protocol dynamically calculates the effective Ο‡ based on A, D, and the current reserves, allowing the curve to be "stretched" when the pool is balanced and to contract towards a constant product shape as it deviates.

This design creates powerful economic incentives. The region of minimal slippage acts as a price anchor, encouraging arbitrageurs to execute trades that profit from tiny deviations from the peg, thus constantly pushing the pool back to equilibrium. For liquidity providers, the concentrated liquidity around the peg means their capital is utilized with high efficiency for the intended trading range, generating fee income from high-volume, low-slippage swaps. However, this efficiency comes with a nuanced risk profile: while impermanent loss is minimized when assets remain pegged, a depeg event (where an asset like a stablecoin loses its 1:1 value) can lead to asymmetric losses as the pool's reserves become heavily skewed toward the depegged asset, and the invariant's shape offers less protection than a pure constant product curve.

key-features
STABLESWAP INVARIANT

Key Features and Characteristics

The Stableswap invariant is a specialized Automated Market Maker (AMM) bonding curve designed for efficient trading of pegged assets. It combines elements of a constant-sum and constant-product formula to minimize slippage and price impact within a defined price range.

01

Combined Curve Formula

The invariant is defined by the equation: Ο‡D^(n-1)βˆ‘x_i + ∏x_i = Ο‡D^n + (D^n / n^n), where D is the total liquidity, x_i are token balances, n is the pool size, and Ο‡ is a dynamic weight. This formula blends a constant-sum line (for minimal slippage near equilibrium) with a constant-product hyperbola (to provide infinite liquidity support and handle large trades).

02

Amplification Coefficient (A)

The key parameter A controls the curve's shape and the pool's behavior. A high A value (e.g., 1000) makes the curve flatter, resembling a constant-sum market with extremely low slippage for like-valued assets. A low A value makes the curve more curved, behaving like a traditional constant-product market (e.g., Uniswap V2), suitable for correlated but not pegged assets.

03

Low Slippage for Stable Assets

The primary design goal is to enable large trades of pegged assets (like stablecoins) with minimal price impact. When pool assets are perfectly balanced, the invariant approximates a constant-sum formula, allowing significant volume to be traded before encountering the curvature of the constant-product portion, thus keeping slippage near zero.

04

Dynamic Fee Adjustment

Many Stableswap implementations incorporate dynamic fees that adjust based on market conditions. When the pool is near equilibrium (e.g., 1 USDC β‰ˆ 1 DAI), fees are kept low to facilitate efficient swaps. If an asset's price deviates significantly from the peg (e.g., due to a depeg event), fees can automatically increase to incentivize arbitrageurs to rebalance the pool.

05

Liquidity Concentration & Capital Efficiency

Unlike constant-product AMMs where liquidity is spread across all prices (0 to ∞), Stableswap concentrates virtually all liquidity around the peg price (e.g., $1). This creates extremely deep liquidity at the target price, leading to superior capital efficiencyβ€”a smaller amount of locked capital can support the same trade volume with lower slippage compared to a standard AMM curve.

06

Handling of Imbalances & Depegs

The invariant's constant-product tail provides a crucial safety mechanism. If a pool becomes severely imbalanced or an asset depegs, the curve transitions to behave like Uniswap V2, ensuring liquidity never runs out and the price can move freely. This prevents liquidity providers from suffering unbounded losses and allows the market to find a new equilibrium price.

mathematical-formula
STABLESWAP INVARIANT

The Mathematical Formula

The Stableswap invariant is a specialized Automated Market Maker (AMM) bonding curve designed to facilitate efficient trading between assets intended to hold the same value, such as stablecoins.

The Stableswap invariant is a mathematical function that defines the relationship between the reserves of two or more assets in a liquidity pool, engineered to maintain extremely low price slippage near a 1:1 peg. Unlike a constant product formula (x * y = k), which creates a hyperbolic curve, the Stableswap invariant combines this with a constant sum formula (x + y = k) to create a long, flat "constant sum" region around the peg. This hybrid curve allows for large trades with minimal price impact when the pool is balanced, while reverting to the properties of a constant product AMM at the curve's extremes to preserve liquidity and prevent reserves from being fully depleted.

The core innovation is the introduction of a leverage parameter, often denoted as A or Ο‡ (chi), which dynamically weights the influence of the constant sum and constant product components. A high A value amplifies the constant sum portion, creating a wider flat section ideal for stable pairs. The invariant is formally expressed as a function of the number of coins n, the amplification coefficient A, the token balances x_i, and the invariant D representing the total liquidity when all assets are at parity. This formula enables the pool to act like a constant sum AMM for small deviations and a constant product AMM for large ones.

This mechanism directly addresses the capital inefficiency of simple constant product AMMs for stable assets. In a standard x * y = k pool, even a small trade between two stablecoins can cause noticeable slippage, requiring massive liquidity to mitigate. The Stableswap invariant concentrates this liquidity around the peg, allowing a pool with the same total value locked (TVL) to offer dramatically better rates for typical trades. The parameter A is often adjustable by governance, allowing a protocol to tune the pool's behavior for specific asset pairs based on their historical volatility and peg stability.

The most famous implementation is the Curve Finance constant function market maker, which popularized the model for swapping like-valued assets such as USDC, DAI, and USDT. Its success demonstrated that AMM design is not one-size-fits-all and that tailoring the bonding curve to the economic properties of the assets can unlock new efficiencies. The invariant's design ensures that arbitrageurs are incentivized to correct small price deviations, as moving along the flat section of the curve is highly profitable, thus naturally reinforcing the peg and maintaining pool equilibrium with minimal external intervention.

Beyond simple stablecoin pairs, the Stableswap invariant has been extended to pools with more than two assets and to metapools, where one liquidity pool (e.g., a 3CRV pool of three stablecoins) can be used as a single asset within another Stableswap pool. This composability allows for deep, efficient liquidity networks. Furthermore, variations of the model have been adapted for correlated assets (like different flavors of wrapped Bitcoin) and even for assets with a known, non-1:1 exchange rate, proving the flexibility of the core mathematical principle.

examples
STABLESWAP INVARIANT

Protocol Examples and Implementations

The Stableswap invariant is a core mathematical formula enabling efficient trading between pegged assets. Its implementations power the largest decentralized exchanges for stablecoins and wrapped assets.

CONSTANT FUNCTION MARKET MAKER COMPARISON

Stableswap vs. Other AMM Models

A technical comparison of core mechanisms, efficiency, and trade-offs between the Stableswap invariant and other common Automated Market Maker bonding curves.

Feature / MetricStableswap (e.g., Curve Finance)Constant Product (e.g., Uniswap V2)Concentrated Liquidity (e.g., Uniswap V3)

Core Invariant Formula

x + y = D (with adjustable amplification)

x * y = k

x * y = k (within a price range)

Primary Design Goal

Minimal slippage for pegged assets

General-purpose token trading

Capital efficiency for volatile pairs

Ideal Asset Pair

Stablecoins / Pegged Assets (e.g., USDC/DAI)

Volatile/Disparate Assets (e.g., ETH/DAI)

Any, with defined price range

Price Impact (Slippage) for Stable Pairs

Very Low (<0.01% for small trades)

High (0.3%+ baseline)

Configurable (Very Low within range)

Capital Efficiency

High for tight correlations

Low

Very High (up to 4000x vs. V2)

Impermanent Loss Risk for Stable Pairs

Very Low

High

Low (if range is correct)

Liquidity Distribution

Uniform across all prices

Uniform across 0 to ∞ price

Concentrated in a custom price range

Fee Structure Example

0.04% (low, due to low risk)

0.3% (standard)

0.05%, 0.3%, 1% (tiered)

Oracle Support

Time-Weighted Average Price (TWAP)

Time-Weighted Average Price (TWAP)

Built-in on-chain oracle

security-considerations
STABLESWAP INVARIANT

Security and Risk Considerations

While the Stableswap invariant enables efficient, low-slippage trading of pegged assets, its mathematical design introduces specific security and financial risks that must be understood by liquidity providers and protocol developers.

01

Impermanent Loss Dynamics

Liquidity providers in a Stableswap pool face a unique impermanent loss (IL) profile. While minimized when assets trade at parity, IL becomes significant during de-pegging events. The invariant's concentrated liquidity amplifies losses if one asset's price diverges and stays away from the 1:1 peg, as the pool becomes heavily imbalanced. This is a non-custodial financial risk, not a smart contract exploit.

02

Oracle Manipulation Vectors

Stableswap pools are often used as price oracles by other DeFi protocols. An attacker could:

  • Drain a pool to create a large, temporary price deviation.
  • Exploit the low-liquidity "tails" of the curve to skew the time-weighted average price (TWAP).
  • Use flash loans to amplify the attack. This can lead to cascading liquidations or faulty arbitrage in dependent systems. Robust oracle designs use multiple data sources and delay mechanisms.
03

Amplification Parameter Risk

The amplification coefficient (A) is a critical, tunable parameter that defines the curve's shape and thus its risk profile. An incorrectly set A parameter can lead to:

  • High slippage if A is too low, making the pool behave like a constant product AMM.
  • Extreme imbalance vulnerability if A is too high, creating a near-flat region that can be drained with minimal price movement. A is often set by governance, introducing governance risk.
04

Composability & Systemic Risk

The deep liquidity in major Stableswap pools (e.g., 3pool, 4pool) makes them systemically important financial infrastructure in DeFi. Risks include:

  • Contagion: A de-peg or exploit in one major stablecoin can drain liquidity for all assets in the shared pool.
  • Integration Risk: Many lending protocols and yield aggregators depend on these pools for liquidity and pricing. A failure can propagate through the ecosystem.
  • Bridge Dependency: Cross-chain Stableswap implementations rely on the security of underlying bridges for asset canonicalization.
05

Smart Contract & Implementation Risk

Beyond the financial model, the code implementing the invariant carries standard DeFi risks:

  • Audit Quality: Complex mathematical functions increase the attack surface for precision errors or rounding issues.
  • Admin Keys: Many implementations have proxy upgradability or privileged functions (e.g., to adjust fees, A). Centralization of these controls is a key risk.
  • Integration Bugs: Errors in how other contracts interact with the pool's functions (e.g., slippage checks, callback hooks) can lead to fund loss.
06

Stablecoin Peg Integrity

The core security assumption of a Stableswap pool is that its constituent assets maintain their peg. The invariant provides no protection against:

  • Stablecoin de-pegging due to regulatory action, bank failure, or algorithmic failure.
  • Collateral insufficiency in fiat-backed or crypto-collateralized stablecoins.
  • Rug pulls or governance attacks on the stablecoin itself. Liquidity providers must independently assess the credit risk of each asset in the pool.
STABLESWAP INVARIANT

Frequently Asked Questions (FAQ)

A deep dive into the core mathematical formula that powers automated market makers (AMMs) for stablecoin and pegged asset trading.

The Stableswap invariant is a mathematical formula used in automated market makers (AMMs) to facilitate efficient trading between assets of similar value, like stablecoins. It dynamically combines the constant product formula (x*y=k) and the constant sum formula (x+y=k) to create a "hybrid curve". This curve is nearly flat (low slippage) when the pool is balanced but behaves more like a constant product curve when reserves become imbalanced, preventing the pool from being drained. The most famous implementation is the Curve Finance invariant, which uses an amplification coefficient (A) to control the "flatness" of the curve. A higher A value creates a larger low-slippage region, optimized for assets like USDC and DAI.

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
Stableswap Invariant: Definition & AMM Algorithm Explained | ChainScore Glossary