Documentation
¶
Index ¶
- Variables
- func ComputeMedian(priceInfo PriceInfo) *big.Int
- func Median(ctx sdk.Context, logger log.Logger, validatorStore ValidatorStore, ...) aggregator.AggregateFn[string, map[connecttypes.CurrencyPair]*big.Int]
- func MedianFromContext(logger log.Logger, validatorStore ValidatorStore, threshold math.LegacyDec) ...
- type CCVCompat
- type CCVConsumerCompatKeeper
- func (c CCVConsumerCompatKeeper) GetPubKeyByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (cmtprotocrypto.PublicKey, error)
- func (c CCVConsumerCompatKeeper) TotalBondedTokens(ctx context.Context) (math.Int, error)
- func (c CCVConsumerCompatKeeper) ValidatorByConsAddr(ctx context.Context, addr sdk.ConsAddress) (stakingtypes.ValidatorI, error)
- type CCValidatorStore
- 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[connecttypes.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[connecttypes.CurrencyPair]*big.Int]
MedianFromContext returns a new Median aggregate function that is parametrized by the latest state of the application.
Types ¶
type CCVCompat ¶
type CCVCompat struct { stakingtypes.ValidatorI // contains filtered or unexported fields }
CCVCompat is used for compatibility between stakingtypes.ValidatorI and CrossChainValidator.
func (CCVCompat) GetBondedTokens ¶
GetBondedTokens returns the power of the validator as math.Int.
type CCVConsumerCompatKeeper ¶
type CCVConsumerCompatKeeper struct {
// contains filtered or unexported fields
}
CCVConsumerCompatKeeper is used for compatibility between the consumer keeper and the ValidatorStore interface.
func NewCCVConsumerCompatKeeper ¶
func NewCCVConsumerCompatKeeper(ccvStore CCValidatorStore) CCVConsumerCompatKeeper
NewCCVConsumerCompatKeeper constructs a CCVConsumerCompatKeeper from a consumer keeper.
func (CCVConsumerCompatKeeper) GetPubKeyByConsAddr ¶
func (c CCVConsumerCompatKeeper) GetPubKeyByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (cmtprotocrypto.PublicKey, error)
GetPubKeyByConsAddr returns the public key of a validator given the consensus addr.
func (CCVConsumerCompatKeeper) TotalBondedTokens ¶
TotalBondedTokens iterates through all CCVs and returns the sum of all validator power.
func (CCVConsumerCompatKeeper) ValidatorByConsAddr ¶
func (c CCVConsumerCompatKeeper) ValidatorByConsAddr(ctx context.Context, addr sdk.ConsAddress) (stakingtypes.ValidatorI, error)
ValidatorByConsAddr returns a compat validator from the consumer keeper.
type CCValidatorStore ¶
type CCValidatorStore interface { GetAllCCValidator(ctx sdk.Context) []types.CrossChainValidator GetCCValidator(ctx sdk.Context, addr []byte) (types.CrossChainValidator, bool) }
CCValidatorStore defines the interface contract required for the cross chain validator consumer store.
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.