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
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.
function addLiquidity(address recipient, uint256 subaccount, AddLiquidityParams calldata params, bytes calldata data)
external
returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds);
Parameters
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
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.
function removeLiquidity(address recipient, uint256 subaccount, RemoveLiquidityParams calldata params)
external
returns (uint256 tokenAOut, uint256 tokenBOut);
Parameters
recipient
address
The address to receive the tokens.
subaccount
uint256
The subaccount for the recipient.
params
RemoveLiquidityParams
The parameters for removing liquidity.
Returns
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.
function migrateBinUpStack(uint32 binId, uint32 maxRecursion) external;
Parameters
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.
function swap(address recipient, SwapParams memory params, bytes calldata data)
external
returns (uint256 amountIn, uint256 amountOut);
Parameters
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).
function flashLoan(address recipient, uint256 amountA, uint256 amountB, bytes calldata data)
external
returns (uint128 lendingFeeA, uint128 lendingFeeB);
Parameters
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.
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
currentReserveA
uint256
Current reserve of token A.
currentReserveB
uint256
Current reserve of token B.
currentLiquidity
uint256
Current liquidity amount.
BinState
Bin state parameters.
struct BinState {
uint128 mergeBinBalance;
uint128 tickBalance;
uint128 totalSupply;
uint8 kind;
int32 tick;
uint32 mergeId;
}
Properties
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.
struct SwapParams {
uint256 amount;
bool tokenAIn;
bool exactOutput;
int32 tickLimit;
}
Properties
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.
struct AddLiquidityParams {
uint8 kind;
int32[] ticks;
uint128[] amounts;
}
Properties
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.
struct RemoveLiquidityParams {
uint32[] binIds;
uint128[] amounts;
}
Properties
binIds
uint32[]
Index array of the bins losing liquidity.
amounts
uint128[]
Array of bin LP amounts to remove.
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
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.
struct BinDelta {
uint128 deltaA;
uint128 deltaB;
}
Last updated