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.
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.
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.
msg.sender should have already given the router an allowance of at least amountIn on the input token.
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.
msg.sender should have already given the router an allowance of at least amountInMax on the input token.
Interface
pragma solidity 0.6.12;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";/// @dev an simple interface for integration dApp to swapinterfaceIBuniCornExchangeRouter {functionswapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata poolsPath, IERC20[] calldata path, address to, uint256 deadline ) externalreturns (uint256[] memory amounts);functionswapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata poolsPath, IERC20[] calldata path, address to, uint256 deadline ) externalreturns (uint256[] memory amounts);functiongetAmountsOut( uint256 amountIn, address[] calldata poolsPath, IERC20[] calldata path ) externalviewreturns (uint256[] memory amounts);functiongetAmountsIn( uint256 amountOut, address[] calldata poolsPath, IERC20[] calldata path ) externalviewreturns (uint256[] memory amounts);}/// @dev an simple interface for integration dApp to contribute liquidityinterfaceIBuniCornLiquidityRouter {/** * @param tokenA address of token in the pool * @param tokenB address of token in the pool * @param pool the address of the pool * @param amountADesired the amount of tokenA users want to add to the pool * @param amountBDesired the amount of tokenB users want to add to the pool * @param amountAMin bounds to the extents to which amountB/amountA can go up * @param amountBMin bounds to the extents to which amountB/amountA can go down * @param vReserveRatioBounds bounds to the extents to which vReserveB/vReserveA can go (precision: 2 ** 112) * @param to Recipient of the liquidity tokens. * @param deadline Unix timestamp after which the transaction will revert. */functionaddLiquidity( IERC20 tokenA, IERC20 tokenB, address pool, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, uint256[2] calldata vReserveRatioBounds, address to, uint256 deadline )externalreturns ( uint256 amountA, uint256 amountB, uint256 liquidity );functionaddLiquidityNewPool( IERC20 tokenA, IERC20 tokenB, uint32 ampBps, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline )externalreturns ( uint256 amountA, uint256 amountB, uint256 liquidity );/** * @param tokenA address of token in the pool * @param tokenB address of token in the pool * @param pool the address of the pool * @param liquidity the amount of lp token users want to burn * @param amountAMin the minimum token retuned after burning * @param amountBMin the minimum token retuned after burning * @param to Recipient of the returned tokens. * @param deadline Unix timestamp after which the transaction will revert. */functionremoveLiquidity( IERC20 tokenA, IERC20 tokenB, address pool, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) externalreturns (uint256 amountA, uint256 amountB);/** * @param tokenA address of token in the pool * @param tokenB address of token in the pool * @param pool the address of the pool * @param liquidity the amount of lp token users want to burn * @param amountAMin the minimum token retuned after burning * @param amountBMin the minimum token retuned after burning * @param to Recipient of the returned tokens. * @param deadline Unix timestamp after which the transaction will revert. * @param approveMax whether users permit the router spending max lp token or not. * @param r s v Signature of user to permit the router spending lp token */functionremoveLiquidityWithPermit( IERC20 tokenA, IERC20 tokenB, address pool, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) externalreturns (uint256 amountA, uint256 amountB);/** * @param amountA amount of 1 side token added to the pool * @param reserveA current reserve of the pool * @param reserveB current reserve of the pool * @return amountB amount of the other token added to the pool */functionquote( uint256 amountA, uint256 reserveA, uint256 reserveB ) externalpurereturns (uint256 amountB);}/// @dev full interface for routerinterfaceIBuniCornRouter01isIBuniCornExchangeRouter, IBuniCornLiquidityRouter {functionfactory() externalpurereturns (address);}
The contract address of the desired pool to add liquidity to.
amountADesired
uint256
The amount of tokenA to add as liquidity if the B/A price is <= amountBDesired/amountADesired (A depreciates).
amountBDesired
uint256
The amount of tokenB to add as liquidity if the A/B price is <= amountADesired/amountBDesired (B depreciates).
amountAMin
uint256
Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired.
amountBMin
uint256
Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired.
vReserveRatioBounds
uint256[2]
Bounds the extent to which the virtual B/A price can move before the transaction reverts.
to
address
Recipient of the liquidity tokens.
deadline
uint256
Unix timestamp after which the transaction will revert.
amountA
uint256
The amount of tokenA sent to the pool.
amountB
uint256
The amount of tokenB sent to the pool.
liquidity
uint256
The amount of liquidity tokens minted.
Name
Type
tokenA
IERC20
The contract address of the desired token.
tokenB
IERC20
The contract address of the desired token.
pool
address
The contract address of the desired pool to remove liquidity from.
liquidity
uint256
The amount of liquidity tokens to remove.
amountAMin
uint256
The minimum amount of tokenA that must be received for the transaction not to revert.
amountBMin
uint256
The minimum amount of tokenB that must be received for the transaction not to revert.
to
address
Recipient of the underlying assets.
deadline
uint256
Unix timestamp after which the transaction will revert.
amountA
uint256
The amount of tokenA received.
amountB
uint256
The amount of tokenB received.
Name
Type
tokenA
IERC20
The contract address of the desired token.
tokenB
IERC20
The contract address of the desired token.
pool
address
The contract address of the desired pool to remove liquidity from.
liquidity
uint256
The amount of liquidity tokens to remove.
amountAMin
uint256
The minimum amount of tokenA that must be received for the transaction not to revert.
amountBMin
uint256
The minimum amount of tokenB that must be received for the transaction not to revert.
to
address
Recipient of the underlying assets.
deadline
uint256
Unix timestamp after which the transaction will revert.
approveMax
bool
Whether or not the approval amount in the signature is for liquidity or uint256(-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
uint256
The amount of tokenA received.
amountB
uint256
The amount of tokenB received.
Name
Type
amountIn
uint256
The amount of input tokens to send.
amountOutMin
uint256
The minimum amount of output tokens that must be received for the transaction not to revert.
poolsPath
address[] calldata
An 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.
path
IERC20[] 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
uint256
Unix timestamp after which the transaction will revert.
amounts
uint256[] memory
The input token amount and all subsequent output token amounts.
Name
Type
amountOut
uint256
The amount of output tokens to receive.
amountInMax
uint256
The maximum amount of input tokens that can be required before the transaction reverts.
poolsPath
address[] calldata
An 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.
path
IERC20[] 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
uint256
Unix timestamp after which the transaction will revert.
amounts
uint256[] memory
The input token amount and all subsequent output token amounts.