Maverick Docs
  • Introducing Maverick
  • Getting Started
    • 🖥️The Maverick V2 UI
    • 👛Connect a Wallet
    • ⛓️Choose a Network
    • 🪙Approving Tokens
  • Guides
    • 🤝Traders
      • How to Make a Swap
    • 💰Liquidity Providers
      • Understanding Liquidity Provision
      • Understanding Modes
      • How to Add Liquidity
      • How to Deploy a New Pool
      • How to Check Position Balances
      • How to Manage Liquidity in a Pool
      • How to Migrate from V1 to V2
      • Understanding Permanent Loss
      • Liquidity Strategies
    • ⚡Incentives
      • Understanding Boosted Positions
      • Understanding Incentives
      • How to Join a Boosted Position
      • How to Create a Boosted Position
      • How to Manage a Boosted Position
      • How to Add Incentives
    • 🎡veFlywheel
      • veFlywheel Basics
      • Guide to veFlywheel Emissions
      • How to Vote to Direct Emissions
    • 👩‍🏫Advanced Tutorials
      • Single-Sided Incentives
  • Technical Reference
    • Contract Addresses
      • V1 Contract Addresses
      • V2 Contract Addresses
    • Maverick V1
      • V1 Whitepaper
      • V1 Contracts
        • Router
        • Pool
        • Factory
        • SlimRouter
    • Maverick V2
      • V2 Whitepaper
      • V2 Contracts
        • Maverick V2 Common Contracts
          • base
            • IMulticall
            • IPayableMulticall
            • Multicall
            • PayableMulticall
          • interfaces
            • IMaverickV2AddLiquidityCallback
            • IMaverickV2Factory
            • IMaverickV2FactoryAdmin
            • IMaverickV2FlashLoanCallback
            • IMaverickV2Pool
            • IMaverickV2PoolAdmin
            • IMaverickV2SwapCallback
          • libraries
            • ArrayOperations
            • Constants
            • Math
            • PoolLib
            • TickMath
            • TransferLib
        • Maverick V2 AMM Contracts
          • poollib
            • Bin
            • Delta
            • Deployer
            • DeployerPermissioned
            • SwapMath
            • Twa
          • MaverickV2Factory
          • MaverickV2Pool
          • MaverickV2PoolPermissioned
        • Maverick V2 Reward Contracts
          • interfaces
            • IMaverickV2IncentiveMatcher
            • IMaverickV2IncentiveMatcherFactory
            • IMaverickV2Reward
            • IMaverickV2RewardFactory
            • IMaverickV2RewardRouter
            • IMaverickV2RewardVault
            • IMaverickV2VotingEscrowBase
            • IMaverickV2VotingEscrow
            • IMaverickV2VotingEscrowFactory
            • IMaverickV2VotingEscrowLens
            • IMaverickV2VotingEscrowWSync
          • libraries
            • IncentiveMatcherDeployer
            • RewardDeployer
            • VotingEscrowDeployer
            • VotingEscrowWSyncDeployer
          • rewardbase
            • IRewardAccounting
            • RewardAccounting
          • votingescrowbase
            • HistoricalBalance
            • IHistoricalBalance
            • ILegacyVeMav
            • VotingEscrow
          • MaverickV2IncentiveMatcher
          • MaverickV2IncentiveMatcherFactory
          • MaverickV2Reward
          • MaverickV2RewardFactory
          • MaverickV2RewardRouter
          • MaverickV2RewardVault
          • MaverickV2VotingEscrow
          • MaverickV2VotingEscrowFactory
          • MaverickV2VotingEscrowLens
          • MaverickV2VotingEscrowWSync
        • Maverick V2 Supplemental Contracts
          • base
            • Checks
            • IChecks
            • IMigrateBins
            • MigrateBins
          • boostedpositionbase
            • BoostedPositionBase
            • IBoostedPositionBase
            • ImmutableArrayGetter
          • interfaces
            • IMaverickV2BoostedPosition
            • IMaverickV2BoostedPositionFactory
            • IMaverickV2LiquidityManager
            • IMaverickV2PoolLens
            • IMaverickV2Position
            • IMaverickV2Quoter
            • IMaverickV2Router
            • IPositionImage
          • libraries
            • BoostedPositionDeployerDynamic
            • BoostedPositionDeployerStatic
            • BytesLib
            • LiquidityUtilities
            • PackLib
            • Path
            • PoolInspection
          • liquiditybase
            • ArgPacker
            • IArgPacker
          • paymentbase
            • IERC20PermitAllowed
            • IPayment
            • ISelfPermit
            • IState
            • IWETH9
            • Payment
            • SelfPermit
            • State
          • positionbase
            • INft
            • Nft
          • routerbase
            • CallbackOperations
            • ExactOutputSlim
            • ICallbackOperations
            • IExactOutputSlim
            • IPushOperations
            • IRouterErrors
            • PushOperations
          • MaverickV2BoostedPositionDynamic
          • MaverickV2BoostedPositionFactory
          • MaverickV2BoostedPositionStatic
          • MaverickV2LiquidityManager
          • MaverickV2PoolLens
          • MaverickV2Position
          • MaverickV2Quoter
          • MaverickV2Router
          • PositionImage
      • V2 API Documentation
      • V2 Testnet Guide
        • Get Sepolia ETH & Test Tokens
        • How to Create a Boosted Position in V2
        • How to Add & Match Incentives
        • How to Create a veFlywheel
    • Development FAQ
    • Finding LP Balances
  • MAV token
    • MAV Token & Tokenomics
    • veMAV & MAV Staking
    • How to Stake MAV
    • Syncing V1 veMAV
    • Airdrop Information
      • Maverick Ecosystem Rewards Pre-Season Airdrop
      • Maverick Governance & S1 Airdrops
  • Further Information
    • Frequently Asked Questions
    • Glossary
    • Security
    • Maverick Wallets
    • Dune Analytics
    • Rebasing Tokens
    • Restricted Territories
    • Delphi Digital Report
Powered by GitBook
On this page
  • Contents
  • Contract Details
  • Structs
  • PoolParams
  • ExactInputParams
  • ExactOutputParams
  • Functions
  • factory()
  • position()
  • exactInput()
  • exactOutput()
  • getOrCreatePoolAndAddLiquidity()
  • addLiquidityToPool()
  • addLiquidityWTickLimits()
  • migrateBinsUpStack()
  • removeLiquidity()
  1. Technical Reference
  2. Maverick V1
  3. V1 Contracts

Router

This documentation provides an overview of the IRouter.sol. This contract defines various functions and structs used for interacting with the Maverick AMM.

PreviousV1 ContractsNextPool

Last updated 1 year ago

Contents

Contract Details

  • Name : IRouter

  • Solidity Version : ^0.8.0

  • SPDX License-Identifier : GPL-2.0-or-later

  • Router is Deployed to

Structs

PoolParams

struct PoolParams {
    uint256 fee;
    uint256 tickSpacing;
    int256 lookback;
    int32 activeTick;
    IERC20 tokenA;
    IERC20 tokenB;
}
  • fee : The fee value uint256 associated with the pool.

  • tickSpacing : The tick spacing value uint256 for the pool.

  • lookback : The lookback value int256 for the pool.

  • activeTick : The active tick value int32 for the pool.

  • tokenA : The ERC20 token A address associated with the pool.

  • tokenB : The ERC20 token B address associated with the pool.

ExactInputParams

struct ExactInputParams {
    bytes path;
    address recipient;
    uint256 deadline;
    uint256 amountIn;
    uint256 amountOutMinimum;
}
  • path : A bytes string representing the path of tokens to swap.

  • recipient : The address 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 token uint256 to be swapped.

  • amountOutMinimum : The minimum acceptable amount of the output token uint256 specified to prevent infinite slippage.

ExactOutputParams

struct ExactOutputParams {
    bytes path;
    address recipient;
    uint256 deadline;
    uint256 amountOut;
    uint256 amountInMaximum;
}
  • path : A bytes string representing the path of tokens to swap (reversed).

  • recipient : The address 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 token uint256 desired.

  • amountInMaximum : The maximum acceptable amount of the input token uint256 required.

Functions

factory()

Returns the address of the factory.

function factory() external view returns (IFactory);
  • Returns :

    • IFactory : The address of the Factory

position()

Returns the address of the Position NFT.

function position() external view returns (IPosition);
  • Returns

    • IPosition : The position NFT address

exactInput()

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 as ExactInputParams in calldata

  • Returns :

    • amountOut : The amount of the received token in uint256

exactOutput()

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 as ExactOutputParams in calldata

  • Returns :

    • amountIn : The amount of the input token in uint256

getOrCreatePoolAndAddLiquidity()

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 with poolParams

    • tokenId : NFT ID of the token uint256 that will hold LP balance. Use 0 to mint a new token

    • addParams : Parameters of liquidity addition with addParams

    • minTokenAAmount : Minimum amount of token A uint256 to add. Reverts if not met

    • minTokenBAmount : Minimum amount of token B uint256 to add. Reverts if not met

    • deadline : Epoch timestamp (in seconds) uint256

  • Returns :

    • receivingTokenId : The ID uint256 of the receiving token

    • tokenAAmount : The amount of token A uint256

    • tokenBAmount : The amount of token B uint256

    • binDeltas : An array of BinDelta structures

addLiquidityToPool()

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 to IPool

    • tokenId : NFT ID of the token uint256 that will hold LP balance. Use 0 to mint a new token

    • params : Parameters of liquidity addition with params

    • minTokenAAmount : Minimum amount of token A uint256 to add. Reverts if not met

    • minTokenBAmount : Minimum amount of token B uint256 to add. Reverts if not met

    • deadline : Epoch timestamp (in seconds) uint256

  • Returns :

    • receivingTokenId : The ID of the receiving token uint256

    • tokenAAmount : The amount of token A uint256

    • tokenBAmount : The amount of token B uint256

    • binDeltas : An array of BinDelta structures

addLiquidityWTickLimits()

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 to IPool

    • tokenId : NFT ID of the token uint256 that will hold LP balance. Use 0 to mint a new token

    • params : Parameters of liquidity addition with params

    • minTokenAAmount : Minimum amount of token A uint256 to add. Reverts if not met

    • minTokenBAmount : Minimum amount of token B uint256 to add. Reverts if not met

    • minActiveTick : Lowest activeTick int32 (inclusive) of the pool that will permit the transaction to pass

    • maxActiveTick : Highest activeTick int32 (inclusive) of the pool that will permit the transaction to pass

    • deadline : Epoch timestamp (in seconds)

  • Returns :

    • receivingTokenId : The ID of the receiving token uint256

    • tokenAAmount : The amount of token A uint256

    • tokenBAmount : The amount of token B uint256

    • binDeltas : An array of BinDelta structures

migrateBinsUpStack()

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 with IPool

    • binIds : Array of binIds to migrate

    • maxRecursion : Maximum recursion depth uint32 before returning; 0 means no maximum

    • deadline : Epoch timestamp (in seconds) uint256

removeLiquidity()

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 with IPool

    • recipient : address where the proceeds are sent. Use zero or router address to leave tokens in the router

    • tokenId : ID uint256 of the position NFT that holds liquidity

    • params : Parameters of liquidity removal with params

    • minTokenAAmount : Minimum amount of token A uint256 to receive. Reverts if not met

    • minTokenBAmount : Minimum amount of token B uint256 to receive. Reverts if not met

    • deadline : Epoch timestamp (in seconds) uint256

  • Returns :

    • tokenAAmount : The amount of token A uint256 received

    • tokenBAmount : The amount of token B uint256 received

    • binDeltas : An array of BinDelta structure

Ethereum:

ZKSync Era:

Code:

0xbBF1EE38152E9D8e3470Dc47947eAa65DcA94913
0x39E098A153Ad69834a9Dac32f0FCa92066aD03f4
Github
Contract Details
Structs
ExactInputParams
ExactOutputParams
PoolParams
Functions
factory()
position()
exactInput()
exactOutput()
getOrCreatePoolAndAddLiquidity()
addLiquidityToPool()
addLiquidityWTickLimits()
migrateBinsUpStack()
removeLiquidity()