6 releases
| new 0.2.0 | Feb 26, 2026 |
|---|---|
| 0.2.0-alpha.2 | Feb 12, 2026 |
| 0.2.0-alpha.0 | Jan 29, 2026 |
| 0.1.10 | Dec 9, 2025 |
#11 in #data-transform
47 downloads per month
Used in rialo-oracle-processor-in…
15KB
56 lines
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:
pub fn aggregate(
aggregator_program_id: &Pubkey,
payer: &Pubkey,
oracle_report: &Pubkey,
aggregated_data_key: &Pubkey,
) -> Instruction
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 {
AggregatorInstruction::Aggregate {} => {
// Your aggregation logic here
// 1. Read oracle data from oracle_report_account
// 2. Process/aggregate the data
// 3. Store results in aggregated_data_account
// 4. Optionally emit events
}
}
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 rialo_aggregator_interface::instruction::AggregatorInstruction;
use rialo_s_pubkey::Pubkey;
let aggregator_program_id = Pubkey::new_unique();
let payer_pubkey = Pubkey::new_unique();
let oracle_report_pubkey = Pubkey::new_unique();
let topic = String::from("price_feed");
let instruction = AggregatorInstruction::aggregate(
&aggregator_program_id,
&payer_pubkey,
&oracle_report_pubkey,
topic,
);
Processing in Your Aggregator Program
use rialo_aggregator_interface::instruction::AggregatorInstruction;
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo<'_>],
instruction_data: &[u8],
) -> ProgramResult {
let instruction: AggregatorInstruction =
limited_deserialize(instruction_data, rialo_limits::MAX_INSTRUCTION_DATA_SIZE)?;
match instruction {
AggregatorInstruction::Aggregate {} => {
// Implement your specific aggregation logic
process_aggregate(program_id, accounts)
}
}
}
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:
#[test]
fn test_aggregate() {
let instruction = AggregatorInstruction::aggregate(
&program_id,
&payer,
&oracle_report,
&aggregated_data_key,
);
// Verify instruction structure and serializability
}
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
Dependencies
~11–17MB
~305K SLoC