Rialo Aggregator Interface
This crate provides the standardized interface for building aggregator programs in the Rialo ecosystem. It defines the common instruction set and account structure that all aggregator implementations should follow.
Overview
The Rialo Aggregator Interface serves as the foundation for programs that consume oracle data and transform it into processed outputs. This interface ensures consistency across different aggregator implementations while providing flexibility for various aggregation strategies.
Core Components
AggregatorInstruction
The interface defines a single instruction type:
Aggregate {}: The primary instruction for processing oracle data and generating aggregated results
Instruction Builder
The AggregatorInstruction::aggregate() function creates properly formatted instructions with the required account
structure:
Account Structure
All aggregator programs following this interface expect accounts in this specific order:
-
Payer Account (
AccountMeta::new(payer, true))- Signer account responsible for transaction fees and rent
- Must be writable and a signer
-
Oracle Report Account (
AccountMeta::new_readonly(oracle_report, false))- Contains the source oracle data to be aggregated
- Read-only access, not a signer
-
Aggregated Data Account (
AccountMeta::new(aggregated_data_key, false))- Target account for storing the aggregated results
- Must be writable for data storage
-
System Program Account (
AccountMeta::new_readonly(system_program::id(), false))- Required for account creation and management
- Standard Solana system program
Implementation Guidelines
When implementing an aggregator program using this interface:
1. Process Instruction Handling
match instruction
2. Account Validation
- Ensure accounts are provided in the correct order
- Validate account ownership and permissions
- Check that writable accounts can be modified
3. Error Handling
- Use appropriate
ProgramErrorvariants - Provide meaningful error messages via
msg!()macro - Handle deserialization failures gracefully
Usage Examples
Creating an Aggregate Instruction
use AggregatorInstruction;
use Pubkey;
let aggregator_program_id = new_unique;
let payer_pubkey = new_unique;
let oracle_report_pubkey = new_unique;
let topic = Stringfrom;
let instruction = aggregate;
Processing in Your Aggregator Program
use AggregatorInstruction;
Aggregation Patterns
This interface supports various aggregation strategies:
- Price Aggregation: Combine multiple price feeds into consolidated trading pair data
- Statistical Aggregation: Calculate averages, medians, or other statistical measures
- Event Aggregation: Transform raw oracle events into higher-level business events
- Cross-Chain Aggregation: Combine data from multiple blockchain sources
Integration with Rialo Ecosystem
Aggregator programs built with this interface integrate seamlessly with:
- Oracle Processors: Source of raw oracle data
- Event Emitters: For publishing aggregated results as Rialo events
- Subscriber Programs: Consumers of aggregated data
- Price Reactors: Applications that respond to aggregated price data
Testing
The interface includes comprehensive tests demonstrating proper usage:
Dependencies
serde: Serialization and deserialization supportrialo_s_instruction: Solana instruction creation utilitiesrialo_s_program: Core Solana program typesrialo_s_pubkey: Public key handling
License
Copyright (c) Subzero Labs, Inc. SPDX-License-Identifier: Apache-2.0