@morpho-org/blue-sdk 5.1.1 → 5.2.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.
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AccrualVault = exports.Vault = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
- const index_js_1 = require("../market/index.js");
6
- const index_js_2 = require("../math/index.js");
7
- const index_js_3 = require("../token/index.js");
5
+ const index_js_1 = require("../math/index.js");
6
+ const index_js_2 = require("../token/index.js");
7
+ const utils_js_1 = require("../utils.js");
8
8
  const VaultMarketAllocation_js_1 = require("./VaultMarketAllocation.js");
9
- class Vault extends index_js_3.VaultToken {
9
+ class Vault extends index_js_2.VaultToken {
10
10
  /**
11
11
  * The MetaMorpho vault's owner address.
12
12
  */
@@ -93,7 +93,7 @@ class Vault extends index_js_3.VaultToken {
93
93
  * The amount of interest in assets accrued since the last interaction with the vault.
94
94
  */
95
95
  get totalInterest() {
96
- return index_js_2.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
96
+ return index_js_1.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
97
97
  }
98
98
  toAssets(shares, rounding = "Down") {
99
99
  return this._unwrap(shares, rounding);
@@ -155,7 +155,7 @@ class AccrualVault extends Vault {
155
155
  }
156
156
  /**
157
157
  * The MetaMorpho vault's current instantaneous Annual Percentage Yield (APY)
158
- * weighted-averaged over its market deposits, before deducting the performance fee.
158
+ * weighted-averaged over its market deposits, before deducting the performance fee (scaled by WAD).
159
159
  * If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
160
160
  */
161
161
  get apy() {
@@ -163,42 +163,32 @@ class AccrualVault extends Vault {
163
163
  }
164
164
  /**
165
165
  * The MetaMorpho vault's current instantaneous Annual Percentage Yield (APY)
166
- * weighted-averaged over its market deposits, after deducting the performance fee.
167
- * If interested in the APY at a specific timestamp, use `getNetApy(timestamp)` instead.
166
+ * weighted-averaged over its market deposits, after deducting the performance fee (scaled by WAD).
167
+ * If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
168
168
  */
169
169
  get netApy() {
170
170
  return this.getNetApy();
171
171
  }
172
172
  /**
173
- * The MetaMorpho vault's per-second rate at which interest _would_ accrue,
173
+ * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
174
174
  * weighted-averaged over its market deposits, before deducting the performance fee,
175
- * if interest was to be accrued on each market at the given timestamp.
175
+ * if interest was to be accrued on each market at the given timestamp (scaled by WAD).
176
176
  */
177
- _getAvgRate(timestamp = morpho_ts_1.Time.timestamp()) {
177
+ getApy(timestamp = morpho_ts_1.Time.timestamp()) {
178
178
  if (this.totalAssets === 0n)
179
179
  return 0n;
180
180
  return (this.allocations
181
181
  .values()
182
182
  .reduce((total, { position }) => total +
183
- position.market.getAvgSupplyRate(timestamp) * position.supplyAssets, 0n) / this.totalAssets);
184
- }
185
- /**
186
- * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
187
- * weighted-averaged over its market deposits, before deducting the performance fee,
188
- * if interest was to be accrued on each market at the given timestamp.
189
- */
190
- getApy(timestamp = morpho_ts_1.Time.timestamp()) {
191
- if (this.totalAssets === 0n)
192
- return 0;
193
- return index_js_1.MarketUtils.rateToApy(this._getAvgRate(timestamp));
183
+ position.market.getAvgSupplyApy(timestamp) * position.supplyAssets, 0n) / this.totalAssets);
194
184
  }
195
185
  /**
196
186
  * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
197
187
  * weighted-averaged over its market deposits, after deducting the performance fee,
198
- * if interest was to be accrued on each market at the given timestamp.
188
+ * if interest was to be accrued on each market at the given timestamp (scaled by WAD).
199
189
  */
200
190
  getNetApy(timestamp = morpho_ts_1.Time.timestamp()) {
201
- return index_js_1.MarketUtils.rateToApy(index_js_2.MathLib.wMulDown(this._getAvgRate(timestamp), index_js_2.MathLib.WAD - this.fee));
191
+ return index_js_1.MathLib.wMulDown(this.getApy(timestamp), index_js_1.MathLib.WAD - this.fee);
202
192
  }
203
193
  getAllocationProportion(marketId) {
204
194
  if (this.totalAssets === 0n)
@@ -206,36 +196,61 @@ class AccrualVault extends Vault {
206
196
  const allocation = this.allocations.get(marketId);
207
197
  if (!allocation)
208
198
  return 0n;
209
- return index_js_2.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
199
+ return index_js_1.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
210
200
  }
201
+ /**
202
+ * Returns the deposit capacity limit of a given amount of assets on the vault.
203
+ * @param assets The maximum amount of assets to deposit.
204
+ * @deprecated Use `maxDeposit` instead.
205
+ */
211
206
  getDepositCapacityLimit(assets) {
207
+ return this.maxDeposit(assets);
208
+ }
209
+ /**
210
+ * Returns the withdraw capacity limit corresponding to a given amount of shares of the vault.
211
+ * @param shares The maximum amount of shares to redeem.
212
+ * @deprecated Use `maxWithdraw` instead.
213
+ */
214
+ getWithdrawCapacityLimit(shares) {
215
+ return this.maxWithdraw(shares);
216
+ }
217
+ /**
218
+ * Returns the maximum amount of assets that can be deposited to the vault.
219
+ * @param assets The maximum amount of assets to deposit.
220
+ */
221
+ maxDeposit(assets) {
222
+ assets = BigInt(assets);
212
223
  const suppliable = this.allocations
213
224
  .values()
214
- .reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_2.MathLib.min(total +
225
+ .reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_1.MathLib.min(total +
215
226
  (this.supplyQueue.includes(marketId)
216
- ? index_js_2.MathLib.zeroFloorSub(cap, supplyAssets)
217
- : 0n), index_js_2.MathLib.MAX_UINT_256), 0n);
227
+ ? index_js_1.MathLib.zeroFloorSub(cap, supplyAssets)
228
+ : 0n), index_js_1.MathLib.MAX_UINT_256), 0n);
218
229
  if (assets > suppliable)
219
230
  return {
220
231
  value: suppliable,
221
- limiter: index_js_1.CapacityLimitReason.cap,
232
+ limiter: utils_js_1.CapacityLimitReason.cap,
222
233
  };
223
234
  return {
224
235
  value: assets,
225
- limiter: index_js_1.CapacityLimitReason.balance,
236
+ limiter: utils_js_1.CapacityLimitReason.balance,
226
237
  };
227
238
  }
228
- getWithdrawCapacityLimit(shares) {
239
+ /**
240
+ * Returns the maximum amount of assets that can be withdrawn from the vault.
241
+ * @param shares The maximum amount of shares to redeem.
242
+ */
243
+ maxWithdraw(shares) {
229
244
  const assets = this.toAssets(shares);
230
245
  const { liquidity } = this;
231
246
  if (assets > liquidity)
232
247
  return {
233
248
  value: liquidity,
234
- limiter: index_js_1.CapacityLimitReason.liquidity,
249
+ limiter: utils_js_1.CapacityLimitReason.liquidity,
235
250
  };
236
251
  return {
237
252
  value: assets,
238
- limiter: index_js_1.CapacityLimitReason.balance,
253
+ limiter: utils_js_1.CapacityLimitReason.balance,
239
254
  };
240
255
  }
241
256
  /**
@@ -253,10 +268,10 @@ class AccrualVault extends Vault {
253
268
  };
254
269
  }));
255
270
  if (vault.lostAssets != null) {
256
- vault.lostAssets += index_js_2.MathLib.max(vault.lastTotalAssets - vault.lostAssets - vault.totalAssets, 0n);
271
+ vault.lostAssets += index_js_1.MathLib.max(vault.lastTotalAssets - vault.lostAssets - vault.totalAssets, 0n);
257
272
  vault.totalAssets += vault.lostAssets;
258
273
  }
259
- const feeAssets = index_js_2.MathLib.wMulDown(vault.totalInterest, vault.fee);
274
+ const feeAssets = index_js_1.MathLib.wMulDown(vault.totalInterest, vault.fee);
260
275
  vault.totalAssets -= feeAssets;
261
276
  const feeShares = vault.toShares(feeAssets, "Down");
262
277
  vault.totalAssets += feeAssets;
@@ -1,7 +1,7 @@
1
1
  import type { AccrualPosition } from "../position/index.js";
2
- import { type IVaultMarketConfig, VaultMarketConfig } from "./VaultMarketConfig.js";
2
+ import type { VaultMarketConfig } from "./VaultMarketConfig.js";
3
3
  export interface IVaultMarketAllocation {
4
- config: IVaultMarketConfig;
4
+ config: VaultMarketConfig;
5
5
  position: AccrualPosition;
6
6
  }
7
7
  export declare class VaultMarketAllocation implements IVaultMarketAllocation {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultMarketAllocation = void 0;
4
4
  const index_js_1 = require("../math/index.js");
5
- const VaultMarketConfig_js_1 = require("./VaultMarketConfig.js");
6
5
  class VaultMarketAllocation {
7
6
  /**
8
7
  * The vault's configuration on the corresponding market.
@@ -13,7 +12,7 @@ class VaultMarketAllocation {
13
12
  */
14
13
  position;
15
14
  constructor({ config, position }) {
16
- this.config = new VaultMarketConfig_js_1.VaultMarketConfig(config);
15
+ this.config = config;
17
16
  this.position = position;
18
17
  }
19
18
  get vault() {
@@ -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);
@@ -0,0 +1,87 @@
1
+ import { type Address, type Hash, type Hex } from "viem";
2
+ import { type RoundingDirection } from "../../math";
3
+ import { type IToken, WrappedToken } from "../../token";
4
+ import type { BigIntish } from "../../types";
5
+ import { type CapacityLimit } from "../../utils";
6
+ import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter";
7
+ export interface IVaultV2Allocation {
8
+ id: Hash;
9
+ absoluteCap: bigint;
10
+ relativeCap: bigint;
11
+ allocation: bigint;
12
+ }
13
+ export interface IVaultV2 extends IToken {
14
+ asset: Address;
15
+ /**
16
+ * The total assets, *including* virtually accrued interest.
17
+ */
18
+ totalAssets: bigint;
19
+ /**
20
+ * The total assets, *excluding* virtually accrued interest.
21
+ */
22
+ _totalAssets: bigint;
23
+ /**
24
+ * The total supply of shares.
25
+ */
26
+ totalSupply: bigint;
27
+ virtualShares: bigint;
28
+ maxRate: bigint;
29
+ lastUpdate: bigint;
30
+ adapters: Address[];
31
+ liquidityAdapter: Address;
32
+ liquidityData: Hex;
33
+ liquidityAllocations: IVaultV2Allocation[] | undefined;
34
+ performanceFee: bigint;
35
+ managementFee: bigint;
36
+ performanceFeeRecipient: Address;
37
+ managementFeeRecipient: Address;
38
+ }
39
+ export declare class VaultV2 extends WrappedToken implements IVaultV2 {
40
+ readonly asset: Address;
41
+ totalAssets: bigint;
42
+ _totalAssets: bigint;
43
+ totalSupply: bigint;
44
+ virtualShares: bigint;
45
+ maxRate: bigint;
46
+ lastUpdate: bigint;
47
+ adapters: `0x${string}`[];
48
+ liquidityAdapter: `0x${string}`;
49
+ liquidityData: `0x${string}`;
50
+ liquidityAllocations: IVaultV2Allocation[] | undefined;
51
+ performanceFee: bigint;
52
+ managementFee: bigint;
53
+ performanceFeeRecipient: `0x${string}`;
54
+ managementFeeRecipient: `0x${string}`;
55
+ constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
56
+ toAssets(shares: BigIntish): bigint;
57
+ toShares(assets: BigIntish): bigint;
58
+ protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
59
+ protected _unwrap(amount: BigIntish, rounding: RoundingDirection): bigint;
60
+ }
61
+ export interface IAccrualVaultV2 extends Omit<IVaultV2, "adapters"> {
62
+ }
63
+ export declare class AccrualVaultV2 extends VaultV2 implements IAccrualVaultV2 {
64
+ accrualLiquidityAdapter: IAccrualVaultV2Adapter | undefined;
65
+ accrualAdapters: IAccrualVaultV2Adapter[];
66
+ assetBalance: bigint;
67
+ constructor(vault: IAccrualVaultV2, accrualLiquidityAdapter: IAccrualVaultV2Adapter | undefined, accrualAdapters: IAccrualVaultV2Adapter[], assetBalance: bigint);
68
+ /**
69
+ * Returns the maximum amount of assets that can be deposited to the vault.
70
+ * @param assets The maximum amount of assets to deposit.
71
+ */
72
+ maxDeposit(assets: BigIntish): CapacityLimit;
73
+ /**
74
+ * Returns the maximum amount of assets that can be withdrawn from the vault.
75
+ * @param shares The maximum amount of shares to redeem.
76
+ */
77
+ maxWithdraw(shares: BigIntish): CapacityLimit;
78
+ /**
79
+ * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
80
+ * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the vault's `lastUpdate`.
81
+ */
82
+ accrueInterest(timestamp: BigIntish): {
83
+ vault: AccrualVaultV2;
84
+ performanceFeeShares: bigint;
85
+ managementFeeShares: bigint;
86
+ };
87
+ }
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccrualVaultV2 = exports.VaultV2 = void 0;
4
+ const viem_1 = require("viem");
5
+ const errors_1 = require("../../errors");
6
+ const math_1 = require("../../math");
7
+ const token_1 = require("../../token");
8
+ const utils_1 = require("../../utils");
9
+ const VaultV2MorphoVaultV1Adapter_1 = require("./VaultV2MorphoVaultV1Adapter");
10
+ class VaultV2 extends token_1.WrappedToken {
11
+ asset;
12
+ totalAssets;
13
+ _totalAssets;
14
+ totalSupply;
15
+ virtualShares;
16
+ maxRate;
17
+ lastUpdate;
18
+ adapters;
19
+ liquidityAdapter;
20
+ liquidityData;
21
+ liquidityAllocations;
22
+ performanceFee;
23
+ managementFee;
24
+ performanceFeeRecipient;
25
+ managementFeeRecipient;
26
+ constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }) {
27
+ super(config, asset);
28
+ this.asset = asset;
29
+ this.totalAssets = totalAssets;
30
+ this._totalAssets = _totalAssets;
31
+ this.totalSupply = totalSupply;
32
+ this.virtualShares = virtualShares;
33
+ this.maxRate = maxRate;
34
+ this.lastUpdate = lastUpdate;
35
+ this.adapters = adapters;
36
+ this.liquidityAdapter = liquidityAdapter;
37
+ this.liquidityData = liquidityData;
38
+ this.liquidityAllocations = liquidityAllocations;
39
+ this.performanceFee = performanceFee;
40
+ this.managementFee = managementFee;
41
+ this.performanceFeeRecipient = performanceFeeRecipient;
42
+ this.managementFeeRecipient = managementFeeRecipient;
43
+ }
44
+ toAssets(shares) {
45
+ return this._unwrap(shares, "Down");
46
+ }
47
+ toShares(assets) {
48
+ return this._wrap(assets, "Down");
49
+ }
50
+ _wrap(amount, rounding) {
51
+ return math_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
52
+ }
53
+ _unwrap(amount, rounding) {
54
+ return math_1.MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
55
+ }
56
+ }
57
+ exports.VaultV2 = VaultV2;
58
+ class AccrualVaultV2 extends VaultV2 {
59
+ accrualLiquidityAdapter;
60
+ accrualAdapters;
61
+ assetBalance;
62
+ constructor(vault, accrualLiquidityAdapter, accrualAdapters, assetBalance) {
63
+ super({ ...vault, adapters: accrualAdapters.map((a) => a.address) });
64
+ this.accrualLiquidityAdapter = accrualLiquidityAdapter;
65
+ this.accrualAdapters = accrualAdapters;
66
+ this.assetBalance = assetBalance;
67
+ }
68
+ /**
69
+ * Returns the maximum amount of assets that can be deposited to the vault.
70
+ * @param assets The maximum amount of assets to deposit.
71
+ */
72
+ maxDeposit(assets) {
73
+ if (this.liquidityAdapter === viem_1.zeroAddress)
74
+ return { value: BigInt(assets), limiter: utils_1.CapacityLimitReason.balance };
75
+ let liquidityAdapterLimit;
76
+ if (this.accrualLiquidityAdapter instanceof VaultV2MorphoVaultV1Adapter_1.AccrualVaultV2MorphoVaultV1Adapter) {
77
+ liquidityAdapterLimit = this.accrualLiquidityAdapter.maxDeposit(this.liquidityData, assets);
78
+ }
79
+ if (this.liquidityAllocations == null || liquidityAdapterLimit == null)
80
+ throw new errors_1.VaultV2Errors.UnsupportedLiquidityAdapter(this.liquidityAdapter);
81
+ // At this stage: `liquidityAdapterLimit.value <= assets`
82
+ for (const { absoluteCap, relativeCap, allocation } of this
83
+ .liquidityAllocations) {
84
+ // `absoluteCap` can be set lower than `allocation`.
85
+ const absoluteMaxDeposit = math_1.MathLib.zeroFloorSub(absoluteCap, allocation);
86
+ if (liquidityAdapterLimit.value > absoluteMaxDeposit)
87
+ return {
88
+ value: absoluteMaxDeposit,
89
+ limiter: utils_1.CapacityLimitReason.vaultV2_absoluteCap,
90
+ };
91
+ // `relativeCap` can be set lower than `allocation / totalAssets`.
92
+ const relativeMaxDeposit = math_1.MathLib.zeroFloorSub(math_1.MathLib.wMulDown(this.totalAssets, relativeCap), allocation);
93
+ if (liquidityAdapterLimit.value > relativeMaxDeposit &&
94
+ relativeCap !== math_1.MathLib.WAD)
95
+ return {
96
+ value: relativeMaxDeposit,
97
+ limiter: utils_1.CapacityLimitReason.vaultV2_relativeCap,
98
+ };
99
+ }
100
+ return liquidityAdapterLimit;
101
+ }
102
+ /**
103
+ * Returns the maximum amount of assets that can be withdrawn from the vault.
104
+ * @param shares The maximum amount of shares to redeem.
105
+ */
106
+ maxWithdraw(shares) {
107
+ const assets = this.toAssets(shares);
108
+ if (this.liquidityAdapter === viem_1.zeroAddress)
109
+ return { value: BigInt(assets), limiter: utils_1.CapacityLimitReason.balance };
110
+ let liquidity = this.assetBalance;
111
+ if (this.accrualLiquidityAdapter instanceof VaultV2MorphoVaultV1Adapter_1.AccrualVaultV2MorphoVaultV1Adapter)
112
+ liquidity += this.accrualLiquidityAdapter.maxWithdraw(this.liquidityData).value;
113
+ if (assets > liquidity)
114
+ return {
115
+ value: liquidity,
116
+ limiter: utils_1.CapacityLimitReason.liquidity,
117
+ };
118
+ return {
119
+ value: assets,
120
+ limiter: utils_1.CapacityLimitReason.balance,
121
+ };
122
+ }
123
+ /**
124
+ * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
125
+ * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the vault's `lastUpdate`.
126
+ */
127
+ accrueInterest(timestamp) {
128
+ const vault = new AccrualVaultV2(this, this.accrualLiquidityAdapter, this.accrualAdapters, this.assetBalance);
129
+ timestamp = BigInt(timestamp);
130
+ const elapsed = timestamp - this.lastUpdate;
131
+ if (elapsed < 0n)
132
+ throw new errors_1.VaultV2Errors.InvalidInterestAccrual(this.address, timestamp, this.lastUpdate);
133
+ // Corresponds to the `firstTotalAssets == 0` onchain check.
134
+ if (elapsed === 0n)
135
+ return { vault, performanceFeeShares: 0n, managementFeeShares: 0n };
136
+ const realAssets = vault.accrualAdapters.reduce((curr, adapter) => curr + adapter.realAssets(timestamp), vault.assetBalance);
137
+ const maxTotalAssets = vault._totalAssets +
138
+ math_1.MathLib.wMulDown(vault._totalAssets * elapsed, vault.maxRate);
139
+ const newTotalAssets = math_1.MathLib.min(realAssets, maxTotalAssets);
140
+ const interest = math_1.MathLib.zeroFloorSub(newTotalAssets, vault._totalAssets);
141
+ const performanceFeeAssets = interest > 0n && vault.performanceFee > 0n
142
+ ? math_1.MathLib.wMulDown(interest, vault.performanceFee)
143
+ : 0n;
144
+ const managementFeeAssets = elapsed > 0n && vault.managementFee > 0n
145
+ ? math_1.MathLib.wMulDown(newTotalAssets * elapsed, vault.managementFee)
146
+ : 0n;
147
+ const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
148
+ const performanceFeeShares = math_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
149
+ const managementFeeShares = math_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
150
+ vault.totalAssets = newTotalAssets;
151
+ vault._totalAssets = newTotalAssets;
152
+ if (performanceFeeShares)
153
+ vault.totalSupply += performanceFeeShares;
154
+ if (managementFeeShares)
155
+ vault.totalSupply += managementFeeShares;
156
+ vault.lastUpdate = BigInt(timestamp);
157
+ return { vault, performanceFeeShares, managementFeeShares };
158
+ }
159
+ }
160
+ exports.AccrualVaultV2 = AccrualVaultV2;
@@ -0,0 +1,29 @@
1
+ import type { Address, Hash, Hex } from "viem";
2
+ import type { BigIntish } from "../../types";
3
+ import type { CapacityLimit } from "../../utils";
4
+ export interface IVaultV2Adapter {
5
+ address: Address;
6
+ parentVault: Address;
7
+ adapterId: Hash;
8
+ skimRecipient: Address;
9
+ }
10
+ export declare abstract class VaultV2Adapter implements IVaultV2Adapter {
11
+ readonly address: Address;
12
+ readonly parentVault: Address;
13
+ readonly adapterId: Hash;
14
+ skimRecipient: Address;
15
+ constructor({ address, parentVault, adapterId, skimRecipient, }: IVaultV2Adapter);
16
+ }
17
+ export interface IAccrualVaultV2Adapter extends IVaultV2Adapter {
18
+ realAssets(timestamp: BigIntish): bigint;
19
+ /**
20
+ * Returns the maximum amount of assets that can be deposited to this adapter.
21
+ * @param assets The maximum amount of assets to deposit.
22
+ */
23
+ maxDeposit(data: Hex, assets: BigIntish): CapacityLimit;
24
+ /**
25
+ * Returns the maximum amount of assets that can be withdrawn from this adapter.
26
+ * @param shares The maximum amount of shares to redeem.
27
+ */
28
+ maxWithdraw(data: Hex): CapacityLimit;
29
+ }
@@ -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,24 @@
1
+ import { type Address, type Hex } 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
+ static adapterId(address: Address): `0x${string}`;
11
+ readonly morphoVaultV1: Address;
12
+ constructor({ morphoVaultV1, ...vaultV2Adapter }: IVaultV2MorphoVaultV1Adapter);
13
+ ids(): `0x${string}`[];
14
+ }
15
+ export interface IAccrualVaultV2MorphoVaultV1Adapter extends IVaultV2MorphoVaultV1Adapter {
16
+ }
17
+ export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter implements IAccrualVaultV2MorphoVaultV1Adapter, IAccrualVaultV2Adapter {
18
+ accrualVaultV1: AccrualVault;
19
+ shares: bigint;
20
+ constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, accrualVaultV1: AccrualVault, shares: bigint);
21
+ realAssets(timestamp: BigIntish): bigint;
22
+ maxDeposit(_data: Hex, assets: BigIntish): import("../..").CapacityLimit;
23
+ maxWithdraw(_data: Hex): import("../..").CapacityLimit;
24
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccrualVaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoVaultV1Adapter = void 0;
4
+ const viem_1 = require("viem");
5
+ const VaultV2Adapter_1 = require("./VaultV2Adapter");
6
+ class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
7
+ static adapterId(address) {
8
+ return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
9
+ }
10
+ morphoVaultV1;
11
+ constructor({ morphoVaultV1, ...vaultV2Adapter }) {
12
+ super({
13
+ ...vaultV2Adapter,
14
+ adapterId: VaultV2MorphoVaultV1Adapter.adapterId(vaultV2Adapter.address),
15
+ });
16
+ this.morphoVaultV1 = morphoVaultV1;
17
+ }
18
+ ids() {
19
+ return [this.adapterId];
20
+ }
21
+ }
22
+ exports.VaultV2MorphoVaultV1Adapter = VaultV2MorphoVaultV1Adapter;
23
+ class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter {
24
+ accrualVaultV1;
25
+ shares;
26
+ constructor(adapter, accrualVaultV1, shares) {
27
+ super(adapter);
28
+ this.accrualVaultV1 = accrualVaultV1;
29
+ this.shares = shares;
30
+ }
31
+ realAssets(timestamp) {
32
+ return this.accrualVaultV1.accrueInterest(timestamp).toAssets(this.shares);
33
+ }
34
+ maxDeposit(_data, assets) {
35
+ return this.accrualVaultV1.maxDeposit(assets);
36
+ }
37
+ maxWithdraw(_data) {
38
+ return this.accrualVaultV1.maxWithdraw(this.shares);
39
+ }
40
+ }
41
+ 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": "5.1.1",
4
+ "version": "5.2.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
- "@morpho-org/test": "^2.6.0",
35
- "@morpho-org/morpho-ts": "^2.4.3"
34
+ "@morpho-org/morpho-ts": "^2.4.3",
35
+ "@morpho-org/test": "^2.6.0"
36
36
  },
37
37
  "scripts": {
38
38
  "prepublish": "$npm_execpath build",