-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
As reported by PS:
So, for now logic to calculate max possible outcome (for BUY) is:
- get 99% of the balance
- divide this balance by scalingFactor and tokenRate
It works fine for most of the cases, but not when we do:
- Unwrap
- Swap
- Wrap
e.g. let's consider BUY 9 USDT for USDC (in backwards order as it's BUY):
- Unwrap (9 USDT tokens <- 6.68 stataUSDT; tokenRate is 1.34)
- Swap (6.68 stataUSDT <- 7.5 stataUSDC)
- 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:
- 11.01 (max available balance) * 0.99 = 11.01
- 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
Metadata
Metadata
Assignees
Labels
No labels