> For the complete documentation index, see [llms.txt](https://docs.tonco.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tonco.io/contracts-v1.6-forthcoming/pool.md).

# Pool

### pool

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

## Description

The **Pool** is the core AMM contract — a concentrated-liquidity (Uniswap-V3-style) pool with price in Q64.96, tick ranges and per-unit-of-liquidity fee growth. It owns the swap math, the tick dictionary and the reserves, and orchestrates mint/burn through the user [Account](/contracts-v1.6-forthcoming/account.md) and [Position NFT](/contracts-v1.6-forthcoming/position_nft.md) sub-contracts (whose addresses it re-derives to authorize them). Swaps and fund flows arrive proxied from the [Router](/contracts-v1.6-forthcoming/router.md); funds leave via the router's PAY\_TO. Locking a pool blocks mint and swap but never burn.

## Interface

### getIsActive

(int) getIsActive ()

Returns is pool is active

#### Return Values

| # | Type | Description                           |
| - | ---- | ------------------------------------- |
| 0 | int  | int containing the pool::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, slice, int, slice, slice, slice, 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   | pool::feeGrowthGlobal0X128                                 |
| 16 | int   | pool::feeGrowthGlobal1X128                                 |
| 17 | int   | Amount of jetton0 fee collected for protocol owners        |
| 18 | int   | Amount of jetton1 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            |
| 25 | slice | Arbiter address                                            |
| 26 | int   | Pool version (e.g. 16000 = v1.6.000)                       |
| 27 | slice | ALM address                                                |
| 28 | slice | Creator address                                            |
| 29 | slice | Oracle address                                             |
| 30 | int   | Pool flags                                                 |

### getChildContracts

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

returns the subcontract codes and NFT metadata used by the pool

#### 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                                     |
| - | ---- | ----------------------------------------------- |
| 1 | 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    |             |
| 1 | int  | amount |             |
| 2 | int  | dir    |             |
| 3 | int  | full   |             |

#### Return Values

| # | Type  | Description       |
| - | ----- | ----------------- |
| 0 | tuple | a tuple with keys |

### getFeeGrowthInside

(int, int) getFeeGrowthInside (int tickLower, int tickUpper, int posLiquidityDelta, int feeGrowthGlobal0X128, int feeGrowthGlobal1X128)

Helper method to estimate fee growth inside a given position

#### Parameters

| # | Type | Name                 | Description |
| - | ---- | -------------------- | ----------- |
| 0 | int  | tickLower            |             |
| 1 | int  | tickUpper            |             |
| 2 | int  | posLiquidityDelta    |             |
| 3 | int  | feeGrowthGlobal0X128 |             |
| 4 | int  | feeGrowthGlobal1X128 |             |

#### Return Values

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

### 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 of the user to compute the account for |

#### 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 |             |
| 1 | int  | tickUpper |             |
| 2 | int  | liquidity |             |

#### 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** Computes estimates fot the swap

#### Parameters

| # | Type | Name              | Description |
| - | ---- | ----------------- | ----------- |
| 0 | int  | zeroForOne        |             |
| 1 | int  | amount            |             |
| 2 | int  | sqrtPriceLimitX96 |             |

#### 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        |                                                                                                                            |
| 1 | int  | amount            |                                                                                                                            |
| 2 | int  | sqrtPriceLimitX96 |                                                                                                                            |
| 3 | int  | minOutAmount      |                                                                                                                            |
| 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   |             |
| 1 | cell  |             |
| 2 | slice |             |

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

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

In accordance with TEP-62

#### Return Values

| # | Type  | Description |
| - | ----- | ----------- |
| 0 | slice |             |

### get\_nft\_content

(cell) get\_nft\_content (int index, cell nftitem\_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 (pool::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

#### Return Values

| # | Type | Description |
| - | ---- | ----------- |
| 0 | cell |             |

### get\_pending\_timelocks

(int, int, cell, int, slice, int, slice, int, int ) get\_pending\_timelocks ()

Get timelocked changes pending to be applied. Timestamp 0 means - never/timelock not active

#### Return Values

| # | Type  | Description                                         |
| - | ----- | --------------------------------------------------- |
| 0 | int   | Timelock delay                                      |
| 1 | int   | Timestamp when new code can be committed            |
| 2 | cell  | Cell with new code                                  |
| 3 | int   | Timestamp when new ALM address can be committed     |
| 4 | slice | New ALM address                                     |
| 5 | int   | Timestamp when new Arbiter address can be committed |
| 6 | slice | New Arbiter address                                 |
| 7 | int   | Timestamp when new flags can be committed           |
| 8 | int   | New flags                                           |

## Messages

### POOL\_INIT

Opcode : **0x441c39ed**

The first mandatory operation that fills crucial parameters of the pool\
Access Rights: Accepted only from the Router or the Pool Admin. The Router forwards it on behalf of the Router Admin (and, indirectly, the Pool Factory), which is the only way to (re)initialize the pool; re-init on an already-deployed pool is rejected unless it comes from the Pool Admin. A request coming through the Pool Factory cannot assign the ALM Vault or Arbiter roles.<br>

<table data-full-width="true"><thead><tr><th width="90">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>0</td><td>Cell(0) roles_cell</td><td>Cell With Role</td></tr><tr><td>0</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>0</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>0</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>0</td><td>controller_addr</td><td>Address(267)</td><td>Address that is allowed to change the fee. Can always be updated by admin.</td></tr><tr><td>0</td><td>has_creator</td><td>Uint(1),Bool</td><td>Flag that shows if this message have a new creator address</td></tr><tr><td>0</td><td>creator_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>0</td><td>0</td><td>Cell(0) privilege_roles_cell</td><td>Cell With Privilege Roles</td></tr><tr><td>0->0</td><td>has_arbiter</td><td>Uint(1),Bool</td><td>Flag that shows if this message have a new Arbiter address</td></tr><tr><td>0->0</td><td>arbiter_addr</td><td>Address(267)</td><td>Address that is allowed to make privileged swaps</td></tr><tr><td>0->0</td><td>has_alm</td><td>Uint(1),Bool</td><td>Flag that shows if this message have a new ALM address</td></tr><tr><td>0->0</td><td>alm_addr</td><td>Address(267)</td><td>Address that is used to identify ALM contract</td></tr><tr><td>0</td><td>1</td><td>Cell(0) roles_add</td><td>Cell With Additional Roles</td></tr><tr><td>0->1</td><td>has_oracle</td><td>Uint(1),Bool</td><td>Flag that shows if this message have a new oracle address</td></tr><tr><td>0->1</td><td>oracle_addr</td><td>Address(267)</td><td>Address that is allowed to change the fee. Can always be updated by admin. 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>Uint(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>Protocol fee 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>Liquidity provider base 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>set_flags</td><td>Uint(1),Bool</td><td>Is initial flags valid and need to be apply</td></tr><tr><td></td><td>initial_flags</td><td>Uint(32),PoolFlags</td><td>Top 32bits Flag that pool should use</td></tr><tr><td></td><td>1</td><td>Cell(0) code_cell</td><td>Cell With Contract Codes</td></tr><tr><td>1</td><td>pool_code</td><td>Cell(0),Code</td><td>Pool code</td></tr><tr><td>1</td><td>account_code</td><td>Cell(0),Code</td><td>Account code</td></tr><tr><td>1</td><td>position_code</td><td>Cell(0),Code</td><td>Position code</td></tr><tr><td></td><td>2</td><td>Cell(0) content_cell</td><td>Cell With Content</td></tr><tr><td>2</td><td>nft_content</td><td>Cell(0),Metadata</td><td>Metadata for the NFT Collection</td></tr><tr><td>2</td><td>nft_item_content</td><td>Cell(0),Metadata</td><td>Metadata for the NFT Item</td></tr><tr><td></td><td>3</td><td>Maybe Cell(1) minter_cell</td><td>Cell With Minters</td></tr><tr><td>3</td><td>jetton0_minter</td><td>Address(267)</td><td>Address of the jetton0 minter, used by indexer and frontend</td></tr><tr><td>3</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</summary>

This is a preliminary tl-b - subject to change

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

```javascript
POOL_INIT#441c39ed 
    query_id:uint64
    from_admin:uint1
    roles_cell:^Roles_cellType
    set_spacing:uint1
    tick_spacing:uint24
    set_price:uint1
    initial_priceX96:uint160
    set_active:uint1
    pool_active:uint1
    protocol_fee:uint16
    lp_fee_base:uint16
    lp_fee_current:uint16
    set_flags:uint1
    initial_flags:uint32
    code_cell:^Code_cellType
    content_cell:^Content_cellType
    minter_cell:(Maybe ^Minter_cellType)
= ContractMessages;
_ 
    has_arbiter:uint1
    arbiter_addr:MsgAddress
    has_alm:uint1
    alm_addr:MsgAddress
= Privilege_roles_cellType;
_ 
    has_oracle:uint1
    oracle_addr:MsgAddress
= Roles_addType;
_ 
    has_admin:uint1
    admin_addr:MsgAddress
    has_controller:uint1
    controller_addr:MsgAddress
    has_creator:uint1
    creator_addr:MsgAddress
    privilege_roles_cell:^Privilege_roles_cellType
    roles_add:^Roles_addType
= Roles_cellType;
_ 
    pool_code:^Cell
    account_code:^Cell
    position_code:^Cell
= Code_cellType;
_ 
    nft_content:^Cell
    nft_item_content:^Cell
= Content_cellType;
_ 
    jetton0_minter:MsgAddress
    jetton1_minter:MsgAddress
= Minter_cellType;
```

{% endcode %}

</details>

### POOL\_LOCK

Opcode : **0x5e74697**

This operation locks the pool. While locked, only mint and swap are blocked — users can still burn their positions.\
Access Rights: Allowed for the Pool Admin or the Controller (the Controller uses this as a lightweight lock method).<br>

<table data-full-width="true"><thead><tr><th width="90">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</summary>

This is a preliminary tl-b - subject to change

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

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

{% endcode %}

</details>

### POOL\_UNLOCK

Opcode : **0x3205adbd**

This operation unlocks the pool, re-enabling mint and swap.\
Access Rights: Allowed for the Pool Admin or the Controller (the Controller uses this as a lightweight unlock method).<br>

<table data-full-width="true"><thead><tr><th width="90">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</summary>

This is a preliminary tl-b - subject to change

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

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

{% endcode %}

</details>

### POOL\_SET\_FEE

Opcode : **0x6bdcbeb8**

This operation sets the fee values for the pool. This is allowed to do by the operator and the admin\
Access Rights: Allowed for the Pool Admin or the Controller. Sets both the pool fee and the protocol fee.<br>

<table data-full-width="true"><thead><tr><th width="90">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>Protocol fee in FEE_DENOMINATOR parts</td></tr><tr><td></td><td>lp_fee_base</td><td>Uint(16)</td><td>Liquidity provider base 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</summary>

This is a preliminary tl-b - subject to change

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

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

{% endcode %}

</details>

### POOL\_FUND\_ACCOUNT

Opcode : **0x4468de77**

Proxy proof of the jettons funding and mint request to the Account. For more information refer to [Account](/contracts-v1.6-forthcoming/account.md)\
Access Rights: Accepted only from the Router (which relays the user's verified jetton deposit). The pool then credits the user's per-pool Account, whose address is derived from the user, so funds can only reach the rightful owner's Account.<br>

<table data-full-width="true"><thead><tr><th width="90">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>initiator_addr</td><td>Address(267)</td><td>Address that started funding sending</td></tr><tr><td></td><td>0</td><td>Cell(0) funds_cell</td><td>Cell with parameters</td></tr><tr><td>0</td><td>fundFirst</td><td>Uint(1),Boolean</td><td>If the amount the jetton0 in the pool</td></tr><tr><td>0</td><td>amount0</td><td>Coins(124)</td><td>Amount of jetton that is funded for the mint</td></tr><tr><td>0</td><td>amount1</td><td>Coins(124)</td><td>Amount of the other jetton that is funded for the mint (unused)</td></tr><tr><td>0</td><td>inputWallet</td><td>Address(267)</td><td>Address that would be user for sending refund in case of the bounce</td></tr><tr><td></td><td>1</td><td>Maybe Cell(1) order_cell</td><td>Cell with order</td></tr><tr><td>1</td><td>enough0</td><td>Coins(124)</td><td>When temporary storage (user account) satisfy both enough0/1 amounts - mint would trigger</td></tr><tr><td>1</td><td>enough1</td><td>Coins(124)</td><td>When temporary storage (user account) satisfy both enough0/1 amounts - mint would trigger</td></tr><tr><td>1</td><td>needPos</td><td>Uint(64)</td><td>Amount of positions that are enough for the order to be executed</td></tr><tr><td>1</td><td>passthrough</td><td>Uint(4)</td><td>Amount of positions that will be untouched</td></tr><tr><td>1</td><td>target_action</td><td>Uint(32)</td><td>Routing of the reforge result (ACTION_TARGET_DEFAULT / ACTION_TARGET_ALM) — see target_action in ACCOUNT_SET_ORDER for details</td></tr><tr><td>1</td><td>0</td><td>Maybe Cell(1) MintOrder0</td><td>Cell with mint order</td></tr><tr><td>1->0</td><td>op0</td><td>Uint(32)</td><td>Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details</td></tr><tr><td>1->0</td><td>liquidity0</td><td>Uint(128)</td><td>Amount of liquidity to mint</td></tr><tr><td>1->0</td><td>tickLower0</td><td>Int(24)</td><td>lower bound of the range in which to mint</td></tr><tr><td>1->0</td><td>tickUpper0</td><td>Int(24)</td><td>upper bound of the range in which to mint</td></tr><tr><td>1->0</td><td>receiver0</td><td>Address(267)</td><td>Address of receiver of the NFT</td></tr><tr><td>1</td><td>1</td><td>Maybe Cell(1) MintOrder1</td><td>Cell with mint order</td></tr><tr><td>1->1</td><td>op1</td><td>Uint(32)</td><td>Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details</td></tr><tr><td>1->1</td><td>liquidity1</td><td>Uint(128)</td><td>Amount of liquidity to mint</td></tr><tr><td>1->1</td><td>tickLower1</td><td>Int(24)</td><td>lower bound of the range in which to mint</td></tr><tr><td>1->1</td><td>tickUpper1</td><td>Int(24)</td><td>upper bound of the range in which to mint</td></tr><tr><td>1->1</td><td>receiver1</td><td>Address(267)</td><td>Address of receiver of the NFT</td></tr><tr><td>1</td><td>2</td><td>Maybe Cell(1) MintOrder2</td><td>Cell with mint order</td></tr><tr><td>1->2</td><td>op2</td><td>Uint(32)</td><td>Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details</td></tr><tr><td>1->2</td><td>liquidity2</td><td>Uint(128)</td><td>Amount of liquidity to mint</td></tr><tr><td>1->2</td><td>tickLower2</td><td>Int(24)</td><td>lower bound of the range in which to mint</td></tr><tr><td>1->2</td><td>tickUpper2</td><td>Int(24)</td><td>upper bound of the range in which to mint</td></tr><tr><td>1->2</td><td>receiver2</td><td>Address(267)</td><td>Address of receiver of the NFT</td></tr><tr><td>1</td><td>3</td><td>Maybe Cell(1) MintOrder3</td><td>Cell with mint order</td></tr><tr><td>1->3</td><td>op3</td><td>Uint(32)</td><td>Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details</td></tr><tr><td>1->3</td><td>liquidity3</td><td>Uint(128)</td><td>Amount of liquidity to mint</td></tr><tr><td>1->3</td><td>tickLower3</td><td>Int(24)</td><td>lower bound of the range in which to mint</td></tr><tr><td>1->3</td><td>tickUpper3</td><td>Int(24)</td><td>upper bound of the range in which to mint</td></tr><tr><td>1->3</td><td>receiver3</td><td>Address(267)</td><td>Address of receiver of the NFT</td></tr></tbody></table>

<details>

<summary>TL-B Description</summary>

This is a preliminary tl-b - subject to change

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

```javascript
POOL_FUND_ACCOUNT#4468de77 
    query_id:uint64
    owner_addr:MsgAddress
    initiator_addr:MsgAddress
    funds_cell:^Funds_cellType
    order_cell:(Maybe ^Order_cellType)
= ContractMessages;
_ 
    fundFirst:uint1
    amount0:(VarUInteger 16)
    amount1:(VarUInteger 16)
    inputWallet:MsgAddress
= Funds_cellType;
_ 
    op0:uint32
    liquidity0:uint128
    tickLower0:int24
    tickUpper0:int24
    receiver0:MsgAddress
= MintOrder0Type;
_ 
    op1:uint32
    liquidity1:uint128
    tickLower1:int24
    tickUpper1:int24
    receiver1:MsgAddress
= MintOrder1Type;
_ 
    op2:uint32
    liquidity2:uint128
    tickLower2:int24
    tickUpper2:int24
    receiver2:MsgAddress
= MintOrder2Type;
_ 
    op3:uint32
    liquidity3:uint128
    tickLower3:int24
    tickUpper3:int24
    receiver3:MsgAddress
= MintOrder3Type;
_ 
    enough0:(VarUInteger 16)
    enough1:(VarUInteger 16)
    needPos:uint64
    passthrough:uint4
    target_action:uint32
    MintOrder0:(Maybe ^MintOrder0Type)
    MintOrder1:(Maybe ^MintOrder1Type)
    MintOrder2:(Maybe ^MintOrder2Type)
    MintOrder3:(Maybe ^MintOrder3Type)
= Order_cellType;
```

{% endcode %}

</details>

### POOL\_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](/contracts-v1.6-forthcoming/position_nft.md) contract\
Access Rights: May be called by anyone — the pool only reads state here and changes nothing. Real authorization happens downstream: the message is forwarded to the Position NFT, which verifies that the original caller is the NFT owner and that the ticks match before the burn proceeds. A spoofed request just wastes the caller's gas.<br>

<table data-full-width="true"><thead><tr><th width="90">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><tr><td></td><td>action</td><td>Cell(0),Maybe</td><td>Cell that describes what to do with the burn result</td></tr></tbody></table>

<details>

<summary>TL-B Description</summary>

This is a preliminary tl-b - subject to change

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

```javascript
POOL_START_BURN#530b5f2c 
    query_id:uint64
    burned_index:uint64
    liquidity2Burn:uint128
    tickLower:int24
    tickUpper:int24
    action:(Maybe ^Cell)
= ContractMessages;
```

{% endcode %}

</details>

### POOL\_SWAP

Opcode : **0xa7fb58f8**

V1.5 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: Accepted from the Router (relaying a user's swap) or, for a privileged self-funded swap, from the Arbiter. The pool computes the swap and instructs the Router to send out the funds; the source type in the body selects which path applies.<br>

<table data-full-width="true"><thead><tr><th width="90">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>source_type</td><td>Uint(4)</td><td>Type of source</td></tr><tr><td></td><td>from_user</td><td>Address(267)</td><td>User that initiated the swap. This is used to control access</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>zeroForOne</td><td>Uint(1),Boolean</td><td>used to identify swap direction</td></tr><tr><td></td><td>input_jetton_wallet</td><td>Address(267)</td><td>Router jetton wallet of the input jetton. Pool ignores it, it is only used to refund the swap on bounce</td></tr><tr><td></td><td>0</td><td>Cell(0) params_cell</td><td>Cell with parameters</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 GRAM 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 GRAM 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><tr><td>1</td><td>excess_address</td><td>Address(267)</td><td>Address to receive the excess gas. Could be addr_none() (*00b*) then owner_address is used</td></tr></tbody></table>

<details>

<summary>TL-B Description</summary>

This is a preliminary tl-b - subject to change

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

```javascript
POOL_SWAP#a7fb58f8 
    query_id:uint64
    source_type:uint4
    from_user:MsgAddress
    owner_address:MsgAddress
    zeroForOne:uint1
    input_jetton_wallet:MsgAddress
    params_cell:^Params_cellType
    payloads_cell:^Payloads_cellType
= ContractMessages;
_ 
    amount:(VarUInteger 16)
    sqrtPriceLimitX96:uint160
    minOutAmount:(VarUInteger 16)
= Params_cellType;
_ 
    target_address:MsgAddress
    ok_forward_amount:(VarUInteger 16)
    ok_forward_payload:(Maybe ^Cell)
    ret_forward_amount:(VarUInteger 16)
    ret_forward_payload:(Maybe ^Cell)
    excess_address:MsgAddress
= Payloads_cellType;
```

{% endcode %}

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.tonco.io/contracts-v1.6-forthcoming/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.
