switchboard_solana/
lib.rs

1#![cfg_attr(doc_cfg, feature(doc_cfg))]
2#![allow(clippy::result_large_err)]
3
4//! Switchboard is a multi-chain, permissionless oracle protocol providing
5//! verifiable off-chain compute for smart contracts.
6//!
7//! This library provides the Anchor account and instruction definitions for operating
8//! Switchboard. The library makes use of the target_os to enable client side features
9//! if the target_os is not 'solana'. This allows the library to be used in both
10//! on-chain programs within the Solana runtime as well as client side applications.
11//!
12//! The Switchboard deployment consists of two programs:
13//!
14//! - The Oracle Program: The core Switchboard deployment consisting of Aggregators (data feeds),
15//!   Oracles, and Oracle Queues. Program_ID: `SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f`
16//! - The Attestation Program (V3): Enables the use of Trusted Execution Environments (TEEs)
17//!   providing verifiable off-chain compute allowing developers to write their own off-chain
18//!   logic and "attest" on-chain whether it was executed within a secure enclave.
19//!   Program_ID: `sbattyXrzedoNATfc4L31wC9Mhxsi1BmFhTiN8gDshx`
20//!
21//! # Accounts
22//!
23//! This SDK provides the following account definitions for the Oracle Program:
24//!
25//! - [OracleQueue](OracleQueueAccountData)
26//! - [Crank](CrankAccountData)
27//! - [Oracle](OracleAccountData)
28//! - [Permission](PermissionAccountData)
29//! - [Aggregator](AggregatorAccountData)
30//! - [Job](JobAccountData)
31//! - [Lease](LeaseAccountData)
32//! - [Vrf](VrfAccountData)
33//! - [VrfLite](VrfLiteAccountData)
34//! - [VrfPool](VrfPoolAccountData)
35//!
36//! This SDK provides the following account definitions for the Attestation Program:
37//!
38//! - [AttestationQueue](AttestationQueueAccountData)
39//! - [Verifier](VerifierAccountData)
40//! - [AttestationPermission](AttestationPermissionAccountData)
41//! - [SwitchboardWallet]
42//! - [Function](FunctionAccountData)
43//! - [FunctionRequest](FunctionRequestAccountData)
44//! # Usage
45//!
46//! Within an Anchor program you can make use of the AccountLoader trait to deserialize
47//! Switchboard accounts within your AccountsContext.
48//!
49//! ```
50//! use anchor_lang::prelude::*;
51//! use switchboard_solana::AggregatorAccountData;
52//!
53//! #[derive(Accounts)]
54//! #[instruction(params: ReadFeedParams)]
55//! pub struct ReadFeed<'info> {
56//!  pub aggregator: AccountLoader<'info, AggregatorAccountData>,
57//! }
58//! ```
59//!
60//! For Solana programs using native rust you can use the `new` method to deserialize
61//! Switchboard accounts.
62//!
63//! ```
64//! use switchboard_solana::{AggregatorAccountData, SWITCHBOARD_PROGRAM_ID};
65//!
66//! use solana_program::{
67//!     account_info::{next_account_info, AccountInfo},
68//!     entrypoint,
69//!     entrypoint::ProgramResult,
70//!     msg,
71//!     program_error::ProgramError,
72//!     pubkey::Pubkey,
73//! };
74//!
75//! entrypoint!(process_instruction);
76//!
77//! fn process_instruction<'a>(
78//!     _program_id: &'a Pubkey,
79//!     accounts: &'a [AccountInfo<'a>],
80//!     _instruction_data: &'a [u8],
81//! ) -> ProgramResult {
82//!     let accounts_iter = &mut accounts.iter();
83//!     let aggregator = next_account_info(accounts_iter)?;
84//!
85//!     // check feed owner
86//!     let owner = *aggregator.owner;
87//!     if owner != SWITCHBOARD_PROGRAM_ID {
88//!         return Err(ProgramError::IncorrectProgramId);
89//!     }
90//!
91//!     // load and deserialize feed
92//!     let feed = AggregatorAccountData::new(aggregator)?;
93//! }
94//! ```
95
96mod macros;
97
98
99pub mod decimal;
100pub use decimal::*;
101
102pub mod oracle_program;
103pub use oracle_program::*;
104
105pub mod error;
106
107pub mod seeds;
108pub use seeds::*;
109
110pub mod utils;
111pub use utils::*;
112
113pub mod events;
114
115pub mod program_id;
116pub use program_id::*;
117
118pub mod accounts;
119pub mod instructions;
120pub mod types;
121
122pub mod prelude;
123
124cfg_macros! {
125    // Futures crate is needed by the proc_macro
126    pub use futures;
127    pub use futures::Future;
128    pub use switchboard_solana_macros::switchboard_function;
129    pub use switchboard_solana_macros::sb_error;
130}
131
132/// The minimum number of slots before a request is considered expired.
133pub const MINIMUM_USERS_NUM_SLOTS_UNTIL_EXPIRATION: u64 = 150; // 1 min at 400ms/slot
134
135/// The default number of slots before a request expires.
136pub const DEFAULT_USERS_NUM_SLOTS_UNTIL_EXPIRATION: u64 = 2250; // 15 min at 400ms/slot
137
138pub const DEFAULT_MAX_CONTAINER_PARAMS_LEN: u32 = 256;
139
140anchor_lang::prelude::declare_id!("SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f");