# UniversalRouter

해당 컨트랙트는 V2 및 V3 풀을 사용하는 KLAYswap 라우터입니다. 이 계약은 V2 및 V3 풀에서 거래를 집계하여 사용자가 매우 유연하고 개인화된 거래에 액세스할 수 있도록 합니다.

## Code

Github Link: (Will be updated after official launch)<br>

## Address

* Cypress : [0xCf4dd4bFd6cB096E695C0e555642dE2F2559A370](https://klaytnscope.com/account/0xCf4dd4bFd6cB096E695C0e555642dE2F2559A370?tabId=txList)

## Events, Read-Only Functions, and State-Changing Functions

{% tabs %}
{% tab title="Parameter Structs" %}

## Parameter Structs

**SwapParams**

```solidity
struct SwapParams {
    address to;
    address[] path;
    address[] pool;
    uint256 deadline;
}
```

**Parameters:**

<table><thead><tr><th width="142.66666666666663">Name</th><th width="107">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>to</code></td><td>address</td><td>교환 후 토큰을 받게 될 주소</td></tr><tr><td><code>path</code></td><td>address[]</td><td>스왑 경로(토큰 주소 목록)</td></tr><tr><td><code>pool</code></td><td>address[]</td><td>스왑의 풀 경로(풀 주소 목록) <br>v2 pool 사용 시 : <code>address(0)</code> <br>v3 pool 사용 시 : <code>v3 풀 주소</code></td></tr><tr><td><code>deadline</code></td><td>uint256</td><td>deadline</td></tr></tbody></table>
{% endtab %}

{% tab title="Read-Only Functions" %}

## Read-Only Functions

**getAmountsOut**

```solidity
function getAmountsOut(
    uint256 amountIn, 
    address[] memory path, 
    address[] memory pool
) public view returns (
    uint256[] memory amounts
)
```

**Parameters:**

<table><thead><tr><th width="142.66666666666663">Name</th><th width="107">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountIn</code></td><td>uint256</td><td>지불해야 하는 첫 번째 토큰의 양</td></tr><tr><td><code>path</code></td><td>address[]</td><td>스왑 경로(토큰 주소 목록)</td></tr><tr><td><code>pool</code></td><td>address[]</td><td>스왑의 풀 경로(풀 주소 목록) <br>v2 pool 사용 시 : <code>address(0)</code> <br>v3 pool 사용 시 : <code>v3 풀 주소</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

**getAmountsIn**

```solidity
function getAmountsIn(
    uint256 amountOut, 
    address[] memory path, 
    address[] memory pool
) public view returns (
    uint256[] memory amounts
)
```

**Parameters:**

<table><thead><tr><th width="147.66666666666666">Name</th><th width="107">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountOut</code></td><td>uint256</td><td>마지막으로 받을 토큰의 양</td></tr><tr><td><code>path</code></td><td>address[]</td><td>스왑 경로(토큰 주소 목록)</td></tr><tr><td><code>pool</code></td><td>address[]</td><td>스왑의 풀 경로(풀 주소 목록) <br>v2 pool 사용 시 : <code>address(0)</code> <br>v3 pool 사용 시 : <code>v3 풀 주소</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>
{% endtab %}

{% tab title="State-Changing Functions" %}

## **State-Changing Functions**

**swapExactTokensForTokens**

```solidity
function swapExactTokensForTokens(
    uint256 amountIn, 
    uint256 amountOutMin, 
    struct SwapParams calldata p
) external returns (uint256[] memory amounts)
```

경로에 의해 결정된 경로를 따라 가능한 한 많은 출력 토큰에 대해 정확한 양의 입력 토큰을 교환합니다.

**Parameters:**

<table><thead><tr><th width="142.66666666666663">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountIn</code></td><td>uint256</td><td>지불할 입력 토큰의 양</td></tr><tr><td><code>amountOutMin</code></td><td>uint256</td><td>트랜잭션이 되돌리지 않기 위해 받아야 하는 출력 토큰의 최소량</td></tr><tr><td><code>p</code></td><td><code>struct SwapParams</code> </td><td>스왑을 위한 <code>struct SwapParams</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

**swapTokensForExactTokens**

```solidity
function swapTokensForExactTokens(
    uint256 amountOut, 
    uint256 amountInMax, 
    struct SwapParams calldata p
) external returns (uint256[] memory amounts)
```

경로에 의해 결정된 경로를 따라 가능한 한 적은 입력 토큰에 대해 정확한 양의 출력 토큰을 받습니다.

**Parameters:**

<table><thead><tr><th width="169.66666666666663">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountOut</code></td><td>uint256</td><td>받을 출력 토큰의 양</td></tr><tr><td><code>amountInMax</code></td><td>uint256</td><td>트랜잭션이 되돌리기 전에 필요할 수 있는 입력 토큰의 최대 양</td></tr><tr><td><code>p</code></td><td><code>struct SwapParams</code> </td><td>스왑을 위한 <code>struct SwapParams</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

**swapExactETHForTokens**

```solidity
function swapExactETHForTokens(
    uint256 amountOutMin, 
    struct SwapParams calldata p
) external payable returns (uint256[] memory amounts)
```

경로에 의해 결정된 경로를 따라 가능한 한 많은 출력 토큰에 대해 정확한 양의 ETH를 교환합니다.

**Parameters:**

<table><thead><tr><th width="173.66666666666663">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>msg.value</code></td><td>uint256</td><td>지불할 ETH 금액</td></tr><tr><td><code>amountOutMin</code></td><td>uint256</td><td>트랜잭션이 되돌리지 않기 위해 받아야 하는 출력 토큰의 최소량</td></tr><tr><td><code>p</code></td><td><code>struct SwapParams</code> </td><td>스왑을 위한 <code>struct SwapParams</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

**swapTokensForExactETH**

```solidity
function swapTokensForExactETH(
    uint256 amountOut, 
    uint256 amountInMax, 
    struct SwapParams calldata p
) external returns (uint256[] memory amounts)
```

경로에 의해 결정된 경로를 따라 가능한 한 적은 입력 토큰에 대해 정확한 양의 ETH를 받습니다.

**Parameters:**

<table><thead><tr><th width="173.66666666666663">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountOut</code></td><td>uint256</td><td>받을 ETH 금액</td></tr><tr><td><code>amountInMax</code></td><td>uint256</td><td>트랜잭션이 되돌리기 전에 필요할 수 있는 입력 토큰의 최대 양</td></tr><tr><td><code>p</code></td><td><code>struct SwapParams</code> </td><td>스왑을 위한 <code>struct SwapParams</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

**swapExactTokensForETH**

```solidity
function swapExactTokensForETH(
    uint256 amountIn, 
    uint256 amountOutMin, 
    struct SwapParams calldata p
) external returns (uint256[] memory amounts)
```

경로에 의해 결정된 경로를 따라 가능한 한 많은 ETH에 대해 정확한 양의 토큰을 스왑합니다.

**Parameters:**

<table><thead><tr><th width="173.66666666666663">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountIn</code></td><td>uint256</td><td>지불할 입력 토큰의 양</td></tr><tr><td><code>amountOutMin</code></td><td>uint256</td><td>트랜잭션이 되돌리지 않기 위해 받아야 하는 출력 토큰의 최소량</td></tr><tr><td><code>p</code></td><td><code>struct SwapParams</code> </td><td>스왑을 위한 <code>struct SwapParams</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

**swapETHForExactTokens**

```solidity
function swapETHForExactTokens(
    uint256 amountOut,
    struct SwapParams calldata p
) external payable returns (uint256[] memory amounts)
```

경로에 의해 결정된 경로를 따라 가능한 한 많은 ETH에 대해 정확한 양의 토큰을 스왑합니다.

**Parameters:**

<table><thead><tr><th width="173.66666666666663">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amountOut</code></td><td>uint256</td><td>받을 토큰의 양</td></tr><tr><td><code>msg.value</code> (amountInMax)</td><td>uint256</td><td>트랜잭션을 되돌리기 전에 요구할 수 있는 최대 ETH 금액</td></tr><tr><td><code>p</code></td><td><code>struct SwapParams</code> </td><td>스왑을 위한 <code>struct SwapParams</code></td></tr></tbody></table>

**Return Values:**

<table><thead><tr><th width="129.66666666666666">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amounts</code></td><td>uint256[]</td><td>입력 토큰 금액 및 모든 후속 출력 토큰 금액.</td></tr></tbody></table>

{% endtab %}
{% endtabs %}
