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

Index
Type
Size (b/r)
Cell
Name
Description

1

addr

267 / 0

1

router::admin_address

Admin address.

2

addr

267 / 0

1

router::pool_admin_address

Admin address.

3

addr

267 / 0

1

router::pool_factory_address

PoolFactory address. Only this address and admin can create new pools

4

uint64

64 / 0

1

router::flags

Flags that control some router features

5

uint64

64 / 0

1

router::pool_seqno

Number of pools created. Used by indexer to ensure that none of pools are skipped

6

code

0 / 1

11

router::poolv3_code

The cell with the code of the pool, that is needed to create a pool contract

7

code

0 / 1

11

router::accountv3_code

The cell with the code of the account, that is needed to create initial data for pool contract

8

code

0 / 1

11

router::position_nftv3_code

The cell with the code of the user NFT position, that is needed to create initial data for pool contract

9

cell

0 / 1

1

router::timelocked_updates

This cell holds 3 maybe_refs to cells with timelock data for changeable structures

Cells

Name
Size
Free

1

929

94

11

0

1023

Interface

getRouterState

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

returns router admin address

Return Values

#
Type
Description

0

slice

router admin address (router::admin_address)

1

slice

default value for pool admin (router::pool_admin_address)

2

slice

pool factory address (router::pool_factory_address)

3

int

currently active flags ( 0 for working and active router)

4

int

router 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

#
Type
Name
Description

0

slice

jetton_wallet0

Address of the jetton 0 wallet belonging to router

1

slice

jetton_wallet1

Address of the jetton 1 wallet belonging to router

Return Values

#
Type
Description

0

slice

pool address

getChildContracts

(cell, cell, cell) getChildContracts ()

returns code of the child contracts

Return Values

#
Type
Description

0

cell

code of the pool contract

1

cell

code of the account contract

2

cell

code of the nft position contract

Messages

JETTON_TRANSFER_NOTIFICATION

Opcode : 0x7362d09c

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

Path
Mnemonic
Type
Description

op

Uint(32),op

query_id

Uint(64)

queryid as of the TON documentation

jetton_amount

Coins(124)

Amount of coins sent to the router

from_user

Address(267)

User that originated the transfer

forward_payload

Cell(0),Either, Payload

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

Path
Mnemonic
Type
Description

op

Uint(32),op

query_id

Uint(64)

queryid as of the TON documentation

jetton_wallet0

Address(267)

Address of the jetton0 wallet. Used to compute pool address

jetton_wallet1

Address(267)

Address of the jetton1 wallet. Used to compute pool address

tick_spacing

Int(24)

Tick spacing to be used in the pool

initial_priceX96

Uint(160),PriceX96

Initial price for the pool

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

Cell(0) 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

0

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

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

Path
Mnemonic
Type
Description

op

Uint(32),op

query_id

Uint(64)

queryid as of the TON documentation

reciever0

Address(267)

Address of the first reciever of the funds

reciever1

Address(267)

Address of the second reciever of the funds

exit_code

Uint(32)

queryid as of the TON documentation

seqno

Uint(64),Indexer

queryid as of the TON documentation

0

Maybe Cell(1) coinsinfo_cell

Cell with info about the coins

0

amount0

Coins(124)

Amount of coins to be payed to reciever0

0

jetton0_address

Address(267)

Jetton to be sent to reciever0 identified by the wallet that belongs to router

0

amount1

Coins(124)

Amount of coins to be payed to reciever1

0

jetton1_address

Address(267)

Jetton to be sent to reciever1 identified by the wallet that belongs to router

Predicate

exit_code = 200

1

Maybe Cell(1) indexer_swap_info_cell

Information for indexer to process after the swap

1

liquidity

Uint(128),Indexer

Post-swap concentrated liquidity at current tick

1

price_sqrt

Uint(160),Indexer,PriceX96

Post-swap square root of the price stored as fixed point 64.96

1

tick

Int(24),Indexer

Post-swap current tick

1

feeGrowthGlobal0X128

Int(256),Indexer

Current range fee per unit of the liquidity for jetton0

1

feeGrowthGlobal1X128

Int(256),Indexer

Current range fee per unit of the liquidity for jetton1

Predicate

exit_code = 201

2

Maybe Cell(1) indexer_burn_info_cell

Information for indexer to process after the burn

2

nftIndex

Uint(64),Indexer

Nft index that is burned

2

liquidityBurned

Uint(128),Indexer

Amount of liquidity burned

2

tickLower

Int(24),Indexer

Lower tick of the range in which liquidity was burned

2

tickUpper

Int(24),Indexer

Upper tick of the range in which liquidity was burned

2

tick

Int(24),Indexer

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

Path
Mnemonic
Type
Description

op

Uint(32),op

query_id

Uint(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;

Last updated