UniversalRouter
This contract is KLAYswap router using V2 and V3 pools. This contract can aggregate trades across V2 and V3 pools to give users access highly-flexible and personalised transactions.
Code
Github Link: (Will be updated after official launch)
Address
Events, Read-Only Functions, and State-Changing Functions
Parameter Structs
SwapParams
struct SwapParams {
address to;
address[] path;
address[] pool;
uint deadline;
}
Parameters:
Name | Type | Description |
---|---|---|
| address | Address to receive tokens after swap |
| address[] | Swap paths (token address list) |
| address[] | Pool paths in swap (list of pool addresses) When using v2 pool: When using v3 pool: v3 pool address |
| uint256 | deadline |
Read-Only Functions
getAmountsOut
function getAmountsOut(
uint256 amountIn,
address[] memory path,
address[] memory pool
) public view returns (
uint256[] memory amounts
)
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of first token required to be paid |
| address[] | The path of the swap (list of token addresses) |
| address[] | The pool path of the swap (list of pool addresses)
When using v2 pool : |
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
getAmountsIn
function getAmountsIn(
uint256 amountOut,
address[] memory path,
address[] memory pool
) public view returns (
uint256[] memory amounts
)
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of the last token that would be received |
| address[] | The token path of the swap (list of token addresses) |
| address[] | The pool path of the swap (list of pool addresses)
When using v2 pool : |
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
State-Changing Functions
swapExactTokensForTokens
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
struct SwapParams calldata p
) external returns (uint256[] memory amounts)
Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path.
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of input tokens to paid |
| uint256 | The minimum amount of output tokens that must be received for the transaction not to revert |
|
|
|
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
swapTokensForExactTokens
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
struct SwapParams calldata p
) external returns (uint256[] memory amounts)
Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path.
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of output tokens to receive |
| uint256 | The maximum amount of input tokens that can be required before the transaction reverts |
|
|
|
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
swapExactETHForTokens
function swapExactETHForTokens(
uint256 amountOutMin,
struct SwapParams calldata p
) external payable returns (uint256[] memory amounts)
Swaps an exact amount of ETH for as many output tokens as possible, along the route determined by the path
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of ETH to be paid |
| uint256 | The minimum amount of output tokens that must be received for the transaction not to revert |
|
|
|
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
swapTokensForExactETH
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
struct SwapParams calldata p
) external returns (uint256[] memory amounts)
Receive an exact amount of ETH for as few input tokens as possible, along the route determined by the path.
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of ETH to receive |
| uint256 | The maximum amount of input tokens that can be required before the transaction reverts |
|
|
|
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
swapExactTokensForETH
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
struct SwapParams calldata p
) external returns (uint256[] memory amounts)
Swaps an exact amount of tokens for as much ETH as possible, along the route determined by the path.
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of input tokens to be paid |
| uint256 | The minimum amount of output tokens that must be received for the transaction not to revert |
|
|
|
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
swapETHForExactTokens
function swapETHForExactTokens(
uint256 amountOut,
struct SwapParams calldata p
) external payable returns (uint256[] memory amounts)
Swaps an exact amount of tokens for as much ETH as possible, along the route determined by the path.
Parameters:
Name | Type | Description |
---|---|---|
| uint256 | The amount of tokens to receive |
| uint256 | The maximum amount of ETH that can be required before the transaction revert |
|
|
|
Return Values:
Name | Type | Description |
---|---|---|
| uint256[] | The input token amount and all subsequent output token amounts. |
Last updated