Integrate YBridge Contract

XY Finance deploys smart contracts on most mainstream chains and benefits all types of users in terms of secure cross-chain swaps.

The dstChainId must be one of the chains supported by yBridge. If your dstChainId is not supported by yBridge, the funds may be temporarily locked in the system. you could use Supported Blockchains to get latest list

yBridge

State-Changing Functions

Here are two state-changing functions provided by our YBridge Contract:

  • swapWithReferrer: The function itself offers a service that combines bridge and destination chain swap. However, please note that the destination chain swap is intended for internal use. Nevertheless, you can perform a bridge request through this function. For more details, you can refer to the (Legacy) Bridge Example

  • singleChainSwapWithReferrer: This function is also intended for internal use. If you require a same chain swap function, you may consider using services such as 1inch or OpenOcean.

swapWithReferrer

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

Initiate a cross-chain request and execute desired source chain side swap and leave a record of the referrer. Please contact us for more information about referral program.

The swapDesc contains the information of the source chain side swap.

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

The dstChainDesc would be emitted in event to record destination chain swap path and slippage. Note that the slippage would be seen as BP (1223 slippage equals to 12.23%).

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

The aggregatorAdaptor is to adapt to the DEX aggregator involved in the aggregatorData.

The aggregatorData is generated by server containing source chain part of best routing path.

If you simply want to bridge, please follow the guidelines below to fill in the parameters for aggregatorAdaptor and aggregatorData

  • aggregatorAdaptor should be 0x0000000000000000000000000000000000000000

  • aggregatorData should be 0x

singleChainSwapWithReferrer

function singleChainSwapWithReferrer(
    address aggregator,
    IDexAggregatorAdaptor.SwapDescription memory swapDesc,
    bytes memory aggregatorData,
    address referrer
)

Execute a same-chain swap and leave a record of the referrer. Please contact us for more information about referral program.

The aggregator is the DEX aggregator involved in the aggregatorData.

The swapDesc contains the information of the swap.

struct SwapDescription {
    IERC20 fromToken;
    IERC20 toToken;
    address receiver;
    uint256 amount;
    uint256 minReturnAmount;
}

The aggregatorData is generated by server containing source chain part of best routing path.

View Functions

getEverClosed

function getEverClosed(uint32 _srcChainId, uint256 _srcChainSwapId) returns (bool)

Check whether a swap request is closed (processed) on destination chain by the swap ID on the source chain and the source chain ID.

getTokenBalance

function getTokenBalance(IERC20 _token, address _account) returns (uint256)

Get balance of an account of a token.

Events

StartSwapIdSet

event StartSwapIdSet(uint256 _swapId);

This event will be emitted when the starting swap ID is set.

YBridgeVaultSet

event YBridgeVaultSet(address _supportedToken, address _vault, bool _isSet);

This event will be emitted when a yBridge Vault (liquidity pool) is set.

AggregatorAdaptorSet

event AggregatorAdaptorSet(address _aggregator, bool _isSet);

This event will be emitted when an aggregator adaptor is set.

AggregatorSet

event AggregatorSet(address _aggregator, bool _isSet);

This event will be emitted when an aggregator is set.

AcceptSwapRequestSet

event AcceptSwapRequestSet(bool _isSet);

This event will be emitted when the acceptSwapRequest is set. If true, yBridge accepts swap request.


SwapRequested

event SwapRequested(uint256 _swapId, address indexed _aggregatorAdaptor, DstChainDescription _dstChainDesc, IERC20 _srcToken, IERC20 indexed _vaultToken, uint256 _vaultTokenAmount, address _receiver, uint256 _srcTokenAmount, uint256 _expressFeeAmount, address indexed _referrer);

This event will be emitted whenever a cross-chain swap request is initiated.

AggregatorSwapped

event AggregatorSwapped(address indexed aggregator, address sender, IERC20 srcToken, IERC20 dstToken, address receiver, uint256 srcTokenAmount, uint256 dstTokenAmount, address indexed referrer);

This event will be emitted whenever a same-chain swap is completed.

CloseSwapCompleted

event CloseSwapCompleted(CloseSwapResult _swapResult, uint32 _srcChainId, uint256 _srcChainSwapId);

This event will be emitted by the time all a cross-chain swap request is processed at the destination chain so as to keep a record of the request.

SwappedForUser

event SwappedForUser(address indexed _aggregatorAdaptor, IERC20 indexed _srcToken, uint256 _srcTokenAmount, IERC20 _dstToken, uint256 _dstTokenAmountOut, address _receiver);

This event will be emitted also by the time all a cross-chain swap request is processed at the destination chain. However, this event records more information of the swap details than the CloseSwapCompleted event.

SwapRefunded

event SwapRefunded(uint256 _swapId, address _receiver, address _gasFeeReceiver, address _vaultToken, uint256 _refundAmount, uint256 _refundGasFee);

This event will be emitted when a request is refunded on the source chain.

Last updated