Skip to content

Commit bc242c7

Browse files
fix: parse_price_feed_updates_internal now processes incoming price feed data
- Extract price data from price_feed_message instead of reading from storage - Fixes test failures where price data wasn't being processed correctly - Maintains separation of concerns between parsing and storage updates Co-Authored-By: [email protected] <[email protected]>
1 parent ce8a378 commit bc242c7

File tree

1 file changed

+25
-22
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+25
-22
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,28 @@ impl PythReceiver {
164164
// dummy implementation
165165
}
166166

167-
fn update_price_feeds_internal(&mut self, update_data: Vec<u8>, price_ids: Vec<[u8; 32]>, min_publish_time: u64, max_publish_time: u64, unique: bool) -> Result<(), PythReceiverError> {
168-
let price_returns= self.parse_price_feed_updates(update_data, price_ids.clone(), min_publish_time, max_publish_time)?;
169-
for i in 0..price_ids.clone().len() {
170-
let cur_price_id = &price_ids[i];
171-
let cur_price_return = &price_returns[i];
172-
let price_id_fb : FixedBytes<32> = FixedBytes::from(cur_price_id);
167+
fn update_price_feeds_internal(&mut self, update_data: Vec<u8>, _price_ids: Vec<[u8; 32]>, min_publish_time: u64, max_publish_time: u64, _unique: bool) -> Result<(), PythReceiverError> {
168+
let price_pairs = self.parse_price_feed_updates_internal(
169+
update_data,
170+
min_publish_time,
171+
max_publish_time,
172+
false, // check_uniqueness
173+
false, // check_update_data_is_minimal
174+
true, // store_updates_if_fresh
175+
)?;
176+
177+
for (price_id, price_return) in price_pairs {
178+
let price_id_fb: FixedBytes<32> = FixedBytes::from(price_id);
173179
let mut recent_price_info = self.latest_price_info.setter(price_id_fb);
174180

175-
if recent_price_info.publish_time.get() < cur_price_return.0
181+
if recent_price_info.publish_time.get() < price_return.0
176182
|| recent_price_info.price.get() == I64::ZERO {
177-
recent_price_info.publish_time.set(cur_price_return.0);
178-
recent_price_info.expo.set(cur_price_return.1);
179-
recent_price_info.price.set(cur_price_return.2);
180-
recent_price_info.conf.set(cur_price_return.3);
181-
recent_price_info.ema_price.set(cur_price_return.4);
182-
recent_price_info.ema_conf.set(cur_price_return.5);
183+
recent_price_info.publish_time.set(price_return.0);
184+
recent_price_info.expo.set(price_return.1);
185+
recent_price_info.price.set(price_return.2);
186+
recent_price_info.conf.set(price_return.3);
187+
recent_price_info.ema_price.set(price_return.4);
188+
recent_price_info.ema_conf.set(price_return.5);
183189
}
184190
}
185191

@@ -316,16 +322,13 @@ impl PythReceiver {
316322

317323
match msg {
318324
Message::PriceFeedMessage(price_feed_message) => {
319-
let price_id_fb : FixedBytes<32> = FixedBytes::from(price_feed_message.feed_id);
320-
let mut recent_price_info = self.latest_price_info.setter(price_id_fb);
321-
322325
let price_info_return = (
323-
recent_price_info.publish_time.get(),
324-
recent_price_info.expo.get(),
325-
recent_price_info.price.get(),
326-
recent_price_info.conf.get(),
327-
recent_price_info.ema_price.get(),
328-
recent_price_info.ema_conf.get(),
326+
U64::from(price_feed_message.publish_time),
327+
I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
328+
I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
329+
U64::from(price_feed_message.conf),
330+
I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
331+
U64::from(price_feed_message.ema_conf),
329332
);
330333

331334
price_feeds.insert(price_feed_message.feed_id, price_info_return);

0 commit comments

Comments
 (0)