Documentation ¶
Index ¶
- Variables
- type Controller
- type Delegator
- type DelegatorEvent
- type Emission
- func (e *Emission) AddToTotalSupply(amount uint64) uint64
- func (e *Emission) CalculateUserDelegationRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error)
- func (e *Emission) ClaimStakingRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error)
- func (e *Emission) DelegateUserStake(nodeID ids.NodeID, delegatorAddress codec.Address, ...) error
- func (e *Emission) DistributeFees(fee uint64)
- func (e *Emission) GetAPRForValidators() float64
- func (e *Emission) GetAllValidators(ctx context.Context) []*Validator
- func (e *Emission) GetDelegatorsForValidator(nodeID ids.NodeID) ([]*Delegator, error)
- func (e *Emission) GetLastAcceptedBlockHeight() uint64
- func (e *Emission) GetLastAcceptedBlockTimestamp() time.Time
- func (e *Emission) GetNumDelegators(nodeID ids.NodeID) int
- func (e *Emission) GetRewardsPerEpoch() uint64
- func (e *Emission) GetStakedValidator(nodeID ids.NodeID) []*Validator
- func (e *Emission) MintNewNAI() uint64
- func (e *Emission) RegisterValidatorStake(nodeID ids.NodeID, nodePublicKey *bls.PublicKey, ...) error
- func (e *Emission) UndelegateUserStake(nodeID ids.NodeID, actor codec.Address) (uint64, error)
- func (e *Emission) WithdrawValidatorStake(nodeID ids.NodeID) (uint64, error)
- type EmissionAccount
- type EpochTracker
- type NuklaiVM
- type RewardConfig
- type StakingConfig
- type Validator
Constants ¶
This section is empty.
Variables ¶
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 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 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 ¶
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 ¶
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 (*Emission) GetAPRForValidators ¶
GetAPRForValidators calculates the Annual Percentage Rate (APR) for validators based on the number of validators.
func (*Emission) GetAllValidators ¶
GetAllValidators fetches the current validators from the underlying VM
func (*Emission) GetDelegatorsForValidator ¶
GetDelegatorsForValidator retrieves all delegators for a specific validator by their NodeID.
func (*Emission) GetLastAcceptedBlockHeight ¶
GetLastAcceptedBlockHeight retrieves the height of the last accepted block from the VM.
func (*Emission) GetLastAcceptedBlockTimestamp ¶
GetLastAcceptedBlockTimestamp retrieves the timestamp of the last accepted block from the VM.
func (*Emission) GetNumDelegators ¶
GetNumDelegators returns the total number of delegators across all validators.
func (*Emission) GetRewardsPerEpoch ¶
GetRewardsPerEpoch calculates the rewards per epoch based on the total staked amount and the APR for validators.
func (*Emission) GetStakedValidator ¶
GetStakedValidator retrieves the details of a specific validator by their NodeID.
func (*Emission) MintNewNAI ¶
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 ¶
UndelegateUserStake decreases the delegated stake for a validator and rebalances the heap.
type EmissionAccount ¶
type EpochTracker ¶
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 }