Crate switchboard_on_demand_client

Crate switchboard_on_demand_client 

Source
Expand description

§Switchboard On-Demand Client

A comprehensive Rust client library for interacting with the Switchboard On-Demand Oracle Network and Crossbar API. This crate provides high-level abstractions for fetching oracle data, submitting responses, and managing Solana on-chain interactions with the Switchboard infrastructure.

§Features

  • Oracle Data Feeds: Fetch real-time price and data feeds from Switchboard oracles
  • Pull Feed Management: Create, update, and manage pull-based oracle feeds
  • Gateway Integration: Seamless communication with Switchboard’s Crossbar gateway
  • Solana Integration: Built-in support for Solana blockchain interactions
  • Consensus Mechanisms: Support for oracle consensus and signature aggregation
  • Cryptographic Security: SECP256k1 signature verification and validation

§Network Support

This crate supports both Solana mainnet and devnet environments:

  • Enable devnet via the devnet feature flag or SB_ENV=devnet environment variable
  • Automatic program ID resolution based on network configuration

§Quick Start

use switchboard_on_demand_client::*;
use solana_sdk::pubkey::Pubkey;
//!
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize a gateway client
    let gateway = Gateway::new("https://api.switchboard.xyz");

    // Get the Switchboard program ID for current network
    let program_id = get_switchboard_on_demand_program_id();
    println!("Using program ID: {}", program_id);

    Ok(())
}

§Architecture

The crate is organized into several key modules:

  • gateway - Crossbar API client for fetching oracle signatures and data
  • pull_feed - Pull-based oracle feed management and utilities
  • accounts - Solana account structures and deserialization
  • instructions - Solana instruction builders for on-chain operations
  • crossbar - Core Crossbar protocol implementations
  • oracle_job - Oracle job definitions and serialization

§Error Handling

This crate uses anyhow for error handling, providing rich error context and easy error propagation. Most functions return Result<T, anyhow::Error> for consistent error handling across the API.

§Security

All cryptographic operations use industry-standard libraries and follow best practices:

  • SECP256k1 signatures for oracle response verification
  • Secure hash functions for data integrity
  • Proper key management and validation

§Performance

The client is designed for high-performance applications:

  • Async/await support throughout the API
  • Efficient serialization with zero-copy where possible
  • Connection pooling and request batching capabilities

Re-exports§

pub use prost;
pub use instructions::*;
pub use crossbar::*;
pub use gateway::*;
pub use pull_feed::*;
pub use associated_token_account::*;
pub use recent_slothashes::*;
pub use accounts::*;
pub use lut_owner::*;

Modules§

accounts
Switchboard account structures and deserialization utilities.
associated_token_account
Associated token account utilities and constants.
crossbar
Core Crossbar protocol implementations and client functionality.
gateway
Gateway client for interfacing with Switchboard’s Crossbar API.
instructions
Solana instruction builders for interacting with the Switchboard On-Demand program.
lut_owner
Lookup table ownership and management functionality.
oracle_job
Oracle job definitions, serialization, and protocol buffer handling.
pull_feed
Pull-based oracle feed management and data fetching utilities.
recent_slothashes
Solana slot hash utilities and recent hash management.
secp256k1
SECP256k1 cryptographic utilities and signature verification.

Constants§

DELEGATION_GROUP_SEED
Seed bytes for deriving delegation group account PDAs.
DELEGATION_SEED
Seed bytes for deriving delegation account PDAs.
LUT_SIGNER_SEED
Seed bytes for deriving lookup table signer account PDAs.
ON_DEMAND_DEVNET_PID
The Switchboard On-Demand program ID for Solana devnet.
ON_DEMAND_MAINNET_PID
The Switchboard On-Demand program ID for Solana mainnet.
ORACLE_FEED_STATS_SEED
Seed bytes for deriving oracle feed statistics account PDAs.
ORACLE_RANDOMNESS_STATS_SEED
Seed bytes for deriving oracle randomness statistics account PDAs.
ORACLE_STATS_SEED
Seed bytes for deriving oracle statistics account PDAs.
REWARD_POOL_VAULT_SEED
Seed bytes for deriving reward pool vault account PDAs.
STATE_SEED
Seed bytes for deriving the Switchboard state account PDA.

Functions§

get_switchboard_on_demand_program_id
Returns the appropriate Switchboard On-Demand program ID for the current network.
is_devnet
Determines if the devnet environment is enabled.
ix_to_tx
Converts a set of instructions into a signed Solana transaction.