keeper

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// EnableAdvanceEpoch indicates whether msgServer accepts MsgAdvanceEpoch or not.
	// Never set this to true in production mode. Doing that will expose serious attack vector.
	EnableAdvanceEpoch = false
)

Functions

func AllInvariants

func AllInvariants(k Keeper) sdk.Invariant

AllInvariants runs all invariants of the farming module.

func HandlePublicPlanProposal

func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicPlanProposal) error

HandlePublicPlanProposal is a handler for executing a public plan creation proposal.

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the farming MsgServer interface for the provided Keeper.

func NonNegativeHistoricalRewardsInvariant

func NonNegativeHistoricalRewardsInvariant(k Keeper) sdk.Invariant

NonNegativeHistoricalRewardsInvariant checks that all HistoricalRewards are non-negative.

func NonNegativeOutstandingRewardsInvariant

func NonNegativeOutstandingRewardsInvariant(k Keeper) sdk.Invariant

NonNegativeOutstandingRewardsInvariant checks that all OutstandingRewards are non-negative.

func OutstandingRewardsAmountInvariant

func OutstandingRewardsAmountInvariant(k Keeper) sdk.Invariant

OutstandingRewardsAmountInvariant checks that OutstandingRewards are consistent with rewards that can be withdrawn.

func PositiveQueuedStakingAmountInvariant

func PositiveQueuedStakingAmountInvariant(k Keeper) sdk.Invariant

PositiveQueuedStakingAmountInvariant checks that the amount of queued staking coins is positive.

func PositiveStakingAmountInvariant

func PositiveStakingAmountInvariant(k Keeper) sdk.Invariant

PositiveStakingAmountInvariant checks that the amount of staking coins is positive.

func PositiveTotalStakingsAmountInvariant

func PositiveTotalStakingsAmountInvariant(k Keeper) sdk.Invariant

PositiveTotalStakingsAmountInvariant checks that all TotalStakings have positive amount.

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)

RegisterInvariants registers all farming invariants.

func RemainingRewardsAmountInvariant

func RemainingRewardsAmountInvariant(k Keeper) sdk.Invariant

RemainingRewardsAmountInvariant checks that the balance of the RewardPoolAddresses of all plans greater than the total amount of unwithdrawn reward coins in all reward objects

func StakingReservedAmountInvariant

func StakingReservedAmountInvariant(k Keeper) sdk.Invariant

StakingReservedAmountInvariant checks that the balance of StakingReserveAcc greater than the amount of staked, Queued coins in all staking objects.

Types

type AllocationInfo

type AllocationInfo struct {
	Plan   types.PlanI
	Amount sdk.Coins
}

AllocationInfo holds information about an allocation for a plan.

type Keeper

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

Keeper of the farming store

func NewKeeper

func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
	accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
) Keeper

NewKeeper returns a farming keeper. It handles: - creating new ModuleAccounts for each pool ReserveAccount - sending to and from ModuleAccounts - minting, burning PoolCoins

func (Keeper) AddPublicPlanProposal

func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []types.AddPlanRequest) error

AddPublicPlanProposal adds a new public plan once the governance proposal is passed.

func (Keeper) AdvanceEpoch

func (k Keeper) AdvanceEpoch(ctx sdk.Context) error

AdvanceEpoch ends the current epoch. When an epoch ends, rewards are distributed and queued staking coins become staked.

func (Keeper) AllRewards

func (k Keeper) AllRewards(ctx sdk.Context, farmerAcc sdk.AccAddress) sdk.Coins

AllRewards returns truncated total rewards accumulated until the current epoch for a farmer.

func (Keeper) AllocateRewards

func (k Keeper) AllocateRewards(ctx sdk.Context) error

AllocateRewards updates historical rewards and current epoch info based on the allocation infos.

func (Keeper) AllocationInfos

func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo

AllocationInfos returns allocation infos for the end of the current epoch. When total allocated coins for a farming pool exceeds the pool's balance, then allocation will not happen.

func (Keeper) CalculateRewards

func (k Keeper) CalculateRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string, endingEpoch uint64) (rewards sdk.DecCoins)

CalculateRewards returns rewards accumulated until endingEpoch for a farmer for a given staking coin denom.

func (Keeper) CreateFixedAmountPlan

func (k Keeper) CreateFixedAmountPlan(ctx sdk.Context, msg *types.MsgCreateFixedAmountPlan, farmingPoolAcc, terminationAcc sdk.AccAddress, typ types.PlanType) (types.PlanI, error)

CreateFixedAmountPlan sets fixed amount plan.

func (Keeper) CreateRatioPlan

func (k Keeper) CreateRatioPlan(ctx sdk.Context, msg *types.MsgCreateRatioPlan, farmingPoolAcc, terminationAcc sdk.AccAddress, typ types.PlanType) (types.PlanI, error)

CreateRatioPlan sets ratio plan.

func (Keeper) DecreaseOutstandingRewards

func (k Keeper) DecreaseOutstandingRewards(ctx sdk.Context, stakingCoinDenom string, amount sdk.DecCoins)

DecreaseOutstandingRewards decreases outstanding rewards for a given staking coin denom by given amount. If the resulting outstanding rewards is zero, then the outstanding rewards will be deleted, not updated.

func (Keeper) DecreaseTotalStakings

func (k Keeper) DecreaseTotalStakings(ctx sdk.Context, stakingCoinDenom string, amount sdk.Int)

DecreaseTotalStakings decreases total stakings for given staking coin denom by given amount.

func (Keeper) DeleteAllHistoricalRewards

func (k Keeper) DeleteAllHistoricalRewards(ctx sdk.Context, stakingCoinDenom string)

DeleteAllHistoricalRewards deletes all historical rewards for a staking coin denom.

func (Keeper) DeleteCurrentEpoch

func (k Keeper) DeleteCurrentEpoch(ctx sdk.Context, stakingCoinDenom string)

DeleteCurrentEpoch deletes current epoch info for a given staking coin denom.

func (Keeper) DeleteHistoricalRewards

func (k Keeper) DeleteHistoricalRewards(ctx sdk.Context, stakingCoinDenom string, epoch uint64)

DeleteHistoricalRewards deletes historical rewards for a given staking coin denom and an epoch number.

func (Keeper) DeleteOutstandingRewards

func (k Keeper) DeleteOutstandingRewards(ctx sdk.Context, stakingCoinDenom string)

DeleteOutstandingRewards deletes outstanding rewards for a given staking coin denom.

func (Keeper) DeletePublicPlanProposal

func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []types.DeletePlanRequest) error

DeletePublicPlanProposal deletes public plan proposal once the governance proposal is passed.

func (Keeper) DeleteQueuedStaking

func (k Keeper) DeleteQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress)

DeleteQueuedStaking deletes a queued staking for given staking coin denom and farmer.

func (Keeper) DeleteStaking

func (k Keeper) DeleteStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress)

DeleteStaking deletes a staking for given staking coin denom and farmer.

func (Keeper) DeleteTotalStakings

func (k Keeper) DeleteTotalStakings(ctx sdk.Context, stakingCoinDenom string)

DeleteTotalStakings deletes total stakings for given staking coin denom.

func (Keeper) DerivePrivatePlanFarmingPoolAcc

func (k Keeper) DerivePrivatePlanFarmingPoolAcc(ctx sdk.Context, name string) (sdk.AccAddress, error)

DerivePrivatePlanFarmingPoolAcc returns a unique account address of a farming pool for a private plan.

func (Keeper) ExportGenesis

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

ExportGenesis returns the farming module's genesis state.

func (Keeper) GetAllQueuedCoinsByFarmer

func (k Keeper) GetAllQueuedCoinsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress) sdk.Coins

GetAllQueuedCoinsByFarmer returns all coins that are queued for staking by a farmer.

func (Keeper) GetAllStakedCoinsByFarmer

func (k Keeper) GetAllStakedCoinsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress) sdk.Coins

GetAllStakedCoinsByFarmer returns all coins that are staked by a farmer.

func (Keeper) GetCodec

func (k Keeper) GetCodec() codec.BinaryCodec

GetCodec returns codec.Codec object used by the keeper>

func (Keeper) GetCurrentEpoch

func (k Keeper) GetCurrentEpoch(ctx sdk.Context, stakingCoinDenom string) uint64

GetCurrentEpoch returns the current epoch number for a given staking coin denom.

func (Keeper) GetCurrentEpochDays

func (k Keeper) GetCurrentEpochDays(ctx sdk.Context) uint32

GetCurrentEpochDays returns the current epoch days(period).

func (Keeper) GetFarmingFeeCollectorAcc

func (k Keeper) GetFarmingFeeCollectorAcc(ctx sdk.Context) sdk.AccAddress

GetFarmingFeeCollectorAcc returns module account for the farming fee collector account.

func (Keeper) GetGlobalPlanId

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

GetGlobalPlanId returns the global Plan ID counter.

func (Keeper) GetHistoricalRewards

func (k Keeper) GetHistoricalRewards(ctx sdk.Context, stakingCoinDenom string, epoch uint64) (rewards types.HistoricalRewards, found bool)

GetHistoricalRewards returns historical rewards for a given staking coin denom and an epoch number.

func (Keeper) GetLastEpochTime

func (k Keeper) GetLastEpochTime(ctx sdk.Context) (t time.Time, found bool)

GetLastEpochTime returns the last time the epoch ended.

func (Keeper) GetNextPlanIdWithUpdate

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

GetNextPlanIdWithUpdate returns and increments the global Plan ID counter. If the global plan number is not set, it initializes it with value 0.

func (Keeper) GetOutstandingRewards

func (k Keeper) GetOutstandingRewards(ctx sdk.Context, stakingCoinDenom string) (rewards types.OutstandingRewards, found bool)

GetOutstandingRewards returns outstanding rewards for a given staking coin denom.

func (Keeper) GetParams

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

GetParams returns the parameters for the farming module.

func (Keeper) GetPlan

func (k Keeper) GetPlan(ctx sdk.Context, id uint64) (plan types.PlanI, found bool)

GetPlan returns a plan for a given plan id.

func (Keeper) GetPlans

func (k Keeper) GetPlans(ctx sdk.Context) (plans []types.PlanI)

GetPlans returns all plans in the store.

func (Keeper) GetQueuedStaking

func (k Keeper) GetQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) (queuedStaking types.QueuedStaking, found bool)

GetQueuedStaking returns a queued staking for given staking coin denom and farmer.

func (Keeper) GetStaking

func (k Keeper) GetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress) (staking types.Staking, found bool)

GetStaking returns a staking for given staking denom and farmer.

func (Keeper) GetTotalStakings

func (k Keeper) GetTotalStakings(ctx sdk.Context, stakingCoinDenom string) (totalStakings types.TotalStakings, found bool)

GetTotalStakings returns total stakings for given staking coin denom.

func (Keeper) Harvest

func (k Keeper) Harvest(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenoms []string) error

Harvest claims farming rewards from the reward pool.

func (Keeper) IncreaseOutstandingRewards

func (k Keeper) IncreaseOutstandingRewards(ctx sdk.Context, stakingCoinDenom string, amount sdk.DecCoins)

IncreaseOutstandingRewards increases outstanding rewards for a given staking coin denom by given amount.

func (Keeper) IncreaseTotalStakings

func (k Keeper) IncreaseTotalStakings(ctx sdk.Context, stakingCoinDenom string, amount sdk.Int)

IncreaseTotalStakings increases total stakings for given staking coin denom by given amount.

func (Keeper) InitGenesis

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

InitGenesis initializes the farming module's state from a given genesis state.

func (Keeper) IterateCurrentEpochs

func (k Keeper) IterateCurrentEpochs(ctx sdk.Context, cb func(stakingCoinDenom string, currentEpoch uint64) (stop bool))

IterateCurrentEpochs iterates through all current epoch infos stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IterateHistoricalRewards

func (k Keeper) IterateHistoricalRewards(ctx sdk.Context, cb func(stakingCoinDenom string, epoch uint64, rewards types.HistoricalRewards) (stop bool))

IterateHistoricalRewards iterates through all historical rewards stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IterateOutstandingRewards

func (k Keeper) IterateOutstandingRewards(ctx sdk.Context, cb func(stakingCoinDenom string, rewards types.OutstandingRewards) (stop bool))

IterateOutstandingRewards iterates through all outstanding rewards stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IteratePlans

func (k Keeper) IteratePlans(ctx sdk.Context, cb func(plan types.PlanI) (stop bool))

IteratePlans iterates over all the stored plans and performs a callback function. Stops iteration when callback returns true.

func (Keeper) IterateQueuedStakings

func (k Keeper) IterateQueuedStakings(ctx sdk.Context, cb func(stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking) (stop bool))

IterateQueuedStakings iterates through all queued stakings stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IterateQueuedStakingsByFarmer

func (k Keeper) IterateQueuedStakingsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(stakingCoinDenom string, queuedStaking types.QueuedStaking) (stop bool))

IterateQueuedStakingsByFarmer iterates through all queued stakings by farmer stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IterateStakings

func (k Keeper) IterateStakings(ctx sdk.Context, cb func(stakingCoinDenom string, farmerAcc sdk.AccAddress, staking types.Staking) (stop bool))

IterateStakings iterates through all stakings stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IterateStakingsByFarmer

func (k Keeper) IterateStakingsByFarmer(ctx sdk.Context, farmerAcc sdk.AccAddress, cb func(stakingCoinDenom string, staking types.Staking) (stop bool))

IterateStakingsByFarmer iterates through all stakings by a farmer stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) IterateTotalStakings

func (k Keeper) IterateTotalStakings(ctx sdk.Context, cb func(stakingCoinDenom string, totalStakings types.TotalStakings) (stop bool))

IterateTotalStakings iterates through all total stakings stored in the store and invokes callback function for each item. Stops the iteration when the callback function returns true.

func (Keeper) Logger

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

Logger returns a module-specific logger.

func (Keeper) MarshalPlan

func (k Keeper) MarshalPlan(plan types.PlanI) ([]byte, error)

MarshalPlan serializes a plan.

func (Keeper) ModifyPublicPlanProposal

func (k Keeper) ModifyPublicPlanProposal(ctx sdk.Context, proposals []types.ModifyPlanRequest) error

ModifyPublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed.

func (Keeper) ProcessQueuedCoins

func (k Keeper) ProcessQueuedCoins(ctx sdk.Context)

ProcessQueuedCoins moves queued coins into staked coins. It causes accumulated rewards to be withdrawn to the farmer.

func (Keeper) ReleaseStakingCoins

func (k Keeper) ReleaseStakingCoins(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoins sdk.Coins) error

ReleaseStakingCoins sends staking coins back to the farmer.

func (Keeper) RemovePlan

func (k Keeper) RemovePlan(ctx sdk.Context, plan types.PlanI)

RemovePlan removes a plan from the store. NOTE: this will cause supply invariant violation if called

func (Keeper) ReserveStakingCoins

func (k Keeper) ReserveStakingCoins(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoins sdk.Coins) error

ReserveStakingCoins sends staking coins to the staking reserve account.

func (Keeper) Rewards

func (k Keeper) Rewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string) sdk.Coins

Rewards returns truncated rewards accumulated until the current epoch for a farmer for a given staking coin denom.

func (Keeper) SetCurrentEpoch

func (k Keeper) SetCurrentEpoch(ctx sdk.Context, stakingCoinDenom string, currentEpoch uint64)

SetCurrentEpoch sets the current epoch number for a given staking coin denom.

func (Keeper) SetCurrentEpochDays

func (k Keeper) SetCurrentEpochDays(ctx sdk.Context, epochDays uint32)

SetCurrentEpochDays sets the current epoch days(period).

func (Keeper) SetGlobalPlanId

func (k Keeper) SetGlobalPlanId(ctx sdk.Context, id uint64)

SetGlobalPlanId sets the global Plan ID counter.

func (Keeper) SetHistoricalRewards

func (k Keeper) SetHistoricalRewards(ctx sdk.Context, stakingCoinDenom string, epoch uint64, rewards types.HistoricalRewards)

SetHistoricalRewards sets historical rewards for a given staking coin denom and an epoch number.

func (Keeper) SetLastEpochTime

func (k Keeper) SetLastEpochTime(ctx sdk.Context, t time.Time)

SetLastEpochTime sets the last time the epoch ended.

func (Keeper) SetOutstandingRewards

func (k Keeper) SetOutstandingRewards(ctx sdk.Context, stakingCoinDenom string, rewards types.OutstandingRewards)

SetOutstandingRewards sets outstanding rewards for a given staking coin denom.

func (Keeper) SetParams

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

SetParams sets the parameters for the farming module.

func (Keeper) SetPlan

func (k Keeper) SetPlan(ctx sdk.Context, plan types.PlanI)

SetPlan sets a plan for a given plan id.

func (Keeper) SetQueuedStaking

func (k Keeper) SetQueuedStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress, queuedStaking types.QueuedStaking)

SetQueuedStaking sets a queued staking for given staking coin denom and farmer.

func (Keeper) SetStaking

func (k Keeper) SetStaking(ctx sdk.Context, stakingCoinDenom string, farmerAcc sdk.AccAddress, staking types.Staking)

SetStaking sets a staking for given staking coin denom and farmer.

func (Keeper) SetTotalStakings

func (k Keeper) SetTotalStakings(ctx sdk.Context, stakingCoinDenom string, totalStakings types.TotalStakings)

SetTotalStakings sets total stakings for given staking coin denom.

func (Keeper) Stake

func (k Keeper) Stake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coins) error

Stake stores staking coins to queued coins, and it will be processed in the next epoch.

func (Keeper) TerminatePlan

func (k Keeper) TerminatePlan(ctx sdk.Context, plan types.PlanI) error

TerminatePlan sends all remaining coins in the plan's farming pool to the termination address and mark the plan as terminated.

func (Keeper) UnmarshalPlan

func (k Keeper) UnmarshalPlan(bz []byte) (plan types.PlanI, err error)

UnmarshalPlan returns a plan from raw serialized bytes of a Proto-based Plan type.

func (Keeper) Unstake

func (k Keeper) Unstake(ctx sdk.Context, farmerAcc sdk.AccAddress, amount sdk.Coins) error

Unstake unstakes an amount of staking coins from the staking reserve account. It causes accumulated rewards to be withdrawn to the farmer.

func (Keeper) ValidateOutstandingRewardsAmount

func (k Keeper) ValidateOutstandingRewardsAmount(ctx sdk.Context) error

ValidateOutstandingRewardsAmount checks that the balance of the rewards reserve pool is greater than the total amount of outstanding rewards.

func (Keeper) ValidateRemainingRewardsAmount

func (k Keeper) ValidateRemainingRewardsAmount(ctx sdk.Context) error

ValidateRemainingRewardsAmount checks that the balance of the rewards reserve pool is greater than the total amount of unwithdrawn rewards.

func (Keeper) ValidateStakingReservedAmount

func (k Keeper) ValidateStakingReservedAmount(ctx sdk.Context) error

ValidateStakingReservedAmount checks that the balance of StakingReserveAcc greater than the amount of staked, queued coins in all staking objects.

func (Keeper) WithdrawAllRewards

func (k Keeper) WithdrawAllRewards(ctx sdk.Context, farmerAcc sdk.AccAddress) (sdk.Coins, error)

WithdrawAllRewards withdraws all accumulated rewards for a farmer.

func (Keeper) WithdrawRewards

func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, stakingCoinDenom string) (sdk.Coins, error)

WithdrawRewards withdraws accumulated rewards for a farmer for a given staking coin denom. It decreases outstanding rewards and set the starting epoch of a staking.

type Querier

type Querier struct {
	Keeper
}

Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper.

func (Querier) CurrentEpochDays

CurrentEpochDays queries current epoch days.

func (Querier) Params

Params queries the parameters of the farming module.

func (Querier) Plan

Plan queries a specific plan.

func (Querier) Plans

Plans queries all plans.

func (Querier) Rewards

Rewards queries accumulated rewards for a farmer.

func (Querier) Stakings

Stakings queries stakings for a farmer.

func (Querier) TotalStakings

TotalStakings queries total staking coin amount for a specific staking coin denom.

Jump to

Keyboard shortcuts

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