(Legacy) Bridge Example
This is a simple bridge request (without invoking swap) example
Please note that directly interacting with the smart contract means your bridge request may not be completed on the target chain since you are initiating a request regardless of the liquidity on the other side. If unfortunately you found your transaction hasn't been processed for more than 30 minutes, please contact us via telegram or discord!
See more detail of available liquidity.
In this example, we try to bridge 100 USDT from Ethereum to Polygon.
The function we're going interact with is the swap
of the XSwapper
on Ethereum.
From (Legacy) Integrate X Swap Contract we can find the interface of swap
:
There are four parameters we need to prepare:
- aggregatorAdaptor
- swapDesc
- aggregatorData
- toChainDesc
aggregatorAdaptor
Since we're just bridging USDT
, no swap actions would be involved. That is, we don't need aggregator and so is its adaptor aggregatorAdaptor
. In this kind of situation aggregatorAdaptor
should be 0x0000000000000000000000000000000000000000
aggregatorData
Normally, we put the data that is going to be executed by the aggregator to this field. However in this case we're not going to swap tokens, so the aggregatorData
we put is 0x
.
swapDesc
A SwapDescription
describes the swap happening on the source chain. In this case, we don't need to swap USDT to something else so both the fromToken
and toToken
should be the address of USDT on Ethereum, which is 0xdAC17F958D2ee523a2206206994597C13D831ec7
.
The receiver
is the one who's going to receive the USDT on target chain (Polygon).
The amount
is the swap amount with padding zeroes. In this case it should be 100000000
since the decimals of USDT on Ethereum is 6
.
The minReturnAmount is used to make sure the return amount of the swap happening on the source chain. In this case we could just put the same amount as amount
.
toChainDesc
As for ToChainDescription
, it describes what should be achieved on the target chain.
The toChainId
is the ID of the target chain, 137
in this case.
The toChainToken
represents the desired token on the target chain, the USDT address on Polygon in this case, which is 0xc2132D05D31c914a87C6611C10748AEb04B58e8F
The expectedToChainTokenAmount
will be used for the swap on the target chain. To keep it simple, we could put the same value as the amount of the swapDesc
. In this case it would be 100000000
since the decimals of Polygon USDT is also 6
.
However, please note that the amount you're going to received will be a bit less owing to the XY Fee.
The slippage
will be used to calculate the minimum received amount from expectedToChainTokenAmount
and it's as well only used when a swap is happening on the target chain. In this case, again, there's no swap involved therefore we put 0
in this field.
To Sum up
The parameters we need to bridge 100 USDT from Ethereum to Polygon would look like:
Check on the Target Chain
After sending a swap request from the source chain, we can get the SwapRequested event from logs. The _swapId
in the event is the ID of the swap request. We can check whether the swap request is processed or not on the target chain by invoking getEverClosed(
_srcChainId, _swapId)
.
If you are looking for more details of the request such as the amount, you should monitor the SwappedForUser event emitted from the XSwapper
on the target chain.
See more of events and functions of XSwapper
here.
See addresses of XSwapper
across all chains here.
Last updated