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 - github crates-io docs-rs
- attestation_
program - decimal
- env
- error
- events
- function_
result - gramine
- instructions
- ipfs
ipfs
and non-target_os="solana"
- oracle_
program - prelude
- program_
id - response
- This module contains structures returned by the IPFS API.
- secrets
secrets
and non-target_os="solana"
- seeds
- types
- utils
Macros§
- blocking_
retry Non- 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.
- retry
Non- target_os="solana"
- Retry a given expression a specified number of times with a delay between each attempt.
Structs§
- ApiError
- Backend
With Global Options - A wrapper for Backend / IpfsApi that adds global options
- Cache
Entry Non- target_os="solana"
- EvmFunction
Environment - EVM specific environment used during a Switchboard function execution
- EvmFunction
Result V0 - EvmFunction
Result V1 - EvmTransaction
- EVM Represents an Ethereum Virtual Machine (EVM) transaction.
- Function
Manager Environment - Function
Result V0 - The schema of the output data that will be sent to the quote verification sidecar.
- Function
Result V1 - The schema of the output data that will be sent to the quote verification sidecar.
- Function
Result Validator Non- target_os="solana"
- Represents a
VerifierAccountData
oracle and verifies an emitted FunctionResult - Function
Result Validator Accounts Non- target_os="solana"
- The list of accounts used by this verifier to verify the function result
- Function
Result Validator Cache Non- target_os="solana"
- Function
Result Validator Init Accounts Non- target_os="solana"
- Function
Runner Non- 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.
- Function
Validator Verify Params Non- target_os="solana"
- The cleaned up parameters used for a verify instruction
- Global
Options - 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.- Ipfs
Client - Ipfs
Manager - Legacy
EvmFunction Result - Legacy
Function Result - The schema of the output data that will be sent to the quote verification sidecar.
This implementation has been deprecated in favor of
FunctionResult
. - Legacy
Solana Function Result - QvnEnvironment
- Solana
Function Environment - The expected environment variables when a solana function is being executed
- Solana
Function Result V0 - Solana Represents the result of a Solana function call.
- Solana
Function Result V1 - Represents the result of a Solana function call.
- Solana
Function Simulation Environment - The expected environment variables when a solana function is being executed
- Starknet
Call - Starknet
Function Result V0
Enums§
- Chain
Result Info - Function result info
- Error
- EvmFunction
Result - Enum representing the result of an EVM function call.
- Function
Result - Function
Result Validator Signer Non- target_os="solana"
- Function
Trigger Type - Legacy
Chain Result Info - QvnReceipt
Non- target_os="solana"
- SbError
- Switchboard Functions error suite
- SbFunction
Error - Solana
Function Request Type - Solana
Function Result - Starknet
Function Request Type - Starknet Result Info
- Starknet
Function Result
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
- Future
macros
and non-target_os="solana"
- A future represents an asynchronous computation obtained by use of
async
. - IpfsApi
- TryFrom
Uri
Functions§
- build_
tx Non- target_os="solana"
- check_
id - Confirms that a given pubkey is equivalent to the program ID
- fetch_
borsh_ account Non- target_os="solana"
- fetch_
borsh_ account_ async Non- target_os="solana"
- fetch_
borsh_ account_ sync Non- target_os="solana"
- fetch_
zerocopy_ account Non- target_os="solana"
- Fetches a zero-copy account from the Solana blockchain.
- fetch_
zerocopy_ account_ async Non- target_os="solana"
- Fetches an account asynchronously using the provided client and public key.
- fetch_
zerocopy_ account_ sync Non- target_os="solana"
- Fetches the account data synchronously from the Solana blockchain using the provided client.
- generate_
signer Non- target_os="solana"
- Creates a signing keypair generated from randomness sourced from the enclave runtime.
- get_
async_ rpc Non- target_os="solana"
- get_
attestation_ program Non- target_os="solana"
- get_
enclave_ signer_ pubkey Non- target_os="solana"
- id
- Returns the program ID
- ix_
to_ tx Non- target_os="solana"
- keypair_
from_ base_ seed Non- target_os="solana"
- Generates a keypair from a base seed, secret key, optional additional bytes, and an optional program ID.
- load_
env_ pubkey Non- target_os="solana"
- load_
keypair_ fs Non- target_os="solana"
- parse_
optional_ pubkey Non- 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_ pubkey Non- target_os="solana"
- subscribe
Non- target_os="solana"
- subscribe_
ro Non- target_os="solana"
- unix_
timestamp - Return the unix timestamp in seconds.
Type Aliases§
- Anchor
Client Non- target_os="solana"
- Anchor
Program Non- target_os="solana"
- BoxStream
- Quote
Verify Fn Non- target_os="solana"
Attribute Macros§
- sb_
error macros
and non-target_os="solana"
- switchboard_
function macros
and non-target_os="solana"