Documentation
¶
Overview ¶
nolint
Index ¶
- Variables
- func AllocateRewards(t *testing.T, input TestFixture, rewards sdk.Coins, votePeriods uint64)
- func FundAccount(input TestFixture, addr sdk.AccAddress, amounts sdk.Coins) error
- func MakeAggregatePrevoteAndVote(t *testing.T, input TestFixture, msgServer types.MsgServer, height int64, ...)
- func MakeEncodingConfig(_ *testing.T) testutil.TestEncodingConfig
- func MakeTestCodec(t *testing.T) codec.Codec
- func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdkmath.Int) *stakingtypes.MsgCreateValidator
- func Tally(votes types.ExchangeRateVotes, rewardBand sdkmath.LegacyDec, ...) sdkmath.LegacyDec
- type Hooks
- type Keeper
- func (k Keeper) Actives(c context.Context, _ *types.QueryActivesRequest) (*types.QueryActivesResponse, error)
- func (k Keeper) AggregateExchangeRatePrevote(goCtx context.Context, msg *types.MsgAggregateExchangeRatePrevote) (*types.MsgAggregateExchangeRatePrevoteResponse, error)
- func (k Keeper) AggregateExchangeRateVote(goCtx context.Context, msg *types.MsgAggregateExchangeRateVote) (msgResp *types.MsgAggregateExchangeRateVoteResponse, err error)
- func (k Keeper) AggregatePrevote(c context.Context, req *types.QueryAggregatePrevoteRequest) (*types.QueryAggregatePrevoteResponse, error)
- func (k Keeper) AggregatePrevotes(c context.Context, _ *types.QueryAggregatePrevotesRequest) (*types.QueryAggregatePrevotesResponse, error)
- func (k Keeper) AggregateVote(c context.Context, req *types.QueryAggregateVoteRequest) (*types.QueryAggregateVoteResponse, error)
- func (k Keeper) AggregateVotes(c context.Context, _ *types.QueryAggregateVotesRequest) (*types.QueryAggregateVotesResponse, error)
- func (k Keeper) AllocateRewards(ctx sdk.Context, funderModule string, totalCoins sdk.Coins, votePeriods uint64) error
- func (k Keeper) DelegateFeedConsent(goCtx context.Context, msg *types.MsgDelegateFeedConsent) (*types.MsgDelegateFeedConsentResponse, error)
- func (k Keeper) EditOracleParams(goCtx context.Context, msg *types.MsgEditOracleParams) (*types.MsgEditOracleParamsResponse, error)
- func (k Keeper) ExchangeRate(c context.Context, req *types.QueryExchangeRateRequest) (*types.QueryExchangeRateResponse, error)
- func (k Keeper) ExchangeRateTwap(c context.Context, req *types.QueryExchangeRateRequest) (response *types.QueryExchangeRateResponse, err error)
- func (k Keeper) ExchangeRates(c context.Context, _ *types.QueryExchangeRatesRequest) (*types.QueryExchangeRatesResponse, error)
- func (k Keeper) FeederDelegation(c context.Context, req *types.QueryFeederDelegationRequest) (*types.QueryFeederDelegationResponse, error)
- func (k Keeper) GatherRewardsForVotePeriod(ctx sdk.Context) sdk.Coins
- func (k Keeper) GetExchangeRateTwap(ctx sdk.Context, pair asset.Pair) (price sdkmath.LegacyDec, err error)
- func (k Keeper) GetWhitelistedPairs(ctx sdk.Context) []asset.Pair
- func (k Keeper) Hooks() Hooks
- func (k Keeper) IsWhitelistedPair(ctx sdk.Context, pair asset.Pair) bool
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) MinValidPerWindow(ctx sdk.Context) (res sdkmath.LegacyDec)
- func (k Keeper) MinVoters(ctx sdk.Context) (res uint64)
- func (k Keeper) MissCounter(c context.Context, req *types.QueryMissCounterRequest) (*types.QueryMissCounterResponse, error)
- func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
- func (k Keeper) RewardBand(ctx sdk.Context) (res sdkmath.LegacyDec)
- func (k Keeper) SetPrice(ctx sdk.Context, pair asset.Pair, price sdkmath.LegacyDec)
- func (k Keeper) SlashAndResetMissCounters(ctx sdk.Context)
- func (k Keeper) SlashFraction(ctx sdk.Context) (res sdkmath.LegacyDec)
- func (k Keeper) SlashWindow(ctx sdk.Context) (res uint64)
- func (k Keeper) UpdateExchangeRates(ctx sdk.Context) types.ValidatorPerformances
- func (k Keeper) UpdateParams(ctx sdk.Context, params types.Params)
- func (k Keeper) ValidateFeeder(ctx sdk.Context, feederAddr sdk.AccAddress, validatorAddr sdk.ValAddress) error
- func (k Keeper) VotePeriod(ctx sdk.Context) (res uint64)
- func (k Keeper) VoteTargets(c context.Context, _ *types.QueryVoteTargetsRequest) (*types.QueryVoteTargetsResponse, error)
- func (k Keeper) VoteThreshold(ctx sdk.Context) (res sdkmath.LegacyDec)
- func (k Keeper) Whitelist(ctx sdk.Context) (res []asset.Pair)
- type TestFixture
Constants ¶
This section is empty.
Variables ¶
var ( ValPubKeys = sims.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(denoms.NIBI, InitTokens)) OracleDecPrecision = 8 )
Test addresses
var ModuleBasics = module.NewBasicManager( auth.AppModuleBasic{}, bank.AppModuleBasic{}, distr.AppModuleBasic{}, staking.AppModuleBasic{}, params.AppModuleBasic{}, sudomodule.AppModuleBasic{}, )
ModuleBasics nolint
Functions ¶
func AllocateRewards ¶
func FundAccount ¶
func FundAccount(input TestFixture, 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 MakeAggregatePrevoteAndVote ¶
func MakeAggregatePrevoteAndVote( t *testing.T, input TestFixture, msgServer types.MsgServer, height int64, rates types.ExchangeRateTuples, valIdx int, )
func MakeEncodingConfig ¶
func MakeEncodingConfig(_ *testing.T) testutil.TestEncodingConfig
MakeEncodingConfig nolint
func NewTestMsgCreateValidator ¶
func NewTestMsgCreateValidator( address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdkmath.Int, ) *stakingtypes.MsgCreateValidator
NewTestMsgCreateValidator test msg creator
func Tally ¶
func Tally( votes types.ExchangeRateVotes, rewardBand sdkmath.LegacyDec, validatorPerformances types.ValidatorPerformances, ) sdkmath.LegacyDec
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 validatorPerformances slice based on the votes made by the validators.
Types ¶
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
func NewHooks ¶
func NewHooks(k Keeper, accountKeeper keeper.AccountKeeper, bankKeeper bankkeeper.Keeper) *Hooks
func (Hooks) AfterEpochEnd ¶
type Keeper ¶
type Keeper struct {
AccountKeeper types.AccountKeeper
StakingKeeper types.StakingKeeper
// Module parameters
ModuleParams collections.Item[types.Params]
ExchangeRateMap collections.Map[asset.Pair, types.ExchangeRateAtBlock]
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 asset.Pair of the snapshot and the creation timestamp as keys.Uint64Key.
PriceSnapshots collections.Map[
collections.Pair[asset.Pair, time.Time],
types.PriceSnapshot]
WhitelistedPairs collections.KeySet[asset.Pair]
Rewards collections.Map[uint64, types.Rewards]
RewardsID collections.Sequence
// contains filtered or unexported fields
}
Keeper of the oracle store
func NewKeeper ¶
func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, distrKeeper types.DistributionKeeper, stakingKeeper types.StakingKeeper, slashingKeeper types.SlashingKeeper, sudoKeeper types.SudoKeeper, distrName string, ) Keeper
NewKeeper constructs a new keeper for oracle
func (Keeper) Actives ¶ added in v2.8.0
func (k Keeper) Actives(c context.Context, _ *types.QueryActivesRequest) (*types.QueryActivesResponse, error)
Actives queries all pairs for which exchange rates exist
func (Keeper) AggregateExchangeRatePrevote ¶ added in v2.8.0
func (k Keeper) AggregateExchangeRatePrevote( goCtx context.Context, msg *types.MsgAggregateExchangeRatePrevote, ) (*types.MsgAggregateExchangeRatePrevoteResponse, error)
func (Keeper) AggregateExchangeRateVote ¶ added in v2.8.0
func (k Keeper) AggregateExchangeRateVote( goCtx context.Context, msg *types.MsgAggregateExchangeRateVote, ) (msgResp *types.MsgAggregateExchangeRateVoteResponse, err error)
func (Keeper) AggregatePrevote ¶ added in v2.8.0
func (k Keeper) AggregatePrevote( c context.Context, req *types.QueryAggregatePrevoteRequest, ) (*types.QueryAggregatePrevoteResponse, error)
AggregatePrevote queries an aggregate prevote of a validator
func (Keeper) AggregatePrevotes ¶ added in v2.8.0
func (k Keeper) AggregatePrevotes( c context.Context, _ *types.QueryAggregatePrevotesRequest, ) (*types.QueryAggregatePrevotesResponse, error)
AggregatePrevotes queries aggregate prevotes of all validators
func (Keeper) AggregateVote ¶ added in v2.8.0
func (k Keeper) AggregateVote( c context.Context, req *types.QueryAggregateVoteRequest, ) (*types.QueryAggregateVoteResponse, error)
AggregateVote queries an aggregate vote of a validator
func (Keeper) AggregateVotes ¶ added in v2.8.0
func (k Keeper) AggregateVotes( c context.Context, _ *types.QueryAggregateVotesRequest, ) (*types.QueryAggregateVotesResponse, error)
AggregateVotes queries aggregate votes of all validators
func (Keeper) AllocateRewards ¶
func (Keeper) DelegateFeedConsent ¶ added in v2.8.0
func (k Keeper) DelegateFeedConsent( goCtx context.Context, msg *types.MsgDelegateFeedConsent, ) (*types.MsgDelegateFeedConsentResponse, error)
func (Keeper) EditOracleParams ¶ added in v2.8.0
func (k Keeper) EditOracleParams(goCtx context.Context, msg *types.MsgEditOracleParams) (*types.MsgEditOracleParamsResponse, error)
EditOracleParams: gRPC tx msg for editing the oracle module params. [SUDO] Only callable by sudoers.
func (Keeper) ExchangeRate ¶ added in v2.8.0
func (k Keeper) ExchangeRate(c context.Context, req *types.QueryExchangeRateRequest) (*types.QueryExchangeRateResponse, error)
ExchangeRate queries exchange rate of a pair
func (Keeper) ExchangeRateTwap ¶ added in v2.8.0
func (k Keeper) ExchangeRateTwap(c context.Context, req *types.QueryExchangeRateRequest) (response *types.QueryExchangeRateResponse, err error)
Gets the time-weighted average price from ( ctx.BlockTime() - interval, ctx.BlockTime() ] Note the open-ended right bracket.
If there's only one snapshot, then this function returns the price from that single snapshot.
Returns -1 if there's no price.
func (Keeper) ExchangeRates ¶
func (k Keeper) ExchangeRates(c context.Context, _ *types.QueryExchangeRatesRequest) (*types.QueryExchangeRatesResponse, error)
ExchangeRates queries exchange rates of all pairs
func (Keeper) FeederDelegation ¶ added in v2.8.0
func (k Keeper) FeederDelegation(c context.Context, req *types.QueryFeederDelegationRequest) (*types.QueryFeederDelegationResponse, error)
FeederDelegation queries the account address that the validator operator delegated oracle vote rights to
func (Keeper) GatherRewardsForVotePeriod ¶
GatherRewardsForVotePeriod retrieves the pair rewards for the provided pair and current vote period.
func (Keeper) GetExchangeRateTwap ¶
func (Keeper) GetWhitelistedPairs ¶
GetWhitelistedPairs returns the whitelisted pairs list on current vote period
func (Keeper) IsWhitelistedPair ¶
IsWhitelistedPair returns existence of a pair in the voting target list
func (Keeper) MinValidPerWindow ¶
MinValidPerWindow returns oracle slashing threshold
func (Keeper) MinVoters ¶
MinVoters returns the minimum number of voters that must participate for a vote to pass.
func (Keeper) MissCounter ¶ added in v2.8.0
func (k Keeper) MissCounter( c context.Context, req *types.QueryMissCounterRequest, ) (*types.QueryMissCounterResponse, error)
MissCounter queries oracle miss counter of a validator
func (Keeper) Params ¶
func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
Params queries params of distribution module
func (Keeper) RewardBand ¶
RewardBand returns a maximum divergence that a price vote can have from the weighted median in the votes. If a vote lies within the valid range defined by:
μ := weightedMedian, validRange := μ ± (μ * rewardBand / 2),
then rewards are added to the validator performance. Note that if the reward band is smaller than 1 standard deviation, the band is taken to be 1 standard deviation.
func (Keeper) SlashAndResetMissCounters ¶
SlashAndResetMissCounters do slash any operator who over criteria & clear all operators miss counter to zero
func (Keeper) SlashFraction ¶
SlashFraction returns oracle voting penalty rate
func (Keeper) SlashWindow ¶
SlashWindow returns the number of voting periods that specify a "slash window". After each slash window, all oracles that have missed more than the penalty threshold are slashed. Missing the penalty threshold is synonymous with submitting fewer valid votes than `MinValidPerWindow`.
func (Keeper) UpdateExchangeRates ¶
func (k Keeper) UpdateExchangeRates(ctx sdk.Context) types.ValidatorPerformances
UpdateExchangeRates updates the ExchangeRates, this is supposed to be executed on EndBlock.
func (Keeper) UpdateParams ¶
UpdateParams updates the oracle parameters
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 ¶
VotePeriod returns the number of blocks during which voting takes place.
func (Keeper) VoteTargets ¶ added in v2.8.0
func (k Keeper) VoteTargets(c context.Context, _ *types.QueryVoteTargetsRequest) (*types.QueryVoteTargetsResponse, error)
VoteTargets queries the voting target list on current vote period
func (Keeper) VoteThreshold ¶
VoteThreshold returns the minimum percentage of votes that must be received for a votes to pass.
type TestFixture ¶
type TestFixture struct {
Ctx sdk.Context
Cdc *codec.LegacyAmino
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
OracleKeeper Keeper
StakingKeeper stakingkeeper.Keeper
DistrKeeper distrkeeper.Keeper
SudoKeeper sudokeeper.Keeper
}
TestFixture nolint
func CreateTestFixture ¶
func CreateTestFixture(t *testing.T) TestFixture
CreateTestFixture nolint Creates a base app, with 5 accounts,