diff --git a/src/agent/market_schedule.rs b/src/agent/market_schedule.rs index ba44ed0..02484a1 100644 --- a/src/agent/market_schedule.rs +++ b/src/agent/market_schedule.rs @@ -47,7 +47,7 @@ const MAX_TIME_INSTANT: NaiveTime = NaiveTime::MIN .overflowing_sub_signed(Duration::nanoseconds(1)) .0; -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq, Clone)] pub struct MarketSchedule { pub timezone: Tz, pub weekly_schedule: Vec, @@ -193,8 +193,9 @@ impl Display for HolidayDaySchedule { } } -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Default, Clone, Debug, Eq, PartialEq)] pub enum ScheduleDayKind { + #[default] Open, Closed, TimeRanges(Vec>), @@ -210,12 +211,6 @@ impl ScheduleDayKind { } } -impl Default for ScheduleDayKind { - fn default() -> Self { - Self::Open - } -} - impl Display for ScheduleDayKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { diff --git a/src/agent/pyth.rs b/src/agent/pyth.rs index 0ab98a5..ec0f9d8 100644 --- a/src/agent/pyth.rs +++ b/src/agent/pyth.rs @@ -4,6 +4,7 @@ use { Serialize, }, std::collections::BTreeMap, + std::sync::Arc, }; pub mod rpc; @@ -16,28 +17,28 @@ pub type Exponent = i64; pub type Conf = u64; pub type Slot = u64; -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct ProductAccountMetadata { pub account: Pubkey, pub attr_dict: Attrs, - pub price: Vec, + pub price: Arc<[PriceAccountMetadata]>, } -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct PriceAccountMetadata { pub account: Pubkey, pub price_type: String, pub price_exponent: Exponent, } -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct ProductAccount { pub account: Pubkey, pub attr_dict: Attrs, - pub price_accounts: Vec, + pub price_accounts: Arc<[PriceAccount]>, } -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct PriceAccount { pub account: Pubkey, pub price_type: String, @@ -52,10 +53,10 @@ pub struct PriceAccount { pub prev_slot: Slot, pub prev_price: Price, pub prev_conf: Conf, - pub publisher_accounts: Vec, + pub publisher_accounts: Arc<[PublisherAccount]>, } -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct PublisherAccount { pub account: Pubkey, pub status: String, @@ -64,20 +65,20 @@ pub struct PublisherAccount { pub slot: Slot, } -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct NotifyPrice { pub subscription: SubscriptionID, pub result: PriceUpdate, } -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct NotifyPriceSched { pub subscription: SubscriptionID, } pub type SubscriptionID = i64; -#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)] pub struct PriceUpdate { pub price: Price, pub conf: Conf, diff --git a/src/agent/state.rs b/src/agent/state.rs index c04f4b7..b512aff 100644 --- a/src/agent/state.rs +++ b/src/agent/state.rs @@ -247,7 +247,7 @@ mod tests { ] .map(|(k, v)| (k.to_string(), v.to_string())), ), - price_accounts: vec![ + price_accounts: [ solana_sdk::pubkey::Pubkey::from_str( "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU", ) @@ -260,7 +260,7 @@ mod tests { "2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6", ) .unwrap(), - ], + ].into(), }, ), ( @@ -280,7 +280,7 @@ mod tests { ] .map(|(k, v)| (k.to_string(), v.to_string())), ), - price_accounts: vec![ + price_accounts: [ solana_sdk::pubkey::Pubkey::from_str( "GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD", ) @@ -293,7 +293,7 @@ mod tests { "GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ", ) .unwrap(), - ], + ].into(), }, ), ]), @@ -372,7 +372,7 @@ mod tests { ] .map(|(k, v)| (k.to_string(), v.to_string())), ), - price: vec![ + price: [ PriceAccountMetadata { account: "GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD".to_string(), price_type: "price".to_string(), @@ -388,7 +388,7 @@ mod tests { price_type: "price".to_string(), price_exponent: 2, }, - ], + ].into(), }, ProductAccountMetadata { account: "CkMrDWtmFJZcmAUC11qNaWymbXQKvnRx4cq1QudLav7t".to_string(), @@ -403,7 +403,7 @@ mod tests { ] .map(|(k, v)| (k.to_string(), v.to_string())), ), - price: vec![ + price: [ PriceAccountMetadata { account: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".to_string(), price_type: "price".to_string(), @@ -419,7 +419,7 @@ mod tests { price_type: "price".to_string(), price_exponent: -6, }, - ], + ].into(), }, ]; @@ -482,7 +482,7 @@ mod tests { }, schedule: Default::default(), publish_interval: None, - price_accounts: vec![ + price_accounts: [ solana_sdk::pubkey::Pubkey::from_str( "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU", ) @@ -495,7 +495,7 @@ mod tests { "2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6", ) .unwrap(), - ], + ].into(), } .into(), ), @@ -544,7 +544,7 @@ mod tests { }, schedule: Default::default(), publish_interval: None, - price_accounts: vec![ + price_accounts: [ solana_sdk::pubkey::Pubkey::from_str( "GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD", ) @@ -557,7 +557,7 @@ mod tests { "GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ", ) .unwrap(), - ], + ].into(), } .into(), ), @@ -1075,7 +1075,7 @@ mod tests { ] .map(|(k, v)| (k.to_string(), v.to_string())), ), - price_accounts: vec![ + price_accounts: [ pyth::PriceAccount { account: "GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD" .to_string(), @@ -1091,7 +1091,7 @@ mod tests { prev_slot: 791279274, prev_price: 98272648, prev_conf: 124986284, - publisher_accounts: vec![ + publisher_accounts: [ PublisherAccount { account: "F42dQ3SMssashRsA4SRfwJxFkGKV1bE3TcmpkagX8vvX".to_string(), status: "trading".to_string(), @@ -1106,7 +1106,7 @@ mod tests { conf: 55896, slot: 32976, }, - ], + ].into(), }, pyth::PriceAccount { account: "fTNjSfj5uW9e4CAMHzUcm65ftRNBxCN1gG5GS1mYfid" @@ -1123,7 +1123,7 @@ mod tests { prev_slot: 893734828, prev_price: 13947294, prev_conf: 349274938, - publisher_accounts: vec![ + publisher_accounts: [ PublisherAccount { account: "8MMroLyuyxyeDRrzMNfpymC5RvmHtQiYooXX9bgeUJdM".to_string(), status: "unknown".to_string(), @@ -1138,7 +1138,7 @@ mod tests { conf: 8962196, slot: 301541, }, - ], + ].into(), }, pyth::PriceAccount { account: "GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ" @@ -1155,15 +1155,15 @@ mod tests { prev_slot: 8878456286, prev_price: 24746384, prev_conf: 6373957, - publisher_accounts: vec![PublisherAccount { + publisher_accounts: [PublisherAccount { account: "33B2brfdz16kizEXeQvYzJXHiS1X95L8pfetuyntEiXg".to_string(), status: "trading".to_string(), price: 61478, conf: 312545, slot: 302156, - }], + }].into(), }, - ], + ].into(), }, pyth::ProductAccount { account: "CkMrDWtmFJZcmAUC11qNaWymbXQKvnRx4cq1QudLav7t".to_string(), @@ -1178,7 +1178,7 @@ mod tests { ] .map(|(k, v)| (k.to_string(), v.to_string())), ), - price_accounts: vec![ + price_accounts: [ pyth::PriceAccount { account: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU" .to_string(), @@ -1194,7 +1194,7 @@ mod tests { prev_slot: 172761778, prev_price: 22691000, prev_conf: 398674, - publisher_accounts: vec![], + publisher_accounts: [].into(), }, pyth::PriceAccount { account: "3VQwtcntVQN1mj1MybQw8qK7Li3KNrrgNskSQwZAPGNr" @@ -1211,13 +1211,13 @@ mod tests { prev_slot: 1727612348, prev_price: 746383678, prev_conf: 757368, - publisher_accounts: vec![PublisherAccount { + publisher_accounts: [PublisherAccount { account: "C9syZ2MoGUwbPyGEgiy8MxesaEEKLdJw8gnwx2jLK1cV".to_string(), status: "trading".to_string(), price: 85698, conf: 23645, slot: 14765, - }], + }].into(), }, pyth::PriceAccount { account: "2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6" @@ -1234,7 +1234,7 @@ mod tests { prev_slot: 86484638, prev_price: 28463947, prev_conf: 83628234, - publisher_accounts: vec![ + publisher_accounts: [ PublisherAccount { account: "DaMuPaW5dhGfRJaX7TzLWXd8hDCMJ5WA2XibJ12hjBNQ".to_string(), status: "trading".to_string(), @@ -1249,9 +1249,9 @@ mod tests { conf: 7456, slot: 865, }, - ], + ].into(), }, - ], + ].into(), }, ]; @@ -1280,7 +1280,7 @@ mod tests { // Check that the result of the conversion to the Pythd API format is what we expected let expected = ProductAccount { account: account.to_string(), - price_accounts: vec![ + price_accounts: [ pyth::PriceAccount { account: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".to_string(), price_type: "price".to_string(), @@ -1295,7 +1295,7 @@ mod tests { prev_slot: 172761778, prev_price: 22691000, prev_conf: 398674, - publisher_accounts: vec![], + publisher_accounts: [].into(), }, pyth::PriceAccount { account: "3VQwtcntVQN1mj1MybQw8qK7Li3KNrrgNskSQwZAPGNr".to_string(), @@ -1311,13 +1311,13 @@ mod tests { prev_slot: 1727612348, prev_price: 746383678, prev_conf: 757368, - publisher_accounts: vec![PublisherAccount { + publisher_accounts: [PublisherAccount { account: "C9syZ2MoGUwbPyGEgiy8MxesaEEKLdJw8gnwx2jLK1cV".to_string(), status: "trading".to_string(), price: 85698, conf: 23645, slot: 14765, - }], + }].into(), }, pyth::PriceAccount { account: "2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6".to_string(), @@ -1333,7 +1333,7 @@ mod tests { prev_slot: 86484638, prev_price: 28463947, prev_conf: 83628234, - publisher_accounts: vec![ + publisher_accounts: [ PublisherAccount { account: "DaMuPaW5dhGfRJaX7TzLWXd8hDCMJ5WA2XibJ12hjBNQ".to_string(), status: "trading".to_string(), @@ -1348,9 +1348,9 @@ mod tests { conf: 7456, slot: 865, }, - ], + ].into(), }, - ], + ].into(), attr_dict: BTreeMap::from( [ ("symbol", "Crypto.LTC/USD"), diff --git a/src/agent/state/exporter.rs b/src/agent/state/exporter.rs index 151a6f2..269b6ac 100644 --- a/src/agent/state/exporter.rs +++ b/src/agent/state/exporter.rs @@ -215,7 +215,7 @@ where } }) .filter_map(|(feed_id, info)| { - let key_from_id = Pubkey::from(feed_id.clone().to_bytes()); + let key_from_id = Pubkey::from(feed_id.to_bytes()); if let Some(publisher_permission) = our_prices.get(&key_from_id) { let now_utc = Utc::now(); let can_publish = publisher_permission.schedule.can_publish_at(&now_utc); @@ -257,7 +257,7 @@ where } }; - let key_from_id = Pubkey::from((update.feed_id).clone().to_bytes()); + let key_from_id = Pubkey::from(update.feed_id.to_bytes()); let publisher_metadata = match our_prices.get(&key_from_id) { Some(metadata) => metadata, None => { @@ -515,7 +515,7 @@ where )); for update in batch { - batch_state.insert(update.feed_id, update.info.clone()); + batch_state.insert(update.feed_id, update.info); } } @@ -579,11 +579,10 @@ where let local_store_contents = LocalStore::get_all_price_infos(&*state).await; for update in batch { let mut update = update.clone(); - update.info = local_store_contents + update.info = *local_store_contents .get(&update.feed_id) .ok_or_else(|| anyhow!("price identifier not found in local store")) - .with_context(|| update.feed_id.to_string())? - .clone(); + .with_context(|| update.feed_id.to_string())?; let stale_price = now > update.info.timestamp + staleness_threshold; if stale_price { diff --git a/src/agent/state/local.rs b/src/agent/state/local.rs index a8d9a14..f1758fc 100644 --- a/src/agent/state/local.rs +++ b/src/agent/state/local.rs @@ -16,7 +16,7 @@ use { tokio::sync::RwLock, }; -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub struct PriceInfo { pub status: PriceStatus, pub price: i64, diff --git a/src/agent/state/oracle.rs b/src/agent/state/oracle.rs index c34e9d5..bf94fdd 100644 --- a/src/agent/state/oracle.rs +++ b/src/agent/state/oracle.rs @@ -51,7 +51,7 @@ use { tracing::instrument, }; -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct ProductEntry { pub account_data: pyth_sdk_solana::state::ProductAccount, pub schedule: MarketSchedule, @@ -130,7 +130,7 @@ impl std::ops::Deref for PriceEntry { } } -#[derive(Default, Debug, Clone)] +#[derive(Default, Debug)] pub struct Data { pub product_accounts: HashMap>, pub price_accounts: HashMap>, @@ -485,7 +485,7 @@ async fn fetch_product_and_price_accounts( ProductEntry { account_data: *product, schedule: market_schedule.unwrap_or_else(|| legacy_schedule.into()), - price_accounts: vec![], + price_accounts: [].into(), publish_interval, }, );