set is-active fixes (#323)

* merge

* use the right command here

* fix handling of boolean

* cleanup

Co-authored-by: Jayant Krishnamurthy <jkrishnamurthy@jumptrading.com>
This commit is contained in:
Jayant Krishnamurthy 2022-09-30 09:00:48 -07:00 committed by GitHub
parent 29f53df71c
commit 575199f724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 5 deletions

View File

@ -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]);