This example demonstrates building a decentralized price oracle that aggregates price data from multiple blockchains using Apex SDK’s unified interface.
Traditional price oracles are ecosystem-specific:
This creates data silos and prevents true cross-chain price discovery.
Apex SDK enables building oracles that:
This example implements a production-ready oracle that:
cd examples/price-oracle
cargo run
// Query Substrate DEX
let substrate_price = query_hydration_price(&sdk).await?;
// Query EVM DEX
let ethereum_price = query_uniswap_price(&sdk).await?;
// Same SDK, different ecosystems!
let aggregated = AggregatedPrice {
median_price_usd: calculate_median(&all_feeds),
vwap_price_usd: calculate_vwap(&all_feeds),
confidence_score: calculate_confidence(&all_feeds),
// ...
};
if aggregated.detect_manipulation(&all_feeds) {
// Use median with higher confidence threshold
// Flag suspicious sources
// Alert monitoring systems
}
// Publish to Substrate
sdk.execute(substrate_oracle_tx).await?;
// Publish to Ethereum
sdk.execute(ethereum_oracle_tx).await?;
// Same publication flow!
This architecture enables:
| Feature | Single-Chain Oracle | Cross-Chain Oracle (Apex SDK) |
|---|---|---|
| Data Sources | 1 ecosystem | 2+ ecosystems |
| Manipulation Resistance | Medium | High (cross-validation) |
| Liquidity Coverage | Limited | Comprehensive |
| Failure Points | Single chain | Multiple chains (redundancy) |
| Price Discovery | Local | Global |
┌─────────────┐ ┌──────────────┐
│ polkadot.js │────▶│ Substrate │
│ (Node.js) │ │ Price Feeds │
└─────────────┘ └──────────────┘
↓
┌─────────────┐
│ Bridge/ │
│ Aggregator │
└─────────────┘
↓
┌─────────────┐ ┌──────────────┐
│ ethers.js │────▶│ Ethereum │
│ (Node.js) │ │ Price Feeds │
└─────────────┘ └──────────────┘
Problems:
┌─────────────┐
│ Apex SDK │
│ (Rust) │
└──────┬──────┘
│
┌─────────┴─────────┐
▼ ▼
┌──────────┐ ┌──────────┐
│Substrate │ │ EVM │
│ Prices │ │ Prices │
└──────────┘ └──────────┘
Benefits: