# UniswapV3PoolUpgradeable

NFTX AMM pool contract. Uses BeaconProxy for deployments.

## Table of Contents

<details>

<summary>Variables</summary>

[#factory](#factory "mention")\
[#token0](#token0 "mention")\
[#token1](#token1 "mention")\
[#fee](#fee "mention")\
[#tickspacing](#tickspacing "mention")\
[#maxliquiditypertick](#maxliquiditypertick "mention")\
[#slot0](#slot0 "mention")\
[#feegrowthglobal0x128](#feegrowthglobal0x128 "mention")\
[#feegrowthglobal1x128](#feegrowthglobal1x128 "mention")\
[#protocolfees](#protocolfees "mention")\
[#liquidity](#liquidity "mention")\
[#ticks](#ticks "mention")\
[#tickbitmap](#tickbitmap "mention")\
[#positions](#positions "mention")\
[#observations](#observations "mention")

</details>

<details>

<summary>Events</summary>

[#initialize](#initialize "mention")\
[#mint](#mint "mention")\
[#collect](#collect "mention")\
[#burn](#burn "mention")\
[#swap](#swap "mention")\
[#flash](#flash "mention")\
[#increaseobservationcardinalitynext](#increaseobservationcardinalitynext "mention")\
[#setfeeprotocol](#setfeeprotocol "mention")\
[#collectprotocol](#collectprotocol "mention")

</details>

<details>

<summary>Public Write Functions</summary>

[#increaseobservationcardinalitynext-1](#increaseobservationcardinalitynext-1 "mention")\
[#initialize](#initialize "mention")\
[#mint-1](#mint-1 "mention")\
[#collect-1](#collect-1 "mention")\
[#burn-1](#burn-1 "mention")\
[#swap-1](#swap-1 "mention")\
[#distributerewards](#distributerewards "mention")\
[#swap-1](#swap-1 "mention")\
[#distributerewards](#distributerewards "mention")

</details>

<details>

<summary>Owner Write Functions</summary>

[#setfeeprotocol-1](#setfeeprotocol-1 "mention")\
[#collectprotocol-1](#collectprotocol-1 "mention")

</details>

<details>

<summary>Read Functions</summary>

[#balance0](#balance0 "mention")\
[#balance1](#balance1 "mention")\
[#snapshotcumulativesinside](#snapshotcumulativesinside "mention")\
[#observe](#observe "mention")

</details>

## Variables

#### factory

```solidity
function factory() external view returns (address)
```

Address of the NFTX AMM's `UniswapV3FactoryUpgradeable` contract.

#### token0

```solidity
function token0() external view returns (address)
```

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

#### token1

```solidity
function token1() external view returns (address)
```

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

#### fee

```solidity
function fee() external view returns (uint24)
```

AMM swap fee tier.

#### tickSpacing

```solidity
function tickSpacing() external view returns (int24)
```

Tick spacing of the pool.&#x20;

#### maxLiquidityPerTick

```solidity
function maxLiquidityPerTick() external view returns (uint128)
```

Maximum liquidity amount per tick.&#x20;

#### slot0

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

Pool data.&#x20;

#### feeGrowthGlobal0X128

```solidity
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

```solidity
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

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

Accumulated fees owed to the protocol (for example, to the governance treasury).&#x20;

#### liquidity

```solidity
function liquidity() external view returns (uint128)
```

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

#### ticks

```solidity
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

```solidity
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

```solidity
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

```solidity
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

```solidity
event Initialize(uint160 sqrtPriceX96, int24 tick)
```

Emitted by `initialize()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>sqrtPriceX96</td><td><code>uint160</code></td><td>Starting price.</td></tr><tr><td>tick</td><td><code>int24</code></td><td>Closest tick representing price. </td></tr></tbody></table>

#### Mint

<pre class="language-solidity"><code class="lang-solidity"><strong>event Mint(
</strong>    address sender,
    address indexed owner,
    int24 indexed tickLower,
    int24 indexed tickUpper,
    uint128 amount,
    uint256 amount0,
    uint256 amount1
)
</code></pre>

Emitted by `mint()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>sender</td><td><code>address</code></td><td>The address that called the mint function to add liquidity.</td></tr><tr><td>owner</td><td><code>address</code></td><td>The address that will own the liquidity position and can collect fees on it.</td></tr><tr><td>tickLower</td><td><code>int24</code></td><td>The lower price tick of the price range for which the liquidity is being provided.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The upper price tick of the price range for which the liquidity is being provided.</td></tr><tr><td>amount</td><td><code>uint128</code></td><td>The amount of liquidity that was added.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that was added as liquidity.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that was added as liquidity.</td></tr></tbody></table>

#### Collect

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

Emitted by `collect()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>owner</td><td><code>address</code></td><td>The address that called the mint function to add liquidity.</td></tr><tr><td>recipient</td><td><code>address</code></td><td>The address that will own the liquidity position and can collect fees on it.</td></tr><tr><td>tickLower</td><td><code>int24</code></td><td>The lower price tick of the price range for which the liquidity is being provided.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The upper price tick of the price range for which the liquidity is being provided.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that was added as liquidity.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that was added as liquidity.</td></tr></tbody></table>

#### Burn

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

Emitted by `burn()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>owner</td><td><code>address</code></td><td>The address that owned the liquidity position and called the function to remove liquidity.</td></tr><tr><td>tickLower</td><td><code>int24</code></td><td>The lower price tick of the price range for which the liquidity was provided.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The lower price tick of the price range for which the liquidity was provided.</td></tr><tr><td>amount</td><td><code>uint128</code></td><td>The amount of liquidity that was removed.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that was removed as liquidity.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that was removed as liquidity.</td></tr></tbody></table>

#### Swap

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

Emitted by `swap()`.&#x20;

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>sender</td><td><code>address</code></td><td>The address that initiated the swap.</td></tr><tr><td>recipient</td><td><code>address</code></td><td>The address that received the output tokens from the swap.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The change in the token0 balance as a result of the swap. A negative value indicates token0 was sold, and a positive value indicates token0 was bought.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The change in the token1 balance as a result of the swap. A negative value indicates token1 was sold, and a positive value indicates token1 was bought.</td></tr><tr><td>sqrtPriceX96</td><td><code>uint160</code></td><td>The price of the pool after the swap has occurred. Encoded as the square root of the ratio of token amounts, and stored as a fixed-point number with 96 bits to the right of the decimal point.</td></tr><tr><td>liquidity</td><td><code>uint128</code></td><td>The active liquidity at the time the swap occurred.</td></tr><tr><td>tick</td><td><code>int24</code></td><td>Represents the tick index of the pool after the swap has occurred.</td></tr></tbody></table>

#### Flash

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

Emitted by `flash()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>sender</td><td><code>address</code></td><td>The address that initiated the flash swap.</td></tr><tr><td>recipient</td><td><code>address</code></td><td>The address that received the tokens from the flash swap.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that the recipient received in the flash swap.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that the recipient received in the flash swap.</td></tr><tr><td>paid0</td><td><code>uint160</code></td><td>The amount of token0 that was paid back to the pool by the sender by the end of the transaction.</td></tr><tr><td>paid1</td><td><code>uint128</code></td><td>The amount of token1 that was paid back to the pool by the sender by the end of the transaction.</td></tr></tbody></table>

#### IncreaseObservationCardinalityNext

```solidity
event IncreaseObservationCardinalityNext(
    uint16 observationCardinalityNextOld,
    uint16 observationCardinalityNextNew
)
```

Emitted by `increaseObservationCardinalityNext()`.

<table><thead><tr><th width="290.3333333333333">Parameters</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>observationCardinalityNextOld</td><td><code>uint16</code></td><td>The previous value of the next maximum number of observations that the pool can store.</td></tr><tr><td>observationCardinalityNextNew</td><td><code>uint16</code></td><td>The updated value of the next maximum number of observations that the pool will store.</td></tr></tbody></table>

#### SetFeeProtocol

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

Emitted by `setProtocolFee()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>feeProtocol0Old</td><td><code>uint8</code></td><td>The previous value of the fee protocol setting for token0.</td></tr><tr><td>feeProtocol1Old</td><td><code>uint8</code></td><td>The previous value of the fee protocol setting for token1.</td></tr><tr><td>feeProtocol0New</td><td><code>uint8</code></td><td>The updated value of the fee protocol setting for token0.</td></tr><tr><td>feeProtocol1New</td><td><code>uint8</code></td><td>The updated value of the fee protocol setting for token1.</td></tr></tbody></table>

#### CollectProtocol

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

Emitted by `collectProtocol()`.

<table><thead><tr><th width="182.33333333333331">Parameters</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>sender</td><td><code>address</code></td><td>The address that initiated the collection of the protocol fees.</td></tr><tr><td>recipient</td><td><code>address</code></td><td>The address that received the collected protocol fees.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that was collected as a protocol fee.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that was collected as a protocol fee.</td></tr></tbody></table>

## Write Functions

#### increaseObservationCardinalityNext

```solidity
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.

<table><thead><tr><th width="256.5">Parameters</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td>observationCardinalityNext</td><td><code>uint26</code></td><td>Specifies the desired future maximum number of observations the pool should be able to store. It should be set to a value greater than the current <code>observationCardinalityNext</code>.</td></tr></tbody></table>

#### initialize

```solidity
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.

<table><thead><tr><th width="174.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>sqrtPriceX96</td><td><code>uint160</code></td><td>The starting price for the pool. Represented as the square root of the ratio of token amounts, stored as a fixed-point number with 96 bits to the right of the decimal point. </td></tr></tbody></table>

#### mint

```solidity
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.

<table><thead><tr><th width="174.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td><code>address</code></td><td>The address that will receive the liquidity position NFT.</td></tr><tr><td>tickLower</td><td><code>int24</code></td><td>The lower bound (in tick terms) of the price range for which liquidity is being provided.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The upper bound (in tick terms) of the price range for which liquidity is being provided.</td></tr><tr><td>amount</td><td><code>uint128</code></td><td>The amount of liquidity being added to the pool within the specified tick range. </td></tr><tr><td>data</td><td><code>bytes</code></td><td>Arbitrary calldata that is forwarded to a callback function.</td></tr></tbody></table>

<table><thead><tr><th width="174.5">Return values</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that the liquidity provider added to the pool.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that the liquidity provider added to the pool.</td></tr></tbody></table>

#### collect

```solidity
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.

<table><thead><tr><th width="198.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td><code>address</code></td><td>The address that will receive the collected tokens (either fees or tokens from removed liquidity).</td></tr><tr><td>tickLower</td><td><code>int24</code></td><td>The lower tick bound of the price range.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The upper tick bound of the price range.</td></tr><tr><td>amount0Requested</td><td><code>uint128</code></td><td>The maximum amount of token0 that the caller wishes to collect.</td></tr><tr><td>amount1Requested</td><td><code>uint128</code></td><td>The maximum amount of token1 that the caller wishes to collect.</td></tr></tbody></table>

<table><thead><tr><th width="174.5">Return values</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 collected.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 collected.</td></tr></tbody></table>

#### burn

```solidity
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

<table><thead><tr><th width="174.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>tickLower</td><td><code>int24</code></td><td>The lower tick bound of the price range of the specific liquidity position from which liquidity is being removed.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The upper tick bound of the price range of the specific liquidity position from which liquidity is being removed.</td></tr><tr><td>amount</td><td><code>uint128</code></td><td>The amount of liquidity that the caller wishes to remove from the specified position within the tick range.</td></tr></tbody></table>

<table><thead><tr><th width="174.5">Return values</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of token0 that was removed and is available for collection.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of token1 that was removed and is available for collection.</td></tr></tbody></table>

#### swap

```solidity
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.&#x20;

<table><thead><tr><th width="187.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td><code>int24</code></td><td>The address that will receive the tokens resulting from the swap.</td></tr><tr><td>zeroForOne</td><td><code>int24</code></td><td>True to swap token0 for token1, false to swap token1 for token0.</td></tr><tr><td>amountSpecified</td><td><code>int128</code></td><td>The exact amount of the token being sold (if positive) or the maximum amount of token one is willing to buy (if negative).</td></tr><tr><td>sqrtPriceLimitX96</td><td><code>uint160</code></td><td>A price constraint for the trade. If <code>zeroForOne</code> is <code>true</code>, the trade will only execute if the pool's price doesn't go above this value (representing a price floor). If <code>zeroForOne</code> is <code>false</code>, the trade will only execute if the pool's price doesn't go below this value (representing a price ceiling). It's represented as the square root of the price ratio encoded in a 96-bit fixed-point format. If set to zero, it means no price constraint is enforced.</td></tr><tr><td>data</td><td><code>bytes</code></td><td>Arbitrary calldata sent along with the function call, allowing for more complex logic or interactions if required by the recipient. It can be used for custom callbacks, which the pool will call after the core swap logic runs.</td></tr></tbody></table>

<table><thead><tr><th width="189.5">Name</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of <code>token0</code> that was either paid (if negative) or received (if positive).</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of <code>token1</code> that was either paid (if negative) or received (if positive).</td></tr></tbody></table>

#### distributeRewards

```solidity
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.&#x20;

<table><thead><tr><th width="187.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>rewardsAmount</td><td><code>int24</code></td><td>The amount of reward tokens to distribute</td></tr><tr><td>isToken0</td><td><code>int24</code></td><td>True if reward token is token0, false if it is token1.</td></tr></tbody></table>

#### flash

```solidity
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.

<table><thead><tr><th width="187.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td><code>address</code></td><td>The address that receives the borrowed tokens and is responsible for ensuring their return within the same transaction. This should ideally be a smart contract that implements the necessary callback logic to repay the borrowed funds.</td></tr><tr><td>amount0</td><td><code>uint256</code></td><td>The amount of <code>token0</code> to be borrowed from the pool.</td></tr><tr><td>amount1</td><td><code>uint256</code></td><td>The amount of <code>token1</code> to be borrowed from the pool.</td></tr><tr><td>data</td><td><code>bytes</code></td><td>Arbitrary calldata forwarded to the recipient's callback function. This allows the recipient smart contract to specify additional parameters or custom logic that should be executed after the tokens are borrowed and before they are returned.</td></tr></tbody></table>

## Owner Functions

#### setFeeProtocol

```solidity
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.

<table><thead><tr><th width="187.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>feeProtocol0</td><td><code>uint8</code></td><td>The fee protocol value for <code>token0</code>.</td></tr><tr><td>feeProtocol1</td><td><code>uint8</code></td><td>The fee protocol value for <code>token1</code>.</td></tr></tbody></table>

#### collectProtocol

```solidity
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.

<table><thead><tr><th width="199.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td><code>address</code></td><td>The address that will receive the collected protocol fees. This is typically a treasury or another designated address decided upon by the protocol's governance.</td></tr><tr><td>amount0Requested</td><td><code>uint128</code></td><td>The maximum amount of <code>token0</code> fees that the caller wishes to collect from the protocol's accumulated fees.</td></tr><tr><td>amount1Requested</td><td><code>uint128</code></td><td>The maximum amount of <code>token1</code> fees that the caller wishes to collect from the protocol's accumulated fees.</td></tr></tbody></table>

## Read Functions

#### snapshotCumulativesInside

```solidity
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.

<table><thead><tr><th width="250.5">Parameters</th><th width="113">Type</th><th>Description</th></tr></thead><tbody><tr><td>tickLower</td><td><code>int24</code></td><td>The lower tick bound of the specific tick range for which the cumulative values are to be fetched.</td></tr><tr><td>tickUpper</td><td><code>int24</code></td><td>The upper tick bound of the specific tick range for which the cumulative values are to be fetched.</td></tr></tbody></table>

<table><thead><tr><th width="252.5">Return values</th><th width="112">Type</th><th>Description</th></tr></thead><tbody><tr><td>tickCumulativeInside</td><td><code>int56</code></td><td>The cumulative tick value within the specified range. This value represents the sum of all tick values each time liquidity was added or removed in the given range, up to the current moment. It's useful for calculating price changes over time.</td></tr><tr><td>secondsPerLiquidityInsideX128</td><td><code>uint160</code></td><td>A cumulative value representing the seconds per liquidity within the specified tick range, encoded in a 128-bit fixed-point format. It's useful for determining how long, on average, liquidity has been available in the tick range, helping in calculations related to fee accrual.</td></tr><tr><td>secondsInside</td><td><code>uint32</code></td><td>The total time in seconds that the pool's current tick has been within the specified tick range. This is useful for determining how long the current price has been within a certain range.</td></tr></tbody></table>

#### observe

```solidity
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.

<table><thead><tr><th width="206.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>secondsAgos</td><td><code>uint32[]</code></td><td>An array of time durations in seconds. Each duration represents how far in the past the data should be fetched. For instance, if one of the durations is <code>3600</code>, it means the function should return the cumulative values from 1 hour ago.</td></tr></tbody></table>

<table><thead><tr><th width="205.5">Return values</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>tickCumulatives</td><td><code>int56[]</code></td><td>An array of cumulative tick values corresponding to each of the durations in the <code>secondsAgos</code> array. Each value represents the sum of all tick values up to the respective historical point. Useful for assessing price movements over multiple historical points.</td></tr><tr><td>secondsPerLiquidityCumulativeX128s</td><td><code>uint160</code></td><td>An array of cumulative values representing the seconds per liquidity up to each of the durations in the <code>secondsAgos</code> array, encoded in a 128-bit fixed-point format. This metric provides insights into how liquidity has changed over each of the specified durations.</td></tr></tbody></table>
