@voltr/vault-sdk 1.0.18 → 1.0.20

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
@@ -263,6 +263,119 @@ class VoltrClient extends AccountUtils {
263
263
  const [lpMetadataAccount] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.METADATA, constants_1.METADATA_PROGRAM_ID.toBuffer(), lpMint.toBuffer()], constants_1.METADATA_PROGRAM_ID);
264
264
  return lpMetadataAccount;
265
265
  }
266
+ /**
267
+ * Finds the protocol PDA address
268
+ * @returns The PDA for the protocol account
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * const protocol = client.findProtocol();
273
+ * ```
274
+ */
275
+ findProtocol() {
276
+ const [protocol] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.PROTOCOL], this.vaultProgram.programId);
277
+ return protocol;
278
+ }
279
+ // --------------------------------------- Protocol Instructions
280
+ /**
281
+ * Creates an instruction to initialize the protocol
282
+ *
283
+ * @param {number} operationalState - Bitflags for allowed operations (e.g., CREATE_VAULT = 1, DEPOSIT_VAULT = 2, etc.)
284
+ * @param {Object} params - Parameters for initializing the protocol
285
+ * @param {PublicKey} params.payer - Public key of the fee payer
286
+ * @param {PublicKey} params.admin - Public key of the protocol admin
287
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for initializing the protocol
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * const ix = await client.createInitProtocolIx(
292
+ * 0xFFFF, // enable all operations
293
+ * {
294
+ * payer: payerPubkey,
295
+ * admin: adminPubkey,
296
+ * }
297
+ * );
298
+ * ```
299
+ */
300
+ async createInitProtocolIx(operationalState, { payer, admin, }) {
301
+ return await this.vaultProgram.methods
302
+ .initProtocol(operationalState)
303
+ .accounts({
304
+ payer,
305
+ admin,
306
+ })
307
+ .instruction();
308
+ }
309
+ /**
310
+ * Creates an instruction to update the protocol configuration
311
+ *
312
+ * @param {ProtocolConfigField} field - The protocol configuration field to update
313
+ * @param {Buffer} data - The serialized data for the new value
314
+ * @param {Object} params - Parameters for updating the protocol
315
+ * @param {PublicKey} params.admin - Public key of the protocol admin
316
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol
317
+ *
318
+ * @throws {Error} If the field is unknown
319
+ *
320
+ * @example Update operational state
321
+ * ```typescript
322
+ * const data = Buffer.alloc(2);
323
+ * data.writeUInt16LE(0xFFFF, 0);
324
+ * const ix = await client.createUpdateProtocolIx(
325
+ * ProtocolConfigField.OperationalState,
326
+ * data,
327
+ * { admin: adminPubkey }
328
+ * );
329
+ * ```
330
+ *
331
+ * @example Set pending admin for 2-step transfer
332
+ * ```typescript
333
+ * const data = newAdmin.toBuffer();
334
+ * const ix = await client.createUpdateProtocolIx(
335
+ * ProtocolConfigField.PendingAdmin,
336
+ * data,
337
+ * { admin: adminPubkey }
338
+ * );
339
+ * ```
340
+ */
341
+ async createUpdateProtocolIx(field, data, { admin, }) {
342
+ const fieldToVariant = {
343
+ [types_1.ProtocolConfigField.OperationalState]: { operationalState: {} },
344
+ [types_1.ProtocolConfigField.PendingAdmin]: { pendingAdmin: {} },
345
+ };
346
+ const fieldVariant = fieldToVariant[field];
347
+ if (!fieldVariant) {
348
+ throw new Error(`Unknown protocol config field: ${field}`);
349
+ }
350
+ return await this.vaultProgram.methods
351
+ .updateProtocol(fieldVariant, data)
352
+ .accounts({
353
+ admin,
354
+ })
355
+ .instruction();
356
+ }
357
+ /**
358
+ * Creates an instruction to accept a protocol admin transfer (2-step admin transfer)
359
+ *
360
+ * @param {Object} params - Parameters for accepting protocol admin
361
+ * @param {PublicKey} params.pendingAdmin - Public key of the pending admin (must be signer)
362
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for accepting protocol admin
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * const ix = await client.createAcceptProtocolAdminIx({
367
+ * pendingAdmin: pendingAdminPubkey,
368
+ * });
369
+ * ```
370
+ */
371
+ async createAcceptProtocolAdminIx({ pendingAdmin, }) {
372
+ return await this.vaultProgram.methods
373
+ .acceptProtocolAdmin()
374
+ .accounts({
375
+ pendingAdmin,
376
+ })
377
+ .instruction();
378
+ }
266
379
  // --------------------------------------- Vault Instructions
267
380
  /**
268
381
  * Creates an instruction to initialize a new vault
@@ -610,6 +723,50 @@ class VoltrClient extends AccountUtils {
610
723
  })
611
724
  .instruction();
612
725
  }
726
+ /**
727
+ * Creates an instant withdraw instruction for a vault (no waiting period required)
728
+ *
729
+ * @param {InstantWithdrawVaultArgs} args - Instant withdrawal arguments
730
+ * @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
731
+ * @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
732
+ * @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
733
+ * @param {Object} params - Instant withdraw parameters
734
+ * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
735
+ * @param {PublicKey} params.vault - Public key of the vault
736
+ * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
737
+ * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
738
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for instant withdrawal
739
+ *
740
+ * @throws {Error} If the vault's withdrawal waiting period is not zero
741
+ *
742
+ * @example
743
+ * ```typescript
744
+ * const ix = await client.createInstantWithdrawVaultIx(
745
+ * {
746
+ * amount: new BN('1000000000'),
747
+ * isAmountInLp: true,
748
+ * isWithdrawAll: false,
749
+ * },
750
+ * {
751
+ * userTransferAuthority: userPubkey,
752
+ * vault: vaultPubkey,
753
+ * vaultAssetMint: mintPubkey,
754
+ * assetTokenProgram: tokenProgramPubkey,
755
+ * }
756
+ * );
757
+ * ```
758
+ */
759
+ async createInstantWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
760
+ return await this.vaultProgram.methods
761
+ .instantWithdrawVault(amount, isAmountInLp, isWithdrawAll)
762
+ .accounts({
763
+ userTransferAuthority,
764
+ vault,
765
+ vaultAssetMint,
766
+ assetTokenProgram,
767
+ })
768
+ .instruction();
769
+ }
613
770
  // --------------------------------------- Strategy Instructions
614
771
  /**
615
772
  * Creates an instruction to add an adaptor to a vault
@@ -632,7 +789,7 @@ class VoltrClient extends AccountUtils {
632
789
  * });
633
790
  * ```
634
791
  */
635
- async createAddAdaptorIx({ vault, payer, admin, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, }) {
792
+ async createAddAdaptorIx({ vault, payer, admin, adaptorProgram, }) {
636
793
  return await this.vaultProgram.methods
637
794
  .addAdaptor()
638
795
  .accountsPartial({
@@ -676,7 +833,7 @@ class VoltrClient extends AccountUtils {
676
833
  * );
677
834
  * ```
678
835
  */
679
- async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
836
+ async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram, remainingAccounts, }) {
680
837
  return await this.vaultProgram.methods
681
838
  .initializeStrategy(instructionDiscriminator ?? null, additionalArgs ?? null)
682
839
  .accounts({
@@ -727,7 +884,7 @@ class VoltrClient extends AccountUtils {
727
884
  * );
728
885
  * ```
729
886
  */
730
- async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
887
+ async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
731
888
  return await this.vaultProgram.methods
732
889
  .depositStrategy(depositAmount, instructionDiscriminator, additionalArgs)
733
890
  .accounts({
@@ -777,7 +934,7 @@ class VoltrClient extends AccountUtils {
777
934
  * );
778
935
  * ```
779
936
  */
780
- async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
937
+ async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
781
938
  return await this.vaultProgram.methods
782
939
  .withdrawStrategy(withdrawAmount, instructionDiscriminator, additionalArgs)
783
940
  .accounts({
@@ -809,7 +966,7 @@ class VoltrClient extends AccountUtils {
809
966
  * });
810
967
  * ```
811
968
  */
812
- async createRemoveAdaptorIx({ vault, admin, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, }) {
969
+ async createRemoveAdaptorIx({ vault, admin, adaptorProgram, }) {
813
970
  return await this.vaultProgram.methods
814
971
  .removeAdaptor()
815
972
  .accountsPartial({
@@ -852,7 +1009,7 @@ class VoltrClient extends AccountUtils {
852
1009
  * );
853
1010
  * ```
854
1011
  */
855
- async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, }) {
1012
+ async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram, }) {
856
1013
  return await this.vaultProgram.methods
857
1014
  .initializeDirectWithdrawStrategy(instructionDiscriminator, additionalArgs, allowUserArgs)
858
1015
  .accountsPartial({
@@ -897,7 +1054,7 @@ class VoltrClient extends AccountUtils {
897
1054
  * );
898
1055
  * ```
899
1056
  */
900
- async createDirectWithdrawStrategyIx({ userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
1057
+ async createDirectWithdrawStrategyIx({ userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
901
1058
  return await this.vaultProgram.methods
902
1059
  .directWithdrawStrategy(userArgs)
903
1060
  .accounts({
@@ -912,19 +1069,20 @@ class VoltrClient extends AccountUtils {
912
1069
  .instruction();
913
1070
  }
914
1071
  /**
915
- * Creates an instruction to withdraw assets from a strategy via direct withdrawal with tolerance
916
- * @param {Object} args - Arguments for the withdrawal
917
- * @param {Buffer | null} args.userArgs - Optional user arguments
918
- * @param {BN} args.tolerance - Tolerance amount for the withdrawal
1072
+ * Creates an instruction to withdraw assets from a direct withdraw strategy with slippage tolerance
1073
+ *
1074
+ * @param {Object} directWithdrawArgs - Withdrawal arguments
1075
+ * @param {Buffer | null} [directWithdrawArgs.userArgs] - Optional user arguments for the instruction
1076
+ * @param {BN} directWithdrawArgs.tolerance - Slippage tolerance in asset amount (max difference between requested and actual)
919
1077
  * @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
920
1078
  * @param {PublicKey} params.user - Public key of the user
921
1079
  * @param {PublicKey} params.vault - Public key of the vault
922
1080
  * @param {PublicKey} params.strategy - Public key of the strategy
923
1081
  * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
924
1082
  * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
925
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
1083
+ * @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
926
1084
  * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
927
- * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from direct withdraw strategy with tolerance
1085
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for direct withdraw with tolerance
928
1086
  * @throws {Error} If instruction creation fails
929
1087
  *
930
1088
  * @example
@@ -932,7 +1090,7 @@ class VoltrClient extends AccountUtils {
932
1090
  * const ix = await client.createDirectWithdrawStrategyWithToleranceIx(
933
1091
  * {
934
1092
  * userArgs: Buffer.from('...'),
935
- * tolerance: new BN(1)
1093
+ * tolerance: new BN(1000),
936
1094
  * },
937
1095
  * {
938
1096
  * user: userPubkey,
@@ -940,13 +1098,12 @@ class VoltrClient extends AccountUtils {
940
1098
  * strategy: strategyPubkey,
941
1099
  * vaultAssetMint: mintPubkey,
942
1100
  * assetTokenProgram: tokenProgramPubkey,
943
- * adaptorProgram: adaptorProgramPubkey,
944
- * remainingAccounts: []
1101
+ * remainingAccounts: [],
945
1102
  * }
946
1103
  * );
947
1104
  * ```
948
1105
  */
949
- async createDirectWithdrawStrategyWithToleranceIx({ userArgs = null, tolerance }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram = constants_1.LENDING_ADAPTOR_PROGRAM_ID, remainingAccounts, }) {
1106
+ async createDirectWithdrawStrategyWithToleranceIx({ userArgs = null, tolerance }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
950
1107
  return await this.vaultProgram.methods
951
1108
  .directWithdrawStrategyWithTolerance(userArgs, tolerance)
952
1109
  .accounts({
@@ -960,6 +1117,112 @@ class VoltrClient extends AccountUtils {
960
1117
  .remainingAccounts(remainingAccounts)
961
1118
  .instruction();
962
1119
  }
1120
+ /**
1121
+ * Creates an instant withdraw instruction for a strategy (no waiting period, withdraws directly from strategy)
1122
+ *
1123
+ * @param {InstantWithdrawStrategyArgs} args - Instant withdrawal arguments
1124
+ * @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
1125
+ * @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
1126
+ * @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
1127
+ * @param {Buffer | null} [args.userArgs] - Optional user arguments passed to the adaptor
1128
+ * @param {Object} params - Instant withdraw strategy parameters
1129
+ * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
1130
+ * @param {PublicKey} params.vault - Public key of the vault
1131
+ * @param {PublicKey} params.strategy - Public key of the strategy
1132
+ * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
1133
+ * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
1134
+ * @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
1135
+ * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
1136
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for instant strategy withdrawal
1137
+ * @throws {Error} If the vault's withdrawal waiting period is not zero
1138
+ *
1139
+ * @example
1140
+ * ```typescript
1141
+ * const ix = await client.createInstantWithdrawStrategyIx(
1142
+ * {
1143
+ * amount: new BN('1000000000'),
1144
+ * isAmountInLp: true,
1145
+ * isWithdrawAll: false,
1146
+ * },
1147
+ * {
1148
+ * userTransferAuthority: userPubkey,
1149
+ * vault: vaultPubkey,
1150
+ * strategy: strategyPubkey,
1151
+ * vaultAssetMint: mintPubkey,
1152
+ * assetTokenProgram: tokenProgramPubkey,
1153
+ * remainingAccounts: [],
1154
+ * }
1155
+ * );
1156
+ * ```
1157
+ */
1158
+ async createInstantWithdrawStrategyIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, }, { userTransferAuthority, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
1159
+ return await this.vaultProgram.methods
1160
+ .instantWithdrawStrategy(amount, isAmountInLp, isWithdrawAll, userArgs ?? null)
1161
+ .accounts({
1162
+ userTransferAuthority,
1163
+ vault,
1164
+ strategy,
1165
+ vaultAssetMint,
1166
+ assetTokenProgram,
1167
+ adaptorProgram,
1168
+ })
1169
+ .remainingAccounts(remainingAccounts)
1170
+ .instruction();
1171
+ }
1172
+ /**
1173
+ * Creates an instant withdraw instruction for a strategy with slippage tolerance
1174
+ *
1175
+ * @param {InstantWithdrawStrategyArgs & { tolerance: BN }} args - Instant withdrawal arguments with tolerance
1176
+ * @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
1177
+ * @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
1178
+ * @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
1179
+ * @param {Buffer | null} [args.userArgs] - Optional user arguments passed to the adaptor
1180
+ * @param {BN} args.tolerance - Slippage tolerance in asset amount (max difference between requested and actual)
1181
+ * @param {Object} params - Instant withdraw strategy parameters
1182
+ * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
1183
+ * @param {PublicKey} params.vault - Public key of the vault
1184
+ * @param {PublicKey} params.strategy - Public key of the strategy
1185
+ * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
1186
+ * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
1187
+ * @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
1188
+ * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
1189
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for instant strategy withdrawal with tolerance
1190
+ * @throws {Error} If the vault's withdrawal waiting period is not zero
1191
+ *
1192
+ * @example
1193
+ * ```typescript
1194
+ * const ix = await client.createInstantWithdrawStrategyWithToleranceIx(
1195
+ * {
1196
+ * amount: new BN('1000000000'),
1197
+ * isAmountInLp: true,
1198
+ * isWithdrawAll: false,
1199
+ * tolerance: new BN(1000),
1200
+ * },
1201
+ * {
1202
+ * userTransferAuthority: userPubkey,
1203
+ * vault: vaultPubkey,
1204
+ * strategy: strategyPubkey,
1205
+ * vaultAssetMint: mintPubkey,
1206
+ * assetTokenProgram: tokenProgramPubkey,
1207
+ * remainingAccounts: [],
1208
+ * }
1209
+ * );
1210
+ * ```
1211
+ */
1212
+ async createInstantWithdrawStrategyWithToleranceIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, tolerance, }, { userTransferAuthority, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
1213
+ return await this.vaultProgram.methods
1214
+ .instantWithdrawStrategyWithTolerance(amount, isAmountInLp, isWithdrawAll, userArgs ?? null, tolerance)
1215
+ .accounts({
1216
+ userTransferAuthority,
1217
+ vault,
1218
+ strategy,
1219
+ vaultAssetMint,
1220
+ assetTokenProgram,
1221
+ adaptorProgram,
1222
+ })
1223
+ .remainingAccounts(remainingAccounts)
1224
+ .instruction();
1225
+ }
963
1226
  /**
964
1227
  * Creates an instruction to harvest fees from a vault
965
1228
  * @param {Object} params - Parameters for harvesting fees
@@ -1084,6 +1347,51 @@ class VoltrClient extends AccountUtils {
1084
1347
  })
1085
1348
  .instruction();
1086
1349
  }
1350
+ /**
1351
+ * Creates an instruction to update per-vault protocol fees (admin-only, protocol level)
1352
+ *
1353
+ * @param {ProtocolFeeField} field - The protocol fee field to update
1354
+ * @param {number} feeBps - The new fee value in basis points
1355
+ * @param {Object} params - Parameters for updating the protocol fee
1356
+ * @param {PublicKey} params.admin - Public key of the protocol admin
1357
+ * @param {PublicKey} params.vault - Public key of the vault
1358
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol fee
1359
+ *
1360
+ * @throws {Error} If the total fee (protocol + admin + manager) exceeds 10000 BPS
1361
+ *
1362
+ * @example
1363
+ * ```typescript
1364
+ * const ix = await client.createUpdateVaultProtocolFeeIx(
1365
+ * ProtocolFeeField.ProtocolPerformanceFee,
1366
+ * 500, // 5%
1367
+ * {
1368
+ * admin: protocolAdminPubkey,
1369
+ * vault: vaultPubkey,
1370
+ * }
1371
+ * );
1372
+ * ```
1373
+ */
1374
+ async createUpdateVaultProtocolFeeIx(field, feeBps, { admin, vault, }) {
1375
+ const fieldToVariant = {
1376
+ [types_1.ProtocolFeeField.ProtocolPerformanceFee]: {
1377
+ protocolPerformanceFee: {},
1378
+ },
1379
+ [types_1.ProtocolFeeField.ProtocolManagementFee]: {
1380
+ protocolManagementFee: {},
1381
+ },
1382
+ };
1383
+ const fieldVariant = fieldToVariant[field];
1384
+ if (!fieldVariant) {
1385
+ throw new Error(`Unknown protocol fee field: ${field}`);
1386
+ }
1387
+ return await this.vaultProgram.methods
1388
+ .updateVaultProtocolFee(fieldVariant, feeBps)
1389
+ .accountsPartial({
1390
+ admin,
1391
+ vault,
1392
+ })
1393
+ .instruction();
1394
+ }
1087
1395
  // --------------------------------------- Account Fetching All
1088
1396
  /**
1089
1397
  * Fetches all strategy init receipt accounts
@@ -1163,6 +1471,19 @@ class VoltrClient extends AccountUtils {
1163
1471
  * @param vault - Public key of the vault
1164
1472
  * @returns Promise resolving to the vault account data
1165
1473
  */
1474
+ /**
1475
+ * Fetches the protocol account's data
1476
+ * @returns Promise resolving to the protocol account data
1477
+ *
1478
+ * @example
1479
+ * ```typescript
1480
+ * const protocolAccount = await client.fetchProtocolAccount();
1481
+ * ```
1482
+ */
1483
+ async fetchProtocolAccount() {
1484
+ const protocol = this.findProtocol();
1485
+ return await this.vaultProgram.account.protocol.fetch(protocol, this.provider.opts.commitment);
1486
+ }
1166
1487
  async fetchVaultAccount(vault) {
1167
1488
  return await this.vaultProgram.account.vault.fetch(vault, this.provider.opts.commitment);
1168
1489
  }
@@ -1257,6 +1578,20 @@ class VoltrClient extends AccountUtils {
1257
1578
  const vaultAccount = await this.fetchVaultAccount(vault);
1258
1579
  return vaultAccount.feeState.accumulatedLpManagerFees;
1259
1580
  }
1581
+ /**
1582
+ * Fetches the accumulated protocol fees for a vault
1583
+ * @param vault - Public key of the vault
1584
+ * @returns Promise resolving to the accumulated protocol fees
1585
+ *
1586
+ * @example
1587
+ * ```typescript
1588
+ * const accumulatedProtocolFees = await client.getAccumulatedProtocolFeesForVault(vaultPubkey);
1589
+ * ```
1590
+ */
1591
+ async getAccumulatedProtocolFeesForVault(vault) {
1592
+ const vaultAccount = await this.fetchVaultAccount(vault);
1593
+ return vaultAccount.feeState.accumulatedLpProtocolFees;
1594
+ }
1260
1595
  /**
1261
1596
  * Fetches the current asset per LP for a vault
1262
1597
  * @param vault - Public key of the vault
@@ -1274,7 +1609,8 @@ class VoltrClient extends AccountUtils {
1274
1609
  const unharvestedFeesLp = vaultAccount.feeState.accumulatedLpAdminFees
1275
1610
  .add(vaultAccount.feeState.accumulatedLpManagerFees)
1276
1611
  .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1277
- const totalLpSupply = unharvestedFeesLp.add(lpSupply);
1612
+ const deadWeight = vaultAccount.deadWeight;
1613
+ const totalLpSupply = unharvestedFeesLp.add(lpSupply).add(deadWeight);
1278
1614
  const currentAssetPerLp = vaultAccount.asset.totalValue.toNumber() / totalLpSupply.toNumber();
1279
1615
  return currentAssetPerLp;
1280
1616
  }
@@ -1315,9 +1651,11 @@ class VoltrClient extends AccountUtils {
1315
1651
  const unharvestedFees = vaultAccount.feeState.accumulatedLpAdminFees
1316
1652
  .add(vaultAccount.feeState.accumulatedLpManagerFees)
1317
1653
  .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1318
- const currentTotalLp = circulating.add(unharvestedFees);
1654
+ const deadWeight = vaultAccount.deadWeight;
1655
+ const currentTotalLp = circulating.add(unharvestedFees).add(deadWeight);
1319
1656
  const unrealisedFees = this.calculateUnrealisedLpFees(currentTotalLp, vaultAccount.asset.totalValue, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vaultAccount.feeConfiguration.managerManagementFee +
1320
- vaultAccount.feeConfiguration.adminManagementFee));
1657
+ vaultAccount.feeConfiguration.adminManagementFee +
1658
+ vaultAccount.feeConfiguration.protocolManagementFee));
1321
1659
  const total = currentTotalLp.add(unrealisedFees);
1322
1660
  return {
1323
1661
  circulating,
@@ -1335,7 +1673,8 @@ class VoltrClient extends AccountUtils {
1335
1673
  const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
1336
1674
  const amountLpEscrowed = receipt.account.amountLpEscrowed;
1337
1675
  const amountAssetToWithdrawAtPresent = this.calculateAssetsForWithdrawHelper(vaultAccount.asset.totalValue, vaultAccount.lockedProfitState.lastUpdatedLockedProfit, vaultAccount.vaultConfiguration.lockedProfitDegradationDuration, vaultAccount.feeState.accumulatedLpAdminFees, vaultAccount.feeState.accumulatedLpManagerFees, vaultAccount.feeState.accumulatedLpProtocolFees, vaultAccount.feeConfiguration.redemptionFee, vaultAccount.feeConfiguration.managerManagementFee +
1338
- vaultAccount.feeConfiguration.adminManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed).toNumber();
1676
+ vaultAccount.feeConfiguration.adminManagementFee +
1677
+ vaultAccount.feeConfiguration.protocolManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed, vaultAccount.deadWeight).toNumber();
1339
1678
  // Cap the withdrawal amount to the initial request amount
1340
1679
  const amountAssetToWithdrawEffective = Math.min(amountAssetToWithdrawAtPresent, amountAssetToWithdrawAtRequest);
1341
1680
  return {
@@ -1428,7 +1767,7 @@ class VoltrClient extends AccountUtils {
1428
1767
  .div(lpDenominator);
1429
1768
  return pendingLpToMint;
1430
1769
  }
1431
- calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount) {
1770
+ calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount, deadWeight = new bn_js_1.default(0)) {
1432
1771
  if (lpSupply <= new bn_js_1.default(0))
1433
1772
  throw new Error("Invalid LP supply");
1434
1773
  if (vaultTotalValue <= new bn_js_1.default(0))
@@ -1438,7 +1777,9 @@ class VoltrClient extends AccountUtils {
1438
1777
  const unharvestedFeesLp = vaultAccumulatedLpAdminFees
1439
1778
  .add(vaultAccumulatedLpManagerFees)
1440
1779
  .add(vaultAccumulatedLpProtocolFees);
1441
- const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1780
+ const lpSupplyInclAccumulatedFees = lpSupply
1781
+ .add(unharvestedFeesLp)
1782
+ .add(deadWeight);
1442
1783
  const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
1443
1784
  const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1444
1785
  // asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
@@ -1474,7 +1815,8 @@ class VoltrClient extends AccountUtils {
1474
1815
  const lpMint = this.findVaultLpMint(vaultPk);
1475
1816
  const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
1476
1817
  const amount = this.calculateAssetsForWithdrawHelper(vault.asset.totalValue, vault.lockedProfitState.lastUpdatedLockedProfit, vault.vaultConfiguration.lockedProfitDegradationDuration, vault.feeState.accumulatedLpAdminFees, vault.feeState.accumulatedLpManagerFees, vault.feeState.accumulatedLpProtocolFees, vault.feeConfiguration.redemptionFee, vault.feeConfiguration.managerManagementFee +
1477
- vault.feeConfiguration.adminManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount);
1818
+ vault.feeConfiguration.adminManagementFee +
1819
+ vault.feeConfiguration.protocolManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount, vault.deadWeight);
1478
1820
  return amount;
1479
1821
  }
1480
1822
  catch (e) {
@@ -1516,9 +1858,12 @@ class VoltrClient extends AccountUtils {
1516
1858
  const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1517
1859
  .add(vault.feeState.accumulatedLpManagerFees)
1518
1860
  .add(vault.feeState.accumulatedLpProtocolFees);
1519
- const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1861
+ const lpSupplyInclAccumulatedFees = lpSupply
1862
+ .add(unharvestedFeesLp)
1863
+ .add(vault.deadWeight);
1520
1864
  const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1521
- vault.feeConfiguration.adminManagementFee));
1865
+ vault.feeConfiguration.adminManagementFee +
1866
+ vault.feeConfiguration.protocolManagementFee));
1522
1867
  const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1523
1868
  // lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
1524
1869
  // lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
@@ -1559,9 +1904,12 @@ class VoltrClient extends AccountUtils {
1559
1904
  const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1560
1905
  .add(vault.feeState.accumulatedLpManagerFees)
1561
1906
  .add(vault.feeState.accumulatedLpProtocolFees);
1562
- const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1907
+ const lpSupplyInclAccumulatedFees = lpSupply
1908
+ .add(unharvestedFeesLp)
1909
+ .add(vault.deadWeight);
1563
1910
  const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1564
- vault.feeConfiguration.adminManagementFee));
1911
+ vault.feeConfiguration.adminManagementFee +
1912
+ vault.feeConfiguration.protocolManagementFee));
1565
1913
  const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1566
1914
  // If the pool is empty, mint LP tokens 1:1 with deposit
1567
1915
  if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
@@ -1,8 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
3
  export declare const VAULT_PROGRAM_ID: PublicKey;
4
- export declare const LENDING_ADAPTOR_PROGRAM_ID: PublicKey;
5
- export declare const DRIFT_ADAPTOR_PROGRAM_ID: PublicKey;
6
4
  export declare const METADATA_PROGRAM_ID: PublicKey;
7
5
  export declare const SEEDS: {
8
6
  PROTOCOL: Buffer<ArrayBuffer>;
package/dist/constants.js CHANGED
@@ -3,12 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MAX_FEE_BPS_BN = exports.ONE_YEAR_BN = exports.SEEDS = exports.METADATA_PROGRAM_ID = exports.DRIFT_ADAPTOR_PROGRAM_ID = exports.LENDING_ADAPTOR_PROGRAM_ID = exports.VAULT_PROGRAM_ID = void 0;
6
+ exports.MAX_FEE_BPS_BN = exports.ONE_YEAR_BN = exports.SEEDS = exports.METADATA_PROGRAM_ID = exports.VAULT_PROGRAM_ID = void 0;
7
7
  const web3_js_1 = require("@solana/web3.js");
8
8
  const bn_js_1 = __importDefault(require("bn.js"));
9
9
  exports.VAULT_PROGRAM_ID = new web3_js_1.PublicKey("vVoLTRjQmtFpiYoegx285Ze4gsLJ8ZxgFKVcuvmG1a8");
10
- exports.LENDING_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("aVoLTRCRt3NnnchvLYH6rMYehJHwM5m45RmLBZq7PGz");
11
- exports.DRIFT_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("EBN93eXs5fHGBABuajQqdsKRkCgaqtJa8vEFD6vKXiP");
12
10
  exports.METADATA_PROGRAM_ID = new web3_js_1.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
13
11
  exports.SEEDS = {
14
12
  PROTOCOL: Buffer.from("protocol"),