> For the complete documentation index, see [llms.txt](https://docs.warpx.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.warpx.exchange/for-developers/warpx-v3/core/warpx-v3-pool.md).

# WarpX V3 Pool

#### Pool Initialization <a href="#user-content-pool-initialization" id="user-content-pool-initialization"></a>

```
function initialize(uint160 sqrtPriceX96) external
```

Sets the initial price for the pool. Must be called before any liquidity can be added or swaps executed.

Price is represented as `sqrt(amountToken1/amountToken0)` in Q64.96 format.

**Parameters:**

| Name           | Type    | Description                          |
| -------------- | ------- | ------------------------------------ |
| `sqrtPriceX96` | uint160 | Initial sqrt price as a Q64.96 value |

**Example:**

```
// Initialize pool with 1:1 price ratiouint160 sqrtPrice = 79228162514264337593543950336; // sqrt(1) * 2^96pool.initialize(sqrtPrice);
```

***

#### Adding Liquidity <a href="#user-content-adding-liquidity" id="user-content-adding-liquidity"></a>

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

Adds liquidity for a given position. Your contract must implement `IUniswapV3MintCallback` to provide tokens.

**Parameters:**

| Name        | Type    | Description                 |
| ----------- | ------- | --------------------------- |
| `recipient` | address | Position owner address      |
| `tickLower` | int24   | Lower tick of the position  |
| `tickUpper` | int24   | Upper tick of the position  |
| `amount`    | uint128 | Amount of liquidity to mint |
| `data`      | bytes   | Data passed to the callback |

**Returns:** Token amounts required (`amount0`, `amount1`)

**Example:**

```
(uint256 amount0, uint256 amount1) = pool.mint(    msg.sender,    -887220, // Lower tick    887220,  // Upper tick    1000000, // Liquidity amount    abi.encode(msg.sender));
```

***

#### Removing Liquidity <a href="#user-content-removing-liquidity" id="user-content-removing-liquidity"></a>

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

Removes liquidity from a position owned by `msg.sender`.

**Parameters:**

| Name        | Type    | Description                 |
| ----------- | ------- | --------------------------- |
| `tickLower` | int24   | Lower tick of the position  |
| `tickUpper` | int24   | Upper tick of the position  |
| `amount`    | uint128 | Amount of liquidity to burn |

**Returns:** Token amounts withdrawn (`amount0`, `amount1`)

**Note:** Fees are not automatically collected. Use `collect()` to withdraw fees.

***

#### Collecting Fees <a href="#user-content-collecting-fees" id="user-content-collecting-fees"></a>

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

Collects fees and tokens owed to a position owned by `msg.sender`.

**Parameters:**

| Name               | Type    | Description                                             |
| ------------------ | ------- | ------------------------------------------------------- |
| `recipient`        | address | Address to receive tokens                               |
| `tickLower`        | int24   | Lower tick of the position                              |
| `tickUpper`        | int24   | Upper tick of the position                              |
| `amount0Requested` | uint128 | Max token0 to collect (use `type(uint128).max` for all) |
| `amount1Requested` | uint128 | Max token1 to collect (use `type(uint128).max` for all) |

**Returns:** Actual amounts collected (`amount0`, `amount1`)

**Example:**

```
// Collect all available fees(uint128 collected0, uint128 collected1) = pool.collect(    msg.sender,    tickLower,    tickUpper,    type(uint128).max,    type(uint128).max);
```

***

#### Swapping Tokens <a href="#user-content-swapping-tokens" id="user-content-swapping-tokens"></a>

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

Swaps tokens in the pool. Your contract must implement `IUniswapV3SwapCallback` to provide input tokens.

**Parameters:**

| Name                | Type    | Description                                                       |
| ------------------- | ------- | ----------------------------------------------------------------- |
| `recipient`         | address | Address to receive output tokens                                  |
| `zeroForOne`        | bool    | `true` = swap token0 for token1, `false` = swap token1 for token0 |
| `amountSpecified`   | int256  | Positive = exact input, Negative = exact output                   |
| `sqrtPriceLimitX96` | uint160 | Price limit as Q64.96 (0 = no limit)                              |
| `data`              | bytes   | Data passed to the callback                                       |

**Returns:** Token deltas (`amount0`, `amount1`) - negative = tokens sent out, positive = tokens received

**Example:**

```
// Swap exactly 1000 token0 for token1(int256 amount0, int256 amount1) = pool.swap(    msg.sender,    true,              // token0 → token1    1000e18,           // Exact input amount    0,                 // No price limit    abi.encode(msg.sender));
```

***

#### Flash Loans <a href="#user-content-flash-loans" id="user-content-flash-loans"></a>

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

Borrow tokens from the pool and repay within the same transaction. Your contract must implement `IUniswapV3FlashCallback`.

**Parameters:**

| Name        | Type    | Description                        |
| ----------- | ------- | ---------------------------------- |
| `recipient` | address | Address to receive borrowed tokens |
| `amount0`   | uint256 | Amount of token0 to borrow         |
| `amount1`   | uint256 | Amount of token1 to borrow         |
| `data`      | bytes   | Data passed to the callback        |

***

### Pool State Queries <a href="#user-content-pool-state-queries" id="user-content-pool-state-queries"></a>

#### Current Price & Tick <a href="#user-content-current-price--tick" id="user-content-current-price--tick"></a>

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

Returns the current pool state including price and tick.

#### Liquidity <a href="#user-content-liquidity" id="user-content-liquidity"></a>

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

Returns the currently in-range liquidity.

#### Position Information <a href="#user-content-position-information" id="user-content-position-information"></a>

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

Returns information about a position. The key is: `keccak256(abi.encodePacked(owner, tickLower, tickUpper))`

#### Tick Information <a href="#user-content-tick-information" id="user-content-tick-information"></a>

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

Returns detailed information about a specific tick.
