Skip to main content

IBasicButtonswapRouter

Inherits: IRootButtonswapRouter

Functions

addLiquidity

Adds liquidity to a pair, creating it if it doesn't exist yet, and transfers the liquidity tokens to the recipient.

*If the pair is empty, amountAMin and amountBMin are ignored. If the pair is nonempty, it deposits as much of tokenA and tokenB as possible while maintaining 3 conditions:

  1. The ratio of tokenA to tokenB in the pair remains approximately the same
  2. The amount of tokenA in the pair is at least amountAMin but less than or equal to amountADesired
  3. The amount of tokenB in the pair is at least amountBMin but less than or equal to amountBDesired*
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
uint16 movingAveragePrice0ThresholdBps,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);

Parameters

NameTypeDescription
tokenAaddressThe address of the first token in the pair.
tokenBaddressThe address of the second token in the pair.
amountADesireduint256The maximum amount of the first token to add to the pair.
amountBDesireduint256The maximum amount of the second token to add to the pair.
amountAMinuint256The minimum amount of the first token to add to the pair.
amountBMinuint256The minimum amount of the second token to add to the pair.
movingAveragePrice0ThresholdBpsuint16The percentage threshold that movingAveragePrice0 can deviate from the current price.
toaddressThe address to send the liquidity tokens to.
deadlineuint256The time after which this transaction can no longer be executed.

Returns

NameTypeDescription
amountAuint256The amount of tokenA actually added to the pair.
amountBuint256The amount of tokenB actually added to the pair.
liquidityuint256The amount of liquidity tokens minted.

addLiquidityWithReservoir

Adds liquidity to a pair, opposite to the existing reservoir, and transfers the liquidity tokens to the recipient

*Since there at most one reservoir at a given time, some conditions are checked:

  1. If there is no reservoir, it rejects
  2. The token with the reservoir has its amountDesired parameter ignored
  3. The token with the reservoir has its amount deducted from the reservoir (checked against corresponding amountMin parameter)*
function addLiquidityWithReservoir(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);

Parameters

NameTypeDescription
tokenAaddressThe address of the first token in the pair.
tokenBaddressThe address of the second token in the pair.
amountADesireduint256The maximum amount of the first token to add to the pair.
amountBDesireduint256The maximum amount of the second token to add to the pair.
amountAMinuint256The minimum amount of the first token to add to the pair.
amountBMinuint256The minimum amount of the second token to add to the pair.
toaddressThe address to send the liquidity tokens to.
deadlineuint256The time after which this transaction can no longer be executed.

Returns

NameTypeDescription
amountAuint256The amount of tokenA actually added to the pair.
amountBuint256The amount of tokenB actually added to the pair.
liquidityuint256The amount of liquidity tokens minted.

removeLiquidity

Removes liquidity from a pair, and transfers the tokens to the recipient.

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

Parameters

NameTypeDescription
tokenAaddressThe address of the first token in the pair.
tokenBaddressThe address of the second token in the pair.
liquidityuint256The amount of liquidity tokens to burn.
amountAMinuint256The minimum amount of the first token to withdraw from the pair.
amountBMinuint256The minimum amount of the second token to withdraw from the pair.
toaddressThe address to send the tokens to.
deadlineuint256The time after which this transaction can no longer be executed.

Returns

NameTypeDescription
amountAuint256The amount of tokenA actually withdrawn from the pair.
amountBuint256The amount of tokenB actually withdrawn from the pair.

removeLiquidityFromReservoir

Removes liquidity from the reservoir of a pair and transfers the tokens to the recipient.

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

Parameters

NameTypeDescription
tokenAaddressThe address of the first token in the pair.
tokenBaddressThe address of the second token in the pair.
liquidityuint256The amount of liquidity tokens to burn.
amountAMinuint256The minimum amount of the first token to withdraw from the pair.
amountBMinuint256The minimum amount of the second token to withdraw from the pair.
toaddressThe address to send the tokens to.
deadlineuint256The time after which this transaction can no longer be executed.

Returns

NameTypeDescription
amountAuint256The amount of tokenA actually withdrawn from the pair.
amountBuint256The amount of tokenB actually withdrawn from the pair.

removeLiquidityWithPermit

Similar to removeLiquidity() but utilizes the Permit signatures to reduce gas consumption. Removes liquidity from a pair, and transfers the tokens to the recipient.

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

Parameters

NameTypeDescription
tokenAaddressThe address of the first token in the pair.
tokenBaddressThe address of the second token in the pair.
liquidityuint256The amount of liquidity tokens to burn.
amountAMinuint256The minimum amount of the first token to withdraw from the pair.
amountBMinuint256The minimum amount of the second token to withdraw from the pair.
toaddressThe address to send the tokens to.
deadlineuint256The time after which this transaction can no longer be executed.
approveMaxboolWhether the signature is for the max uint256 or liquidity value
vuint8Part of the signature
rbytes32Part of the signature
sbytes32Part of the signature

Returns

NameTypeDescription
amountAuint256The amount of tokenA actually withdrawn from the pair.
amountBuint256The amount of tokenB actually withdrawn from the pair.

swapExactTokensForTokens

Given an ordered array of tokens, performs consecutive swaps from a specific amount of the first token to the last token in the array.

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

Parameters

NameTypeDescription
amountInuint256The amount of the first token to swap.
amountOutMinuint256The minimum amount of the last token to receive from the swap.
pathaddress[]An array of token addresses [tokenA, tokenB, tokenC, ...] representing the path the input token takes to get to the output token
toaddressThe address to send the output token to.
deadlineuint256The time after which this transaction can no longer be executed.

swapTokensForExactTokens

Given an ordered array of tokens, performs consecutive swaps from the first token to a specific amount of the last token in the array.

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

Parameters

NameTypeDescription
amountOutuint256The amount of the last token to receive from the swap.
amountInMaxuint256The maximum amount of the first token to swap.
pathaddress[]An array of token addresses [tokenA, tokenB, tokenC, ...] representing the path the input token takes to get to the output token
toaddressThe address to send the output token to.
deadlineuint256The time after which this transaction can no longer be executed.