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

Incorrect calculation of "Minimum received after slippage" #6206

Open
mazurroman opened this issue Mar 21, 2023 · 1 comment
Open

Incorrect calculation of "Minimum received after slippage" #6206

mazurroman opened this issue Mar 21, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@mazurroman
Copy link

Bug Description
From the Uniswap's docs:

If your slippage is set too high, then you may get less tokens than expected when swapping. For example, if your slippage is set to 25%, then you may receive 25% less than the expected swap outcome (tokens) that is shown to you in the swap preview.

This confirms how slippage should be calculated. However, this is not the case in the current Uniswap app and Uniswap widget. What actually happens is that the app calculates 25% of the execution price instead of the expected price.

Steps to Reproduce

  1. Go to uniswap.exchange
  2. Input swap from 1000 USDC to 1000 DAI and set slippage to 25%
  3. Notice the minimum amount out is 800 DAI, which is 20% less than expected price

Expected Behavior

  1. Go to uniswap.exchange
  2. Input 1000 USDC to 1000 DAI and set slippage to 25%
  3. Notice the minimum amount out is 750 DAI, which is 25% less than expected price

Additional Context
uniswap-slippage-bug

@mazurroman mazurroman added the bug Something isn't working label Mar 21, 2023
@Jdecristi
Copy link
Contributor

Jdecristi commented May 13, 2023

@mazurroman After some digging, the issue resides in the @uniswap/router-sdk. The issue is that the math, is supposed to be "outputAmount * (1 - slippageTolerance)" However, it is "1 + slippageTolerance / 1 * outputAmount" which is producing the wrong amount.

I've made an issue Issue #43 and fixed in PR #44 in the router-sdk repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants