Skip to content
167 changes: 167 additions & 0 deletions text/0045-transaction_fee_minting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
- Feature Name: transaction_fee_minting
- Start Date: 2025-02-24
- RFC PR: (to be created)
- Hathor Issue: (leave this empty)
- Author: Raul Soares de Oliveira

# Summary
[summary]: #summary
Currently, when minting X tokens, a [deposit of P% (1%) of X in HTR is required](./0011-token-deposit.md). This deposit can later be withdrawn when the tokens are melted.

This proposal suggests an alternative mechanism where, instead of requiring an upfront deposit of HTR when minting new tokens, a transaction fee is charged on each transfer of the newly minted tokens.

# Motivation
[motivation]: #motivation

Dozer suggested an alternative to the HTR deposit requirement when minting tokens. The idea is to create a new type of custom tokens where tokens would be minted for free (i.e., no deposits) and fess will be charged for transactions. [RFC](https://github.com/Dozer-Protocol/hathor-rfcs/blob/new-token-economics/projects/new-token-economics/token-economics.md)

This change would reduce the upfront cost of minting tokens, making it more accessible to users who may not have sufficient HTR at the time of minting. The network would still benefit from a fee mechanism that contributes to miners’ incentives and overall network security.

# Guide-level explanation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing a section to explain what will happen to the fees. Will they be collected by miners? Or will they simply be burned? Or something in between?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should control inflation, and reward miners. In any case, I don't have enough experience with blockchains to decide it.
It's a question to be addressed by the business. The business should decide the kind of the drawbacks it would take.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. So, let's assume that fees will be paid by burning tokens. More specifically, fee = sum(outputs) - sum(inputs). Just clarify that another mechanism (e.g., miners collecting fees) can be put in place if needed.

[guide-level-explanation]: #guide-level-explanation

When minting tokens, creators can choose between two transaction models: Deposit-Based and Fee-Based. Each model offers different benefits, depending on how the tokens will be used. For handle it we will use the same definitions of the [Token Creation Transaction](https://github.com/HathorNetwork/rfcs/blob/master/text/0004-tokens.md), possibly adding a variation of it using a new version.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still validating which version (tx version or token_info_version) to change with a POC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to cover this implementation detail in the guide level explanation. You can leave it to the low level design.


## Deposit-Based Model (as is)

Currently, creators must [deposit a percentage](https://github.com/HathorNetwork/rfcs/blob/master/text/0011-token-deposit.md) (P%) of the minted tokens’ value in HTR. For example, if P% is set at 1% and a user mints 100 tokens, they must deposit 1 HTR. This deposit acts as a reserve and is fully refundable if the tokens are later melted.

## Fee-Based Model

Adding the fee-based model the platform won't require an upfront deposit. Instead, each transfer of the minted tokens incurs a transaction fee, which is deducted automatically. The exact fee rate will be defined at a later stage.

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.

### How to pproach

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.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, its structure promotes sustainability, ensuring controlled blockchain growth.

Can you elaborate, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited


### Fee calculation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is still missing what's going to happen with the fee. Is it going to be burned? An example showing a concrete transaction would help a lot.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the example, pls check if it's clear. I added a simple transaction with 1 input and two outputs. The idea is to become closer as possible to a flat fee in simple transaction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed, now it's charging by each fee token output.


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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we going for this model? The original proposal suggests a flat fee.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasons I ultimately moved away from a flat fee model and instead adopted a fee calculation based on the transaction size are:

  • Flat fees could disproportionately penalize small, simple transactions while inadvertently subsidizing larger ones. A fee model based on transaction size fairly charges users according to their actual network usage.
  • A flat fee, while initially predictable, doesn’t adapt to network usage or congestion. Introducing a size-based fee model offers adaptability, better managing network capacity and preventing potential bottlenecks during high traffic periods.
  • Enabling a custom token fee, will allow users to melt tokens without authority.
  • Users are already familiar with fee models based on transaction size (e.g., Bitcoin and Ethereum). Adopting a similar approach reduces friction in user onboarding, simplifies adoption, and aligns Hathor with established blockchain industry standards.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A flat fee, while initially predictable, doesn’t adapt to network usage or congestion.

Nor does a tx size based fee. What can help in this case are priority fees, but this can be added in both fee models (flat or tx size).

Users are already familiar with fee models based on transaction size (e.g., Bitcoin and Ethereum).

It doesn't mean they are happy with it. I guess 99% of users in Ethereum complain about unpredictable fees.

Flat fees could disproportionately penalize small, simple transactions while inadvertently subsidizing larger ones.

I agree, but this is something we did not prioritize in our existing token standard and hasn't been an issue. Currently, you pay the same deposit regardless of the "type" of transaction you will make. There might be tokens that have a majority of small txs (few inputs and outputs) and other that have larger txs. Both pay the same deposit (1%). I don't see the benefit of doing this differently now.

In the end, this variable fee introduces more complexity and reduces the UX for users. He may send a 5 HTR tx and pay 0.1 HTR one time and later, while transferring the same amount, pay double if he has to use more inputs.

Enabling a custom token fee, will allow users to melt tokens without authority.

It depends how we will handle the fees. If the fees are melted, then yes. However, if the fees are sent to an address that is inaccessible, the supply remains the same. In practice, it's the same, though. In any case, I can always send the tokens I have to an inaccessible address today.

My recommendation

We should have a flat fee per fee-based token.

We should also allow custom tokens as fee payment (as well as HTR), but only the same token that is on the transaction. For instance, when sending hUSDC, I can only use hUSDC for fee payment.

I don't have an opinion yet if payment of fees with custom tokens should be decided at token creation - i.e. when someone is creating the token, he should choose to allow it to be used for fee payment. So when creating YanCoin, I can choose whether fee payment is only in HTR or users can also use YanCoin itself.

@trondbjoroy suggested that all tokens should support fee payment in the token itself as "fees should work in a consistent way for all tokens". That's a fair point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you see tokens which value nothing being used to pay the fee in a transaction?

Example:

  • Token A is minted without a deposit, and I can choose the amount.It means token A values nothing.

Does make sense to enable the charge of custom tokens?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are 100% correct, I mixed things up. For fee payment, it must happen with a token that has been created with the deposit model. So if we choose to enable fee payment in custom tokens, a deposit-based token will be needed to pay for fee-based token tx fees.

This removes our argument that users would not need to hold other tokens (eg: when sending USDC, they'd need another token as well).

I still believe we should have a flat fee (probably 0.01 HTR). However, we'd need to decide if we enable other deposit-based tokens to be used for fee payment or just HTR.

On Dozer's proposal, the token creator selects the token used for fee payment when creating the token. I'm thinking it might be more confusing for users, unless there's a clear benefit of allowing it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an example of a Protocol using this approach, but I can elaborate on a hypothetical scenario.
Let's say I want to operate stablecoins on the Hathor Network. However, I want to charge fees when users transact with my coins within the network. If I create a gas coin using the 1% HTR lock method (let's call it SGC—StableGasCoin), I can mint and sell it to users who will need it to pay transaction fees for all my stablecoins that are programmed to use SGC instead of HTR for gas.

The process would work like this:

  1. Protocol mints SGC (StableGasCoin);
  2. Protocol issues stablecoins with this rule - for example, mints sBRL with gas set to SGC instead of HTR;
  3. Protocol sells SGC at arbitrary or fixed price (could be via a smart contract);
  4. Users pay fees using the protocol's gas coin, initially minted using HTR.

This creates utility for the SGC coin and potential revenue for the protocol while also contributing to Hathor, as the 1% lock is burned.

Copy link
Member

@obiyankenobi obiyankenobi Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, it's clearer now. It seems the use case would be to monetize a product/protocol that has usage.

I'm wondering if it makes sense to add this or just keep it simple and only accept HTR. Just to be clear, I think we should keep it simple for business reasons, not because development would be (slightly) harder. It would end up being a friction point for users, who may have to hold multiple tokens for fee payment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msbrogli replying to your comment about fees.

require us to determine a single flat fee that works for both simple and complex transactions.

I don’t yet have a strong opinion on the best approach, but another alternative would be to charge fees based on the number of outputs with fee-based tokens.

I don't see a problem charging the same fee for small or large txs. This is something we already don't handle in the deposit-based txs and it hasn't been a problem. While I appreciate it drives more demand for HTR tokens, I believe the gains in simplicity are greater.

Almost all txs that a user sends have 2 outputs, as it needs to include a change output. So if we say it's 0.01 HTR per fee-based token output, it will cost 0.02. However, he may send a tx and the output match the input, so it will only cost 0.01 HTR. This discrepancy is not easy to explain to the average user.

This would remove the incentive for bundling multiple transactions to save on fees.

I guess only a few players would have the ability to do that, as exchanges and marketplaces. Most commonly, people will not do that.

Copy link
Member

@msbrogli msbrogli Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost all txs that a user sends have 2 outputs, as it needs to include a change output. So if we say it's 0.01 HTR per fee-based token output, it will cost 0.02. However, he may send a tx and the output match the input, so it will only cost 0.01 HTR. This discrepancy is not easy to explain to the average user.

It is very complicated to explain to EVM users how fees are calculated. But they all understand how much it costs. I guess it is the same here. One transaction would pay 0.01 HTR while the other would pay 0.02 HTR in fees. It seems simple enough for users.

I guess only a few players would have the ability to do that, as exchanges and marketplaces. Most commonly, people will not do that.

Everything is hard to reach masses without tools. All we need is a popular wallet to implement it and then lots of people would use it unconsciously. For instance, mixers were theory before Tornado Cash made it simple for people to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is hard to reach masses without tools. All we need is a popular wallet to implement it and then lots of people would use it unconsciously.

I agree, but to reach this point there must be use on the network, and simplifying fees, which is a barrier to adoption, is a way to be able to get there.

All we need is a popular wallet to implement it and then lots of people would use it unconsciously.

It will be a good problem when we reach the point when we have these kind of services in the network.

It is very complicated to explain to EVM users how fees are calculated. But they all understand how much it costs. I guess it is the same here.

I don't think they understand how it works, they just pay what's displayed on the wallet. To quote @trondbjoroy "Bitcoin and Ethereum shouldn't be viewed as success stories when it comes to fees IMO". They do it because they want to send transactions, because there's demand for it. As a smaller network having to attract users and products, we need to look for enhancements to the current models.


Proof-of-Work difficulty (transaction weight) will not influence the fee calculation.

Let's assume:
1. HTR is always used as the fee unit, regardless of the tokens involved in the transaction.
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.
3. Interacting with nano contracts may introduce an additional fee depending on the execution complexity.

Below is a pseudo code that explain how fee should be calculated, using a fee rate per byte:

*(Note: Excluded "hash" size from calculation, hence 114 reduced to 84 bytes.)*

```python
def calculate_tx_fee(tx, fee_rate_per_byte):
# Fixed size fields (always present)
fixed_size = 84 # version (2) + timestamp (4) + nonce (4) + weight (8) + parents (64)

# Tokens array size
tokens_size = 32 * len(tx.tokens)

# Inputs size calculation
inputs_size = 0
for input in tx.inputs:
inputs_size += 35 + len(input.data)
# 32 bytes (tx_id) + 1 byte (index) + 2 bytes (data length prefix) + len(data)

# Outputs size calculation
outputs_size = 0
for output in tx.outputs:
outputs_size += 7 + len(output.script)
# 4 bytes (value) + 1 byte (token_data) + 2 bytes (script length prefix) + len(script)

# Total transaction size
tx_size = fixed_size + tokens_size + inputs_size + outputs_size

# Fee calculation
fee = tx_size * fee_rate_per_byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the proposed value for the fee_rate_per_byte? It might be useful to get a histogram of tx size of transactions with custom tokens in mainnet so we can understand how much fee would be charged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll grab it. For now I've added an example using the tx anamoty as reference. Pls, check if it's clear this way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


return fee + tx.priority_tip # plus any nano fee that should match

```


### **Example Calculation:**

**Hypothetical Transaction:**
- 1 token UID
- 2 inputs (with 108 bytes of data each, common signature size)
- 2 outputs (with 25 bytes of script each, common P2PKH script)

Calculate size:

| Field | Calculation | Size |
|----------------------|-----------------------------|----------|
| Fixed-size fields | | **84** bytes |
| Tokens | 1 token × 32 bytes | **32** bytes |
| Inputs | 2 × (35 + 108) | **286** bytes |
| Outputs | 2 × (7 + 25) | **64** bytes |
| **Total Tx Size** | 84 + 32 + 286 + 64 | **466** bytes |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is focused on calculating the tx size. But that's something we already have. I guess it would be more useful to have examples of the expected fee charged for small, medium and big transactions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited


## Wallet UI

We should provide to the users the option to select between the two models (deposit and fee) when minting.

# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation
TODO

# Drawbacks of the Hybrid Fee Model
[drawbacks]: #drawbacks

While the hybrid fee model balances incentives and network sustainability, it also introduces potential drawbacks that must be considered. Below are key concerns and challenges:

### Complexity in Multi-Token Transactions

**Issue:** Transactions involving multiple tokens introduce a more complex fee structure, requiring additional computation to determine the appropriate charge.

**Impact:**
- Increased processing overhead for wallets.
- Potential user confusion when sending transactions with different token types.

**Potential Mitigation:**
- Improve **wallet UX** to clearly display estimated fees before confirming transactions.

# Prior art

### How Bitcoin deals with fee

Bitcoin handles transaction fees through a system based on competition for limited block space. Each transaction has a weight measured in vBytes, and users set their fees by offering satoshis per vByte, which influences the confirmation speed. During periods of high demand, fees increase due to competition, while in lower traffic periods, they decrease.

Wallets and services use fee estimators to suggest optimal fees based on the mempool. The protocol does not enforce a minimum fee, but nodes can set a "relay fee" to prevent spam from very low-value transactions.

### How Etherium deals with fee

Ethereum handles transaction fees through the concept of Gas, where each operation consumes a specific amount of computational resources. Before EIP-1559, users set the Gas Price, and those who paid more had priority. With EIP-1559, a dynamically adjusted Base Fee was introduced based on demand, along with an optional Priority Tip to incentivize validators.

The Base Fee is burned, reducing the Ether supply, while the Priority Tip goes to validators. This model improves fee predictability, making costs more stable and transparent for users.


# Unresolved questions
[unresolved-questions]: #unresolved-questions

- What will happen to the fees? Will they be collected by the miners?
- How should melt operations be handled for fee-based custom tokens?
- Should storage fees be one-time or recurring (rent model)?
- How fee adjustments will be governed?
- Should TX mining remain if transaction fees are introduced? How will it affect the tx-mining-service?

# Future possibilities
[future-possibilities]: #future-possibilities

- Custom Fee Markets (letting users optimize fees).
- Dynamic Fee Adjustment Mechanism, where fees scale based on network congestion.

# References

- https://github.com/HathorNetwork/rfcs/blob/master/text/0011-token-deposit.md
- https://github.com/HathorNetwork/rfcs/blob/master/text/0004-tokens.md
- https://github.com/HathorNetwork/rfcs/blob/master/text/0015-anatomy-of-tx.md
- https://bitcoin.org/bitcoin.pdf
- https://eips.ethereum.org/EIPS/eip-1559
- https://ethereum.org/en/developers/docs/gas/
- https://developer.bitcoin.org/devguide/transactions.html#transaction-fees-and-change