emission

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidatorAlreadyRegistered = errors.New("validator already registered")
	ErrStakedAmountInvalid        = errors.New("staked amount invalid")
	ErrValidatorNotFound          = errors.New("validator not found")
	ErrInvalidStakeDuration       = errors.New("invalid stake duration")
	ErrInsufficientRewards        = errors.New("insufficient rewards")
	ErrStakeExpired               = errors.New("stake expired")
	ErrDelegatorAlreadyStaked     = errors.New("delegator already staked")
	ErrDelegatorNotFound          = errors.New("delegator not found")
	ErrDelegatorAlreadyClaimed    = errors.New("delegator already claimed")
	ErrInvalidBlockHeight         = errors.New("invalid block height")
	ErrValidatorNotActive         = errors.New("validator not active")

	ErrInvalidNodeID      = errors.New("invalid node id")
	ErrStakeNotFound      = errors.New("stake not found")
	ErrNotAValidator      = errors.New("not a validator")
	ErrNotAValidatorOwner = errors.New("not a validator owner")
)

Functions

This section is empty.

Types

type Controller

type Controller interface {
	Logger() logging.Logger
}

type Delegator

type Delegator struct {
	IsActive        bool   `json:"isActive"`        // Indicates if the delegator is currently active
	StakedAmount    uint64 `json:"stakedAmount"`    // Total amount staked by the delegator
	StakeStartBlock uint64 `json:"stakeStartBlock"` // Start block of the stake
	StakeEndBlock   uint64 `json:"stakeEndBlock"`   // End block of the stake
}

type DelegatorEvent

type DelegatorEvent struct {
	ValidatorNodeID ids.NodeID
	Delegator       codec.Address
}

type Emission

type Emission struct {
	TotalSupply     uint64          `json:"totalSupply"`     // Total supply of NAI
	MaxSupply       uint64          `json:"maxSupply"`       // Max supply of NAI
	EmissionAccount EmissionAccount `json:"emissionAccount"` // Emission Account Info

	TotalStaked uint64 `json:"totalStaked"` // Total staked NAI

	EpochTracker EpochTracker `json:"epochTracker"` // Epoch Tracker Info
	// contains filtered or unexported fields
}

func GetEmission

func GetEmission() *Emission

GetEmission returns the singleton instance of Emission

func New

func New(c Controller, vm NuklaiVM, totalSupply, maxSupply uint64, emissionAddress codec.Address) *Emission

New initializes the Emission struct with initial parameters and sets up the validators heap and indices map.

func (*Emission) AddToTotalSupply

func (e *Emission) AddToTotalSupply(amount uint64) uint64

AddToTotalSupply increases the total supply of NAI by a specified amount, ensuring it does not exceed the max supply.

func (*Emission) CalculateUserDelegationRewards

func (e *Emission) CalculateUserDelegationRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error)

CalculateUserDelegationRewards computes the rewards for a user's delegated stake to a validator, factoring in the delegation duration and amount.

func (*Emission) ClaimStakingRewards

func (e *Emission) ClaimStakingRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error)

ClaimStakingRewards lets validators and delegators claim their rewards

func (*Emission) DelegateUserStake

func (e *Emission) DelegateUserStake(nodeID ids.NodeID, delegatorAddress codec.Address, stakeStartBlock, stakeEndBlock, stakedAmount uint64) error

DelegateUserStake increases the delegated stake for a validator and rebalances the heap.

func (*Emission) DistributeFees

func (e *Emission) DistributeFees(fee uint64)

func (*Emission) GetAPRForValidators

func (e *Emission) GetAPRForValidators() float64

GetAPRForValidators calculates the Annual Percentage Rate (APR) for validators based on the number of validators.

func (*Emission) GetAllValidators

func (e *Emission) GetAllValidators(ctx context.Context) []*Validator

GetAllValidators fetches the current validators from the underlying VM

func (*Emission) GetDelegatorsForValidator

func (e *Emission) GetDelegatorsForValidator(nodeID ids.NodeID) ([]*Delegator, error)

GetDelegatorsForValidator retrieves all delegators for a specific validator by their NodeID.

func (*Emission) GetLastAcceptedBlockHeight

func (e *Emission) GetLastAcceptedBlockHeight() uint64

GetLastAcceptedBlockHeight retrieves the height of the last accepted block from the VM.

func (*Emission) GetLastAcceptedBlockTimestamp

func (e *Emission) GetLastAcceptedBlockTimestamp() time.Time

GetLastAcceptedBlockTimestamp retrieves the timestamp of the last accepted block from the VM.

func (*Emission) GetNumDelegators

func (e *Emission) GetNumDelegators(nodeID ids.NodeID) int

GetNumDelegators returns the total number of delegators across all validators.

func (*Emission) GetRewardsPerEpoch

func (e *Emission) GetRewardsPerEpoch() uint64

GetRewardsPerEpoch calculates the rewards per epoch based on the total staked amount and the APR for validators.

func (*Emission) GetStakedValidator

func (e *Emission) GetStakedValidator(nodeID ids.NodeID) []*Validator

GetStakedValidator retrieves the details of a specific validator by their NodeID.

func (*Emission) MintNewNAI

func (e *Emission) MintNewNAI() uint64

func (*Emission) RegisterValidatorStake

func (e *Emission) RegisterValidatorStake(nodeID ids.NodeID, nodePublicKey *bls.PublicKey, stakeStartBlock, stakeEndBlock, stakedAmount, delegationFeeRate uint64) error

RegisterValidatorStake adds a new validator to the heap with the specified staked amount and updates the total staked amount.

func (*Emission) UndelegateUserStake

func (e *Emission) UndelegateUserStake(nodeID ids.NodeID, actor codec.Address) (uint64, error)

UndelegateUserStake decreases the delegated stake for a validator and rebalances the heap.

func (*Emission) WithdrawValidatorStake

func (e *Emission) WithdrawValidatorStake(nodeID ids.NodeID) (uint64, error)

WithdrawValidatorStake removes a validator from the heap and updates the total staked amount accordingly.

type EmissionAccount

type EmissionAccount struct {
	Address           codec.Address `json:"address"`
	AccumulatedReward uint64        `json:"accumulatedReward"`
}

type EpochTracker

type EpochTracker struct {
	BaseAPR        float64 `json:"baseAPR"`        // Base APR to use
	BaseValidators uint64  `json:"baseValidators"` // Base number of validators to use
	EpochLength    uint64  `json:"epochLength"`    // Number of blocks per reward epoch
}

type NuklaiVM

type NuklaiVM interface {
	CurrentValidators(ctx context.Context) (map[ids.NodeID]*validators.GetValidatorOutput, map[string]struct{})
	LastAcceptedBlock() *chain.StatelessBlock
	State() (merkledb.MerkleDB, error)
}

type RewardConfig

type RewardConfig struct {
	// 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"`

	// Emission Balancer Address
	EmissionAddress string `json:"emissionAddress"`
}

type StakingConfig

type StakingConfig struct {
	// Minimum stake, in NAI, required to validate the nuklai network
	MinValidatorStake uint64 `json:"minValidatorStake"`
	// Maximum stake, in NAI, allowed to be placed on a single validator in
	// the nuklai network
	MaxValidatorStake uint64 `json:"maxValidatorStake"`
	// Minimum stake, in NAI, that can be delegated on the nuklai network
	MinDelegatorStake uint64 `json:"minDelegatorStake"`
	// Minimum delegation fee, in the range [0, 100], that can be charged
	// for delegation on the nuklai network.
	MinDelegationFee uint64 `json:"minDelegationFee"`
	// MinValidatorStakeDuration is the minimum amount of blocks  a validator can validate
	// for in a single period.
	MinValidatorStakeDuration uint64 `json:"minValidatorStakeDuration"`
	// MaxStakeDuration is the maximum amount of blocks a validator can validate
	// for in a single period.
	MaxValidatorStakeDuration uint64 `json:"maxValidatorStakeDuration"`
	// RewardConfig is the config for the reward function.
	RewardConfig RewardConfig `json:"rewardConfig"`
}

func GetStakingConfig

func GetStakingConfig() StakingConfig

type Validator

type Validator struct {
	IsActive                   bool       `json:"isActive"`                   // Indicates if the validator is currently active
	NodeID                     ids.NodeID `json:"nodeID"`                     // Node ID of the validator
	PublicKey                  []byte     `json:"publicKey"`                  // Public key of the validator
	StakedAmount               uint64     `json:"stakedAmount"`               // Total amount staked by the validator
	AccumulatedStakedReward    uint64     `json:"accumulatedStakedReward"`    // Total rewards accumulated by the validator
	DelegationFeeRate          float64    `json:"delegationFeeRate"`          // Fee rate for delegations
	DelegatedAmount            uint64     `json:"delegatedAmount"`            // Total amount delegated to the validator
	AccumulatedDelegatedReward uint64     `json:"accumulatedDelegatedReward"` // Total rewards accumulated by the delegators of the validator
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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