浏览代码

chore: xc-admin-cli improvements (#2196)

* do it

* go

* go

* go
guibescos 11 月之前
父节点
当前提交
97270f240b
共有 1 个文件被更改,包括 25 次插入1 次删除
  1. 25 1
      governance/xc_admin/packages/xc_admin_cli/src/index.ts

+ 25 - 1
governance/xc_admin/packages/xc_admin_cli/src/index.ts

@@ -458,6 +458,15 @@ multisigCommand(
     );
   });
 
+async function accountExists(
+  cluster: PythCluster,
+  accountPubkey: PublicKey
+): Promise<boolean> {
+  const connection = new Connection(getPythClusterApiUrl(cluster));
+  const account = await connection.getAccountInfo(accountPubkey);
+  return account !== null;
+}
+
 multisigCommand(
   "initialize-stake-accounts",
   "Initialize stake accounts and assign them to the given vote accounts"
@@ -484,6 +493,15 @@ multisigCommand(
         authorizedPubkey,
         votePubkey
       );
+
+      if (await accountExists(cluster, stakePubkey)) {
+        throw new Error(
+          "Stake account for validator " +
+            votePubkey.toBase58() +
+            " already exists, it may be already permissioned"
+        );
+      }
+
       instructions.push(
         SystemProgram.createAccountWithSeed({
           basePubkey: authorizedPubkey,
@@ -513,11 +531,17 @@ multisigCommand(
       );
     }
 
-    await vault.proposeInstructions(
+    const proposalAddresses = await vault.proposeInstructions(
       instructions,
       cluster,
       DEFAULT_PRIORITY_FEE_CONFIG
     );
+
+    // This should be a single proposal normally
+    console.log(
+      "Successfully proposed at: https://proposals.pyth.network/?tab=proposals&proposal=" +
+        proposalAddresses[0].toBase58()
+    );
   });
 
 multisigCommand(