ERGO
Oracle Integration
Advanced
1-2 weeks

Oracle Pool Aggregation & Medianization

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

GitHub

Problema

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

Soluzione

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

Come funziona

  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

Esempi di codice

{
  // 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.

Casi d'uso

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

Considerazioni sulla sicurezza

  • !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

Implementazioni reali

Ergo Oracle Pools

ERG/USD price feed

Risorse

Considerazioni sulle commissioni

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

Migliora le tue competenze ErgoScript

Ricevi notifiche su nuovi pattern, tutorial e risorse per sviluppatori.

Follow for daily updates