hermez-node/common/fee.go
common/fee.goRaw
1package common
2
3import "math"
4
5// Fee is a type that represents the percentage of tokens that will be paid in a transaction
6// to incentivaise the materialization of it
7type Fee float64
8
9// RecommendedFee is the recommended fee to pay in USD per transaction set by
10// the coordinator according to the tx type (if the tx requires to create an
11// account and register, only register or he account already esists)
12type RecommendedFee struct {
13 ExistingAccount float64
14 CreatesAccount float64
15 CreatesAccountAndRegister float64
16}
17
18// FeeSelector is used to select a percentage from the FeePlan.
19type FeeSelector uint8
20
21// Percentage returns the associated percentage of the FeeSelector
22func (f FeeSelector) Percentage() float64 {
23 if f == 0 {
24 return 0
25 //nolint:gomnd
26 } else if f <= 32 { //nolint:gomnd
27 return math.Pow(10, -24+(float64(f)/2)) //nolint:gomnd
28 } else if f <= 223 { //nolint:gomnd
29 return math.Pow(10, -8+(0.041666666666667*(float64(f)-32))) //nolint:gomnd
30 } else {
31 return math.Pow(10, float64(f)-224) //nolint:gomnd
32 }
33}
34
35// MaxFeePlan is the maximum value of the FeePlan
36const MaxFeePlan = 256
37
38// FeePlan represents the fee model, a position in the array indicates the
39// percentage of tokens paid in concept of fee for a transaction
40var FeePlan = [MaxFeePlan]float64{}