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 futures;macros and non-target_os="solana"
pub use decimal::*;
pub use oracle_program::*;
pub use attestation_program::*;
pub use seeds::*;
pub use utils::*;
pub use events::*;
pub use program_id::*;
pub use secrets::*;secrets and non-target_os="solana"

Modules§

accounts
async_trait
githubcrates-iodocs-rs
attestation_program
decimal
env
error
events
function_result
gramine
instructions
ipfsipfs and non-target_os="solana"
oracle_program
prelude
program_id
response
This module contains structures returned by the IPFS API.
secretssecrets and non-target_os="solana"
seeds
types
utils

Macros§

blocking_retryNon-target_os="solana"
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_not_client
Macro used to wrap exclusively non-client modules
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.
retryNon-target_os="solana"
Retry a given expression a specified number of times with a delay between each attempt.

Structs§

ApiError
BackendWithGlobalOptions
A wrapper for Backend / IpfsApi that adds global options
CacheEntryNon-target_os="solana"
EvmFunctionEnvironment
EVM specific environment used during a Switchboard function execution
EvmFunctionResultV0
EvmFunctionResultV1
EvmTransaction
EVM Represents an Ethereum Virtual Machine (EVM) transaction.
FunctionManagerEnvironment
FunctionResultV0
The schema of the output data that will be sent to the quote verification sidecar.
FunctionResultV1
The schema of the output data that will be sent to the quote verification sidecar.
FunctionResultValidatorNon-target_os="solana"
Represents a VerifierAccountData oracle and verifies an emitted FunctionResult
FunctionResultValidatorAccountsNon-target_os="solana"
The list of accounts used by this verifier to verify the function result
FunctionResultValidatorCacheNon-target_os="solana"
FunctionResultValidatorInitAccountsNon-target_os="solana"
FunctionRunnerNon-target_os="solana"
An object containing the context to execute a Switchboard Function. Inititlizing this object will load all required variables from the runtime to execute and sign an output transaction to be verified and committed by the switchboard network.
FunctionValidatorVerifyParamsNon-target_os="solana"
The cleaned up parameters used for a verify instruction
GlobalOptions
Options valid on any IPFS Api request
Gramine
Gramine: Gramine is a virtualized runtime used to manage vanilla binaries to execute in an SGX execution environment. This struct allows access to specific overrides that come out-of-the-box with Gramine.
IpfsClient
IpfsManager
LegacyEvmFunctionResult
LegacyFunctionResult
The schema of the output data that will be sent to the quote verification sidecar. This implementation has been deprecated in favor of FunctionResult.
LegacySolanaFunctionResult
QvnEnvironment
SolanaFunctionEnvironment
The expected environment variables when a solana function is being executed
SolanaFunctionResultV0
Solana Represents the result of a Solana function call.
SolanaFunctionResultV1
Represents the result of a Solana function call.
SolanaFunctionSimulationEnvironment
The expected environment variables when a solana function is being executed
StarknetCall
StarknetFunctionResultV0

Enums§

ChainResultInfo
Function result info
Error
EvmFunctionResult
Enum representing the result of an EVM function call.
FunctionResult
FunctionResultValidatorSignerNon-target_os="solana"
FunctionTriggerType
LegacyChainResultInfo
QvnReceiptNon-target_os="solana"
SbError
Switchboard Functions error suite
SbFunctionError
SolanaFunctionRequestType
SolanaFunctionResult
StarknetFunctionRequestType
Starknet Result Info
StarknetFunctionResult

Constants§

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

Statics§

FUNCTION_RESULT_PREFIX
ID
The static program ID

Traits§

ApiRequest
A request that can be made against the Ipfs API.
Backend
Futuremacros and non-target_os="solana"
A future represents an asynchronous computation obtained by use of async.
IpfsApi
TryFromUri

Functions§

build_txNon-target_os="solana"
check_id
Confirms that a given pubkey is equivalent to the program ID
fetch_borsh_accountNon-target_os="solana"
fetch_borsh_account_asyncNon-target_os="solana"
fetch_borsh_account_syncNon-target_os="solana"
fetch_zerocopy_accountNon-target_os="solana"
Fetches a zero-copy account from the Solana blockchain.
fetch_zerocopy_account_asyncNon-target_os="solana"
Fetches an account asynchronously using the provided client and public key.
fetch_zerocopy_account_syncNon-target_os="solana"
Fetches the account data synchronously from the Solana blockchain using the provided client.
generate_signerNon-target_os="solana"
Creates a signing keypair generated from randomness sourced from the enclave runtime.
get_async_rpcNon-target_os="solana"
get_attestation_programNon-target_os="solana"
get_enclave_signer_pubkeyNon-target_os="solana"
id
Returns the program ID
ix_to_txNon-target_os="solana"
keypair_from_base_seedNon-target_os="solana"
Generates a keypair from a base seed, secret key, optional additional bytes, and an optional program ID.
load_env_pubkeyNon-target_os="solana"
load_keypair_fsNon-target_os="solana"
parse_optional_pubkeyNon-target_os="solana"
Parse a string into an optional Pubkey. If the string is empty, return None.
read_and_trim_file
Read a file to a string and trim any leading or trailing whitespace.
signer_to_pubkeyNon-target_os="solana"
subscribeNon-target_os="solana"
subscribe_roNon-target_os="solana"
unix_timestamp
Return the unix timestamp in seconds.

Type Aliases§

AnchorClientNon-target_os="solana"
AnchorProgramNon-target_os="solana"
BoxStream
QuoteVerifyFnNon-target_os="solana"

Attribute Macros§

sb_errormacros and non-target_os="solana"
switchboard_functionmacros and non-target_os="solana"