Swap
In the following subsections, we will detail the functions related to swapping that has been defined in the Infinity Protocol.

swapExactTokensForTokens

This function allows swapping an exact amount of input tokens along the route determined by the path for as many output tokens as possible.
1
function swapExactTokensForTokens(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
)
Copied!
The swapExactTokensForTokens function accepts these parameters:
Parameter
Type
Description
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[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapTokensForExactTokens

Receive an exact amount of output tokens along the route determined by the path for as few input tokens as possible.
1
function swapTokensForExactTokens(
2
uint amountOut,
3
uint amountInMax,
4
address[] calldata path,
5
address to,
6
uint deadline
7
)
Copied!
The swapTokensForExactTokens function accepts these parameters:
Type
Parameter
Description
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[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapExactETHForTokens

Swap an exact amount of the chains native asset such as ETH or BNB for as many output tokens as possible, along the route determined by the path.
1
function swapExactETHForTokens(
2
uint amountOutMin,
3
address[] calldata path,
4
address to,
5
uint deadline
6
)
Copied!
The swapExactETHForTokens function accepts these parameters:
Type
Parameter
Description
amountOutMin
uint
The minimum amount of output tokens that must be received for the transaction not to revert.
path
address[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapTokensForExactETH

Receive an exact amount of the chains native asset such as ETH or BNB along the route determined by the path for as few input tokens as possible.
1
function swapTokensForExactETH(
2
uint amountOut,
3
uint amountInMax,
4
address[] calldata path,
5
address to,
6
uint deadline
7
)
Copied!
The swapTokensForExactETH function accepts these parameters:
Type
Parameter
Description
amountOut
uint
The amount of ETH to receive.
amountInMax
uint
The maximum amount of input tokens that can be required before the transaction reverts.
path
address[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapExactTokensForETH

Swaps an exact amount of tokens along the route determined by the path for as much of the chains native asset such as ETH or BNB as possible.
1
function swapExactTokensForETH(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
)
Copied!
The swapExactTokensForETH function accepts these parameters:
Type
Parameter
Description
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[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapETHForExactTokens

Receive an exact amount of tokens along the route determined by the path for as little of the chains native asset such as ETH or BNB as possible.
1
function swapETHForExactTokens(
2
uint amountOut,
3
address[] calldata path,
4
address to,
5
uint deadline
6
)
Copied!
The swapETHForExactTokens function accepts these parameters:
Type
Parameter
Description
amountOut
uint
The amount of tokens to receive.
path
address[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapExactTokensForTokensSupportingFeeOnTransferTokens

This function is identical to swapExactTokensForTokens, but is for tokens that take a fee on transfer. It allows swapping an exact amount of input tokens along the route determined by the path for as many output tokens as possible.
1
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
)
Copied!
The swapExactTokensForTokensSupportingFeeOnTransferTokens function accepts these parameters:
Type
Parameter
Description
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[]
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
The Unix-time deadline for which the transaction must be confirmed before.

swapExactETHForTokensSupportingFeeOnTransferTokens

This function is identical to swapExactETHForTokens, but is for tokens that take a fee on transfer. It allows swapping an exact amount of the chains native asset such as ETH or BNB for as many output tokens as possible, along the route determined by the path.
1
function swapExactETHForTokensSupportingFeeOnTransferTokens(
2
uint amountOutMin,
3
address[] calldata path,
4
address to,
5
uint deadline
6
)
Copied!
The swapExactETHForTokensSupportingFeeOnTransferTokens function accepts these parameters:
Type
Parameter
Description
amountOutMin
uint
The minimum amount of output tokens that must be received for the transaction not to revert.
path
address
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
The Unix-time deadline for which the transaction must be confirmed before.

swapExactTokensForETHSupportingFeeOnTransferTokens

This function is identical to swapExactTokensForETH, but is for tokens that take a fee on transfer. It allows swapping an exact amount of tokens along the route determined by the path for as much of the chains native asset such as ETH or BNB as possible.
1
function swapExactTokensForETHSupportingFeeOnTransferTokens(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
)
Copied!
The swapExactTokensForETHSupportingFeeOnTransferTokens function accepts these parameters:
Type
Parameter
Description
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[]
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 ETH.
deadline
uint
The Unix-time deadline for which the transaction must be confirmed before.
Last modified 6mo ago