# Bridge : yBridge

### Mechanism

There will be at most three transactions involved in the `circle` of 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 is still one TXs pertinent to whether users' funds could be transferred onto the target chain with success.

* **TX1**: Users send assets (quoted price) via the yBridge on Chain A (the source chain DEX).
* **TX2**: yBridge (our executor) helps swap on Chain B (the target chain DEX) and transfers tokens back to users. This TX will be conducted using a proof of [consensus](https://docs.xy.finance/products/broken-reference), and by so doing the whole swap can be closed, good and proper.

### Example

Suppose Bob would like to swap 1 **`wBTC on ETH`** for some **`CAKE on BSC`**. With the assistance of yBridge, 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.&#x20;

![ A simple flow chart of a swap](https://3694085950-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mcs9EhDrgbKHodtcAT6%2F-MgsM8fwYdq-1bPSejm8%2F-Mgsi4Vw00fColmmlcpu%2FHow%20it%20works.png?alt=media\&token=c12ad4cf-5e1e-4792-b472-b457a51449a2)

### Swap Breakdown

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 wBTC` to yBridge

➁ Our **yBridge** on Ethereum will trade `1 wBTC` on Chain A (Dex1) for the best offer **30000 USDT**.

➂ yBridge will charge some fees, say **20 USDT**, and then submits a transaction request to swap **29980** **USDT** to yBridge for `CAKE on BNB`. Should you wish to learn more about how the fees are calculated, feel free to check the section attached below.

{% content-ref url="../fee-structure/ybridge-fee-information" %}
[ybridge-fee-information](https://docs.xy.finance/fee-structure/ybridge-fee-information)
{% endcontent-ref %}

➃ ➄ yBridge 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 BNB` suddenly fluctuates following **TX1** and a trading failure results, which means the swap fails to swap **2970** **CAKE** (at least) to Bob, then yBridge will instead transfer **29980 USDT** (BSC) from yBridge to Mr. Bob, who still gets his assets back, safe and sound.

{% hint style="info" %}
If yBridge is unable to successfully complete the transaction on the destination chain due to force majeure, yBridge and/or the Validator Set will reach a consensus that one of them is required to initiate a new transaction in which the equivalent amount of "30000 minus gas fees" USDT (ETH) will be returned to Bob.
{% endhint %}
