keeper

package
v0.3.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2023 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CrossingPriceUpdateCutoffPpm = uint32(500_000) // 50%
)

Variables

This section is empty.

Functions

func GenerateMarketPriceUpdateEvents

func GenerateMarketPriceUpdateEvents(markets []types.MarketPrice) []*indexerevents.MarketEventV1

GenerateMarketPriceUpdateEvents takes in a slice of market prices and returns a slice of price updates.

func NewMsgServerImpl

func NewMsgServerImpl(keeper types.PricesKeeper) types.MsgServer

NewMsgServerImpl returns an implementation of the MsgServer interface for the provided Keeper.

Types

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey storetypes.StoreKey,
	indexPriceCache *pricefeedtypes.MarketToExchangePrices,
	marketToSmoothedPrices types.MarketToSmoothedPrices,
	timeProvider libtime.TimeProvider,
	indexerEventManager indexer_manager.IndexerEventManager,
	authorities []string,
) *Keeper

func (Keeper) CreateMarket

func (k Keeper) CreateMarket(
	ctx sdk.Context,
	marketParam types.MarketParam,
	marketPrice types.MarketPrice,
) (types.MarketParam, error)

CreateMarket creates a new market param in the store along with a new market price for that market param. This is the only path to creating new MarketPrices, so if we have a param defined for a market, we should expect to see a price defined, and vice versa.

func (Keeper) GetAllMarketParamPrices

func (k Keeper) GetAllMarketParamPrices(ctx sdk.Context) ([]types.MarketParamPrice, error)

GetAllMarketParamPrices returns a slice of MarketParam, MarketPrice tuples for all markets.

func (Keeper) GetAllMarketParams

func (k Keeper) GetAllMarketParams(ctx sdk.Context) []types.MarketParam

GetAllMarketParams returns all market params.

func (Keeper) GetAllMarketPrices

func (k Keeper) GetAllMarketPrices(ctx sdk.Context) []types.MarketPrice

GetAllMarketPrices returns all market prices.

func (Keeper) GetIndexerEventManager

func (k Keeper) GetIndexerEventManager() indexer_manager.IndexerEventManager

func (Keeper) GetMarketIdToValidIndexPrice added in v0.3.0

func (k Keeper) GetMarketIdToValidIndexPrice(
	ctx sdk.Context,
) map[uint32]types.MarketPrice

GetMarketIdToValidIndexPrice returns a map of market id to valid index price. An index price is valid iff: 1) the last update time is within a predefined threshold away from the given read time. 2) the number of prices that meet 1) are greater than the minimum number of exchanges specified in the given input. If a market does not have a valid index price, its `marketId` is not included in returned map.

func (Keeper) GetMarketParam

func (k Keeper) GetMarketParam(
	ctx sdk.Context,
	id uint32,
) (
	market types.MarketParam,
	exists bool,
)

GetMarketParam returns a market param from its id.

func (Keeper) GetMarketPrice

func (k Keeper) GetMarketPrice(
	ctx sdk.Context,
	id uint32,
) (types.MarketPrice, error)

GetMarketPrice returns a market price from its id.

func (Keeper) GetMarketsMissingFromPriceUpdates

func (k Keeper) GetMarketsMissingFromPriceUpdates(
	ctx sdk.Context,
	marketPriceUpdates []*types.MsgUpdateMarketPrices_MarketPrice,
) []uint32

GetMarketsMissingFromPriceUpdates returns a list of market ids that should have been included but not present in the `MsgUpdateMarketPrices`.

Note: this is NOT determistic, because it relies on "index price" that is subject to each validator.

func (Keeper) GetValidMarketPriceUpdates

func (k Keeper) GetValidMarketPriceUpdates(
	ctx sdk.Context,
) *types.MsgUpdateMarketPrices

GetValidMarketPriceUpdates returns a msg containing a list of "valid" price updates that should be included in a block. A "valid" price update means: 1) All values used to compute the valid price must exist and be valid: - the index price exists and is nonzero. - the smoothed price exists and is nonzero. 2) The smoothed price and the index price must be on the same side compared to the oracle price. 3) The proposed price is either the index price or the smoothed price, depending on which is closer to the oracle price. 4) The proposed price meets the minimum price change ppm requirement. Note: the list of market price updates can be empty if there are no "valid" index prices, smoothed prices, and/or proposed prices for any market.

func (Keeper) HasAuthority added in v0.3.0

func (k Keeper) HasAuthority(authority string) bool

func (Keeper) InitializeForGenesis

func (k Keeper) InitializeForGenesis(ctx sdk.Context)

func (Keeper) IsRecentlyAdded added in v0.3.0

func (k Keeper) IsRecentlyAdded(marketId uint32) bool

IsRecentlyAdded returns true if the market was added recently. Since it takes a few seconds for index prices to populate, we would not consider missing index prices for a recently added market to be an error.

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) MarketParam

func (Keeper) MarketPrice

func (Keeper) ModifyMarketParam

func (k Keeper) ModifyMarketParam(
	ctx sdk.Context,
	marketParam types.MarketParam,
) (types.MarketParam, error)

ModifyMarketParam modifies an existing market param in the store.

func (Keeper) PerformStatefulPriceUpdateValidation

func (k Keeper) PerformStatefulPriceUpdateValidation(
	ctx sdk.Context,
	marketPriceUpdates *types.MsgUpdateMarketPrices,
	performNonDeterministicValidation bool,
) error

PerformStatefulPriceUpdateValidation performs stateful validations on `MsgUpdateMarketPrices`. Depending on the input, this func performs non-deterministic stateful validation.

func (Keeper) UnsafeModifyMarketParam added in v0.3.0

func (k Keeper) UnsafeModifyMarketParam(
	ctx sdk.Context,
	marketParam types.MarketParam,
) error

UnsafeModifyMarketParam modifies an existing market param in the store.

func (Keeper) UnsafeSetMarketPrice added in v0.3.0

func (k Keeper) UnsafeSetMarketPrice(
	ctx sdk.Context,
	price types.MarketPrice,
)

UnsafeSetMarketPrice sets market price without validation.

func (Keeper) UpdateMarketPrices

func (k Keeper) UpdateMarketPrices(
	ctx sdk.Context,
	updates []*types.MsgUpdateMarketPrices_MarketPrice,
) error

UpdateMarketPrices updates the prices for markets.

func (Keeper) UpdateSmoothedPrices

func (k Keeper) UpdateSmoothedPrices(ctx sdk.Context) error

UpdateSmoothedPrices updates the internal map of smoothed prices for all markets. The smoothing is calculated with Basic Exponential Smoothing, see https://en.wikipedia.org/wiki/Exponential_smoothing If there is no valid index price for a market at this time, the smoothed price does not change.

type PriceTuple

type PriceTuple struct {
	OldPrice   uint64
	IndexPrice uint64
	NewPrice   uint64
}

PriceTuple labels and encapsulates the set of prices used for various price computations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL