Swapping different ERC20 tokens with different decimals


I was wondering how to handel ERC20 tokens with different decimals. I want for example swap two tokens:

  1. Token 1, 18 decimals
  2. Token 2, 9 decimals

If I want to swap these and I would pass the value 1 in Wei for bot token:

1 000 000 000 000 000 000 (18 decimals, Token1)
1 000 000 000 (9 decimals, Token2)

Is that correct or should both values 18 decimal?

Yes, that is correct. The invariant constant K will take care of it.

1 Like

Are you asking about swapping in an AMM DEX? Or implementing your own code?

AMM DEX, correct. I need the correct decimals. I just used the data from Pancakeswap to test it