UniversalRouter
Last updated
Was this helpful?
Last updated
Was this helpful?
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)
Cypress :
SwapParams
struct SwapParams {
address to;
address[] path;
address[] pool;
uint deadline;
}
Parameters:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
amounts
uint256[]
The input token amount and all subsequent output token amounts.