types

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PriceTimeout = 15 * time.Second
)

Variables

This section is empty.

Functions

func GetBlockHeight

func GetBlockHeight(msg []byte) (uint64, error)

Types

type EventStream

type EventStream interface {
	// ParamsUpdate signals a new Params update.
	// EventStream must provide, on startup, the
	// initial Params found on the chain.
	ParamsUpdate() <-chan Params
	// VotingPeriodStarted signals a new x/oracle
	// voting period has just started.
	VotingPeriodStarted() <-chan VotingPeriod
	// Close shuts down the EventStream.
	Close()
}

EventStream defines the asynchronous stream of events required by the feeder's Loop function. EventStream must handle failures by itself.

type FetchPricesFunc

type FetchPricesFunc func(symbols set.Set[Symbol], logger zerolog.Logger) (map[Symbol]float64, error)

FetchPricesFunc is the function used to fetch updated prices. The symbols passed are the symbols we require prices for. The returned map must map symbol to its float64 price, or an error. If there's a failure in updating only one price then the map can be returned without the provided symbol.

type NewBlockJSON

type NewBlockJSON struct {
	Jsonrpc string `json:"jsonrpc"`
	ID      int    `json:"id"`
	Result  struct {
		Query string `json:"query"`
		Data  struct {
			Type  string `json:"type"`
			Value struct {
				Block struct {
					Header struct {
						ChainID        string    `json:"chain_id"`
						Height         string    `json:"height"`
						Time           time.Time `json:"time"`
						LastCommitHash string    `json:"last_commit_hash"`
					} `json:"header"`
					Data struct {
						Txs []interface{} `json:"txs"`
					} `json:"data"`
				} `json:"block"`
				ResultBeginBlock struct {
					Events []TmEvent `json:"events"`
				} `json:"result_begin_block"`
				ResultEndBlock struct {
					ValidatorUpdates []interface{} `json:"validator_updates"`
					Events           []TmEvent     `json:"events"`
				} `json:"result_end_block"`
			} `json:"value"`
		} `json:"data"`
	} `json:"result"`
}

todo mercilex split in concrete types instead of anonymous

type Params

type Params struct {
	// Pairs are the symbols we need to provide prices for.
	Pairs []asset.Pair
	// VotePeriodBlocks is how
	VotePeriodBlocks uint64
}

Params is the x/oracle specific subset of parameters required for price feeding.

func ParamsFromOracleParams

func ParamsFromOracleParams(p oracletypes.Params) Params

ParamsFromOracleParams converts oracletypes.Params into Params. Panics on invalid whitelist pairs.

func (Params) Equal

func (p Params) Equal(params Params) bool

type Price

type Price struct {
	// Pair defines the symbol we're posting prices for.
	Pair asset.Pair
	// Price defines the symbol's price.
	Price float64
	// SourceName defines the source which is providing the prices.
	SourceName string
	// Valid reports whether the price is valid or not.
	// If not valid then an abstain vote will be posted.
	// Computed from the update time.
	Valid bool
}

Price defines the price of a symbol.

type PricePoster

type PricePoster interface {
	// Whoami returns the validator address the PricePoster
	// is sending prices for.
	Whoami() types.ValAddress
	// SendPrices sends the provided slice of Price.
	SendPrices(vp VotingPeriod, prices []Price)
	// Close shuts down the PricePoster.
	Close()
}

PricePoster defines the validator oracle client, which sends new prices. PricePoster must handle failures by itself.

type PriceProvider

type PriceProvider interface {
	// GetPrice returns the Price for the given symbol.
	// Price.Pair, Price.Source must always be non-empty.
	// If there are errors whilst fetching prices, then
	// Price.Valid must be set to false.
	GetPrice(pair asset.Pair) Price
	// Close shuts down the PriceProvider.
	Close()
}

PriceProvider defines an exchange API which provides prices for the given assets. PriceProvider must handle failures by itself.

type RawPrice

type RawPrice struct {
	Price      float64
	UpdateTime time.Time
}

type Source

type Source interface {
	// PriceUpdates is a readonly channel which provides
	// the latest prices update. Updates can be provided
	// for one asset only or in batches, hence the map.
	PriceUpdates() <-chan map[Symbol]RawPrice
	// Close closes the Source.
	Close()
}

Source defines a source for price provision. This source has no knowledge of nibiru internals and mappings across asset.Pair and the Source symbols.

type Symbol

type Symbol string

Symbol refers to the ticker name used by the third party data source/exchange.

type TmEvent

type TmEvent struct {
	Type       string `json:"type"`
	Attributes []TmEventAttribute
}

type TmEventAttribute

type TmEventAttribute struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	Index bool   `json:"index"`
}

type VotingPeriod

type VotingPeriod struct {
	// Height is the height of the voting period.
	Height uint64
}

VotingPeriod contains information concerning the current voting period.

Directories

Path Synopsis
Package mock_types is a generated GoMock package.
Package mock_types is a generated GoMock package.

Jump to

Keyboard shortcuts

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