Submitted by WatchPug
Per the document: https://github.com/ElasticSwap/elasticswap/blob/a90bb67e2817d892b517da6c1ba6fae5303e9867/ElasticSwapMath.md#:~:text=When%20there%20is%20alphaDecay
and related code: https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L227-L283
Gamma is the ratio of shares received by the new liquidity provider when addLiquidity() (Ro) to the new totalSupply (total shares = Ro = Ro + Ro).
In the current implementation:
Y is the quoteToken added by the new liquidity provider. See:
Y is the new Y after addLiquidity(), Y' = Y + Y. See:
X is Y * Omega. See:
^ is Alpha - X. See:
For instance:
Given:
When: new liquidity provider addLiquidity() with 4 quoteToken:
After addLiquidity():
As a result, the new liquidity provider suffers a fund loss of 4 - 240 / 90 = 1.3333333333333333 in the terms of quoteToken
The case above can be reproduced by changing the numbers in this test unit.
Per the document: https://github.com/ElasticSwap/elasticswap/blob/a90bb67e2817d892b517da6c1ba6fae5303e9867/ElasticSwapMath.md#:~:text=When%20there%20is%20betaDecay
and related code: https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/libraries/MathLib.sol#L297-L363
Gamma is the ratio of shares received by the new liquidity provider when addLiquidity() (Ro) to the new totalSupply (total shares = Ro = Ro + Ro).
In the current implementation:
X is the amount of baseToken added by the new liquidity provider. See:
X is the balanceOf baseToken. See:
XByQuoteTokenAmount is X / Omega, the value of X in the terms of quoteToken. See:
^ is maxX / Omega, the value of maxX in the terms of quoteToken. maxX = X - Alpha. See:
For instance:
Given:
When: new liquidity provider addLiquidity() with 4 baseToken
After addLiquidity():
As a result, the new liquidity provider suffers a fund loss of 4 - 120 / 90 = 2.6666666666666665 in the terms of quoteToken
The case above can be reproduced by changing the numbers in this test unit.
See issue page for details.
Update code and document using the correct formula for Ro.
0xean (ElasticSwap) confirmed and commented:
Alex the Entreprenerd (judge) commented:
0xean (ElasticSwap) resolved
