@voltr/vault-sdk 0.1.1 → 0.1.3
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/README.md +85 -65
- package/dist/client.d.ts +180 -29
- package/dist/client.js +200 -40
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +3 -2
- package/dist/idl/voltr_vault.json +1247 -673
- package/dist/types/vault.d.ts +7 -0
- package/dist/types/voltr_vault.d.ts +1232 -658
- package/package.json +1 -1
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,9 +277,8 @@ 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
|
+
.initializeVault(vaultParams.config, vaultParams.name, vaultParams.description)
|
|
270
282
|
.accounts({
|
|
271
283
|
payer,
|
|
272
284
|
admin,
|
|
@@ -274,13 +286,50 @@ 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();
|
|
281
292
|
}
|
|
282
293
|
/**
|
|
283
|
-
* Creates a
|
|
294
|
+
* Creates an instruction to update a vault
|
|
295
|
+
* @param {VaultConfig} vaultConfig - Configuration parameters for the vault
|
|
296
|
+
* @param {BN} vaultConfig.maxCap - Maximum capacity of the vault
|
|
297
|
+
* @param {BN} vaultConfig.startAtTs - Vault start timestamp in seconds
|
|
298
|
+
* @param {number} vaultConfig.managerManagementFee - Manager's management fee in basis points (e.g., 50 = 0.5%)
|
|
299
|
+
* @param {number} vaultConfig.managerPerformanceFee - Manager's performance fee in basis points (e.g., 1000 = 10%)
|
|
300
|
+
* @param {number} vaultConfig.adminManagementFee - Admin's management fee in basis points (e.g., 50 = 0.5%)
|
|
301
|
+
* @param {number} vaultConfig.adminPerformanceFee - Admin's performance fee in basis points (e.g., 1000 = 10%)
|
|
302
|
+
* @param {Object} params - Parameters for updating the vault
|
|
303
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
304
|
+
* @param {PublicKey} params.admin - Public key of the vault admin
|
|
305
|
+
* @returns Transaction instruction for updating the vault
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const ix = await client.createUpdateVaultIx(
|
|
310
|
+
* {
|
|
311
|
+
* maxCap: new BN('1000000000'),
|
|
312
|
+
* startAtTs: new BN(Math.floor(Date.now() / 1000)),
|
|
313
|
+
* managerManagementFee: 50,
|
|
314
|
+
* managerPerformanceFee: 1000,
|
|
315
|
+
* adminManagementFee: 50,
|
|
316
|
+
* adminPerformanceFee: 1000,
|
|
317
|
+
* },
|
|
318
|
+
* { vault: vaultPubkey, admin: adminPubkey }
|
|
319
|
+
* );
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
async createUpdateVaultIx(vaultConfig, { vault, admin, }) {
|
|
323
|
+
return await this.vaultProgram.methods
|
|
324
|
+
.updateVault(vaultConfig)
|
|
325
|
+
.accountsPartial({
|
|
326
|
+
admin,
|
|
327
|
+
vault,
|
|
328
|
+
})
|
|
329
|
+
.instruction();
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Creates a deposit instruction for a vault
|
|
284
333
|
*
|
|
285
334
|
* @param {BN} amount - Amount of tokens to deposit
|
|
286
335
|
* @param {Object} params - Deposit parameters
|
|
@@ -293,7 +342,7 @@ class VoltrClient extends AccountUtils {
|
|
|
293
342
|
*
|
|
294
343
|
* @example
|
|
295
344
|
* ```typescript
|
|
296
|
-
* const ix = await client.
|
|
345
|
+
* const ix = await client.createDepositVaultIx(
|
|
297
346
|
* new BN('1000000000'),
|
|
298
347
|
* {
|
|
299
348
|
* userAuthority: userPubkey,
|
|
@@ -304,9 +353,9 @@ class VoltrClient extends AccountUtils {
|
|
|
304
353
|
* );
|
|
305
354
|
* ```
|
|
306
355
|
*/
|
|
307
|
-
async
|
|
356
|
+
async createDepositVaultIx(amount, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
308
357
|
return await this.vaultProgram.methods
|
|
309
|
-
.
|
|
358
|
+
.depositVault(amount)
|
|
310
359
|
.accounts({
|
|
311
360
|
userTransferAuthority: userAuthority,
|
|
312
361
|
vault,
|
|
@@ -316,7 +365,7 @@ class VoltrClient extends AccountUtils {
|
|
|
316
365
|
.instruction();
|
|
317
366
|
}
|
|
318
367
|
/**
|
|
319
|
-
* Creates a withdraw instruction
|
|
368
|
+
* Creates a withdraw instruction for a vault
|
|
320
369
|
*
|
|
321
370
|
* @param amount - Amount of LP tokens to withdraw
|
|
322
371
|
* @param {Object} params - Withdraw parameters
|
|
@@ -329,7 +378,7 @@ class VoltrClient extends AccountUtils {
|
|
|
329
378
|
* @throws {Error} If the instruction creation fails
|
|
330
379
|
*
|
|
331
380
|
* @example
|
|
332
|
-
* const ix = await client.
|
|
381
|
+
* const ix = await client.createWithdrawVaultIx(
|
|
333
382
|
* new BN('1000000000'),
|
|
334
383
|
* {
|
|
335
384
|
* userAuthority: userPubkey,
|
|
@@ -339,9 +388,9 @@ class VoltrClient extends AccountUtils {
|
|
|
339
388
|
* }
|
|
340
389
|
* );
|
|
341
390
|
*/
|
|
342
|
-
async
|
|
391
|
+
async createWithdrawVaultIx(amount, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
343
392
|
return await this.vaultProgram.methods
|
|
344
|
-
.
|
|
393
|
+
.withdrawVault(amount)
|
|
345
394
|
.accounts({
|
|
346
395
|
userTransferAuthority: userAuthority,
|
|
347
396
|
vault,
|
|
@@ -356,6 +405,7 @@ class VoltrClient extends AccountUtils {
|
|
|
356
405
|
* @param {Object} params - Parameters for adding adaptor to vault
|
|
357
406
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
358
407
|
* @param {PublicKey} params.payer - Public key of the payer
|
|
408
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
359
409
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
360
410
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for adding adaptor to vault
|
|
361
411
|
*
|
|
@@ -366,15 +416,17 @@ class VoltrClient extends AccountUtils {
|
|
|
366
416
|
* const ix = await client.createAddAdaptorIx({
|
|
367
417
|
* vault: vaultPubkey,
|
|
368
418
|
* payer: payerPubkey,
|
|
419
|
+
* admin: adminPubkey,
|
|
369
420
|
* adaptorProgram: adaptorProgramPubkey
|
|
370
421
|
* });
|
|
371
422
|
* ```
|
|
372
423
|
*/
|
|
373
|
-
async createAddAdaptorIx({ vault, payer, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
424
|
+
async createAddAdaptorIx({ vault, payer, admin, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
374
425
|
return await this.vaultProgram.methods
|
|
375
426
|
.addAdaptor()
|
|
376
|
-
.
|
|
427
|
+
.accountsPartial({
|
|
377
428
|
payer,
|
|
429
|
+
admin,
|
|
378
430
|
vault,
|
|
379
431
|
adaptorProgram,
|
|
380
432
|
})
|
|
@@ -391,6 +443,7 @@ class VoltrClient extends AccountUtils {
|
|
|
391
443
|
* @param {PublicKey} params.manager - Public key of the manager
|
|
392
444
|
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
393
445
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
446
|
+
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
394
447
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing strategy to vault
|
|
395
448
|
* @throws {Error} If the instruction creation fails
|
|
396
449
|
*
|
|
@@ -406,12 +459,13 @@ class VoltrClient extends AccountUtils {
|
|
|
406
459
|
* vault: vaultPubkey,
|
|
407
460
|
* manager: managerPubkey,
|
|
408
461
|
* strategy: strategyPubkey,
|
|
409
|
-
* adaptorProgram: adaptorProgramPubkey
|
|
462
|
+
* adaptorProgram: adaptorProgramPubkey,
|
|
463
|
+
* remainingAccounts: []
|
|
410
464
|
* }
|
|
411
465
|
* );
|
|
412
466
|
* ```
|
|
413
467
|
*/
|
|
414
|
-
async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
468
|
+
async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
415
469
|
return await this.vaultProgram.methods
|
|
416
470
|
.initializeStrategy(instructionDiscriminator ?? null, additionalArgs ?? null)
|
|
417
471
|
.accounts({
|
|
@@ -421,16 +475,18 @@ class VoltrClient extends AccountUtils {
|
|
|
421
475
|
strategy,
|
|
422
476
|
adaptorProgram,
|
|
423
477
|
})
|
|
478
|
+
.remainingAccounts(remainingAccounts)
|
|
424
479
|
.instruction();
|
|
425
480
|
}
|
|
426
481
|
/**
|
|
427
482
|
* Creates an instruction to deposit assets into a strategy
|
|
428
483
|
*
|
|
429
|
-
* @param {
|
|
484
|
+
* @param {DepositStrategyArgs} depositArgs - Deposit arguments
|
|
430
485
|
* @param {BN} depositArgs.depositAmount - Amount of assets to deposit
|
|
431
486
|
* @param {Buffer | null} [depositArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
432
487
|
* @param {Buffer | null} [depositArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
433
488
|
* @param {Object} params - Strategy deposit parameters
|
|
489
|
+
* @param {PublicKey} params.manager - Public key of the manager
|
|
434
490
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
435
491
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
436
492
|
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
@@ -449,6 +505,7 @@ class VoltrClient extends AccountUtils {
|
|
|
449
505
|
* additionalArgs: Buffer.from('...')
|
|
450
506
|
* },
|
|
451
507
|
* {
|
|
508
|
+
* manager: managerPubkey,
|
|
452
509
|
* vault: vaultPubkey,
|
|
453
510
|
* vaultAssetMint: mintPubkey,
|
|
454
511
|
* strategy: strategyPubkey,
|
|
@@ -459,10 +516,11 @@ class VoltrClient extends AccountUtils {
|
|
|
459
516
|
* );
|
|
460
517
|
* ```
|
|
461
518
|
*/
|
|
462
|
-
async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
519
|
+
async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
463
520
|
return await this.vaultProgram.methods
|
|
464
521
|
.depositStrategy(depositAmount, instructionDiscriminator, additionalArgs)
|
|
465
522
|
.accounts({
|
|
523
|
+
manager,
|
|
466
524
|
vault,
|
|
467
525
|
vaultAssetMint,
|
|
468
526
|
adaptorProgram,
|
|
@@ -475,7 +533,7 @@ class VoltrClient extends AccountUtils {
|
|
|
475
533
|
/**
|
|
476
534
|
* Creates an instruction to withdraw assets from a strategy
|
|
477
535
|
*
|
|
478
|
-
* @param {
|
|
536
|
+
* @param {WithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
479
537
|
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
480
538
|
* @param {Buffer | null} [withdrawArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
481
539
|
* @param {Buffer | null} [withdrawArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
@@ -508,10 +566,11 @@ class VoltrClient extends AccountUtils {
|
|
|
508
566
|
* );
|
|
509
567
|
* ```
|
|
510
568
|
*/
|
|
511
|
-
async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
569
|
+
async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
512
570
|
return await this.vaultProgram.methods
|
|
513
571
|
.withdrawStrategy(withdrawAmount, instructionDiscriminator, additionalArgs)
|
|
514
572
|
.accounts({
|
|
573
|
+
manager,
|
|
515
574
|
vault,
|
|
516
575
|
vaultAssetMint,
|
|
517
576
|
adaptorProgram,
|
|
@@ -525,27 +584,124 @@ class VoltrClient extends AccountUtils {
|
|
|
525
584
|
* Creates an instruction to remove a strategy from a vault
|
|
526
585
|
* @param {Object} params - Parameters for removing strategy
|
|
527
586
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
587
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
528
588
|
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
529
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing
|
|
589
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing adaptor from vault
|
|
530
590
|
* @throws {Error} If instruction creation fails
|
|
531
591
|
*
|
|
532
592
|
* @example
|
|
533
593
|
* ```typescript
|
|
534
|
-
* const ix = await client.
|
|
594
|
+
* const ix = await client.createRemoveAdaptorIx({
|
|
535
595
|
* vault: vaultPubkey,
|
|
596
|
+
* admin: adminPubkey,
|
|
536
597
|
* adaptorProgram: adaptorProgramPubkey
|
|
537
598
|
* });
|
|
538
599
|
* ```
|
|
539
600
|
*/
|
|
540
|
-
async
|
|
601
|
+
async createRemoveAdaptorIx({ vault, admin, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
541
602
|
return await this.vaultProgram.methods
|
|
542
603
|
.removeAdaptor()
|
|
543
|
-
.
|
|
604
|
+
.accountsPartial({
|
|
544
605
|
vault,
|
|
606
|
+
admin,
|
|
545
607
|
adaptorProgram,
|
|
546
608
|
})
|
|
547
609
|
.instruction();
|
|
548
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* Creates an instruction to initialize a direct withdraw strategy
|
|
613
|
+
* @param {InitializeDirectWithdrawStrategyArgs} initArgs - Arguments for initializing direct withdraw strategy
|
|
614
|
+
* @param {Buffer | null} initArgs.instructionDiscriminator - Optional discriminator for the instruction
|
|
615
|
+
* @param {Buffer | null} initArgs.additionalArgs - Optional additional arguments for the instruction
|
|
616
|
+
* @param {boolean} initArgs.allowUserArgs - Whether to allow user arguments
|
|
617
|
+
* @param {Object} params - Parameters for initializing direct withdraw strategy
|
|
618
|
+
* @param {PublicKey} params.payer - Public key of the payer
|
|
619
|
+
* @param {PublicKey} params.admin - Public key of the admin
|
|
620
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
621
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
622
|
+
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
623
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing direct withdraw strategy
|
|
624
|
+
* @throws {Error} If instruction creation fails
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```typescript
|
|
628
|
+
* const ix = await client.createInitializeDirectWithdrawStrategyIx(
|
|
629
|
+
* {
|
|
630
|
+
* instructionDiscriminator: Buffer.from('...'),
|
|
631
|
+
* additionalArgs: Buffer.from('...'),
|
|
632
|
+
* allowUserArgs: true
|
|
633
|
+
* },
|
|
634
|
+
* {
|
|
635
|
+
* payer: payerPubkey,
|
|
636
|
+
* admin: adminPubkey,
|
|
637
|
+
* vault: vaultPubkey,
|
|
638
|
+
* strategy: strategyPubkey,
|
|
639
|
+
* adaptorProgram: adaptorProgramPubkey
|
|
640
|
+
* }
|
|
641
|
+
* );
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
|
|
645
|
+
return await this.vaultProgram.methods
|
|
646
|
+
.initializeDirectWithdrawStrategy(instructionDiscriminator, additionalArgs, allowUserArgs)
|
|
647
|
+
.accountsPartial({
|
|
648
|
+
payer,
|
|
649
|
+
admin,
|
|
650
|
+
vault,
|
|
651
|
+
strategy,
|
|
652
|
+
adaptorProgram,
|
|
653
|
+
})
|
|
654
|
+
.instruction();
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Creates an instruction to withdraw assets from a direct withdraw strategy
|
|
658
|
+
* @param {DirectWithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
659
|
+
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
660
|
+
* @param {Buffer | null} [withdrawArgs.userArgs] - Optional user arguments for the instruction
|
|
661
|
+
* @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
|
|
662
|
+
* @param {PublicKey} params.user - Public key of the user
|
|
663
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
664
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
665
|
+
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
666
|
+
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
667
|
+
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
668
|
+
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
669
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from direct withdraw strategy
|
|
670
|
+
* @throws {Error} If instruction creation fails
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```typescript
|
|
674
|
+
* const ix = await client.createDirectWithdrawStrategyIx(
|
|
675
|
+
* {
|
|
676
|
+
* withdrawAmount: new BN('1000000000'),
|
|
677
|
+
* userArgs: Buffer.from('...')
|
|
678
|
+
* },
|
|
679
|
+
* {
|
|
680
|
+
* user: userPubkey,
|
|
681
|
+
* vault: vaultPubkey,
|
|
682
|
+
* strategy: strategyPubkey,
|
|
683
|
+
* vaultAssetMint: mintPubkey,
|
|
684
|
+
* assetTokenProgram: tokenProgramPubkey,
|
|
685
|
+
* adaptorProgram: adaptorProgramPubkey,
|
|
686
|
+
* remainingAccounts: []
|
|
687
|
+
* }
|
|
688
|
+
* );
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
async createDirectWithdrawStrategyIx({ withdrawAmount, userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
|
|
692
|
+
return await this.vaultProgram.methods
|
|
693
|
+
.directWithdrawStrategy(withdrawAmount, userArgs)
|
|
694
|
+
.accounts({
|
|
695
|
+
userTransferAuthority: user,
|
|
696
|
+
strategy,
|
|
697
|
+
adaptorProgram,
|
|
698
|
+
vault,
|
|
699
|
+
vaultAssetMint,
|
|
700
|
+
assetTokenProgram,
|
|
701
|
+
})
|
|
702
|
+
.remainingAccounts(remainingAccounts)
|
|
703
|
+
.instruction();
|
|
704
|
+
}
|
|
549
705
|
// --------------------------------------- Account Fetching All
|
|
550
706
|
/**
|
|
551
707
|
* Fetches all strategy init receipt accounts
|
|
@@ -677,9 +833,13 @@ class VoltrClient extends AccountUtils {
|
|
|
677
833
|
throw new Error("Invalid LP supply");
|
|
678
834
|
if (totalValue <= new anchor_1.BN(0))
|
|
679
835
|
throw new Error("Invalid total assets");
|
|
836
|
+
const amountPreRedemption = lpAmount.mul(totalValue).div(lpSupply);
|
|
837
|
+
const amount = amountPreRedemption
|
|
838
|
+
.mul(new anchor_1.BN(10000 - constants_1.REDEMPTION_FEE_PERCENTAGE_BPS))
|
|
839
|
+
.div(new anchor_1.BN(10000));
|
|
680
840
|
// Calculate: (lpAmount * totalValue) / totalLpSupply
|
|
681
841
|
try {
|
|
682
|
-
return
|
|
842
|
+
return amount;
|
|
683
843
|
}
|
|
684
844
|
catch (e) {
|
|
685
845
|
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
|
};
|
package/dist/constants.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SEEDS = exports.DEFAULT_ADAPTOR_PROGRAM_ID = exports.VAULT_PROGRAM_ID = void 0;
|
|
3
|
+
exports.SEEDS = exports.REDEMPTION_FEE_PERCENTAGE_BPS = exports.DEFAULT_ADAPTOR_PROGRAM_ID = exports.VAULT_PROGRAM_ID = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.VAULT_PROGRAM_ID = new web3_js_1.PublicKey("vVoLTRjQmtFpiYoegx285Ze4gsLJ8ZxgFKVcuvmG1a8");
|
|
6
6
|
exports.DEFAULT_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("aVoLTRCRt3NnnchvLYH6rMYehJHwM5m45RmLBZq7PGz");
|
|
7
|
+
exports.REDEMPTION_FEE_PERCENTAGE_BPS = 10;
|
|
7
8
|
exports.SEEDS = {
|
|
8
9
|
VAULT_LP_MINT: Buffer.from("vault_lp_mint"),
|
|
9
|
-
VAULT_LP_FEE_AUTH: Buffer.from("vault_lp_fee_auth"),
|
|
10
10
|
VAULT_ASSET_IDLE_AUTH: Buffer.from("vault_asset_idle_auth"),
|
|
11
11
|
STRATEGY: Buffer.from("strategy"),
|
|
12
12
|
STRATEGY_INIT_RECEIPT: Buffer.from("strategy_init_receipt"),
|
|
13
13
|
VAULT_STRATEGY_AUTH: Buffer.from("vault_strategy_auth"),
|
|
14
|
+
DIRECT_WITHDRAW_INIT_RECEIPT_SEED: Buffer.from("direct_withdraw_init_receipt"),
|
|
14
15
|
};
|