@voltr/vault-sdk 1.0.21 → 1.1.0

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
@@ -1478,12 +1478,12 @@ export declare class VoltrClient extends AccountUtils {
1478
1478
  amountLpEscrowed: number;
1479
1479
  withdrawableFromTs: number;
1480
1480
  }[]>;
1481
- calculateLockedProfit(lastUpdatedLockedProfit: BN, lockedProfitDegradationDuration: BN, currentTime: BN): BN;
1481
+ calculateLockedProfit(lastUpdatedLockedProfit: BN, lastReport: BN, lockedProfitDegradationDuration: BN, currentTime: BN): BN;
1482
1482
  /**
1483
1483
  * Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
1484
1484
  */
1485
1485
  private calculateUnrealisedLpFees;
1486
- calculateAssetsForWithdrawHelper(vaultTotalValue: BN, vaultLastUpdatedLockedProfit: BN, vaultLockedProfitDegradationDuration: BN, vaultAccumulatedLpAdminFees: BN, vaultAccumulatedLpManagerFees: BN, vaultAccumulatedLpProtocolFees: BN, vaultRedemptionFeeBps: number, vaultManagementFeeBps: number, vaultLastManagementFeeUpdateTs: BN, lpSupply: BN, lpAmount: BN, deadWeight?: BN): BN;
1486
+ calculateAssetsForWithdrawHelper(vaultTotalValue: BN, vaultLastUpdatedLockedProfit: BN, vaultLastReport: BN, vaultLockedProfitDegradationDuration: BN, vaultAccumulatedLpAdminFees: BN, vaultAccumulatedLpManagerFees: BN, vaultAccumulatedLpProtocolFees: BN, vaultRedemptionFeeBps: number, vaultManagementFeeBps: number, vaultLastManagementFeeUpdateTs: BN, lpSupply: BN, lpAmount: BN, deadWeight?: BN): BN;
1487
1487
  /**
1488
1488
  * Calculates the amount of assets that would be received for a given LP token amount
1489
1489
  *
package/dist/client.js CHANGED
@@ -1697,7 +1697,7 @@ class VoltrClient extends AccountUtils {
1697
1697
  const amountAssetToWithdrawDecimal = (0, decimals_1.convertDecimalBitsToDecimal)(receipt.account.amountAssetToWithdrawDecimalBits);
1698
1698
  const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
1699
1699
  const amountLpEscrowed = receipt.account.amountLpEscrowed;
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 +
1700
+ const amountAssetToWithdrawAtPresent = this.calculateAssetsForWithdrawHelper(vaultAccount.asset.totalValue, vaultAccount.lockedProfitState.lastUpdatedLockedProfit, vaultAccount.lockedProfitState.lastReport, vaultAccount.vaultConfiguration.lockedProfitDegradationDuration, vaultAccount.feeState.accumulatedLpAdminFees, vaultAccount.feeState.accumulatedLpManagerFees, vaultAccount.feeState.accumulatedLpProtocolFees, vaultAccount.feeConfiguration.redemptionFee, vaultAccount.feeConfiguration.managerManagementFee +
1701
1701
  vaultAccount.feeConfiguration.adminManagementFee +
1702
1702
  vaultAccount.feeConfiguration.protocolManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed, vaultAccount.deadWeight).toNumber();
1703
1703
  // Cap the withdrawal amount to the initial request amount
@@ -1750,17 +1750,15 @@ class VoltrClient extends AccountUtils {
1750
1750
  const lpSupply = new bn_js_1.default(lp.supply.toString());
1751
1751
  return Promise.all(requestWithdrawVaultReceipts.map((receipt) => this.processWithdrawalReceipt(receipt, vaultAccount, lpSupply)));
1752
1752
  }
1753
- calculateLockedProfit(lastUpdatedLockedProfit, lockedProfitDegradationDuration, currentTime) {
1753
+ calculateLockedProfit(lastUpdatedLockedProfit, lastReport, lockedProfitDegradationDuration, currentTime) {
1754
1754
  if (lockedProfitDegradationDuration.eq(new bn_js_1.default(0)))
1755
1755
  return new bn_js_1.default(0);
1756
- const duration = currentTime.sub(lastUpdatedLockedProfit);
1757
- const lockedProfit = lastUpdatedLockedProfit
1758
- .mul(lockedProfitDegradationDuration.sub(duration))
1759
- .div(lockedProfitDegradationDuration);
1756
+ const duration = currentTime.sub(lastReport);
1760
1757
  if (duration.gt(lockedProfitDegradationDuration))
1761
1758
  return new bn_js_1.default(0);
1762
- else
1763
- return lockedProfit;
1759
+ return lastUpdatedLockedProfit
1760
+ .mul(lockedProfitDegradationDuration.sub(duration))
1761
+ .div(lockedProfitDegradationDuration);
1764
1762
  }
1765
1763
  /**
1766
1764
  * Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
@@ -1792,12 +1790,12 @@ class VoltrClient extends AccountUtils {
1792
1790
  .div(lpDenominator);
1793
1791
  return pendingLpToMint;
1794
1792
  }
1795
- calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount, deadWeight = new bn_js_1.default(0)) {
1793
+ calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLastReport, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount, deadWeight = new bn_js_1.default(0)) {
1796
1794
  if (lpSupply <= new bn_js_1.default(0))
1797
1795
  throw new Error("Invalid LP supply");
1798
1796
  if (vaultTotalValue <= new bn_js_1.default(0))
1799
1797
  throw new Error("Invalid total assets");
1800
- const lockedProfit = this.calculateLockedProfit(vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, new bn_js_1.default(Date.now() / 1000));
1798
+ const lockedProfit = this.calculateLockedProfit(vaultLastUpdatedLockedProfit, vaultLastReport, vaultLockedProfitDegradationDuration, new bn_js_1.default(Math.floor(Date.now() / 1000)));
1801
1799
  const totalUnlockedValue = vaultTotalValue.sub(lockedProfit);
1802
1800
  const unharvestedFeesLp = vaultAccumulatedLpAdminFees
1803
1801
  .add(vaultAccumulatedLpManagerFees)
@@ -1839,7 +1837,7 @@ class VoltrClient extends AccountUtils {
1839
1837
  const vault = await this.fetchVaultAccount(vaultPk);
1840
1838
  const lpMint = this.findVaultLpMint(vaultPk);
1841
1839
  const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
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 +
1840
+ const amount = this.calculateAssetsForWithdrawHelper(vault.asset.totalValue, vault.lockedProfitState.lastUpdatedLockedProfit, vault.lockedProfitState.lastReport, vault.vaultConfiguration.lockedProfitDegradationDuration, vault.feeState.accumulatedLpAdminFees, vault.feeState.accumulatedLpManagerFees, vault.feeState.accumulatedLpProtocolFees, vault.feeConfiguration.redemptionFee, vault.feeConfiguration.managerManagementFee +
1843
1841
  vault.feeConfiguration.adminManagementFee +
1844
1842
  vault.feeConfiguration.protocolManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount, vault.deadWeight);
1845
1843
  return amount;
@@ -1870,7 +1868,7 @@ class VoltrClient extends AccountUtils {
1870
1868
  try {
1871
1869
  const vault = await this.fetchVaultAccount(vaultPk);
1872
1870
  const totalValue = vault.asset.totalValue;
1873
- const lockedProfit = this.calculateLockedProfit(vault.lockedProfitState.lastUpdatedLockedProfit, vault.vaultConfiguration.lockedProfitDegradationDuration, new bn_js_1.default(Date.now() / 1000));
1871
+ const lockedProfit = this.calculateLockedProfit(vault.lockedProfitState.lastUpdatedLockedProfit, vault.lockedProfitState.lastReport, vault.vaultConfiguration.lockedProfitDegradationDuration, new bn_js_1.default(Math.floor(Date.now() / 1000)));
1874
1872
  const totalUnlockedValue = totalValue.sub(lockedProfit);
1875
1873
  const lpMint = this.findVaultLpMint(vaultPk);
1876
1874
  const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltr/vault-sdk",
3
- "version": "1.0.21",
3
+ "version": "1.1.0",
4
4
  "description": "SDK for interacting with Voltr Protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",