Uniswap liquidity shares(流动性代币份额)

Uniswap v2 initially mints shares equal to the geometric mean of the amounts deposited:

s_minted =sqrt(x_deposited · y_deposited)

This formula ensures that the value of a liquidity pool share at any time is essentially independent of the ratio at which liquidity was initially deposited. For example, suppose that the price of 1 ABC is currently 100 XYZ. If the initial deposit had been 2 ABC and 200 XYZ (a ratio of 1:100), the depositor would have received √(2 · 200) = 20 shares. Those shares should now still be worth 2 ABC and 200 XYZ, plus accumulated fees. If the initial deposit had been 2 ABC and 800 XYZ (a ratio of 1:400), the depositor would have received √(2 · 800) = 40 pool shares.

The above formula ensures that a liquidity pool share will never be worth less than the geometric mean of the reserves in that pool. However, it is possible for the value of a liquidity pool share to grow over time, either by accumulating trading fees or through “donations” to the liquidity pool. In theory, this could result in a situation where the value of the minimum quantity of liquidity pool shares (1e-18 pool shares) is worth so much that it becomes infeasible for small liquidity providers to provide any liquidity.

To mitigate this, Uniswap v2 burns the first 1e-15 (0.000000000000001) pool shares that are minted (1000 times the minimum quantity of pool shares), sending them to the zero address instead of to the minter. This should be a negligible cost for almost any token pair.11 But it dramatically increases the cost of the above attack. In order to raise the value of a liquidity pool share to $100, the attacker would need to donate $100,000 to the pool, which would be permanently locked up as liquidity.

第一个流动性提供者获得的 pool shares 是 充入代币数量的几何平均数,即充入代币数量的乘机的平方根

如 第一个流动性提供者充入10ETH+1000ABC,那么获得的 pool shares 是 sqrt(10*1000)=100。

如果第二个人又充入 1ETH+100ABC,他能获得多少 pool shares 呢?

官网提供的这个图,我一度怀疑是不是他们搞错了。。。

首先,第一点,费率应该是 0.3%;因此,交换方(Trader)充入10A,除去0.03A的fee,实际充入9.97A,可获得 10 - 100*10/(100+9.97) = 10 - 9.0934 = 0.9066B; 也就是 Output = 0.9066 B。池子里新的储存值是 109.97A+ 0.03A + 9.0934B =110A+9.0934B。

其次,加入 100A+10B 是第一个流动性提供者充入的代币,那么他可以获得的 pool shares 应该是 sqrt(100 * 10)=31.623, Liquidity Provider 充入 10A+1B ,池子里新的储存值就是 110A+11B。如果把这个状态(有了新的流动资金充入而变成110A+11B的pool)看做一个整体,那么 新的pool shares总额就应该是 sqrt(110 * 11)=34.785。给到该 Liquidity Provider 的 pool shares 就应该是 34.785-31.623=3.162。即 Output = 3.162 pool shares。

3.162/34.785100%=9.09%, 而 10/110100%=9.09%。也就是流动性提供者充入的资金在整个pool中所占的份额,和他能获得的pool token数在整个pool tokens中的比例是相同的。

总结:任何时候,pool tokens 总额 = Unisawap Pool 中代币数量的几何平均数。 即 pool-token_amount = sqrt(TokenA_amount * TokenB_amount)

对于一个新的 Liquidity Provider,其获得的 pool token 数量是:

sqrt[(TokenA_reserve-amount + TokenA_deposit-amount) * (TokenB_reserve-amount + TokenB_ deposit-amount)] - sqrt(TokenA_reserve-amount * TokenB_reserve-amount)