Skip to content

Commit 6458143

Browse files
committed
reference level update
1 parent 14e0666 commit 6458143

1 file changed

Lines changed: 59 additions & 24 deletions

File tree

text/0045-transaction_fee_minting.md

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ This proposal suggests **0.01 HTR per output**.
4141
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**.
4242

4343
### 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.
4551

4652
For instance, if there is a transaction with:
47-
Fee-based Token (FBT), Deposit-based Token (DBT)
4853

4954
Inputs: [1000 FBT, FBT Melt Authority, 500 DBT]
5055
Outputs: [500 FBT, 400 DBT]
@@ -101,32 +106,62 @@ The `calculate_fee` method will receive a `token_dict` as input, then count the
101106
It will consider 1 output for melting operations that don't have any output.
102107
It won't consider mint and melt authorities.
103108

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-
106109
## Transaction verifier
107110

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-
if not 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-
127111
### 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
136+
137+
diffHTR + fee = withdraw + withdraw_without_authority - deposit
138+
139+
140+
Let's use the same example of the guide level explanation use the following tokens: Deposit Based Token (DBT), and Fee Based Token (FBT).
141+
142+
Inputs: [2 HTR, 100 FBT, 200 DBT, 100 DBT3, 100 DBT3 melt authority]
143+
Outputs: [
144+
1 HTR,
145+
50 FBT,
146+
50 FBT,
147+
200 DBT2,
148+
DBT2 mint authority,
149+
DBT2 melt authority
150+
]
151+
Fee: 2 HTR
152+
153+
diffHTR = 2 HTR
154+
fee = 2 HTR
155+
withdraw_without_authority = 2 HTR (resulting from 200 DBT)
156+
withdraw = 1 HTR (resulting from 100 DBT3)
157+
deposit = 2
158+
159+
The balance check is valid:
160+
161+
diffHTR + fee = withdraw + withdraw_without_authority - deposit
162+
-1 + 2 = 1 + 2 - 2
163+
1 = 1
128164

129-
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.
130165

131166
## Feature flag in settings
132167
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

Comments
 (0)