소스 검색

set is-active fixes (#323)

* merge

* use the right command here

* fix handling of boolean

* cleanup

Co-authored-by: Jayant Krishnamurthy <jkrishnamurthy@jumptrading.com>
Jayant Krishnamurthy 3 년 전
부모
커밋
575199f724
1개의 변경된 파일17개의 추가작업 그리고 5개의 파일을 삭제
  1. 17 5
      third_party/pyth/multisig-wh-message-builder/src/index.ts

+ 17 - 5
third_party/pyth/multisig-wh-message-builder/src/index.ts

@@ -89,7 +89,7 @@ program
   .option(
     "-i, --is-active <true/false>",
     "set the isActive field to this value",
-    true
+    "true"
   )
   .action(async (options) => {
     const squad = await getSquadsClient(
@@ -99,7 +99,8 @@ program
       options.ledgerDerivationChange,
       options.wallet
     );
-    const msAccount = await squad.getMultisig(options.vaultAddress);
+    const msAccount = await squad.getMultisig(new PublicKey(options.vaultAddress));
+
     const vaultAuthority = squad.getAuthorityPDA(
       msAccount.publicKey,
       msAccount.authorityIndex
@@ -110,13 +111,23 @@ program
       options.ledger,
       new PublicKey(options.vaultAddress)
     );
+
+    let isActive = undefined;
+    if (options.isActive === 'true') {
+      isActive = true;
+    } else if (options.isActive === 'false') {
+      isActive = false;
+    } else {
+      throw new Error(`Illegal argument for --is-active. Expected "true" or "false", got "${options.isActive}"`)
+    }
+
     const squadIxs: SquadInstruction[] = [
       {
         instruction: await setIsActiveIx(
           vaultAuthority,
           vaultAuthority,
           attesterProgramId,
-          options.active
+          isActive
         ),
       },
     ];
@@ -282,10 +293,11 @@ async function setIsActiveIx(
   attesterProgramId: PublicKey,
   isActive: boolean
 ): Promise<TransactionInstruction> {
-  const configKey = PublicKey.createProgramAddressSync(
+  const [configKey, _bump] = PublicKey.findProgramAddressSync(
     [Buffer.from("pyth2wormhole-config-v3")],
     attesterProgramId
   );
+
   const config: AccountMeta = {
     pubkey: configKey,
     isSigner: false,
@@ -303,7 +315,7 @@ async function setIsActiveIx(
     isWritable: true,
   };
 
-  const isActiveInt = isActive === true ? 1 : 0;
+  const isActiveInt = isActive ? 1 : 0;
   // first byte is the isActive instruction, second byte is true/false
   const data = Buffer.from([4, isActiveInt]);