Router01
Last modified:
CenturionV2Router01 should not be used any longer, because of the discovery of a low severity bug and the fact that some methods do not work with tokens that take fees on transfer. The current recommendation is to use CenturionV2Router02.
Code
Address
CenturionV2Router01 is deployed at 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a on the Ethereum mainnet, and the Ropsten, Rinkeby, Görli, and Kovan testnets. It was built from commit 2ad7da2.
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.
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.sendershould 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.
| Name | Type | |
|---|---|---|
| tokenA | address | A pool token. |
| tokenB | address | A pool token. |
| amountADesired | uint | The amount of tokenA to add as liquidity if the B/A price is = amountBDesired/amountADesired (A depreciates). |
| amountBDesired | uint | The amount of tokenB to add as liquidity if the A/B price is = amountADesired/amountBDesired (B depreciates). |
| amountAMin | uint | Bounds the extent to which the B/A price can go up before the transaction reverts. Must be = amountADesired. |
| amountBMin | uint | Bounds the extent to which the A/B price can go up before the transaction reverts. Must be = amountBDesired. |
| to | address | Recipient of the liquidity tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amountA | uint | The amount of tokenA sent to the pool. |
| amountB | uint | The amount of tokenB sent to the pool. |
| liquidity | uint | The 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.
- To cover all possible scenarios,
msg.sendershould 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.valueis treated as a amountCTNDesired.- Leftover CTN, if any, is returned to
msg.sender. - If a pool for the passed token and WCTN does not exists, one is created automatically, and exactly amountTokenDesired/
msg.valuetokens are added.
| Name | Type | |
|---|---|---|
| token | address | A pool token. |
| amountTokenDesired | uint | The amount of token to add as liquidity if the WCTN/token price is = msg.value/amountTokenDesired (token depreciates). |
msg.value (amountCTNDesired) | uint | The amount of CTN to add as liquidity if the token/WCTN price is = amountTokenDesired/msg.value (WCTN depreciates). |
| amountTokenMin | uint | Bounds the extent to which the WCTN/token price can go up before the transaction reverts. Must be = amountTokenDesired. |
| amountCTNMin | uint | Bounds the extent to which the token/WCTN price can go up before the transaction reverts. Must be = msg.value. |
| to | address | Recipient of the liquidity tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amountToken | uint | The amount of token sent to the pool. |
| amountCTN | uint | The amount of CTN converted to WCTN and sent to the pool. |
| liquidity | uint | The 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.
msg.sendershould have already given the router an allowance of at least liquidity on the pool.
| Name | Type | |
|---|---|---|
| tokenA | address | A pool token. |
| tokenB | address | A pool token. |
| liquidity | uint | The amount of liquidity tokens to remove. |
| amountAMin | uint | The minimum amount of tokenA that must be received for the transaction not to revert. |
| amountBMin | uint | The minimum amount of tokenB that must be received for the transaction not to revert. |
| to | address | Recipient of the underlying assets. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amountA | uint | The amount of tokenA received. |
| amountB | uint | The 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.
msg.sendershould have already given the router an allowance of at least liquidity on the pool.
| Name | Type | |
|---|---|---|
| token | address | A pool token. |
| liquidity | uint | The amount of liquidity tokens to remove. |
| amountTokenMin | uint | The minimum amount of token that must be received for the transaction not to revert. |
| amountCTNMin | uint | The minimum amount of CTN that must be received for the transaction not to revert. |
| to | address | Recipient of the underlying assets. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amountToken | uint | The amount of token received. |
| amountCTN | uint | The 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.
| Name | Type | |
|---|---|---|
| tokenA | address | A pool token. |
| tokenB | address | A pool token. |
| liquidity | uint | The amount of liquidity tokens to remove. |
| amountAMin | uint | The minimum amount of tokenA that must be received for the transaction not to revert. |
| amountBMin | uint | The minimum amount of tokenB that must be received for the transaction not to revert. |
| to | address | Recipient of the underlying assets. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| approveMax | bool | Whether or not the approval amount in the signature is for liquidity or uint(-1). |
| v | uint8 | The v component of the permit signature. |
| r | bytes32 | The r component of the permit signature. |
| s | bytes32 | The s component of the permit signature. |
| amountA | uint | The amount of tokenA received. |
| amountB | uint | The 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.
| Name | Type | |
|---|---|---|
| token | address | A pool token. |
| liquidity | uint | The amount of liquidity tokens to remove. |
| amountTokenMin | uint | The minimum amount of token that must be received for the transaction not to revert. |
| amountCTNMin | uint | The minimum amount of CTN that must be received for the transaction not to revert. |
| to | address | Recipient of the underlying assets. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| approveMax | bool | Whether or not the approval amount in the signature is for liquidity or uint(-1). |
| v | uint8 | The v component of the permit signature. |
| r | bytes32 | The r component of the permit signature. |
| s | bytes32 | The s component of the permit signature. |
| amountToken | uint | The amount of token received. |
| amountCTN | uint | The 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).
msg.sendershould have already given the router an allowance of at least amountIn on the input token.
| Name | Type | |
|---|---|---|
| amountIn | uint | The amount of input tokens to send. |
| amountOutMin | uint | The minimum amount of output tokens that must be received for the transaction not to revert. |
| path | address[] calldata | An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity. |
| to | address | Recipient of the output tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amounts | uint[] memory | The 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 pairs to trade through (if, for example, a direct pair does not exist).
msg.sendershould have already given the router an allowance of at least amountInMax on the input token.
| Name | Type | |
|---|---|---|
| amountOut | uint | The amount of output tokens to receive. |
| amountInMax | uint | The maximum amount of input tokens that can be required before the transaction reverts. |
| path | address[] calldata | An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity. |
| to | address | Recipient of the output tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amounts | uint[] memory | The 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).
| Name | Type | |
|---|---|---|
msg.value (amountIn) | uint | The amount of CTN to send. |
| amountOutMin | uint | The minimum amount of output tokens that must be received for the transaction not to revert. |
| path | address[] calldata | An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity. |
| to | address | Recipient of the output tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amounts | uint[] memory | The 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).
msg.sendershould 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 CTN.
| Name | Type | |
|---|---|---|
| amountOut | uint | The amount of CTN to receive. |
| amountInMax | uint | The maximum amount of input tokens that can be required before the transaction reverts. |
| path | address[] calldata | An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity. |
| to | address | Recipient of CTN. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amounts | uint[] memory | The 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).
- If the to address is a smart contract, it must have the ability to receive CTN.
| Name | Type | |
|---|---|---|
| amountIn | uint | The amount of input tokens to send. |
| amountOutMin | uint | The minimum amount of output tokens that must be received for the transaction not to revert. |
| path | address[] calldata | An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity. |
| to | address | Recipient of the CTN. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amounts | uint[] memory | The 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).
- Leftover CTN, if any, is returned to
msg.sender.
| Name | Type | |
|---|---|---|
| amountOut | uint | The amount of tokens to receive. |
msg.value (amountInMax) | uint | The maximum amount of CTN that can be required before the transaction reverts. |
| path | address[] calldata | An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity. |
| to | address | Recipient of the output tokens. |
| deadline | uint | Unix timestamp after which the transaction will revert. |
| amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
quote
See quote.
getAmountOut
See getAmountOut.
getAmountIn
This function contains a low severity bug, do not use.
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);SeegetAmountsIn.
Interface
import '@centurion-dex/v2-periphery/contracts/interfaces/ICenturionV2Router01.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);
}ABI
import ICenturionV2Router01 from '@centurion-dex/v2-periphery/build/ICenturionV2Router01.json'https://unpkg.com/@centurion-dex/v2-periphery@1.0.0-beta.0/build/ICenturionV2Router01.json