0

I have two tokens, tokenA which has a decimal value of 18 and tokenB with 9 decimals. I would like to buy tokenB for tokenA or vica-versa. The question is that do I need to make any conversions with the wei values because the different decimals in Solidity? I know that decimals are important when we convert from wei to ether for instance, but if I keep both token amounts in wei, I assume the below calculation will be correct without managing the two amount variable differently.

// calculating the output amount of DAI for X ETH
address[] memory path;
path[0] = token18Dec; // ETH
path[1] = token9Dec; // DAI token with 9 decimals
amounts = uniswapRouter.getAmountsOut(ethBudget, path)[1];

// calculating the output amount of ETH for X DAI address[] memory path; path[0] = token9Dec; // ETH path[1] = token18Dec; // DAI token with 9 decimals amounts = uniswapRouter.getAmountsOut(daiTokenBalance, path)[1];

rihekopo
  • 316
  • 1
  • 12

1 Answers1

0

Yes, you should convert both to the Wei as solidity by default deals any integer as in Wei