rialo-aggregator-interface

Crates.iorialo-aggregator-interface
lib.rsrialo-aggregator-interface
version0.1.10
created_at2025-12-08 19:42:49.316488+00
updated_at2025-12-09 21:52:52.619549+00
descriptionInstructions and constructors for aggregators program
homepage
repository
max_upload_size
id1974273
size59,878
(subzerolabs-eng-ops)

documentation

README

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:

  1. Payer Account (AccountMeta::new(payer, true))

    • Signer account responsible for transaction fees and rent
    • Must be writable and a signer
  2. Oracle Report Account (AccountMeta::new_readonly(oracle_report, false))

    • Contains the source oracle data to be aggregated
    • Read-only access, not a signer
  3. Aggregated Data Account (AccountMeta::new(aggregated_data_key, false))

    • Target account for storing the aggregated results
    • Must be writable for data storage
  4. 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 ProgramError variants
  • 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 support
  • rialo_s_instruction: Solana instruction creation utilities
  • rialo_s_program: Core Solana program types
  • rialo_s_pubkey: Public key handling

License

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

Commit count: 0

cargo fmt