# amm v3 swaprouter

## Overview

Swap router address supplied for the AMM V3 deployment.

* Contract name: `SwapRouter`
* Address: `0x5628a59dF0ECAC3f3171f877A94bEb26BA6DFAa0`
* Network: Mantle Mainnet (`chainId 5000`)
* Explorer: [`Mantle Explorer`](https://explorer.mantle.xyz/address/0x5628a59dF0ECAC3f3171f877A94bEb26BA6DFAa0)
* Explorer API: [`address payload`](https://explorer.mantle.xyz/api/v2/addresses/0x5628a59dF0ECAC3f3171f877A94bEb26BA6DFAa0)
* [`Mantlescan code page`](https://mantlescan.xyz/address/0x5628a59dF0ECAC3f3171f877A94bEb26BA6DFAa0#code)
* [`SwapRouter.sol`](https://github.com/Uniswap/v3-periphery/blob/main/contracts/SwapRouter.sol)
* [`PeripheryPaymentsWithFee.sol`](https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/PeripheryPaymentsWithFee.sol)
* [`SelfPermit.sol`](https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/SelfPermit.sol)
* [`Multicall.sol`](https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/Multicall.sol)

***

## Read Functions

The matched source only exposes immutable getters on the read side. Routing itself is stateful or callback-driven.

### factory

```solidity
function factory() external view returns (address factory)
```

Returns the Uniswap V3 factory address used by the router.

This function does not take parameters.

Return Values

| Name      | Type      | Description                              |
| --------- | --------- | ---------------------------------------- |
| `factory` | `address` | Factory address used for pool discovery. |

### WETH9

```solidity
function WETH9() external view returns (address weth9)
```

Returns the wrapped native token address configured for the router.

This function does not take parameters.

Return Values

| Name    | Type      | Description                   |
| ------- | --------- | ----------------------------- |
| `weth9` | `address` | Wrapped native token address. |

***

## Write Functions

### uniswapV3SwapCallback

```solidity
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes data) external
```

Pool callback used during router-managed swaps. This is protocol plumbing rather than a normal end-user entrypoint.

Parameters

| Name           | Type     | Description                                                         |
| -------------- | -------- | ------------------------------------------------------------------- |
| `amount0Delta` | `int256` | Amount of token0 the pool expects to receive or send.               |
| `amount1Delta` | `int256` | Amount of token1 the pool expects to receive or send.               |
| `data`         | `bytes`  | Encoded swap callback context used to continue or settle the route. |

This function does not return a value.

### exactInputSingle

```solidity
function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountOut)
```

Swaps a fixed input amount through a single V3 pool.

Parameters

| Name                       | Type      | Description                             |
| -------------------------- | --------- | --------------------------------------- |
| `params.tokenIn`           | `address` | Input token address.                    |
| `params.tokenOut`          | `address` | Output token address.                   |
| `params.fee`               | `uint24`  | Fee tier of the target pool.            |
| `params.recipient`         | `address` | Recipient of the output token.          |
| `params.deadline`          | `uint256` | Latest valid execution timestamp.       |
| `params.amountIn`          | `uint256` | Exact input amount to swap.             |
| `params.amountOutMinimum`  | `uint256` | Minimum acceptable output amount.       |
| `params.sqrtPriceLimitX96` | `uint160` | Optional swap price limit for the pool. |

Return Values

| Name        | Type      | Description                      |
| ----------- | --------- | -------------------------------- |
| `amountOut` | `uint256` | Amount of output token received. |

### exactInput

```solidity
function exactInput((bytes path, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum) params) external payable returns (uint256 amountOut)
```

Swaps a fixed input amount across a multi-hop encoded path.

Parameters

| Name                      | Type      | Description                               |
| ------------------------- | --------- | ----------------------------------------- |
| `params.path`             | `bytes`   | Encoded token and fee path for the route. |
| `params.recipient`        | `address` | Recipient of the output token.            |
| `params.deadline`         | `uint256` | Latest valid execution timestamp.         |
| `params.amountIn`         | `uint256` | Exact input amount to swap.               |
| `params.amountOutMinimum` | `uint256` | Minimum acceptable output amount.         |

Return Values

| Name        | Type      | Description                      |
| ----------- | --------- | -------------------------------- |
| `amountOut` | `uint256` | Amount of output token received. |

### exactOutputSingle

```solidity
function exactOutputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)
```

Swaps as little input as possible to receive an exact output amount from a single pool.

Parameters

| Name                       | Type      | Description                             |
| -------------------------- | --------- | --------------------------------------- |
| `params.tokenIn`           | `address` | Input token address.                    |
| `params.tokenOut`          | `address` | Output token address.                   |
| `params.fee`               | `uint24`  | Fee tier of the target pool.            |
| `params.recipient`         | `address` | Recipient of the output token.          |
| `params.deadline`          | `uint256` | Latest valid execution timestamp.       |
| `params.amountOut`         | `uint256` | Exact output amount requested.          |
| `params.amountInMaximum`   | `uint256` | Maximum input amount willing to spend.  |
| `params.sqrtPriceLimitX96` | `uint160` | Optional swap price limit for the pool. |

Return Values

| Name       | Type      | Description                  |
| ---------- | --------- | ---------------------------- |
| `amountIn` | `uint256` | Input amount actually spent. |

### exactOutput

```solidity
function exactOutput((bytes path, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum) params) external payable returns (uint256 amountIn)
```

Swaps as little input as possible to receive an exact output amount across a reversed multi-hop path.

Parameters

| Name                     | Type      | Description                                  |
| ------------------------ | --------- | -------------------------------------------- |
| `params.path`            | `bytes`   | Encoded token and fee path in reverse order. |
| `params.recipient`       | `address` | Recipient of the output token.               |
| `params.deadline`        | `uint256` | Latest valid execution timestamp.            |
| `params.amountOut`       | `uint256` | Exact output amount requested.               |
| `params.amountInMaximum` | `uint256` | Maximum input amount willing to spend.       |

Return Values

| Name       | Type      | Description                  |
| ---------- | --------- | ---------------------------- |
| `amountIn` | `uint256` | Input amount actually spent. |

### multicall

```solidity
function multicall(bytes[] data) external payable returns (bytes[] results)
```

Batches multiple router calls into a single transaction.

Parameters

| Name   | Type      | Description                              |
| ------ | --------- | ---------------------------------------- |
| `data` | `bytes[]` | Encoded calldata for each internal call. |

Return Values

| Name      | Type      | Description                        |
| --------- | --------- | ---------------------------------- |
| `results` | `bytes[]` | Return data for each batched call. |

### unwrapWETH9

```solidity
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable
```

Unwraps the router's wrapped native token balance and sends native MNT to `recipient`.

Parameters

| Name            | Type      | Description                                               |
| --------------- | --------- | --------------------------------------------------------- |
| `amountMinimum` | `uint256` | Minimum wrapped balance that must be available to unwrap. |
| `recipient`     | `address` | Recipient of the unwrapped native token.                  |

This function does not return a value.

### unwrapWETH9WithFee

```solidity
function unwrapWETH9WithFee(uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) public payable
```

Unwraps the router's wrapped native balance, splits out a fee, and sends the remainder to `recipient`.

Parameters

| Name            | Type      | Description                                                     |
| --------------- | --------- | --------------------------------------------------------------- |
| `amountMinimum` | `uint256` | Minimum wrapped balance required before unwrapping.             |
| `recipient`     | `address` | Recipient of the net native token amount.                       |
| `feeBips`       | `uint256` | Fee share in basis points, capped by the matched source at 100. |
| `feeRecipient`  | `address` | Recipient of the fee amount.                                    |

This function does not return a value.

### refundETH

```solidity
function refundETH() external payable
```

Refunds any remaining native token balance held by the router back to the caller.

This function does not take parameters.

This function does not return a value.

### sweepToken

```solidity
function sweepToken(address token, uint256 amountMinimum, address recipient) external payable
```

Transfers the router's full balance of `token` to `recipient`, subject to a minimum balance check.

Parameters

| Name            | Type      | Description                                   |
| --------------- | --------- | --------------------------------------------- |
| `token`         | `address` | Token to transfer out of the router.          |
| `amountMinimum` | `uint256` | Minimum token balance required for the sweep. |
| `recipient`     | `address` | Recipient of the swept tokens.                |

This function does not return a value.

### sweepTokenWithFee

```solidity
function sweepTokenWithFee(address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) public payable
```

Transfers the router's full balance of `token`, splitting out a fee before sending the remainder to `recipient`.

Parameters

| Name            | Type      | Description                                                     |
| --------------- | --------- | --------------------------------------------------------------- |
| `token`         | `address` | Token held by the router.                                       |
| `amountMinimum` | `uint256` | Minimum token balance required for the sweep.                   |
| `recipient`     | `address` | Recipient of the net token amount.                              |
| `feeBips`       | `uint256` | Fee share in basis points, capped by the matched source at 100. |
| `feeRecipient`  | `address` | Recipient of the fee amount.                                    |

This function does not return a value.

### selfPermit

```solidity
function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public payable
```

Calls EIP-2612 `permit` on `token` so the router can spend it in the same transaction.

Parameters

| Name       | Type      | Description                           |
| ---------- | --------- | ------------------------------------- |
| `token`    | `address` | Token that supports EIP-2612 permits. |
| `value`    | `uint256` | Allowance value to approve.           |
| `deadline` | `uint256` | Permit expiration timestamp.          |
| `v`        | `uint8`   | Signature recovery byte.              |
| `r`        | `bytes32` | Signature `r` value.                  |
| `s`        | `bytes32` | Signature `s` value.                  |

This function does not return a value.

### selfPermitIfNecessary

```solidity
function selfPermitIfNecessary(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable
```

Calls `selfPermit` only if the caller's current allowance is lower than `value`.

Parameters

| Name       | Type      | Description                           |
| ---------- | --------- | ------------------------------------- |
| `token`    | `address` | Token that supports EIP-2612 permits. |
| `value`    | `uint256` | Allowance value to ensure.            |
| `deadline` | `uint256` | Permit expiration timestamp.          |
| `v`        | `uint8`   | Signature recovery byte.              |
| `r`        | `bytes32` | Signature `r` value.                  |
| `s`        | `bytes32` | Signature `s` value.                  |

This function does not return a value.

### selfPermitAllowed

```solidity
function selfPermitAllowed(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public payable
```

Calls the DAI-style `permit` flow on tokens that implement the allowed-permit extension.

Parameters

| Name     | Type      | Description                                       |
| -------- | --------- | ------------------------------------------------- |
| `token`  | `address` | Token that supports the allowed-permit extension. |
| `nonce`  | `uint256` | Permit nonce.                                     |
| `expiry` | `uint256` | Permit expiration timestamp.                      |
| `v`      | `uint8`   | Signature recovery byte.                          |
| `r`      | `bytes32` | Signature `r` value.                              |
| `s`      | `bytes32` | Signature `s` value.                              |

This function does not return a value.

### selfPermitAllowedIfNecessary

```solidity
function selfPermitAllowedIfNecessary(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external payable
```

Calls `selfPermitAllowed` only if the caller has not already granted the router a maximum allowance.

Parameters

| Name     | Type      | Description                                       |
| -------- | --------- | ------------------------------------------------- |
| `token`  | `address` | Token that supports the allowed-permit extension. |
| `nonce`  | `uint256` | Permit nonce.                                     |
| `expiry` | `uint256` | Permit expiration timestamp.                      |
| `v`      | `uint8`   | Signature recovery byte.                          |
| `r`      | `bytes32` | Signature `r` value.                              |
| `s`      | `bytes32` | Signature `s` value.                              |

This function does not return a value.


---

# 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://fluxion-network.gitbook.io/fluxion-network/developer-resources/technical-overview-and-api/amm-v3-swaprouter.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.
