Liquidity Lu saysCurve’s stableswap invariant blends constant-sum (flat near peg) with constant-product (steep at the edges) — high amplification keeps two stables trading near 1:1 with tiny slippage.
Curve's stableswap invariant interpolates between constant-sum (flat) and constant-product (curved) depending on an amplification coefficient A. Near the peg, the curve is nearly flat — trades happen with almost no slippage. As reserves drift away from equal weight, it bends sharply, raising slippage and discouraging trading away from peg.
Real Curve solves for D iteratively each swap. The demo uses a stylized model showing slippage staying near zero while balanced and ramping as reserves skew.
Power-ups you unlock
Invariant blends constant-sum + constant-product via amplification A
Near peg: flat curve, near-zero slippage
Far from peg: steep curve, slippage rises sharply
High A (100, 1000) → stronger peg-stickiness
Best for assets that should trade near 1:1 (stables, LSTs)
The Sandwich Bot attacks — common mistakes
Using stableswap for assets that should NOT trade 1:1
Setting A too high (peg-stickiness becomes brittleness)
Forgetting LP exposure to depegs (you eat the loss)
Ignoring iterative D computation cost
Boss battleShow stableswap slippage staying small near 50/50 balance and rising as the pool skews to 90/10.
Example code
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>
// stylized: real Curve solves D iteratively. this shows the qualitative behaviour.
function slippage(A, x, y){
const r = x / (x + y);
const skew = Math.abs(r - 0.5);
return (Math.pow(skew * 2, 3) / A);
}
const A = 100;
const rows = [];
for(const x of [5000, 4500, 4000, 3000, 2000, 1000]){
const y = 10000 - x;
const ratio = x / (x + y);
rows.push(' ratio x/(x+y)=' + ratio.toFixed(2) + ' slippage ≈ ' + (slippage(A, x, y) * 100).toFixed(4) + '%');
}
document.getElementById('o').textContent = [
'stableswap (amp=' + A + ', stylized):',
...rows,
'',
'near 50/50 → near-zero slippage; toward 90/10 → slippage ramps fast'
].join('\n');
</script></body></html>