Documentation ¶
Index ¶
- Constants
- Variables
- func NewEmissionSubscriptionFactory(log logging.Logger, emission Tracker) event.SubscriptionFactory[*chain.ExecutedBlock]
- 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) GetEmissionValidators() map[ids.NodeID]*Validator
- func (e *Emission) GetInfo() (emissionAccount EmissionAccount, totalSupply uint64, maxSupply uint64, ...)
- 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 EmissionSubscriptionFactory
- type EpochTracker
- type MockEmission
- func (m *MockEmission) AddToTotalSupply(amount uint64) uint64
- func (m *MockEmission) CalculateUserDelegationRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error)
- func (m *MockEmission) ClaimStakingRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error)
- func (m *MockEmission) DelegateUserStake(nodeID ids.NodeID, delegatorAddress codec.Address, ...) error
- func (m *MockEmission) DistributeFees(fee uint64)
- func (m *MockEmission) GetAPRForValidators() float64
- func (m *MockEmission) GetAllValidators(ctx context.Context) []*Validator
- func (m *MockEmission) GetDelegatorsForValidator(nodeID ids.NodeID) ([]*Delegator, error)
- func (m *MockEmission) GetEmissionValidators() map[ids.NodeID]*Validator
- func (m *MockEmission) GetInfo() (emissionAccount EmissionAccount, totalSupply uint64, maxSupply uint64, ...)
- func (m *MockEmission) GetLastAcceptedBlockHeight() uint64
- func (m *MockEmission) GetLastAcceptedBlockTimestamp() time.Time
- func (m *MockEmission) GetNumDelegators(nodeID ids.NodeID) int
- func (m *MockEmission) GetRewardsPerEpoch() uint64
- func (m *MockEmission) GetStakedValidator(nodeID ids.NodeID) []*Validator
- func (m *MockEmission) MintNewNAI() uint64
- func (m *MockEmission) RegisterValidatorStake(nodeID ids.NodeID, nodePublicKey *bls.PublicKey, ...) error
- func (m *MockEmission) UndelegateUserStake(nodeID ids.NodeID, actor codec.Address) (uint64, error)
- func (m *MockEmission) WithdrawValidatorStake(nodeID ids.NodeID) (uint64, error)
- type RewardConfig
- type StakingConfig
- type Tracker
- type Validator
Constants ¶
const ( Name = "emissionBalancer" Namespace = "emissionBalancer" )
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 ¶
func NewEmissionSubscriptionFactory ¶ added in v0.1.3
func NewEmissionSubscriptionFactory(log logging.Logger, emission Tracker) event.SubscriptionFactory[*chain.ExecutedBlock]
Types ¶
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 NewEmission ¶ added in v0.1.1
NewEmission 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) GetEmissionValidators ¶ added in v0.1.1
func (*Emission) GetInfo ¶ added in v0.1.1
func (e *Emission) GetInfo() (emissionAccount EmissionAccount, totalSupply uint64, maxSupply uint64, totalStaked uint64, epochTracker EpochTracker)
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 EmissionSubscriptionFactory ¶ added in v0.1.3
type EmissionSubscriptionFactory struct {
// contains filtered or unexported fields
}
func (*EmissionSubscriptionFactory) Accept ¶ added in v0.1.3
func (e *EmissionSubscriptionFactory) Accept(blk *chain.ExecutedBlock) error
func (*EmissionSubscriptionFactory) Close ¶ added in v0.1.3
func (*EmissionSubscriptionFactory) Close() error
func (*EmissionSubscriptionFactory) New ¶ added in v0.1.3
func (e *EmissionSubscriptionFactory) New() (event.Subscription[*chain.ExecutedBlock], error)
type EpochTracker ¶
type MockEmission ¶ added in v0.1.3
type MockEmission struct { TotalSupplyVal uint64 RewardsPerEpoch uint64 APRForValidators float64 NumDelegators int StakeRewards uint64 LastAcceptedBlockHeight uint64 Validator *Validator }
func MockNewEmission ¶ added in v0.1.3
func MockNewEmission(mockEmission *MockEmission) *MockEmission
func (*MockEmission) AddToTotalSupply ¶ added in v0.1.3
func (m *MockEmission) AddToTotalSupply(amount uint64) uint64
func (*MockEmission) CalculateUserDelegationRewards ¶ added in v0.1.3
func (*MockEmission) ClaimStakingRewards ¶ added in v0.1.3
func (*MockEmission) DelegateUserStake ¶ added in v0.1.3
func (*MockEmission) DistributeFees ¶ added in v0.1.3
func (m *MockEmission) DistributeFees(fee uint64)
func (*MockEmission) GetAPRForValidators ¶ added in v0.1.3
func (m *MockEmission) GetAPRForValidators() float64
func (*MockEmission) GetAllValidators ¶ added in v0.1.3
func (m *MockEmission) GetAllValidators(ctx context.Context) []*Validator
func (*MockEmission) GetDelegatorsForValidator ¶ added in v0.1.3
func (m *MockEmission) GetDelegatorsForValidator(nodeID ids.NodeID) ([]*Delegator, error)
func (*MockEmission) GetEmissionValidators ¶ added in v0.1.3
func (m *MockEmission) GetEmissionValidators() map[ids.NodeID]*Validator
func (*MockEmission) GetInfo ¶ added in v0.1.3
func (m *MockEmission) GetInfo() (emissionAccount EmissionAccount, totalSupply uint64, maxSupply uint64, totalStaked uint64, epochTracker EpochTracker)
func (*MockEmission) GetLastAcceptedBlockHeight ¶ added in v0.1.3
func (m *MockEmission) GetLastAcceptedBlockHeight() uint64
func (*MockEmission) GetLastAcceptedBlockTimestamp ¶ added in v0.1.3
func (m *MockEmission) GetLastAcceptedBlockTimestamp() time.Time
func (*MockEmission) GetNumDelegators ¶ added in v0.1.3
func (m *MockEmission) GetNumDelegators(nodeID ids.NodeID) int
func (*MockEmission) GetRewardsPerEpoch ¶ added in v0.1.3
func (m *MockEmission) GetRewardsPerEpoch() uint64
func (*MockEmission) GetStakedValidator ¶ added in v0.1.3
func (m *MockEmission) GetStakedValidator(nodeID ids.NodeID) []*Validator
func (*MockEmission) MintNewNAI ¶ added in v0.1.3
func (m *MockEmission) MintNewNAI() uint64
func (*MockEmission) RegisterValidatorStake ¶ added in v0.1.3
func (*MockEmission) UndelegateUserStake ¶ added in v0.1.3
func (*MockEmission) WithdrawValidatorStake ¶ added in v0.1.3
func (m *MockEmission) WithdrawValidatorStake(nodeID ids.NodeID) (uint64, 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 Tracker ¶ added in v0.1.1
type Tracker interface { AddToTotalSupply(amount uint64) uint64 GetRewardsPerEpoch() uint64 GetAPRForValidators() float64 GetNumDelegators(nodeID ids.NodeID) int CalculateUserDelegationRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error) RegisterValidatorStake(nodeID ids.NodeID, nodePublicKey *bls.PublicKey, stakeStartBlock, stakeEndBlock, stakedAmount, delegationFeeRate uint64) error WithdrawValidatorStake(nodeID ids.NodeID) (uint64, error) DelegateUserStake(nodeID ids.NodeID, delegatorAddress codec.Address, stakeStartBlock, stakeEndBlock, stakedAmount uint64) error UndelegateUserStake(nodeID ids.NodeID, actor codec.Address) (uint64, error) ClaimStakingRewards(nodeID ids.NodeID, actor codec.Address) (uint64, error) MintNewNAI() uint64 DistributeFees(fee uint64) GetStakedValidator(nodeID ids.NodeID) []*Validator GetAllValidators(ctx context.Context) []*Validator GetDelegatorsForValidator(nodeID ids.NodeID) ([]*Delegator, error) GetLastAcceptedBlockTimestamp() time.Time GetLastAcceptedBlockHeight() uint64 GetEmissionValidators() map[ids.NodeID]*Validator GetInfo() (emissionAccount EmissionAccount, totalSupply uint64, maxSupply uint64, totalStaked uint64, epochTracker EpochTracker) }
func GetEmission ¶
func GetEmission() Tracker
GetEmission returns the singleton instance of Emission
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 }