Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Jan 28, 2024
1 parent 49501f1 commit e474508
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
7 changes: 7 additions & 0 deletions programs/drift/src/controller/pnl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions programs/drift/src/controller/spot_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 0 additions & 17 deletions programs/drift/src/instructions/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/src/state/paused_operations.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand Down
8 changes: 4 additions & 4 deletions programs/drift/src/state/perp_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e474508

Please sign in to comment.