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

getMaxSwapAmount #79

Open
johngrantuk opened this issue Dec 6, 2024 · 0 comments
Open

getMaxSwapAmount #79

johngrantuk opened this issue Dec 6, 2024 · 0 comments

Comments

@johngrantuk
Copy link
Member

As reported by PS:

So, for now logic to calculate max possible outcome (for BUY) is:

  1. get 99% of the balance
  2. divide this balance by scalingFactor and tokenRate

It works fine for most of the cases, but not when we do:

  1. Unwrap
  2. Swap
  3. Wrap

e.g. let's consider BUY 9 USDT for USDC (in backwards order as it's BUY):

  1. Unwrap (9 USDT tokens <- 6.68 stataUSDT; tokenRate is 1.34)
  2. Swap (6.68 stataUSDT <- 7.5 stataUSDC)
  3. Wrap (7.5 stataUSDC <- 9.0 USDC, tokenRate is 1.2 )

As an end result, we can spent up to 9.0 of USDC tokens to buy 9 USDT tokens.

but, in getMaxSwapAmount we calculate:

  1. 11.01 (max available balance) * 0.99 = 11.01
  2. 11.01 / 1 (scaling factor) * 1.34 (USDT token rate) = 8.18 USDT

So, even though we can see that it's possible to buy 9 USDT, getMaxSwapAmount returns 8.18 USDT

It's not a big problem, as it occurs only on the numbers that are close to the max available balance, but still I found it's important to let you know

Simulation: https://www.tdly.co/shared/simulation/a1c4985f-2920-4039-b607-c072bc0cda95

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

1 participant