Router

Because routers are stateless and do not hold token balances, they can be replaced safely and trustlessly, if necessary. This may happen if more efficient smart contract patterns are discovered, or if additional functionality is desired.

Code

DragonswapRouter.sol

Read-Only Functions

factory

function factory() external pure returns (address);

Returns factory address.

WSEI

function WSEI() external pure returns (address);

Returns the canonical WSEI address on the SEI V2 mainnet.

quote

See quote.

getAmountOut

See getAmountOut.

getAmountIn

See getAmountIn.

getAmountsOut

function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts);

See getAmountsOut.

getAmountsIn

function getAmountsIn(uint amountOut, address[] memory path) public view returns (uint[] memory amounts);

See getAmountsIn.

State-Changing Functions

addLiquidity

function addLiquidity(
  address tokenA,
  address tokenB,
  uint amountADesired,
  uint amountBDesired,
  uint amountAMin,
  uint amountBMin,
  address to,
  uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);

Adds liquidity to an ERC-20⇄ERC-20 pool.

  • To cover all possible scenarios, msg.sender should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.

  • Always adds assets at the ideal ratio, according to the price when the transaction is executed.

  • If a pool for the passed tokens does not exists, one is created automatically, and exactly amountADesired/amountBDesired tokens are added.

addLiquiditySEI

function addLiquiditySEI(
  address token,
  uint amountTokenDesired,
  uint amountTokenMin,
  uint amountSEIMin,
  address to,
  uint deadline
) external payable returns (uint amountToken, uint amountSEI, uint liquidity);

Adds liquidity to an ERC-20⇄WSEI pool with SEI.

  • To cover all possible scenarios, msg.sender should have already given the router an allowance of at least amountTokenDesired on token.

  • Always adds assets at the ideal ratio, according to the price when the transaction is executed.

  • msg.value is treated as a amountSEIDesired.

  • Leftover SEI, if any, is returned to msg.sender.

  • If a pool for the passed token and WSEI does not exists, one is created automatically, and exactly amountTokenDesired/msg.value tokens are added.

removeLiquidity

function removeLiquidity(
  address tokenA,
  address tokenB,
  uint liquidity,
  uint amountAMin,
  uint amountBMin,
  address to,
  uint deadline
) external returns (uint amountA, uint amountB);

Removes liquidity from an ERC-20⇄ERC-20 pool.

  • msg.sender should have already given the router an allowance of at least liquidity on the pool.

removeLiquiditySEI

function removeLiquiditySEI(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountSEIMin,
  address to,
  uint deadline
) external returns (uint amountToken, uint amountSEI);

Removes liquidity from an ERC-20⇄WSEI pool and receive SEI.

  • msg.sender should have already given the router an allowance of at least liquidity on the pool.

removeLiquidityWithPermit

function removeLiquidityWithPermit(
  address tokenA,
  address tokenB,
  uint liquidity,
  uint amountAMin,
  uint amountBMin,
  address to,
  uint deadline,
  bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);

Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval, thanks to permit.

removeLiquiditySEIWithPermit

function removeLiquiditySEIWithPermit(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountSEIMin,
  address to,
  uint deadline,
  bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountSEI);

Removes liquidity from an ERC-20⇄WSEI pool and receive SEI without pre-approval, thanks to permit.

removeLiquiditySEISupportingFeeOnTransferTokens

function removeLiquiditySEISupportingFeeOnTransferTokens(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountSEIMin,
  address to,
  uint deadline
) external returns (uint amountSEI);

Identical to removeLiquiditySEI, but succeeds for tokens that take a fee on transfer.

  • msg.sender should have already given the router an allowance of at least liquidity on the pool.

removeLiquiditySEIWithPermitSupportingFeeOnTransferTokens

function removeLiquiditySEIWithPermitSupportingFeeOnTransferTokens(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountSEIMin,
  address to,
  uint deadline,
  bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountSEI);

Identical to removeLiquiditySEIWithPermit, but succeeds for tokens that take a fee on transfer.

swapExactTokensForTokens

function swapExactTokensForTokens(
  uint amountIn,
  uint amountOutMin,
  address[] calldata path,
  address to,
  uint deadline
) external returns (uint[] memory amounts);

Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

  • msg.sender should have already given the router an allowance of at least amountIn on the input token.

swapTokensForExactTokens

function swapTokensForExactTokens(
  uint amountOut,
  uint amountInMax,
  address[] calldata path,
  address to,
  uint deadline
) external returns (uint[] memory amounts);

Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last is the output token, and any intermediate elements represent intermediate tokens to trade through (if, for example, a direct pair does not exist).

  • msg.sender should have already given the router an allowance of at least amountInMax on the input token.

swapExactSEIForTokens

function swapExactSEIForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
  external
  payable
  returns (uint[] memory amounts);

Swaps an exact amount of SEI for as many output tokens as possible, along the route determined by the path. The first element of path must be WSEI, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

swapTokensForExactSEI

function swapTokensForExactSEI(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
  external
  returns (uint[] memory amounts);

Receive an exact amount of SEI for as few input tokens as possible, along the route determined by the path. The first element of path is the input token, the last must be WSEI, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

  • msg.sender should have already given the router an allowance of at least amountInMax on the input token.

  • If the to address is a smart contract, it must have the ability to receive SEI.

swapExactTokensForSEI

function swapExactTokensForSEI(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
  external
  returns (uint[] memory amounts);

Swaps an exact amount of tokens for as much SEI as possible, along the route determined by the path. The first element of path is the input token, the last must be WSEI, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

  • If the to address is a smart contract, it must have the ability to receive SEI.

swapSEIForExactTokens

function swapSEIForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
  external
  payable
  returns (uint[] memory amounts);

Receive an exact amount of tokens for as little SEIas possible, along the route determined by the path. The first element of path must be WETH, the last is the output token and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

  • Leftover SEI, if any, is returned to msg.sender.

swapExactTokensForTokensSupportingFeeOnTransferTokens

function swapExactTokensForTokensSupportingFeeOnTransferTokens(
  uint amountIn,
  uint amountOutMin,
  address[] calldata path,
  address to,
  uint deadline
) external;

Identical to swapExactTokensForTokens, but succeeds for tokens that take a fee on transfer.

  • msg.sender should have already given the router an allowance of at least amountIn on the input token.

swapExactSEIForTokensSupportingFeeOnTransferTokens

function swapExactSEIForTokensSupportingFeeOnTransferTokens(
  uint amountOutMin,
  address[] calldata path,
  address to,
  uint deadline
) external payable;

Identical to swapExactSEIForTokens, but succeeds for tokens that take a fee on transfer.

swapExactTokensForSEISupportingFeeOnTransferTokens

function swapExactTokensForSEISupportingFeeOnTransferTokens(
  uint amountIn,
  uint amountOutMin,
  address[] calldata path,
  address to,
  uint deadline
) external;

Identical to swapExactTokensForSEI, but succeeds for tokens that take a fee on transfer.

  • If the to address is a smart contract, it must have the ability to receive SEI.

Interface

pragma solidity >=0.6.2;

interface IDragonswapRouter {
    function factory() external pure returns (address);
    function WSEI() external pure returns (address);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquiditySEI(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountSEIMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountSEI, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquiditySEI(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountSEIMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountSEI);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquiditySEIWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountSEIMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountSEI);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactSEIForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactSEI(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForSEI(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapSEIForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function removeLiquiditySEISupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountSEIMin,
        address to,
        uint deadline
    ) external returns (uint amountSEI);
    function removeLiquiditySEIWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountSEIMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountSEI);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactSEIForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForSEISupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

ABI

https://github.com/dragonswap-app/dragonswap-core/blob/7daf58214605f2bcbb2b06d295acc1d891437fc7/deployments/abis.json#L3

Last updated