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

Router

router

Description

This contract implements the router and does the management of the pools. Due to the distributed nature of the TON Blockchain router, it can't do many checks, so it's mostly the proxy for the calls. The router contract so far is used as an owner of all the wallets holding the funds invested by liquidity providers.

The main idea is that if malformed or corrupted data is sent to the router it would create a malformed address of the pool and the message sent to it would fail. So if the message reaches the pool it means some criteria are satisfied.

Data Storage

IndexTypeSize (b/r)CellNameDescription
1addr267 / 01router::admin_addressAdmin address.
2addr267 / 01router::pool_admin_addressAdmin address.
3addr267 / 01router::pool_factory_addressPoolFactory address. Only this address and admin can create new pools
4uint6464 / 01router::flagsFlags that control some router features
5uint6464 / 01router::pool_seqnoNumber of pools created. Used by indexer to ensure that none of pools are skipped
6code0 / 111router::poolv3_codeThe cell with the code of the pool, that is needed to create a pool contract
7code0 / 111router::accountv3_codeThe cell with the code of the account, that is needed to create initial data for pool contract
8code0 / 111router::position_nftv3_codeThe cell with the code of the user NFT position, that is needed to create initial data for pool contract
9cell0 / 11router::timelocked_updatesThis cell holds 3 maybe_refs to cells with timelock data for changeable structures

Cells

NameSizeFree
192994
1101023

Interface

getRouterState

(slice, slice, slice, int, int) getRouterState ()

returns router admin address

Return Values

#TypeDescription
0slicerouter admin address (router::admin_address)
1slicedefault value for pool admin (router::pool_admin_address)
2slicepool factory address (router::pool_factory_address)
3intcurrently active flags ( 0 for working and active router)
4introuter internal number of pool creation or reinit messages

getPoolAddress

(slice) getPoolAddress (slice jetton_wallet0, slice jetton_wallet1)

returns pool address for two given jetton_wallets belonging to the router

Parameters

#TypeNameDescription
0slicejetton_wallet0Address of the jetton 0 wallet belonging to router
1slicejetton_wallet1Address of the jetton 1 wallet belonging to router

Return Values

#TypeDescription
0slicepool address

getChildContracts

(cell, cell, cell) getChildContracts ()

returns code of the child contracts

Return Values

#TypeDescription
0cellcode of the pool contract
1cellcode of the account contract
2cellcode of the nft position contract

Messages

JETTON_TRANSFER_NOTIFICATION

Opcode : 0x7362d09c

Process router funding, payload determines if it is mint or swap
\

PathMnemonicTypeDescription
opUint(32),op
query_idUint(64)queryid as of the TON documentation
jetton_amountCoins(124)Amount of coins sent to the router
from_userAddress(267)User that originated the transfer
forward_payloadCell(0),Either, PayloadPayload for processing
TL-B Description (TBD)

This is a preliminary tl-b - subject to change

Tlb for JETTON_TRANSFER_NOTIFICATION

JETTON_TRANSFER_NOTIFICATION#7362d09c 
    query_id:uint64
    jetton_amount:(VarUInteger 16)
    from_user:MsgAddress
    forward_payload:(Either ^Cell Cell)
= ContractMessages;

ROUTERV3_CREATE_POOL

Opcode : 0x2e3034ef

Operation that deploys and inits new Pool contract for two given jettons identified by their wallets. New pool would reorder the jettons to match the invariant slice_hash(jetton0_address) > slice_hash(jetton1_address).
\

PathMnemonicTypeDescription
opUint(32),op
query_idUint(64)queryid as of the TON documentation
jetton_wallet0Address(267)Address of the jetton0 wallet. Used to compute pool address
jetton_wallet1Address(267)Address of the jetton1 wallet. Used to compute pool address
tick_spacingInt(24)Tick spacing to be used in the pool
initial_priceX96Uint(160),PriceX96Initial price for the pool
protocol_feeUint(16),FeeLiquidity provider fee. base in FEE_DENOMINATOR parts. If value is more than 10000 value would be default
lp_fee_baseUint(16),FeeProtocol fee in FEE_DENOMINATOR. If value is more than 10000 value would be default
lp_fee_currentUint(16),FeeCurrent value of the pool fee, in case of dynamic adjustment. If value is more than 10000 value would be default
nftv3_contentCell(0),MetadataMetadata for the NFT Collection
nftv3item_contentCell(0),MetadataMetadata for the NFT Item
0Cell(0) minter_cellCell With Minters
0jetton0_minterAddress(267)Address of the jetton0 minter, used by indexer and frontend
0jetton1_minterAddress(267)Address of the jetton1 minter, used by indexer and frontend
0controller_addrAddress(267)Address that is allowed to change the fee. Can always be updated by admin. If has_controller is false could be 00b
TL-B Description (TBD)

This is a preliminary tl-b - subject to change

Tlb for ROUTERV3_CREATE_POOL

ROUTERV3_CREATE_POOL#2e3034ef 
    query_id:uint64
    jetton_wallet0:MsgAddress
    jetton_wallet1:MsgAddress
    tick_spacing:int24
    initial_priceX96:uint160
    protocol_fee:uint16
    lp_fee_base:uint16
    lp_fee_current:uint16
    nftv3_content:Cell
    nftv3item_content:Cell
    minter_cell:^[
        jetton0_minter:MsgAddress
        jetton1_minter:MsgAddress
        controller_addr:MsgAddress
    ]  
= ContractMessages;

ROUTERV3_PAY_TO

Opcode : 0xa1daa96d

This is not a message Op this is a payload format for JETTON_TRANSFER_NOTIFICATION
\

PathMnemonicTypeDescription
opUint(32),op
query_idUint(64)queryid as of the TON documentation
reciever0Address(267)Address of the first reciever of the funds
reciever1Address(267)Address of the second reciever of the funds
exit_codeUint(32)queryid as of the TON documentation
seqnoUint(64),Indexerqueryid as of the TON documentation
0Maybe Cell(1) coinsinfo_cellCell with info about the coins
0amount0Coins(124)Amount of coins to be payed to reciever0
0jetton0_addressAddress(267)Jetton to be sent to reciever0 identified by the wallet that belongs to router
0amount1Coins(124)Amount of coins to be payed to reciever1
0jetton1_addressAddress(267)Jetton to be sent to reciever1 identified by the wallet that belongs to router
Predicateexit_code = 200
1Maybe Cell(1) indexer_swap_info_cellInformation for indexer to process after the swap
1liquidityUint(128),IndexerPost-swap concentrated liquidity at current tick
1price_sqrtUint(160),Indexer,PriceX96Post-swap square root of the price stored as fixed point 64.96
1tickInt(24),IndexerPost-swap current tick
1feeGrowthGlobal0X128Int(256),IndexerCurrent range fee per unit of the liquidity for jetton0
1feeGrowthGlobal1X128Int(256),IndexerCurrent range fee per unit of the liquidity for jetton1
Predicateexit_code = 201
2Maybe Cell(1) indexer_burn_info_cellInformation for indexer to process after the burn
2nftIndexUint(64),IndexerNft index that is burned
2liquidityBurnedUint(128),IndexerAmount of liquidity burned
2tickLowerInt(24),IndexerLower tick of the range in which liquidity was burned
2tickUpperInt(24),IndexerUpper tick of the range in which liquidity was burned
2tickInt(24),IndexerPost-burn current tick
TL-B Description (TBD)

This is a preliminary tl-b - subject to change

Tlb for ROUTERV3_PAY_TO

ROUTERV3_PAY_TO#a1daa96d 
    query_id:uint64
    reciever0:MsgAddress
    reciever1:MsgAddress
    exit_code:uint32
    seqno:uint64
    coinsinfo_cell:(Maybe ^[
        amount0:(VarUInteger 16)
        jetton0_address:MsgAddress
        amount1:(VarUInteger 16)
        jetton1_address:MsgAddress
    ] ) 
    (exit_code = 200)?(
        indexer_swap_info_cell:(Maybe ^[
            liquidity:uint128
            price_sqrt:uint160
            tick:int24
            feeGrowthGlobal0X128:int256
            feeGrowthGlobal1X128:int256
        ] ) 
    )
    (exit_code = 201)?(
        indexer_burn_info_cell:(Maybe ^[
            nftIndex:uint64
            liquidityBurned:uint128
            tickLower:int24
            tickUpper:int24
            tick:int24
        ] ) 
    )
= ContractMessages;

ROUTERV3_RESET_GAS

Opcode : 0x42a0fb43

This operation allows router owners the gas if too much accumulated on the contract
Access Rights: This operation is allowed for router::admin_address\

PathMnemonicTypeDescription
opUint(32),op
query_idUint(64)queryid as of the TON documentation
TL-B Description (TBD)

This is a preliminary tl-b - subject to change

Tlb for ROUTERV3_RESET_GAS

ROUTERV3_RESET_GAS#42a0fb43 
    query_id:uint64
= ContractMessages;