There are some conditions when adding liquidity to the Blue Lotus DAO:
After LP contributions, the token price is unchanged.
P m i n P_{min} P min โ and P m a x P_{max} P ma x โ are also unchanged after LP contributions.
In Blue Lotus DAO, the pool for pair X-Y needs to maintain 4 parameters:
The initial amount of token X X X that is used for amplification, denoted by x 0 x_0 x 0 โ
The initial amount of token Y Y Y that is used for amplification, denoted by y 0 y_0 y 0 โ
The change in token X X X amount after trading activities, denoted by ฮ x 0 \Delta x_0 ฮ x 0 โ
The change in token Y Y Y amount after trading activities, denoted by ฮ y 0 \Delta y_0 ฮ y 0 โ
Therefore, the real balances and virtual balances of the reserves are:
Real Balances
x = x 0 + ฮ x 0 y = y 0 + ฮ y 0 x = x_0 + \Delta x_0 \\ y = y_0 + \Delta y_0 x = x 0 โ + ฮ x 0 โ y = y 0 โ + ฮ y 0 โ Virtual Balances
x โฒ = a โ
x 0 + ฮ x 0 y โฒ = a โ
y 0 + ฮ y 0 x' = a \cdot x_0 + \Delta x_0 \\ y' = a \cdot y_0 + \Delta y_0 x โฒ = a โ
x 0 โ + ฮ x 0 โ y โฒ = a โ
y 0 โ + ฮ y 0 โ where a a a is the amplification factor. You may find more information about the amplification factor here .
The constant product x โฒ โ
y โฒ = ( a โ
x 0 + ฮ x 0 ) โ
( a โ
y 0 + ฮ y 0 ) = k โฒ x' \cdot y' = (a \cdot x_0 + \Delta x_0) \cdot (a \cdot y_0 + \Delta y_0) = k' x โฒ โ
y โฒ = ( a โ
x 0 โ + ฮ x 0 โ ) โ
( a โ
y 0 โ + ฮ y 0 โ ) = k โฒ .
Note that P m i n P_{min} P min โ and P m a x P_{max} P ma x โ at this time are:
{ P m i n = ( y 0 โ
a โ y 0 ) 2 k โฒ P m a x = k โฒ ( x 0 โ
a โ x 0 ) 2 \begin{cases} P_{min} = \cfrac{(y_0 \cdot a - y_0)^2}{k'} \\ \\ P_{max} = \cfrac{k'}{(x_0 \cdot a - x_0)^2} \end{cases} โฉ โจ โง โ P min โ = k โฒ ( y 0 โ โ
a โ y 0 โ ) 2 โ P ma x โ = ( x 0 โ โ
a โ x 0 โ ) 2 k โฒ โ โ The current price: P = y โฒ x โฒ = a โ
y 0 + ฮ y 0 a โ
x 0 + ฮ x 0 P = \cfrac{y'}{x'} = \cfrac{a \cdot y_0 + \Delta y_0}{a \cdot x_0 + \Delta x_0} P = x โฒ y โฒ โ = a โ
x 0 โ + ฮ x 0 โ a โ
y 0 โ + ฮ y 0 โ โ
Liquidity Providers have to contribute in the same proportion for all 4 amount types. We denote the contribution ratio to be b b b . LPs have to contribute x 1 + ฮ x 1 x_1 + \Delta x_1 x 1 โ + ฮ x 1 โ , y 1 + ฮ y 1 y_1 + \Delta y_1 y 1 โ + ฮ y 1 โ in which:
{ x 1 = b โ
x 0 ฮ x 1 = b โ
ฮ x 0 y 1 = b โ
y 0 ฮ y 1 = b โ
ฮ y 0 \begin{cases} x_1 = b \cdot x_0 \\ \Delta x_1 = b \cdot \Delta x_0 \\ y_1 = b \cdot y_0 \\ \Delta y_1 = b \cdot \Delta y_0 \end{cases} โฉ โจ โง โ x 1 โ = b โ
x 0 โ ฮ x 1 โ = b โ
ฮ x 0 โ y 1 โ = b โ
y 0 โ ฮ y 1 โ = b โ
ฮ y 0 โ โ The real balances and virtual balances of the reserve after contribution are:
Real Balances
x = ( x 0 + x 1 ) + ( ฮ x 0 + ฮ x 1 ) = ( b + 1 ) โ
( x 0 + ฮ x 0 ) y = ( y 0 + y 1 ) + ( ฮ y 0 + ฮ y 1 ) = ( b + 1 ) โ
( y 0 + ฮ y 0 ) x = (x_0 + x_1) + (\Delta x_0 + \Delta x_1) = (b + 1) \cdot (x_0 + \Delta x_0) \\ y = (y_0 + y_1) + (\Delta y_0 + \Delta y_1) = (b + 1) \cdot (y_0 + \Delta y_0) x = ( x 0 โ + x 1 โ ) + ( ฮ x 0 โ + ฮ x 1 โ ) = ( b + 1 ) โ
( x 0 โ + ฮ x 0 โ ) y = ( y 0 โ + y 1 โ ) + ( ฮ y 0 โ + ฮ y 1 โ ) = ( b + 1 ) โ
( y 0 โ + ฮ y 0 โ ) Virtual Balances
x โฒ = a โ
( x 0 + x 1 ) + ( ฮ x 0 + ฮ x 1 ) = ( b + 1 ) โ
( a โ
x 0 + ฮ x 0 ) y โฒ = a โ
( y 0 + y 1 ) + ( ฮ y 0 + ฮ y 1 ) = ( b + 1 ) โ
( a โ
y 0 + ฮ y 0 ) x' = a \cdot (x_0 + x_1) + (\Delta x_0 + \Delta x_1) = (b + 1) \cdot (a \cdot x_0 + \Delta x_0) \\ y' = a \cdot (y_0 + y_1) + (\Delta y_0 + \Delta y_1) = (b + 1) \cdot (a \cdot y_0 + \Delta y_0) x โฒ = a โ
( x 0 โ + x 1 โ ) + ( ฮ x 0 โ + ฮ x 1 โ ) = ( b + 1 ) โ
( a โ
x 0 โ + ฮ x 0 โ ) y โฒ = a โ
( y 0 โ + y 1 โ ) + ( ฮ y 0 โ + ฮ y 1 โ ) = ( b + 1 ) โ
( a โ
y 0 โ + ฮ y 0 โ ) The constant product, after the LP contribution, becomes:
x โฒ โ
y โฒ = ( b + 1 ) 2 โ
( a โ
x 0 + ฮ x 0 ) โ
( a โ
y 0 + ฮ y 0 ) = ( b + 1 ) 2 โ
k โฒ x' \cdot y' = (b + 1)^2 \cdot (a \cdot x_0 + \Delta x_0) \cdot (a \cdot y_0 + \Delta y_0) = (b + 1)^2 \cdot k' x โฒ โ
y โฒ = ( b + 1 ) 2 โ
( a โ
x 0 โ + ฮ x 0 โ ) โ
( a โ
y 0 โ + ฮ y 0 โ ) = ( b + 1 ) 2 โ
k โฒ P m i n P_{min} P min โ and P m a x P_{max} P ma x โ at this time are:
{ P m i n = ( ( y 0 + y 1 ) โ
a โ ( y 0 + y 1 ) ) 2 ( b + 1 ) 2 โ
k โฒ = ( y 0 โ
a โ y 0 ) 2 k โฒ P m a x = ( b + 1 ) 2 โ
k โฒ ( ( x 0 + x 1 ) โ
a โ ( x 0 + x 1 ) ) 2 = ( x 0 โ
a โ x 0 ) 2 k โฒ \begin{cases} P_{min} = \cfrac{((y_0 + y_1) \cdot a - (y_0 + y_1))^2}{(b + 1)^2 \cdot k'} = \cfrac{(y_0 \cdot a - y_0)^2}{k'} \\ P_{max} = \cfrac{(b + 1)^2 \cdot k'}{((x_0 + x_1) \cdot a - (x_0 + x_1))^2} = \cfrac{(x_0 \cdot a - x_0)^2}{k'} \end{cases} โฉ โจ โง โ P min โ = ( b + 1 ) 2 โ
k โฒ (( y 0 โ + y 1 โ ) โ
a โ ( y 0 โ + y 1 โ ) ) 2 โ = k โฒ ( y 0 โ โ
a โ y 0 โ ) 2 โ P ma x โ = (( x 0 โ + x 1 โ ) โ
a โ ( x 0 โ + x 1 โ ) ) 2 ( b + 1 ) 2 โ
k โฒ โ = k โฒ ( x 0 โ โ
a โ x 0 โ ) 2 โ โ The current price is updated to be P = y โฒ x โฒ = ( a โ
y 0 + ฮ y 0 ) โ
( b + 1 ) ( a โ
x 0 + ฮ x 0 ) โ
( b + 1 ) = a โ
y 0 + ฮ y 0 a โ
x 0 + ฮ x 0 P = \cfrac{y'}{x'} = \cfrac{(a \cdot y_0 + \Delta y_0) \cdot (b + 1)}{(a \cdot x_0 + \Delta x_0) \cdot (b + 1)} = \cfrac{a \cdot y_0 + \Delta y_0}{a \cdot x_0 + \Delta x_0} P = x โฒ y โฒ โ = ( a โ
x 0 โ + ฮ x 0 โ ) โ
( b + 1 ) ( a โ
y 0 โ + ฮ y 0 โ ) โ
( b + 1 ) โ = a โ
x 0 โ + ฮ x 0 โ a โ
y 0 โ + ฮ y 0 โ โ
We see that after LP contributes, the current price, P m i n P_{min} P min โ and P m a x P_{max} P ma x โ are unchanged. It is similar in the case of LPs withdrawals, where the ratio b b b is negative.
Example
Initially, the first LP put 100 X X X and 100 Y Y Y to the reserve, we have: x = 100 , y = 100 , ฮ x = 0 , ฮ y = 0 x = 100, y = 100, \Delta x = 0, \Delta y = 0 x = 100 , y = 100 , ฮ x = 0 , ฮ y = 0 .
A user trades 20 X for 15 Y, so we have the updated parameters: x = 100 , y = 100 , ฮ x = 20 , ฮ y = โ 15 x = 100, y = 100, \Delta x = 20, \Delta y = โ15 x = 100 , y = 100 , ฮ x = 20 , ฮ y = โ 15 .
Suppose an LP wants to contribute 20% of the current token amounts in the pool, so he should deposit:
0.2 โ
100 + 0.2 โ
20 = 24 ( X ) 0.2 โ
100 + 0.2 โ
( โ 15 ) = 17 ( Y ) 0.2 ยท 100 + 0.2 ยท 20 = 24 (X) \\ 0.2 ยท 100 + 0.2 ยท (โ15) = 17 (Y) 0.2 โ
100 + 0.2 โ
20 = 24 ( X ) 0.2 โ
100 + 0.2 โ
( โ 15 ) = 17 ( Y ) ie. deposit 24X and 17Y tokens.
The parameters are then updated to be: x = 120 x = 120 x = 120 , y = 120 y = 120 y = 120 , ฮ x = 24 \Delta x = 24 ฮ x = 24 , ฮ y = โ 18 \Delta y = โ18 ฮ y = โ 18 .