From 58d1f846c510e122b6ae7eb12837ebd16863de5e Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 26 Nov 2024 13:44:09 -0600 Subject: [PATCH] fix remainder of tests --- .../drift/src/controller/position/tests.rs | 44 +++++++++++-------- programs/drift/src/math/margin/tests.rs | 9 ++-- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/programs/drift/src/controller/position/tests.rs b/programs/drift/src/controller/position/tests.rs index c051ea322..aa3bfe149 100644 --- a/programs/drift/src/controller/position/tests.rs +++ b/programs/drift/src/controller/position/tests.rs @@ -110,16 +110,19 @@ fn amm_pred_expiry_price_yes_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(1000000, 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(); @@ -336,16 +339,19 @@ fn amm_pred_settle_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(); @@ -2001,7 +2007,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, OracleSource::Pyth)).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&perp_market.oracle_id()).unwrap(); let state = State::default(); @@ -2043,7 +2049,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, OracleSource::Pyth)).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&perp_market.oracle_id()).unwrap(); let state = State::default(); @@ -2085,7 +2091,7 @@ fn recenter_amm_1() { println!("perp_market: {:?}", perp_market.amm.last_update_slot); - let oracle_price_data = oracle_map.get_price_data(&(key, OracleSource::Pyth)).unwrap(); + let oracle_price_data = oracle_map.get_price_data(&perp_market.oracle_id()).unwrap(); let state = State::default(); diff --git a/programs/drift/src/math/margin/tests.rs b/programs/drift/src/math/margin/tests.rs index 22fbd2126..4321f5926 100644 --- a/programs/drift/src/math/margin/tests.rs +++ b/programs/drift/src/math/margin/tests.rs @@ -2217,7 +2217,7 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, - oracle_source: OracleSource::QuoteAsset, + oracle_source: OracleSource::PythStableCoin, cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2278,6 +2278,9 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { ) .unwrap(); + let usdc_price = oracle_map.get_price_data(&(usdc_oracle_price_key, OracleSource::QuoteAsset)).unwrap().price; + println!("usdc_price: {}", usdc_price); + assert_eq!(margin_requirement, 0); assert_eq!(total_collateral, 990000); @@ -2362,7 +2365,7 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, - oracle_source: OracleSource::QuoteAsset, + oracle_source: OracleSource::PythStableCoin, cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, decimals: 6, @@ -2508,7 +2511,7 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, - oracle_source: OracleSource::QuoteAsset, + oracle_source: OracleSource::PythStableCoin, cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION,