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;
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
Macros
- 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.
- Macro used to include IPFS code if the feature ‘ipfs’ is enabled.
- Macro used to include code if the feature ‘macros’ is enabled.
- Macro used to wrap exclusively non-client modules
- 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.
- 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.
Structs
- CacheEntryNon-
target_os="solana"
- EVM specific environment used during a Switchboard function execution
- EVM Represents an Ethereum Virtual Machine (EVM) transaction.
- The schema of the output data that will be sent to the quote verification sidecar.
- The schema of the output data that will be sent to the quote verification sidecar.
- FunctionResultValidatorNon-
target_os="solana"
Represents aVerifierAccountData
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 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.- The schema of the output data that will be sent to the quote verification sidecar. This implementation has been deprecated in favor of
FunctionResult
. - The expected environment variables when a solana function is being executed
- Solana Represents the result of a Solana function call.
- Represents the result of a Solana function call.
Enums
- Function result info
- Enum representing the result of an EVM function call.
- FunctionResultValidatorSignerNon-
target_os="solana"
- QvnReceiptNon-
target_os="solana"
- Switchboard Functions error suite
- Starknet Result Info
Constants
- The default number of slots before a request expires.
- The minimum number of slots before a request is considered expired.
Statics
- The static program ID
Traits
- Future
macros
and non-target_os="solana"
A future represents an asynchronous computation obtained by use ofasync
.
Functions
- build_txNon-
target_os="solana"
- 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"
- fetch_zerocopy_account_asyncNon-
target_os="solana"
- fetch_zerocopy_account_syncNon-
target_os="solana"
- 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"
- Returns the program ID
- ix_to_txNon-
target_os="solana"
- keypair_from_base_seedNon-
target_os="solana"
- 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 a file to a string and trim any leading or trailing whitespace.
- signer_to_pubkeyNon-
target_os="solana"
- subscribeNon-
target_os="solana"
- Return the unix timestamp in seconds.
Type Aliases
- AnchorClientNon-
target_os="solana"
- AnchorProgramNon-
target_os="solana"
- QuoteVerifyFnNon-
target_os="solana"
Attribute Macros
- sb_error
macros
and non-target_os="solana"
- switchboard_function
macros
and non-target_os="solana"