Oracle Integration
Advanced
1-2 weeksАгрегация пула Oracle & Медианизация
Build an Oracle Pool that aggregates multiple data points and publishes median
Problem
You need to provide reliable, manipulation-resistant data feeds by aggregating multiple data sources.
Solution
Oracle pools collect data points from multiple operators, calculate median/aggregate, and publish to a single canonical box that consumers can trust.
How It Works
- 1Multiple oracle operators submit data points to individual boxes
- 2Each operator stakes collateral as commitment
- 3Aggregator contract collects all data points
- 4Median (or other aggregation) is calculated
- 5Result is published to canonical oracle box with pool NFT
- 6Operators who deviate significantly can be slashed
Code Examples
{
// 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.
Use Cases
- →Price feed oracles
- →Weather data for insurance
- →Sports scores for betting
- →Random number generation
- →Cross-chain data bridges
Security Considerations
- !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
Resources
Fee Considerations
Operators pay for submission transactions. Consider reward mechanisms to incentivize honest participation.