UniswapV3PoolUpgradeable

UniswapV3PoolUpgradeable.sol

NFTX AMM pool contract. Uses BeaconProxy for deployments.

Table of Contents

Variables
Events
Public Write Functions
Owner Write Functions
Read Functions

Variables

factory

function factory() external view returns (address)

Address of the NFTX AMM's UniswapV3FactoryUpgradeable contract.

token0

function token0() external view returns (address)

Address of "token0" (either WETH or vToken).

token1

function token1() external view returns (address)

Address of "token1" (either WETH or vToken).

fee

function fee() external view returns (uint24)

AMM swap fee tier.

tickSpacing

function tickSpacing() external view returns (int24)

Tick spacing of the pool.

maxLiquidityPerTick

function maxLiquidityPerTick() external view returns (uint128)

Maximum liquidity amount per tick.

slot0

function slot0()
    external
    view
    returns (
        uint160 sqrtPriceX96,
        int24 tick,
        uint16 observationIndex,
        uint16 observationCardinality,
        uint16 observationCardinalityNext,
        uint8 feeProtocol,
        bool unlocked
    )

Pool data.

feeGrowthGlobal0X128

function feeGrowthGlobal0X128() external view returns (uint256)

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

function feeGrowthGlobal1X128() external view returns (uint256)

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

function protocolFees() external view returns (uint128 token0, uint128 token1)

Accumulated fees owed to the protocol (for example, to the governance treasury).

liquidity

function liquidity() external view returns (uint128)

The total liquidity that's currently active in the pool.

ticks

function ticks(int24 tick)
    external
    view
    returns (
        uint128 liquidityGross,
        int128 liquidityNet,
        uint256 feeGrowthOutside0X128,
        uint256 feeGrowthOutside1X128,
        int56 tickCumulativeOutside,
        uint160 secondsPerLiquidityOutsideX128,
        uint32 secondsOutside,
        bool initialized
    )

Tick data.

tickBitmap

function tickBitmap(int16 wordPosition) external view returns (uint256)

A mapping that represents a sub-interval of ticks to help with gas-efficient calculations related to liquidity.

positions

function positions(bytes32 key)
    external
    view
    returns (
        uint128 liquidity,
        uint256 feeGrowthInside0LastX128,
        uint256 feeGrowthInside1LastX128,
        uint128 tokensOwed0,
        uint128 tokensOwed1
    )

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

function observations(uint256 index)
    external
    view
    returns (
        uint32 blockTimestamp,
        int56 tickCumulative,
        uint160 secondsPerLiquidityCumulativeX128,
        bool initialized
    )

An array used for calculating the time-weighted average price (TWAP).

Events

Initialize

event Initialize(uint160 sqrtPriceX96, int24 tick)

Emitted by initialize().

Mint

event Mint(
    address sender,
    address indexed owner,
    int24 indexed tickLower,
    int24 indexed tickUpper,
    uint128 amount,
    uint256 amount0,
    uint256 amount1
)

Emitted by mint().

Collect

event Collect(
    address indexed owner,
    address recipient,
    int24 indexed tickLower,
    int24 indexed tickUpper,
    uint128 amount0,
    uint128 amount1
)

Emitted by collect().

Burn

event Burn(
    address indexed owner,
    int24 indexed tickLower,
    int24 indexed tickUpper,
    uint128 amount,
    uint256 amount0,
    uint256 amount1
)

Emitted by burn().

Swap

event Swap(
    address indexed sender,
    address indexed recipient,
    int256 amount0,
    int256 amount1,
    uint160 sqrtPriceX96,
    uint128 liquidity,
    int24 tick
)

Emitted by swap().

Flash

event Flash(
    address indexed sender,
    address indexed recipient,
    uint256 amount0,
    uint256 amount1,
    uint256 paid0,
    uint256 paid1
)

Emitted by flash().

IncreaseObservationCardinalityNext

event IncreaseObservationCardinalityNext(
    uint16 observationCardinalityNextOld,
    uint16 observationCardinalityNextNew
)

Emitted by increaseObservationCardinalityNext().

SetFeeProtocol

event SetFeeProtocol(
    uint8 feeProtocol0Old, 
    uint8 feeProtocol1Old, 
    uint8 feeProtocol0New, 
    uint8 feeProtocol1New
)

Emitted by setProtocolFee().

CollectProtocol

event CollectProtocol(
    address indexed sender, 
    address indexed recipient, 
    uint128 amount0, 
    uint128 amount1
)

Emitted by collectProtocol().

Write Functions

increaseObservationCardinalityNext

function increaseObservationCardinalityNext(
    uint16 observationCardinalityNext
) external

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

function initialize(uint160 sqrtPriceX96) external

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

function mint(
    address recipient,
    int24 tickLower,
    int24 tickUpper,
    uint128 amount,
    bytes calldata data
) external returns (uint256 amount0, uint256 amount1)

Adds liquidity to a specific price range within the AMM pool.

collect

function collect(
    address recipient,
    int24 tickLower,
    int24 tickUpper,
    uint128 amount0Requested,
    uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1)

Allows liquidity providers to retrieve tokens owed from one or both of the two following scenarios:

  1. To remove accumulated fees from their specified liquidity range.

  2. 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

function burn(
    int24 tickLower,
    int24 tickUpper,
    uint128 amount
) external returns (uint256 amount0, uint256 amount1)

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

function swap(
    address recipient,
    bool zeroForOne,
    int256 amountSpecified,
    uint160 sqrtPriceLimitX96,
    bytes calldata data
) external returns (int256 amount0, int256 amount1)

Swaps one token for another, taking slippage, price limits, and other factors into account.

distributeRewards

function distributeRewards(
    uint256 rewardsAmount,
    bool isToken0
) external

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

function flash(
    address recipient,
    uint256 amount0,
    uint256 amount1,
    bytes calldata data
) external

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

function setFeeProtocol(
    uint8 feeProtocol0,
    uint8 feeProtocol1
) external

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

function collectProtocol(
    address recipient,
    uint128 amount0Requested,
    uint128 amount1Requested
) external

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

function snapshotCumulativesInside(
    int24 tickLower,
    int24 tickUpper
)
    external
    view
    returns (
        int56 tickCumulativeInside,
        uint160 secondsPerLiquidityInsideX128,
        uint32 secondsInside
    )

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

function observe(
    uint32[] calldata secondsAgos
)
    external
    view
    returns (
        int56[] memory tickCumulatives,
        uint160[] memory secondsPerLiquidityCumulativeX128s
    )

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