keeper

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllInvariants

func AllInvariants(k *Keeper) sdk.Invariant

AllInvariants runs all invariants of the module

func CanWithdrawInvariant

func CanWithdrawInvariant(k *Keeper) sdk.Invariant

CanWithdrawInvariant checks that current rewards can be completely withdrawn

func ModuleAccountInvariant

func ModuleAccountInvariant(k *Keeper) sdk.Invariant

ModuleAccountInvariant checks that the coins held by the global rewards pool is consistent with the sum of outstanding rewards

func NewMsgServer

func NewMsgServer(k *Keeper) types.MsgServer

func NewQueryServer

func NewQueryServer(k *Keeper) types.QueryServer

func NonNegativeOutstandingInvariant

func NonNegativeOutstandingInvariant(k *Keeper) sdk.Invariant

NonNegativeOutstandingInvariant checks that outstanding unwithdrawn fees are never negative

func ReferenceCountInvariant

func ReferenceCountInvariant(k *Keeper) sdk.Invariant

ReferenceCountInvariant checks that the number of historical rewards records is correct

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, k *Keeper)

RegisterInvariants registers all module invariants

Types

type DistributionInfo

type DistributionInfo struct {
	DelegationTarget restakingtypes.DelegationTarget
	DelegationsValue math.LegacyDec
}

DistributionInfo stores information about a delegation target and its delegation value.

type Hooks

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

func (Hooks) AfterOperatorDelegationModified

func (h Hooks) AfterOperatorDelegationModified(ctx sdk.Context, operatorID uint32, delegator string) error

func (Hooks) AfterPoolDelegationModified

func (h Hooks) AfterPoolDelegationModified(ctx sdk.Context, poolID uint32, delegator string) error

func (Hooks) AfterServiceDelegationModified

func (h Hooks) AfterServiceDelegationModified(ctx sdk.Context, serviceID uint32, delegator string) error

func (Hooks) AfterUnbondingInitiated

func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) error

func (Hooks) BeforeOperatorDelegationCreated

func (h Hooks) BeforeOperatorDelegationCreated(ctx sdk.Context, operatorID uint32, delegator string) error

func (Hooks) BeforeOperatorDelegationRemoved

func (h Hooks) BeforeOperatorDelegationRemoved(_ sdk.Context, _ uint32, _ string) error

func (Hooks) BeforeOperatorDelegationSharesModified

func (h Hooks) BeforeOperatorDelegationSharesModified(ctx sdk.Context, operatorID uint32, delegator string) error

func (Hooks) BeforePoolDelegationCreated

func (h Hooks) BeforePoolDelegationCreated(ctx sdk.Context, poolID uint32, delegator string) error

func (Hooks) BeforePoolDelegationRemoved

func (h Hooks) BeforePoolDelegationRemoved(_ sdk.Context, _ uint32, _ string) error

func (Hooks) BeforePoolDelegationSharesModified

func (h Hooks) BeforePoolDelegationSharesModified(ctx sdk.Context, poolID uint32, delegator string) error

func (Hooks) BeforeServiceDelegationCreated

func (h Hooks) BeforeServiceDelegationCreated(ctx sdk.Context, serviceID uint32, delegator string) error

func (Hooks) BeforeServiceDelegationRemoved

func (h Hooks) BeforeServiceDelegationRemoved(_ sdk.Context, _ uint32, _ string) error

func (Hooks) BeforeServiceDelegationSharesModified

func (h Hooks) BeforeServiceDelegationSharesModified(ctx sdk.Context, serviceID uint32, delegator string) error

type Keeper

type Keeper struct {
	Schema                    collections.Schema
	Params                    collections.Item[types.Params]
	NextRewardsPlanID         collections.Item[uint64]
	RewardsPlans              collections.Map[uint64, types.RewardsPlan]
	LastRewardsAllocationTime collections.Item[gogotypes.Timestamp]
	DelegatorWithdrawAddrs    collections.Map[sdk.AccAddress, sdk.AccAddress]

	PoolDelegatorStartingInfos collections.Map[collections.Pair[uint32, sdk.AccAddress], types.DelegatorStartingInfo]
	PoolHistoricalRewards      collections.Map[collections.Pair[uint32, uint64], types.HistoricalRewards]
	PoolCurrentRewards         collections.Map[uint32, types.CurrentRewards]
	PoolOutstandingRewards     collections.Map[uint32, types.OutstandingRewards]

	OperatorAccumulatedCommissions collections.Map[uint32, types.AccumulatedCommission]
	OperatorDelegatorStartingInfos collections.Map[collections.Pair[uint32, sdk.AccAddress], types.DelegatorStartingInfo]
	OperatorHistoricalRewards      collections.Map[collections.Pair[uint32, uint64], types.HistoricalRewards]
	OperatorCurrentRewards         collections.Map[uint32, types.CurrentRewards]
	OperatorOutstandingRewards     collections.Map[uint32, types.OutstandingRewards]

	ServiceDelegatorStartingInfos collections.Map[collections.Pair[uint32, sdk.AccAddress], types.DelegatorStartingInfo]
	ServiceHistoricalRewards      collections.Map[collections.Pair[uint32, uint64], types.HistoricalRewards]
	ServiceCurrentRewards         collections.Map[uint32, types.CurrentRewards]
	ServiceOutstandingRewards     collections.Map[uint32, types.OutstandingRewards]
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.Codec,
	storeService corestoretypes.KVStoreService,
	accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper,
	communityPoolKeeper types.CommunityPoolKeeper,
	oracleKeeper types.OracleKeeper,
	poolsKeeper types.PoolsKeeper,
	operatorsKeeper types.OperatorsKeeper,
	servicesKeeper types.ServicesKeeper,
	restakingKeeper types.RestakingKeeper,
	assetsKeeper types.AssetsKeeper,
	authority string,
) *Keeper

func (*Keeper) AfterDelegationModified

func (k *Keeper) AfterDelegationModified(ctx sdk.Context, delType restakingtypes.DelegationType, targetID uint32, delegator string) error

func (*Keeper) AllocateRewards

func (k *Keeper) AllocateRewards(ctx context.Context) error

AllocateRewards allocates restaking rewards to different entities based on active rewards plans. AllocateRewards skips rewards distribution when there's no last rewards allocation time set. In that case, AllocateRewards simply set the current block time as new last rewards allocation time.

func (*Keeper) AllocateRewardsByPlan

func (k *Keeper) AllocateRewardsByPlan(
	ctx context.Context, plan types.RewardsPlan, timeSinceLastAllocation time.Duration,
	pools []poolstypes.Pool, operators []operatorstypes.Operator,
) error

AllocateRewardsByPlan allocates rewards by a specific rewards plan.

func (*Keeper) BeforeDelegationCreated

func (k *Keeper) BeforeDelegationCreated(ctx sdk.Context, delType restakingtypes.DelegationType, targetID uint32) error

func (*Keeper) BeforeDelegationSharesModified

func (k *Keeper) BeforeDelegationSharesModified(ctx sdk.Context, delType restakingtypes.DelegationType, targetID uint32, delegator string) error

func (*Keeper) BeginBlocker

func (k *Keeper) BeginBlocker(ctx context.Context) error

BeginBlocker is called every block and is used to terminate ended rewards plans and allocate restaking rewards for the previous block.

func (*Keeper) CalculateDelegationRewards

func (k *Keeper) CalculateDelegationRewards(
	ctx context.Context, target restakingtypes.DelegationTarget, del restakingtypes.Delegation, endingPeriod uint64,
) (rewards types.DecPools, err error)

CalculateDelegationRewards calculates the total rewards accrued by a delegation between the starting period and the current block height

func (*Keeper) CreateRewardsPlan

func (k *Keeper) CreateRewardsPlan(
	ctx context.Context,
	description string,
	serviceID uint32,
	amt sdk.Coins,
	startTime,
	endTime time.Time,
	poolsDistribution types.Distribution,
	operatorsDistribution types.Distribution,
	usersDistribution types.UsersDistribution,
) (types.RewardsPlan, error)

func (*Keeper) EditRewardsPlan added in v1.4.0

func (k *Keeper) EditRewardsPlan(
	ctx sdk.Context,
	planID uint64,
	newDescription string,
	newAmountPerDay sdk.Coins,
	newStartTime,
	newEndTime time.Time,
	newPoolsDistribution types.Distribution,
	newOperatorsDistribution types.Distribution,
	newUsersDistribution types.UsersDistribution,
) error

EditRewardsPlan edits an existing rewards plan.

func (*Keeper) ExportGenesis

func (k *Keeper) ExportGenesis(ctx sdk.Context) (*types.GenesisState, error)

ExportGenesis returns the GenesisState associated with the given context

func (*Keeper) GetAssetAndPrice

func (k *Keeper) GetAssetAndPrice(ctx context.Context, denom string) (assetstypes.Asset, math.LegacyDec, error)

func (*Keeper) GetAuthority

func (k *Keeper) GetAuthority() string

GetAuthority returns the module's authority.

func (*Keeper) GetCoinValue

func (k *Keeper) GetCoinValue(ctx context.Context, coin sdk.Coin) (math.LegacyDec, error)

func (*Keeper) GetCoinsValue

func (k *Keeper) GetCoinsValue(ctx context.Context, coins sdk.Coins) (math.LegacyDec, error)

func (*Keeper) GetCurrentRewards

func (k *Keeper) GetCurrentRewards(ctx context.Context, target restakingtypes.DelegationTarget) (types.CurrentRewards, error)

GetCurrentRewards returns the current rewards for a target

func (*Keeper) GetDelegationRewards

func (k *Keeper) GetDelegationRewards(
	ctx context.Context, delAddr sdk.AccAddress, delType restakingtypes.DelegationType, targetID uint32,
) (types.DecPools, error)

GetDelegationRewards returns the rewards for a delegation

func (*Keeper) GetDelegationTarget

func (k *Keeper) GetDelegationTarget(
	ctx context.Context, delType restakingtypes.DelegationType, targetID uint32,
) (restakingtypes.DelegationTarget, error)

func (*Keeper) GetDelegatorStartingInfo

func (k *Keeper) GetDelegatorStartingInfo(
	ctx context.Context, target restakingtypes.DelegationTarget, delegator sdk.AccAddress,
) (types.DelegatorStartingInfo, error)

GetDelegatorStartingInfo returns the delegator starting info for a delegator and target

func (*Keeper) GetDelegatorWithdrawAddr

func (k *Keeper) GetDelegatorWithdrawAddr(ctx context.Context, delegator sdk.AccAddress) (sdk.AccAddress, error)

GetDelegatorWithdrawAddr returns the delegator's withdraw address if set, otherwise the delegator address is returned.

func (*Keeper) GetHistoricalRewards

func (k *Keeper) GetHistoricalRewards(
	ctx context.Context, target restakingtypes.DelegationTarget, period uint64,
) (types.HistoricalRewards, error)

GetHistoricalRewards returns the historical rewards for a target and period

func (*Keeper) GetLastRewardsAllocationTime

func (k *Keeper) GetLastRewardsAllocationTime(ctx context.Context) (*time.Time, error)

GetLastRewardsAllocationTime returns the last time rewards were allocated. If there's no last rewards allocation time set yet, nil is returned.

func (*Keeper) GetOperatorAccumulatedCommission

func (k *Keeper) GetOperatorAccumulatedCommission(ctx context.Context, operatorID uint32) (commission types.AccumulatedCommission, err error)

GetOperatorAccumulatedCommission returns the accumulated commission for an operator.

func (*Keeper) GetOperatorDelegationRewards

func (k *Keeper) GetOperatorDelegationRewards(ctx context.Context, delAddr sdk.AccAddress, operatorID uint32) (types.DecPools, error)

GetOperatorDelegationRewards returns the rewards for an operator delegation

func (*Keeper) GetOutstandingRewards

func (k *Keeper) GetOutstandingRewards(ctx context.Context, target restakingtypes.DelegationTarget) (types.OutstandingRewards, error)

GetOutstandingRewards returns the outstanding rewards for a target

func (*Keeper) GetOutstandingRewardsCoins

func (k *Keeper) GetOutstandingRewardsCoins(ctx context.Context, target restakingtypes.DelegationTarget) (types.DecPools, error)

GetOutstandingRewardsCoins returns the outstanding rewards coins for a target

func (*Keeper) GetPoolDelegationRewards

func (k *Keeper) GetPoolDelegationRewards(ctx context.Context, delAddr sdk.AccAddress, poolID uint32) (types.DecPools, error)

GetPoolDelegationRewards returns the rewards for a pool delegation

func (*Keeper) GetRewardsPlan

func (k *Keeper) GetRewardsPlan(ctx context.Context, planID uint64) (types.RewardsPlan, error)

GetRewardsPlan returns a rewards plan by ID.

func (*Keeper) GetServiceDelegationRewards

func (k *Keeper) GetServiceDelegationRewards(
	ctx context.Context, delAddr sdk.AccAddress, serviceID uint32,
) (types.DecPools, error)

GetServiceDelegationRewards returns the rewards for a service delegation

func (*Keeper) HasCurrentRewards

func (k *Keeper) HasCurrentRewards(ctx context.Context, target restakingtypes.DelegationTarget) (bool, error)

HasCurrentRewards returns true if the current rewards exist for a target

func (*Keeper) HasDelegatorStartingInfo

func (k *Keeper) HasDelegatorStartingInfo(
	ctx context.Context, target restakingtypes.DelegationTarget, delegator sdk.AccAddress,
) (bool, error)

HasDelegatorStartingInfo returns true if the delegator starting info exists for a delegator and target

func (*Keeper) Hooks

func (k *Keeper) Hooks() Hooks

func (*Keeper) IncrementDelegationTargetPeriod

func (k *Keeper) IncrementDelegationTargetPeriod(ctx context.Context, target restakingtypes.DelegationTarget) (uint64, error)

increment period, returning the period just ended

func (*Keeper) InitGenesis

func (k *Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) error

InitGenesis initializes the state from a GenesisState

func (*Keeper) Logger

func (k *Keeper) Logger(ctx context.Context) log.Logger

Logger returns a module-specific logger.

func (*Keeper) RemoveDelegatorStartingInfo

func (k *Keeper) RemoveDelegatorStartingInfo(
	ctx context.Context, target restakingtypes.DelegationTarget, delegator sdk.AccAddress,
) error

RemoveDelegatorStartingInfo removes the delegator starting info for a delegator and target

func (*Keeper) RemoveHistoricalRewards

func (k *Keeper) RemoveHistoricalRewards(
	ctx context.Context, target restakingtypes.DelegationTarget, period uint64,
) error

RemoveHistoricalRewards removes the historical rewards for a target and period

func (*Keeper) SetCurrentRewards

func (k *Keeper) SetCurrentRewards(
	ctx context.Context, target restakingtypes.DelegationTarget, rewards types.CurrentRewards,
) error

SetCurrentRewards sets the current rewards for a target

func (*Keeper) SetDelegatorStartingInfo

func (k *Keeper) SetDelegatorStartingInfo(
	ctx context.Context, target restakingtypes.DelegationTarget, del sdk.AccAddress, info types.DelegatorStartingInfo,
) error

SetDelegatorStartingInfo sets the delegator starting info for a delegator.

func (*Keeper) SetHistoricalRewards

func (k *Keeper) SetHistoricalRewards(
	ctx context.Context, target restakingtypes.DelegationTarget, period uint64,
	rewards types.HistoricalRewards,
) error

SetHistoricalRewards sets the historical rewards for a target and period

func (*Keeper) SetLastRewardsAllocationTime

func (k *Keeper) SetLastRewardsAllocationTime(ctx context.Context, t time.Time) error

SetLastRewardsAllocationTime sets the last time rewards were allocated.

func (*Keeper) SetOutstandingRewards

func (k *Keeper) SetOutstandingRewards(
	ctx context.Context, target restakingtypes.DelegationTarget, rewards types.OutstandingRewards,
) error

SetOutstandingRewards sets the outstanding rewards for a target.

func (*Keeper) SetWithdrawAddress

func (k *Keeper) SetWithdrawAddress(ctx context.Context, addr, withdrawAddr sdk.AccAddress) error

SetWithdrawAddress sets a new address that will receive the rewards upon withdrawal

func (*Keeper) TerminateEndedRewardsPlans

func (k *Keeper) TerminateEndedRewardsPlans(ctx context.Context) error

TerminateEndedRewardsPlans terminates all rewards plans that have ended.

func (*Keeper) WithdrawDelegationRewards

func (k *Keeper) WithdrawDelegationRewards(
	ctx context.Context, delAddr sdk.AccAddress, target restakingtypes.DelegationTarget,
) (types.Pools, error)

WithdrawDelegationRewards withdraws the rewards from the delegation and reinitializes it

func (*Keeper) WithdrawOperatorCommission

func (k *Keeper) WithdrawOperatorCommission(ctx context.Context, operatorID uint32) (types.Pools, error)

WithdrawOperatorCommission withdraws the operator's accumulated commission

Jump to

Keyboard shortcuts

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