@voltr/vault-sdk 0.1.6 → 1.0.0

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.js CHANGED
@@ -32,9 +32,13 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.VoltrClient = void 0;
37
40
  const anchor_1 = require("@coral-xyz/anchor");
41
+ const bn_js_1 = __importDefault(require("bn.js"));
38
42
  const web3_js_1 = require("@solana/web3.js");
39
43
  const spl_token_1 = require("@solana/spl-token");
40
44
  const constants_1 = require("./constants");
@@ -227,6 +231,21 @@ class VoltrClient extends AccountUtils {
227
231
  directWithdrawInitReceipt,
228
232
  };
229
233
  }
234
+ /**
235
+ * Finds the request withdraw vault receipt address
236
+ * @param vault - Public key of the vault
237
+ * @param user - Public key of the user
238
+ * @returns The PDA for the request withdraw vault receipt
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const requestWithdrawVaultReceipt = client.findRequestWithdrawVaultReceipt(vaultPubkey, userPubkey);
243
+ * ```
244
+ */
245
+ findRequestWithdrawVaultReceipt(vault, user) {
246
+ const [requestWithdrawVaultReceipt] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.REQUEST_WITHDRAW_VAULT_RECEIPT, vault.toBuffer(), user.toBuffer()], this.vaultProgram.programId);
247
+ return requestWithdrawVaultReceipt;
248
+ }
230
249
  // --------------------------------------- Vault Instructions
231
250
  /**
232
251
  * Creates an instruction to initialize a new vault
@@ -235,10 +254,14 @@ class VoltrClient extends AccountUtils {
235
254
  * @param {VaultConfig} vaultParams.config - Vault configuration settings
236
255
  * @param {BN} vaultParams.config.maxCap - Maximum capacity of the vault
237
256
  * @param {BN} vaultParams.config.startAtTs - Vault start timestamp in seconds
257
+ * @param {BN} vaultParams.config.lockedProfitDegradationDuration - Locked profit degradation duration in seconds
238
258
  * @param {number} vaultParams.config.managerManagementFee - Manager's management fee in basis points (e.g., 50 = 0.5%)
239
259
  * @param {number} vaultParams.config.managerPerformanceFee - Manager's performance fee in basis points (e.g., 1000 = 10%)
240
260
  * @param {number} vaultParams.config.adminManagementFee - Admin's management fee in basis points (e.g., 50 = 0.5%)
241
261
  * @param {number} vaultParams.config.adminPerformanceFee - Admin's performance fee in basis points (e.g., 1000 = 10%)
262
+ * @param {number} vaultParams.config.redemptionFee - Redemption fee in basis points (e.g., 10 = 0.1%)
263
+ * @param {number} vaultParams.config.issuanceFee - Issuance fee in basis points (e.g., 10 = 0.1%)
264
+ * @param {BN} vaultParams.config.withdrawalWaitingPeriod - Withdrawal waiting period in seconds
242
265
  * @param {string} vaultParams.name - Name of the vault
243
266
  * @param {string} vaultParams.description - Description of the vault
244
267
  * @param {Object} params - Additional parameters for initializing the vault
@@ -256,6 +279,10 @@ class VoltrClient extends AccountUtils {
256
279
  * config: {
257
280
  * maxCap: new BN('1000000000'),
258
281
  * startAtTs: new BN(Math.floor(Date.now() / 1000)),
282
+ * lockedProfitDegradationDuration: new BN(3600), // 1 hour
283
+ * redemptionFee: 10,
284
+ * issuanceFee: 10,
285
+ * withdrawalWaitingPeriod: new BN(3600), // 1 hour
259
286
  * managerManagementFee: 50, // 0.5%
260
287
  * managerPerformanceFee: 1000, // 10%
261
288
  * adminManagementFee: 50, // 0.5%
@@ -365,29 +392,86 @@ class VoltrClient extends AccountUtils {
365
392
  .instruction();
366
393
  }
367
394
  /**
368
- * Creates a withdraw instruction for a vault
395
+ * Creates a request withdraw instruction for a vault
369
396
  *
370
- * @param {WithdrawVaultArgs} obj - Arguments for withdrawing from the vault
371
- * @param {BN} obj.amount - Amount of LP tokens to withdraw
372
- * @param {boolean} obj.isAmountInLp - Whether the amount is in LP tokens
373
- * @param {boolean} obj.isWithdrawAll - Whether to withdraw all assets
374
- * @param {Object} params - Withdraw parameters
397
+ * @param {RequestWithdrawVaultArgs} requestWithdrawArgs - Arguments for withdrawing from the vault
398
+ * @param {BN} requestWithdrawArgs.amount - Amount of LP tokens to withdraw
399
+ * @param {boolean} requestWithdrawArgs.isAmountInLp - Whether the amount is in LP tokens
400
+ * @param {boolean} requestWithdrawArgs.isWithdrawAll - Whether to withdraw all assets
401
+ * @param {Object} params - Request withdraw parameters
402
+ * @param {PublicKey} params.payer - Public key of the payer
375
403
  * @param {PublicKey} params.userAuthority - Public key of the user authority
376
404
  * @param {PublicKey} params.vault - Public key of the vault
377
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
378
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
379
405
  * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
380
406
  *
381
407
  * @throws {Error} If the instruction creation fails
382
408
  *
383
409
  * @example
384
- * const ix = await client.createWithdrawVaultIx(
410
+ * const ix = await client.createRequestWithdrawVaultIx(
385
411
  * {
386
412
  * amount: new BN('1000000000'),
387
413
  * isAmountInLp: true,
388
414
  * isWithdrawAll: false,
389
415
  * },
390
416
  * {
417
+ * payer: payerPubkey,
418
+ * userAuthority: userPubkey,
419
+ * vault: vaultPubkey,
420
+ * }
421
+ * );
422
+ */
423
+ async createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { payer, userAuthority, vault, }) {
424
+ return await this.vaultProgram.methods
425
+ .requestWithdrawVault(amount, isAmountInLp, isWithdrawAll)
426
+ .accounts({
427
+ payer,
428
+ userTransferAuthority: userAuthority,
429
+ vault,
430
+ })
431
+ .instruction();
432
+ }
433
+ /**
434
+ * Creates a cancel withdraw instruction for a vault
435
+ *
436
+ * @param {Object} params - Cancel withdraw request parameters
437
+ * @param {PublicKey} params.userAuthority - Public key of the user authority
438
+ * @param {PublicKey} params.vault - Public key of the vault
439
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
440
+ *
441
+ * @throws {Error} If the instruction creation fails
442
+ *
443
+ * @example
444
+ * const ix = await client.createCancelRequestWithdrawVaultIx(
445
+ * {
446
+ * userAuthority: userPubkey,
447
+ * vault: vaultPubkey,
448
+ * }
449
+ * );
450
+ */
451
+ async createCancelRequestWithdrawVaultIx({ userAuthority, vault, }) {
452
+ return await this.vaultProgram.methods
453
+ .cancelRequestWithdrawVault()
454
+ .accounts({
455
+ userTransferAuthority: userAuthority,
456
+ vault,
457
+ })
458
+ .instruction();
459
+ }
460
+ /**
461
+ * Creates a withdraw instruction for a vault
462
+ *
463
+ * @param {Object} params - Withdraw parameters
464
+ * @param {PublicKey} params.userAuthority - Public key of the user authority
465
+ * @param {PublicKey} params.vault - Public key of the vault
466
+ * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
467
+ * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
468
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
469
+ *
470
+ * @throws {Error} If the instruction creation fails
471
+ *
472
+ * @example
473
+ * const ix = await client.createWithdrawVaultIx(
474
+ * {
391
475
  * userAuthority: userPubkey,
392
476
  * vault: vaultPubkey,
393
477
  * vaultAssetMint: mintPubkey,
@@ -395,9 +479,9 @@ class VoltrClient extends AccountUtils {
395
479
  * }
396
480
  * );
397
481
  */
398
- async createWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
482
+ async createWithdrawVaultIx({ userAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
399
483
  return await this.vaultProgram.methods
400
- .withdrawVault(amount, isAmountInLp, isWithdrawAll)
484
+ .withdrawVault()
401
485
  .accounts({
402
486
  userTransferAuthority: userAuthority,
403
487
  vault,
@@ -428,7 +512,7 @@ class VoltrClient extends AccountUtils {
428
512
  * });
429
513
  * ```
430
514
  */
431
- async createAddAdaptorIx({ vault, payer, admin, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
515
+ async createAddAdaptorIx({ vault, payer, admin, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, }) {
432
516
  return await this.vaultProgram.methods
433
517
  .addAdaptor()
434
518
  .accountsPartial({
@@ -472,7 +556,7 @@ class VoltrClient extends AccountUtils {
472
556
  * );
473
557
  * ```
474
558
  */
475
- async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
559
+ async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
476
560
  return await this.vaultProgram.methods
477
561
  .initializeStrategy(instructionDiscriminator ?? null, additionalArgs ?? null)
478
562
  .accounts({
@@ -523,7 +607,7 @@ class VoltrClient extends AccountUtils {
523
607
  * );
524
608
  * ```
525
609
  */
526
- async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
610
+ async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
527
611
  return await this.vaultProgram.methods
528
612
  .depositStrategy(depositAmount, instructionDiscriminator, additionalArgs)
529
613
  .accounts({
@@ -573,7 +657,7 @@ class VoltrClient extends AccountUtils {
573
657
  * );
574
658
  * ```
575
659
  */
576
- async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
660
+ async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
577
661
  return await this.vaultProgram.methods
578
662
  .withdrawStrategy(withdrawAmount, instructionDiscriminator, additionalArgs)
579
663
  .accounts({
@@ -605,7 +689,7 @@ class VoltrClient extends AccountUtils {
605
689
  * });
606
690
  * ```
607
691
  */
608
- async createRemoveAdaptorIx({ vault, admin, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
692
+ async createRemoveAdaptorIx({ vault, admin, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, }) {
609
693
  return await this.vaultProgram.methods
610
694
  .removeAdaptor()
611
695
  .accountsPartial({
@@ -648,7 +732,7 @@ class VoltrClient extends AccountUtils {
648
732
  * );
649
733
  * ```
650
734
  */
651
- async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, }) {
735
+ async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, }) {
652
736
  return await this.vaultProgram.methods
653
737
  .initializeDirectWithdrawStrategy(instructionDiscriminator, additionalArgs, allowUserArgs)
654
738
  .accountsPartial({
@@ -662,10 +746,7 @@ class VoltrClient extends AccountUtils {
662
746
  }
663
747
  /**
664
748
  * Creates an instruction to withdraw assets from a direct withdraw strategy
665
- * @param {DirectWithdrawStrategyArgs} directWithdrawArgs - Withdrawal arguments
666
- * @param {BN} directWithdrawArgs.amount - Amount of assets to withdraw
667
- * @param {boolean} directWithdrawArgs.isAmountInLp - Whether the amount is in LP tokens
668
- * @param {boolean} directWithdrawArgs.isWithdrawAll - Whether to withdraw all assets
749
+ * @param {Object} directWithdrawArgs - Withdrawal arguments
669
750
  * @param {Buffer | null} [directWithdrawArgs.userArgs] - Optional user arguments for the instruction
670
751
  * @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
671
752
  * @param {PublicKey} params.user - Public key of the user
@@ -682,9 +763,6 @@ class VoltrClient extends AccountUtils {
682
763
  * ```typescript
683
764
  * const ix = await client.createDirectWithdrawStrategyIx(
684
765
  * {
685
- * amount: new BN('1000000000'),
686
- * isAmountInLp: true,
687
- * isWithdrawAll: false,
688
766
  * userArgs: Buffer.from('...')
689
767
  * },
690
768
  * {
@@ -699,9 +777,9 @@ class VoltrClient extends AccountUtils {
699
777
  * );
700
778
  * ```
701
779
  */
702
- async createDirectWithdrawStrategyIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram = constants_1.DEFAULT_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
780
+ async createDirectWithdrawStrategyIx({ userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
703
781
  return await this.vaultProgram.methods
704
- .directWithdrawStrategy(amount, isAmountInLp, isWithdrawAll, userArgs)
782
+ .directWithdrawStrategy(userArgs)
705
783
  .accounts({
706
784
  userTransferAuthority: user,
707
785
  strategy,
@@ -815,6 +893,18 @@ class VoltrClient extends AccountUtils {
815
893
  return await this.vaultProgram.account.adaptorAddReceipt.fetch(adaptorAddReceipt, "confirmed");
816
894
  }
817
895
  // --------------------------------------- Helpers
896
+ calculateLockedProfit(lastUpdatedLockedProfit, lockedProfitDegradationDuration, currentTime) {
897
+ if (lockedProfitDegradationDuration.eq(new bn_js_1.default(0)))
898
+ return new bn_js_1.default(0);
899
+ const duration = currentTime.sub(lastUpdatedLockedProfit);
900
+ const lockedProfit = lastUpdatedLockedProfit
901
+ .mul(lockedProfitDegradationDuration.sub(duration))
902
+ .div(lockedProfitDegradationDuration);
903
+ if (duration.gt(lockedProfitDegradationDuration))
904
+ return new bn_js_1.default(0);
905
+ else
906
+ return lockedProfit;
907
+ }
818
908
  /**
819
909
  * Calculates the amount of assets that would be received for a given LP token amount
820
910
  *
@@ -834,33 +924,90 @@ class VoltrClient extends AccountUtils {
834
924
  * ```
835
925
  */
836
926
  async calculateAssetsForWithdraw(vaultPk, lpAmount) {
837
- const vault = await this.fetchVaultAccount(vaultPk);
838
- const totalValue = vault.asset.totalValue;
839
- const lpMint = this.findVaultLpMint(vaultPk);
840
- const lp = await (0, spl_token_1.getMint)(this.conn, lpMint);
841
- const lpSupply = new anchor_1.BN(lp.supply.toString());
842
- // Validate inputs
843
- if (lpSupply <= new anchor_1.BN(0))
844
- throw new Error("Invalid LP supply");
845
- if (totalValue <= new anchor_1.BN(0))
846
- throw new Error("Invalid total assets");
847
- const amountPreRedemption = lpAmount.mul(totalValue).div(lpSupply);
848
- const amount = amountPreRedemption
849
- .mul(new anchor_1.BN(10000 - constants_1.REDEMPTION_FEE_PERCENTAGE_BPS))
850
- .div(new anchor_1.BN(10000));
851
- // Calculate: (lpAmount * totalValue) / totalLpSupply
852
927
  try {
928
+ const vault = await this.fetchVaultAccount(vaultPk);
929
+ const totalValue = vault.asset.totalValue;
930
+ const lockedProfit = this.calculateLockedProfit(vault.lockedProfitState.lastUpdatedLockedProfit, vault.vaultConfiguration.lockedProfitDegradationDuration, new bn_js_1.default(Date.now() / 1000));
931
+ const totalUnlockedValue = totalValue.sub(lockedProfit);
932
+ const lpMint = this.findVaultLpMint(vaultPk);
933
+ const lp = await (0, spl_token_1.getMint)(this.conn, lpMint);
934
+ const lpSupply = new bn_js_1.default(lp.supply.toString());
935
+ // Validate inputs
936
+ if (lpSupply <= new bn_js_1.default(0))
937
+ throw new Error("Invalid LP supply");
938
+ if (totalValue <= new bn_js_1.default(0))
939
+ throw new Error("Invalid total assets");
940
+ const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
941
+ .add(vault.feeState.accumulatedLpManagerFees)
942
+ .add(vault.feeState.accumulatedLpProtocolFees);
943
+ const lpSupplyInclFees = lpSupply.add(unharvestedFeesLp);
944
+ // asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
945
+ // asset_to_redeem_post_fee = asset_to_redeem_pre_fee * (10000 - redemption_fee_bps) / 10000
946
+ const assetToRedeemNumerator = lpAmount
947
+ .mul(totalUnlockedValue)
948
+ .mul(new bn_js_1.default(10000 - vault.feeConfiguration.redemptionFee));
949
+ const assetToRedeemDenominator = lpSupplyInclFees.mul(new bn_js_1.default(10000));
950
+ const amount = assetToRedeemNumerator.div(assetToRedeemDenominator);
853
951
  return amount;
854
952
  }
855
953
  catch (e) {
856
- throw new Error("Math overflow in asset calculation");
954
+ throw new Error("Math overflow in asset calculation for withdraw");
955
+ }
956
+ }
957
+ /**
958
+ * Calculates the amount of LP tokens that would be burned for a given asset amount
959
+ *
960
+ * @param vaultPk - Public key of the vault
961
+ * @param assetAmount - Amount of assets to calculate for
962
+ * @returns Promise resolving to the amount of LP tokens that would be burned
963
+ *
964
+ * @throws {Error} If LP supply or total assets are invalid
965
+ * @throws {Error} If math overflow occurs during calculation
966
+ *
967
+ * @example
968
+ * ```typescript
969
+ * const lpTokensToBurn = await client.calculateLpForWithdraw(
970
+ * vaultPubkey,
971
+ * new BN('1000000000')
972
+ * );
973
+ * ```
974
+ */
975
+ async calculateLpForWithdraw(vaultPk, assetAmount) {
976
+ try {
977
+ const vault = await this.fetchVaultAccount(vaultPk);
978
+ const totalValue = vault.asset.totalValue;
979
+ const lockedProfit = this.calculateLockedProfit(vault.lockedProfitState.lastUpdatedLockedProfit, vault.vaultConfiguration.lockedProfitDegradationDuration, new bn_js_1.default(Date.now() / 1000));
980
+ const totalUnlockedValue = totalValue.sub(lockedProfit);
981
+ const lpMint = this.findVaultLpMint(vaultPk);
982
+ const lp = await (0, spl_token_1.getMint)(this.conn, lpMint);
983
+ const lpSupply = new bn_js_1.default(lp.supply.toString());
984
+ // Validate inputs
985
+ if (lpSupply <= new bn_js_1.default(0))
986
+ throw new Error("Invalid LP supply");
987
+ if (totalValue <= new bn_js_1.default(0))
988
+ throw new Error("Invalid total assets");
989
+ const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
990
+ .add(vault.feeState.accumulatedLpManagerFees)
991
+ .add(vault.feeState.accumulatedLpProtocolFees);
992
+ const lpSupplyInclFees = lpSupply.add(unharvestedFeesLp);
993
+ // lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
994
+ // lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
995
+ const lpToBurnNumerator = assetAmount
996
+ .mul(lpSupplyInclFees)
997
+ .mul(new bn_js_1.default(10000));
998
+ const lpToBurnDenominator = totalUnlockedValue.mul(new bn_js_1.default(10000 - vault.feeConfiguration.redemptionFee));
999
+ const lpToBurn = lpToBurnNumerator.div(lpToBurnDenominator);
1000
+ return lpToBurn;
1001
+ }
1002
+ catch (e) {
1003
+ throw new Error("Math overflow in LP token calculation for withdraw");
857
1004
  }
858
1005
  }
859
1006
  /**
860
1007
  * Calculates the amount of LP tokens that would be received for a given asset deposit
861
1008
  *
862
- * @param depositAmount - Amount of assets to deposit
863
1009
  * @param vaultPk - Public key of the vault
1010
+ * @param assetAmount - Amount of assets to deposit
864
1011
  * @returns Promise resolving to the amount of LP tokens that would be received
865
1012
  *
866
1013
  * @throws {Error} If math overflow occurs during calculation
@@ -868,32 +1015,43 @@ class VoltrClient extends AccountUtils {
868
1015
  * @example
869
1016
  * ```typescript
870
1017
  * const lpTokens = await client.calculateLpTokensForDeposit(
871
- * new BN('1000000000'),
872
1018
  * vaultPubkey
1019
+ * new BN('1000000000'),
873
1020
  * );
874
1021
  * ```
875
1022
  */
876
- async calculateLpTokensForDeposit(depositAmount, vaultPk) {
1023
+ async calculateLpForDeposit(vaultPk, assetAmount) {
877
1024
  const vault = await this.fetchVaultAccount(vaultPk);
878
1025
  const totalValue = vault.asset.totalValue;
879
1026
  const lpMint = this.findVaultLpMint(vaultPk);
880
1027
  const lp = await (0, spl_token_1.getMint)(this.conn, lpMint);
881
- const lpSupply = new anchor_1.BN(lp.supply.toString());
1028
+ const lpSupply = new bn_js_1.default(lp.supply.toString());
1029
+ const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1030
+ .add(vault.feeState.accumulatedLpManagerFees)
1031
+ .add(vault.feeState.accumulatedLpProtocolFees);
1032
+ const lpSupplyInclFees = lpSupply.add(unharvestedFeesLp);
882
1033
  // If the pool is empty, mint LP tokens 1:1 with deposit
883
- if (totalValue <= new anchor_1.BN(0) && lpSupply <= new anchor_1.BN(0)) {
1034
+ if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
884
1035
  const assetMint = await (0, spl_token_1.getMint)(this.conn, vault.asset.mint);
885
1036
  const assetDecimals = assetMint.decimals;
886
1037
  const lpDecimals = lp.decimals;
887
- return depositAmount
888
- .mul(new anchor_1.BN(10 ** lpDecimals))
889
- .div(new anchor_1.BN(10 ** assetDecimals));
1038
+ return assetAmount
1039
+ .mul(new bn_js_1.default(10 ** lpDecimals))
1040
+ .div(new bn_js_1.default(10 ** assetDecimals));
890
1041
  }
891
- // Calculate: (depositAmount * totalLpSupply) / totalValue
892
1042
  try {
893
- return depositAmount.mul(lpSupply).div(totalValue);
1043
+ const lpToMintNumerator = assetAmount
1044
+ .mul(lpSupplyInclFees)
1045
+ .mul(new bn_js_1.default(10000 - vault.feeConfiguration.issuanceFee));
1046
+ const totalAssetPostDeposit = totalValue.add(assetAmount);
1047
+ const lpToMintDenominator = totalAssetPostDeposit
1048
+ .mul(new bn_js_1.default(10000))
1049
+ .sub(assetAmount.mul(new bn_js_1.default(10000 - vault.feeConfiguration.issuanceFee)));
1050
+ const lpToMint = lpToMintNumerator.div(lpToMintDenominator);
1051
+ return lpToMint;
894
1052
  }
895
1053
  catch (e) {
896
- throw new Error("Math overflow in LP token calculation");
1054
+ throw new Error("Math overflow in LP token calculation for deposit");
897
1055
  }
898
1056
  }
899
1057
  }
@@ -1,12 +1,17 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  export declare const VAULT_PROGRAM_ID: PublicKey;
3
- export declare const DEFAULT_ADAPTOR_PROGRAM_ID: PublicKey;
4
- export declare const REDEMPTION_FEE_PERCENTAGE_BPS = 10;
3
+ export declare const LENDING_ADAPTOR_PROGRAM_ID: PublicKey;
4
+ export declare const DRIFT_ADAPTOR_PROGRAM_ID: PublicKey;
5
5
  export declare const SEEDS: {
6
+ PROTOCOL: Buffer<ArrayBuffer>;
6
7
  VAULT_LP_MINT: Buffer<ArrayBuffer>;
8
+ VAULT_LP_MINT_AUTH: Buffer<ArrayBuffer>;
7
9
  VAULT_ASSET_IDLE_AUTH: Buffer<ArrayBuffer>;
8
- STRATEGY: Buffer<ArrayBuffer>;
10
+ ADAPTOR_ADD_RECEIPT: Buffer<ArrayBuffer>;
9
11
  STRATEGY_INIT_RECEIPT: Buffer<ArrayBuffer>;
10
12
  VAULT_STRATEGY_AUTH: Buffer<ArrayBuffer>;
13
+ VAULT_STRATEGY: Buffer<ArrayBuffer>;
11
14
  DIRECT_WITHDRAW_INIT_RECEIPT_SEED: Buffer<ArrayBuffer>;
15
+ REQUEST_WITHDRAW_VAULT_RECEIPT: Buffer<ArrayBuffer>;
16
+ STRATEGY: Buffer<ArrayBuffer>;
12
17
  };
package/dist/constants.js CHANGED
@@ -1,15 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SEEDS = exports.REDEMPTION_FEE_PERCENTAGE_BPS = exports.DEFAULT_ADAPTOR_PROGRAM_ID = exports.VAULT_PROGRAM_ID = void 0;
3
+ exports.SEEDS = exports.DRIFT_ADAPTOR_PROGRAM_ID = exports.LENDING_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
- exports.DEFAULT_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("aVoLTRCRt3NnnchvLYH6rMYehJHwM5m45RmLBZq7PGz");
7
- exports.REDEMPTION_FEE_PERCENTAGE_BPS = 10;
6
+ exports.LENDING_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("aVoLTRCRt3NnnchvLYH6rMYehJHwM5m45RmLBZq7PGz");
7
+ exports.DRIFT_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("EBN93eXs5fHGBABuajQqdsKRkCgaqtJa8vEFD6vKXiP");
8
8
  exports.SEEDS = {
9
+ PROTOCOL: Buffer.from("protocol"),
9
10
  VAULT_LP_MINT: Buffer.from("vault_lp_mint"),
11
+ VAULT_LP_MINT_AUTH: Buffer.from("vault_lp_mint_auth"),
10
12
  VAULT_ASSET_IDLE_AUTH: Buffer.from("vault_asset_idle_auth"),
11
- STRATEGY: Buffer.from("strategy"),
13
+ ADAPTOR_ADD_RECEIPT: Buffer.from("adaptor_add_receipt"),
12
14
  STRATEGY_INIT_RECEIPT: Buffer.from("strategy_init_receipt"),
13
15
  VAULT_STRATEGY_AUTH: Buffer.from("vault_strategy_auth"),
16
+ VAULT_STRATEGY: Buffer.from("vault_strategy"),
14
17
  DIRECT_WITHDRAW_INIT_RECEIPT_SEED: Buffer.from("direct_withdraw_init_receipt"),
18
+ REQUEST_WITHDRAW_VAULT_RECEIPT: Buffer.from("request_withdraw_vault_receipt"),
19
+ // TODO: Remove this
20
+ STRATEGY: Buffer.from("strategy"),
15
21
  };