Skip to content

getMaxSwapAmount #79

@johngrantuk

Description

@johngrantuk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions