Liquidity Pool
The module x/liquiditypool
is for minting LP tokens of XXX/SR
with AMM mechanism. LP tokens can be used for Proof of Liquidity for Sunrise L1, and also can be used for Sovereign Proof of Liquidity for L2s on Sunrise.
This module supports Concentrated Liquidity while the LP tokens are still fungible.
Notions
Pair
Before creating the pool, the pair of tokens have to be registered. The notion of 1
Pair will be linked to N
Pools.
There are some restrictions for the pair registration while the pair consists of base_token / quote_token
:
$SR
can't be the base token.If the quote token is not
$SR
, the pairquote_token / $SR
must be registered.
These rules enable the calculation of $SR
converted value of LP tokens by using TWAP to use them in Proof of Liquidity.
Pool
In contrast to Uniswap V3, each user can't designate the range of providing concentrated liquidity in the same pool. Each pool has a fixed range of liquidity provision, and users will decide which pool to provide liquidity. This design enables making the LP tokens fungible in the same pool.
The range of the concentrated liquidity can be changed and the funds can be rebalanced by the governance in x/group
module for each pool.
Mathematics
To mitigate the calculation cost on the chain, each pool i
of token pair X
and Y
contains the information of the fuction
where
x_i
is the amount of tokenX
in the pooli
y_i
is the amount of tokenY
in the pooli
k_i
is the constant value of the pooli
All equations are the explicit form of the single implicit function
where
f_i
is the function that uniquely determines the range and allocation of the liquidity in pooli
.
For example, Uniswap V2 like AMM can be described as
Uniswap V3 like Concentrated Liquidity MM can be described as
Then, the change of token amounts without consideration of fees can be described as below
where
dx_i
is the change of tokenX
amount in the pooli
dy_i
is the change of tokenY
amount in the pooli
To find the optimal weights w_i
to maximize the amount to receive, the following optimization problem can be solved for each case with r_i
that is the sum of the fee rate of the pool i
and the protocol.
Send exact amount of token X
to pools (dx > 0
)
Receive exact amount of token X
from pools (dx < 0
)
Send exact amount of token Y
to pools (dy > 0
)
Receive exact amount of token Y
from pools (dy < 0
)
These calculation can be done in the client side, then the load on the chain can be reduced because the chain side only need to receive the weight w
to execute the optimal swap.
TWAP
Sunrise chain will record the last prices of the pool periodically, and they will be used for calculating Time Weighted Average Price. TWAP will be utilized for calculating the voting power from the LP tokens by using the price ratio to $SR
token.
Msgs
MsgSwapExactAmountIn
This message can contain the array of the pairs.
MsgSwapExactAmountOut
This message can't contain the array of the pairs.
MsgJoinPool
MsgExitPool
MsgCreatePool
MsgUpdatePool
Last updated