Crates.io | switchboard-on-demand |
lib.rs | switchboard-on-demand |
version | 0.1.17 |
source | src |
created_at | 2024-03-10 18:34:16.753235 |
updated_at | 2024-11-13 18:25:56.67809 |
description | A Rust library to interact with the Switchboard Solana program. |
homepage | https://switchboard.xyz |
repository | https://github.com/switchboard-xyz/solana-sdk/tree/main/rust/switchboard-solana |
max_upload_size | |
id | 1168849 |
size | 140,158 |
A Rust library for seamless interaction with Switchboard Oracle accounts on the Solana blockchain.
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.
Ensure you have the following installed:
Add switchboard-on-demand
to your Cargo.toml
:
[dependencies]
switchboard-on-demand = "0.1.0"
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(())
}