mercury

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const ByteWidthInt192 = 24

Bounds on an int192

View Source
const EvmHashLen = 32

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

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

type EpochRound struct {
	Epoch uint32
	Round uint8
}

func (EpochRound) Less

func (x EpochRound) Less(y EpochRound) bool

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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