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.

Solução

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

Como funciona

  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

Exemplos de código

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

Casos de uso

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

Considerações de segurança

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

Implementações reais

Ergo Oracle Pools

ERG/USD price feed

Recursos

Considerações de taxas

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

Aprimore suas habilidades em ErgoScript

Receba notificações sobre novos padrões, tutoriais e recursos para desenvolvedores.

Follow for daily updates