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
  • aggregatorAdaptor
  • aggregatorData
  • swapDesc
  • toChainDesc
  • To Sum up
  • Check on the Target Chain

Was this helpful?

  1. Single Bridge Integration
  2. yBridge Contract Integration
  3. (Legacy) Integrate X Swap Contract

(Legacy) Bridge Example

This is a simple bridge request (without invoking swap) example

Previous(Legacy) Integrate X Swap ContractNext(Legacy) Integrate Y Pool Contract

Last updated 1 year ago

Was this helpful?

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 .

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:

function swap(
    address aggregatorAdaptor,
    IDexAggregatorAdaptor.SwapDescription memory swapDesc,
    bytes memory aggregatorData,
    ToChainDescription calldata toChainDesc
)

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

struct SwapDescription {
    IERC20 fromToken;
    IERC20 toToken;
    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 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

struct ToChainDescription {
    uint32 toChainId;
    IERC20 toChainToken;
    uint256 expectedToChainTokenAmount;
    uint32 slippage;
}

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:

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

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 . See addresses of XSwapper across all chains .

available liquidity
here
here