A deep dive into the StableSwap invariant, the unique algorithm powering Curve Finance that enables highly efficient trading of pegged assets like stablecoins.

In Decentralized Finance (DeFi), automated market makers (AMMs) use mathematical formulas called invariants to price assets. The most well-known invariant is the constant product formula (x * y = k), which Uniswap v2 employs. However, this formula lacks efficiency for trading pegged assets such as stablecoins.
The StableSwap invariant , designed by Curve Finance, addresses this inefficiency. It serves as a specialized bonding curve optimized for trading pegged assets, such as stablecoins, by creating a hybrid curve. This curve is flatter than the constant product curve, resulting in lower slippage and enhanced capital efficiency. Understanding the StableSwap invariant is essential for grasping whyCurve pools dominate the stablecoin trading market.
This article explains the StableSwap invariant, its functionality, and its advantages in pegged asset swaps.
| Feature | Description |
|---|---|
| Hybrid Formula | The StableSwap invariant smoothly transitions between a constant sum formula (x + y = k) and a constant product formula (x * y = k). |
| Primary Goal | It aims to create a bonding curve that remains flat when liquidity pools are balanced but still offers liquidity when one asset de-pegs. |
| Low Price Impact | It results in minimal price impact (slippage) for substantial trades between assets like USDC and DAI. |
| Amplification Parameter (A) | The shape of the StableSwap curve is influenced by the amplification parameter A. A higher value flattens the curve, concentrating liquidity around the peg. |
Capital Efficiency | Concentrating liquidity enables greater capital efficiency compared to general-purpose AMMs. |
The x * y = k formula is not suitable for stablecoin pairs like USDC/DAI due to several reasons:
x * y = k curve forms a hyperbola, distributing liquidity across all possible price points from zero to infinity.For trading two equally valued assets, the constant sum formula(x + y = k) is ideal:
However, a pool based on this formula is highly fragile. If one stablecoin, such as USDC, de-pegs and trades at a significantly lower value on other exchanges, arbitrage bots would quickly drain all DAI from the pool, leaving only the de-pegged USDC. This scenario leads to significant losses for liquidity providers.
The StableSwap invariant merges the benefits of both the constant sum and constant product formulas. While the actual formula is complex, its behavior can be intuitively understood:
The StableSwap invariant functions like a constant sum formula when the pool is balanced, then transitions to a constant product formula as the pool becomes imbalanced.
x + y = k line. This configuration allows for significant trades with minimal slippage.x * y = k hyperbola. This adjustment ensures that the pool maintains liquidity, preventing total depletion and protecting liquidity providers.The amplification parameter, or A, is important in controlling the StableSwap invariant's behavior:
| A Value | Curve Characteristics |
|---|---|
| High | Flatter curve, concentrating liquidity tightly around the 1:1 price. Suitable for stable, highly correlated assets (e.g., USDC/DAI/USDT pool). |
| Low | More curved shape resembling a standard constant product formula. Used for pegged assets with higher volatility (e.g., pools involving different liquid staking derivatives like stETH/rETH). |
By adjusting the A parameter, Curve pools optimize for the specific characteristics of their assets.
The bonding curves can be visualized as follows:
| Formula Type | Description | Visual Representation |
|---|---|---|
| Constant Product | Smooth, symmetric hyperbola | |
| Constant Sum | Perfect diagonal line | |
| StableSwap (Curve) | Almost flat near the center, sharply curves away |
This visual representation illustrates how StableSwap can accommodate significantly more volume with less slippage in the critical price range for pegged assets.
The term "invariant" refers to the constant value k computed by the formula, which remains unchanged during trades, disregarding transaction fees.
No, traders benefit from low slippage without needing to grasp the underlying mathematics. Liquidity providers enjoy high capital efficiency, as the protocol abstracts the complexity.
No, but it considerably reduces impermanent loss for pegged assets. Since the assets are expected to maintain similar prices, the risk is lower compared to pools with volatile assets. However, permanent loss can occur if one stablecoin fails to maintain its peg.
Is the StableSwap formula used by other protocols? Yes, while Curve pioneered the StableSwap concept, other decentralized exchanges focusing on stable assets have adopted similar hybrid bonding curves.
Explore more guides and career playbooks