# Swap

Swap functions use the liquidity available to trade one token with another

```rust
    #[payable("*")]
    #[endpoint(swap)]
    fn swap(
        &self, 
        first_token: TokenIdentifier,  
        second_token: TokenIdentifier, 
        opt_min_out: OptionalValue<BigUint>,
    )
```

first\_token will always be MID token and second\_token indicate what liquidity to use.

Payment token can be first or second token.

opt\_min\_out (slippage) : is an optionnal value where user can indicate the minimum amount of token he want to receive. We will use this to set the slippage tolerance

```rust
    #[payable("*")]
    #[endpoint(dualSwap)]
    fn dual_swap(
        &self, 
        first_token: TokenIdentifier,  
        second_token: TokenIdentifier, 
        opt_min_out: OptionalValue<BigUint>,
    )
```

first token and second token must be in the "swaped\_tokens" list


---

# 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.middlestaking.fr/contracts/swap-contract/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.
