mercury

package
v0.0.0-...-3f0f60f Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_mercury_config_proto protoreflect.FileDescriptor
View Source
var File_mercury_observation_proto protoreflect.FileDescriptor

Functions

func DecodeValueInt192

func DecodeValueInt192(s []byte) (*big.Int, error)

Decodes a value using 24-byte big endian two's complement representation. This function never panics.

func EncodeValueInt192

func EncodeValueInt192(i *big.Int) ([]byte, error)

Encodes a value using 24-byte big endian two's complement representation. This function never panics.

func GetConsensusAsk

func GetConsensusAsk(paos []ParsedAttributedObservation, f int) (*big.Int, error)

GetConsensusAsk gets the median ask

func GetConsensusBenchmarkPrice

func GetConsensusBenchmarkPrice(paos []ParsedAttributedObservation, f int) (*big.Int, error)

GetConsensusBenchmarkPrice gets the median benchmark price

func GetConsensusBid

func GetConsensusBid(paos []ParsedAttributedObservation, f int) (*big.Int, error)

GetConsensusBid gets the median bid

func GetConsensusCurrentBlock

func GetConsensusCurrentBlock(paos []ParsedAttributedObservation, f int) (hash []byte, num int64, ts uint64, err error)

GetConsensusCurrentBlock gets the most common (mode) block hash/number/timestamps. In the event of a tie, use the lowest numerical value

func GetConsensusMaxFinalizedBlockNum

func GetConsensusMaxFinalizedBlockNum(paos []ParsedAttributedObservation, f int) (int64, error)

GetConsensusMaxFinalizedBlockNum gets the most common (mode) ConsensusMaxFinalizedBlockNum In the event of a tie, the lower number is chosen

func GetConsensusTimestamp

func GetConsensusTimestamp(paos []ParsedAttributedObservation) uint32

GetConsensusTimestamp gets the median timestamp

func MustEncodeValueInt192

func MustEncodeValueInt192(i *big.Int) []byte

func ValidateAsk

func ValidateAsk(paos []ParsedAttributedObservation, f int, min, max *big.Int) error

func ValidateBenchmarkPrice

func ValidateBenchmarkPrice(paos []ParsedAttributedObservation, f int, min, max *big.Int) error

func ValidateBid

func ValidateBid(paos []ParsedAttributedObservation, f int, min, max *big.Int) error

func ValidateCurrentBlock

func ValidateCurrentBlock(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) error

Types

type DataSource

type DataSource interface {
	// Observe queries the data source. Returns a value or an error. Once the
	// context is expires, Observe may still do cheap computations and return a
	// result, but should return as quickly as possible.
	//
	// More details: In the current implementation, the context passed to
	// Observe will time out after MaxDurationObservation. However, Observe
	// should *not* make any assumptions about context timeout behavior. Once
	// the context times out, Observe should prioritize returning as quickly as
	// possible, but may still perform fast computations to return a result
	// rather than error. For example, if Observe medianizes a number of data
	// sources, some of which already returned a result to Observe prior to the
	// context's expiry, Observe might still compute their median, and return it
	// instead of an error.
	//
	// Important: Observe should not perform any potentially time-consuming
	// actions like database access, once the context passed has expired.
	Observe(ctx context.Context, repts ocrtypes.ReportTimestamp, fetchMaxFinalizedBlockNum bool) (Observation, error)
}

DataSource implementations must be thread-safe. Observe may be called by many different threads concurrently.

type Factory

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

func NewFactory

func NewFactory(ds DataSource, lggr logger.Logger, occ OnchainConfigCodec, rc ReportCodec) Factory

func (Factory) NewMercuryPlugin

type Fetcher

type Fetcher interface {
	// FetchInitialMaxFinalizedBlockNumber should fetch the initial max
	// finalized block number from the mercury server.
	FetchInitialMaxFinalizedBlockNumber(context.Context) (*int64, error)
}

type MercuryConfigProto

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

Empty for now; might add in future

func (*MercuryConfigProto) Descriptor deprecated

func (*MercuryConfigProto) Descriptor() ([]byte, []int)

Deprecated: Use MercuryConfigProto.ProtoReflect.Descriptor instead.

func (*MercuryConfigProto) ProtoMessage

func (*MercuryConfigProto) ProtoMessage()

func (*MercuryConfigProto) ProtoReflect

func (x *MercuryConfigProto) ProtoReflect() protoreflect.Message

func (*MercuryConfigProto) Reset

func (x *MercuryConfigProto) Reset()

func (*MercuryConfigProto) String

func (x *MercuryConfigProto) String() string

type MercuryObservationProto

type MercuryObservationProto struct {
	Timestamp uint32 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// Prices
	BenchmarkPrice []byte `protobuf:"bytes,2,opt,name=benchmarkPrice,proto3" json:"benchmarkPrice,omitempty"`
	Bid            []byte `protobuf:"bytes,3,opt,name=bid,proto3" json:"bid,omitempty"`
	Ask            []byte `protobuf:"bytes,4,opt,name=ask,proto3" json:"ask,omitempty"`
	// All three prices must be valid, or none are (they all should come from one API query and hold invariant bid <= bm <= ask)
	PricesValid bool `protobuf:"varint,5,opt,name=pricesValid,proto3" json:"pricesValid,omitempty"`
	// Current block
	CurrentBlockNum       int64  `protobuf:"varint,6,opt,name=currentBlockNum,proto3" json:"currentBlockNum,omitempty"`
	CurrentBlockHash      []byte `protobuf:"bytes,7,opt,name=currentBlockHash,proto3" json:"currentBlockHash,omitempty"`
	CurrentBlockTimestamp uint64 `protobuf:"varint,8,opt,name=currentBlockTimestamp,proto3" json:"currentBlockTimestamp,omitempty"`
	// All three block observations must be valid, or none are (they all come from the same block)
	CurrentBlockValid bool `protobuf:"varint,9,opt,name=currentBlockValid,proto3" json:"currentBlockValid,omitempty"`
	// MaxFinalizedBlockNumber comes from previous report when present and is
	// only observed from mercury server when previous report is nil
	MaxFinalizedBlockNumber      int64 `protobuf:"varint,10,opt,name=maxFinalizedBlockNumber,proto3" json:"maxFinalizedBlockNumber,omitempty"`
	MaxFinalizedBlockNumberValid bool  `protobuf:"varint,11,opt,name=maxFinalizedBlockNumberValid,proto3" json:"maxFinalizedBlockNumberValid,omitempty"`
	// contains filtered or unexported fields
}

TODO: what about different report formats for different clients?

func (*MercuryObservationProto) Descriptor deprecated

func (*MercuryObservationProto) Descriptor() ([]byte, []int)

Deprecated: Use MercuryObservationProto.ProtoReflect.Descriptor instead.

func (*MercuryObservationProto) GetAsk

func (x *MercuryObservationProto) GetAsk() []byte

func (*MercuryObservationProto) GetBenchmarkPrice

func (x *MercuryObservationProto) GetBenchmarkPrice() []byte

func (*MercuryObservationProto) GetBid

func (x *MercuryObservationProto) GetBid() []byte

func (*MercuryObservationProto) GetCurrentBlockHash

func (x *MercuryObservationProto) GetCurrentBlockHash() []byte

func (*MercuryObservationProto) GetCurrentBlockNum

func (x *MercuryObservationProto) GetCurrentBlockNum() int64

func (*MercuryObservationProto) GetCurrentBlockTimestamp

func (x *MercuryObservationProto) GetCurrentBlockTimestamp() uint64

func (*MercuryObservationProto) GetCurrentBlockValid

func (x *MercuryObservationProto) GetCurrentBlockValid() bool

func (*MercuryObservationProto) GetMaxFinalizedBlockNumber

func (x *MercuryObservationProto) GetMaxFinalizedBlockNumber() int64

func (*MercuryObservationProto) GetMaxFinalizedBlockNumberValid

func (x *MercuryObservationProto) GetMaxFinalizedBlockNumberValid() bool

func (*MercuryObservationProto) GetPricesValid

func (x *MercuryObservationProto) GetPricesValid() bool

func (*MercuryObservationProto) GetTimestamp

func (x *MercuryObservationProto) GetTimestamp() uint32

func (*MercuryObservationProto) ProtoMessage

func (*MercuryObservationProto) ProtoMessage()

func (*MercuryObservationProto) ProtoReflect

func (x *MercuryObservationProto) ProtoReflect() protoreflect.Message

func (*MercuryObservationProto) Reset

func (x *MercuryObservationProto) Reset()

func (*MercuryObservationProto) String

func (x *MercuryObservationProto) String() string

type ObsResult

type ObsResult[T any] struct {
	Val T
	Err error
}

type Observation

type Observation struct {
	BenchmarkPrice        ObsResult[*big.Int]
	Bid                   ObsResult[*big.Int]
	Ask                   ObsResult[*big.Int]
	CurrentBlockNum       ObsResult[int64]
	CurrentBlockHash      ObsResult[[]byte]
	CurrentBlockTimestamp ObsResult[uint64]
	// MaxFinalizedBlockNumber comes from previous report when present and is
	// only observed from mercury server when previous report is nil
	MaxFinalizedBlockNumber ObsResult[int64]
}

type OffchainConfig

type OffchainConfig struct{}

func DecodeOffchainConfig

func DecodeOffchainConfig(b []byte) (o OffchainConfig, err error)

func (OffchainConfig) Encode

func (c OffchainConfig) Encode() []byte

type OnchainConfig

type OnchainConfig struct {
	// applies to all values: price, bid and ask
	Min *big.Int
	Max *big.Int
}

type OnchainConfigCodec

type OnchainConfigCodec interface {
	Encode(OnchainConfig) ([]byte, error)
	Decode([]byte) (OnchainConfig, error)
}

type ParsedAttributedObservation

type ParsedAttributedObservation struct {
	Timestamp uint32
	Observer  commontypes.OracleID

	BenchmarkPrice *big.Int
	Bid            *big.Int
	Ask            *big.Int
	// All three prices must be valid, or none are (they all should come from one API query and hold invariant bid <= bm <= ask)
	PricesValid bool

	CurrentBlockNum       int64 // inclusive; current block
	CurrentBlockHash      []byte
	CurrentBlockTimestamp uint64
	// All three block observations must be valid, or none are (they all come from the same block)
	CurrentBlockValid bool

	// MaxFinalizedBlockNumber comes from previous report when present and is
	// only observed from mercury server when previous report is nil
	//
	// MaxFinalizedBlockNumber will be -1 if there is none
	MaxFinalizedBlockNumber      int64
	MaxFinalizedBlockNumberValid bool
}

type ReportCodec

type ReportCodec interface {
	// BuildReport Implementers may assume that there is at most one
	// ParsedAttributedObservation per observer, and that all observers are
	// valid. However, observation values, timestamps, etc... should all be
	// treated as untrusted.
	BuildReport(paos []ParsedAttributedObservation, f int, validFromBlockNum int64) (ocrtypes.Report, error)

	// MaxReportLength Returns the maximum length of a report based on n, the number of oracles.
	// The output of BuildReport must respect this maximum length.
	MaxReportLength(n int) (int, error)

	// CurrentBlockNumFromReport returns the median current block number from a report
	CurrentBlockNumFromReport(types.Report) (int64, error)
}

ReportCodec All functions on ReportCodec should be pure and thread-safe. Be careful validating and parsing any data passed.

type StandardOnchainConfigCodec

type StandardOnchainConfigCodec struct{}

StandardOnchainConfigCodec provides a mercury-specific implementation of OnchainConfigCodec.

An encoded onchain config is expected to be in the format <version><min><max> where version is a uint8 and min and max are in the format returned by EncodeValueInt192.

func (StandardOnchainConfigCodec) Decode

func (StandardOnchainConfigCodec) Encode

type Transmitter

type Transmitter interface {
	Fetcher
	// NOTE: Mercury doesn't actually transmit on-chain, so there is no
	// "contract" involved with the transmitter.
	// - Transmit should be implemented and send to Mercury server
	// - LatestConfigDigestAndEpoch is a stub method, does not need to do anything
	// - FromAccount() should return CSA public key
	ocrtypes.ContractTransmitter
}

Jump to

Keyboard shortcuts

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