reward

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

View Source
const PercentDenominator = 1_000_000

PercentDenominator is the denominator used to calculate percentages

Variables

This section is empty.

Functions

func Split

func Split(totalAmount uint64, shares uint32) (uint64, uint64)

Split [totalAmount] into [totalAmount * shares percentage] and the remainder.

Invariant: [shares] <= PercentDenominator

Types

type Calculator

type Calculator interface {
	Calculate(stakedDuration time.Duration, stakedAmount, currentSupply uint64) uint64
}

func NewCalculator

func NewCalculator(c Config) Calculator
Example
const (
	day             = 24 * time.Hour
	week            = 7 * day
	stakingDuration = 4 * week

	stakeAmount = 100_000 * constants.Lux // 100k LUX

	// The current supply can be fetched with the platform.getCurrentSupply API
	// With 6 decimal precision, values are in microLUX (μLUX)
	currentSupply = 447_903_490 * constants.Lux // ~448m LUX
)
var (
	mainnetRewardConfig = Config{
		MaxConsumptionRate: .12 * PercentDenominator,
		MinConsumptionRate: .10 * PercentDenominator,
		MintingPeriod:      365 * 24 * time.Hour,
		SupplyCap:          720 * constants.MegaLux,
	}
	mainnetCalculator = NewCalculator(mainnetRewardConfig)
)

potentialReward := mainnetCalculator.Calculate(stakingDuration, stakeAmount, currentSupply)

fmt.Printf("Staking %d μLUX for %s with the current supply of %d μLUX would have a potential reward of %d μLUX",
	stakeAmount,
	stakingDuration,
	currentSupply,
	potentialReward,
)
Output:
Staking 100000000000 μLUX for 672h0m0s with the current supply of 447903490000000 μLUX would have a potential reward of 473168954 μLUX

type Config

type Config struct {
	// MaxConsumptionRate is the rate to allocate funds if the validator's stake
	// duration is equal to [MintingPeriod]
	MaxConsumptionRate uint64 `json:"maxConsumptionRate"`

	// MinConsumptionRate is the rate to allocate funds if the validator's stake
	// duration is 0.
	MinConsumptionRate uint64 `json:"minConsumptionRate"`

	// MintingPeriod is period that the staking calculator runs on. It is
	// not valid for a validator's stake duration to be larger than this.
	MintingPeriod time.Duration `json:"mintingPeriod"`

	// SupplyCap is the target value that the reward calculation should be
	// asymptotic to.
	SupplyCap uint64 `json:"supplyCap"`
}

Jump to

Keyboard shortcuts

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