You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

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