The Math
This section explains the technical-mathematical terms and concepts behind ElasticSwap v1.
Technical Terms
Note: The usage of dash notation (
') & delta notation (Δ) is explained in subsequent examples in the following sections.
X- The internal balance of,baseTokenfor accounting purposes.DeltaX (ΔX)- The (incoming or outgoing) change in the quantity ofXXDash (X')->X' = ΔX + X- The new quantity ofXpost 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 ofYYDash (Y')->Y' = ΔY + Y- The new quantity ofYpost the occurrence of a trade or a liquidity eventAlpha (α)- The ERC20 balance ofbaseTokencurrently in the Exchange.Beta (β)- The ERC20 balance ofquoteTokencurrently in the Exchange.Omega (ω)-X/Y- The ratio of the internal balance ofbaseTokento the internal balance ofquoteToken.iOmega (iω)-Y/X- The ratio of the internal balance ofquoteTokento the internal balance ofbaseToken.K-X*Y- The product of the internal balance ofbaseTokenand the internal balance ofquoteToken. It is used to price trades betweenbaseTokenandquoteToken.Sigma (σ)-α/β- The ratio of the balance ofbaseTokencurrently in the Exchange to the balance ofquoteTokencurrently 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 ofliquidityTokenwhenalphaDecay(α^)orBetaDecay (β^)exists in the system.
Further explained: Presence of AlphaDecay(α^) and BetaDecay(β^)
AlphaDecay(α^) and BetaDecay(β^)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,ω' != σ'
Issuance of liquidity Tokens ΔRo
ΔRoLiquidity Tokens, Ro, are provided to liquidity providers. There are multiple ways to provide liquidity: creating an Elastic AMM pool, singleAssetEntry, doubleAssetEntry and a partialSingleAndDoubleAssetEntry.
Creation of an Elastic AMM pool: This case refers to the creation of an ELastic AMM pool( a pool that consists of both
baseTokenandquoteToken) on ElasticSwap, this differs fromdoubleAssetEntrybecause here there is noOmega,SigmaUntil the pool has been created. The first batch of LP tokensRois also minted to the liquidity provider who bootstraps the pool.The amount of
liquidityTokens- (ΔRo) issued to the liquidity provider, in this case, is given by: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 ofOmegaandSigma.The amount of
liquidityTokens- (ΔRo) issued to the liquidity provider, in this case, is given by:Note: To understand the usage of Delta(
Δ) and Dash(') notation, the above scenario initially(prior to Double Asset Entry) was:The "change" that the system is introduced to the AMM by the liquidity provider, providing baseToken and quoteToken is given by:
As a result of which a certain amount
ΔRo(DeltaRo) is issued to the liquidity provider (refer above). Which results in the final state being:The function that does this is
addLiquidityin Exchange.solSingle 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:When there is
betaDecay:The respective solidity functions can be found at Exchange.sol
PartialSingleAndDoubleAssetEntry: When the liquidity provider wants to provide both
baseTokenandquoteTokenwhen decay is present, it is called aPartialSingleAndDoubleAssetEntry. This is because firstly, asingleAssetEntryoccurs, and then adoubleAssetEntryoccurs. The liquidity provider receivesΔRo(liquidity tokens) that takes into account both the entires.The amount of
liquidityTokens- (ΔRo) issued to the liquidity provider, in this case, is given by:Note: In
PartialSingleAndDoubleAssetEntryit is possible that the user might end up with a certain amount of unusedbaseTokenorquoteToken, This is because in the presence ofAlphaDecay (α^)theSingleAssetEntryuses up a certain amount ofquoteTokenand then the remaining amount of which is used along with an equivalent amount ofbaseTokenfor theDoubleAssetEntry, the quantity of which could be lower than the amount the liquidity provider wanted to provide.
Redemption of liquidity Tokens ΔRo
ΔRoThe underlying redemption value of liquidity tokens increases due to the accrual of trading fees. At any time, they can be redeemed for equivalent amounts of baseToken and quoteToken. The amount of baseToken and quoteToken received is given by:
The function that handles this is removeLiquidity in Exchange.sol.
Note: It is possible to redeem
Rowhen there is decay (alpha or beta) present in the system.
Fees:
As with any other AMM, the incentive to provide liquidity is such that the LP tokens issued accrue fees.
There is a 30 basis points (BPS) fee for swap occurrences(this is at par with other AMM's at the moment, this can be changed via vote if the ElasticSwap DAO votes to do so ), 5 BPS of which goes to the feeAddress (an address which is ElasticDAO initially, this can be changed via vote if the ElasticSwap DAO votes to do so). The remaining 25 BPS is realized by the LP holders pro-rata.
The fees are accrued on swap occurrences, the portion of the fees (5 BPS) that the feeAddress receives is sent to it when liquidity events occur.
Tokens supported by ElasticSwap:
For the rebasing token - baseToken, any ERC20 token which is Elastic in nature, i.e its supply contracts and expands due to external factors can be used to create a pool with a standard ERC20 non-elastic token - quoteToken.
Note: Support for tokens that have Fee on transfer behaviour will not supported in V1.
Examples:
Example 1:
Example 2: Rebase down -> SAE + DAE -> exit
Last updated