keeper

package
v0.0.0-...-a9c8dba Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 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 GenerateMarketPriceUpdateIndexerEvent

func GenerateMarketPriceUpdateIndexerEvent(
	market types.MarketPrice,
) *indexerevents.MarketEventV1

GenerateMarketPriceUpdateIndexerEvents 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

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

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) GetSmoothedSpotPrice

func (k Keeper) GetSmoothedSpotPrice(
	markedId uint32,
) (uint64, bool)

func (Keeper) GetValidMarketSpotPriceUpdates

func (k Keeper) GetValidMarketSpotPriceUpdates(
	ctx sdk.Context,
) []*types.MarketSpotPriceUpdate

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

func (k Keeper) HasAuthority(authority string) bool

func (Keeper) InitializeForGenesis

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

func (Keeper) IsRecentlyAvailable

func (k Keeper) IsRecentlyAvailable(ctx sdk.Context, marketId uint32) bool

IsRecentlyAvailable returns true if the market was recently made available to the pricefeed daemon. A market is considered recently available either if it was recently created, or if the pricefeed daemon was recently started. If an index price does not exist for a recently available market, the protocol does not consider this an error condition, as it is expected that the pricefeed daemon will eventually provide a price for the market within a few seconds.

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,
	updatedMarketParam types.MarketParam,
) (types.MarketParam, error)

ModifyMarketParam modifies an existing market param in the store.

func (Keeper) PerformStatefulPriceUpdateValidation

func (k Keeper) PerformStatefulPriceUpdateValidation(
	ctx sdk.Context,
	marketPriceUpdate *types.MarketPriceUpdate,
) (isSpotValid bool, isPnlValid bool)

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

func (Keeper) UpdatePnlPrice

func (k Keeper) UpdatePnlPrice(
	ctx sdk.Context,
	update *types.MarketPnlPriceUpdate,
) error

func (Keeper) UpdateSmoothedSpotPrices

func (k Keeper) UpdateSmoothedSpotPrices(
	ctx sdk.Context,
	linearInterpolateFunc func(v0 uint64, v1 uint64, ppm uint32) (uint64, error),
) 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.

func (Keeper) UpdateSpotAndPnlMarketPrices

func (k Keeper) UpdateSpotAndPnlMarketPrices(
	ctx sdk.Context,
	update *types.MarketPriceUpdate,
) error

UpdateMarketPrices updates the prices for markets.

func (Keeper) UpdateSpotPrice

func (k Keeper) UpdateSpotPrice(
	ctx sdk.Context,
	update *types.MarketSpotPriceUpdate,
) error

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