# Pool

### pool

* [Description](#description)
* [Data Storage](#data-storage)
* [Interface](#interface)
* [Messages](#messages)

## Description

This contract implements V3 like functionality of the pool with concentrated liquidity.

Due to the new storage organization and availability of the **dict** data type we don't need the tickBitmap data structures. However, gas consumption while using the dict is also quite significant

## Data Storage

<table data-full-width="true"><thead><tr><th width="70">Index</th><th width="100">Type</th><th width="100">Size (b/r)</th><th width="58">Cell</th><th width="280">Name</th><th>Description</th></tr></thead><tbody><tr><td>1</td><td>addr</td><td>267 / 0</td><td>1</td><td>poolv3::router_address</td><td>Address of the router contract that created this pool (totally immutable set at creation )</td></tr><tr><td>2</td><td>uint16</td><td>16 / 0</td><td>1</td><td>poolv3::lp_fee_base</td><td>Liquidity provider fee. base in FEE_DENOMINATOR parts</td></tr><tr><td>3</td><td>uint16</td><td>16 / 0</td><td>1</td><td>poolv3::protocol_fee</td><td>Protocol fee in FEE_DENOMINATOR</td></tr><tr><td>4</td><td>uint16</td><td>16 / 0</td><td>1</td><td>poolv3::lp_fee_current</td><td>Current value of the pool fee, in case of dynamic adjustment</td></tr><tr><td>5</td><td>addr</td><td>267 / 0</td><td>1</td><td>poolv3::jetton0_wallet</td><td>Address of the 0 token in the pool. This is an address of the jetton0 wallet attached to router</td></tr><tr><td>6</td><td>addr</td><td>267 / 0</td><td>1</td><td>poolv3::jetton1_wallet</td><td>Address of the 1 token in the pool This is an address of the jetton0 wallet attached to router</td></tr><tr><td>7</td><td>int24</td><td>24 / 0</td><td>1</td><td>poolv3::tick_spacing</td><td>Spacing of the ticks, 24 bits of signed int would be used</td></tr><tr><td>8</td><td>uint64</td><td>64 / 0</td><td>1</td><td>poolv3::seqno</td><td>Used by indexer to ensure that none of pool interactions are skipped</td></tr><tr><td>9</td><td>uint256</td><td>256 / 0</td><td>11</td><td>poolv3::feeGrowthGlobal0X128</td><td>This variable stores current collected fee per the unit of liquidity in jetton0</td></tr><tr><td>10</td><td>uint256</td><td>256 / 0</td><td>11</td><td>poolv3::feeGrowthGlobal1X128</td><td>This variable stores current collected fee per the unit of liquidity in jetton0</td></tr><tr><td>11</td><td>uint128</td><td>128 / 0</td><td>11</td><td>poolv3::collectedProtocolFee0</td><td>Collected protocol fee of the jetton0</td></tr><tr><td>12</td><td>uint128</td><td>128 / 0</td><td>11</td><td>poolv3::collectedProtocolFee1</td><td>Collected protocol fee of the jetton1</td></tr><tr><td>13</td><td>coins</td><td>124 / 0</td><td>11</td><td>poolv3::reserve0</td><td>These are additional separate protection system - it calculates the reserves of the pool<br>In case main math has a bug it protects the funds of other pools. Reserve of the jetton0</td></tr><tr><td>14</td><td>coins</td><td>124 / 0</td><td>11</td><td>poolv3::reserve1</td><td>Reserve of the jetton1</td></tr><tr><td>15</td><td>uint1</td><td>1 / 0</td><td>12</td><td>poolv3::pool_active</td><td>Pool acitve flag 0 is inactive, 1 is active</td></tr><tr><td>16</td><td>int24</td><td>24 / 0</td><td>12</td><td>poolv3::tick</td><td>Current tick, signed, 24 bits would be used. Pool maintains it in correspondence to poolv3::price_sqrt</td></tr><tr><td>17</td><td>uint160</td><td>160 / 0</td><td>12</td><td>poolv3::price_sqrt</td><td>Current square root of the price in Q64.96 format using 160 bits</td></tr><tr><td>18</td><td>uint128</td><td>128 / 0</td><td>12</td><td>poolv3::liquidity</td><td>Current active concentrated liquidity in 128 bits</td></tr><tr><td>19</td><td>uint24</td><td>24 / 0</td><td>12</td><td>poolv3::occupied_ticks</td><td>number of occupied ticks in storage</td></tr><tr><td>20</td><td>uint64</td><td>64 / 0</td><td>12</td><td>poolv3::nftv3item_counter</td><td>Pool is also an NFT collection. So this is the counter of currently minted positions</td></tr><tr><td>21</td><td>uint64</td><td>64 / 0</td><td>12</td><td>poolv3::nftv3items_active</td><td>Pool is also an NFT collection. Number of unburnt items</td></tr><tr><td>22</td><td>addr</td><td>267 / 0</td><td>12</td><td>poolv3::admin_address</td><td>Admin address. Can init pool</td></tr><tr><td>23</td><td>addr</td><td>267 / 0</td><td>12</td><td>poolv3::controller_address</td><td>Controller address. Can change fee and lock and unlock pool</td></tr><tr><td>24</td><td>addr</td><td>267 / 0</td><td>121</td><td>poolv3::jetton0_minter</td><td>Address of the 0 token minter. Beta only.</td></tr><tr><td>25</td><td>addr</td><td>267 / 0</td><td>121</td><td>poolv3::jetton1_minter</td><td>Address of the 1 token minter. Beta only.</td></tr><tr><td>26</td><td>dict</td><td>0 / 1</td><td>13</td><td>poolv3::ticks_dictionary</td><td>Storage of the ticks</td></tr><tr><td>27</td><td>code</td><td>0 / 1</td><td>14</td><td>poolv3::accountv3_code</td><td>Pool knows how to create user accounts to store fund pairs for a particular user</td></tr><tr><td>28</td><td>code</td><td>0 / 1</td><td>14</td><td>poolv3::position_nftv3_code</td><td>Pool knows how to create user position. So it stores it's code</td></tr><tr><td>29</td><td>cell</td><td>0 / 1</td><td>14</td><td>poolv3::nftv3_content</td><td>packed metadata that would be given to nft that corresponds to nft collection</td></tr><tr><td>30</td><td>cell</td><td>0 / 1</td><td>14</td><td>poolv3::nftv3item_content</td><td>packed metadata that would be given to nft that corresponds to the position</td></tr></tbody></table>

## Cells

| Name | Size | Free |
| ---- | ---- | ---- |
| 1    | 937  | 86   |
| 11   | 1016 | 7    |
| 12   | 999  | 24   |
| 13   | 0    | 1023 |
| 14   | 0    | 1023 |
| 121  | 534  | 489  |

## Interface

### getIsActive

(int) getIsActive ()

Returns is pool is active

#### Return Values

| # | Type | Description                             |
| - | ---- | --------------------------------------- |
| 0 | int  | int containing the poolv3::pool\_active |

### getPoolStateAndConfiguration

(slice, slice, slice, slice, slice, slice, slice, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int ) getPoolStateAndConfiguration ()

Returns pool state and configuration

#### Return Values

| #  | Type  | Description                                                |
| -- | ----- | ---------------------------------------------------------- |
| 0  | slice | Router address                                             |
| 1  | slice | Admin address                                              |
| 2  | slice | Controller address                                         |
| 3  | slice | Jetton 0 Wallet address. The wallet is owned by the Router |
| 4  | slice | Jetton 1 Wallet address. The wallet is owned by the Router |
| 5  | slice | Jetton 0 Minter address.                                   |
| 6  | slice | Jetton 1 Minter address.                                   |
| 7  | int   | Flag that denotes if the pool is active                    |
| 8  | int   | Pool tick spacing                                          |
| 9  | int   | Fee that is used as a base. Stored in x 1/10000            |
| 10 | int   | Fee that protocol takes. Stored in x 1/10000               |
| 11 | int   | Fee that is currently active. Stored in x 1/10000          |
| 12 | int   | Current tick                                               |
| 13 | int   | Current price                                              |
| 14 | int   | Current liquidity                                          |
| 15 | int   | poolv3::feeGrowthGlobal0X128                               |
| 16 | int   | poolv3::feeGrowthGlobal1X128                               |
| 17 | int   | Amount of jetton0 fee collected for protocol owners        |
| 18 | int   | Amount of jetton0 fee collected for protocol owners        |
| 19 | int   | Number of total minted NFT positions                       |
| 20 | int   | Reserves of the jetton0                                    |
| 21 | int   | Reserves of the jetton1                                    |
| 22 | int   | Number of active NFT positions                             |
| 23 | int   | Number of currently occupied ticks                         |
| 24 | int   | Number of operations with pool since the deploy            |

### getChildContracts

(cell, cell, cell, cell) getChildContracts ()

#### Return Values

| # | Type | Description                       |
| - | ---- | --------------------------------- |
| 0 | cell | code of the account contract      |
| 1 | cell | code of the nft position contract |
| 2 | cell | metadata for NFT Collection       |
| 3 | cell | metadata for NFT Item             |

### getAllTickInfos

(cell) getAllTickInfos ()

returns the cell with all the ticks.

#### Return Values

| # | Type | Description                                     |
| - | ---- | ----------------------------------------------- |
| 0 | cell | cell that contains the dict with all the ticks. |

### getTickInfosFrom

(tuple) getTickInfosFrom (int key, int amount, int dir, int full)

Returns ticks starting form key (non-inclusive)

* 0 forward
* 1 backward

#### Parameters

| # | Type | Name   | Description                                                      |
| - | ---- | ------ | ---------------------------------------------------------------- |
| 0 | int  | key    | key (tick number) from which to get data                         |
| 1 | int  | amount | amount of ticks to get (large values would fail with out of gas) |
| 2 | int  | dir    | 0 - for forward search, 1 - for backward                         |
| 3 | int  | full   | with true (non zero) would fill fee counter values               |

### getCollectedFees

(int, int) getCollectedFees (int tickLower, int tickUpper, int posLiquidityDelta, int posFeeGrowthInside0X128, int posFeeGrowthInside1X128)

Predicts how much fees a position can collect

#### Parameters

| # | Type | Name                    | Description |
| - | ---- | ----------------------- | ----------- |
| 0 | int  | tickLower               |             |
| 1 | int  | tickUpper               |             |
| 2 | int  | posLiquidityDelta       |             |
| 3 | int  | posFeeGrowthInside0X128 |             |
| 4 | int  | posFeeGrowthInside1X128 |             |

#### Return Values

| # | Type | Description                         |
| - | ---- | ----------------------------------- |
| 0 | int  | amount of jetton0 that is collected |
| 1 | int  | amount of jetton1 that is collected |

### getUserAccountAddress

(slice) getUserAccountAddress (slice user\_address)

computes user account address for a given user

#### Parameters

| # | Type  | Name          | Description                                    |
| - | ----- | ------------- | ---------------------------------------------- |
| 0 | slice | user\_address | address for witch account address is requested |

#### Return Values

| # | Type  | Description     |
| - | ----- | --------------- |
| 0 | slice | account address |

### getMintEstimate

(int, int, int) getMintEstimate (int tickLower, int tickUpper, int liquidity)

Computes estimates for the mint

#### Parameters

| # | Type | Name      | Description                            |
| - | ---- | --------- | -------------------------------------- |
| 0 | int  | tickLower | lower tick for the desired position    |
| 1 | int  | tickUpper | upper tick for the desired position    |
| 2 | int  | liquidity | liquidity that is planned to be minted |

#### Return Values

| # | Type | Description                                                          |
| - | ---- | -------------------------------------------------------------------- |
| 0 | int  | amount of jetton0 needed to mint the position                        |
| 1 | int  | amount of jetton1 needed to mint the position                        |
| 2 | int  | error code that shows if the basic checks for the mint would succeed |

### getSwapEstimate

(int, int) getSwapEstimate (int zeroForOne, int amount, int sqrtPriceLimitX96)

**Deprecated. Use getSwapEstimateGas instead**

Computes estimates fot the swap

#### Parameters

| # | Type | Name              | Description                                                                                       |
| - | ---- | ----------------- | ------------------------------------------------------------------------------------------------- |
| 0 | int  | zeroForOne        | direction of the swap zeroForOne !=0 - swap jetton0 for jetton1, otherwise jetton1 for jetton0    |
| 1 | int  | amount            | amount of input token for the swap                                                                |
| 2 | int  | sqrtPriceLimitX96 | limit price (formatted as fixed point 64.96 square root of the price).If reached - swap will stop |

#### Return Values

| # | Type | Description                                              |
| - | ---- | -------------------------------------------------------- |
| 0 | int  | amount of jetton0 that would be put to/get from the pool |
| 1 | int  | amount of jetton1 that would be put to/get from the pool |

### getSwapEstimateGas

(int, int) getSwapEstimateGas (int zeroForOne, int amount, int sqrtPriceLimitX96, int minOutAmount, int gasLimit)

Computes estimates for the swap

#### Parameters

| # | Type | Name              | Description                                                                                                                                                           |
| - | ---- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0 | int  | zeroForOne        | direction of the swap zeroForOne !=0 - swap jetton0 for jetton1, otherwise jetton1 for jetton0                                                                        |
| 1 | int  | amount            | amount of input token for the swap                                                                                                                                    |
| 2 | int  | sqrtPriceLimitX96 | limit price (formatted as fixed point 64.96 square root of the price).If reached - swap will stop (swap would succeed remaining input amount would return as change ) |
| 3 | int  | minOutAmount      | minimum amount. If return value would be less than this, swap will be reverted                                                                                        |
| 4 | int  | gasLimit          | amount of gas (in gas units). If gasLimit is 0 - default value is used - that equals to contract gas limit from the config                                            |

#### Return Values

| # | Type | Description                                              |
| - | ---- | -------------------------------------------------------- |
| 0 | int  | amount of jetton0 that would be put to/get from the pool |
| 1 | int  | amount of jetton1 that would be put to/get from the pool |

### get\_collection\_data

(int, cell, slice) get\_collection\_data ()

In accordance with TEP-62

#### Return Values

| # | Type  | Description                |
| - | ----- | -------------------------- |
| 0 | int   | poolv3::nftv3item\_counter |
| 1 | cell  | poolv3::nftv3\_content     |
| 2 | slice | poolv3::router\_address    |

### get\_nft\_address\_by\_index

(slice) get\_nft\_address\_by\_index (int index)

In accordance with TEP-62

#### Parameters

| # | Type | Name  | Description                               |
| - | ---- | ----- | ----------------------------------------- |
| 0 | int  | index | index of the requested NFT (Position NFT) |

#### Return Values

| # | Type  | Description                 |
| - | ----- | --------------------------- |
| 0 | slice | address of the Position NFT |

### get\_nft\_content

(cell) get\_nft\_content (int index, cell nftv3item\_content)

In accordance with TEP-62 we will form the output NFT onchain metadata

If NFTItemContent "description" field that is passed to the pool by the pool administrator (poolv3::nftv3item\_content) begins with marker "%N%", data from the NFT is added to the beginning of the "description" field. If there is no data attached to the dictionary by the NFT, NFTItemContent description is unchanged

#### Parameters

| # | Type | Name               | Description                                               |
| - | ---- | ------------------ | --------------------------------------------------------- |
| 0 | int  | index              | index of the requested NFT                                |
| 1 | cell | nftv3item\_content | NFT content returned from the get\_nft\_data() of the NFT |

#### Return Values

| # | Type | Description               |
| - | ---- | ------------------------- |
| 0 | cell | cell with metadata dict() |

## Messages

### POOLV3\_INIT

Opcode : **0x441c39ed**

The first mandatory operation that fills crucial parameters of the pool\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>from_admin</td><td>Uint(1),Bool</td><td>Flag that shows if this message goes from router admin or pool factory</td></tr><tr><td></td><td>has_admin</td><td>Uint(1),Bool</td><td>Flag that shows if this message have a new admin address</td></tr><tr><td></td><td>admin_addr</td><td>Address(267)</td><td>New address of the admin. If has_admin is false could be 00b</td></tr><tr><td></td><td>has_controller</td><td>Uint(1),Bool</td><td>Flag that shows if this message have a new controller address</td></tr><tr><td></td><td>controller_addr</td><td>Address(267)</td><td>Address that is allowed to change the fee. Can always be updated by admin. If has_controller is false could be 00b</td></tr><tr><td></td><td>set_spacing</td><td>Uint(1),Bool</td><td>Flag that shows if tick_spacing should be set to the pool or ignored</td></tr><tr><td></td><td>tick_spacing</td><td>Int(24)</td><td>Tick spacing to be used in the pool</td></tr><tr><td></td><td>set_price</td><td>Uint(1),Bool</td><td>Flag that shows if initial_priceX96 should be set to the pool or ignored</td></tr><tr><td></td><td>initial_priceX96</td><td>Uint(160),PriceX96</td><td>Initial price for the pool</td></tr><tr><td></td><td>set_active</td><td>Uint(1),Bool</td><td>Flag that shows if pool_active should be set to the pool or ignored</td></tr><tr><td></td><td>pool_active</td><td>Uint(1),Bool</td><td>Flag is we should start the pool as unlocked</td></tr><tr><td></td><td>protocol_fee</td><td>Uint(16),Fee</td><td>Liquidity provider fee. base in FEE_DENOMINATOR parts. If value is more than 10000 value would be default</td></tr><tr><td></td><td>lp_fee_base</td><td>Uint(16),Fee</td><td>Protocol fee in FEE_DENOMINATOR. If value is more than 10000 value would be default</td></tr><tr><td></td><td>lp_fee_current</td><td>Uint(16),Fee</td><td>Current value of the pool fee, in case of dynamic adjustment. If value is more than 10000 value would be default</td></tr><tr><td></td><td>nftv3_content</td><td>Cell(0),Metadata</td><td>Metadata for the NFT Collection</td></tr><tr><td></td><td>nftv3item_content</td><td>Cell(0),Metadata</td><td>Metadata for the NFT Item</td></tr><tr><td></td><td>0</td><td>Maybe Cell(1) minter_cell</td><td>Cell With Minters</td></tr><tr><td>0</td><td>jetton0_minter</td><td>Address(267)</td><td>Address of the jetton0 minter, used by indexer and frontend</td></tr><tr><td>0</td><td>jetton1_minter</td><td>Address(267)</td><td>Address of the jetton1 minter, used by indexer and frontend</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_INIT" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_INIT#441c39ed 
    query_id:uint64
    from_admin:uint1
    has_admin:uint1
    admin_addr:MsgAddress
    has_controller:uint1
    controller_addr:MsgAddress
    set_spacing:uint1
    tick_spacing:int24
    set_price:uint1
    initial_priceX96:uint160
    set_active:uint1
    pool_active:uint1
    protocol_fee:uint16
    lp_fee_base:uint16
    lp_fee_current:uint16
    nftv3_content:Cell
    nftv3item_content:Cell
    minter_cell:(Maybe ^[
        jetton0_minter:MsgAddress
        jetton1_minter:MsgAddress
    ] ) 
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_LOCK

Opcode : **0x5e74697**

This operation locks the pool. This is allowed to do by the operator and the admin\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_LOCK" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_LOCK#5e74697 
    query_id:uint64
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_UNLOCK

Opcode : **0x3205adbd**

This operation locks the pool. This is allowed to do by the operator and the admin\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_UNLOCK" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_UNLOCK#3205adbd 
    query_id:uint64
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_MINT

Opcode : **0x81702ef8**

\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>amount0Funded</td><td>Coins(124)</td><td>Amount of jetton 0 received by router for the mint</td></tr><tr><td></td><td>amount1Funded</td><td>Coins(124)</td><td>Amount of jetton 1 recived by router for the mint</td></tr><tr><td></td><td>recipient</td><td>Address(267)</td><td>Address that would receive the minted NFT, excesses and refunds</td></tr><tr><td></td><td>liquidity</td><td>Uint(128)</td><td>Amount of liquidity to mint</td></tr><tr><td></td><td>tickLower</td><td>Int(24)</td><td>lower bound of the range in which to mint</td></tr><tr><td></td><td>tickUpper</td><td>Int(24)</td><td>upper bound of the range in which to mint</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_MINT" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_MINT#81702ef8 
    query_id:uint64
    amount0Funded:(VarUInteger 16)
    amount1Funded:(VarUInteger 16)
    recipient:MsgAddress
    liquidity:uint128
    tickLower:int24
    tickUpper:int24
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_BURN

Opcode : **0xd73ac09d**

Burn whole or part of nft. Is sent by [Position NFT](https://docs.tonco.io/dokumentaciya-i-gaidy/technical-reference/contracts/position_nft) itself, would only be accepted from the correct NFT itself\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>recipient</td><td>Address(267)</td><td>NFT owner to receive funds</td></tr><tr><td></td><td>burned_index</td><td>Uint(64)</td><td>Index if the NFT to burn. Should match the sender address</td></tr><tr><td></td><td>liquidity</td><td>Uint(128)</td><td>NFT liquidity amount prior to burn</td></tr><tr><td></td><td>tickLower</td><td>Int(24)</td><td>Lower tick of the NFT. Sanitized by NFTPosition contract</td></tr><tr><td></td><td>tickUpper</td><td>Int(24)</td><td>Upper tick of the NFT. Sanitized by NFTPosition contract</td></tr><tr><td></td><td>liquidity2Burn</td><td>Uint(128)</td><td>Amount of the liquidity to burn, 0 is a valid amount, in this case only collected fees would be returned</td></tr><tr><td></td><td>0</td><td>Cell(0) old_fee_cell</td><td>Fee counters to collect from</td></tr><tr><td>0</td><td>feeGrowthInside0LastX128</td><td>Uint(256),x128</td><td>Fee counter inside position range for jetton0, per unit of liquidity, in 128.128 fixed point</td></tr><tr><td>0</td><td>feeGrowthInside1LastX128</td><td>Uint(256),x128</td><td>Fee counter inside position range for jetton1, per unit of liquidity, in 128.128 fixed point</td></tr><tr><td></td><td>1</td><td>Cell(0) new_fee_cell</td><td>Fee counters to collect to (Used by indexer)</td></tr><tr><td>1</td><td>feeGrowthInside0CurrentX128</td><td>Uint(256),x128,Indexer</td><td>Fee counter inside position range for jetton0, per unit of liquidity, in 128.128 fixed point</td></tr><tr><td>1</td><td>feeGrowthInside1CurrentX128</td><td>Uint(256),x128,Indexer</td><td>Fee counter inside position range for jetton1, per unit of liquidity, in 128.128 fixed point</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_BURN" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_BURN#d73ac09d 
    query_id:uint64
    recipient:MsgAddress
    burned_index:uint64
    liquidity:uint128
    tickLower:int24
    tickUpper:int24
    liquidity2Burn:uint128
    old_fee_cell:^[
        feeGrowthInside0LastX128:uint256
        feeGrowthInside1LastX128:uint256
    ]  
    new_fee_cell:^[
        feeGrowthInside0CurrentX128:uint256
        feeGrowthInside1CurrentX128:uint256
    ]  
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_SET\_FEE

Opcode : **0x6bdcbeb8**

This operation sets the fee values for the pool. This is allowed to do by the operator and the admin\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>protocol_fee</td><td>Uint(16)</td><td>Liquidity provider fee. base in FEE_DENOMINATOR parts</td></tr><tr><td></td><td>lp_fee_base</td><td>Uint(16)</td><td>Protocol fee in FEE_DENOMINATOR</td></tr><tr><td></td><td>lp_fee_current</td><td>Uint(16)</td><td>Current value of the pool fee, in case of dynamic adjustment</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_SET\_FEE" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_SET_FEE#6bdcbeb8 
    query_id:uint64
    protocol_fee:uint16
    lp_fee_base:uint16
    lp_fee_current:uint16
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_FUND\_ACCOUNT

Opcode : **0x4468de77**

Proxy proof of the jettons funding and mint request to the AccountV3. For more information refer to [AccountV3](https://docs.tonco.io/dokumentaciya-i-gaidy/technical-reference/contracts/account)\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>owner_addr</td><td>Address(267)</td><td>Address that would receive the minted NFT, excesses and refunds</td></tr><tr><td></td><td>amount0</td><td>Coins(124)</td><td>Amount of jetton0 that is funded for the mint</td></tr><tr><td></td><td>amount1</td><td>Coins(124)</td><td>Amount of jetton1 that is funded for the mint</td></tr><tr><td></td><td>enough0</td><td>Coins(124)</td><td>Minimum amount of jetton0 totally collected on the account that is required to start the mint</td></tr><tr><td></td><td>enough1</td><td>Coins(124)</td><td>Minimum amount of jetton1 totally collected on the account that is required to start the mint</td></tr><tr><td></td><td>liquidity</td><td>Uint(128)</td><td>Amount of liquidity to mint</td></tr><tr><td></td><td>tickLower</td><td>Int(24)</td><td>lower bound of the range in which to mint</td></tr><tr><td></td><td>tickUpper</td><td>Int(24)</td><td>upper bound of the range in which to mint</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_FUND\_ACCOUNT" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_FUND_ACCOUNT#4468de77 
    query_id:uint64
    owner_addr:MsgAddress
    amount0:(VarUInteger 16)
    amount1:(VarUInteger 16)
    enough0:(VarUInteger 16)
    enough1:(VarUInteger 16)
    liquidity:uint128
    tickLower:int24
    tickUpper:int24
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_START\_BURN

Opcode : **0x530b5f2c**

Burn whole or part of nft. Can be called by anyone, but if not called be the owner - would fail later. This operation would compute the amount of the fees that the position is eligible to get and then forwards a message to the [Position NFT](https://docs.tonco.io/dokumentaciya-i-gaidy/technical-reference/contracts/position_nft) contract\ <br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>burned_index</td><td>Uint(64)</td><td>Index if the NFT to burn</td></tr><tr><td></td><td>liquidity2Burn</td><td>Uint(128)</td><td>Amount of the liquidity to burn, 0 is a valid amount, in this case only collected fees would be returned</td></tr><tr><td></td><td>tickLower</td><td>Int(24)</td><td>Lower tick of the NFT. Should match the real one</td></tr><tr><td></td><td>tickUpper</td><td>Int(24)</td><td>Upper tick of the NFT. Should match the real one</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_START\_BURN" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_START_BURN#530b5f2c 
    query_id:uint64
    burned_index:uint64
    liquidity2Burn:uint128
    tickLower:int24
    tickUpper:int24
= ContractMessages;
```

{% endcode %}

</details>

### POOLV3\_SWAP

Opcode : **0xa7fb58f8**

Computes the swap math, and issues a command to the router to send funds. Only would be accepted from the router This operation we have several input parameters that would affect the result of the swap

| Condition                                                                         | Swap result                  | Returned Change | Error Code                       |
| --------------------------------------------------------------------------------- | ---------------------------- | --------------- | -------------------------------- |
| Swap finished sqrtPriceLimitX96 not reached. minOutAmount surpassed               | total output number of coins | 0               | RESULT\_SWAP\_OK                 |
| Swap finished minOutAmount not surpassed                                          | 0                            | amount          | RESULT\_SWAP\_OUTPUT\_TOO\_SMALL |
| Swap reached sqrtPriceLimitX96 after changing part1 coins. minOutAmount surpassed | output number of coins       | amount - part1  | RESULT\_SWAP\_OK                 |

\
Access Rights: This operation is allowed for poolv3::router\_address<br>

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>owner_address</td><td>Address(267)</td><td>Owner of the liquidity in swap</td></tr><tr><td></td><td>source_wallet</td><td>Address(267)</td><td>jetton wallet attached to the router. used to identify swap direction</td></tr><tr><td></td><td>0</td><td>Cell(0) params_cell</td><td>Fee counters To (Used by indexer)</td></tr><tr><td>0</td><td>amount</td><td>Coins(124)</td><td>Input amount of the jettons to be swapped</td></tr><tr><td>0</td><td>sqrtPriceLimitX96</td><td>Uint(160),PriceX96</td><td>Limit marginal price. Swap won't go beyond it.</td></tr><tr><td>0</td><td>minOutAmount</td><td>Coins(124)</td><td>Minimum amount of the output jettons to get back. If not reached, your input would be returned to you</td></tr><tr><td></td><td>1</td><td>Cell(0) payloads_cell</td><td>Cell with payloads for swap result and change</td></tr><tr><td>1</td><td>target_address</td><td>Address(267)</td><td>Target will receive the result of the swap. Could be addr_none() (*00b*) then owner_address is used</td></tr><tr><td>1</td><td>ok_forward_amount</td><td>Coins(124)</td><td>Amount of TON to use for forward payload that would be sent with the result of the swap</td></tr><tr><td>1</td><td>ok_forward_payload</td><td>Cell(0),Maybe,Payload</td><td>Payload that would be sent with the jettons of the result of the swap</td></tr><tr><td>1</td><td>ret_forward_amount</td><td>Coins(124)</td><td>Amount of TON to use for forward payload that would be sent with the change for the swap (if any)</td></tr><tr><td>1</td><td>ret_forward_payload</td><td>Cell(0),Maybe,Payload</td><td>Payload that would be sent with the jettons of the change of the swap (if any)</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOLV3\_SWAP" overflow="wrap" lineNumbers="true" %}

```javascript
POOLV3_SWAP#a7fb58f8 
    query_id:uint64
    owner_address:MsgAddress
    source_wallet:MsgAddress
    params_cell:^[
        amount:(VarUInteger 16)
        sqrtPriceLimitX96:uint160
        minOutAmount:(VarUInteger 16)
    ]  
    payloads_cell:^[
        target_address:MsgAddress
        ok_forward_amount:(VarUInteger 16)
        ok_forward_payload:(Maybe ^Cell)
        ret_forward_amount:(VarUInteger 16)
        ret_forward_payload:(Maybe ^Cell)
    ]  
= ContractMessages;
```

{% endcode %}

</details>
