@morpho-org/blue-sdk 6.1.0 → 6.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.
@@ -740,6 +740,36 @@ declare const _addressesRegistry: {
740
740
  readonly chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8";
741
741
  readonly preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922";
742
742
  };
743
+ readonly 2818: {
744
+ readonly morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905";
745
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
746
+ readonly bundler3: {
747
+ readonly bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628";
748
+ readonly generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776";
749
+ };
750
+ readonly adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319";
751
+ readonly vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B";
752
+ readonly morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6";
753
+ readonly registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481";
754
+ readonly chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1";
755
+ readonly preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866";
756
+ readonly wNative: "0x5300000000000000000000000000000000000011";
757
+ };
758
+ readonly 4326: {
759
+ readonly morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100";
760
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
761
+ readonly bundler3: {
762
+ readonly bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63";
763
+ readonly generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b";
764
+ };
765
+ readonly adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323";
766
+ readonly vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B";
767
+ readonly morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012";
768
+ readonly registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c";
769
+ readonly chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2";
770
+ readonly preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8";
771
+ readonly wNative: "0x4200000000000000000000000000000000000006";
772
+ };
743
773
  };
744
774
  /** Deployment block registry with the same shape as `ChainAddresses`. */
745
775
  export type ChainDeployments<Addresses = ChainAddresses> = {
@@ -1354,6 +1384,36 @@ declare const _deployments: {
1354
1384
  readonly chainlinkOracleFactory: 1208882n;
1355
1385
  readonly preLiquidationFactory: 1208882n;
1356
1386
  };
1387
+ readonly 2818: {
1388
+ readonly morpho: 23180020n;
1389
+ readonly permit2: 5081244n;
1390
+ readonly bundler3: {
1391
+ readonly bundler3: 23180020n;
1392
+ readonly generalAdapter1: 23180020n;
1393
+ };
1394
+ readonly adaptiveCurveIrm: 23180020n;
1395
+ readonly vaultV2Factory: 23180183n;
1396
+ readonly morphoMarketV1AdapterV2Factory: 23180228n;
1397
+ readonly registryList: 23180228n;
1398
+ readonly chainlinkOracleFactory: 23180111n;
1399
+ readonly preLiquidationFactory: 23180111n;
1400
+ readonly wNative: 0n;
1401
+ };
1402
+ readonly 4326: {
1403
+ readonly morpho: 16408957n;
1404
+ readonly permit2: 0n;
1405
+ readonly bundler3: {
1406
+ readonly bundler3: 16408957n;
1407
+ readonly generalAdapter1: 16408957n;
1408
+ };
1409
+ readonly adaptiveCurveIrm: 16408957n;
1410
+ readonly vaultV2Factory: 16409067n;
1411
+ readonly morphoMarketV1AdapterV2Factory: 16409115n;
1412
+ readonly registryList: 16409115n;
1413
+ readonly chainlinkOracleFactory: 16409024n;
1414
+ readonly preLiquidationFactory: 16409024n;
1415
+ readonly wNative: 0n;
1416
+ };
1357
1417
  };
1358
1418
  /** Dot-separated label for an address entry in the chain registry. */
1359
1419
  export type AddressLabel = DottedKeys<(typeof _addressesRegistry)[ChainId]>;
@@ -2115,6 +2175,36 @@ export declare let addressesRegistry: {
2115
2175
  readonly chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8";
2116
2176
  readonly preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922";
2117
2177
  };
2178
+ readonly 2818: {
2179
+ readonly morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905";
2180
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
2181
+ readonly bundler3: {
2182
+ readonly bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628";
2183
+ readonly generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776";
2184
+ };
2185
+ readonly adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319";
2186
+ readonly vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B";
2187
+ readonly morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6";
2188
+ readonly registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481";
2189
+ readonly chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1";
2190
+ readonly preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866";
2191
+ readonly wNative: "0x5300000000000000000000000000000000000011";
2192
+ };
2193
+ readonly 4326: {
2194
+ readonly morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100";
2195
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
2196
+ readonly bundler3: {
2197
+ readonly bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63";
2198
+ readonly generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b";
2199
+ };
2200
+ readonly adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323";
2201
+ readonly vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B";
2202
+ readonly morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012";
2203
+ readonly registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c";
2204
+ readonly chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2";
2205
+ readonly preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8";
2206
+ readonly wNative: "0x4200000000000000000000000000000000000006";
2207
+ };
2118
2208
  };
2119
2209
  /** Address registry keyed by numeric chain id. */
2120
2210
  export declare let addresses: Record<number, ChainAddresses>;
@@ -2728,6 +2818,36 @@ export declare let deployments: {
2728
2818
  readonly chainlinkOracleFactory: 1208882n;
2729
2819
  readonly preLiquidationFactory: 1208882n;
2730
2820
  };
2821
+ readonly 2818: {
2822
+ readonly morpho: 23180020n;
2823
+ readonly permit2: 5081244n;
2824
+ readonly bundler3: {
2825
+ readonly bundler3: 23180020n;
2826
+ readonly generalAdapter1: 23180020n;
2827
+ };
2828
+ readonly adaptiveCurveIrm: 23180020n;
2829
+ readonly vaultV2Factory: 23180183n;
2830
+ readonly morphoMarketV1AdapterV2Factory: 23180228n;
2831
+ readonly registryList: 23180228n;
2832
+ readonly chainlinkOracleFactory: 23180111n;
2833
+ readonly preLiquidationFactory: 23180111n;
2834
+ readonly wNative: 0n;
2835
+ };
2836
+ readonly 4326: {
2837
+ readonly morpho: 16408957n;
2838
+ readonly permit2: 0n;
2839
+ readonly bundler3: {
2840
+ readonly bundler3: 16408957n;
2841
+ readonly generalAdapter1: 16408957n;
2842
+ };
2843
+ readonly adaptiveCurveIrm: 16408957n;
2844
+ readonly vaultV2Factory: 16409067n;
2845
+ readonly morphoMarketV1AdapterV2Factory: 16409115n;
2846
+ readonly registryList: 16409115n;
2847
+ readonly chainlinkOracleFactory: 16409024n;
2848
+ readonly preLiquidationFactory: 16409024n;
2849
+ readonly wNative: 0n;
2850
+ };
2731
2851
  };
2732
2852
  /** Deep-frozen registry of wrapped token to unwrapped token mappings. */
2733
2853
  export declare let unwrappedTokensMapping: Record<number, Record<`0x${string}`, `0x${string}`>>;
@@ -732,6 +732,36 @@ const _addressesRegistry = {
732
732
  chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8",
733
733
  preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922",
734
734
  },
735
+ [chain_js_1.ChainId.MorphMainnet]: {
736
+ morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905",
737
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
738
+ bundler3: {
739
+ bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628",
740
+ generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776",
741
+ },
742
+ adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319",
743
+ vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B",
744
+ morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6",
745
+ registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481",
746
+ chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1",
747
+ preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866",
748
+ wNative: "0x5300000000000000000000000000000000000011",
749
+ },
750
+ [chain_js_1.ChainId.MegaEthMainnet]: {
751
+ morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100",
752
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
753
+ bundler3: {
754
+ bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63",
755
+ generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b",
756
+ },
757
+ adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323",
758
+ vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B",
759
+ morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012",
760
+ registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c",
761
+ chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2",
762
+ preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8",
763
+ wNative: "0x4200000000000000000000000000000000000006",
764
+ },
735
765
  };
736
766
  const _deployments = {
737
767
  [chain_js_1.ChainId.EthMainnet]: {
@@ -1342,6 +1372,36 @@ const _deployments = {
1342
1372
  chainlinkOracleFactory: 1208882n,
1343
1373
  preLiquidationFactory: 1208882n,
1344
1374
  },
1375
+ [chain_js_1.ChainId.MorphMainnet]: {
1376
+ morpho: 23180020n,
1377
+ permit2: 5081244n,
1378
+ bundler3: {
1379
+ bundler3: 23180020n,
1380
+ generalAdapter1: 23180020n,
1381
+ },
1382
+ adaptiveCurveIrm: 23180020n,
1383
+ vaultV2Factory: 23180183n,
1384
+ morphoMarketV1AdapterV2Factory: 23180228n,
1385
+ registryList: 23180228n,
1386
+ chainlinkOracleFactory: 23180111n,
1387
+ preLiquidationFactory: 23180111n,
1388
+ wNative: 0n,
1389
+ },
1390
+ [chain_js_1.ChainId.MegaEthMainnet]: {
1391
+ morpho: 16408957n,
1392
+ permit2: 0n,
1393
+ bundler3: {
1394
+ bundler3: 16408957n,
1395
+ generalAdapter1: 16408957n,
1396
+ },
1397
+ adaptiveCurveIrm: 16408957n,
1398
+ vaultV2Factory: 16409067n,
1399
+ morphoMarketV1AdapterV2Factory: 16409115n,
1400
+ registryList: 16409115n,
1401
+ chainlinkOracleFactory: 16409024n,
1402
+ preLiquidationFactory: 16409024n,
1403
+ wNative: 0n,
1404
+ },
1345
1405
  };
1346
1406
  /**
1347
1407
  * Returns the protocol address registry for a chain.
@@ -1486,6 +1546,12 @@ const _unwrappedTokensMapping = {
1486
1546
  [chain_js_1.ChainId.KaiaMainnet]: {
1487
1547
  [_addressesRegistry[chain_js_1.ChainId.KaiaMainnet].wNative]: exports.NATIVE_ADDRESS,
1488
1548
  },
1549
+ [chain_js_1.ChainId.MorphMainnet]: {
1550
+ [_addressesRegistry[chain_js_1.ChainId.MorphMainnet].wNative]: exports.NATIVE_ADDRESS,
1551
+ },
1552
+ [chain_js_1.ChainId.MegaEthMainnet]: {
1553
+ [_addressesRegistry[chain_js_1.ChainId.MegaEthMainnet].wNative]: exports.NATIVE_ADDRESS,
1554
+ },
1489
1555
  };
1490
1556
  /**
1491
1557
  * Returns the unwrapped token mapped to a wrapped token on a chain.
@@ -39,7 +39,9 @@ export declare enum ChainId {
39
39
  FlareMainnet = 14,
40
40
  XdcMainnet = 50,
41
41
  KaiaMainnet = 8217,
42
- ArcMainnet = 5042
42
+ ArcMainnet = 5042,
43
+ MorphMainnet = 2818,
44
+ MegaEthMainnet = 4326
43
45
  }
44
46
  /** Explorer, native currency, and identifier metadata for a supported chain. */
45
47
  export interface ChainMetadata {
@@ -572,5 +574,27 @@ export declare namespace ChainUtils {
572
574
  explorerUrl: string;
573
575
  identifier: string;
574
576
  };
577
+ 2818: {
578
+ name: string;
579
+ id: ChainId.MorphMainnet;
580
+ nativeCurrency: {
581
+ name: string;
582
+ symbol: string;
583
+ decimals: number;
584
+ };
585
+ explorerUrl: string;
586
+ identifier: string;
587
+ };
588
+ 4326: {
589
+ name: string;
590
+ id: ChainId.MegaEthMainnet;
591
+ nativeCurrency: {
592
+ name: string;
593
+ symbol: string;
594
+ decimals: number;
595
+ };
596
+ explorerUrl: string;
597
+ identifier: string;
598
+ };
575
599
  };
576
600
  }
package/lib/cjs/chain.js CHANGED
@@ -44,6 +44,8 @@ var ChainId;
44
44
  ChainId[ChainId["XdcMainnet"] = 50] = "XdcMainnet";
45
45
  ChainId[ChainId["KaiaMainnet"] = 8217] = "KaiaMainnet";
46
46
  ChainId[ChainId["ArcMainnet"] = 5042] = "ArcMainnet";
47
+ ChainId[ChainId["MorphMainnet"] = 2818] = "MorphMainnet";
48
+ ChainId[ChainId["MegaEthMainnet"] = 4326] = "MegaEthMainnet";
47
49
  })(ChainId || (exports.ChainId = ChainId = {}));
48
50
  /** Chain metadata helpers and registries. */
49
51
  var ChainUtils;
@@ -414,5 +416,19 @@ var ChainUtils;
414
416
  explorerUrl: "http://explorer.arc.io/",
415
417
  identifier: "arc",
416
418
  },
419
+ [ChainId.MorphMainnet]: {
420
+ name: "Morph",
421
+ id: ChainId.MorphMainnet,
422
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
423
+ explorerUrl: "https://explorer.morphl2.io",
424
+ identifier: "morph",
425
+ },
426
+ [ChainId.MegaEthMainnet]: {
427
+ name: "MegaETH",
428
+ id: ChainId.MegaEthMainnet,
429
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
430
+ explorerUrl: "https://mega.etherscan.io",
431
+ identifier: "megaeth",
432
+ },
417
433
  };
418
434
  })(ChainUtils || (exports.ChainUtils = ChainUtils = {}));
@@ -28,6 +28,11 @@ export declare class UnknownVaultConfigError extends UnknownDataError {
28
28
  readonly vault: Address;
29
29
  constructor(vault: Address);
30
30
  }
31
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
32
+ export declare class UnknownMarketAllocationError extends UnknownDataError {
33
+ readonly marketId: MarketId;
34
+ constructor(marketId: MarketId);
35
+ }
31
36
  /** Error thrown when a chain id has no configured SDK registry entry. */
32
37
  export declare class UnsupportedChainIdError extends Error {
33
38
  readonly chainId: number;
package/lib/cjs/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnknownOfFactory = exports.UnknownFactory = exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = exports.InvalidMarketParamsError = void 0;
3
+ exports.UnknownOfFactory = exports.UnknownFactory = exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownMarketAllocationError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = exports.InvalidMarketParamsError = void 0;
4
4
  exports._try = _try;
5
5
  const viem_1 = require("viem");
6
6
  /** Error thrown when bytes cannot be decoded into valid Morpho Blue market params. */
@@ -52,6 +52,15 @@ class UnknownVaultConfigError extends UnknownDataError {
52
52
  }
53
53
  }
54
54
  exports.UnknownVaultConfigError = UnknownVaultConfigError;
55
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
56
+ class UnknownMarketAllocationError extends UnknownDataError {
57
+ marketId;
58
+ constructor(marketId) {
59
+ super(`unknown allocation for market ${marketId}`);
60
+ this.marketId = marketId;
61
+ }
62
+ }
63
+ exports.UnknownMarketAllocationError = UnknownMarketAllocationError;
55
64
  /** Error thrown when a chain id has no configured SDK registry entry. */
56
65
  class UnsupportedChainIdError extends Error {
57
66
  chainId;
@@ -121,7 +121,7 @@ var AdaptiveCurveIrmLib;
121
121
  }
122
122
  else {
123
123
  // Non negative because MIN_RATE_AT_TARGET > 0.
124
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
124
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
125
125
  const _newRateAtTarget = (linearAdaptation) => MathLib_js_1.MathLib.min(MathLib_js_1.MathLib.max(MathLib_js_1.MathLib.wMulDown(startRateAtTarget, wExp(linearAdaptation)), AdaptiveCurveIrmLib.MIN_RATE_AT_TARGET), AdaptiveCurveIrmLib.MAX_RATE_AT_TARGET);
126
126
  // Formula of the average rate that should be returned to Morpho Blue:
127
127
  // avg = 1/T * ∫_0^T curve(startRateAtTarget*exp(speed*x), err) dx
@@ -216,6 +216,8 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
216
216
  /**
217
217
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
218
218
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
219
+ * @returns A new vault whose market positions and fee accounting reflect accrued interest.
220
+ * @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
219
221
  */
220
222
  accrueInterest(timestamp?: BigIntish): AccrualVault;
221
223
  }
@@ -2,6 +2,7 @@
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 errors_js_1 = require("../errors.js");
5
6
  const index_js_1 = require("../market/index.js");
6
7
  const index_js_2 = require("../math/index.js");
7
8
  const index_js_3 = require("../token/index.js");
@@ -270,12 +271,22 @@ class AccrualVault extends Vault {
270
271
  /**
271
272
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
272
273
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
274
+ * @returns A new vault whose market positions and fee accounting reflect accrued interest.
275
+ * @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
273
276
  */
274
277
  accrueInterest(timestamp) {
275
278
  const vault = new AccrualVault(this,
276
279
  // Keep withdraw queue order.
277
280
  this.withdrawQueue.map((marketId) => {
278
- const { config, position } = this.allocations.get(marketId);
281
+ const allocation = this.allocations.get(marketId);
282
+ // Fail loudly rather than silently dropping the market: a stale
283
+ // `withdrawQueue` entry (e.g., one mutated after construction to
284
+ // reference a market that is no longer allocated) would otherwise
285
+ // crash with an opaque "Cannot destructure property 'config' of
286
+ // 'undefined'" via the non-null assertion below.
287
+ if (allocation == null)
288
+ throw new errors_js_1.UnknownMarketAllocationError(marketId);
289
+ const { config, position } = allocation;
279
290
  return {
280
291
  config,
281
292
  position: position.accrueInterest(timestamp),
@@ -43,7 +43,7 @@ var VaultUtils;
43
43
  */
44
44
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
45
45
  function toAssets(shares, { totalAssets, totalSupply,
46
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
46
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
47
47
  decimalsOffset, }, rounding = "Down") {
48
48
  return index_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
49
49
  }
@@ -67,7 +67,7 @@ var VaultUtils;
67
67
  */
68
68
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
69
69
  function toShares(assets, { totalAssets, totalSupply,
70
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
70
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
71
71
  decimalsOffset, }, rounding = "Up") {
72
72
  return index_js_1.MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
73
73
  }
@@ -53,7 +53,7 @@ class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter {
53
53
  maxWithdraw(data) {
54
54
  const marketId = index_js_1.MarketParams.fromHex(data).id;
55
55
  const position = this.positions.find(
56
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
56
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
57
57
  (position) => position.marketId === marketId);
58
58
  return (position?.market?.getWithdrawCapacityLimit(position) ?? {
59
59
  value: 0n,
@@ -59,7 +59,7 @@ class AccrualVaultV2MorphoMarketV1AdapterV2 extends VaultV2MorphoMarketV1Adapter
59
59
  }
60
60
  maxWithdraw(data) {
61
61
  const marketId = index_js_1.MarketParams.fromHex(data).id;
62
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
62
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
63
63
  const market = this.markets.find((market) => market.id === marketId);
64
64
  return (market?.getWithdrawCapacityLimit({
65
65
  supplyShares: this.supplyShares[marketId] ?? 0n,
@@ -740,6 +740,36 @@ declare const _addressesRegistry: {
740
740
  readonly chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8";
741
741
  readonly preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922";
742
742
  };
743
+ readonly 2818: {
744
+ readonly morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905";
745
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
746
+ readonly bundler3: {
747
+ readonly bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628";
748
+ readonly generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776";
749
+ };
750
+ readonly adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319";
751
+ readonly vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B";
752
+ readonly morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6";
753
+ readonly registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481";
754
+ readonly chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1";
755
+ readonly preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866";
756
+ readonly wNative: "0x5300000000000000000000000000000000000011";
757
+ };
758
+ readonly 4326: {
759
+ readonly morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100";
760
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
761
+ readonly bundler3: {
762
+ readonly bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63";
763
+ readonly generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b";
764
+ };
765
+ readonly adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323";
766
+ readonly vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B";
767
+ readonly morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012";
768
+ readonly registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c";
769
+ readonly chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2";
770
+ readonly preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8";
771
+ readonly wNative: "0x4200000000000000000000000000000000000006";
772
+ };
743
773
  };
744
774
  /** Deployment block registry with the same shape as `ChainAddresses`. */
745
775
  export type ChainDeployments<Addresses = ChainAddresses> = {
@@ -1354,6 +1384,36 @@ declare const _deployments: {
1354
1384
  readonly chainlinkOracleFactory: 1208882n;
1355
1385
  readonly preLiquidationFactory: 1208882n;
1356
1386
  };
1387
+ readonly 2818: {
1388
+ readonly morpho: 23180020n;
1389
+ readonly permit2: 5081244n;
1390
+ readonly bundler3: {
1391
+ readonly bundler3: 23180020n;
1392
+ readonly generalAdapter1: 23180020n;
1393
+ };
1394
+ readonly adaptiveCurveIrm: 23180020n;
1395
+ readonly vaultV2Factory: 23180183n;
1396
+ readonly morphoMarketV1AdapterV2Factory: 23180228n;
1397
+ readonly registryList: 23180228n;
1398
+ readonly chainlinkOracleFactory: 23180111n;
1399
+ readonly preLiquidationFactory: 23180111n;
1400
+ readonly wNative: 0n;
1401
+ };
1402
+ readonly 4326: {
1403
+ readonly morpho: 16408957n;
1404
+ readonly permit2: 0n;
1405
+ readonly bundler3: {
1406
+ readonly bundler3: 16408957n;
1407
+ readonly generalAdapter1: 16408957n;
1408
+ };
1409
+ readonly adaptiveCurveIrm: 16408957n;
1410
+ readonly vaultV2Factory: 16409067n;
1411
+ readonly morphoMarketV1AdapterV2Factory: 16409115n;
1412
+ readonly registryList: 16409115n;
1413
+ readonly chainlinkOracleFactory: 16409024n;
1414
+ readonly preLiquidationFactory: 16409024n;
1415
+ readonly wNative: 0n;
1416
+ };
1357
1417
  };
1358
1418
  /** Dot-separated label for an address entry in the chain registry. */
1359
1419
  export type AddressLabel = DottedKeys<(typeof _addressesRegistry)[ChainId]>;
@@ -2115,6 +2175,36 @@ export declare let addressesRegistry: {
2115
2175
  readonly chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8";
2116
2176
  readonly preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922";
2117
2177
  };
2178
+ readonly 2818: {
2179
+ readonly morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905";
2180
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
2181
+ readonly bundler3: {
2182
+ readonly bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628";
2183
+ readonly generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776";
2184
+ };
2185
+ readonly adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319";
2186
+ readonly vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B";
2187
+ readonly morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6";
2188
+ readonly registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481";
2189
+ readonly chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1";
2190
+ readonly preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866";
2191
+ readonly wNative: "0x5300000000000000000000000000000000000011";
2192
+ };
2193
+ readonly 4326: {
2194
+ readonly morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100";
2195
+ readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
2196
+ readonly bundler3: {
2197
+ readonly bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63";
2198
+ readonly generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b";
2199
+ };
2200
+ readonly adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323";
2201
+ readonly vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B";
2202
+ readonly morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012";
2203
+ readonly registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c";
2204
+ readonly chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2";
2205
+ readonly preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8";
2206
+ readonly wNative: "0x4200000000000000000000000000000000000006";
2207
+ };
2118
2208
  };
2119
2209
  /** Address registry keyed by numeric chain id. */
2120
2210
  export declare let addresses: Record<number, ChainAddresses>;
@@ -2728,6 +2818,36 @@ export declare let deployments: {
2728
2818
  readonly chainlinkOracleFactory: 1208882n;
2729
2819
  readonly preLiquidationFactory: 1208882n;
2730
2820
  };
2821
+ readonly 2818: {
2822
+ readonly morpho: 23180020n;
2823
+ readonly permit2: 5081244n;
2824
+ readonly bundler3: {
2825
+ readonly bundler3: 23180020n;
2826
+ readonly generalAdapter1: 23180020n;
2827
+ };
2828
+ readonly adaptiveCurveIrm: 23180020n;
2829
+ readonly vaultV2Factory: 23180183n;
2830
+ readonly morphoMarketV1AdapterV2Factory: 23180228n;
2831
+ readonly registryList: 23180228n;
2832
+ readonly chainlinkOracleFactory: 23180111n;
2833
+ readonly preLiquidationFactory: 23180111n;
2834
+ readonly wNative: 0n;
2835
+ };
2836
+ readonly 4326: {
2837
+ readonly morpho: 16408957n;
2838
+ readonly permit2: 0n;
2839
+ readonly bundler3: {
2840
+ readonly bundler3: 16408957n;
2841
+ readonly generalAdapter1: 16408957n;
2842
+ };
2843
+ readonly adaptiveCurveIrm: 16408957n;
2844
+ readonly vaultV2Factory: 16409067n;
2845
+ readonly morphoMarketV1AdapterV2Factory: 16409115n;
2846
+ readonly registryList: 16409115n;
2847
+ readonly chainlinkOracleFactory: 16409024n;
2848
+ readonly preLiquidationFactory: 16409024n;
2849
+ readonly wNative: 0n;
2850
+ };
2731
2851
  };
2732
2852
  /** Deep-frozen registry of wrapped token to unwrapped token mappings. */
2733
2853
  export declare let unwrappedTokensMapping: Record<number, Record<`0x${string}`, `0x${string}`>>;
@@ -724,6 +724,36 @@ const _addressesRegistry = {
724
724
  chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8",
725
725
  preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922",
726
726
  },
727
+ [ChainId.MorphMainnet]: {
728
+ morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905",
729
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
730
+ bundler3: {
731
+ bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628",
732
+ generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776",
733
+ },
734
+ adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319",
735
+ vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B",
736
+ morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6",
737
+ registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481",
738
+ chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1",
739
+ preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866",
740
+ wNative: "0x5300000000000000000000000000000000000011",
741
+ },
742
+ [ChainId.MegaEthMainnet]: {
743
+ morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100",
744
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
745
+ bundler3: {
746
+ bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63",
747
+ generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b",
748
+ },
749
+ adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323",
750
+ vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B",
751
+ morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012",
752
+ registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c",
753
+ chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2",
754
+ preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8",
755
+ wNative: "0x4200000000000000000000000000000000000006",
756
+ },
727
757
  };
728
758
  const _deployments = {
729
759
  [ChainId.EthMainnet]: {
@@ -1334,6 +1364,36 @@ const _deployments = {
1334
1364
  chainlinkOracleFactory: 1208882n,
1335
1365
  preLiquidationFactory: 1208882n,
1336
1366
  },
1367
+ [ChainId.MorphMainnet]: {
1368
+ morpho: 23180020n,
1369
+ permit2: 5081244n,
1370
+ bundler3: {
1371
+ bundler3: 23180020n,
1372
+ generalAdapter1: 23180020n,
1373
+ },
1374
+ adaptiveCurveIrm: 23180020n,
1375
+ vaultV2Factory: 23180183n,
1376
+ morphoMarketV1AdapterV2Factory: 23180228n,
1377
+ registryList: 23180228n,
1378
+ chainlinkOracleFactory: 23180111n,
1379
+ preLiquidationFactory: 23180111n,
1380
+ wNative: 0n,
1381
+ },
1382
+ [ChainId.MegaEthMainnet]: {
1383
+ morpho: 16408957n,
1384
+ permit2: 0n,
1385
+ bundler3: {
1386
+ bundler3: 16408957n,
1387
+ generalAdapter1: 16408957n,
1388
+ },
1389
+ adaptiveCurveIrm: 16408957n,
1390
+ vaultV2Factory: 16409067n,
1391
+ morphoMarketV1AdapterV2Factory: 16409115n,
1392
+ registryList: 16409115n,
1393
+ chainlinkOracleFactory: 16409024n,
1394
+ preLiquidationFactory: 16409024n,
1395
+ wNative: 0n,
1396
+ },
1337
1397
  };
1338
1398
  /**
1339
1399
  * Returns the protocol address registry for a chain.
@@ -1477,6 +1537,12 @@ const _unwrappedTokensMapping = {
1477
1537
  [ChainId.KaiaMainnet]: {
1478
1538
  [_addressesRegistry[ChainId.KaiaMainnet].wNative]: NATIVE_ADDRESS,
1479
1539
  },
1540
+ [ChainId.MorphMainnet]: {
1541
+ [_addressesRegistry[ChainId.MorphMainnet].wNative]: NATIVE_ADDRESS,
1542
+ },
1543
+ [ChainId.MegaEthMainnet]: {
1544
+ [_addressesRegistry[ChainId.MegaEthMainnet].wNative]: NATIVE_ADDRESS,
1545
+ },
1480
1546
  };
1481
1547
  /**
1482
1548
  * Returns the unwrapped token mapped to a wrapped token on a chain.
@@ -39,7 +39,9 @@ export declare enum ChainId {
39
39
  FlareMainnet = 14,
40
40
  XdcMainnet = 50,
41
41
  KaiaMainnet = 8217,
42
- ArcMainnet = 5042
42
+ ArcMainnet = 5042,
43
+ MorphMainnet = 2818,
44
+ MegaEthMainnet = 4326
43
45
  }
44
46
  /** Explorer, native currency, and identifier metadata for a supported chain. */
45
47
  export interface ChainMetadata {
@@ -572,5 +574,27 @@ export declare namespace ChainUtils {
572
574
  explorerUrl: string;
573
575
  identifier: string;
574
576
  };
577
+ 2818: {
578
+ name: string;
579
+ id: ChainId.MorphMainnet;
580
+ nativeCurrency: {
581
+ name: string;
582
+ symbol: string;
583
+ decimals: number;
584
+ };
585
+ explorerUrl: string;
586
+ identifier: string;
587
+ };
588
+ 4326: {
589
+ name: string;
590
+ id: ChainId.MegaEthMainnet;
591
+ nativeCurrency: {
592
+ name: string;
593
+ symbol: string;
594
+ decimals: number;
595
+ };
596
+ explorerUrl: string;
597
+ identifier: string;
598
+ };
575
599
  };
576
600
  }
package/lib/esm/chain.js CHANGED
@@ -41,6 +41,8 @@ export var ChainId;
41
41
  ChainId[ChainId["XdcMainnet"] = 50] = "XdcMainnet";
42
42
  ChainId[ChainId["KaiaMainnet"] = 8217] = "KaiaMainnet";
43
43
  ChainId[ChainId["ArcMainnet"] = 5042] = "ArcMainnet";
44
+ ChainId[ChainId["MorphMainnet"] = 2818] = "MorphMainnet";
45
+ ChainId[ChainId["MegaEthMainnet"] = 4326] = "MegaEthMainnet";
44
46
  })(ChainId || (ChainId = {}));
45
47
  /** Chain metadata helpers and registries. */
46
48
  export var ChainUtils;
@@ -411,5 +413,19 @@ export var ChainUtils;
411
413
  explorerUrl: "http://explorer.arc.io/",
412
414
  identifier: "arc",
413
415
  },
416
+ [ChainId.MorphMainnet]: {
417
+ name: "Morph",
418
+ id: ChainId.MorphMainnet,
419
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
420
+ explorerUrl: "https://explorer.morphl2.io",
421
+ identifier: "morph",
422
+ },
423
+ [ChainId.MegaEthMainnet]: {
424
+ name: "MegaETH",
425
+ id: ChainId.MegaEthMainnet,
426
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
427
+ explorerUrl: "https://mega.etherscan.io",
428
+ identifier: "megaeth",
429
+ },
414
430
  };
415
431
  })(ChainUtils || (ChainUtils = {}));
@@ -28,6 +28,11 @@ export declare class UnknownVaultConfigError extends UnknownDataError {
28
28
  readonly vault: Address;
29
29
  constructor(vault: Address);
30
30
  }
31
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
32
+ export declare class UnknownMarketAllocationError extends UnknownDataError {
33
+ readonly marketId: MarketId;
34
+ constructor(marketId: MarketId);
35
+ }
31
36
  /** Error thrown when a chain id has no configured SDK registry entry. */
32
37
  export declare class UnsupportedChainIdError extends Error {
33
38
  readonly chainId: number;
package/lib/esm/errors.js CHANGED
@@ -42,6 +42,14 @@ export class UnknownVaultConfigError extends UnknownDataError {
42
42
  this.vault = vault;
43
43
  }
44
44
  }
45
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
46
+ export class UnknownMarketAllocationError extends UnknownDataError {
47
+ marketId;
48
+ constructor(marketId) {
49
+ super(`unknown allocation for market ${marketId}`);
50
+ this.marketId = marketId;
51
+ }
52
+ }
45
53
  /** Error thrown when a chain id has no configured SDK registry entry. */
46
54
  export class UnsupportedChainIdError extends Error {
47
55
  chainId;
@@ -118,7 +118,7 @@ export var AdaptiveCurveIrmLib;
118
118
  }
119
119
  else {
120
120
  // Non negative because MIN_RATE_AT_TARGET > 0.
121
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
121
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
122
122
  const _newRateAtTarget = (linearAdaptation) => MathLib.min(MathLib.max(MathLib.wMulDown(startRateAtTarget, wExp(linearAdaptation)), AdaptiveCurveIrmLib.MIN_RATE_AT_TARGET), AdaptiveCurveIrmLib.MAX_RATE_AT_TARGET);
123
123
  // Formula of the average rate that should be returned to Morpho Blue:
124
124
  // avg = 1/T * ∫_0^T curve(startRateAtTarget*exp(speed*x), err) dx
@@ -216,6 +216,8 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
216
216
  /**
217
217
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
218
218
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
219
+ * @returns A new vault whose market positions and fee accounting reflect accrued interest.
220
+ * @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
219
221
  */
220
222
  accrueInterest(timestamp?: BigIntish): AccrualVault;
221
223
  }
@@ -1,4 +1,5 @@
1
1
  import { Time } from "@morpho-org/morpho-ts";
2
+ import { UnknownMarketAllocationError } from "../errors.js";
2
3
  import { MarketUtils } from "../market/index.js";
3
4
  import { MathLib } from "../math/index.js";
4
5
  import { VaultToken } from "../token/index.js";
@@ -266,12 +267,22 @@ export class AccrualVault extends Vault {
266
267
  /**
267
268
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
268
269
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
270
+ * @returns A new vault whose market positions and fee accounting reflect accrued interest.
271
+ * @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
269
272
  */
270
273
  accrueInterest(timestamp) {
271
274
  const vault = new AccrualVault(this,
272
275
  // Keep withdraw queue order.
273
276
  this.withdrawQueue.map((marketId) => {
274
- const { config, position } = this.allocations.get(marketId);
277
+ const allocation = this.allocations.get(marketId);
278
+ // Fail loudly rather than silently dropping the market: a stale
279
+ // `withdrawQueue` entry (e.g., one mutated after construction to
280
+ // reference a market that is no longer allocated) would otherwise
281
+ // crash with an opaque "Cannot destructure property 'config' of
282
+ // 'undefined'" via the non-null assertion below.
283
+ if (allocation == null)
284
+ throw new UnknownMarketAllocationError(marketId);
285
+ const { config, position } = allocation;
275
286
  return {
276
287
  config,
277
288
  position: position.accrueInterest(timestamp),
@@ -40,7 +40,7 @@ export var VaultUtils;
40
40
  */
41
41
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
42
42
  function toAssets(shares, { totalAssets, totalSupply,
43
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
43
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
44
44
  decimalsOffset, }, rounding = "Down") {
45
45
  return MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
46
46
  }
@@ -64,7 +64,7 @@ export var VaultUtils;
64
64
  */
65
65
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
66
66
  function toShares(assets, { totalAssets, totalSupply,
67
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
67
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
68
68
  decimalsOffset, }, rounding = "Up") {
69
69
  return MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
70
70
  }
@@ -49,7 +49,7 @@ export class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Ad
49
49
  maxWithdraw(data) {
50
50
  const marketId = MarketParams.fromHex(data).id;
51
51
  const position = this.positions.find(
52
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
52
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
53
53
  (position) => position.marketId === marketId);
54
54
  return (position?.market?.getWithdrawCapacityLimit(position) ?? {
55
55
  value: 0n,
@@ -55,7 +55,7 @@ export class AccrualVaultV2MorphoMarketV1AdapterV2 extends VaultV2MorphoMarketV1
55
55
  }
56
56
  maxWithdraw(data) {
57
57
  const marketId = MarketParams.fromHex(data).id;
58
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
58
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
59
59
  const market = this.markets.find((market) => market.id === marketId);
60
60
  return (market?.getWithdrawCapacityLimit({
61
61
  supplyShares: this.supplyShares[marketId] ?? 0n,
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": "6.1.0",
4
+ "version": "6.2.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "typescript": "^6.0.3",
37
- "viem": "^2.50.4",
38
- "vitest": "^4.1.7",
37
+ "viem": "2.52.2",
38
+ "vitest": "^4.1.8",
39
39
  "@morpho-org/morpho-ts": "^2.6.0",
40
40
  "@morpho-org/test": "^2.8.1"
41
41
  },