optke3 2 жил өмнө
parent
commit
e6eceb6ef8

+ 12 - 1
target_chains/sui/scripts/pyth/update_price_feeds.ts

@@ -49,7 +49,8 @@ async function main() {
   // For a full list of testnet price feed ids, see:
   // https://pyth.network/developers/price-feed-ids#pyth-evm-testnet
   const price_feed_ids = [
-    "0x63f341689d98a12ef60a5cff1d7f85c70a9e17bf1575f0e7c0b2512d48b1c8b3",
+    //"0xec2bf6a3087d222ce960afcf75b42b96985d580a80fcd4c45c76a5d5e5713cc7" //testnet
+    "0x2b9ab1e972a281585084148ba1389800799bd4be63b957507db1349314e47445", // mainnet
     // INSERT YOUR PRICE FEED ID HERE!
   ];
 
@@ -109,6 +110,16 @@ async function update_price_feeds(
     verified_vaas = verified_vaas.concat(verified_vaa);
   }
 
+  // // For testing only (take the VAA payload then drop it without using it)
+  // for (let verified_vaa of verified_vaas){
+  //   tx.moveCall({
+  //     target: `${WORM_PACKAGE}::vaa::take_payload`,
+  //     arguments: [
+  //       verified_vaa
+  //     ],
+  //   });
+  // }
+
   // Create a hot potato vector of price feed updates that will
   // be used to update price feeds.
   let [price_updates_hot_potato] = tx.moveCall({

+ 2 - 2
target_chains/sui/scripts/utils/transfer_tokens.ts

@@ -32,7 +32,7 @@ async function main() {
   );
   let sender = await wallet.getAddress();
   let recipient =
-    "0x4ed01b6abcc271a5c7a1e05ee9344d6eb72d0c1f2483a1c600b46d73a22ba764";
+    "0x893a6889c5252ce9945148675ab414a90f820ca91d927f14fb7cd781bc09512a";
   console.log("Sender: ", sender);
   transfer_tokens(wallet, recipient);
 }
@@ -42,7 +42,7 @@ main();
 async function transfer_tokens(signer: RawSigner, recipient: string) {
   const tx = new TransactionBlock();
 
-  let coin = tx.splitCoins(tx.gas, [tx.pure(100000000000)]);
+  let coin = tx.splitCoins(tx.gas, [tx.pure(971000000)]);
 
   tx.transferObjects([coin], tx.pure(recipient));
 

+ 109 - 0
target_chains/sui/scripts/wormhole/deploy_coins.ts

@@ -0,0 +1,109 @@
+/// Deploy Pyth to Sui testnet (devnet deploy can be done via CLI)
+import {
+    fromB64,
+    getPublishedObjectChanges,
+    normalizeSuiObjectId,
+    RawSigner,
+    TransactionBlock,
+    SUI_CLOCK_OBJECT_ID,
+    JsonRpcProvider,
+    Ed25519Keypair,
+    testnetConnection,
+    Connection,
+  } from "@mysten/sui.js";
+  import { execSync } from "child_process";
+  import fs from "fs";
+  import { resolve } from "path";
+  import dotenv from "dotenv";
+  import { REGISTRY, NETWORK } from "../registry";
+  dotenv.config({ path: "~/.env" });
+
+  // Network dependent settings.
+  let network = NETWORK.TESTNET; // <= NOTE: Update this when changing network
+  const walletPrivateKey = process.env.SUI_TESTNET; // <= NOTE: Update this when changing network
+
+  // Load registry and provider.
+  const registry = REGISTRY[network];
+  const provider = new JsonRpcProvider(
+    new Connection({ fullnode: registry["RPC_URL"] })
+  );
+
+  async function main() {
+    if (walletPrivateKey === undefined) {
+      throw new Error("SUI_TESTNET unset in environment");
+    }
+    const wallet = new RawSigner(
+      Ed25519Keypair.fromSecretKey(Buffer.from(walletPrivateKey, "hex")),
+      provider
+    );
+    await publishPackage(wallet, "~/developer/wormhole/sui/examples/coins");
+  }
+
+  main();
+
+  async function publishPackage(
+    signer: RawSigner,
+    //network: Network,
+    packagePath: string
+  ) {
+    try {
+      // Build contracts
+      const buildOutput: {
+        modules: string[];
+        dependencies: string[];
+      } = JSON.parse(
+        execSync(
+          `sui move build --dump-bytecode-as-base64 --path ${packagePath} 2> /dev/null`,
+          {
+            encoding: "utf-8",
+          }
+        )
+      );
+  
+      console.log("buildOutput: ", buildOutput);
+  
+      // Publish contracts
+      const transactionBlock = new TransactionBlock();
+  
+      // important
+      transactionBlock.setGasBudget(5000000000);
+  
+      const [upgradeCap] = transactionBlock.publish({
+        modules: buildOutput.modules.map((m: string) => Array.from(fromB64(m))),
+        dependencies: buildOutput.dependencies.map((d: string) =>
+          normalizeSuiObjectId(d)
+        ),
+      });
+  
+      // Transfer upgrade capability to deployer
+      transactionBlock.transferObjects(
+        [upgradeCap],
+        transactionBlock.pure(await signer.getAddress())
+      );
+  
+      // Execute transactions
+      const res = await signer.signAndExecuteTransactionBlock({
+        transactionBlock,
+        options: {
+          showInput: true,
+          showObjectChanges: true,
+        },
+      });
+  
+      // Update network-specific Move.toml with package ID
+      const publishEvents = getPublishedObjectChanges(res);
+      if (publishEvents.length !== 1) {
+        throw new Error(
+          "No publish event found in transaction:" +
+            JSON.stringify(res.objectChanges, null, 2)
+        );
+      }
+  
+      // Return publish transaction info
+      return res;
+    } catch (e) {
+      throw e;
+    } finally {
+    }
+  }
+