Exchange
Exchange contract is factory that processing user swap with particular exchange adapter. In general exchange call looks like:
Each adapters has it's own realization of swap (depends on DEX interfaces) but all of them implement the same interface for factory.
To swap tokens through factory we should call method swap()
of Exchange contract:
Parameters:
aggregatorId
- for now it's 4 possible options for this field:SaucerSwapV1
SaucerSwapV2
Pangolin
HeliSwap
Choose the one which DEX you want to use for swap.
path
special way encoded swap route. Could be different depending on particular provider. Value can be retrieved from API.amountFrom
andamountTo
. Amounts of tokens to swap in coins. Each token has different amount of decimals, for example if you want to swap 1 GRELF to your account, which has 8 decimals - you need to provideamountFrom=100000000
.deadline
- this is "rudiment" of porting DEXes from ethereum network, because on ethereum transactions can wait large amount of time before execution (with different gas strategy). On Hedera most of all transactions processed in 4 seconds. Value of this field should be 10 digits timestamp. Just make sure this timestamp > current date. For example on Javascript you can use this snippet to calculatedeadline
:
isTokenFromHBAR
. True if you swapping HBAR to something, otherwise false.feeOnTransfer
. This parameter regulate which token to apply slippage. If you want to apply slippage to tokenTo (it means you swap exact amount oftokenFrom
to variable amount oftokenTo
) - you need to passfalse
, otherwise (it means you want to receive exact amount oftokenTo
using variable amount oftokenFrom
- passtrue
. If you want more explanation about AMM basics and slippage - proceed by this link: https://academy.binance.com/en/articles/what-is-an-automated-market-maker-amm
Also there is one more useful readonly function on Exchange smart-contract:
This function returns current EtaSwap fee for particular aggregator. Returned value dimension - is promille. For example if function return 1 - it means EtaSwap fee is 0.1%.
Last updated