> 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/validators/erc20swapvalidator.md).

# ERC20SwapValidator

### Overview

`ERC20SwapValidator` ensures that only authorized routers and tokens are used for ERC20 token swaps. It provides validation methods, mappings to track supported routers/tokens, and emits relevant events to keep track of changes.

### Key Features

* **Router and Token Support**: Controls which routers and tokens are authorized for swap operations.
* **Swap Validation**: Enforces rules for swap operations, ensuring compliance with authorized routers and tokens.
* **Error Reporting**: Raises specific errors when a swap operation fails validation.

### Error Definitions

* **InvalidLength**: Raised when the data length for a swap operation is incorrect.
* **InvalidSelector**: The function selector provided is not recognized.
* **UnsupportedToken**: The token used is not on the supported list.
* **UnsupportedRouter**: The router used is not on the supported list.

### Core Methods

1. **View Functions**
   * `isSupportedRouter(address)`: Checks if a router is supported for swaps.
   * `isSupportedToken(address)`: Checks if a token is supported for swaps.
2. **Configuration Functions**
   * `setSupportedRouter(address, bool)`: Sets a router's supported status.
   * `setSupportedToken(address, bool)`: Sets a token's supported status.
3. **Validation Function**
   * `validate(address, address, bytes)`: Validates that the swap operation complies with the rules:
     * Checks function signatures.
     * Verifies swap parameters.
     * Ensures routers and tokens are authorized.

### Events

1. **Router Updates:**
   * `ERC20SwapValidatorSetSupportedRouter(address, bool, uint256)`: Emitted when a router's support status is updated.
     * **router**: Address of the router.
     * **flag**: Boolean indicating support status.
     * **timestamp**: Timestamp of the action.
2. **Token Updates:**
   * `ERC20SwapValidatorSetSupportedToken(address, bool, uint256)`: Emitted when a token's support status is updated.
     * **token**: Address of the token.
     * **flag**: Boolean indicating support status.
     * **timestamp**: Timestamp of the action.


---

# 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/validators/erc20swapvalidator.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.
