Router
This section contains api reference of the router contract
Off-chain get methods
get_pool_address
get_pool_address
Returns an address of a pool for a specified pair of assets.
It's necessary to specify addresses of Jetton wallets of the router as the arguments of this method. These addresses can be retrieved with get_wallet_address
of the Jetton minter.
Arguments
token0
address
0
The address of the router's wallet of first Jetton
token1
address
1
The address of the router's wallet of second Jetton
Result
Returns single slice with the address of liquidity pool for specified pair of Jettons.
get_router_data
get_router_data
Returns the current state of the router: is the router locked, admin address, pending code or admin upgrades, pool contract code, lp wallet code, lp account code.
Arguments
None
Result
Returns current state of the Router
Result structure
is_locked
bool
0
if operations are locked (swap
, provide_lp
)
admin_address
address
1
Address of contract's admin account
temp_upgrade
cell
2
A structure describing state of contract's code & admin upgrade; zero values indicate that no upgrade is pending
pool_code
cell
3
Code of the router's liquidity pool contract
jetton_lp_wallet_code
cell
4
Code of lp wallet contract
lp_account_code
cell
5
Code of lp account contract
transfer_notification operations
transfer_notification
(0x7362d09c)
transfer_notification
(0x7362d09c)Messages received from Jetton wallets belonging to the router upon getting a token transfer from a user. The user must include a custom payload with additional op code (either swap
or provide_lp
) and appropriate data in order for those messages to be processed correctly.
TL-B
Message body
op
uint32
Operation code; equal to transfer_notification
query_id
uint64
Query id
jetton_amount
coins
Jetton amount (in basic token units)
from_user
address
User address
ref_msg_data
cell
Cell with data
ref_msg_data
body
ref_msg_data
bodytransferred_op
uint32
Additional operation code
token_wallet1
address
The address of the router's wallet of second Jetton
Notes:
ref_msg_data
contains other fields depending on which op code is called
Transfer operations table
swap
0x25938561
Swap one type of Jetton tokens for another
provide_lp
0xfcf9e58f
Provide liquidity; route call to the correct pool
swap
(0x25938561)
swap
(0x25938561)Swap tokens. This message is received when the Router's Jetton token wallet sends a message upon confirmation of token transfer from a user with a custom payload. The router then sends a swap
message to the appropriate pool contract address.
TL-B
ref_msg_data
body
ref_msg_data
bodytransferred_op
uint32
Additional operation code; equal to swap
token_wallet1
address
The address of the router's wallet of second Jetton
min_out
coins
Minimum amount out (in basic token units)
to_address
address
User address
has_ref
uint1
If referral is present
ref_address
address
Referral address; present only if has_ref
is 1
Outgoing messages
Sends a message with op swap
to a liquidity pool
provide_lp
(0xfcf9e58f)
provide_lp
(0xfcf9e58f)Provide liquidity for a pool. This message is received when Router's token wallet sends a message upon confirmation of token transfer from a user with a custom payload. The router then sends a provide_lp
message to the appropriate pool contract address.
TL-B
ref_msg_data
body
ref_msg_data
bodytransferred_op
uint32
Additional operation code; equal to provide_lp
token_wallet1
address
The address of the router's wallet of second Jetton
min_lp_out
coins
Minimum amount of created liquidity tokens (in basic token units)
Outgoing messages
Sends a message with op provide_lp
to a liquidity pool
On-chain queries
On-chain counterparts of getter methods
Operations table
getter_pool_address
0xd1db969b
Sends a message with a pool address for a requested token pair; counterpart to get_pool_address
getter_pool_address
(0xd1db969b)
getter_pool_address
(0xd1db969b)Sends a message with an address of a pool for a specified pair of assets; counterpart to get_pool_address
TL-B
Message Body
token0
address
The address of the router's wallet of first Jetton
token1
address
The address of the router's wallet of second Jetton
Outgoing messages
Sends a message back to the sender with the pool address
Response message body
op
uint32
Operation code equal to getter_pool_address
query_id
uint64
Query id
pool_address
address
Address of a pool
On-chain admin operations
Handles governance message from admin to change pool parameters.
The admin can lock/unlock trading on all pools, change fees on a certain pool, upgrade the router code, etc.
Operations table
set_fees
0x355423e5
Change fee parameters of a pool
collect_fees
0x1fcb7d3d
Collect protocol fees from a pool
lock
0x878f9b0e
Lock the router (locks all swaps and liquidity providing)
unlock
0x6ae4b0ef
Unlock the router
init_code_upgrade
0xdf1e233d
Initiate code upgrade for the router
init_admin_upgrade
0x2fb94384
Initiate admin change for the router
cancel_admin_upgrade
0xa4ed9981
Cancel an admin change
cancel_code_upgrade
0x357ccc67
Cancel a code upgrade
finalize_upgrades
0x6378509f
Finalize upgrades of the router code and admin change
reset_gas
0x42a0fb43
Update the amount of $TON (in nanoTons) on the router to REQUIRED_TON_RESERVE
of the router
reset_pool_gas
0xf6aa9737
Update the amount of $TON (in nanoTons) on a pool to REQUIRED_TON_RESERVE
of a pool
Notes:
REQUIRED_TON_RESERVE
for the router is 100000
set_fees
(0x355423e5)
set_fees
(0x355423e5)Change fees of a pool including liquidity pool fees, protocol fees and referral fees. It's necessary to provide correct Jetton token addresses for a target liquidity pool.
TL-B
Arguments
new_lp_fee
uint8
New liquidity pool fee ratio (multiplied by FEE_DIVIDER
)
new_protocol_fee
uint8
New protocol fee ratio (multiplied by FEE_DIVIDER
)
new_ref_fee
uint8
New referral fee ratio (multiplied by FEE_DIVIDER
)
new_protocol_fee_address
address
Address for receiving protocol fees
ref_wallets
cell
Cell with wallet addresses
ref_wallets
body
ref_wallets
bodyjetton_wallet0
address
The address of the router's wallet of first Jetton
jetton_wallet1
address
The address of the router's wallet of second Jetton
Notes:
fee ratio is the value of fee divided by
FEE_DIVIDER
(10000); so to set a fee to 1% the value must be 100fees must be between
MIN_FEE
(0) andMAX_FEE
(100)
Outgoing messages
Sends a message with op set_fees
to a liquidity pool.
collect_fees
(0x1fcb7d3d)
collect_fees
(0x1fcb7d3d)Collect protocol fees from a pool. The appropriate Jetton wallet addresses must be provided.
TL-B
Arguments
jetton_wallet0
address
The address of the router's wallet of first Jetton
jetton_wallet1
address
The address of the router's wallet of second Jetton
Outgoing messages
Sends a message to a liquidity pool with collect_fees
op code.
lock
(0x878f9b0e)
lock
(0x878f9b0e)Stops all transfer_notification
messages from going through. Effectively blocks swap
and provide_lp
transactions through this router.
TL-B
Arguments
None.
Outgoing messages
None.
unlock
(0x6ae4b0ef)
unlock
(0x6ae4b0ef)Allows all transfer_notification
messages to go through. Enables swap
and provide_lp
transactions through this router.
TL-B
Arguments
None
Outgoing messages
None.
init_code_upgrade
(0xdf1e233d)
init_code_upgrade
(0xdf1e233d)Initiates code upgrade for the router. An appropriate data with the new router code must be provided. The changes won't take effect until finalize_upgrades
is received by the router. The minimum delay between initiating code upgrade and finalizing the changes in seven days.
TL-B
Arguments
code
cell
Code of the new router contract
Outgoing messages
None
init_admin_upgrade
(0x2fb94384)
init_admin_upgrade
(0x2fb94384)Initiates admin change for the router. An appropriate address for a new router admin must be provided. The changes won't take effect until finalize_upgrades
is received by the router. The minimum delay between initiating admin change and finalizing the changes in two days.
TL-B
Arguments
admin
address
New admin address
Outgoing messages
None
cancel_admin_upgrade
(0xa4ed9981)
cancel_admin_upgrade
(0xa4ed9981)Cancels an admin change if there's a pending admin change.
TL-B
Arguments
None
Outgoing messages
None
cancel_code_upgrade
(0x357ccc67)
cancel_code_upgrade
(0x357ccc67)Cancels a code upgrade if there's a pending code change.
TL-B
Arguments
None
Outgoing messages
None
finalize_upgrades
(0x6378509f)
finalize_upgrades
(0x6378509f)Finalizes upgrades of the router code and admin change. In order for the changes to take effect an appropriate amount of time must pass since initializing and upgrade. For code upgrade the delay is seven days, for an admin change the delay is two days.
TL-B
Arguments
None
Outgoing messages
None
reset_gas
(0x42a0fb43)
reset_gas
(0x42a0fb43)Updates the amount of $TON (in nanoTons) on the router to REQUIRED_TON_RESERVE
(100000) of the router. The remaining $TON will be sent to the router admin.
TL-B
Arguments
None
Outgoing messages
Sends an empty message back to admin with the remaining $TON
reset_pool_gas
(0xf6aa9737)
reset_pool_gas
(0xf6aa9737)Updates the amount of $TON (in nanoTons) on a pool to REQUIRED_TON_RESERVE
of a pool. Forwards this message to a pool contract for provided pair of Jetton tokens.
TL-B
Arguments
jetton_wallet0
address
The address of the router's wallet of first Jetton
jetton_wallet1
address
The address of the router's wallet of second Jetton
Outgoing messages
Sends a message to a liquidity pool with reset_gas
op code carrying remaining gas
Internal message handlers
pay_to
(0xf93bb43f)
pay_to
(0xf93bb43f)Initiates a Jetton token transfer from wallets belonging to this router, called from pools (on swap, liquidity providing, refund, etc).
TL-B
Message body
op
uint32
Operation code; equal to pay_to
query_id
uint64
Query id
owner
address
Address of a receiver
exit_code
uint32
Exit code
ref_coins_data
cell
Cell with Jetton wallet addresses and token amounts
ref_coins_data
body
ref_coins_data
bodyamount0_out
coins
Amount of the first Jetton token (in basic token units)
token0_address
address
The address of the router's wallet of the first Jetton
amount1_out
coins
Amount of the second Jetton token (in basic token units)
token1_address
address
The address of the router's wallet of the second Jetton
Outgoing messages
Sends transfer of amount0_out
tokens to owner
message to token0_address
wallet if amount0_out
> 0
Sends transfer of amount1_out
tokens to owner
message to token1_address
wallet if amount1_out
> 0
Constants
WORKCHAIN
0
Workchain id
REQUIRED_TON_RESERVE
100000
Amount of $TON (in nanoTons) to be left on the router contract as gas
TWODAYS
172800
Two days is seconds
SEVENDAYS
604800
Seven days in seconds
Last updated