To guarantee the safety of the pool, there are some conditions which need to be fulfilled when adding liquidity to KyberSwap Classic pools:
After LP contributions, the token price remains unchanged.
Pmin and Pmax are also unchanged after LP contributions.
In KyberSwap, 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+Δx0y=y0+Δy0
Virtual Balances
x′=a⋅x0+Δx0y′=a⋅y0+Δy0
where a is the amplification factor.
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)2Pmax=(x0⋅a−x0)2k′
The current price: P=x′y′=a⋅x0+Δx0a⋅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 in which:
⎩⎨⎧x1=b⋅x0Δx1=b⋅Δx0y1=b⋅y0Δy1=b⋅Δy0
The real balances and virtual balances of the reserve after contribution are:
The current price is updated to be P=x′y′=(a⋅x0+Δx0)⋅(b+1)(a⋅y0+Δy0)⋅(b+1)=a⋅x0+Δx0a⋅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.