@voltr/vault-sdk 1.0.14 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -1082,6 +1082,22 @@ export declare class VoltrClient extends AccountUtils {
1082
1082
  highestAssetPerLp: number;
1083
1083
  lastUpdatedTs: number;
1084
1084
  }>;
1085
+ /**
1086
+ * Fetches the breakdown of the LP supply for a vault
1087
+ * @param vault - Public key of the vault
1088
+ * @returns Promise resolving to the breakdown of the LP supply
1089
+ *
1090
+ * @example
1091
+ * ```typescript
1092
+ * const lpSupplyBreakdown = await client.getVaultLpSupplyBreakdown(vaultPubkey);
1093
+ * ```
1094
+ */
1095
+ getVaultLpSupplyBreakdown(vault: PublicKey): Promise<{
1096
+ circulating: BN;
1097
+ unharvestedFees: BN;
1098
+ unrealisedFees: BN;
1099
+ total: BN;
1100
+ }>;
1085
1101
  /**
1086
1102
  * Processes a withdrawal receipt into a standardized withdrawal info object
1087
1103
  * @private
@@ -1125,7 +1141,11 @@ export declare class VoltrClient extends AccountUtils {
1125
1141
  withdrawableFromTs: number;
1126
1142
  }[]>;
1127
1143
  calculateLockedProfit(lastUpdatedLockedProfit: BN, lockedProfitDegradationDuration: BN, currentTime: BN): BN;
1128
- calculateAssetsForWithdrawHelper(vaultTotalValue: BN, vaultLastUpdatedLockedProfit: BN, vaultLockedProfitDegradationDuration: BN, vaultAccumulatedLpAdminFees: BN, vaultAccumulatedLpManagerFees: BN, vaultAccumulatedLpProtocolFees: BN, vaultRedemptionFee: number, lpSupply: BN, lpAmount: BN): BN;
1144
+ /**
1145
+ * Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
1146
+ */
1147
+ private calculateUnrealisedLpFees;
1148
+ calculateAssetsForWithdrawHelper(vaultTotalValue: BN, vaultLastUpdatedLockedProfit: BN, vaultLockedProfitDegradationDuration: BN, vaultAccumulatedLpAdminFees: BN, vaultAccumulatedLpManagerFees: BN, vaultAccumulatedLpProtocolFees: BN, vaultRedemptionFeeBps: number, vaultManagementFeeBps: number, vaultLastManagementFeeUpdateTs: BN, lpSupply: BN, lpAmount: BN): BN;
1129
1149
  /**
1130
1150
  * Calculates the amount of assets that would be received for a given LP token amount
1131
1151
  *
package/dist/client.js CHANGED
@@ -1275,6 +1275,36 @@ class VoltrClient extends AccountUtils {
1275
1275
  lastUpdatedTs: vaultAccount.highWaterMark.lastUpdatedTs.toNumber(),
1276
1276
  };
1277
1277
  }
1278
+ /**
1279
+ * Fetches the breakdown of the LP supply for a vault
1280
+ * @param vault - Public key of the vault
1281
+ * @returns Promise resolving to the breakdown of the LP supply
1282
+ *
1283
+ * @example
1284
+ * ```typescript
1285
+ * const lpSupplyBreakdown = await client.getVaultLpSupplyBreakdown(vaultPubkey);
1286
+ * ```
1287
+ */
1288
+ async getVaultLpSupplyBreakdown(vault) {
1289
+ const [vaultAccount, lpMintInfo] = await Promise.all([
1290
+ this.fetchVaultAccount(vault),
1291
+ (0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
1292
+ ]);
1293
+ const circulating = new bn_js_1.default(lpMintInfo.supply.toString());
1294
+ const unharvestedFees = vaultAccount.feeState.accumulatedLpAdminFees
1295
+ .add(vaultAccount.feeState.accumulatedLpManagerFees)
1296
+ .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1297
+ const currentTotalLp = circulating.add(unharvestedFees);
1298
+ const unrealisedFees = this.calculateUnrealisedLpFees(currentTotalLp, vaultAccount.asset.totalValue, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vaultAccount.feeConfiguration.managerManagementFee +
1299
+ vaultAccount.feeConfiguration.adminManagementFee));
1300
+ const total = currentTotalLp.add(unrealisedFees);
1301
+ return {
1302
+ circulating,
1303
+ unharvestedFees,
1304
+ unrealisedFees,
1305
+ total,
1306
+ };
1307
+ }
1278
1308
  /**
1279
1309
  * Processes a withdrawal receipt into a standardized withdrawal info object
1280
1310
  * @private
@@ -1283,7 +1313,8 @@ class VoltrClient extends AccountUtils {
1283
1313
  const amountAssetToWithdrawDecimal = (0, decimals_1.convertDecimalBitsToDecimal)(receipt.account.amountAssetToWithdrawDecimalBits);
1284
1314
  const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
1285
1315
  const amountLpEscrowed = receipt.account.amountLpEscrowed;
1286
- 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, lpSupply, amountLpEscrowed).toNumber();
1316
+ 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 +
1317
+ vaultAccount.feeConfiguration.adminManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed).toNumber();
1287
1318
  // Cap the withdrawal amount to the initial request amount
1288
1319
  const amountAssetToWithdrawEffective = Math.min(amountAssetToWithdrawAtPresent, amountAssetToWithdrawAtRequest);
1289
1320
  return {
@@ -1346,7 +1377,37 @@ class VoltrClient extends AccountUtils {
1346
1377
  else
1347
1378
  return lockedProfit;
1348
1379
  }
1349
- calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFee, lpSupply, lpAmount) {
1380
+ /**
1381
+ * Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
1382
+ */
1383
+ calculateUnrealisedLpFees(currentTotalLp, assetTotalValue, lastManagementFeeUpdateTs, managementFeeBps) {
1384
+ if (lastManagementFeeUpdateTs.eq(new bn_js_1.default(0)) ||
1385
+ assetTotalValue.eq(new bn_js_1.default(0)) ||
1386
+ managementFeeBps.eq(new bn_js_1.default(0))) {
1387
+ return new bn_js_1.default(0);
1388
+ }
1389
+ const nowBn = new bn_js_1.default(Math.floor(Date.now() / 1000));
1390
+ const timeElapsed = bn_js_1.default.max(new bn_js_1.default(0), nowBn.sub(lastManagementFeeUpdateTs));
1391
+ if (timeElapsed.eq(new bn_js_1.default(0))) {
1392
+ return new bn_js_1.default(0);
1393
+ }
1394
+ const feeAmountInAsset = assetTotalValue
1395
+ .mul(timeElapsed)
1396
+ .mul(managementFeeBps)
1397
+ .div(constants_1.MAX_FEE_BPS_BN)
1398
+ .div(constants_1.ONE_YEAR_BN);
1399
+ const lpNumerator = feeAmountInAsset.mul(currentTotalLp);
1400
+ const lpDenominator = assetTotalValue.sub(feeAmountInAsset);
1401
+ if (lpDenominator.lte(new bn_js_1.default(0))) {
1402
+ return new bn_js_1.default(0);
1403
+ }
1404
+ const pendingLpToMint = lpNumerator
1405
+ .add(lpDenominator)
1406
+ .sub(new bn_js_1.default(1))
1407
+ .div(lpDenominator);
1408
+ return pendingLpToMint;
1409
+ }
1410
+ calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount) {
1350
1411
  if (lpSupply <= new bn_js_1.default(0))
1351
1412
  throw new Error("Invalid LP supply");
1352
1413
  if (vaultTotalValue <= new bn_js_1.default(0))
@@ -1356,12 +1417,14 @@ class VoltrClient extends AccountUtils {
1356
1417
  const unharvestedFeesLp = vaultAccumulatedLpAdminFees
1357
1418
  .add(vaultAccumulatedLpManagerFees)
1358
1419
  .add(vaultAccumulatedLpProtocolFees);
1359
- const lpSupplyInclFees = lpSupply.add(unharvestedFeesLp);
1420
+ const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1421
+ const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
1422
+ const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1360
1423
  // asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
1361
1424
  // asset_to_redeem_post_fee = asset_to_redeem_pre_fee * (10000 - redemption_fee_bps) / 10000
1362
1425
  const assetToRedeemNumerator = lpAmount
1363
1426
  .mul(totalUnlockedValue)
1364
- .mul(new bn_js_1.default(10000 - vaultRedemptionFee));
1427
+ .mul(new bn_js_1.default(10000 - vaultRedemptionFeeBps));
1365
1428
  const assetToRedeemDenominator = lpSupplyInclFees.mul(new bn_js_1.default(10000));
1366
1429
  const amount = assetToRedeemNumerator.div(assetToRedeemDenominator);
1367
1430
  return amount;
@@ -1389,7 +1452,8 @@ class VoltrClient extends AccountUtils {
1389
1452
  const vault = await this.fetchVaultAccount(vaultPk);
1390
1453
  const lpMint = this.findVaultLpMint(vaultPk);
1391
1454
  const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
1392
- 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, new bn_js_1.default(lp.supply.toString()), lpAmount);
1455
+ 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 +
1456
+ vault.feeConfiguration.adminManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount);
1393
1457
  return amount;
1394
1458
  }
1395
1459
  catch (e) {
@@ -1431,7 +1495,10 @@ class VoltrClient extends AccountUtils {
1431
1495
  const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1432
1496
  .add(vault.feeState.accumulatedLpManagerFees)
1433
1497
  .add(vault.feeState.accumulatedLpProtocolFees);
1434
- const lpSupplyInclFees = lpSupply.add(unharvestedFeesLp);
1498
+ const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1499
+ const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1500
+ vault.feeConfiguration.adminManagementFee));
1501
+ const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1435
1502
  // lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
1436
1503
  // lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
1437
1504
  const lpToBurnNumerator = assetAmount
@@ -1471,7 +1538,10 @@ class VoltrClient extends AccountUtils {
1471
1538
  const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1472
1539
  .add(vault.feeState.accumulatedLpManagerFees)
1473
1540
  .add(vault.feeState.accumulatedLpProtocolFees);
1474
- const lpSupplyInclFees = lpSupply.add(unharvestedFeesLp);
1541
+ const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
1542
+ const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1543
+ vault.feeConfiguration.adminManagementFee));
1544
+ const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1475
1545
  // If the pool is empty, mint LP tokens 1:1 with deposit
1476
1546
  if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
1477
1547
  const assetMint = await (0, spl_token_1.getMint)(this.conn, vault.asset.mint, this.provider.opts.commitment);
@@ -1,4 +1,5 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
+ import BN from "bn.js";
2
3
  export declare const VAULT_PROGRAM_ID: PublicKey;
3
4
  export declare const LENDING_ADAPTOR_PROGRAM_ID: PublicKey;
4
5
  export declare const DRIFT_ADAPTOR_PROGRAM_ID: PublicKey;
@@ -17,3 +18,5 @@ export declare const SEEDS: {
17
18
  STRATEGY: Buffer<ArrayBuffer>;
18
19
  METADATA: Buffer<ArrayBuffer>;
19
20
  };
21
+ export declare const ONE_YEAR_BN: BN;
22
+ export declare const MAX_FEE_BPS_BN: BN;
package/dist/constants.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.DRIFT_ADAPTOR_PROGRAM_ID = exports.LENDING_ADAPTOR_PROGRAM_ID = exports.VAULT_PROGRAM_ID = void 0;
4
7
  const web3_js_1 = require("@solana/web3.js");
8
+ const bn_js_1 = __importDefault(require("bn.js"));
5
9
  exports.VAULT_PROGRAM_ID = new web3_js_1.PublicKey("vVoLTRjQmtFpiYoegx285Ze4gsLJ8ZxgFKVcuvmG1a8");
6
10
  exports.LENDING_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("aVoLTRCRt3NnnchvLYH6rMYehJHwM5m45RmLBZq7PGz");
7
11
  exports.DRIFT_ADAPTOR_PROGRAM_ID = new web3_js_1.PublicKey("EBN93eXs5fHGBABuajQqdsKRkCgaqtJa8vEFD6vKXiP");
@@ -21,3 +25,5 @@ exports.SEEDS = {
21
25
  STRATEGY: Buffer.from("strategy"),
22
26
  METADATA: Buffer.from("metadata"),
23
27
  };
28
+ exports.ONE_YEAR_BN = new bn_js_1.default(365 * 24 * 60 * 60);
29
+ exports.MAX_FEE_BPS_BN = new bn_js_1.default(10000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltr/vault-sdk",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "SDK for interacting with Voltr Protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",