#switchboard #solana #oracle

switchboard-on-demand

A Rust library to interact with the Switchboard Solana program

19 releases

new 0.1.17 Nov 13, 2024
0.1.16 Nov 12, 2024
0.1.15 Oct 2, 2024
0.1.14 Aug 15, 2024
0.1.4 Mar 25, 2024

#4 in #switchboard

Download history 49/week @ 2024-07-24 45/week @ 2024-07-31 30/week @ 2024-08-07 154/week @ 2024-08-14 190/week @ 2024-08-21 106/week @ 2024-08-28 73/week @ 2024-09-04 67/week @ 2024-09-11 113/week @ 2024-09-18 97/week @ 2024-09-25 302/week @ 2024-10-02 251/week @ 2024-10-09 409/week @ 2024-10-16 297/week @ 2024-10-23 247/week @ 2024-10-30 251/week @ 2024-11-06

1,282 downloads per month

MIT license

140KB
3K SLoC

Switchboard Logo

switchboard-on-demand

A Rust library for seamless interaction with Switchboard Oracle accounts on the Solana blockchain.

Crates.io Discord Twitter Follow

Switchboard Documentation: docs.switchboard.xyz
Rustdoc: switchboard-on-demand-rust-docs.web.app

Overview

switchboard-on-demand provides Rust developers with an efficient and easy-to-use client for integrating Solana-based oracles from Switchboard into their applications. This library empowers developers to leverage decentralized, trustless, and highly reliable oracle data for various applications, particularly in the DeFi and Web3 spaces.

Features

  • On-Demand Oracle Data: Fetch real-time, accurate, and tamper-proof data for blockchain applications.
  • Custom Oracle Creation: Design and deploy your own oracles tailored to your specific data needs.
  • High Fidelity Financial Data: Ideal for applications requiring precise and dependable financial data.
  • Privacy-Focused: Operates within confidential runtimes to ensure data integrity and security.

Getting Started

Prerequisites

Ensure you have the following installed:

  • Rust (latest stable version)
  • Cargo
  • Solana CLI tools (if interacting directly with the Solana blockchain)

Installation

Add switchboard-on-demand to your Cargo.toml:

[dependencies]
switchboard-on-demand = "0.1.0"

Using on chain

use switchboard_on_demand::PullFeedAccountData;
use rust_decimal::Decimal;

pub fn solana_ix<'a>(mut ctx: Context<YourAccounts<'a>>, params: Params) -> Result<()> {
    // Assume `account_info` is obtained from the Solana blockchain
    let feed = PullFeedAccountData::parse(ctx.accounts.sb_feed)?;
    let max_stale_slots = 100; // Define the maximum number of slots before data is considered stale
    let min_samples = 5; // Set the minimum number of samples for data accuracy
    let price: Decimal = feed.get_value(&Clock::get()?, max_stale_slots, min_samples, true)?;

    msg!("Oracle Price: {}", price);

    Ok(())
}

Dependencies

~30–50MB
~892K SLoC