Router
This documentation provides an overview of the IRouter.sol. This contract defines various functions and structs used for interacting with the Maverick AMM.
Contents
Contract Details
Name : IRouter
Solidity Version : ^0.8.0
SPDX License-Identifier : GPL-2.0-or-later
Routeris Deployed toZKSync Era:
0x39E098A153Ad69834a9Dac32f0FCa92066aD03f4
Code: Github
Structs
PoolParams
fee: The fee valueuint256associated with the pool.tickSpacing: The tick spacing valueuint256for the pool.lookback: The lookback valueint256for the pool.activeTick: The active tick valueint32for the pool.tokenA: The ERC20 token Aaddressassociated with the pool.tokenB: The ERC20 token Baddressassociated with the pool.
ExactInputParams
path: Abytesstring representing the path of tokens to swap.recipient: Theaddresswhere the swapped tokens will be sent.deadline: The deadline timestamp (in seconds)uint256until which the swap can be executed.amountIn: The amount of the input tokenuint256to be swapped.amountOutMinimum: The minimum acceptable amount of the output tokenuint256specified to prevent infinite slippage.
ExactOutputParams
path: Abytesstring representing the path of tokens to swap (reversed).recipient: Theaddresswhere the swapped tokens will be sent.deadline: The deadline timestamp (in seconds)uint256until which the swap can be executed.amountOut: The amount of the output tokenuint256desired.amountInMaximum: The maximum acceptable amount of the input tokenuint256required.
Functions
factory()
Returns the address of the factory.
Returns :
IFactory : The
addressof the Factory
position()
Returns the address of the Position NFT.
Returns
IPosition : The position NFT
address
exactInput()
Swaps amountIn of one token for as much as possible of another along the specified path.
Parameters :
params: The parameters necessary for the multi-hop swap, encoded asExactInputParamsin calldata
Returns :
amountOut: The amount of the received token inuint256
exactOutput()
Swaps as little as possible of one token for amountOut of another along the specified path (reversed).
Parameters :
params: The parameters necessary for the multi-hop swap, encoded asExactOutputParamsin calldata
Returns :
amountIn: The amount of the input token inuint256
getOrCreatePoolAndAddLiquidity()
Either gets an existing pool or creates a pool if it does not exist and adds liquidity to it.
Parameters :
poolParams: Parameters of a pool withpoolParamstokenId: NFT ID of the tokenuint256that will hold LP balance. Use0to mint a new tokenaddParams: Parameters of liquidity addition withaddParamsminTokenAAmount: Minimum amount of token Auint256to add. Reverts if not metminTokenBAmount: Minimum amount of token Buint256to add. Reverts if not metdeadline: Epoch timestamp (in seconds)uint256
Returns :
receivingTokenId: The IDuint256of the receiving tokentokenAAmount: The amount of token Auint256tokenBAmount: The amount of token Buint256binDeltas: An array ofBinDeltastructures
addLiquidityToPool()
Adds liquidity to a pool.
Parameters :
pool: Pool to add liquidity toIPooltokenId: NFT ID of the tokenuint256that will hold LP balance. Use0to mint a new tokenparams: Parameters of liquidity addition withparamsminTokenAAmount: Minimum amount of token Auint256to add. Reverts if not metminTokenBAmount: Minimum amount of token Buint256to add. Reverts if not metdeadline: Epoch timestamp (in seconds)uint256
Returns :
receivingTokenId: The ID of the receiving tokenuint256tokenAAmount: The amount of token Auint256tokenBAmount: The amount of token Buint256binDeltas: An array ofBinDeltastructures
addLiquidityWTickLimits()
Adds liquidity to a pool with active tick limits.
Parameters :
pool: Pool to add liquidity toIPooltokenId: NFT ID of the tokenuint256that will hold LP balance. Use0to mint a new tokenparams: Parameters of liquidity addition withparamsminTokenAAmount: Minimum amount of token Auint256to add. Reverts if not metminTokenBAmount: Minimum amount of token Buint256to 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 tokenuint256tokenAAmount: The amount of token Auint256tokenBAmount: The amount of token Buint256binDeltas: An array ofBinDeltastructures
migrateBinsUpStack()
Moves the head of input merged bins to the active bin.
Parameters :
pool: Pool to remove from withIPoolbinIds: Array ofbinIdsto migratemaxRecursion: Maximum recursion depthuint32before returning;0means no maximumdeadline: Epoch timestamp (in seconds)uint256
removeLiquidity()
Removes liquidity from a pool and receives WETH if one of the tokens is WETH.
Router must be approved for the withdrawing tokenId:
Position.approve(router, tokenId)
Parameters :
pool: Pool to remove from withIPoolrecipient:addresswhere the proceeds are sent. Usezeroor router address to leave tokens in the routertokenId: IDuint256of the position NFT that holds liquidityparams: Parameters of liquidity removal withparamsminTokenAAmount: Minimum amount of token Auint256to receive. Reverts if not metminTokenBAmount: Minimum amount of token Buint256to receive. Reverts if not metdeadline: Epoch timestamp (in seconds)uint256
Returns :
tokenAAmount: The amount of token Auint256receivedtokenBAmount: The amount of token Buint256receivedbinDeltas: An array ofBinDeltastructure
Last updated