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 orSB_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 datapull_feed
- Pull-based oracle feed management and utilitiesaccounts
- Solana account structures and deserializationinstructions
- Solana instruction builders for on-chain operationscrossbar
- Core Crossbar protocol implementationsoracle_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.