# Swap

**Users can swap between BTC and Runes tokens available in the RunesDeX liquidity pools. The swap price is determined by the ratio of the tokens in the pool, adjusted according to the constant product formula.**

### Swap transaction explanation: &#x20;

**1. User's Runes with Dust BTC or BTC Transfer to Swap**

The user initiates the SWAP by transferring their Runes tokens along with a small amount of BTC (dust BTC) or BTC directly to the swap contract. This step includes the user's intention to exchange Runes tokens for BTC or vice versa.

\
**2. Fee Transfer to the Pool (Not Less Than Dust BTC)**

A portion of the transaction fee is transferred to the liquidity pool. This fee, which is not less than the dust BTC amount, compensates the liquidity providers for their participation and risk in the pool. This fee helps maintain the pool's operation and incentivizes liquidity provision.

**3. Fee Transfer to the Treasury (Not Less Than Dust BTC)**

Another portion of the transaction fee is directed to the RunesDeX treasury. This fee, also not less than the dust BTC amount, supports the maintenance and development of the RunesDeX platform, ensuring its sustainability and growth.

**4. Pool's Runes with Dust BTC or BTC Transfer to Swap**

The liquidity pool responds by transferring the corresponding amount of Runes tokens with dust BTC or BTC to the user’s wallet. This step completes the exchange process, ensuring the user receives the desired tokens as per the swap rate.

**5. Transfer Back the User's Unused BTC from Input UTXOs**

If the user initially transfers more BTC than is required for the swap, the unused BTC is returned to the user's wallet. This step ensures that only the necessary amount of BTC is used for the transaction, and any excess BTC is safely returned.

**6. Transfer Back the Pool's or User's (Based on Sender) Unused Runes**

Similarly, if the liquidity pool or user transferred more Runes tokens than required for the swap, the unused Runes tokens are returned to the respective sender. This step ensures efficient use of the tokens and avoids any excess transfer.


---

# 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.runesdex.com/products/exchange/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.
