Pool
This documentation covers functionality of v3 pool.
#
Code[AlgebraPool.sol
]
#
AddressSee Pool Addresses.
#
Events#
InitializeEmitted exactly once by a pool when #initialize is first called on the pool. Mint/Burn/Swap cannot be emitted by the pool before Initialize
Params
price
The initial sqrt price of the pool, as a Q64.96tick
The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
#
MintEmitted when liquidity is minted for a given position
Params
sender
The address that minted the liquidityowner
The owner of the position and recipient of any minted liquiditybottomTick
The lower tick of the positiontopTick
The upper tick of the positionliquidityAmount
The amount of liquidity minted to the position rangeamount0
How much token0 was required for the minted liquidityamount1
How much token1 was required for the minted liquidity
#
CollectEmitted when fees are collected by the owner of a position. Collect
events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
Params
owner
The owner of the position for which fees are collectedrecipient
The address that received feesbottomTick
The lower tick of the positiontopTick
The upper tick of the positionamount0
The amount of token0 fees collectedamount1
The amount of token1 fees collected
#
BurnEmitted when a position's liquidity is removed. Does not withdraw any fees earned by the liquidity position, which must be withdrawn via collect
Params
owner
The owner of the position for which liquidity is removedbottomTick
The lower tick of the positiontopTick
The upper tick of the positionliquidityAmount
The amount of liquidity to removeamount0
The amount of token0 withdrawnamount1
The amount of token1 withdrawn
#
SwapEmitted by the pool for any swaps between token0 and token1
Params
sender
The address that initiated the swap call, and that received the callbackrecipient
The address that received the output of the swapamount0
The delta of the token0 balance of the poolamount1
The delta of the token1 balance of the poolprice
The sqrt(price) of the pool after the swap, as a Q64.96liquidity
The liquidity of the pool after the swaptick
The log base 1.0001 of price of the pool after the swap
#
FlashEmitted by the pool for any flashes of token0/token1
Params
sender
The address that initiated the swap call, and that received the callbackrecipient
The address that received the tokens from flashamount0
The amount of token0 that was flashedamount1
The amount of token1 that was flashedpaid0
The amount of token0 paid for the flash, which can exceed the amount0 plus the feepaid1
The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
#
CommunityFeeEmitted when the community fee is changed by the pool
Params
communityFee0New
The updated value of the token0 community fee percentcommunityFee1New
The updated value of the token1 community fee percent
#
IncentiveEmitted when new activeIncentive is set
Params
virtualPoolAddress
The address of a virtual pool associated with the current active incentive
#
FeeParams
fee
The value of the token fee
#
LiquidityCooldownParams
liquidityCooldown
The value of locktime for added liquidity
#
Read-Only Functions#
dataStorageOperatorThe contract that stores all the timepoints and can perform actions with them Returns the operator address
#
factoryThe contract that deployed the pool, which must adhere to the IAlgebraFactory interface Returns the contract address
#
token0The first of the two tokens of the pool, sorted by address Returns the token contract address
#
token1The second of the two tokens of the pool, sorted by address Returns the token contract address
#
tickSpacingThe pool tick spacing. Ticks can only be used at multiples of this value. e.g.: a tickSpacing of 60 means ticks can be initialized every 60th tick, i.e., ..., -120, -60, 0, 60, 120, ... This value is an int24 to avoid casting even though it is always positive. Returns the tick spacing
#
maxLiquidityPerTickThe maximum amount of position liquidity that can use any tick in the range. This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool. Returns the max amount of liquidity per tick
#
globalStateThe globalState structure in the pool stores many values but requires only one slot and is exposed as a single method to save gas when accessed externally.
Returns
price
The current price of the pool as a sqrt(token1/token0) Q64.96 valuetick
The current tick of the pool, i.e. according to the last tick transition that was run. Returns This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(price) if the price is on a tick boundaryfee
The last pool fee value in hundredths of a bip, i.e. 1e-6timepointIndex
The index of the last written timepointcommunityFeeToken0
The community fee percentage of the swap fee in thousandths (1e-3) for token0communityFeeToken1
The community fee percentage of the swap fee in thousandths (1e-3) for token1unlocked
Whether the pool is currently locked to reentrancy
#
totalFeeGrowth0TokenThe fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool. This value can overflow the uint256
#
totalFeeGrowth1TokenThe fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool. This value can overflow the uint256
#
liquidityThe currently in range liquidity available to the pool. This value has no relationship to the total liquidity across all ticks. Returned value cannot exceed type(uint128).max
#
ticksLook up information about a specific tick in the pool. This is a public structure, so the return
natspec tags are omitted.
Params
tick
The tick to look up
Return
liquidityTotal
the total amount of position liquidity that uses the pool either as tick lower or tick upperliquidityDelta
how much liquidity changes when the pool price crosses the tickouterFeeGrowth0Token
the fee growth on the other side of the tick from the current tick in token0outerFeeGrowth1Token
the fee growth on the other side of the tick from the current tick in token1outerTickCumulative
the cumulative tick value on the other side of the tick from the current tickouterSecondsPerLiquidity
the seconds spent per liquidity on the other side of the tick from the current tickouterSecondsSpent
the seconds spent on the other side of the tick from the current tickinitialized
Set to true if the tick is initialized, i.e. liquidityTotal is greater than 0 otherwise equal to false. Outside values can only be used if the tick is initialized In addition, these values are only relative and must be used only in comparison to previous snapshots for a specific position.
#
tickTableReturns 256 packed tick initialized boolean values. See [TickTable
] for more information
#
positionsReturns the information about a position by the position's key. This is a public mapping of structures, so the return
natspec tags are omitted.
Params
key
The position's key is a hash of a preimage composed by the owner, bottomTick and topTick
Return
liquidityAmount
The amount of liquidity in the positionlastLiquidityAddTimestamp
Timestamp of last adding of liquidityinnerFeeGrowth0Token
Fee growth of token0 inside the tick range as of the last mint/burn/pokeinnerFeeGrowth1Token
Fee growth of token1 inside the tick range as of the last mint/burn/pokefees0
The computed amount of token0 owed to the position as of the last mint/burn/pokefees1
The computed amount of token1 owed to the position as of the last mint/burn/poke
#
timepointsReturns data about a specific timepoint index. You most likely want to use getTimepoints() instead of this method to get an timepoint as of some amount of time ago, rather than at a specific index in the array. This is a public mapping of structures, so the return
natspec tags are omitted.
Params
index
The element of the timepoints array to fetch
Return
initialized
whether the timepoint has been initialized and the values are safe to useblockTimestamp
The timestamp of the timepointtickCumulative
the tick multiplied by seconds elapsed for the life of the pool as of the timepoint timestampsecondsPerLiquidityCumulative
the seconds per in range liquidity for the life of the pool as of the timepoint timestampvolatilityCumulative
Cumulative standard deviation for the life of the pool as of the timepoint timestampaverageTick
Time-weighted average tickvolumePerLiquidityCumulative
Cumulative swap volume per liquidity for the life of the pool as of the timepoint timestamp
#
activeIncentiveReturns the information about active incentive. If there is no active incentive at the moment, virtualPool,endTimestamp,startTimestamp would be equal to 0.
Return
virtualPool
The address of a virtual pool associated with the current active incentive
#
liquidityCooldownReturns the lock time for added liquidity.
#
getTimepointsReturns the cumulative tick and liquidity as of each timestamp secondsAgo
from the current block timestamp. To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, you must call it with secondsAgos = [3600, 0]. The time weighted average tick represents the geometric time weighted average price of the pool, in log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
Params
secondsAgos
From how long ago each cumulative tick and liquidity value should be returned
Return
tickCumulatives
Cumulative tick values as of eachsecondsAgos
from the current block timestampsecondsPerLiquidityCumulatives
Cumulative seconds per liquidity-in-range value as of eachsecondsAgos
from the current block timestampvolatilityCumulatives
Cumulative standard deviation as of eachsecondsAgos
volumePerAvgLiquiditys
Cumulative swap volume per liquidity as of eachsecondsAgos
#
getInnerCumulativesReturns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range. Snapshots must only be compared to other snapshots, taken over a period for which a position existed. I.e., snapshots cannot be compared if a position is not held for the entire period between when the first snapshot is taken and the second snapshot is taken.
Params
bottomTick
The lower tick of the rangetopTick
The upper tick of the range
Return
innerTickCumulative
The snapshot of the tick accumulator for the rangeinnerSecondsSpentPerLiquidity
The snapshot of seconds per liquidity for the rangeinnerSecondsSpent
The snapshot of the number of seconds during which the price was in this range
#
State-Changing Functions#
initializeSets the initial price for the pool. Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
Params
price
the initial sqrt price of the pool as a Q64.96
#
mintAdds liquidity for the given recipient/bottomTick/topTick position. The caller of this method receives a callback in the form of IAlgebraMintCallback# AlgebraMintCallback in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends on bottomTick, topTick, the amount of liquidity, and the current price.
Params
sender
The address which will receive potential surplus of paid tokensrecipient
The address for which the liquidity will be createdbottomTick
The lower tick of the position in which to add liquiditytopTick
The upper tick of the position in which to add liquidityamount
The desired amount of liquidity to mintdata
Any data that should be passed through to the callback
Return
amount0
The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callbackamount1
The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callbackliquidityActual
The actual minted amount of liquidity
#
collectCollects tokens owed to a position. Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
Params
recipient
The address which should receive the fees collectedbottomTick
The lower tick of the position for which to collect feestopTick
The upper tick of the position for which to collect feesamount0Requested
How much token0 should be withdrawn from the fees owedamount1Requested
How much token1 should be withdrawn from the fees owed
Return
amount0
The amount of fees collected in token0amount1
The amount of fees collected in token1
#
burnBurn liquidity from the sender and account tokens owed for the liquidity to the position. Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0. Fees must be collected separately via a call to collect
Params
bottomTick
The lower tick of the position for which to burn liquiditytopTick
The upper tick of the position for which to burn liquidityamount
How much liquidity to burn
Return
amount0
The amount of token0 sent to the recipientamount1
The amount of token1 sent to the recipient
#
swapSwap token0 for token1, or token1 for token0. The caller of this method receives a callback in the form of IAlgebraSwapCallback# AlgebraSwapCallback
Params
recipient
The address to receive the output of the swapzeroToOne
The direction of the swap, true for token0 to token1, false for token1 to token0amountSpecified
The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)limitSqrtPrice
The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swapdata
Any data to be passed through to the callback. If using the Router it should contain SwapRouter#SwapCallbackData
Return
amount0
The delta of the balance of token0 of the pool, exact when negative, minimum when positiveamount1
The delta of the balance of token1 of the pool, exact when negative, minimum when positive
#
swapSupportingFeeOnInputTokensSwap token0 for token1, or token1 for token0 (tokens that have fee on transfer). The caller of this method receives a callback in the form of IAlgebraSwapCallback# AlgebraSwapCallback
Params
sender
The address called this function (Comes from the Router)recipient
The address to receive the output of the swapzeroToOne
The direction of the swap, true for token0 to token1, false for token1 to token0amountSpecified
The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)limitSqrtPrice
The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swapdata
Any data to be passed through to the callback. If using the Router it should contain SwapRouter#SwapCallbackData
Return
amount0
The delta of the balance of token0 of the pool, exact when negative, minimum when positiveamount1
The delta of the balance of token1 of the pool, exact when negative, minimum when positive
#
flashReceive token0 and/or token1 and pay it back, plus a fee, in the callback. The caller of this method receives a callback in the form of IAlgebraFlashCallback# AlgebraFlashCallback. All excess tokens paid in the callback are distributed to liquidity providers as an additional fee. So this method can be used to donate underlying tokens to currently in-range liquidity providers by calling with 0 amount{0,1} and sending the donation amount(s) from the callback
Params
recipient
The address which will receive the token0 and token1 amountsamount0
The amount of token0 to sendamount1
The amount of token1 to senddata
Any data to be passed through to the callback
#
setCommunityFeeSet the community's % share of the fees. Cannot exceed 25% (250)
Params
communityFee0
new community fee percent for token0 of the pool in thousandths (1e-3)communityFee1
new community fee percent for token1 of the pool in thousandths (1e-3)
#
setIncentiveSets an active incentive
Params
virtualPoolAddress
The address of a virtual pool associated with the incentive
#
setLiquidityCooldownSets new lock time for added liquidity
Params
newLiquidityCooldown
The time in seconds