mcpField
P
pyth-price-feeds

pyth-price-feeds

github.com/hedera-devDevelopment28464 installsUpdated 8w ago
Repository

About pyth-price-feeds

pyth-price-feeds is an implementation and review guide for Hedera smart contract developers using Pyth price feeds. It explains submitting Hermes updates, reading age-bounded prices, and validating confidence and exponent values.

Key features

  1. 01Submit price updates through Hermes
  2. 02Pay update fees before reading prices
  3. 03Read prices with a maximum-age limit
  4. 04Validate price and confidence values
  5. 05Normalize values using the signed exponent

Use cases

  1. 01Update Pyth prices in Hedera contracts
  2. 02Read prices within a defined freshness bound
  3. 03Review confidence values and exponent conversions

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/hedera-dev/hedera-skills --skill pyth-price-feeds

After installing, type/pyth-price-feedsin Claude Code to confirm it loaded.

Bundled filesreferences/examples.mdreferences/hedera-feeds.md

Details

From the project README

Pyth Price Feeds (Hedera)

Pull pattern: Pyth is not a fire-and-forget push feed. Fresh reads usually need a Hermes payload submitted on-chain (payable) before getPriceNoOlderThan.

Hermes → updatePriceFeeds{value: fee}(updateData) → getPriceNoOlderThan(priceId, maxAge)

Consumers may wrap Pyth behind a local interface; that is optional. Do not assume a project-specific adapter name.

Quick Reference

PieceRole
Pyth contractNetwork IPyth address
Price IDbytes32 feed id (not an aggregator address)
UpdatePayable updatePriceFeeds with Hermes updateData
FeegetUpdateFee(updateData) — msg.value must cover it
ReadgetPriceNoOlderThan(priceId, maxAge)
ConfidenceReject when conf > uint64(price)
ScaleSigned price + expo → consumer decimals (often 18)

Hedera chain IDs: testnet 296, mainnet 295.

See references/hedera-feeds.md for where to source the Pyth contract and price IDs. See references/examples.md for update / read / expo sketches.

Critical: Update Before Fresh Reads

If the on-chain price is older than your staleness bound, fetch Hermes update data and submit it:

function updatePrice(bytes[] calldata updateData) external payable {
    uint256 fee = PYTH.getUpdateFee(updateData);
    if (msg.value < fee) revert UpdateFeeTooLow(msg.value, fee);
    PYTH.updatePriceFeeds{ value: msg.value }(updateData);
}

Hedera msg.value is tinybars via JSON-RPC — attach enough native value for the Pyth fee. Do not treat a stale getPriceUnsafe as a valid trading price.

Critical: Confidence And Signed Expo

After getPriceNoOlderThan:

CheckWhy
publishTime != 0Incomplete
price > 0Invalid / non-positive
conf > uint64(price)Confidence wider than the price
Normalize expoexpo is signed; not the same as ERC-20 decimals
PythStructs.Price memory price = PYTH.getPriceNoOlderThan(priceId, maxStaleness);
if (price.publishTime == 0) revert IncompleteRound();
if (price.price <= 0) revert InvalidPrice();
if (price.conf > uint64(price.price)) revert InvalidConfidence();

Checklist

When implementing or reviewing Pyth on Hedera:

  • Pyth contract + price IDs taken from Pyth Hedera / Hermes docs (not Ethereum defaults)
  • Hermes payloads submitted with sufficient msg.value before relying on a fresh price
  • Reads use getPriceNoOlderThan (or equivalent max-age API), not unbounded unsafe prices for trading
  • Confidence wider than price reverts
  • Signed expo normalized to the consumer scale
  • Chain ID is 295 or 296 (or the project’s documented Hedera network)

References

Comments

Markdown supported