pyth

package
v1.3.51 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "pyth_api"

	URL = "http://localhost:8444/prices"

	// SolanaFormatMagic is the Pyth Lazer Solana format magic (LE u32).
	SolanaFormatMagic uint32 = 0x821a01b9
)
View Source
const (
	// PythPubKeyEnv is the environment variable holding the trusted Pyth
	// signer public key (base58-encoded Solana ed25519 public key).
	PythPubKeyEnv = "PYTH_PUB_KEY"
)

Variables

View Source
var DefaultAPIConfig = config.APIConfig{
	Name:             Name,
	Atomic:           false,
	Enabled:          true,
	Timeout:          3000 * time.Millisecond,
	Interval:         3000 * time.Millisecond,
	ReconnectTimeout: 2000 * time.Millisecond,
	MaxQueries:       1,
	Endpoints:        []config.Endpoint{{URL: URL}},
}

Functions

func NewAPIHandler

func NewAPIHandler(
	api config.APIConfig,
) (types.PriceAPIDataHandler, error)

NewAPIHandler returns a new Pyth PriceAPIDataHandler.

func VerifyPythSolanaSignature

func VerifyPythSolanaSignature(payloadBase64 string) error

VerifyPythSolanaSignature decodes the base64 Pyth Lazer Solana-format payload, verifies the ed25519 signature, and checks that the embedded public key matches the trusted key from PYTH_PUB_KEY.

Payload layout (Pyth Lazer "solana" format):

[0..4)    magic     – LE u32, must be 0x821a01b9
[4..68)   signature – 64-byte ed25519 signature
[68..100) pubkey    – 32-byte ed25519 public key
[100..102) msgLen   – LE u16, length of signed message
[102..102+msgLen)   – signed message bytes

Types

type APIHandler

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

APIHandler implements the PriceAPIDataHandler interface for Pyth.

func (*APIHandler) CreateURL

func (h *APIHandler) CreateURL(
	tickers []types.ProviderTicker,
) (string, error)

CreateURL returns the URL used to fetch prices from the Pyth oracle service. Feed IDs are passed as a comma-separated "asset" query parameter, with "&provider=pyth" appended.

func (*APIHandler) ParseResponse

func (h *APIHandler) ParseResponse(
	tickers []types.ProviderTicker,
	resp *http.Response,
) types.PriceResponse

ParseResponse parses a batch Pyth API response ({"data": [...]}), verifies each entry's Pyth Solana ed25519 signature, and returns the parsed prices.

type BatchPriceResponse

type BatchPriceResponse struct {
	Data []PriceResponse `json:"data"`
}

BatchPriceResponse is the top-level response containing prices for multiple feeds.

type PriceResponse

type PriceResponse struct {
	Market            string `json:"market"`
	Price             string `json:"price"`
	TimestampMs       int64  `json:"timestampMs"`
	PythSolanaPayload string `json:"pythSolanaPayload"`
}

PriceResponse is a single feed entry within the batch response.

Jump to

Keyboard shortcuts

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