> For the complete documentation index, see [llms.txt](https://fluxion-network.gitbook.io/fluxion-network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fluxion-network.gitbook.io/fluxion-network/developer-resources/technical-overview-and-api/amm-v2-router.md).

# amm v2 router

## Overview

Routing entrypoint for swaps, liquidity management, and quoting across approved V2 pools.

* Contract name: `Router`
* Address: `0xd772E655af24Fe5Af92504D613D1Da0d9cFb6408`
* Network: Mantle Mainnet (`chainId 5000`)
* Explorer: [`Mantle Explorer`](https://explorer.mantle.xyz/address/0xd772E655af24Fe5Af92504D613D1Da0d9cFb6408)
* Explorer API: [`smart-contract payload`](https://explorer.mantle.xyz/api/v2/smart-contracts/0xd772E655af24Fe5Af92504D613D1Da0d9cFb6408)
* Sourcify metadata: [`metadata.json`](https://repo.sourcify.dev/contracts/full_match/5000/0xd772E655af24Fe5Af92504D613D1Da0d9cFb6408/metadata.json)
* Sourcify source: [`contracts/Router.sol`](https://repo.sourcify.dev/contracts/full_match/5000/0xd772E655af24Fe5Af92504D613D1Da0d9cFb6408/sources/contracts/Router.sol)

***

## Read Functions

### `ETHER`

```solidity
function ETHER() external view returns (address return0)
```

Reads contract state.

This function does not take parameters.

**Return Values**

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### `defaultFactory`

```solidity
function defaultFactory() external view returns (address return0)
```

Address of Protocol PoolFactory.sol

This function does not take parameters.

**Return Values**

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### `factoryRegistry`

```solidity
function factoryRegistry() external view returns (address return0)
```

Reads contract state.

This function does not take parameters.

**Return Values**

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### `getAmountsIn`

```solidity
function getAmountsIn(uint256 amountOut, tuple(address from, address to, bool stable, address factory)[] routes) external view returns (uint256[] amounts)
```

Reads contract state.

**Parameters**

| Name        | Type                                                              | Description                |
| ----------- | ----------------------------------------------------------------- | -------------------------- |
| `amountOut` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`    | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |

**Return Values**

| Name      | Type        | Description                |
| --------- | ----------- | -------------------------- |
| `amounts` | `uint256[]` | Not documented in NatSpec. |

***

### `getAmountsOut`

```solidity
function getAmountsOut(uint256 amountIn, tuple(address from, address to, bool stable, address factory)[] routes) external view returns (uint256[] amounts)
```

Reads contract state.

**Parameters**

| Name       | Type                                                              | Description                |
| ---------- | ----------------------------------------------------------------- | -------------------------- |
| `amountIn` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`   | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |

**Return Values**

| Name      | Type        | Description                |
| --------- | ----------- | -------------------------- |
| `amounts` | `uint256[]` | Not documented in NatSpec. |

***

### `getReserves`

```solidity
function getReserves(address tokenA, address tokenB, bool stable, address _factory) external view returns (uint256 reserveA, uint256 reserveB)
```

Fetch and sort the reserves for a pool

**Parameters**

| Name       | Type      | Description                                  |
| ---------- | --------- | -------------------------------------------- |
| `tokenA`   | `address` | .                                            |
| `tokenB`   | `address` | .                                            |
| `stable`   | `bool`    | True if pool is stable, false if volatile    |
| `_factory` | `address` | Address of PoolFactory for tokenA and tokenB |

**Return Values**

| Name       | Type      | Description                              |
| ---------- | --------- | ---------------------------------------- |
| `reserveA` | `uint256` | Amount of reserves of the sorted token A |
| `reserveB` | `uint256` | Amount of reserves of the sorted token B |

***

### `isTrustedForwarder`

```solidity
function isTrustedForwarder(address forwarder) external view returns (bool return0)
```

Indicates whether any particular address is the trusted forwarder.

**Parameters**

| Name        | Type      | Description                |
| ----------- | --------- | -------------------------- |
| `forwarder` | `address` | Not documented in NatSpec. |

**Return Values**

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| `return0` | `bool` | Not documented in NatSpec. |

***

### `poolFor`

```solidity
function poolFor(address tokenA, address tokenB, bool stable, address _factory) external view returns (address pool)
```

Calculate the address of a pool by its' factory. Used by all Router functions containing a `Route[]` or `_factory` argument. Reverts if \_factory is not approved by the FactoryRegistry

**Parameters**

| Name       | Type      | Description                               |
| ---------- | --------- | ----------------------------------------- |
| `tokenA`   | `address` | Address of token to query                 |
| `tokenB`   | `address` | Address of token to query                 |
| `stable`   | `bool`    | True if pool is stable, false if volatile |
| `_factory` | `address` | Address of factory which created the pool |

**Return Values**

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `pool` | `address` | Not documented in NatSpec. |

***

### `quoteAddLiquidity`

```solidity
function quoteAddLiquidity(address tokenA, address tokenB, bool stable, address _factory, uint256 amountADesired, uint256 amountBDesired) external view returns (uint256 amountA, uint256 amountB, uint256 liquidity)
```

Quote the amount deposited into a Pool

**Parameters**

| Name             | Type      | Description                                  |
| ---------------- | --------- | -------------------------------------------- |
| `tokenA`         | `address` | .                                            |
| `tokenB`         | `address` | .                                            |
| `stable`         | `bool`    | True if pool is stable, false if volatile    |
| `_factory`       | `address` | Address of PoolFactory for tokenA and tokenB |
| `amountADesired` | `uint256` | Amount of tokenA desired to deposit          |
| `amountBDesired` | `uint256` | Amount of tokenB desired to deposit          |

**Return Values**

| Name        | Type      | Description                                     |
| ----------- | --------- | ----------------------------------------------- |
| `amountA`   | `uint256` | Amount of tokenA to actually deposit            |
| `amountB`   | `uint256` | Amount of tokenB to actually deposit            |
| `liquidity` | `uint256` | Amount of liquidity token returned from deposit |

***

### `quoteRemoveLiquidity`

```solidity
function quoteRemoveLiquidity(address tokenA, address tokenB, bool stable, address _factory, uint256 liquidity) external view returns (uint256 amountA, uint256 amountB)
```

Quote the amount of liquidity removed from a Pool

**Parameters**

| Name        | Type      | Description                                  |
| ----------- | --------- | -------------------------------------------- |
| `tokenA`    | `address` | .                                            |
| `tokenB`    | `address` | .                                            |
| `stable`    | `bool`    | True if pool is stable, false if volatile    |
| `_factory`  | `address` | Address of PoolFactory for tokenA and tokenB |
| `liquidity` | `uint256` | Amount of liquidity to remove                |

**Return Values**

| Name      | Type      | Description               |
| --------- | --------- | ------------------------- |
| `amountA` | `uint256` | Amount of tokenA received |
| `amountB` | `uint256` | Amount of tokenB received |

***

### `quoteStableLiquidityRatio`

```solidity
function quoteStableLiquidityRatio(address tokenA, address tokenB, address _factory) external view returns (uint256 ratio)
```

Used by zapper to determine appropriate ratio of A to B to deposit liquidity. Assumes stable pool.

**Parameters**

| Name       | Type      | Description                                 |
| ---------- | --------- | ------------------------------------------- |
| `tokenA`   | `address` | tokenA of stable pool you are zapping into. |
| `tokenB`   | `address` | tokenB of stable pool you are zapping into. |
| `_factory` | `address` | Not documented in NatSpec.                  |

**Return Values**

| Name    | Type      | Description                                             |
| ------- | --------- | ------------------------------------------------------- |
| `ratio` | `uint256` | Ratio of token0 to token1 required to deposit into zap. |

***

### `sortTokens`

```solidity
function sortTokens(address tokenA, address tokenB) external pure returns (address token0, address token1)
```

Sort two tokens by which address value is less than the other

**Parameters**

| Name     | Type      | Description              |
| -------- | --------- | ------------------------ |
| `tokenA` | `address` | Address of token to sort |
| `tokenB` | `address` | Address of token to sort |

**Return Values**

| Name     | Type      | Description                                    |
| -------- | --------- | ---------------------------------------------- |
| `token0` | `address` | Lower address value between tokenA and tokenB  |
| `token1` | `address` | Higher address value between tokenA and tokenB |

***

### `trustedForwarder`

```solidity
function trustedForwarder() external view returns (address return0)
```

Returns the address of the trusted forwarder.

This function does not take parameters.

**Return Values**

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### `voter`

```solidity
function voter() external view returns (address return0)
```

Address of Voter.sol

This function does not take parameters.

**Return Values**

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### `weth`

```solidity
function weth() external view returns (address return0)
```

Interface of WETH contract used for WETH => ETH wrapping/unwrapping

This function does not take parameters.

**Return Values**

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

## Write Functions

### `UNSAFE_swapExactTokensForTokens`

```solidity
function UNSAFE_swapExactTokensForTokens(uint256[] amounts, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external returns (uint256[] return0)
```

Executes a state-changing call.

**Parameters**

| Name       | Type                                                              | Description                |
| ---------- | ----------------------------------------------------------------- | -------------------------- |
| `amounts`  | `uint256[]`                                                       | Not documented in NatSpec. |
| `routes`   | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`       | `address`                                                         | Not documented in NatSpec. |
| `deadline` | `uint256`                                                         | Not documented in NatSpec. |

**Return Values**

| Name      | Type        | Description                |
| --------- | ----------- | -------------------------- |
| `return0` | `uint256[]` | Not documented in NatSpec. |

***

### `addLiquidity`

```solidity
function addLiquidity(address tokenA, address tokenB, bool stable, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline) external returns (uint256 amountA, uint256 amountB, uint256 liquidity)
```

Add liquidity of two tokens to a Pool

**Parameters**

| Name             | Type      | Description                               |
| ---------------- | --------- | ----------------------------------------- |
| `tokenA`         | `address` | .                                         |
| `tokenB`         | `address` | .                                         |
| `stable`         | `bool`    | True if pool is stable, false if volatile |
| `amountADesired` | `uint256` | Amount of tokenA desired to deposit       |
| `amountBDesired` | `uint256` | Amount of tokenB desired to deposit       |
| `amountAMin`     | `uint256` | Minimum amount of tokenA to deposit       |
| `amountBMin`     | `uint256` | Minimum amount of tokenB to deposit       |
| `to`             | `address` | Recipient of liquidity token              |
| `deadline`       | `uint256` | Deadline to receive liquidity             |

**Return Values**

| Name        | Type      | Description                                     |
| ----------- | --------- | ----------------------------------------------- |
| `amountA`   | `uint256` | Amount of tokenA to actually deposit            |
| `amountB`   | `uint256` | Amount of tokenB to actually deposit            |
| `liquidity` | `uint256` | Amount of liquidity token returned from deposit |

***

### `addLiquidityETH`

```solidity
function addLiquidityETH(address token, bool stable, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity)
```

Add liquidity of a token and WETH (transferred as ETH) to a Pool

**Parameters**

| Name                 | Type      | Description                               |
| -------------------- | --------- | ----------------------------------------- |
| `token`              | `address` | .                                         |
| `stable`             | `bool`    | True if pool is stable, false if volatile |
| `amountTokenDesired` | `uint256` | Amount of token desired to deposit        |
| `amountTokenMin`     | `uint256` | Minimum amount of token to deposit        |
| `amountETHMin`       | `uint256` | Minimum amount of ETH to deposit          |
| `to`                 | `address` | Recipient of liquidity token              |
| `deadline`           | `uint256` | Deadline to add liquidity                 |

**Return Values**

| Name          | Type      | Description                                     |
| ------------- | --------- | ----------------------------------------------- |
| `amountToken` | `uint256` | Amount of token to actually deposit             |
| `amountETH`   | `uint256` | Amount of tokenETH to actually deposit          |
| `liquidity`   | `uint256` | Amount of liquidity token returned from deposit |

***

### `removeLiquidity`

```solidity
function removeLiquidity(address tokenA, address tokenB, bool stable, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline) external returns (uint256 amountA, uint256 amountB)
```

Remove liquidity of two tokens from a Pool

**Parameters**

| Name         | Type      | Description                               |
| ------------ | --------- | ----------------------------------------- |
| `tokenA`     | `address` | .                                         |
| `tokenB`     | `address` | .                                         |
| `stable`     | `bool`    | True if pool is stable, false if volatile |
| `liquidity`  | `uint256` | Amount of liquidity to remove             |
| `amountAMin` | `uint256` | Minimum amount of tokenA to receive       |
| `amountBMin` | `uint256` | Minimum amount of tokenB to receive       |
| `to`         | `address` | Recipient of tokens received              |
| `deadline`   | `uint256` | Deadline to remove liquidity              |

**Return Values**

| Name      | Type      | Description               |
| --------- | --------- | ------------------------- |
| `amountA` | `uint256` | Amount of tokenA received |
| `amountB` | `uint256` | Amount of tokenB received |

***

### `removeLiquidityETH`

```solidity
function removeLiquidityETH(address token, bool stable, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external returns (uint256 amountToken, uint256 amountETH)
```

Remove liquidity of a token and WETH (returned as ETH) from a Pool

**Parameters**

| Name             | Type      | Description                               |
| ---------------- | --------- | ----------------------------------------- |
| `token`          | `address` | .                                         |
| `stable`         | `bool`    | True if pool is stable, false if volatile |
| `liquidity`      | `uint256` | Amount of liquidity to remove             |
| `amountTokenMin` | `uint256` | Minimum amount of token to receive        |
| `amountETHMin`   | `uint256` | Minimum amount of ETH to receive          |
| `to`             | `address` | Recipient of liquidity token              |
| `deadline`       | `uint256` | Deadline to receive liquidity             |

**Return Values**

| Name          | Type      | Description              |
| ------------- | --------- | ------------------------ |
| `amountToken` | `uint256` | Amount of token received |
| `amountETH`   | `uint256` | Amount of ETH received   |

***

### `removeLiquidityETHSupportingFeeOnTransferTokens`

```solidity
function removeLiquidityETHSupportingFeeOnTransferTokens(address token, bool stable, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external returns (uint256 amountETH)
```

Remove liquidity of a fee-on-transfer token and WETH (returned as ETH) from a Pool

**Parameters**

| Name             | Type      | Description                               |
| ---------------- | --------- | ----------------------------------------- |
| `token`          | `address` | .                                         |
| `stable`         | `bool`    | True if pool is stable, false if volatile |
| `liquidity`      | `uint256` | Amount of liquidity to remove             |
| `amountTokenMin` | `uint256` | Minimum amount of token to receive        |
| `amountETHMin`   | `uint256` | Minimum amount of ETH to receive          |
| `to`             | `address` | Recipient of liquidity token              |
| `deadline`       | `uint256` | Deadline to receive liquidity             |

**Return Values**

| Name        | Type      | Description            |
| ----------- | --------- | ---------------------- |
| `amountETH` | `uint256` | Amount of ETH received |

***

### `swapExactETHForTokens`

```solidity
function swapExactETHForTokens(uint256 amountOutMin, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external payable returns (uint256[] amounts)
```

Executes a payable state-changing call.

**Parameters**

| Name           | Type                                                              | Description                |
| -------------- | ----------------------------------------------------------------- | -------------------------- |
| `amountOutMin` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`       | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`           | `address`                                                         | Not documented in NatSpec. |
| `deadline`     | `uint256`                                                         | Not documented in NatSpec. |

**Return Values**

| Name      | Type        | Description                |
| --------- | ----------- | -------------------------- |
| `amounts` | `uint256[]` | Not documented in NatSpec. |

***

### `swapExactETHForTokensSupportingFeeOnTransferTokens`

```solidity
function swapExactETHForTokensSupportingFeeOnTransferTokens(uint256 amountOutMin, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external payable
```

Executes a payable state-changing call.

**Parameters**

| Name           | Type                                                              | Description                |
| -------------- | ----------------------------------------------------------------- | -------------------------- |
| `amountOutMin` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`       | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`           | `address`                                                         | Not documented in NatSpec. |
| `deadline`     | `uint256`                                                         | Not documented in NatSpec. |

This function does not return a value.

***

### `swapExactTokensForETH`

```solidity
function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external returns (uint256[] amounts)
```

Executes a state-changing call.

**Parameters**

| Name           | Type                                                              | Description                |
| -------------- | ----------------------------------------------------------------- | -------------------------- |
| `amountIn`     | `uint256`                                                         | Not documented in NatSpec. |
| `amountOutMin` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`       | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`           | `address`                                                         | Not documented in NatSpec. |
| `deadline`     | `uint256`                                                         | Not documented in NatSpec. |

**Return Values**

| Name      | Type        | Description                |
| --------- | ----------- | -------------------------- |
| `amounts` | `uint256[]` | Not documented in NatSpec. |

***

### `swapExactTokensForETHSupportingFeeOnTransferTokens`

```solidity
function swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external
```

Executes a state-changing call.

**Parameters**

| Name           | Type                                                              | Description                |
| -------------- | ----------------------------------------------------------------- | -------------------------- |
| `amountIn`     | `uint256`                                                         | Not documented in NatSpec. |
| `amountOutMin` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`       | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`           | `address`                                                         | Not documented in NatSpec. |
| `deadline`     | `uint256`                                                         | Not documented in NatSpec. |

This function does not return a value.

***

### `swapExactTokensForTokens`

```solidity
function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external returns (uint256[] amounts)
```

Executes a state-changing call.

**Parameters**

| Name           | Type                                                              | Description                |
| -------------- | ----------------------------------------------------------------- | -------------------------- |
| `amountIn`     | `uint256`                                                         | Not documented in NatSpec. |
| `amountOutMin` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`       | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`           | `address`                                                         | Not documented in NatSpec. |
| `deadline`     | `uint256`                                                         | Not documented in NatSpec. |

**Return Values**

| Name      | Type        | Description                |
| --------- | ----------- | -------------------------- |
| `amounts` | `uint256[]` | Not documented in NatSpec. |

***

### `swapExactTokensForTokensSupportingFeeOnTransferTokens`

```solidity
function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, tuple(address from, address to, bool stable, address factory)[] routes, address to, uint256 deadline) external
```

Executes a state-changing call.

**Parameters**

| Name           | Type                                                              | Description                |
| -------------- | ----------------------------------------------------------------- | -------------------------- |
| `amountIn`     | `uint256`                                                         | Not documented in NatSpec. |
| `amountOutMin` | `uint256`                                                         | Not documented in NatSpec. |
| `routes`       | `tuple(address from, address to, bool stable, address factory)[]` | Not documented in NatSpec. |
| `to`           | `address`                                                         | Not documented in NatSpec. |
| `deadline`     | `uint256`                                                         | Not documented in NatSpec. |

This function does not return a value.
