KLAYswap
English
English
  • Introduction
  • Protocol Overview
  • Core Concept
  • KLAYswap Advantages
  • Risk & Security
  • Privacy Policy
  • Audit
  • TOKENOMICS
    • KSP
      • KSP TOKENOMICS
      • Automation of KSP distribution rate
        • Voting policy on passing governance
        • KSP distribution ratio reflection policy
      • KSP Allocation
  • PRODUCT
    • SWAP
    • Single-side Deposit
      • Detailed policy of Single Deposit
    • Pair Deposit
    • V3 Pair Deposit
      • V2 to V3 Migration
        • V2 to V3 Migration Guide
        • V2 to V3 Migration Policy
      • V3 Pair Deposit
        • V3 Deposit Guide
        • V3 pair Deposit Policy
      • V3 to V3 Migration
        • V3 to V3 Migration Guide
        • V3 to V3 Migration Policy
      • V3 Pair Withdraw
        • V3 Withdraw Guide
        • V3 Withdraw Policy
    • Plus Deposit
      • Detailed policy of Plus Deposit
    • Long/Short Position Deposit
      • Open and Close Long/Short Positions
        • Open Short Positions
        • Open Long Positions
        • Remove Long Position
        • Remove Short Position
      • Position Deposit Details Policy
    • KSP Staking & Voting
      • Staking, Pool Voting Policy
    • Governance
      • Governance Voting Policy
    • Drops
    • Ecopot
    • Pool Airdrop
    • APR & APY
      • TVL
      • Pool
      • Staking
    • Interest rate
  • DEVELOPERS
    • Contract
      • Factory
      • Exchange
      • PoolVoting
      • VotingKSP
      • Treasury
      • Distribution
      • Governor
      • SinglePool
      • SinglePool Factory
      • PlusPool
      • PlusPool Factory
      • Store
      • Utils
      • Single/Plus Utils
      • Helper
      • EcoPotVoting
      • EcoPot
      • V3
        • V3Factory
        • V3Pool
        • NonfungiblePositionManager
        • NonfungibleTokenPositionDescriptor
        • V3SwapRouter
        • V3Migrator
        • V3Estimator
        • PositionMigrator
        • V3Treasury
        • V3AirdropOperator
        • UniversalRouter
    • Airdrop
      • Set Airdrop Operator
      • Start Airdrop
    • EcoPot
      • Set EcoPot
      • Start EcoPot
  • HOW-TO GUIDES
    • KLAYswap Guide
    • How to add liquidity on KLAYswap
    • [Burrito Wallet] How to deposit assets using mobile devices?
    • How to create a liquidity pool on KLAYswap
    • How to stake and vote on KLAYswap
    • How to deposit assets
      • Deposit Klaytn-based assets
      • Deposit Ethereum-based assets
      • Deposit XRP
    • FAQ
  • KLAYswap
  • Orbit Bridge
  • KLAYswap git
  • Orbit Bridge git
  • KLAYswap audit report
Powered by GitBook
On this page
  • Code
  • Address
  • Events, Read-Only Functions, and State-Changing Functions

Was this helpful?

  1. DEVELOPERS
  2. Contract
  3. V3

UniversalRouter

PreviousV3AirdropOperatorNextAirdrop

Last updated 1 year ago

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.

Code

Github Link: (Will be updated after official launch)

Address

  • Cypress :

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

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

Read-Only Functions

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.

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

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.

0xe0fbB27D0E7F3a397A67a9d4864D4f4DD7cF8cB9