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
.
UniswapV2Router02
is deployed at 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
on the Ethereum mainnet, and the Ropsten, Rinkeby, Görli, and Kovan testnets. It was built from commit 6961711.
function factory() external pure returns (address);
Returns factory address.
function WVET() external pure returns (address);
Returns the canonical WVET address on the Ethereum mainnet, or the Ropsten, Rinkeby, Görli, or Kovan testnets.
See quote.
See getAmountOut.
See getAmountIn.
function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts);
See getAmountsOut.
function getAmountsIn(uint amountOut, address[] memory path) public view returns (uint[] memory amounts);
See getAmountsIn.
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 VIP-180⇄VIP-180 pool.
msg.sender
should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.Name | Type | |
---|---|---|
tokenA | address | The contract address of the desired token. |
tokenB | address | The contract address of the desired 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. |
function addLiquidityETH(address token,uint amountTokenDesired,uint amountTokenMin,uint amountETHMin,address to,uint deadline) external payable returns (uint amountToken, uint amountETH, uint liquidity);
Adds liquidity to an VIP-180⇄WVET pool with VET.
msg.sender
should have already given the router an allowance of at least amountTokenDesired on token.msg.value
is treated as a amountETHDesired.msg.sender
.msg.value
tokens are added.Name | Type | |
---|---|---|
token | address | The contract address of the desired token. |
amountTokenDesired | uint | The amount of token to add as liquidity if the WVET/token price is <= msg.value /amountTokenDesired (token depreciates). |
msg.value (amountETHDesired) | uint | The amount of VET to add as liquidity if the token/WVET price is <= amountTokenDesired/msg.value (WVET depreciates). |
amountTokenMin | uint | Bounds the extent to which the WVET/token price can go up before the transaction reverts. Must be <= amountTokenDesired. |
amountETHMin | uint | Bounds the extent to which the token/WVET 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 VET converted to WVET and sent to the pool. |
liquidity | uint | The amount of liquidity tokens minted. |
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 VIP-180⇄VIP-180 pool.
msg.sender
should have already given the router an allowance of at least liquidity on the pool.Name | Type | |
---|---|---|
tokenA | address | The contract address of the desired token. |
tokenB | address | The contract address of the desired 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. |
function removeLiquidityETH(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline) external returns (uint amountToken, uint amountETH);
Removes liquidity from an VIP-180⇄WVET pool and receive VET.
msg.sender
should have already given the router an allowance of at least liquidity on the pool.Name | Type | |
---|---|---|
token | address | The contract address of the desired 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 VET 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 VET received. |
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 VIP-180⇄VIP-180 pool without pre-approval, thanks to permit.
Name | Type | |
---|---|---|
tokenA | address | The contract address of the desired token. |
tokenB | address | The contract address of the desired 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. |
function removeLiquidityETHWithPermit(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline,bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint amountToken, uint amountETH);
Removes liquidity from an VIP-180⇄WVET pool and receive VET without pre-approval, thanks to permit.
Name | Type | |
---|---|---|
token | address | The contract address of the desired 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 VET 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 VET received. |
function removeLiquidityETHSupportingFeeOnTransferTokens(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline) external returns (uint amountETH);
Identical to removeLiquidityVET, 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 | The contract address of the desired 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 VET 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 VET received. |
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline,bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint amountETH);
Identical to removeLiquidityVETWithPermit, but succeeds for tokens that take a fee on transfer.
Name | Type | |
---|---|---|
token | address | The contract address of the desired 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 VET 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 VET received. |
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.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. |
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).
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. |
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)externalpayablereturns (uint[] memory amounts);
Swaps an exact amount of VET for as many output tokens as possible, along the route determined by the path. The first element of path must be WVET, 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 VET 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. |
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)externalreturns (uint[] memory amounts);
Receive an exact amount of VET 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 WVET, 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.Name | Type | |
---|---|---|
amountOut | uint | The amount of VET 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 VET. |
deadline | uint | Unix timestamp after which the transaction will revert. |
amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)externalreturns (uint[] memory amounts);
Swaps an exact amount of tokens for as much VET as possible, along the route determined by the path. The first element of path is the input token, the last must be WVET, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
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 VET. |
deadline | uint | Unix timestamp after which the transaction will revert. |
amounts | uint[] memory | The input token amount and all subsequent output token amounts. |
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)externalpayablereturns (uint[] memory amounts);
Receive an exact amount of tokens for as little VET as possible, along the route determined by the path. The first element of path must be WVET, 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
.Name | Type | |
---|---|---|
amountOut | uint | The amount of tokens to receive. |
msg.value (amountInMax) | uint | The maximum amount of VET 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. |
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.
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. |
function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin,address[] calldata path,address to,uint deadline) external payable;
Identical to swapExactETHForTokens, but succeeds for tokens that take a fee on transfer.
Name | Type | |
---|---|---|
msg.value (amountIn) | uint | The amount of VET 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. |
function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external;
Identical to swapExactTokensForETH, but succeeds for tokens that take a fee on transfer.
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 VET. |
deadline | uint | Unix timestamp after which the transaction will revert. |
import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';
pragma solidity >=0.6.2;interface IUniswapV2Router01 {function factory() external pure returns (address);function WVET() 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 addLiquidityETH(address token,uint amountTokenDesired,uint amountTokenMin,uint amountETHMin,address to,uint deadline) external payable returns (uint amountToken, uint amountETH, 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 removeLiquidityETH(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline) external returns (uint amountToken, uint amountETH);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 removeLiquidityETHWithPermit(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline,bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint amountToken, uint amountETH);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 swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)externalpayablereturns (uint[] memory amounts);function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)externalreturns (uint[] memory amounts);function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)externalreturns (uint[] memory amounts);function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)externalpayablereturns (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 IUniswapV2Router02 is IUniswapV2Router01 {function removeLiquidityETHSupportingFeeOnTransferTokens(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline) external returns (uint amountETH);function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(address token,uint liquidity,uint amountTokenMin,uint amountETHMin,address to,uint deadline,bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint amountETH);function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external;function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin,address[] calldata path,address to,uint deadline) external payable;function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn,uint amountOutMin,address[] calldata path,address to,uint deadline) external;}
import IUniswapV2Router02 from '@uniswap/v2-periphery/build/IUniswapV2Router02.json'
https://unpkg.com/@uniswap/v2-periphery@1.1.0-beta.0/build/IUniswapV2Router02.json