There are some conditions when adding liquidity to the DMM:
- After LP contributions, the token price is unchanged.
- Pminโ and Pmaxโ are also unchanged after LP contributions.
In the DMM, the pool for pair X-Y needs to maintain 4 parameters:
- The initial amount of token X that is used for amplification, denoted by x0โ
- The initial amount of token Y that is used for amplification, denoted by y0โ
- The change in token X amount after trading activities, denoted by ฮx0โ
- The change in token Y amount after trading activities, denoted by ฮy0โ
Therefore, the real balances and virtual balances of the reserves are:
Real Balances
x=x0โ+ฮx0โy=y0โ+ฮy0โ Virtual Balances
xโฒ=aโ
x0โ+ฮx0โyโฒ=aโ
y0โ+ฮy0โ where a is the amplification factor. You may find more information about the amplification factor here.
The constant product xโฒโ
yโฒ=(aโ
x0โ+ฮx0โ)โ
(aโ
y0โ+ฮy0โ)=kโฒ. Note that Pminโ and Pmaxโ at this time are:
โฉโชโชโชโชโชโจโชโชโชโชโชโงโPminโ=kโฒ(y0โโ
aโy0โ)2โPmaxโ=(x0โโ
aโx0โ)2kโฒโโ The current price: P=xโฒyโฒโ=aโ
x0โ+ฮx0โaโ
y0โ+ฮy0โโ
Liquidity Providers have to contribute in the same proportion for all 4 amount types. We denote the contribution ratio to be b. LPs have to contribute x1โ+ฮx1โ, y1โ+ฮy1โ in which:
โฉโชโชโชโชโจโชโชโชโชโงโx1โ=bโ
x0โฮx1โ=bโ
ฮx0โy1โ=bโ
y0โฮy1โ=bโ
ฮy0โโ The real balances and virtual balances of the reserve after contribution are:
Real Balances
x=(x0โ+x1โ)+(ฮx0โ+ฮx1โ)=(b+1)โ
(x0โ+ฮx0โ)y=(y0โ+y1โ)+(ฮy0โ+ฮy1โ)=(b+1)โ
(y0โ+ฮy0โ) Virtual Balances
xโฒ=aโ
(x0โ+x1โ)+(ฮx0โ+ฮx1โ)=(b+1)โ
(aโ
x0โ+ฮx0โ)yโฒ=aโ
(y0โ+y1โ)+(ฮy0โ+ฮy1โ)=(b+1)โ
(aโ
y0โ+ฮy0โ) The constant product, after the LP contribution, becomes:
xโฒโ
yโฒ=(b+1)2โ
(aโ
x0โ+ฮx0โ)โ
(aโ
y0โ+ฮy0โ)=(b+1)2โ
kโฒ Pminโ and Pmaxโ at this time are:
โฉโชโชโชโจโชโชโชโงโPminโ=(b+1)2โ
kโฒ((y0โ+y1โ)โ
aโ(y0โ+y1โ))2โ=kโฒ(y0โโ
aโy0โ)2โPmaxโ=((x0โ+x1โ)โ
aโ(x0โ+x1โ))2(b+1)2โ
kโฒโ=kโฒ(x0โโ
aโx0โ)2โโ The current price is updated to be P=xโฒyโฒโ=(aโ
x0โ+ฮx0โ)โ
(b+1)(aโ
y0โ+ฮy0โ)โ
(b+1)โ=aโ
x0โ+ฮx0โaโ
y0โ+ฮy0โโ
We see that after LP contributes, the current price, Pminโ and Pmaxโ are unchanged. It is similar in the case of LPs withdrawals, where the ratio b is negative.
Example#
Initially, the first LP put 100 X and 100 Y to the reserve, we have:
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.
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)
ie. deposit 24X and 17Y tokens.
The parameters are then updated to be:
x=120, y=120, ฮx=24, ฮy=โ18.