@voltr/vault-sdk 1.0.19 → 1.0.21

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
@@ -1050,6 +1313,31 @@ class VoltrClient extends AccountUtils {
1050
1313
  })
1051
1314
  .instruction();
1052
1315
  }
1316
+ /**
1317
+ * Creates an instruction to calibrate the high water mark without fee clawback (unsafe)
1318
+ * @param {Object} params - Parameters for calibrating the high water mark
1319
+ * @param {PublicKey} params.vault - Public key of the vault (must be whitelisted)
1320
+ * @param {PublicKey} params.admin - Public key of the admin
1321
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for unsafe calibration
1322
+ * @throws {Error} If instruction creation fails or vault is not whitelisted
1323
+ *
1324
+ * @example
1325
+ * ```typescript
1326
+ * const ix = await client.createCalibrateHighWaterMarkUnsafeIx({
1327
+ * vault: vaultPubkey,
1328
+ * admin: adminPubkey,
1329
+ * });
1330
+ * ```
1331
+ */
1332
+ async createCalibrateHighWaterMarkUnsafeIx({ vault, admin, }) {
1333
+ return await this.vaultProgram.methods
1334
+ .calibrateHighWaterMarkUnsafe()
1335
+ .accountsPartial({
1336
+ vault,
1337
+ admin,
1338
+ })
1339
+ .instruction();
1340
+ }
1053
1341
  /**
1054
1342
  * Creates an instruction to create LP metadata
1055
1343
  * @param {Object} createLpMetadataArgs - Parameters for creating LP metadata
@@ -1084,6 +1372,51 @@ class VoltrClient extends AccountUtils {
1084
1372
  })
1085
1373
  .instruction();
1086
1374
  }
1375
+ /**
1376
+ * Creates an instruction to update per-vault protocol fees (admin-only, protocol level)
1377
+ *
1378
+ * @param {ProtocolFeeField} field - The protocol fee field to update
1379
+ * @param {number} feeBps - The new fee value in basis points
1380
+ * @param {Object} params - Parameters for updating the protocol fee
1381
+ * @param {PublicKey} params.admin - Public key of the protocol admin
1382
+ * @param {PublicKey} params.vault - Public key of the vault
1383
+ * @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol fee
1384
+ *
1385
+ * @throws {Error} If the total fee (protocol + admin + manager) exceeds 10000 BPS
1386
+ *
1387
+ * @example
1388
+ * ```typescript
1389
+ * const ix = await client.createUpdateVaultProtocolFeeIx(
1390
+ * ProtocolFeeField.ProtocolPerformanceFee,
1391
+ * 500, // 5%
1392
+ * {
1393
+ * admin: protocolAdminPubkey,
1394
+ * vault: vaultPubkey,
1395
+ * }
1396
+ * );
1397
+ * ```
1398
+ */
1399
+ async createUpdateVaultProtocolFeeIx(field, feeBps, { admin, vault, }) {
1400
+ const fieldToVariant = {
1401
+ [types_1.ProtocolFeeField.ProtocolPerformanceFee]: {
1402
+ protocolPerformanceFee: {},
1403
+ },
1404
+ [types_1.ProtocolFeeField.ProtocolManagementFee]: {
1405
+ protocolManagementFee: {},
1406
+ },
1407
+ };
1408
+ const fieldVariant = fieldToVariant[field];
1409
+ if (!fieldVariant) {
1410
+ throw new Error(`Unknown protocol fee field: ${field}`);
1411
+ }
1412
+ return await this.vaultProgram.methods
1413
+ .updateVaultProtocolFee(fieldVariant, feeBps)
1414
+ .accountsPartial({
1415
+ admin,
1416
+ vault,
1417
+ })
1418
+ .instruction();
1419
+ }
1087
1420
  // --------------------------------------- Account Fetching All
1088
1421
  /**
1089
1422
  * Fetches all strategy init receipt accounts
@@ -1163,6 +1496,19 @@ class VoltrClient extends AccountUtils {
1163
1496
  * @param vault - Public key of the vault
1164
1497
  * @returns Promise resolving to the vault account data
1165
1498
  */
1499
+ /**
1500
+ * Fetches the protocol account's data
1501
+ * @returns Promise resolving to the protocol account data
1502
+ *
1503
+ * @example
1504
+ * ```typescript
1505
+ * const protocolAccount = await client.fetchProtocolAccount();
1506
+ * ```
1507
+ */
1508
+ async fetchProtocolAccount() {
1509
+ const protocol = this.findProtocol();
1510
+ return await this.vaultProgram.account.protocol.fetch(protocol, this.provider.opts.commitment);
1511
+ }
1166
1512
  async fetchVaultAccount(vault) {
1167
1513
  return await this.vaultProgram.account.vault.fetch(vault, this.provider.opts.commitment);
1168
1514
  }
@@ -1257,6 +1603,20 @@ class VoltrClient extends AccountUtils {
1257
1603
  const vaultAccount = await this.fetchVaultAccount(vault);
1258
1604
  return vaultAccount.feeState.accumulatedLpManagerFees;
1259
1605
  }
1606
+ /**
1607
+ * Fetches the accumulated protocol fees for a vault
1608
+ * @param vault - Public key of the vault
1609
+ * @returns Promise resolving to the accumulated protocol fees
1610
+ *
1611
+ * @example
1612
+ * ```typescript
1613
+ * const accumulatedProtocolFees = await client.getAccumulatedProtocolFeesForVault(vaultPubkey);
1614
+ * ```
1615
+ */
1616
+ async getAccumulatedProtocolFeesForVault(vault) {
1617
+ const vaultAccount = await this.fetchVaultAccount(vault);
1618
+ return vaultAccount.feeState.accumulatedLpProtocolFees;
1619
+ }
1260
1620
  /**
1261
1621
  * Fetches the current asset per LP for a vault
1262
1622
  * @param vault - Public key of the vault
@@ -1274,7 +1634,8 @@ class VoltrClient extends AccountUtils {
1274
1634
  const unharvestedFeesLp = vaultAccount.feeState.accumulatedLpAdminFees
1275
1635
  .add(vaultAccount.feeState.accumulatedLpManagerFees)
1276
1636
  .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1277
- const totalLpSupply = unharvestedFeesLp.add(lpSupply);
1637
+ const deadWeight = vaultAccount.deadWeight;
1638
+ const totalLpSupply = unharvestedFeesLp.add(lpSupply).add(deadWeight);
1278
1639
  const currentAssetPerLp = vaultAccount.asset.totalValue.toNumber() / totalLpSupply.toNumber();
1279
1640
  return currentAssetPerLp;
1280
1641
  }
@@ -1315,9 +1676,11 @@ class VoltrClient extends AccountUtils {
1315
1676
  const unharvestedFees = vaultAccount.feeState.accumulatedLpAdminFees
1316
1677
  .add(vaultAccount.feeState.accumulatedLpManagerFees)
1317
1678
  .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1318
- const currentTotalLp = circulating.add(unharvestedFees);
1679
+ const deadWeight = vaultAccount.deadWeight;
1680
+ const currentTotalLp = circulating.add(unharvestedFees).add(deadWeight);
1319
1681
  const unrealisedFees = this.calculateUnrealisedLpFees(currentTotalLp, vaultAccount.asset.totalValue, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vaultAccount.feeConfiguration.managerManagementFee +
1320
- vaultAccount.feeConfiguration.adminManagementFee));
1682
+ vaultAccount.feeConfiguration.adminManagementFee +
1683
+ vaultAccount.feeConfiguration.protocolManagementFee));
1321
1684
  const total = currentTotalLp.add(unrealisedFees);
1322
1685
  return {
1323
1686
  circulating,
@@ -1335,7 +1698,8 @@ class VoltrClient extends AccountUtils {
1335
1698
  const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
1336
1699
  const amountLpEscrowed = receipt.account.amountLpEscrowed;
1337
1700
  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();
1701
+ vaultAccount.feeConfiguration.adminManagementFee +
1702
+ vaultAccount.feeConfiguration.protocolManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed, vaultAccount.deadWeight).toNumber();
1339
1703
  // Cap the withdrawal amount to the initial request amount
1340
1704
  const amountAssetToWithdrawEffective = Math.min(amountAssetToWithdrawAtPresent, amountAssetToWithdrawAtRequest);
1341
1705
  return {
@@ -1428,7 +1792,7 @@ class VoltrClient extends AccountUtils {
1428
1792
  .div(lpDenominator);
1429
1793
  return pendingLpToMint;
1430
1794
  }
1431
- calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount) {
1795
+ calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount, deadWeight = new bn_js_1.default(0)) {
1432
1796
  if (lpSupply <= new bn_js_1.default(0))
1433
1797
  throw new Error("Invalid LP supply");
1434
1798
  if (vaultTotalValue <= new bn_js_1.default(0))
@@ -1438,7 +1802,9 @@ class VoltrClient extends AccountUtils {
1438
1802
  const unharvestedFeesLp = vaultAccumulatedLpAdminFees
1439
1803
  .add(vaultAccumulatedLpManagerFees)
1440
1804
  .add(vaultAccumulatedLpProtocolFees);
1441
- const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1805
+ const lpSupplyInclAccumulatedFees = lpSupply
1806
+ .add(unharvestedFeesLp)
1807
+ .add(deadWeight);
1442
1808
  const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
1443
1809
  const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1444
1810
  // asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
@@ -1474,7 +1840,8 @@ class VoltrClient extends AccountUtils {
1474
1840
  const lpMint = this.findVaultLpMint(vaultPk);
1475
1841
  const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
1476
1842
  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);
1843
+ vault.feeConfiguration.adminManagementFee +
1844
+ vault.feeConfiguration.protocolManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount, vault.deadWeight);
1478
1845
  return amount;
1479
1846
  }
1480
1847
  catch (e) {
@@ -1516,9 +1883,12 @@ class VoltrClient extends AccountUtils {
1516
1883
  const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1517
1884
  .add(vault.feeState.accumulatedLpManagerFees)
1518
1885
  .add(vault.feeState.accumulatedLpProtocolFees);
1519
- const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1886
+ const lpSupplyInclAccumulatedFees = lpSupply
1887
+ .add(unharvestedFeesLp)
1888
+ .add(vault.deadWeight);
1520
1889
  const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1521
- vault.feeConfiguration.adminManagementFee));
1890
+ vault.feeConfiguration.adminManagementFee +
1891
+ vault.feeConfiguration.protocolManagementFee));
1522
1892
  const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1523
1893
  // lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
1524
1894
  // lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
@@ -1559,9 +1929,12 @@ class VoltrClient extends AccountUtils {
1559
1929
  const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1560
1930
  .add(vault.feeState.accumulatedLpManagerFees)
1561
1931
  .add(vault.feeState.accumulatedLpProtocolFees);
1562
- const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1932
+ const lpSupplyInclAccumulatedFees = lpSupply
1933
+ .add(unharvestedFeesLp)
1934
+ .add(vault.deadWeight);
1563
1935
  const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1564
- vault.feeConfiguration.adminManagementFee));
1936
+ vault.feeConfiguration.adminManagementFee +
1937
+ vault.feeConfiguration.protocolManagementFee));
1565
1938
  const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1566
1939
  // If the pool is empty, mint LP tokens 1:1 with deposit
1567
1940
  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"),