Skip to content

Commit

Permalink
rename get_oracle_id to oracle_id
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 26, 2024
1 parent 2a28efb commit 3f148a8
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 80 deletions.
4 changes: 2 additions & 2 deletions programs/drift/src/controller/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
40 changes: 24 additions & 16 deletions programs/drift/src/controller/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(&quote_spot_market.get_oracle_id())?.price;
let quote_oracle_price = oracle_map
.get_price_data(&quote_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)?,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(&quote_spot_market.get_oracle_id())?.price;
let quote_oracle_price = oracle_map
.get_price_data(&quote_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)?,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(&quote_spot_market.get_oracle_id())?.price;
let quote_price = oracle_map
.get_price_data(&quote_spot_market.oracle_id())?
.price;

let pnl_asset_weight =
market.get_unrealized_asset_weight(pnl, MarginRequirementType::Maintenance)?;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(&quote_spot_market.get_oracle_id())?.price;
let quote_price = oracle_map
.get_price_data(&quote_spot_market.oracle_id())?
.price;

(
unsettled_pnl.unsigned_abs(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(&QUOTE_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(
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion programs/drift/src/controller/lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
54 changes: 29 additions & 25 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()?,
)?;
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(&quote_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
Expand Down Expand Up @@ -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) = {
Expand Down Expand Up @@ -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,
Expand All @@ -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(&quote_market.get_oracle_id())?;
let oracle_price_data = oracle_map.get_price_data(&quote_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, &quote_market)?;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(&quote_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(&quote_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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()?,
)?;
Expand Down
Loading

0 comments on commit 3f148a8

Please sign in to comment.