1

I'm quite a rookie in using the uniswap API.

What I have is the following. Let's say I want to know how much WETH I need to 100 dydx tokens

amountOut = BigInt(100).toString()
let result = await _routerPath[0].getAmountsIn(amountOut, [_token0.address, _token1.address])  

What I get as a result is 1 for WETH.

However, when I use the Uniswap UI I get 0.15225.

Why is this happening?

1 Answer 1

0

Uniswap smart contract functions, including getAmountsIn, expect their arguments to be passed in the smallest units of the token. The DYDX token has 18 decimals, so effectively your code is asking to swap 100 * 1e-18 or in other words 0.0000000000000001 DYDX tokens for WETH. Since WETH also has decimals, the results may look reasonable, but still be quite different from the case when 100 DYDX tokens are swapped, due to rounding errors and the reduced price impact.

1
  • Yeah, I figured it out shortly after. Thank you.
    – iliev951
    Commented Mar 21, 2023 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.