Browse Source

some contract updates to compile with WH branch sui/mainnet
deployment script updates

optke3 2 years ago
parent
commit
2bdc573b54

+ 2 - 2
target_chains/sui/contracts/Move.lock

@@ -10,11 +10,11 @@ dependencies = [
 
 [[move.package]]
 name = "MoveStdlib"
-source = { git = "https://github.com/MystenLabs/sui.git", rev = "3a70c4374090b020b95465787f3220a95d8ab0ba", subdir = "crates/sui-framework/packages/move-stdlib" }
+source = { git = "https://github.com/MystenLabs/sui.git", rev = "09b2081498366df936abae26eea4b2d5cafb2788", subdir = "crates/sui-framework/packages/move-stdlib" }
 
 [[move.package]]
 name = "Sui"
-source = { git = "https://github.com/MystenLabs/sui.git", rev = "3a70c4374090b020b95465787f3220a95d8ab0ba", subdir = "crates/sui-framework/packages/sui-framework" }
+source = { git = "https://github.com/MystenLabs/sui.git", rev = "09b2081498366df936abae26eea4b2d5cafb2788", subdir = "crates/sui-framework/packages/sui-framework" }
 
 dependencies = [
   { name = "MoveStdlib" },

+ 2 - 2
target_chains/sui/contracts/Move.toml

@@ -5,11 +5,11 @@ version = "0.0.1"
 [dependencies.Sui]
 git = "https://github.com/MystenLabs/sui.git"
 subdir = "crates/sui-framework/packages/sui-framework"
-rev = "3a70c4374090b020b95465787f3220a95d8ab0ba"
+rev = "09b2081498366df936abae26eea4b2d5cafb2788"
 
 [dependencies.Wormhole]
 local = "../../../../wormhole/sui/wormhole"
 
 [addresses]
 pyth = "0x0"
-wormhole = "0x07aa529a7ab00007b9081f47728537d47d7fe0f3d7fded2c01fa34340ac7a71c"
+wormhole = "0x80c60bff35fe5026e319cf3d66ae671f2b4e12923c92c45df75eaf4de79e3ce7"

+ 3 - 18
target_chains/sui/contracts/sources/state.move

@@ -79,20 +79,12 @@ module pyth::state {
 
         let consumed_vaas = consumed_vaas::new(ctx);
 
-
-        // Set first version for this package.
-        package_utils::init_version(
-            &mut uid,
-            version_control::current_version()
-        );
-
         // Initialize package info. This will be used for emitting information
         // of successful migrations.
         package_utils::init_package_info(
             &mut uid,
-            &upgrade_cap,
-            bytes32::default(),
-            bytes32::default()
+            version_control::current_version(),
+            &upgrade_cap
         );
 
         State {
@@ -340,20 +332,13 @@ module pyth::state {
         // fields do not exist in the previous build (0.1.0).
         // See `state::new` above.
 
-        // Need to remove old dynamic field. This was set when performing the
-        // upgrade on previous version. We need to take this digest and then
-        // initialize package info with this as the pending digest.
-        let pending_digest =
-            sui::dynamic_field::remove(&mut self.id, CurrentDigest {});
-
         // Initialize package info. This will be used for emitting information
         // of successful migrations.
         let upgrade_cap = &self.upgrade_cap;
         package_utils::init_package_info(
             &mut self.id,
+            version_control::current_version(),
             upgrade_cap,
-            bytes32::default(),
-            pending_digest
         );
     }
 

+ 8 - 8
target_chains/sui/scripts/deploy.ts

@@ -90,14 +90,14 @@ main()
         },
       });
 
-    //   // 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)
-    //     );
-    //   }
+      // 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;

+ 108 - 0
target_chains/sui/scripts/deploy_wormhole.ts

@@ -0,0 +1,108 @@
+/// 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"})
+
+let network = NETWORK.TESTNET
+const registry = REGISTRY[network]
+const provider = new JsonRpcProvider(new Connection({ fullnode: registry["RPC_URL"] }))
+const walletPrivateKey = process.env.SUI_TESTNET;
+
+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/wormhole");
+}
+
+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 {
+    }
+  };

+ 5 - 5
target_chains/sui/scripts/init_pyth.ts

@@ -15,15 +15,15 @@ import {
 import {REGISTRY, NETWORK, INITIAL_DATA_SOURCES} from "./registry"
 dotenv.config({"path":"~/.env"})
 
-let network = NETWORK.DEVNET
+let network = NETWORK.TESTNET // <= Update this when changing network
 const registry = REGISTRY[network]
 const initial_data_sources = INITIAL_DATA_SOURCES[network]
 const provider = new JsonRpcProvider(new Connection({ fullnode: registry["RPC_URL"]}))
-let walletPrivateKey = process.env.SUI_DEVNET; // <= Update this with the right private key
+let walletPrivateKey = process.env.SUI_TESTNET_BASE_64; // <= Update this when changing network
 
 async function main() {
     if (walletPrivateKey === undefined) {
-      throw new Error("SUI_DEVNET unset in environment");
+      throw new Error("SUI_TESTNET unset in environment");
     }
 
     const wallet = new RawSigner(
@@ -36,8 +36,8 @@ async function main() {
     const PYTH_PACKAGE = registry["PYTH_PACKAGE_ID"]
 
     // Note: Set these before calling init_pyth
-    const upgradeCap = "0x4d14b6d73323af805fa531bad542c44696d671858303ffc1bfbf70212e20b042"
-    const deployerCap = "0xa49273072591dce457a77fc71f47c7ec9244cbdbe870938e10bc0d7209bb54d1"
+    const upgradeCap = "0xca0db6d95d5c8498cd5de0b6767e24b6fed45af463abca66982e476e3bb4bba4"
+    const deployerCap = "0xc28b1f1efc64db5647c931cb643f5cd4e3bdac38e0b64cd6f0fb13dfae94e98c"
 
     init_pyth(wallet, PYTH_PACKAGE, deployerCap, upgradeCap)
 }

+ 105 - 0
target_chains/sui/scripts/init_wormhole.ts

@@ -0,0 +1,105 @@
+/// Initialize Wormhole on Sui testnet
+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"})
+
+let network = NETWORK.TESTNET
+const registry = REGISTRY[network]
+const provider = new JsonRpcProvider(new Connection({ fullnode: registry["RPC_URL"] }))
+const walletPrivateKey = process.env.SUI_TESTNET;
+
+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 init_wormhole(wallet, registry["WORMHOLE_PACKAGE_ID"]);
+}
+
+main()
+
+ async function init_wormhole(
+    signer: RawSigner,
+    WORMHOLE_PACKAGE_ID: string
+  ) {
+    try {
+      // Publish contracts
+      const tx = new TransactionBlock();
+
+      // important
+      tx.setGasBudget(2500000000);
+
+    //   public fun complete(
+    //     deployer: DeployerCap,
+    //     upgrade_cap: UpgradeCap,
+    //     governance_chain: u16,
+    //     governance_contract: vector<u8>,
+    //     guardian_set_index: u32,
+    //     initial_guardians: vector<vector<u8>>,
+    //     guardian_set_seconds_to_live: u32,
+    //     message_fee: u64,
+    let DEPLOYER_CAP = "0x19f253b07e88634bfd5a3a749f60bfdb83c9748910646803f06b60b76319e7ba";
+    let UPGRADE_CAP = "0x746cbe8c14f9ef163fc4e18c1edc6fc61041e118f7d6e751bcc4162b722636d4"
+    let GOVERNANCE_CHAIN = 1;
+    let GOVERNANCE_CONTRACT = "04";
+    let GUARDIAN_SET_INDEX = 0;
+    let INITIAL_GUARDIANS = ["13947bd48b18e53fdaeee77f3473391ac727c638"]
+    let GUARDIAN_SECONDS_TO_LIVE = "100000000"
+    let MESSAGE_FEE = 0
+
+    tx.moveCall({
+        target: `${WORMHOLE_PACKAGE_ID}::setup::complete`,
+        arguments: [
+            tx.object(DEPLOYER_CAP),
+            tx.object(UPGRADE_CAP),
+            tx.pure(GOVERNANCE_CHAIN),
+            tx.pure(GOVERNANCE_CONTRACT),
+            tx.pure(GUARDIAN_SET_INDEX),
+            tx.pure(INITIAL_GUARDIANS.map(x=>[...Buffer.from(x, "hex")])),
+            tx.pure(GUARDIAN_SECONDS_TO_LIVE),
+            tx.pure(MESSAGE_FEE)
+        ],
+      });
+
+      let res = await signer.signAndExecuteTransactionBlock({
+        transactionBlock: tx,
+        options: {
+          showInput: true,
+          showEffects: true,
+          showEvents: true,
+          showObjectChanges: true,
+          showBalanceChanges: true,
+        },
+      });
+      console.log(res)
+
+      // Return publish transaction info
+      return res;
+    } catch (e) {
+      throw e;
+    } finally {
+    }
+  };

+ 7 - 7
target_chains/sui/scripts/registry.ts

@@ -14,10 +14,10 @@ export const REGISTRY =
         "RPC_URL": "http://0.0.0.0:9000"
     },
     TESTNET: {
-        "PYTH_PACKAGE_ID": "0x0",
+        "PYTH_PACKAGE_ID": "0xc17dcfa2b406995f5ea5237565418ebe6106467430a5a8ba198e451ca86f35e2",
         "PYTH_STATE_ID": "0x0",
-        "WORMHOLE_PACKAGE_ID": "0x0",
-        "WORMHOLE_STATE_ID": "0x0",
+        "WORMHOLE_PACKAGE_ID": "0x80c60bff35fe5026e319cf3d66ae671f2b4e12923c92c45df75eaf4de79e3ce7",
+        "WORMHOLE_STATE_ID": "0x79ab4d569f7eb1efdcc1f25b532f8593cda84776206772e33b490694cb8fc07a",
         "RPC_URL": "https://fullnode.testnet.sui.io:443"
     },
     MAINNET: {
@@ -38,15 +38,15 @@ export const INITIAL_DATA_SOURCES = {
             DATA_SOURCE_CHAINS: [1, 26]
         },
         TESTNET: {
-            GOVERNANCE_ADDRESS: "0x63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385",
+            GOVERNANCE_ADDRESS: "63278d271099bfd491951b3e648f08b1c71631e4a53674ad43e8f9f98068c385",
             GOVERNANCE_CHAIN: 1,
-            DATA_SOURCE_ADDRESSES: ["0xf346195ac02f37d60d4db8ffa6ef74cb1be3550047543a4a9ee9acf4d78697b0", "0xa27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6"],
+            DATA_SOURCE_ADDRESSES: ["f346195ac02f37d60d4db8ffa6ef74cb1be3550047543a4a9ee9acf4d78697b0", "a27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6"],
             DATA_SOURCE_CHAINS: [1, 26]
         },
         MAINNET: {
-            GOVERNANCE_ADDRESS: "0x5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e",
+            GOVERNANCE_ADDRESS: "5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e",
             GOVERNANCE_CHAIN: 1,
-            DATA_SOURCE_ADDRESSES: ["0x6bb14509a612f01fbbc4cffeebd4bbfb492a86df717ebe92eb6df432a3f00a25", "0xf8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0"],
+            DATA_SOURCE_ADDRESSES: ["6bb14509a612f01fbbc4cffeebd4bbfb492a86df717ebe92eb6df432a3f00a25", "f8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0"],
             DATA_SOURCE_CHAINS: [1, 26]
         }
 }