Skip to content

Commit

Permalink
look at config in ix to turn on mode
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 29, 2024
1 parent 9d371e1 commit a10366a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion programs/drift/src/instructions/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ use crate::state::paused_operations::{PerpOperation, SpotOperation};
use crate::state::perp_market::ContractType;
use crate::state::perp_market::MarketStatus;
use crate::state::perp_market_map::{get_writable_perp_market_set, MarketSet};
use crate::state::protected_maker_mode_config::ProtectedMakerModeConfig;
use crate::state::rfq_user::{load_rfq_user_account_map, RFQUser, RFQ_PDA_SEED};
use crate::state::spot_fulfillment_params::SpotFulfillmentParams;
use crate::state::spot_market::SpotBalanceType;
Expand Down Expand Up @@ -2286,7 +2287,7 @@ pub fn handle_update_user_advanced_lp(
}

pub fn handle_update_user_protected_maker_orders(
ctx: Context<UpdateUser>,
ctx: Context<UpdateUserProtectedMakerMode>,
_sub_account_id: u16,
protected_maker_orders: bool,
) -> Result<()> {
Expand All @@ -2295,6 +2296,23 @@ pub fn handle_update_user_protected_maker_orders(
validate!(!user.is_being_liquidated(), ErrorCode::LiquidationsOngoing)?;

user.update_protected_maker_orders_status(protected_maker_orders)?;

let mut config = load_mut!(ctx.accounts.protected_maker_mode_config)?;

if protected_maker_orders {
validate!(
!config.is_reduce_only(),
ErrorCode::DefaultError,
"protected maker mode config reduce only"
)?;

config.current_users = config.current_users.safe_add(1)?;
} else {
config.current_users = config.current_users.safe_sub(1)?;
}

config.validate()?;

Ok(())
}

Expand Down Expand Up @@ -2976,6 +2994,24 @@ pub struct EnableUserHighLeverageMode<'info> {
pub high_leverage_mode_config: AccountLoader<'info, HighLeverageModeConfig>,
}

#[derive(Accounts)]
#[instruction(
sub_account_id: u16,
)]
pub struct UpdateUserProtectedMakerMode<'info> {
pub state: Box<Account<'info, State>>,
#[account(
mut,
seeds = [b"user", authority.key.as_ref(), sub_account_id.to_le_bytes().as_ref()],
bump,
)]
pub user: AccountLoader<'info, User>,
pub authority: Signer<'info>,
#[account(mut)]
pub protected_maker_mode_config: AccountLoader<'info, ProtectedMakerModeConfig>,
}


#[access_control(
fill_not_paused(&ctx.accounts.state)
)]
Expand Down
2 changes: 1 addition & 1 deletion programs/drift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub mod drift {
}

pub fn update_user_protected_maker_orders(
ctx: Context<UpdateUser>,
ctx: Context<UpdateUserProtectedMakerMode>,
_sub_account_id: u16,
protected_maker_orders: bool,
) -> Result<()> {
Expand Down

0 comments on commit a10366a

Please sign in to comment.