StableSwap AMM
Curve-style StableSwap invariant for pegged assets, interpolating between constant sum and constant product by an amplification coefficient
Abstract
StableSwap implements the Curve invariant for trading between assets that should maintain a 1:1 peg (stablecoins, wrapped assets, liquid staking derivatives). The invariant interpolates between constant-sum (x + y = k, zero slippage) and constant-product (x * y = k, full slippage) based on an amplification parameter A. At typical operating ranges, StableSwap achieves 100-1000x lower slippage than constant-product AMMs for pegged pairs.
Motivation
Two dollars are not two different assets. Pricing them on x*y=k charges the trader slippage for a risk that does not exist while the peg holds — and offers no protection when it breaks. The amplification coefficient makes that trade-off explicit and tunable: near the peg the curve is nearly flat, and it degrades continuously into constant product as the pool skews.
Specification
Invariant
The StableSwap invariant for n tokens:
A * n^n * sum(x_i) + D = A * D * n^n + D^(n+1) / (n^n * prod(x_i))
Where:
A: amplification coefficient (higher = closer to constant-sum)D: total deposit value at equilibriumx_i: reserve of token in: number of tokens in the pool
Pool Types
| Type | Tokens | Typical A | Use Case |
|---|---|---|---|
| 2-pool | USDC/USDT | 200 | USD stablecoins |
| 3-pool | USDC/USDT/DAI | 100 | Multi-stablecoin |
| Meta-pool | newStable/3pool-LP | 50 | New stablecoin bootstrapping |
| LST-pool | LUX/sLUX | 30 | Liquid staking derivatives |
Amplification Ramping
The amplification parameter A can be adjusted by governance over a ramping period:
- Ramp duration: minimum 1 day
- Max change: 10x per ramp
- Direction: increase (tighter peg) or decrease (more like constant-product)
Ramping prevents sudden invariant changes that could be exploited.
Fee Structure
- Swap fee: 0.04% (4 bps) -- lower than constant-product or concentrated pools because stable pairs have lower IL risk
- Admin fee: 50% of swap fee goes to protocol treasury
- LP fee: 50% of swap fee accrues to LP tokens
LP Tokens
StableSwap LP tokens are fungible ERC-20. Deposits and withdrawals can be single-sided (any one token) or balanced (all tokens proportionally). Single-sided operations incur a small fee to compensate for the imbalance.
Virtual Price
The LP token's virtual price is D / totalSupply. It monotonically increases as fees accrue. This makes LP tokens suitable as collateral in lending protocols (LP-9203).
Rationale
A is a single knob with a physical meaning: the depth of the flat region around the peg. Ramping it over at least a day rather than in one transaction is what prevents a governance action from re-pricing the pool inside a block — the exploit that an instantaneous A change would enable.
Security Considerations
- De-peg risk: if an asset in the pool loses its peg, the pool concentrates into the depegged asset. The amplification parameter
Adetermines how quickly this happens. - Amplification attacks: malicious governance could ramp
Ato extreme values. The ramp rate limit and timelock mitigate this. - Read-only reentrancy: the
get_virtual_price()function must be called with a reentrancy guard when used as an oracle by external protocols.
Reference
| Resource | Location |
|---|---|
| StableSwap contracts | github.com/luxfi/standard/contracts/amm/stable/ |
| Pool factory | StableSwapFactory.sol |
| Math library | StableSwapMath.sol |
Related LPs
Copyright
Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.
Licensed under the MIT License.