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.

tokenB

Pool tokenB.

factory

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

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.

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.

binIdByTickKind

ID of bin at input tick position and kind.

protocolFeeA

Accumulated tokenA protocol fee.

protocolFeeB

Accumulated tokenB protocol fee.

lendingFeeRateD18

Lending fee rate on flash loans.

getCurrentTwa

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

getState

External function to get the state of the pool.

getBin

Return state of Bin at input binId.

getTick

Return state of Tick at input tick position.

balanceOf

Retrieves the balance of a user within a bin.

Parameters

Name
Type
Description

user

address

The user's address.

subaccount

uint256

The subaccount for the user.

binId

uint32

The ID of the bin.

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.

Parameters

Name
Type
Description

recipient

address

The account that will receive credit for the added liquidity.

subaccount

uint256

The account that will receive credit for the added liquidity.

params

AddLiquidityParams

Parameters containing the details for adding liquidity, such as token types and amounts.

data

bytes

Bytes information that gets passed to the callback.

Returns

Name
Type
Description

tokenAAmount

uint256

The amount of token A added to the pool.

tokenBAmount

uint256

The amount of token B added to the pool.

binIds

uint32[]

An array of bin IDs where the liquidity is stored.

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.

Parameters

Name
Type
Description

recipient

address

The address to receive the tokens.

subaccount

uint256

The subaccount for the recipient.

params

RemoveLiquidityParams

The parameters for removing liquidity.

Returns

Name
Type
Description

tokenAOut

uint256

The amount of token A received.

tokenBOut

uint256

The amount of token B received.

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.

Parameters

Name
Type
Description

binId

uint32

The ID of the bin to migrate.

maxRecursion

uint32

The maximum recursion depth for the migration.

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.

Parameters

Name
Type
Description

recipient

address

The address to receive the output tokens.

params

SwapParams

Parameters containing the details of the swap

data

bytes

Bytes information that gets passed to the callback.

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).

Parameters

Name
Type
Description

recipient

address

The address to receive the loaned tokens.

amountA

uint256

amountB

uint256

Loan amount of tokenA sent to recipient.

data

bytes

Bytes information that gets passed to the callback.

setFee

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

Events

PoolSwap

PoolAddLiquidity

PoolMigrateBinsUpStack

PoolRemoveLiquidity

PoolSetVariableFee

Errors

PoolZeroLiquidityAdded

PoolMinimumLiquidityNotMet

PoolLocked

PoolInvalidInput

PoolInsufficientBalance

PoolReservesExceedMaximum

PoolValueExceedsBits

PoolTickMaxExceeded

PoolMigrateBinFirst

PoolCurrentTickBeyondSwapLimit

PoolSenderNotAccessor

PoolSenderNotFactory

PoolFunctionNotImplemented

PoolTokenNotSolvent

Structs

TickState

Tick state parameters.

TickData

Tick data parameters.

Properties

Name
Type
Description

currentReserveA

uint256

Current reserve of token A.

currentReserveB

uint256

Current reserve of token B.

currentLiquidity

uint256

Current liquidity amount.

BinState

Bin state parameters.

Properties

Name
Type
Description

mergeBinBalance

uint128

LP token balance that this bin possesses of the merge bin.

tickBalance

uint128

Balance of the tick.

totalSupply

uint128

Total amount of LP tokens in this bin.

kind

uint8

One of the 4 kinds (0=static, 1=right, 2=left, 3=both).

tick

int32

The lower price tick of the bin in its current state.

mergeId

uint32

Bin ID of the bin that this bin has merged into.

SwapParams

Parameters for swap.

Properties

Name
Type
Description

amount

uint256

Amount of the token that is either the input if exactOutput is false or the output if exactOutput is true.

tokenAIn

bool

Boolean indicating whether tokenA is the input.

exactOutput

bool

Boolean indicating whether the amount specified is the exact output amount (true).

tickLimit

int32

The furthest tick a swap will execute in. If no limit is desired, value should be set to type(int32).max for a tokenAIn swap and type(int32).min for a swap where tokenB is the input.

AddLiquidityParams

Parameters associated with adding liquidity.

Properties

Name
Type
Description

kind

uint8

One of the 4 kinds (0=static, 1=right, 2=left, 3=both).

ticks

int32[]

Array of ticks to add liquidity to.

amounts

uint128[]

Array of bin LP amounts to add.

RemoveLiquidityParams

Parameters for each bin that will have liquidity removed.

Properties

Name
Type
Description

binIds

uint32[]

Index array of the bins losing liquidity.

amounts

uint128[]

Array of bin LP amounts to remove.

State

State of the pool.

Properties

Name
Type
Description

reserveA

uint128

Pool tokenA balanceOf at end of last operation

reserveB

uint128

Pool tokenB balanceOf at end of last operation

lastTwaD8

int64

Value of log time weighted average price at last block. Value is 8-decimal scale and is in the fractional tick domain. E.g. a value of 12.3e8 indicates the TWAP was 3/10ths of the way into the 12th tick.

lastLogPriceD8

int64

Value of log price at last block. Value is 8-decimal scale and is in the fractional tick domain. E.g. a value of 12.3e8 indicates the price was 3/10ths of the way into the 12th tick.

lastTimestamp

uint40

Last block.timestamp value in seconds for latest swap transaction.

activeTick

int32

Current tick position that contains the active bins.

isLocked

bool

Pool isLocked, E.g., locked or unlocked; isLocked values defined in Pool.sol.

binCounter

uint32

Index of the last bin created.

protocolFeeRatioD3

uint8

Ratio of the swap fee that is kept for the protocol.

BinDelta

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

Last updated