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
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.
tickSpacing
TickSpacing of pool where 1.0001^tickSpacing is the bin width.
lookback
Lookback period of pool in seconds.
accessor
Address of Pool accessor. This is Zero address for permissionless pools.
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 |
---|---|---|
|
| The user's address. |
|
| The subaccount for the user. |
|
| 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 |
---|---|---|
|
| The account that will receive credit for the added liquidity. |
|
| The account that will receive credit for the added liquidity. |
|
| Parameters containing the details for adding liquidity, such as token types and amounts. |
|
| Bytes information that gets passed to the callback. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of token A added to the pool. |
|
| The amount of token B added to the pool. |
|
| 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 |
---|---|---|
|
| The address to receive the tokens. |
|
| The subaccount for the recipient. |
|
| The parameters for removing liquidity. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of token A received. |
|
| 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 |
---|---|---|
|
| The ID of the bin to migrate. |
|
| 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 |
---|---|---|
|
| The address to receive the output tokens. |
|
| Parameters containing the details of the swap |
|
| 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 |
---|---|---|
|
| The address to receive the loaned tokens. |
|
| |
|
| Loan amount of tokenA sent to recipient. |
|
| 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 |
---|---|---|
|
| Current reserve of token A. |
|
| Current reserve of token B. |
|
| Current liquidity amount. |
BinState
Bin state parameters.
Properties
Name | Type | Description |
---|---|---|
|
| LP token balance that this bin possesses of the merge bin. |
|
| Balance of the tick. |
|
| Total amount of LP tokens in this bin. |
|
| One of the 4 kinds (0=static, 1=right, 2=left, 3=both). |
|
| The lower price tick of the bin in its current state. |
|
| Bin ID of the bin that this bin has merged into. |
SwapParams
Parameters for swap.
Properties
Name | Type | Description |
---|---|---|
|
| Amount of the token that is either the input if exactOutput is false or the output if exactOutput is true. |
|
| Boolean indicating whether tokenA is the input. |
|
| Boolean indicating whether the amount specified is the exact output amount (true). |
|
| 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 |
---|---|---|
|
| One of the 4 kinds (0=static, 1=right, 2=left, 3=both). |
|
| Array of ticks to add liquidity to. |
|
| Array of bin LP amounts to add. |
RemoveLiquidityParams
Parameters for each bin that will have liquidity removed.
Properties
Name | Type | Description |
---|---|---|
|
| Index array of the bins losing liquidity. |
|
| Array of bin LP amounts to remove. |
State
State of the pool.
Properties
Name | Type | Description |
---|---|---|
|
| Pool tokenA balanceOf at end of last operation |
|
| Pool tokenB balanceOf at end of last operation |
|
| 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. |
|
| 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. |
|
| Last block.timestamp value in seconds for latest swap transaction. |
|
| Current tick position that contains the active bins. |
|
| Pool isLocked, E.g., locked or unlocked; isLocked values defined in Pool.sol. |
|
| Index of the last bin created. |
|
| 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