Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Pool

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 and Position NFT sub-contracts (whose addresses it re-derives to authorize them). Swaps and fund flows arrive proxied from the Router; 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

#TypeDescription
0intint 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

#TypeDescription
0sliceRouter address
1sliceAdmin address
2sliceController address
3sliceJetton 0 Wallet address. The wallet is owned by the Router
4sliceJetton 1 Wallet address. The wallet is owned by the Router
5sliceJetton 0 Minter address.
6sliceJetton 1 Minter address.
7intFlag that denotes if the pool is active
8intPool tick spacing
9intFee that is used as a base. Stored in x 1/10000
10intFee that protocol takes. Stored in x 1/10000
11intFee that is currently active. Stored in x 1/10000
12intCurrent tick
13intCurrent price
14intCurrent liquidity
15intpool::feeGrowthGlobal0X128
16intpool::feeGrowthGlobal1X128
17intAmount of jetton0 fee collected for protocol owners
18intAmount of jetton1 fee collected for protocol owners
19intNumber of total minted NFT positions
20intReserves of the jetton0
21intReserves of the jetton1
22intNumber of active NFT positions
23intNumber of currently occupied ticks
24intNumber of operations with pool since the deploy
25sliceArbiter address
26intPool version (e.g. 16000 = v1.6.000)
27sliceALM address
28sliceCreator address
29sliceOracle address
30intPool flags

getChildContracts

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

returns the subcontract codes and NFT metadata used by the pool

Return Values

#TypeDescription
0cellcode of the account contract
1cellcode of the nft position contract
2cellmetadata for NFT Collection
3cellmetadata for NFT Item

getAllTickInfos

(cell) getAllTickInfos ()

returns the cell with all the ticks.

Return Values

#TypeDescription
1cellcell 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

#TypeNameDescription
0intkey
1intamount
2intdir
3intfull

Return Values

#TypeDescription
0tuplea 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

#TypeNameDescription
0inttickLower
1inttickUpper
2intposLiquidityDelta
3intfeeGrowthGlobal0X128
4intfeeGrowthGlobal1X128

Return Values

#TypeDescription
0intamount of jetton0 that is collected
1intamount 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

#TypeNameDescription
0inttickLower
1inttickUpper
2intposLiquidityDelta
3intposFeeGrowthInside0X128
4intposFeeGrowthInside1X128

Return Values

#TypeDescription
0intamount of jetton0 that is collected
1intamount of jetton1 that is collected

getUserAccountAddress

(slice) getUserAccountAddress (slice user_address)

computes user account address for a given user

Parameters

#TypeNameDescription
0sliceuser_addressAddress of the user to compute the account for

Return Values

#TypeDescription
0sliceaccount address

getMintEstimate

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

Computes estimates for the mint

Parameters

#TypeNameDescription
0inttickLower
1inttickUpper
2intliquidity

Return Values

#TypeDescription
0intamount of jetton0 needed to mint the position
1intamount of jetton1 needed to mint the position
2interror 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

#TypeNameDescription
0intzeroForOne
1intamount
2intsqrtPriceLimitX96

Return Values

#TypeDescription
0intamount of jetton0 that would be put to/get from the pool
1intamount 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

#TypeNameDescription
0intzeroForOne
1intamount
2intsqrtPriceLimitX96
3intminOutAmount
4intgasLimitamount of gas (in gas units). If gasLimit is 0 - default value is used - that equals to contract gas limit from the config

Return Values

#TypeDescription
0intamount of jetton0 that would be put to/get from the pool
1intamount 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

#TypeDescription
0int
1cell
2slice

get_nft_address_by_index

(slice) get_nft_address_by_index (int index)

In accordance with TEP-62

Return Values

#TypeDescription
0slice

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

#TypeDescription
0cell

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

#TypeDescription
0intTimelock delay
1intTimestamp when new code can be committed
2cellCell with new code
3intTimestamp when new ALM address can be committed
4sliceNew ALM address
5intTimestamp when new Arbiter address can be committed
6sliceNew Arbiter address
7intTimestamp when new flags can be committed
8intNew 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.

PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
from_admin Uint(1),Bool Flag that shows if this message goes from router admin or pool factory
0 Cell(0) roles_cell Cell With Role
0 has_admin Uint(1),Bool Flag that shows if this message have a new admin address
0 admin_addr Address(267) New address of the admin. If has_admin is false could be 00b
0 has_controller Uint(1),Bool Flag that shows if this message have a new controller address
0 controller_addr Address(267) Address that is allowed to change the fee. Can always be updated by admin.
0 has_creator Uint(1),Bool Flag that shows if this message have a new creator address
0 creator_addr Address(267) Address that is allowed to change the fee. Can always be updated by admin. If has_controller is false could be 00b
0 0 Cell(0) privilege_roles_cell Cell With Privilege Roles
0->0 has_arbiter Uint(1),Bool Flag that shows if this message have a new Arbiter address
0->0 arbiter_addr Address(267) Address that is allowed to make privileged swaps
0->0 has_alm Uint(1),Bool Flag that shows if this message have a new ALM address
0->0 alm_addr Address(267) Address that is used to identify ALM contract
0 1 Cell(0) roles_add Cell With Additional Roles
0->1 has_oracle Uint(1),Bool Flag that shows if this message have a new oracle address
0->1 oracle_addr Address(267) Address that is allowed to change the fee. Can always be updated by admin. Could be 00b
set_spacing Uint(1),Bool Flag that shows if tick_spacing should be set to the pool or ignored
tick_spacing Uint(24) Tick spacing to be used in the pool
set_price Uint(1),Bool Flag that shows if initial_priceX96 should be set to the pool or ignored
initial_priceX96 Uint(160),PriceX96 Initial price for the pool
set_active Uint(1),Bool Flag that shows if pool_active should be set to the pool or ignored
pool_active Uint(1),Bool Flag is we should start the pool as unlocked
protocol_fee Uint(16),Fee Protocol fee in FEE_DENOMINATOR parts. If value is more than 10000 value would be default
lp_fee_base Uint(16),Fee Liquidity provider base fee in FEE_DENOMINATOR. If value is more than 10000 value would be default
lp_fee_current Uint(16),Fee Current value of the pool fee, in case of dynamic adjustment. If value is more than 10000 value would be default
set_flags Uint(1),Bool Is initial flags valid and need to be apply
initial_flags Uint(32),PoolFlags Top 32bits Flag that pool should use
1 Cell(0) code_cell Cell With Contract Codes
1 pool_code Cell(0),Code Pool code
1 account_code Cell(0),Code Account code
1 position_code Cell(0),Code Position code
2 Cell(0) content_cell Cell With Content
2 nft_content Cell(0),Metadata Metadata for the NFT Collection
2 nft_item_content Cell(0),Metadata Metadata for the NFT Item
3 Maybe Cell(1) minter_cell Cell With Minters
3 jetton0_minter Address(267) Address of the jetton0 minter, used by indexer and frontend
3 jetton1_minter Address(267) Address of the jetton1 minter, used by indexer and frontend
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_INIT**
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;

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).

PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_LOCK**
POOL_LOCK#5e74697 
    query_id:uint64
= ContractMessages;

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).

PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_UNLOCK**
POOL_UNLOCK#3205adbd 
    query_id:uint64
= ContractMessages;

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.

PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
protocol_fee Uint(16) Protocol fee in FEE_DENOMINATOR parts
lp_fee_base Uint(16) Liquidity provider base fee in FEE_DENOMINATOR
lp_fee_current Uint(16) Current value of the pool fee, in case of dynamic adjustment
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_SET_FEE**
POOL_SET_FEE#6bdcbeb8 
    query_id:uint64
    protocol_fee:uint16
    lp_fee_base:uint16
    lp_fee_current:uint16
= ContractMessages;

POOL_FUND_ACCOUNT

Opcode : 0x4468de77

Proxy proof of the jettons funding and mint request to the Account. For more information refer to Account
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.

PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
owner_addr Address(267) Address that would receive the minted NFT, excesses and refunds
initiator_addr Address(267) Address that started funding sending
0 Cell(0) funds_cell Cell with parameters
0 fundFirst Uint(1),Boolean If the amount the jetton0 in the pool
0 amount0 Coins(124) Amount of jetton that is funded for the mint
0 amount1 Coins(124) Amount of the other jetton that is funded for the mint (unused)
0 inputWallet Address(267) Address that would be user for sending refund in case of the bounce
1 Maybe Cell(1) order_cell Cell with order
1 enough0 Coins(124) When temporary storage (user account) satisfy both enough0/1 amounts - mint would trigger
1 enough1 Coins(124) When temporary storage (user account) satisfy both enough0/1 amounts - mint would trigger
1 needPos Uint(64) Amount of positions that are enough for the order to be executed
1 passthrough Uint(4) Amount of positions that will be untouched
1 target_action Uint(32) Routing of the reforge result (ACTION_TARGET_DEFAULT / ACTION_TARGET_ALM) — see target_action in ACCOUNT_SET_ORDER for details
1 0 Maybe Cell(1) MintOrder0 Cell with mint order
1->0 op0 Uint(32) Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details
1->0 liquidity0 Uint(128) Amount of liquidity to mint
1->0 tickLower0 Int(24) lower bound of the range in which to mint
1->0 tickUpper0 Int(24) upper bound of the range in which to mint
1->0 receiver0 Address(267) Address of receiver of the NFT
1 1 Maybe Cell(1) MintOrder1 Cell with mint order
1->1 op1 Uint(32) Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details
1->1 liquidity1 Uint(128) Amount of liquidity to mint
1->1 tickLower1 Int(24) lower bound of the range in which to mint
1->1 tickUpper1 Int(24) upper bound of the range in which to mint
1->1 receiver1 Address(267) Address of receiver of the NFT
1 2 Maybe Cell(1) MintOrder2 Cell with mint order
1->2 op2 Uint(32) Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details
1->2 liquidity2 Uint(128) Amount of liquidity to mint
1->2 tickLower2 Int(24) lower bound of the range in which to mint
1->2 tickUpper2 Int(24) upper bound of the range in which to mint
1->2 receiver2 Address(267) Address of receiver of the NFT
1 3 Maybe Cell(1) MintOrder3 Cell with mint order
1->3 op3 Uint(32) Mint mode (MINT_NOT_LESS / MINT_AS_MUCH_AS_POSSIBLE) — see mintOp in ACCOUNT_SET_ORDER for details
1->3 liquidity3 Uint(128) Amount of liquidity to mint
1->3 tickLower3 Int(24) lower bound of the range in which to mint
1->3 tickUpper3 Int(24) upper bound of the range in which to mint
1->3 receiver3 Address(267) Address of receiver of the NFT
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_FUND_ACCOUNT**
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;

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

PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
burned_index Uint(64) Index if the NFT to burn
liquidity2Burn Uint(128) Amount of the liquidity to burn, 0 is a valid amount, in this case only collected fees would be returned
tickLower Int(24) Lower tick of the NFT. Should match the real one
tickUpper Int(24) Upper tick of the NFT. Should match the real one
action Cell(0),Maybe Cell that describes what to do with the burn result
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_START_BURN**
POOL_START_BURN#530b5f2c 
    query_id:uint64
    burned_index:uint64
    liquidity2Burn:uint128
    tickLower:int24
    tickUpper:int24
    action:(Maybe ^Cell)
= ContractMessages;

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

ConditionSwap resultReturned ChangeError Code
Swap finished sqrtPriceLimitX96 not reached. minOutAmount surpassedtotal output number of coins0RESULT_SWAP_OK
Swap finished minOutAmount not surpassed0amountRESULT_SWAP_OUTPUT_TOO_SMALL
Swap reached sqrtPriceLimitX96 after changing part1 coins. minOutAmount surpassedoutput number of coinsamount - part1RESULT_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.
PathMnemonicTypeDescription
op Uint(32),op
query_id Uint(64) queryid as of the TON documentation
source_type Uint(4) Type of source
from_user Address(267) User that initiated the swap. This is used to control access
owner_address Address(267) Owner of the liquidity in swap
zeroForOne Uint(1),Boolean used to identify swap direction
input_jetton_wallet Address(267) Router jetton wallet of the input jetton. Pool ignores it, it is only used to refund the swap on bounce
0 Cell(0) params_cell Cell with parameters
0 amount Coins(124) Input amount of the jettons to be swapped
0 sqrtPriceLimitX96 Uint(160),PriceX96 Limit marginal price. Swap won't go beyond it.
0 minOutAmount Coins(124) Minimum amount of the output jettons to get back. If not reached, your input would be returned to you
1 Cell(0) payloads_cell Cell with payloads for swap result and change
1 target_address Address(267) Target will receive the result of the swap. Could be addr_none() (*00b*) then owner_address is used
1 ok_forward_amount Coins(124) Amount of GRAM to use for forward payload that would be sent with the result of the swap
1 ok_forward_payload Cell(0),Maybe,Payload Payload that would be sent with the jettons of the result of the swap
1 ret_forward_amount Coins(124) Amount of GRAM to use for forward payload that would be sent with the change for the swap (if any)
1 ret_forward_payload Cell(0),Maybe,Payload Payload that would be sent with the jettons of the change of the swap (if any)
1 excess_address Address(267) Address to receive the excess gas. Could be addr_none() (*00b*) then owner_address is used
TL-B Description This is a preliminary tl-b - subject to change **Tlb for POOL_SWAP**
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;