diff --git a/programs/drift/src/controller/pnl.rs b/programs/drift/src/controller/pnl.rs index 8776a29fd..3a52772f7 100644 --- a/programs/drift/src/controller/pnl.rs +++ b/programs/drift/src/controller/pnl.rs @@ -26,6 +26,7 @@ use crate::state::margin_calculation::MarginContext; use crate::state::events::{OrderActionExplanation, SettlePnlExplanation, SettlePnlRecord}; use crate::state::oracle_map::OracleMap; +use crate::state::paused_operations::PausedOperations; use crate::state::perp_market::MarketStatus; use crate::state::perp_market_map::PerpMarketMap; use crate::state::spot_market::{SpotBalance, SpotBalanceType}; @@ -140,6 +141,12 @@ pub fn settle_pnl( "Cannot settle pnl under current market status" )?; + validate!( + perp_market.is_operation_paused(PausedOperations::Withdraw), + ErrorCode::InvalidMarketStatusToSettlePnl, + "Cannot settle pnl under current market status" + )?; + let pnl_pool_token_amount = get_token_amount( perp_market.pnl_pool.scaled_balance, spot_market, diff --git a/programs/drift/src/controller/spot_position.rs b/programs/drift/src/controller/spot_position.rs index 8ca185f0a..68ec56aa3 100644 --- a/programs/drift/src/controller/spot_position.rs +++ b/programs/drift/src/controller/spot_position.rs @@ -9,6 +9,7 @@ use crate::math::safe_math::SafeMath; use crate::math::spot_withdraw::check_withdraw_limits; use crate::safe_decrement; use crate::safe_increment; +use crate::state::paused_operations::PausedOperations; use crate::state::perp_market::MarketStatus; use crate::state::spot_market::{AssetTier, SpotBalance, SpotBalanceType, SpotMarket}; use crate::state::user::{SpotPosition, User, UserStats}; @@ -134,6 +135,13 @@ pub fn update_spot_balances_and_cumulative_deposits_with_limits( spot_market.market_index )?; + validate!( + spot_market.is_operation_paused(PausedOperations::Withdraw), + ErrorCode::MarketWithdrawPaused, + "Spot Market {} withdraws are currently paused", + spot_market.market_index + )?; + validate!( !(spot_market.asset_tier == AssetTier::Protected && user.spot_positions[spot_position_index].balance_type() == &SpotBalanceType::Borrow), diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index 102fa2a05..fc8e7515a 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -641,23 +641,6 @@ pub fn handle_transfer_deposit( { let spot_market = &mut spot_market_map.get_ref_mut(&market_index)?; - validate!( - matches!( - spot_market.status, - MarketStatus::Active | MarketStatus::ReduceOnly | MarketStatus::Settlement - ), - ErrorCode::MarketWithdrawPaused, - "Spot Market {} withdraws are currently paused", - spot_market.market_index - )?; - - validate!( - spot_market.is_operation_paused(PausedOperations::Withdraw), - ErrorCode::MarketWithdrawPaused, - "Spot Market {} withdraws are currently paused", - spot_market.market_index - )?; - from_user.increment_total_withdraws( amount, oracle_price, diff --git a/programs/drift/src/state/paused_operations.rs b/programs/drift/src/state/paused_operations.rs index b3cf1ac2f..9701321af 100644 --- a/programs/drift/src/state/paused_operations.rs +++ b/programs/drift/src/state/paused_operations.rs @@ -1,12 +1,12 @@ #[derive(Clone, Copy, PartialEq, Debug, Eq)] pub enum PausedOperations { - /// funding rate updates are paused + /// perps: funding | spot: interest Funding = 0b00000001, /// amm fills are prevented/blocked AmmFills = 0b00000010, /// fills are blocked Fill = 0b00000100, - /// perp: pause settling negative pnl | spot: pause depositing asset + /// perp: pause settling pnl | spot: withdraw asset Withdraw = 0b00001000, } diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index a43924c7e..7cd8dfac5 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -44,13 +44,13 @@ pub enum MarketStatus { Initialized, /// all operations allowed Active, - /// funding rate updates are paused + /// Deprecated in favor of PausedOperations FundingPaused, - /// amm fills are prevented/blocked + /// Deprecated in favor of PausedOperations AmmPaused, - /// fills are blocked + /// Deprecated in favor of PausedOperations FillPaused, - /// perp: pause settling negative pnl | spot: pause depositing asset + /// Deprecated in favor of PausedOperations WithdrawPaused, /// fills only able to reduce liability ReduceOnly,