XY Finance
  • Getting Started
  • XY Token
  • Supported Blockchains/Bridges/DEXs
  • Fee Structure
    • 🌉yBridge Fee Information
    • 🌉(Legacy) XY Bridge Fee Information
  • products
    • Bridge Aggregator : XY Finance
      • Gasless Transaction
    • Bridge : yBridge
      • Yield Farming
      • Omnichain Settlement
      • Consensus
    • Refuel
    • Proxy Bridge
    • Cross Chain Infrastructure
  • Bridge Aggregator Integration
    • XY Finance API (Multiple Bridges Aggregator)
      • 1️⃣Get Quote
      • 2️⃣Get Allowance
      • 3️⃣Build Approval Transaction
      • 4️⃣Build Swap Transaction
      • 5️⃣Get Cross-Chain Status
      • 6️⃣Get MinimumSwapAmount
      • ✔️Recommended Tokens
      • ✅Supported Blockchains/Bridges/DEXs
      • 📩Error Message
      • 💰Monetization / Take Fees
      • 📄Change Log
    • XY Finance Widget (iframe)
      • (Legacy) XY Finance Widget (iframe)
    • XY Finance Widget (NPM)
      • 1️⃣Install the Widget
      • 2️⃣Configure the Widget
      • 3️⃣Customize the Theme
      • 📘Widget API Reference
      • 📄Change Log
    • Custom-Built Link
    • Token Listing
  • Single Bridge Integration
    • yBridge API
      • 1️⃣Get Quote
      • 2️⃣Get Allowance
      • 3️⃣Build Approval Transaction
      • 4️⃣Build Swap Transaction
      • 5️⃣Get Cross-Chain Status
      • 🚰Get Pool Liquidity
      • 💲Get Fee Structure
      • ✔️Recommended Tokens
      • ✅Supported Blockchains
      • 📩Error Message
      • 📄Change Log
    • yBridge Contract Integration
      • Integrate YBridge Contract
        • Bridge Example
        • Latest Upgrade ( 2024/07/17 )
        • Migrate from V2 to V3
      • Integrate YBridgeVault Contract
        • Maximum Available Liquidity
        • Migrate from V2 to V3
      • (Legacy) Integrate X Swap Contract
        • (Legacy) Bridge Example
      • (Legacy) Integrate Y Pool Contract
        • (Legacy) Maximum Available Liquidity
    • xAsset Bridge
      • How to Develop Under XY Standards
        • Function Interface for Token Contract
      • How to Deposit / Withdraw Liquidity
        • Direct Contract Interaction
        • Through the Explorer
      • Set up Your Own Validator
  • SMART CONTRACT
    • Addresses
      • Ethereum (chain id : 1)
      • BNB Chain (chain id : 56)
      • Polygon (chain id : 137)
      • Cronos (chain id : 25)
      • Avalanche (chain id : 43144)
      • Kucoin Community Chain (chain id : 321)
      • Arbitrum (chain id : 42161)
      • Optimism (chain id : 10)
      • Astar (chain id : 592)
      • Kaia (chain id : 8217)
      • zkSync Era (chain id : 324)
      • Polygon zkEVM ( chainid : 1101)
      • Linea (chain id : 59144)
      • Base (chain id : 8453)
      • Mantle ( chain id : 5000)
      • Scroll (chain id : 534352 )
      • Blast (chain id : 81457)
      • X Layer (chain id : 196)
      • Taiko (chain id : 167000)
      • Cronos zkEVM (chain id : 388)
      • Abstract (chain id : 2741)
      • Berachain (chain id : 80094)
      • Numbers (chain id : 10507)
      • Treasury
      • (Suspended)Fantom
      • (Suspended)ThunderCore
      • (Suspended)Moonriver
    • Audit Reports
    • Privileged Roles Management
  • Document
    • Terms of Use
    • AML and CFT Compliance Statement
    • Integration Terms and Brand Guidelines
    • Product Update
  • FAQ
    • How to Speed up Pending Transactions
    • How to add a custom RPC to my wallet
  • Contact Us
    • Telegram
    • Medium
    • Twitter
    • Discord
Powered by GitBook
On this page
  • Integration Notice
  • yBridge
  • State-Changing Functions
  • swapWithReferrer
  • singleChainSwapWithReferrer
  • View Functions
  • getEverClosed
  • getTokenBalance
  • Events
  • System Setting Related Events
  • User Related Events

Was this helpful?

  1. Single Bridge Integration
  2. yBridge Contract Integration

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

function swapWithReferrer(
    address aggregatorAdaptor,
    IDexAggregatorAdaptor.SwapDescription memory swapDesc,
    bytes memory aggregatorData,
    PreviousDstChainDescription calldata dstChainDesc, ## Renamed after 2024/7/17
    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 PreviousDstChainDescription ## Renamed after 2024/7/17 {
    uint32 dstChainId;
    IERC20 dstChainToken;
    address dstAggregatorAdaptor;
    uint256 expectedDstChainTokenAmount;
    uint32 slippage;// denominator = 10**4
}

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

System Setting Related 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.


User Related Events

SwapRequested

struct DstChainDescription {
    uint32 dstChainId;
    IERC20 dstChainToken;
    address dstAggregatorAdaptor;
    uint256 expectedDstChainTokenAmount;
    uint32 slippage; // denominator = 10**4
}
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.

PreviousyBridge Contract IntegrationNextBridge Example

Last updated 9 months ago

Was this helpful?