@voltr/vault-sdk 0.1.1 → 0.1.2
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/dist/client.d.ts +141 -23
- package/dist/client.js +153 -31
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +3 -2
- package/dist/idl/voltr_vault.json +759 -245
- package/dist/types/vault.d.ts +7 -0
- package/dist/types/voltr_vault.d.ts +759 -245
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Program, AnchorProvider, Idl, BN } from "@coral-xyz/anchor";
|
|
2
2
|
import { Connection, Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import { VaultParams, VoltrVault, InitializeStrategyArgs, DepositStrategyArgs, WithdrawStrategyArgs } from "./types";
|
|
3
|
+
import { VaultParams, VoltrVault, InitializeStrategyArgs, DepositStrategyArgs, WithdrawStrategyArgs, InitializeDirectWithdrawStrategyArgs, DirectWithdrawStrategyArgs } from "./types";
|
|
4
4
|
declare class AccountUtils {
|
|
5
5
|
conn: Connection;
|
|
6
6
|
constructor(conn: Connection);
|
|
@@ -53,17 +53,6 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
53
53
|
* @returns The PDA for the vault's asset idle authority
|
|
54
54
|
*/
|
|
55
55
|
findVaultAssetIdleAuth(vault: PublicKey): PublicKey;
|
|
56
|
-
/**
|
|
57
|
-
* Finds the vault's LP fee authority address
|
|
58
|
-
* @param vault - Public key of the vault
|
|
59
|
-
* @returns The PDA for the vault's LP fee authority
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const feeAuth = client.findVaultLpFeeAuth(vaultPubkey);
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
findVaultLpFeeAuth(vault: PublicKey): PublicKey;
|
|
67
56
|
/**
|
|
68
57
|
* Finds all vault-related addresses
|
|
69
58
|
* @param vault - Public key of the vault
|
|
@@ -80,7 +69,6 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
80
69
|
findVaultAddresses(vault: PublicKey): {
|
|
81
70
|
vaultLpMint: PublicKey;
|
|
82
71
|
vaultAssetIdleAuth: PublicKey;
|
|
83
|
-
vaultLpFeeAuth: PublicKey;
|
|
84
72
|
};
|
|
85
73
|
/**
|
|
86
74
|
* Finds the vault strategy auth address
|
|
@@ -106,6 +94,23 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
106
94
|
* ```
|
|
107
95
|
*/
|
|
108
96
|
findStrategyInitReceipt(vault: PublicKey, strategy: PublicKey): PublicKey;
|
|
97
|
+
/**
|
|
98
|
+
* Finds the direct withdraw init receipt address
|
|
99
|
+
* @param vault - Public key of the vault
|
|
100
|
+
* @param strategy - Public key of the strategy
|
|
101
|
+
* @returns The PDA for the direct withdraw init receipt
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const directWithdrawInitReceipt = client.findDirectWithdrawInitReceipt(vaultPubkey, strategyPubkey);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
findDirectWithdrawInitReceipt(vault: PublicKey, strategy: PublicKey): PublicKey;
|
|
109
|
+
findVaultStrategyAddresses(vault: PublicKey, strategy: PublicKey): {
|
|
110
|
+
vaultStrategyAuth: PublicKey;
|
|
111
|
+
strategyInitReceipt: PublicKey;
|
|
112
|
+
directWithdrawInitReceipt: PublicKey;
|
|
113
|
+
};
|
|
109
114
|
/**
|
|
110
115
|
* Creates an instruction to initialize a new vault
|
|
111
116
|
*
|
|
@@ -225,6 +230,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
225
230
|
* @param {Object} params - Parameters for adding adaptor to vault
|
|
226
231
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
227
232
|
* @param {PublicKey} params.payer - Public key of the payer
|
|
233
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
228
234
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
229
235
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for adding adaptor to vault
|
|
230
236
|
*
|
|
@@ -235,13 +241,15 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
235
241
|
* const ix = await client.createAddAdaptorIx({
|
|
236
242
|
* vault: vaultPubkey,
|
|
237
243
|
* payer: payerPubkey,
|
|
244
|
+
* admin: adminPubkey,
|
|
238
245
|
* adaptorProgram: adaptorProgramPubkey
|
|
239
246
|
* });
|
|
240
247
|
* ```
|
|
241
248
|
*/
|
|
242
|
-
createAddAdaptorIx({ vault, payer, adaptorProgram, }: {
|
|
249
|
+
createAddAdaptorIx({ vault, payer, admin, adaptorProgram, }: {
|
|
243
250
|
vault: PublicKey;
|
|
244
251
|
payer: PublicKey;
|
|
252
|
+
admin: PublicKey;
|
|
245
253
|
adaptorProgram?: PublicKey;
|
|
246
254
|
}): Promise<TransactionInstruction>;
|
|
247
255
|
/**
|
|
@@ -255,6 +263,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
255
263
|
* @param {PublicKey} params.manager - Public key of the manager
|
|
256
264
|
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
257
265
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
266
|
+
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
258
267
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing strategy to vault
|
|
259
268
|
* @throws {Error} If the instruction creation fails
|
|
260
269
|
*
|
|
@@ -270,26 +279,33 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
270
279
|
* vault: vaultPubkey,
|
|
271
280
|
* manager: managerPubkey,
|
|
272
281
|
* strategy: strategyPubkey,
|
|
273
|
-
* adaptorProgram: adaptorProgramPubkey
|
|
282
|
+
* adaptorProgram: adaptorProgramPubkey,
|
|
283
|
+
* remainingAccounts: []
|
|
274
284
|
* }
|
|
275
285
|
* );
|
|
276
286
|
* ```
|
|
277
287
|
*/
|
|
278
|
-
createInitializeStrategyIx({ instructionDiscriminator, additionalArgs, }: InitializeStrategyArgs, { payer, vault, manager, strategy, adaptorProgram, }: {
|
|
288
|
+
createInitializeStrategyIx({ instructionDiscriminator, additionalArgs, }: InitializeStrategyArgs, { payer, vault, manager, strategy, adaptorProgram, remainingAccounts, }: {
|
|
279
289
|
payer: PublicKey;
|
|
280
290
|
vault: PublicKey;
|
|
281
291
|
manager: PublicKey;
|
|
282
292
|
strategy: PublicKey;
|
|
283
293
|
adaptorProgram?: PublicKey;
|
|
294
|
+
remainingAccounts: Array<{
|
|
295
|
+
pubkey: PublicKey;
|
|
296
|
+
isSigner: boolean;
|
|
297
|
+
isWritable: boolean;
|
|
298
|
+
}>;
|
|
284
299
|
}): Promise<TransactionInstruction>;
|
|
285
300
|
/**
|
|
286
301
|
* Creates an instruction to deposit assets into a strategy
|
|
287
302
|
*
|
|
288
|
-
* @param {
|
|
303
|
+
* @param {DepositStrategyArgs} depositArgs - Deposit arguments
|
|
289
304
|
* @param {BN} depositArgs.depositAmount - Amount of assets to deposit
|
|
290
305
|
* @param {Buffer | null} [depositArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
291
306
|
* @param {Buffer | null} [depositArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
292
307
|
* @param {Object} params - Strategy deposit parameters
|
|
308
|
+
* @param {PublicKey} params.manager - Public key of the manager
|
|
293
309
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
294
310
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
295
311
|
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
@@ -308,6 +324,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
308
324
|
* additionalArgs: Buffer.from('...')
|
|
309
325
|
* },
|
|
310
326
|
* {
|
|
327
|
+
* manager: managerPubkey,
|
|
311
328
|
* vault: vaultPubkey,
|
|
312
329
|
* vaultAssetMint: mintPubkey,
|
|
313
330
|
* strategy: strategyPubkey,
|
|
@@ -318,7 +335,8 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
318
335
|
* );
|
|
319
336
|
* ```
|
|
320
337
|
*/
|
|
321
|
-
createDepositStrategyIx({ depositAmount, instructionDiscriminator, additionalArgs, }: DepositStrategyArgs, { vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }: {
|
|
338
|
+
createDepositStrategyIx({ depositAmount, instructionDiscriminator, additionalArgs, }: DepositStrategyArgs, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }: {
|
|
339
|
+
manager: PublicKey;
|
|
322
340
|
vault: PublicKey;
|
|
323
341
|
vaultAssetMint: PublicKey;
|
|
324
342
|
strategy: PublicKey;
|
|
@@ -333,7 +351,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
333
351
|
/**
|
|
334
352
|
* Creates an instruction to withdraw assets from a strategy
|
|
335
353
|
*
|
|
336
|
-
* @param {
|
|
354
|
+
* @param {WithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
337
355
|
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
338
356
|
* @param {Buffer | null} [withdrawArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
339
357
|
* @param {Buffer | null} [withdrawArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
@@ -366,7 +384,8 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
366
384
|
* );
|
|
367
385
|
* ```
|
|
368
386
|
*/
|
|
369
|
-
createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator, additionalArgs, }: WithdrawStrategyArgs, { vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }: {
|
|
387
|
+
createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator, additionalArgs, }: WithdrawStrategyArgs, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }: {
|
|
388
|
+
manager: PublicKey;
|
|
370
389
|
vault: PublicKey;
|
|
371
390
|
vaultAssetMint: PublicKey;
|
|
372
391
|
strategy: PublicKey;
|
|
@@ -382,22 +401,113 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
382
401
|
* Creates an instruction to remove a strategy from a vault
|
|
383
402
|
* @param {Object} params - Parameters for removing strategy
|
|
384
403
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
404
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
385
405
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
386
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing
|
|
406
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing adaptor from vault
|
|
387
407
|
* @throws {Error} If instruction creation fails
|
|
388
408
|
*
|
|
389
409
|
* @example
|
|
390
410
|
* ```typescript
|
|
391
|
-
* const ix = await client.
|
|
411
|
+
* const ix = await client.createRemoveAdaptorIx({
|
|
392
412
|
* vault: vaultPubkey,
|
|
413
|
+
* admin: adminPubkey,
|
|
393
414
|
* adaptorProgram: adaptorProgramPubkey
|
|
394
415
|
* });
|
|
395
416
|
* ```
|
|
396
417
|
*/
|
|
397
|
-
|
|
418
|
+
createRemoveAdaptorIx({ vault, admin, adaptorProgram, }: {
|
|
398
419
|
vault: PublicKey;
|
|
420
|
+
admin: PublicKey;
|
|
399
421
|
adaptorProgram?: PublicKey;
|
|
400
422
|
}): Promise<TransactionInstruction>;
|
|
423
|
+
/**
|
|
424
|
+
* Creates an instruction to initialize a direct withdraw strategy
|
|
425
|
+
* @param {InitializeDirectWithdrawStrategyArgs} initArgs - Arguments for initializing direct withdraw strategy
|
|
426
|
+
* @param {Buffer | null} initArgs.instructionDiscriminator - Optional discriminator for the instruction
|
|
427
|
+
* @param {Buffer | null} initArgs.additionalArgs - Optional additional arguments for the instruction
|
|
428
|
+
* @param {boolean} initArgs.allowUserArgs - Whether to allow user arguments
|
|
429
|
+
* @param {Object} params - Parameters for initializing direct withdraw strategy
|
|
430
|
+
* @param {PublicKey} params.payer - Public key of the payer
|
|
431
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
432
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
433
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
434
|
+
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
435
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing direct withdraw strategy
|
|
436
|
+
* @throws {Error} If instruction creation fails
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```typescript
|
|
440
|
+
* const ix = await client.createInitializeDirectWithdrawStrategyIx(
|
|
441
|
+
* {
|
|
442
|
+
* instructionDiscriminator: Buffer.from('...'),
|
|
443
|
+
* additionalArgs: Buffer.from('...'),
|
|
444
|
+
* allowUserArgs: true
|
|
445
|
+
* },
|
|
446
|
+
* {
|
|
447
|
+
* payer: payerPubkey,
|
|
448
|
+
* admin: adminPubkey,
|
|
449
|
+
* vault: vaultPubkey,
|
|
450
|
+
* strategy: strategyPubkey,
|
|
451
|
+
* adaptorProgram: adaptorProgramPubkey
|
|
452
|
+
* }
|
|
453
|
+
* );
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator, additionalArgs, allowUserArgs, }: InitializeDirectWithdrawStrategyArgs, { payer, admin, vault, strategy, adaptorProgram, }: {
|
|
457
|
+
payer: PublicKey;
|
|
458
|
+
admin: PublicKey;
|
|
459
|
+
vault: PublicKey;
|
|
460
|
+
strategy: PublicKey;
|
|
461
|
+
adaptorProgram?: PublicKey;
|
|
462
|
+
}): Promise<TransactionInstruction>;
|
|
463
|
+
/**
|
|
464
|
+
* Creates an instruction to withdraw assets from a direct withdraw strategy
|
|
465
|
+
* @param {DirectWithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
466
|
+
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
467
|
+
* @param {Buffer | null} [withdrawArgs.userArgs] - Optional user arguments for the instruction
|
|
468
|
+
* @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
|
|
469
|
+
* @param {PublicKey} params.user - Public key of the user
|
|
470
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
471
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
472
|
+
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
473
|
+
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
474
|
+
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
475
|
+
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
476
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from direct withdraw strategy
|
|
477
|
+
* @throws {Error} If instruction creation fails
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* const ix = await client.createDirectWithdrawStrategyIx(
|
|
482
|
+
* {
|
|
483
|
+
* withdrawAmount: new BN('1000000000'),
|
|
484
|
+
* userArgs: Buffer.from('...')
|
|
485
|
+
* },
|
|
486
|
+
* {
|
|
487
|
+
* user: userPubkey,
|
|
488
|
+
* vault: vaultPubkey,
|
|
489
|
+
* strategy: strategyPubkey,
|
|
490
|
+
* vaultAssetMint: mintPubkey,
|
|
491
|
+
* assetTokenProgram: tokenProgramPubkey,
|
|
492
|
+
* adaptorProgram: adaptorProgramPubkey,
|
|
493
|
+
* remainingAccounts: []
|
|
494
|
+
* }
|
|
495
|
+
* );
|
|
496
|
+
* ```
|
|
497
|
+
*/
|
|
498
|
+
createDirectWithdrawStrategyIx({ withdrawAmount, userArgs }: DirectWithdrawStrategyArgs, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }: {
|
|
499
|
+
user: PublicKey;
|
|
500
|
+
vault: PublicKey;
|
|
501
|
+
strategy: PublicKey;
|
|
502
|
+
vaultAssetMint: PublicKey;
|
|
503
|
+
assetTokenProgram: PublicKey;
|
|
504
|
+
adaptorProgram?: PublicKey;
|
|
505
|
+
remainingAccounts: Array<{
|
|
506
|
+
pubkey: PublicKey;
|
|
507
|
+
isSigner: boolean;
|
|
508
|
+
isWritable: boolean;
|
|
509
|
+
}>;
|
|
510
|
+
}): Promise<TransactionInstruction>;
|
|
401
511
|
/**
|
|
402
512
|
* Fetches all strategy init receipt accounts
|
|
403
513
|
* @returns Promise resolving to an array of strategy init receipt accounts
|
|
@@ -410,6 +520,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
410
520
|
fetchAllStrategyInitReceiptAccounts(): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
411
521
|
vault: PublicKey;
|
|
412
522
|
strategy: PublicKey;
|
|
523
|
+
adaptorProgram: PublicKey;
|
|
413
524
|
positionValue: BN;
|
|
414
525
|
lastUpdatedTs: BN;
|
|
415
526
|
version: number;
|
|
@@ -431,6 +542,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
431
542
|
fetchAllStrategyInitReceiptAccountsOfVault(vault: PublicKey): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
432
543
|
vault: PublicKey;
|
|
433
544
|
strategy: PublicKey;
|
|
545
|
+
adaptorProgram: PublicKey;
|
|
434
546
|
positionValue: BN;
|
|
435
547
|
lastUpdatedTs: BN;
|
|
436
548
|
version: number;
|
|
@@ -454,7 +566,9 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
454
566
|
adaptorProgram: PublicKey;
|
|
455
567
|
version: number;
|
|
456
568
|
bump: number;
|
|
569
|
+
isActive: boolean;
|
|
457
570
|
padding0: number[];
|
|
571
|
+
lastUpdatedEpoch: BN;
|
|
458
572
|
reserved: number[];
|
|
459
573
|
}>[]>;
|
|
460
574
|
getPositionAndTotalValuesForVault(vault: PublicKey): Promise<{
|
|
@@ -478,6 +592,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
478
592
|
admin: PublicKey;
|
|
479
593
|
vaultConfiguration: any;
|
|
480
594
|
feeConfiguration: any;
|
|
595
|
+
feeState: any;
|
|
481
596
|
lastUpdatedTs: BN;
|
|
482
597
|
version: number;
|
|
483
598
|
padding0: number[];
|
|
@@ -496,6 +611,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
496
611
|
fetchStrategyInitReceiptAccount(strategyInitReceipt: PublicKey): Promise<{
|
|
497
612
|
vault: PublicKey;
|
|
498
613
|
strategy: PublicKey;
|
|
614
|
+
adaptorProgram: PublicKey;
|
|
499
615
|
positionValue: BN;
|
|
500
616
|
lastUpdatedTs: BN;
|
|
501
617
|
version: number;
|
|
@@ -519,7 +635,9 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
519
635
|
adaptorProgram: PublicKey;
|
|
520
636
|
version: number;
|
|
521
637
|
bump: number;
|
|
638
|
+
isActive: boolean;
|
|
522
639
|
padding0: number[];
|
|
640
|
+
lastUpdatedEpoch: BN;
|
|
523
641
|
reserved: number[];
|
|
524
642
|
}>;
|
|
525
643
|
/**
|
package/dist/client.js
CHANGED
|
@@ -147,20 +147,6 @@ class VoltrClient extends AccountUtils {
|
|
|
147
147
|
const [vaultAssetIdleAuth] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_ASSET_IDLE_AUTH, vault.toBuffer()], this.vaultProgram.programId);
|
|
148
148
|
return vaultAssetIdleAuth;
|
|
149
149
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Finds the vault's LP fee authority address
|
|
152
|
-
* @param vault - Public key of the vault
|
|
153
|
-
* @returns The PDA for the vault's LP fee authority
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* const feeAuth = client.findVaultLpFeeAuth(vaultPubkey);
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
findVaultLpFeeAuth(vault) {
|
|
161
|
-
const [vaultLpFeeAuth] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_LP_FEE_AUTH, vault.toBuffer()], this.vaultProgram.programId);
|
|
162
|
-
return vaultLpFeeAuth;
|
|
163
|
-
}
|
|
164
150
|
/**
|
|
165
151
|
* Finds all vault-related addresses
|
|
166
152
|
* @param vault - Public key of the vault
|
|
@@ -177,11 +163,9 @@ class VoltrClient extends AccountUtils {
|
|
|
177
163
|
findVaultAddresses(vault) {
|
|
178
164
|
const vaultLpMint = this.findVaultLpMint(vault);
|
|
179
165
|
const vaultAssetIdleAuth = this.findVaultAssetIdleAuth(vault);
|
|
180
|
-
const vaultLpFeeAuth = this.findVaultLpFeeAuth(vault);
|
|
181
166
|
return {
|
|
182
167
|
vaultLpMint,
|
|
183
168
|
vaultAssetIdleAuth,
|
|
184
|
-
vaultLpFeeAuth,
|
|
185
169
|
};
|
|
186
170
|
}
|
|
187
171
|
/**
|
|
@@ -214,6 +198,35 @@ class VoltrClient extends AccountUtils {
|
|
|
214
198
|
const [strategyInitReceipt] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.STRATEGY_INIT_RECEIPT, vault.toBuffer(), strategy.toBuffer()], this.vaultProgram.programId);
|
|
215
199
|
return strategyInitReceipt;
|
|
216
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Finds the direct withdraw init receipt address
|
|
203
|
+
* @param vault - Public key of the vault
|
|
204
|
+
* @param strategy - Public key of the strategy
|
|
205
|
+
* @returns The PDA for the direct withdraw init receipt
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const directWithdrawInitReceipt = client.findDirectWithdrawInitReceipt(vaultPubkey, strategyPubkey);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
findDirectWithdrawInitReceipt(vault, strategy) {
|
|
213
|
+
const [directWithdrawInitReceipt] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
214
|
+
constants_1.SEEDS.DIRECT_WITHDRAW_INIT_RECEIPT_SEED,
|
|
215
|
+
vault.toBuffer(),
|
|
216
|
+
strategy.toBuffer(),
|
|
217
|
+
], this.vaultProgram.programId);
|
|
218
|
+
return directWithdrawInitReceipt;
|
|
219
|
+
}
|
|
220
|
+
findVaultStrategyAddresses(vault, strategy) {
|
|
221
|
+
const vaultStrategyAuth = this.findVaultStrategyAuth(vault, strategy);
|
|
222
|
+
const strategyInitReceipt = this.findStrategyInitReceipt(vault, strategy);
|
|
223
|
+
const directWithdrawInitReceipt = this.findDirectWithdrawInitReceipt(vault, strategy);
|
|
224
|
+
return {
|
|
225
|
+
vaultStrategyAuth,
|
|
226
|
+
strategyInitReceipt,
|
|
227
|
+
directWithdrawInitReceipt,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
217
230
|
// --------------------------------------- Vault Instructions
|
|
218
231
|
/**
|
|
219
232
|
* Creates an instruction to initialize a new vault
|
|
@@ -264,7 +277,6 @@ class VoltrClient extends AccountUtils {
|
|
|
264
277
|
async createInitializeVaultIx(vaultParams, { vault, vaultAssetMint, admin, manager, payer, }) {
|
|
265
278
|
const addresses = this.findVaultAddresses(vault.publicKey);
|
|
266
279
|
const vaultAssetIdleAta = (0, spl_token_1.getAssociatedTokenAddressSync)(vaultAssetMint, addresses.vaultAssetIdleAuth, true);
|
|
267
|
-
const vaultLpFeeAta = (0, spl_token_1.getAssociatedTokenAddressSync)(addresses.vaultLpMint, addresses.vaultLpFeeAuth, true);
|
|
268
280
|
return await this.vaultProgram.methods
|
|
269
281
|
.initialize(vaultParams.config, vaultParams.name, vaultParams.description)
|
|
270
282
|
.accounts({
|
|
@@ -274,7 +286,6 @@ class VoltrClient extends AccountUtils {
|
|
|
274
286
|
vault: vault.publicKey,
|
|
275
287
|
vaultAssetMint,
|
|
276
288
|
vaultAssetIdleAta,
|
|
277
|
-
vaultLpFeeAta,
|
|
278
289
|
assetTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
279
290
|
})
|
|
280
291
|
.instruction();
|
|
@@ -356,6 +367,7 @@ class VoltrClient extends AccountUtils {
|
|
|
356
367
|
* @param {Object} params - Parameters for adding adaptor to vault
|
|
357
368
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
358
369
|
* @param {PublicKey} params.payer - Public key of the payer
|
|
370
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
359
371
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
360
372
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for adding adaptor to vault
|
|
361
373
|
*
|
|
@@ -366,15 +378,17 @@ class VoltrClient extends AccountUtils {
|
|
|
366
378
|
* const ix = await client.createAddAdaptorIx({
|
|
367
379
|
* vault: vaultPubkey,
|
|
368
380
|
* payer: payerPubkey,
|
|
381
|
+
* admin: adminPubkey,
|
|
369
382
|
* adaptorProgram: adaptorProgramPubkey
|
|
370
383
|
* });
|
|
371
384
|
* ```
|
|
372
385
|
*/
|
|
373
|
-
async createAddAdaptorIx({ vault, payer, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
386
|
+
async createAddAdaptorIx({ vault, payer, admin, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
374
387
|
return await this.vaultProgram.methods
|
|
375
388
|
.addAdaptor()
|
|
376
|
-
.
|
|
389
|
+
.accountsPartial({
|
|
377
390
|
payer,
|
|
391
|
+
admin,
|
|
378
392
|
vault,
|
|
379
393
|
adaptorProgram,
|
|
380
394
|
})
|
|
@@ -391,6 +405,7 @@ class VoltrClient extends AccountUtils {
|
|
|
391
405
|
* @param {PublicKey} params.manager - Public key of the manager
|
|
392
406
|
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
393
407
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
408
|
+
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
394
409
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing strategy to vault
|
|
395
410
|
* @throws {Error} If the instruction creation fails
|
|
396
411
|
*
|
|
@@ -406,12 +421,13 @@ class VoltrClient extends AccountUtils {
|
|
|
406
421
|
* vault: vaultPubkey,
|
|
407
422
|
* manager: managerPubkey,
|
|
408
423
|
* strategy: strategyPubkey,
|
|
409
|
-
* adaptorProgram: adaptorProgramPubkey
|
|
424
|
+
* adaptorProgram: adaptorProgramPubkey,
|
|
425
|
+
* remainingAccounts: []
|
|
410
426
|
* }
|
|
411
427
|
* );
|
|
412
428
|
* ```
|
|
413
429
|
*/
|
|
414
|
-
async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
430
|
+
async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
415
431
|
return await this.vaultProgram.methods
|
|
416
432
|
.initializeStrategy(instructionDiscriminator ?? null, additionalArgs ?? null)
|
|
417
433
|
.accounts({
|
|
@@ -421,16 +437,18 @@ class VoltrClient extends AccountUtils {
|
|
|
421
437
|
strategy,
|
|
422
438
|
adaptorProgram,
|
|
423
439
|
})
|
|
440
|
+
.remainingAccounts(remainingAccounts)
|
|
424
441
|
.instruction();
|
|
425
442
|
}
|
|
426
443
|
/**
|
|
427
444
|
* Creates an instruction to deposit assets into a strategy
|
|
428
445
|
*
|
|
429
|
-
* @param {
|
|
446
|
+
* @param {DepositStrategyArgs} depositArgs - Deposit arguments
|
|
430
447
|
* @param {BN} depositArgs.depositAmount - Amount of assets to deposit
|
|
431
448
|
* @param {Buffer | null} [depositArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
432
449
|
* @param {Buffer | null} [depositArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
433
450
|
* @param {Object} params - Strategy deposit parameters
|
|
451
|
+
* @param {PublicKey} params.manager - Public key of the manager
|
|
434
452
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
435
453
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
436
454
|
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
@@ -449,6 +467,7 @@ class VoltrClient extends AccountUtils {
|
|
|
449
467
|
* additionalArgs: Buffer.from('...')
|
|
450
468
|
* },
|
|
451
469
|
* {
|
|
470
|
+
* manager: managerPubkey,
|
|
452
471
|
* vault: vaultPubkey,
|
|
453
472
|
* vaultAssetMint: mintPubkey,
|
|
454
473
|
* strategy: strategyPubkey,
|
|
@@ -459,10 +478,11 @@ class VoltrClient extends AccountUtils {
|
|
|
459
478
|
* );
|
|
460
479
|
* ```
|
|
461
480
|
*/
|
|
462
|
-
async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
481
|
+
async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
463
482
|
return await this.vaultProgram.methods
|
|
464
483
|
.depositStrategy(depositAmount, instructionDiscriminator, additionalArgs)
|
|
465
484
|
.accounts({
|
|
485
|
+
manager,
|
|
466
486
|
vault,
|
|
467
487
|
vaultAssetMint,
|
|
468
488
|
adaptorProgram,
|
|
@@ -475,7 +495,7 @@ class VoltrClient extends AccountUtils {
|
|
|
475
495
|
/**
|
|
476
496
|
* Creates an instruction to withdraw assets from a strategy
|
|
477
497
|
*
|
|
478
|
-
* @param {
|
|
498
|
+
* @param {WithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
479
499
|
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
480
500
|
* @param {Buffer | null} [withdrawArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
481
501
|
* @param {Buffer | null} [withdrawArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
@@ -508,10 +528,11 @@ class VoltrClient extends AccountUtils {
|
|
|
508
528
|
* );
|
|
509
529
|
* ```
|
|
510
530
|
*/
|
|
511
|
-
async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
531
|
+
async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
512
532
|
return await this.vaultProgram.methods
|
|
513
533
|
.withdrawStrategy(withdrawAmount, instructionDiscriminator, additionalArgs)
|
|
514
534
|
.accounts({
|
|
535
|
+
manager,
|
|
515
536
|
vault,
|
|
516
537
|
vaultAssetMint,
|
|
517
538
|
adaptorProgram,
|
|
@@ -525,25 +546,122 @@ class VoltrClient extends AccountUtils {
|
|
|
525
546
|
* Creates an instruction to remove a strategy from a vault
|
|
526
547
|
* @param {Object} params - Parameters for removing strategy
|
|
527
548
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
549
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
528
550
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
529
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing
|
|
551
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing adaptor from vault
|
|
530
552
|
* @throws {Error} If instruction creation fails
|
|
531
553
|
*
|
|
532
554
|
* @example
|
|
533
555
|
* ```typescript
|
|
534
|
-
* const ix = await client.
|
|
556
|
+
* const ix = await client.createRemoveAdaptorIx({
|
|
535
557
|
* vault: vaultPubkey,
|
|
558
|
+
* admin: adminPubkey,
|
|
536
559
|
* adaptorProgram: adaptorProgramPubkey
|
|
537
560
|
* });
|
|
538
561
|
* ```
|
|
539
562
|
*/
|
|
540
|
-
async
|
|
563
|
+
async createRemoveAdaptorIx({ vault, admin, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
541
564
|
return await this.vaultProgram.methods
|
|
542
565
|
.removeAdaptor()
|
|
543
|
-
.
|
|
566
|
+
.accountsPartial({
|
|
567
|
+
vault,
|
|
568
|
+
admin,
|
|
569
|
+
adaptorProgram,
|
|
570
|
+
})
|
|
571
|
+
.instruction();
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Creates an instruction to initialize a direct withdraw strategy
|
|
575
|
+
* @param {InitializeDirectWithdrawStrategyArgs} initArgs - Arguments for initializing direct withdraw strategy
|
|
576
|
+
* @param {Buffer | null} initArgs.instructionDiscriminator - Optional discriminator for the instruction
|
|
577
|
+
* @param {Buffer | null} initArgs.additionalArgs - Optional additional arguments for the instruction
|
|
578
|
+
* @param {boolean} initArgs.allowUserArgs - Whether to allow user arguments
|
|
579
|
+
* @param {Object} params - Parameters for initializing direct withdraw strategy
|
|
580
|
+
* @param {PublicKey} params.payer - Public key of the payer
|
|
581
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
582
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
583
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
584
|
+
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
585
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing direct withdraw strategy
|
|
586
|
+
* @throws {Error} If instruction creation fails
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```typescript
|
|
590
|
+
* const ix = await client.createInitializeDirectWithdrawStrategyIx(
|
|
591
|
+
* {
|
|
592
|
+
* instructionDiscriminator: Buffer.from('...'),
|
|
593
|
+
* additionalArgs: Buffer.from('...'),
|
|
594
|
+
* allowUserArgs: true
|
|
595
|
+
* },
|
|
596
|
+
* {
|
|
597
|
+
* payer: payerPubkey,
|
|
598
|
+
* admin: adminPubkey,
|
|
599
|
+
* vault: vaultPubkey,
|
|
600
|
+
* strategy: strategyPubkey,
|
|
601
|
+
* adaptorProgram: adaptorProgramPubkey
|
|
602
|
+
* }
|
|
603
|
+
* );
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
607
|
+
return await this.vaultProgram.methods
|
|
608
|
+
.initializeDirectWithdrawStrategy(instructionDiscriminator, additionalArgs, allowUserArgs)
|
|
609
|
+
.accountsPartial({
|
|
610
|
+
payer,
|
|
611
|
+
admin,
|
|
544
612
|
vault,
|
|
613
|
+
strategy,
|
|
614
|
+
adaptorProgram,
|
|
615
|
+
})
|
|
616
|
+
.instruction();
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Creates an instruction to withdraw assets from a direct withdraw strategy
|
|
620
|
+
* @param {DirectWithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
621
|
+
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
622
|
+
* @param {Buffer | null} [withdrawArgs.userArgs] - Optional user arguments for the instruction
|
|
623
|
+
* @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
|
|
624
|
+
* @param {PublicKey} params.user - Public key of the user
|
|
625
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
626
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
627
|
+
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
628
|
+
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
629
|
+
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
630
|
+
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
631
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from direct withdraw strategy
|
|
632
|
+
* @throws {Error} If instruction creation fails
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* ```typescript
|
|
636
|
+
* const ix = await client.createDirectWithdrawStrategyIx(
|
|
637
|
+
* {
|
|
638
|
+
* withdrawAmount: new BN('1000000000'),
|
|
639
|
+
* userArgs: Buffer.from('...')
|
|
640
|
+
* },
|
|
641
|
+
* {
|
|
642
|
+
* user: userPubkey,
|
|
643
|
+
* vault: vaultPubkey,
|
|
644
|
+
* strategy: strategyPubkey,
|
|
645
|
+
* vaultAssetMint: mintPubkey,
|
|
646
|
+
* assetTokenProgram: tokenProgramPubkey,
|
|
647
|
+
* adaptorProgram: adaptorProgramPubkey,
|
|
648
|
+
* remainingAccounts: []
|
|
649
|
+
* }
|
|
650
|
+
* );
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
async createDirectWithdrawStrategyIx({ withdrawAmount, userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
654
|
+
return await this.vaultProgram.methods
|
|
655
|
+
.directWithdrawStrategy(withdrawAmount, userArgs)
|
|
656
|
+
.accounts({
|
|
657
|
+
userTransferAuthority: user,
|
|
658
|
+
strategy,
|
|
545
659
|
adaptorProgram,
|
|
660
|
+
vault,
|
|
661
|
+
vaultAssetMint,
|
|
662
|
+
assetTokenProgram,
|
|
546
663
|
})
|
|
664
|
+
.remainingAccounts(remainingAccounts)
|
|
547
665
|
.instruction();
|
|
548
666
|
}
|
|
549
667
|
// --------------------------------------- Account Fetching All
|
|
@@ -677,9 +795,13 @@ class VoltrClient extends AccountUtils {
|
|
|
677
795
|
throw new Error("Invalid LP supply");
|
|
678
796
|
if (totalValue <= new anchor_1.BN(0))
|
|
679
797
|
throw new Error("Invalid total assets");
|
|
798
|
+
const amountPreRedemption = lpAmount.mul(totalValue).div(lpSupply);
|
|
799
|
+
const amount = amountPreRedemption
|
|
800
|
+
.mul(new anchor_1.BN(10000 - constants_1.REDEMPTION_FEE_PERCENTAGE_BPS))
|
|
801
|
+
.div(new anchor_1.BN(10000));
|
|
680
802
|
// Calculate: (lpAmount * totalValue) / totalLpSupply
|
|
681
803
|
try {
|
|
682
|
-
return
|
|
804
|
+
return amount;
|
|
683
805
|
}
|
|
684
806
|
catch (e) {
|
|
685
807
|
throw new Error("Math overflow in asset calculation");
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
export declare const VAULT_PROGRAM_ID: PublicKey;
|
|
3
3
|
export declare const DEFAULT_ADAPTOR_PROGRAM_ID: PublicKey;
|
|
4
|
+
export declare const REDEMPTION_FEE_PERCENTAGE_BPS = 10;
|
|
4
5
|
export declare const SEEDS: {
|
|
5
6
|
VAULT_LP_MINT: Buffer<ArrayBuffer>;
|
|
6
|
-
VAULT_LP_FEE_AUTH: Buffer<ArrayBuffer>;
|
|
7
7
|
VAULT_ASSET_IDLE_AUTH: Buffer<ArrayBuffer>;
|
|
8
8
|
STRATEGY: Buffer<ArrayBuffer>;
|
|
9
9
|
STRATEGY_INIT_RECEIPT: Buffer<ArrayBuffer>;
|
|
10
10
|
VAULT_STRATEGY_AUTH: Buffer<ArrayBuffer>;
|
|
11
|
+
DIRECT_WITHDRAW_INIT_RECEIPT_SEED: Buffer<ArrayBuffer>;
|
|
11
12
|
};
|