keeper

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 29 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 DelegationTarget

DelegationTarget is a wrapper around the delegation target that holds the delegation type and collection references for the target's type.

type DistributionInfo

type DistributionInfo struct {
	DelegationTarget DelegationTarget
	DelegationsValue math.LegacyDec
}

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

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]
	// (poolID, serviceID) -> total delegator shares
	PoolServiceTotalDelegatorShares collections.Map[collections.Pair[uint32, uint32], types.PoolServiceTotalDelegatorShares]

	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 context.Context, delType restakingtypes.DelegationType, targetID uint32, delegator string) error

AfterDelegationModified is called after a delegation to a target is modified

func (*Keeper) AfterDelegationTargetCreated

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

AfterDelegationTargetCreated is called after a delegation target is created

func (*Keeper) AfterServiceAccreditationModified

func (k *Keeper) AfterServiceAccreditationModified(ctx context.Context, serviceID uint32) error

AfterServiceAccreditationModified implements servicestypes.ServicesHooks

func (*Keeper) AfterUserPreferencesModified

func (k *Keeper) AfterUserPreferencesModified(
	ctx context.Context,
	userAddress string,
	oldPreferences, newPreferences restakingtypes.UserPreferences,
) error

AfterUserPreferencesModified is called after a user's trust in a service is updated. It updates the total delegator shares for the service in all pools where the user has a delegation.

func (*Keeper) AfterUserTrustedServiceUpdated

func (k *Keeper) AfterUserTrustedServiceUpdated(
	ctx context.Context,
	userAddress string,
	serviceID uint32,
	trusted bool,
) error

AfterUserTrustedServiceUpdated is called after a user's trust in a service is updated. AfterUserTrustedServiceUpdated updates the total delegator shares for the service in all pools where the user has a delegation.

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, restakableDenoms []string,
) error

AllocateRewardsByPlan allocates rewards by a specific rewards plan.

func (*Keeper) BeforeDelegationCreated

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

BeforeDelegationCreated is called before a delegation to a target is created

func (*Keeper) BeforeDelegationSharesModified

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

BeforeDelegationSharesModified is called before a delegation to a target is modified

func (*Keeper) BeforeDelegationTargetRemoved

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

BeforeDelegationTargetRemoved is called before a delegation target is removed

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 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) DecrementPoolServiceTotalDelegatorShares

func (k *Keeper) DecrementPoolServiceTotalDelegatorShares(
	ctx context.Context, poolID, serviceID uint32, shares sdk.DecCoins,
) error

DecrementPoolServiceTotalDelegatorShares decrements the total delegator shares for a pool-service pair.

func (*Keeper) DeleteAllPoolServiceTotalDelegatorSharesByService

func (k *Keeper) DeleteAllPoolServiceTotalDelegatorSharesByService(ctx context.Context, serviceID uint32) error

DeleteAllPoolServiceTotalDelegatorSharesByService deletes all total delegator shares for a pool.

func (*Keeper) DeleteHistoricalRewards

func (k *Keeper) DeleteHistoricalRewards(ctx context.Context, target DelegationTarget) error

DeleteHistoricalRewards deletes all historical rewards for a target

func (*Keeper) DeleteOperatorAccumulatedCommission

func (k *Keeper) DeleteOperatorAccumulatedCommission(ctx context.Context, operatorID uint32) error

DeleteOperatorAccumulatedCommission deletes the accumulated commission for an operator.

func (*Keeper) DeletePoolServiceTotalDelegatorShares

func (k *Keeper) DeletePoolServiceTotalDelegatorShares(ctx context.Context, poolID, serviceID uint32) error

DeletePoolServiceTotalDelegatorShares deletes the total delegator shares for a pool-service pair.

func (*Keeper) EditRewardsPlan

func (k *Keeper) EditRewardsPlan(
	ctx context.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) 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,
) (DelegationTarget, error)

GetDelegationTarget returns the wrapped delegation target for the given delegation type and target ID.

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) 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) GetOperatorWithdrawAddr

func (k *Keeper) GetOperatorWithdrawAddr(ctx context.Context, operator operatorstypes.Operator) (sdk.AccAddress, error)

GetOperatorWithdrawAddr returns the outstanding rewards coins for an operator

func (*Keeper) GetOutstandingRewardsCoins

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

GetOutstandingRewardsCoins returns the outstanding rewards coins for a target

func (*Keeper) GetParams

func (k *Keeper) GetParams(ctx context.Context) (p types.Params, err error)

GetParams returns the module parameters

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) GetPoolServiceTotalDelegatorShares

func (k *Keeper) GetPoolServiceTotalDelegatorShares(ctx context.Context, poolID, serviceID uint32) (sdk.DecCoins, error)

GetPoolServiceTotalDelegatorShares returns the total delegator shares for a pool-service pair.

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) IncrementDelegationTargetPeriod

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

IncrementDelegationTargetPeriod increments the period, returning the period that just ended

func (*Keeper) IncrementPoolServiceTotalDelegatorShares

func (k *Keeper) IncrementPoolServiceTotalDelegatorShares(
	ctx context.Context, poolID, serviceID uint32, shares sdk.DecCoins,
) error

IncrementPoolServiceTotalDelegatorShares increments the total delegator shares for a pool-service pair.

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) OperatorsHooks

func (k *Keeper) OperatorsHooks() OperatorsHooks

func (*Keeper) PoolsHooks

func (k *Keeper) PoolsHooks() PoolsHooks

func (*Keeper) RestakingHooks

func (k *Keeper) RestakingHooks() RestakingHooks

func (*Keeper) ServicesHooks

func (k *Keeper) ServicesHooks() ServicesHooks

func (*Keeper) SetLastRewardsAllocationTime

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

SetLastRewardsAllocationTime sets the last time rewards were allocated.

func (*Keeper) SetParams

func (k *Keeper) SetParams(ctx context.Context, params types.Params) error

SetParams sets module parameters

func (*Keeper) SetPoolServiceTotalDelegatorShares

func (k *Keeper) SetPoolServiceTotalDelegatorShares(ctx context.Context, poolID, serviceID uint32, shares sdk.DecCoins) error

SetPoolServiceTotalDelegatorShares sets the total delegator shares for a pool-service pair.

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 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

type OperatorsHooks

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

func (OperatorsHooks) AfterOperatorInactivatingCompleted

func (h OperatorsHooks) AfterOperatorInactivatingCompleted(context.Context, uint32) error

AfterOperatorInactivatingCompleted implements operatorstypes.OperatorsHooks

func (OperatorsHooks) AfterOperatorInactivatingStarted

func (h OperatorsHooks) AfterOperatorInactivatingStarted(context.Context, uint32) error

AfterOperatorInactivatingStarted implements operatorstypes.OperatorsHooks

func (OperatorsHooks) AfterOperatorReactivated

func (h OperatorsHooks) AfterOperatorReactivated(context.Context, uint32) error

AfterOperatorReactivated implements operatorstypes.OperatorsHooks

func (OperatorsHooks) AfterOperatorRegistered

func (h OperatorsHooks) AfterOperatorRegistered(ctx context.Context, operatorID uint32) error

AfterOperatorRegistered implements operatorstypes.OperatorsHooks

func (OperatorsHooks) BeforeOperatorDeleted

func (h OperatorsHooks) BeforeOperatorDeleted(ctx context.Context, operatorID uint32) error

BeforeOperatorDeleted implements operatorstypes.OperatorsHooks

type PoolsHooks

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

func (PoolsHooks) AfterPoolCreated

func (h PoolsHooks) AfterPoolCreated(ctx context.Context, poolID uint32) error

AfterPoolCreated implements poolstypes.PoolsHooks

type RestakingHooks

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

func (RestakingHooks) AfterOperatorDelegationModified

func (h RestakingHooks) AfterOperatorDelegationModified(ctx context.Context, operatorID uint32, delegator string) error

AfterOperatorDelegationModified implements restakingtypes.RestakingHooks

func (RestakingHooks) AfterPoolDelegationModified

func (h RestakingHooks) AfterPoolDelegationModified(ctx context.Context, poolID uint32, delegator string) error

AfterPoolDelegationModified implements restakingtypes.RestakingHooks

func (RestakingHooks) AfterServiceDelegationModified

func (h RestakingHooks) AfterServiceDelegationModified(ctx context.Context, serviceID uint32, delegator string) error

AfterServiceDelegationModified implements restakingtypes.RestakingHooks

func (RestakingHooks) AfterUnbondingInitiated

func (h RestakingHooks) AfterUnbondingInitiated(_ context.Context, _ uint64) error

AfterUnbondingInitiated implements restakingtypes.RestakingHooks

func (RestakingHooks) AfterUserPreferencesModified

func (h RestakingHooks) AfterUserPreferencesModified(ctx context.Context, userAddress string, oldPreferences, newPreferences restakingtypes.UserPreferences) error

AfterUserPreferencesModified implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforeOperatorDelegationCreated

func (h RestakingHooks) BeforeOperatorDelegationCreated(ctx context.Context, operatorID uint32, _ string) error

BeforeOperatorDelegationCreated implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforeOperatorDelegationRemoved

func (h RestakingHooks) BeforeOperatorDelegationRemoved(_ context.Context, _ uint32, _ string) error

BeforeOperatorDelegationRemoved implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforeOperatorDelegationSharesModified

func (h RestakingHooks) BeforeOperatorDelegationSharesModified(ctx context.Context, operatorID uint32, delegator string) error

BeforeOperatorDelegationSharesModified implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforePoolDelegationCreated

func (h RestakingHooks) BeforePoolDelegationCreated(ctx context.Context, poolID uint32, _ string) error

BeforePoolDelegationCreated implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforePoolDelegationRemoved

func (h RestakingHooks) BeforePoolDelegationRemoved(_ context.Context, _ uint32, _ string) error

BeforePoolDelegationRemoved implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforePoolDelegationSharesModified

func (h RestakingHooks) BeforePoolDelegationSharesModified(ctx context.Context, poolID uint32, delegator string) error

BeforePoolDelegationSharesModified implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforeServiceDelegationCreated

func (h RestakingHooks) BeforeServiceDelegationCreated(ctx context.Context, serviceID uint32, _ string) error

BeforeServiceDelegationCreated implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforeServiceDelegationRemoved

func (h RestakingHooks) BeforeServiceDelegationRemoved(_ context.Context, _ uint32, _ string) error

BeforeServiceDelegationRemoved implements restakingtypes.RestakingHooks

func (RestakingHooks) BeforeServiceDelegationSharesModified

func (h RestakingHooks) BeforeServiceDelegationSharesModified(ctx context.Context, serviceID uint32, delegator string) error

BeforeServiceDelegationSharesModified implements restakingtypes.RestakingHooks

type ServicesHooks

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

func (ServicesHooks) AfterServiceAccreditationModified

func (h ServicesHooks) AfterServiceAccreditationModified(ctx context.Context, serviceID uint32) error

AfterServiceAccreditationModified implements servicestypes.ServicesHooks

func (ServicesHooks) AfterServiceActivated

func (h ServicesHooks) AfterServiceActivated(context.Context, uint32) error

AfterServiceActivated implements servicestypes.ServicesHooks

func (ServicesHooks) AfterServiceCreated

func (h ServicesHooks) AfterServiceCreated(ctx context.Context, serviceID uint32) error

AfterServiceCreated implements servicestypes.ServicesHooks

func (ServicesHooks) AfterServiceDeactivated

func (h ServicesHooks) AfterServiceDeactivated(context.Context, uint32) error

AfterServiceDeactivated implements servicestypes.ServicesHooks

func (ServicesHooks) BeforeServiceDeleted

func (h ServicesHooks) BeforeServiceDeleted(ctx context.Context, serviceID uint32) error

BeforeServiceDeleted implements servicestypes.ServicesHooks

Jump to

Keyboard shortcuts

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