chainlink-data-feeds

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Chainlink Data Feeds (Hedera)

Chainlink Data Feeds(Hedera)

Push feed pattern: a Chainlink aggregator is updated off-chain; on-chain readers call
latestRoundData()
and must reject incomplete, non-positive, or stale rounds.
text
Chainlink DON → AggregatorV3Interface feed → consumer latestRoundData()
Consumers may wrap the feed behind a local interface; that is optional. Do not assume a project-specific adapter name.
推送式喂价模式: Chainlink聚合器在链下更新;链上调用方调用
latestRoundData()
,且必须拒绝不完整、非正或过时的轮次数据。
text
Chainlink DON → AggregatorV3Interface feed → consumer latestRoundData()
调用方可以将喂价封装在本地接口后;这是可选操作。请勿假定存在项目特定的适配器名称。

Quick Reference

快速参考

PieceRole
AggregatorV3Interface
latestRoundData()
+
decimals()
Round completeness
answeredInRound >= roundId
and
updatedAt != 0
Price
answer > 0
(feeds are typically signed
int256
)
FreshnessCompare
block.timestamp - updatedAt
to a max staleness
ScaleNormalize feed decimals to the consumer’s scale (often 18)
Pair identityPrefer canonical uppercase symbols (
HBAR
,
USD
) if you hash pair keys
Hedera chain IDs: testnet
296
, mainnet
295
.
See references/hedera-feeds.md for where to source Hedera feed addresses. See references/examples.md for read and normalize sketches.
项作用
AggregatorV3Interface
提供
latestRoundData()
+
decimals()
方法
轮次完整性
answeredInRound >= roundId
且
updatedAt != 0
价格
answer > 0
(喂价通常为有符号
int256
类型)
新鲜度将
block.timestamp - updatedAt
与最大允许过时时长对比
数值刻度将喂价小数位数标准化为调用方的刻度(通常为18位)
交易对标识若对交易对键做哈希,优先使用标准大写符号(
HBAR
、
USD
)
Hedera链ID: 测试网
296
,主网
295
。
获取Hedera喂价地址的方式请参考references/hedera-feeds.md。读取与标准化示例请参考references/examples.md。

Critical: Completeness Then Staleness

关键注意点:先校验完整性,再校验时效性

Never return a price from a missing or unfinished round. Revert when:
ConditionWhy
answeredInRound < roundId
Aggregator has not finished this round
updatedAt == 0
No successful update
answer <= 0
Invalid / non-positive price
block.timestamp - updatedAt > maxStaleness
Stale for this consumer
solidity
(uint80 roundId, int256 answer,, uint256 updatedAt, uint80 answeredInRound) =
    feed.latestRoundData();

if (answeredInRound < roundId || updatedAt == 0) revert IncompleteRound();
if (answer <= 0) revert InvalidPrice();
if (block.timestamp - updatedAt > maxStaleness) revert StalePrice(updatedAt, maxStaleness);
切勿返回缺失或未完成轮次的价格。出现以下情况时应回滚交易:
条件原因
answeredInRound < roundId
聚合器尚未完成本轮更新
updatedAt == 0
无成功更新记录
answer <= 0
价格无效/非正
block.timestamp - updatedAt > maxStaleness
对该调用方而言数据已过时
solidity
(uint80 roundId, int256 answer,, uint256 updatedAt, uint80 answeredInRound) =
    feed.latestRoundData();

if (answeredInRound < roundId || updatedAt == 0) revert IncompleteRound();
if (answer <= 0) revert InvalidPrice();
if (block.timestamp - updatedAt > maxStaleness) revert StalePrice(updatedAt, maxStaleness);

Critical: Hedera Feeds, Not Ethereum Addresses

关键注意点:使用Hedera专属喂价,而非以太坊地址

Do not copy Ethereum mainnet aggregator addresses onto Hedera. Look up Hedera-specific Data Feed addresses for chain
295
/
296
and re-check docs before mainnet.
Pair maps (if you use them) should be constructor-only unless the project explicitly supports post-deploy updates.
切勿将以太坊主网的聚合器地址复用到Hedera上。请查询链ID
295
/
296
对应的Hedera专属Data Feed地址,并在主网上线前重新核对文档。
交易对映射(若使用)应仅在构造函数中初始化,除非项目明确支持部署后更新。

Decimal Normalization

小数位数标准化

feed.decimals()
is often 8. Convert to the scale your app uses before arithmetic:
solidity
uint256 price = normalizeToScale(uint256(answer), feed.decimals(), /* target */ 18);
Keep conversion rounding explicit (usually round down). Do not mix raw aggregator units with 18-decimal amounts.
feed.decimals()
通常为8。在进行计算前,请将其转换为你的应用使用的刻度:
solidity
uint256 price = normalizeToScale(uint256(answer), feed.decimals(), /* target */ 18);
转换时需明确舍入规则(通常向下取整)。请勿将原始聚合器单位与18位小数的金额混用。

Checklist

检查清单

When implementing or reviewing Chainlink reads on Hedera:
  • Feed address taken from Hedera Data Feeds docs (not Ethereum)
  • latestRoundData
    completeness checks before using
    answer
  • Non-positive prices revert
  • Staleness bound is enforced
  • Decimals normalized to the consumer scale
  • Chain ID is
    295
    or
    296
    (or the project’s documented Hedera network)
在Hedera上实现或审核Chainlink喂价读取逻辑时:
  • 喂价地址取自Hedera Data Feeds文档(而非以太坊)
  • 使用
    answer
    前已完成
    latestRoundData
    的完整性校验
  • 非正价格会触发回滚
  • 已强制执行时效性限制
  • 小数位数已标准化为调用方的刻度
  • 链ID为
    295
    或
    296
    (或项目文档规定的Hedera网络)

References

参考资料