# Swappers

Swappers are a contract that allows users to perform a swap as part of the series of operation they bundle together when they 'cook' a transaction with Abracadabra. It is often used in 3 contexts: Leverage, Deleverage and Liquidations, to swap collateral and MIM.

While the freedom that cauldrons gives the user in terms of callable contracts would enable them to call any decentralize exchange, swappers are contracts that facilitate this process, standardizing the calls to be made.

Early Swappers hardcoded a route, using a Curve Pool or a UniV2-like DEX, while SwapperV2 support DEX Aggregators and augment the possibilities and adaptability of the system.

Here are the 2 interfaces Swappers can conform to. V2 added a 'data' parameter to be given to the dex aggregator in order to perform swaps in any arbitrary route.

### ISwapperV1

```solidity
interface ISwapper {
    /// @notice Withdraws 'amountFrom' of token 'from' from the BentoBox account for this swapper.
    /// Swaps it for at least 'amountToMin' of token 'to'.
    /// Transfers the swapped tokens of 'to' into the BentoBox using a plain ERC20 transfer.
    /// Returns the amount of tokens 'to' transferred to BentoBox.
    /// (The BentoBox skim function will be used by the caller to get the swapped funds).
    function swap(
        IERC20 fromToken,
        IERC20 toToken,
        address recipient,
        uint256 shareToMin,
        uint256 shareFrom
    ) external returns (uint256 extraShare, uint256 shareReturned);
```

### ISwapperV2

```solidity
interface ISwapperV2 {
    /// @notice Withdraws 'amountFrom' of token 'from' from the BentoBox account for this swapper.
    /// Swaps it for at least 'amountToMin' of token 'to'.
    /// Transfers the swapped tokens of 'to' into the BentoBox using a plain IERC20 transfer.
    /// Returns the amount of tokens 'to' transferred to BentoBox.
    /// (The BentoBox skim function will be used by the caller to get the swapped funds).
    function swap(
        address fromToken,
        address toToken,
        address recipient,
        uint256 shareToMin,
        uint256 shareFrom,
        bytes calldata data
    ) external returns (uint256 extraShare, uint256 shareReturned);
}
```


---

# 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://dev.abracadabra.money/periphery-contracts/swappers.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.
