Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbalanced liquidity affects prices #143

Open
Jeiwan opened this issue Dec 24, 2021 · 3 comments
Open

Unbalanced liquidity affects prices #143

Jeiwan opened this issue Dec 24, 2021 · 3 comments

Comments

@Jeiwan
Copy link

Jeiwan commented Dec 24, 2021

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?

@ghost
Copy link

ghost commented Dec 31, 2023

Yes it is intentional, you can also make a swap without transferring a pair token.

@pegahcarter
Copy link

This is a bug as the depositor receives the minimum amount of LP tokens and the Pair keeps the change. So, if we had a pair where reserve0 == reserve1, I could deposit a small amount of token0 and a large amount of token1, receive LP tokens based on my token0 amount, and the token1 is stuck in the pair (and can be arb'd back to reserve0 == reserve1.

@borseno
Copy link

borseno commented Sep 30, 2024

It's not really a bug, but a design choice based on game theory. If we assume that the depositor is rational, they would deposit an equal value of tokens. Otherwise they get punished. The other LPs shouldn't really be punished for that too, they can take away the difference. The main point is to punish bad actors who supply irrational ratio of liquidity. Correct me if I'm wrong :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants