@voltr/vault-sdk 1.0.15 → 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 +20 -1
- package/dist/client.js +47 -8
- package/package.json +1 -1
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,10 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
1125
1141
|
withdrawableFromTs: number;
|
|
1126
1142
|
}[]>;
|
|
1127
1143
|
calculateLockedProfit(lastUpdatedLockedProfit: BN, lockedProfitDegradationDuration: BN, currentTime: BN): BN;
|
|
1128
|
-
|
|
1144
|
+
/**
|
|
1145
|
+
* Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
|
|
1146
|
+
*/
|
|
1147
|
+
private calculateUnrealisedLpFees;
|
|
1129
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;
|
|
1130
1149
|
/**
|
|
1131
1150
|
* Calculates the amount of assets that would be received for a given LP token amount
|
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
|
|
@@ -1347,29 +1377,35 @@ class VoltrClient extends AccountUtils {
|
|
|
1347
1377
|
else
|
|
1348
1378
|
return lockedProfit;
|
|
1349
1379
|
}
|
|
1350
|
-
|
|
1380
|
+
/**
|
|
1381
|
+
* Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
|
|
1382
|
+
*/
|
|
1383
|
+
calculateUnrealisedLpFees(currentTotalLp, assetTotalValue, lastManagementFeeUpdateTs, managementFeeBps) {
|
|
1351
1384
|
if (lastManagementFeeUpdateTs.eq(new bn_js_1.default(0)) ||
|
|
1352
1385
|
assetTotalValue.eq(new bn_js_1.default(0)) ||
|
|
1353
1386
|
managementFeeBps.eq(new bn_js_1.default(0))) {
|
|
1354
|
-
return
|
|
1387
|
+
return new bn_js_1.default(0);
|
|
1355
1388
|
}
|
|
1356
1389
|
const nowBn = new bn_js_1.default(Math.floor(Date.now() / 1000));
|
|
1357
1390
|
const timeElapsed = bn_js_1.default.max(new bn_js_1.default(0), nowBn.sub(lastManagementFeeUpdateTs));
|
|
1358
1391
|
if (timeElapsed.eq(new bn_js_1.default(0))) {
|
|
1359
|
-
return
|
|
1392
|
+
return new bn_js_1.default(0);
|
|
1360
1393
|
}
|
|
1361
1394
|
const feeAmountInAsset = assetTotalValue
|
|
1362
1395
|
.mul(timeElapsed)
|
|
1363
|
-
.mul(
|
|
1396
|
+
.mul(managementFeeBps)
|
|
1364
1397
|
.div(constants_1.MAX_FEE_BPS_BN)
|
|
1365
1398
|
.div(constants_1.ONE_YEAR_BN);
|
|
1366
1399
|
const lpNumerator = feeAmountInAsset.mul(currentTotalLp);
|
|
1367
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
|
+
}
|
|
1368
1404
|
const pendingLpToMint = lpNumerator
|
|
1369
1405
|
.add(lpDenominator)
|
|
1370
1406
|
.sub(new bn_js_1.default(1))
|
|
1371
1407
|
.div(lpDenominator);
|
|
1372
|
-
return
|
|
1408
|
+
return pendingLpToMint;
|
|
1373
1409
|
}
|
|
1374
1410
|
calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount) {
|
|
1375
1411
|
if (lpSupply <= new bn_js_1.default(0))
|
|
@@ -1382,7 +1418,8 @@ class VoltrClient extends AccountUtils {
|
|
|
1382
1418
|
.add(vaultAccumulatedLpManagerFees)
|
|
1383
1419
|
.add(vaultAccumulatedLpProtocolFees);
|
|
1384
1420
|
const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
|
|
1385
|
-
const
|
|
1421
|
+
const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
|
|
1422
|
+
const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
|
|
1386
1423
|
// asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
|
|
1387
1424
|
// asset_to_redeem_post_fee = asset_to_redeem_pre_fee * (10000 - redemption_fee_bps) / 10000
|
|
1388
1425
|
const assetToRedeemNumerator = lpAmount
|
|
@@ -1459,8 +1496,9 @@ class VoltrClient extends AccountUtils {
|
|
|
1459
1496
|
.add(vault.feeState.accumulatedLpManagerFees)
|
|
1460
1497
|
.add(vault.feeState.accumulatedLpProtocolFees);
|
|
1461
1498
|
const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
|
|
1462
|
-
const
|
|
1499
|
+
const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
|
|
1463
1500
|
vault.feeConfiguration.adminManagementFee));
|
|
1501
|
+
const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
|
|
1464
1502
|
// lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
|
|
1465
1503
|
// lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
|
|
1466
1504
|
const lpToBurnNumerator = assetAmount
|
|
@@ -1501,8 +1539,9 @@ class VoltrClient extends AccountUtils {
|
|
|
1501
1539
|
.add(vault.feeState.accumulatedLpManagerFees)
|
|
1502
1540
|
.add(vault.feeState.accumulatedLpProtocolFees);
|
|
1503
1541
|
const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
|
|
1504
|
-
const
|
|
1542
|
+
const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
|
|
1505
1543
|
vault.feeConfiguration.adminManagementFee));
|
|
1544
|
+
const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
|
|
1506
1545
|
// If the pool is empty, mint LP tokens 1:1 with deposit
|
|
1507
1546
|
if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
|
|
1508
1547
|
const assetMint = await (0, spl_token_1.getMint)(this.conn, vault.asset.mint, this.provider.opts.commitment);
|