Skip to content

Commit 9832193

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andcommitted
fix: use previous values for price and conf when status is not Trading
Co-Authored-By: Jayant Krishnamurthy <[email protected]>
1 parent 1360d25 commit 9832193

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

target_chains/cosmwasm/contracts/pyth/src/contract.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use {
3434
pythnet_sdk::{
3535
accumulators::merkle::MerkleRoot,
3636
hashers::keccak256_160::Keccak160,
37-
messages::{Message, PriceFeedMessage},
37+
messages::{Message, PriceFeedMessage, PriceStatus},
3838
wire::{
3939
from_slice,
4040
v1::{
@@ -533,17 +533,34 @@ fn parse_batch_attestation(deps: &Deps, env: &Env, data: &Binary) -> StdResult<V
533533
}
534534

535535
fn create_price_feed_from_price_attestation(price_feed_message: &PriceFeedMessage) -> PriceFeed {
536+
let (publish_time, price, conf, ema_price, ema_conf) = match price_feed_message.status {
537+
PriceStatus::Trading => (
538+
price_feed_message.publish_time,
539+
price_feed_message.price,
540+
price_feed_message.conf,
541+
price_feed_message.ema_price,
542+
price_feed_message.ema_conf,
543+
),
544+
_ => (
545+
price_feed_message.prev_publish_time,
546+
price_feed_message.prev_publish_time,
547+
price_feed_message.conf,
548+
price_feed_message.prev_publish_time,
549+
price_feed_message.conf,
550+
),
551+
};
552+
536553
let current_price = Price {
537-
price: price_feed_message.price,
538-
conf: price_feed_message.conf,
554+
price,
555+
conf,
539556
expo: price_feed_message.exponent,
540-
publish_time: price_feed_message.publish_time,
557+
publish_time,
541558
};
542559
let ema_price = Price {
543-
price: price_feed_message.ema_price,
544-
conf: price_feed_message.ema_conf,
560+
price: ema_price,
561+
conf: ema_conf,
545562
expo: price_feed_message.exponent,
546-
publish_time: price_feed_message.publish_time,
563+
publish_time,
547564
};
548565
PriceFeed::new(
549566
PriceIdentifier::new(price_feed_message.feed_id),

0 commit comments

Comments
 (0)