Crate switchboard_solana

Source
Expand description

Switchboard is a multi-chain, permissionless oracle protocol providing verifiable off-chain compute for smart contracts.

This library provides the Anchor account and instruction definitions for operating Switchboard. The library makes use of the target_os to enable client side features if the target_os is not ‘solana’. This allows the library to be used in both on-chain programs within the Solana runtime as well as client side applications.

The Switchboard deployment consists of two programs:

  • The Oracle Program: The core Switchboard deployment consisting of Aggregators (data feeds), Oracles, and Oracle Queues. Program_ID: SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f
  • The Attestation Program (V3): Enables the use of Trusted Execution Environments (TEEs) providing verifiable off-chain compute allowing developers to write their own off-chain logic and “attest” on-chain whether it was executed within a secure enclave. Program_ID: sbattyXrzedoNATfc4L31wC9Mhxsi1BmFhTiN8gDshx

§Accounts

This SDK provides the following account definitions for the Oracle Program:

This SDK provides the following account definitions for the Attestation Program:

§Usage

Within an Anchor program you can make use of the AccountLoader trait to deserialize Switchboard accounts within your AccountsContext.

use anchor_lang::prelude::*;
use switchboard_solana::AggregatorAccountData;

#[derive(Accounts)]
#[instruction(params: ReadFeedParams)]
pub struct ReadFeed<'info> {
 pub aggregator: AccountLoader<'info, AggregatorAccountData>,
}

For Solana programs using native rust you can use the new method to deserialize Switchboard accounts.

use switchboard_solana::{AggregatorAccountData, SWITCHBOARD_PROGRAM_ID};

use solana_program::{
    account_info::{next_account_info, AccountInfo},
    entrypoint,
    entrypoint::ProgramResult,
    msg,
    program_error::ProgramError,
    pubkey::Pubkey,
};

entrypoint!(process_instruction);

fn process_instruction<'a>(
    _program_id: &'a Pubkey,
    accounts: &'a [AccountInfo<'a>],
    _instruction_data: &'a [u8],
) -> ProgramResult {
    let accounts_iter = &mut accounts.iter();
    let aggregator = next_account_info(accounts_iter)?;

    // check feed owner
    let owner = *aggregator.owner;
    if owner != SWITCHBOARD_PROGRAM_ID {
        return Err(ProgramError::IncorrectProgramId);
    }

    // load and deserialize feed
    let feed = AggregatorAccountData::new(aggregator)?;
}

Re-exports§

pub use decimal::*;
pub use oracle_program::*;
pub use seeds::*;
pub use utils::*;
pub use program_id::*;

Modules§

accounts
decimal
error
events
instructions
oracle_program
prelude
program_id
seeds
types
utils

Macros§

blocking_retry
Retry a given expression a specified number of times with a delay between each attempt. This will block the current thread until a value is resolved or the maximum number of attempts is reached.
cfg_client
Macro used to include code if the target_os is not ‘solana’. This is intended to be used for code that is primarily for off-chain Switchboard Functions.
cfg_ipfs
Macro used to include IPFS code if the feature ‘ipfs’ is enabled.
cfg_macros
Macro used to include code if the feature ‘macros’ is enabled.
cfg_program
Macro used to include code only if the target_os is ‘solana’. This is intended to be used for code that is primarily for on-chain programs.
cfg_secrets
Macro used to include code if the feature ‘secrets’ is enabled. This is intended to be used for code that is primarily for off-chain Switchboard Secrets.
retry
Retry a given expression a specified number of times with a delay between each attempt.

Constants§

DEFAULT_MAX_CONTAINER_PARAMS_LEN
DEFAULT_USERS_NUM_SLOTS_UNTIL_EXPIRATION
The default number of slots before a request expires.
ID_CONST
Const version of ID
MINIMUM_USERS_NUM_SLOTS_UNTIL_EXPIRATION
The minimum number of slots before a request is considered expired.

Statics§

ID
The static program ID

Functions§

check_id
Confirms that a given pubkey is equivalent to the program ID
id
Returns the program ID
id_const
Const version of ID