Pair (CRC-20)
Pair (CRC-20) This documentation covers CRC-20 functionality for denominating pool tokens. For Capricorn-specific functionality, see Pair.
Code
Events
Approval
Emitted each time an approval occurs via approve or permit.
Transfer
Emitted each time a transfer occurs via transfer, transferFrom, mint, or burn.
Read-Only Functions
name
Returns caprion for all pairs.
symbol
Returns cap for all pairs.
decimals
Returns 18
for all pairs.
totalSupply
Returns the total amount of pool tokens for a pair.
balanceOf
Returns the amount of pool tokens owned by an address.
allowance
Returns the amount of liquidity tokens owned by an address that a spender is allowed to transfer via transferFrom.
DOMAIN_SEPARATOR
Returns a domain separator for use in permit.
PERMIT_TYPEHASH
Returns a typehash for use in permit.
State-Changing Functions
approve
Lets msg.sender
set their allowance for a spender.
Emits Approval.
transfer
Lets msg.sender send pool tokens to an address.
Emits Transfer.
transferFrom
Sends pool tokens from one address to another.
Requires approval.
Emits Transfer.
permit
Sets the allowance for a spender where approval is granted via a signature.
See Using Permit.
Emits Approval.
Library
Code
Internal Functions
sortTokens
Sorts token addresses.
pairFor
Calculates the address for a pair without making any external calls via the SDK.
getReserves
Calls getReserves on the pair for the passed tokens, and returns the results sorted in the order that the parameters were passed in.
quote
Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.
Useful for calculating optimal token amounts before calling mint.
getAmountOut
Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.
getAmountIn
Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.
getAmountsOut
Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountOut.
Useful for calculating optimal token amounts before calling swap.
getAmountsIn
Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountIn.
Router
Router02 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 Source Code
Address CapswapV2Router02 is deployed at 0x34c385dd9015d663830a37CD2E75818fda6C605f on the Cube mainnet.
Read-Only Functions
facotry
WCUBE
Returns the canonical WCUBE address on the CUBE mainnet.
quote See quote.
getAmountOut See getAmountOut.
getAmountIn See getAmountIn.
getAmountsOut
getAmountsIn
State-Changing Functions
addLiquidity
Adds liquidity to an CRC-20⇄CRC-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.
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. |
addLiquidityETH
Adds liquidity to an CRC-20⇄WCUBE pool with CUBE.
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 amountETHDesired.
Leftover CUBE, if any, is returned to msg.sender.
If a pool for the passed token and WCUBE does not exists, one is created automatically, and exactly amountTokenDesired/msg.value tokens are added.
Name | Type | |
---|---|---|
token | address | A pool token. |
amountTokenDesired | uint | The amount of token to add as liquidity if the WCUBE/token price is <= msg.value/amountTokenDesired (token depreciates). |
msg.value (amountETHDesired) | uint | The amount of CUBE to add as liquidity if the token/WCUBE price is <= amountTokenDesired/msg.value (WCUBE depreciates). |
amountTokenMin | uint | Bounds the extent to which the WCUBE/token price can go up before the transaction reverts. Must be <= amountTokenDesired. |
amountETHMin | uint | Bounds the extent to which the token/WCUBE 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. |
amountETH | uint | The amount of CUBE converted to WCUBE and sent to the pool. |
liquidity | uint | The amount of liquidity tokens minted. |
removeLiquidity
Removes liquidity from an CRC-20⇄CRC-20 pool.
msg.sender should 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. |
removeLiquidityETH
Removes liquidity from an CRC-20⇄WCUBE pool and receive CUBE.
msg.sender should 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. |
amountETHMin | uint | The minimum amount of CUBE 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. |
amountETH | uint | The amount of CUBE received. |
removeLiquidityWithPermit
Removes liquidity from an CRC-20⇄CRC-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. |
removeLiquidityETHWithPermit
Removes liquidity from an CRC-20⇄WCUBE pool and receive CUBE 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. |
amountETHMin | uint | The minimum amount of CUBE 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. |
amountETH | uint | The amount of CUBE received. |
removeLiquidityETHSupportingFeeOnTransferTokens
Identical to removeLiquidityETH, 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.
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. |
amountETHMin | uint | The minimum amount of CUBE 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. |
amountETH | uint | The amount of CUBE received. |
removeLiquidityETHWithPermitSupportingFeeOnTransferTokens
Identical to removeLiquidityETHWithPermit, but succeeds for tokens that take a fee on transfer.
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. |
amountETHMin | uint | The minimum amount of CUBE 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. |
amountETH | uint | The amount of CUBE received. |
swapExactTokensForTokens
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.
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
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.
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. |
swapExactETHForTokens
Swaps an exact amount of CUBE for as many output tokens as possible, along the route determined by the path. The first element of path must be WCUBE, 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 CUBE 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. |
swapTokensForExactETH
Receive an exact amount of CUBE 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 WCUBE, 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 CUBE.
Name | Type | |
---|---|---|
amountOut | uint | The amount of CUBE 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 CUBE. |
deadline | uint | Unix timestamp after which the transaction will revert. |
amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
swapExactTokensForETH
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 CUBE. |
deadline | uint | Unix timestamp after which the transaction will revert. |
amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
swapETHForExactTokens
Name | Type | |
---|---|---|
amountOut | uint | The amount of tokens to receive. |
msg.value (amountInMax) | uint | The maximum amount of CUBE 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. |
swapExactTokensForTokensSupportingFeeOnTransferTokens
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. |
swapExactETHForTokensSupportingFeeOnTransferTokens
Name | Type | |
---|---|---|
amountOut | uint | The amount of tokens to receive. |
msg.value (amountInMax) | uint | The maximum amount of CUBE 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. |
swapExactTokensForTokensSupportingFeeOnTransferTokens
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. |
swapExactETHForTokensSupportingFeeOnTransferTokens
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 CUBE. |
deadline | uint | Unix timestamp after which the transaction will revert. |
Last updated