IMaverickV2Pool

Functions

kinds

1-15 number to represent the active kinds. 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both; E.g. a pool with all 4 modes will have kinds = b1111 = 15

function kinds() external view returns (uint8);

fee

Pool swap fee for the given direction (A-in or B-in swap) in 18-decimal format. E.g. 0.01e18 is a 1% swap fee.

function fee(bool tokenAIn) external view returns (uint256);

tickSpacing

TickSpacing of pool where 1.0001^tickSpacing is the bin width.

function tickSpacing() external view returns (uint256);

lookback

Lookback period of pool in seconds.

function lookback() external view returns (uint256);

accessor

Address of Pool accessor. This is Zero address for permissionless pools.

function accessor() external view returns (address);

tokenA

Pool tokenA. Address of tokenA is such that tokenA < tokenB.

function tokenA() external view returns (IERC20);

tokenB

Pool tokenB.

function tokenB() external view returns (IERC20);

factory

Deploying factory of the pool and also contract that has ability to set and collect protocol fees for the pool.

function factory() external view returns (IMaverickV2Factory);

tokenAScale

Most significant bit of scale value is a flag to indicate whether tokenA has more or less than 18 decimals. Scale is used in conjuction with Math.toScale/Math.fromScale functions to convert from token amounts to D18 scale internal pool accounting.

function tokenAScale() external view returns (uint256);

tokenBScale

Most significant bit of scale value is a flag to indicate whether tokenA has more or less than 18 decimals. Scale is used in conjuction with Math.toScale/Math.fromScale functions to convert from token amounts to D18 scale internal pool accounting.

function tokenBScale() external view returns (uint256);

binIdByTickKind

ID of bin at input tick position and kind.

function binIdByTickKind(int32 tick, uint256 kind) external view returns (uint32);

protocolFeeA

Accumulated tokenA protocol fee.

function protocolFeeA() external view returns (uint128);

protocolFeeB

Accumulated tokenB protocol fee.

function protocolFeeB() external view returns (uint128);

lendingFeeRateD18

Lending fee rate on flash loans.

function lendingFeeRateD18() external view returns (uint256);

getCurrentTwa

External function to get the current time-weighted average price.

function getCurrentTwa() external view returns (int256);

getState

External function to get the state of the pool.

function getState() external view returns (State memory);

getBin

Return state of Bin at input binId.

function getBin(uint32 binId) external view returns (BinState memory bin);

getTick

Return state of Tick at input tick position.

function getTick(int32 tick) external view returns (TickState memory tickState);

balanceOf

Retrieves the balance of a user within a bin.

function balanceOf(address user, uint256 subaccount, uint32 binId) external view returns (uint128 lpToken);

Parameters

addLiquidity

Add liquidity to a pool. This function allows users to deposit tokens into a liquidity pool.

This function will call maverickV2AddLiquidityCallback on the calling contract to collect the tokenA/tokenB payment.

function addLiquidity(address recipient, uint256 subaccount, AddLiquidityParams calldata params, bytes calldata data)
    external
    returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds);

Parameters

Returns

removeLiquidity

Removes liquidity from the pool.

Liquidity can only be removed from a bin that is either unmerged or has a mergeId of an unmerged bin. If a bin is merged more than one level deep, it must be migrated up the merge stack to the root bin before liquidity removal.

function removeLiquidity(address recipient, uint256 subaccount, RemoveLiquidityParams calldata params)
    external
    returns (uint256 tokenAOut, uint256 tokenBOut);

Parameters

Returns

migrateBinUpStack

Migrate bins up the linked list of merged bins so that its mergeId is the currrent active bin.

Liquidity can only be removed from a bin that is either unmerged or has a mergeId of an unmerged bin. If a bin is merged more than one level deep, it must be migrated up the merge stack to the root bin before liquidity removal.

function migrateBinUpStack(uint32 binId, uint32 maxRecursion) external;

Parameters

swap

Swap tokenA/tokenB assets in the pool. The swap user has two options for funding their swap.

  • The user can push the input token amount to the pool before calling the swap function. In order to avoid having the pool call the callback, the user should pass a zero-length data bytes object with the swap call.

  • The user can send the input token amount to the pool when the pool calls the maverickV2SwapCallback function on the calling contract. That callback has input parameters that specify the token address of the input token, the input and output amounts, and the bytes data sent to the swap function.

If the users elects to do a callback-based swap, the output assets will be sent before the callback is called, allowing the user to execute flash swaps. However, the pool does have reentrancy protection, so a swapper will not be able to interact with the same pool again while they are in the callback function.

function swap(address recipient, SwapParams memory params, bytes calldata data)
    external
    returns (uint256 amountIn, uint256 amountOut);

Parameters

flashLoan

Loan tokenA/tokenB assets from the pool to recipient. The fee rate of a loan is determined by lendingFeeRateD18, which is set at the protocol level by the factory. This function calls maverickV2FlashLoanCallback on the calling contract. At the end of the callback, the caller must pay back the loan with fee (if there is a fee).

function flashLoan(address recipient, uint256 amountA, uint256 amountB, bytes calldata data)
    external
    returns (uint128 lendingFeeA, uint128 lendingFeeB);

Parameters

setFee

Sets fee for permissioned pools. May only be called by the accessor.

function setFee(uint256 newFeeAIn, uint256 newFeeBIn) external;

Events

PoolSwap

event PoolSwap(address sender, address recipient, SwapParams params, uint256 amountIn, uint256 amountOut);

PoolAddLiquidity

event PoolAddLiquidity(
    address sender,
    address recipient,
    uint256 subaccount,
    AddLiquidityParams params,
    uint256 tokenAAmount,
    uint256 tokenBAmount,
    uint32[] binIds
);

PoolMigrateBinsUpStack

event PoolMigrateBinsUpStack(address sender, uint32 binId, uint32 maxRecursion);

PoolRemoveLiquidity

event PoolRemoveLiquidity(
    address sender,
    address recipient,
    uint256 subaccount,
    RemoveLiquidityParams params,
    uint256 tokenAOut,
    uint256 tokenBOut
);

PoolSetVariableFee

event PoolSetVariableFee(uint256 newFeeAIn, uint256 newFeeBIn);

Errors

PoolZeroLiquidityAdded

error PoolZeroLiquidityAdded();

PoolMinimumLiquidityNotMet

error PoolMinimumLiquidityNotMet();

PoolLocked

error PoolLocked();

PoolInvalidInput

error PoolInvalidInput();

PoolInsufficientBalance

error PoolInsufficientBalance(uint256 deltaLpAmount, uint256 accountBalance);

PoolReservesExceedMaximum

error PoolReservesExceedMaximum(uint256 amount);

PoolValueExceedsBits

error PoolValueExceedsBits(uint256 amount, uint256 bits);

PoolTickMaxExceeded

error PoolTickMaxExceeded(uint256 tick);

PoolMigrateBinFirst

error PoolMigrateBinFirst();

PoolCurrentTickBeyondSwapLimit

error PoolCurrentTickBeyondSwapLimit(int32 startingTick);

PoolSenderNotAccessor

error PoolSenderNotAccessor(address sender_, address accessor);

PoolSenderNotFactory

error PoolSenderNotFactory(address sender_, address accessor);

PoolFunctionNotImplemented

error PoolFunctionNotImplemented();

PoolTokenNotSolvent

error PoolTokenNotSolvent(uint256 internalReserve, uint256 tokenBalance, IERC20 token);

Structs

TickState

Tick state parameters.

struct TickState {
    uint128 reserveA;
    uint128 reserveB;
    uint128 totalSupply;
    uint32[4] binIdsByTick;
}

TickData

Tick data parameters.

struct TickData {
    uint256 currentReserveA;
    uint256 currentReserveB;
    uint256 currentLiquidity;
}

Properties

BinState

Bin state parameters.

struct BinState {
    uint128 mergeBinBalance;
    uint128 tickBalance;
    uint128 totalSupply;
    uint8 kind;
    int32 tick;
    uint32 mergeId;
}

Properties

SwapParams

Parameters for swap.

struct SwapParams {
    uint256 amount;
    bool tokenAIn;
    bool exactOutput;
    int32 tickLimit;
}

Properties

AddLiquidityParams

Parameters associated with adding liquidity.

struct AddLiquidityParams {
    uint8 kind;
    int32[] ticks;
    uint128[] amounts;
}

Properties

RemoveLiquidityParams

Parameters for each bin that will have liquidity removed.

struct RemoveLiquidityParams {
    uint32[] binIds;
    uint128[] amounts;
}

Properties

State

State of the pool.

struct State {
    uint128 reserveA;
    uint128 reserveB;
    int64 lastTwaD8;
    int64 lastLogPriceD8;
    uint40 lastTimestamp;
    int32 activeTick;
    bool isLocked;
    uint32 binCounter;
    uint8 protocolFeeRatioD3;
}

Properties

BinDelta

Internal data used for data passing between Pool and Bin code.

struct BinDelta {
    uint128 deltaA;
    uint128 deltaB;
}

Last updated