Skip to content

Unbalanced liquidity affects prices #143

@Jeiwan

Description

@Jeiwan

Hello 👋

The mint function in UniswapV2Pair allows to deposit unbalanced amounts of tokens. I.e., if current ratio of reserves is 1:1, nothing forbids depositing amounts in ratio 1:2. To properly calculate the amount of LP tokens issued in such situations, Math.min is used:

liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);

However, both deposited amounts are then saved to reserves:

_update(balance0, balance1, _reserve0, _reserve1);

reserve0 = uint112(balance0);
reserve1 = uint112(balance1);

As a result, prices get changed. Is this intentional? I have always thought that prices can only be changed via trading.

It also looks like that due to the Math.min usage, total amount LP tokens doesn't reflect reserves. Why not taking an average of amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions