@morpho-org/blue-sdk 5.2.0-next.0 → 5.2.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.
@@ -1,12 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Market = void 0;
3
+ exports.Market = exports.CapacityLimitReason = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const errors_js_1 = require("../errors.js");
6
6
  const index_js_1 = require("../math/index.js");
7
- const utils_js_1 = require("../utils.js");
8
7
  const MarketParams_js_1 = require("./MarketParams.js");
9
8
  const MarketUtils_js_1 = require("./MarketUtils.js");
9
+ var CapacityLimitReason;
10
+ (function (CapacityLimitReason) {
11
+ CapacityLimitReason["liquidity"] = "Liquidity";
12
+ CapacityLimitReason["balance"] = "Balance";
13
+ CapacityLimitReason["position"] = "Position";
14
+ CapacityLimitReason["collateral"] = "Collateral";
15
+ CapacityLimitReason["cap"] = "Cap";
16
+ })(CapacityLimitReason || (exports.CapacityLimitReason = CapacityLimitReason = {}));
10
17
  /**
11
18
  * Represents a lending market on Morpho Blue.
12
19
  */
@@ -87,27 +94,13 @@ class Market {
87
94
  return MarketUtils_js_1.MarketUtils.getUtilization(this);
88
95
  }
89
96
  /**
90
- * The market's Annual Percentage Yield (APY) at the IRM's target utilization rate, if applicable (scaled by WAD).
97
+ * The market's Annual Percentage Yield (APY) at the IRM's target utilization rate, if applicable.
91
98
  */
92
99
  get apyAtTarget() {
93
100
  if (this.rateAtTarget == null)
94
101
  return;
95
102
  return MarketUtils_js_1.MarketUtils.rateToApy(this.rateAtTarget);
96
103
  }
97
- /**
98
- * Returns the rate at which interest accrued for suppliers of this market,
99
- * since the last time the market was updated (scaled by WAD).
100
- * @deprecated There's no such thing as a supply rate in Morpho. Only the supply APY is meaningful.
101
- */
102
- get supplyRate() {
103
- return MarketUtils_js_1.MarketUtils.getSupplyRate(this.avgBorrowRate, this);
104
- }
105
- /**
106
- * @deprecated Use `avgBorrowRate` instead.
107
- */
108
- get borrowRate() {
109
- return this.getAccrualBorrowRates().avgBorrowRate;
110
- }
111
104
  /**
112
105
  * Returns the instantaneous rate at which interest accrues for borrowers of this market,
113
106
  * if `accrueInterest` was called immediately onchain (scaled by WAD).
@@ -138,25 +131,19 @@ class Market {
138
131
  return this.getAccrualBorrowRates().avgBorrowRate;
139
132
  }
140
133
  /**
141
- * The market's current, instantaneous supply-side Annual Percentage Yield (APY) (scaled by WAD).
134
+ * The market's current, instantaneous supply-side Annual Percentage Yield (APY).
142
135
  * If interested in the APY at a specific timestamp, use `getSupplyApy(timestamp)` instead.
143
136
  */
144
137
  get supplyApy() {
145
138
  return this.getSupplyApy();
146
139
  }
147
140
  /**
148
- * The market's current, instantaneous borrow-side Annual Percentage Yield (APY) (scaled by WAD).
141
+ * The market's current, instantaneous borrow-side Annual Percentage Yield (APY).
149
142
  * If interested in the APY at a specific timestamp, use `getBorrowApy(timestamp)` instead.
150
143
  */
151
144
  get borrowApy() {
152
145
  return this.getBorrowApy();
153
146
  }
154
- /**
155
- * @deprecated Use `getEndBorrowRate(timestamp)` instead.
156
- */
157
- getBorrowRate(timestamp = morpho_ts_1.Time.timestamp()) {
158
- return this.getAccrualBorrowRates(timestamp).endBorrowRate;
159
- }
160
147
  /**
161
148
  * Returns the instantaneous rate at which interest accrues for borrowers of this market,
162
149
  * at the given timestamp, if the state remains unchanged (not accrued) (scaled by WAD).
@@ -204,7 +191,7 @@ class Market {
204
191
  }
205
192
  /**
206
193
  * The market's instantaneous borrow-side Annual Percentage Yield (APY) at the given timestamp,
207
- * if the state remains unchanged (not accrued) (scaled by WAD).
194
+ * if the state remains unchanged (not accrued).
208
195
  * @param timestamp The timestamp at which to calculate the borrow APY.
209
196
  * Must be greater than or equal to `lastUpdate`.
210
197
  * Defaults to `Time.timestamp()` (returns the current borrow APY).
@@ -215,18 +202,18 @@ class Market {
215
202
  }
216
203
  /**
217
204
  * The market's instantaneous supply-side Annual Percentage Yield (APY) at the given timestamp,
218
- * if the state remains unchanged (not accrued) (scaled by WAD).
205
+ * if the state remains unchanged (not accrued).
219
206
  * @param timestamp The timestamp at which to calculate the supply APY.
220
207
  * Must be greater than or equal to `lastUpdate`.
221
208
  * Defaults to `Time.timestamp()` (returns the current supply APY).
222
209
  */
223
210
  getSupplyApy(timestamp = morpho_ts_1.Time.timestamp()) {
224
- const borrowApy = this.getBorrowApy(timestamp);
225
- return index_js_1.MathLib.wMulUp(index_js_1.MathLib.wMulDown(borrowApy, this.utilization), index_js_1.MathLib.WAD - this.fee);
211
+ const borrowRate = this.getEndBorrowRate(timestamp);
212
+ return MarketUtils_js_1.MarketUtils.rateToApy(index_js_1.MathLib.wMulUp(index_js_1.MathLib.wMulDown(borrowRate, this.utilization), index_js_1.MathLib.WAD - this.fee));
226
213
  }
227
214
  /**
228
215
  * The market's experienced borrow-side Annual Percentage Yield (APY),
229
- * if interest was to be accrued at the given timestamp (scaled by WAD).
216
+ * if interest was to be accrued at the given timestamp.
230
217
  * @param timestamp The timestamp at which to calculate the borrow APY.
231
218
  * Must be greater than or equal to `lastUpdate`.
232
219
  * Defaults to `Time.timestamp()` (returns the current borrow APY).
@@ -235,16 +222,26 @@ class Market {
235
222
  const borrowRate = this.getAvgBorrowRate(timestamp);
236
223
  return MarketUtils_js_1.MarketUtils.rateToApy(borrowRate);
237
224
  }
225
+ /**
226
+ * Returns the average rate at which interest _would_ accrue for suppliers of this market,
227
+ * if `accrueInterest` was called at the given timestamp (scaled by WAD).
228
+ * @param timestamp The timestamp at which to calculate the average supply rate.
229
+ * Must be greater than or equal to `lastUpdate`.
230
+ * Defaults to `Time.timestamp()` (returns the current average supply rate).
231
+ */
232
+ getAvgSupplyRate(timestamp = morpho_ts_1.Time.timestamp()) {
233
+ const borrowRate = this.getAvgBorrowRate(timestamp);
234
+ return index_js_1.MathLib.wMulUp(index_js_1.MathLib.wMulDown(borrowRate, this.utilization), index_js_1.MathLib.WAD - this.fee);
235
+ }
238
236
  /**
239
237
  * The market's experienced supply-side Annual Percentage Yield (APY),
240
- * if interest was to be accrued at the given timestamp (scaled by WAD).
238
+ * if interest was to be accrued at the given timestamp.
241
239
  * @param timestamp The timestamp at which to calculate the supply APY.
242
240
  * Must be greater than or equal to `lastUpdate`.
243
241
  * Defaults to `Time.timestamp()` (returns the current supply APY).
244
242
  */
245
243
  getAvgSupplyApy(timestamp = morpho_ts_1.Time.timestamp()) {
246
- const borrowApy = this.getAvgBorrowApy(timestamp);
247
- return index_js_1.MathLib.wMulUp(index_js_1.MathLib.wMulDown(borrowApy, this.utilization), index_js_1.MathLib.WAD - this.fee);
244
+ return MarketUtils_js_1.MarketUtils.rateToApy(this.getAvgSupplyRate(timestamp));
248
245
  }
249
246
  /**
250
247
  * Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
@@ -500,11 +497,11 @@ class Market {
500
497
  if (maxBorrowableAssets > liquidity)
501
498
  return {
502
499
  value: liquidity,
503
- limiter: utils_js_1.CapacityLimitReason.liquidity,
500
+ limiter: CapacityLimitReason.liquidity,
504
501
  };
505
502
  return {
506
503
  value: maxBorrowableAssets,
507
- limiter: utils_js_1.CapacityLimitReason.collateral,
504
+ limiter: CapacityLimitReason.collateral,
508
505
  };
509
506
  }
510
507
  /**
@@ -517,11 +514,11 @@ class Market {
517
514
  if (borrowAssets > loanTokenBalance)
518
515
  return {
519
516
  value: loanTokenBalance,
520
- limiter: utils_js_1.CapacityLimitReason.balance,
517
+ limiter: CapacityLimitReason.balance,
521
518
  };
522
519
  return {
523
520
  value: borrowAssets,
524
- limiter: utils_js_1.CapacityLimitReason.position,
521
+ limiter: CapacityLimitReason.position,
525
522
  };
526
523
  }
527
524
  /**
@@ -535,11 +532,11 @@ class Market {
535
532
  if (supplyAssets > liquidity)
536
533
  return {
537
534
  value: liquidity,
538
- limiter: utils_js_1.CapacityLimitReason.liquidity,
535
+ limiter: CapacityLimitReason.liquidity,
539
536
  };
540
537
  return {
541
538
  value: supplyAssets,
542
- limiter: utils_js_1.CapacityLimitReason.position,
539
+ limiter: CapacityLimitReason.position,
543
540
  };
544
541
  }
545
542
  /**
@@ -555,11 +552,11 @@ class Market {
555
552
  if (position.collateral > withdrawableCollateral)
556
553
  return {
557
554
  value: withdrawableCollateral,
558
- limiter: utils_js_1.CapacityLimitReason.collateral,
555
+ limiter: CapacityLimitReason.collateral,
559
556
  };
560
557
  return {
561
558
  value: position.collateral,
562
- limiter: utils_js_1.CapacityLimitReason.position,
559
+ limiter: CapacityLimitReason.position,
563
560
  };
564
561
  }
565
562
  /**
@@ -573,14 +570,14 @@ class Market {
573
570
  return {
574
571
  supply: {
575
572
  value: loanTokenBalance,
576
- limiter: utils_js_1.CapacityLimitReason.balance,
573
+ limiter: CapacityLimitReason.balance,
577
574
  },
578
575
  withdraw: this.getWithdrawCapacityLimit(position),
579
576
  borrow: this.getBorrowCapacityLimit(position, options?.borrow),
580
577
  repay: this.getRepayCapacityLimit(position.borrowShares, loanTokenBalance),
581
578
  supplyCollateral: {
582
579
  value: collateralTokenBalance,
583
- limiter: utils_js_1.CapacityLimitReason.balance,
580
+ limiter: CapacityLimitReason.balance,
584
581
  },
585
582
  withdrawCollateral: this.getWithdrawCollateralCapacityLimit(position, options?.withdrawCollateral),
586
583
  };
@@ -26,29 +26,11 @@ export declare namespace MarketUtils {
26
26
  totalBorrowAssets: BigIntish;
27
27
  }): bigint;
28
28
  /**
29
- * Returns the rate at which interest accrued for suppliers on the corresponding market,
30
- * since the last time the market was updated (scaled by WAD).
31
- * @param borrowRate The average borrow rate since the last market update (scaled by WAD).
32
- * @param market The market state.
33
- * @deprecated There's no such thing as a supply rate in Morpho. Only the supply APY is meaningful.
34
- */
35
- function getSupplyRate(borrowRate: BigIntish, { utilization, fee }: {
36
- utilization: BigIntish;
37
- fee: BigIntish;
38
- }): bigint;
39
- /**
40
- * Returns the per-second rate continuously compounded over the given period, as calculated in Morpho Blue (scaled by WAD).
41
- * @param rate The per-second rate to compound (scaled by WAD).
42
- * @param period The period to compound the rate over (in seconds). Defaults to 1 year.
43
- * @deprecated The compounded rate is inaccurate if rate * period >> 0. If interested in the APY, use `rateToApy` instead.
44
- */
45
- function compoundRate(rate: BigIntish, period?: BigIntish): bigint;
46
- /**
47
- * Returns the per-second rate continuously compounded over a year (scaled by WAD),
29
+ * Returns the per-second rate continuously compounded over a year,
48
30
  * as calculated in Morpho Blue assuming the market is frequently accrued onchain.
49
- * @param rate The per-second rate to compound annually (scaled by WAD).
31
+ * @param rate The per-second rate to compound annually.
50
32
  */
51
- function rateToApy(rate: BigIntish): bigint;
33
+ function rateToApy(rate: BigIntish): number;
52
34
  /**
53
35
  * Returns the interest accrued on both sides of the given market
54
36
  * as well as the supply shares minted to the fee recipient.
@@ -6,7 +6,6 @@ const utils_1 = require("@noble/hashes/utils");
6
6
  const viem_1 = require("viem");
7
7
  const constants_js_1 = require("../constants.js");
8
8
  const index_js_1 = require("../math/index.js");
9
- const utils_js_1 = require("../utils.js");
10
9
  /**
11
10
  * Namespace of utility functions to ease market-related calculations.
12
11
  */
@@ -52,35 +51,12 @@ var MarketUtils;
52
51
  }
53
52
  MarketUtils.getUtilization = getUtilization;
54
53
  /**
55
- * Returns the rate at which interest accrued for suppliers on the corresponding market,
56
- * since the last time the market was updated (scaled by WAD).
57
- * @param borrowRate The average borrow rate since the last market update (scaled by WAD).
58
- * @param market The market state.
59
- * @deprecated There's no such thing as a supply rate in Morpho. Only the supply APY is meaningful.
60
- */
61
- function getSupplyRate(borrowRate, { utilization, fee }) {
62
- const borrowRateWithoutFees = index_js_1.MathLib.wMulUp(borrowRate, utilization);
63
- return index_js_1.MathLib.wMulUp(borrowRateWithoutFees, index_js_1.MathLib.WAD - BigInt(fee));
64
- }
65
- MarketUtils.getSupplyRate = getSupplyRate;
66
- /**
67
- * Returns the per-second rate continuously compounded over the given period, as calculated in Morpho Blue (scaled by WAD).
68
- * @param rate The per-second rate to compound (scaled by WAD).
69
- * @param period The period to compound the rate over (in seconds). Defaults to 1 year.
70
- * @deprecated The compounded rate is inaccurate if rate * period >> 0. If interested in the APY, use `rateToApy` instead.
71
- */
72
- function compoundRate(rate, period = constants_js_1.SECONDS_PER_YEAR) {
73
- return index_js_1.MathLib.wTaylorCompounded(rate, period);
74
- }
75
- MarketUtils.compoundRate = compoundRate;
76
- /**
77
- * Returns the per-second rate continuously compounded over a year (scaled by WAD),
54
+ * Returns the per-second rate continuously compounded over a year,
78
55
  * as calculated in Morpho Blue assuming the market is frequently accrued onchain.
79
- * @param rate The per-second rate to compound annually (scaled by WAD).
56
+ * @param rate The per-second rate to compound annually.
80
57
  */
81
- // TODO: return a Number for APYs.
82
58
  function rateToApy(rate) {
83
- return (0, utils_js_1.safeParseNumber)(Math.expm1(+(0, viem_1.formatEther)(BigInt(rate) * constants_js_1.SECONDS_PER_YEAR)));
59
+ return Math.expm1(+(0, viem_1.formatEther)(BigInt(rate) * constants_js_1.SECONDS_PER_YEAR));
84
60
  }
85
61
  MarketUtils.rateToApy = rateToApy;
86
62
  /**
@@ -109,7 +109,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
109
109
  * Returns the maximum amount of loan assets that can be withdrawn given a certain supply position
110
110
  * and a balance of loan assets, and the reason for the limit.
111
111
  */
112
- get withdrawCapacityLimit(): import("../utils.js").CapacityLimit;
112
+ get withdrawCapacityLimit(): import("../market/Market.js").CapacityLimit;
113
113
  /**
114
114
  * Returns a new position derived from this position, whose interest has been accrued up to the given timestamp.
115
115
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the market's `lastUpdate`.
@@ -137,9 +137,9 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
137
137
  assets: bigint;
138
138
  shares: bigint;
139
139
  };
140
- getBorrowCapacityLimit(options?: MaxBorrowOptions): import("../utils.js").CapacityLimit | undefined;
141
- getWithdrawCollateralCapacityLimit(options?: MaxWithdrawCollateralOptions): import("../utils.js").CapacityLimit | undefined;
142
- getRepayCapacityLimit(loanTokenBalance: bigint): import("../utils.js").CapacityLimit;
140
+ getBorrowCapacityLimit(options?: MaxBorrowOptions): import("../market/Market.js").CapacityLimit | undefined;
141
+ getWithdrawCollateralCapacityLimit(options?: MaxWithdrawCollateralOptions): import("../market/Market.js").CapacityLimit | undefined;
142
+ getRepayCapacityLimit(loanTokenBalance: bigint): import("../market/Market.js").CapacityLimit;
143
143
  getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint, options?: {
144
144
  borrow?: MaxBorrowOptions;
145
145
  withdrawCollateral?: MaxWithdrawCollateralOptions;
@@ -4,7 +4,6 @@ exports.AccrualPosition = exports.Position = void 0;
4
4
  const errors_js_1 = require("../errors.js");
5
5
  const index_js_1 = require("../market/index.js");
6
6
  const MathLib_js_1 = require("../math/MathLib.js");
7
- const utils_js_1 = require("../utils.js");
8
7
  class Position {
9
8
  /**
10
9
  * The user holding this position.
@@ -226,14 +225,14 @@ class AccrualPosition extends Position {
226
225
  return {
227
226
  supply: {
228
227
  value: loanTokenBalance,
229
- limiter: utils_js_1.CapacityLimitReason.balance,
228
+ limiter: index_js_1.CapacityLimitReason.balance,
230
229
  },
231
230
  withdraw: this.withdrawCapacityLimit,
232
231
  borrow: this.getBorrowCapacityLimit(options?.borrow),
233
232
  repay: this.getRepayCapacityLimit(loanTokenBalance),
234
233
  supplyCollateral: {
235
234
  value: collateralTokenBalance,
236
- limiter: utils_js_1.CapacityLimitReason.balance,
235
+ limiter: index_js_1.CapacityLimitReason.balance,
237
236
  },
238
237
  withdrawCollateral: this.getWithdrawCollateralCapacityLimit(options?.withdrawCollateral),
239
238
  };
@@ -1,5 +1,5 @@
1
1
  import type { RoundingDirection } from "../math/index.js";
2
- import type { Address, BigIntish } from "../types.js";
2
+ import type { Address } from "../types.js";
3
3
  import type { IVaultConfig } from "../vault/VaultConfig.js";
4
4
  import { WrappedToken } from "./WrappedToken.js";
5
5
  export interface IVaultToken {
@@ -18,6 +18,6 @@ export declare class VaultToken extends WrappedToken implements IVaultToken {
18
18
  */
19
19
  totalAssets: bigint;
20
20
  constructor(config: IVaultConfig, { totalAssets, totalSupply }: IVaultToken);
21
- protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
22
- protected _unwrap(amount: BigIntish, rounding: RoundingDirection): bigint;
21
+ protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
22
+ protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
23
23
  }
package/lib/types.d.ts CHANGED
@@ -23,5 +23,4 @@ export declare enum TransactionType {
23
23
  export type Loadable<T> = T | undefined;
24
24
  export type Failable<T> = T | null;
25
25
  export type Fetchable<T> = Failable<Loadable<T>>;
26
- export declare function isFetched<T>(v: Fetchable<T>): v is T;
27
26
  export declare const isMarketId: (value: unknown) => value is MarketId;
package/lib/types.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isMarketId = exports.TransactionType = void 0;
4
- exports.isFetched = isFetched;
5
4
  /**
6
5
  * The possible transaction type on the Blue contract
7
6
  */
@@ -14,9 +13,5 @@ var TransactionType;
14
13
  TransactionType["Borrow"] = "Borrow";
15
14
  TransactionType["Repay"] = "Repay";
16
15
  })(TransactionType || (exports.TransactionType = TransactionType = {}));
17
- // TODO: replace with isDefined
18
- function isFetched(v) {
19
- return v !== undefined && v !== null;
20
- }
21
16
  const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
22
17
  exports.isMarketId = isMarketId;
@@ -1,7 +1,7 @@
1
+ import { type CapacityLimit } from "../market/index.js";
1
2
  import { type RoundingDirection } from "../math/index.js";
2
3
  import { VaultToken } from "../token/index.js";
3
4
  import type { Address, BigIntish, MarketId } from "../types.js";
4
- import { type CapacityLimit } from "../utils.js";
5
5
  import type { IVaultConfig } from "./VaultConfig.js";
6
6
  import { type IVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
7
7
  export interface Pending<T> {
@@ -116,8 +116,8 @@ export declare class Vault extends VaultToken implements IVault {
116
116
  * The amount of interest in assets accrued since the last interaction with the vault.
117
117
  */
118
118
  get totalInterest(): bigint;
119
- toAssets(shares: BigIntish, rounding?: RoundingDirection): bigint;
120
- toShares(assets: BigIntish, rounding?: RoundingDirection): bigint;
119
+ toAssets(shares: bigint, rounding?: RoundingDirection): bigint;
120
+ toShares(assets: bigint, rounding?: RoundingDirection): bigint;
121
121
  }
122
122
  export interface CollateralAllocation {
123
123
  address: Address;
@@ -149,51 +149,37 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
149
149
  get liquidity(): bigint;
150
150
  /**
151
151
  * The MetaMorpho vault's current instantaneous Annual Percentage Yield (APY)
152
- * weighted-averaged over its market deposits, before deducting the performance fee (scaled by WAD).
152
+ * weighted-averaged over its market deposits, before deducting the performance fee.
153
153
  * If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
154
154
  */
155
- get apy(): bigint;
155
+ get apy(): number;
156
156
  /**
157
157
  * The MetaMorpho vault's current instantaneous Annual Percentage Yield (APY)
158
- * weighted-averaged over its market deposits, after deducting the performance fee (scaled by WAD).
159
- * If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
158
+ * weighted-averaged over its market deposits, after deducting the performance fee.
159
+ * If interested in the APY at a specific timestamp, use `getNetApy(timestamp)` instead.
160
+ */
161
+ get netApy(): number;
162
+ /**
163
+ * The MetaMorpho vault's per-second rate at which interest _would_ accrue,
164
+ * weighted-averaged over its market deposits, before deducting the performance fee,
165
+ * if interest was to be accrued on each market at the given timestamp.
160
166
  */
161
- get netApy(): bigint;
167
+ private _getAvgRate;
162
168
  /**
163
169
  * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
164
170
  * weighted-averaged over its market deposits, before deducting the performance fee,
165
- * if interest was to be accrued on each market at the given timestamp (scaled by WAD).
171
+ * if interest was to be accrued on each market at the given timestamp.
166
172
  */
167
- getApy(timestamp?: BigIntish): bigint;
173
+ getApy(timestamp?: BigIntish): number;
168
174
  /**
169
175
  * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
170
176
  * weighted-averaged over its market deposits, after deducting the performance fee,
171
- * if interest was to be accrued on each market at the given timestamp (scaled by WAD).
177
+ * if interest was to be accrued on each market at the given timestamp.
172
178
  */
173
- getNetApy(timestamp?: BigIntish): bigint;
179
+ getNetApy(timestamp?: BigIntish): number;
174
180
  getAllocationProportion(marketId: MarketId): bigint;
175
- /**
176
- * Returns the deposit capacity limit of a given amount of assets on the vault.
177
- * @param assets The maximum amount of assets to deposit.
178
- * @deprecated Use `maxDeposit` instead.
179
- */
180
181
  getDepositCapacityLimit(assets: bigint): CapacityLimit;
181
- /**
182
- * Returns the withdraw capacity limit corresponding to a given amount of shares of the vault.
183
- * @param shares The maximum amount of shares to redeem.
184
- * @deprecated Use `maxWithdraw` instead.
185
- */
186
182
  getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
187
- /**
188
- * Returns the maximum amount of assets that can be deposited to the vault.
189
- * @param assets The maximum amount of assets to deposit.
190
- */
191
- maxDeposit(assets: BigIntish): CapacityLimit;
192
- /**
193
- * Returns the maximum amount of assets that can be withdrawn from the vault.
194
- * @param shares The maximum amount of shares to redeem.
195
- */
196
- maxWithdraw(shares: BigIntish): CapacityLimit;
197
183
  /**
198
184
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
199
185
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
@@ -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("../math/index.js");
6
- const index_js_2 = require("../token/index.js");
7
- const utils_js_1 = require("../utils.js");
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");
8
8
  const VaultMarketAllocation_js_1 = require("./VaultMarketAllocation.js");
9
- class Vault extends index_js_2.VaultToken {
9
+ class Vault extends index_js_3.VaultToken {
10
10
  /**
11
11
  * The MetaMorpho vault's owner address.
12
12
  */
@@ -93,7 +93,7 @@ class Vault extends index_js_2.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_1.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
96
+ return index_js_2.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 (scaled by WAD).
158
+ * weighted-averaged over its market deposits, before deducting the performance fee.
159
159
  * If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
160
160
  */
161
161
  get apy() {
@@ -163,32 +163,42 @@ 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 (scaled by WAD).
167
- * If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
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.
168
168
  */
169
169
  get netApy() {
170
170
  return this.getNetApy();
171
171
  }
172
172
  /**
173
- * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
173
+ * The MetaMorpho vault's per-second rate at which interest _would_ accrue,
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 (scaled by WAD).
175
+ * if interest was to be accrued on each market at the given timestamp.
176
176
  */
177
- getApy(timestamp = morpho_ts_1.Time.timestamp()) {
177
+ _getAvgRate(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.getAvgSupplyApy(timestamp) * position.supplyAssets, 0n) / this.totalAssets);
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));
184
194
  }
185
195
  /**
186
196
  * The MetaMorpho vault's experienced Annual Percentage Yield (APY)
187
197
  * weighted-averaged over its market deposits, after deducting the performance fee,
188
- * if interest was to be accrued on each market at the given timestamp (scaled by WAD).
198
+ * if interest was to be accrued on each market at the given timestamp.
189
199
  */
190
200
  getNetApy(timestamp = morpho_ts_1.Time.timestamp()) {
191
- return index_js_1.MathLib.wMulDown(this.getApy(timestamp), index_js_1.MathLib.WAD - this.fee);
201
+ return index_js_1.MarketUtils.rateToApy(index_js_2.MathLib.wMulDown(this._getAvgRate(timestamp), index_js_2.MathLib.WAD - this.fee));
192
202
  }
193
203
  getAllocationProportion(marketId) {
194
204
  if (this.totalAssets === 0n)
@@ -196,61 +206,36 @@ class AccrualVault extends Vault {
196
206
  const allocation = this.allocations.get(marketId);
197
207
  if (!allocation)
198
208
  return 0n;
199
- return index_js_1.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
209
+ return index_js_2.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
200
210
  }
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
- */
206
211
  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);
223
212
  const suppliable = this.allocations
224
213
  .values()
225
- .reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_1.MathLib.min(total +
214
+ .reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_2.MathLib.min(total +
226
215
  (this.supplyQueue.includes(marketId)
227
- ? index_js_1.MathLib.zeroFloorSub(cap, supplyAssets)
228
- : 0n), index_js_1.MathLib.MAX_UINT_256), 0n);
216
+ ? index_js_2.MathLib.zeroFloorSub(cap, supplyAssets)
217
+ : 0n), index_js_2.MathLib.MAX_UINT_256), 0n);
229
218
  if (assets > suppliable)
230
219
  return {
231
220
  value: suppliable,
232
- limiter: utils_js_1.CapacityLimitReason.cap,
221
+ limiter: index_js_1.CapacityLimitReason.cap,
233
222
  };
234
223
  return {
235
224
  value: assets,
236
- limiter: utils_js_1.CapacityLimitReason.balance,
225
+ limiter: index_js_1.CapacityLimitReason.balance,
237
226
  };
238
227
  }
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) {
228
+ getWithdrawCapacityLimit(shares) {
244
229
  const assets = this.toAssets(shares);
245
230
  const { liquidity } = this;
246
231
  if (assets > liquidity)
247
232
  return {
248
233
  value: liquidity,
249
- limiter: utils_js_1.CapacityLimitReason.liquidity,
234
+ limiter: index_js_1.CapacityLimitReason.liquidity,
250
235
  };
251
236
  return {
252
237
  value: assets,
253
- limiter: utils_js_1.CapacityLimitReason.balance,
238
+ limiter: index_js_1.CapacityLimitReason.balance,
254
239
  };
255
240
  }
256
241
  /**
@@ -268,10 +253,10 @@ class AccrualVault extends Vault {
268
253
  };
269
254
  }));
270
255
  if (vault.lostAssets != null) {
271
- vault.lostAssets += index_js_1.MathLib.max(vault.lastTotalAssets - vault.lostAssets - vault.totalAssets, 0n);
256
+ vault.lostAssets += index_js_2.MathLib.max(vault.lastTotalAssets - vault.lostAssets - vault.totalAssets, 0n);
272
257
  vault.totalAssets += vault.lostAssets;
273
258
  }
274
- const feeAssets = index_js_1.MathLib.wMulDown(vault.totalInterest, vault.fee);
259
+ const feeAssets = index_js_2.MathLib.wMulDown(vault.totalInterest, vault.fee);
275
260
  vault.totalAssets -= feeAssets;
276
261
  const feeShares = vault.toShares(feeAssets, "Down");
277
262
  vault.totalAssets += feeAssets;
@@ -1,7 +1,7 @@
1
1
  import type { AccrualPosition } from "../position/index.js";
2
- import type { VaultMarketConfig } from "./VaultMarketConfig.js";
2
+ import { type IVaultMarketConfig, VaultMarketConfig } from "./VaultMarketConfig.js";
3
3
  export interface IVaultMarketAllocation {
4
- config: VaultMarketConfig;
4
+ config: IVaultMarketConfig;
5
5
  position: AccrualPosition;
6
6
  }
7
7
  export declare class VaultMarketAllocation implements IVaultMarketAllocation {