Skip to content

Commit

Permalink
fix remainder of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 26, 2024
1 parent 5fa4660 commit 58d1f84
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
44 changes: 25 additions & 19 deletions programs/drift/src/controller/position/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

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

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

Expand Down
9 changes: 6 additions & 3 deletions programs/drift/src/math/margin/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 58d1f84

Please sign in to comment.