Skip to main content
Version: V1

DMMRouter02

Code#

DMMRouter02.sol

Address#

DMMRouter02 is deployed at 0x1c87257f5e8609940bc751a07bb085bb7f8cdbe6 on the Ethereum mainnet. It was built from commit 04b47545c58fa0ab99d4bb9eae729b3be31efb0c.

Read-Only Functions#

factory#

function factory() external pure returns (address);

Returns the factory address.

weth#

function weth() external pure returns (address);

Returns the canonical WETH address on the Ethereum mainnet, or the Ropsten, Rinkeby, Görli, or Kovan testnets.

quote#

function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);

Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.

getAmountsOut#

function getAmountsOut(uint256 amountIn, address[] memory poolsPath, IERC20[] memory path) external view returns (uint256[] memory amounts);

First calls verifyPoolsPathSwap to verify the validity of the poolsPath and path variables.

Then, given an input asset amount and an array of token and corresponding pool addresses, calculates all subsequent maximum output token amounts by calling getTradeInfo for each pair of token addresses in the path in turn, and using these to call getAmountOut.

getAmountsIn#

function getAmountsIn(uint256 amountOut, address[] memory poolsPath, IERC20[] memory path) external view returns (uint256[] memory amounts);

First calls verifyPoolsPathSwap to verify the validity of the poolsPath and path variables.

Then, given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getTradeInfo for each pair of token addresses in the path in turn, and using these to call getAmountIn.

State-Changing Functions#

addLiquidityNewPool#

function addLiquidityNewPool(
IERC20 tokenA,
IERC20 tokenB,
uint32 ampBps,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);

Creates a new ERC-20⇄ERC-20 pool.

  • msg.sender should have already given the router an allowance of at least amountADesired/amountBDesired on tokenA/tokenB.
  • There can only be 1 unamplified pool (ampBps = 1). If one already exists, the function will instead add liquidity to the existing pool.
  • Exactly amountADesired and amountBDesired tokens are added.
NameType
tokenAIERC20The contract address of the desired token.
tokenBIERC20The contract address of the desired token.
ampBpsuint32The amplification factor in basis points. Learn more in this section
amountADesireduint256The amount of tokenA to add as liquidity if the B/A price is <= amountBDesired/amountADesired (A depreciates).
amountBDesireduint256The amount of tokenB to add as liquidity if the A/B price is <= amountADesired/amountBDesired (B depreciates).
amountAMinuint256Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired.
amountBMinuint256Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired.
toaddressRecipient of the liquidity tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountAuint256The amount of tokenA sent to the pool.
amountBuint256The amount of tokenB sent to the pool.
liquidityuint256The amount of liquidity tokens minted.

addLiquidity#

function addLiquidity(
IERC20 tokenA,
IERC20 tokenB,
address pool,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
uint256[2] memory vReserveRatioBounds,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);

Adds liquidity to an existing ERC-20⇄ERC-20 pool.

  • pool should already be an existing pool of the token pair of tokenA and tokenB. Otherwise, the transaction will revert.
  • 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.
NameType
tokenAIERC20The contract address of the desired token.
tokenBIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to add liquidity to.
amountADesireduint256The amount of tokenA to add as liquidity if the B/A price is <= amountBDesired/amountADesired (A depreciates).
amountBDesireduint256The amount of tokenB to add as liquidity if the A/B price is <= amountADesired/amountBDesired (B depreciates).
amountAMinuint256Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired.
amountBMinuint256Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired.
vReserveRatioBoundsuint256[2]Bounds the extent to which the virtual B/A price can move before the transaction reverts.
toaddressRecipient of the liquidity tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountAuint256The amount of tokenA sent to the pool.
amountBuint256The amount of tokenB sent to the pool.
liquidityuint256The amount of liquidity tokens minted.

addLiquidityNewPoolETH#

function addLiquidityNewPoolETH(
IERC20 token,
uint32 ampBps,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);

Creates a new ERC-20⇄WETH pool with ETH.

  • To cover all possible scenarios, msg.sender should have already given the router an allowance of at least amountTokenDesired on token.
  • There can only be 1 unamplified pool (ampBps = 1). If one already exists, the function will instead add liquidity to the existing pool.
  • msg.value is treated as a amountETHDesired.
  • Exactly msg.value and amountTokenDesired tokens are added.
NameType
tokenIERC20The contract address of the desired token.
ampBpsuint32The amplification factor in basis points. Learn more in this section
amountTokenDesireduint256The amount of token to add as liquidity if the WETH/token price is <= msg.value/amountTokenDesired (token depreciates).
msg.value (amountETHDesired)uint256The amount of ETH to add as liquidity if the token/WETH price is <= amountTokenDesired/msg.value (WETH depreciates).
amountTokenMinuint256Bounds the extent to which the WETH/token price can go up before the transaction reverts. Must be <= amountTokenDesired.
amountETHMinuint256Bounds the extent to which the token/WETH price can go up before the transaction reverts. Must be <= msg.value.
toaddressRecipient of the liquidity tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountTokenuint256The amount of token sent to the pool.
amountETHuint256The amount of ETH converted to WETH and sent to the pool.
liquidityuint256The amount of liquidity tokens minted.

addLiquidityETH#

function addLiquidityETH(
IERC20 token,
address pool,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
uint256[2] memory vReserveRatioBounds,
address to,
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);

Adds liquidity to an existing ERC-20⇄WETH pool with ETH.

  • pool should already be an existing pool of the token pair of tokenA and tokenB. Otherwise, the transaction will revert.
  • 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 amountETHDesired.
  • Leftover ETH, if any, is returned to msg.sender.
NameType
tokenIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to add liquidity to.
amountTokenDesireduint256The amount of token to add as liquidity if the WETH/token price is <= msg.value/amountTokenDesired (token depreciates).
msg.value (amountETHDesired)uint256The amount of ETH to add as liquidity if the token/WETH price is <= amountTokenDesired/msg.value (WETH depreciates).
amountTokenMinuint256Bounds the extent to which the WETH/token price can go up before the transaction reverts. Must be <= amountTokenDesired.
amountETHMinuint256Bounds the extent to which the token/WETH price can go up before the transaction reverts. Must be <= msg.value.
vReserveRatioBoundsuint256[2]Bounds the extent to which the virtual B/A price can move before the transaction reverts.
toaddressRecipient of the liquidity tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountTokenuint256The amount of token sent to the pool.
amountETHuint256The amount of ETH converted to WETH and sent to the pool.
liquidityuint256The amount of liquidity tokens minted.

removeLiquidity#

function removeLiquidity(
IERC20 tokenA,
IERC20 tokenB,
address pool,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);

Removes liquidity from a specified ERC-20⇄ERC-20 pool.

  • msg.sender should have already given the router an allowance of at least liquidity on the pool.
NameType
tokenAIERC20The contract address of the desired token.
tokenBIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to remove liquidity from.
liquidityuint256The amount of liquidity tokens to remove.
amountAMinuint256The minimum amount of tokenA that must be received for the transaction not to revert.
amountBMinuint256The minimum amount of tokenB that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuint256Unix timestamp after which the transaction will revert.
amountAuint256The amount of tokenA received.
amountBuint256The amount of tokenB received.

removeLiquidityETH#

function removeLiquidityETH(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);

Removes liquidity from an ERC-20⇄WETH pool and receive ETH.

  • msg.sender should have already given the router an allowance of at least liquidity on the pool.
NameType
tokenIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to remove liquidity from.
liquidityuint256The amount of liquidity tokens to remove.
amountTokenMinuint256The minimum amount of token that must be received for the transaction not to revert.
amountETHMinuint256The minimum amount of ETH that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuint256Unix timestamp after which the transaction will revert.
amountTokenuint256The amount of token received.
amountETHuint256The amount of ETH received.

removeLiquidityWithPermit#

function removeLiquidityWithPermit(
IERC20 tokenA,
IERC20 tokenB,
address pool,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint256 amountA, uint256 amountB);

Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval, thanks to permit.

NameType
tokenAIERC20The contract address of the desired token.
tokenBIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to remove liquidity from.
liquidityuint256The amount of liquidity tokens to remove.
amountAMinuint256The minimum amount of tokenA that must be received for the transaction not to revert.
amountBMinuint256The minimum amount of tokenB that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuint256Unix timestamp after which the transaction will revert.
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint256(-1).
vuint8The v component of the permit signature.
rbytes32The r component of the permit signature.
sbytes32The s component of the permit signature.
amountAuint256The amount of tokenA received.
amountBuint256The amount of tokenB received.

removeLiquidityETHWithPermit#

function removeLiquidityETHWithPermit(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);

Removes liquidity from an ERC-20⇄WETTH pool and receive ETH without pre-approval, thanks to permit.

NameType
tokenIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to remove liquidity from.
liquidityuint256The amount of liquidity tokens to remove.
amountTokenMinuint256The minimum amount of token that must be received for the transaction not to revert.
amountETHMinuint256The minimum amount of ETH that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuint256Unix timestamp after which the transaction will revert.
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint256(-1).
vuint8The v component of the permit signature.
rbytes32The r component of the permit signature.
sbytes32The s component of the permit signature.
amountTokenuint256The amount of token received.
amountETHuint256The amount of ETH received.

removeLiquidityETHSupportingFeeOnTransferTokens#

function removeLiquidityETHSupportingFeeOnTransferTokens(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);

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.
NameType
tokenIERC20The contract address of the desired token.
pooladdressThe contract address of the desired pool to remove liquidity from.
liquidityuint256The amount of liquidity tokens to remove.
amountTokenMinuint256The minimum amount of token that must be received for the transaction not to revert.
amountETHMinuint256The minimum amount of ETH that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuint256Unix timestamp after which the transaction will revert.
amountETHuint256The amount of ETH received.

removeLiquidityETHWithPermitSupportingFeeOnTransferTokens#

function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint256 amountETH);

Identical to removeLiquidityETHWithPermit, but succeeds for tokens that take a fee on transfer.

NameType
tokenaddressThe contract address of the desired token.
pooladdressThe contract address of the desired pool to remove liquidity from.
liquidityuint256The amount of liquidity tokens to remove.
amountTokenMinuint256The minimum amount of token that must be received for the transaction not to revert.
amountETHMinuint256The minimum amount of ETH that must be received for the transaction not to revert.
toaddressRecipient of the underlying assets.
deadlineuint256Unix timestamp after which the transaction will revert.
approveMaxboolWhether or not the approval amount in the signature is for liquidity or uint256(-1).
vuint8The v component of the permit signature.
rbytes32The r component of the permit signature.
sbytes32The s component of the permit signature.
amountETHuint256The amount of ETH received.

swapExactTokensForTokens#

function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);

Swaps an exact amount of input tokens for as many output tokens as possible. The token and pool routes are specified by the poolsPath and path variables respectively.

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). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.

For more information on deciding which pools to use, see this section.

  • msg.sender should have already given the router an allowance of at least amountIn on the input token.
NameType
amountInuint256The amount of input tokens to send.
amountOutMinuint256The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountsuint256[] memoryThe input token amount and all subsequent output token amounts.

swapTokensForExactTokens#

function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);

Receive an exact amount of output tokens for as few input tokens as possible. The token and pool routes are specified by the poolsPath and path variables respectively.

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). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.

For more information on deciding which pools to use, see this section.

  • msg.sender should have already given the router an allowance of at least amountInMax on the input token.
NameType
amountOutuint256The amount of output tokens to receive.
amountInMaxuint256The maximum amount of input tokens that can be required before the transaction reverts.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountsuint256[] memoryThe input token amount and all subsequent output token amounts.

swapExactETHForTokens#

function swapExactETHForTokens(uint256 amountOutMin, address[] calldata poolsPath, IERC20[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);

Swaps an exact amount of ETH for as many output tokens as possible. The token and pool routes are specified by the poolsPath and path variables respectively.

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). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.

For more information on deciding which pools to use, see this section.

NameType
msg.value (amountIn)uint256The amount of ETH to send.
amountOutMinuint256The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountsuint256[] memoryThe input token amount and all subsequent output token amounts.

swapTokensForExactETH#

function swapTokensForExactETH(uint256 amountOut, uint256 amountInMax, address[] calldata poolsPath, IERC20[] calldata path, address to, uint256 deadline)
external
returns (uint256[] memory amounts);

Receive an exact amount of ETH for as few input tokens as possible. The token and pool routes are specified by the poolsPath and path variables respectively.

The first element of path is the input token, the last must be weth, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.

For more information on deciding which pools to use, see this section.

  • 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 ETH.
NameType
amountOutuint256The amount of ETH to receive.
amountInMaxuint256The maximum amount of input tokens that can be required before the transaction reverts.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of ETH.
deadlineuint256Unix timestamp after which the transaction will revert.
amountsuint256[] memoryThe input token amount and all subsequent output token amounts.

swapExactTokensForETH#

function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] calldata poolsPath, IERC20[] calldata path, address to, uint256 deadline)
external
returns (uint256[] memory amounts);

Swaps an exact amount of tokens for as much ETH as possible. The token and pool routes are specified by the poolsPath and path variables respectively.

The first element of path is the input token, the last must be weth, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.

For more information on deciding which pools to use, see this section.

  • If the to address is a smart contract, it must have the ability to receive ETH.
NameType
amountInuint256The amount of input tokens to send.
amountOutMinuint256The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the ETH.
deadlineuint256Unix timestamp after which the transaction will revert.
amountsuint256[] memoryThe input token amount and all subsequent output token amounts.

swapETHForExactTokens#

function swapETHForExactTokens(uint256 amountOut, address[] calldata poolsPath, IERC20[] calldata path, address to, uint256 deadline)
external
payable
returns (uint256[] memory amounts);

Receive an exact amount of tokens for as little ETH as possible.

. The token and pool routes are specified by the poolsPath and path variables respectively.

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). The nth element of poolsPath is the first pool to be used for the nth and (n+1)th elements of path. It therefore is a requirement for poolsPath to be a size smaller than path, ie. poolsPath.length = path.length - 1.

For more information on deciding which pools to use, see this section.

  • Leftover ETH, if any, is returned to msg.sender.
NameType
amountOutuint256The amount of tokens to receive.
msg.value (amountInMax)uint256The maximum amount of ETH that can be required before the transaction reverts.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuint256Unix timestamp after which the transaction will revert.
amountsuint256[] memoryThe input token amount and all subsequent output token amounts.

swapExactTokensForTokensSupportingFeeOnTransferTokens#

function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 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.
NameType
amountInuint256The amount of input tokens to send.
amountOutMinuint256The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuint256Unix timestamp after which the transaction will revert.

swapExactETHForTokensSupportingFeeOnTransferTokens#

function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external payable;

Identical to swapExactETHForTokens, but succeeds for tokens that take a fee on transfer.

NameType
msg.value (amountIn)uint256The amount of ETH to send.
amountOutMinuint256The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the output tokens.
deadlineuint256Unix timestamp after which the transaction will revert.

swapExactTokensForETHSupportingFeeOnTransferTokens#

function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external;

Identical to swapExactTokensForETH, 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 ETH.
NameType
amountInuint256The amount of input tokens to send.
amountOutMinuint256The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPathaddress[] calldataAn array of pool addresses. poolsPath.length must be smaller than path.length by 1. Each pool specified is a pool for each consecutive pair of addresses and must have liquidity.
pathIERC20[] calldataAn array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
toaddressRecipient of the ETH.
deadlineuint256Unix timestamp after which the transaction will revert.

Internal Functions#

verifyPoolsPathSwap#

function verifyPoolsPathSwap(address[] memory poolsPath, IERC20[] memory path) internal view

Verifies the length of the poolsPath and path variables, and will call verifyPoolAddress for each pool specified per token pair.

verifyPoolAddress#

function verifyPoolAddress(IERC20 tokenA, IERC20 tokenB, address pool) internal view

Checks requirement that pool is indeed a valid pool address for the token pair tokenA and tokenB.

Interface#

import '@dynamic-amm/smart-contracts/contracts/interfaces/IDMMRouter02.sol';
pragma solidity 0.6.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @dev an simple interface for integration dApp to swap
interface IDMMExchangeRouter {
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(
uint256 amountOut,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function getAmountsOut(
uint256 amountIn,
address[] calldata poolsPath,
IERC20[] calldata path
) external view returns (uint256[] memory amounts);
function getAmountsIn(
uint256 amountOut,
address[] calldata poolsPath,
IERC20[] calldata path
) external view returns (uint256[] memory amounts);
}
/// @dev an simple interface for integration dApp to contribute liquidity
interface IDMMLiquidityRouter {
function addLiquidity(
IERC20 tokenA,
IERC20 tokenB,
address pool,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
)
external
returns (
uint256 amountA,
uint256 amountB,
uint256 liquidity
);
function addLiquidityNewPool(
IERC20 tokenA,
IERC20 tokenB,
uint32 ampBps,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
)
external
returns (
uint256 amountA,
uint256 amountB,
uint256 liquidity
);
function addLiquidityNewPoolETH(
IERC20 token,
uint32 ampBps,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function addLiquidityETH(
IERC20 token,
address pool,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function removeLiquidity(
IERC20 tokenA,
IERC20 tokenB,
address pool,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityWithPermit(
IERC20 tokenA,
IERC20 tokenB,
address pool,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityETHWithPermit(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function quote(
uint256 amountA,
uint256 reserveA,
uint256 reserveB
) external pure returns (uint256 amountB);
}
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256) external;
}
/// @dev full interface for router
interface IDMMRouter01 is IDMMExchangeRouter, IDMMLiquidityRouter {
function factory() external pure returns (address);
function weth() external pure returns (IWETH);
}
/// @dev supporting fee on transfer tokens
interface IDMMRouter02 is IDMMRouter01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
IERC20 token,
address pool,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata poolsPath,
IERC20[] calldata path,
address to,
uint256 deadline
) external;
}

ABI#

import IDMMRouter02 from '@dynamic-amm/smart-contracts/artifacts/contracts/interfaces/IDMMRouter02.sol/IDMMRouter02.json'

https://unpkg.com/@dynamic-amm/smart-contracts/artifacts/contracts/interfaces/IDMMRouter02.sol/IDMMRouter02.json