FxEVM smart-contracts

Hi @lancelai or anyone else !

I’m having a hard time finding how to quote (programmatically) a swap between a pair of currencies using the currently deployed smart contracts ? What I’m trying to do is getting the amount of the second currency when providing the amount of the first…

Could you point me toward a method of an existing FXSwap EVM smart-contract ?

Thanks !


1 Like

You need to get both tokens smart-contract addresses…
For example, for WFX-USDT, you get:

Then, you need to use getReserves method of the pair smart-contract address (like WFX-USDT pair), and you get a Tuple3 (Note that the pair smart-contract address is a KECCAK256 calculation of both tokens smart-contract addresses).
Then, you apply the following algorithm:

pairDecimals = token1Decimals - token2Decimals;
valueOfToken1InToken2 = pairDecimals > 0 ?
    Tuple3Component1.divide(Tuple3Component2).movePointLeft(pairDecimals) :
valueOfToken2InToken1 = -pairDecimals > 0 ?
    Tuple3Component2.divide(Tuple3Component1).movePointLeft(pairDecimals) :

This gives you the current prices of Token1/Token2 and Token2/Token1 (without taking into account the LP fee).