oracle

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Oracle

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

Oracle implements the core component responsible for fetching exchange rates for a given set of currency pairs and determining exchange rates.

func New

func New(
	logger log.Logger,
	oracleTicker time.Duration,
	providers []types.Provider,
	aggregateFn types.AggregateFn,
) *Oracle

New returns a new instance of an Oracle. The oracle inputs providers that are responsible for fetching prices for a given set of currency pairs (base, quote). The oracle will fetch new prices concurrently every oracleTicker interval. In the case where the oracle fails to fetch prices from a given provider, it will continue to fetch prices from the remaining providers. The oracle currently assumes that each provider aggregates prices using TWAPs, TVWAPs, etc. When determining final prices, the oracle will utilize the aggregateFn to compute the final price for each currency pair. By default, the oracle will compute the median price across all providers.

func NewDefaultOracle

func NewDefaultOracle(
	logger log.Logger,
	oracleTicker time.Duration,
	providers []types.Provider,
	currencyPairs []oracletypes.CurrencyPair,
) *Oracle

NewDefaultOracle returns a new instance of an Oracle with a default aggregate function. It registers the given providers with the same set of currency pairs. The default aggregate function computes the median price across all providers.

func NewOracleFromConfig

func NewOracleFromConfig(logger log.Logger, cfg *config.Config) (*Oracle, error)

NewOracleFromConfig returns a new oracle instance from the given OracleConfig.

func (*Oracle) GetLastSyncTime

func (o *Oracle) GetLastSyncTime() time.Time

GetLastSyncTime returns the last time the oracle successfully updated prices.

func (*Oracle) GetPrices

func (o *Oracle) GetPrices() map[oracletypes.CurrencyPair]*uint256.Int

GetPrices returns the aggregate prices from the oracle.

func (*Oracle) IsRunning

func (o *Oracle) IsRunning() bool

IsRunning returns true if the oracle is running.

func (*Oracle) SetLastSyncTime

func (o *Oracle) SetLastSyncTime(t time.Time)

SetLastSyncTime sets the last time the oracle successfully updated prices.

func (*Oracle) Start

func (o *Oracle) Start(ctx context.Context) error

Start starts the (blocking) oracle process. It will return when the context is cancelled or the oracle is stopped. The oracle will fetch prices from each provider concurrently every oracleTicker interval.

func (*Oracle) Stop

func (o *Oracle) Stop()

Stop stops the oracle process and waits for it to gracefully exit.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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