diff --git a/programs/drift/src/controller/liquidation/tests.rs b/programs/drift/src/controller/liquidation/tests.rs index 116f47118..5d522ba26 100644 --- a/programs/drift/src/controller/liquidation/tests.rs +++ b/programs/drift/src/controller/liquidation/tests.rs @@ -775,7 +775,7 @@ pub mod liquidate_perp { margin_requirement_plus_buffer ); - let oracle_price = oracle_map.get_price_data(&oracle_price_key).unwrap().price; + let oracle_price = oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap().price; let perp_value = calculate_base_asset_value_with_oracle_price( user.perp_positions[0].base_asset_amount as i128, @@ -2357,7 +2357,7 @@ pub mod liquidate_perp { margin_requirement_plus_buffer ); - let oracle_price = oracle_map.get_price_data(&oracle_price_key).unwrap().price; + let oracle_price = oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap().price; let perp_value = calculate_base_asset_value_with_oracle_price( user.perp_positions[0].base_asset_amount as i128, @@ -3674,7 +3674,7 @@ pub mod liquidate_spot { &user.spot_positions[1].balance_type, ) .unwrap(); - let oracle_price_data = oracle_map.get_price_data(&sol_oracle_price_key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(sol_oracle_price_key, OracleSource::Pyth)).unwrap(); let token_value = get_token_value(token_amount as i128, 6, oracle_price_data.price).unwrap(); @@ -4884,7 +4884,7 @@ pub mod liquidate_borrow_for_perp_pnl { &user.spot_positions[0].balance_type, ) .unwrap(); - let oracle_price_data = oracle_map.get_price_data(&sol_oracle_price_key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(sol_oracle_price_key, OracleSource::Pyth)).unwrap(); let token_value = get_token_value(token_amount as i128, 6, oracle_price_data.price).unwrap(); diff --git a/programs/drift/src/controller/orders/tests.rs b/programs/drift/src/controller/orders/tests.rs index e6899479e..d3be6dd37 100644 --- a/programs/drift/src/controller/orders/tests.rs +++ b/programs/drift/src/controller/orders/tests.rs @@ -47,7 +47,7 @@ pub mod fulfill_order_with_maker_order { }; use super::*; - use crate::state::oracle::HistoricalOracleData; + use crate::state::oracle::{HistoricalOracleData, OracleSource}; use std::str::FromStr; #[test] @@ -1758,7 +1758,7 @@ pub mod fulfill_order_with_maker_order { .get_price_data_and_validity( MarketType::Perp, market.market_index, - &oracle_price_key, + &(oracle_price_key, OracleSource::Pyth), market.amm.historical_oracle_data.last_oracle_price_twap, market.get_max_confidence_interval_multiplier().unwrap(), ) @@ -1909,7 +1909,7 @@ pub mod fulfill_order_with_maker_order { let taker_price = taker.orders[0] .get_limit_price( - Some(oracle_map.get_price_data(&oracle_price_key).unwrap().price), + Some(oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap().price), None, slot, 1, @@ -2059,7 +2059,7 @@ pub mod fulfill_order_with_maker_order { let mut taker_stats = UserStats::default(); let mut maker_stats = UserStats::default(); - let valid_oracle_price = Some(oracle_map.get_price_data(&oracle_price_key).unwrap().price); + let valid_oracle_price = Some(oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap().price); let taker_limit_price = taker.orders[0] .get_limit_price( valid_oracle_price, @@ -2196,7 +2196,7 @@ pub mod fulfill_order_with_maker_order { let taker_price = taker.orders[0] .get_limit_price( - Some(oracle_map.get_price_data(&oracle_price_key).unwrap().price), + Some(oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap().price), None, slot, 1, diff --git a/programs/drift/src/controller/pnl/delisting.rs b/programs/drift/src/controller/pnl/delisting.rs index bd472fed7..eafbd2148 100644 --- a/programs/drift/src/controller/pnl/delisting.rs +++ b/programs/drift/src/controller/pnl/delisting.rs @@ -2333,7 +2333,7 @@ pub mod delisting_test { assert_eq!(shorter.perp_positions[0].base_asset_amount, -1000000000000); assert_eq!(shorter.perp_positions[0].quote_asset_amount, 97000000000); - let oracle_price_data = oracle_map.get_price_data(&market.amm.oracle).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); let strict_quote_price = StrictOraclePrice::test(QUOTE_PRECISION_I64); let (perp_margin_requirement, weighted_pnl, _, _, _) = @@ -2413,7 +2413,7 @@ pub mod delisting_test { { let market = market_map.get_ref_mut(&0).unwrap(); - let oracle_price_data = oracle_map.get_price_data(&market.amm.oracle).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); let strict_quote_price = StrictOraclePrice::test(QUOTE_PRECISION_I64); let (perp_margin_requirement, weighted_pnl, _, _, _) = @@ -2496,7 +2496,7 @@ pub mod delisting_test { { let mut market = market_map.get_ref_mut(&0).unwrap(); - let oracle_price_data = oracle_map.get_price_data(&market.amm.oracle).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); assert_eq!(market.amm.quote_asset_amount, 97200000000); @@ -2588,7 +2588,7 @@ pub mod delisting_test { { let market = market_map.get_ref_mut(&0).unwrap(); - let oracle_price_data = oracle_map.get_price_data(&market.amm.oracle).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); assert_eq!(market.amm.quote_asset_amount, 20000010000 + 77199990000); @@ -2832,7 +2832,7 @@ pub mod delisting_test { assert_eq!(market.amm.total_social_loss, 3449991000); - let oracle_price_data = oracle_map.get_price_data(&market.amm.oracle).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); assert_eq!(oracle_price_data.price, 100 * PRICE_PRECISION_I64); let net_pnl = calculate_net_user_pnl(&market.amm, oracle_price_data.price).unwrap(); assert_eq!(net_pnl, 3449991000); diff --git a/programs/drift/src/controller/position/tests.rs b/programs/drift/src/controller/position/tests.rs index 86dd443d3..c051ea322 100644 --- a/programs/drift/src/controller/position/tests.rs +++ b/programs/drift/src/controller/position/tests.rs @@ -17,7 +17,7 @@ use crate::math::constants::{ use crate::math::lp::calculate_settle_lp_metrics; use crate::math::position::swap_direction_to_close_position; use crate::math::repeg; -use crate::state::oracle::OraclePriceData; +use crate::state::oracle::{OraclePriceData, PrelaunchOracle}; use crate::state::oracle_map::OracleMap; use crate::state::perp_market::{AMMLiquiditySplit, PerpMarket, AMM}; use crate::state::perp_market_map::PerpMarketMap; @@ -222,16 +222,19 @@ fn amm_pred_expiry_price_market_example() { // let mut oracle_map: OracleMap<'_> = // OracleMap::load_one(&jto_market_account_info, clock_slot, None).unwrap(); - let mut sol_oracle_price: pyth::pc::Price = get_hardcoded_pyth_price(1, 6); - sol_oracle_price.agg.conf = 1655389; + let mut prelaunch_oracle_price = PrelaunchOracle { + price: PRICE_PRECISION_I64, + confidence: 1655389, + ..PrelaunchOracle::default() + }; - let sol_oracle_price_key: Pubkey = + let prelaunch_oracle_price_key: Pubkey = Pubkey::from_str("3TVuLmEGBRfVgrmFRtYTheczXaaoRBwcHw1yibZHSeNA").unwrap(); - let pyth_program = crate::ids::pyth_program::id(); - create_account_info!( - sol_oracle_price, - &sol_oracle_price_key, - &pyth_program, + let drift_program = crate::id(); + create_anchor_account_info!( + prelaunch_oracle_price, + &prelaunch_oracle_price_key, + PrelaunchOracle, oracle_account_info ); let mut oracle_map = OracleMap::load_one(&oracle_account_info, clock_slot, None).unwrap(); @@ -1998,7 +2001,7 @@ fn update_amm_near_boundary() { println!("perp_market: {:?}", perp_market.amm.last_update_slot); - let oracle_price_data = oracle_map.get_price_data(&key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(key, OracleSource::Pyth)).unwrap(); let state = State::default(); @@ -2040,7 +2043,7 @@ fn update_amm_near_boundary2() { println!("perp_market: {:?}", perp_market.amm.last_update_slot); - let oracle_price_data = oracle_map.get_price_data(&key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(key, OracleSource::Pyth)).unwrap(); let state = State::default(); @@ -2082,7 +2085,7 @@ fn recenter_amm_1() { println!("perp_market: {:?}", perp_market.amm.last_update_slot); - let oracle_price_data = oracle_map.get_price_data(&key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(key, OracleSource::Pyth)).unwrap(); let state = State::default(); @@ -2180,7 +2183,7 @@ fn recenter_amm_2() { assert_eq!(perp_market.amm.quote_asset_reserve, 64381518181749930705); assert_eq!(perp_market.amm.base_asset_reserve, 307161425106214); - let oracle_price_data = oracle_map.get_price_data(&oracle_price_key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap(); let state = State::default(); @@ -2307,7 +2310,7 @@ fn test_move_amm() { assert_eq!(perp_market.amm.quote_asset_reserve, 64381518181749930705); assert_eq!(perp_market.amm.base_asset_reserve, 307161425106214); - let oracle_price_data = oracle_map.get_price_data(&oracle_price_key).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&(oracle_price_key, OracleSource::Pyth)).unwrap(); let state = State::default(); diff --git a/programs/drift/src/math/funding/tests.rs b/programs/drift/src/math/funding/tests.rs index b2668b9fc..114159d75 100644 --- a/programs/drift/src/math/funding/tests.rs +++ b/programs/drift/src/math/funding/tests.rs @@ -652,7 +652,7 @@ fn unsettled_funding_pnl() { market.amm.funding_period, ) .unwrap(); - let oracle_price_data = oracle_map.get_price_data(&market.amm.oracle).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); assert_eq!(time_until_next_update, 0); let block_funding_rate_update = block_operation(