Skip to content

Commit

Permalink
cli: add derive-vault-address
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Oct 21, 2023
1 parent f8ec340 commit 8aa6624
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ts/sdk/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
initVault,
viewVault,
deriveVaultAddress,
managerDeposit,
managerRequestWithdraw,
managerCancelWithdraw,
Expand Down Expand Up @@ -43,6 +44,11 @@ program
.description("View Vault account details")
.addOption(new Option("--vault-address <address>", "Address of the Vault to view").makeOptionMandatory(true))
.action((opts) => viewVault(program, opts));
program
.command("derive-vault-address")
.description("Derives the vault address from its name")
.addOption(new Option("--vault-name <string>", "Name of the vault").makeOptionMandatory(true))
.action((opts) => deriveVaultAddress(program, opts));
program
.command("view-vault-depositor")
.description("View VaultDepositor account details")
Expand Down
15 changes: 15 additions & 0 deletions ts/sdk/cli/commands/deriveVaultAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
OptionValues,
Command
} from "commander";
import { encodeName } from "@drift-labs/sdk";
import { VAULT_PROGRAM_ID, getVaultAddressSync } from "../../src";

export const deriveVaultAddress = async (_program: Command, cmdOpts: OptionValues) => {

const vaultName = cmdOpts.vaultName;
const vaultNameBytes = encodeName(vaultName!);
const vaultAddress = getVaultAddressSync(VAULT_PROGRAM_ID, vaultNameBytes);

console.log(`Vault address: ${vaultAddress.toBase58()}`);
};
1 change: 1 addition & 0 deletions ts/sdk/cli/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './initVault';
export * from './viewVault';
export * from './deriveVaultAddress';
export * from './managerDeposit';
export * from './managerRequestWithdraw';
export * from './managerCancelWithdraw';
Expand Down

0 comments on commit 8aa6624

Please sign in to comment.