Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This section describes different op codes of AMM smart contracts v2
The section contains separate documents for each smart contract used in AMM:
Definitions of terminology used can be found in Glossary
Example schemes can be found here:
A table with DEX v2 op codes:
custom payload & nested operations after swaps
chain multiple swaps on the same Router
chain multiple swaps on different v2 Routers
custom refund address and payload on swap failure
deadline for tx completion
custom payload after liquidly provision
improved initial liquidity locking management, no coins are lost anymore
now always mints a maximum possible amount of lp tokens to user even if provision ratio is different from current one in Pool
single side liquidity provision
deadline for tx completion
referral fees are stored in Vault
contract
custom referral fee value in each swap (maximum 1%)
now uses a custom op code for ton transfers
ton transfer to user is non-bouncable
improved gas management
can chain ton transfers between 2 pTON wallets (to chain pTON swaps on v2 Routers
)
LpAccount
and Vault
are deleted if they have 0 tokens on balance to avoid paying storage cost
better error management: no coins are lost if Pool
doesn't exist / payload is not correct
complete refactoring of the codebase and usage of libs in masterchain to make all operations cheaper
fixed various excesses issues
fixed some Pools
having broken get_jetton_data
off-chain get_expected_outputs
off-chain get_expected_tokens
off-chain get_expected_liquidity
on-chain getter_expected_outputs
on-chain getter_expected_tokens
on-chain getter_expected_liquidity
user-called collect_fees
This section contains api reference of the lp wallet contract
This is a standard Jetton token wallet for holding liquidity tokens. Only specific modifications for this implementation will be described.
burn
(0x595f07bc)Burn an amount of liquidity tokens.
op
uint32
Operation code is equal to burn
query_id
uint64
Query id
amount
coins
Amount of coins to burn (in basic token units)
response_destination
address
Address of a user
custom_payloads
maybe_ref
Payloads for token0 and token1
payload_0
maybe_ref
Payload used for amount0
; can be cross_swap
payload_1
maybe_ref
Payload used for amount1
; can be cross_swap
Sends a message with burn_notification_ext
op code to the router contract with the amount of token burnt.
This section contains api reference of the vault contract
Check examples for in-depth message flow.
get_vault_data
Returns Vault
data
None
Returns VaultData
structure containing current state of the Vault
.
RouterData
structure
owner_address
address
0
Owner of this Vault
token_address
address
1
Address of Router
's jetton wallet for s token'
router_address
address
2
Router
's address
deposited_amount
bigint
3
Amount of tokens collected
Handles calls from the Vault
owner
withdraw_fee
(0x354bcdf4)Burn an amount of liquidity tokens.
op
uint32
Operation code
query_id
uint64
Query id
Sends a message with vault_pay_to
op code to the router contract with the amount of token to be payed.
Handles calls from the Router
owner
deposit_ref_fee
(0x0490f09b)Increase ref fee tracker for the user.
op
uint32
Operation code
query_id
uint64
Query id
jetton_amount
bigint
Amount of the tokens
excesses_address
address
Address to receive TON excesses
Sends excesses to excesses_address
.
This section contains api reference of the lp account contract
get_lp_account_data
Returns current state of the LpAccount
.
None
Returns LpAccountData
structure containing current state of the lp account.
LpAccountData
structure
user_address
address
0
Owner's address
pool_address
address
1
Pool's address
amount0
coins
2
Balance of the first Jetton token (in basic token units)
amount1
coins
3
Balance of the second Jetton token (in basic token units)
On-chain counterparts of getter methods.
getter_lp_account_data
0x24cfc100
Sends a message with the current state of the pool
getter_lp_account_data
(0x24cfc100)Sends a message with current state of the lp account. On-chain equivalent of get_lp_account_data
.
None
Sends a message with current state of the lp account to sender_address
op
uint32
Operation code equal to getter_lp_account_data
query_id
uint64
Query id
user_address
address
Owner's address
pool_address
address
Pool's address
amount0
coins
Balance of the first Jetton token (in basic token units)
amount1
coins
Balance of the second Jetton token (in basic token units)
Handles incoming messages from a pool
add_liquidity
0x50c6a654
Add liquidity
add_liquidity
(0x50c6a654)Stores the sent amount of tokens by the user to be added as new liquidity. Upon receiving an appropriate amount of both tokens sends a message with those amounts to a pool to be added as new liquidity. The automatic liquidity addition happens only if the amount of both tokens if greater than 1000 and non-zero min_lp_out
was specified, otherwise the user can keep increasing the amount of stored tokens.
new_amount0
coins
Amount of the first Jetton tokens added (in basic token units)
new_amount1
coins
Amount of the second Jetton tokens added (in basic token units)
min_lp_out
coins
Minimum required amount of received new liquidity tokens (in basic token units)
fwd_amount
coins
Forward amount used to send custom_payload
(if present) in transfer_notification
both_positive
uint1
Trigger liquidity deposit only if both token amounts are non-zero
to_address
address
Owner of new liquidity tokens
custom_payload
maybe_ref
Payload sent in transfer_notification
upon receiving tokens
additional_fields
ref
See table below
refund_address
address
Address of the owner of LpAccount
where tokens will be refunded if liquidity mint wasn't successful
excess_address
address
Address where all TON excesses will be sent
Notes:
addition of liquidity will fail if a user should receive less than min_lp_out
of lp tokens as a result
Sends a message to the pool with cb_add_liquidity
op
op
uint32
Operation code, equal to cb_add_liquidity
query_id
uint64
Query id
amount0
coins
Amount of the first Jetton tokens added (in basic token units)
amount1
coins
Amount of the second Jetton tokens added (in basic token units)
user_address
address
Owner's address
min_lp_out
coins
Minimum amount of received liquidity tokens (in basic token units)
fwd_amount
coins
Forward amount used to send custom_payload
(if present) in transfer_notification
custom_payload
maybe_ref
Payload sent in transfer_notification
upon receiving tokens
additional_data
ref
See table below
to_address
address
Owner of new liquidity tokens
refund_address
address
Address of the owner of LpAccount
where tokens will be refunded if liquidity mint wasn't successful
excess_address
address
Address where all TON excesses will be sent
Notes:
addition of liquidity will fail if a user should receive less than min_lp_out
of lp tokens as a result
LpAccount
is deleted upon sending this message (Pool
always sends msgs with state_init
)
Handles incoming messages from a user
refund_me
0x132b9a2c
Return previously sent tokens back to the user
direct_add_liquidity
0x0ff8bfc6
Directly add liquidity with specified amount of tokens and a minimum amount of received liquidity tokens
reset_gas
0x29d22935
Reset gas
refund_me
(0x132b9a2c)Initiates a refund of stored tokens by add_liquidity
if the user decides to cancel the addition of new liquidity. The amount of stored tokens will be sent to the pool which will initiate a transfer back to the user.
None
Sends a message with cb_refund_me
op code and amount of stored tokens to a pool. The pool will send a message to refund those tokens back to the user.
op
uint32
Operation code
query_id
uint64
Query id
amount0
coins
Amount of the first Jetton tokens (in basic token units)
amount1
coins
Amount of the second Jetton tokens (in basic token units)
user_address
address
Owner's address
payload_0
maybe_ref
Payload used for amount0
; can be cross_swap
payload_1
maybe_ref
Payload used for amount1
; can be cross_swap
direct_add_liquidity
(0x0ff8bfc6)Initiates an addition of new liquidity to a pool with a specified amount of both tokens and a minimum amount of received liquidity. The operation is successful only if there's an equal or greater amount of both tokens stored in the account (the amount of both tokens must be greater than 1000). This method is useful if an automatic liquidity addition has not been triggered upon deposition of tokens.
amount0
coins
Amount of the first Jetton tokens (in basic token units)
amount1
coins
Amount of the second Jetton tokens (in basic token units)
min_lp_out
coins
Minimum amount of received liquidity tokens (in basic token units)
fwd_amount
coins
Forward amount used to send custom_payload
(if present) in transfer_notification
to_address
address
Owner of new liquidity tokens
custom_payload
maybe_ref
Payload sent in transfer_notification
upon receiving tokens
additional_fields
ref
See table below
refund_address
address
Address of the owner of LpAccount
where tokens will be refunded if liquidity mint wasn't successful
excess_address
address
Address where all TON excesses will be sent
Notes:
addition of liquidity will fail if a user should receive less than min_lp_out
of lp tokens as a result
min_lp_out
value must be greater than zero for this operation to proceed
Sends a message with cb_add_liquidity
op code and amount of both tokens to be added as new liquidity.
reset_gas
(0x29d22935)Updates the amount of TON (in nanoTons) on the lp account to storage_fee::lp_account
(10000000) of the account. The remaining TON will be sent back to the user_address
None
Sends an empty message back to the user with the remaining TON
storage_fee::lp_account
1000000
Amount of TON (in nanoTons) to be left on the lp account contract as gas
This section contains example schemes Vault operations
Token vault is used to store referral fees on a separate contract similar to lp account. This will allow us to decrease tx fees for swaps since users won't have to pay for additional jetton transfer tx.
Vault address is defined by router_address
, owner_address
and router_token_Wallet_address
, so for each token each user can have a dedicated vault contract.
Bob
is user doing the swap, Alice
is referral, Send
is send token, Receive
is receive token.
Withdraw op can be called by anyone, not only the Vault
owner. All excesses are sent to the owner.
Notes:
the Vault
contract is deleted on withdraw in order to not pay storage fees (each deposit sends state init so it will be redeployed as soon as any new deposit occurs)
This section contains api reference of the pool contract
get_pool_data
Returns the current state of the Pool
None
Returns PoolData
structure containing current state of the pool. Typed pools may return additional arguments if present
PoolData
structure
Notes:
fee ratio is the value of fee divided by params::fee_divider
(10000); so a fee of 1% has a value of 100
stableswap
)Additional data in PoolData
structure specific to stableswap pools
PoolData
structure additional params
get_lp_account_address
Get the lp account address of a user
Returns the lp account address of a user
get_jetton_data
Standard jetton 'get' methods from TonWeb JettonMinter.
None
Returns a structure with Jetton data
JettonData
structure
get_wallet_address
Get lp wallet address of a user.
Returns a calculated lp wallet address of a user
get_pool_type
Get Pool
type, equals to dex_type
param in get_router_data
None
Return pool type of this pool as string:
constant_product
stableswap
On-chain counterparts of getter methods.
getter_pool_data
(0x26df39fc)Sends a message with the current state of the pool. On-chain equivalent of get_pool_data
.
None
Sends a message with current pool data to the sender_address
additional_data
bodygetter_lp_account_address
(0x15fbca95)Sends a message with the lp account address of a user. On-chain equivalent of get_lp_account_address
.
Sends a message with the lp account address of a user to sender_address
provide_wallet_address
(0x2c76b973)Sends a message with the lp wallet address of a user. On-chain equivalent of get_wallet_address
.
Sends a message back to sender with the calculated lp wallet address of a user
additional_data
bodyHandles operations sent from a Jetton wallet.
burn_notification_ext
(0x297437cf)Sent by LpWallet
after burning LP jettons to release liquidity.
Sends a message with op excesses
(0xd53276db) to response_address
Sends a message with a released amount of both tokens to be received by a user as a result of the burn operation to the router, which initiates pay_to
operation to from_address
Handles messages from the router.
swap
(0x6664de2a)Swap tokens. This message is received from the router when the user initiates a token swap.
payload
bodyadditional_data
bodyNotes:
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%)
Sends a message with an amount of the other tokens to be received by a user as a result of the swap to the router, which initiates pay_to
operation
Additionally may send a message with referral fees to the router, which initiates pay_vault
operation to Vault
of referral_address
provide_lp
(0x37c096df)Provide liquidity for the pool. A user must submit an amount of both tokens to receive lp tokens and add new liquidity to a pool. This message is routed to liquidity pool account with add_liquidity
operation code.
payload
bodyadditional_data
bodySends a message to liquidity pool account with add_liquidity
operation code.
reset_gas
(0x29d22935)Updates the amount of TON (in nanoTons) on the pool to storage_fee::pool
(10000000) of the pool. The remaining amount of TON will be sent to excesses_address
.
Sends a message to excesses_address
with the remaining TON
internal_set_fees
(0x75930d63)Set new fee values including liquidity pool fees, protocol fees and referral fees as well as an address for receiving collected protocol fees.
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 params::min_fee
(0) and params::max_fee
(100)
Sends a message to excesses_address
with the remaining TON
Handles messages from the protocol_fee_address
.
collect_fees
(0x1ee4911e)Collect protocol fees. The amount of fees in both tokens will be sent to protocol_fee_address
address.
Sends a message with collected fees in both tokens to the router, which initiates pay_to
operation to protocol_fee_address
.
Handles messages from an lp account.
cb_add_liquidity
(0x06ecd527)Add new liquidity to the pool. Sent by user's lp account after both or one amounts tokens is sent by a user. The resulting added liquidity must be greater than min_lp_out
for the operation to be successful.
Notes:
addition of liquidity will fail if a user should receive less than min_lp_out
of lp tokens as a result
cannot add liquidity if a supply of either tokens becomes greater than MAX_COINS
(2^120 - 1)
Sends a message with internal_transfer
(0x178d4519) op code to the lp wallet of to_address
with minted liquidity tokens
cb_refund_me
(0x0f98e2b8)Sent by user's lp account after a user initiates refund_me
operation to cancel addition of new liquidity. The amount of previously stored tokens will be sent back to the user.
Sends a message with amount0
of the first token and amount1
of the second token to the router, which initiates pay_to
operation
This section contains example schemes for swap operations
Simple swap of one token to another.
Bob
is user doing the swap, Alice
is referral, Send
is send token, Receive
is receive token.
Swap of one token to another using an intermediary token. This method is used if there's no available pool for a pair of tokens but there're pools for each token and some other (the same for both) intermediary token. This type of swap is not limited to 1 intermediary: in practice an arbitrary amount of intermediaries can be used. This type of swap can be combined with cross-swap using multiple Routers
.
Bob
is user doing the swap, Send
is send token, Mid
is intermediary token, Receive
is receive token.
Swap of one token to another using different Routers
. This method is used if there's no available pool for a pair of tokens on the same Router but there're pools for each token and some other (the same for both) intermediary token on both Routers
. This type of swap is not limited to 1 intermediary: in practice an arbitrary amount of intermediaries can be used. This type of swap can be combined with cross-swap on the same Router
.
Bob
is user doing the swap, Send
is send token, Mid
is intermediary token, Receive
is receive token.
Refund swap if there's not enough liquidity in the pool or the expected amount of receive tokens is less than expected minimum. Since multi-contract transactions in TON are not atomic it is not possible to fully refund cross swap (on the same router or multiple), in such event the user will receive some intermediate token based on the pool used to route the swap.
Bob
is user doing the swap, Send
is send token, Receive
is receive token.
This section contains api reference of the router contract
get_vault_address
Returns an address of a vault for a specified asset and user.
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.
Returns Pool
address.
get_router_data
Returns the current state of the Router
None
Returns RouterData
structure containing current state of the Router
.
RouterData
structure
Notes:
possible dex_type
values:
constant_product
stableswap
get_router_version
Returns the current Router
version
None
Returns VersionData
structure containing Router
version.
RouterData
structure
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.
payload
bodyNotes:
payload
contains other fields depending on which op code is called
swap
(0x6664de2a)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.
payload
bodyadditional_data
bodyNotes:
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%)
Sends a message with op swap
to Pool
provide_lp
(0x37c096df)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.
payload
bodyadditional_data
bodySends a message with op provide_lp
to a liquidity pool
On-chain counterparts of getter methods
getter_pool_address
(0x2993ade0)Sends a message with an address of a pool for a specified pair of assets; counterpart to get_pool_address
Sends a message back to the sender with the pool address
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.
set_fees
(0x58274069)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.
additional_data
bodyNotes:
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)
Sends a message with op set_fees
to a liquidity pool.
update_status
(0x38a6022f)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
.
None.
None.
init_code_upgrade
(0x03601fc8)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.
Excesses will be sent to admin_address
init_admin_upgrade
(0x0b02fd5b)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.
Excesses will be sent to admin_address
cancel_admin_upgrade
(0x72d6b3b4)Cancels an admin change if there's a pending admin change.
None
Excesses will be sent to admin_address
cancel_code_upgrade
(0x1f72111a)Cancels a code upgrade if there's a pending code change.
None
Excesses will be sent to admin_address
finalize_upgrades
(0x4e6707b7)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.
None
None
reset_gas
(0x29d22935)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.
None
Excesses will be sent to admin_address
reset_pool_gas
(0x66d0dff2)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.
Sends a message to a liquidity pool with reset_gas
op code carrying remaining gas
update_pool_status
(0x2af4607c)Changes Pool
is_locked
var to the opposite value. If is_locked == 1
blocks swaps and liquidity withdraws from this Pool
Excesses will be sent to excesses_address
pay_to
(0x657b54f5)Initiates a Jetton token transfer from wallets belonging to this Router
, called from pools (on swap, liquidity providing, refund, etc).
additional_data
bodySends 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
to some Pool
if custom_payload
is cross_swap
pay_vault
(0x63381632)Deposit a token amount into a Vault
contract; used if swap
was done with referral
additional_data
bodySends deposit_ref_fee
to a corresponding token Vault
of to_address
vault_pay_to
(0x2100c922)Initiates a Jetton token transfer from wallets belonging to this Router
, called from a Vault
when an owner withdraws their collected referral fees.
Sends transfer of amount_out
tokens to to_address
message to token_address
wallet
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.
This payload allows chaining of swap operations on the same Router
; fwd_gas
is ignored.
custom_payload
bodyadditional_data
bodyThis section contains example schemes for liquidity provision
Liquidity provision is done via 2 transactions: deposit of the first token and deposit of the second token.
The amount of the first token sent is stored on a user's lp account awaiting a transaction of the second token.
When the second token is sent, lp account automatically initiates liquidity addition into the pool. As a result, full amounts of deposited tokens are used as new liquidity and the user receives lp tokens.
Notes:
the Lp Account
contract is deleted on cb_add_liquidity
in order to not pay storage fees (each deposit sends state init so it will be redeployed as soon as any new deposit occurs)
when depositing initial liquidity 0.000001001
lp tokens will be reserved on pool, the rest of liquidity will be sent to the user
It is possible to deposit liquidity by sending just 1 type of token, the pool will automatically perform a swap and use the resulting amount to mint lp tokens
It is possible to specify who will receive lp tokens and to include a payload which will be sent as transfer_notification
(e.g. Farm
contract)
In the event that the issued amount of lp tokens doesn't match the specified minimum value, all deposited liquidity is returned to lp account and can be withdrawn by user.
Liquidly is withdrawn from a pool by burning lp tokens, a user then receives both pool tokens based on the current exchange rate.
A user can deposit liquidity after it was refunded to lp account without doing a withdraw.
Check for in-depth message flow.
Check for in-depth message flow.
is_locked
bool
0
true if transfer_notification
operations are locked (swap
, provide_lp
)
router_address
address
1
Address of the Router
total_supply
coins
2
Total supply of lp tokens
reserve0
coins
3
Amount of the first token (in basic token units)
reserve1
coins
4
Amount of the second token (in basic token units)
token0_wallet_address
address
5
Address of the first Jetton token
token1_wallet_address
address
6
Address of the second Jetton token
lp_fee
uint16
7
Liquidity pool fee value
protocol_fee
uint16
8
Protocol fee
protocol_fee_address
address
9
Address for receiving protocol fees
collected_token0_protocol_fee
coins
10
Amount of collected protocol fees of the first token (in basic token units)
collected_token1_protocol_fee
coins
11
Amount of collected protocol fees of the second token (in basic token units)
amp
uint32
12
Stableswap amplification parameter
owner_address
address
Address of a user
total_supply
coins
0
Total token supply of lp tokens (in basic token units)
mintable
bool
1
always true
admin_address
address
2
Router
address
jetton_content_uri
string
3
Offchain uri with Jetton data
jetton_wallet_code
cell
4
Code of the lp Jetton wallet
owner_address
address
Address of a user
getter_pool_data
0x26df39fc
Sends a message with the current state of the pool
getter_lp_account_address
0x15fbca95
Sends a message with the lp account address of a user
provide_wallet_address
0x2c76b973
Sends a message with the lp wallet address of a user
op
uint32
Operation code is equal to getter_pool_data
query_id
uint64
Query id
is_locked
uint1
If this Pool
is locked
reserve0
coins
Amount of the first token (in basic token units)
reserve1
coins
Amount of the second token (in basic token units)
token0_address
address
Address of the first Jetton token
token1_address
address
Address of the second Jetton token
additional_data
cell
Cell with additional data
lp_fee
uint16
Liquidity pool fee value
protocol_fee
uint16
Protocol fee
router_address
address
Address of the Router
protocol_fee_address
address
Address for receiving protocol fees
total_supply
coins
Total amount of minted lp tokens
collected_token0_protocol_fee
coins
Amount of collected protocol fees of the first token (in basic token units)
collected_token1_protocol_fee
coins
Amount of collected protocol fees of the second token (in basic token units)
user_address
address
Address of a user
op
uint32
Operation code is equal to getter_expected_outputs
query_id
uint64
Query id
lp_account_address
address
lp account address of a user
owner_address
address
Address of a user
include_address?
uint1
Include user address in the response message
op
uint32
Operation code is equal to take_wallet_address
(0xd1735400)
query_id
uint64
Query id
lp_wallet_address
address
Calculated lp wallet address
additional_data
maybe_ref
Cell with data if include_address?
evaluates to true
included_address
address
Address of a user
burn_notification_ext
0x297437cf
Sent by LP wallet after burning LP jettons to release liquidity
jetton_amount
coins
Amount of liquidity tokens to burn (in basic token units)
from_address
address
User address
response_address
address
Address for a response message
custom_payloads
maybe_ref
Payloads for token0 and token1
payload_1
maybe_ref
Payload used for amount0
; can be cross_swap
payload_2
maybe_ref
Payload used for amount1
; can be cross_swap
swap
0x6664de2a
Swap tokens
provide_lp
0x37c096df
Provide liquidity
reset_gas
0x29d22935
Reset gas
set_fees
0x58274069
Set new fee parameters
from_user
address
User address
amount0
coins
Amount of incoming first token
amount1
coins
Amount of incoming second token
payload
cell
Cell with dex payload
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
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
from_user
address
User address
amount0
coins
Amount of incoming first token
amount1
coins
Amount of incoming second token
payload
cell
Cell with dex payload
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
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
excesses_address
address
Address where excess ton will be sent
new_lp_fee
uint16
New liquidity pool fee ratio (multiplied by params::fee_divider
)
new_protocol_fee
uint16
New protocol fee ratio (multiplied by params::fee_divider
)
new_protocol_fee_address
address
Address for receiving protocol fees
excesses_address
address
Address where TON excesses will be sent
collect_fees
0x1ee4911e
Collect fees
payload_0
maybe_ref
Payload used for amount0
; can be cross_swap
payload_1
maybe_ref
Payload used for amount1
; can be cross_swap
cb_add_liquidity
0x06ecd527
Sent by user's lp_account after adding liquidity
cb_refund_me
0x0f98e2b8
Sent by user's lp_account after adding liquidity
amount0
coins
Amount of the first Jetton tokens added (in basic token units)
amount1
coins
Amount of the second Jetton tokens added (in basic token units)
user_address
address
Owner's address
min_lp_out
coins
Minimum amount of received liquidity tokens (in basic token units)
fwd_amount
coins
Forward amount used to send custom_payload
(if present) in transfer_notification
custom_payload
maybe_ref
Payload sent in transfer_notification
upon receiving tokens
additional_data
ref
See table below
to_address
address
Owner of new liquidity tokens
refund_address
address
Address of the owner of LpAccount
where tokens will be refunded if liquidity mint wasn't successful
excess_address
address
Address where all TON excesses will be sent
amount0
coins
Amount of the first Jetton tokens (in basic token units)
amount1
coins
Amount of the second Jetton tokens (in basic token units)
user_address
address
Owner's address
payload_0
maybe_ref
Payload used for amount0
; can be cross_swap
payload_1
maybe_ref
Payload used for amount1
; can be cross_swap
storage_fee::pool
10000000
Amount of TON (in nanoTons) to be left on the pool contract as gas
params::required_min_liquidity
1001
Minimum amount of liquidity required
MAX_COINS
2^120 - 1
Maximum amount of tokens (in basic token units) stored as liquidity
gas::pool::provide_wallet_address
20000000
Additional gas (in nanoTons) for providing a wallet
params::fee_divider
10000
Fee values are divided by this value
params::min_fee
0
Minimum fee allowed (0%)
params::max_fee
100
Maximum fee allowed (1%)
swap
0x6664de2a
Token transfer payload op
for swap
provide_lp
0x37c096df
Token transfer payload op
for liquidity addition
cross_swap
0x69cf1a5b
Custom payload op in swap payload to chain swaps on the same Router
set_fees
0x58274069
Sent by admin to Router
to set new Pool
fees
reset_gas
0x29d22935
Sent by admin to Router
to reset gas
reset_pool_gas
0x66d0dff2
Sent by admin to Router
to reset Pool
gas
update_status
0x38a6022f
Sent by admin to Router
to change Router
lock status
init_code_upgrade
0x03601fc8
Sent by admin to Router
to initiate code upgrade
init_admin_upgrade
0x0b02fd5b
Sent by admin to Router
to initiate admin update
cancel_code_upgrade
0x1f72111a
Sent by admin to Router
to cancel code upgrade
cancel_admin_upgrade
0x72d6b3b4
Sent by admin to Router
to cancel admin update
finalize_upgrades
0x4e6707b7
Sent by admin to Router
to apply all pending updates if cooldown passed
update_pool_status
0x2af4607c
Sent by admin to Router
to change Pool
lock status
set_params
0x2b8b3b62
Sent by admin to Router
to update pool-specific params if present
direct_add_liquidity
0x0ff8bfc6
Sent by user to LpAccount
to initiate liquidity addition
refund_me
0x132b9a2c
Sent by user to LpAccount
to refund deposited tokens
withdraw_fee
0x354bcdf4
Sent by user to Vault
to collect their tokens
set_rate
0x4a2bddb0
Sent by setter to Pool
to change ratio variable (if present)
collect_fees
0x1ee4911e
Sent by protocol address to Pool
to collect fees
internal_set_fees
0x58274069
Sent from Router
to Pool
to change fees
reset_gas
0x29d22935
Sent from Router
to Pool
to rest gas
internal_update_status
0x62752512
Sent from Router
to Pool
to change Pool
lock status
internal_set_params
0x7163444a
Sent from Router
to Pool
to update pool-specific params if present
deposit_ref_fee
0x0490f09b
Sent from Router
to Vault
to deposit tokens in Vault
pay_to
0x657b54f5
Sent from Pool
to Router
to initiate token transfer
add_liquidity
0x50c6a654
Sent from Pool
to LpAccount
to add tokens
pay_vault
0x63381632
Sent from Pool
to Router
to deposit tokens in Vault
cb_add_liquidity
0x06ecd527
Sent from LpAccount
to Pool
to add liquidity
cb_refund_me
0x0f98e2b8
Sent from LpAccount
to Pool
to refund tokens
burn_notification_ext
0x297437cf
Sent from LpWallet
to Pool
after lp tokens burn
vault_pay_to
0x2100c922
Sent from Vault
to Router
to transfer tokens from Vault
to user
swap_refund_no_liq
0x5ffe1295
No liquidity in Pool
swap_refund_tx_expired
0x1ec28412
Swap transaction expired on Pool
swap_refund_reserve_err
0x38976e9b
Not enough liquidity to perform a swap
swap_refund_0_out
0x5f954434
Swap out token amount is 0
swap_refund_slippage
0x39603190
Swap out token amount is less than provided minimum value
swap_pool_locked
0x365c484d
Pool
is locked
swap_fee_out_of_bounds
0xa768c0d1
Ref fee is too big
swap_ok
0xc64370e5
Transfer after swap
burn_ok
0xdda48b6a
Transfer after liquidity withdraw (lp token burn)
refund_ok
0xde7dbbc2
Transfer after LpAccount
refund
transfer_bounce_locked
0x0a0dbdcb
Router
is locked
transfer_bounce_invalid_pool
0x09a8afbf
Incorrect Pool
(both token addresses are the same)
transfer_bounce_wrong_wc
0x720f5b17
Call was done from the wrong workchain
transfer_bounce_low_gas
0x8368a711
Not enough gas to preform operation
transfer_bounce_invalid_request
0x19727ea8
Incorrect token transfer payload op
transfer_bounce_tx_expired
0x0f5681d3
Transaction expired on Router
provide_refund_wrong_workchain
0x4e7405a8
Receiver of liquidity is in the wrong workchain
provide_refund_tx_expired
0xd6a53fd8
Provide transaction expired on Pool
provide_wallet_address
0x2c76b973
Received by Pool
to return lp wallet address for a specified user
take_wallet_address
0xd1735400
Send as a response to provide_wallet_address
with lp wallet address
getter_lp_account_data
0x24cfc100
On-chain getter with LpAccount
data
getter_pool_data
0x26df39fc
On-chain getter with Pool
common data
getter_lp_account_address
0x15fbca95
On-chain getter with LpAccount
address
getter_pool_address
0x2993ade0
On-chain getter with Pool
address
user
address
0
The address of the Vault
's owner
token
address
1
The address of the Router
's jetton wallet
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
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
major
uint
0
Major version
minor
uint
1
Minor version
development
string
2
Contains additional version info
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
transferred_op
uint32
Additional operation code
token_wallet1
address
The address of the Router
's wallet of second Jetton
swap
0x6664de2a
Swap one type of Jetton tokens for another
provide_lp
0x37c096df
Provide liquidity; route call to the correct pool
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
deadline
uint64
Timestamp of execution deadline for this tx
additional_data
cell
Cell with additional data
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
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
deadline
uint64
Timestamp of execution deadline for this tx
additional_data
cell
Cell with additional data
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
getter_pool_address
0x2993ade0
Sends a message with a pool address for a requested token pair; counterpart to get_pool_address
token0
address
The address of the Router
's wallet of first Jetton
token1
address
The address of the Router
's wallet of second Jetton
op
uint32
Operation code equal to getter_pool_address
query_id
uint64
Query id
pool_address
address
Address of a pool
set_fees
0x58274069
Change fee parameters of a pool
reset_pool_gas
0x66d0dff2
Update the amount of TON (in nanoTons) on a pool to storage_fee::router
of a pool
update_pool_status
0x2af4607c
Change Pool
status
update_status
0x38a6022f
Change Router
status
init_code_upgrade
0x03601fc8
Initiate code upgrade for the Router
init_admin_upgrade
0x0b02fd5b
Initiate admin change for the Router
cancel_admin_upgrade
0x72d6b3b4
Cancel an admin change
cancel_code_upgrade
0x1f72111a
Cancel a code upgrade
finalize_upgrades
0x4e6707b7
Finalize upgrades of the Router
code and admin change
reset_gas
0x29d22935
Update the amount of TON (in nanoTons) on the Router
to storage_fee::router
of the Router
set_params
0x2b8b3b62
Change pool-specific parameters
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
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
new_code
cell
Code of the new Router
contract
new_admin
address
New admin address
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
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
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
original_caller
address
Address of the original tx sender
exit_code
uint32
Exit code
custom_payload
maybe_ref
Payload sent in transfer_notification
additional_data
cell
Cell with additional data
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
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
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
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
op
uint32
Cross-swap op (0x69cf1a5b)
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
deadline
uint64
Timestamp of execution deadline for this tx
additional_data
cell
Cell with additional data
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
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