Crate switchboard_on_demand

Crate switchboard_on_demand 

Source
Expand description

§Switchboard On-Demand Oracle SDK

Official Rust SDK for Switchboard On-Demand Oracles on Solana.

This SDK provides secure, efficient access to real-time oracle data with comprehensive validation and zero-copy performance optimizations.

§Quick Start

use switchboard_on_demand::prelude::*;

// Configure the verifier with required accounts
let mut verifier = QuoteVerifier::new();
verifier
    .queue(&queue_account)
    .slothash_sysvar(&slothash_sysvar)
    .ix_sysvar(&instructions_sysvar)
    .clock(&clock_sysvar)
    .max_age(150);

// Load and verify the oracle quote
let quote = verifier.load_and_verify(0)?;

// Access feed data
for feed in quote.feeds() {
    println!("Feed {}: {}", feed.hex_id(), feed.value());
}

§Security Considerations

  • Always validate oracle data freshness with appropriate max_age values
  • Use minimum sample counts for critical operations
  • Verify feed signatures in production environments
  • Monitor for stale data and implement appropriate fallback mechanisms

§Feature Flags

  • client - Enable RPC client functionality
  • anchor - Enable Anchor framework integration

Re-exports§

pub use decimal::*;
pub use on_demand::*;
pub use utils::*;
pub use anchor_traits::*;
pub use program_id::*;
pub use sysvar::*;

Modules§

accounts
Solana account definitions and parsers
anchor_traits
Traits extracted from anchor-lang to avoid dependency conflicts
decimal
Decimal number utilities for handling Switchboard oracle data
instructions
Solana instruction builders and processors
on_demand
Core oracle functionality for on-demand data feeds
prelude
Re-exports of commonly used types and traits for convenience
program_id
Solana program ID constants
sysvar
Solana sysvar utilities
types
Common type definitions
utils
Utility functions and helpers

Macros§

blocking_retry
Retry a given expression a specified number of times with a delay between each attempt. This will block the current thread until a value is resolved or the maximum number of attempts is reached.
cfg_client
Macro used to include code if the target_os is not ‘solana’. This is intended to be used for code that is primarily for off-chain Switchboard Functions.
cfg_secrets
Macro used to include code if the feature ‘secrets’ is enabled. This is intended to be used for code that is primarily for off-chain Switchboard Secrets.
cfg_storage
Macro used to include storage code if the storage feature is enabled.
impl_account_deserialize
Implements AccountDeserialize trait for Anchor compatibility
retry
Retry a given expression a specified number of times with a delay between each attempt.

Constants§

MIN_SOLANA_VERSION
Minimum supported Solana version for compatibility
SDK_NAME
SDK name for identification
SUPPORTED_PROGRAM_VERSIONS
Supported Switchboard On-Demand program versions on Solana
VERSION
Current SDK version