Router

This section contains api reference of the `Router` contract

Off-chain get methods

get_vault_address

Returns an address of a vault for a specified asset and user.

(slice) get_vault_address(slice user, slice token_wallet) method_id;

Arguments

KeyTypeIndexDescription

user

address

0

The address of the Vault's owner

token

address

1

The address of the Router's jetton wallet

Result

Returns VaultV2 object for Vault's' 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.

(slice) get_pool_address(slice token_wallet0, slice token_wallet1) method_id;

Arguments

KeyTypeIndexDescription

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 Pool address.

get_router_data

Returns the current state of the Router

(int, slice, int, slice, cell, cell, cell, cell, cell) get_router_data() method_id;

Arguments

None

Result

Returns RouterData structure containing current state of the Router.

RouterData structure

KeyTypeIndexDescription

id

uint32

0

Router id

dex_type

string

1

Router type

is_locked

bool

2

true if transfer_notification operations are locked (swap, provide_lp)

admin_address

address

3

Address of contract's admin account

temp_upgrade

cell

4

A structure describing state of contract's code & admin upgrade; zero values indicate that no upgrade is pending

pool_code

cell

5

Code of the Router's liquidity pool contract

jetton_lp_wallet_code

cell

6

Code of lp wallet contract

lp_account_code

cell

7

Code of lp account contract

vault_code

cell

8

Code of lp account contract

get_router_version

Returns the current Router version

(int, int, slice) get_router_version() method_id;

Arguments

None

Result

Returns VersionData structure containing Router version.

RouterData structure

KeyTypeIndexDescription

major

uint

0

Major version

minor

uint

1

Minor version

development

string

2

Contains additional version info


transfer_notification operations

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

transfer_notification#7362d09c query_id:uint64 jetton_amount:Grams from_user:MsgAddress forward_payload:^DexPayload = InternalMsgBody;

Message body

NameTypeDescription

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

payload

cell

Cell with data

payload body

NameTypeDescription

transferred_op

uint32

Additional operation code

token_wallet1

address

The address of the Router's wallet of second Jetton

Notes:

  • payload contains other fields depending on which op code is called

Transfer operations table

NameValueDescription

swap

0x25938561

Swap one type of Jetton tokens for another

provide_lp

0xfcf9e58f

Provide liquidity; route call to the correct pool

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

swap_op#25938561 = SwapOP;
swap_body$_ min_out:Coins receiver:MsgAddress fwd_gas:Coins custom_payload:^Cell refund_fwd_gas:Coins refund_payload:^Cell ref_fee:uint16 ref_address:MsgAddress = SwapBody;
swap$_ transferred_op:SwapOP token_wallet1:MsgAddress refund_address:MsgAddress excesses_address:MsgAddress swap_body:SwapBody = DexPayload;

payload body

NameTypeDescription

op

uint32

Swap op

other_token_wallet

address

Address of the other Router token wallet

refund_address

address

Address where refund will be sent if swap fails

excesses_address

address

Address where TON excesses will be sent

additional_data

cell

Cell with additional data

additional_data body

NameTypeDescription

min_out

coins

Minimum required amount of tokens to receive

receiver_address

address

Address where tokens will be sent after swap

fwd_gas

coins

Gas used to forward a message in transfer_notification after swap if custom_payload is present

custom_payload

maybe_ref

Payload sent in transfer_notification after swap

refund_fwd_gas

coins

Gas used to forward a message in transfer_notification if swap fails if refund_payload is present

refund_payload

maybe_ref

Payload sent in transfer_notification if swap fails

ref_fee

uint16

Referral fee

referral_address

address

Referral address

Notes:

  • swap will fail if a user should receive less than min_out of tokens as a result

  • max allowed value of ref_fee is 100 (1%)

Outgoing messages

Sends a message with op swap to Pool

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

provide_liquidity_op#fcf9e58f = ProvideLiquidityOP;
provide_liquidity_body$_ min_lp_out:Coins to_address:MsgAddress both_positive:uint1 fwd_amount:Coins custom_payload:^Cell = ProvideLiquidityBody;
provide_liquidity$_ transferred_op:ProvideLiquidityOP token_wallet1:MsgAddress refund_address:MsgAddress excesses_address:MsgAddress provide_lp_body:ProvideLiquidityBody = DexPayload;

payload body

NameTypeDescription

op

uint32

Provide lp op

other_token_wallet

address

Address of the other Router token wallet

refund_address

address

Address where refund will be sent if swap fails

excesses_address

address

Address where TON excesses will be sent

additional_data

cell

Cell with additional data

additional_data body

NameTypeDescription

min_lp_out

coins

Minimum required amount of lp tokens to receive

receiver_address

address

Address where lp tokens will be sent

both_positive

uint1

Trigger liquidity deposit only if both token amounts are non-zero

fwd_gas

coins

Gas used to forward a message in transfer_notification after mint if custom_payload is present

custom_payload

maybe_ref

Payload sent in transfer_notification after lp mint

Outgoing messages

Sends a message with op provide_lp to a liquidity pool


On-chain queries

On-chain counterparts of getter methods

Operations table

NameValueDescription

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)

Sends a message with an address of a pool for a specified pair of assets; counterpart to get_pool_address

TL-B

getter_pool_address#d1db969b query_id:uint64 token0:MsgAddress token1:MsgAddress = InternalMsgBody;

Message Body

NameTypeDescription

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

NameTypeDescription

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.

Common operations table

NameValueDescription

set_fees

0x355423e5

Change fee parameters of a pool

reset_pool_gas

0xf6aa9737

Update the amount of TON (in nanoTons) on a pool to storage_fee::router of a pool

update_pool_status

0x5377909a

Change Pool status

update_status

0x78d6e3f2

Change Router status

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 storage_fee::router of the Router

set_params

0x2b8b3b62

Change pool-specific parameters

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

jetton_info_set_fees$_ jetton_wallet0:MsgAddress jetton_wallet1:MsgAddress = JettonInfoSetFees;
set_fees#355423e5 query_id:uint64 new_lp_fee:uint16 new_protocol_fee:uint16 new_protocol_fee_address:MsgAddress jetton_info:JettonInfoSetFees = InternalMsgBody;

Arguments

NameTypeDescription

new_lp_fee

uint16

New liquidity pool fee ratio

new_protocol_fee

uint16

New protocol fee ratio

new_protocol_fee_address

address

Address for receiving protocol fees

additional_data

cell

Cell with wallet addresses

additional_data body

NameTypeDescription

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

excesses_address

address

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 100

  • fees must be between MIN_FEE (0) and MAX_FEE (100)

Outgoing messages

Sends a message with op set_fees to a liquidity pool.

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

update_status#78d6e3f2 query_id:uint64 = InternalMsgBody;

Arguments

None.

Outgoing messages

None.

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

init_code_upgrade#df1e233d query_id:uint64 new_code:^Cell = InternalMsgBody;

Arguments

NameTypeDescription

new_code

cell

Code of the new Router contract

Outgoing messages

Excesses will be sent to admin_address

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

init_admin_upgrade#2fb94384 query_id:uint64 new_admin_address:MsgAddress = InternalMsgBody;

Arguments

NameTypeDescription

new_admin

address

New admin address

Outgoing messages

Excesses will be sent to admin_address

cancel_admin_upgrade (0xa4ed9981)

Cancels an admin change if there's a pending admin change.

TL-B

cancel_admin_upgrade#a4ed9981 query_id:uint64 = InternalMsgBody;

Arguments

None

Outgoing messages

Excesses will be sent to admin_address

cancel_code_upgrade (0x357ccc67)

Cancels a code upgrade if there's a pending code change.

TL-B

cancel_code_upgrade#357ccc67 query_id:uint64 = InternalMsgBody;

Arguments

None

Outgoing messages

Excesses will be sent to admin_address

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

finalize_upgrades#6378509f query_id:uint64 = InternalMsgBody;

Arguments

None

Outgoing messages

None

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

reset_gas#42a0fb43 query_id:uint64 = InternalMsgBody;

Arguments

None

Outgoing messages

Excesses will be sent to admin_address

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

reset_pool_gas#f6aa9737 query_id:uint64 jetton_wallet0:MsgAddress jetton_wallet1:MsgAddress excesses_recipient:MsgAddress = InternalMsgBody;

Arguments

NameTypeDescription

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

excesses_address

address

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)

Changes Pool is_locked var to the opposite value. If is_locked == 1 blocks swaps and liquidity withdraws from this Pool

TL-B

update_pool_status#5377909a query_id:uint64 jetton_wallet0:MsgAddress jetton_wallet1:MsgAddress excesses_recipient:MsgAddress = InternalMsgBody;

Arguments

NameTypeDescription

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

excesses_address

address

The address where TON excesses will be sent

Outgoing messages

Excesses will be sent to excesses_address


Internal message handlers

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

additional_fields_pay_to$_ fwd_ton_amount:Coins amount0_out:Coins token0_address:MsgAddress amount1_out:Coins token1_address:MsgAddress = AdditionalFieldsPayTo;
pay_to#f93bb43f query_id:uint64 owner:MsgAddress excesses_address:MsgAddress exit_code:uint32 custom_payload:(Maybe ^Cell) additional_info:AdditionalFieldsPayTo = InternalMsgBody;

Message body

NameTypeDescription

op

uint32

Operation code; equal to pay_to

query_id

uint64

Query id

to_address

address

Address of a receiver

excesses_address

address

Address where TON excesses will be sent

exit_code

uint32

Exit code

custom_payload

maybe_ref

Payload sent in transfer_notification

additional_data

cell

Cell with additional data

additional_data body

NameTypeDescription

fwd_gas

coins

Gas used to forward custom_payload if present

amount0_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

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)

Deposit a token amount into a Vault contract; used if swap was done with referral

TL-B

additional_fields_pay_vault$_ fwd_ton_amount:Coins amount0_out:Coins token0_address:MsgAddress amount1_out:Coins token1_address:MsgAddress = AdditionalFieldsPayVault;
pay_vault#b7d1e6b8 query_id:uint64 owner:MsgAddress excesses_address:MsgAddress additional_info:AdditionalFieldsPayVault = InternalMsgBody;

Message body

NameTypeDescription

op

uint32

Operation code; equal to pay_vault

query_id

uint64

Query id

to_address

address

Address of a receiver

excesses_address

address

The address where TON excesses will be sent

additional_data

cell

Cell with additional data

additional_data body

NameTypeDescription

amount0_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 deposit_ref_fee to a corresponding token Vault of to_address

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

vault_pay_to#3eb18447 query_id:uint64 amount_out:Coins token_address:MsgAddress to_address:MsgAddress = InternalMsgBody;

Message body

NameTypeDescription

op

uint32

Operation code; equal to vault_pay_to

query_id

uint64

Query id

amount_out

coins

Amount of the Jetton token (in basic token units)

token_address

address

The address of the Router's wallet of the Jetton

to_address

address

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

cross_swap_op#FFFFFFEF = CrossSwapOP;
cross_swap_body$_ min_out:Coins receiver:MsgAddress fwd_gas:Coins custom_payload:^Cell refund_fwd_gas:Coins refund_payload:^Cell ref_fee:uint16 ref_address:MsgAddress = CrossSwapBody;
cross_swap$_ transferred_op:CrossSwapOP token_wallet1:MsgAddress refund_address:MsgAddress excesses_address:MsgAddress cross_swap_body:CrossSwapBody = DexPayload;

custom_payload body

NameTypeDescription

op

uint32

Cross-swap op (0xffffffef)

other_token_wallet

address

Address of the other Router token wallet

refund_address

address

Address where refund will be sent if swap fails

excesses_address

address

Address where TON excesses will be sent

additional_data

cell

Cell with additional data

additional_data body

NameTypeDescription

min_out

coins

Minimum required amount of tokens to receive

receiver_address

address

Address where tokens will be sent after swap

fwd_gas

coins

Gas used to forward a message in transfer_notification after swap if custom_payload is present

custom_payload

maybe_ref

Payload sent in transfer_notification after swap

refund_fwd_gas

coins

Gas used to forward a message in transfer_notification if swap fails if refund_payload is present

refund_payload

maybe_ref

Payload sent in transfer_notification if swap fails

ref_fee

uint16

Referral fee

referral_address

address

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

cross_provide_liquidity_op#FFFFFEFF = CrossProvideLiquidityOP;
cross_provide_liquidity_body$_ min_lp_out:Coins to_address:MsgAddress both_positive:uint1 fwd_amount:Coins custom_payload:^Cell = CrossProvideLiquidityBody;
cross_provide_liquidity$_ transferred_op:CrossProvideLiquidityOP token_wallet1:MsgAddress refund_address:MsgAddress excesses_address:MsgAddress cross_provide_lp_body:CrossProvideLiquidityBody = DexPayload;

custom_payload body

NameTypeDescription

op

uint32

Cross-provide lp op (0xfffffeff)

other_token_wallet

address

Address of the other Router token wallet

refund_address

address

Address where refund will be sent if swap fails

excesses_address

address

Address where TON excesses will be sent

additional_data

cell

Cell with additional data

additional_data body

NameTypeDescription

min_lp_out

coins

Minimum required amount of lp tokens to receive

receiver_address

address

Address where lp tokens will be sent

both_positive

uint1

Trigger liquidity deposit only if both token amounts are non-zero

fwd_gas

coins

Gas used to forward a message in transfer_notification after mint if custom_payload is present

custom_payload

maybe_ref

Payload sent in transfer_notification after lp mint


Constants

NameValueDescription

storage_fee::router

10000000

Amount of TON (in nanoTons) to be left on the Router contract as gas

params::twodays

172800

Two days is seconds

params::sevendays

604800

Seven days in seconds

Last updated