| Crates.io | rialo-price-reactor-aggregator-interface |
| lib.rs | rialo-price-reactor-aggregator-interface |
| version | 0.1.10 |
| created_at | 2025-12-09 14:31:31.471742+00 |
| updated_at | 2025-12-09 21:51:58.574615+00 |
| description | Interface for the Price Reactor Aggregator example program |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1975573 |
| size | 71,595 |
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.
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.
The interface currently supports the following cryptocurrency pairs:
pub const PAIRS_KEYS: [&str; 7] = ["BTC", "ETH", "GOAT", "LUNA", "FARTCOIN", "DOGE", "AIXBT"];
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:
RialoEvent trait for seamless event emissionThe interface implements sophisticated median-based aggregation:
pub fn from_updates(oracle_updates: &[OracleUpdate]) -> Self
This method processes raw oracle updates and creates aggregated trading pair data:
Median::from_with_method() with MedianMethod::Averagepub 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.
The interface uses median aggregation with the following characteristics:
MedianMethod::Average - provides balanced resultsuse 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) ?;
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
);
// 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) ?;
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
}
OracleUpdate arrays from oracle processor interfacesrialo_aggregators_utils: Median calculation utilitiesrialo_events_core: Core event framework and derive macrosrialo_oracle_processor_interface: Oracle update data structuresserde: Serialization and deserialization supportCopyright (c) Subzero Labs, Inc.
SPDX-License-Identifier: Apache-2.0