Skip to content

Commit ce974a6

Browse files
committed
adding fee calculation and pow
1 parent 7953366 commit ce974a6

1 file changed

Lines changed: 46 additions & 52 deletions

File tree

text/0045-transaction_fee_minting.md

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,80 +32,74 @@ Adding the fee-based model the platform won't require an upfront deposit. Instea
3232

3333
By selecting the appropriate model, token creators can optimize their minting strategy based on their specific needs and usage scenarios. A key use case is the creation of memecoins.
3434

35-
### An hybrid approach
35+
### How to pproach
3636

37-
An alternative to bitcoin and etherium approchaes for blockchain fees is a hybrid model that combines minimum fees with payments based on actual resource usage, along with policies to prevent spam on the network. This model aims to balance user simplicity, protection against spam attacks, and long-term sustainability.
37+
An alternative to bitcoin and etherium approchaes for blockchain fees is a hybrid model that combines fees based in the transaction size, with priority tip payments.
3838

3939
This model offers several advantages. First, it simplifies the user experience by providing a predictable fee without major fluctuations. Additionally, it enables a filtering mechanism to prevent excessively large or complex transactions, protecting the network from spam. Finally, its structure promotes sustainability, ensuring controlled blockchain growth.
4040

41-
### General Fee calculation rule
41+
### Fee calculation
4242

43+
Hathor’s fees will be calculated similarly to Bitcoin, depending only on transaction size (in bytes) and a network-defined fee rate (in HTR per byte).
44+
45+
Proof-of-Work difficulty (transaction weight) will not influence the fee calculation.
46+
47+
Let's assume:
4348
1. HTR is always used as the fee unit, regardless of the tokens involved in the transaction.
44-
2. If only fee-based tokens are used, a single fee in HTR will be charged, regardless of the number of tokens.
45-
3. If a transaction includes both deposit-based and fee-based tokens, only the fee-based tokens will incur a fee.
46-
4. Interacting with nano contracts may introduce an additional fee depending on the execution complexity.
49+
2. Even if fee-based tokens are used alone, or with a deposit-based token, a single fee in HTR will be charged, regarding the transaction size.
50+
3. Interacting with nano contracts may introduce an additional fee depending on the execution complexity.
4751

48-
### Example Scenarios
52+
Below is a pseudo code that explain how fee should be calculated, using a fee rate per byte:
4953

50-
#### Swapping Token A for Token A with a fee paid in HTR (fee in HTR)
54+
*(Note: Excluded "hash" size from calculation, hence 114 reduced to 84 bytes.)*
5155

52-
Description: Transfer of the same token (A) between two parties.
56+
```python
57+
def calculate_tx_fee(tx, fee_rate_per_byte):
58+
# Fixed size fields (always present)
59+
fixed_size = 84 # version (2) + timestamp (4) + nonce (4) + weight (8) + parents (64)
5360

54-
Fee Calculation:
61+
# Tokens array size
62+
tokens_size = 32 * len(tx.tokens)
5563

56-
- Since Token A is fee-based, the transaction requires a fee in HTR.
57-
```
58-
- Base Fee: 0.001 HTR
59-
- Total Fee: 0.001 HTR (regardless of the amount transferred)
60-
```
61-
----
62-
#### Token A x Token B x Token C (only 1 fee, in HTR)
64+
# Inputs size calculation
65+
inputs_size = 0
66+
for input in tx.inputs:
67+
inputs_size += 35 + len(input.data)
68+
# 32 bytes (tx_id) + 1 byte (index) + 2 bytes (data length prefix) + len(data)
6369

64-
Description: Multi-token transfer involving three fee-based tokens.
70+
# Outputs size calculation
71+
outputs_size = 0
72+
for output in tx.outputs:
73+
outputs_size += 7 + len(output.script)
74+
# 4 bytes (value) + 1 byte (token_data) + 2 bytes (script length prefix) + len(script)
6575

66-
Fee Calculation:
67-
- Only one HTR fee is charged, regardless of the number of tokens.
68-
```
69-
- Base Fee: 0.001 HTR
70-
- Complexity Fee (extra tokens): 0.0005 HTR per additional token.
71-
- Total Fee: 0.002 HTR (0.001 + 0.0005 + 0.0005)
72-
```
76+
# Total transaction size
77+
tx_size = fixed_size + tokens_size + inputs_size + outputs_size
7378

74-
#### Token A x HTR (fee in HTR)
79+
# Fee calculation
80+
fee = tx_size * fee_rate_per_byte
7581

76-
Description: Transfer of a fee-based token and HTR in the same transaction.
82+
return fee + tx.priority_tip # plus any nano fee that should match
7783

78-
Fee Calculation:
79-
- Since a fee-based token is involved, an HTR fee will be charged.
80-
```
81-
- Base Fee: 0.001 HTR
82-
- Total Fee: 0.001 HTR
8384
```
8485

85-
#### Token D (deposit-based) x Token B (fee-based)
86-
Description: Transfer of a deposit-based token (D) and a fee-based token (B).
8786

88-
Fee Calculation:
89-
- The deposit-based token (D) does not pay a fee.
90-
- The fee-based token (B) pays the standard fee.
87+
### **Example Calculation:**
9188

92-
```
93-
- Base Fee: 0.001 HTR
94-
- Total Fee: 0.001 HTR (no extra charge for Token D)
95-
```
89+
**Hypothetical Transaction:**
90+
- 1 token UID
91+
- 2 inputs (with 108 bytes of data each, common signature size)
92+
- 2 outputs (with 25 bytes of script each, common P2PKH script)
9693

97-
#### Transaction Interacting with a Nano Contract
98-
Description: A transfer involving a nano contract, which may require additional execution on the network.
94+
Calculate size:
9995

100-
Fee Calculation:
101-
- The standard transaction base fee still applies.
102-
- Since nano contract execution involves additional computation, an extra fee may be charged based on complexity.
103-
- Execution Fee (depends on contract complexity): Example, 0.002 HTR.
104-
105-
```
106-
- Base Fee: 0.001 HTR
107-
- Total Fee: 0.003 HTR (0.001 base + 0.002 contract execution)
108-
```
96+
| Field | Calculation | Size |
97+
|----------------------|-----------------------------|----------|
98+
| Fixed-size fields | | **84** bytes |
99+
| Tokens | 1 token × 32 bytes | **32** bytes |
100+
| Inputs | 2 × (35 + 108) | **286** bytes |
101+
| Outputs | 2 × (7 + 25) | **64** bytes |
102+
| **Total Tx Size** | 84 + 32 + 286 + 64 | **466** bytes |
109103

110104
## Wallet UI
111105

0 commit comments

Comments
 (0)