Переглянути джерело

[solana] Fix idl (#1279)

* Test

* Fix idl

* Cleanup

* Add the script
guibescos 1 рік тому
батько
коміт
8f62566dbb

+ 3 - 0
target_chains/solana/Anchor.toml

@@ -11,3 +11,6 @@ url = "https://api.apr.dev"
 [provider]
 cluster = "https://api.devnet.solana.com"
 wallet = "~/.config/solana/id.json"
+
+[scripts]
+export = "anchor build && ./scripts/patch_idl.sh"

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

@@ -169,7 +169,9 @@ pub mod pyth_solana_receiver {
         );
 
         let vaa_components = VaaComponents {
-            verification_level: VerificationLevel::Partial(vaa.signature_count()),
+            verification_level: VerificationLevel::Partial {
+                num_signatures: vaa.signature_count(),
+            },
             emitter_address:    vaa.body().emitter_address(),
             emitter_chain:      vaa.body().emitter_chain(),
         };

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

@@ -14,7 +14,7 @@ use {
  * If partial, at least config.minimum signatures have been verified, but in the case config.minimum_signatures changes in the future we also include the number of signatures that were checked */
 #[derive(AnchorSerialize, AnchorDeserialize, Copy, Clone, PartialEq, BorshSchema, Debug)]
 pub enum VerificationLevel {
-    Partial(u8),
+    Partial { num_signatures: u8 },
     Full,
 }
 #[account]

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

@@ -342,7 +342,7 @@ async fn test_post_price_update_from_vaa() {
     assert_eq!(price_update_account.write_authority, poster.pubkey());
     assert_eq!(
         price_update_account.verification_level,
-        VerificationLevel::Partial(13)
+        VerificationLevel::Partial { num_signatures: 13 }
     );
     assert_eq!(
         Message::PriceFeedMessage(price_update_account.price_message),
@@ -391,7 +391,7 @@ async fn test_post_price_update_from_vaa() {
     assert_eq!(price_update_account.write_authority, poster.pubkey());
     assert_eq!(
         price_update_account.verification_level,
-        VerificationLevel::Partial(13)
+        VerificationLevel::Partial { num_signatures: 13 }
     );
     assert_eq!(
         Message::PriceFeedMessage(price_update_account.price_message),
@@ -444,7 +444,7 @@ async fn test_post_price_update_from_vaa() {
     assert_eq!(price_update_account.write_authority, poster.pubkey());
     assert_eq!(
         price_update_account.verification_level,
-        VerificationLevel::Partial(13)
+        VerificationLevel::Partial { num_signatures: 13 },
     );
     assert_eq!(
         Message::PriceFeedMessage(price_update_account.price_message),

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

@@ -94,7 +94,7 @@ async fn test_post_update_atomic() {
     assert_eq!(price_update_account.write_authority, poster.pubkey());
     assert_eq!(
         price_update_account.verification_level,
-        VerificationLevel::Partial(5)
+        VerificationLevel::Partial { num_signatures: 5 }
     );
     assert_eq!(
         Message::PriceFeedMessage(price_update_account.price_message),
@@ -130,7 +130,7 @@ async fn test_post_update_atomic() {
     assert_eq!(price_update_account.write_authority, poster.pubkey());
     assert_eq!(
         price_update_account.verification_level,
-        VerificationLevel::Partial(5)
+        VerificationLevel::Partial { num_signatures: 5 }
     );
     assert_eq!(
         Message::PriceFeedMessage(price_update_account.price_message),
@@ -165,7 +165,7 @@ async fn test_post_update_atomic() {
     assert_eq!(price_update_account.write_authority, poster.pubkey());
     assert_eq!(
         price_update_account.verification_level,
-        VerificationLevel::Partial(5)
+        VerificationLevel::Partial { num_signatures: 5 }
     );
     assert_eq!(
         Message::PriceFeedMessage(price_update_account.price_message),

+ 4 - 0
target_chains/solana/scripts/patch_idl.sh

@@ -0,0 +1,4 @@
+#! /bin/bash
+cat target/idl/pyth_solana_receiver.json |
+# ADD EXTERNAL TYPES
+jq --slurpfile external_types target/idl/external_types.json '.types += $external_types[]' > target/idl/tmp.json && mv target/idl/tmp.json target/idl/pyth_solana_receiver.json

+ 64 - 0
target_chains/solana/target/idl/external_types.json

@@ -0,0 +1,64 @@
+[
+  {
+    "name": "PriceFeedMessage",
+    "type": {
+      "kind": "struct",
+      "fields": [
+        {
+          "name": "feedId",
+          "type": {
+            "array": ["u8", 32]
+          }
+        },
+        {
+          "name": "price",
+          "type": "i64"
+        },
+        {
+          "name": "conf",
+          "type": "u64"
+        },
+        {
+          "name": "exponent",
+          "type": "i32"
+        },
+        {
+          "name": "publishTime",
+          "type": "i64"
+        },
+        {
+          "name": "prevPublishTime",
+          "type": "i64"
+        },
+        {
+          "name": "emaPrice",
+          "type": "i64"
+        },
+        {
+          "name": "emaConf",
+          "type": "u64"
+        }
+      ]
+    }
+  },
+  {
+    "name": "MerklePriceUpdate",
+    "type": {
+      "kind": "struct",
+      "fields": [
+        {
+          "name": "message",
+          "type": "bytes"
+        },
+        {
+          "name": "merkleProof",
+          "type": {
+            "vec": {
+              "array": ["u8", 20]
+            }
+          }
+        }
+      ]
+    }
+  }
+]