Comment on page
The Math
This section explains the technical-mathematical terms and concepts behind ElasticSwap v1.
Note: The usage of dash notation ('
) & delta notation (Δ
) is explained in subsequent examples in the following sections.
X
- The internal balance of,baseToken
for accounting purposes.DeltaX (ΔX)
- The (incoming or outgoing) change in the quantity ofX
XDash (X')
->X' = ΔX + X
- The new quantity ofX
post the occurrence of a trade or a liquidity eventY
- The internal balance ofquoteToken
, for accounting purposes.DeltaY (ΔY)
- The (incoming or outgoing) change in the quantity ofY
YDash (Y')
->Y' = ΔY + Y
- The new quantity ofY
post the occurrence of a trade or a liquidity eventAlpha (α)
- The ERC20 balance ofbaseToken
currently in the Exchange.Beta (β)
- The ERC20 balance ofquoteToken
currently in the Exchange.Omega (ω)
-X/Y
- The ratio of the internal balance ofbaseToken
to the internal balance ofquoteToken
.iOmega (iω)
-Y/X
- The ratio of the internal balance ofquoteToken
to the internal balance ofbaseToken
.K
-X*Y
- The product of the internal balance ofbaseToken
and the internal balance ofquoteToken
. It is used to price trades betweenbaseToken
andquoteToken
.Sigma (σ)
-α/β
- The ratio of the balance ofbaseToken
currently in the Exchange to the balance ofquoteToken
currently in the Exchange.AlphaDecay (α^)
-α-X
- The amount ofAlpha(α)
not contributing to the liquidity due to an imbalance in the tokens caused by elastic supply (a rebase).BetaDecay (β^)
-β-Y
- The amount ofBeta(β)
not contributing to the liquidity due to an imbalance in the tokens caused by elastic supply (a rebase).Ro (ρ)
- The total supply of theliquidityToken
.Gamma
- Gamma is a multiplier term that is used to issue the correct amounts ofliquidityToken
whenalphaDecay(α^)
orBetaDecay (β^)
exists in the system.
The presence of the terms
X
, Y
, Alpha(α)
, Beta(β)
Allows the ElasticSwap v1 to support stable pricing on rebasing events for an elastic-non elastic supply token pair. This is done with the concept of AlphaDecay(α^)
and BetaDecay(β^)
. Whenever a rebase event occurs, which results in the increase or decrease in the supply of the baseToken
decay is introduced. The presence (or absence) of which determines how much Ro(ρ)
is issued to liquidity providers.- When there is an increase in the supply of the
baseToken
, essentially the quantity ofAlpha(α)
has increased, considering the situation where there was no decay prior to the rebase event, i.e., initiallyα = X
(andβ = Y
), implyingα^ = 0
(andβ^ = 0
). Post the rebase event:α^ = α' - X
( andβ^ = 0
, as there has been no change inβ
orY
)Note: In the above scenario, initiallyω = σ
, post the rebase event,ω' != σ'
- When there is a contraction in the supply of the
baseToken
, essentially the quantity ofAlpha(α)
has now decreased, considering the situation where there was no decay prior to the rebase event, i.e., initiallyα = X
(andβ = Y
), due to the contraction in supply, theBetaDecay (β^)
is given byβ^ = (X - α') * iω
.Note: In the above scenario, initiallyω = σ
, post the rebase event,ω' != σ'
Liquidity Tokens,
Ro
, are provided to liquidity providers. There are multiple ways to provide liquidity: creating an Elastic AMM pool, singleAssetEntry
, doubleAssetEntry
and a partialSingleAndDoubleAssetEntry
.- 1.Creation of an Elastic AMM pool: This case refers to the creation of an ELastic AMM pool( a pool that consists of both
baseToken
andquoteToken
) on ElasticSwap, this differs fromdoubleAssetEntry
because here there is noOmega
,Sigma
Until the pool has been created. The first batch of LP tokensRo
is also minted to the liquidity provider who bootstraps the pool.The amount ofliquidityTokens
- (ΔRo
) issued to the liquidity provider, in this case, is given by:ΔRo = sqrt(ΔY * ΔX)where,# sqrt - Stands for the square root of the numbers provided, ex: sqrt(4) = 2# ΔY - The amount of quoteTokens the liquidity provider wants to provide.# ΔX - The amount of baseTokens the liquidity provider wants to provide.Note: Initially, Ro = 0, hence after creation of the pool,Ro' = ΔRo + Ro => Ro' = ΔRo + 0(this becomes the Ro for other liquidity events, the dash and delta notation (Ro', ΔX, ΔY) is further explained in the Double Aset entry section) - 2.Double Asset Entry: Double asset entry occurs when the liquidity provider provides both baseToken and quoteToken (in equivalent amounts, such that Omega stays constant) to the AMM. Double asset entry is only possible when there is NO
AlphaDecay (α^)
orBetaDecay (β^)
present in the system. Double asset entry maintains the values ofOmega
andSigma
.The amount ofliquidityTokens
- (ΔRo
) issued to the liquidity provider, in this case, is given by:ΔRo = (ΔY/Y) * Rowhere,# ΔRo - The amount of tokens the liquidity provider receives.# ΔY - The amount of quoteTokens the liquidity provider wants to provide.# Y - The internal balance of quoteToken.# Ro - The current total supply of the liquidityTokenNote: To understand the usage of Delta(Δ
) and Dash('
) notation, the above scenario initially(prior to Double Asset Entry) was:Y - The internal balance of the quoteToken,Ro - The current total supply of the liquidityToken,The "change" that the system is introduced to the AMM by the liquidity provider, providing baseToken and quoteToken is given by:ΔY - The amount of quoteTokens the liquidity provider wants to provide.ΔX - The amount of baseTokens the liquidity provider has to provide. Given by ΔX = K / ΔYNote: The vice versa also holds true, If the liquidity provider wanted to provide a specific amount of baseTokens(ΔX), then the amount of quoteTokens(ΔY) to be provided would be given by ΔY = K / ΔXAs a result of which a certain amountΔRo
(DeltaRo) is issued to the liquidity provider (refer above). Which results in the final state being:Y' = Y + ΔY - The (new) internal balance of quoteToken after this liquidity eventX' = Y + ΔX - The (new) internal balance of baseToken after this liquidity eventRo' = Ro + ΔRo - The (new) current total of the liquidity tokensNote: Y', X', Ro' become Y, X, Ro respectively for the next following liquidity event(regardless of it being single or double asset entry). - 3.Single Asset Entry: Single asset entry is only possible when there exists decay (alpha or beta) in the system. When there is decay in the system it means that Omega != Sigma. With Single Asset Entry, the liquidity provider is "correcting" this with their liquidity, i.e bringing Sigma in line with Omega.The amount of
liquidityTokens
- (ΔRo
) issued to the liquidity provider, in this case, is given by: When there isalphaDecay
:ΔRo = (Ro/(1 - γ)) * γwhere,# ΔRo - The amount of tokens the liquidity provider receives.# γ = ΔY / ( (Alpha/Omega) + Y' )# ΔY = α^ / ω - The amount of quoteTokens required to completely offset alphaDecay.When there isbetaDecay
:ΔRo = (Ro/(1 - γ)) * γwhere,# ΔRo - The amount of tokens the liquidity provider receives.# γ = ΔX / ( X + (Alpha + ΔX) )# ΔX = α - X - The amount of baseTokens required to completely offset betaDecay(and by extension alphaDecay).# β^ = ΔX / ω - 4.PartialSingleAndDoubleAssetEntry: When the liquidity provider wants to provide both
baseToken
andquoteToken
when decay is present, it is called aPartialSingleAndDoubleAssetEntry
. This is because firstly, asingleAssetEntry
occurs, and then adoubleAssetEntry
occurs. The liquidity provider receivesΔRo
(liquidity tokens) that takes into account both the entires.The amount ofliquidityTokens
- (