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.
Integration Notice
Before starting the integration, please note the following points for your input parameters:
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
Use
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
as the address for the native token in your parameter.
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
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.
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%).
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 be0x0000000000000000000000000000000000000000
aggregatorData
should be0x
singleChainSwapWithReferrer
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.
The aggregatorData
is generated by server containing source chain part of best routing path.
View Functions
getEverClosed
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
Get balance of an account of a token.
Events
System Setting Related Events
StartSwapIdSet
This event will be emitted when the starting swap ID is set.
YBridgeVaultSet
This event will be emitted when a yBridge Vault (liquidity pool) is set.
AggregatorAdaptorSet
This event will be emitted when an aggregator adaptor is set.
AggregatorSet
This event will be emitted when an aggregator is set.
AcceptSwapRequestSet
This event will be emitted when the acceptSwapRequest is set. If true, yBridge accepts swap request.
User Related Events
SwapRequested
This event will be emitted whenever a cross-chain swap request is initiated.
AggregatorSwapped
This event will be emitted whenever a same-chain swap is completed.
CloseSwapCompleted
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
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
This event will be emitted when a request is refunded on the source chain.
Last updated