Documentation ¶
Overview ¶
nolint
Index ¶
- Variables
- func AllocateRewards(t *testing.T, input TestInput, pair string, rewards sdk.Coins, ...)
- func FundAccount(input TestInput, addr sdk.AccAddress, amounts sdk.Coins) error
- func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig
- func MakeTestCodec(t *testing.T) codec.Codec
- func NewMsgServerImpl(keeper Keeper) types.MsgServer
- func NewQuerier(keeper Keeper) types.QueryServer
- func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator
- func RemoveInvalidBallots(ctx sdk.Context, k Keeper, voteTargets map[string]struct{}, ...)
- func Tally(_ sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec, ...) (weightedMedian sdk.Dec)
- type Keeper
- func (k Keeper) AccrueVotePeriodPairRewards(ctx sdk.Context, pair string) sdk.Coins
- func (k Keeper) AllocatePairRewards(ctx sdk.Context, funderModule string, pair string, totalCoins sdk.Coins, ...) error
- func (k Keeper) ApplyWhitelist(ctx sdk.Context, whitelist types.PairList, voteTargets map[string]struct{})
- func (k Keeper) ClearBallots(ctx sdk.Context, votePeriod uint64)
- func (k Keeper) ClearExchangeRates(ctx sdk.Context)
- func (k Keeper) ClearPairs(ctx sdk.Context)
- func (k Keeper) CreatePairReward(ctx sdk.Context, rewards *types.PairReward)
- func (k Keeper) DeleteAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAddress)
- func (k Keeper) DeleteAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddress)
- func (k Keeper) DeleteExchangeRate(ctx sdk.Context, pair string)
- func (k Keeper) DeleteMissCounter(ctx sdk.Context, operator sdk.ValAddress)
- func (k Keeper) DeletePairReward(ctx sdk.Context, pair string, id uint64) error
- func (k Keeper) GetAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAddress) (aggregatePrevote types.AggregateExchangeRatePrevote, err error)
- func (k Keeper) GetAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddress) (aggregateVote types.AggregateExchangeRateVote, err error)
- func (k Keeper) GetExchangeRate(ctx sdk.Context, pair string) (sdk.Dec, error)
- func (k Keeper) GetFeederDelegation(ctx sdk.Context, operator sdk.ValAddress) sdk.AccAddress
- func (k Keeper) GetMissCounter(ctx sdk.Context, operator sdk.ValAddress) uint64
- func (k Keeper) GetOracleAccount(ctx sdk.Context) authtypes.ModuleAccountI
- func (k Keeper) GetPairReward(ctx sdk.Context, pair string, id uint64) (*types.PairReward, error)
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetVoteTargets(ctx sdk.Context) (voteTargets []string)
- func (k Keeper) IsVoteTarget(ctx sdk.Context, pair string) bool
- func (k Keeper) IterateAggregateExchangeRatePrevotes(ctx sdk.Context, ...)
- func (k Keeper) IterateAggregateExchangeRateVotes(ctx sdk.Context, ...)
- func (k Keeper) IterateAllPairRewards(ctx sdk.Context, do func(rewards *types.PairReward) (stop bool))
- func (k Keeper) IterateExchangeRates(ctx sdk.Context, handler func(pair string, exchangeRate sdk.Dec) (stop bool))
- func (k Keeper) IterateFeederDelegations(ctx sdk.Context, ...)
- func (k Keeper) IterateMissCounters(ctx sdk.Context, ...)
- func (k Keeper) IteratePairRewards(ctx sdk.Context, pair string, do func(rewards *types.PairReward) (stop bool))
- func (k Keeper) IteratePairs(ctx sdk.Context, handler func(pair string) (stop bool))
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) MinValidPerWindow(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) NextPairRewardKey(ctx sdk.Context) uint64
- func (k Keeper) OrganizeBallotByPair(ctx sdk.Context, validatorsPerformance map[string]types.ValidatorPerformance) (ballots map[string]types.ExchangeRateBallot)
- func (k Keeper) PairExists(ctx sdk.Context, pair string) bool
- func (k Keeper) RewardBallotWinners(ctx sdk.Context, voteTargets map[string]struct{}, ...)
- func (k Keeper) RewardBand(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) SetAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAddress, ...)
- func (k Keeper) SetAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddress, vote types.AggregateExchangeRateVote)
- func (k Keeper) SetExchangeRate(ctx sdk.Context, pair string, exchangeRate sdk.Dec)
- func (k Keeper) SetExchangeRateWithEvent(ctx sdk.Context, pair string, exchangeRate sdk.Dec)
- func (k Keeper) SetFeederDelegation(ctx sdk.Context, operator sdk.ValAddress, delegatedFeeder sdk.AccAddress)
- func (k Keeper) SetMissCounter(ctx sdk.Context, operator sdk.ValAddress, missCounter uint64)
- func (k Keeper) SetPair(ctx sdk.Context, pair string)
- func (k Keeper) SetPairReward(ctx sdk.Context, rewards *types.PairReward)
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SetWhitelist(ctx sdk.Context, whitelist types.PairList)
- func (k Keeper) SlashAndResetMissCounters(ctx sdk.Context)
- func (k Keeper) SlashFraction(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) SlashWindow(ctx sdk.Context) (res uint64)
- func (k Keeper) UpdateExchangeRates(ctx sdk.Context)
- 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) VoteThreshold(ctx sdk.Context) (res sdk.Dec)
- func (k Keeper) Whitelist(ctx sdk.Context) (res types.PairList)
- type TestInput
Constants ¶
This section is empty.
Variables ¶
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
var ModuleBasics = module.NewBasicManager( auth.AppModuleBasic{}, bank.AppModuleBasic{}, distr.AppModuleBasic{}, staking.AppModuleBasic{}, params.AppModuleBasic{}, )
ModuleBasics nolint
Functions ¶
func AllocateRewards ¶ added in v0.15.0
func FundAccount ¶
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 NewMsgServerImpl ¶
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 RemoveInvalidBallots ¶ added in v0.15.0
func RemoveInvalidBallots(ctx sdk.Context, k Keeper, voteTargets map[string]struct{}, voteMap map[string]types.ExchangeRateBallot)
RemoveInvalidBallots removes the ballots which have not reached the vote threshold or which are not part of the vote targets anymore: example when params change during a vote period but some votes were already made.
func Tally ¶ added in v0.14.0
func Tally(_ sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec, validatorClaimMap map[string]types.ValidatorPerformance) (weightedMedian 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 CONTRACT: pb must be sorted
Types ¶
type Keeper ¶
type Keeper struct { StakingKeeper types.StakingKeeper // 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) AccrueVotePeriodPairRewards ¶ added in v0.15.0
AccrueVotePeriodPairRewards retrieves the vote period rewards for the provided pair. And decreases the distribution period count of each pair reward instance. If the distribution period count drops to 0: the reward instance is removed. TODO(mercilex): don't like API name
func (Keeper) AllocatePairRewards ¶ added in v0.15.0
func (Keeper) ApplyWhitelist ¶
func (k Keeper) ApplyWhitelist(ctx sdk.Context, whitelist types.PairList, voteTargets map[string]struct{})
ApplyWhitelist updates the whitelist by detecting possible changes between the current vote targets and the current updated whitelist.
func (Keeper) ClearBallots ¶
ClearBallots clears all tallied prevotes and votes from the store
func (Keeper) ClearExchangeRates ¶ added in v0.14.0
ClearExchangeRates iterates over all exchange rates and clears them.
func (Keeper) ClearPairs ¶
ClearPairs clears tobin taxes
func (Keeper) CreatePairReward ¶
func (k Keeper) CreatePairReward(ctx sdk.Context, rewards *types.PairReward)
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) DeleteExchangeRate ¶
DeleteExchangeRate deletes the consensus exchange rate of the provided pair from the store.
func (Keeper) DeleteMissCounter ¶
func (k Keeper) DeleteMissCounter(ctx sdk.Context, operator sdk.ValAddress)
DeleteMissCounter removes miss counter for the validator
func (Keeper) DeletePairReward ¶
func (Keeper) GetAggregateExchangeRatePrevote ¶
func (k Keeper) GetAggregateExchangeRatePrevote(ctx sdk.Context, voter sdk.ValAddress) (aggregatePrevote types.AggregateExchangeRatePrevote, err error)
GetAggregateExchangeRatePrevote retrieves an oracle prevote from the store
func (Keeper) GetAggregateExchangeRateVote ¶
func (k Keeper) GetAggregateExchangeRateVote(ctx sdk.Context, voter sdk.ValAddress) (aggregateVote types.AggregateExchangeRateVote, err error)
GetAggregateExchangeRateVote retrieves an oracle prevote from the store
func (Keeper) GetExchangeRate ¶
GetExchangeRate gets the consensus exchange rate of the given pair from the store.
func (Keeper) GetFeederDelegation ¶
func (k Keeper) GetFeederDelegation(ctx sdk.Context, operator sdk.ValAddress) sdk.AccAddress
GetFeederDelegation gets the account address that the validator operator delegated oracle vote rights to
func (Keeper) GetMissCounter ¶
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) GetPairReward ¶
func (Keeper) GetVoteTargets ¶
GetVoteTargets returns the voting target list on current vote period
func (Keeper) IsVoteTarget ¶
IsVoteTarget returns existence of a pair in the voting target list
func (Keeper) IterateAggregateExchangeRatePrevotes ¶
func (k Keeper) IterateAggregateExchangeRatePrevotes(ctx sdk.Context, handler func(voterAddr sdk.ValAddress, aggregatePrevote types.AggregateExchangeRatePrevote) (stop bool))
IterateAggregateExchangeRatePrevotes iterates rate over prevotes in the store
func (Keeper) IterateAggregateExchangeRateVotes ¶
func (k Keeper) IterateAggregateExchangeRateVotes(ctx sdk.Context, handler func(voterAddr sdk.ValAddress, aggregateVote types.AggregateExchangeRateVote) (stop bool))
IterateAggregateExchangeRateVotes iterates rate over prevotes in the store
func (Keeper) IterateAllPairRewards ¶
func (Keeper) IterateExchangeRates ¶
func (k Keeper) IterateExchangeRates(ctx sdk.Context, handler func(pair string, exchangeRate sdk.Dec) (stop bool))
IterateExchangeRates iterates over pair's exchange rates
func (Keeper) IterateFeederDelegations ¶
func (k Keeper) IterateFeederDelegations(ctx sdk.Context, handler func(delegator sdk.ValAddress, delegate sdk.AccAddress) (stop bool))
IterateFeederDelegations iterates over the feed delegates and performs a callback function.
func (Keeper) IterateMissCounters ¶
func (k Keeper) IterateMissCounters(ctx sdk.Context, handler func(operator sdk.ValAddress, missCounter uint64) (stop bool))
IterateMissCounters iterates over the miss counters and performs a callback function.
func (Keeper) IteratePairRewards ¶
func (Keeper) IteratePairs ¶
IteratePairs iterates rate over tobin taxes in the store
func (Keeper) MinValidPerWindow ¶
MinValidPerWindow returns oracle slashing threshold
func (Keeper) OrganizeBallotByPair ¶
func (k Keeper) OrganizeBallotByPair(ctx sdk.Context, validatorsPerformance map[string]types.ValidatorPerformance) (ballots map[string]types.ExchangeRateBallot)
OrganizeBallotByPair collects all oracle votes for the period, categorized by the votes' pair parameter
func (Keeper) PairExists ¶
PairExists return tobin tax for the pair TODO(mercilex): use AssetPair
func (Keeper) RewardBallotWinners ¶
func (k Keeper) RewardBallotWinners( ctx sdk.Context, voteTargets map[string]struct{}, ballotWinners map[string]types.ValidatorPerformance, )
RewardBallotWinners implements at the end of every VotePeriod, give out a portion of spread fees collected in the oracle reward pool to the oracle voters that voted faithfully.
func (Keeper) RewardBand ¶
RewardBand returns the ratio of allowable exchange rate error that a validator can be rewared
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 ¶
SetExchangeRate sets the consensus exchange rate of the given pair.
func (Keeper) SetExchangeRateWithEvent ¶
SetExchangeRateWithEvent calls SetExchangeRate and emits an event.
func (Keeper) SetFeederDelegation ¶
func (k Keeper) SetFeederDelegation(ctx sdk.Context, operator sdk.ValAddress, delegatedFeeder sdk.AccAddress)
SetFeederDelegation sets the account address that the validator operator delegated oracle vote rights to
func (Keeper) SetMissCounter ¶
SetMissCounter updates the # of vote periods missed in this oracle slash window
func (Keeper) SetPairReward ¶
func (k Keeper) SetPairReward(ctx sdk.Context, rewards *types.PairReward)
func (Keeper) SetWhitelist ¶
SetWhitelist store new whitelist to param store this function is only for test purpose
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 # of vote period for oracle slashing
func (Keeper) UpdateExchangeRates ¶ added in v0.14.0
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) VoteThreshold ¶
VoteThreshold returns the minimum percentage of votes that must be received for a ballot to pass.
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 ¶
CreateTestInput nolint Creates a base app, with 5 accounts,