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
  • State Variables
  • Functions
  • Errors
  • Structs
  1. Technical Reference
  2. Maverick V2
  3. V2 Contracts
  4. Maverick V2 Supplemental Contracts
  5. libraries

LiquidityUtilities

State Variables

MIN_DELTA_RESERVES

uint256 internal constant MIN_DELTA_RESERVES = 100;

Functions

priceIndexFromPriceBreaks

Return index into the price breaks array that corresponds to the current pool price.

Price break array is N elements [e_0, e_1, ..., e_{n-1}].

If price is less than e_0, then 0 is returned, if price is betweeen e_0 and e_1, then 1 is returned, etc. If the price is between e_{n-2} and e_{n-1}, then n-2 is returned. If price is larger than e_{n-1}, then n-1 is returned.

function priceIndexFromPriceBreaks(uint256 sqrtPrice, bytes memory packedSqrtPriceBreaks)
    internal
    pure
    returns (uint256 index);

tokenScales

function tokenScales(IMaverickV2Pool pool) internal view returns (uint256 tokenAScale, uint256 tokenBScale);

deltaReservesFromDeltaLpBalanceAtNewPrice

function deltaReservesFromDeltaLpBalanceAtNewPrice(
    IMaverickV2Pool pool,
    int32 tick,
    uint128 deltaLpBalance,
    uint8 kind,
    uint256 newSqrtPrice
) internal view returns (uint256 deltaA, uint256 deltaB);

deltaReservesFromDeltaLpBalancesAtNewPrice

function deltaReservesFromDeltaLpBalancesAtNewPrice(
    IMaverickV2Pool pool,
    IMaverickV2Pool.AddLiquidityParams memory addParams,
    uint256 newSqrtPrice
) internal view returns (IMaverickV2PoolLens.TickDeltas memory tickDeltas);

scaleAddParams

function scaleAddParams(
    IMaverickV2Pool.AddLiquidityParams memory addParams,
    uint128[] memory ratios,
    uint256 addAmount,
    uint256 targetAmount
) internal pure returns (IMaverickV2Pool.AddLiquidityParams memory addParamsScaled);

getScaledAddParams

function getScaledAddParams(
    IMaverickV2Pool pool,
    IMaverickV2Pool.AddLiquidityParams memory addParams,
    uint128[] memory ratios,
    uint256 newSqrtPrice,
    uint256 targetAmount,
    bool targetIsA
)
    internal
    view
    returns (
        IMaverickV2Pool.AddLiquidityParams memory addParamsScaled,
        IMaverickV2PoolLens.TickDeltas memory tickDeltas
    );

getAddLiquidityParamsFromRelativeBinLpBalance

function getAddLiquidityParamsFromRelativeBinLpBalance(
    IMaverickV2PoolLens.BoostedPositionSpecification memory spec,
    int32[] memory ticks,
    IMaverickV2PoolLens.AddParamsSpecification memory params
)
    internal
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );

getAddLiquidityParams

Compute add params for N price breaks around price with max right slippage of p * (1 + f) and max left slippage of p / (1 + f). The user specifies the max A and B they are willing to spend. If the price of the pool does not move, the user will spend exactly this amount. If the price moves left, then the user would like to spend the specified B amount, but will end up spending less A. Conversely, if the price moves right, the user will spend their max A amount, but less B. By having more break points, we make it so that the user gets as much liquidity as possible at the new price. With too few break points, the user will not have bought as much liquidity as they could have.

function getAddLiquidityParams(IMaverickV2PoolLens.AddParamsViewInputs memory params)
    internal
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );

deltaReservesFromDeltaLiquidity

function deltaReservesFromDeltaLiquidity(
    uint256 poolTickSpacing,
    uint256 tokenAScale,
    uint256 tokenBScale,
    int32 tick,
    uint128 deltaLiquidity,
    uint256 tickSqrtPrice
) internal pure returns (uint256 deltaA, uint256 deltaB);

deltasFromBinLiquidityAmounts

function deltasFromBinLiquidityAmounts(
    uint256 poolTickSpacing,
    uint256 tokenAScale,
    uint256 tokenBScale,
    int32[] memory ticks,
    uint128[] memory liquidityAmounts,
    uint256 newSqrtPrice
) internal pure returns (uint256 deltaA, uint256 deltaB, uint256[] memory deltaAs, uint256[] memory deltaBs);

_deltasFromRelativeBinLiquidityAmountsAndTargetAmount

function _deltasFromRelativeBinLiquidityAmountsAndTargetAmount(RelativeLiquidityInput memory input)
    internal
    pure
    returns (IMaverickV2PoolLens.TickDeltas memory output, bool success);

lpBalanceForArrayOfTargetAmountsEmptyPool

function lpBalanceForArrayOfTargetAmountsEmptyPool(
    IMaverickV2PoolLens.TickDeltas memory tickDeltas,
    RelativeLiquidityInput memory input,
    StateInfo memory existingState,
    uint8 kind
) internal pure returns (IMaverickV2Pool.AddLiquidityParams memory addParams);

lpBalanceForArrayOfTargetAmounts

function lpBalanceForArrayOfTargetAmounts(RelativeLiquidityInput memory input, IMaverickV2Pool pool, uint8 kind)
    internal
    view
    returns (
        IMaverickV2Pool.AddLiquidityParams memory addParams,
        IMaverickV2PoolLens.TickDeltas memory tickDeltas,
        bool success
    );

donateAndSwapData

function donateAndSwapData(
    uint256 poolTickSpacing,
    int32 poolTick,
    uint256 poolFee,
    IERC20 tokenB,
    uint256 targetAmountB,
    uint256 targetSqrtPrice
) internal view returns (uint128 deltaLpBalanceB, uint256 swapAmount);

getCreatePoolParams

function getCreatePoolParams(IMaverickV2PoolLens.CreateAndAddParamsViewInputs memory params, uint256 protocolFeeRatio)
    internal
    view
    returns (IMaverickV2PoolLens.CreateAndAddParamsInputs memory output);

emulateExactOut

function emulateExactOut(
    uint256 amountOut,
    uint256 currentReserveB,
    uint256 sqrtLowerTickPrice,
    uint256 sqrtUpperTickPrice,
    uint256 fee,
    uint256 protocolFee
) internal pure returns (uint256 amountAIn);

reservesInTickForGivenPrice

Calculates deltaA = liquidity * (sqrt(upper) - sqrt(lower)) Calculates deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper), i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))

function reservesInTickForGivenPrice(IMaverickV2Pool pool, int32 tick, uint256 newSqrtPrice)
    internal
    view
    returns (IMaverickV2Pool.TickState memory tickState, bool tickLtActive, bool tickGtActive);

lpBalanceRequiredForTargetReserveAmountsMultiBinTick

function lpBalanceRequiredForTargetReserveAmountsMultiBinTick(
    RelativeLiquidityInput memory input,
    IMaverickV2Pool pool,
    int32 tick,
    uint8 kind,
    uint256 amountAMax,
    uint256 amountBMax
) internal view returns (uint256 deltaLpBalance);

lpBalanceRequiredForTargetReserveAmountsOneBinTick

function lpBalanceRequiredForTargetReserveAmountsOneBinTick(
    RelativeLiquidityInput memory input,
    int32 tick,
    uint256 amountAMax,
    uint256 amountBMax,
    uint256 reserveA,
    uint256 reserveB,
    uint256 binTotalSupply,
    bool tickLtActive
) internal pure returns (uint256 deltaLpBalance);

emptyTickLpBalanceRequirement

function emptyTickLpBalanceRequirement(
    RelativeLiquidityInput memory input,
    int32 tick,
    uint256 amountAMax,
    uint256 amountBMax,
    bool tickLtActive
) internal pure returns (uint256 deltaLpBalance);

getBoostedPositionSpec

function getBoostedPositionSpec(IMaverickV2BoostedPosition boostedPosition)
    internal
    view
    returns (IMaverickV2PoolLens.BoostedPositionSpecification memory spec, int32[] memory ticks);

Errors

LiquidityUtilitiesTargetPriceOutOfBounds

error LiquidityUtilitiesTargetPriceOutOfBounds(
    uint256 targetSqrtPrice, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice
);

LiquidityUtilitiesTooLittleLiquidity

error LiquidityUtilitiesTooLittleLiquidity(uint256 relativeLiquidityAmount, uint256 deltaA, uint256 deltaB);

LiquidityUtilitiesTargetingTokenWithNoDelta

error LiquidityUtilitiesTargetingTokenWithNoDelta(bool targetIsA, uint256 deltaA, uint256 deltaB);

LiquidityUtilitiesNoSwapLiquidity

error LiquidityUtilitiesNoSwapLiquidity();

LiquidityUtilitiesFailedToFindDeltaAmounts

error LiquidityUtilitiesFailedToFindDeltaAmounts();

LiquidityUtilitiesInitialTargetBTooSmall

error LiquidityUtilitiesInitialTargetBTooSmall(uint256 initialTargetB, uint256 deltaLpBalance);

Structs

StateInfo

struct StateInfo {
    uint256 reserveA;
    uint256 reserveB;
    uint256 binTotalSupply;
    int32 activeTick;
}

RelativeLiquidityInput

struct RelativeLiquidityInput {
    uint256 poolTickSpacing;
    uint256 tokenAScale;
    uint256 tokenBScale;
    int32[] ticks;
    uint128[] relativeLiquidityAmounts;
    uint256 targetAmount;
    bool targetIsA;
    uint256 newSqrtPrice;
}

PreviousBytesLibNextPackLib

Last updated 1 year ago