# AllSwap

AllSwap builds on top of AllSet's liquidity layer to enable seamless cross chain swaps. It aggregates decentralized exchanges (DEXs) across networks, identifies the best available rates, and executes swaps instantly, powered by Fast's verifiable claim system.

<figure><img src="/files/uG9F9IFCkf4H2yh2ud9Z" alt=""><figcaption><p><strong>Figure 1:</strong> AllSwap high-level architecture.</p></figcaption></figure>

This diagram shows how AllSwap benefits from the interactions with AllSet and Fast to provide secure and verifiable swaps. It begins by retrieving and ranking the best DEX rates and forming a swap intent on the source chain. That intent is then relayed through AllSwap, where AllSet verifiers confirm the claim and proof. Once validated by Fast, AllSwap mints/burns the appropriate assets on the destination chain to complete the swap.

## AllSwap protocol

AllSwap makes it possible to move and trade assets across chains with the same security and speed that Fast provides.

<figure><img src="/files/OR13X1qORjZci76n8Q0T" alt=""><figcaption><p><strong>Figure 2:</strong> AllSwap workflow.</p></figcaption></figure>

AllSwap's workflow can be split into three categories: 1) retrieve and rank, 2) swap, and 3) withdrawal and deposit.

### Retrieve and Rank

{% stepper %}
{% step %}

#### Retrieve

AllSwap retrieves the best DEX rates accross all chains.
{% endstep %}

{% step %}

#### Rank

AllSwap ranks the best DEX rates for the user to choose.
{% endstep %}
{% endstepper %}

### Swap

{% stepper %}
{% step %}

#### Send transferClaim and swapIntentClaim

Once the user chooses the desired decentralized exchange, say DEX Y, two claims are sent to the Fast network:

**i.** A transferClaim specifying that `amt1` xAsset tokens have to be transferred from the sender's account to the target chain account (Chain Y Bridge Account).

**ii.** A swapIntentClaim specifying the swap intent of the same amount `amt1` xAsset tokens.

And this begins the **swap** workflow.
{% endstep %}

{% step %}

#### Receive transferClaim and swapIntentClaim

AllSet, through its Relayer component, gets notified about the two claims: transferClaim and swapIntentClaim.
{% endstep %}

{% step %}

#### Relay «Swap intent»

Next, AllSet Relayer forwards the withdraw intent to Fast Contract Y, a contract responsible for the swap transaction on the DEX Y.
{% endstep %}

{% step %}

#### Send «Swap transaction»

Once the intent is verified, Fast Contract Y initiates a swap transaction. `amt1` yAsset1 to be exchanged for `amt2` yAsset2.\
\
The swap transaction comprises of the following:

* Withdrawal from the Fast Contract Y, for the swap transaction to be taken place at DEX Y. Hence, this triggers the arrows as represented by W<sub>5</sub>-W<sub>7</sub>.
* Deposit back to the Fast Contract Y, indicating that it is meant to be deposited back to the Sender Account on Fast. Hence, this triggers the arrows as represented by D<sub>2</sub>-D<sub>4</sub>.

Recall that *y*Asset denotes the representation of Asset on chain Y.
{% endstep %}
{% endstepper %}

Observe that steps S<sub>1</sub>-S<sub>4</sub> are similar to Steps W<sub>1</sub>-W<sub>4</sub> in [AllSet's withdraw workflow](/allset-archived/architecture.md#withdraw), with the difference that the intent claim and transaction in last step are now about swapping and not just withdrawing.

### Withdrawal and Deposit

The swap transaction triggers a withdraw flow for `amt1` xAsset and a deposit flow for `amt2` yAsset. Steps W<sub>5</sub>-W<sub>7</sub> and D<sub>2</sub>-D<sub>4</sub> correspond to the homonym steps in AllSet's [withdraw](/allset-archived/architecture.md#withdraw), respectively [deposit](/allset-archived/architecture.md#deposit) workflow.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fast.xyz/allset-archived/applications/allswap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
