> For the complete documentation index, see [llms.txt](https://doc.torch.finance/dex/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.torch.finance/dex/getting-started/architecture/meesage-flows/swap.md).

# Swap

![TorchSwapFlow](https://hackmd.io/_uploads/rkPeVeJIyl.png)

Torch’s Stable Swap mechanism effectively reduces slippage during swaps, providing a more cost-efficient trading experience. Below is a detailed breakdown of the swap process:

1. **Asset Transfer to Vault**
   * Users transfer the asset they wish to swap (swap in asset) to the corresponding Vault contract.
2. **Vault Notifies Pool**
   * Once the Vault receives the asset, it sends an `op::swap_internal` message to the Pool contract, initiating the swap calculation.
3. **Pool Calculates and Notifies Vault**
   * After the calculation, the Pool determines the amount of the swap out asset and sends an `op::payout` message to the Vault responsible for the swap out asset.
   * The Vault then transfers the swapped asset to the user’s designated address as instructed.
4. **Cross-Pool Swap Operations**
   * If the swap involves cross-pool operations, the Pool includes swap details and sends an `op::swap_between` or `op::withdraw_between` message to the next Pool to continue the swap process.
   * A detailed explanation of cross-pool operations will be provided in the [following sections](https://hackmd.io/WUJkKbNOSeujHtjYyB73uA?view#Cross-Pool-Operations).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://doc.torch.finance/dex/getting-started/architecture/meesage-flows/swap.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.
