This Oracle Program fetches price data from the Pyth API and provides it to the SEDA network. It demonstrates how to integrate external price feeds with SEDA's decentralized oracle infrastructure.
This Oracle Program is built from the SEDA starter kit and implements a complete Pyth Network price feed solution:
- Fetches Real-Time Price Data: Connects to Pyth Network's API via SEDA's data proxy (
pyth.proxy.testnet.seda.xyz) to retrieve live price information for any supported asset - Handles Price Formatting: Properly converts Pyth's raw price data by applying the exponent system - scales prices to 6 decimal precision for consistent formatting
- Ensures Data Integrity: Uses SEDA's consensus mechanism with multiple executors to prevent manipulation and ensure reliable data
- Calculates Median Prices: Aggregates results from multiple sources and calculates the median for maximum reliability and resistance to outliers
- Provides EVM Integration: Includes smart contracts for seamless integration with Ethereum-compatible blockchains
- Precision: Converts Pyth's variable exponent format to fixed 6 decimal places (e.g.,
45127616withexpo: -5becomes451.276160) - Data Proxy: Uses SEDA's secure proxy infrastructure for external API calls to prevent censorship and ensure reliability
- Consensus: Supports multiple reveals with median calculation for robust price determination
- Integer Arithmetic: Uses u128 for precise calculations to avoid floating-point precision issues
Network: SEDA Testnet
Program ID: cf98370a6bdf3f9f7eaefe282ac3f5979dec8a284965a119edbd3c1495b3a32a
Explorer: View on SEDA Explorer
Note
This Oracle Program is built from the SEDA starter kit. For detailed setup instructions, requirements, and advanced usage, see the starter kit documentation.
# Build the Oracle Program
bun run build
# Run tests
bun run test
# Deploy to SEDA network
bun run deploy
# Submit a data request
bun run post-drThis Pyth Network Oracle Program consists of the following key components:
-
src/main.rs: The entry point that coordinates both the execution and tally phases of the Data Request. -
src/execution_phase.rs: Fetches price data from the Pyth Network API via SEDA's data proxy using a single price feed ID. Converts Pyth's raw price (with exponent) to a scaled 6-decimal precision value using integer arithmetic. Outputs the result as a u128 value in little-endian byte format. Each executor runs this phase independently. -
src/tally_phase.rs: Aggregates revealed results from all executors (parsed as u128 little-endian values), validates each reveal, and calculates the median price. This deterministic phase ensures consensus by filtering invalid reveals and outputting the final median value as u128 little-endian bytes. -
src/fetch_pyth.rs: Contains the Pyth Network API integration logic, including data structures for parsing Pyth's response format and the HTTP client for fetching price data.
The Oracle Program expects a single Pyth Network price feed ID as input (e.g., TSLA/USD "16dad506d7db8da01c87581c87ca897a012a153557d4d578c3b9c9e1bc0632f1").
To find the price feed ID for a specific asset, you can query the Pyth Network API:
curl "https://hermes.pyth.network/v2/price_feeds?query=TSLA&asset_type=equity" | jqThis will return the available price feed IDs for the queried asset.
The Oracle Program returns the actual price value as a string with 6 decimal precision (e.g., "451.276160").
- Fetches Raw Data: Retrieves price data from Pyth Network via SEDA's data proxy
- Applies Exponent: Converts Pyth's raw price using the exponent (e.g.,
45127616withexpo: -5=451.27616) - Scales to 6 Decimals: Multiplies by
10^6for consistent 6-decimal precision - Consensus: Multiple executors run the same process, results are aggregated
- Median Calculation: Final price is the median of all executor results
Raw Pyth Data: {"price": "45127616", "expo": -5}
Calculation: 45127616 * 10^(-5) = 451.27616
Scaled: 451.27616 * 10^6 = 451276160
Final Output: "451.276160"
Create a .env file with the required variables:
# RPC for the SEDA network you want to interact with
SEDA_RPC_ENDPOINT=https://rpc.testnet.seda.xyz
# Your SEDA chain mnemonic
SEDA_MNEMONIC=your_mnemonic_here
# Oracle Program ID (use the deployed one above or upload your own)
ORACLE_PROGRAM_ID=cf98370a6bdf3f9f7eaefe282ac3f5979dec8a284965a119edbd3c1495b3a32aContents of this repository are open source under MIT License.