Bridge Example

This is a simple bridge request (without invoking swap on the source chain) example

Please note that directly interacting with the smart contract means your bridge request may not be completed on the destination 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 are going to bridge 100 USDT from Ethereum to Polygon.

The function we're going interact with is the swapWithReferrer of the YBridge on Ethereum.

From Integrate YBridge Contract, we can find the interface of swapWithReferrer:

function swapWithReferrer(
    address aggregatorAdaptor,
    IDexAggregatorAdaptor.SwapDescription memory swapDesc,
    bytes memory aggregatorData,
    DstChainDescription calldata dstChainDesc

There are four parameters we need to prepare: - aggregatorAdaptor - swapDesc - aggregatorData - dstChainDesc


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


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.


struct SwapDescription {
    IERC20 srcToken;
    IERC20 dstToken;
    address receiver;
    uint256 amount;
    uint256 minReturnAmount;

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 srcToken and dstToken should be the address of USDT on Ethereum, which is 0xdAC17F958D2ee523a2206206994597C13D831ec7.

The receiver is the one who's going to receive the USDT on destination 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.


struct DstChainDescription {
    uint32 dstChainId;
    IERC20 dstChainToken;
    uint256 expectedDstChainTokenAmount;
    uint32 slippage;

As for DstChainDescription, it describes what should be achieved on the destination chain.

The dstChainId is the ID of the destination chain, 137 in this case.

The dstChainToken represents the desired token on the destination chain, the USDT address on Polygon in this case, which is 0xc2132D05D31c914a87C6611C10748AEb04B58e8F

The expectedDstChainTokenAmount will be used for the swap on the destination 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 expectedDstChainTokenAmount and it's as well only used when a swap is happening on the destination 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:

    0x0000000000000000000000000000000000000000, // aggregatorAdaptor
    (0xdAC17F958D2ee523a2206206994597C13D831ec7, 0xdAC17F958D2ee523a2206206994597C13D831ec7, receiver, 100000000, 100000000), // swapDesc
    0x, // aggregatorData
    (137, 0xc2132D05D31c914a87C6611C10748AEb04B58e8F, 100000000, 0) // dstChainDesc

Check on the Destination 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 a swap request is processed or not on the destination chain by invoking getEverClosed(_srcChainId, _srcChainSwapId).

If you are looking for more details of the request such as the amount, you should monitor the SwappedForUser event emitted from the YBridge on the destination chain.

See more of events and functions of YBridge here. See addresses of YBridge across all chains here.

Last updated