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
Read-Only Functions
factory
Returns factory address.
WSEI
Returns the canonical WSEI address on the SEI V2 mainnet.
quote
See quote.
getAmountOut
See getAmountOut.
getAmountIn
See getAmountIn.
getAmountsOut
See getAmountsOut.
getAmountsIn
See getAmountsIn.
State-Changing Functions
addLiquidity
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.
Name | Type | |
---|---|---|
tokenA |
| A pool token. |
tokenB |
| A pool token. |
amountADesired |
| The amount of tokenA to add as liquidity if the B/A price is <= amountBDesired/amountADesired (A depreciates). |
amountBDesired |
| The amount of tokenB to add as liquidity if the A/B price is <= amountADesired/amountBDesired (B depreciates). |
amountAMin |
| Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired. |
amountBMin |
| Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired. |
to |
| Recipient of the liquidity tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
amountA |
| The amount of tokenA sent to the pool. |
amountB |
| The amount of tokenB sent to the pool. |
liquidity |
| The amount of liquidity tokens minted. |
addLiquiditySEI
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.
Name | Type | |
---|---|---|
token |
| A pool token. |
amountTokenDesired |
| The amount of token to add as liquidity if the WSEI/token price is <= |
|
| The amount of SEI to add as liquidity if the token/WSEI price is <= amountTokenDesired/ |
amountTokenMin |
| Bounds the extent to which the WSEI/token price can go up before the transaction reverts. Must be <= amountTokenDesired. |
amountSEIMin |
| Bounds the extent to which the token/WSEI price can go up before the transaction reverts. Must be <= |
to |
| Recipient of the liquidity tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
amountToken |
| The amount of token sent to the pool. |
amountSEI |
| The amount of SEI converted to WSEI and sent to the pool. |
liquidity |
| The amount of liquidity tokens minted. |
removeLiquidity
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.
Name | Type | |
---|---|---|
tokenA |
| A pool token. |
tokenB |
| A pool token. |
liquidity |
| The amount of liquidity tokens to remove. |
amountAMin |
| The minimum amount of tokenA that must be received for the transaction not to revert. |
amountBMin |
| The minimum amount of tokenB that must be received for the transaction not to revert. |
to |
| Recipient of the underlying assets. |
deadline |
| Unix timestamp after which the transaction will revert. |
amountA |
| The amount of tokenA received. |
amountB |
| The amount of tokenB received. |
removeLiquiditySEI
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.
Name | Type | |
---|---|---|
token |
| A pool token. |
liquidity |
| The amount of liquidity tokens to remove. |
amountTokenMin |
| The minimum amount of token that must be received for the transaction not to revert. |
amountSEIMin |
| The minimum amount of SEI that must be received for the transaction not to revert. |
to |
| Recipient of the underlying assets. |
deadline |
| Unix timestamp after which the transaction will revert. |
amountToken |
| The amount of token received. |
amountSEI |
| The amount of SEI received. |
removeLiquidityWithPermit
Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval, thanks to permit.
Name | Type | |
---|---|---|
tokenA |
| A pool token. |
tokenB |
| A pool token. |
liquidity |
| The amount of liquidity tokens to remove. |
amountAMin |
| The minimum amount of tokenA that must be received for the transaction not to revert. |
amountBMin |
| The minimum amount of tokenB that must be received for the transaction not to revert. |
to |
| Recipient of the underlying assets. |
deadline |
| Unix timestamp after which the transaction will revert. |
approveMax |
| Whether or not the approval amount in the signature is for liquidity or |
v |
| The v component of the permit signature. |
r |
| The r component of the permit signature. |
s |
| The s component of the permit signature. |
amountA |
| The amount of tokenA received. |
amountB |
| The amount of tokenB received. |
removeLiquiditySEIWithPermit
Removes liquidity from an ERC-20⇄WSEI pool and receive SEI without pre-approval, thanks to permit.
Name | Type | |
---|---|---|
token |
| A pool token. |
liquidity |
| The amount of liquidity tokens to remove. |
amountTokenMin |
| The minimum amount of token that must be received for the transaction not to revert. |
amountSEIMin |
| The minimum amount of SEI that must be received for the transaction not to revert. |
to |
| Recipient of the underlying assets. |
deadline |
| Unix timestamp after which the transaction will revert. |
approveMax |
| Whether or not the approval amount in the signature is for liquidity or |
v |
| The v component of the permit signature. |
r |
| The r component of the permit signature. |
s |
| The s component of the permit signature. |
amountToken |
| The amount of token received. |
amountSEI |
| The amount of SEI received. |
removeLiquiditySEISupportingFeeOnTransferTokens
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.
Name | Type | |
---|---|---|
token |
| A pool token. |
liquidity |
| The amount of liquidity tokens to remove. |
amountTokenMin |
| The minimum amount of token that must be received for the transaction not to revert. |
amountSEIMin |
| The minimum amount of SEI that must be received for the transaction not to revert. |
to |
| Recipient of the underlying assets. |
deadline |
| Unix timestamp after which the transaction will revert. |
amountSEI |
| The amount of SEI received. |
removeLiquiditySEIWithPermitSupportingFeeOnTransferTokens
Identical to removeLiquiditySEIWithPermit, but succeeds for tokens that take a fee on transfer.
Name | Type | |
---|---|---|
token |
| A pool token. |
liquidity |
| The amount of liquidity tokens to remove. |
amountTokenMin |
| The minimum amount of token that must be received for the transaction not to revert. |
amountSEIMin |
| The minimum amount of SEI that must be received for the transaction not to revert. |
to |
| Recipient of the underlying assets. |
deadline |
| Unix timestamp after which the transaction will revert. |
approveMax |
| Whether or not the approval amount in the signature is for liquidity or |
v |
| The v component of the permit signature. |
r |
| The r component of the permit signature. |
s |
| The s component of the permit signature. |
amountSEI |
| The amount of SEI 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 |
| The amount of input tokens to send. |
amountOutMin |
| The minimum amount of output tokens that must be received for the transaction not to revert. |
path |
| An array of token addresses. |
to |
| Recipient of the output tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
amounts |
| 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 |
| The amount of output tokens to receive. |
amountInMax |
| The maximum amount of input tokens that can be required before the transaction reverts. |
path |
| An array of token addresses. |
to |
| Recipient of the output tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
amounts |
| The input token amount and all subsequent output token amounts. |
swapExactSEIForTokens
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).
Name | Type | |
---|---|---|
|
| The amount of SEI to send. |
amountOutMin |
| The minimum amount of output tokens that must be received for the transaction not to revert. |
path |
| An array of token addresses. |
to |
| Recipient of the output tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
amounts |
| The input token amount and all subsequent output token amounts. |
swapTokensForExactSEI
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.
Name | Type | |
---|---|---|
amountOut |
| The amount of SEI to receive. |
amountInMax |
| The maximum amount of input tokens that can be required before the transaction reverts. |
path |
| An array of token addresses. |
to |
| Recipient of SEI. |
deadline |
| Unix timestamp after which the transaction will revert. |
amounts |
| The input token amount and all subsequent output token amounts. |
swapExactTokensForSEI
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.
Name | Type | |
---|---|---|
amountIn |
| The amount of input tokens to send. |
amountOutMin |
| The minimum amount of output tokens that must be received for the transaction not to revert. |
path |
| An array of token addresses. |
to |
| Recipient of the SEI. |
deadline |
| Unix timestamp after which the transaction will revert. |
amounts |
| The input token amount and all subsequent output token amounts. |
swapSEIForExactTokens
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
.
Name | Type | |
---|---|---|
amountOut |
| The amount of tokens to receive. |
|
| The maximum amount of SEI that can be required before the transaction reverts. |
path |
| An array of token addresses. |
to |
| Recipient of the output tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
amounts |
| The input token amount and all subsequent output token amounts. |
swapExactTokensForTokensSupportingFeeOnTransferTokens
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.
Name | Type | |
---|---|---|
amountIn |
| The amount of input tokens to send. |
amountOutMin |
| The minimum amount of output tokens that must be received for the transaction not to revert. |
path |
| An array of token addresses. |
to |
| Recipient of the output tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
swapExactSEIForTokensSupportingFeeOnTransferTokens
Identical to swapExactSEIForTokens, but succeeds for tokens that take a fee on transfer.
Name | Type | |
---|---|---|
|
| The amount of SEI to send. |
amountOutMin |
| The minimum amount of output tokens that must be received for the transaction not to revert. |
path |
| An array of token addresses. |
to |
| Recipient of the output tokens. |
deadline |
| Unix timestamp after which the transaction will revert. |
swapExactTokensForSEISupportingFeeOnTransferTokens
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.
Name | Type | |
---|---|---|
amountIn |
| The amount of input tokens to send. |
amountOutMin |
| The minimum amount of output tokens that must be received for the transaction not to revert. |
path |
| An array of token addresses. |
to |
| Recipient of the SEI. |
deadline |
| Unix timestamp after which the transaction will revert. |
Interface
ABI
Last updated