ERGO
Oracle Integration
Advanced
1-2 weeks

Oracle Pool Aggregation & Medianization

Build an Oracle Pool that aggregates multiple data points and publishes median

GitHub

问题

You need to provide reliable, manipulation-resistant data feeds by aggregating multiple data sources.

解决方案

Oracle pools collect data points from multiple operators, calculate median/aggregate, and publish to a single canonical box that consumers can trust.

工作原理

  1. 1Multiple oracle operators submit data points to individual boxes
  2. 2Each operator stakes collateral as commitment
  3. 3Aggregator contract collects all data points
  4. 4Median (or other aggregation) is calculated
  5. 5Result is published to canonical oracle box with pool NFT
  6. 6Operators who deviate significantly can be slashed

代码示例

{
  // Individual oracle operator submission
  // R4: Data value (e.g., price)
  // R5: Timestamp (block height)
  // R6: Operator public key
  // R7: Signature of data (for accountability)
  
  val operatorNFT = SELF.tokens(0)._1  // Operator identity
  val dataValue = SELF.R4[Long].get
  val submissionHeight = SELF.R5[Int].get
  val operatorPK = SELF.R6[SigmaProp].get
  
  // Data must be recent (within 5 blocks of current height)
  val isRecent = HEIGHT - submissionHeight < 5
  
  // Operator can update their data point
  val operatorUpdate = {
    val newBox = OUTPUTS(0)
    newBox.tokens(0)._1 == operatorNFT &&
    newBox.R5[Int].get == HEIGHT &&
    operatorPK
  }
  
  // Aggregator can consume for pool update
  val aggregatorConsume = {
    val poolBox = OUTPUTS(0)
    val poolNFT = fromBase64("ORACLE_POOL_NFT")
    poolBox.tokens(0)._1 == poolNFT
  }
  
  isRecent && (operatorUpdate || aggregatorConsume)
}

Individual operator submission box. Operators update their data points, aggregator collects them for pool update.

使用场景

  • Price feed oracles
  • Weather data for insurance
  • Sports scores for betting
  • Random number generation
  • Cross-chain data bridges

安全注意事项

  • !Require minimum number of operators for updates
  • !Implement slashing for malicious operators
  • !Use median to resist outlier manipulation
  • !Monitor for coordinated attacks
  • !Consider time-weighted averages for critical data

实际项目应用

Ergo Oracle Pools

ERG/USD price feed

参考资源

手续费说明

Operators pay for submission transactions. Consider reward mechanisms to incentivize honest participation.

提升你的 ErgoScript 技能

获取新模式、教程和开发者资源的最新通知。

Follow for daily updates