diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index 4b59836bd..b5d62bb46 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -317,12 +317,15 @@ pub fn get_sb_on_demand_price( let pull_feed_account_info: Ref = load_ref(price_oracle).or(Err(ErrorCode::UnableToLoadOracle))?; - let price = convert_sb_i128( - &pull_feed_account_info - .value() - .ok_or(ErrorCode::UnableToLoadOracle)?, - )? - .cast::()?; + let latest_oracle_submssions: Vec = + pull_feed_account_info.latest_submissions(); + let average_price = latest_oracle_submssions + .iter() + .map(|submission| submission.value) + .sum::() + / latest_oracle_submssions.len() as i128; + + let price = convert_sb_i128(&average_price)?.cast::()?; let confidence = convert_sb_i128( &pull_feed_account_info @@ -332,13 +335,9 @@ pub fn get_sb_on_demand_price( .cast::()? .unsigned_abs(); - let delay = clock_slot.cast::()?.safe_sub( - pull_feed_account_info - .result - .result_slot() - .ok_or(ErrorCode::UnableToLoadOracle)? - .cast()?, - )?; + let delay = clock_slot + .cast::()? + .safe_sub(latest_oracle_submssions[0].landed_at.cast()?)?; let has_sufficient_number_of_data_points = true; diff --git a/programs/drift/src/state/oracle/tests.rs b/programs/drift/src/state/oracle/tests.rs index 79810dd5c..0fe9cf089 100644 --- a/programs/drift/src/state/oracle/tests.rs +++ b/programs/drift/src/state/oracle/tests.rs @@ -95,14 +95,14 @@ fn pyth_pull_1m() { #[test] fn switchboard_on_demand() { let oracle_price_key = - Pubkey::from_str("J9nrFWjDUeDVZ4BhhxsbQXWgLcLEgQyNBrCbwSADmJdr").unwrap(); - let oracle_market_str = String::from("xBtsxArX2yhcpt/dK9uhJ5ChHVRrHXiHZujddFlPpgPNVHTgIIoj0/BurhMAAAAAAAAAAAAAAAAAQAj/uFTJBAAAAAAAAAAAaOJJQ2555N+2mXP67/PxVDaFEhuxV8baKRzw7FrU5VPwbq4TAAAAAAAAAAAAAAAAAEAI/7hUyQQAAAAAAAAAAAXn72s0bOcHlsJ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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="); let mut decoded_bytes = base64::decode(oracle_market_str).unwrap(); let oracle_market_bytes = decoded_bytes.as_mut_slice(); let mut lamports = 0; let sb_program = crate::ids::switchboard_on_demand::id(); - let w_oracle_info = create_account_info( + let dsol_oracle_info = create_account_info( &oracle_price_key, true, &mut lamports, @@ -112,17 +112,17 @@ fn switchboard_on_demand() { let oracle_price_data = get_oracle_price( &OracleSource::SwitchboardOnDemand, - &w_oracle_info, - 330198768, + &dsol_oracle_info, + 339848045, ) .unwrap(); - assert_eq!(oracle_price_data.price, 344900); + assert_eq!(oracle_price_data.price, 226556945); let amm = AMM { oracle_source: OracleSource::SwitchboardOnDemand, ..AMM::default() }; - let twap = amm.get_oracle_twap(&w_oracle_info, 0).unwrap(); - assert_eq!(twap, Some(344900)); + let twap = amm.get_oracle_twap(&dsol_oracle_info, 0).unwrap(); + assert_eq!(twap, Some(226556945)); } diff --git a/programs/switchboard-on-demand/src/lib.rs b/programs/switchboard-on-demand/src/lib.rs index bd8a53d4c..80779e43a 100644 --- a/programs/switchboard-on-demand/src/lib.rs +++ b/programs/switchboard-on-demand/src/lib.rs @@ -36,8 +36,11 @@ pub struct CurrentResult { pub min_value: i128, /// The maximum value of the submissions needed for quorom size pub max_value: i128, + /// The number of samples used to calculate this result pub num_samples: u8, - pub padding1: [u8; 7], + /// The index of the submission that was used to calculate this result + pub submission_idx: u8, + pub padding1: [u8; 6], /// The slot at which this value was signed. pub slot: u64, /// The slot at which the first considered submission was made @@ -123,7 +126,8 @@ pub struct OracleSubmission { pub oracle: Pubkey, /// The slot at which this value was signed. pub slot: u64, - padding1: [u8; 8], + /// The slot at which this value was landed on chain. + pub landed_at: u64, /// The value that was submitted. pub value: i128, } @@ -180,7 +184,7 @@ impl PullFeedAccountData { } /// The median value of the submissions needed for quorom size - pub fn value(&self) -> Option { + pub fn median_value(&self) -> Option { self.result.value() } @@ -208,4 +212,23 @@ impl PullFeedAccountData { pub fn max_value(&self) -> Option { self.result.max_value() } + + pub fn median_result_land_slot(&self) -> u64 { + let submission: OracleSubmission = self.submissions[self.result.submission_idx as usize]; + submission.landed_at + } + + pub fn latest_submissions(&self) -> Vec { + let max_landed_at = self + .submissions + .iter() + .map(|s| s.landed_at) + .max() + .unwrap_or(0); + self.submissions + .iter() + .filter(|submission| submission.landed_at == max_landed_at) + .cloned() + .collect() + } } diff --git a/sdk/src/idl/switchboard_on_demand_30.json b/sdk/src/idl/switchboard_on_demand_30.json index 97786b835..172559046 100644 --- a/sdk/src/idl/switchboard_on_demand_30.json +++ b/sdk/src/idl/switchboard_on_demand_30.json @@ -2396,12 +2396,19 @@ ], "type": "u8" }, + { + "name": "submission_idx", + "docs": [ + "The index of the submission that was used to calculate this result" + ], + "type": "u8" + }, { "name": "padding1", "type": { "array": [ "u8", - 7 + 6 ] } }, @@ -3019,13 +3026,11 @@ "type": "u64" }, { - "name": "padding1", - "type": { - "array": [ - "u8", - 8 - ] - } + "name": "landed_at", + "docs": [ + "The slot at which this value was landed on chain." + ], + "type": "u64" }, { "name": "value",