You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0045-transaction_fee_minting.md
+59-24Lines changed: 59 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,10 +41,15 @@ This proposal suggests **0.01 HTR per output**.
41
41
Apart from accepting HTR for fee payment, any deposit-based token will be accepted. In this case, since the token was created with a 100:1 ratio of HTR ([deposit model](#deposit-based-model-as-is)), the fee needs to be 100x the HTR rate. That means **0.01 HTR or 1.00 deposit-based-token**.
42
42
43
43
### Fee and melting operations
44
-
The fee will be charged before any melting operation and doesn't require any authority for it.
44
+
In the examples below we'll use Fee-based Token (FBT), and Deposit-based Token (DBT) as our tokens.
45
+
46
+
To accept deposit tokens, the transaction should have an amount >= 100, for example:
47
+
48
+
Inputs: [100 FBT, 150 DBT]
49
+
Outputs: [100 FBT, 100 DBT]
50
+
Since 50 DBT represents an withdraw of 0 HTR, this operation should be blocked and considered an attempt to melt without an authority.
45
51
46
52
For instance, if there is a transaction with:
47
-
Fee-based Token (FBT), Deposit-based Token (DBT)
48
53
49
54
Inputs: [1000 FBT, FBT Melt Authority, 500 DBT]
50
55
Outputs: [500 FBT, 400 DBT]
@@ -101,32 +106,62 @@ The `calculate_fee` method will receive a `token_dict` as input, then count the
101
106
It will consider 1 output for melting operations that don't have any output.
102
107
It won't consider mint and melt authorities.
103
108
104
-
The `collect_fee` method will receive the `token_dict` and the fee. It will use the differences between the input and output amounts and return the paid fee in HTR. For each token that has a difference, it will collect the fee by incrementing the amount value in the corresponding `token_dict` entry.
105
-
106
109
## Transaction verifier
107
110
108
-
### verify_fee()
109
-
Inside the transaction verifier, the `verify_fee` method will be added. It's responsible for orchestrating the fee flow by checking if the fee should be charged, calculating it, and checking the payment availability:
110
-
111
-
Example:
112
-
```python
113
-
ifnot should_charge_fee(token_dict):
114
-
return
115
-
116
-
fee = calculate_fee(token_dict)
117
-
paid_fee = collect_fee(token_dict)
118
-
119
-
if fee - paid_fee >0:
120
-
raise InputOutputMismatch(
121
-
'HTR or deposit tokens are not enough to pay the fee. (amount={}, expected={})'.format(
122
-
paid_fee,
123
-
fee,
124
-
))
125
-
```
126
-
127
111
### verify_sum()
112
+
The `verify_sum` method will be modified to match the following based on the `token_dict` result:
113
+
114
+
- Only calculate a fee value if the `should_charge_fee()` method returns `True`.
115
+
- It will call the `calculate_fee()` method from `fee.py` as the `fee`.
116
+
117
+
For deposit tokens:
118
+
- It will sum all the deposit based tokens withdraws with melt authority
119
+
- It will sum all the deposit based tokens withdraws without a melt authority:
120
+
- When the amount of a token is a multiple of 100, otherwise it will be **treated as an attempt of melting without an authority**.
121
+
- For example, `99 DBT` isn't represents `1 HTR` and an `InputOutputMismatch` error will be raised.
122
+
- Also, `101 DBT` and `199 DBT` represents `1 HTR` and a `InputOutputMismatch` error will be raised, blocking the melting.
123
+
- It will **reject** any deposit based token which tries to **mint without an authority**.
124
+
- It'll **reject** if the sum of the **withdraws without an authority** are **higher than** the `fee`. If this validation fails, an `InputOutputMismatch` error will be raised.
125
+
126
+
For fee tokens:
127
+
- It will reject any Fee based token which tries to **melt** or **melt** without an authority.
128
+
129
+
The assertions above are placed to guaranteed the following equality:
130
+
131
+
diffHTR = HTR Output - HTR Input
132
+
fee = result of fee calculation
133
+
withdraw_without_authority = sum of withdraw by melting deposit based tokens without an authority
134
+
withdraw = sum of withdraw by melting deposit based tokens with an authority
135
+
deposit = sum of the required HTR to mint deposit based tokens
Since we already normalized the `token_dict` values in the `verify_fee` method before calling this one, we just need to adjust the withdraw and deposit amounts here, collecting only for deposit tokens.
130
165
131
166
## Feature flag in settings
132
167
For development purposes, this feature will be feature-flagged to run only on the local network by setting the `FEE_FEATURE_FLAG` in settings to true.
0 commit comments