Notes and explicit expressions for StableSwap pools.
The StableSwap invariant follows
where
The StableSwap invariant can be thought of as a superposition of the constant product invariant and the constant sum linear invariant
where maintains the nice AMM property of providing liquidity at all prices: i.e. implies for the two coin case.
A StableSwap metapool is simply a Curve pool with at least one of the coins in the pool as a Curve LP token from a base pool. e.g. MIM Metapool has token pairs and , where 3Crv is the LP token for the base 3pool with tokens DAI, USDC, USDT. The metapool allows the usual swaps between e.g. MIM and 3Crv or swaps between MIM and USDC/USDT/DAI via exchange_underlying
.
Balances along the invariant curve compared to constant product are most pronounced near e.g. in the two token case, where price is 1.
Blue dotted is CP, green dotted is CS, and orangle is StableSwap invariant. You can see the transition toward/away from constant sum as you move toward/away from the equilibrium point of close to equal balances between tokens.
Define the marginal price quoted by the pool for base token and quote token as the negative of the derivative of base w.r.t quote
Applying to the StableSwap invariant equation gives an expression for the marginal price as a function of token balances in the pool
where .
For the MIM metapool example, it's relatively easy to solve for this price w.r.t the 3Crv quote token (assuming relative to MIM). Solving the quadratic in the two coin case,
where
for (i.e. not pure constant product).
Plots of the marginal price (green) with balance invariant (orange dotted) in the background illustrate the flattening of the price curve as the pool becomes more balanced (i.e. ):
Define the marginal slippage experienced by the trader as the negative of the derivative of marginal price w.r.t. quote
Applying to the general expression for marginal price
where .
For the two coin case, slippage is given by
Plots of the marginal slippage (red) with balance invariant (orange dotted) and marginal price (green dotted) in the background illustrate the flattening of the slippage curve toward zero as the pool becomes more balanced (i.e. ):