mercury

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 43 Imported by: 1 module, 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

View Source
const ByteWidthInt192 = 24

Bounds on an int192

View Source
const DefaultMaxTransmitQueueSize = 300_000

DefaultMaxTransmitQueueSize is used when the configured max transmit queue size is unset (0). The in-memory TransmitQueue treats 0 as "unlimited", but PruneTransmitRequests uses the value as an absolute row cap, so 0 would delete every persisted request. Clamp it to a sane default instead.

View Source
const DefaultTransmitTimeout = 1 * time.Second

DefaultTransmitTimeout is used when the configured transmit timeout is non-positive, which would otherwise produce an already-expired context and spin the transmit loop.

View Source
const (
	// Mercury server error codes
	DuplicateReport = 2
)
View Source
const EvmHashLen = 32

NOTE: hardcoded for now, this may need to change if we support block range on chains other than eth

View Source
const TransmitQueueMaxSize = 10_000 // hardcode this for legacy transmitter since we want the config var to apply only to LLO

Variables

View Source
var FeeScalingFactor = decimal.NewFromInt(1e18)

FeeScalingFactor indicates the multiplier applied to fees. e.g. for a 1e18 multiplier, a LINK fee of 7.42 will be represented as 7.42e18 This is what will be baked into the report for use on-chain.

View Source
var MaxInt192 *big.Int
View Source
var MaxInt192Enc []byte
View Source
var PayloadTypes = getPayloadTypes()
View Source
var PriceScalingFactor = decimal.NewFromInt(1e18) //nolint:revive

PriceScalingFactor indicates the multiplier applied to token prices that we expect from data source e.g. for a 1e8 multiplier, a LINK/USD value of 7.42 will be derived from a data source value of 742000000

View Source
var Zero = big.NewInt(0)

Functions

func CalculateFee

func CalculateFee(tokenPriceInUSD *big.Int, baseUSDFee decimal.Decimal) *big.Int

CalculateFee outputs a fee in wei according to the formula: baseUSDFee * scaleFactor / tokenPriceInUSD

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 FeedIDFromReport added in v0.1.14

func FeedIDFromReport(report ocrtypes.Report) (feedID mercury.FeedID, err error)

func GetConsensusAsk

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

GetConsensusAsk gets the median ask

func GetConsensusBenchmarkPrice

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

GetConsensusBenchmarkPrice gets the median benchmark price

func GetConsensusBid

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

GetConsensusBid gets the median bid

func GetConsensusLinkFee

func GetConsensusLinkFee(paos []PAOLinkFee, f int) (*big.Int, error)

GetConsensusLinkFee gets the median link fee

func GetConsensusMaxFinalizedTimestamp

func GetConsensusMaxFinalizedTimestamp(paos []PAOMaxFinalizedTimestamp, f int) (int64, error)

GetConsensusMaxFinalizedTimestamp returns the highest count with > f observations

func GetConsensusNativeFee

func GetConsensusNativeFee(paos []PAONativeFee, f int) (*big.Int, error)

GetConsensusNativeFee gets the median native fee

func GetConsensusTimestamp

func GetConsensusTimestamp(paos []PAO) uint32

GetConsensusTimestamp gets the median timestamp

func MustEncodeValueInt192

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

func MustHexToConfigDigest added in v0.1.14

func MustHexToConfigDigest(s string) (cd ocrtypes.ConfigDigest)

func NewTransmitter added in v0.1.14

func NewTransmitter(lggr logger.Logger, cfg TransmitterConfig, clients map[string]wsrpc.Client, fromAccountHex string, jobID int32, feedID [32]byte, orm ORM, codec TransmitterReportDecoder, benchmarkPriceDecoder BenchmarkPriceDecoder) *mercuryTransmitter

func ValidateBetween

func ValidateBetween(name string, answer *big.Int, min, max *big.Int) error

ValidateBetween checks that value is between min and max

func ValidateExpiresAt

func ValidateExpiresAt(observationTimestamp uint32, expiresAt uint32) error

func ValidateFee

func ValidateFee(name string, answer *big.Int) error

func ValidateValidFromTimestamp

func ValidateValidFromTimestamp(observationTimestamp uint32, validFromTimestamp uint32) error

Types

type BenchmarkPriceDecoder added in v0.1.14

type BenchmarkPriceDecoder func(ctx context.Context, feedID mercury.FeedID, report ocrtypes.Report) (*big.Int, error)

type ConfigTracker added in v0.1.14

type ConfigTracker interface {
	LatestConfigDetails(ctx context.Context) (changedInBlock uint64, configDigest ocrtypes.ConfigDigest, err error)
}

type EpochRound

type EpochRound struct {
	Epoch uint32
	Round uint8
}

func (EpochRound) Less

func (x EpochRound) Less(y EpochRound) bool

type ORM added in v0.1.14

type ORM interface {
	InsertTransmitRequest(ctx context.Context, serverURLs []string, req *pb.TransmitRequest, jobID int32, reportCtx ocrtypes.ReportContext) error
	DeleteTransmitRequests(ctx context.Context, serverURL string, reqs []*pb.TransmitRequest) error
	GetTransmitRequests(ctx context.Context, serverURL string, jobID int32) ([]*Transmission, error)
	PruneTransmitRequests(ctx context.Context, serverURL string, jobID int32, maxSize int) error
	LatestReport(ctx context.Context, feedID [32]byte) (report []byte, err error)
}

func NewORM added in v0.1.14

func NewORM(ds sqlutil.DataSource) ORM

type OffchainConfig

type OffchainConfig struct {
	ExpirationWindow uint32          `json:"expirationWindow"` // Integer number of seconds
	BaseUSDFee       decimal.Decimal `json:"baseUSDFee"`       // Base USD fee
}

func DecodeOffchainConfig

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

func (OffchainConfig) Encode

func (c OffchainConfig) Encode() ([]byte, error)

type OffchainConfigDigester added in v0.1.14

type OffchainConfigDigester struct {
	FeedID          mercury.FeedID
	ChainID         *big.Int
	ContractAddress common.Address
	Prefix          ocrtypes.ConfigDigestPrefix
}

func NewOffchainConfigDigester added in v0.1.14

func NewOffchainConfigDigester(feedID [32]byte, chainID *big.Int, contractAddress common.Address, prefix ocrtypes.ConfigDigestPrefix) OffchainConfigDigester

func (OffchainConfigDigester) ConfigDigest added in v0.1.14

func (OffchainConfigDigester) ConfigDigestPrefix added in v0.1.14

type PAO

type PAO interface {
	// These fields are common to all observations
	GetTimestamp() uint32
	GetObserver() commontypes.OracleID
	GetBenchmarkPrice() (*big.Int, bool)
}

type PAOAsk

type PAOAsk interface {
	GetAsk() (*big.Int, bool)
}

type PAOBid

type PAOBid interface {
	GetBid() (*big.Int, bool)
}

type PAOLinkFee

type PAOLinkFee interface {
	GetLinkFee() (*big.Int, bool)
}

type PAOMaxFinalizedTimestamp

type PAOMaxFinalizedTimestamp interface {
	GetMaxFinalizedTimestamp() (int64, bool)
}

type PAONativeFee

type PAONativeFee interface {
	GetNativeFee() (*big.Int, bool)
}

type PersistenceManager added in v0.1.14

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

func NewPersistenceManager added in v0.1.14

func NewPersistenceManager(lggr logger.Logger, serverURL string, orm ORM, jobID int32, maxTransmitQueueSize int, flushDeletesFrequency, pruneFrequency time.Duration) *PersistenceManager

func (*PersistenceManager) AsyncDelete added in v0.1.14

func (pm *PersistenceManager) AsyncDelete(req *pb.TransmitRequest)

func (*PersistenceManager) Close added in v0.1.14

func (pm *PersistenceManager) Close() error

func (*PersistenceManager) Delete added in v0.1.14

func (pm *PersistenceManager) Delete(ctx context.Context, req *pb.TransmitRequest) error

func (*PersistenceManager) Insert added in v0.1.14

func (*PersistenceManager) Load added in v0.1.14

func (pm *PersistenceManager) Load(ctx context.Context) ([]*Transmission, error)

func (*PersistenceManager) Start added in v0.1.14

func (pm *PersistenceManager) Start(ctx context.Context) error

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 Transmission added in v0.1.14

type Transmission struct {
	Req       *pb.TransmitRequest    // the payload to transmit
	ReportCtx ocrtypes.ReportContext // contains priority information (latest epoch/round wins)
}

type TransmitQueue added in v0.1.14

type TransmitQueue interface {
	services.Service

	BlockingPop() (t *Transmission)
	Push(req *pb.TransmitRequest, reportCtx ocrtypes.ReportContext) (ok bool)
	Init(transmissions []*Transmission)
	IsEmpty() bool
}

func NewTransmitQueue added in v0.1.14

func NewTransmitQueue(lggr logger.Logger, serverURL, feedID string, maxlen int, asyncDeleter asyncDeleter) TransmitQueue

maxlen controls how many items will be stored in the queue 0 means unlimited - be careful, this can cause memory leaks

type Transmitter added in v0.1.14

type Transmitter interface {
	mercury.Transmitter
	services.Service
}

type TransmitterConfig added in v0.1.14

type TransmitterConfig interface {
	TransmitTimeout() time.Duration
}

type TransmitterReportDecoder added in v0.1.14

type TransmitterReportDecoder interface {
	BenchmarkPriceFromReport(ctx context.Context, report ocrtypes.Report) (*big.Int, error)
	ObservationTimestampFromReport(ctx context.Context, report ocrtypes.Report) (uint32, error)
}

Directories

Path Synopsis
cmd
v2
v3
v4
pb

Jump to

Keyboard shortcuts

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