Stake
This section describes how to stake.
Overview
In Financial contract there is an op-code OP::SIMPLE_TRANSFER
. It's used to perform staking of TON in the contract, resulting in the creation of a corresponding amount of jettons in exchange for the staked TON. The current pools of jettons and TON are taken into account, allowing the calculation of the amount of jettons to be created dynamically. If the operation is successful, the total supply of jettons and TON is updated, and the newly minted jettons are sent to the user's wallet address.
OP::SIMPLE_TRANSFER
: Calls the mint function with aquery_id
of0
. It is a simple invocation that doesn’t pass any extra data.
When a user stakes a certain amount of TON (msg_value
), the number of jettons to be minted is determined based on the existing jetton and TON pools. The process involves the following formulas: Determining the Number of Jettons to Be Minted
The number of Jettons minted (stake_jetton_amount) is calculated using the formula: stake_jetton_amount = jetton_total_supply * stake_ton_amount / ton_total_supply
Where:
jetton_total_supply
is the total supply of Jettons before staking.ton_total_supply
is the total amount of staked TON before the staking operation.stake_ton_amount
is the amount of TON to be staked after subtracting any relevant fees (int stake_ton_amount = msg_value - DEPOSIT_PROCESSING_FEE
.
Steps to verify the result of staking operation:
To ensure the staking operation was executed correctly, follow these steps:
1.Check the updated jetton and TON total supply in the Financial contract:
Verify that the
jetton_total_supply
has increased by the calculatedstake_jetton_amount
.Ensure that the
ton_total_supply
has increased bystake_ton_amount
.
2.Confirm the transfer of Jettons:
The minted jettons should be sent to the user’s jetton wallet address. Verify that the correct amount was transferred.
The transaction should use the
OP::INTERNAL_TRANSFER
, and thequery_id
be0
.
Common errors that may occur during processing OP::SIMPLE_TRANSFER
When performing operations in a smart contract, various errors can occur due to incorrect input, insufficient funds, or other issues. To handle these errors effectively, it’s important to understand what kind of errors might arise, how to catch them, and how to determine the underlying issue. Below is a detailed guide on common errors, how to detect them, and troubleshooting strategies.
ERROR::INSUFFICIENT_MSG_VALUE
Cause: This error occurs when the provided message value (
msg_value
) is less than the required amount to perform the operation. Message value must be greater than 0.05 TON (DEPOSIT_PROCESSING_FEE)
.How to Detect: Check if the contract throws this error when the condition
msg_value - DEPOSIT_PROCESSING_FEE <= 0
is true.Troubleshooting: Ensure that the amount sent in the transaction is enough to cover the required fees and the intended operation.
ERROR::NOT_WORKCHAIN
Cause: This error happens when the message is sent from a non-basechain workchain (i.e., not workchain 0). The contract may be designed to only accept transactions from the main chain.
How to Detect: The contract checks if the sender’s workchain is not equal to 0 and throws this error if true.
Troubleshooting: Ensure that the transaction is being sent from the basechain (workchain = 0). Verify the sender address and ensure that it matches the expected workchain for the operation.
Example of sending stake message using pytoniq:
So, to create a payload cell you need to provide the following params:
OP::SIMPLE_TRANSFER
(0
) - The operation code indicating the type of operation. Represented by a 32-bit unsigned integer
Or you can just send tons attached to the empty message to the Financial contract
Let's write a simple code that builds payload cell and sends message to Financial:
Last updated