ST - Invariant

Invariant (k variable) used in ST liquidity pools is adopted from the Uniswap approach to liquidity pairs balance. It is calculated using following equation:

$k =p *m$

Where:
k = invariant
p = amount of ST tokens in the pool (i.e. “left” side of the pool)
m = amount of CDO tokens in the pool ( “right” side of the pool)

Invariant needs to remain the same, regardless of how many ST tokens have been taken away from the pool (i.e. bought) or added to it (i.e. sold). So in order to keep the k variable as const, the right side of the pool (m) needs to be adjusted along every trade affecting the left side of the pool (p).

In other words, if [n] amount tokens is being added or removed from [p], value of [m] needs to change so as k would remain the same:

$m =[p +n] / k$

Where:
k = invariant
p = amount of ST tokens in the pool (i.e. “left” side of the pool)
m = amount of CDO tokens in the pool ( “right” side of the pool) n = amount of ST tokens subjected to transaction (buy or sell)

Newly calculated m is the amount of CDO tokens that should be locked in the liquidity pool. We need to deduct the current amount of CDO tokens in the pool [m’] from it, and then divide the resulting number by the amount of ST tokens subjected to transaction [n], to identify the CDO price of a single ST token:

$z =[m -m'] / n$

Copy link