StableSwap invariant
The StableSwap invariant, introduced by Curve Finance, is a pricing curve specially shaped for assets that should trade near a 1-to-1 ratio — two stablecoins, or a token and its wrapped or staked version. A plain constant-product curve charges meaningful price impact even on a swap between two dollar-pegged coins, which is wasteful when they are supposed to be worth the same. StableSwap fixes this by being almost flat near the balance point, so large trades between pegged assets suffer tiny slippage, while still curving away to protect the pool when one asset depegs and the reserves become lopsided.
It achieves this by blending two classic invariants. A constant-sum curve (x + y = constant) gives zero slippage but can be fully drained; a constant-product curve (x * y = constant) never empties but always has slippage. StableSwap interpolates between them using an amplification coefficient A: when the pool is near balance it behaves like the slippage-free constant-sum curve, and as the reserves diverge it smoothly transitions toward the safer constant-product behavior. A higher A means a flatter, more constant-sum-like curve (lower slippage but less protection if the peg breaks); a lower A means more constant-product-like safety.
This design made Curve the dominant venue for stablecoin and pegged-asset swaps, and the low impermanent loss of like-valued pools made providing liquidity attractive. The same idea generalizes to more than two assets and to assets with a known exchange rate rather than exactly 1-to-1 (for example a liquid-staking token that accrues value against ETH). The crucial caveat is that the flatness which makes StableSwap so efficient is also a liability during a depeg: because the curve resists price movement near balance, liquidity providers can be left holding a disproportionate amount of the asset that is losing its peg before the curve steepens enough to push trades away.
The StableSwap invariant for n assets, with amplification A and invariant total D.
The amplification coefficient A is a deliberate trade-off, not a free lunch: cranking A up to advertise ultra-low slippage also means the pool will absorb a depegging asset deeply before defending itself, so a high-A pool quietly carries more tail risk during a crisis.