Comment on page
Router
This documentation provides an overview of the IRouter.sol. This contract defines various functions and structs used for interacting with the Maverick AMM.
- Name : IRouter
- Solidity Version : ^0.8.0
- SPDX License-Identifier : GPL-2.0-or-later
Router
is Deployed to
struct PoolParams {
uint256 fee;
uint256 tickSpacing;
int256 lookback;
int32 activeTick;
IERC20 tokenA;
IERC20 tokenB;
}
fee
: The fee valueuint256
associated with the pool.tickSpacing
: The tick spacing valueuint256
for the pool.lookback
: The lookback valueint256
for the pool.activeTick
: The active tick valueint32
for the pool.tokenA
: The ERC20 token Aaddress
associated with the pool.tokenB
: The ERC20 token Baddress
associated with the pool.
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
path
: Abytes
string representing the path of tokens to swap.recipient
: Theaddress
where the swapped tokens will be sent.deadline
: The deadline timestamp (in seconds)uint256
until which the swap can be executed.amountIn
: The amount of the input tokenuint256
to be swapped.amountOutMinimum
: The minimum acceptable amount of the output tokenuint256
specified to prevent infinite slippage.
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
path
: Abytes
string representing the path of tokens to swap (reversed).recipient
: Theaddress
where the swapped tokens will be sent.deadline
: The deadline timestamp (in seconds)uint256
until which the swap can be executed.amountOut
: The amount of the output tokenuint256
desired.amountInMaximum
: The maximum acceptable amount of the input tokenuint256
required.
Returns the address of the factory.
function factory() external view returns (IFactory);
- Returns :
- IFactory : The
address
of the Factory
Returns the address of the Position NFT.
function position() external view returns (IPosition);
- Returns
- IPosition : The position NFT
address
Swaps
amountIn
of one token for as much as possible of another along the specified path.function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
- Parameters :
params
: The parameters necessary for the multi-hop swap, encoded asExactInputParams
in calldata
- Returns :
amountOut
: The amount of the received token inuint256
Swaps as little as possible of one token for
amountOut
of another along the specified path (reversed).function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
- Parameters :
params
: The parameters necessary for the multi-hop swap, encoded asExactOutputParams
in calldata
- Returns :
amountIn
: The amount of the input token inuint256
Either gets an existing pool or creates a pool if it does not exist and adds liquidity to it.
function getOrCreatePoolAndAddLiquidity(
PoolParams calldata poolParams,
uint256 tokenId,
IPool.AddLiquidityParams[] calldata addParams,
uint256 minTokenAAmount,
uint256 minTokenBAmount,
uint256 deadline
) external payable returns (uint256 receivingTokenId, uint256 tokenAAmount, uint256 tokenBAmount, IPool.BinDelta[] memory binDeltas);
- Parameters :
poolParams
: Parameters of a pool withpoolParams
tokenId
: NFT ID of the tokenuint256
that will hold LP balance. Use0
to mint a new tokenaddParams
: Parameters of liquidity addition withaddParams
minTokenAAmount
: Minimum amount of token Auint256
to add. Reverts if not metminTokenBAmount
: Minimum amount of token Buint256
to add. Reverts if not metdeadline
: Epoch timestamp (in seconds)uint256
- Returns :
receivingTokenId
: The IDuint256
of the receiving tokentokenAAmount
: The amount of token Auint256
tokenBAmount
: The amount of token Buint256
binDeltas
: An array ofBinDelta
structures
Adds liquidity to a pool.
function addLiquidityToPool(
IPool pool,
uint256 tokenId,
IPool.AddLiquidityParams[] calldata params,
uint256 minTokenAAmount,
uint256 minTokenBAmount,
uint256 deadline
) external payable returns (uint256 receivingTokenId, uint256 tokenAAmount, uint256 tokenBAmount, IPool.BinDelta[] memory binDeltas);
- Parameters :
pool
: Pool to add liquidity toIPool
tokenId
: NFT ID of the tokenuint256
that will hold LP balance. Use0
to mint a new tokenparams
: Parameters of liquidity addition withparams
minTokenAAmount
: Minimum amount of token Auint256
to add. Reverts if not metminTokenBAmount
: Minimum amount of token Buint256
to add. Reverts if not metdeadline
: Epoch timestamp (in seconds)uint256
- Returns :
receivingTokenId
: The ID of the receiving tokenuint256
tokenAAmount
: The amount of token Auint256
tokenBAmount
: The amount of token Buint256
binDeltas
: An array ofBinDelta
structures
Adds liquidity to a pool with active tick limits.
function addLiquidityWTickLimits(
IPool pool,
uint256 tokenId,
IPool.AddLiquidityParams[] calldata params,
uint256 minTokenAAmount,
uint256 minTokenBAmount,
int32 minActiveTick,
int32 maxActiveTick,
uint256 deadline
) external payable returns (uint256 receivingTokenId, uint256 tokenAAmount, uint256 tokenBAmount, IPool.BinDelta[] memory binDeltas);
- Parameters :
pool
: Pool to add liquidity toIPool
tokenId
: NFT ID of the tokenuint256
that will hold LP balance. Use0
to mint a new tokenparams
: Parameters of liquidity addition withparams
minTokenAAmount
: Minimum amount of token Auint256
to add. Reverts if not metminTokenBAmount
: Minimum amount of token Buint256
to add. Reverts if not metminActiveTick
: Lowest activeTickint32
(inclusive) of the pool that will permit the transaction to passmaxActiveTick
: Highest activeTickint32
(inclusive) of the pool that will permit the transaction to passdeadline
: Epoch timestamp (in seconds)
- Returns :
receivingTokenId
: The ID of the receiving tokenuint256
tokenAAmount
: The amount of token Auint256
tokenBAmount
: The amount of token Buint256
binDeltas
: An array ofBinDelta
structures
Moves the head of input merged bins to the active bin.
function migrateBinsUpStack(IPool pool, uint128[] calldata binIds, uint32 maxRecursion, uint256 deadline) external;
- Parameters :
pool
: Pool to remove from withIPool
binIds
: Array ofbinIds
to migratemaxRecursion
: Maximum recursion depthuint32
before returning;0
means no maximumdeadline
: Epoch timestamp (in seconds)uint256
Removes liquidity from a pool and receives WETH if one of the tokens is WETH.
function removeLiquidity(
IPool pool,
address recipient,
uint256 tokenId,
IPool.RemoveLiquidityParams[] calldata params,
uint256 minTokenAAmount,
uint256 minTokenBAmount,
uint256 deadline
) external returns (uint256 tokenAAmount, uint256 tokenBAmount, IPool.BinDelta[] memory binDeltas);
Router must be approved for the withdrawing tokenId:Position.approve(router, tokenId)
- Parameters :
pool
: Pool to remove from withIPool
recipient
:address
where the proceeds are sent. Usezero
or router address to leave tokens in the routertokenId
: IDuint256
of the position NFT that holds liquidityparams
: Parameters of liquidity removal withparams
minTokenAAmount
: Minimum amount of token Auint256
to receive. Reverts if not metminTokenBAmount
: Minimum amount of token Buint256
to receive. Reverts if not metdeadline
: Epoch timestamp (in seconds)uint256
- Returns :
tokenAAmount
: The amount of token Auint256
receivedtokenBAmount
: The amount of token Buint256
receivedbinDeltas
: An array ofBinDelta
structure
Last modified 6mo ago