From 7893dc7cb163e05bf768468c4d95af9f0b375569 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Fri, 25 Apr 2025 12:56:12 +0800 Subject: [PATCH] ioc => bit_flags on OrderParams --- crates/src/drift_idl.rs | 106 ++++++++++++++++++++++++++- crates/src/ffi.rs | 2 +- crates/src/swift_order_subscriber.rs | 2 +- crates/src/types.rs | 10 +-- res/drift.json | 65 ++++++++++++++-- 5 files changed, 169 insertions(+), 16 deletions(-) diff --git a/crates/src/drift_idl.rs b/crates/src/drift_idl.rs index 7a3d1b9..58ec1a0 100644 --- a/crates/src/drift_idl.rs +++ b/crates/src/drift_idl.rs @@ -12,7 +12,7 @@ use anchor_lang::{ }; use serde::{Deserialize, Serialize}; use solana_sdk::{instruction::AccountMeta, pubkey::Pubkey}; -pub const IDL_VERSION: &str = "2.118.0"; +pub const IDL_VERSION: &str = "2.119.0"; use self::traits::ToAccountMetas; pub mod traits { use solana_sdk::instruction::AccountMeta; @@ -1893,6 +1893,17 @@ pub mod instructions { #[automatically_derived] impl anchor_lang::InstructionData for UpdatePerpMarketFuel {} #[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] + pub struct UpdatePerpMarketProtectedMakerParams { + pub protected_maker_limit_price_divisor: Option, + pub protected_maker_dynamic_divisor: Option, + } + #[automatically_derived] + impl anchor_lang::Discriminator for UpdatePerpMarketProtectedMakerParams { + const DISCRIMINATOR: &[u8] = &[249, 213, 115, 34, 253, 239, 75, 173]; + } + #[automatically_derived] + impl anchor_lang::InstructionData for UpdatePerpMarketProtectedMakerParams {} + #[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] pub struct UpdateSpotMarketFuel { pub fuel_boost_deposits: Option, pub fuel_boost_borrows: Option, @@ -2455,7 +2466,7 @@ pub mod types { pub market_index: u16, pub reduce_only: bool, pub post_only: PostOnlyParam, - pub immediate_or_cancel: bool, + pub bit_flags: u8, pub max_ts: Option, pub trigger_price: Option, pub trigger_condition: OrderTriggerCondition, @@ -2542,7 +2553,7 @@ pub mod types { pub price: Option, pub reduce_only: Option, pub post_only: Option, - pub immediate_or_cancel: Option, + pub bit_flags: Option, pub max_ts: Option, pub trigger_price: Option, pub trigger_condition: Option, @@ -3469,6 +3480,23 @@ pub mod types { Debug, PartialEq, )] + pub enum OrderParamsBitFlag { + #[default] + ImmediateOrCancel, + UpdateHighLeverageMode, + } + #[derive( + AnchorSerialize, + AnchorDeserialize, + InitSpace, + Serialize, + Deserialize, + Copy, + Clone, + Default, + Debug, + PartialEq, + )] pub enum PostOnlyParam { #[default] None, @@ -19131,6 +19159,76 @@ pub mod accounts { } #[repr(C)] #[derive(Copy, Clone, Default, AnchorSerialize, AnchorDeserialize, Serialize, Deserialize)] + pub struct UpdatePerpMarketProtectedMakerParams { + pub admin: Pubkey, + pub state: Pubkey, + pub perp_market: Pubkey, + } + #[automatically_derived] + impl anchor_lang::Discriminator for UpdatePerpMarketProtectedMakerParams { + const DISCRIMINATOR: &[u8] = &[31, 187, 231, 244, 165, 74, 103, 137]; + } + #[automatically_derived] + unsafe impl anchor_lang::__private::bytemuck::Pod for UpdatePerpMarketProtectedMakerParams {} + #[automatically_derived] + unsafe impl anchor_lang::__private::bytemuck::Zeroable for UpdatePerpMarketProtectedMakerParams {} + #[automatically_derived] + impl anchor_lang::ZeroCopy for UpdatePerpMarketProtectedMakerParams {} + #[automatically_derived] + impl anchor_lang::InstructionData for UpdatePerpMarketProtectedMakerParams {} + #[automatically_derived] + impl ToAccountMetas for UpdatePerpMarketProtectedMakerParams { + fn to_account_metas(&self) -> Vec { + vec![ + AccountMeta { + pubkey: self.admin, + is_signer: true, + is_writable: false, + }, + AccountMeta { + pubkey: self.state, + is_signer: false, + is_writable: false, + }, + AccountMeta { + pubkey: self.perp_market, + is_signer: false, + is_writable: true, + }, + ] + } + } + #[automatically_derived] + impl anchor_lang::AccountSerialize for UpdatePerpMarketProtectedMakerParams { + fn try_serialize(&self, writer: &mut W) -> anchor_lang::Result<()> { + if writer.write_all(Self::DISCRIMINATOR).is_err() { + return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into()); + } + if AnchorSerialize::serialize(self, writer).is_err() { + return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into()); + } + Ok(()) + } + } + #[automatically_derived] + impl anchor_lang::AccountDeserialize for UpdatePerpMarketProtectedMakerParams { + fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result { + let given_disc = &buf[..8]; + if Self::DISCRIMINATOR != given_disc { + return Err(anchor_lang::error!( + anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch + )); + } + Self::try_deserialize_unchecked(buf) + } + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + let mut data: &[u8] = &buf[8..]; + AnchorDeserialize::deserialize(&mut data) + .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into()) + } + } + #[repr(C)] + #[derive(Copy, Clone, Default, AnchorSerialize, AnchorDeserialize, Serialize, Deserialize)] pub struct UpdateSpotMarketFuel { pub admin: Pubkey, pub state: Pubkey, @@ -21221,6 +21319,8 @@ pub mod errors { InvalidTransferPerpPosition, #[msg("Invalid SignedMsgUserOrders resize")] InvalidSignedMsgUserOrdersResize, + #[msg("Could not deserialize high leverage mode config")] + CouldNotDeserializeHighLeverageModeConfig, } } pub mod events { diff --git a/crates/src/ffi.rs b/crates/src/ffi.rs index 89091f7..6faa206 100644 --- a/crates/src/ffi.rs +++ b/crates/src/ffi.rs @@ -204,7 +204,7 @@ pub fn simulate_place_perp_order( /// /// Returns `true` if the order's auctions will get sanitized pub fn simulate_will_auction_params_sanitize( - order_params: &mut types::OrderParams, + order_params: &types::OrderParams, perp_market: &accounts::PerpMarket, oracle_price: i64, is_signed_msg: bool, diff --git a/crates/src/swift_order_subscriber.rs b/crates/src/swift_order_subscriber.rs index c0a958f..d62c325 100644 --- a/crates/src/swift_order_subscriber.rs +++ b/crates/src/swift_order_subscriber.rs @@ -510,7 +510,7 @@ mod tests { market_index: 2, reduce_only: false, post_only: PostOnlyParam::None, - immediate_or_cancel: false, + bit_flags: 0, max_ts: None, trigger_price: None, trigger_condition: OrderTriggerCondition::Above, diff --git a/crates/src/types.rs b/crates/src/types.rs index 9dfcb64..489d021 100644 --- a/crates/src/types.rs +++ b/crates/src/types.rs @@ -207,7 +207,7 @@ pub struct NewOrder { reduce_only: bool, market_id: MarketId, post_only: PostOnlyParam, - ioc: bool, + ioc: u8, amount: u64, price: u64, user_order_id: u8, @@ -253,9 +253,9 @@ impl NewOrder { self.reduce_only = flag; self } - /// Set immediate or cancel (default: false) - pub fn ioc(mut self, flag: bool) -> Self { - self.ioc = flag; + /// Set immediate or cancel and other flags (default: false) + pub fn bit_flags(mut self, flags: u8) -> Self { + self.ioc = flags; self } /// Set post-only (default: None) @@ -278,7 +278,7 @@ impl NewOrder { base_asset_amount: self.amount, reduce_only: self.reduce_only, direction: self.direction, - immediate_or_cancel: self.ioc, + bit_flags: self.ioc, post_only: self.post_only, user_order_id: self.user_order_id, ..Default::default() diff --git a/res/drift.json b/res/drift.json index e54f60e..85d8928 100644 --- a/res/drift.json +++ b/res/drift.json @@ -1,5 +1,5 @@ { - "version": "2.118.0", + "version": "2.119.0", "name": "drift", "instructions": [ { @@ -6415,6 +6415,40 @@ } ] }, + { + "name": "updatePerpMarketProtectedMakerParams", + "accounts": [ + { + "name": "admin", + "isMut": false, + "isSigner": true + }, + { + "name": "state", + "isMut": false, + "isSigner": false + }, + { + "name": "perpMarket", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "protectedMakerLimitPriceDivisor", + "type": { + "option": "u8" + } + }, + { + "name": "protectedMakerDynamicDivisor", + "type": { + "option": "u8" + } + } + ] + }, { "name": "updateSpotMarketFuel", "accounts": [ @@ -9436,8 +9470,8 @@ } }, { - "name": "immediateOrCancel", - "type": "bool" + "name": "bitFlags", + "type": "u8" }, { "name": "maxTs", @@ -9634,9 +9668,9 @@ } }, { - "name": "immediateOrCancel", + "name": "bitFlags", "type": { - "option": "bool" + "option": "u8" } }, { @@ -11714,6 +11748,20 @@ ] } }, + { + "name": "OrderParamsBitFlag", + "type": { + "kind": "enum", + "variants": [ + { + "name": "ImmediateOrCancel" + }, + { + "name": "UpdateHighLeverageMode" + } + ] + } + }, { "name": "PostOnlyParam", "type": { @@ -15078,9 +15126,14 @@ "code": 6313, "name": "InvalidSignedMsgUserOrdersResize", "msg": "Invalid SignedMsgUserOrders resize" + }, + { + "code": 6314, + "name": "CouldNotDeserializeHighLeverageModeConfig", + "msg": "Could not deserialize high leverage mode config" } ], "metadata": { "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" } -} +} \ No newline at end of file