niftyswap icon indicating copy to clipboard operation
niftyswap copied to clipboard

N8 - Minted liquidity tokens can round to zero

Open PhABC opened this issue 5 years ago • 4 comments

image

PhABC avatar Feb 10 '20 21:02 PhABC

How could it round to zero? I haven't found a scenario where this could happen.

@Agusx1211 (with the new divRound approach).

PhABC avatar Feb 12 '20 02:02 PhABC

This is the ultimate edge case... but here it goes:

  • A pool exists with base = 1000, tokens = 2000, totalSupply = 500
  • An user adds 1 token, proportional base is 1 base
  • Minted liquidity tokens rounds to 0, because (1 * 500) / 1000 == 0

The new divRound makes the minting formula (0 * 500) / 1000 == 0, the example still works

Agusx1211 avatar Feb 16 '20 03:02 Agusx1211

Right, I see, though if we changed that, the owner of the 500 initial liquidity tokens would lose some, as per https://github.com/arcadeum/niftyswap/issues/19.

For instance, User A adds 1 token (and 1 base), and get 1 Liquidity Token.

Pools are now base == 1001, tokens == 2001, liquidity == 501.

User A burns 1 liquidity to get back Base : 1 (1 == 1 * 1001 / 501) Tokens: 3 (3 == 1 * 2001 / 501)

And made a 2 tokens profit at the cost of initial liquidity provider. If we round up, we have to take some tokens from the existing liquidity providers and if we round down, the new liquidity provider loses some tokens, favoring existing liquidity providers. I think not hurting existing liquidity providers is more important.

What do you think?

PhABC avatar Feb 17 '20 23:02 PhABC

I think not hurting existing liquidity providers is more important. I agree; all formulas that require rounding should favor them.

Maybe a simple way of fixing this issue is adding a require(minted != 0) or adding a minimumMinted as a parameter on the addLiquidity method.

Agusx1211 avatar Feb 26 '20 08:02 Agusx1211