Documentation ¶
Index ¶
- Variables
- func ComputeVoteWeightedMedian(priceInfo VoteWeightedPriceInfo) *big.Int
- func VoteWeightedMedian(ctx sdk.Context, logger log.Logger, validatorStore ValidatorStore, ...) aggregator.AggregateFn[string, map[types.CurrencyPair]*big.Int]
- func VoteWeightedMedianFromContext(logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec) aggregator.AggregateFnFromContext[string, map[types.CurrencyPair]*big.Int]
- type ValidatorStore
- type VoteWeightedPriceInfo
- type VoteWeightedPricePerValidator
Constants ¶
This section is empty.
Variables ¶
var DefaultPowerThreshold = math.LegacyNewDecWithPrec(667, 3)
DefaultPowerThreshold defines the total voting power % that must be submitted in order for a currency pair to be considered for the final oracle price. We provide a default supermajority threshold of 2/3+.
Functions ¶
func ComputeVoteWeightedMedian ¶
func ComputeVoteWeightedMedian(priceInfo VoteWeightedPriceInfo) *big.Int
ComputeVoteWeightedMedian computes the stake-weighted median price for a given asset.
func VoteWeightedMedian ¶
func VoteWeightedMedian( ctx sdk.Context, logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec, ) aggregator.AggregateFn[string, map[types.CurrencyPair]*big.Int]
VoteWeightedMedian returns an aggregation function that computes the stake weighted median price as the final deterministic oracle price for any qualifying currency pair (base, quote). There are a few things to note about the implementation:
- Price updates for a given currency pair will only be written to state if the power % threshold is met. The threshold is determined by the total voting power of all validators that submitted a price update for a given currency pair divided by the total network voting power. The threshold to meet is configurable by developers.
- In the case where there are not enough price updates for a given currency pair, the price will not be included in the final set of oracle prices.
- Given the threshold is met, the final oracle price for a given currency pair is the median price weighted by the stake of each validator that submitted a price.
func VoteWeightedMedianFromContext ¶
func VoteWeightedMedianFromContext( logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec, ) aggregator.AggregateFnFromContext[string, map[types.CurrencyPair]*big.Int]
VoteWeightedMedianFromContext returns a new VoteWeightedMedian aggregate function that is parametrized by the latest state of the application.
Types ¶
type ValidatorStore ¶
type ValidatorStore interface { ValidatorByConsAddr(ctx context.Context, addr sdk.ConsAddress) (stakingtypes.ValidatorI, error) TotalBondedTokens(ctx context.Context) (math.Int, error) }
ValidatorStore defines the interface contract required for calculating stake-weighted median prices + total voting power for a given currency pair.
type VoteWeightedPriceInfo ¶
type VoteWeightedPriceInfo struct { Prices []VoteWeightedPricePerValidator TotalWeight math.Int }
VoteWeightPriceInfo tracks the stake weight(s) + price(s) for a given currency pair.