> For the complete documentation index, see [llms.txt](https://pangeaswap.gitbook.io/pangeaswap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pangeaswap.gitbook.io/pangeaswap/en/developers/contracts/core-contracts/poolrouter.md).

# PoolRouter

{% embed url="<https://github.com/pangea-protocol/pangea-core/blob/main/contracts/pool/PoolRouter.sol>" %}

## Overview

![](/files/L1IYteyPhdjKaHtInd3M)

PoolRouter is an intermediary that allows you to swap tokens in multiple pools of Pangea. Currently supports exactInputSingle and will expand to support various swaps with exactOutput, exactOutputSingle, complexPathSwap.

## Methods

### exactInput

```solidity
function exactInput(IRouter.ExactInputParams params) external payable returns (uint256 amountOut)
```

swap amountIn of one token for as much as possible of another token

**Parameters**

| Name   | Type                     | Description                                                                                                       |
| ------ | ------------------------ | ----------------------------------------------------------------------------------------------------------------- |
| params | IRouter.ExactInputParams | abi.encode(address tokenIn, uint256 amountIn, uint256 amountOutMinimum, address\[] path, address to, bool unwrap) |

**IRouter.ExactInputParams Struct**

<table><thead><tr><th></th><th width="249.33333333333331"></th><th>Description</th></tr></thead><tbody><tr><td>tokenIn</td><td>address</td><td>the input token address. If tokenIn is address(0), msg.value will be wrapped and used as input token </td></tr><tr><td>amountIn</td><td>uint256</td><td>the amount of input tokens to send.</td></tr><tr><td>amountOutMinimum</td><td>amountOutMinimum</td><td>minimum required amount of output token after swap</td></tr><tr><td>path</td><td>address[]</td><td>an array of pool addresses to pass through</td></tr><tr><td>to</td><td>address</td><td>recipient of the output tokens</td></tr><tr><td>unwrap</td><td>bool</td><td>unwrap if output token is wrapped klay</td></tr></tbody></table>

### exactInputSingle

```solidity
function exactInputSingle(IRouter.ExactInputSingleParams params) external payable returns (uint256 amountOut)
```

swap amountIn of one token for as much as possible of another token along the specified path

**Parameters**

| Name   | Type                           | Description                                                                                                    |
| ------ | ------------------------------ | -------------------------------------------------------------------------------------------------------------- |
| params | IRouter.ExactInputSingleParams | abi.encode(address tokenIn, uint256 amountIn, uint256 amountOutMinimum, address pool, address to, bool unwrap) |

**IRouter.ExactInputSingleParams Struct**

|                  |         |                                                                                                      |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------- |
| tokenIn          | address | the input token address. If tokenIn is address(0), msg.value will be wrapped and used as input token |
| amountIn         | uint256 | the amount of input token to send                                                                    |
| amountOutMinimum | uint256 | minimum required amount of output token after swap                                                   |
| pool             | address | pool address to swap                                                                                 |
| to               | address | address to receive output tokens                                                                     |
| unwrap           | bool    | unwrap if output token is wrapped klay                                                               |

### exactOutput

```solidity
function exactOutput(IRouter.ExactOutputParams params) external payable returns (uint256 amountIn)  . 
```

Swaps as little as possible of one token for `amountOut` of another token

**Parameters**

| Name   | Type                      | Description                                                                                                       |
| ------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| params | IRouter.ExactOutputParams | abi.encode(address tokenIn, uint256 amountOut, uint256 amountInMaximum, address\[] path, address to, bool unwrap) |

**IRouter.ExactOutputParams Struct**

<table><thead><tr><th></th><th width="249.33333333333331"></th><th>Description</th></tr></thead><tbody><tr><td>tokenIn</td><td>address</td><td>the input token address. If <code>tokenIn</code> is address(0), <code>msg.value</code> will be wrapped and used as input token </td></tr><tr><td>amountOut</td><td>uint256</td><td>the amount of output tokens to receive</td></tr><tr><td>amountInMaximum</td><td>uint256</td><td>maximum available amount of input token for swap</td></tr><tr><td>path</td><td>address[]</td><td>an array of pool addresses to pass through</td></tr><tr><td>to</td><td>address</td><td>recipient of the output tokens</td></tr><tr><td>unwrap</td><td>bool</td><td>unwrap if output token is wrapped KLAY</td></tr></tbody></table>

### exactOutputSingle

```solidity
function exactOutputSingle(IRouter.ExactOutputSingleParams params) external payable returns (uint256 amountOut)
```

Swaps `amountIn` of one token for as much as possible of another token along the specified path

**Parameters**

| Name   | Type                            | Description                                                                                                    |
| ------ | ------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| params | IRouter.ExactOutputSingleParams | abi.encode(address tokenIn, uint256 amountOut, uint256 amountInMaximum, address pool, address to, bool unwrap) |

**IRouter.ExactOutputSingleParams Struct**

|                 |         |                                                                                                          |
| --------------- | ------- | -------------------------------------------------------------------------------------------------------- |
| tokenIn         | address | the input token address. If `tokenIn` is address(0), `msg.value` will be wrapped and used as input token |
| amountOut       | uint256 | the amount of input token to send                                                                        |
| amountInMaximum | uint256 | maximum available amount of input token for swap                                                         |
| pool            | address | pool address to swap                                                                                     |
| to              | address | address to receive output tokens                                                                         |
| unwrap          | bool    | unwrap if output token is wrapped KLAY                                                                   |

### sweep

```solidity
function sweep(address token, uint256 amount, address recipient) external payable
```

Recover mistakenly sent tokens


---

# 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://pangeaswap.gitbook.io/pangeaswap/en/developers/contracts/core-contracts/poolrouter.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.
