oracle

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetriesReConnectWebSocket = 5
)

Variables

View Source
var ErrInvalidMessage = errors.New("received invalid message")

Functions

func CombineSignatureToString

func CombineSignatureToString(signature Signature) (result string)

CombineSignatureToString combines a signature to a string

func ConvertDataToAssetPair

func ConvertDataToAssetPair(data Data, assetId string) (result oracletypes.AssetPair)

ConvertDataToAssetPair converts data get from websocket to list of asset pairs

func ConvertSignedPrice

func ConvertSignedPrice(signeds SignedPrice) oracletypes.SignedPriceOfAssetPair

ConvertSignedPrice converts signed price to SignedPriceOfAssetPair of Stork

func ConvertTimestampToSecond

func ConvertTimestampToSecond(timestamp uint64) uint64

func NewStorkFetcher

func NewStorkFetcher(storkMessage string, storkTickers []string) *storkFetcher

NewStorkFetcher returns a new StorkFetcher instance.

Types

type Data

type Data struct {
	Timestamp     int64         `json:"timestamp"`
	AssetID       string        `json:"asset_id"`
	SignatureType string        `json:"signature_type"`
	Trigger       string        `json:"trigger"`
	Price         string        `json:"price"`
	SignedPrices  []SignedPrice `json:"signed_prices"`
}

type FeedConfig

type FeedConfig struct {
	ProviderName      string `toml:"provider"`
	Ticker            string `toml:"ticker"`
	PullInterval      string `toml:"pullInterval"`
	ObservationSource string `toml:"observationSource"`
	OracleType        string `toml:"oracleType"`
}

func ParseDynamicFeedConfig

func ParseDynamicFeedConfig(body []byte) (*FeedConfig, error)

func ParseStorkFeedConfig

func ParseStorkFeedConfig(body []byte) (*FeedConfig, error)

func (*FeedConfig) Hash

func (c *FeedConfig) Hash() string

type FeedProvider

type FeedProvider string
const (
	FeedProviderDynamic FeedProvider = "_"
	FeedProviderBinance FeedProvider = "binance"
	FeedProviderStork   FeedProvider = "stork"
)

func (FeedProvider) String

func (f FeedProvider) String() string

type PriceData

type PriceData struct {
	// Ticker is BASE/QUOTE pair name
	Ticker Ticker

	// ProviderName is the name of the feed
	ProviderName string

	// Symbol is provider-specific
	Symbol string

	// Price is the reported price by feed integarion
	Price decimal.Decimal

	// Asset pair - for Stork Oracle
	AssetPair *oracletypes.AssetPair

	// Timestamp of the report
	Timestamp time.Time

	OracleType oracletypes.OracleType
}

PriceData stores additional meta info for a price report.

type PriceFeedConfig

type PriceFeedConfig struct {
	Symbol        string
	FeedProvider  FeedProvider
	PullInterval  time.Duration
	DynamicConfig *FeedConfig
}

type PricePuller

type PricePuller interface {
	Provider() FeedProvider
	ProviderName() string
	Symbol() string
	Interval() time.Duration

	// PullPrice method must be implemented in order to get a price
	// from external source, handled by PricePuller.
	PullPrice(ctx context.Context) (priceData *PriceData, err error)
	OracleType() oracletypes.OracleType
}

func NewDynamicPriceFeed

func NewDynamicPriceFeed(cfg *FeedConfig) (PricePuller, error)

NewDynamicPriceFeed returns price puller that is implemented by Chainlink's job spec runner that accepts dotDag graphs as a definition of the observation source.

func NewStorkPriceFeed

func NewStorkPriceFeed(storkFetcher StorkFetcher, cfg *FeedConfig) (PricePuller, error)

NewStorkPriceFeed returns price puller

type Service

type Service interface {
	Start() error
	Close()
}

func NewService

func NewService(
	_ context.Context,
	cosmosClient chainclient.ChainClient,
	exchangeQueryClient exchangetypes.QueryClient,
	oracleQueryClient oracletypes.QueryClient,
	feedConfigs map[string]*FeedConfig,
	storkFetcher StorkFetcher,
) (Service, error)

type Signature

type Signature struct {
	R string `json:"r"`
	S string `json:"s"`
	V string `json:"v"`
}

type SignedPrice

type SignedPrice struct {
	PublisherKey         string               `json:"publisher_key"`
	ExternalAssetID      string               `json:"external_asset_id"`
	SignatureType        string               `json:"signature_type"`
	Price                math.LegacyDec       `json:"price"`
	TimestampedSignature TimestampedSignature `json:"timestamped_signature"`
}

type StorkConfig

type StorkConfig struct {
	WebsocketUrl    string
	WebsocketHeader string
	Message         string
}

type StorkFetcher

type StorkFetcher interface {
	Start(ctx context.Context, conn *websocket.Conn) error
	AssetPair(ticker string) *oracletypes.AssetPair
}

type Ticker

type Ticker string

func (Ticker) Base

func (t Ticker) Base() string

func (Ticker) Quote

func (t Ticker) Quote() string

type TimestampedSignature

type TimestampedSignature struct {
	Signature Signature `json:"signature"`
	Timestamp uint64    `json:"timestamp"`
	MsgHash   string    `json:"msg_hash"`
}

Jump to

Keyboard shortcuts

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