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