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#
Address0x017dAd2578372CAEE5c6CddfE35eEDB3728544C4
#
Read-Only Functions#
factoryReturns factory address.
#
WSYSReturns the 0xd3e822f3ef011Ca5f17D82C956D952D8d7C3A1BB.
#
quoteSee quote.
#
getAmountOutSee getAmountOut.
#
getAmountInSee getAmountIn.
#
getAmountsOutSee getAmountsOut.
#
getAmountsInSee getAmountsIn.
#
State-Changing Functions#
addLiquidityAdds 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.
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. |
#
addLiquiditySYSAdds liquidity to an ERC-20⇄WSYS pool with SYS.
- 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 amountSYSDesired.- Leftover SYS, if any, is returned to
msg.sender
. - If a pool for the passed token and WSYS 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 WSYS/token price is <= msg.value /amountTokenDesired (token depreciates). |
msg.value (amountSYSDesired) | uint | The amount of SYS to add as liquidity if the token/WSYS price is <= amountTokenDesired/msg.value (WSYS depreciates). |
amountTokenMin | uint | Bounds the extent to which the WSYS/token price can go up before the transaction reverts. Must be <= amountTokenDesired. |
amountSYSMin | uint | Bounds the extent to which the token/WSYS 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. |
amountSYS | uint | The amount of SYS converted to WSYS and sent to the pool. |
liquidity | uint | The amount of liquidity tokens minted. |
#
removeLiquidityRemoves 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.
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. |
#
removeLiquiditySYSRemoves liquidity from an ERC-20⇄WSYS pool and receive SYS.
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. |
amountSYSMin | uint | The minimum amount of SYS 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. |
amountSYS | uint | The amount of SYS received. |
#
removeLiquidityWithPermitRemoves 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. |
#
removeLiquiditySYSWithPermitRemoves liquidity from an ERC-20⇄WETTH pool and receive SYS 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. |
amountSYSMin | uint | The minimum amount of SYS 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. |
amountSYS | uint | The amount of SYS received. |
#
removeLiquiditySYSSupportingFeeOnTransferTokensIdentical to removeLiquiditySYS, 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. |
amountSYSMin | uint | The minimum amount of SYS 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. |
amountSYS | uint | The amount of SYS received. |
#
removeLiquiditySYSWithPermitSupportingFeeOnTransferTokensIdentical to removeLiquiditySYSWithPermit, 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. |
amountSYSMin | uint | The minimum amount of SYS 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. |
amountSYS | uint | The amount of SYS received. |
#
swapExactTokensForTokensSwaps 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. |
#
swapTokensForExactTokensReceive 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. |
#
swapExactSYSForTokensSwaps an exact amount of SYS for as many output tokens as possible, along the route determined by the path. The first element of path must be WSYS, 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 SYS 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. |
#
swapTokensForExactSYSReceive an exact amount of SYS 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 WSYS, 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 SYS.
Name | Type | |
---|---|---|
amountOut | uint | The amount of SYS 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 SYS. |
deadline | uint | Unix timestamp after which the transaction will revert. |
amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
#
swapExactTokensForSYSSwaps an exact amount of tokens for as much SYS as possible, along the route determined by the path. The first element of path is the input token, the last must be WSYS, 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 SYS.
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 SYS. |
deadline | uint | Unix timestamp after which the transaction will revert. |
amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
#
swapSYSForExactTokensReceive an exact amount of tokens for as little SYS as possible, along the route determined by the path. The first element of path must be WSYS, 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 SYS, 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 SYS 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. |
#
swapExactTokensForTokensSupportingFeeOnTransferTokensIdentical 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.
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. |
#
swapExactSYSForTokensSupportingFeeOnTransferTokensIdentical to swapExactSYSForTokens, but succeeds for tokens that take a fee on transfer.
Name | Type | |
---|---|---|
msg.value (amountIn) | uint | The amount of SYS 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. |
#
swapExactTokensForSYSSupportingFeeOnTransferTokensIdentical to swapExactTokensForSYS, 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 SYS.
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 SYS. |
deadline | uint | Unix timestamp after which the transaction will revert. |