Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The pool implements weighted voting for network config proposals:

## Get methods

### `get_pool_data`
#### Get-method get_pool_data

Returns complete pool state information as a tuple containing:

Expand Down Expand Up @@ -161,7 +161,7 @@ validator_reward = (reward * validator_reward_share) / 10000
17. `config_proposal_votings` (Cell)
Raw dictionary of active proposal votes

### `list_nominators`
#### Get-method list_nominators

Returns an array of all nominators with their:

Expand All @@ -174,7 +174,7 @@ Returns an array of all nominators with their:
4. `withdraw_request` (int)
`-1` indicates active withdrawal request

### `get_nominator_data`
#### Get-method get_nominator_data

Returns detailed nominator information for the specified address.

Expand All @@ -193,16 +193,17 @@ For nominator `EQA0i8-CdGnF_DhUHHf92R1ONH6sIA9vLZ_WLcCIhfBBXwtG`:
get_nominator_data 0x348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f
```


### Voting Methods

#### `list_votes`
#### Get-method list_votes

Returns all active proposals with the following:

1. `proposal_hash` (uint) - Convert with `dec_to_hex()`
2. `votes_create_time` (uint) - Unix timestamp

#### `list_voters(proposal_hash)`
#### Get-method list_voters

Returns voting details per proposal:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ If you have a single nominator who holds all stakes for validation, this is the

The nominator owner can perform 4 operations:

### 1. Withdraw

This is used to withdraw funds to the owner's wallet. To withdraw the funds, the owner should send a message with a body that includes opcode=0x1000 (32 bits), query_id (64 bits), and the withdrawn amount (stored as a coin variable). The nominator contract will send the funds with the BOUNCEABLE flag and mode=64.

In case the owner is using a **hot wallet** (not recommended), [withdraw-deeplink.ts](https://github.com/ton-blockchain/single-nominator/blob/main/scripts/ts/withdraw-deeplink.ts) can be used to generate a deeplink to initiate a withdrawal from tonkeeper wallet.
#### 1. Withdraw
Used to withdraw funds to the owner's wallet. To withdraw the funds the owner should send a message with a body that includes: opcode=0x1000 (32 bits), query_id (64 bits) and withdraw amount (stored as coin variable). The nominator contract will send the funds with BOUNCEABLE flag and mode=64. <br/><br/>
In case the owner is using a **hot wallet** (not recommended), [withdraw-deeplink.ts](https://github.com/ton-blockchain/single-nominator/blob/main/scripts/ts/withdraw-deeplink.ts) can be used to generate a deeplink to initiate a withdrawal from tonkeeper wallet. <br/>

Command line: `ts-node scripts/ts/withdraw-deeplink.ts single-nominator-addr withdraw-amount` where:

Expand Down
3 changes: 2 additions & 1 deletion docs/v3/documentation/smart-contracts/func/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ forall X -> (tuple) to_tuple (X x) asm "NOP";



### How to write custom functions using the `asm` keyword
### How to write own functions using asm keyword


Many features we use in FunC come from pre-prepared methods inside `stdlib.fc`. However, we have many more capabilities, and learning to write custom functions unlocks new possibilities.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
# Accept Message Effects

`accept_message` and `set_gas_limit` may cause not that straightforward effects when doing exactly what is said in the [stdlib reference](/v3/documentation/smart-contracts/func/docs/stdlib#accept_message).
The `accept_message` and `set_gas_limit` TVM primitives play a crucial role in managing gas limits and transaction processing in TON smart contracts. While their basic functionality is documented in the [stdlib reference](/v3/documentation/smart-contracts/func/docs/stdlib#accept_message), their effects on transaction processing, gas limits, and contract balances can be complex and have important security implications. This page explores these effects in detail, particularly focusing on how they impact external and internal message processing.

## External messages

External messages are processed as follows:
- The `gas_limit` is set to `gas_credit` (ConfigParam 20 and ConfigParam 21), which is equal to 10k gas.
- During the spending of those credits, a contract should call `accept_message` to `set_gas_limit`, indicating that it is ready to pay fees for message processing.
- If `gas_credit` is reached or computation is finished, and `accept_message` is not called, the message will be completely discarded (as if it never existed at all).
- Otherwise, a new gas limit, equal to `contract_balance/gas_price` (in the case of `accept_message`) or a custom number (in the case of `set_gas_limit`), will be set; after the transaction ends, full computation fees will be deducted from the contract balance (in this way, `gas_credit` is indeed **credit**, not free gas).
External messages follow this processing flow:
- The `gas_limit` is initially set to `gas_credit` ([Param20/Param21](v3/documentation/network/configs/blockchain-configs#param-20-and-21)), which equals 10k gas units
- During credit spending, a contract must call `accept_message` to `set_gas_limit`, indicating its readiness to pay processing fees
- If `gas_credit` is depleted or computation completes without `accept_message`, the message is discarded (as if it never existed)
- Otherwise, a new gas limit is set to either:
- `contract_balance/gas_price` (with `accept_message`)
- A custom value (with `set_gas_limit`)
- After transaction completion, full computation fees are deducted from the contract balance (making `gas_credit` truly a credit, not free gas)


Note that if, after `accept_message`, some error is thrown (either in ComputePhase or ActionPhase), the transaction will be written to the blockchain, and fees will be deducted from the contract balance. However, storage will not be updated, and actions will not be applied, as is the case in any transaction with an error exit code.
If an error occurs after `accept_message` (in either Compute or Action phase):
- The transaction is recorded on the blockchain
- Fees are deducted from the contract balance
- Storage remains unchanged
- Actions are not applied

As a result, if the contract accepts an external message and then throws an exception due to an error in the message data or the sending of an incorrectly serialized message, it will pay for processing but will have no way of preventing message replay. **The same message will be accepted by the contract over and over until it consumes the entire balance.**
**Critical Security Consideration:**
If a contract accepts an external message and then throws an exception (due to invalid message data or serialization errors), it:
- Pays for processing
- Cannot prevent message replay
- Will continue accepting the same message until its balance is depleted

## Internal message


## Internal message

By default, when a contract receives an internal message, the gas limit is set to `message_balance`/`gas_price`. In other words, the message pays for its processing. By using `accept_message`/`set_gas_limit`, the contract may change the gas limit during execution.
When a contract receives an internal message from another contract:
- Default gas limit: `message_value`/`gas_price` (message covers its own processing)
- The contract can modify this limit using `accept_message`/`set_gas_limit`

Note that manual settings of gas limits do not interfere with bouncing behavior; messages will be bounced if sent in bounceable mode and contain enough money to pay for their processing and the creation of bounce messages.

:::info example
For instance, if you send a bounceable message with 0.1 TON in the basechain that is accepted by a contract with a 1 TON balance, and the computation costs 0.005 TON, with a message fee of 0.001 TON, then the bounce message will contain `0.1 - 0.005 - 0.001` = `0.094` TON.
**Case 1:**
If you send a bounceable message with 0.1 TON in the basechain that is accepted by a contract with a 1 TON balance, and the computation costs 0.005 TON, with a message fee of 0.001 TON, then the bounce message will contain `0.1 - 0.005 - 0.001` = `0.094` TON.

**Case 2:**
If in the same example, the computation cost is 0.5 (instead of 0.005), there will be no bounce (the message balance would be `0.1 - 0.5 - 0.001 = -0.401`, thus no bounce), and the contract balance will be `1 + 0.1 - 0.5` = `0.6` TON.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

:::caution
This section describes instructions and manuals for interacting with TON at a low level.

Here you will find the **raw formulas** for calculating commissions and fees on TON.

However, most of them are **already implemented through opcodes**! So, you **use them instead of manual calculations**.
However, most of them are **already implemented through opcodes**!
So, you **use them instead of manual calculations**.
:::

This document provides a general idea of transaction fees on TON and particularly computation fees for the FunC code. There is also a [detailed specification in the TVM whitepaper](https://ton.org/tvm.pdf).
Expand All @@ -18,15 +17,14 @@ As was described in the [TVM overview](/v3/documentation/tvm/tvm-overview), tran

TON validators collect storage fees from smart contracts.

Storage fees are collected from the smart contract `balance` at the **Storage phase** of **any** transaction due to storage payments for the account state
(including smart-contract code and data, if present) up to the present time. Even if [contract received 1 nanoton](https://retracer.ton.org/?tx=1805820dccd7ffd70d6cee6cb581e60ee2f91f7f3eeb20ed00c08dc9fcd6a08b) it will pay all the debt since last payment. The smart contract may be frozen as a result. **Only unique hash cells are counted for storage and forward fees i.e. 3 identical hash cells are counted as one**. In particular, it [deduplicates](/v3/documentation/data-formats/tlb/library-cells) data: if there are several equivalent sub-cells referenced in different branches, their content is only stored once.
Storage fees are collected from the smart contract `balance` at the **Storage phase** of **any** transaction due to storage payments for the account state (including smart-contract code and data, if present) up to the present time. Even if a contract receives 1 nanoton, it will pay all the debt since the last payment. The smart contract may be frozen as a result. **Only unique hash cells are counted for storage and forward fees i.e. 3 identical hash cells are counted as one**. In particular, it [deduplicates](/v3/documentation/data-formats/tlb/library-cells) data: if there are several equivalent sub-cells referenced in different branches, their content is only stored once.

Its important to keep in mind that on TON you pay for both the execution of a smart contract and for the **used storage** (check [@thedailyton article](https://telegra.ph/Commissions-on-TON-07-22)), `storage_fee` depends on your contract size: number of cells and sum of bits from that cells. It means you have to pay a storage fee for having TON Wallet (even if it's very-very small).
It's important to keep in mind that on TON you pay for both the execution of a smart contract and for the **used storage** (check [@thedailyton article](https://telegra.ph/Commissions-on-TON-07-22)), `storage_fee` depends on your contract size: number of cells and sum of bits from that cells. It means you have to pay a storage fee for having TON Wallet (even if it's very-very small).

If you have not used your TON Wallet for a significant period of time (1 year), _you will have to pay a significantly larger commission than usual because the wallet pays commission on sending and receiving transactions_.

:::info **Note**:
When message is bounced from the contract, the contract will pay it's current `storage_fee`
:::info **Note**:
When a message is bounced from the contract, the contract will pay its current `storage_fee`
:::

### Formula
Expand Down Expand Up @@ -64,7 +62,7 @@ Current values are:
mc_cell_price_ps:500000
```

### Calculator Example
### Calculator example

You can use this JS script to calculate storage price for 1 MB in the workchain for 1 year

Expand Down Expand Up @@ -297,10 +295,10 @@ For educational purposes [example of the old one](https://explorer.toncoin.org/c

## References

- Based on @thedailyton [article](https://telegra.ph/Fees-calculation-on-the-TON-Blockchain-07-24) from 24.07\*
- Based on @thedailyton [article](https://telegra.ph/Fees-calculation-on-the-TON-Blockchain-07-24) from July 24th

## See Also
## See also

- [TON Fees overview](/v3/documentation/smart-contracts/transaction-fees/fees)
- [Transactions and Phases](/v3/documentation/tvm/tvm-overview#transactions-and-phases)
- [Transactions and phases](/v3/documentation/tvm/tvm-overview#transactions-and-phases)
- [Fees calculation](/v3/guidelines/smart-contracts/fee-calculation)
16 changes: 8 additions & 8 deletions docs/v3/documentation/smart-contracts/transaction-fees/fees.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ The price of gas units is determined by the [chain configuration](https://tonvie
Current settings in basechain are as follows: 1 unit of gas costs 400 nanotons.

```cpp
1 gas = 26214400 / 2^16 nanotons = 0,000 000 4 TON
1 gas = 26214400 / 2^16 nanotons = 0.000 000 4 TON
```

Current settings in masterchain are as follows: 1 unit of gas costs 10000 nanotons.

```cpp
1 gas = 655360000 / 2^16 nanotons = 0,000 01 TON
1 gas = 655360000 / 2^16 nanotons = 0.000 01 TON
```

### Average transaction cost
Expand All @@ -34,7 +34,7 @@ The current gas amount is written in the Network Config [param 20](https://tonvi

The gas fee, like many other parameters of TON, is configurable and may be changed by a special vote made in the mainnet.

Changing any parameter requires getting 66% of the validator votes.
Changing any parameter requires approval from 66% of the validators' votes.

#### Could gas cost more?

Expand All @@ -48,7 +48,7 @@ Validators receive a small fee for processing transactions, and charging higher

Fees on TON are difficult to calculate in advance, as their amount depends on transaction run time, account status, message content and size, blockchain network settings, and a number of other variables that cannot be calculated until the transaction is sent.

That is why even NFT marketplaces usually take an extra amount of TON (_~1 TON_) and return (_`1 - transaction_fee`_) later.
That is why NFT marketplaces typically require an extra amount of TON (~1 TON) and refund the remaining amount (1 - transaction_fee) after the transaction.

:::info
Each contract should check incoming messages for the amount of TON attached to ensure it is enough to cover the fees.
Expand Down Expand Up @@ -146,21 +146,21 @@ The average fee for minting one NFT is 0.08 TON.

### Cost of saving data in TON?

Saving 1 MB of data for one year on TON will cost 6.01 TON. Note that you usually dont need to store large amounts of data on-chain. Consider using [TON Storage](/v3/guidelines/web3/ton-storage/storage-daemon) if you need decentralized storage.
Saving 1 MB of data for one year on TON will cost 6.01 TON. Note that you usually don't need to store large amounts of data on-chain. Consider using [TON Storage](/v3/guidelines/web3/ton-storage/storage-daemon) if you need decentralized storage.

### Is it possible to send a gasless transaction?

In TON, gasless transactions are possible using [wallet v5](/v3/documentation/smart-contracts/contracts-specs/wallet-contracts#preparing-for-gasless-transactions) a relayer that pays the gas fee for transaction.

### How to calculation?
### How to calculate fees?

There is an article about [fee calculation](/v3/guidelines/smart-contracts/fee-calculation) in TON Blockchain.

## References

- Based on the [@thedailyton article](https://telegra.ph/Commissions-on-TON-07-22) originally written by [menschee](https://github.com/menschee)\*
- Based on the [@thedailyton article](https://telegra.ph/Commissions-on-TON-07-22) originally written by [menschee](https://github.com/menschee)

## See Also
## See also

- ["Low-level fees overview"](/v3/documentation/smart-contracts/transaction-fees/fees-low-level)—read about the formulas for calculating commissions.
- [Smart contract function to calculate forward fees in FunC](https://github.com/ton-blockchain/token-contract/blob/main/misc/forward-fee-calc.fc)
Loading
Loading