> For the complete documentation index, see [llms.txt](https://docs.mellow.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mellow.finance/resources/mellow-lrt-depreciated/modules/delegatemodules/erc20swapmodule.md).

# ERC20SwapModule

### Overview

`ERC20SwapModule` contract facilitates ERC20 token swaps based on predefined parameters.

### Key Features

* **Secure ERC20 Swaps**: Enables ERC20 swaps with security checks on input and output amounts.
* **Parameter Validation**: Ensures swap parameters like deadlines and minimum amounts are respected.
* **Allowance Management**: Uses `forceApprove` to manage allowances securely after swaps.

### Error Definitions

* **Deadline**: Raised when the swap operation exceeds the specified deadline.
* **SwapFailed**: The swap operation did not execute successfully.
* **InvalidSwapAmounts**: Input or output amounts don't meet the expected values.

### Methods

1. **Swap Function**
   * `swap(SwapParams, address, bytes)`: Executes a token swap based on provided parameters.
     * **params**: Contains details of the swap operation:
       * **tokenIn**: The address of the input token.
       * **tokenOut**: The address of the output token.
       * **amountIn**: The amount of the input token to swap.
       * **minAmountOut**: The minimum acceptable amount of the output token.
       * **deadline**: The deadline for completing the swap.
     * **to**: Address of the swap target.
     * **data**: Call data required to execute the swap operation.
     * **Returns**: The response from the swap call.
     * **Errors**:
       * `Deadline`: If the current timestamp is past the deadline.
       * `InvalidSwapAmounts`: If the amount of tokens swapped does not match the specified input or output criteria.
       * `SwapFailed`: The swap operation failed to execute successfully.

### Event

* `ERC20SwapModuleSwap(SwapParams, address, bytes, uint256, bytes)`: Emitted after a swap is successfully executed.
  * **params**: The parameters used for the swap.
  * **to**: The address of the swap target.
  * **data**: The call data used for the swap.
  * **timestamp**: The timestamp when the swap was completed.
  * **response**: The response data returned from the swap operation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.mellow.finance/resources/mellow-lrt-depreciated/modules/delegatemodules/erc20swapmodule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
