keeper

package
v0.18.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Overview

nolint

Index

Constants

This section is empty.

Variables

View Source
var (
	ValPubKeys = simapp.CreateTestPubKeys(5)

	Addrs = []sdk.AccAddress{
		sdk.AccAddress(pubKeys[0].Address()),
		sdk.AccAddress(pubKeys[1].Address()),
		sdk.AccAddress(pubKeys[2].Address()),
		sdk.AccAddress(pubKeys[3].Address()),
		sdk.AccAddress(pubKeys[4].Address()),
	}

	ValAddrs = []sdk.ValAddress{
		sdk.ValAddress(pubKeys[0].Address()),
		sdk.ValAddress(pubKeys[1].Address()),
		sdk.ValAddress(pubKeys[2].Address()),
		sdk.ValAddress(pubKeys[3].Address()),
		sdk.ValAddress(pubKeys[4].Address()),
	}

	InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
	InitCoins  = sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, InitTokens))

	OracleDecPrecision = 8
)

Test addresses

ModuleBasics nolint

Functions

func AllocateRewards added in v0.15.0

func AllocateRewards(t *testing.T, input TestInput, pair common.AssetPair, rewards sdk.Coins, votePeriods uint64)

func FundAccount

func FundAccount(input TestInput, addr sdk.AccAddress, amounts sdk.Coins) error

FundAccount is a utility function that funds an account by minting and sending the coins to the address. This should be used for testing purposes only!

func MakeEncodingConfig

func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig

MakeEncodingConfig nolint

func MakeTestCodec

func MakeTestCodec(t *testing.T) codec.Codec

MakeTestCodec nolint

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

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

func NewQuerier

func NewQuerier(keeper Keeper) types.QueryServer

NewQuerier returns an implementation of the oracle QueryServer interface for the provided Keeper.

func NewTestMsgCreateValidator

func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator

NewTestMsgCreateValidator test msg creator

func Tally added in v0.14.0

func Tally(ballots types.ExchangeRateBallots, rewardBand sdk.Dec, validatorPerformanceMap map[string]types.ValidatorPerformance) sdk.Dec

Tally calculates the median and returns it. Sets the set of voters to be rewarded, i.e. voted within a reasonable spread from the weighted median to the store

ALERT: This function mutates validatorPerformanceMap slice based on the votes made by the validators.

Types

type Keeper

type Keeper struct {
	StakingKeeper types.StakingKeeper

	ExchangeRates     collections.Map[common.AssetPair, sdk.Dec]
	FeederDelegations collections.Map[sdk.ValAddress, sdk.AccAddress]
	MissCounters      collections.Map[sdk.ValAddress, uint64]
	Prevotes          collections.Map[sdk.ValAddress, types.AggregateExchangeRatePrevote]
	Votes             collections.Map[sdk.ValAddress, types.AggregateExchangeRateVote]

	// PriceSnapshots maps types.PriceSnapshot to the common.AssetPair of the snapshot and the creation timestamp as keys.Uint64Key.
	PriceSnapshots   collections.Map[collections.Pair[common.AssetPair, time.Time], types.PriceSnapshot]
	WhitelistedPairs collections.KeySet[common.AssetPair]
	PairRewards      collections.IndexedMap[uint64, types.PairReward, PairRewardsIndexes]
	PairRewardsID    collections.Sequence
	// contains filtered or unexported fields
}

Keeper of the oracle store

func NewKeeper

func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey,
	paramspace paramstypes.Subspace, accountKeeper types.AccountKeeper,
	bankKeeper types.BankKeeper, distrKeeper types.DistributionKeeper,
	stakingKeeper types.StakingKeeper, distrName string) Keeper

NewKeeper constructs a new keeper for oracle

func (Keeper) AllocatePairRewards added in v0.15.0

func (k Keeper) AllocatePairRewards(ctx sdk.Context, funderModule string, pair common.AssetPair, totalCoins sdk.Coins, votePeriods uint64) error

func (Keeper) GatherRewardsForVotePeriod added in v0.19.0

func (k Keeper) GatherRewardsForVotePeriod(ctx sdk.Context, pair common.AssetPair) sdk.Coins

GatherRewardsForVotePeriod retrieves the pair rewards for the provided pair and current vote period.

func (Keeper) GetExchangeRate

func (k Keeper) GetExchangeRate(ctx sdk.Context, pair common.AssetPair) (price sdk.Dec, err error)

func (Keeper) GetExchangeRateTwap added in v0.17.0

func (k Keeper) GetExchangeRateTwap(ctx sdk.Context, pair common.AssetPair) (price sdk.Dec, err error)

func (Keeper) GetOracleAccount

func (k Keeper) GetOracleAccount(ctx sdk.Context) authtypes.ModuleAccountI

GetOracleAccount returns oracle ModuleAccount

func (Keeper) GetParams

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

GetParams returns the total set of oracle parameters.

func (Keeper) GetWhitelistedPairs added in v0.16.1

func (k Keeper) GetWhitelistedPairs(ctx sdk.Context) []common.AssetPair

GetWhitelistedPairs returns the whitelisted pairs list on current vote period

func (Keeper) IsWhitelistedPair added in v0.16.1

func (k Keeper) IsWhitelistedPair(ctx sdk.Context, pair common.AssetPair) bool

IsWhitelistedPair returns existence of a pair in the voting target list

func (Keeper) Logger

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

Logger returns a module-specific logger.

func (Keeper) MinValidPerWindow

func (k Keeper) MinValidPerWindow(ctx sdk.Context) (res sdk.Dec)

MinValidPerWindow returns oracle slashing threshold

func (Keeper) RemoveInvalidBallots added in v0.16.1

func (k Keeper) RemoveInvalidBallots(
	ctx sdk.Context,
	pairBallotsMap map[common.AssetPair]types.ExchangeRateBallots,
) (map[common.AssetPair]types.ExchangeRateBallots, map[common.AssetPair]struct{})

RemoveInvalidBallots removes the ballots which have not reached the vote threshold or which are not part of the whitelisted pairs anymore: example when params change during a vote period but some votes were already made.

ALERT: This function mutates pairBallotMap slice, it removes the ballot for the pair which is not passing the threshold or which is not whitelisted anymore.

func (Keeper) RewardBand

func (k Keeper) RewardBand(ctx sdk.Context) (res sdk.Dec)

RewardBand returns the ratio of allowable exchange rate error that a validator can be rewared

func (Keeper) SetParams

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

SetParams sets the total set of oracle parameters.

func (Keeper) SetPrice added in v0.17.0

func (k Keeper) SetPrice(ctx sdk.Context, pair common.AssetPair, price sdk.Dec)

SetPrice sets the price for a pair as well as the price snapshot.

func (Keeper) SetWhitelist

func (k Keeper) SetWhitelist(ctx sdk.Context, whitelist []common.AssetPair)

SetWhitelist store new whitelist to param store this function is only for test purpose

func (Keeper) SlashAndResetMissCounters

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

SlashAndResetMissCounters do slash any operator who over criteria & clear all operators miss counter to zero

func (Keeper) SlashFraction

func (k Keeper) SlashFraction(ctx sdk.Context) (res sdk.Dec)

SlashFraction returns oracle voting penalty rate

func (Keeper) SlashWindow

func (k Keeper) SlashWindow(ctx sdk.Context) (res uint64)

SlashWindow returns # of vote period for oracle slashing

func (Keeper) UpdateExchangeRates added in v0.14.0

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

UpdateExchangeRates updates the ExchangeRates, this is supposed to be executed on EndBlock.

func (Keeper) ValidateFeeder

func (k Keeper) ValidateFeeder(ctx sdk.Context, feederAddr sdk.AccAddress, validatorAddr sdk.ValAddress) error

ValidateFeeder return the given feeder is allowed to feed the message or not

func (Keeper) VotePeriod

func (k Keeper) VotePeriod(ctx sdk.Context) (res uint64)

VotePeriod returns the number of blocks during which voting takes place.

func (Keeper) VoteThreshold

func (k Keeper) VoteThreshold(ctx sdk.Context) (res sdk.Dec)

VoteThreshold returns the minimum percentage of votes that must be received for a ballot to pass.

func (Keeper) Whitelist

func (k Keeper) Whitelist(ctx sdk.Context) (res []common.AssetPair)

Whitelist returns the pair list that can be activated

type PairRewardsIndexes added in v0.15.0

type PairRewardsIndexes struct {
	// RewardsByPair is the index that maps rewards associated with specific pairs.
	RewardsByPair collections.MultiIndex[common.AssetPair, uint64, types.PairReward]
}

func (PairRewardsIndexes) IndexerList added in v0.15.0

type TestInput

type TestInput struct {
	Ctx           sdk.Context
	Cdc           *codec.LegacyAmino
	AccountKeeper authkeeper.AccountKeeper
	BankKeeper    bankkeeper.Keeper
	OracleKeeper  Keeper
	StakingKeeper stakingkeeper.Keeper
	DistrKeeper   distrkeeper.Keeper
}

TestInput nolint

func CreateTestInput

func CreateTestInput(t *testing.T) TestInput

CreateTestInput nolint Creates a base app, with 5 accounts,

Jump to

Keyboard shortcuts

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