@morpho-org/blue-sdk 4.14.0-next.1 → 4.14.0-next.2

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/lib/errors.d.ts CHANGED
@@ -69,6 +69,14 @@ export declare namespace BlueErrors {
69
69
  constructor(deadline: bigint);
70
70
  }
71
71
  }
72
+ export declare namespace VaultV2Errors {
73
+ class InvalidInterestAccrual extends Error {
74
+ readonly vault: Address;
75
+ readonly timestamp: bigint;
76
+ readonly lastUpdate: bigint;
77
+ constructor(vault: Address, timestamp: bigint, lastUpdate: bigint);
78
+ }
79
+ }
72
80
  export interface ErrorClass<E extends Error> {
73
81
  new (...args: any[]): E;
74
82
  }
package/lib/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
3
+ exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
4
4
  exports._try = _try;
5
5
  const viem_1 = require("viem");
6
6
  class UnknownDataError extends Error {
@@ -141,6 +141,21 @@ var BlueErrors;
141
141
  }
142
142
  BlueErrors.ExpiredSignature = ExpiredSignature;
143
143
  })(BlueErrors || (exports.BlueErrors = BlueErrors = {}));
144
+ var VaultV2Errors;
145
+ (function (VaultV2Errors) {
146
+ class InvalidInterestAccrual extends Error {
147
+ vault;
148
+ timestamp;
149
+ lastUpdate;
150
+ constructor(vault, timestamp, lastUpdate) {
151
+ super(`invalid interest accrual on vault ${vault}: accrual timestamp ${timestamp} can't be prior to last update ${lastUpdate}`);
152
+ this.vault = vault;
153
+ this.timestamp = timestamp;
154
+ this.lastUpdate = lastUpdate;
155
+ }
156
+ }
157
+ VaultV2Errors.InvalidInterestAccrual = InvalidInterestAccrual;
158
+ })(VaultV2Errors || (exports.VaultV2Errors = VaultV2Errors = {}));
144
159
  function _try(accessor, ...errorClasses) {
145
160
  const maybeCatchError = (error) => {
146
161
  if (errorClasses.length === 0 ||
package/lib/index.d.ts CHANGED
@@ -11,5 +11,4 @@ export * from "./holding/index.js";
11
11
  export * from "./position/index.js";
12
12
  export * from "./vault/index.js";
13
13
  export * from "./preLiquidation.js";
14
- export * from "./vault-v2/index.js";
15
14
  export * from "./utils.js";
package/lib/index.js CHANGED
@@ -27,5 +27,4 @@ __exportStar(require("./holding/index.js"), exports);
27
27
  __exportStar(require("./position/index.js"), exports);
28
28
  __exportStar(require("./vault/index.js"), exports);
29
29
  __exportStar(require("./preLiquidation.js"), exports);
30
- __exportStar(require("./vault-v2/index.js"), exports);
31
30
  __exportStar(require("./utils.js"), exports);
@@ -5,3 +5,4 @@ export * from "./VaultMarketConfig.js";
5
5
  export * from "./VaultMarketPublicAllocatorConfig.js";
6
6
  export * from "./VaultUser.js";
7
7
  export * from "./Vault.js";
8
+ export * from "./v2";
@@ -21,3 +21,4 @@ __exportStar(require("./VaultMarketConfig.js"), exports);
21
21
  __exportStar(require("./VaultMarketPublicAllocatorConfig.js"), exports);
22
22
  __exportStar(require("./VaultUser.js"), exports);
23
23
  __exportStar(require("./Vault.js"), exports);
24
+ __exportStar(require("./v2"), exports);
@@ -1,42 +1,47 @@
1
1
  import type { Address } from "viem";
2
- import { type RoundingDirection } from "../math";
3
- import { type IToken, WrappedToken } from "../token";
4
- import type { BigIntish } from "../types";
2
+ import { type RoundingDirection } from "../../math";
3
+ import { type IToken, WrappedToken } from "../../token";
4
+ import type { BigIntish } from "../../types";
5
5
  import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter";
6
6
  export interface IVaultV2 extends IToken {
7
7
  asset: Address;
8
- totalSupply: bigint;
8
+ /**
9
+ * The total assets, *including* virtually accrued interest.
10
+ */
9
11
  totalAssets: bigint;
10
- performanceFee: bigint;
11
- managementFee: bigint;
12
+ /**
13
+ * The total assets, *excluding* virtually accrued interest.
14
+ */
15
+ _totalAssets: bigint;
16
+ /**
17
+ * The total supply of shares.
18
+ */
19
+ totalSupply: bigint;
12
20
  virtualShares: bigint;
21
+ maxRate: bigint;
13
22
  lastUpdate: bigint;
14
23
  adapters: Address[];
15
- maxRate: bigint;
16
24
  liquidityAdapter: Address;
25
+ performanceFee: bigint;
26
+ managementFee: bigint;
17
27
  performanceFeeRecipient: Address;
18
28
  managementFeeRecipient: Address;
19
29
  }
20
30
  export declare class VaultV2 extends WrappedToken implements IVaultV2 {
21
31
  readonly asset: Address;
22
- /**
23
- * The ERC4626 vault's total supply of shares.
24
- */
25
- totalSupply: bigint;
26
- /**
27
- * The ERC4626 vault's total assets, without accrued interest
28
- */
29
32
  totalAssets: bigint;
33
+ _totalAssets: bigint;
34
+ totalSupply: bigint;
30
35
  virtualShares: bigint;
36
+ maxRate: bigint;
31
37
  lastUpdate: bigint;
32
38
  adapters: Address[];
33
- maxRate: bigint;
39
+ liquidityAdapter: Address;
34
40
  performanceFee: bigint;
35
41
  managementFee: bigint;
36
- liquidityAdapter: Address;
37
42
  performanceFeeRecipient: Address;
38
43
  managementFeeRecipient: Address;
39
- constructor({ totalSupply, asset, totalAssets, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
44
+ constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
40
45
  toAssets(shares: bigint): bigint;
41
46
  toShares(assets: bigint): bigint;
42
47
  protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
@@ -48,6 +53,10 @@ export declare class AccrualVaultV2 extends VaultV2 implements IAccrualVaultV2 {
48
53
  readonly accrualAdapters: IAccrualVaultV2Adapter[];
49
54
  readonly assetBalance: bigint;
50
55
  constructor(vault: IAccrualVaultV2, accrualAdapters: IAccrualVaultV2Adapter[], assetBalance: bigint);
56
+ /**
57
+ * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
58
+ * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the vault's `lastUpdate`.
59
+ */
51
60
  accrueInterest(timestamp: BigIntish): {
52
61
  vault: AccrualVaultV2;
53
62
  performanceFeeShares: bigint;
@@ -1,39 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AccrualVaultV2 = exports.VaultV2 = void 0;
4
- const math_1 = require("../math");
5
- const token_1 = require("../token");
4
+ const errors_1 = require("../../errors");
5
+ const math_1 = require("../../math");
6
+ const token_1 = require("../../token");
6
7
  class VaultV2 extends token_1.WrappedToken {
7
8
  asset;
8
- /**
9
- * The ERC4626 vault's total supply of shares.
10
- */
11
- totalSupply;
12
- /**
13
- * The ERC4626 vault's total assets, without accrued interest
14
- */
15
9
  totalAssets;
10
+ _totalAssets;
11
+ totalSupply;
16
12
  virtualShares;
13
+ maxRate;
17
14
  lastUpdate;
18
15
  adapters;
19
- maxRate;
16
+ liquidityAdapter;
20
17
  performanceFee;
21
18
  managementFee;
22
- liquidityAdapter;
23
19
  performanceFeeRecipient;
24
20
  managementFeeRecipient;
25
- constructor({ totalSupply, asset, totalAssets, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }) {
21
+ constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }) {
26
22
  super(config, asset);
27
- this.totalSupply = totalSupply;
23
+ this.asset = asset;
28
24
  this.totalAssets = totalAssets;
25
+ this._totalAssets = _totalAssets;
26
+ this.totalSupply = totalSupply;
29
27
  this.virtualShares = virtualShares;
30
- this.lastUpdate = lastUpdate;
31
- this.asset = asset;
32
28
  this.maxRate = maxRate;
29
+ this.lastUpdate = lastUpdate;
33
30
  this.adapters = adapters;
31
+ this.liquidityAdapter = liquidityAdapter;
34
32
  this.performanceFee = performanceFee;
35
33
  this.managementFee = managementFee;
36
- this.liquidityAdapter = liquidityAdapter;
37
34
  this.performanceFeeRecipient = performanceFeeRecipient;
38
35
  this.managementFeeRecipient = managementFeeRecipient;
39
36
  }
@@ -59,16 +56,24 @@ class AccrualVaultV2 extends VaultV2 {
59
56
  this.accrualAdapters = accrualAdapters;
60
57
  this.assetBalance = assetBalance;
61
58
  }
59
+ /**
60
+ * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
61
+ * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the vault's `lastUpdate`.
62
+ */
62
63
  accrueInterest(timestamp) {
63
64
  const vault = new AccrualVaultV2(this, this.accrualAdapters, this.assetBalance);
64
- const elapsed = BigInt(timestamp) - vault.lastUpdate;
65
- if (elapsed <= 0n)
65
+ timestamp = BigInt(timestamp);
66
+ const elapsed = timestamp - this.lastUpdate;
67
+ if (elapsed < 0n)
68
+ throw new errors_1.VaultV2Errors.InvalidInterestAccrual(this.address, timestamp, this.lastUpdate);
69
+ // Corresponds to the `firstTotalAssets == 0` onchain check.
70
+ if (elapsed === 0n)
66
71
  return { vault, performanceFeeShares: 0n, managementFeeShares: 0n };
67
72
  const realAssets = vault.accrualAdapters.reduce((curr, adapter) => curr + adapter.realAssets(timestamp), vault.assetBalance);
68
- const maxTotalAssets = vault.totalAssets +
69
- math_1.MathLib.wMulDown(vault.totalAssets * elapsed, vault.maxRate);
73
+ const maxTotalAssets = vault._totalAssets +
74
+ math_1.MathLib.wMulDown(vault._totalAssets * elapsed, vault.maxRate);
70
75
  const newTotalAssets = math_1.MathLib.min(realAssets, maxTotalAssets);
71
- const interest = math_1.MathLib.zeroFloorSub(newTotalAssets, vault.totalAssets);
76
+ const interest = math_1.MathLib.zeroFloorSub(newTotalAssets, vault._totalAssets);
72
77
  const performanceFeeAssets = interest > 0n && vault.performanceFee > 0n
73
78
  ? math_1.MathLib.wMulDown(interest, vault.performanceFee)
74
79
  : 0n;
@@ -79,6 +84,7 @@ class AccrualVaultV2 extends VaultV2 {
79
84
  const performanceFeeShares = math_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
80
85
  const managementFeeShares = math_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
81
86
  vault.totalAssets = newTotalAssets;
87
+ vault._totalAssets = newTotalAssets;
82
88
  if (performanceFeeShares)
83
89
  vault.totalSupply += performanceFeeShares;
84
90
  if (managementFeeShares)
@@ -1,5 +1,5 @@
1
1
  import type { Address, Hash } from "viem";
2
- import type { BigIntish } from "../types";
2
+ import type { BigIntish } from "../../types";
3
3
  export interface IVaultV2Adapter {
4
4
  address: Address;
5
5
  parentVault: Address;
@@ -3,8 +3,8 @@ import { VaultV2Adapter } from "./VaultV2Adapter";
3
3
  export interface IVaultV2MorphoVaultV1Adapter extends IVaultV2Adapter {
4
4
  morphoVaultV1: Address;
5
5
  }
6
- import type { BigIntish } from "../types";
7
- import type { AccrualVault } from "../vault";
6
+ import type { BigIntish } from "../../types";
7
+ import type { AccrualVault } from "../Vault";
8
8
  import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
9
9
  export declare class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter implements IVaultV2MorphoVaultV1Adapter {
10
10
  readonly morphoVaultV1: Address;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/blue-sdk",
3
3
  "description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
4
- "version": "4.14.0-next.1",
4
+ "version": "4.14.0-next.2",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
File without changes
File without changes
File without changes