@drift-labs/vaults-sdk 0.1.2 → 0.1.4

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/bun.lockb ADDED
Binary file
@@ -26,11 +26,13 @@ class PollingVaultDepositorSubscriber extends pollingVaultsProgramAccountSubscri
26
26
  async fetch() {
27
27
  var _a, _b;
28
28
  await this.accountLoader.load();
29
- const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.pubkey);
29
+ const bufferAndSlot = this.accountLoader.getBufferAndSlot(this.pubkey);
30
+ if (!bufferAndSlot)
31
+ return;
30
32
  const currentSlot = (_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
31
- if (buffer && slot > currentSlot) {
32
- const account = this.program.account.vaultDepositor.coder.accounts.decode('vaultDepositor', buffer);
33
- this.account = { data: account, slot };
33
+ if (bufferAndSlot.buffer && bufferAndSlot.slot > currentSlot) {
34
+ const account = this.program.account.vaultDepositor.coder.accounts.decode('vaultDepositor', bufferAndSlot.buffer);
35
+ this.account = { data: account, slot: bufferAndSlot.slot };
34
36
  }
35
37
  }
36
38
  updateData(vaultDepositorAcc, slot) {
@@ -26,11 +26,13 @@ class PollingVaultSubscriber extends pollingVaultsProgramAccountSubscriber_1.Pol
26
26
  async fetch() {
27
27
  var _a, _b;
28
28
  await this.accountLoader.load();
29
- const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.pubkey);
29
+ const bufferAndSlot = this.accountLoader.getBufferAndSlot(this.pubkey);
30
+ if (!bufferAndSlot)
31
+ return;
30
32
  const currentSlot = (_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
31
- if (buffer && slot > currentSlot) {
32
- const account = this.program.account.vault.coder.accounts.decode('vault', buffer);
33
- this.account = { data: account, slot };
33
+ if (bufferAndSlot.buffer && bufferAndSlot.slot > currentSlot) {
34
+ const account = this.program.account.vault.coder.accounts.decode('vault', bufferAndSlot.buffer);
35
+ this.account = { data: account, slot: bufferAndSlot.slot };
34
36
  }
35
37
  }
36
38
  updateData(vaultAcc, slot) {
@@ -45,9 +45,9 @@ class PollingVaultsProgramAccountSubscriber {
45
45
  return;
46
46
  }
47
47
  this.accountLoader.removeAccount(this.pubkey, this.callbackId);
48
- this.callbackId = undefined;
48
+ this.callbackId = null;
49
49
  this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
50
- this.errorCallbackId = undefined;
50
+ this.errorCallbackId = null;
51
51
  this._isSubscribed = false;
52
52
  }
53
53
  async fetchIfUnloaded() {
@@ -62,6 +62,9 @@ class PollingVaultsProgramAccountSubscriber {
62
62
  }
63
63
  getAccountAndSlot() {
64
64
  this.assertIsSubscribed();
65
+ if (!this.account) {
66
+ throw new Error('Account not loaded');
67
+ }
65
68
  return this.account;
66
69
  }
67
70
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
- import { BN, Program } from '@coral-xyz/anchor';
3
- import { BulkAccountLoader } from '@drift-labs/sdk';
2
+ import { Program } from '@coral-xyz/anchor';
3
+ import { BulkAccountLoader, BN } from '@drift-labs/sdk';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { DriftVaults } from '../types/drift_vaults';
6
6
  import { Vault, VaultAccountEvents } from '../types/types';
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultAccount = void 0;
4
- const anchor_1 = require("@coral-xyz/anchor");
5
4
  const sdk_1 = require("@drift-labs/sdk");
6
5
  const accountSubscribers_1 = require("../accountSubscribers");
7
6
  const vaultsProgramAccount_1 = require("./vaultsProgramAccount");
@@ -31,21 +30,21 @@ class VaultAccount extends vaultsProgramAccount_1.VaultsProgramAccount {
31
30
  managementFeeShares: sdk_1.ZERO,
32
31
  };
33
32
  }
34
- const now = new anchor_1.BN(Date.now() / 1000);
33
+ const now = new sdk_1.BN(Date.now() / 1000);
35
34
  const sinceLast = now.sub(accountData.lastFeeUpdateTs);
36
35
  let managementFeeAmount = depositorsEquity
37
36
  .mul(accountData.managementFee)
38
37
  .div(sdk_1.PERCENTAGE_PRECISION)
39
38
  .mul(sinceLast)
40
39
  .div(sdk_1.ONE_YEAR);
41
- managementFeeAmount = anchor_1.BN.min(managementFeeAmount, depositorsEquity.sub(sdk_1.ONE));
40
+ managementFeeAmount = sdk_1.BN.min(managementFeeAmount, depositorsEquity.sub(sdk_1.ONE));
42
41
  const newTotalSharesFactor = depositorsEquity
43
42
  .mul(sdk_1.PERCENTAGE_PRECISION)
44
43
  .div(depositorsEquity.sub(managementFeeAmount));
45
44
  let newTotalShares = accountData.totalShares
46
45
  .mul(newTotalSharesFactor)
47
46
  .div(sdk_1.PERCENTAGE_PRECISION);
48
- newTotalShares = anchor_1.BN.max(newTotalShares, accountData.userShares);
47
+ newTotalShares = sdk_1.BN.max(newTotalShares, accountData.userShares);
49
48
  const managementFeeShares = newTotalShares.sub(accountData.totalShares);
50
49
  return { totalShares: newTotalShares, managementFeeShares };
51
50
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
- import { BN, Program } from '@coral-xyz/anchor';
3
- import { BulkAccountLoader } from '@drift-labs/sdk';
2
+ import { Program } from '@coral-xyz/anchor';
3
+ import { BN, BulkAccountLoader } from '@drift-labs/sdk';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { DriftVaults } from '../types/drift_vaults';
6
6
  import { VaultDepositor, VaultDepositorAccountEvents } from '../types/types';
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultDepositorAccount = void 0;
4
- const anchor_1 = require("@coral-xyz/anchor");
5
4
  const sdk_1 = require("@drift-labs/sdk");
6
5
  const accountSubscribers_1 = require("../accountSubscribers");
7
6
  const vaultsProgramAccount_1 = require("./vaultsProgramAccount");
@@ -30,7 +29,7 @@ class VaultDepositorAccount extends vaultsProgramAccount_1.VaultsProgramAccount
30
29
  const profit = depositorEquity
31
30
  .sub(accountData.netDeposits)
32
31
  .sub(accountData.cumulativeProfitShareAmount);
33
- if (profit.lte(new anchor_1.BN(0))) {
32
+ if (profit.lte(new sdk_1.BN(0))) {
34
33
  return sdk_1.ZERO;
35
34
  }
36
35
  const profitShareAmount = profit
@@ -2,7 +2,7 @@
2
2
  import { BN, DriftClient } from '@drift-labs/sdk';
3
3
  import { Program, ProgramAccount } from '@coral-xyz/anchor';
4
4
  import { DriftVaults } from './types/drift_vaults';
5
- import { CompetitionsClient } from '@drift-labs/competitions-sdk/lib/competitionClient';
5
+ import { CompetitionsClient } from '@drift-labs/competitions-sdk';
6
6
  import { PublicKey, SetComputeUnitLimitParams, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
7
7
  import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
8
8
  export declare class VaultClient {
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultClient = void 0;
4
4
  const sdk_1 = require("@drift-labs/sdk");
5
5
  const anchor_1 = require("@coral-xyz/anchor");
6
- const addresses_1 = require("@drift-labs/competitions-sdk/lib/addresses");
7
- const addresses_2 = require("./addresses");
6
+ const competitions_sdk_1 = require("@drift-labs/competitions-sdk");
7
+ const addresses_1 = require("./addresses");
8
8
  const web3_js_1 = require("@solana/web3.js");
9
9
  const spl_token_1 = require("@solana/spl-token");
10
10
  const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
@@ -15,6 +15,7 @@ class VaultClient {
15
15
  this.cliMode = !!cliMode;
16
16
  }
17
17
  async getVault(vault) {
18
+ // @ts-ignore
18
19
  return await this.program.account.vault.fetch(vault);
19
20
  }
20
21
  async getVaultDepositor(vaultDepositor) {
@@ -55,6 +56,7 @@ class VaultClient {
55
56
  async calculateVaultEquity(params) {
56
57
  let vaultAccount;
57
58
  if (params.address !== undefined) {
59
+ // @ts-ignore
58
60
  vaultAccount = await this.program.account.vault.fetch(params.address);
59
61
  }
60
62
  else if (params.vault !== undefined) {
@@ -73,10 +75,13 @@ class VaultClient {
73
75
  return netSpotValue.add(unrealizedPnl);
74
76
  }
75
77
  async initializeVault(params) {
76
- const vault = (0, addresses_2.getVaultAddressSync)(this.program.programId, params.name);
77
- const tokenAccount = (0, addresses_2.getTokenVaultAddressSync)(this.program.programId, vault);
78
+ const vault = (0, addresses_1.getVaultAddressSync)(this.program.programId, params.name);
79
+ const tokenAccount = (0, addresses_1.getTokenVaultAddressSync)(this.program.programId, vault);
78
80
  const driftState = await this.driftClient.getStatePublicKey();
79
81
  const spotMarket = this.driftClient.getSpotMarketAccount(params.spotMarketIndex);
82
+ if (!spotMarket) {
83
+ throw new Error(`Spot market ${params.spotMarketIndex} not found on driftClient`);
84
+ }
80
85
  const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
81
86
  const userKey = (0, sdk_1.getUserAccountPublicKeySync)(this.driftClient.program.programId, vault);
82
87
  const accounts = {
@@ -138,6 +143,9 @@ class VaultClient {
138
143
  async managerDeposit(vault, amount) {
139
144
  const vaultAccount = await this.program.account.vault.fetch(vault);
140
145
  const driftSpotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
146
+ if (!driftSpotMarket) {
147
+ throw new Error(`Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`);
148
+ }
141
149
  const user = new sdk_1.User({
142
150
  driftClient: this.driftClient,
143
151
  userAccountPublicKey: vaultAccount.user,
@@ -164,6 +172,7 @@ class VaultClient {
164
172
  .rpc();
165
173
  }
166
174
  async managerRequestWithdraw(vault, amount, withdrawUnit) {
175
+ // @ts-ignore
167
176
  const vaultAccount = (await this.program.account.vault.fetch(vault));
168
177
  if (!this.driftClient.wallet.publicKey.equals(vaultAccount.manager)) {
169
178
  throw new Error(`Only the manager of the vault can request a withdraw.`);
@@ -232,8 +241,8 @@ class VaultClient {
232
241
  else {
233
242
  const cancelRequestWithdrawIx = this.program.instruction.mangerCancelWithdrawRequest({
234
243
  accounts: {
235
- manager: this.driftClient.wallet.publicKey,
236
244
  ...accounts,
245
+ manager: this.driftClient.wallet.publicKey,
237
246
  },
238
247
  remainingAccounts,
239
248
  });
@@ -320,7 +329,7 @@ class VaultClient {
320
329
  });
321
330
  }
322
331
  createInitVaultDepositorIx(vault, authority) {
323
- const vaultDepositor = (0, addresses_2.getVaultDepositorAddressSync)(this.program.programId, vault, authority);
332
+ const vaultDepositor = (0, addresses_1.getVaultDepositorAddressSync)(this.program.programId, vault, authority || this.driftClient.wallet.publicKey);
324
333
  const accounts = {
325
334
  vaultDepositor,
326
335
  vault,
@@ -343,7 +352,7 @@ class VaultClient {
343
352
  * @returns
344
353
  */
345
354
  async initializeVaultDepositor(vault, authority) {
346
- const vaultDepositor = (0, addresses_2.getVaultDepositorAddressSync)(this.program.programId, vault, authority);
355
+ const vaultDepositor = (0, addresses_1.getVaultDepositorAddressSync)(this.program.programId, vault, authority || this.driftClient.wallet.publicKey);
347
356
  const accounts = {
348
357
  vaultDepositor,
349
358
  vault,
@@ -389,6 +398,9 @@ class VaultClient {
389
398
  const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultPubKey);
390
399
  const driftStateKey = await this.driftClient.getStatePublicKey();
391
400
  const spotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
401
+ if (!spotMarket) {
402
+ throw new Error(`Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`);
403
+ }
392
404
  const accounts = {
393
405
  vault: vaultPubKey,
394
406
  vaultDepositor,
@@ -481,6 +493,9 @@ class VaultClient {
481
493
  const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultDepositorAccount.vault);
482
494
  const driftStateKey = await this.driftClient.getStatePublicKey();
483
495
  const spotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
496
+ if (!spotMarket) {
497
+ throw new Error(`Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`);
498
+ }
484
499
  const accounts = {
485
500
  vault: vaultDepositorAccount.vault,
486
501
  vaultDepositor,
@@ -619,11 +634,15 @@ class VaultClient {
619
634
  async initializeInsuranceFundStake(vault, spotMarketIndex) {
620
635
  const vaultAccount = await this.program.account.vault.fetch(vault);
621
636
  const ifStakeAccountPublicKey = (0, sdk_1.getInsuranceFundStakeAccountPublicKey)(this.driftClient.program.programId, vault, spotMarketIndex);
637
+ const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
638
+ if (!spotMarket) {
639
+ throw new Error(`Spot market ${spotMarketIndex} not found on driftClient`);
640
+ }
622
641
  return await this.program.methods
623
642
  .initializeInsuranceFundStake(spotMarketIndex)
624
643
  .accounts({
625
644
  vault: vault,
626
- driftSpotMarket: this.driftClient.getSpotMarketAccount(spotMarketIndex).pubkey,
645
+ driftSpotMarket: spotMarket.pubkey,
627
646
  insuranceFundStake: ifStakeAccountPublicKey,
628
647
  driftUserStats: vaultAccount.userStats,
629
648
  driftState: await this.driftClient.getStatePublicKey(),
@@ -640,8 +659,8 @@ class VaultClient {
640
659
  async initializeCompetitor(vault, competitionsClient, competitionName) {
641
660
  const vaultAccount = await this.program.account.vault.fetch(vault);
642
661
  const encodedName = (0, sdk_1.encodeName)(competitionName);
643
- const competitionAddress = (0, addresses_1.getCompetitionAddressSync)(competitionsClient.program.programId, encodedName);
644
- const competitorAddress = (0, addresses_1.getCompetitorAddressSync)(competitionsClient.program.programId, competitionAddress, vault);
662
+ const competitionAddress = (0, competitions_sdk_1.getCompetitionAddressSync)(competitionsClient.program.programId, encodedName);
663
+ const competitorAddress = (0, competitions_sdk_1.getCompetitorAddressSync)(competitionsClient.program.programId, competitionAddress, vault);
645
664
  return await this.program.methods
646
665
  .initializeCompetitor()
647
666
  .accounts({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/vaults-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "directories": {
@@ -8,7 +8,8 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@coral-xyz/anchor": "^0.26.0",
11
- "@drift-labs/sdk": "2.43.0-beta.5",
11
+ "@drift-labs/competitions-sdk": "^0.2.5",
12
+ "@drift-labs/sdk": "2.43.0-beta.17",
12
13
  "@solana/web3.js": "1.73.2",
13
14
  "commander": "^11.0.0",
14
15
  "dotenv": "^16.3.1",
@@ -47,14 +47,15 @@ export class PollingVaultDepositorSubscriber
47
47
 
48
48
  async fetch(): Promise<void> {
49
49
  await this.accountLoader.load();
50
- const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.pubkey);
50
+ const bufferAndSlot = this.accountLoader.getBufferAndSlot(this.pubkey);
51
+ if (!bufferAndSlot) return;
51
52
  const currentSlot = this.account?.slot ?? 0;
52
- if (buffer && slot > currentSlot) {
53
+ if (bufferAndSlot.buffer && bufferAndSlot.slot > currentSlot) {
53
54
  const account = this.program.account.vaultDepositor.coder.accounts.decode(
54
55
  'vaultDepositor',
55
- buffer
56
+ bufferAndSlot.buffer
56
57
  );
57
- this.account = { data: account, slot };
58
+ this.account = { data: account, slot: bufferAndSlot.slot };
58
59
  }
59
60
  }
60
61
 
@@ -41,14 +41,15 @@ export class PollingVaultSubscriber
41
41
 
42
42
  async fetch(): Promise<void> {
43
43
  await this.accountLoader.load();
44
- const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.pubkey);
44
+ const bufferAndSlot = this.accountLoader.getBufferAndSlot(this.pubkey);
45
+ if (!bufferAndSlot) return;
45
46
  const currentSlot = this.account?.slot ?? 0;
46
- if (buffer && slot > currentSlot) {
47
+ if (bufferAndSlot.buffer && bufferAndSlot.slot > currentSlot) {
47
48
  const account = this.program.account.vault.coder.accounts.decode(
48
49
  'vault',
49
- buffer
50
+ bufferAndSlot.buffer
50
51
  );
51
- this.account = { data: account, slot };
52
+ this.account = { data: account, slot: bufferAndSlot.slot };
52
53
  }
53
54
  }
54
55
 
@@ -77,11 +77,11 @@ export abstract class PollingVaultsProgramAccountSubscriber<
77
77
  return;
78
78
  }
79
79
 
80
- this.accountLoader.removeAccount(this.pubkey, this.callbackId);
81
- this.callbackId = undefined;
80
+ this.accountLoader.removeAccount(this.pubkey, this.callbackId!);
81
+ this.callbackId = null;
82
82
 
83
- this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
84
- this.errorCallbackId = undefined;
83
+ this.accountLoader.removeErrorCallbacks(this.errorCallbackId!);
84
+ this.errorCallbackId = null;
85
85
 
86
86
  this._isSubscribed = false;
87
87
  }
@@ -102,6 +102,9 @@ export abstract class PollingVaultsProgramAccountSubscriber<
102
102
 
103
103
  getAccountAndSlot(): DataAndSlot<Account> {
104
104
  this.assertIsSubscribed();
105
+ if (!this.account) {
106
+ throw new Error('Account not loaded');
107
+ }
105
108
  return this.account;
106
109
  }
107
110
 
@@ -1,10 +1,11 @@
1
- import { BN, Program } from '@coral-xyz/anchor';
1
+ import { Program } from '@coral-xyz/anchor';
2
2
  import {
3
3
  BulkAccountLoader,
4
4
  ONE,
5
5
  ONE_YEAR,
6
6
  PERCENTAGE_PRECISION,
7
7
  ZERO,
8
+ BN,
8
9
  } from '@drift-labs/sdk';
9
10
  import { PublicKey } from '@solana/web3.js';
10
11
  import { DriftVaults } from '../types/drift_vaults';
@@ -1,5 +1,10 @@
1
- import { BN, Program } from '@coral-xyz/anchor';
2
- import { BulkAccountLoader, PERCENTAGE_PRECISION, ZERO } from '@drift-labs/sdk';
1
+ import { Program } from '@coral-xyz/anchor';
2
+ import {
3
+ BN,
4
+ BulkAccountLoader,
5
+ PERCENTAGE_PRECISION,
6
+ ZERO,
7
+ } from '@drift-labs/sdk';
3
8
  import { PublicKey } from '@solana/web3.js';
4
9
  import { DriftVaults } from '../types/drift_vaults';
5
10
  import { VaultDepositor, VaultDepositorAccountEvents } from '../types/types';
@@ -9,6 +9,7 @@ export abstract class VaultsProgramAccount<
9
9
  Account,
10
10
  AccountEvents extends VaultsProgramAccountBaseEvents
11
11
  > {
12
+ // @ts-ignore
12
13
  accountSubscriber: VaultsProgramAccountSubscriber<Account, AccountEvents>;
13
14
 
14
15
  get isSubscribed(): boolean {
@@ -11,10 +11,10 @@ import {
11
11
  import { BorshAccountsCoder, Program, ProgramAccount } from '@coral-xyz/anchor';
12
12
  import { DriftVaults } from './types/drift_vaults';
13
13
  import {
14
+ CompetitionsClient,
14
15
  getCompetitionAddressSync,
15
16
  getCompetitorAddressSync,
16
- } from '@drift-labs/competitions-sdk/lib/addresses';
17
- import { CompetitionsClient } from '@drift-labs/competitions-sdk/lib/competitionClient';
17
+ } from '@drift-labs/competitions-sdk';
18
18
  import {
19
19
  getTokenVaultAddressSync,
20
20
  getVaultAddressSync,
@@ -57,6 +57,7 @@ export class VaultClient {
57
57
  }
58
58
 
59
59
  public async getVault(vault: PublicKey): Promise<Vault> {
60
+ // @ts-ignore
60
61
  return await this.program.account.vault.fetch(vault);
61
62
  }
62
63
 
@@ -109,6 +110,7 @@ export class VaultClient {
109
110
  }): Promise<BN> {
110
111
  let vaultAccount: Vault;
111
112
  if (params.address !== undefined) {
113
+ // @ts-ignore
112
114
  vaultAccount = await this.program.account.vault.fetch(params.address);
113
115
  } else if (params.vault !== undefined) {
114
116
  vaultAccount = params.vault;
@@ -149,6 +151,11 @@ export class VaultClient {
149
151
  const spotMarket = this.driftClient.getSpotMarketAccount(
150
152
  params.spotMarketIndex
151
153
  );
154
+ if (!spotMarket) {
155
+ throw new Error(
156
+ `Spot market ${params.spotMarketIndex} not found on driftClient`
157
+ );
158
+ }
152
159
 
153
160
  const userStatsKey = getUserStatsAccountPublicKey(
154
161
  this.driftClient.program.programId,
@@ -233,6 +240,11 @@ export class VaultClient {
233
240
  const driftSpotMarket = this.driftClient.getSpotMarketAccount(
234
241
  vaultAccount.spotMarketIndex
235
242
  );
243
+ if (!driftSpotMarket) {
244
+ throw new Error(
245
+ `Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`
246
+ );
247
+ }
236
248
 
237
249
  const user = new User({
238
250
  driftClient: this.driftClient,
@@ -276,6 +288,7 @@ export class VaultClient {
276
288
  amount: BN,
277
289
  withdrawUnit: WithdrawUnit
278
290
  ): Promise<TransactionSignature> {
291
+ // @ts-ignore
279
292
  const vaultAccount = (await this.program.account.vault.fetch(
280
293
  vault
281
294
  )) as Vault;
@@ -370,8 +383,8 @@ export class VaultClient {
370
383
  const cancelRequestWithdrawIx =
371
384
  this.program.instruction.mangerCancelWithdrawRequest({
372
385
  accounts: {
373
- manager: this.driftClient.wallet.publicKey,
374
386
  ...accounts,
387
+ manager: this.driftClient.wallet.publicKey,
375
388
  },
376
389
  remainingAccounts,
377
390
  });
@@ -515,7 +528,7 @@ export class VaultClient {
515
528
  const vaultDepositor = getVaultDepositorAddressSync(
516
529
  this.program.programId,
517
530
  vault,
518
- authority
531
+ authority || this.driftClient.wallet.publicKey
519
532
  );
520
533
 
521
534
  const accounts = {
@@ -549,7 +562,7 @@ export class VaultClient {
549
562
  const vaultDepositor = getVaultDepositorAddressSync(
550
563
  this.program.programId,
551
564
  vault,
552
- authority
565
+ authority || this.driftClient.wallet.publicKey
553
566
  );
554
567
 
555
568
  const accounts = {
@@ -615,6 +628,11 @@ export class VaultClient {
615
628
  const spotMarket = this.driftClient.getSpotMarketAccount(
616
629
  vaultAccount.spotMarketIndex
617
630
  );
631
+ if (!spotMarket) {
632
+ throw new Error(
633
+ `Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`
634
+ );
635
+ }
618
636
 
619
637
  const accounts = {
620
638
  vault: vaultPubKey,
@@ -753,6 +771,11 @@ export class VaultClient {
753
771
  const spotMarket = this.driftClient.getSpotMarketAccount(
754
772
  vaultAccount.spotMarketIndex
755
773
  );
774
+ if (!spotMarket) {
775
+ throw new Error(
776
+ `Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`
777
+ );
778
+ }
756
779
 
757
780
  const accounts = {
758
781
  vault: vaultDepositorAccount.vault,
@@ -948,12 +971,18 @@ export class VaultClient {
948
971
  spotMarketIndex
949
972
  );
950
973
 
974
+ const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
975
+ if (!spotMarket) {
976
+ throw new Error(
977
+ `Spot market ${spotMarketIndex} not found on driftClient`
978
+ );
979
+ }
980
+
951
981
  return await this.program.methods
952
982
  .initializeInsuranceFundStake(spotMarketIndex)
953
983
  .accounts({
954
984
  vault: vault,
955
- driftSpotMarket:
956
- this.driftClient.getSpotMarketAccount(spotMarketIndex).pubkey,
985
+ driftSpotMarket: spotMarket.pubkey,
957
986
  insuranceFundStake: ifStakeAccountPublicKey,
958
987
  driftUserStats: vaultAccount.userStats,
959
988
  driftState: await this.driftClient.getStatePublicKey(),
package/tsconfig.json CHANGED
@@ -6,8 +6,14 @@
6
6
  "declaration": true,
7
7
  "outDir": "./lib",
8
8
  "resolveJsonModule": true,
9
- "skipLibCheck": true
9
+ "skipLibCheck": true,
10
+ "strict": true
10
11
  },
11
- "include": ["src"],
12
- "exclude": ["node_modules", "tests"]
13
- }
12
+ "include": [
13
+ "src"
14
+ ],
15
+ "exclude": [
16
+ "node_modules",
17
+ "tests"
18
+ ]
19
+ }