@morpho-org/blue-sdk 5.23.3 → 6.0.1

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.
@@ -13,11 +13,7 @@ export interface IVaultV2Allocation {
13
13
  export interface IVaultV2 extends IToken {
14
14
  asset: Address;
15
15
  /**
16
- * The total assets, *including* virtually accrued interest.
17
- */
18
- totalAssets: bigint;
19
- /**
20
- * The total assets, *excluding* virtually accrued interest.
16
+ * Stored total assets at `lastUpdate`, excluding virtually accrued interest.
21
17
  */
22
18
  _totalAssets: bigint;
23
19
  /**
@@ -38,7 +34,6 @@ export interface IVaultV2 extends IToken {
38
34
  }
39
35
  export declare class VaultV2 extends WrappedToken implements IVaultV2 {
40
36
  readonly asset: Address;
41
- totalAssets: bigint;
42
37
  _totalAssets: bigint;
43
38
  totalSupply: bigint;
44
39
  virtualShares: bigint;
@@ -52,7 +47,7 @@ export declare class VaultV2 extends WrappedToken implements IVaultV2 {
52
47
  managementFee: bigint;
53
48
  performanceFeeRecipient: `0x${string}`;
54
49
  managementFeeRecipient: `0x${string}`;
55
- constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
50
+ constructor({ asset, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
56
51
  toAssets(shares: BigIntish): bigint;
57
52
  toShares(assets: BigIntish): bigint;
58
53
  protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
@@ -8,7 +8,6 @@ const index_js_2 = require("../../token/index.js");
8
8
  const utils_js_1 = require("../../utils.js");
9
9
  class VaultV2 extends index_js_2.WrappedToken {
10
10
  asset;
11
- totalAssets;
12
11
  _totalAssets;
13
12
  totalSupply;
14
13
  virtualShares;
@@ -22,10 +21,9 @@ class VaultV2 extends index_js_2.WrappedToken {
22
21
  managementFee;
23
22
  performanceFeeRecipient;
24
23
  managementFeeRecipient;
25
- constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }) {
24
+ constructor({ asset, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }) {
26
25
  super(config, asset);
27
26
  this.asset = asset;
28
- this.totalAssets = totalAssets;
29
27
  this._totalAssets = _totalAssets;
30
28
  this.totalSupply = totalSupply;
31
29
  this.virtualShares = virtualShares;
@@ -47,10 +45,11 @@ class VaultV2 extends index_js_2.WrappedToken {
47
45
  return this._wrap(assets, "Down");
48
46
  }
49
47
  _wrap(amount, rounding) {
50
- return index_js_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
48
+ // Pair pre-accrue `_totalAssets` with pre-accrue `totalSupply`; call `AccrualVaultV2.accrueInterest` for post-accrue math.
49
+ return index_js_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this._totalAssets + 1n, rounding);
51
50
  }
52
51
  _unwrap(amount, rounding) {
53
- return index_js_1.MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
52
+ return index_js_1.MathLib.mulDiv(amount, this._totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
54
53
  }
55
54
  }
56
55
  exports.VaultV2 = VaultV2;
@@ -94,8 +93,8 @@ class AccrualVaultV2 extends VaultV2 {
94
93
  limiter: utils_js_1.CapacityLimitReason.vaultV2_absoluteCap,
95
94
  };
96
95
  if (relativeCap !== index_js_1.MathLib.WAD) {
97
- // `relativeCap` can be set lower than `allocation / totalAssets`.
98
- const relativeMaxDeposit = index_js_1.MathLib.zeroFloorSub(index_js_1.MathLib.wMulDown(this.totalAssets, relativeCap), allocation);
96
+ // `relativeCap` can be set lower than `allocation / _totalAssets`.
97
+ const relativeMaxDeposit = index_js_1.MathLib.zeroFloorSub(index_js_1.MathLib.wMulDown(this._totalAssets, relativeCap), allocation);
99
98
  if (liquidityAdapterLimit.value > relativeMaxDeposit)
100
99
  liquidityAdapterLimit = {
101
100
  value: relativeMaxDeposit,
@@ -153,7 +152,6 @@ class AccrualVaultV2 extends VaultV2 {
153
152
  const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
154
153
  const performanceFeeShares = index_js_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
155
154
  const managementFeeShares = index_js_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
156
- vault.totalAssets = newTotalAssets;
157
155
  vault._totalAssets = newTotalAssets;
158
156
  if (performanceFeeShares)
159
157
  vault.totalSupply += performanceFeeShares;
@@ -13,11 +13,7 @@ export interface IVaultV2Allocation {
13
13
  export interface IVaultV2 extends IToken {
14
14
  asset: Address;
15
15
  /**
16
- * The total assets, *including* virtually accrued interest.
17
- */
18
- totalAssets: bigint;
19
- /**
20
- * The total assets, *excluding* virtually accrued interest.
16
+ * Stored total assets at `lastUpdate`, excluding virtually accrued interest.
21
17
  */
22
18
  _totalAssets: bigint;
23
19
  /**
@@ -38,7 +34,6 @@ export interface IVaultV2 extends IToken {
38
34
  }
39
35
  export declare class VaultV2 extends WrappedToken implements IVaultV2 {
40
36
  readonly asset: Address;
41
- totalAssets: bigint;
42
37
  _totalAssets: bigint;
43
38
  totalSupply: bigint;
44
39
  virtualShares: bigint;
@@ -52,7 +47,7 @@ export declare class VaultV2 extends WrappedToken implements IVaultV2 {
52
47
  managementFee: bigint;
53
48
  performanceFeeRecipient: `0x${string}`;
54
49
  managementFeeRecipient: `0x${string}`;
55
- constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
50
+ constructor({ asset, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
56
51
  toAssets(shares: BigIntish): bigint;
57
52
  toShares(assets: BigIntish): bigint;
58
53
  protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
@@ -5,7 +5,6 @@ import { WrappedToken } from "../../token/index.js";
5
5
  import { CapacityLimitReason } from "../../utils.js";
6
6
  export class VaultV2 extends WrappedToken {
7
7
  asset;
8
- totalAssets;
9
8
  _totalAssets;
10
9
  totalSupply;
11
10
  virtualShares;
@@ -19,10 +18,9 @@ export class VaultV2 extends WrappedToken {
19
18
  managementFee;
20
19
  performanceFeeRecipient;
21
20
  managementFeeRecipient;
22
- constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }) {
21
+ constructor({ asset, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }) {
23
22
  super(config, asset);
24
23
  this.asset = asset;
25
- this.totalAssets = totalAssets;
26
24
  this._totalAssets = _totalAssets;
27
25
  this.totalSupply = totalSupply;
28
26
  this.virtualShares = virtualShares;
@@ -44,10 +42,11 @@ export class VaultV2 extends WrappedToken {
44
42
  return this._wrap(assets, "Down");
45
43
  }
46
44
  _wrap(amount, rounding) {
47
- return MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
45
+ // Pair pre-accrue `_totalAssets` with pre-accrue `totalSupply`; call `AccrualVaultV2.accrueInterest` for post-accrue math.
46
+ return MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this._totalAssets + 1n, rounding);
48
47
  }
49
48
  _unwrap(amount, rounding) {
50
- return MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
49
+ return MathLib.mulDiv(amount, this._totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
51
50
  }
52
51
  }
53
52
  export class AccrualVaultV2 extends VaultV2 {
@@ -90,8 +89,8 @@ export class AccrualVaultV2 extends VaultV2 {
90
89
  limiter: CapacityLimitReason.vaultV2_absoluteCap,
91
90
  };
92
91
  if (relativeCap !== MathLib.WAD) {
93
- // `relativeCap` can be set lower than `allocation / totalAssets`.
94
- const relativeMaxDeposit = MathLib.zeroFloorSub(MathLib.wMulDown(this.totalAssets, relativeCap), allocation);
92
+ // `relativeCap` can be set lower than `allocation / _totalAssets`.
93
+ const relativeMaxDeposit = MathLib.zeroFloorSub(MathLib.wMulDown(this._totalAssets, relativeCap), allocation);
95
94
  if (liquidityAdapterLimit.value > relativeMaxDeposit)
96
95
  liquidityAdapterLimit = {
97
96
  value: relativeMaxDeposit,
@@ -149,7 +148,6 @@ export class AccrualVaultV2 extends VaultV2 {
149
148
  const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
150
149
  const performanceFeeShares = MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
151
150
  const managementFeeShares = MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
152
- vault.totalAssets = newTotalAssets;
153
151
  vault._totalAssets = newTotalAssets;
154
152
  if (performanceFeeShares)
155
153
  vault.totalSupply += performanceFeeShares;
package/package.json CHANGED
@@ -1,12 +1,16 @@
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": "5.23.3",
4
+ "version": "6.0.1",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
8
8
  ],
9
- "repository": "github:morpho-org/sdks",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/morpho-org/sdks.git",
12
+ "directory": "packages/blue-sdk"
13
+ },
10
14
  "homepage": "https://github.com/morpho-org/sdks",
11
15
  "bugs": {
12
16
  "url": "https://github.com/morpho-org/sdks/issues",
@@ -30,10 +34,10 @@
30
34
  },
31
35
  "devDependencies": {
32
36
  "typescript": "^6.0.3",
33
- "viem": "^2.49.3",
34
- "vitest": "^4.1.6",
35
- "@morpho-org/morpho-ts": "^2.5.1",
36
- "@morpho-org/test": "^2.7.3"
37
+ "viem": "^2.50.4",
38
+ "vitest": "^4.1.7",
39
+ "@morpho-org/morpho-ts": "^2.5.3",
40
+ "@morpho-org/test": "^2.8.1"
37
41
  },
38
42
  "scripts": {
39
43
  "prepublish": "$npm_execpath build",