### Rust BlockhashSubscriber: Start Subscription Source: https://docs.rs/drift-rs/latest/drift_rs/blockhash_subscriber/struct Starts the background task for the BlockhashSubscriber. This method is essential for the subscriber to begin polling for new blockhashes. ```Rust pub fn subscribe(&self) ``` -------------------------------- ### Initialize RS_Drift Protocol Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/instructions/index Initializes the RS_Drift protocol, setting up core configurations and states. This function is crucial for the initial setup of the protocol's operations. ```rust pub fn initialize( ctx: Context, state_nonce: u8, // Perp market config perp_market_nonce: u8, perp_market_base_spread: u128, perp_market_tick_size: u128, perp_market_step_size: u128, perp_market_expiry_times: Vec, perp_market_expiry_price_types: Vec, perp_market_max_slippage_ratio: u128, perp_market_max_funding_rate_long: u128, perp_market_max_funding_rate_short: u128, perp_market_liquidation_fee_ratio: u128, perp_market_liquidation_duration: u128, perp_market_liquidation_margin_buffer_ratio: u128, perp_market_liquidation_incentive_numerator: u128, perp_market_liquidation_incentive_denominator: u128, perp_market_floor_id: Option, perp_market_ceil_id: Option, perp_market_min_order_size: u128, perp_market_token_a_decimals: u8, perp_market_token_b_decimals: u8, perp_market_base_decimals: u8, perp_market_unrealized_asset_weight: u128, perp_market_contract_tier: ContractTier, perp_market_concentration_coef: u128, perp_market_oracle_id: Pubkey, perp_market_funding_period: i64, perp_market_quote_decimals: u8, perp_market_quote_max_amount_to_deposit: u128, perp_market_quote_max_amount_to_borrow: u128, perp_market_quote_min_amount_to_deposit: u128, perp_market_quote_min_amount_to_borrow: u128, perp_market_quote_min_order_size: u128, perp_market_quote_max_order_size: u128, perp_market_quote_max_leverage: u128, perp_market_quote_initial_margin_ratio: u128, perp_market_quote_maintenance_margin_ratio: u128, perp_market_quote_unrealized_asset_weight: u128, perp_market_quote_contract_tier: ContractTier, perp_market_quote_concentration_coef: u128, perp_market_quote_oracle_id: Pubkey, perp_market_quote_funding_period: i64, perp_market_quote_token_decimals: u8, perp_market_quote_token_max_amount_to_deposit: u128, perp_market_quote_token_max_amount_to_borrow: u128, perp_market_quote_token_min_amount_to_deposit: u128, perp_market_quote_token_min_amount_to_borrow: u128, perp_market_quote_token_min_order_size: u128, perp_market_quote_token_max_order_size: u128, perp_market_quote_token_max_leverage: u128, perp_market_quote_token_initial_margin_ratio: u128, perp_market_quote_token_maintenance_margin_ratio: u128, perp_market_quote_token_unrealized_asset_weight: u128, perp_market_quote_token_contract_tier: ContractTier, perp_market_quote_token_concentration_coef: u128, perp_market_quote_token_oracle_id: Pubkey, perp_market_quote_token_funding_period: i64, perp_market_quote_token_token_decimals: u8, perp_market_quote_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_min_order_size: u128, perp_market_quote_token_token_max_order_size: u128, perp_market_quote_token_token_max_leverage: u128, perp_market_quote_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_contract_tier: ContractTier, perp_market_quote_token_token_concentration_coef: u128, perp_market_quote_token_token_oracle_id: Pubkey, perp_market_quote_token_token_funding_period: i64, perp_market_quote_token_token_token_decimals: u8, perp_market_quote_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_deposit: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_min_amount_to_borrow: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_min_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_max_order_size: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_max_leverage: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_initial_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_maintenance_margin_ratio: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_unrealized_asset_weight: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_contract_tier: ContractTier, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_concentration_coef: u128, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_oracle_id: Pubkey, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_funding_period: i64, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_token_decimals: u8, perp_market_quote_token_token_token_token_token_token_token_token_token_token_token_token_token_token_max_amount_to_deposit: u ``` -------------------------------- ### Get Account Data Source: https://docs.rs/drift-rs/latest/drift_rs/struct Retrieves the account data for the user. ```rust pub fn account_data(&self) -> &Cow<'_, User> ``` -------------------------------- ### GlobalUserMap: Get User Data Source: https://docs.rs/drift-rs/latest/drift_rs/usermap/struct The `get` method retrieves user data associated with a specific public key. It returns an `Option`. ```Rust pub fn get(&self, pubkey: &str) -> Option ``` -------------------------------- ### Get Program Data Source: https://docs.rs/drift-rs/latest/drift_rs/struct Retrieves the program data associated with the current context. ```rust pub fn program_data(&self) -> &ProgramData ``` -------------------------------- ### Rust: Initialize and Use TransactionBuilder Source: https://docs.rs/drift-rs/latest/drift_rs/struct Demonstrates how to initialize a TransactionBuilder with necessary context and use it to place multiple orders and cancel all existing orders. It also shows how to set the transaction to legacy mode and build the final transaction for signing and sending. ```Rust use drift_rs::{types::Context, TransactionBuilder, Wallet}; let wallet = Wallet::from_seed_bs58("seed"); let client = DriftClient::new(Context::DevNet, "api.example.com", wallet).await.unwrap(); let account_data = client.get_account(wallet.default_sub_account()).await.unwrap(); let tx = TransactionBuilder::new(client.program_data, wallet.default_sub_account(), account_data.into()) .cancel_all_orders() .place_orders(&[ NewOrder::default().build(), NewOrder::default().build(), ]) .legacy() .build(); let signature = client.sign_and_send(tx, &wallet).await?; ``` -------------------------------- ### Get Field by Offset (Mut) Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/types/struct Gets a mutable reference to a field identified by its offset, assuming alignment. ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F; ``` -------------------------------- ### Get Field by Offset (Const) Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/types/struct Gets a const reference to a field identified by its offset, assuming alignment. ```Rust fn f_get(&self, offset: FieldOffset) -> &F; ``` -------------------------------- ### Drift Protocol Instructions: User and System Updates Source: https://docs.rs/drift-rs/latest/drift_rs/all Contains instructions for updating user-specific settings and system-wide parameters. ```rust pub struct ChangeSignedMsgWsDelegateStatus; pub struct InitializeSignedMsgWsDelegates; ``` -------------------------------- ### Get Field Pointer by Offset (Mut) Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/types/struct Gets a mutable pointer to a field identified by its offset, with generic alignment. ```Rust fn f_get_mut_ptr(&mut self, offset: FieldOffset) -> *mut F; ``` -------------------------------- ### Initialize and Use Wallet in Rust Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Demonstrates how to initialize a `Wallet` in Rust from a base58 private key string, and how to construct wallets for delegated signing or read-only applications. ```Rust pub struct Wallet { /* private fields */ } ``` ```Rust // load wallet from base58 private key or path to wallet.json let wallet = Wallet::try_from_str("PRIVATE_KEY").unwrap(); // construct wallet for delegated signing let delegated_keypair = solana_sdk::signature::Keypair::new(); let delegated_wallet = Wallet::delegated(delegated_keypair, drift_account_key); // place holder wallet for readonly apps let ro_wallet = Wallet::read_only(drift_authority); ``` -------------------------------- ### Get Field Pointer by Offset (Const) Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/types/struct Gets a const pointer to a field identified by its offset, with generic alignment. ```Rust fn f_get_ptr(&self, offset: FieldOffset) -> *const F; ``` -------------------------------- ### Rust: TransactionBuilder - Place and Make Source: https://docs.rs/drift-rs/latest/drift_rs/struct Adds a 'place and make' instruction for a trade. This is used when initiating a trade where you are the maker. It includes order details, taker information, and optional referrer and fulfillment type. ```Rust pub fn place_and_make( self, order: OrderParams, taker_info: &(Pubkey, User), taker_order_id: u32, referrer: Option, fulfillment_type: Option, ) -> Self ``` -------------------------------- ### Initialize Wallet from Seed Bytes in Rust Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Demonstrates initializing a `Wallet` in Rust from a slice of seed bytes, using the default sub-account. ```Rust pub fn from_seed(seed: &[u8]) -> SdkResult ``` -------------------------------- ### Get Reference to Field (Rust) Source: https://docs.rs/drift-rs/latest/drift_rs/math/struct Gets a reference to a field within a struct, determined by an offset. This is part of an FFI-safe mechanism for accessing struct fields. ```Rust fn as_c_ref(from: &'a T) -> >::RefC ``` -------------------------------- ### Initialize Wallet from String in Rust Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Shows how to initialize a `Wallet` in Rust using `try_from_str`, supporting both private key strings and file paths. ```Rust // from private key str let wallet = Wallet::try_from_str("PRIVATE_KEY").unwrap(); // from file path let wallet = Wallet::try_from_str("/path/to/wallet.json").unwrap(); ``` -------------------------------- ### Rust: MarketMap::get Method Source: https://docs.rs/drift-rs/latest/drift_rs/marketmap/struct The `get` method retrieves a market account by its `market_index`. It returns an `Option>`, which is `Some` if the market exists and `None` otherwise. ```Rust pub fn get(&self, market_index: &u16) -> Option> ``` -------------------------------- ### Initialize Wallet with Keypair in Rust Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Shows how to initialize a `Wallet` in Rust using a `Keypair` for transaction signing. ```Rust pub fn new(authority: Keypair) -> Self ``` -------------------------------- ### Get Field Copy by Offset (Aligned) Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/types/struct Gets a copy of a field (identified by offset). The field must implement Copy. Assumes alignment. ```Rust fn f_get_copy(&self, offset: FieldOffset) -> F where F: Copy, ``` -------------------------------- ### Rust: Get Field Reference Source: https://docs.rs/drift-rs/latest/drift_rs/priority_fee_subscriber/struct Provides methods to get a reference to a field within a struct using `FieldOffset`. This is useful for accessing struct members by offset. ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` -------------------------------- ### Rust: TransactionBuilder - Place and Take Source: https://docs.rs/drift-rs/latest/drift_rs/struct Adds a 'place and take' instruction for a trade. This is used when initiating a trade where you are the taker. It includes order details, maker information, and optional referrer, fulfillment type, and success condition. ```Rust pub fn place_and_take( self, order: OrderParams, maker_info: Option<(Pubkey, User)>, referrer: Option, fulfillment_type: Option, success_condition: Option, ) -> Self ``` -------------------------------- ### Get Field by Offset (Aligned) Source: https://docs.rs/drift-rs/latest/drift_rs/swift_order_subscriber/struct Provides methods to access fields of a struct `S` using `FieldOffset` for aligned fields. Includes getting references, mutable references, and pointers. ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` ```Rust fn f_get_ptr(&self, offset: FieldOffset) -> *const F ``` ```Rust fn f_get_mut_ptr(&mut self, offset: FieldOffset) -> *mut F ``` -------------------------------- ### Simulate Placing Perp Order - Rust Source: https://docs.rs/drift-rs/latest/drift_rs/ffi/index Simulates the program's `place_perp_order` instruction. This is useful for verifying if an order can be placed given factors like available margin. ```Rust pub fn simulate_place_perp_order( state_index: u8, account_index: u8, order: &mut PerpOrder, margin_requirement: u64, total_collateral: u64, liability_info: &mut LiabilityInfo, ) -> Result<()> ``` -------------------------------- ### Protocol Configuration and State Management Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/accounts/index Functions for configuring and managing the overall protocol state, including settings for protected maker modes, share transfers, and general protocol initialization. ```rust InitializePredictionMarket InitializeProtectedMakerModeConfig InitializeProtocolIfSharesTransferConfig ProtectedMakerModeConfig ProtocolIfSharesTransferConfig UpdateProtectedMakerModeConfig UpdateProtocolIfSharesTransferConfig ``` -------------------------------- ### Rust: Get Mutable Field Reference Source: https://docs.rs/drift-rs/latest/drift_rs/priority_fee_subscriber/struct Provides methods to get a mutable reference to a field within a struct using `FieldOffset`. This allows modification of struct members by offset. ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` -------------------------------- ### Drift Protocol: Place and Take Spot Order Source: https://docs.rs/drift-rs/latest/drift_rs/all Enables placing a spot market order and taking liquidity on the Drift Protocol. This instruction is for immediate execution against existing orders. ```Rust drift_idl::instructions::PlaceAndTakeSpotOrder ``` -------------------------------- ### Get Field Reference (Aligned) Source: https://docs.rs/drift-rs/latest/drift_rs/blockhash_subscriber/struct Provides methods to get references to fields within a struct based on an `FieldOffset`. Supports both immutable and mutable access, as well as raw pointers. ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` ```Rust fn f_get_ptr(&self, offset: FieldOffset) -> *const F ``` ```Rust fn f_get_mut_ptr(&mut self, offset: FieldOffset) -> *mut F ``` -------------------------------- ### Rust: Type conversion with turbofish syntax Source: https://docs.rs/drift-rs/latest/drift_rs/grpc/grpc_subscriber/struct Provides methods to perform type conversions using the turbofish syntax (`::<>`). This includes `into_`, `as_ref_`, and `as_mut_` for various reference conversions. ```Rust fn into_(self) -> T where Self: Into ``` ```Rust fn as_ref_(&self) -> &T where Self: AsRef, T: ?Sized ``` ```Rust fn as_mut_(&mut self) -> &mut T where Self: AsMut, T: ?Sized ``` -------------------------------- ### Get Field by Offset in Rust (Aligned) Source: https://docs.rs/drift-rs/latest/drift_rs/swift_order_subscriber/enum Provides methods to access fields of a struct `S` using `FieldOffset` for aligned memory layouts. Includes getting references, mutable references, and pointers to fields. ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` ```Rust fn f_get_ptr(&self, offset: FieldOffset) -> *const F ``` ```Rust fn f_get_mut_ptr(&mut self, offset: FieldOffset) -> *mut F ``` -------------------------------- ### Get Field Reference (Aligned) Source: https://docs.rs/drift-rs/latest/drift_rs/struct Provides methods to get references to fields within a struct based on an `FieldOffset`. Supports both immutable and mutable access, as well as raw pointers. ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` ```Rust fn f_get_ptr(&self, offset: FieldOffset) -> *const F ``` ```Rust fn f_get_mut_ptr(&mut self, offset: FieldOffset) -> *mut F ``` -------------------------------- ### JIT Client for Drift Protocol Source: https://docs.rs/drift-rs/latest/drift_rs/all Provides client functionalities for Just-In-Time (JIT) operations within the Drift Protocol. Includes parameters for compute budget, JIT instructions, and JIT swift operations. ```rust jit_client::ComputeBudgetParams jit_client::JitIxParams jit_client::JitProxyClient jit_client::JitSwiftParams ``` -------------------------------- ### drift_rs::drift_idl Module Documentation Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/accounts/index Provides documentation for the drift_idl module in the drift-rs crate. It covers IDL Account types, platform specifics, and feature flags. ```Rust /// IDL Account types /// Platform /// Feature flags ``` -------------------------------- ### Rust: Get Field Copy Source: https://docs.rs/drift-rs/latest/drift_rs/priority_fee_subscriber/struct Provides methods to get a copy of a field from a struct using `FieldOffset`, requiring the field type to implement `Copy`. This is useful for obtaining field values without borrowing. ```Rust fn f_get_copy(&self, offset: FieldOffset) -> F where F: Copy, ``` ```Rust fn f_get_copy(&self, offset: FieldOffset) -> F where F: Copy, ``` -------------------------------- ### Rust: TransactionBuilder - Place and Make Swift Order Source: https://docs.rs/drift-rs/latest/drift_rs/struct Adds a 'place and make' instruction for a swift order (Perpetuals only). This is used when the maker defines the order parameters and the taker provides signed order information. ```Rust pub fn place_and_make_swift_order( self, maker_order: OrderParams, signed_order_info: &SignedOrderInfo, taker_account: &User, taker_account_referrer: &Pubkey, ) -> Self ``` -------------------------------- ### Get FFI-safe Reference Source: https://docs.rs/drift-rs/latest/drift_rs/account_map/struct Provides an FFI-safe equivalent of a reference to `Self`. ```Rust type RefC = &'a T ``` -------------------------------- ### Rust Blanket Implementation: CloneToUninit for T Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/instructions/struct Details the blanket implementation of `CloneToUninit` for any type `T` that implements `Clone`, facilitating initialization of uninitialized memory. ```Rust impl CloneToUninit for T where T: Clone, ``` -------------------------------- ### FGet Method Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Gets a reference to a field using an offset. Part of `ROExtAcc`. ```Rust fn f_get(&self, offset: FieldOffset) -> &F ``` -------------------------------- ### Create DriftGrpcClient Source: https://docs.rs/drift-rs/latest/drift_rs/grpc/grpc_subscriber/struct Initializes a new DriftGrpcClient with the specified endpoint and authentication token. This client is used to interact with Drift's gRPC services. ```Rust pub struct DriftGrpcClient { /* private fields */ } impl DriftGrpcClient { pub fn new(endpoint: String, x_token: String) -> Self { // ... implementation details ... } } ``` -------------------------------- ### Rust Get TypeId Source: https://docs.rs/drift-rs/latest/drift_rs/drift_idl/types/enum Retrieves the `TypeId` of a given object. ```Rust impl Any for T where T: 'static + ?Sized { fn type_id(&self) -> TypeId; } ``` -------------------------------- ### FGetMutPtr Method Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Gets a mutable pointer to a field using an offset. Part of `ROExtAcc`. ```Rust fn f_get_mut_ptr(&mut self, offset: FieldOffset) -> *mut F ``` -------------------------------- ### Drift Protocol Instructions: Market Operations Source: https://docs.rs/drift-rs/latest/drift_rs/all Defines instructions for interacting with and managing perpetual and spot markets. ```rust pub struct AdminDisableUpdatePerpBidAskTwap; pub struct BeginSwap; pub struct DeleteInitializedPerpMarket; pub struct DeleteInitializedSpotMarket; pub struct DeletePrelaunchOracle; pub struct DeleteSignedMsgUserOrders; pub struct EndSwap; pub struct FillPerpOrder; pub struct FillSpotOrder; pub struct ForceCancelOrders; pub struct InitializeOpenbookV2FulfillmentConfig; pub struct InitializePerpMarket; pub struct InitializePhoenixFulfillmentConfig; pub struct InitializePredictionMarket; pub struct InitializePrelaunchOracle; pub struct InitializeProtectedMakerModeConfig; pub struct InitializeProtocolIfSharesTransferConfig; pub struct InitializePythLazerOracle; pub struct InitializePythPullOracle; pub struct InitializeReferrerName; pub struct InitializeSerumFulfillmentConfig; pub struct InitializeSignedMsgUserOrders; pub struct InitializeSignedMsgWsDelegates; pub struct InitializeSpotMarket; pub struct LiquidateBorrowForPerpPnl; pub struct LiquidatePerp; pub struct LiquidatePerpPnlForDeposit; pub struct LiquidatePerpWithFill; pub struct LiquidateSpot; pub struct LiquidateSpotWithSwapBegin; pub struct LiquidateSpotWithSwapEnd; pub struct ModifyOrder; ``` -------------------------------- ### Rust: MarketMap::new Constructor Source: https://docs.rs/drift-rs/latest/drift_rs/marketmap/struct The `new` function is a constructor for the `MarketMap` struct. It takes an `Arc` and `CommitmentConfig` as arguments to initialize the market map, likely for subscribing to updates. ```Rust pub fn new(pubsub: Arc, commitment: CommitmentConfig) -> Self> ``` -------------------------------- ### FGetPtr Method Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Gets a const pointer to a field using an offset. Part of `ROExtAcc`. ```Rust fn f_get_ptr(&self, offset: FieldOffset) -> *const F ``` -------------------------------- ### FGetMut Method Source: https://docs.rs/drift-rs/latest/drift_rs/wallet/struct Gets a mutable reference to a field using an offset. Part of `ROExtAcc`. ```Rust fn f_get_mut(&mut self, offset: FieldOffset) -> &mut F ``` -------------------------------- ### Rust CloneToUninit Experimental API Source: https://docs.rs/drift-rs/latest/drift_rs/jit_client/enum An experimental, nightly-only API for performing copy-assignment from self to a destination pointer. Requires the type to implement Clone. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ```