From 3f148a8b0d8c979fec71a673845ad7ceb140bf53 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 26 Nov 2024 08:37:20 -0600 Subject: [PATCH] rename get_oracle_id to oracle_id --- programs/drift/src/controller/funding.rs | 4 +- programs/drift/src/controller/liquidation.rs | 40 +++++++++------ programs/drift/src/controller/lp.rs | 2 +- programs/drift/src/controller/orders.rs | 54 +++++++++++--------- programs/drift/src/controller/pnl.rs | 4 +- programs/drift/src/controller/repeg.rs | 4 +- programs/drift/src/instructions/keeper.rs | 10 ++-- programs/drift/src/instructions/user.rs | 20 ++++---- programs/drift/src/math/margin.rs | 16 +++--- programs/drift/src/math/orders.rs | 6 +-- programs/drift/src/state/oracle.rs | 4 +- programs/drift/src/state/oracle_map.rs | 5 +- programs/drift/src/state/perp_market.rs | 2 +- programs/drift/src/state/spot_market.rs | 2 +- 14 files changed, 93 insertions(+), 80 deletions(-) diff --git a/programs/drift/src/controller/funding.rs b/programs/drift/src/controller/funding.rs index 1d83b2b53..a66d7c9cc 100644 --- a/programs/drift/src/controller/funding.rs +++ b/programs/drift/src/controller/funding.rs @@ -170,7 +170,7 @@ pub fn update_funding_rate( // Pause funding if oracle is invalid or if mark/oracle spread is too divergent let block_funding_rate_update = oracle::block_operation( market, - oracle_map.get_price_data(&market.get_oracle_id())?, + oracle_map.get_price_data(&market.oracle_id())?, guard_rails, reserve_price, slot, @@ -186,7 +186,7 @@ pub fn update_funding_rate( !funding_paused && !block_funding_rate_update && (time_until_next_update == 0); if valid_funding_update { - let oracle_price_data = oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id())?; let sanitize_clamp_denominator = market.get_sanitize_clamp_denominator()?; let oracle_price_twap = amm::update_oracle_price_twap( diff --git a/programs/drift/src/controller/liquidation.rs b/programs/drift/src/controller/liquidation.rs index 62a2aec91..fc60db395 100644 --- a/programs/drift/src/controller/liquidation.rs +++ b/programs/drift/src/controller/liquidation.rs @@ -194,7 +194,7 @@ pub fn liquidate_perp( )?; let mut market = perp_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id())?; update_amm_and_check_validity( &mut market, @@ -333,7 +333,9 @@ pub fn liquidate_perp( let market = perp_market_map.get_ref(&market_index)?; let quote_spot_market = spot_market_map.get_ref(&market.quote_spot_market_index)?; - let quote_oracle_price = oracle_map.get_price_data("e_spot_market.get_oracle_id())?.price; + let quote_oracle_price = oracle_map + .get_price_data("e_spot_market.oracle_id())? + .price; let liquidator_fee = market.liquidator_fee; let if_liquidation_fee = calculate_perp_if_fee( intermediate_margin_calculation.tracked_market_margin_shortage(margin_shortage)?, @@ -773,7 +775,7 @@ pub fn liquidate_perp_with_fill( )?; let mut market = perp_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id())?; update_amm_and_check_validity( &mut market, @@ -901,7 +903,9 @@ pub fn liquidate_perp_with_fill( let market = perp_market_map.get_ref(&market_index)?; let quote_spot_market = spot_market_map.get_ref(&market.quote_spot_market_index)?; - let quote_oracle_price = oracle_map.get_price_data("e_spot_market.get_oracle_id())?.price; + let quote_oracle_price = oracle_map + .get_price_data("e_spot_market.oracle_id())? + .price; let liquidator_fee = market.liquidator_fee; let if_liquidation_fee = calculate_perp_if_fee( intermediate_margin_calculation.tracked_market_margin_shortage(margin_shortage)?, @@ -1203,7 +1207,7 @@ pub fn liquidate_spot( let (asset_amount, asset_price, asset_decimals, asset_weight, asset_liquidation_multiplier) = { let mut asset_market = spot_market_map.get_ref_mut(&asset_market_index)?; let (asset_price_data, validity_guard_rails) = - oracle_map.get_price_data_and_guard_rails(&asset_market.get_oracle_id())?; + oracle_map.get_price_data_and_guard_rails(&asset_market.oracle_id())?; update_spot_market_and_check_validity( &mut asset_market, @@ -1252,7 +1256,7 @@ pub fn liquidate_spot( ) = { let mut liability_market = spot_market_map.get_ref_mut(&liability_market_index)?; let (liability_price_data, validity_guard_rails) = - oracle_map.get_price_data_and_guard_rails(&liability_market.get_oracle_id())?; + oracle_map.get_price_data_and_guard_rails(&liability_market.oracle_id())?; update_spot_market_and_check_validity( &mut liability_market, @@ -1783,7 +1787,9 @@ pub fn liquidate_borrow_for_perp_pnl( let market = perp_market_map.get_ref(&perp_market_index)?; let quote_spot_market = spot_market_map.get_ref(&market.quote_spot_market_index)?; - let quote_price = oracle_map.get_price_data("e_spot_market.get_oracle_id())?.price; + let quote_price = oracle_map + .get_price_data("e_spot_market.oracle_id())? + .price; let pnl_asset_weight = market.get_unrealized_asset_weight(pnl, MarginRequirementType::Maintenance)?; @@ -1809,7 +1815,7 @@ pub fn liquidate_borrow_for_perp_pnl( ) = { let mut liability_market = spot_market_map.get_ref_mut(&liability_market_index)?; let (liability_price_data, validity_guard_rails) = - oracle_map.get_price_data_and_guard_rails(&liability_market.get_oracle_id())?; + oracle_map.get_price_data_and_guard_rails(&liability_market.oracle_id())?; update_spot_market_and_check_validity( &mut liability_market, @@ -1903,7 +1909,7 @@ pub fn liquidate_borrow_for_perp_pnl( if intermediate_margin_calculation.can_exit_liquidation()? { let market = perp_market_map.get_ref(&perp_market_index)?; - let market_oracle_price = oracle_map.get_price_data(&market.get_oracle_id())?.price; + let market_oracle_price = oracle_map.get_price_data(&market.oracle_id())?.price; emit!(LiquidationRecord { ts: now, @@ -2094,7 +2100,7 @@ pub fn liquidate_borrow_for_perp_pnl( let market_oracle_price = { let market = perp_market_map.get_ref_mut(&perp_market_index)?; - oracle_map.get_price_data(&market.get_oracle_id())?.price + oracle_map.get_price_data(&market.oracle_id())?.price }; emit!(LiquidationRecord { @@ -2232,7 +2238,7 @@ pub fn liquidate_perp_pnl_for_deposit( ) = { let mut asset_market = spot_market_map.get_ref_mut(&asset_market_index)?; let (asset_price_data, validity_guard_rails) = - oracle_map.get_price_data_and_guard_rails(&asset_market.get_oracle_id())?; + oracle_map.get_price_data_and_guard_rails(&asset_market.oracle_id())?; update_spot_market_and_check_validity( &mut asset_market, @@ -2309,7 +2315,9 @@ pub fn liquidate_perp_pnl_for_deposit( let market = perp_market_map.get_ref(&perp_market_index)?; let quote_spot_market = spot_market_map.get_ref(&market.quote_spot_market_index)?; - let quote_price = oracle_map.get_price_data("e_spot_market.get_oracle_id())?.price; + let quote_price = oracle_map + .get_price_data("e_spot_market.oracle_id())? + .price; ( unsettled_pnl.unsigned_abs(), @@ -2386,7 +2394,7 @@ pub fn liquidate_perp_pnl_for_deposit( if exiting_liq_territory || is_contract_tier_violation { let market = perp_market_map.get_ref(&perp_market_index)?; - let market_oracle_price = oracle_map.get_price_data(&market.get_oracle_id())?.price; + let market_oracle_price = oracle_map.get_price_data(&market.oracle_id())?.price; emit!(LiquidationRecord { ts: now, @@ -2589,7 +2597,7 @@ pub fn liquidate_perp_pnl_for_deposit( let market_oracle_price = { let market = perp_market_map.get_ref_mut(&perp_market_index)?; - oracle_map.get_price_data(&market.get_oracle_id())?.price + oracle_map.get_price_data(&market.oracle_id())?.price }; emit!(LiquidationRecord { @@ -2715,7 +2723,7 @@ pub fn resolve_perp_bankruptcy( // move if payment to pnl pool let spot_market = &mut spot_market_map.get_ref_mut("E_SPOT_MARKET_INDEX)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; update_spot_market_cumulative_interest(spot_market, Some(oracle_price_data), now)?; update_spot_balances( @@ -2936,7 +2944,7 @@ pub fn resolve_spot_bankruptcy( { let mut spot_market = spot_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = &oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = &oracle_map.get_price_data(&spot_market.oracle_id())?; let quote_social_loss = get_token_value( -borrow_amount.cast()?, spot_market.decimals, diff --git a/programs/drift/src/controller/lp.rs b/programs/drift/src/controller/lp.rs index 60a545206..e9e3f37e3 100644 --- a/programs/drift/src/controller/lp.rs +++ b/programs/drift/src/controller/lp.rs @@ -382,7 +382,7 @@ pub fn remove_perp_lp_shares( ErrorCode::InsufficientLPTokens )?; - let oracle_price = oracle_map.get_price_data(&market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&market.oracle_id())?.price; let (position_delta, pnl) = burn_lp_shares(position, &mut market, shares_to_burn, oracle_price)?; diff --git a/programs/drift/src/controller/orders.rs b/programs/drift/src/controller/orders.rs index e8ab04269..38a714ed7 100644 --- a/programs/drift/src/controller/orders.rs +++ b/programs/drift/src/controller/orders.rs @@ -210,7 +210,7 @@ pub fn place_perp_order( (existing_position_direction, base_asset_amount) }; - let oracle_price_data = oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id())?; // updates auction params for crossing limit orders w/out auction duration // dont modify if it's a liquidation @@ -286,7 +286,7 @@ pub fn place_perp_order( padding: [0; 3], }; - let valid_oracle_price = Some(oracle_map.get_price_data(&market.get_oracle_id())?.price); + let valid_oracle_price = Some(oracle_map.get_price_data(&market.oracle_id())?.price); match validate_order(&new_order, market, valid_oracle_price, slot) { Ok(()) => {} Err(ErrorCode::PlacePostOnlyLimitFailure) @@ -382,7 +382,7 @@ pub fn place_perp_order( taker_order, maker, maker_order, - oracle_map.get_price_data(&market.get_oracle_id())?.price, + oracle_map.get_price_data(&market.oracle_id())?.price, )?; emit_stack::<_, { OrderActionRecord::SIZE }>(order_action_record)?; @@ -802,9 +802,9 @@ pub fn cancel_order( validate!(order_status == OrderStatus::Open, ErrorCode::OrderNotOpen)?; let oracle_id = if is_perp_order { - perp_market_map.get_ref(&order_market_index)?.get_oracle_id() + perp_market_map.get_ref(&order_market_index)?.oracle_id() } else { - spot_market_map.get_ref(&order_market_index)?.get_oracle_id() + spot_market_map.get_ref(&order_market_index)?.oracle_id() }; if !skip_log { @@ -1179,7 +1179,7 @@ pub fn fill_perp_order( let (oracle_price_data, _oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Perp, market.market_index, - &market.get_oracle_id(), + &market.oracle_id(), market.amm.historical_oracle_data.last_oracle_price_twap, market.get_max_confidence_interval_multiplier()?, )?; @@ -1801,7 +1801,7 @@ fn fulfill_perp_order( let fulfillment_methods = { let market = perp_market_map.get_ref(&market_index)?; - let oracle_price = oracle_map.get_price_data(&market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&market.oracle_id())?.price; determine_perp_fulfillment_methods( &user.orders[user_order_index], @@ -2409,7 +2409,7 @@ pub fn fulfill_perp_order_with_amm( taker_order, maker, maker_order, - oracle_map.get_price_data(&market.get_oracle_id())?.price, + oracle_map.get_price_data(&market.oracle_id())?.price, )?; emit_stack::<_, { OrderActionRecord::SIZE }>(order_action_record)?; @@ -2486,7 +2486,7 @@ pub fn fulfill_perp_order_with_match( return Ok((0_u64, 0_u64, 0_u64)); } - let oracle_price = oracle_map.get_price_data(&market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&market.oracle_id())?.price; let taker_direction: PositionDirection = taker.orders[taker_order_index].direction; let taker_price = if let Some(taker_limit_price) = taker_limit_price { @@ -2830,7 +2830,7 @@ pub fn fulfill_perp_order_with_match( Some(taker.orders[taker_order_index]), Some(*maker_key), Some(maker.orders[maker_order_index]), - oracle_map.get_price_data(&market.get_oracle_id())?.price, + oracle_map.get_price_data(&market.oracle_id())?.price, )?; emit_stack::<_, { OrderActionRecord::SIZE }>(order_action_record)?; @@ -2949,7 +2949,7 @@ pub fn trigger_order( let (oracle_price_data, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Perp, perp_market.market_index, - &perp_market.get_oracle_id(), + &perp_market.oracle_id(), perp_market .amm .historical_oracle_data @@ -3299,10 +3299,10 @@ pub fn burn_user_lp_shares_for_risk_reduction( let quote_oracle_id = spot_market_map .get_ref(&market.quote_spot_market_index)? - .get_oracle_id(); + .oracle_id(); let quote_oracle_price = oracle_map.get_price_data("e_oracle_id)?.price; - let oracle_price_data = oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id())?; let oracle_price = if market.status == MarketStatus::Settlement { market.expiry_price @@ -3535,7 +3535,7 @@ pub fn place_spot_order( let token_amount = user.spot_positions[spot_position_index].get_token_amount(spot_market)?; let signed_token_amount = get_signed_token_amount(token_amount, &balance_type)?; - let oracle_price_data = *oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = *oracle_map.get_price_data(&spot_market.oracle_id())?; // Increment open orders for existing position let (existing_position_direction, order_base_asset_amount) = { @@ -3812,7 +3812,11 @@ pub fn fill_spot_order( }; let oracle_price = oracle_map - .get_price_data(&spot_market_map.get_ref_mut(&order_market_index)?.get_oracle_id())? + .get_price_data( + &spot_market_map + .get_ref_mut(&order_market_index)? + .oracle_id(), + )? .price; let maker_order_info = get_spot_maker_orders_info( perp_market_map, @@ -3832,11 +3836,11 @@ pub fn fill_spot_order( { let mut quote_market = spot_market_map.get_quote_spot_market_mut()?; - let oracle_price_data = oracle_map.get_price_data("e_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data("e_market.oracle_id())?; update_spot_market_cumulative_interest(&mut quote_market, Some(oracle_price_data), now)?; let mut base_market = spot_market_map.get_ref_mut(&order_market_index)?; - let oracle_price_data = oracle_map.get_price_data(&base_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&base_market.oracle_id())?; update_spot_market_cumulative_interest(&mut base_market, Some(oracle_price_data), now)?; fulfillment_params.validate_markets(&base_market, "e_market)?; @@ -3952,7 +3956,7 @@ pub fn fill_spot_order( spot_market.get_precision(), )?; - let oracle_price = oracle_map.get_price_data(&spot_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&spot_market.oracle_id())?.price; let oracle_twap_5min = spot_market .historical_oracle_data .last_oracle_price_twap_5min; @@ -4265,7 +4269,7 @@ fn fulfill_spot_order( } // todo come up with fallback price - let oracle_price = oracle_map.get_price_data(&base_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&base_market.oracle_id())?.price; let limit_price = user.orders[user_order_index].get_limit_price( Some(oracle_price), None, @@ -4367,8 +4371,8 @@ fn fulfill_spot_order( .force_get_spot_position_mut(base_market_index)? .get_signed_token_amount(&base_market)?; - let quote_price = oracle_map.get_price_data("e_market.get_oracle_id())?.price; - let base_price = oracle_map.get_price_data(&base_market.get_oracle_id())?.price; + let quote_price = oracle_map.get_price_data("e_market.oracle_id())?.price; + let base_price = oracle_map.get_price_data(&base_market.oracle_id())?.price; let strict_quote_price = StrictOraclePrice::new( quote_price, @@ -4579,7 +4583,7 @@ pub fn fulfill_spot_order_with_match( } let market_index = taker.orders[taker_order_index].market_index; - let oracle_price = oracle_map.get_price_data(&base_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&base_market.oracle_id())?.price; let taker_price = match taker.orders[taker_order_index].get_limit_price( Some(oracle_price), None, @@ -4881,7 +4885,7 @@ pub fn fulfill_spot_order_with_match( Some(taker.orders[taker_order_index]), Some(*maker_key), Some(maker.orders[maker_order_index]), - oracle_map.get_price_data(&base_market.get_oracle_id())?.price, + oracle_map.get_price_data(&base_market.oracle_id())?.price, )?; emit_stack::<_, { OrderActionRecord::SIZE }>(order_action_record)?; @@ -4917,7 +4921,7 @@ pub fn fulfill_spot_order_with_external_market( fee_structure: &FeeStructure, fulfillment_params: &mut dyn SpotFulfillmentParams, ) -> DriftResult<(u64, u64)> { - let oracle_price = oracle_map.get_price_data(&base_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&base_market.oracle_id())?.price; let taker_price = taker.orders[taker_order_index].get_limit_price( Some(oracle_price), None, @@ -5224,7 +5228,7 @@ pub fn trigger_spot_order( let (oracle_price_data, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Spot, spot_market.market_index, - &spot_market.get_oracle_id(), + &spot_market.oracle_id(), spot_market.historical_oracle_data.last_oracle_price_twap, spot_market.get_max_confidence_interval_multiplier()?, )?; diff --git a/programs/drift/src/controller/pnl.rs b/programs/drift/src/controller/pnl.rs index 1a4e72149..f1d88ed93 100644 --- a/programs/drift/src/controller/pnl.rs +++ b/programs/drift/src/controller/pnl.rs @@ -70,7 +70,7 @@ pub fn settle_pnl( let mut market = perp_market_map.get_ref_mut(&market_index)?; - let oracle_price = oracle_map.get_price_data(&market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&market.oracle_id())?.price; validate_market_within_price_band(&market, state, oracle_price)?; @@ -159,7 +159,7 @@ pub fn settle_pnl( let (_, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Perp, perp_market.market_index, - &perp_market.get_oracle_id(), + &perp_market.oracle_id(), perp_market .amm .historical_oracle_data diff --git a/programs/drift/src/controller/repeg.rs b/programs/drift/src/controller/repeg.rs index a13e3292a..79d0c033d 100644 --- a/programs/drift/src/controller/repeg.rs +++ b/programs/drift/src/controller/repeg.rs @@ -110,7 +110,7 @@ pub fn update_amms( let updated = true; // todo for (_key, market_account_loader) in perp_market_map.0.iter_mut() { let market = &mut load_mut!(market_account_loader)?; - let oracle_price_data = &oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = &oracle_map.get_price_data(&market.oracle_id())?; _update_amm(market, oracle_price_data, state, now, clock_slot)?; } @@ -125,7 +125,7 @@ pub fn update_amm( clock: &Clock, ) -> DriftResult { let market = &mut perp_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id())?; let cost_of_update = _update_amm( market, diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index c25c6a4e3..42dcf7eb0 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -1399,7 +1399,7 @@ pub fn handle_resolve_perp_pnl_deficit<'c: 'info, 'info>( "Market is in settlement mode", )?; - let oracle_price = oracle_map.get_price_data(&perp_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&perp_market.oracle_id())?.price; controller::orders::validate_market_within_price_band(perp_market, state, oracle_price)?; controller::insurance::resolve_perp_pnl_deficit( @@ -1682,7 +1682,7 @@ pub fn handle_update_funding_rate( Some(state.oracle_guard_rails), )?; - let oracle_price_data = &oracle_map.get_price_data(&perp_market.get_oracle_id())?; + let oracle_price_data = &oracle_map.get_price_data(&perp_market.oracle_id())?; controller::repeg::_update_amm(perp_market, oracle_price_data, state, now, clock_slot)?; validate!( @@ -1777,7 +1777,7 @@ pub fn handle_update_perp_bid_ask_twap<'c: 'info, 'info>( min_if_stake )?; - let oracle_price_data = oracle_map.get_price_data(&perp_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&perp_market.oracle_id())?; controller::repeg::_update_amm(perp_market, oracle_price_data, state, now, slot)?; let remaining_accounts_iter = &mut ctx.remaining_accounts.iter().peekable(); @@ -1939,7 +1939,7 @@ pub fn handle_update_spot_market_cumulative_interest( Some(state.oracle_guard_rails), )?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; if !state.funding_paused()? { controller::spot_balance::update_spot_market_cumulative_interest( @@ -2213,7 +2213,7 @@ pub fn handle_force_delete_user<'c: 'info, 'info>( } let spot_market = &mut spot_market_map.get_ref_mut(&spot_position.market_index)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; controller::spot_balance::update_spot_market_cumulative_interest( spot_market, diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index 38f3dc65e..fa7d542b6 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -355,7 +355,7 @@ pub fn handle_deposit<'c: 'info, 'info>( validate!(!user.is_bankrupt(), ErrorCode::UserBankrupt)?; let mut spot_market = spot_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = *oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = *oracle_map.get_price_data(&spot_market.oracle_id())?; validate!( !matches!(spot_market.status, MarketStatus::Initialized), @@ -523,7 +523,7 @@ pub fn handle_withdraw<'c: 'info, 'info>( let spot_market_is_reduce_only = { let spot_market = &mut spot_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; controller::spot_balance::update_spot_market_cumulative_interest( spot_market, @@ -566,7 +566,7 @@ pub fn handle_withdraw<'c: 'info, 'info>( }; let spot_market = &mut spot_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; user.increment_total_withdraws( amount, @@ -605,7 +605,7 @@ pub fn handle_withdraw<'c: 'info, 'info>( user.update_last_active_slot(slot); let mut spot_market = spot_market_map.get_ref_mut(&market_index)?; - let oracle_price = oracle_map.get_price_data(&spot_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&spot_market.oracle_id())?.price; let is_borrow = user .get_spot_position(market_index) @@ -714,7 +714,7 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>( { let spot_market = &mut spot_market_map.get_ref_mut(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; controller::spot_balance::update_spot_market_cumulative_interest( spot_market, Some(oracle_price_data), @@ -724,7 +724,7 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>( let oracle_price = { let spot_market = &spot_market_map.get_ref(&market_index)?; - oracle_map.get_price_data(&spot_market.get_oracle_id())?.price + oracle_map.get_price_data(&spot_market.oracle_id())?.price }; { @@ -2963,7 +2963,7 @@ pub fn handle_begin_swap<'c: 'info, 'info>( "begin_swap ended in invalid state" )?; - let in_oracle_data = oracle_map.get_price_data(&in_spot_market.get_oracle_id())?; + let in_oracle_data = oracle_map.get_price_data(&in_spot_market.oracle_id())?; controller::spot_balance::update_spot_market_cumulative_interest( &mut in_spot_market, Some(in_oracle_data), @@ -2986,7 +2986,7 @@ pub fn handle_begin_swap<'c: 'info, 'info>( "begin_swap ended in invalid state" )?; - let out_oracle_data = oracle_map.get_price_data(&out_spot_market.get_oracle_id())?; + let out_oracle_data = oracle_map.get_price_data(&out_spot_market.oracle_id())?; controller::spot_balance::update_spot_market_cumulative_interest( &mut out_spot_market, Some(out_oracle_data), @@ -3220,7 +3220,7 @@ pub fn handle_end_swap<'c: 'info, 'info>( "the in_spot_market must have a flash loan amount set" )?; - let in_oracle_data = oracle_map.get_price_data(&in_spot_market.get_oracle_id())?; + let in_oracle_data = oracle_map.get_price_data(&in_spot_market.oracle_id())?; let in_oracle_price = in_oracle_data.price; let mut out_spot_market = spot_market_map.get_ref_mut(&out_market_index)?; @@ -3232,7 +3232,7 @@ pub fn handle_end_swap<'c: 'info, 'info>( out_market_index )?; - let out_oracle_data = oracle_map.get_price_data(&out_spot_market.get_oracle_id())?; + let out_oracle_data = oracle_map.get_price_data(&out_spot_market.oracle_id())?; let out_oracle_price = out_oracle_data.price; let in_vault = &mut ctx.accounts.in_spot_market_vault; diff --git a/programs/drift/src/math/margin.rs b/programs/drift/src/math/margin.rs index de21499b8..15c84dddd 100644 --- a/programs/drift/src/math/margin.rs +++ b/programs/drift/src/math/margin.rs @@ -260,7 +260,7 @@ pub fn calculate_margin_requirement_and_total_collateral_and_liability_info( let (oracle_price_data, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Spot, spot_market.market_index, - &spot_market.get_oracle_id(), + &spot_market.oracle_id(), spot_market.historical_oracle_data.last_oracle_price_twap, spot_market.get_max_confidence_interval_multiplier()?, )?; @@ -483,7 +483,7 @@ pub fn calculate_margin_requirement_and_total_collateral_and_liability_info( .get_price_data_and_validity( MarketType::Spot, quote_spot_market.market_index, - "e_spot_market.get_oracle_id(), + "e_spot_market.oracle_id(), quote_spot_market .historical_oracle_data .last_oracle_price_twap, @@ -502,7 +502,7 @@ pub fn calculate_margin_requirement_and_total_collateral_and_liability_info( let (oracle_price_data, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Perp, market.market_index, - &market.get_oracle_id(), + &market.oracle_id(), market.amm.historical_oracle_data.last_oracle_price_twap, market.get_max_confidence_interval_multiplier()?, )?; @@ -763,7 +763,7 @@ pub fn calculate_max_withdrawable_amount( .get_spot_position(market_index)? .get_token_amount(spot_market)?; - let oracle_price = oracle_map.get_price_data(&spot_market.get_oracle_id())?.price; + let oracle_price = oracle_map.get_price_data(&spot_market.oracle_id())?.price; let asset_weight = spot_market.get_asset_weight( token_amount, @@ -837,7 +837,7 @@ pub fn validate_spot_margin_trading( let bids = spot_position.open_bids; if bids > 0 { let spot_market = spot_market_map.get_ref(&spot_position.market_index)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; let open_bids_value = get_token_value(-bids as i128, spot_market.decimals, oracle_price_data.price)?; @@ -880,7 +880,7 @@ pub fn calculate_user_equity( let (oracle_price_data, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Spot, spot_market.market_index, - &spot_market.get_oracle_id(), + &spot_market.oracle_id(), spot_market.historical_oracle_data.last_oracle_price_twap, spot_market.get_max_confidence_interval_multiplier()?, )?; @@ -907,7 +907,7 @@ pub fn calculate_user_equity( .get_price_data_and_validity( MarketType::Spot, quote_spot_market.market_index, - "e_spot_market.get_oracle_id(), + "e_spot_market.oracle_id(), quote_spot_market .historical_oracle_data .last_oracle_price_twap, @@ -923,7 +923,7 @@ pub fn calculate_user_equity( let (oracle_price_data, oracle_validity) = oracle_map.get_price_data_and_validity( MarketType::Perp, market.market_index, - &market.get_oracle_id(), + &market.oracle_id(), market.amm.historical_oracle_data.last_oracle_price_twap, market.get_max_confidence_interval_multiplier()?, )?; diff --git a/programs/drift/src/math/orders.rs b/programs/drift/src/math/orders.rs index 2b593a1c2..45553ab34 100644 --- a/programs/drift/src/math/orders.rs +++ b/programs/drift/src/math/orders.rs @@ -825,11 +825,11 @@ pub fn calculate_max_perp_order_size( let perp_market = perp_market_map.get_ref(&market_index)?; - let oracle_price_data_price = oracle_map.get_price_data(&perp_market.get_oracle_id())?.price; + let oracle_price_data_price = oracle_map.get_price_data(&perp_market.oracle_id())?.price; let quote_spot_market = spot_market_map.get_ref(&perp_market.quote_spot_market_index)?; let quote_oracle_price = oracle_map - .get_price_data("e_spot_market.get_oracle_id())? + .get_price_data("e_spot_market.oracle_id())? .price .max( quote_spot_market @@ -971,7 +971,7 @@ pub fn calculate_max_spot_order_size( let spot_market = spot_market_map.get_ref(&market_index)?; - let oracle_price_data = oracle_map.get_price_data(&spot_market.get_oracle_id())?; + let oracle_price_data = oracle_map.get_price_data(&spot_market.oracle_id())?; let twap = spot_market .historical_oracle_data .last_oracle_price_twap_5min; diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index 70ab53c29..560a639d3 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -107,7 +107,9 @@ impl HistoricalIndexData { } } -#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Eq, PartialEq, Debug, Default, Ord, PartialOrd)] +#[derive( + AnchorSerialize, AnchorDeserialize, Clone, Copy, Eq, PartialEq, Debug, Default, Ord, PartialOrd, +)] pub enum OracleSource { #[default] Pyth, diff --git a/programs/drift/src/state/oracle_map.rs b/programs/drift/src/state/oracle_map.rs index 1eb758c46..2c5e45d1a 100644 --- a/programs/drift/src/state/oracle_map.rs +++ b/programs/drift/src/state/oracle_map.rs @@ -1,7 +1,7 @@ use crate::error::ErrorCode::UnableToLoadOracle; use crate::error::{DriftResult, ErrorCode}; use crate::ids::{ - drift_oracle_receiver_program, switchboard_on_demand, switchboard_program, pyth_program + drift_oracle_receiver_program, pyth_program, switchboard_on_demand, switchboard_program, }; use crate::math::constants::PRICE_PRECISION_I64; use crate::math::oracle::{oracle_validity, OracleValidity}; @@ -143,7 +143,7 @@ impl<'a> OracleMap<'a> { let validity_guard_rails = &self.oracle_guard_rails.validity; return Ok((&self.quote_asset_price_data, validity_guard_rails)); } - + if self.price_data.contains_key(oracle_id) { let oracle_price_data = self.price_data.get(oracle_id).safe_unwrap()?; let validity_guard_rails = &self.oracle_guard_rails.validity; @@ -226,7 +226,6 @@ impl<'a> OracleMap<'a> { oracles.insert(pubkey, account_info.clone()); - continue; } diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 2e083f509..988fc8044 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -300,7 +300,7 @@ impl MarketIndexOffset for PerpMarket { } impl PerpMarket { - pub fn get_oracle_id(&self) -> OracleIdentifier { + pub fn oracle_id(&self) -> OracleIdentifier { (self.amm.oracle, self.amm.oracle_source) } diff --git a/programs/drift/src/state/spot_market.rs b/programs/drift/src/state/spot_market.rs index 1e45dfeaf..206e47363 100644 --- a/programs/drift/src/state/spot_market.rs +++ b/programs/drift/src/state/spot_market.rs @@ -285,7 +285,7 @@ impl MarketIndexOffset for SpotMarket { } impl SpotMarket { - pub fn get_oracle_id(&self) -> OracleIdentifier { + pub fn oracle_id(&self) -> OracleIdentifier { (self.oracle, self.oracle_source) }