Skip to content

Commit

Permalink
Remove unnecessary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Feb 27, 2025
1 parent 07571e9 commit d179fd2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 63 deletions.
11 changes: 3 additions & 8 deletions src/agent/market_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScheduleDayKind>,
Expand Down Expand Up @@ -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<RangeInclusive<NaiveTime>>),
Expand All @@ -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 {
Expand Down
23 changes: 12 additions & 11 deletions src/agent/pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
Serialize,
},
std::collections::BTreeMap,
std::sync::Arc,
};

pub mod rpc;
Expand All @@ -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<PriceAccountMetadata>,
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<PriceAccount>,
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,
Expand All @@ -52,10 +53,10 @@ pub struct PriceAccount {
pub prev_slot: Slot,
pub prev_price: Price,
pub prev_conf: Conf,
pub publisher_accounts: Vec<PublisherAccount>,
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,
Expand All @@ -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,
Expand Down
68 changes: 34 additions & 34 deletions src/agent/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand All @@ -260,7 +260,7 @@ mod tests {
"2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6",
)
.unwrap(),
],
].into(),
},
),
(
Expand All @@ -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",
)
Expand All @@ -293,7 +293,7 @@ mod tests {
"GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ",
)
.unwrap(),
],
].into(),
},
),
]),
Expand Down Expand Up @@ -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(),
Expand All @@ -388,7 +388,7 @@ mod tests {
price_type: "price".to_string(),
price_exponent: 2,
},
],
].into(),
},
ProductAccountMetadata {
account: "CkMrDWtmFJZcmAUC11qNaWymbXQKvnRx4cq1QudLav7t".to_string(),
Expand All @@ -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(),
Expand All @@ -419,7 +419,7 @@ mod tests {
price_type: "price".to_string(),
price_exponent: -6,
},
],
].into(),
},
];

Expand Down Expand Up @@ -482,7 +482,7 @@ mod tests {
},
schedule: Default::default(),
publish_interval: None,
price_accounts: vec![
price_accounts: [
solana_sdk::pubkey::Pubkey::from_str(
"GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU",
)
Expand All @@ -495,7 +495,7 @@ mod tests {
"2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6",
)
.unwrap(),
],
].into(),
}
.into(),
),
Expand Down Expand Up @@ -544,7 +544,7 @@ mod tests {
},
schedule: Default::default(),
publish_interval: None,
price_accounts: vec![
price_accounts: [
solana_sdk::pubkey::Pubkey::from_str(
"GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD",
)
Expand All @@ -557,7 +557,7 @@ mod tests {
"GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ",
)
.unwrap(),
],
].into(),
}
.into(),
),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -1106,7 +1106,7 @@ mod tests {
conf: 55896,
slot: 32976,
},
],
].into(),
},
pyth::PriceAccount {
account: "fTNjSfj5uW9e4CAMHzUcm65ftRNBxCN1gG5GS1mYfid"
Expand All @@ -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(),
Expand All @@ -1138,7 +1138,7 @@ mod tests {
conf: 8962196,
slot: 301541,
},
],
].into(),
},
pyth::PriceAccount {
account: "GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ"
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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(),
Expand All @@ -1249,9 +1249,9 @@ mod tests {
conf: 7456,
slot: 865,
},
],
].into(),
},
],
].into(),
},
];

Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -1348,9 +1348,9 @@ mod tests {
conf: 7456,
slot: 865,
},
],
].into(),
},
],
].into(),
attr_dict: BTreeMap::from(
[
("symbol", "Crypto.LTC/USD"),
Expand Down
Loading

0 comments on commit d179fd2

Please sign in to comment.