fyziktom / VirtualEconomyFramework

Framework for economy applications
https://veframework.com/
MIT License
24 stars 7 forks source link

Correcting calculation of fee for a NFT #4

Closed VenkataRoundSqr closed 2 years ago

VenkataRoundSqr commented 2 years ago

The current logic for calculating fee is based on length of metadata which needs to be removed and a new logic is to be written. The idea is to use NBitcoin library to calculate the length of the transactions and assess the fee for it.

more details and workflow diagram to be followed.

fyziktom commented 2 years ago

Thank you to open this issue. It is bug in some situations especially when the address contains lots of small utxos.

We should start to solve it on classic Neblio transactions and then we can add token transactions and finally we will implement it for Dogecoin too. When we will have more blockchains integrated, we will design new more common function/core for this.

We can also explore how the NBitcoin library solve this (they have the functions for this too), but it creates new dependency to NBitcoin.

Example: You need to send 10 NEBL and you have two basic situations:

The function should assembly the transaction or based on standardized structure it should calculated expected size and then fee. Then NeblioAccount class provides the list of already loaded utxos which should be available for the transaction. So it can happen that after you will create tx and you will see that you need the bigger fee, you will need to add another utox as input to be able cover the fee. This can be prevent if we will set some minimal amount which is required for send transactions (for example you must have on you address: amount to send + 0.1 NEBL (not token txs) for cover fees.

The best next steps will be to add some basic new logic into NeblioTransactionsHelpers class. It can be shared between all the functions.

We need to consider:

fyziktom commented 2 years ago

After some exploring of this issue we agreed to me explore this too. Today I have commit first part of the solution. This can be improved, but now it should solve the bugs:

Added CalcFee function

I have created function which takes the constant length of the signed inputs, outputs, etc. and calculate some expected length (with some reserve). Then it will return some expected fee based on specific logic for the network. It was added for both Neblio and Dogecoin. It should be considered like common function for both because they are both based on utxo protocol (same logic can be used for Bitcoin, ReddCoin, etc.).

Function is here:

CalcFee Function for Neblio

Here you can find the example use:

Use of the CalcFee for Neblio Classic Payment

Here it is for the Token transaction (this one is little more complicated because it sends both Neblio and Tokens, for example airdrop):

Use of the CalcFee for Neblio and Tokens

Next steps should be some tests and refactoring. Then do some common function for all utxo based blockchains.

fyziktom commented 2 years ago

I think we can close this issue now. For Neblio we do not have this issues anymore. There is still some issue during calculation of the dogecoin. We should open separated issue for this if it will happen again.