fees

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_REFRESH_INTERVAL = 60 * time.Minute
	MAX_RATES_PAGE       = 100
)
View Source
const (
	// At this point, always return congestion as 100%
	MAX_CONGESTION_RATIO = 1.5
)

Variables

This section is empty.

Functions

func CalculateCongestion

func CalculateCongestion(last5Minutes [5]int32, targetRatePerMinute int32) int32

* The algorithm for calculating congestion is as follows:

1) Compute the average number of messages per minute, excluding the current minute which may be incomplete 2) Take the greater of: the current minute's rate, the previous minute's rate, or the preceding 4 minute average 3) Compute the ratio of the max rate to the target rate 4) If the ratio is less than or equal to 1, return 0 5) If the ratio is greater than MAX_CONGESTION_RATIO, return 100 6) Otherwise, return the congestion as an exponential function of the ratio *

Types

type ContractRatesFetcher

type ContractRatesFetcher struct {
	// contains filtered or unexported fields
}

ContractRatesFetcher pulls all the rates from the RatesManager contract and stores them in a sorted set to find the appropriate rate for a given timestamp

func NewContractRatesFetcher

func NewContractRatesFetcher(
	ctx context.Context,
	ethclient bind.ContractCaller,
	logger *zap.Logger,
	options config.ContractsOptions,
) (*ContractRatesFetcher, error)

NewContractRatesFetcher creates a new ContractRatesFetcher using the provided eth client

func (*ContractRatesFetcher) GetRates

func (c *ContractRatesFetcher) GetRates(timestamp time.Time) (*Rates, error)

func (*ContractRatesFetcher) Start

func (c *ContractRatesFetcher) Start() error

Start the ContractRatesFetcher and begin fetching rates from the smart contract periodically.

type FeeCalculator

type FeeCalculator struct {
	// contains filtered or unexported fields
}

func NewFeeCalculator

func NewFeeCalculator(ratesFetcher IRatesFetcher) *FeeCalculator

func (*FeeCalculator) CalculateBaseFee

func (c *FeeCalculator) CalculateBaseFee(
	messageTime time.Time,
	messageSize int64,
	storageDurationDays uint32,
) (currency.PicoDollar, error)

func (*FeeCalculator) CalculateCongestionFee

func (c *FeeCalculator) CalculateCongestionFee(
	ctx context.Context,
	querier *queries.Queries,
	messageTime time.Time,
	originatorID uint32,
) (currency.PicoDollar, error)

type FixedRatesFetcher

type FixedRatesFetcher struct {
	// contains filtered or unexported fields
}

A fixed fee schedule that doesn't rely on the blockchain. Used primarily for testing, and until we have fees onchain.

func NewFixedRatesFetcher

func NewFixedRatesFetcher(rates *Rates) *FixedRatesFetcher

func (*FixedRatesFetcher) GetRates

func (f *FixedRatesFetcher) GetRates(_messageTime time.Time) (*Rates, error)

type IFeeCalculator

type IFeeCalculator interface {
	CalculateBaseFee(
		messageTime time.Time,
		messageSize int64,
		storageDurationDays uint32,
	) (currency.PicoDollar, error)
	CalculateCongestionFee(
		ctx context.Context,
		querier *queries.Queries,
		messageTime time.Time,
		originatorID uint32,
	) (currency.PicoDollar, error)
}

type IRatesFetcher

type IRatesFetcher interface {
	GetRates(messageTime time.Time) (*Rates, error)
}

The RatesFetcher is responsible for loading the rates for a given message time. This allows us to roll out new rates over time, and apply them to messages consistently.

type Rates

type Rates struct {
	MessageFee          currency.PicoDollar // The flat per-message fee
	StorageFee          currency.PicoDollar // The fee per byte-day of storage
	CongestionFee       currency.PicoDollar // The fee per unit of congestion
	TargetRatePerMinute uint64              // The target rate per minute for each node
}

Rates contain the cost for each fee component at a given message time. Values in the rates struct are denominated in USD PicoDollars

type RatesContract

type RatesContract interface {
	GetRates(
		opts *bind.CallOpts,
		fromIndex *big.Int,
		count *big.Int,
	) ([]rateregistry.IRateRegistryRates, error)
	GetRatesCount(opts *bind.CallOpts) (*big.Int, error)
}

Dumbed down version of the RatesManager contract interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL