Skip to content

Commit

Permalink
cli:add list all vault depositors command
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Sep 8, 2023
1 parent 2846373 commit 074ac22
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ts/sdk/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
deposit,
requestWithdraw,
withdraw,
listDepositorsForVault,
} from "./commands";

import { Command, Option } from 'commander';
Expand Down Expand Up @@ -39,6 +40,11 @@ program
.addOption(new Option("--vault-address <address>", "Address of the Vault to view").makeOptionMandatory(false))
.addOption(new Option("--authority <vaultDepositorAuthority>", "VaultDepositor authority address").makeOptionMandatory(false))
.action((opts) => viewVaultDepositor(program, opts));
program
.command("list-vault-depositors")
.description("List VaultDepositors for a Vault")
.addOption(new Option("--vault-address <address>", "Address of the Vault to view").makeOptionMandatory(true))
.action((opts) => listDepositorsForVault(program, opts));
program
.command("manager-deposit")
.description("Make a deposit to your vault")
Expand Down Expand Up @@ -96,4 +102,4 @@ program
.addOption(new Option("--authority <vaultDepositorAuthority>", "VaultDepositor authority address").makeOptionMandatory(false))
.action((opts) => withdraw(program, opts));

program.parseAsync().then(() => {});
program.parseAsync().then(() => { });
3 changes: 2 additions & 1 deletion ts/sdk/cli/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export * from './applyProfitShare';
export * from './initVaultDepositor';
export * from './deposit';
export * from './requestWithdraw';
export * from './withdraw';
export * from './withdraw';
export * from './listDepositorsForVault';
33 changes: 33 additions & 0 deletions ts/sdk/cli/commands/listDepositorsForVault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { PublicKey } from "@solana/web3.js";
import {
OptionValues,
Command
} from "commander";
import { getCommandContext } from "../utils";

export const listDepositorsForVault = async (program: Command, cmdOpts: OptionValues) => {

const {
driftVault
} = await getCommandContext(program, false);

let vaultAddress: PublicKey | undefined = undefined;
try {
if (cmdOpts.vaultAddress !== undefined) {
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
} else {
console.error("Must supply --vault-address");
process.exit(1);
}
} catch (err) {
console.error("Failed to load VaultDepositor address");
process.exit(1);
}

const vaultDepositors = await driftVault.getAllVaultDepositors(vaultAddress);
vaultDepositors.forEach((vaultDepositor) => {
console.log(vaultDepositor.publicKey.toBase58());
});
// printVaultDepositor(vaultDepositor);
console.log("Done!");
};

0 comments on commit 074ac22

Please sign in to comment.