@morpho-org/blue-sdk 4.13.0 → 4.14.0-next.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.
@@ -49,8 +49,6 @@ export interface ChainAddresses {
49
49
  adaptiveCurveIrm: Address;
50
50
  publicAllocator?: Address;
51
51
  metaMorphoFactory?: Address;
52
- vaultV2Factory?: Address;
53
- morphoVaultV1AdapterFactory?: Address;
54
52
  registryList?: Address;
55
53
  chainlinkOracleFactory?: Address;
56
54
  preLiquidationFactory?: Address;
@@ -66,6 +64,8 @@ export interface ChainAddresses {
66
64
  usdc?: Address;
67
65
  stEth?: Address;
68
66
  wstEth?: Address;
67
+ vaultV2Factory?: Address;
68
+ morphoVaultV1AdapterFactory?: Address;
69
69
  }
70
70
  declare const _addressesRegistry: {
71
71
  readonly 1: {
@@ -111,8 +111,6 @@ declare const _addressesRegistry: {
111
111
  readonly adaptiveCurveIrm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
112
112
  readonly publicAllocator: "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D";
113
113
  readonly metaMorphoFactory: "0x1897A8997241C1cD4bD0698647e4EB7213535c24";
114
- readonly vaultV2Factory: "0xA1D94F746dEfa1928926b84fB2596c06926C0405";
115
- readonly morphoVaultV1AdapterFactory: "0xD1B8E2dee25c2b89DCD2f98448a7ce87d6F63394";
116
114
  readonly registryList: "0x3696c5eAe4a7Ffd04Ea163564571E9CD8Ed9364e";
117
115
  readonly chainlinkOracleFactory: "0x3A7bB36Ee3f3eE32A60e9f2b33c1e5f2E83ad766";
118
116
  readonly preLiquidationFactory: "0x6FF33615e792E35ed1026ea7cACCf42D9BF83476";
@@ -143,6 +141,8 @@ declare const _addressesRegistry: {
143
141
  readonly crvUSDETHCRV: "0x4eBdF703948ddCEA3B11f675B4D1Fba9d2414A14";
144
142
  readonly "stkcvx2BTC-f-morpho": "0x385E12cf4040543Bc8C18e05C1298Be5B04f3f5e";
145
143
  readonly "2BTC-f": "0xB7ECB2AA52AA64a717180E030241bC75Cd946726";
144
+ readonly vaultV2Factory: "0xA1D94F746dEfa1928926b84fB2596c06926C0405";
145
+ readonly morphoVaultV1AdapterFactory: "0xD1B8E2dee25c2b89DCD2f98448a7ce87d6F63394";
146
146
  };
147
147
  readonly 8453: {
148
148
  readonly morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb";
@@ -174,8 +174,6 @@ declare const _addressesRegistry: {
174
174
  readonly adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687";
175
175
  readonly publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467";
176
176
  readonly metaMorphoFactory: "0xFf62A7c278C62eD665133147129245053Bbf5918";
177
- readonly vaultV2Factory: "0x4501125508079A99ebBebCE205DeC9593C2b5857";
178
- readonly morphoVaultV1AdapterFactory: "0xF42D9c36b34c9c2CF3Bc30eD2a52a90eEB604642";
179
177
  readonly registryList: "0x5C2531Cbd2cf112Cf687da3Cd536708aDd7DB10a";
180
178
  readonly chainlinkOracleFactory: "0x2DC205F24BCb6B311E5cdf0745B0741648Aebd3d";
181
179
  readonly preLiquidationFactory: "0x8cd16b62E170Ee0bA83D80e1F80E6085367e2aef";
@@ -183,6 +181,8 @@ declare const _addressesRegistry: {
183
181
  readonly usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
184
182
  readonly verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b";
185
183
  readonly testUsdc: "0xBC77067f829979812d795d516E523C4033b66409";
184
+ readonly vaultV2Factory: "0x4501125508079A99ebBebCE205DeC9593C2b5857";
185
+ readonly morphoVaultV1AdapterFactory: "0xF42D9c36b34c9c2CF3Bc30eD2a52a90eEB604642";
186
186
  };
187
187
  readonly 137: {
188
188
  readonly morpho: "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67";
@@ -481,11 +481,11 @@ declare const _deployments: {
481
481
  readonly adaptiveCurveIrm: 18883124n;
482
482
  readonly publicAllocator: 19375099n;
483
483
  readonly metaMorphoFactory: 21439510n;
484
- readonly vaultV2Factory: 23375073n;
485
- readonly morphoVaultV1AdapterFactory: 23375073n;
486
484
  readonly registryList: 23375119n;
487
485
  readonly chainlinkOracleFactory: 19375066n;
488
486
  readonly preLiquidationFactory: 21414664n;
487
+ readonly vaultV2Factory: 23375073n;
488
+ readonly morphoVaultV1AdapterFactory: 23375073n;
489
489
  };
490
490
  readonly 8453: {
491
491
  readonly morpho: 13977148n;
@@ -501,11 +501,11 @@ declare const _deployments: {
501
501
  readonly adaptiveCurveIrm: 13977152n;
502
502
  readonly publicAllocator: 13979545n;
503
503
  readonly metaMorphoFactory: 23928808n;
504
- readonly vaultV2Factory: 35615206n;
505
- readonly morphoVaultV1AdapterFactory: 35615206n;
506
504
  readonly registryList: 35615358n;
507
505
  readonly chainlinkOracleFactory: 13978286n;
508
506
  readonly preLiquidationFactory: 23779056n;
507
+ readonly vaultV2Factory: 35615206n;
508
+ readonly morphoVaultV1AdapterFactory: 35615206n;
509
509
  };
510
510
  readonly 137: {
511
511
  readonly morpho: 66931042n;
@@ -824,8 +824,6 @@ export declare let addressesRegistry: {
824
824
  readonly adaptiveCurveIrm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
825
825
  readonly publicAllocator: "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D";
826
826
  readonly metaMorphoFactory: "0x1897A8997241C1cD4bD0698647e4EB7213535c24";
827
- readonly vaultV2Factory: "0xA1D94F746dEfa1928926b84fB2596c06926C0405";
828
- readonly morphoVaultV1AdapterFactory: "0xD1B8E2dee25c2b89DCD2f98448a7ce87d6F63394";
829
827
  readonly registryList: "0x3696c5eAe4a7Ffd04Ea163564571E9CD8Ed9364e";
830
828
  readonly chainlinkOracleFactory: "0x3A7bB36Ee3f3eE32A60e9f2b33c1e5f2E83ad766";
831
829
  readonly preLiquidationFactory: "0x6FF33615e792E35ed1026ea7cACCf42D9BF83476";
@@ -856,6 +854,8 @@ export declare let addressesRegistry: {
856
854
  readonly crvUSDETHCRV: "0x4eBdF703948ddCEA3B11f675B4D1Fba9d2414A14";
857
855
  readonly "stkcvx2BTC-f-morpho": "0x385E12cf4040543Bc8C18e05C1298Be5B04f3f5e";
858
856
  readonly "2BTC-f": "0xB7ECB2AA52AA64a717180E030241bC75Cd946726";
857
+ readonly vaultV2Factory: "0xA1D94F746dEfa1928926b84fB2596c06926C0405";
858
+ readonly morphoVaultV1AdapterFactory: "0xD1B8E2dee25c2b89DCD2f98448a7ce87d6F63394";
859
859
  };
860
860
  readonly 8453: {
861
861
  readonly morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb";
@@ -887,8 +887,6 @@ export declare let addressesRegistry: {
887
887
  readonly adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687";
888
888
  readonly publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467";
889
889
  readonly metaMorphoFactory: "0xFf62A7c278C62eD665133147129245053Bbf5918";
890
- readonly vaultV2Factory: "0x4501125508079A99ebBebCE205DeC9593C2b5857";
891
- readonly morphoVaultV1AdapterFactory: "0xF42D9c36b34c9c2CF3Bc30eD2a52a90eEB604642";
892
890
  readonly registryList: "0x5C2531Cbd2cf112Cf687da3Cd536708aDd7DB10a";
893
891
  readonly chainlinkOracleFactory: "0x2DC205F24BCb6B311E5cdf0745B0741648Aebd3d";
894
892
  readonly preLiquidationFactory: "0x8cd16b62E170Ee0bA83D80e1F80E6085367e2aef";
@@ -896,6 +894,8 @@ export declare let addressesRegistry: {
896
894
  readonly usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
897
895
  readonly verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b";
898
896
  readonly testUsdc: "0xBC77067f829979812d795d516E523C4033b66409";
897
+ readonly vaultV2Factory: "0x4501125508079A99ebBebCE205DeC9593C2b5857";
898
+ readonly morphoVaultV1AdapterFactory: "0xF42D9c36b34c9c2CF3Bc30eD2a52a90eEB604642";
899
899
  };
900
900
  readonly 137: {
901
901
  readonly morpho: "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67";
@@ -1192,11 +1192,11 @@ export declare let deployments: {
1192
1192
  readonly adaptiveCurveIrm: 18883124n;
1193
1193
  readonly publicAllocator: 19375099n;
1194
1194
  readonly metaMorphoFactory: 21439510n;
1195
- readonly vaultV2Factory: 23375073n;
1196
- readonly morphoVaultV1AdapterFactory: 23375073n;
1197
1195
  readonly registryList: 23375119n;
1198
1196
  readonly chainlinkOracleFactory: 19375066n;
1199
1197
  readonly preLiquidationFactory: 21414664n;
1198
+ readonly vaultV2Factory: 23375073n;
1199
+ readonly morphoVaultV1AdapterFactory: 23375073n;
1200
1200
  };
1201
1201
  readonly 8453: {
1202
1202
  readonly morpho: 13977148n;
@@ -1212,11 +1212,11 @@ export declare let deployments: {
1212
1212
  readonly adaptiveCurveIrm: 13977152n;
1213
1213
  readonly publicAllocator: 13979545n;
1214
1214
  readonly metaMorphoFactory: 23928808n;
1215
- readonly vaultV2Factory: 35615206n;
1216
- readonly morphoVaultV1AdapterFactory: 35615206n;
1217
1215
  readonly registryList: 35615358n;
1218
1216
  readonly chainlinkOracleFactory: 13978286n;
1219
1217
  readonly preLiquidationFactory: 23779056n;
1218
+ readonly vaultV2Factory: 35615206n;
1219
+ readonly morphoVaultV1AdapterFactory: 35615206n;
1220
1220
  };
1221
1221
  readonly 137: {
1222
1222
  readonly morpho: 66931042n;
package/lib/addresses.js CHANGED
@@ -60,8 +60,6 @@ const _addressesRegistry = {
60
60
  adaptiveCurveIrm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC",
61
61
  publicAllocator: "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D",
62
62
  metaMorphoFactory: "0x1897A8997241C1cD4bD0698647e4EB7213535c24",
63
- vaultV2Factory: "0xA1D94F746dEfa1928926b84fB2596c06926C0405",
64
- morphoVaultV1AdapterFactory: "0xD1B8E2dee25c2b89DCD2f98448a7ce87d6F63394",
65
63
  registryList: "0x3696c5eAe4a7Ffd04Ea163564571E9CD8Ed9364e",
66
64
  chainlinkOracleFactory: "0x3A7bB36Ee3f3eE32A60e9f2b33c1e5f2E83ad766",
67
65
  preLiquidationFactory: "0x6FF33615e792E35ed1026ea7cACCf42D9BF83476",
@@ -98,6 +96,8 @@ const _addressesRegistry = {
98
96
  crvUSDETHCRV: "0x4eBdF703948ddCEA3B11f675B4D1Fba9d2414A14",
99
97
  "stkcvx2BTC-f-morpho": "0x385E12cf4040543Bc8C18e05C1298Be5B04f3f5e",
100
98
  "2BTC-f": "0xB7ECB2AA52AA64a717180E030241bC75Cd946726",
99
+ vaultV2Factory: "0xA1D94F746dEfa1928926b84fB2596c06926C0405",
100
+ morphoVaultV1AdapterFactory: "0xD1B8E2dee25c2b89DCD2f98448a7ce87d6F63394",
101
101
  },
102
102
  [chain_js_1.ChainId.BaseMainnet]: {
103
103
  morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb",
@@ -129,8 +129,6 @@ const _addressesRegistry = {
129
129
  adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687",
130
130
  publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467",
131
131
  metaMorphoFactory: "0xFf62A7c278C62eD665133147129245053Bbf5918",
132
- vaultV2Factory: "0x4501125508079A99ebBebCE205DeC9593C2b5857",
133
- morphoVaultV1AdapterFactory: "0xF42D9c36b34c9c2CF3Bc30eD2a52a90eEB604642",
134
132
  registryList: "0x5C2531Cbd2cf112Cf687da3Cd536708aDd7DB10a",
135
133
  chainlinkOracleFactory: "0x2DC205F24BCb6B311E5cdf0745B0741648Aebd3d",
136
134
  preLiquidationFactory: "0x8cd16b62E170Ee0bA83D80e1F80E6085367e2aef",
@@ -139,6 +137,8 @@ const _addressesRegistry = {
139
137
  usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
140
138
  verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b",
141
139
  testUsdc: "0xBC77067f829979812d795d516E523C4033b66409",
140
+ vaultV2Factory: "0x4501125508079A99ebBebCE205DeC9593C2b5857",
141
+ morphoVaultV1AdapterFactory: "0xF42D9c36b34c9c2CF3Bc30eD2a52a90eEB604642",
142
142
  },
143
143
  [chain_js_1.ChainId.PolygonMainnet]: {
144
144
  morpho: "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67",
@@ -443,11 +443,11 @@ const _deployments = {
443
443
  adaptiveCurveIrm: 18883124n,
444
444
  publicAllocator: 19375099n,
445
445
  metaMorphoFactory: 21439510n,
446
- vaultV2Factory: 23375073n,
447
- morphoVaultV1AdapterFactory: 23375073n,
448
446
  registryList: 23375119n,
449
447
  chainlinkOracleFactory: 19375066n,
450
448
  preLiquidationFactory: 21414664n,
449
+ vaultV2Factory: 23375073n,
450
+ morphoVaultV1AdapterFactory: 23375073n,
451
451
  },
452
452
  [chain_js_1.ChainId.BaseMainnet]: {
453
453
  morpho: 13977148n,
@@ -463,11 +463,11 @@ const _deployments = {
463
463
  adaptiveCurveIrm: 13977152n,
464
464
  publicAllocator: 13979545n,
465
465
  metaMorphoFactory: 23928808n,
466
- vaultV2Factory: 35615206n,
467
- morphoVaultV1AdapterFactory: 35615206n,
468
466
  registryList: 35615358n,
469
467
  chainlinkOracleFactory: 13978286n,
470
468
  preLiquidationFactory: 23779056n,
469
+ vaultV2Factory: 35615206n,
470
+ morphoVaultV1AdapterFactory: 35615206n,
471
471
  },
472
472
  [chain_js_1.ChainId.PolygonMainnet]: {
473
473
  morpho: 66931042n,
package/lib/errors.d.ts CHANGED
@@ -25,6 +25,10 @@ export declare class UnsupportedPreLiquidationParamsError extends Error {
25
25
  readonly lltv: bigint;
26
26
  constructor(lltv: bigint);
27
27
  }
28
+ export declare class UnsupportedVaultV2AdapterError extends Error {
29
+ readonly address: Address;
30
+ constructor(address: Address);
31
+ }
28
32
  export declare namespace BlueErrors {
29
33
  class AlreadySet extends Error {
30
34
  readonly name: string;
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.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
3
+ 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 {
@@ -54,6 +54,14 @@ class UnsupportedPreLiquidationParamsError extends Error {
54
54
  }
55
55
  }
56
56
  exports.UnsupportedPreLiquidationParamsError = UnsupportedPreLiquidationParamsError;
57
+ class UnsupportedVaultV2AdapterError extends Error {
58
+ address;
59
+ constructor(address) {
60
+ super(`vault v2 adapter "${address}" is not supported`);
61
+ this.address = address;
62
+ }
63
+ }
64
+ exports.UnsupportedVaultV2AdapterError = UnsupportedVaultV2AdapterError;
57
65
  var BlueErrors;
58
66
  (function (BlueErrors) {
59
67
  class AlreadySet extends Error {
package/lib/index.d.ts CHANGED
@@ -11,4 +11,5 @@ 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";
14
15
  export * from "./utils.js";
package/lib/index.js CHANGED
@@ -27,4 +27,5 @@ __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);
30
31
  __exportStar(require("./utils.js"), exports);
@@ -0,0 +1,56 @@
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";
5
+ import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter";
6
+ export interface IVaultV2 extends IToken {
7
+ asset: Address;
8
+ totalSupply: bigint;
9
+ totalAssets: bigint;
10
+ performanceFee: bigint;
11
+ managementFee: bigint;
12
+ virtualShares: bigint;
13
+ lastUpdate: bigint;
14
+ adapters: Address[];
15
+ maxRate: bigint;
16
+ liquidityAdapter: Address;
17
+ performanceFeeRecipient: Address;
18
+ managementFeeRecipient: Address;
19
+ }
20
+ export declare class VaultV2 extends WrappedToken implements IVaultV2 {
21
+ 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
+ totalAssets: bigint;
30
+ virtualShares: bigint;
31
+ lastUpdate: bigint;
32
+ adapters: Address[];
33
+ maxRate: bigint;
34
+ performanceFee: bigint;
35
+ managementFee: bigint;
36
+ liquidityAdapter: Address;
37
+ performanceFeeRecipient: Address;
38
+ managementFeeRecipient: Address;
39
+ constructor({ totalSupply, asset, totalAssets, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
40
+ toAssets(shares: bigint): bigint;
41
+ toShares(assets: bigint): bigint;
42
+ protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
43
+ protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
44
+ }
45
+ export interface IAccrualVaultV2 extends Omit<IVaultV2, "adapters"> {
46
+ }
47
+ export declare class AccrualVaultV2 extends VaultV2 implements IAccrualVaultV2 {
48
+ readonly accrualAdapters: IAccrualVaultV2Adapter[];
49
+ readonly assetBalance: bigint;
50
+ constructor(vault: IAccrualVaultV2, accrualAdapters: IAccrualVaultV2Adapter[], assetBalance: bigint);
51
+ accrueInterest(timestamp: BigIntish): {
52
+ vault: AccrualVaultV2;
53
+ performanceFeeShares: bigint;
54
+ managementFeeShares: bigint;
55
+ };
56
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccrualVaultV2 = exports.VaultV2 = void 0;
4
+ const math_1 = require("../math");
5
+ const token_1 = require("../token");
6
+ class VaultV2 extends token_1.WrappedToken {
7
+ 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
+ totalAssets;
16
+ virtualShares;
17
+ lastUpdate;
18
+ adapters;
19
+ maxRate;
20
+ performanceFee;
21
+ managementFee;
22
+ liquidityAdapter;
23
+ performanceFeeRecipient;
24
+ managementFeeRecipient;
25
+ constructor({ totalSupply, asset, totalAssets, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }) {
26
+ super(config, asset);
27
+ this.totalSupply = totalSupply;
28
+ this.totalAssets = totalAssets;
29
+ this.virtualShares = virtualShares;
30
+ this.lastUpdate = lastUpdate;
31
+ this.asset = asset;
32
+ this.maxRate = maxRate;
33
+ this.adapters = adapters;
34
+ this.performanceFee = performanceFee;
35
+ this.managementFee = managementFee;
36
+ this.liquidityAdapter = liquidityAdapter;
37
+ this.performanceFeeRecipient = performanceFeeRecipient;
38
+ this.managementFeeRecipient = managementFeeRecipient;
39
+ }
40
+ toAssets(shares) {
41
+ return this._unwrap(shares, "Down");
42
+ }
43
+ toShares(assets) {
44
+ return this._wrap(assets, "Down");
45
+ }
46
+ _wrap(amount, rounding) {
47
+ return math_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
48
+ }
49
+ _unwrap(amount, rounding) {
50
+ return math_1.MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
51
+ }
52
+ }
53
+ exports.VaultV2 = VaultV2;
54
+ class AccrualVaultV2 extends VaultV2 {
55
+ accrualAdapters;
56
+ assetBalance;
57
+ constructor(vault, accrualAdapters, assetBalance) {
58
+ super({ ...vault, adapters: accrualAdapters.map((a) => a.address) });
59
+ this.accrualAdapters = accrualAdapters;
60
+ this.assetBalance = assetBalance;
61
+ }
62
+ accrueInterest(timestamp) {
63
+ const vault = new AccrualVaultV2(this, this.accrualAdapters, this.assetBalance);
64
+ const elapsed = BigInt(timestamp) - vault.lastUpdate;
65
+ if (elapsed <= 0n)
66
+ return { vault, performanceFeeShares: 0n, managementFeeShares: 0n };
67
+ 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);
70
+ const newTotalAssets = math_1.MathLib.min(realAssets, maxTotalAssets);
71
+ const interest = math_1.MathLib.zeroFloorSub(newTotalAssets, vault.totalAssets);
72
+ const performanceFeeAssets = interest > 0n && vault.performanceFee > 0n
73
+ ? math_1.MathLib.wMulDown(interest, vault.performanceFee)
74
+ : 0n;
75
+ const managementFeeAssets = elapsed > 0n && vault.managementFee > 0n
76
+ ? math_1.MathLib.wMulDown(newTotalAssets * elapsed, vault.managementFee)
77
+ : 0n;
78
+ const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
79
+ const performanceFeeShares = math_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
80
+ const managementFeeShares = math_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
81
+ vault.totalAssets = newTotalAssets;
82
+ if (performanceFeeShares)
83
+ vault.totalSupply += performanceFeeShares;
84
+ if (managementFeeShares)
85
+ vault.totalSupply += managementFeeShares;
86
+ vault.lastUpdate = BigInt(timestamp);
87
+ return { vault, performanceFeeShares, managementFeeShares };
88
+ }
89
+ }
90
+ exports.AccrualVaultV2 = AccrualVaultV2;
@@ -0,0 +1,18 @@
1
+ import type { Address, Hash } from "viem";
2
+ import type { BigIntish } from "../types";
3
+ export interface IVaultV2Adapter {
4
+ address: Address;
5
+ parentVault: Address;
6
+ adapterId: Hash;
7
+ skimRecipient: Address;
8
+ }
9
+ export declare abstract class VaultV2Adapter implements IVaultV2Adapter {
10
+ readonly address: Address;
11
+ readonly parentVault: Address;
12
+ readonly adapterId: Hash;
13
+ skimRecipient: Address;
14
+ constructor({ address, parentVault, adapterId, skimRecipient, }: IVaultV2Adapter);
15
+ }
16
+ export interface IAccrualVaultV2Adapter extends IVaultV2Adapter {
17
+ realAssets(timestamp: BigIntish): bigint;
18
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaultV2Adapter = void 0;
4
+ class VaultV2Adapter {
5
+ address;
6
+ parentVault;
7
+ adapterId;
8
+ skimRecipient;
9
+ constructor({ address, parentVault, adapterId, skimRecipient, }) {
10
+ this.address = address;
11
+ this.parentVault = parentVault;
12
+ this.adapterId = adapterId;
13
+ this.skimRecipient = skimRecipient;
14
+ }
15
+ }
16
+ exports.VaultV2Adapter = VaultV2Adapter;
@@ -0,0 +1,21 @@
1
+ import type { Address } from "viem";
2
+ import { VaultV2Adapter } from "./VaultV2Adapter";
3
+ export interface IVaultV2MorphoVaultV1Adapter extends IVaultV2Adapter {
4
+ morphoVaultV1: Address;
5
+ }
6
+ import type { BigIntish } from "../types";
7
+ import type { AccrualVault } from "../vault";
8
+ import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
9
+ export declare class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter implements IVaultV2MorphoVaultV1Adapter {
10
+ readonly morphoVaultV1: Address;
11
+ constructor({ morphoVaultV1, ...vaultV2Adapter }: IVaultV2MorphoVaultV1Adapter);
12
+ ids(): `0x${string}`[];
13
+ }
14
+ export interface IAccrualVaultV2MorphoVaultV1Adapter extends IVaultV2MorphoVaultV1Adapter {
15
+ }
16
+ export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter implements IAccrualVaultV2MorphoVaultV1Adapter, IAccrualVaultV2Adapter {
17
+ vaultV1: AccrualVault;
18
+ shares: bigint;
19
+ constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, vaultV1: AccrualVault, shares: bigint);
20
+ realAssets(timestamp: BigIntish): bigint;
21
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccrualVaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoVaultV1Adapter = void 0;
4
+ const VaultV2Adapter_1 = require("./VaultV2Adapter");
5
+ class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
6
+ morphoVaultV1;
7
+ constructor({ morphoVaultV1, ...vaultV2Adapter }) {
8
+ super(vaultV2Adapter);
9
+ this.morphoVaultV1 = morphoVaultV1;
10
+ }
11
+ ids() {
12
+ return [this.adapterId];
13
+ }
14
+ }
15
+ exports.VaultV2MorphoVaultV1Adapter = VaultV2MorphoVaultV1Adapter;
16
+ class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter {
17
+ vaultV1;
18
+ shares;
19
+ constructor(adapter, vaultV1, shares) {
20
+ super(adapter);
21
+ this.vaultV1 = vaultV1;
22
+ this.shares = shares;
23
+ }
24
+ realAssets(timestamp) {
25
+ return this.vaultV1.accrueInterest(timestamp).toAssets(this.shares);
26
+ }
27
+ }
28
+ exports.AccrualVaultV2MorphoVaultV1Adapter = AccrualVaultV2MorphoVaultV1Adapter;
@@ -0,0 +1,3 @@
1
+ export * from "./VaultV2.js";
2
+ export * from "./VaultV2Adapter.js";
3
+ export * from "./VaultV2MorphoVaultV1Adapter.js";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./VaultV2.js"), exports);
18
+ __exportStar(require("./VaultV2Adapter.js"), exports);
19
+ __exportStar(require("./VaultV2MorphoVaultV1Adapter.js"), exports);
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.13.0",
4
+ "version": "4.14.0-next.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
@@ -29,10 +29,10 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.7.2",
32
- "viem": "^2.23.0",
32
+ "viem": "^2.33.3",
33
33
  "vitest": "^3.0.5",
34
34
  "@morpho-org/morpho-ts": "^2.4.2",
35
- "@morpho-org/test": "^2.6.0"
35
+ "@morpho-org/test": "^2.6.1-next.0"
36
36
  },
37
37
  "scripts": {
38
38
  "prepublish": "$npm_execpath build",