How It Works
This explains the mechanism for swapping tokens via X Swap.
There will be at most three transactions involved in the
circleof the swapping process. Under normal circumstances and as previously noted, users will only have to engage in ONE transaction (hereinafter abbreviated as "TX") for the swap to get closed, which is TX1. However, it's worth noting that there are still two TXs pertinent to whether users' funds could be transferred onto the target chain with success. Last but not least, XY Protocol will carry out another TX with regard to Y Pool so as to complete the whole swap circle as illustrated in TX3 below.
- TX1: Users send assets (quoted price) via the Swapper on Chain A (the source chain DEX).
- TX2: XY Protocol (our robot) helps swap on Chain B (the target chain DEX) and transfers tokens back to users.
- TX3: XY Protocol will help claim the assets that are temporarily stored on the source chain Swapper during the swaps back and return them to Y Pool. This TX will be conducted using a proof of consensus, and by so doing the whole swap can be closed, good and proper.
Suppose Bob would like to swap 1
wBTC on ETHfor some
CAKE on BSC. With the assistance of XY Protocol, Bob simply needs to give us permission to access their assets in his wallet (i.e. TX 1 as ➀ below), and the rest of the swap process will thenceforth be well taken care of. From his viewpoint, he will be able to receive his desired CAKE on BSC with only two TXs that are pertinent to his swap (➀ & ➄). The next section will give the breakdown of the full swapping process.
A simple flow chart of a swap
Please refer to the flow chart above for reference.
➀ Firstly, Bob will receive a quotation by interacting with our APIs, which have been instructed to search for and single out the best route for Bob. For instance,
1 wBTC (ETH)could be swapped for 3000 CAKE (BNB) in return and with a 1% slippage tolerance. If Bob accepts the quoted price, he can file a TX request, namely TX1, by sending
1 wBTCto Swapper.
➂ A node on ETH run by XY Protocol will detect TX1 and check if there'a any opportunity of arbitrage at play. If there is, XY Protocol will charge some fees, say 20 USDT, and then submits a transaction request to swap 29980 USDT to Swapper for
CAKE on BNB. Should you wish to learn more about how the fees are calculated, feel free to check the section attached below.
➃ ➄ Swapper on BNB will swap USDT for CAKE via DEXs such as Pancake. Once successfully traded, CAKE will be transferred to Bob right after. However, if, unfortunately, the price of
CAKE on BNBsuddenly fluctuates following TX1 and a trading failure results, which means the swap fails to swap 2970 CAKE (at least) to Bob, then Swapper will instead transfer 29980 USDT (BSC) from XY Protocol to Mr. Bob, who still gets his assets back, safe and sound.
Not that if XY Protocol lacks sufficient funds to underpin the TX, XY Protocol
Validator Set will arrive at a consensus that either of them is obliged to file a new TX where the equivalent amount of
"30000 minus gas fees" USDT
(ETH) will be returned to Bob.