Pool
This documentation provides an overview of the IPool.sol. This contract defines the functions and events for interacting with a liquidity pool in Maverick AMM.
Table of Contents
Contract Details
Name : IPool
Solidity Version : ^0.8.0
SPDX License-Identifier : GPL-2.0-or-later
Code: Github
Events
Swap
sender: Theaddressthat executed this swaprecipient: Theaddressreceiving this swaptokenAIn: Abooleanto determine if there is any input for Token AexactOutput: Abooleanto determine if there is any exact amount of tokens expected to receiveamountIn: Theuint256amount of the input tokenamountOut: Theuint256amount of the output tokenactiveTick: The active tickint32value for the pool
AddLiquidity
sender: The indexed senderaddressthat executedaddLiquidity()tokenId: Theuint256indexed ID of the receiving tokenbinDeltas: An array ofBinDeltastructures
MigrateBinsUpStack
sender: The indexed senderaddressthat executedMigrateBinsUpStack()binId: Theuint128bin ID that was migratedmaxRecursion: Maximum recursion depth inuint32
TransferLiquidity
fromTokenId: Transfer liquidity from token IDuint256toTokenId: Transfer liquidity to token IDuint256params: Array ofRemoveLiquidityParamsthat specify the bins and amounts
RemoveLiquidity
sender: Remove liquidity from senderaddressrecipient: Remove liquidity to receiveraddresstokenId: Current indexeduint256tokenId to remove liquidity frombinDeltas: Array ofBinDeltathat specify the bins and amounts
BinMerged
binId: The indexed bin IDuint128that was merged.reserveA: amount of A tokenuint128in bin.reserveB: amount of B tokenuint128in bin.mergeId: The current active binuint128.
BinMoved
binId: The indexed bin IDuint128that was moved.previousTick: Previous tick value inint128.newTick: New tick value inuint128.
ProtocolFeeCollected
protocolFee: Amount of Protocol fee collected inuint256.isTokenA:booleancheck if Token A was used for Protocol fee.
SetProtocolFeeRatio
protocolFee: The new amount of Protocol fee set inuint256.
Structs
BinDelta
Return parameters for Add/Remove liquidity.
deltaA: The amount of A tokenuint128that has been added or removeddeltaB: The amount of B tokenuint128that has been added or removeddeltaLpBalance: The amount of LP balanceuint256that has increase (add) or decreased (remove)binId: The bin IDuint128of the bin that changedkind: One of the 4 Kinds (0=static, 1=right, 2=left, 3=both) inuint8lowerTick: The lower price tickint32of the bin in its current stateisActive: Abooleanto indicate whether the bin is still active
TwaState
Time weighted average state.
twa: The twaint96at the last update instantvalue: The new valueint96that was passed in at the last updatelastTimestamp: The timestampuint64of the last update in seconds
BinState
The bin state parameters.
reserveA: The amount of A tokenuint128in binreserveB: The amount of B tokenuint128in binmergeBinBalance: The LP token balanceuint128that this bin possesses after mergemergeId: ThebinIdthat this binuint128has merged in tototalSupply: The total amount of LP tokensuint128in this binkind: one of the 4 Kinds (0=static, 1=right, 2=left, 3=both) inuint8lowerTick: The lower price tickint32of the bin in its current state
AddLiquidityParams
Parameters for each bin that will get new liquidity.
kind: one of the 4 Kinds (0=static, 1=right, 2=left, 3=both) inuint8pos: The bin position inint32isDelta: Abooleanthat indicates whether the bin position is relative to the current bin or an absolute positiondeltaA: The amount of A tokenuint128to adddeltaB: The amount of B tokenuint128to add
RemoveLiquidityParams
Parameters for each bin that will have liquidity removed.
binId: The index of the binuint128losing liquidityamount: The LP balance amountuint128to remove
State
The state of the pool.
activeTick: The current bin positionint32that contains the active binsstatus: The status valuesuint8defined inPool.sole.g. locked or unlocked;binCounter: The indexuint128of the last bin createdprotocolFeeRatio: The ratio of the swap fee that is kept for the protocol inuint64
Functions
fee()
Retrieves the fee for the pool in 18 decimal format.
Returns :
The fee
uint256for the pool as a uint256 value
tickSpacing()
Retrieves the tick spacing of the pool. The tick spacing is used to calculate the bin width.
Returns :
The tick spacing as a
uint256value
tokenA()
Retrieves the address of token A associated with the pool.
Returns :
The
addressof token A as an IERC20 interface
tokenB()
Retrieves the address of token B associated with the pool.
Returns :
The
addressof token B as an IERC20 interface
factory()
Retrieves the address of the factory contract associated with the pool.
Returns :
The
addressof the factory contract as anIFactoryinterface
binMap()
Retrieves the bitmap of active bins at the given tick.
Parameters :
tick : The tick
int32for which to retrieve the active bin map
Returns :
The bitmap of active bins as a
uint256value
binPositions()
Retrieves the bin ID for the given tick and bin kind
Parameters:
tick: The tickint32for which to retrieve the bin IDkind: The kinduint256of the bin (0=static, 1=right, 2=left, 3=both)
Returns:
The bin ID as a uint128 value
binBalanceA()
Retrieves the internal accounting of the sum of token A balances across bins.
Returns: The sum of token A balances as a
uint128value
binBalanceB()
Retrieves the internal accounting of the sum of token B balances across bins.
Returns:
The sum of token B balances as a
uint128value
getTwa()
Retrieves the time-weighted average (TWA) state values.
Returns:
A
TwaStatestructure containing the TWA, value, last timestamp, and look back
getCurrentTwa()
Retrieves the log base binWidth of the time-weighted average price.
Returns:
The log base binWidth of the TWA as an
int256value.
getState()
Retrieves the state of the pool.
Returns:
A
Statestructure containing the active tick, status, bin counter, and protocol fee ratio
addLiquidity()
Adds liquidity to a pool.
Parameters:
tokenId: The NFT token IDuint256that will hold the position.params: An array ofAddLiquidityParamsstructures that specify the mode, position, and liquidity details.data: A callback function thataddLiquiditywill call to transfer tokens.
Returns:
tokenAAmount: The amount of token A added as auint256value.tokenBAmount: The amount of token B added as auint256value.binDeltas: An array ofBinDeltastructures representing the changes in bin states.
transferLiquidity()
Transfers liquidity from one NFT token ID to another using an array of bins.
Parameters:
fromTokenId: The NFT token IDuint256that holds the position being transferred.toTokenId: The NFT token IDuint256that is receiving the liquidity.params: An array ofRemoveLiquidityParamsstructures specifying the bins and amounts to transfer.
removeLiquidity()
Removes liquidity from a pool.
Parameters:
recipient: Theaddressthat will receive the removed tokens.tokenId: The NFT token IDuint256that holds the position being removed.params: An array ofRemoveLiquidityParamsstructures specifying the bins and amounts to remove.
Returns:
tokenAOut: The amount of token Auin256received as a result of removing liquidity.tokenBOut: The amount of token Buin256received as a result of removing liquidity.binDeltas: An array ofBinDeltastructures representing the changes in bin states.
migrateBinUpStack()
Migrates bins up the linked list of merged bins so that its mergeId is the current active bin.
Parameters:
binId: An array of the bin IDsuint128to be migrated.maxRecursion: The maximum recursion depthuint32of the migration. Set tozeroto recurse until the active bin is found.
swap()
Swaps tokens.
Parameters:
recipient: Theaddressthat will receive the output tokens.amount: The amount of tokensuint256to swap.tokenAIn: Abooleanindicating whether token A is the input.exactOutput: Abooleanindicating whether the amount specified is the exact output amount (true).sqrtPriceLimit: The limiting square root priceuint256of the swap. A value of0indicates no limit. The limit is only engaged forexactOutput=false. If the limit is reached, only part of the input amount will be swapped, and the callback will only require that amount of the swap to be paid.data: A callback functionbytesthat swap will call to transfer tokens.
Returns:
amountIn: The amount of tokensuint256swapped as input.amountOut: The amount of tokensuint256received as output.
getBin()
Retrieves the bin information for a given bin ID.
Parameters:
binId: The index of the binuint128.
Returns:
A
BinStatestructure containing the details of the bin.
balanceOf()
Retrieves the LP token balance for a given tokenId at a specific binId.
Parameters:
tokenId: The NFT token IDuint256.binId: The index of the binuint128.
Returns:
The LP token balance as a
uint256value.
tokenAScale()
Retrieves the tokenA scale value.
msbis a flag to indicate whether tokenA has more or less than 18 decimals. Scale is used in conjuction withMath.toScale/Math.fromScalefunctions to convert from token amounts to D18 scale internal pool accounting.
Returns:
The tokenA scale value as a
uint256.
tokenBScale()
Retrieves the tokenB scale value.
msbis a flag to indicate whether tokenA has more or less than 18 decimals. Scale is used in conjuction withMath.toScale/Math.fromScalefunctions to convert from token amounts to D18 scale internal pool accounting.
Returns:
The tokenB scale value as a
uint256.
Last updated