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
Key | Type | Index | Description |
---|---|---|---|
|
| 0 | The address of the router's wallet of first Jetton |
|
| 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
Key | Type | Index | Description |
---|---|---|---|
|
| 0 | if operations are locked ( |
|
| 1 | Address of contract's admin account |
|
| 2 | A structure describing state of contract's code & admin upgrade; zero values indicate that no upgrade is pending |
|
| 3 | Code of the router's liquidity pool contract |
|
| 4 | Code of lp wallet contract |
|
| 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
Name | Type | Description |
---|---|---|
|
| Operation code; equal to |
|
| Query id |
|
| Jetton amount (in basic token units) |
|
| User address |
|
| Cell with data |
ref_msg_data
body
ref_msg_data
bodyName | Type | Description |
---|---|---|
|
| Additional operation code |
|
| 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
Name | Value | Description |
---|---|---|
| 0x25938561 | Swap one type of Jetton tokens for another |
| 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
bodyName | Type | Description |
---|---|---|
|
| Additional operation code; equal to |
|
| The address of the router's wallet of second Jetton |
|
| Minimum amount out (in basic token units) |
|
| User address |
|
| If referral is present |
|
| Referral address; present only if |
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
bodyName | Type | Description |
---|---|---|
|
| Additional operation code; equal to |
|
| The address of the router's wallet of second Jetton |
|
| 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
Name | Value | Description |
---|---|---|
| 0xd1db969b | Sends a message with a pool address for a requested token pair; counterpart to |
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
Name | Type | Description |
---|---|---|
|
| The address of the router's wallet of first Jetton |
|
| 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
Name | Type | Description |
---|---|---|
|
| Operation code equal to |
|
| Query id |
|
| 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
Name | Value | Description |
---|---|---|
| 0x355423e5 | Change fee parameters of a pool |
| 0x1fcb7d3d | Collect protocol fees from a pool |
| 0x878f9b0e | Lock the router (locks all swaps and liquidity providing) |
| 0x6ae4b0ef | Unlock the router |
| 0xdf1e233d | Initiate code upgrade for the router |
| 0x2fb94384 | Initiate admin change for the router |
| 0xa4ed9981 | Cancel an admin change |
| 0x357ccc67 | Cancel a code upgrade |
| 0x6378509f | Finalize upgrades of the router code and admin change |
| 0x42a0fb43 | Update the amount of $TON (in nanoTons) on the router to |
| 0xf6aa9737 | Update the amount of $TON (in nanoTons) on a pool to |
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
Name | Type | Description |
---|---|---|
|
| New liquidity pool fee ratio (multiplied by |
|
| New protocol fee ratio (multiplied by |
|
| New referral fee ratio (multiplied by |
|
| Address for receiving protocol fees |
|
| Cell with wallet addresses |
ref_wallets
body
ref_wallets
bodyName | Type | Description |
---|---|---|
|
| The address of the router's wallet of first Jetton |
|
| 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
Name | Type | Description |
---|---|---|
|
| The address of the router's wallet of first Jetton |
|
| 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
Name | Type | Description |
---|---|---|
|
| 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
Name | Type | Description |
---|---|---|
|
| 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
Name | Type | Description |
---|---|---|
|
| The address of the router's wallet of first Jetton |
|
| 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
Name | Type | Description |
---|---|---|
|
| Operation code; equal to |
|
| Query id |
|
| Address of a receiver |
|
| Exit code |
|
| Cell with Jetton wallet addresses and token amounts |
ref_coins_data
body
ref_coins_data
bodyName | Type | Description |
---|---|---|
|
| Amount of the first Jetton token (in basic token units) |
|
| The address of the router's wallet of the first Jetton |
|
| Amount of the second Jetton token (in basic token units) |
|
| 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
Name | Value | Description |
---|---|---|
| 0 | Workchain id |
| 100000 | Amount of $TON (in nanoTons) to be left on the router contract as gas |
| 172800 | Two days is seconds |
| 604800 | Seven days in seconds |
Last updated