Skip to content

Commit 4167e2d

Browse files
authored
Decouple (#370)
1 parent fd2f137 commit 4167e2d

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

program/rust/src/accounts/price.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl PriceFeedMessage {
246246
pub const MESSAGE_SIZE: usize = 1 + 32 + 8 + 8 + 4 + 8 + 8 + 8 + 8;
247247
pub const DISCRIMINATOR: u8 = 0;
248248

249-
pub fn from_price_account(key: &Pubkey, account: &PriceAccountV2) -> Self {
249+
pub fn from_price_account(key: &Pubkey, account: &PriceAccount) -> Self {
250250
let (price, conf, publish_time) = if account.agg_.status_ == PC_STATUS_TRADING {
251251
(account.agg_.price_, account.agg_.conf_, account.timestamp_)
252252
} else {

program/rust/src/processor/upd_price.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use {
33
crate::accounts::{
44
PriceFeedMessage,
5-
TwapMessage,
65
UPD_PRICE_WRITE_SEED,
76
},
87
solana_program::instruction::{
@@ -179,14 +178,21 @@ pub fn upd_price(
179178

180179
if aggregate_updated {
181180
price_data.update_price_cumulative()?;
182-
// We want to send a message every time the aggregate price updates. However, during the migration,
183-
// not every publisher will necessarily provide the accumulator accounts. The message_sent_ flag
184-
// ensures that after every aggregate update, the next publisher who provides the accumulator accounts
185-
// will send the message.
186-
price_data.message_sent_ = 0;
187181
}
182+
}
183+
184+
let mut price_data = load_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
188185

189-
#[cfg(feature = "pythnet")]
186+
187+
#[cfg(feature = "pythnet")]
188+
{
189+
// We want to send a message every time the aggregate price updates. However, during the migration,
190+
// not every publisher will necessarily provide the accumulator accounts. The message_sent_ flag
191+
// ensures that after every aggregate update, the next publisher who provides the accumulator accounts
192+
// will send the message.
193+
if aggregate_updated {
194+
price_data.message_sent_ = 0;
195+
}
190196
if let Some(accumulator_accounts) = maybe_accumulator_accounts {
191197
if price_data.message_sent_ == 0 {
192198
// Check that the oracle PDA is correctly configured for the program we are calling.
@@ -219,14 +225,12 @@ pub fn upd_price(
219225
},
220226
];
221227

222-
let message = vec![
223-
PriceFeedMessage::from_price_account(price_account.key, &price_data)
224-
.as_bytes()
225-
.to_vec(),
226-
TwapMessage::from_price_account(price_account.key, &price_data)
227-
.as_bytes()
228-
.to_vec(),
229-
];
228+
let message =
229+
vec![
230+
PriceFeedMessage::from_price_account(price_account.key, &price_data)
231+
.as_bytes()
232+
.to_vec(),
233+
];
230234

231235
// anchor discriminator for "global:put_all"
232236
let discriminator: [u8; 8] = [212, 225, 193, 91, 151, 238, 20, 93];
@@ -248,9 +252,6 @@ pub fn upd_price(
248252
}
249253
}
250254

251-
252-
let mut price_data = load_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
253-
254255
// Try to update the publisher's price
255256
if is_component_update(cmd_args)? {
256257
let status: u32 =

0 commit comments

Comments
 (0)