CenturionDEX
Launch App

Router02

Last modified:

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. For this reason, routers have release numbers, starting at 01. This is currently recommended release, 02.

Code

CenturionV2Router02.sol

Address

CenturionV2Router02 is deployed at 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D on the Ethereum mainnet, and the Ropsten, Rinkeby, Görli, and Kovan testnets. It was built from commit 6961711.

Read-Only Functions

factory

function factory() external pure returns (address);

Returns factory address.

WCTN

function WCTN() external pure returns (address);

Returns the canonical WCTN address on the Ethereum mainnet, or the Ropsten, Rinkeby, Görli, or Kovan testnets.

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.

NameType
tokenAaddressA pool token.
tokenBaddressA pool token.
amountADesireduintThe amount of tokenA to add as liquidity if the B/A price is = amountBDesired/amountADesired (A depreciates).
amountBDesireduintThe amount of tokenB to add as liquidity if the A/B price is = amountADesired/amountBDesired (B depreciates).
amountAMinuintBounds the extent to which the B/A price can go up before the transaction reverts. Must be = amountADesired.
amountBMinuintBounds the extent to which the A/B price can go up before the transaction reverts. Must be = amountBDesired.
toaddressRecipient of the liquidity tokens.
deadlineuintUnix timestamp after which the transaction will revert.
amountAuintThe amount of tokenA sent to the pool.
amountBuintThe amount of tokenB sent to the pool.
liquidityuintThe amount of liquidity tokens minted.

addLiquidityCTN

function addLiquidityCTN(
  address token,
  uint amountTokenDesired,
  uint amountTokenMin,
  uint amountCTNMin,
  address to,
  uint deadline
) external payable returns (uint amountToken, uint amountCTN, uint liquidity);

Adds liquidity to an ERC-20⇄WCTN pool with CTN.

NameType
tokenaddressA pool token.
amountTokenDesireduintThe amount of token to add as liquidity if the WCTN/token price is = msg.value/amountTokenDesired (token depreciates).
msg.value (amountCTNDesired)uintThe amount of CTN to add as liquidity if the token/WCTN price is = amountTokenDesired/msg.value (WCTN depreciates).
amountTokenMinuintBounds the extent to which the WCTN/token price can go up before the transaction reverts. Must be = amountTokenDesired.
amountCTNMinuintBounds the extent to which the token/WCTN price can go up before the transaction reverts. Must be = msg.value.
toaddressRecipient of the liquidity tokens.
deadlineuintUnix timestamp after which the transaction will revert.
amountTokenuintThe amount of token sent to the pool.
amountCTNuintThe amount of CTN converted to WCTN and sent to the pool.
liquidityuintThe amount of liquidity tokens minted.

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.

NameType
tokenAaddressA pool token.
tokenBaddressA pool token.
liquidityuintThe amount of liquidity tokens to remove.
amountAMinuintThe minimum amount of tokenA that must be received for the transaction not to revert.
amountBMinuintThe minimum amount of tokenB that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuintUnix timestamp after which the transaction will revert.
amountAuintThe amount of tokenA received.
amountBuintThe amount of tokenB received.

removeLiquidityCTN

function removeLiquidityCTN(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountCTNMin,
  address to,
  uint deadline
) external returns (uint amountToken, uint amountCTN);

Removes liquidity from an ERC-20⇄WCTN pool and receive CTN.

NameType
tokenaddressA pool token.
liquidityuintThe amount of liquidity tokens to remove.
amountTokenMinuintThe minimum amount of token that must be received for the transaction not to revert.
amountCTNMinuintThe minimum amount of CTN that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuintUnix timestamp after which the transaction will revert.
amountTokenuintThe amount of token received.
amountCTNuintThe amount of CTN received.

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.

NameType
tokenAaddressA pool token.
tokenBaddressA pool token.
liquidityuintThe amount of liquidity tokens to remove.
amountAMinuintThe minimum amount of tokenA that must be received for the transaction not to revert.
amountBMinuintThe minimum amount of tokenB that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuintUnix timestamp after which the transaction will revert.
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint(-1).
vuint8The v component of the permit signature.
rbytes32The r component of the permit signature.
sbytes32The s component of the permit signature.
amountAuintThe amount of tokenA received.
amountBuintThe amount of tokenB received.

removeLiquidityCTNWithPermit

function removeLiquidityCTNWithPermit(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountCTNMin,
  address to,
  uint deadline,
  bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountCTN);

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

NameType
tokenaddressA pool token.
liquidityuintThe amount of liquidity tokens to remove.
amountTokenMinuintThe minimum amount of token that must be received for the transaction not to revert.
amountCTNMinuintThe minimum amount of CTN that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuintUnix timestamp after which the transaction will revert.
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint(-1).
vuint8The v component of the permit signature.
rbytes32The r component of the permit signature.
sbytes32The s component of the permit signature.
amountTokenuintThe amount of token received.
amountCTNuintThe amount of CTN received.

removeLiquidityCTNSupportingFeeOnTransferTokens

function removeLiquidityCTNSupportingFeeOnTransferTokens(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountCTNMin,
  address to,
  uint deadline
) external returns (uint amountCTN);

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

NameType
tokenaddressA pool token.
liquidityuintThe amount of liquidity tokens to remove.
amountTokenMinuintThe minimum amount of token that must be received for the transaction not to revert.
amountCTNMinuintThe minimum amount of CTN that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuintUnix timestamp after which the transaction will revert.
amountCTNuintThe amount of CTN received.

removeLiquidityCTNWithPermitSupportingFeeOnTransferTokens

function removeLiquidityCTNWithPermitSupportingFeeOnTransferTokens(
  address token,
  uint liquidity,
  uint amountTokenMin,
  uint amountCTNMin,
  address to,
  uint deadline,
  bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountCTN);

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

NameType
tokenaddressA pool token.
liquidityuintThe amount of liquidity tokens to remove.
amountTokenMinuintThe minimum amount of token that must be received for the transaction not to revert.
amountCTNMinuintThe minimum amount of CTN that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuintUnix timestamp after which the transaction will revert.
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint(-1).
vuint8The v component of the permit signature.
rbytes32The r component of the permit signature.
sbytes32The s component of the permit signature.
amountCTNuintThe amount of CTN received.

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).

NameType
amountInuintThe amount of input tokens to send.
amountOutMinuintThe minimum amount of output tokens that must be received for the transaction not to revert.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuintUnix timestamp after which the transaction will revert.
amountsuint[] memoryThe input token amount and all subsequent output token amounts.

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).

NameType
amountOutuintThe amount of output tokens to receive.
amountInMaxuintThe maximum amount of input tokens that can be required before the transaction reverts.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuintUnix timestamp after which the transaction will revert.
amountsuint[] memoryThe input token amount and all subsequent output token amounts.

swapExactCTNForTokens

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

Swaps an exact amount of CTN for as many output tokens as possible, along the route determined by the path. The first element of path must be WCTN, 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).

NameType
msg.value (amountIn)uintThe amount of CTN to send.
amountOutMinuintThe minimum amount of output tokens that must be received for the transaction not to revert.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuintUnix timestamp after which the transaction will revert.
amountsuint[] memoryThe input token amount and all subsequent output token amounts.

swapTokensForExactCTN

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

Receive an exact amount of CTN 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 WCTN, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

NameType
amountOutuintThe amount of CTN to receive.
amountInMaxuintThe maximum amount of input tokens that can be required before the transaction reverts.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of CTN.
deadlineuintUnix timestamp after which the transaction will revert.
amountsuint[] memoryThe input token amount and all subsequent output token amounts.

swapExactTokensForCTN

function swapExactTokensForCTN(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 CTN as possible, along the route determined by the path. The first element of path is the input token, the last must be WCTN, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).

NameType
amountInuintThe amount of input tokens to send.
amountOutMinuintThe minimum amount of output tokens that must be received for the transaction not to revert.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the CTN.
deadlineuintUnix timestamp after which the transaction will revert.
amountsuint[] memoryThe input token amount and all subsequent output token amounts.

swapCTNForExactTokens

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

Receive an exact amount of tokens for as little CTN as possible, along the route determined by the path. The first element of path must be WCTN, 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).

NameType
amountOutuintThe amount of tokens to receive.
msg.value (amountInMax)uintThe maximum amount of CTN that can be required before the transaction reverts.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuintUnix timestamp after which the transaction will revert.
amountsuint[] memoryThe input token amount and all subsequent output token amounts.

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.

NameType
amountInuintThe amount of input tokens to send.
amountOutMinuintThe minimum amount of output tokens that must be received for the transaction not to revert.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuintUnix timestamp after which the transaction will revert.

swapExactCTNForTokensSupportingFeeOnTransferTokens

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

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

NameType
msg.value (amountIn)uintThe amount of CTN to send.
amountOutMinuintThe minimum amount of output tokens that must be received for the transaction not to revert.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuintUnix timestamp after which the transaction will revert.

swapExactTokensForCTNSupportingFeeOnTransferTokens

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

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

NameType
amountInuintThe amount of input tokens to send.
amountOutMinuintThe minimum amount of output tokens that must be received for the transaction not to revert.
pathaddress[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the CTN.
deadlineuintUnix timestamp after which the transaction will revert.

Interface

import '@centurion-dex/v2-periphery/contracts/interfaces/ICenturionV2Router02.sol';
pragma solidity >=0.6.2;
 
interface ICenturionV2Router01 {
    function factory() external pure returns (address);
    function WCTN() external pure returns (address);
 
    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 addLiquidityCTN(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountCTNMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountCTN, 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 removeLiquidityCTN(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountCTNMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountCTN);
    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 removeLiquidityCTNWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountCTNMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountCTN);
    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 swapExactCTNForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactCTN(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForCTN(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapCTNForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
 
    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);
}
 
interface ICenturionV2Router02 is ICenturionV2Router01 {
    function removeLiquidityCTNSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountCTNMin,
        address to,
        uint deadline
    ) external returns (uint amountCTN);
    function removeLiquidityCTNWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountCTNMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountCTN);
 
    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactCTNForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForCTNSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

ABI

import ICenturionV2Router02 from '@centurion-dex/v2-periphery/build/ICenturionV2Router02.json'

https://unpkg.com/@centurion-dex/v2-periphery@1.1.0-beta.0/build/ICenturionV2Router02.json