@voltr/vault-sdk 1.0.14 → 1.0.15
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 +2 -1
- package/dist/client.js +38 -7
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +7 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1125,7 +1125,8 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
1125
1125
|
withdrawableFromTs: number;
|
|
1126
1126
|
}[]>;
|
|
1127
1127
|
calculateLockedProfit(lastUpdatedLockedProfit: BN, lockedProfitDegradationDuration: BN, currentTime: BN): BN;
|
|
1128
|
-
|
|
1128
|
+
private getProjectedLpSupply;
|
|
1129
|
+
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
1130
|
/**
|
|
1130
1131
|
* Calculates the amount of assets that would be received for a given LP token amount
|
|
1131
1132
|
*
|
package/dist/client.js
CHANGED
|
@@ -1283,7 +1283,8 @@ class VoltrClient extends AccountUtils {
|
|
|
1283
1283
|
const amountAssetToWithdrawDecimal = (0, decimals_1.convertDecimalBitsToDecimal)(receipt.account.amountAssetToWithdrawDecimalBits);
|
|
1284
1284
|
const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
|
|
1285
1285
|
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,
|
|
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, vaultAccount.feeConfiguration.managerManagementFee +
|
|
1287
|
+
vaultAccount.feeConfiguration.adminManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed).toNumber();
|
|
1287
1288
|
// Cap the withdrawal amount to the initial request amount
|
|
1288
1289
|
const amountAssetToWithdrawEffective = Math.min(amountAssetToWithdrawAtPresent, amountAssetToWithdrawAtRequest);
|
|
1289
1290
|
return {
|
|
@@ -1346,7 +1347,31 @@ class VoltrClient extends AccountUtils {
|
|
|
1346
1347
|
else
|
|
1347
1348
|
return lockedProfit;
|
|
1348
1349
|
}
|
|
1349
|
-
|
|
1350
|
+
getProjectedLpSupply(currentTotalLp, assetTotalValue, lastManagementFeeUpdateTs, managementFeeBps) {
|
|
1351
|
+
if (lastManagementFeeUpdateTs.eq(new bn_js_1.default(0)) ||
|
|
1352
|
+
assetTotalValue.eq(new bn_js_1.default(0)) ||
|
|
1353
|
+
managementFeeBps.eq(new bn_js_1.default(0))) {
|
|
1354
|
+
return currentTotalLp;
|
|
1355
|
+
}
|
|
1356
|
+
const nowBn = new bn_js_1.default(Math.floor(Date.now() / 1000));
|
|
1357
|
+
const timeElapsed = bn_js_1.default.max(new bn_js_1.default(0), nowBn.sub(lastManagementFeeUpdateTs));
|
|
1358
|
+
if (timeElapsed.eq(new bn_js_1.default(0))) {
|
|
1359
|
+
return currentTotalLp;
|
|
1360
|
+
}
|
|
1361
|
+
const feeAmountInAsset = assetTotalValue
|
|
1362
|
+
.mul(timeElapsed)
|
|
1363
|
+
.mul(new bn_js_1.default(managementFeeBps))
|
|
1364
|
+
.div(constants_1.MAX_FEE_BPS_BN)
|
|
1365
|
+
.div(constants_1.ONE_YEAR_BN);
|
|
1366
|
+
const lpNumerator = feeAmountInAsset.mul(currentTotalLp);
|
|
1367
|
+
const lpDenominator = assetTotalValue.sub(feeAmountInAsset);
|
|
1368
|
+
const pendingLpToMint = lpNumerator
|
|
1369
|
+
.add(lpDenominator)
|
|
1370
|
+
.sub(new bn_js_1.default(1))
|
|
1371
|
+
.div(lpDenominator);
|
|
1372
|
+
return currentTotalLp.add(pendingLpToMint);
|
|
1373
|
+
}
|
|
1374
|
+
calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount) {
|
|
1350
1375
|
if (lpSupply <= new bn_js_1.default(0))
|
|
1351
1376
|
throw new Error("Invalid LP supply");
|
|
1352
1377
|
if (vaultTotalValue <= new bn_js_1.default(0))
|
|
@@ -1356,12 +1381,13 @@ class VoltrClient extends AccountUtils {
|
|
|
1356
1381
|
const unharvestedFeesLp = vaultAccumulatedLpAdminFees
|
|
1357
1382
|
.add(vaultAccumulatedLpManagerFees)
|
|
1358
1383
|
.add(vaultAccumulatedLpProtocolFees);
|
|
1359
|
-
const
|
|
1384
|
+
const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
|
|
1385
|
+
const lpSupplyInclFees = this.getProjectedLpSupply(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
|
|
1360
1386
|
// asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
|
|
1361
1387
|
// asset_to_redeem_post_fee = asset_to_redeem_pre_fee * (10000 - redemption_fee_bps) / 10000
|
|
1362
1388
|
const assetToRedeemNumerator = lpAmount
|
|
1363
1389
|
.mul(totalUnlockedValue)
|
|
1364
|
-
.mul(new bn_js_1.default(10000 -
|
|
1390
|
+
.mul(new bn_js_1.default(10000 - vaultRedemptionFeeBps));
|
|
1365
1391
|
const assetToRedeemDenominator = lpSupplyInclFees.mul(new bn_js_1.default(10000));
|
|
1366
1392
|
const amount = assetToRedeemNumerator.div(assetToRedeemDenominator);
|
|
1367
1393
|
return amount;
|
|
@@ -1389,7 +1415,8 @@ class VoltrClient extends AccountUtils {
|
|
|
1389
1415
|
const vault = await this.fetchVaultAccount(vaultPk);
|
|
1390
1416
|
const lpMint = this.findVaultLpMint(vaultPk);
|
|
1391
1417
|
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,
|
|
1418
|
+
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 +
|
|
1419
|
+
vault.feeConfiguration.adminManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount);
|
|
1393
1420
|
return amount;
|
|
1394
1421
|
}
|
|
1395
1422
|
catch (e) {
|
|
@@ -1431,7 +1458,9 @@ class VoltrClient extends AccountUtils {
|
|
|
1431
1458
|
const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
|
|
1432
1459
|
.add(vault.feeState.accumulatedLpManagerFees)
|
|
1433
1460
|
.add(vault.feeState.accumulatedLpProtocolFees);
|
|
1434
|
-
const
|
|
1461
|
+
const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
|
|
1462
|
+
const lpSupplyInclFees = this.getProjectedLpSupply(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
|
|
1463
|
+
vault.feeConfiguration.adminManagementFee));
|
|
1435
1464
|
// lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
|
|
1436
1465
|
// lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
|
|
1437
1466
|
const lpToBurnNumerator = assetAmount
|
|
@@ -1471,7 +1500,9 @@ class VoltrClient extends AccountUtils {
|
|
|
1471
1500
|
const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
|
|
1472
1501
|
.add(vault.feeState.accumulatedLpManagerFees)
|
|
1473
1502
|
.add(vault.feeState.accumulatedLpProtocolFees);
|
|
1474
|
-
const
|
|
1503
|
+
const lpSupplyInclAccumulatedFees = lpSupply.add(unharvestedFeesLp);
|
|
1504
|
+
const lpSupplyInclFees = this.getProjectedLpSupply(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
|
|
1505
|
+
vault.feeConfiguration.adminManagementFee));
|
|
1475
1506
|
// If the pool is empty, mint LP tokens 1:1 with deposit
|
|
1476
1507
|
if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
|
|
1477
1508
|
const assetMint = await (0, spl_token_1.getMint)(this.conn, vault.asset.mint, this.provider.opts.commitment);
|
package/dist/constants.d.ts
CHANGED
|
@@ -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);
|