# Pool Factory

### pool\_factory

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

## Description

This contract implements the creation of the pools. And works as a proxy to CREATE\_POOL message of the router

## 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>pool_factory::admin_address</td><td>Admin address. Only this address can change pool creation parameters</td></tr><tr><td>2</td><td>addr</td><td>267 / 0</td><td>1</td><td>pool_factory::router_address</td><td>Router address. Address of the pool to witch pool creation request will be forwarded</td></tr><tr><td>3</td><td>coins</td><td>124 / 0</td><td>1</td><td>pool_factory::ton_price</td><td>Ton price that is taken form the pool creator to discourage pool creation spam</td></tr><tr><td>4</td><td>cell</td><td>0 / 1</td><td>1</td><td>pool_factory::order_code</td><td>Code of pool factory order subcontract. It is used internally and have no user callable methods</td></tr><tr><td>5</td><td>cell</td><td>0 / 1</td><td>1</td><td>pool_factory::nftv3_content</td><td>packed metadata that would be given to nft that corresponds to nft collection</td></tr><tr><td>6</td><td>cell</td><td>0 / 1</td><td>1</td><td>pool_factory::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    | 658  | 365  |

## Interface

### getPoolFactoryData

(slice, slice, int, cell, cell) getPoolFactoryData ()

Returns current settings of the pool factory

#### Return Values

| # | Type  | Description                                           |
| - | ----- | ----------------------------------------------------- |
| 0 | slice | address containing the pool\_factory::admin\_address  |
| 1 | slice | address containing the pool\_factory::router\_address |
| 2 | int   | int containing the pool\_factory::ton\_price          |
| 3 | cell  | int containing the pool\_factory::nftv3\_content      |
| 4 | cell  | int containing the pool\_factory::nftv3item\_content  |

### getOrderAddress

(slice) getOrderAddress (slice jetton0MinterAddr, slice jetton1MinterAddr)

Returns future order address

#### Return Values

| # | Type  | Description                                           |
| - | ----- | ----------------------------------------------------- |
| 0 | slice | address where pool creation order is/will be deployed |

## Messages

### POOL\_FACTORY\_CREATE\_POOL

Opcode : **0x9e9a8f7f**

Message that initiates pool creation

You need to pass jetton 0/1 masters(minters) of the coins for which to create the pool You also need to provide two wallet address for the jettons, these need to be the wallets belonging to the [Router](https://docs.tonco.io/technical-reference/integration-faq#mainnet). Also price need to be provided in sqrt Q64.96 format [Sqrt Q64.96 Format](https://docs.tonco.io/technical-reference/contracts/storage-formats#price-storage-format-and-conversion)

**Please note** that price should be presented in pool internal format. This means that if you have two jettons - jetton0 and jetton1 and price **1 jetton0 = X jetton1**, you need to check if the jettons are in pool natural order - slice\_hash(jetton0\_wallet\_address) > slice\_hash(jetton1\_wallet\_address). If it's not true you would need to invert your price. **1 jetton1 = (1/X) jetton0**

**Please note** that pool factory checks for strict master/minter and wallet correspondence. This is done by onchain call to minter with [PROVIDE\_WALLET\_ADDRESS](https://github.com/ton-builders/open-ton-contract/blob/015e40475ec474596a9c016a92488f395a695d61/contracts/ft_func/jetton-master.fc#L99) message. If the minter is lacking this method **pool creation is impossible**

There are 3 settings presets

| NO | fee   | tick\_spacing |
| -- | ----- | ------------- |
| 1  | 0.01% | 10            |
| 2  | 0.3%  | 60            |
| 3  | 1%    | 200           |

\ <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>jetton0Minter</td><td>Address(267)</td><td>Minter address of the first jetton</td></tr><tr><td></td><td>jetton1Minter</td><td>Address(267)</td><td>Minter address of the second jetton</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>settings</td><td>Uint(16)</td><td>Value that describes pool configuration preset</td></tr><tr><td></td><td>0</td><td>Cell(0) wallet_cell</td><td>Cell With Wallets. Currently content is ignored</td></tr><tr><td>0</td><td>jetton0Wallet</td><td>Address(267)</td><td>Address of the jetton0 wallet of the Router</td></tr><tr><td>0</td><td>jetton1Wallet</td><td>Address(267)</td><td>Address of the jetton1 wallet of the Router</td></tr></tbody></table>

<details>

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

This is a preliminary tl-b - subject to change

{% code title="Tlb for POOL\_FACTORY\_CREATE\_POOL" overflow="wrap" lineNumbers="true" %}

```javascript
POOL_FACTORY_CREATE_POOL#9e9a8f7f 
    query_id:uint64
    jetton0Minter:MsgAddress
    jetton1Minter:MsgAddress
    initial_priceX96:uint160
    settings:uint16
    wallet_cell:^[
        jetton0Wallet:MsgAddress
        jetton1Wallet:MsgAddress
    ]  
= ContractMessages;
```

{% endcode %}

</details>


---

# 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.tonco.io/technical-reference/contracts/pool_factory.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.
