keeper

package
v23.0.5-iavl-v1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterLocksByMinDuration

func FilterLocksByMinDuration(locks []lockuptypes.PeriodLock, minDuration time.Duration, scratchSlice *[]*lockuptypes.PeriodLock) []*lockuptypes.PeriodLock

FilterLocksByMinDuration returns locks whose lock duration is greater than the provided minimum duration.

func NewIncentivesProposalHandler

func NewIncentivesProposalHandler(k Keeper) govtypesv1.Handler

func NewMsgServerImpl

func NewMsgServerImpl(keeper *Keeper) types.MsgServer

NewMsgServerImpl returns an instance of MsgServer for the provided keeper.

Types

type Hooks

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

Hooks is the wrapper struct for the incentives keeper.

func (Hooks) AfterEpochEnd

func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error

AfterEpochEnd is the epoch end hook.

func (Hooks) BeforeEpochStart

func (h Hooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error

BeforeEpochStart is the epoch start hook.

func (Hooks) GetModuleName added in v23.0.1

func (Hooks) GetModuleName() string

GetModuleName implements types.EpochHooks.

type Keeper

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

Keeper provides a way to manage incentives module storage.

func NewKeeper

NewKeeper returns a new instance of the incentive module keeper struct.

func (Keeper) ActiveGaugesIterator

func (k Keeper) ActiveGaugesIterator(ctx sdk.Context) sdk.Iterator

ActiveGaugesIterator returns the iterator for all active gauges.

func (Keeper) AddToGaugeRewards

func (k Keeper) AddToGaugeRewards(ctx sdk.Context, owner sdk.AccAddress, coins sdk.Coins, gaugeID uint64) error

AddToGaugeRewards adds coins to gauge.

func (Keeper) AfterEpochEnd

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error

AfterEpochEnd is the epoch end hook.

func (Keeper) AllocateAcrossGauges

func (k Keeper) AllocateAcrossGauges(ctx sdk.Context, activeGroups []types.Group) error

AllocateAcrossGauges for every gauge in the input, it updates the weights according to the splitting policy and allocates the coins to the underlying gauges per the updated weights. Note, every group is associated with a group gauge. The distribution to regular gauges happens from the group gauge. Returns error if: - fails to retrieve a group gauge - fails to add gauge rewards to any of the underlying gauges in the group.

Silently skips the following errors: - syncing group gauge weights fails - this is acceptable. We don't want to fail all distributions due to an oddity with one group. The rewards should stay in the group gauge until the next distribution. Any issues can be fixed with a major upgrade without any loss of funds. - group gauge is inactive - similar reason, don't want to fail all distributions due to non-fatal issue.

ASSUMPTIONS: - group cannot outlive the gauges associated with it. CONTRACT: - every group in the input is active. If inactive group is passed in, it will be skipped.

func (Keeper) BeforeEpochStart

func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error

BeforeEpochStart is the epoch start hook.

func (Keeper) CreateGauge

func (k Keeper) CreateGauge(ctx sdk.Context, isPerpetual bool, owner sdk.AccAddress, coins sdk.Coins, distrTo lockuptypes.QueryCondition, startTime time.Time, numEpochsPaidOver uint64, poolId uint64) (uint64, error)

CreateGauge creates a gauge with the given parameters and sends coins to the gauge. There can be 3 kinds of gauges for a given set of parameters: * lockuptypes.ByDuration - a gauge that incentivizes one of the lockable durations. For this gauge, the pool id must be 0. Fails if not.

* lockuptypes.NoLock - a gauge that incentivizes pools without locking. Initially, this is meant specifically for the concentrated liquidity pools. As a result, if NoLock gauge is being created, the given pool id must be non-zero, the pool at this id must exist and be of a concentrated liquidity type. Fails if not. Additionally, lockuptypes.Denom must be either an empty string, signifying that this is an external gauge, or be equal to types.NoLockInternalGaugeDenom(poolId). If the denom is empty, it will get overwritten to types.NoLockExternalGaugeDenom(poolId). This denom formatting is useful for querying internal vs external gauges associated with a pool. * lockuptypes.Group - a gauge that incentivizes a group of internal pool gauges based on the splitting policy created by a group data structure. It is expected to be created via CreateGroup keeper method. This gauge is the only gauge type that does not have ref keys (active/upcoming/finished) created and associated with it. For this gauge, the pool id must be 0. Fails if not.

Returns error if: - attempts to create non-perpetual gauge with numEpochsPaidOver of 0

On success, returns the gauge ID.

func (Keeper) CreateGaugeRefKeys

func (k Keeper) CreateGaugeRefKeys(ctx sdk.Context, gauge *types.Gauge, combinedKeys []byte) error

CreateGaugeRefKeys takes combinedKey (the keyPrefix for upcoming, active, or finished gauges combined with gauge start time) and adds a reference to the respective gauge ID. If gauge is active or upcoming, creates reference between the denom and gauge ID. Used to consolidate codepaths for InitGenesis and CreateGauge.

func (Keeper) CreateGroup

func (k Keeper) CreateGroup(ctx sdk.Context, coins sdk.Coins, numEpochPaidOver uint64, owner sdk.AccAddress, poolIDs []uint64) (uint64, error)

CreateGroup creates a new group. The group is 1:1 mapped to a group gauge that allocates rewards dynamically across its internal pool gauges based on the volume splitting policy. For each pool ID in the given slice, its main internal gauge is used to create gauge records to be associated with the Group. Note, that implies that only perpetual pool gauges can be associated with the Group. For Group's own distribution policy, a 1:1 group Gauge is created. This is the Gauge that receives incentives at the end of an epoch in the pool incentives as defined by the DistrRecord. The Group's Gauge can either be perpetual or non-perpetual. If numEpochPaidOver is 0, then the Group's Gauge is perpetual. Otherwise, it is non-perpetual. It syncs the group's weights at the time of creation. This is useful for validating that all the pools in the group are valid and have the associated volume at group creation time. Charges group creation fee, unless incentives module account. Returns nil on success. Returns error if: - given pool IDs slice is empty or has 1 pool only - fails to initialize gauge information for every pool ID - fails to send coins from owner to the incentives module for the Group's Gauge - fails to charge group creation fee - fails to set the Group's Gauge to state

func (Keeper) CreateGroupAsIncentivesModuleAcc

func (k Keeper) CreateGroupAsIncentivesModuleAcc(ctx sdk.Context, numEpochPaidOver uint64, poolIDs []uint64) (uint64, error)

CreateGroupAsIncentivesModuleAcc creates a group as incentives module account. The group is 1:1 mapped to a group gauge that allocates rewards dynamically across its internal pool gauges based on the volume splitting policy. For each pool ID in the given slice, its main internal gauge is used to create gauge records to be associated with the Group. Note, that implies that only perpetual pool gauges can be associated with the Group. For Group's own distribution policy, a 1:1 group Gauge is created. This is the Gauge that receives incentives at the end of an epoch in the pool incentives as defined by the DistrRecord. The Group's Gauge can either be perpetual or non-perpetual. If numEpochPaidOver is 0, then the Group's Gauge is perpetual. Otherwise, it is non-perpetual. The group is created with empty coins. It does not sync weights at the time of creation. This is useful for creating groups of pools in a privileged way For example, in the upgrade handler. Use with care since it is possible to create a group of pools that are invalid (have no volume) due to lack of syncing. Stores the group to state. The group creation fee is not charged on the incentives module account. See other details of group creation by reviewing createGroup() spec. Returns group gauge ID on success. Returns error if: - fails to create Group

func (Keeper) Distribute

func (k Keeper) Distribute(ctx sdk.Context, gauges []types.Gauge) (sdk.Coins, error)

Distribute distributes coins from an array of gauges to all eligible locks and pools in the case of "NoLock" gauges. Skips any group gauges as they are handled separately in AllocateAcrossGauges() CONTRACT: gauges must be active.

func (Keeper) ExportGenesis

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

ExportGenesis returns the x/incentives module's exported genesis.

func (Keeper) FilteredLocksDistributionEst

func (k Keeper) FilteredLocksDistributionEst(ctx sdk.Context, gauge types.Gauge, filteredLocks []lockuptypes.PeriodLock) (types.Gauge, sdk.Coins, bool, error)

FilteredLocksDistributionEst estimates distribution amount of coins from gauge. It also applies an update for the gauge, handling the sending of the rewards. (Note this update is in-memory, it does not change state.)

func (Keeper) FinishedGaugesIterator

func (k Keeper) FinishedGaugesIterator(ctx sdk.Context) sdk.Iterator

FinishedGaugesIterator returns the iterator for all finished gauges.

func (Keeper) GaugesIterator

func (k Keeper) GaugesIterator(ctx sdk.Context) sdk.Iterator

GaugesIterator returns the iterator for all gauges.

func (Keeper) GetActiveGauges

func (k Keeper) GetActiveGauges(ctx sdk.Context) []types.Gauge

GetActiveGauges returns active gauges.

func (Keeper) GetAllGroups

func (k Keeper) GetAllGroups(ctx sdk.Context) ([]types.Group, error)

GetAllGroupGauges gets all the groupGauges that is in state.

func (Keeper) GetAllGroupsGauges

func (k Keeper) GetAllGroupsGauges(ctx sdk.Context) ([]types.Gauge, error)

GetAllGroupsGauges iterates through all groups, sequentially pulls the gauges from each, and returns just the gauges.

func (Keeper) GetAllGroupsWithGauge

func (k Keeper) GetAllGroupsWithGauge(ctx sdk.Context) ([]types.GroupsWithGauge, error)

GetAllGroupsWithGauge iterates through all groups, sequentially pulls the gauges from each, and returns the groups with their associated gauge.

func (Keeper) GetEpochInfo

func (k Keeper) GetEpochInfo(ctx sdk.Context) epochtypes.EpochInfo

GetEpochInfo returns EpochInfo struct given context.

func (Keeper) GetFinishedGauges

func (k Keeper) GetFinishedGauges(ctx sdk.Context) []types.Gauge

GetFinishedGauges returns finished gauges.

func (Keeper) GetGaugeByID

func (k Keeper) GetGaugeByID(ctx sdk.Context, gaugeID uint64) (*types.Gauge, error)

GetGaugeByID returns gauge from gauge ID.

func (Keeper) GetGaugeFromIDs

func (k Keeper) GetGaugeFromIDs(ctx sdk.Context, gaugeIDs []uint64) ([]types.Gauge, error)

GetGaugeFromIDs returns multiple gauges from a gaugeIDs array.

func (Keeper) GetGauges

func (k Keeper) GetGauges(ctx sdk.Context) []types.Gauge

GetGauges returns upcoming, active, and finished gauges.

func (Keeper) GetGroupByGaugeID

func (k Keeper) GetGroupByGaugeID(ctx sdk.Context, gaugeID uint64) (types.Group, error)

GetGroupByGaugeID gets group struct for a given gauge ID. Note that Group and group's associated gauge are 1:1 mapped. As a result, they share the same ID.

func (Keeper) GetLastGaugeID

func (k Keeper) GetLastGaugeID(ctx sdk.Context) uint64

GetLastGaugeID returns the last used gauge ID.

func (Keeper) GetLockableDurations

func (k Keeper) GetLockableDurations(ctx sdk.Context) []time.Duration

GetLockableDurations returns all incentivized lockable durations.

func (Keeper) GetModuleDistributedCoins

func (k Keeper) GetModuleDistributedCoins(ctx sdk.Context) sdk.Coins

GetModuleDistributedCoins returns sum of coins that have been distributed so far for all of the module.

func (Keeper) GetModuleToDistributeCoins

func (k Keeper) GetModuleToDistributeCoins(ctx sdk.Context) sdk.Coins

GetModuleToDistributeCoins returns sum of coins yet to be distributed for all of the module.

func (Keeper) GetNotFinishedGauges

func (k Keeper) GetNotFinishedGauges(ctx sdk.Context) []types.Gauge

GetNotFinishedGauges returns both upcoming and active gauges.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams returns all of the parameters in the incentive module.

func (Keeper) GetPoolFromGaugeId

func (k Keeper) GetPoolFromGaugeId(ctx sdk.Context, gaugeId uint64, duration time.Duration) (poolmanagertypes.PoolI, error)

GetPoolFromGaugeId returns a pool associated with the given gauge id. Returns error if there is no link between pool id and gauge id. Returns error if pool is not saved in state.

func (Keeper) GetPoolIdAndDurationFromGaugeRecord

func (k Keeper) GetPoolIdAndDurationFromGaugeRecord(ctx sdk.Context, gaugeRecord types.InternalGaugeRecord) (uint64, time.Duration, error)

GetPoolIdAndDurationFromGaugeRecord retrieves the pool ID and duration associated with a given gauge record. The function first retrieves the gauge associated with the gauge record. If the gauge's lock query type is NoLock, the function sets the gauge duration to the epoch duration. Otherwise, it sets the gauge duration to the longest lockable duration. The function then retrieves the pool ID associated with the gauge ID and the gauge duration. The function returns the pool ID and the gauge duration. If there is an error retrieving the gauge, the longest lockable duration, or the pool ID, the function returns an error.

func (Keeper) GetPoolIdsAndDurationsFromGaugeRecords

func (k Keeper) GetPoolIdsAndDurationsFromGaugeRecords(ctx sdk.Context, gaugeRecords []types.InternalGaugeRecord) ([]uint64, []time.Duration, error)

GetPoolIdsAndDurationsFromGaugeRecords retrieves the pool IDs and their associated durations from a group's gauge records It iterates over each record and retrieves the pool ID and duration. The function returns two slices: one for the pool IDs and one for the durations. The indices in these slices correspond to each other. If there is an error retrieving the pool ID and duration for any gauge record, the function returns an error.

func (Keeper) GetRewardsEst

func (k Keeper) GetRewardsEst(ctx sdk.Context, addr sdk.AccAddress, locks []lockuptypes.PeriodLock, endEpoch int64) sdk.Coins

GetRewardsEst returns rewards estimation at a future specific time (by epoch) If locks are nil, it returns the rewards between now and the end epoch associated with address. If locks are not nil, it returns all the rewards for the given locks between now and end epoch.

func (Keeper) GetUpcomingGauges

func (k Keeper) GetUpcomingGauges(ctx sdk.Context) []types.Gauge

GetUpcomingGauges returns upcoming gauges.

func (Keeper) HandleCreateGaugeProposal

func (k Keeper) HandleCreateGaugeProposal(ctx sdk.Context, p *types.CreateGroupsProposal) error

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

Hooks returns the hook wrapper struct.

func (Keeper) InitGenesis

func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState)

InitGenesis initializes the incentives module's state from a provided genesis state.

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a logger instance for the incentives module.

func (Keeper) ParseGroupFromBz

func (k Keeper) ParseGroupFromBz(bz []byte) (group types.Group, err error)

func (Keeper) SetGaugeWithRefKey

func (k Keeper) SetGaugeWithRefKey(ctx sdk.Context, gauge *types.Gauge) error

SetGaugeWithRefKey takes a single gauge and assigns a key. Takes combinedKey (the keyPrefix for upcoming, active, or finished gauges combined with gauge start time) and adds a reference to the respective gauge ID. If this gauge is active or upcoming, creates reference between the denom and gauge ID.

func (Keeper) SetGroup

func (k Keeper) SetGroup(ctx sdk.Context, group types.Group)

SetGroup sets groupGroup for a specific key. TODO: explore if we can store this better, this has GroupGaugeId in key and value

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(ih types.IncentiveHooks) *Keeper

SetHooks sets the incentives hooks.

func (Keeper) SetLastGaugeID

func (k Keeper) SetLastGaugeID(ctx sdk.Context, ID uint64)

SetLastGaugeID sets the last used gauge ID to the provided ID.

func (Keeper) SetLockableDurations

func (k Keeper) SetLockableDurations(ctx sdk.Context, lockableDurations []time.Duration)

SetLockableDurations sets which lockable durations will be incentivized.

func (Keeper) SetParam

func (k Keeper) SetParam(ctx sdk.Context, key []byte, value interface{})

SetParam sets a specific incentives module's parameter with the provided parameter.

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams sets all of the parameters in the incentive module.

func (*Keeper) SetPoolIncentivesKeeper

func (k *Keeper) SetPoolIncentivesKeeper(poolIncentiveKeeper types.PoolIncentiveKeeper)

SetPoolIncentivesKeeper sets pool incentives keeper

func (Keeper) UpcomingGaugesIterator

func (k Keeper) UpcomingGaugesIterator(ctx sdk.Context) sdk.Iterator

UpcomingGaugesIterator returns the iterator for all upcoming gauges.

func (Keeper) UpcomingGaugesIteratorAfterTime

func (k Keeper) UpcomingGaugesIteratorAfterTime(ctx sdk.Context, time time.Time) sdk.Iterator

UpcomingGaugesIteratorAfterTime returns the iterator to get all upcoming gauges that start distribution after a specific time.

func (Keeper) UpcomingGaugesIteratorBeforeTime

func (k Keeper) UpcomingGaugesIteratorBeforeTime(ctx sdk.Context, time time.Time) sdk.Iterator

UpcomingGaugesIteratorBeforeTime returns the iterator to get all upcoming gauges that have already started distribution before a specific time.

type Querier

type Querier struct {
	Keeper
}

Querier defines a wrapper around the incentives module keeper providing gRPC method handlers.

func NewQuerier

func NewQuerier(k Keeper) Querier

NewQuerier creates a new Querier struct.

func (Querier) ActiveGauges

ActiveGauges returns all active gauges.

func (Querier) ActiveGaugesPerDenom

ActiveGaugesPerDenom returns all active gauges for the specified denom.

func (Querier) AllGroups

AllGroups returns all groups that exist on chain.

func (Querier) AllGroupsGauges

AllGroupsGauges returns all group gauges that exist on chain.

func (Querier) AllGroupsWithGauge

AllGroupsWithGauge returns all groups with their respective gauge that exist on chain.

func (Querier) GaugeByID

GaugeByID takes a gaugeID and returns its respective gauge.

func (Querier) Gauges

func (q Querier) Gauges(goCtx context.Context, req *types.GaugesRequest) (*types.GaugesResponse, error)

Gauges returns all upcoming and active gauges.

func (Querier) GroupByGroupGaugeID

GroupByGroupGaugeID retrieves a group by its associated gauge ID. If the group cannot be found or an error occurs during the operation, it returns an error.

func (Querier) LockableDurations

LockableDurations returns all of the allowed lockable durations on chain.

func (Querier) ModuleToDistributeCoins

ModuleToDistributeCoins returns coins that are going to be distributed.

func (Querier) RewardsEst

RewardsEst returns rewards estimation at a future specific time (by epoch).

func (Querier) UpcomingGauges

UpcomingGauges returns all upcoming gauges.

func (Querier) UpcomingGaugesPerDenom

UpcomingGaugesPerDenom returns all upcoming gauges for the specified denom.

Jump to

Keyboard shortcuts

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