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.
Github Link: (Will be updated after official launch)
Parameter Structs
Read-Only Functions
State-Changing Functions
SwapParams
struct SwapParams {
address to;
address[] path;
address[] pool;
uint deadline;
}
Parameters:
Name | Type | Description |
---|---|---|
to | address | Address to receive tokens after swap |
path | address[] | Swap paths (token address list) |
pool | address[] | Pool paths in swap (list of pool addresses) When using v2 pool: address(0) When using v3 pool: v3 pool address |
deadline | uint256 | deadline |
getAmountsOut
function getAmountsOut(
uint256 amountIn,
address[] memory path,
address[] memory pool
) public view returns (
uint256[] memory amounts
)
Parameters:
Name | Type | Description |
---|---|---|
amountIn | uint256 | The amount of first token required to be paid |
path | address[] | The path of the swap (list of token addresses) |
pool | address[] | The pool path of the swap (list of pool addresses)
When using v2 pool : address(0)
When using v3 pool : address of v3 pool |
Return Values:
Name | Type | Description |
---|---|---|
amounts | 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 |
---|---|---|
amountOut | uint256 | The amount of the last token that would be received |
path | address[] | The token path of the swap (list of token addresses) |
pool | address[] | The pool path of the swap (list of pool addresses)
When using v2 pool : address(0)
When using v3 pool : address of v3 pool |
Return Values:
Name | Type | Description |
---|---|---|
amounts | uint256[] | The input token amount and all subsequent output token amounts. |
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 |
---|---|---|
amountIn | uint256 | The amount of input tokens to paid |
amountOutMin | uint256 | The minimum amount of output tokens that must be received for the transaction not to revert |
p | struct SwapParams | struct SwapParams for swap |
Return Values:
Name | Type | Description |
---|---|---|
amounts | 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 |
---|---|---|
amountOut | uint256 | The amount of output tokens to receive |
amountInMax | uint256 | The maximum amount of input tokens that can be required before the transaction reverts |
p | struct SwapParams | struct SwapParams for swap |
Return Values:
Name | Type | Description |
---|---|---|
amounts | 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 |
---|---|---|
msg.value | uint256 | The amount of ETH to be paid |
amountOutMin | uint256 | The minimum amount of output tokens that must be received for the transaction not to revert |
p | struct SwapParams | struct SwapParams for swap |
Return Values:
Name | Type | Description |
---|---|---|
amounts | 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 |
---|---|---|
amountOut | uint256 | The amount of ETH to receive |
amountInMax | uint256 | The maximum amount of input tokens that can be required before the transaction reverts |
p | struct SwapParams | struct SwapParams for swap |
Return Values:
Name | Type | Description |
---|---|---|
amounts | 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 |
---|---|---|
amountIn | uint256 | The amount of input tokens to be paid |
amountOutMin | uint256 | The minimum amount of output tokens that must be received for the transaction not to revert |
p | struct SwapParams | struct SwapParams for swap |
Return Values:
Name | Type | Description |
---|---|---|
amounts | 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 |
---|---|---|
amountOut | uint256 | The amount of tokens to receive |
msg.value (amountInMax) | uint256 | The maximum amount of ETH that can be required before the transaction revert |
p | struct SwapParams | struct SwapParams for swap |
Return Values:
Name | Type | Description |
---|---|---|
amounts | uint256[] | The input token amount and all subsequent output token amounts. |
Last modified 2mo ago