#switchboard #solana #oracle

switchboard-program

A Rust library to interact with Switchboard data feeds

10 releases

0.2.1 Mar 15, 2022
0.1.63 Jan 21, 2022
0.1.59 Nov 3, 2021
0.1.49 Jul 26, 2021

#20 in #switchboard

Download history 328/week @ 2024-07-23 249/week @ 2024-07-30 367/week @ 2024-08-06 372/week @ 2024-08-13 332/week @ 2024-08-20 396/week @ 2024-08-27 408/week @ 2024-09-03 388/week @ 2024-09-10 459/week @ 2024-09-17 317/week @ 2024-09-24 317/week @ 2024-10-01 335/week @ 2024-10-08 769/week @ 2024-10-15 1060/week @ 2024-10-22 1815/week @ 2024-10-29 1317/week @ 2024-11-05

5,072 downloads per month
Used in 3 crates (2 directly)

MIT license

12KB
188 lines

switchboard-program

A Rust library to interact with Switchboard's hosted data feeds.

Description

This package can be used to manage Switchboard data feed account parsing.

Specifically, this package will return the most recent confirmed round result from a provided data feed AccountInfo.

Usage

use switchboard_program;
use switchboard_program::{
    AggregatorState,
    RoundResult,
    FastRoundResultAccountData,
    fast_parse_switchboard_result
};
...
let aggregator: AggregatorState = switchboard_program::get_aggregator(
    switchboard_feed_account // &AccountInfo
)?;
let round_result: RoundResult = switchboard_program::get_aggregator_result(
    &aggregator)?;

// pub struct RoundResult {
    // pub num_success: Option<i32>,
    // pub num_error: Option<i32>,
    // pub result: Option<f64>,
    // pub round_open_slot: Option<u64>,
    // pub round_open_timestamp: Option<i64>,
    // pub min_response: Option<f64>,
    // pub max_response: Option<f64>,
    // pub medians: Vec<f64>,
// }

...
// Compute conservative? Use the parse optimized result account instead:

let fast_parse_feed_round = FastRoundResultAccountData::deserialize(
    &switchboard_parse_optimized_account.try_borrow_data()?).unwrap();

// pub struct FastRoundResultAccountData {
    // pub parent: [u8;32],
    // pub result: FastRoundResult,
// }
// // A precisioned decimal representation of the current aggregator result
// // where `result is represented as ${mantissa} / (10^${scale})`
// pub struct SwitchboardDecimal {
    // pub mantissa: i128,
    // pub scale: u64
// }
// pub struct FastRoundResult {
    // pub num_success: i32,
    // pub num_error: i32,
    // pub result: f64,
    // pub round_open_slot: u64,
    // pub round_open_timestamp: i64,
    // pub min_response: f64,
    // pub max_response: f64,
    // pub decimal: SwitchboardDecimal,
// }

Dependencies

~18–26MB
~449K SLoC