> For the complete documentation index, see [llms.txt](https://docs.middlestaking.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.middlestaking.fr/contracts/swap-contract/swap.md).

# 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
