UniswapV3PoolUpgradeable
UniswapV3PoolUpgradeable.sol
NFTX AMM pool contract. Uses BeaconProxy for deployments.
Table of Contents
Variables
factory
Address of the NFTX AMM's UniswapV3FactoryUpgradeable
contract.
token0
Address of "token0" (either WETH or vToken).
token1
Address of "token1" (either WETH or vToken).
fee
AMM swap fee tier.
tickSpacing
Tick spacing of the pool.
maxLiquidityPerTick
Maximum liquidity amount per tick.
slot0
Pool data.
feeGrowthGlobal0X128
Represents the accumulated fees of token0 that have been earned per unit of liquidity since the contract was deployed, stored as a fixed-point number.
feeGrowthGlobal1X128
Represents the accumulated fees of token1 that have been earned per unit of liquidity since the contract was deployed, stored as a fixed-point number.
protocolFees
Accumulated fees owed to the protocol (for example, to the governance treasury).
liquidity
The total liquidity that's currently active in the pool.
ticks
Tick data.
tickBitmap
A mapping that represents a sub-interval of ticks to help with gas-efficient calculations related to liquidity.
positions
A mapping that keeps track of individual liquidity provider positions. The key to this mapping is a bytes32 value derived from the liquidity provider's address and the tick range in which they've provided liquidity.
observations
An array used for calculating the time-weighted average price (TWAP).
Events
Initialize
Emitted by initialize()
.
Mint
Emitted by mint()
.
Collect
Emitted by collect()
.
Burn
Emitted by burn()
.
Swap
Emitted by swap()
.
Flash
Emitted by flash()
.
IncreaseObservationCardinalityNext
Emitted by increaseObservationCardinalityNext()
.
SetFeeProtocol
Emitted by setProtocolFee()
.
CollectProtocol
Emitted by collectProtocol()
.
Write Functions
increaseObservationCardinalityNext
Used to schedule an increase in the maximum number of observations that the pool can store. Observations are utilized in the AMM pool for computing TWAPs. By invoking this function, the caller is expressing the intent to expand the observation capacity in the future. The actual expansion of capacity takes effect the next time the pool undergoes significant interaction, like when liquidity is added or when a swap occurs that moves the price.
initialize
Used to set the initial price of the pool when it's first created. This function can only be called once for a pool, when it's transitioning from an uninitialized to an initialized state. Typically called by the AMM pool factory contract during the creation of a new pool.
mint
Adds liquidity to a specific price range within the AMM pool.
collect
Allows liquidity providers to retrieve tokens owed from one or both of the two following scenarios:
To remove accumulated fees from their specified liquidity range.
To retrieve tokens from liquidity that has previously been removed from the position.
The function can be used to collect either or both of the pool tokens, up to amounts specified by the caller.
burn
Allows liquidity providers to remove, or "burn," a specified amount of liquidity from a particular price range in the pool. After burning liquidity, the underlying tokens aren't immediately returned to the caller. Instead, the tokens can be later collected using the collect
function
swap
Swaps one token for another, taking slippage, price limits, and other factors into account.
distributeRewards
Distributes the received vault fees among the current LPs, proportional to their liquidity contribution. Can only be called by feeDistributor, after it sends the reward tokens to this pool.
flash
Executes a flash swap within the AMM pool. Allows a smart contract to borrow tokens from the pool, execute specific logic, and then either repay the borrowed amount with fees or provide equivalent value in the other token—all within a single transaction.
Owner Functions
setFeeProtocol
Allows the factory owner to set or update the fee protocol values for the pool. This function doesn't directly set the protocol fee rate (i.e., the fraction of LP fees that become protocol fees—which is set on the SwapRouter). Instead, it sets how these collected protocol fees are allocated. This function can be seen as a way to change the internal allocation mechanism or beneficiaries without affecting the global setting at the factory level.
collectProtocol
Collects protocol fees that have accrued in the pool. Protocol fees are distinct from the fees accrued by individual liquidity providers; they're set at the protocol level and typically go to a treasury or another protocol-specific address.
Read Functions
snapshotCumulativesInside
Provides a snapshot of the cumulative tick and liquidity values inside a specific tick range. It's designed to give insights and facilitate calculations related to accrued fees and other operations for positions within that range.
observe
Retrieves historical data on the pool's tick and liquidity based on a set of specified past timestamps. It's designed to facilitate off-chain computations, particularly for time-weighted averages and other time-dependent metrics.
Last updated