evm

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const PluginVersion uint32 = 1 // the legacy mercury plugin is 0
View Source
const Precision int32 = 18

NOTE: Inexact divisions will have this degree of precision

View Source
const ZeroBytesSentinel = "bytes0"

Variables

View Source
var (
	BaseSchemaUint32 = getBaseSchema("uint32")
	BaseSchemaUint64 = getBaseSchema("uint64")
)

BaseSchema represents the fixed base schema that remains unchanged for all EVMABIEncodeUnpacked reports.

An arbitrary payload will be appended to this.

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 File_evm_streamlined_proto protoreflect.FileDescriptor
View Source
var (
	PayloadTypes = getPayloadTypes()
)

Functions

func CalculateFee

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

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

func ClampReportRange

func ClampReportRange(r logger.Logger, report protocol.Report, maxReportRange protocol.Duration) uint64

ClampReportRange clamps the report range to the max report range if it exceeds the max range. Returns the clamped valid after nanoseconds. If the report range is within the max range, returns the valid after nanoseconds unchanged. If the max report range is not specified, uses the default max report range. A non-positive maxReportRange falls back to the default; Verify rejects negative values in channel definitions, but a definition committed before that check existed could still carry one.

func EncodePackedBigInt

func EncodePackedBigInt(value *big.Int, typeStr string) ([]byte, error)

EncodePackedBigInt converts a *big.Int to packed EVM bytes according to the Solidity type. For unsigned types ("uintN"), the value must be non-negative and fit in N bits. For signed types ("intN"), the value must be between -2^(N-1) and 2^(N-1)-1; then the function returns the two's complement representation in N bits.

func EncodePaddedBigInt

func EncodePaddedBigInt(v *big.Int, t string) (b []byte, err error)

func ExtractReportValues

func ExtractReportValues(report protocol.Report) (nativePrice, linkPrice decimal.Decimal, quote *protocol.Quote, err error)

ExtractReportValues extracts the native price, link price and quote from the report Can handle either *Decimal or *Quote types for native/link prices

func ExtractTimestamps

func ExtractTimestamps(report protocol.Report) (validAfterSeconds, observationTimestampSeconds uint32, err error)

Extracts nanosecond timestamps as uint32 number of seconds

func LLOExtraHash

func LLOExtraHash(donID uint32) common.Hash

Uniquely identifies this as LLO plugin, rather than the legacy plugin (which uses all zeroes).

This is quite a hack but serves the purpose of uniquely identifying dons/plugin versions to the mercury server without having to modify any existing tooling or breaking backwards compatibility. It should be safe since the DonID is encoded into the config digest anyway so report context is already dependent on it, and all LLO jobs in the same don are expected to have the same don ID set.

Packs donID+pluginVersion as (uint32, uint32), for example donID=2, PluginVersion=1 Yields: 0x0000000000000000000000000000000000000000000000000000000200000001

func LegacyReportContext

func LegacyReportContext(cd ocr2types.ConfigDigest, seqNr uint64, donID uint32) (ocr2types.ReportContext, error)

func SeqNrToEpochAndRound

func SeqNrToEpochAndRound(seqNr uint64) (epoch uint32, round uint8, err error)

Types

type ABIEncoder

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

An ABIEncoder encodes exactly one stream value into a byte slice

func (ABIEncoder) EncodePacked

func (a ABIEncoder) EncodePacked(sv protocol.StreamValue) ([]byte, error)

func (ABIEncoder) EncodePadded

func (a ABIEncoder) EncodePadded(sv protocol.StreamValue) ([]byte, error)

func (ABIEncoder) MarshalJSON

func (a ABIEncoder) MarshalJSON() ([]byte, error)

func (*ABIEncoder) UnmarshalJSON

func (a *ABIEncoder) UnmarshalJSON(data []byte) error

type BaseReportFields

type BaseReportFields struct {
	FeedID             common.Hash
	ValidFromTimestamp uint64
	Timestamp          uint64
	NativeFee          *big.Int
	LinkFee            *big.Int
	ExpiresAt          uint64
}

type LLOEVMStreamlinedReportWithContext

type LLOEVMStreamlinedReportWithContext struct {
	ConfigDigest  []byte `protobuf:"bytes,1,opt,name=config_digest,json=configDigest,proto3" json:"config_digest,omitempty"`
	SeqNr         uint64 `protobuf:"varint,2,opt,name=seq_nr,json=seqNr,proto3" json:"seq_nr,omitempty"`
	PackedPayload []byte `protobuf:"bytes,3,opt,name=packed_payload,json=packedPayload,proto3" json:"packed_payload,omitempty"`
	// contains filtered or unexported fields
}

func (*LLOEVMStreamlinedReportWithContext) Descriptor deprecated

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

Deprecated: Use LLOEVMStreamlinedReportWithContext.ProtoReflect.Descriptor instead.

func (*LLOEVMStreamlinedReportWithContext) GetConfigDigest

func (x *LLOEVMStreamlinedReportWithContext) GetConfigDigest() []byte

func (*LLOEVMStreamlinedReportWithContext) GetPackedPayload

func (x *LLOEVMStreamlinedReportWithContext) GetPackedPayload() []byte

func (*LLOEVMStreamlinedReportWithContext) GetSeqNr

func (*LLOEVMStreamlinedReportWithContext) ProtoMessage

func (*LLOEVMStreamlinedReportWithContext) ProtoMessage()

func (*LLOEVMStreamlinedReportWithContext) ProtoReflect

func (*LLOEVMStreamlinedReportWithContext) Reset

func (*LLOEVMStreamlinedReportWithContext) String

type ReportCodecEVMABIEncodeUnpacked

type ReportCodecEVMABIEncodeUnpacked struct {
	logger.Logger
	// contains filtered or unexported fields
}

func NewReportCodecEVMABIEncodeUnpacked

func NewReportCodecEVMABIEncodeUnpacked(lggr logger.Logger, donID uint32) ReportCodecEVMABIEncodeUnpacked

func (ReportCodecEVMABIEncodeUnpacked) Encode

func (ReportCodecEVMABIEncodeUnpacked) FeedID added in v1.1.1

FeedID implements protocol.FeedIDer: these reports always carry a feed ID, and Verify has already rejected a zero one.

func (ReportCodecEVMABIEncodeUnpacked) Verify

type ReportCodecEVMABIEncodeUnpackedExpr

type ReportCodecEVMABIEncodeUnpackedExpr struct {
	logger.Logger
	// contains filtered or unexported fields
}

func NewReportCodecEVMABIEncodeUnpackedExpr

func NewReportCodecEVMABIEncodeUnpackedExpr(lggr logger.Logger, donID uint32) ReportCodecEVMABIEncodeUnpackedExpr

func (ReportCodecEVMABIEncodeUnpackedExpr) Encode

func (ReportCodecEVMABIEncodeUnpackedExpr) FeedID added in v1.1.1

FeedID implements protocol.FeedIDer: these reports always carry a feed ID, and Verify has already rejected a zero one.

func (ReportCodecEVMABIEncodeUnpackedExpr) Verify

func (ReportCodecEVMABIEncodeUnpackedExpr) VerifyForAdmission added in v1.1.1

VerifyForAdmission implements protocol.AdmissionVerifier: it rejects statically invalid expressions before the definition can reach consensus. An expression that cannot be analyzed can never produce a value, so the channel would be installed and then never report.

This is not part of Verify because definitions committed before the check existed may fail it, and rejecting those would stop every oracle from observing rather than just stopping that one channel from reporting.

Like Verify it runs on an untrusted definition and is a pure function of it: this parses and analyzes only, with no stream values and no state.

nil opts cache: the definition is given directly, so the opts are decoded from it rather than looked up.

type ReportCodecEVMStreamlined

type ReportCodecEVMStreamlined struct {
	logger.Logger
}

func NewReportCodecStreamlined

func NewReportCodecStreamlined(lggr logger.Logger) ReportCodecEVMStreamlined

func (ReportCodecEVMStreamlined) Encode

func (rc ReportCodecEVMStreamlined) Encode(r protocol.Report, cd llotypes.ChannelDefinition, optsCache *protocol.OptsCache) (payload []byte, err error)

func (ReportCodecEVMStreamlined) FeedID added in v1.1.1

FeedID implements protocol.FeedIDer. The feed ID is optional for this format: a channel that omits it identifies its payload by channel ID instead, so it has no feed ID to check for uniqueness.

func (ReportCodecEVMStreamlined) Pack

func (ReportCodecEVMStreamlined) Verify

type ReportCodecPremiumLegacy

type ReportCodecPremiumLegacy struct {
	logger.Logger
	// contains filtered or unexported fields
}

func NewReportCodecPremiumLegacy

func NewReportCodecPremiumLegacy(lggr logger.Logger, donID uint32) ReportCodecPremiumLegacy

func (ReportCodecPremiumLegacy) Decode

func (r ReportCodecPremiumLegacy) Decode(b []byte) (*v3.Report, error)

func (ReportCodecPremiumLegacy) Encode

func (ReportCodecPremiumLegacy) FeedID added in v1.1.1

FeedID implements protocol.FeedIDer: premium legacy reports always carry a feed ID, and Verify has already rejected a zero one.

func (ReportCodecPremiumLegacy) Pack

Pack assembles the report values into a payload for verifying on-chain

func (ReportCodecPremiumLegacy) Verify

type ReportFormatEVMABIEncodeOpts

type ReportFormatEVMABIEncodeOpts struct {
	// BaseUSDFee is the cost on-chain of verifying a report
	BaseUSDFee decimal.Decimal `json:"baseUSDFee"`
	// Expiration window is the length of time in seconds the report is valid
	// for, from the observation timestamp
	ExpirationWindow uint32 `json:"expirationWindow"`
	// FeedID is for compatibility with existing on-chain verifiers
	FeedID common.Hash `json:"feedID"`
	// ABI defines the encoding of the payload. Each element maps to exactly
	// one stream (although sub-arrays may be specified for streams that
	// produce a composite data type).
	//
	// EXAMPLE
	//
	// [{"multiplier":"10000","type":"uint192"}, ...]
	//
	// See definition of ABIEncoder struct for more details.
	//
	// The total number of streams must be 2+n, where n is the number of
	// top-level elements in this ABI array (stream 0 is always the native
	// token price and stream 1 is the link token price).
	ABI []ABIEncoder `json:"abi"`
	// TimeResolution is the resolution of the timestamps in the report.
	// Seconds use uint32 ABI encoding, while milliseconds/microseconds/nanoseconds use uint64.
	// Defaults to "s" (seconds) if not specified.
	TimeResolution protocol.TimeResolution `json:"TimeResolution,omitempty"`
	// MaxReportRange is the maximum range of the report.
	// The range will be limited to ObservationTimestamp + MaxReportRange if the report is longer than the max range.
	// Defaults to 5 minutes if not specified.
	MaxReportRange protocol.Duration `json:"maxReportRange,omitempty"`
}

Opts format remains unchanged

func (*ReportFormatEVMABIEncodeOpts) Decode

func (r *ReportFormatEVMABIEncodeOpts) Decode(opts []byte) error

func (*ReportFormatEVMABIEncodeOpts) Encode

func (r *ReportFormatEVMABIEncodeOpts) Encode() ([]byte, error)

type ReportFormatEVMPremiumLegacyOpts

type ReportFormatEVMPremiumLegacyOpts struct {
	// BaseUSDFee is the cost on-chain of verifying a report
	BaseUSDFee decimal.Decimal `json:"baseUSDFee"`
	// Expiration window is the length of time in seconds the report is valid
	// for, from the observation timestamp
	ExpirationWindow uint32 `json:"expirationWindow"`
	// FeedID is for compatibility with existing on-chain verifiers
	FeedID common.Hash `json:"feedID"`
	// Multiplier is used to scale the bid, benchmark and ask values in the
	// report. If not specified, or zero is used, a multiplier of 1 is assumed.
	Multiplier *ubig.Big `json:"multiplier"`
	// MaxReportRange is the maximum range of the report.
	// The range will be limited to ObservationTimestamp + MaxReportRange if the report is longer than the max range.
	// Defaults to 5 minutes if not specified.
	MaxReportRange protocol.Duration `json:"maxReportRange,omitempty"`
}

func (*ReportFormatEVMPremiumLegacyOpts) Decode

func (r *ReportFormatEVMPremiumLegacyOpts) Decode(opts []byte) error

type ReportFormatEVMStreamlinedOpts

type ReportFormatEVMStreamlinedOpts struct {
	// FeedID is optional. If unspecified, the uint32 channel ID will be used
	// instead to identify the payload.
	FeedID *common.Hash `json:"feedID,omitempty"`
	// ABI defines the encoding of the payload. Each element maps to exactly
	// one stream (although sub-arrays may be specified for streams that
	// produce a composite data type).
	//
	// EXAMPLE
	//
	// [{"multiplier":"10000","type":"uint192"}, ...]
	//
	// See definition of ABIEncoder struct for more details.
	//
	// The total number of streams must be n, where n is the number of
	// top-level elements in this ABI array
	ABI []ABIEncoder `json:"abi"`
	// MaxReportRange is the maximum range of the report.
	// The range will be limited to ObservationTimestamp + MaxReportRange if the report is longer than the max range.
	// Defaults to 5 minutes if not specified.
	MaxReportRange protocol.Duration `json:"maxReportRange,omitempty"`
}

func (*ReportFormatEVMStreamlinedOpts) Decode

func (r *ReportFormatEVMStreamlinedOpts) Decode(opts []byte) error

func (*ReportFormatEVMStreamlinedOpts) Encode

func (r *ReportFormatEVMStreamlinedOpts) Encode() ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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