Pool
Last updated
Last updated
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
Index | Type | Size (b/r) | Cell | Name | Description |
---|---|---|---|---|---|
(int) getIsActive ()
Returns is pool is active
@return0 int containing the poolv3::pool_active
(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
@return0 Router address
@return1 Admin address
@return2 Jetton 0 Wallet address. The wallet is owned by the Router
@return3 Jetton 1 Wallet address. The wallet is owned by the Router
@return4 Jetton 0 Minter address.
@return5 Jetton 1 Minter address.
@return6 Flag that denotes if the pool is active
@return7 Pool tick spacing
@return8 Fee that is used as a base. Stored in x 1/10000
@return9 Fee that protocol takes. Stored in x 1/10000
@return10 Fee that is currently active. Stored in x 1/10000
@return11 Current tick
@return12 Current price
@return13 Current liquidity
@return14 poolv3::feeGrowthGlobal0X128
@return15 poolv3::feeGrowthGlobal1X128
@return16 Amount of jetton0 fee collected for protocol owners
@return17 Amount of jetton0 fee collected for protocol owners
@return18 Number of total minted NFT positions
@return19 Reserves of the jetton0
@return20 Reserves of the jetton1
@return21 Number of active NFT positions
@return22 Number of currently occupied ticks
@return22 Number of operations with pool since the deploy
(cell, cell, cell, cell) getChildContracts ()
@return1 code of the account contract
@return2 code of the nft position contract
@return3 metadata for NFT Collection
@return4 metadata for NFT Item
(cell) getAllTickInfos ()
returns the cell with all the ticks.
@return1 cell that contains the dict with all the ticks.
(tuple) getTickInfosFrom (int key, int amount, int dir, int full)
Returns ticks starting form key (non-inclusive) 0 forward 1 backward
@param key
@param amount
@param dir
@param full
@return0 a tuple with keys
@return1 a tuple with corresponding
liquidityTotal
liquidityDelta
outerFeeGrowth0Token
outerFeeGrowth1Token
(int, int) getCollectedFees (int tickLower, int tickUpper, int posLiquidityDelta, int posFeeGrowthInside0X128, int posFeeGrowthInside1X128)
Predicts how much fees a position can collect
@param tickLower
@param tickUpper
@param posLiquidityDelta
@param posFeeGrowthInside0X128
@param posFeeGrowthInside1X128
@return0 amount of jetton0 that is collected
@return1 amount of jetton1 that is collected
(slice) getUserAccountAddress (slice user_address)
computes user account address for a given user
@return0 account address
(int, int, int) getMintEstimate (int tickLower, int tickUpper, int liquidity)
Computes estimates for the mint
@param tickLower
@param tickUpper
@param liquidity
@return0 amount of jetton0 needed to mint the position
@return1 amount of jetton1 needed to mint the position
@return2 error code that shows if the basic checks for the mint would succeed
(int, int) getSwapEstimate (int zeroForOne, int amount, int sqrtPriceLimitX96)
Deprecated Computes estimates fot the swap
@param zeroForOne
@param amount
@param sqrtPriceLimitX96
@return0 amount of jetton0 that would be put to/get from the pool
@return1 amount of jetton1 that would be put to/get from the pool
(int, int) getSwapEstimateGas (int zeroForOne, int amount, int sqrtPriceLimitX96, int minOutAmount, int gasLimit)
Computes estimates for the swap
@param zeroForOne
@param amount
@param sqrtPriceLimitX96
@param minAmountOut
@param gasLimit amount of gas (in gas units). If gasLimit is 0 - default value is used - that equals to contract gas limit from the config
@return0 amount of jetton0 that would be put to/get from the pool
@return1 amount of jetton1 that would be put to/get from the pool
(int, cell, slice) get_collection_data ()
In accordance with TEP-62
@return0
@return1
@return2
(slice) get_nft_address_by_index (int index)
In accordance with TEP-62
@return0
(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
@return0
Opcode : 0x441c39ed
The first mandatory operation that fills crucial parameters of the pool
Opcode : 0x5e74697
This operation locks the pool. This is allowed to do by the operator and the admin
Opcode : 0x3205adbd
This operation locks the pool. This is allowed to do by the operator and the admin
Opcode : 0x81702ef8
Opcode : 0xd73ac09d
Burn whole or part of nft. Is sent by Position NFT itself, would only be accepted from the correct NFT itself
Opcode : 0x6bdcbeb8
This operation sets the fee values for the pool. This is allowed to do by the operator and the admin
Opcode : 0x4468de77
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
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
Name | Size | Free |
---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
Condition | Swap result | Returned Change | Error Code |
---|---|---|---|
Path | Mnemonic | Type | Description |
---|---|---|---|
1
addr
267 / 0
1
poolv3::router_address
Address of the router contract that created this pool
2
uint16
16 / 0
1
poolv3::lp_fee_base
Liquidity provider fee. base in FEE_DENOMINATOR parts
3
uint16
16 / 0
1
poolv3::protocol_fee
Protocol fee in FEE_DENOMINATOR (16 bit)
4
uint16
16 / 0
1
poolv3::lp_fee_current
Current value of the pool fee, in case of dynamic adjustment
5
addr
267 / 0
1
poolv3::jetton0_wallet
Address of the 0 token in the pool. This is an address of the jetton0 wallet attached to router
6
addr
267 / 0
1
poolv3::jetton1_wallet
Address of the 1 token in the pool This is an address of the jetton0 wallet attached to router
7
int24
24 / 0
1
poolv3::tick_spacing
Spacing of the ticks, 24 bits of signed int would be used
8
uint64
64 / 0
1
poolv3::seqno
Used by indexer to ensure that none of pool interactions are skipped
9
uint256
256 / 0
11
poolv3::feeGrowthGlobal0X128
This variable stores current collected fee per the unit of liquidity in jetton0
10
uint256
256 / 0
11
poolv3::feeGrowthGlobal1X128
This variable stores current collected fee per the unit of liquidity in jetton0
11
uint128
128 / 0
11
poolv3::collectedProtocolFee0
Collected protocol fee of the jetton0
12
uint128
128 / 0
11
poolv3::collectedProtocolFee1
Collected protocol fee of the jetton1
13
coins
124 / 0
11
poolv3::reserve0
These are additional separate protection system - it calculates the reserves of the pool In case main math has a bug it protects the funds of other pools. Reserve of the jetton0
14
coins
124 / 0
11
poolv3::reserve1
Reserve of the jetton1
15
uint1
1 / 0
2
poolv3::pool_active
Pool acitve flag 0 is inactive, 1 is active
16
int24
24 / 0
2
poolv3::tick
Current tick, signed, 24 bits would be used. Pool maintains it in correspondence to poolv3::price_sqrt
17
uint160
160 / 0
2
poolv3::price_sqrt
Current square root of the price in Q64.96 format using 160 bits
18
uint128
128 / 0
2
poolv3::liquidity
Current active concentrated liquidity in 128 bits
19
uint24
24 / 0
2
poolv3::occupied_ticks
number of occupied ticks in storage
20
uint64
64 / 0
2
poolv3::nftv3item_counter
Pool is also an NFT collection. So this is the counter of currently minted positions
21
uint64
64 / 0
2
poolv3::nftv3items_active
Pool is also an NFT collection. Number of unburnt items
22
addr
267 / 0
2
poolv3::admin_address
Admin address. Can init pool
23
addr
267 / 0
2
poolv3::controller_address
Controller address. Can change fee and lock and unlock pool
24
addr
267 / 0
21
poolv3::jetton0_minter
Address of the 0 token minter. Beta only.
25
addr
267 / 0
21
poolv3::jetton1_minter
Address of the 1 token minter. Beta only.
26
dict
0 / 1
3
poolv3::ticks_dictionary
Storage of the ticks
27
code
0 / 1
4
poolv3::accountv3_code
Pool knows how to create user accounts to store fund pairs for a particular user
28
code
0 / 1
4
poolv3::position_nftv3_code
Pool knows how to create user position. So it stores it's code
29
cell
0 / 1
4
poolv3::nftv3_content
packed metadata that would be given to nft that corresponds to nft collection
30
cell
0 / 1
4
poolv3::nftv3item_content
packed metadata that would be given to nft that corresponds to the position
1
937
86
2
999
24
3
0
1023
4
0
1023
11
1016
7
21
534
489
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
has_admin
Uint(1),Bool
Flag that shows if this message have a new admin address
admin_addr
Address(267)
New address of the admin. If has_admin is false could be 00b
has_controller
Uint(1),Bool
Flag that shows if this message have a new controller address
controller_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
set_spacing
Uint(1),Bool
Flag that shows if tick_spacing should be set to the pool or ignored
tick_spacing
Int(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
Liquidity provider fee. base in FEE_DENOMINATOR parts. If value is more than 10000 value would be default
lp_fee_base
Uint(16),Fee
Protocol 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
nftv3_content
Cell(0),Metadata
Metadata for the NFT Collection
nftv3item_content
Cell(0),Metadata
Metadata for the NFT Item
0
Maybe Cell(1) minter_cell
Cell With Minters
0
jetton0_minter
Address(267)
Address of the jetton0 minter, used by indexer and frontend
0
jetton1_minter
Address(267)
Address of the jetton1 minter, used by indexer and frontend
op
Uint(32),op
query_id
Uint(64)
queryid as of the TON documentation
op
Uint(32),op
query_id
Uint(64)
queryid as of the TON documentation
op
Uint(32),op
query_id
Uint(64)
queryid as of the TON documentation
amount0Funded
Coins(124)
Amount of jetton 0 received by router for the mint
amount1Funded
Coins(124)
Amount of jetton 1 recived by router for the mint
recipient
Address(267)
Address that would receive the minted NFT, excesses and refunds
liquidity
Uint(128)
Amount of liquidity to mint
tickLower
Int(24)
lower bound of the range in which to mint
tickUpper
Int(24)
upper bound of the range in which to mint
op
Uint(32),op
query_id
Uint(64)
queryid as of the TON documentation
recipient
Address(267)
NFT owner to receive funds
burned_index
Uint(64)
Index if the NFT to burn. Should match the sender address
liquidity
Uint(128)
NFT liquidity amount prior to burn
tickLower
Int(24)
Lower tick of the NFT. Sanitized by NFTPosition contract
tickUpper
Int(24)
Upper tick of the NFT. Sanitized by NFTPosition contract
liquidity2Burn
Uint(128)
Amount of the liquidity to burn, 0 is a valid amount, in this case only collected fees would be returned
0
Cell(0) old_fee_cell
Fee counters From
0
feeGrowthInside0LastX128
Uint(256),x128
0
feeGrowthInside1LastX128
Uint(256),x128
1
Cell(0) new_fee_cell
Fee counters To (Used by indexer)
1
feeGrowthInside0CurrentX128
Uint(256),x128,Indexer
1
feeGrowthInside1CurrentX128
Uint(256),x128,Indexer
op
Uint(32),op
query_id
Uint(64)
queryid as of the TON documentation
protocol_fee
Uint(16)
Liquidity provider fee. base in FEE_DENOMINATOR parts
lp_fee_base
Uint(16)
Protocol fee in FEE_DENOMINATOR
lp_fee_current
Uint(16)
Current value of the pool fee, in case of dynamic adjustment
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
amount0
Coins(124)
amount1
Coins(124)
enough0
Coins(124)
enough1
Coins(124)
liquidity
Uint(128)
Amount of liquidity to mint
tickLower
Int(24)
lower bound of the range in which to mint
tickUpper
Int(24)
upper bound of the range in which to mint
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
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
op
Uint(32),op
query_id
Uint(64)
queryid as of the TON documentation
owner_address
Address(267)
Owner of the liquidity in swap
source_wallet
Address(267)
jetton wallet attached to the router. used to identify swap direction
0
Cell(0) params_cell
Fee counters To (Used by indexer)
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
Fee counters To (Used by indexer)
1
target_address
Address(267)
1
ok_forward_amount
Coins(124)
1
ok_forward_payload
Cell(0),Payload
1
ret_forward_amount
Coins(124)
1
ret_forward_payload
Cell(0),Payload