Documentation
¶
Index ¶
- Variables
- func ComputeMedian(priceInfo PriceInfo) *big.Int
- func Median(ctx sdk.Context, logger log.Logger, validatorStore ValidatorStore, ...) aggregator.AggregateFn[string, map[slinkytypes.CurrencyPair]*big.Int]
- func MedianFromContext(logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec) ...
- type PriceInfo
- type PricePerValidator
- type ValidatorStore
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 ComputeMedian ¶
ComputeMedian computes the stake-weighted median price for a given asset.
func Median ¶
func Median( ctx sdk.Context, logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec, ) aggregator.AggregateFn[string, map[slinkytypes.CurrencyPair]*big.Int]
Median 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 MedianFromContext ¶
func MedianFromContext( logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec, ) aggregator.AggregateFnFromContext[string, map[slinkytypes.CurrencyPair]*big.Int]
MedianFromContext returns a new Median aggregate function that is parametrized by the latest state of the application.
Types ¶
type PriceInfo ¶
type PriceInfo struct {
Prices []PricePerValidator
TotalWeight math.Int
}
VoteWeightPriceInfo tracks the stake weight(s) + price(s) for a given currency pair.
type PricePerValidator ¶
VoteWeightPrice defines a price update that includes the stake weight of the validator.
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.