Skip to content

Commit 55658af

Browse files
feat: implement check_uniqueness validation in parse_price_feed_updates_internal
- Add uniqueness checking logic when check_uniqueness parameter is true - Require minAllowedPublishTime > prevPublishTime for uniqueness validation - Return PythReceiverError::PriceFeedNotFoundWithinRange when uniqueness check fails - Retrieve previous publish time from latest_price_info storage Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
1 parent 3e39a40 commit 55658af

File tree

1 file changed

+10
-0
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ impl PythReceiver {
389389
return Err(PythReceiverError::PriceFeedNotFoundWithinRange);
390390
}
391391

392+
if check_uniqueness {
393+
let price_id_fb = FixedBytes::<32>::from(price_feed_message.feed_id);
394+
let prev_price_info = self.latest_price_info.get(price_id_fb);
395+
let prev_publish_time = prev_price_info.publish_time.get().to::<u64>();
396+
397+
if prev_publish_time > 0 && min_allowed_publish_time <= prev_publish_time {
398+
return Err(PythReceiverError::PriceFeedNotFoundWithinRange);
399+
}
400+
}
401+
392402
let price_info_return = (
393403
U64::from(publish_time),
394404
I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),

0 commit comments

Comments
 (0)