# Pool

The pool contract is the main contract responsible for maintaining the pool's current price, current liquidity, and all deposited liquidity.\
It also determines output amounts for swaps and handles liquidity burning.

***

## Interface

### `get_pool_data`

Returns pool data.

**Arguments**

*None*

**Returns**

| Data Type | Description                           |
| --------- | ------------------------------------- |
| `slice`   | Token0 vault address                  |
| `slice`   | Token1 vault address                  |
| `int`     | LP fee                                |
| `int`     | Protocol fee                          |
| `int`     | Referral fee                          |
| `slice`   | Protocol fee address                  |
| `int`     | Token0 protocol fee earned            |
| `int`     | Token1 protocol fee earned            |
| `int`     | Sqrt price X128                       |
| `int`     | Current lower tick                    |
| `int`     | Current upper tick                    |
| `int`     | Current tick                          |
| `int`     | Current liquidity                     |
| `int`     | Is initialized                        |
| `int`     | Is active                             |
| `int`     | Tx count                              |
| `int`     | Global fee growth in token0 X128      |
| `int`     | Global fee growth in token1 X128      |
| `int`     | Min tick (pool index)                 |
| `int`     | Seconds                               |
| `int`     | Seconds per liquidity cumulative X128 |

***

### `get_tick_data`

Returns entire pool tick data.

**Arguments**

*None*

**Returns**

| Data Type | Description   |
| --------- | ------------- |
| `dict`    | All tick data |

**Tick Format**

| Key     | Value     |
| ------- | --------- |
| `Int32` | Tick      |
| `Cell`  | Tick data |

**Tick Data Contents**

| Data Type | Description                                |
| --------- | ------------------------------------------ |
| `Int128`  | Liquidity delta at tick                    |
| `Uint128` | Gross liquidity at tick                    |
| `Uint256` | Fee growth in token0 above tick X128       |
| `Uint256` | Fee growth in token1 above tick X128       |
| `^Cell`   | Tick seconds data                          |
|           | → `Uint256`: Seconds                       |
|           | → `Uint256`: Cumulative sec/liquidity X128 |

***

### `get_nft_address_by_index`

Returns NFT position address for a given index.

**Arguments**

| Data Type | Description    |
| --------- | -------------- |
| `int`     | Position index |

**Returns**

| Data Type | Description            |
| --------- | ---------------------- |
| `slice`   | User LP wallet address |

***

### `get_simulate_swap`

Simulates a swap and returns result.

**Arguments**

| Data Type | Description  |
| --------- | ------------ |
| `int`     | Is token0 in |
| `int`     | Amount in    |

**Returns**

| Data Type | Description             |
| --------- | ----------------------- |
| `int`     | Exit code               |
| `int`     | State was altered       |
| `int`     | Refund amount           |
| `int`     | Other token output      |
| `int`     | Is fwd (ignore)         |
| `int`     | Fwd amount (ignore)     |
| `int`     | Number of ticks crossed |

***

### `get_amounts_for_liquidity`

Get required token amounts to provide liquidity.

**Arguments**

| Data Type | Description |
| --------- | ----------- |
| `int`     | Liquidity   |
| `int`     | Lower tick  |
| `int`     | Upper tick  |

**Returns**

| Data Type | Description      |
| --------- | ---------------- |
| `int`     | Amount0 required |
| `int`     | Amount1 required |

***

## Messages

### Add Liquidity

```plaintext
Opcode: 0x33f9243b
```

| Data Type      | Description  |
| -------------- | ------------ |
| `Uint32`       | Opcode       |
| `Uint64`       | Query ID     |
| `Int32`        | Low tick     |
| `Int32`        | High tick    |
| `Coins`        | Amount0      |
| `Coins`        | Amount1      |
| `Address`      | User address |
| `Uint128`      | Liquidity    |
| `^Cell`        | Farm data    |
| `Uint1`        | Should stake |
| `Maybe Uint32` | Farm index   |

***

### Swap

```plaintext
Opcode: 0x6559ce1d
```

| Data Type       | Description              |
| --------------- | ------------------------ |
| `Uint32`        | Opcode                   |
| `Uint64`        | Query ID                 |
| `Address`       | Destination user address |
| `Address`       | User address             |
| `Coins`         | Amount in                |
| `Coins`         | Desired amount out       |
| `Uint1`         | Is exact in              |
| `Uint1`         | Has referral address     |
| `Maybe ^Cell`   | Referral address cell    |
| → `Address`     | Referral address         |
| `^Cell`         | Custom DEX data          |
| → `Coins`       | Custom forward amount    |
| → `Uint1`       | Has custom payload       |
| → `Maybe ^Cell` | Custom payload           |
| `Coins`         | Refund forward payload   |
| `Uint1`         | Has refund payload       |
| `Maybe ^Cell`   | Refund payload           |

***

### Burn Liquidity

```plaintext
Opcode: 0xf8f6fc24
```

| Data Type | Description    |
| --------- | -------------- |
| `Uint32`  | Opcode         |
| `Int32`   | Low tick       |
| `Int32`   | High tick      |
| `Uint128` | Liquidity      |
| `Uint64`  | Position index |

***

### Burn Notification

```plaintext
Opcode: 0x7bdd97de
```

| Data Type | Description    |
| --------- | -------------- |
| `Uint32`  | Opcode         |
| `Uint64`  | Query ID       |
| `Int32`   | Low tick       |
| `Int32`   | High tick      |
| `Uint128` | Liquidity      |
| `Address` | User address   |
| `Uint64`  | Position index |

***

### Stake Liquidity

```plaintext
Opcode: 0x5576549b
```

| Data Type   | Description                |
| ----------- | -------------------------- |
| `Uint32`    | Opcode                     |
| `Uint64`    | Query ID                   |
| `Int32`     | Low tick                   |
| `Int32`     | High tick                  |
| `Uint128`   | Liquidity                  |
| `Uint256`   | Tx count                   |
| `^Cell`     | Farm data cell             |
| → `Uint64`  | Farming rewards start time |
| → `Uint64`  | Farming rewards end time   |
| → `Address` | User address               |
| → `Uint64`  | Position index             |
| → `Uint32`  | Farm index                 |

***

### Unstake LP

```plaintext
Opcode: 0x82acbf5f
```

| Data Type   | Description                               |
| ----------- | ----------------------------------------- |
| `Uint32`    | Opcode                                    |
| `Uint64`    | Query ID                                  |
| `Int32`     | Low tick                                  |
| `Int32`     | High tick                                 |
| `Uint128`   | Liquidity                                 |
| `Uint256`   | Tx count                                  |
| `Uint32`    | Farm index                                |
| `Uint1`     | Should restake                            |
| `^Cell`     | Farm data cell                            |
| → `Uint256` | Position sec/liquidity growth inside X128 |
| → `Uint64`  | Start timestamp                           |
| → `Uint64`  | End timestamp                             |

***

### Stake LP

```plaintext
Opcode: 0x80c51caa
```

| Data Type | Description    |
| --------- | -------------- |
| `Uint32`  | Opcode         |
| `Uint64`  | Query ID       |
| `Address` | User address   |
| `Uint64`  | Position index |
| `Int32`   | Low tick       |
| `Int32`   | High tick      |
| `Uint128` | Liquidity      |
| `Uint256` | Tx count       |
| `Uint32`  | Farm index     |

***

### Stake Notification

```plaintext
Opcode: 0xbaaf2375
```

| Data Type | Description      |
| --------- | ---------------- |
| `Uint32`  | Opcode           |
| `Uint64`  | Query ID         |
| `Uint32`  | Farm index       |
| `Uint64`  | Position index   |
| `Address` | Response address |

***

### Collect Protocol Fees

```plaintext
Opcode: 0x4ab8bdfa
```

| Data Type | Description |
| --------- | ----------- |
| `Uint32`  | Opcode      |
| `Uint64`  | Query ID    |


---

# 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.titan.tg/colossus-concentrated-liquidity-amm/smart-contracts/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.
