pyth-price-feeds

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Pyth Price Feeds (Hedera)

Pyth 价格馈送(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
.
text
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.
拉取模式: Pyth 不是“即发即弃”的推送式馈送。要读取最新价格,通常需要先在链上提交(需付费)Hermes payload,再调用
getPriceNoOlderThan
。
text
Hermes → updatePriceFeeds{value: fee}(updateData) → getPriceNoOlderThan(priceId, maxAge)
调用方可将Pyth封装在本地接口之后,这是可选操作。请勿默认存在特定项目的适配器名称。

Quick Reference

快速参考

PieceRole
Pyth contractNetwork
IPyth
address
Price ID
bytes32
feed id (not an aggregator address)
UpdatePayable
updatePriceFeeds
with Hermes
updateData
Fee
getUpdateFee(updateData)
—
msg.value
must cover it
Read
getPriceNoOlderThan(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.
组件作用
Pyth 合约网络上的
IPyth
地址
Price ID
bytes32
类型的馈送ID(不是聚合器地址)
更新需付费的
updatePriceFeeds
调用,传入 Hermes 的
updateData
费用通过
getUpdateFee(updateData)
获取,
msg.value
必须足额覆盖
读取调用
getPriceNoOlderThan(priceId, maxAge)
置信度当
conf > uint64(price)
时应拒绝
数值缩放带符号的
price
+
expo
→ 调用方所需的小数位数(通常为18位)
Hedera 链ID: 测试网
296
,主网
295
。
关于Pyth合约和Price ID的获取方式,请参阅 references/hedera-feeds.md。关于更新、读取、expo处理的示例代码,请参阅 references/examples.md。

Critical: Update Before Fresh Reads

核心注意事项:读取最新价格前必须先更新

If the on-chain price is older than your staleness bound, fetch Hermes update data and submit it:
solidity
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.
如果链上价格的陈旧度超过你的容忍阈值,请获取Hermes更新数据并提交:
solidity
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上,通过JSON-RPC传递的
msg.value
单位为tinybars——请附加足够的原生代币以支付Pyth费用。请勿将过期的
getPriceUnsafe
返回值作为有效交易价格使用。

Critical: Confidence And Signed Expo

核心注意事项:置信度与带符号expo

After
getPriceNoOlderThan
:
CheckWhy
publishTime != 0
Incomplete
price > 0
Invalid / non-positive
conf > uint64(price)
Confidence wider than the price
Normalize
expo
expo
is signed; not the same as ERC-20 decimals
solidity
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();
调用
getPriceNoOlderThan
之后需检查:
检查项原因
publishTime != 0
数据不完整
price > 0
价格无效/为非正值
conf > uint64(price)
置信区间宽度超过价格本身
标准化
expo
expo
为带符号值,与 ERC-20 的小数位数规则不同
solidity
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)
在Hedera上实现或审核Pyth集成时,请确认:
  • Pyth 合约和Price ID取自Pyth Hedera / Hermes官方文档(而非Ethereum默认值)
  • 在依赖最新价格之前,已提交Hermes payload并附带足额的
    msg.value
  • 读取操作使用
    getPriceNoOlderThan
    (或等效的带最大陈旧时间限制的API),而非用于交易的无限制不安全价格
  • 置信度超过价格时会触发回滚
  • 带符号的
    expo
    已标准化为调用方所需的数值精度
  • 链ID为
    295
    或
    296
    (或项目文档中指定的Hedera网络)

References

参考资料