mercury

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 17 Imported by: 0

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) *big.Int

GetConsensusAsk gets the median ask

func GetConsensusBenchmarkPrice

func GetConsensusBenchmarkPrice(paos []ParsedAttributedObservation) *big.Int

GetConsensusBenchmarkPrice gets the median benchmark price

func GetConsensusBid

func GetConsensusBid(paos []ParsedAttributedObservation) *big.Int

GetConsensusBid gets the median bid

func GetConsensusCurrentBlock

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

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

func GetConsensusTimestamp

func GetConsensusTimestamp(paos []ParsedAttributedObservation) uint32

GetConsensusTimestamp gets the median timestamp

func GetConsensusValidFromBlock

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

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

func ValidateAsk

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

func ValidateBenchmarkPrice

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

func ValidateBid

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

func ValidateBlockValues

func ValidateBlockValues(paos []ParsedAttributedObservation, f int, maxFinalizedBlockNumber 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(context.Context) (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, f Fetcher) Factory

func (Factory) NewReportingPlugin

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"`
	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"`
	CurrentBlockNum   int64  `protobuf:"varint,5,opt,name=currentBlockNum,proto3" json:"currentBlockNum,omitempty"`
	CurrentBlockHash  []byte `protobuf:"bytes,6,opt,name=currentBlockHash,proto3" json:"currentBlockHash,omitempty"`
	ValidFromBlockNum int64  `protobuf:"varint,7,opt,name=validFromBlockNum,proto3" json:"validFromBlockNum,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) GetTimestamp

func (x *MercuryObservationProto) GetTimestamp() uint32

func (*MercuryObservationProto) GetValidFromBlockNum

func (x *MercuryObservationProto) GetValidFromBlockNum() int64

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 Observation

type Observation struct {
	BenchmarkPrice    *big.Int
	Bid               *big.Int
	Ask               *big.Int
	CurrentBlockNum   int64
	CurrentBlockHash  []byte
	ValidFromBlockNum 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
	BenchmarkPrice    *big.Int
	Bid               *big.Int
	Ask               *big.Int
	CurrentBlockNum   int64 // inclusive; current block
	CurrentBlockHash  []byte
	ValidFromBlockNum int64 // exclusive; one above previous upper block
	Observer          commontypes.OracleID
}

type ReportCodec

type ReportCodec interface {
	// 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) (ocrtypes.Report, error)

	// 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

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

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 should be implemented and fetch from Mercury server
	// - 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