@drift-labs/vaults-sdk 0.1.531 → 0.1.532

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.
@@ -315,6 +315,177 @@ exports.IDL = {
315
315
  ],
316
316
  args: [],
317
317
  },
318
+ {
319
+ name: 'initializeTokenizedVaultDepositor',
320
+ accounts: [
321
+ {
322
+ name: 'vault',
323
+ isMut: false,
324
+ isSigner: false,
325
+ },
326
+ {
327
+ name: 'vaultDepositor',
328
+ isMut: true,
329
+ isSigner: false,
330
+ },
331
+ {
332
+ name: 'mintAccount',
333
+ isMut: true,
334
+ isSigner: false,
335
+ },
336
+ {
337
+ name: 'metadataAccount',
338
+ isMut: true,
339
+ isSigner: false,
340
+ },
341
+ {
342
+ name: 'payer',
343
+ isMut: true,
344
+ isSigner: true,
345
+ },
346
+ {
347
+ name: 'tokenProgram',
348
+ isMut: false,
349
+ isSigner: false,
350
+ },
351
+ {
352
+ name: 'tokenMetadataProgram',
353
+ isMut: false,
354
+ isSigner: false,
355
+ },
356
+ {
357
+ name: 'rent',
358
+ isMut: false,
359
+ isSigner: false,
360
+ },
361
+ {
362
+ name: 'systemProgram',
363
+ isMut: false,
364
+ isSigner: false,
365
+ },
366
+ ],
367
+ args: [
368
+ {
369
+ name: 'params',
370
+ type: {
371
+ defined: 'InitializeTokenizedVaultDepositorParams',
372
+ },
373
+ },
374
+ ],
375
+ },
376
+ {
377
+ name: 'tokenizeShares',
378
+ accounts: [
379
+ {
380
+ name: 'vault',
381
+ isMut: true,
382
+ isSigner: false,
383
+ },
384
+ {
385
+ name: 'vaultDepositor',
386
+ isMut: true,
387
+ isSigner: false,
388
+ },
389
+ {
390
+ name: 'authority',
391
+ isMut: false,
392
+ isSigner: true,
393
+ },
394
+ {
395
+ name: 'tokenizedVaultDepositor',
396
+ isMut: true,
397
+ isSigner: false,
398
+ },
399
+ {
400
+ name: 'mint',
401
+ isMut: true,
402
+ isSigner: false,
403
+ },
404
+ {
405
+ name: 'userTokenAccount',
406
+ isMut: false,
407
+ isSigner: false,
408
+ },
409
+ {
410
+ name: 'driftUser',
411
+ isMut: true,
412
+ isSigner: false,
413
+ },
414
+ {
415
+ name: 'tokenProgram',
416
+ isMut: false,
417
+ isSigner: false,
418
+ },
419
+ ],
420
+ args: [
421
+ {
422
+ name: 'amount',
423
+ type: 'u64',
424
+ },
425
+ {
426
+ name: 'unit',
427
+ type: {
428
+ defined: 'WithdrawUnit',
429
+ },
430
+ },
431
+ ],
432
+ },
433
+ {
434
+ name: 'redeemTokens',
435
+ accounts: [
436
+ {
437
+ name: 'vault',
438
+ isMut: true,
439
+ isSigner: false,
440
+ },
441
+ {
442
+ name: 'vaultDepositor',
443
+ isMut: true,
444
+ isSigner: false,
445
+ },
446
+ {
447
+ name: 'authority',
448
+ isMut: false,
449
+ isSigner: true,
450
+ },
451
+ {
452
+ name: 'tokenizedVaultDepositor',
453
+ isMut: true,
454
+ isSigner: false,
455
+ },
456
+ {
457
+ name: 'mint',
458
+ isMut: true,
459
+ isSigner: false,
460
+ },
461
+ {
462
+ name: 'userTokenAccount',
463
+ isMut: true,
464
+ isSigner: false,
465
+ },
466
+ {
467
+ name: 'vaultTokenAccount',
468
+ isMut: true,
469
+ isSigner: false,
470
+ },
471
+ {
472
+ name: 'driftUser',
473
+ isMut: true,
474
+ isSigner: false,
475
+ },
476
+ {
477
+ name: 'tokenProgram',
478
+ isMut: false,
479
+ isSigner: false,
480
+ },
481
+ ],
482
+ args: [
483
+ {
484
+ name: 'tokensToBurn',
485
+ type: 'u64',
486
+ },
487
+ ],
488
+ },
318
489
  {
319
490
  name: 'deposit',
320
491
  accounts: [
@@ -838,6 +1009,48 @@ exports.IDL = {
838
1009
  ],
839
1010
  args: [],
840
1011
  },
1012
+ {
1013
+ name: 'applyRebase',
1014
+ accounts: [
1015
+ {
1016
+ name: 'vault',
1017
+ isMut: true,
1018
+ isSigner: false,
1019
+ },
1020
+ {
1021
+ name: 'vaultDepositor',
1022
+ isMut: true,
1023
+ isSigner: false,
1024
+ },
1025
+ {
1026
+ name: 'driftUser',
1027
+ isMut: true,
1028
+ isSigner: false,
1029
+ },
1030
+ ],
1031
+ args: [],
1032
+ },
1033
+ {
1034
+ name: 'applyRebaseTokenizedDepositor',
1035
+ accounts: [
1036
+ {
1037
+ name: 'vault',
1038
+ isMut: true,
1039
+ isSigner: false,
1040
+ },
1041
+ {
1042
+ name: 'tokenizedVaultDepositor',
1043
+ isMut: true,
1044
+ isSigner: false,
1045
+ },
1046
+ {
1047
+ name: 'driftUser',
1048
+ isMut: true,
1049
+ isSigner: false,
1050
+ },
1051
+ ],
1052
+ args: [],
1053
+ },
841
1054
  {
842
1055
  name: 'forceWithdraw',
843
1056
  accounts: [
@@ -965,57 +1178,6 @@ exports.IDL = {
965
1178
  },
966
1179
  ],
967
1180
  },
968
- {
969
- name: 'initializeCompetitor',
970
- accounts: [
971
- {
972
- name: 'vault',
973
- isMut: true,
974
- isSigner: false,
975
- },
976
- {
977
- name: 'manager',
978
- isMut: false,
979
- isSigner: true,
980
- },
981
- {
982
- name: 'payer',
983
- isMut: true,
984
- isSigner: true,
985
- },
986
- {
987
- name: 'rent',
988
- isMut: false,
989
- isSigner: false,
990
- },
991
- {
992
- name: 'systemProgram',
993
- isMut: false,
994
- isSigner: false,
995
- },
996
- {
997
- name: 'competitor',
998
- isMut: true,
999
- isSigner: false,
1000
- },
1001
- {
1002
- name: 'driftCompetitions',
1003
- isMut: true,
1004
- isSigner: false,
1005
- },
1006
- {
1007
- name: 'driftUserStats',
1008
- isMut: true,
1009
- isSigner: false,
1010
- },
1011
- {
1012
- name: 'driftCompetitionsProgram',
1013
- isMut: false,
1014
- isSigner: false,
1015
- },
1016
- ],
1017
- args: [],
1018
- },
1019
1181
  {
1020
1182
  name: 'protocolRequestWithdraw',
1021
1183
  accounts: [
@@ -1167,6 +1329,105 @@ exports.IDL = {
1167
1329
  },
1168
1330
  ],
1169
1331
  accounts: [
1332
+ {
1333
+ name: 'tokenizedVaultDepositor',
1334
+ type: {
1335
+ kind: 'struct',
1336
+ fields: [
1337
+ {
1338
+ name: 'vault',
1339
+ docs: ['The vault deposited into'],
1340
+ type: 'publicKey',
1341
+ },
1342
+ {
1343
+ name: 'pubkey',
1344
+ docs: [
1345
+ "The vault depositor account's pubkey. It is a pda of vault",
1346
+ ],
1347
+ type: 'publicKey',
1348
+ },
1349
+ {
1350
+ name: 'mint',
1351
+ docs: [
1352
+ 'The token mint for tokenized shares owned by this VaultDepositor',
1353
+ ],
1354
+ type: 'publicKey',
1355
+ },
1356
+ {
1357
+ name: 'vaultShares',
1358
+ docs: [
1359
+ "share of vault owned by this depositor. vault_shares / vault.total_shares is depositor's ownership of vault_equity",
1360
+ ],
1361
+ type: 'u128',
1362
+ },
1363
+ {
1364
+ name: 'lastVaultShares',
1365
+ docs: [
1366
+ 'stores the vault_shares from the most recent liquidity event (redeem or issuance) before a spl token',
1367
+ 'CPI is done, used to track invariants',
1368
+ ],
1369
+ type: 'u128',
1370
+ },
1371
+ {
1372
+ name: 'lastValidTs',
1373
+ docs: ['creation ts of vault depositor'],
1374
+ type: 'i64',
1375
+ },
1376
+ {
1377
+ name: 'netDeposits',
1378
+ docs: ['lifetime net deposits of vault depositor for the vault'],
1379
+ type: 'i64',
1380
+ },
1381
+ {
1382
+ name: 'totalDeposits',
1383
+ docs: ['lifetime total deposits'],
1384
+ type: 'u64',
1385
+ },
1386
+ {
1387
+ name: 'totalWithdraws',
1388
+ docs: ['lifetime total withdraws'],
1389
+ type: 'u64',
1390
+ },
1391
+ {
1392
+ name: 'cumulativeProfitShareAmount',
1393
+ docs: [
1394
+ 'the token amount of gains the vault depositor has paid performance fees on',
1395
+ ],
1396
+ type: 'i64',
1397
+ },
1398
+ {
1399
+ name: 'profitShareFeePaid',
1400
+ type: 'u64',
1401
+ },
1402
+ {
1403
+ name: 'vaultSharesBase',
1404
+ docs: [
1405
+ 'The exponent for vault_shares decimal places at the time the tokenized vault depositor was initialized.',
1406
+ 'If the vault undergoes a rebase, this TokenizedVaultDepositor can no longer issue new tokens, only redeem',
1407
+ 'is possible.',
1408
+ ],
1409
+ type: 'u32',
1410
+ },
1411
+ {
1412
+ name: 'bump',
1413
+ docs: ['The bump for the vault pda'],
1414
+ type: 'u8',
1415
+ },
1416
+ {
1417
+ name: 'padding1',
1418
+ type: {
1419
+ array: ['u8', 3],
1420
+ },
1421
+ },
1422
+ {
1423
+ name: 'padding',
1424
+ type: {
1425
+ array: ['u64', 10],
1426
+ },
1427
+ },
1428
+ ],
1429
+ },
1430
+ },
1170
1431
  {
1171
1432
  name: 'vaultDepositor',
1172
1433
  type: {
@@ -1557,6 +1818,30 @@ exports.IDL = {
1557
1818
  },
1558
1819
  ],
1559
1820
  types: [
1821
+ {
1822
+ name: 'InitializeTokenizedVaultDepositorParams',
1823
+ type: {
1824
+ kind: 'struct',
1825
+ fields: [
1826
+ {
1827
+ name: 'tokenName',
1828
+ type: 'string',
1829
+ },
1830
+ {
1831
+ name: 'tokenSymbol',
1832
+ type: 'string',
1833
+ },
1834
+ {
1835
+ name: 'tokenUri',
1836
+ type: 'string',
1837
+ },
1838
+ {
1839
+ name: 'decimals',
1840
+ type: 'u8',
1841
+ },
1842
+ ],
1843
+ },
1844
+ },
1560
1845
  {
1561
1846
  name: 'VaultWithProtocolParams',
1562
1847
  type: {
@@ -1790,6 +2075,12 @@ exports.IDL = {
1790
2075
  {
1791
2076
  name: 'FeePayment',
1792
2077
  },
2078
+ {
2079
+ name: 'TokenizeShares',
2080
+ },
2081
+ {
2082
+ name: 'RedeemTokens',
2083
+ },
1793
2084
  ],
1794
2085
  },
1795
2086
  },
@@ -2031,6 +2322,61 @@ exports.IDL = {
2031
2322
  },
2032
2323
  ],
2033
2324
  },
2325
+ {
2326
+ name: 'ShareTransferRecord',
2327
+ fields: [
2328
+ {
2329
+ name: 'ts',
2330
+ type: 'i64',
2331
+ index: false,
2332
+ },
2333
+ {
2334
+ name: 'vault',
2335
+ type: 'publicKey',
2336
+ index: false,
2337
+ },
2338
+ {
2339
+ name: 'fromVaultDepositor',
2340
+ type: 'publicKey',
2341
+ index: false,
2342
+ },
2343
+ {
2344
+ name: 'toVaultDepositor',
2345
+ type: 'publicKey',
2346
+ index: false,
2347
+ },
2348
+ {
2349
+ name: 'shares',
2350
+ type: 'u128',
2351
+ index: false,
2352
+ },
2353
+ {
2354
+ name: 'value',
2355
+ type: 'u64',
2356
+ index: false,
2357
+ },
2358
+ {
2359
+ name: 'fromDepositorSharesBefore',
2360
+ type: 'u128',
2361
+ index: false,
2362
+ },
2363
+ {
2364
+ name: 'fromDepositorSharesAfter',
2365
+ type: 'u128',
2366
+ index: false,
2367
+ },
2368
+ {
2369
+ name: 'toDepositorSharesBefore',
2370
+ type: 'u128',
2371
+ index: false,
2372
+ },
2373
+ {
2374
+ name: 'toDepositorSharesAfter',
2375
+ type: 'u128',
2376
+ index: false,
2377
+ },
2378
+ ],
2379
+ },
2034
2380
  ],
2035
2381
  errors: [
2036
2382
  {
@@ -2148,5 +2494,10 @@ exports.IDL = {
2148
2494
  name: 'VaultProtocolMissing',
2149
2495
  msg: 'VaultProtocolMissing',
2150
2496
  },
2497
+ {
2498
+ code: 6023,
2499
+ name: 'InvalidTokenization',
2500
+ msg: 'InvalidTokenization',
2501
+ },
2151
2502
  ],
2152
2503
  };
package/lib/utils.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { DriftClient, IWallet } from '@drift-labs/sdk';
2
- import { Connection } from '@solana/web3.js';
2
+ import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
3
3
  import { DriftVaults } from './types/drift_vaults';
4
4
  import { VaultClient } from './vaultClient';
5
5
  import * as anchor from '@coral-xyz/anchor';
6
6
  export declare const getDriftVaultProgram: (connection: Connection, wallet: IWallet) => anchor.Program<DriftVaults>;
7
7
  export declare const getVaultClient: (connection: Connection, wallet: IWallet, driftClient: DriftClient) => VaultClient;
8
+ export declare const getOrCreateATAInstruction: (tokenMint: PublicKey, owner: PublicKey, connection: Connection, allowOwnerOffCurve?: boolean, payer?: PublicKey) => Promise<[PublicKey, TransactionInstruction?]>;
package/lib/utils.js CHANGED
@@ -23,12 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getVaultClient = exports.getDriftVaultProgram = void 0;
26
+ exports.getOrCreateATAInstruction = exports.getVaultClient = exports.getDriftVaultProgram = void 0;
27
27
  const anchor_1 = require("@coral-xyz/anchor");
28
28
  const drift_vaults_1 = require("./types/drift_vaults");
29
29
  const vaultClient_1 = require("./vaultClient");
30
30
  const anchor = __importStar(require("@coral-xyz/anchor"));
31
31
  const types_1 = require("./types/types");
32
+ const spl_token_1 = require("@solana/spl-token");
32
33
  const getDriftVaultProgram = (connection, wallet) => {
33
34
  const provider = new anchor_1.AnchorProvider(connection, wallet, {});
34
35
  anchor.setProvider(provider);
@@ -45,3 +46,21 @@ const getVaultClient = (connection, wallet, driftClient) => {
45
46
  return vaultClient;
46
47
  };
47
48
  exports.getVaultClient = getVaultClient;
49
+ const getOrCreateATAInstruction = async (tokenMint, owner, connection, allowOwnerOffCurve = true, payer = owner) => {
50
+ let toAccount;
51
+ try {
52
+ toAccount = await (0, spl_token_1.getAssociatedTokenAddress)(tokenMint, owner, allowOwnerOffCurve);
53
+ const account = await connection.getAccountInfo(toAccount);
54
+ if (!account) {
55
+ const ix = (0, spl_token_1.createAssociatedTokenAccountInstruction)(payer, toAccount, owner, tokenMint);
56
+ return [toAccount, ix];
57
+ }
58
+ return [toAccount, undefined];
59
+ }
60
+ catch (e) {
61
+ /* handle error */
62
+ console.error('Error::getOrCreateATAInstruction', e);
63
+ throw e;
64
+ }
65
+ };
66
+ exports.getOrCreateATAInstruction = getOrCreateATAInstruction;
@@ -1,10 +1,10 @@
1
1
  import { BN, DriftClient, UserMap } from '@drift-labs/sdk';
2
2
  import { Program, ProgramAccount } from '@coral-xyz/anchor';
3
3
  import { DriftVaults } from './types/drift_vaults';
4
- import { CompetitionsClient } from '@drift-labs/competitions-sdk';
5
4
  import { AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
6
5
  import { Vault, VaultDepositor, VaultProtocol, VaultProtocolParams, WithdrawUnit } from './types/types';
7
6
  import { UserMapConfig } from '@drift-labs/sdk';
7
+ import { Metaplex } from '@metaplex-foundation/js';
8
8
  export type TxParams = {
9
9
  cuLimit?: number;
10
10
  cuPriceMicroLamports?: number;
@@ -13,15 +13,17 @@ export type TxParams = {
13
13
  };
14
14
  export declare class VaultClient {
15
15
  driftClient: DriftClient;
16
+ metaplex?: Metaplex;
16
17
  program: Program<DriftVaults>;
17
18
  cliMode: boolean;
18
19
  /**
19
20
  * Cache map of drift user accounts of vaults.
20
21
  */
21
22
  readonly vaultUsers: UserMap;
22
- constructor({ driftClient, program, cliMode, userMapConfig, }: {
23
+ constructor({ driftClient, program, metaplex, cliMode, userMapConfig, }: {
23
24
  driftClient: DriftClient;
24
25
  program: Program<DriftVaults>;
26
+ metaplex?: Metaplex;
25
27
  cliMode?: boolean;
26
28
  userMapConfig?: UserMapConfig;
27
29
  });
@@ -136,6 +138,10 @@ export declare class VaultClient {
136
138
  permissioned: boolean | null;
137
139
  }): Promise<TransactionSignature>;
138
140
  getApplyProfitShareIx(vault: PublicKey, vaultDepositor: PublicKey): Promise<TransactionInstruction>;
141
+ getApplyRebaseTokenizedDepositorIx(vault: PublicKey, tokenizedVaultDepositor: PublicKey): Promise<TransactionInstruction>;
142
+ applyRebase(vault: PublicKey, vaultDepositor: PublicKey): Promise<TransactionSignature>;
143
+ getApplyRebaseIx(vault: PublicKey, vaultDepositor: PublicKey): Promise<TransactionInstruction>;
144
+ applyRebaseTokenizedDepositor(vault: PublicKey, tokenizedVaultDepositor: PublicKey): Promise<TransactionSignature>;
139
145
  private createInitVaultDepositorIx;
140
146
  /**
141
147
  * Initializes the vault depositor account. This account is used to deposit funds into a vault.
@@ -144,10 +150,30 @@ export declare class VaultClient {
144
150
  * @returns
145
151
  */
146
152
  initializeVaultDepositor(vault: PublicKey, authority?: PublicKey): Promise<TransactionSignature>;
153
+ initializeTokenizedVaultDepositor(params: {
154
+ vault: PublicKey;
155
+ tokenName: string;
156
+ tokenSymbol: string;
157
+ tokenUri: string;
158
+ decimals?: number;
159
+ sharesBase?: number;
160
+ }): Promise<TransactionSignature>;
161
+ createTokenizeSharesIx(vaultDepositor: PublicKey, amount: BN, unit: WithdrawUnit, mint?: PublicKey): Promise<TransactionInstruction[]>;
162
+ tokenizeShares(vaultDepositor: PublicKey, amount: BN, unit: WithdrawUnit, mint?: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
163
+ createRedeemTokensIx(vaultDepositor: PublicKey, tokensToBurn: BN, sharesBase?: number): Promise<TransactionInstruction>;
164
+ /**
165
+ * Redeems tokens from the vault.
166
+ * @param vaultDepositor
167
+ * @param tokensToBurn
168
+ * @param mint optionally provide a mint, or infer the mint from the current vault share base
169
+ * @param txParams
170
+ * @returns
171
+ */
172
+ redeemTokens(vaultDepositor: PublicKey, tokensToBurn: BN, sharesBase?: number, txParams?: TxParams): Promise<TransactionSignature>;
147
173
  prepDepositTx(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
148
174
  authority: PublicKey;
149
175
  vault: PublicKey;
150
- }): Promise<{
176
+ }, userTokenAccount?: PublicKey): Promise<{
151
177
  vaultAccount: {
152
178
  name: number[];
153
179
  pubkey: PublicKey;
@@ -228,10 +254,11 @@ export declare class VaultClient {
228
254
  deposit(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
229
255
  authority: PublicKey;
230
256
  vault: PublicKey;
231
- }, txParams?: TxParams): Promise<TransactionSignature>;
257
+ }, txParams?: TxParams, userTokenAccount?: PublicKey): Promise<TransactionSignature>;
232
258
  requestWithdraw(vaultDepositor: PublicKey, amount: BN, withdrawUnit: WithdrawUnit, txParams?: TxParams): Promise<TransactionSignature>;
233
259
  withdraw(vaultDepositor: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
234
260
  forceWithdraw(vaultDepositor: PublicKey): Promise<TransactionSignature>;
261
+ getForceWithdrawIx(vaultDepositor: PublicKey): Promise<TransactionInstruction[]>;
235
262
  cancelRequestWithdraw(vaultDepositor: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
236
263
  /**
237
264
  * Liquidates (become delegate for) a vault.
@@ -253,13 +280,6 @@ export declare class VaultClient {
253
280
  * @returns
254
281
  */
255
282
  initializeInsuranceFundStake(vault: PublicKey, spotMarketIndex: number): Promise<TransactionSignature>;
256
- /**
257
- * Initializes a DriftCompetitions Competitor account for the vault.
258
- * @param vault vault address to initialize Competitor for
259
- * @param competitionName name of the competition to initialize for
260
- * @returns
261
- */
262
- initializeCompetitor(vault: PublicKey, competitionsClient: CompetitionsClient, competitionName: string): Promise<TransactionSignature>;
263
283
  protocolRequestWithdraw(vault: PublicKey, amount: BN, withdrawUnit: WithdrawUnit): Promise<TransactionSignature>;
264
284
  protocolCancelWithdrawRequest(vault: PublicKey): Promise<TransactionSignature>;
265
285
  protocolWithdraw(vault: PublicKey): Promise<TransactionSignature>;