# jediswap\_v2\_nft\_position\_manager

Wraps JediSwap V2 positions in the ERC721 non-fungible token interface

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

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

```rust
fn mint(ref self: ContractState, params: MintParams) -> (u256, u128, u256, u256)
```

Creates a new position wrapped in a NFT

Call this when the pool does exist and is initialized

Emits [IncreaseLiquidity](#event_increaseliquidity).

**Parameters:**

| Name   | Type       | Description                             |
| ------ | ---------- | --------------------------------------- |
| params | MintParams | The params necessary to mint a position |

**Return Values:**

| Type | Description                                             |
| ---- | ------------------------------------------------------- |
| u256 | The ID of the token that represents the minted position |
| u128 | The amount of liquidity for this position               |
| u256 | The amount of token0                                    |
| u256 | The amount of token1                                    |

#### increase\_liquidity <a href="#increase_liquidity" id="increase_liquidity"></a>

{% code overflow="wrap" %}

```rust
fn increase_liquidity(ref self: ContractState, params: IncreaseLiquidityParams) -> (u128, u256, u256)
```

{% endcode %}

Increases the amount of liquidity in a position, with tokens paid by the caller

Emits [IncreaseLiquidity](#event_increaseliquidity).

**Parameters:**

| Name   | Type                    | Description                                              |
| ------ | ----------------------- | -------------------------------------------------------- |
| params | IncreaseLiquidityParams | The params necessary to increase liquidity of a position |

**Return Values:**

| Type | Description                                          |
| ---- | ---------------------------------------------------- |
| u128 | The new liquidity amount as a result of the increase |
| u256 | The amount of token0 to achieve resulting liquidity  |
| u256 | The amount of token1 to achieve resulting liquidity  |

#### decrease\_liquidity <a href="#decrease_liquidity" id="decrease_liquidity"></a>

{% code overflow="wrap" %}

```rust
fn decrease_liquidity(ref self: ContractState, params: DecreaseLiquidityParams) -> (u256, u256)
```

{% endcode %}

Decreases the amount of liquidity in a position and accounts it to the position

Emits [DecreaseLiquidity](#event_decreaseliquidity).

**Parameters:**

| Name   | Type                    | Description                                              |
| ------ | ----------------------- | -------------------------------------------------------- |
| params | DecreaseLiquidityParams | The params necessary to decrease liquidity of a position |

**Return Values:**

| Type | Description                                                  |
| ---- | ------------------------------------------------------------ |
| u256 | The amount of token0 accounted to the position's tokens owed |
| u256 | The amount of token1 accounted to the position's tokens owed |

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

```rust
fn collect(ref self: ContractState, params: CollectParams) -> (u128, u128)
```

Collects up to a maximum amount of fees owed to a specific position to the recipient

Emits [Collect](#event_collect).

**Parameters:**

| Name   | Type          | Description                                        |
| ------ | ------------- | -------------------------------------------------- |
| params | CollectParams | The params necessary to collect fees of a position |

**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>

```rust
fn burn(ref self: ContractState, token_id: u256)
```

Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens must be collected first.

**Parameters:**

| Name      | Type | Description                              |
| --------- | ---- | ---------------------------------------- |
| token\_id | u256 | The ID of the token that is being burned |

#### create\_and\_initialize\_pool <a href="#create_and_initialize_pool" id="create_and_initialize_pool"></a>

{% code overflow="wrap" %}

```rust
fn create_and_initialize_pool(ref self: ContractState, token0: ContractAddress, token1: ContractAddress, fee: u32, sqrt_price_X96: u256) -> ContractAddress
```

{% endcode %}

Creates a new pool if it does not exist, then initializes if not initialized

This method can be bundled with others via multicall for the first action (e.g. mint) performed against a pool

**Parameters:**

| Name             | Type            | Description                                                 |
| ---------------- | --------------- | ----------------------------------------------------------- |
| token0           | ContractAddress | The contract address of token0 of the pool                  |
| token1           | ContractAddress | The contract address of token1 of the pool                  |
| fee              | u32             | The fee amount of the v2 pool for the specified token pair  |
| sqrt\_price\_X96 | u256            | The initial square root price of the pool as a Q64.96 value |

**Return Values:**

| Type            | Description                                                                                                   |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| ContractAddress | The pool address based on the pair of tokens and fee, will return the newly created pool address if necessary |

#### jediswap\_v2\_mint\_callback <a href="#jediswap_v2_mint_callback" id="jediswap_v2_mint_callback"></a>

```rust
fn jediswap_v2_mint_callback(ref self: ContractState, amount0_owed: u256, amount1_owed: u256, callback_data_span: Span<felt252>)
```

**Parameters:**

| Name                 | Type           | Description |
| -------------------- | -------------- | ----------- |
| amount0\_owed        | u256           |             |
| amount1\_owed        | u256           |             |
| callback\_data\_span | Span\<felt252> |             |

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

#### IncreaseLiquidity <a href="#event_increaseliquidity" id="event_increaseliquidity"></a>

Emitted when liquidity is increased for a position NFT. Also emitted when a token is minted.

```rust
struct IncreaseLiquidity {
    token_id: u256,
    liquidity: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name      | Type | Description                                                      |
| --------- | ---- | ---------------------------------------------------------------- |
| token\_id | u256 | The ID of the token for which liquidity was increased            |
| liquidity | u128 | The amount by which liquidity for the NFT position was increased |
| amount0   | u256 | The amount of token0 that was paid for the increase in liquidity |
| amount1   | u256 | The amount of token1 that was paid for the increase in liquidity |

#### DecreaseLiquidity <a href="#event_decreaseliquidity" id="event_decreaseliquidity"></a>

```rust
struct DecreaseLiquidity {
    token_id: u256,
    liquidity: u128,
    amount0: u256,
    amount1: u256
}
```

**Parameters:**

| Name      | Type | Description                                                           |
| --------- | ---- | --------------------------------------------------------------------- |
| token\_id | u256 | The ID of the token for which liquidity was decreased                 |
| liquidity | u128 | The amount by which liquidity for the NFT position was decreased      |
| amount0   | u256 | The amount of token0 that was accounted for the decrease in liquidity |
| amount1   | u256 | The amount of token1 that was accounted for the decrease in liquidity |

#### Collect <a href="#event_collect" id="event_collect"></a>

```rust
struct Collect {
    token_id: u256,
    recipient: ContractAddress,
    amount0_collect: u128,
    amount1_collect: u128
}
```

The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior

**Parameters:**

| Name             | Type            | Description                                                    |
| ---------------- | --------------- | -------------------------------------------------------------- |
| token\_id        | u256            | The ID of the token for which underlying tokens were collected |
| recipient        | ContractAddress | The address of the account that received the collected tokens  |
| amount0\_collect | u128            | The amount of token0 owed to the position that was collected   |
| amount1\_collect | u128            | The amount of token1 owed to the position that was collected   |

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

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

// @notice The identifying key of the pool
struct PoolKey {
    // @notice The first of the two tokens of the pool, sorted by address
    token0: ContractAddress,
    // @notice The second of the two tokens of the pool, sorted by address
    token1: ContractAddress,
    // @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    fee: u32
}

// @notice details about the JediSwap V2 position
struct PositionDetail {
    // @notice The address that is approved for spending this token
    operator: ContractAddress,
    // @notice The ID of the pool with which this token is connected
    pool_id: u64,
    // @notice The lower tick of the position
    tick_lower: i32,
    // @notice The upper tick of the position
    tick_upper: i32,
    // @notice The liquidity of the position
    liquidity: u128,
    // @notice The fee growth of the aggregate position as of the last action on the individual position, for token0
    fee_growth_inside_0_last_X128: u256,
    // @notice The fee growth of the aggregate position as of the last action on the individual position, for token1
    fee_growth_inside_1_last_X128: u256,
    // @notice Uncollected token0 owed to the position, as of the last computation
    tokens_owed_0: u128,
    // @notice Uncollected token1 owed to the position, as of the last computation
    tokens_owed_1: u128
}

struct MintParams {
    token0: ContractAddress,
    token1: ContractAddress,
    fee: u32,
    tick_lower: i32,
    tick_upper: i32,
    amount0_desired: u256,
    amount1_desired: u256,
    amount0_min: u256,
    amount1_min: u256,
    recipient: ContractAddress,
    deadline: u64
}

struct IncreaseLiquidityParams {
    token_id: u256,
    amount0_desired: u256,
    amount1_desired: u256,
    amount0_min: u256,
    amount1_min: u256,
    deadline: u64
}

struct DecreaseLiquidityParams {
    token_id: u256,
    liquidity: u128,
    amount0_min: u256,
    amount1_min: u256,
    deadline: u64
}

struct CollectParams {
    token_id: u256,
    recipient: ContractAddress,
    amount0_max: u128,
    amount1_max: u128
}

#[starknet::interface]
trait IJediSwapV2NFTPositionManager<TContractState> {
    fn get_factory(self: @TContractState) -> ContractAddress;
    fn get_position(self: @TContractState, token_id: u256) -> (PositionDetail, PoolKey);

    fn mint(ref self: TContractState, params: MintParams) -> (u256, u128, u256, u256);
    fn increase_liquidity(ref self: TContractState, params: IncreaseLiquidityParams) -> (u128, u256, u256);
    fn decrease_liquidity(ref self: TContractState, params: DecreaseLiquidityParams) -> (u256, u256);
    fn collect(ref self: TContractState, params: CollectParams) -> (u128, u128);
    fn burn(ref self: TContractState, token_id: u256);
    fn create_and_initialize_pool(ref self: TContractState, token0: ContractAddress, token1: ContractAddress, fee: u32, sqrt_price_X96: u256) -> ContractAddress;
    fn jediswap_v2_mint_callback(ref self: TContractState, amount0_owed: u256, amount1_owed: u256, callback_data_span: Span<felt252>);
}
```


---

# 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/periphery/jediswap_v2_nft_position_manager.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.
