keeper

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type AvgKeeper

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

func (AvgKeeper) GetCurrentAvg

func (k AvgKeeper) GetCurrentAvg(denom string) (sdk.Dec, error)

type Hooks

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

Hooks defines a structure around the x/oracle Keeper that implements various Hooks interface defined by other modules such as x/leverage.

func (Hooks) AfterRegisteredTokenRemoved

func (h Hooks) AfterRegisteredTokenRemoved(sdk.Context, leveragetypes.Token)

AfterRegisteredTokenRemoved implements the x/leverage Hooks interface. Currently, it performs a no-op, however, we may want to remove tokens from the accept list in the future when they're removed from the x/leverage Token registry.

We don't remove the token from the accept list because it might prove to be useful to still have price data for assets outside of the scope of the x/leverage registry. If assets need to be removed, they can always be purged via param change proposals.

func (Hooks) AfterTokenRegistered

func (h Hooks) AfterTokenRegistered(ctx sdk.Context, token leveragetypes.Token)

AfterTokenRegistered implements the x/leverage Hooks interface. Specifically, it checks if the provided Token should be added to the existing accepted list of assets for the x/oracle module.

type IterateExchangeRateVote

type IterateExchangeRateVote = func(
	voterAddr sdk.ValAddress,
	aggregateVote types.AggregateExchangeRateVote,
) (stop bool)

type IterateFeederDelegationHandler

type IterateFeederDelegationHandler func(delegator sdk.ValAddress, delegate sdk.AccAddress) (stop bool)

type Keeper

type Keeper struct {
	StakingKeeper types.StakingKeeper

	AvgPeriod time.Duration
	AvgShift  time.Duration
	// contains filtered or unexported fields
}

Keeper of the oracle store

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey storetypes.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) AcceptList

func (k Keeper) AcceptList(ctx sdk.Context) (res types.DenomList)

AcceptList returns the denom list that can be activated

func (Keeper) AddHistoricPrice

func (k Keeper) AddHistoricPrice(
	ctx sdk.Context,
	denom string,
	exchangeRate sdk.Dec,
)

AddHistoricPrice adds the historic price of a denom at the current block height.

func (Keeper) AllHistoricPrices

func (k Keeper) AllHistoricPrices(ctx sdk.Context) types.Prices

AllHistoricPrices is a helper function that collects and returns all median prices using the IterateAllHistoricPrices iterator

func (Keeper) AllMedianDeviationPrices

func (k Keeper) AllMedianDeviationPrices(ctx sdk.Context) types.Prices

AllMedianDeviationPrices is a helper function that collects and returns all median prices using the IterateAllMedianDeviationPrices iterator

func (Keeper) AllMedianPrices

func (k Keeper) AllMedianPrices(ctx sdk.Context) types.Prices

AllMedianPrices is a helper function that collects and returns all median prices using the IterateAllMedianPrices iterator

func (Keeper) AverageOfHistoricMedians

func (k Keeper) AverageOfHistoricMedians(
	ctx sdk.Context,
	denom string,
	numStamps uint64,
) (sdk.Dec, uint32, error)

AverageOfHistoricMedians calculates and returns the average of the last stampNum historic medians as well as the amount of medians used to calculate that average. If no medians are available, all returns are zero and error is nil.

func (Keeper) AvgKeeper

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

func (Keeper) CalcAndSetHistoricMedian

func (k Keeper) CalcAndSetHistoricMedian(
	ctx sdk.Context,
	denom string,
) error

CalcAndSetHistoricMedian uses all the historic prices of a given denom to calculate its median price at the current block and set it to the store. It will also call setMedianDeviation with the calculated median.

func (Keeper) ClearExchangeRates

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

func (Keeper) ClearVotes

func (k Keeper) ClearVotes(ctx sdk.Context, votePeriod uint64)

ClearVotes clears all tallied prevotes and votes from the store.

func (Keeper) DeleteAggregateExchangeRatePrevote

func (k Keeper) DeleteAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAddress)

DeleteAggregateExchangeRatePrevote deletes an oracle prevote from the store.

func (Keeper) DeleteAggregateExchangeRateVote

func (k Keeper) DeleteAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddress)

DeleteAggregateExchangeRateVote deletes an oracle prevote from the store.

func (Keeper) DeleteHistoricMedian

func (k Keeper) DeleteHistoricMedian(
	ctx sdk.Context,
	denom string,
	blockNum uint64,
)

DeleteHistoricMedian deletes a given denom's median price at a given block.

func (Keeper) DeleteHistoricMedianDeviation

func (k Keeper) DeleteHistoricMedianDeviation(
	ctx sdk.Context,
	denom string,
	blockNum uint64,
)

DeleteHistoricMedianDeviation deletes a given denom's standard deviation around its median price at a given block.

func (Keeper) DeleteHistoricPrice

func (k Keeper) DeleteHistoricPrice(
	ctx sdk.Context,
	denom string,
	blockNum uint64,
)

DeleteHistoricPrice deletes the historic price of a denom at a given block.

func (Keeper) DeleteMissCounter

func (k Keeper) DeleteMissCounter(ctx sdk.Context, operator sdk.ValAddress)

DeleteMissCounter removes miss counter for the validator.

func (Keeper) GetAggregateExchangeRatePrevote

func (k Keeper) GetAggregateExchangeRatePrevote(
	ctx sdk.Context,
	voter sdk.ValAddress,
) (types.AggregateExchangeRatePrevote, error)

GetAggregateExchangeRatePrevote retrieves an oracle prevote from the store.

func (Keeper) GetAggregateExchangeRateVote

func (k Keeper) GetAggregateExchangeRateVote(
	ctx sdk.Context,
	voter sdk.ValAddress,
) (types.AggregateExchangeRateVote, error)

GetAggregateExchangeRateVote retrieves an oracle prevote from the store.

func (Keeper) GetExchangeRate

func (k Keeper) GetExchangeRate(ctx sdk.Context, symbol string) (sdk.Dec, error)

GetExchangeRate gets the consensus exchange rate of USD denominated in the denom asset from the store.

func (Keeper) GetExchangeRateBase

func (k Keeper) GetExchangeRateBase(ctx sdk.Context, denom string) (sdk.Dec, error)

GetExchangeRateBase gets the consensus exchange rate of an asset in the base denom (e.g. ATOM -> uatom)

func (Keeper) GetFeederDelegation

func (k Keeper) GetFeederDelegation(ctx sdk.Context, vAddr sdk.ValAddress) (sdk.AccAddress, error)

GetFeederDelegation gets the account address to which the validator operator delegated oracle vote rights.

func (Keeper) GetMissCounter

func (k Keeper) GetMissCounter(ctx sdk.Context, operator sdk.ValAddress) uint64

GetMissCounter retrieves the # of vote periods missed in this oracle slash window.

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

func (k Keeper) GetRewardPool(ctx sdk.Context, denom string) sdk.Coin

GetRewardPool retrieves the balance of the oracle module account.

func (Keeper) HasAggregateExchangeRatePrevote

func (k Keeper) HasAggregateExchangeRatePrevote(
	ctx sdk.Context,
	voter sdk.ValAddress,
) bool

HasAggregateExchangeRatePrevote checks if a validator has an existing prevote.

func (Keeper) HistoricAvgPrice

func (k Keeper) HistoricAvgPrice(ctx sdk.Context, denom string) (sdk.Dec, error)

func (Keeper) HistoricMedianDeviation

func (k Keeper) HistoricMedianDeviation(
	ctx sdk.Context,
	denom string,
) (*types.Price, error)

HistoricMedianDeviation returns a given denom's most recently stamped standard deviation around its median price at a given block.

func (Keeper) HistoricMedians

func (k Keeper) HistoricMedians(
	ctx sdk.Context,
	denom string,
	numStamps uint64,
) types.Prices

func (Keeper) HistoricStampPeriod

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

HistoricStampPeriod returns the amount of blocks the oracle module waits before recording a new historic price.

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

Hooks returns a new Hooks instance that wraps the x/oracle keeper.

func (*Keeper) IsPeriodLastBlock

func (k *Keeper) IsPeriodLastBlock(ctx sdk.Context, blocksPerPeriod uint64) bool

IsPeriodLastBlock returns true if we are at the last block of the period

func (Keeper) IterateAggregateExchangeRatePrevotes

func (k Keeper) IterateAggregateExchangeRatePrevotes(
	ctx sdk.Context,
	handler func(sdk.ValAddress, types.AggregateExchangeRatePrevote) bool,
)

IterateAggregateExchangeRatePrevotes iterates rate over prevotes in the store

func (Keeper) IterateAggregateExchangeRateVotes

func (k Keeper) IterateAggregateExchangeRateVotes(
	ctx sdk.Context,
	handler IterateExchangeRateVote,
)

IterateAggregateExchangeRateVotes iterates rate over prevotes in the store.

func (Keeper) IterateAllHistoricPrices

func (k Keeper) IterateAllHistoricPrices(
	ctx sdk.Context,
	handler func(types.Price) bool,
)

IterateAllHistoricPrices iterates over all historic prices. Iterator stops when exhausting the source, or when the handler returns `true`.

func (Keeper) IterateAllMedianDeviationPrices

func (k Keeper) IterateAllMedianDeviationPrices(
	ctx sdk.Context,
	handler func(types.Price) bool,
)

IterateAllMedianDeviationPrices iterates over all median deviation prices. Iterator stops when exhausting the source, or when the handler returns `true`.

func (Keeper) IterateAllMedianPrices

func (k Keeper) IterateAllMedianPrices(
	ctx sdk.Context,
	handler func(types.Price) bool,
)

IterateAllMedianPrices iterates over all median prices. Iterator stops when exhausting the source, or when the handler returns `true`.

func (Keeper) IterateExchangeRates

func (k Keeper) IterateExchangeRates(ctx sdk.Context, handler func(string, sdk.Dec) bool)

IterateExchangeRates iterates over all USD rates in the store.

func (Keeper) IterateFeederDelegations

func (k Keeper) IterateFeederDelegations(ctx sdk.Context, handler IterateFeederDelegationHandler)

IterateFeederDelegations iterates over the feed delegates and performs a callback function.

func (Keeper) IterateHistoricMedians

func (k Keeper) IterateHistoricMedians(
	ctx sdk.Context,
	denom string,
	numStamps uint,
	handler func(types.Price) bool,
)

IterateHistoricMediansSinceBlock iterates over medians of a given denom in the store in reverse. Iterator stops when exhausting the source, or when the handler returns `true`.

func (Keeper) IterateHistoricPrices

func (k Keeper) IterateHistoricPrices(
	ctx sdk.Context,
	denom string,
	numStamps uint,
	handler func(sdk.Dec) bool,
)

IterateHistoricPrices iterates over historic prices of a given denom in the store in reverse. Iterator stops when exhausting the source, or when the handler returns `true`.

func (Keeper) IterateMissCounters

func (k Keeper) IterateMissCounters(ctx sdk.Context, handler func(sdk.ValAddress, uint64) bool)

IterateMissCounters iterates over the miss counters and performs a callback function.

func (Keeper) Logger

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

Logger returns a module-specific logger.

func (Keeper) MaxOfHistoricMedians

func (k Keeper) MaxOfHistoricMedians(
	ctx sdk.Context,
	denom string,
	numStamps uint64,
) (sdk.Dec, uint32, error)

MaxOfHistoricMedian calculates and returns the maximum value of the last stampNum historic medians as well as the amount of medians used to calculate that maximum. If no medians are available, all returns are zero and error is nil.

func (Keeper) MaximumMedianStamps

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

MaximumMedianStamps returns the maximum amount of medians the oracle module will hold.

func (Keeper) MaximumPriceStamps

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

MaximumMedianStamps returns the maximum amount of historic prices the oracle module will hold.

func (Keeper) MedianOfHistoricMedians

func (k Keeper) MedianOfHistoricMedians(
	ctx sdk.Context,
	denom string,
	numStamps uint64,
) (sdk.Dec, uint32, error)

MedianOfHistoricMedians calculates and returns the median of the last stampNum historic medians as well as the amount of medians used to calculate that median. If no medians are available, all returns are zero and error is nil.

func (Keeper) MedianStampPeriod

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

MedianStampPeriod returns the amount blocks the oracle module waits between calculating a new median and standard deviation of that median.

func (Keeper) MinOfHistoricMedians

func (k Keeper) MinOfHistoricMedians(
	ctx sdk.Context,
	denom string,
	numStamps uint64,
) (sdk.Dec, uint32, error)

MinOfHistoricMedians calculates and returns the minimum value of the last stampNum historic medians as well as the amount of medians used to calculate that minimum. If no medians are available, all returns are zero and error is nil.

func (Keeper) MinValidPerWindow

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

MinValidPerWindow returns oracle slashing threshold

func (Keeper) OrganizeBallotByDenom

func (k Keeper) OrganizeBallotByDenom(
	ctx sdk.Context,
	validatorClaimMap map[string]types.Claim,
) []types.BallotDenom

OrganizeBallotByDenom collects all oracle votes for the current vote period, categorized by the votes' denom parameter.

func (*Keeper) PruneAllPrices

func (k *Keeper) PruneAllPrices(ctx sdk.Context)

PruneAllPrices deletes all historic prices, medians, and median deviations outside pruning period determined by the stamp period multiplied by the maximum stamps.

func (Keeper) PruneHistoricPricesBeforeBlock

func (k Keeper) PruneHistoricPricesBeforeBlock(ctx sdk.Context, blockNum uint64)

func (Keeper) PruneMedianDeviationsBeforeBlock

func (k Keeper) PruneMedianDeviationsBeforeBlock(ctx sdk.Context, blockNum uint64)

func (Keeper) PruneMediansBeforeBlock

func (k Keeper) PruneMediansBeforeBlock(ctx sdk.Context, blockNum uint64)

func (Keeper) RewardBallotWinners

func (k Keeper) RewardBallotWinners(
	ctx sdk.Context,
	votePeriod int64,
	rewardDistributionWindow int64,
	voteTargets []string,
	ballotWinners []types.Claim,
)

RewardBallotWinners is executed at the end of every voting period, where we give out a portion of seigniorage reward(reward-weight) to the oracle voters that voted correctly.

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

func (Keeper) RewardDistributionWindow

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

RewardDistributionWindow returns the number of vote periods during which seigniorage reward comes in and then is distributed.

func (Keeper) SetAcceptList

func (k Keeper) SetAcceptList(ctx sdk.Context, acceptList types.DenomList)

SetAcceptList updates the accepted list of assets supported by the x/oracle module.

func (Keeper) SetAggregateExchangeRatePrevote

func (k Keeper) SetAggregateExchangeRatePrevote(
	ctx sdk.Context,
	voter sdk.ValAddress,
	prevote types.AggregateExchangeRatePrevote,
)

SetAggregateExchangeRatePrevote set an oracle aggregate prevote to the store.

func (Keeper) SetAggregateExchangeRateVote

func (k Keeper) SetAggregateExchangeRateVote(
	ctx sdk.Context,
	voter sdk.ValAddress,
	vote types.AggregateExchangeRateVote,
)

SetAggregateExchangeRateVote adds an oracle aggregate prevote to the store.

func (Keeper) SetExchangeRate

func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, exchangeRate sdk.Dec)

SetExchangeRate sets the consensus exchange rate of USD denominated in the denom asset to the store.

func (Keeper) SetExchangeRateWithEvent

func (k Keeper) SetExchangeRateWithEvent(ctx sdk.Context, denom string, exchangeRate sdk.Dec)

SetExchangeRateWithEvent sets an consensus exchange rate to the store with ABCI event

func (Keeper) SetFeederDelegation

func (k Keeper) SetFeederDelegation(ctx sdk.Context, operator sdk.ValAddress, delegatedFeeder sdk.AccAddress)

SetFeederDelegation sets the account address to which the validator operator delegated oracle vote rights.

func (Keeper) SetHistoricMedian

func (k Keeper) SetHistoricMedian(
	ctx sdk.Context,
	denom string,
	blockNum uint64,
	median sdk.Dec,
)

func (Keeper) SetHistoricMedianDeviation

func (k Keeper) SetHistoricMedianDeviation(
	ctx sdk.Context,
	denom string,
	blockNum uint64,
	medianDeviation sdk.Dec,
)

func (Keeper) SetHistoricPrice

func (k Keeper) SetHistoricPrice(
	ctx sdk.Context,
	denom string,
	blockNum uint64,
	exchangeRate sdk.Dec,
)

func (Keeper) SetHistoricStampPeriod

func (k Keeper) SetHistoricStampPeriod(ctx sdk.Context, historicPriceStampPeriod uint64)

SetHistoricStampPeriod updates the amount of blocks the oracle module waits before recording a new historic price.

func (Keeper) SetMaximumMedianStamps

func (k Keeper) SetMaximumMedianStamps(ctx sdk.Context, maximumMedianStamps uint64)

SetMaximumMedianStamps updates the the maximum amount of medians the oracle module will hold.

func (Keeper) SetMaximumPriceStamps

func (k Keeper) SetMaximumPriceStamps(ctx sdk.Context, maximumPriceStamps uint64)

SetMaximumPriceStamps updates the the maximum amount of historic prices the oracle module will hold.

func (Keeper) SetMedianStampPeriod

func (k Keeper) SetMedianStampPeriod(ctx sdk.Context, medianStampPeriod uint64)

SetMedianStampPeriod updates the amount blocks the oracle module waits between calculating a new median and standard deviation of that median.

func (Keeper) SetMissCounter

func (k Keeper) SetMissCounter(ctx sdk.Context, operator sdk.ValAddress, missCounter uint64)

SetMissCounter updates the # of vote periods missed in this oracle slash window.

func (Keeper) SetParams

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

SetParams sets the total set of oracle parameters.

func (Keeper) SetVoteThreshold

func (k Keeper) SetVoteThreshold(ctx sdk.Context, threshold sdk.Dec) error

SetVoteThreshold sets min combined validator power voting on a denom to accept it as valid. TODO: this is used in tests, we should refactor the way how this is handled.

func (Keeper) SlashAndResetMissCounters

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

SlashAndResetMissCounters iterates over all the current missed counters and calculates the "valid vote rate" as: (votePeriodsPerWindow - missCounter)/votePeriodsPerWindow.

If the valid vote rate is below the minValidPerWindow, the validator will be slashed and jailed.

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

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

ValidateFeeder returns error if the given feeder is not allowed to feed the message.

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 portion of combined validator power of votes that must be received for a ballot to pass.

func (Keeper) WithinHistoricMedianDeviation

func (k Keeper) WithinHistoricMedianDeviation(
	ctx sdk.Context,
	denom string,
) (bool, error)

WithinHistoricMedianDeviation returns whether or not the current price of a given denom is within the latest stamped Standard Deviation around the Median.

type Migrator

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

Migrator is a struct for handling in-place store migrations.

func NewMigrator

func NewMigrator(keeper *Keeper) Migrator

NewMigrator creates a Migrator.

func (Migrator) HistoracleParams3x4

func (m Migrator) HistoracleParams3x4(ctx sdk.Context) error

HistoracleParams3x4 updates Historic Params to defaults for the v4.0 upgrade

func (Migrator) Migrate1to2

func (m Migrator) Migrate1to2(ctx sdk.Context) error

Migrate1to2 migrates from version 1 to 2.

func (Migrator) MigrateBNB

func (m Migrator) MigrateBNB(ctx sdk.Context)

MigrateBNB fixes the BNB base denom for the 4.1 upgrade without using leverage hooks

Jump to

Keyboard shortcuts

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