Router
This section contains api reference of the `Router` contract
Off-chain get methods
get_vault_address
get_vault_address
Returns an address of a vault for a specified asset and user.
Arguments
Key | Type | Index | Description |
---|---|---|---|
|
| 0 | The address of the |
|
| 1 | The address of the |
Result
Returns VaultV2
object for Vault
's' address.
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 |
|
| 1 | The address of the |
Result
Returns Pool
address.
get_router_data
get_router_data
Returns the current state of the Router
Arguments
None
Result
Returns RouterData
structure containing current state of the Router
.
RouterData
structure
Key | Type | Index | Description |
---|---|---|---|
|
| 0 |
|
|
| 1 |
|
|
| 2 | true if |
|
| 3 | Address of contract's admin account |
|
| 4 | A structure describing state of contract's code & admin upgrade; zero values indicate that no upgrade is pending |
|
| 5 | Code of the |
|
| 6 | Code of lp wallet contract |
|
| 7 | Code of lp account contract |
|
| 8 | Code of lp account contract |
get_router_version
get_router_version
Returns the current Router
version
Arguments
None
Result
Returns VersionData
structure containing Router
version.
RouterData
structure
Key | Type | Index | Description |
---|---|---|---|
|
| 0 | Major version |
|
| 1 | Minor version |
|
| 2 | Contains additional version info |
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 |
payload
body
payload
bodyName | Type | Description |
---|---|---|
|
| Additional operation code |
|
| The address of the |
Notes:
payload
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.
Check examples for in-depth message flow.
TL-B
payload
body
payload
bodyName | Type | Description |
---|---|---|
|
| Swap op |
|
| Address of the other |
|
| Address where refund will be sent if swap fails |
|
| Address where TON excesses will be sent |
|
| Cell with additional data |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| Minimum required amount of tokens to receive |
|
| Address where tokens will be sent after swap |
|
| Gas used to forward a message in |
|
| Payload sent in |
|
| Gas used to forward a message in |
|
| Payload sent in |
|
| Referral fee |
|
| Referral address |
Notes:
swap will fail if a user should receive less than
min_out
of tokens as a resultmax allowed value of
ref_fee
is 100 (1%)
Outgoing messages
Sends a message with op swap
to 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.
Check examples for in-depth message flow.
TL-B
payload
body
payload
bodyName | Type | Description |
---|---|---|
|
| Provide lp op |
|
| Address of the other |
|
| Address where refund will be sent if swap fails |
|
| Address where TON excesses will be sent |
|
| Cell with additional data |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| Minimum required amount of lp tokens to receive |
|
| Address where lp tokens will be sent |
|
| Trigger liquidity deposit only if both token amounts are non-zero |
|
| Gas used to forward a message in |
|
| Payload sent in |
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 |
|
| The address of the |
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.
Common operations table
Name | Value | Description |
---|---|---|
| 0x355423e5 | Change fee parameters of a pool |
| 0xf6aa9737 | Update the amount of TON (in nanoTons) on a pool to |
| 0x5377909a | Change |
| 0x78d6e3f2 | Change |
| 0xdf1e233d | Initiate code upgrade for the |
| 0x2fb94384 | Initiate admin change for the |
| 0xa4ed9981 | Cancel an admin change |
| 0x357ccc67 | Cancel a code upgrade |
| 0x6378509f | Finalize upgrades of the |
| 0x42a0fb43 | Update the amount of TON (in nanoTons) on the |
| 0x2b8b3b62 | Change pool-specific parameters |
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 |
|
| New protocol fee ratio |
|
| Address for receiving protocol fees |
|
| Cell with wallet addresses |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| The address of the |
|
| The address of the |
|
| The address where TON excesses will be sent |
Notes:
fee ratio is the value of fee divided by
params::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.
update_status
(0x78d6e3f2)
update_status
(0x78d6e3f2)Changes Router
is_locked
var to the opposite value. If is_locked == 1
blocks transfer_notification
messages from going through. Effectively blocks 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 |
Outgoing messages
Excesses will be sent to admin_address
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
Excesses will be sent to admin_address
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
Excesses will be sent to admin_address
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
Excesses will be sent to admin_address
finalize_upgrades
(0x6378509f)
finalize_upgrades
(0x6378509f)Finalizes upgrades of the Router
code and admin changes. 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 storage_fee::router
(100000) of the Router
. The remaining TON will be sent to the Router
admin.
TL-B
Arguments
None
Outgoing messages
Excesses will be sent to admin_address
reset_pool_gas
(0xf6aa9737)
reset_pool_gas
(0xf6aa9737)Updates the amount of TON (in nanoTons) on a pool to storage_fee::router
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 |
|
| The address of the |
|
| The address where TON excesses will be sent |
Outgoing messages
Sends a message to a liquidity pool with reset_gas
op code carrying remaining gas
update_pool_status
(0x5377909a)
update_pool_status
(0x5377909a)Changes Pool
is_locked
var to the opposite value. If is_locked == 1
blocks swaps and liquidity withdraws from this Pool
TL-B
Arguments
Name | Type | Description |
---|---|---|
|
| The address of the |
|
| The address of the |
|
| The address where TON excesses will be sent |
Outgoing messages
Excesses will be sent to excesses_address
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 |
|
| Address where TON excesses will be sent |
|
| Exit code |
|
| Payload sent in |
|
| Cell with additional data |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| Gas used to forward |
|
| Amount of the first Jetton token (in basic token units) |
|
| The address of the |
|
| Amount of the second Jetton token (in basic token units) |
|
| The address of the |
Outgoing messages
Sends transfer of amount0_out
tokens to owner
message to token0_address
wallet if amount0_out
> 0
or
Sends transfer of amount1_out
tokens to owner
message to token1_address
wallet if amount1_out
> 0
or
Sends swap
or lp_provide
to some Pool
if custom_payload
is cross_swap
or cross_provide_lp
pay_vault
(0xb7d1e6b8)
pay_vault
(0xb7d1e6b8)Deposit a token amount into a Vault
contract; used if swap
was done with referral
TL-B
Message body
Name | Type | Description |
---|---|---|
|
| Operation code; equal to |
|
| Query id |
|
| Address of a receiver |
|
| The address where TON excesses will be sent |
|
| Cell with additional data |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| Amount of the first Jetton token (in basic token units) |
|
| The address of the |
|
| Amount of the second Jetton token (in basic token units) |
|
| The address of the |
Outgoing messages
Sends deposit_ref_fee
to a corresponding token Vault
of to_address
vault_pay_to
(0x3eb18447)
vault_pay_to
(0x3eb18447)Initiates a Jetton token transfer from wallets belonging to this Router
, called from a Vault
when an owner withdraws their collected referral fees.
TL-B
Message body
Name | Type | Description |
---|---|---|
|
| Operation code; equal to |
|
| Query id |
|
| Amount of the Jetton token (in basic token units) |
|
| The address of the |
|
| Address of a receiver |
Outgoing messages
Sends transfer of amount_out
tokens to to_address
message to token_address
wallet
Custom swap payloads
Forward swap to another router
Use a normal swap payload as custom_payload
in the initial swap with the other Router
address as the receiver_address
. The value of fwd_gas
must be non-zero and enough to perform the next swap.
Cross-swap payload
This payload allows chaining of swap operations on the same Router
; fwd_gas
is ignored.
TL-B
custom_payload
body
custom_payload
bodyName | Type | Description |
---|---|---|
|
| Cross-swap op (0xffffffef) |
|
| Address of the other |
|
| Address where refund will be sent if swap fails |
|
| Address where TON excesses will be sent |
|
| Cell with additional data |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| Minimum required amount of tokens to receive |
|
| Address where tokens will be sent after swap |
|
| Gas used to forward a message in |
|
| Payload sent in |
|
| Gas used to forward a message in |
|
| Payload sent in |
|
| Referral fee |
|
| Referral address |
Cross-provide payload
This payload allows chaining of swap and liquidity provision operations on the same Router
; fwd_gas
is ignored.
TL-B
custom_payload
body
custom_payload
bodyName | Type | Description |
---|---|---|
|
| Cross-provide lp op (0xfffffeff) |
|
| Address of the other |
|
| Address where refund will be sent if swap fails |
|
| Address where TON excesses will be sent |
|
| Cell with additional data |
additional_data
body
additional_data
bodyName | Type | Description |
---|---|---|
|
| Minimum required amount of lp tokens to receive |
|
| Address where lp tokens will be sent |
|
| Trigger liquidity deposit only if both token amounts are non-zero |
|
| Gas used to forward a message in |
|
| Payload sent in |
Constants
Name | Value | Description |
---|---|---|
| 10000000 | Amount of TON (in nanoTons) to be left on the |
| 172800 | Two days is seconds |
| 604800 | Seven days in seconds |
Last updated