# Understanding Slippage

## Slippage and MEV

Setting a low slippage tolerance is the simplest defense against toxic-MEV. Since searchers exploit slippage for price manipulation, transactions with lower slippage tolerance could provide less opportunity for toxic-MEV exploitation from trades.

Additionally, slippage modeling generally incorporates statistics into a smart order routing algorithm to deliver the optimal trade route.

Nevertheless, these solutions are incomplete. Even with optimal slippage, MEV bots may still derive value from your trades.

***

## On Solana

In [**Solana's Token Swap Program**](https://github.com/solana-labs/solana-program-library/tree/master/token-swap), a generic swap involves the input `amount_in`, which represents the amount of token the user wants to trade, and `minimum_amount_out`, which denotes the minimum amount of output tokens necessary to avoid excessive slippage:

```rust
/// Swap instruction data
pub struct Swap {
    /// SOURCE amount to transfer, output to DESTINATION is based on the exchange rate
    pub amount_in: u64,
    /// Minimum amount of DESTINATION token to output, prevents excessive slippage
    pub minimum_amount_out: u64,
}
```

The minimum amount of output tokens is connected to the actual number of output tokens by the slippage, ensuring that:

$$
\min(N\_{out}^A) = N\_{out}^A - S^A \times N\_{out}^A
$$

The slippage can be derived as follows:

$$
S^A = \frac{N\_{out}^A - \min(N\_{out}^A)}{N\_{out}^A} %
$$


---

# 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.urani.trade/urani-protocol/technical-considerations/multidimensional-market/on-solana/understanding-slippage.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.
