# jediswap\_v2\_pool

### Functions <a href="#functions" id="functions"></a>

#### initialize <a href="#initialize" id="initialize"></a>

```rust
fn initialize(ref self: ContractState, sqrt_price_X96: u256)
```

Sets the initial price for the pool

Emits [Initialize](#event-initialize).

**Parameters:**

| Name             | Type | Description                                    |
| ---------------- | ---- | ---------------------------------------------- |
| sqrt\_price\_X96 | u256 | The initial sqrt price of the pool as a Q64.96 |

#### mint <a href="#mint" id="mint"></a>

{% code overflow="wrap" fullWidth="false" %}

```rust
fn mint(ref self: ContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount: u128, data: Array<felt252>) -> (u256, u256)
```

{% endcode %}

Adds liquidity for the given recipient/tick\_lower/tick\_upper position

The caller of this method receives a callback in the form of [jediswap\_v2\_mint\_callback](/for-developers/jediswap-v2/periphery/jediswap_v2_nft_position_manager.md#jediswap_v2_mint_callback) in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends on tick\_lower, tick\_upper, the amount of liquidity, and the current price.

Emits [Mint](#event-mint).

**Parameters:**

| Name        | Type            | Description                                              |
| ----------- | --------------- | -------------------------------------------------------- |
| recipient   | ContractAddress | The address for which the liquidity will be created      |
| tick\_lower | i32             | The lower tick of the position in which to add liquidity |
| tick\_upper | i32             | The upper tick of the position in which to add liquidity |
| amount      | u128            | The amount of liquidity to mint                          |
| data        | Array\<felt252> | Any data that should be passed through to the callback   |

**Return Values:**

| Type | Description                                                                                                 |
| ---- | ----------------------------------------------------------------------------------------------------------- |
| u256 | The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback |
| u256 | The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback |

#### collect <a href="#collect" id="collect"></a>

{% code overflow="wrap" %}

```rust
fn collect(ref self: ContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128)
```

{% endcode %}

Collects tokens owed to a position

It 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, amount0\_requested or amount1\_requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. BoundedInt::\<u128>::max(). Tokens owed may be from accumulated swap fees or burned liquidity.

Emits [Collect](#event-collect).

**Parameters:**

| Name               | Type            | Description                                              |
| ------------------ | --------------- | -------------------------------------------------------- |
| recipient          | ContractAddress | The address which should receive the fees collected      |
| tick\_lower        | i32             | The lower tick of the position for which to collect fees |
| tick\_upper        | i32             | The upper tick of the position for which to collect fees |
| amount0\_requested | u128            | How much token0 should be withdrawn from the fees owed   |
| amount1\_requested | u128            | How much token1 should be withdrawn from the fees owed   |

**Return Values:**

| Type | Description                            |
| ---- | -------------------------------------- |
| u128 | The amount of fees collected in token0 |
| u128 | The amount of fees collected in token1 |

#### burn <a href="#burn" id="burn"></a>

{% code overflow="wrap" %}

```rust
fn burn(ref self: ContractState, tick_lower: i32, tick_upper: i32, amount: u128) -> (u256, u256)
```

{% endcode %}

Burn liquidity from the sender and account tokens owed for the liquidity to the position

It 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](#collect).

Emits [Burn](#event-burn).

**Parameters:**

| Name        | Type | Description                                                |
| ----------- | ---- | ---------------------------------------------------------- |
| tick\_lower | i32  | The lower tick of the position for which to burn liquidity |
| tick\_upper | i32  | The upper tick of the position for which to burn liquidity |
| amount      | u128 | How much liquidity to burn                                 |

**Return Values:**

| Type | Description                                |
| ---- | ------------------------------------------ |
| u256 | The amount of token0 sent to the recipient |
| u256 | The amount of token1 sent to the recipient |

#### swap <a href="#swap" id="swap"></a>

{% code overflow="wrap" %}

```rust
fn swap(ref self: ContractState, recipient: ContractAddress, zero_for_one: bool, amount_specified: i256, sqrt_price_limit_X96: u256, data: Array<felt252>) -> (i256, i256)
```

{% endcode %}

Swap token0 for token1, or token1 for token0

The caller of this method receives a callback in the form of [jediswap\_v2\_swap\_callback](/for-developers/jediswap-v2/periphery/jediswap_v2_swap_router.md#jediswap_v2_swap_callback)

Emits [Swap](#event-swap).

**Parameters:**

| Name                    | Type            | Description                                                                                                                                                                        |
| ----------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| recipient               | ContractAddress | The address to receive the output of the swap                                                                                                                                      |
| zero\_for\_one          | bool            | The direction of the swap, true for token0 to token1, false for token1 to token0                                                                                                   |
| amount\_specified       | i256            | The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)                                                                 |
| sqrt\_price\_limit\_X96 | u256            | 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 swap |
| data                    | Array\<felt252> | Any data to be passed through to the callback                                                                                                                                      |

**Return Values:**

| Type | Description                                                                                |
| ---- | ------------------------------------------------------------------------------------------ |
| i256 | The delta of the balance of token0 of the pool, exact when negative, minimum when positive |
| i256 | The delta of the balance of token1 of the pool, exact when negative, minimum when positive |

#### collect\_protocol <a href="#collect_protocol" id="collect_protocol"></a>

{% code overflow="wrap" %}

```rust
fn collect_protocol(ref self: ContractState, recipient: ContractAddress, amount0_requested: u128, amount1_requested: u128) -> (u128, u128)
```

{% endcode %}

Collect the protocol fee accrued to the pool

Only the factory owner can call this function.

Emits [CollectProtocol](#event-collectprotocol).

**Parameters:**

| Name               | Type            | Description                                                                   |
| ------------------ | --------------- | ----------------------------------------------------------------------------- |
| recipient          | ContractAddress | The address to which collected protocol fees should be sent                   |
| amount0\_requested | u128            | The maximum amount of token0 to send, can be 0 to collect fees in only token1 |
| amount1\_requested | u128            | The maximum amount of token1 to send, can be 0 to collect fees in only token0 |

**Return Values:**

| Type | Description                          |
| ---- | ------------------------------------ |
| u128 | The protocol fee collected in token0 |
| u128 | The protocol fee collected in token1 |

### Events <a href="#events" id="events"></a>

#### Initialize <a href="#event-initialize" id="event-initialize"></a>

```rust
struct Initialize {
    sqrt_price_X96: u256,
    tick: i32
}
```

Emitted exactly once by a pool when [initialize](#initialize) is first called on the pool

Mint/Burn/Swap cannot be emitted by the pool before Initialize

**Parameters:**

| Name             | Type | Description                                                                          |
| ---------------- | ---- | ------------------------------------------------------------------------------------ |
| sqrt\_price\_X96 | u256 | The initial sqrt price of the pool, as a Q64.96                                      |
| tick             | i32  | The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool |

#### Mint <a href="#event-mint" id="event-mint"></a>

```rust
struct Mint {
    sender: ContractAddress,
    owner: ContractAddress,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name        | Type            | Description                                                     |
| ----------- | --------------- | --------------------------------------------------------------- |
| sender      | ContractAddress | The address that minted the liquidity                           |
| owner       | ContractAddress | The owner of the position and recipient of any minted liquidity |
| tick\_lower | i32             | The lower tick of the position                                  |
| tick\_upper | i32             | The upper tick of the position                                  |
| amount      | u128            | The amount of liquidity minted to the position range            |
| amount0     | u256            | How much token0 was required for the minted liquidity           |
| amount1     | u256            | How much token1 was required for the minted liquidity           |

#### Collect <a href="#event-collect" id="event-collect"></a>

Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees

```rust
struct Collect {
    owner: ContractAddress,
    recipient: ContractAddress,
    tick_lower: i32,
    tick_upper: i32,
    amount0: u128,
    amount1: u128
}
```

**Parameters:**

| Name        | Type            | Description                                            |
| ----------- | --------------- | ------------------------------------------------------ |
| owner       | ContractAddress | The owner of the position for which fees are collected |
| recipient   | ContractAddress | The address which should receive the fees collected    |
| tick\_lower | i32             | The lower tick of the position                         |
| tick\_upper | i32             | The upper tick of the position                         |
| amount0     | u128            | The amount of token0 fees collected                    |
| amount1     | u128            | The amount of token1 fees collected                    |

#### Burn <a href="#event-burn" id="event-burn"></a>

```rust
struct Burn {
    owner: ContractAddress,
    tick_lower: i32,
    tick_upper: i32,
    amount: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name        | Type            | Description                                              |
| ----------- | --------------- | -------------------------------------------------------- |
| owner       | ContractAddress | The owner of the position for which liquidity is removed |
| tick\_lower | i32             | The lower tick of the position                           |
| tick\_upper | i32             | The upper tick of the position                           |
| amount      | u128            | The amount of liquidity to remove                        |
| amount0     | u256            | The amount of token0 withdrawn                           |
| amount1     | u256            | The amount of token1 withdrawn                           |

#### Swap <a href="#event-swap" id="event-swap"></a>

```rust
struct Swap {
    sender: ContractAddress,
    recipient: ContractAddress,
    amount0: i256,
    amount1: i256,
    sqrt_price_X96: u256,
    liquidity: u128,
    tick: i32
}
```

**Parameters:**

| Name             | Type            | Description                                                              |
| ---------------- | --------------- | ------------------------------------------------------------------------ |
| sender           | ContractAddress | The address that initiated the swap call, and that received the callback |
| recipient        | ContractAddress | The address that received the output of the swap                         |
| amount0          | i256            | The delta of the token0 balance of the pool                              |
| amount1          | i256            | The delta of the token1 balance of the pool                              |
| sqrt\_price\_X96 | u256            | The sqrt(price) of the pool after the swap, as a Q64.96                  |
| liquidity        | u128            | The liquidity of the pool after the swap                                 |
| tick             | i32             | The log base 1.0001 of price of the pool after the swap                  |

#### CollectProtocol <a href="#event-collectprotocol" id="event-collectprotocol"></a>

```rust
struct CollectProtocol {
    sender: ContractAddress,
    recipient: ContractAddress,
    amount0: u128,
    amount1: u128
}
```

**Parameters:**

| Name      | Type            | Description                                           |
| --------- | --------------- | ----------------------------------------------------- |
| sender    | ContractAddress | The address that collects the protocol fees           |
| recipient | ContractAddress | The address that receives the collected protocol fees |
| amount0   | u128            | The amount of token0 protocol fees that is withdrawn  |
| amount1   | u128            | The amount of token1 protocol fees that is withdrawn  |

### ABI <a href="#abi" id="abi"></a>

```rust
//sign true for negative numbers
struct i32 {
    mag: u32,
    sign: bool,
}

//sign true for negative numbers
struct i128 {
    mag: u128,
    sign: bool,
}

//sign true for negative numbers
struct i256 {
    mag: u256,
    sign: bool,
}

struct ProtocolFees {
    // @notice Accumulated protocol fees in token0
    token0: u128,
    // @notice Accumulated protocol fees in token1
    token1: u128
}

struct TickInfo {
    // @notice The total position liquidity that references this tick
    liquidity_gross: u128,
    // @notice Amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left),
    liquidity_net: i128,
    // @notice Fee growth for token0 per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    fee_growth_outside_0_X128: u256,
    // @notice Fee growth for token1 per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    fee_growth_outside_1_X128: u256,
}

struct PositionInfo {
    // @notice The amount of liquidity owned by this position
    liquidity: u128,
    // @notice Fee growth of token0 per unit of liquidity as of the last update to liquidity or fees owned
    fee_growth_inside_0_last_X128: u256,
    // @notice Fee growth of token1 per unit of liquidity as of the last update to liquidity or fees owned
    fee_growth_inside_1_last_X128: u256,
    // @notice The fees owed to the position owner in token0
    tokens_owed_0: u128,
    // @notice The fees owed to the position owner in token1
    tokens_owed_1: u128,
}

struct PositionKey {
    // @notice The owner of the position
    owner: ContractAddress,
    // @notice The lower tick of the position's tick range
    tick_lower: i32,
    // @notice The upper tick of the position's tick range
    tick_upper: i32,
}

#[starknet::interface]
trait IJediSwapV2Pool<TContractState> {
    fn get_factory(self: @TContractState) -> ContractAddress;
    fn get_token0(self: @TContractState) -> ContractAddress;
    fn get_token1(self: @TContractState) -> ContractAddress;
    fn get_fee(self: @TContractState) -> u32;
    fn get_tick_spacing(self: @TContractState) -> u32;
    fn get_max_liquidity_per_tick(self: @TContractState) -> u128;
    fn get_sqrt_price_X96(self: @TContractState) -> u256;
    fn get_tick(self: @TContractState) -> i32;
    fn get_fee_protocol(self: @TContractState) -> u8;
    fn get_fee_growth_global_0_X128(self: @TContractState) -> u256;
    fn get_fee_growth_global_1_X128(self: @TContractState) -> u256;
    fn get_protocol_fees(self: @TContractState) -> ProtocolFees;
    fn get_liquidity(self: @TContractState) -> u128;
    fn get_tick_info(self: @TContractState, tick: i32) -> TickInfo;
    fn get_position_info(self: @TContractState, position_key: PositionKey) -> PositionInfo;
    fn static_collect(self: @TContractState, owner: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128);
    
    fn initialize(ref self: TContractState, sqrt_price_X96: u256);
    fn mint(ref self: TContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount: u128, data: Array<felt252>) -> (u256, u256);
    fn collect(ref self: TContractState, recipient: ContractAddress, tick_lower: i32, tick_upper: i32, amount0_requested: u128, amount1_requested: u128) -> (u128, u128);
    fn burn(ref self: TContractState, tick_lower: i32, tick_upper: i32, amount: u128) -> (u256, u256);
    fn swap(ref self: TContractState, recipient: ContractAddress, zero_for_one: bool, amount_specified: i256, sqrt_price_limit_X96: u256, data: Array<felt252>) -> (i256, i256);
    fn collect_protocol(ref self: TContractState, recipient: ContractAddress, amount0_requested: u128, amount1_requested: u128) -> (u128, u128);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jediswap.xyz/for-developers/jediswap-v2/core/jediswap_v2_pool.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
