Curve Finance: Stableswap Invariant

Here is what will be covered:

  • Constant sum invariant
  • Constant product invariant
  • Creation of stable swap invariant
  • Implications of stable swap invariant
  • How concentration of liquidity is integrated with the invariant

A stable swap invariant is used in the pools having assets having the same value i.e. pegged assets. The information is a bit math-heavy but I am sure you would be impressed learning the implications of the invariant used by Curve V1.


If this simple reading layout doesn’t excite you, you could scroll down to consume the same content as if it were a magazine.

Disclaimer: All information presented here is my perspective and should be considered educational content. I won’t be responsible for any kind of financial profits or losses derived from your decisions. Financial and investment advice


Constructing the Stable Swap Invariant

Stableswap uses a combination of both constant-sum as well as constant product invariant. Constant sum function provides 0% slippage.

Constant sum Invariant

Constant sum invariant with zero price impact while trading
Constant sum invariant with zero price impact while trading

Constant sum function: x + y = k (constant)

It provides a 1:1 value exchange, thus it is possible to swap the whole pool with zero slippage

Constant product Invariant

A liquidity pool that works on constant product function considers the factor of demand while trades are executed. As the quantity of one of the assets starts to dip, the price for that particular asset increases. It is impossible that a pool working on a constant product function ends up in a single asset.

Constant product function: x * y = k (constant)
If there are 100 X tokens and 100 Y tokens, k = 10000. A trader will receive 13.33 Y tokens for exchanging 25 X tokens.
The price would change to 0.53 from 1.

It becomes very expensive to drain a pool because
the token becomes exponentially more expensive.

Here is the graph for x * y = k

Constant product invariant compared to constant sum invariant
Constant product invariant compared to constant sum invariant

Combining Constant sum and Constant product Invariants

The StableSwap algorithm combines x * y = k and x + y = k. The pool switches to a constant sum function when the price is near $1 (stable coins pair). As and when the pool gets unbalanced, the invariant becomes a product function instead of the sum function, therefore swapping will become more expensive.

Combining constant sum and constant product invariant.
Combining constant sum and constant product invariant.

D is the total number of coins when they have an equal price.
This function gives out a graph similar to that of the constant product function

A factor (X ) is multiplied by the constant sum portion of the equation which will make the curve more effective.

A variable is added to the constant sum part to magnify it when needed.
A variable is added to the constant sum part to magnify it when needed.

As the multiplier X increases, it will magnify the low slippage portion of the equation by flattening the curve near the price of 1.

X must be a function of quantities of tokens in the pool (X & Y) so that:

X would decrease when the pool is unbalanced; product invariant would govern the trades.

X would increase when the pool is balanced; the constant sum invariant would govern the trades.

By multiplying D by the leverage factor (X ), it no longer depends on the number of tokens or the depth of liquidity.

Balancing the units. Removing the dependency of the constant sum part on the number of tokens.
Balancing the units. Removing the dependency of the constant sum part on the number of tokens.

Our leverage factor (X ) is :

The equation for leverage factor.
The equation for leverage factor.

A is a fixed constant (Amplification Coefficient).

X would be equal to A when the pool is balanced and as the pool gets more and more unbalanced, the X would be equal to a fractional value of A.
This fractional value of A will keep on shrinking with the degree of imbalance in the pool.

The final StableSwap equation:

Stable swap invariant equation.
Stable swap invariant equation.

n: number of tokens in the pool
A: amplification coefficient
D: total number of coins when the pool is balanced.

Implications of Stable Swap Invariant

For a constant value of amplification coefficient (A) when the price impact across the trades is computed with the stable swap equations, the price impact near the price was the lowest when the pool was balanced and the price impact keeps on increasing as the pool moves further away from the balanced condition.

Amplification coefficient and concentration of liquidity in the pool

X controls the amplification of some variant
A escalates the value of X based on the pool condition

This can be pulled off by altering the liquidity distribution in the pool.
The concept of concentrated liquidity is working here: whenever the X is magnified through the amplification coefficient A, the liquidity is getting concentrated near the price where the pool is balanced.

Altering the amplification coefficient (A) is governed by community votes from users.
Changing the value of A can have significant effects on that particular liquidity pool.

A could be increased in certain situations

Increased A would result in a leverage position for the pool to achieve extremely low slippage by creating huge liquidity depth near the price.

It would take a huge amount of demand-supply distortion for the pool to get out of balance but at the same time when any pool is pushed into an unbalanced state (an event where a stable coin loses its peg), it would take a huge volume of single-sided trades to rebalance the pool.

Lowering the A value is the best decision in the case of a distorted pool.

A could be decreased while rebalancing or when the pool is not mature enough to tank the risk of distortion.

Lowering the A value will reduce the liquidity concentration, thus it would take far less volume of single-sided trades to move the price.

Essential while rebalancing the pool.

Curve finance actively manages the health of the stablecoin liquidity pools via altering the amplification coefficient depending upon the situation and governance.


Thank you for being here.

You can provide the same value by sharing this article with your circle.

You could even contribute/support these articles by owning one ✌.


---
---
---
---

Thank you for being here.

You can provide the same value by sharing this article with your circle.

You could even contribute/support these articles by owning one ✌.


Subscribe to DiligentDeer
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.