@drift-labs/vaults-sdk 0.1.57 → 0.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/cli.ts CHANGED
@@ -15,7 +15,8 @@ import {
15
15
  withdraw,
16
16
  forceWithdraw,
17
17
  listDepositorsForVault,
18
- managerUpdateMarginTradingEnabled
18
+ managerUpdateMarginTradingEnabled,
19
+ decodeLogs,
19
20
  } from "./commands";
20
21
 
21
22
  import { Command, Option } from 'commander';
@@ -141,6 +142,11 @@ program
141
142
  .description("Forces the vault to send out a withdraw after the redeem period has passed")
142
143
  .addOption(new Option("--vault-depositor-address <vaultDepositorAddress>", "VaultDepositor address").makeOptionMandatory(false))
143
144
  .action((opts) => forceWithdraw(program, opts));
145
+ program
146
+ .command("decode-logs")
147
+ .description("Decode program logs from a txid")
148
+ .addOption(new Option("--tx <tx>", "Transaction hash").makeOptionMandatory(true))
149
+ .action((opts) => decodeLogs(program, opts));
144
150
 
145
151
  program.parseAsync().then(() => {
146
152
  process.exit(0);
@@ -0,0 +1,68 @@
1
+ import {
2
+ OptionValues,
3
+ Command
4
+ } from "commander";
5
+ import { getCommandContext } from "../utils";
6
+ import { VaultDepositorRecord } from "../../src";
7
+ import { BN, TEN, convertToNumber, getVariant } from "@drift-labs/sdk";
8
+
9
+ export const decodeLogs = async (program: Command, cmdOpts: OptionValues) => {
10
+
11
+ let txId: string;
12
+ try {
13
+ txId = cmdOpts.tx as string;
14
+ } catch (err) {
15
+ console.error("Invalid transaction hash");
16
+ process.exit(1);
17
+ }
18
+ if (!txId) {
19
+ console.error("Invalid transaction hash");
20
+ process.exit(1);
21
+ }
22
+
23
+ const {
24
+ driftVault,
25
+ driftClient,
26
+ } = await getCommandContext(program, false);
27
+
28
+ const tx = await driftClient.connection.getParsedTransaction(txId, {
29
+ commitment: "confirmed",
30
+ maxSupportedTransactionVersion: 0,
31
+ });
32
+
33
+ // @ts-ignore
34
+ for (const event of driftVault.program._events._eventParser.parseLogs(
35
+ tx!.meta!.logMessages
36
+ )) {
37
+
38
+ /* eslint-disable no-case-declarations */
39
+ switch (event.name) {
40
+ case "VaultDepositorRecord":
41
+ const data: VaultDepositorRecord = event.data;
42
+ const spotMarket = driftClient.getSpotMarketAccount(data.spotMarketIndex);
43
+ const spotPrecision = TEN.pow(new BN(spotMarket!.decimals));
44
+ const date = new Date(data.ts.toNumber() * 1000);
45
+
46
+ console.log(event.name);
47
+ console.log(` ts: ${date.toISOString()} (${data.ts.toNumber()})`);
48
+ console.log(` vault: ${data.vault.toBase58()}`);
49
+ console.log(` depositorAuthority: ${data.depositorAuthority.toBase58()}`);
50
+ console.log(` action: ${getVariant(data.action)}`);
51
+ console.log(` amount: ${convertToNumber(data.amount, spotPrecision)}`);
52
+ console.log(` vaultSharesBefore: ${data.vaultSharesBefore.toNumber()}`);
53
+ console.log(` vaultSharesAfter: ${data.vaultSharesAfter.toNumber()} (${data.vaultSharesAfter.toNumber() - data.vaultSharesBefore.toNumber()})`);
54
+ console.log(` vaultEquityBefore: ${convertToNumber(data.vaultEquityBefore, spotPrecision)}`);
55
+ console.log(` userVaultSharesBefore: ${data.userVaultSharesBefore.toNumber()}`);
56
+ console.log(` userVaultSharesAfter: ${data.userVaultSharesAfter.toNumber()} (${data.userVaultSharesAfter.toNumber() - data.userVaultSharesBefore.toNumber()})`);
57
+ console.log(` totalVaultSharesBefore: ${data.totalVaultSharesBefore.toNumber()}`);
58
+ console.log(` totalVaultSharesAfter: ${data.totalVaultSharesAfter.toNumber()} (${data.totalVaultSharesAfter.toNumber() - data.totalVaultSharesBefore.toNumber()})`);
59
+ console.log(` profitShare: ${data.profitShare.toNumber()}`);
60
+ console.log(` managementFee: ${data.managementFee.toNumber()}`);
61
+ console.log(` managementFeeShares: ${data.managementFeeShares.toNumber()}`);
62
+ break;
63
+ default:
64
+ console.log(event);
65
+ }
66
+ }
67
+
68
+ };
@@ -21,7 +21,11 @@ export const deposit = async (program: Command, cmdOpts: OptionValues) => {
21
21
  driftVault
22
22
  } = await getCommandContext(program, true);
23
23
 
24
- const spotMarket = driftClient.getSpotMarketAccount(0); // takes USDC deposits
24
+ const vaultDepositorAccount =
25
+ await driftVault.program.account.vaultDepositor.fetch(vaultDepositorAddress);
26
+ const vaultAddress = vaultDepositorAccount.vault;
27
+ const vaultAccount = await driftVault.program.account.vault.fetch(vaultAddress);
28
+ const spotMarket = driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
25
29
  if (!spotMarket) {
26
30
  throw new Error("No spot market found");
27
31
  }
@@ -14,4 +14,5 @@ export * from './requestWithdraw';
14
14
  export * from './forceWithdraw';
15
15
  export * from './withdraw';
16
16
  export * from './listDepositorsForVault';
17
- export * from './managerUpdateMarginTradingEnabled';
17
+ export * from './managerUpdateMarginTradingEnabled';
18
+ export * from './decodeLogs';
@@ -34,7 +34,7 @@ export const initVault = async (program: Command, cmdOpts: OptionValues) => {
34
34
  spotMarketIndex = "0";
35
35
  }
36
36
  spotMarketIndex = parseInt(spotMarketIndex);
37
- const spotMarket = driftClient.getSpotMarketAccount(spotMarketIndex); // takes USDC deposits
37
+ const spotMarket = driftClient.getSpotMarketAccount(spotMarketIndex);
38
38
  if (!spotMarket) {
39
39
  throw new Error("No spot market found");
40
40
  }
@@ -77,8 +77,8 @@ export const initVault = async (program: Command, cmdOpts: OptionValues) => {
77
77
  if (!minDepositAmount) {
78
78
  minDepositAmount = "0";
79
79
  }
80
- minDepositAmount = parseInt(minDepositAmount);
81
- const minDepositAmountBN = new BN(minDepositAmount).mul(spotPrecision);
80
+ minDepositAmount = parseFloat(minDepositAmount);
81
+ const minDepositAmountBN = new BN(spotPrecision.toNumber() * minDepositAmount);
82
82
 
83
83
  let delegate = cmdOpts.delegate;
84
84
  if (!delegate) {
@@ -21,7 +21,8 @@ export const managerDeposit = async (program: Command, cmdOpts: OptionValues) =>
21
21
  driftVault
22
22
  } = await getCommandContext(program, true);
23
23
 
24
- const spotMarket = driftClient.getSpotMarketAccount(0); // takes USDC deposits
24
+ const vaultAccount = await driftVault.program.account.vault.fetch(vaultAddress);
25
+ const spotMarket = driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
25
26
  if (!spotMarket) {
26
27
  throw new Error("No spot market found");
27
28
  }
package/cli/utils.ts CHANGED
@@ -91,7 +91,9 @@ export async function getCommandContext(program: Command, needToSign: boolean):
91
91
  }
92
92
 
93
93
  const wallet = new Wallet(keypair);
94
- console.log(`Signing wallet address (need to sign: ${needToSign}): `, wallet.publicKey.toBase58());
94
+ if (needToSign) {
95
+ console.log(`Signing wallet address: `, wallet.publicKey.toBase58());
96
+ }
95
97
 
96
98
  const connection = new Connection(opts.url, {
97
99
  commitment: opts.commitment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/vaults-sdk",
3
- "version": "0.1.57",
3
+ "version": "0.1.58",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "directories": {
@@ -8,8 +8,8 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@coral-xyz/anchor": "^0.26.0",
11
- "@drift-labs/competitions-sdk": "^0.2.5",
12
- "@drift-labs/sdk": "2.49.0-beta.9",
11
+ "@drift-labs/competitions-sdk": "0.2.73",
12
+ "@drift-labs/sdk": "2.49.0-beta.10",
13
13
  "@solana/web3.js": "1.73.2",
14
14
  "commander": "^11.0.0",
15
15
  "dotenv": "^16.3.1",