rialo-price-reactor-aggregator-interface

Crates.iorialo-price-reactor-aggregator-interface
lib.rsrialo-price-reactor-aggregator-interface
version0.1.10
created_at2025-12-09 14:31:31.471742+00
updated_at2025-12-09 21:51:58.574615+00
descriptionInterface for the Price Reactor Aggregator example program
homepage
repository
max_upload_size
id1975573
size71,595
(subzerolabs-eng-ops)

documentation

README

Rialo Price Reactor Aggregator Interface

This crate provides the interface for price aggregation programs in the Rialo ecosystem. It defines the TradingPairs event structure and implements median-based price aggregation logic for cryptocurrency trading pairs.

Overview

The Price Reactor Aggregator Interface enables programs to process oracle price updates and emit standardized trading pair events. It focuses on seven major cryptocurrency pairs and provides robust median-based price aggregation to handle outliers and ensure reliable price data.

Supported Trading Pairs

The interface currently supports the following cryptocurrency pairs:

pub const PAIRS_KEYS: [&str; 7] = ["BTC", "ETH", "GOAT", "LUNA", "FARTCOIN", "DOGE", "AIXBT"];
  • BTC: Bitcoin
  • ETH: Ethereum
  • GOAT: Goatseus Maximus
  • LUNA: Terra Luna
  • FARTCOIN: Fartcoin
  • DOGE: Dogecoin
  • AIXBT: AIXBT

Core Components

TradingPairs Event

The TradingPairs struct is the primary event type for aggregated price data:

#[derive(Debug, Clone, Default, Serialize, Deserialize, RialoEvent)]
#[serde(rename_all = "UPPERCASE")]
pub struct TradingPairs {
    btc: f64,
    eth: f64,
    goat: f64,
    luna: f64,
    fartcoin: f64,
    aixbt: f64,
    doge: f64,
}

Features:

  • Rialo Event Integration: Implements the RialoEvent trait for seamless event emission
  • Serialization: Supports JSON serialization with uppercase field names
  • Default Implementation: Provides zero-value defaults for all trading pairs

Price Aggregation Logic

The interface implements sophisticated median-based aggregation:

From Oracle Updates

pub fn from_updates(oracle_updates: &[OracleUpdate]) -> Self

This method processes raw oracle updates and creates aggregated trading pair data:

  1. Iterates through supported pairs: Processes each of the 7 supported trading pairs
  2. Median calculation: Uses Median::from_with_method() with MedianMethod::Average
  3. Outlier resistance: Median approach provides robustness against extreme price values
  4. Automatic mapping: Maps calculated medians to appropriate trading pair fields

Manual Construction

pub fn new(
    btc: f64, eth: f64, goat: f64, luna: f64,
    fartcoin: f64, aixbt: f64, doge: f64
) -> Self

Allows direct construction of trading pairs with specific price values.

Aggregation Strategy

Median-Based Approach

The interface uses median aggregation with the following characteristics:

  • Method: MedianMethod::Average - provides balanced results
  • Robustness: Resistant to extreme outliers in oracle data
  • Reliability: Ensures stable price feeds even with inconsistent oracle reports
  • Scalability: Efficiently processes multiple oracle sources

Benefits of Median Aggregation

  1. Outlier Resistance: Extreme price values don't skew the final result
  2. Byzantine Fault Tolerance: Can handle up to 50% malicious or faulty oracles
  3. Stable Pricing: Reduces volatility from individual oracle inconsistencies
  4. Market Representation: Better reflects true market consensus

Usage Examples

Creating Trading Pairs from Oracle Data

use rialo_price_reactor_aggregator_interface::event::TradingPairs;
use rialo_oracle_processor_interface::state::OracleUpdate;

// Process oracle updates into trading pairs
let oracle_updates: Vec<OracleUpdate> = get_oracle_updates();
let trading_pairs = TradingPairs::from_updates( & oracle_updates);

// Emit as Rialo event
trading_pairs.emit(program_id, & accounts) ?;

Manual Price Construction

let trading_pairs = TradingPairs::new(
50000.0,  // BTC
3000.0,   // ETH
1.5,      // GOAT
80.0,     // LUNA
0.001,    // FARTCOIN
2.5,      // AIXBT
0.08,     // DOGE
);

Rialo Event Integration

// Initialize storage for the event
if event_account.data_is_empty() {
trading_pairs.initialize_storage(program_id, & accounts) ?;
}

// Emit the trading pairs event
trading_pairs.emit(program_id, & accounts) ?;

Event Schema

When serialized, the TradingPairs event produces JSON with uppercase field names:

{
  "BTC": 50000.0,
  "ETH": 3000.0,
  "GOAT": 1.5,
  "LUNA": 80.0,
  "FARTCOIN": 0.001,
  "AIXBT": 2.5,
  "DOGE": 0.08
}

Integration Points

With Oracle Processors

  • Consumes OracleUpdate arrays from oracle processor interfaces
  • Handles multiple oracle sources for each trading pair
  • Processes real-time price feeds

With Aggregator Programs

  • Provides the event structure for price aggregator implementations
  • Supports the standard Rialo aggregator instruction flow
  • Enables consistent price data formats across programs

With Price Reactors

  • Emits standardized events for downstream price-sensitive applications
  • Supports automated trading, liquidation, and risk management systems
  • Provides reliable price feeds for DeFi protocols

Dependencies

  • rialo_aggregators_utils: Median calculation utilities
  • rialo_events_core: Core event framework and derive macros
  • rialo_oracle_processor_interface: Oracle update data structures
  • serde: Serialization and deserialization support

License

Copyright (c) Subzero Labs, Inc.
SPDX-License-Identifier: Apache-2.0

Commit count: 0

cargo fmt