瀏覽代碼

feat: fix anchor 0.30.0

Guillermo Bescos 1 年之前
父節點
當前提交
be8d1ec235

+ 6 - 12
target_chains/solana/programs/pyth-push-oracle/tests/test_update_price_feed.rs

@@ -106,10 +106,7 @@ async fn test_update_price_feed() {
         price_feed_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_feed_account.price_message),
-        feed_1_old
-    );
+    assert_eq!(Message::from(price_feed_account.price_message), feed_1_old);
     assert_eq!(
         price_feed_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -153,7 +150,7 @@ async fn test_update_price_feed() {
         VerificationLevel::Full
     );
     assert_eq!(
-        Message::PriceFeedMessage(price_feed_account.price_message),
+        Message::from(price_feed_account.price_message),
         feed_1_recent
     );
     assert_eq!(
@@ -199,7 +196,7 @@ async fn test_update_price_feed() {
         VerificationLevel::Full
     );
     assert_eq!(
-        Message::PriceFeedMessage(price_feed_account.price_message),
+        Message::from(price_feed_account.price_message),
         feed_1_recent
     );
     assert_eq!(
@@ -245,7 +242,7 @@ async fn test_update_price_feed() {
         VerificationLevel::Full
     );
     assert_eq!(
-        Message::PriceFeedMessage(price_feed_account.price_message),
+        Message::from(price_feed_account.price_message),
         feed_1_recent
     );
     assert_eq!(
@@ -266,10 +263,7 @@ async fn test_update_price_feed() {
         price_feed_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_feed_account.price_message),
-        feed_1_old
-    );
+    assert_eq!(Message::from(price_feed_account.price_message), feed_1_old);
     assert_eq!(
         price_feed_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -310,7 +304,7 @@ async fn test_update_price_feed() {
         VerificationLevel::Full
     );
     assert_eq!(
-        Message::PriceFeedMessage(price_feed_account.price_message),
+        Message::from(price_feed_account.price_message),
         feed_1_recent
     );
     assert_eq!(

+ 1 - 1
target_chains/solana/programs/pyth-solana-receiver/src/lib.rs

@@ -444,7 +444,7 @@ fn post_price_update_from_vaa<'info>(
         Message::PriceFeedMessage(price_feed_message) => {
             price_update_account.write_authority = write_authority.key();
             price_update_account.verification_level = vaa_components.verification_level;
-            price_update_account.price_message = price_feed_message;
+            price_update_account.price_message = price_feed_message.into();
             price_update_account.posted_slot = Clock::get()?.slot;
         }
         Message::TwapMessage(_) => {

+ 4 - 16
target_chains/solana/programs/pyth-solana-receiver/tests/test_post_price_update_from_vaa.rs

@@ -356,10 +356,7 @@ async fn test_post_price_update_from_vaa() {
         price_update_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_1
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_1);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -401,10 +398,7 @@ async fn test_post_price_update_from_vaa() {
         price_update_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_1
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_1);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -467,10 +461,7 @@ async fn test_post_price_update_from_vaa() {
         price_update_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_1
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_1);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -525,10 +516,7 @@ async fn test_post_price_update_from_vaa() {
         price_update_account.verification_level,
         VerificationLevel::Partial { num_signatures: 12 }
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_2
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_2);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot

+ 2 - 8
target_chains/solana/programs/pyth-solana-receiver/tests/test_post_updates.rs

@@ -95,10 +95,7 @@ async fn test_post_update() {
         price_update_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_1
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_1);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -138,10 +135,7 @@ async fn test_post_update() {
         price_update_account.verification_level,
         VerificationLevel::Full
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_2
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_2);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot

+ 3 - 12
target_chains/solana/programs/pyth-solana-receiver/tests/test_post_updates_atomic.rs

@@ -99,10 +99,7 @@ async fn test_post_update_atomic() {
         price_update_account.verification_level,
         VerificationLevel::Partial { num_signatures: 5 }
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_1
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_1);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -145,10 +142,7 @@ async fn test_post_update_atomic() {
         price_update_account.verification_level,
         VerificationLevel::Partial { num_signatures: 5 }
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_2
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_2);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot
@@ -195,10 +189,7 @@ async fn test_post_update_atomic() {
         price_update_account.verification_level,
         VerificationLevel::Partial { num_signatures: 5 }
     );
-    assert_eq!(
-        Message::PriceFeedMessage(price_update_account.price_message),
-        feed_1
-    );
+    assert_eq!(Message::from(price_update_account.price_message), feed_1);
     assert_eq!(
         price_update_account.posted_slot,
         program_simulator.get_clock().await.unwrap().slot

+ 47 - 5
target_chains/solana/pyth_solana_receiver_sdk/src/price_update.rs

@@ -9,11 +9,53 @@ use {
     },
     pythnet_sdk::messages::{
         FeedId,
+        Message,
         PriceFeedMessage,
     },
     solana_program::pubkey::Pubkey,
 };
 
+#[derive(AnchorSerialize, AnchorDeserialize, BorshSchema, Debug, Clone, Copy)]
+pub struct AnchorPriceFeedMessage {
+    pub feed_id:           FeedId,
+    pub price:             i64,
+    pub conf:              u64,
+    pub exponent:          i32,
+    pub publish_time:      i64,
+    pub prev_publish_time: i64,
+    pub ema_price:         i64,
+    pub ema_conf:          u64,
+}
+
+impl From<PriceFeedMessage> for AnchorPriceFeedMessage {
+    fn from(price_feed_message: PriceFeedMessage) -> Self {
+        Self {
+            feed_id:           price_feed_message.feed_id,
+            price:             price_feed_message.price,
+            conf:              price_feed_message.conf,
+            exponent:          price_feed_message.exponent,
+            publish_time:      price_feed_message.publish_time,
+            prev_publish_time: price_feed_message.prev_publish_time,
+            ema_price:         price_feed_message.ema_price,
+            ema_conf:          price_feed_message.ema_conf,
+        }
+    }
+}
+
+impl From<AnchorPriceFeedMessage> for Message {
+    fn from(value: AnchorPriceFeedMessage) -> Self {
+        Message::PriceFeedMessage(PriceFeedMessage {
+            feed_id:           value.feed_id,
+            price:             value.price,
+            conf:              value.conf,
+            exponent:          value.exponent,
+            publish_time:      value.publish_time,
+            prev_publish_time: value.prev_publish_time,
+            ema_price:         value.ema_price,
+            ema_conf:          value.ema_conf,
+        })
+    }
+}
 
 /// Pyth price updates are bridged to all blockchains via Wormhole.
 /// Using the price updates on another chain requires verifying the signatures of the Wormhole guardians.
@@ -59,7 +101,7 @@ impl VerificationLevel {
 pub struct PriceUpdateV2 {
     pub write_authority:    Pubkey,
     pub verification_level: VerificationLevel,
-    pub price_message:      PriceFeedMessage,
+    pub price_message:      AnchorPriceFeedMessage,
     pub posted_slot:        u64,
 }
 
@@ -218,13 +260,13 @@ pub mod tests {
         crate::{
             error::GetPriceError,
             price_update::{
+                AnchorPriceFeedMessage,
                 Price,
                 PriceUpdateV2,
                 VerificationLevel,
             },
         },
         anchor_lang::Discriminator,
-        pythnet_sdk::messages::PriceFeedMessage,
         solana_program::{
             borsh0_10,
             clock::Clock,
@@ -298,7 +340,7 @@ pub mod tests {
         let price_update_unverified = PriceUpdateV2 {
             write_authority:    Pubkey::new_unique(),
             verification_level: VerificationLevel::Partial { num_signatures: 0 },
-            price_message:      PriceFeedMessage {
+            price_message:      AnchorPriceFeedMessage {
                 feed_id,
                 ema_conf: 0,
                 ema_price: 0,
@@ -314,7 +356,7 @@ pub mod tests {
         let price_update_partially_verified = PriceUpdateV2 {
             write_authority:    Pubkey::new_unique(),
             verification_level: VerificationLevel::Partial { num_signatures: 5 },
-            price_message:      PriceFeedMessage {
+            price_message:      AnchorPriceFeedMessage {
                 feed_id,
                 ema_conf: 0,
                 ema_price: 0,
@@ -330,7 +372,7 @@ pub mod tests {
         let price_update_fully_verified = PriceUpdateV2 {
             write_authority:    Pubkey::new_unique(),
             verification_level: VerificationLevel::Full,
-            price_message:      PriceFeedMessage {
+            price_message:      AnchorPriceFeedMessage {
                 feed_id,
                 ema_conf: 0,
                 ema_price: 0,