@morpho-org/morpho-sdk 5.9.0 → 5.11.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.
Files changed (97) hide show
  1. package/README.md +6 -0
  2. package/lib/cjs/abis.d.ts +17 -2
  3. package/lib/cjs/abis.js +14 -1
  4. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  5. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  6. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  7. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  8. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  9. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  10. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  11. package/lib/cjs/blue/abis.d.ts +5 -1
  12. package/lib/cjs/blue/abis.js +2 -0
  13. package/lib/cjs/blue/entities.d.ts +8 -2
  14. package/lib/cjs/blue/entities.js +1 -0
  15. package/lib/cjs/blue/errors.d.ts +1 -1
  16. package/lib/cjs/blue/errors.js +2 -1
  17. package/lib/cjs/blue/fetch.d.ts +3 -1
  18. package/lib/cjs/blue/fetch.js +1 -0
  19. package/lib/cjs/entities/blue/blue.d.ts +10 -0
  20. package/lib/cjs/entities/blue/blue.js +9 -2
  21. package/lib/cjs/entities/index.d.ts +8 -2
  22. package/lib/cjs/entities/index.js +1 -0
  23. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  24. package/lib/cjs/entities/midnight/midnight.js +5 -13
  25. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +71 -12
  26. package/lib/cjs/entities/vaultV1/vaultV1.js +9 -2
  27. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  28. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  29. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -0
  30. package/lib/cjs/entities/vaultV2/vaultV2.js +3 -1
  31. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  32. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  33. package/lib/cjs/errors.d.ts +1 -1
  34. package/lib/cjs/errors.js +3 -2
  35. package/lib/cjs/fetch.d.ts +3 -1
  36. package/lib/cjs/fetch.js +1 -0
  37. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  38. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  39. package/lib/cjs/helpers/metadata.d.ts +3 -5
  40. package/lib/cjs/helpers/metadata.js +4 -6
  41. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  42. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  43. package/lib/cjs/helpers/validate.d.ts +30 -8
  44. package/lib/cjs/helpers/validate.js +30 -8
  45. package/lib/cjs/types/action.d.ts +57 -4
  46. package/lib/cjs/types/error.d.ts +1 -1
  47. package/lib/cjs/types/error.js +2 -2
  48. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  49. package/lib/esm/abis.d.ts +17 -2
  50. package/lib/esm/abis.js +17 -2
  51. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  52. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  53. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  54. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  55. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  56. package/lib/esm/actions/midnight/takeLend.js +2 -2
  57. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  58. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  59. package/lib/esm/blue/abis.d.ts +5 -1
  60. package/lib/esm/blue/abis.js +5 -1
  61. package/lib/esm/blue/entities.d.ts +8 -2
  62. package/lib/esm/blue/entities.js +3 -1
  63. package/lib/esm/blue/errors.d.ts +1 -1
  64. package/lib/esm/blue/errors.js +1 -1
  65. package/lib/esm/blue/fetch.d.ts +3 -1
  66. package/lib/esm/blue/fetch.js +3 -1
  67. package/lib/esm/entities/blue/blue.d.ts +10 -0
  68. package/lib/esm/entities/blue/blue.js +9 -2
  69. package/lib/esm/entities/index.d.ts +8 -2
  70. package/lib/esm/entities/index.js +3 -1
  71. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  72. package/lib/esm/entities/midnight/midnight.js +5 -13
  73. package/lib/esm/entities/vaultV1/vaultV1.d.ts +71 -12
  74. package/lib/esm/entities/vaultV1/vaultV1.js +9 -2
  75. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  76. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  77. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -0
  78. package/lib/esm/entities/vaultV2/vaultV2.js +3 -1
  79. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  80. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  81. package/lib/esm/errors.d.ts +1 -1
  82. package/lib/esm/errors.js +1 -1
  83. package/lib/esm/fetch.d.ts +3 -1
  84. package/lib/esm/fetch.js +3 -1
  85. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  86. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  87. package/lib/esm/helpers/metadata.d.ts +3 -5
  88. package/lib/esm/helpers/metadata.js +4 -6
  89. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  90. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  91. package/lib/esm/helpers/validate.d.ts +30 -8
  92. package/lib/esm/helpers/validate.js +30 -8
  93. package/lib/esm/types/action.d.ts +57 -4
  94. package/lib/esm/types/error.d.ts +1 -1
  95. package/lib/esm/types/error.js +2 -2
  96. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  97. package/package.json +8 -8
@@ -78,6 +78,7 @@ export interface BlueActions {
78
78
  *
79
79
  * @param params - Supply parameters.
80
80
  * @returns Object with `buildTx` and `getRequirements`.
81
+ * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
81
82
  */
82
83
  supply: (params: {
83
84
  userAddress: Address;
@@ -192,6 +193,7 @@ export interface BlueActions {
192
193
  *
193
194
  * @param params - Repay parameters including pre-fetched `positionData`.
194
195
  * @returns Object with `buildTx` and `getRequirements`.
196
+ * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
195
197
  */
196
198
  repay: (params: {
197
199
  userAddress: Address;
@@ -245,6 +247,7 @@ export interface BlueActions {
245
247
  *
246
248
  * @param params - Combined parameters including pre-fetched `positionData`.
247
249
  * @returns Object with `buildTx` and `getRequirements`.
250
+ * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
248
251
  */
249
252
  repayWithdrawCollateral: (params: {
250
253
  userAddress: Address;
@@ -337,6 +340,7 @@ export interface BlueActions {
337
340
  * @param params.targetReallocations - Homogeneous Vault V1 or Vault V2 reallocations into the
338
341
  * target market. Vault V1 inputs are deprecated; prefer Vault V2.
339
342
  * @returns Object with `buildTx` and `getRequirements`.
343
+ * @throws {UnsupportedBlueMarketIrmError} when positive source or target debt requires an unsupported IRM projection.
340
344
  * @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
341
345
  * @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
342
346
  * @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
@@ -456,6 +460,7 @@ export interface BlueActions {
456
460
  * @returns Array of vault reallocations ready to pass to `borrow()`, `supplyCollateralBorrow()`,
457
461
  * or `withdraw()`. Empty array if no reallocation is needed.
458
462
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
463
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
459
464
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
460
465
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds the target market supply.
461
466
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -482,6 +487,7 @@ export interface BlueActions {
482
487
  * @param params.options - Optional allocator and utilization options.
483
488
  * @returns Vault V1 reallocations ready for a Blue action.
484
489
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
490
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
485
491
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
486
492
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
487
493
  * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
@@ -505,6 +511,7 @@ export interface BlueActions {
505
511
  * @param params.options - Optional allocator discovery controls and operation to support.
506
512
  * @returns Action-ready reallocations and their post-simulation state.
507
513
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
514
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
508
515
  * @throws {NegativeInputError} when a utilization or penalty limit is negative.
509
516
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
510
517
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
@@ -749,6 +756,7 @@ export declare class MorphoBlue implements BlueActions {
749
756
  * @param params.options - Optional allocator and utilization options.
750
757
  * @returns Vault reallocations ready to pass to `borrow`, `supplyCollateralBorrow`, or `withdraw`.
751
758
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
759
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
752
760
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
753
761
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
754
762
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -775,6 +783,7 @@ export declare class MorphoBlue implements BlueActions {
775
783
  * @param params.options - Optional allocator and utilization options.
776
784
  * @returns Vault V1 reallocations ready for a Blue action.
777
785
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
786
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
778
787
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
779
788
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
780
789
  * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
@@ -798,6 +807,7 @@ export declare class MorphoBlue implements BlueActions {
798
807
  * @param params.options - Optional allocator discovery controls and operation to support.
799
808
  * @returns Action-ready reallocations and their post-simulation state.
800
809
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
810
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
801
811
  * @throws {NegativeInputError} when a utilization or penalty limit is negative.
802
812
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
803
813
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
@@ -806,8 +806,12 @@ export class MorphoBlue {
806
806
  const sourceAccrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
807
807
  (sharesMode ? Time.s.from.h(2n) : 0n);
808
808
  const targetAccrualTimestamp = MathLib.max(Time.timestamp(), target.positionData.market.lastUpdate);
809
- const accruedSource = positionData.market.accrueInterest(sourceAccrualTimestamp);
810
- const accruedTarget = target.positionData.market.accrueInterest(targetAccrualTimestamp);
809
+ const accruedSource = shouldMigrateBorrow || positionData.borrowShares > 0n
810
+ ? positionData.market.accrueInterest(sourceAccrualTimestamp)
811
+ : positionData.market;
812
+ const accruedTarget = shouldMigrateBorrow
813
+ ? target.positionData.market.accrueInterest(targetAccrualTimestamp)
814
+ : target.positionData.market;
811
815
  // Shares burned by the source repay: exact in shares mode, else mirror Morpho's toSharesDown.
812
816
  const repaidShares = sharesMode
813
817
  ? requestedShares
@@ -1112,6 +1116,7 @@ export class MorphoBlue {
1112
1116
  * @param params.options - Optional allocator and utilization options.
1113
1117
  * @returns Vault reallocations ready to pass to `borrow`, `supplyCollateralBorrow`, or `withdraw`.
1114
1118
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
1119
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1115
1120
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
1116
1121
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
1117
1122
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -1158,6 +1163,7 @@ export class MorphoBlue {
1158
1163
  * @param params.options - Optional allocator and utilization options.
1159
1164
  * @returns Vault V1 reallocations ready for a Blue action.
1160
1165
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1166
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1161
1167
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
1162
1168
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
1163
1169
  * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
@@ -1183,6 +1189,7 @@ export class MorphoBlue {
1183
1189
  * @param params.options - Optional allocator discovery controls and operation to support.
1184
1190
  * @returns Action-ready reallocations and their post-simulation state.
1185
1191
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1192
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1186
1193
  * @throws {NegativeInputError} when a utilization or penalty limit is negative.
1187
1194
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
1188
1195
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
@@ -10,7 +10,11 @@ IPosition, IPreLiquidationParams as IBluePreLiquidationParams,
10
10
  /** @deprecated Use `IBluePreLiquidationParams` or the raw Blue subpath. */
11
11
  IPreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition,
12
12
  /** @deprecated Use `IBluePreLiquidationPosition` or the raw Blue subpath. */
13
- IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
13
+ IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig,
14
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BlueMarketPublicAllocatorConfig`. */
15
+ IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType,
16
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BluePublicAllocatorConfig`. */
17
+ VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
14
18
  export { AccrualPosition as BlueAccrualPosition,
15
19
  /** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
16
20
  AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
@@ -25,7 +29,9 @@ PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
25
29
  /** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
26
30
  PreLiquidationPosition, Token, User as BlueUser,
27
31
  /** @deprecated Use `BlueUser` or the raw Blue subpath. */
28
- User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
32
+ User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
33
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
34
+ VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
29
35
  export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
30
36
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
31
37
  export { MorphoBlue } from "./blue/index.js";
@@ -12,7 +12,9 @@ PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
12
12
  /** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
13
13
  PreLiquidationPosition, Token, User as BlueUser,
14
14
  /** @deprecated Use `BlueUser` or the raw Blue subpath. */
15
- User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
15
+ User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
16
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
17
+ VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
16
18
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
17
19
  export { MorphoBlue } from "./blue/index.js";
18
20
  export { MorphoMidnight, } from "./midnight/index.js";
@@ -20,8 +20,8 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
20
20
  * const output = midnight.takeLend({
21
21
  * accountAddress: lender,
22
22
  * marketData,
23
- * assets: BigInt(quote.data.availableAssets),
24
- * minUnits: BigInt(quote.data.availableUnits),
23
+ * assets: 1_000_000n,
24
+ * minUnits: 900_000n,
25
25
  * takeableOffers: quote.data.takeableOffers,
26
26
  * deadline: maxUint256,
27
27
  * });
@@ -547,7 +547,6 @@ export class MorphoMidnight {
547
547
  }
548
548
  });
549
549
  const midnight = getChainAddress(this.chainId, "midnight");
550
- const signedPayloads = new Map();
551
550
  return {
552
551
  groups: data.groups,
553
552
  root: data.tree.root,
@@ -564,14 +563,12 @@ export class MorphoMidnight {
564
563
  })));
565
564
  requirements.push(...(await this.getRatifierRequirements({
566
565
  offersData: data,
567
- signedPayloads,
568
566
  })));
569
567
  return requirements;
570
568
  },
571
569
  buildTx: (signatures) => this.buildSubmitOffersTx({
572
570
  offersData: data,
573
571
  signatures,
574
- signedPayloads,
575
572
  }),
576
573
  };
577
574
  }
@@ -602,7 +599,6 @@ export class MorphoMidnight {
602
599
  validation: params.validation,
603
600
  });
604
601
  validateOfferSides(data.tree.offers, false);
605
- const signedPayloads = new Map();
606
602
  return {
607
603
  groups: data.groups,
608
604
  root: data.tree.root,
@@ -610,13 +606,11 @@ export class MorphoMidnight {
610
606
  getRequirements: async () => {
611
607
  return await this.getRatifierRequirements({
612
608
  offersData: data,
613
- signedPayloads,
614
609
  });
615
610
  },
616
611
  buildTx: (signatures) => this.buildSubmitOffersTx({
617
612
  offersData: data,
618
613
  signatures,
619
- signedPayloads,
620
614
  }),
621
615
  };
622
616
  }
@@ -674,7 +668,6 @@ export class MorphoMidnight {
674
668
  }
675
669
  }
676
670
  const midnight = getChainAddress(this.chainId, "midnight");
677
- const signedPayloads = new Map();
678
671
  return {
679
672
  groups: data.groups,
680
673
  root: data.tree.root,
@@ -699,7 +692,6 @@ export class MorphoMidnight {
699
692
  }),
700
693
  ...(await this.getRatifierRequirements({
701
694
  offersData: data,
702
- signedPayloads,
703
695
  })),
704
696
  ];
705
697
  return requirements;
@@ -707,7 +699,6 @@ export class MorphoMidnight {
707
699
  buildTx: (signatures) => this.buildSubmitOffersTx({
708
700
  offersData: data,
709
701
  signatures,
710
- signedPayloads,
711
702
  }),
712
703
  };
713
704
  }
@@ -939,7 +930,6 @@ export class MorphoMidnight {
939
930
  signature,
940
931
  });
941
932
  const payload = await Payload.encode(items);
942
- params.signedPayloads.set(signature.toLowerCase(), payload);
943
933
  return deepFreeze({
944
934
  args: {
945
935
  owner: userAddress,
@@ -1007,11 +997,13 @@ export class MorphoMidnight {
1007
997
  actualOffers: signature.action.args.offers,
1008
998
  });
1009
999
  }
1010
- const signedPayload = params.signedPayloads.get(signature.args.signature.toLowerCase());
1011
- if (signedPayload == null) {
1000
+ // The payload is carried on the signature the caller hands to buildTx, so
1001
+ // a prepared offer-root requirement can be signed on one instance and
1002
+ // submitted from another without sharing in-memory state.
1003
+ if (signature.args.payload == null) {
1012
1004
  throw new UnpreparedMidnightOfferRootSignatureError();
1013
1005
  }
1014
- payload = signedPayload;
1006
+ payload = signature.args.payload;
1015
1007
  }
1016
1008
  else {
1017
1009
  selectRequirementSignatures(collectedSignatures, {});
@@ -5,10 +5,10 @@ import type { FetchParameters } from "../../types/data.js";
5
5
  import { type ActionOutput, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV1Actions {
7
7
  /**
8
- * Fetches the latest vault data with accrued interest.
8
+ * Fetches direct onchain vault and allocation state without applying virtual interest.
9
9
  *
10
10
  * @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
11
- * @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The latest vault data.
11
+ * @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
12
12
  */
13
13
  getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
14
14
  /**
@@ -85,6 +85,7 @@ export interface VaultV1Actions {
85
85
  * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
86
86
  * @returns Lazy prerequisite resolution and a synchronous transaction builder.
87
87
  * @throws {ChainIdMismatchError} when the client and entity target different chains.
88
+ * @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
88
89
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
89
90
  * @throws {NonPositiveInputError} when `amount` is not positive.
90
91
  * @throws {EmptyMarketParamsListError} when the market list is empty.
@@ -134,18 +135,75 @@ export interface VaultV1Actions {
134
135
  readonly deadline?: bigint;
135
136
  }) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
136
137
  /**
137
- * Prepares a full migration from VaultV1 to VaultV2.
138
+ * Prepares an atomic migration of Vault V1 shares to Vault V2 through bundler3.
138
139
  *
139
- * Redeems all V1 shares and atomically deposits the resulting assets into V2
140
- * via bundler3. Computes slippage-protected share prices for both legs.
140
+ * Accrues the source snapshot before converting V1 shares to assets so pending Vault V1
141
+ * performance-fee shares are reflected in both migration bounds. Projects the target Vault V2
142
+ * two hours forward when computing the deposit-leg maximum share price.
141
143
  *
142
- * @param {Object} params - The migration parameters.
143
- * @param {Address} params.userAddress - User address initiating the migration.
144
- * @param {AccrualVault} params.sourceVault - Pre-fetched V1 vault data.
145
- * @param {AccrualVaultV2} params.targetVault - Pre-fetched V2 vault data.
146
- * @param {bigint} params.shares - User's V1 share balance to migrate.
147
- * @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Slippage tolerance (default 0.03%, max 10%).
148
- * @returns {Object} Object with `buildTx` and `getRequirements`.
144
+ * @param params - Migration parameters.
145
+ * @param params.userAddress - Account whose Vault V1 shares are migrated and that receives Vault
146
+ * V2 shares.
147
+ * @param params.sourceVault - Pre-fetched Vault V1 state with market allocations for local accrual.
148
+ * @param params.targetVault - Pre-fetched Vault V2 accrual snapshot with the same underlying
149
+ * asset.
150
+ * @param params.shares - Positive number of Vault V1 shares to migrate.
151
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to
152
+ * `DEFAULT_SLIPPAGE_TOLERANCE` and cannot exceed 10%.
153
+ * @returns Lazy approval or permit resolution through `getRequirements()` and a synchronous
154
+ * `buildTx()` returning a deep-frozen `Transaction<VaultV1MigrateToV2Action>`.
155
+ * @throws {ChainIdMismatchError} when the client and entity target different chains.
156
+ * @throws {UnsupportedBlueMarketIrmError} when an allocated source or target market with positive debt uses an unsupported IRM.
157
+ * @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
158
+ * @throws {VaultAssetMismatchError} when the source and target assets differ.
159
+ * @throws {NonPositiveInputError} when `shares` is not positive or the target projection yields
160
+ * no shares.
161
+ * @throws {NegativeInputError} when `slippageTolerance` is negative.
162
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
163
+ * @throws {UnknownBlueMarketAllocationError} when `sourceVault.withdrawQueue` references a market
164
+ * absent from `sourceVault.allocations`.
165
+ * @throws {UnsupportedChainIdError} from `getRequirements()` or `buildTx()` when the chain has no
166
+ * address registry.
167
+ * @throws {viem.BaseError} from `getRequirements()` when an RPC contract read fails.
168
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is
169
+ * supplied.
170
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when several permit signatures
171
+ * are supplied.
172
+ * @throws {DepositAssetMismatchError} from `buildTx()` when a supplied permit targets another
173
+ * token.
174
+ * @throws {DepositAmountMismatchError} from `buildTx()` when a supplied permit covers another
175
+ * amount.
176
+ * @throws {Permit2ExpirationMissingError} from `buildTx()` when a Permit2 signature lacks an
177
+ * expiration.
178
+ * @example
179
+ * ```ts
180
+ * import {
181
+ * morphoViemExtension,
182
+ * type Transaction,
183
+ * type VaultV1MigrateToV2Action,
184
+ * } from "@morpho-org/morpho-sdk";
185
+ * import { createPublicClient, http } from "viem";
186
+ * import { mainnet } from "viem/chains";
187
+ *
188
+ * const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
189
+ * morphoViemExtension(),
190
+ * );
191
+ * const sourceVaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
192
+ * const targetVaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
193
+ * const userAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
194
+ * const source = client.morpho.vaultV1(sourceVaultAddress, mainnet.id);
195
+ * const [sourceVault, targetVault] = await Promise.all([
196
+ * source.getData(),
197
+ * client.morpho.vaultV2(targetVaultAddress, mainnet.id).getData(),
198
+ * ]);
199
+ * const { buildTx } = source.migrateToV2({
200
+ * userAddress,
201
+ * sourceVault,
202
+ * targetVault,
203
+ * shares: 1_000_000n,
204
+ * });
205
+ * const tx: Readonly<Transaction<VaultV1MigrateToV2Action>> = buildTx();
206
+ * ```
149
207
  */
150
208
  migrateToV2: (params: {
151
209
  userAddress: Address;
@@ -194,6 +252,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
194
252
  readonly userAddress: Address;
195
253
  readonly deadline?: bigint;
196
254
  }): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
255
+ /** {@inheritDoc VaultV1Actions.migrateToV2} */
197
256
  migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance, }: {
198
257
  userAddress: Address;
199
258
  sourceVault: AccrualVault;
@@ -156,6 +156,8 @@ export class MorphoVaultV1 {
156
156
  const allocation = vaultData.allocations.get(marketId);
157
157
  if (allocation?.config.enabled !== true)
158
158
  continue;
159
+ if (allocation.position.supplyShares === 0n)
160
+ continue;
159
161
  const market = allocation.position.market.accrueInterest(now);
160
162
  const available = market.toSupplyAssets(allocation.position.supplyShares);
161
163
  const assigned = assignedByMarket.get(marketId) ?? 0n;
@@ -284,6 +286,7 @@ export class MorphoVaultV1 {
284
286
  },
285
287
  };
286
288
  }
289
+ /** {@inheritDoc VaultV1Actions.migrateToV2} */
287
290
  migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, }) {
288
291
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
289
292
  if (!isAddressEqual(sourceVault.address, this.vault)) {
@@ -296,8 +299,12 @@ export class MorphoVaultV1 {
296
299
  throw new NonPositiveInputError("shares", shares);
297
300
  }
298
301
  validateSlippageTolerance(slippageTolerance);
299
- // Compute minSharePriceVaultV1 for V1 redeem (slippage downward)
300
- const v1RefAssets = sourceVault.toAssets(shares);
302
+ // V1 redeem accrues pending market interest and performance fees before converting shares.
303
+ const sourceAccrualTimestamp = sourceVault.allocations
304
+ .values()
305
+ .reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), Time.timestamp());
306
+ const accruedSourceVault = sourceVault.accrueInterest(sourceAccrualTimestamp);
307
+ const v1RefAssets = accruedSourceVault.toAssets(shares);
301
308
  const minSharePriceVaultV1 = MathLib.mulDivDown(v1RefAssets, MathLib.wToRay(MathLib.WAD - slippageTolerance), shares);
302
309
  // Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
303
310
  // Accrue VaultV2 interest forward to bound the on-chain share price at execution.
@@ -130,10 +130,13 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
130
130
  * Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
131
131
  * on-chain `reallocateTo` fee semantics: one fee charge per vault with at
132
132
  * least one computed withdrawal.
133
+ * Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
134
+ * are skipped before projecting source interest.
133
135
  *
134
136
  * @param marketId - Target market to supply with shared liquidity.
135
137
  * @param options - Optional allocator discovery options.
136
138
  * @returns Computed source-market withdrawals and the post-reallocation state.
139
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
137
140
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
138
141
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
139
142
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -179,6 +182,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
179
182
  * @param marketId - Target market to supply with shared liquidity.
180
183
  * @param options - Optional allocator discovery options.
181
184
  * @returns Computed source-market withdrawals and the post-reallocation state.
185
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
182
186
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
183
187
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
184
188
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -199,6 +203,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
199
203
  * @param marketId - Target market that would receive the liquidity.
200
204
  * @param options - Optional allocator discovery options.
201
205
  * @returns Total reallocatable assets in loan-token units; `0n` when none is available.
206
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
202
207
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
203
208
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
204
209
  * `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
@@ -252,6 +257,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
252
257
  * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
253
258
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
254
259
  * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
260
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
255
261
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
256
262
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
257
263
  * `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
@@ -210,10 +210,13 @@ export class VaultV1ReallocationData {
210
210
  * Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
211
211
  * on-chain `reallocateTo` fee semantics: one fee charge per vault with at
212
212
  * least one computed withdrawal.
213
+ * Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
214
+ * are skipped before projecting source interest.
213
215
  *
214
216
  * @param marketId - Target market to supply with shared liquidity.
215
217
  * @param options - Optional allocator discovery options.
216
218
  * @returns Computed source-market withdrawals and the post-reallocation state.
219
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
217
220
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
218
221
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
219
222
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -311,6 +314,7 @@ export class VaultV1ReallocationData {
311
314
  * @param marketId - Target market to supply with shared liquidity.
312
315
  * @param options - Optional allocator discovery options.
313
316
  * @returns Computed source-market withdrawals and the post-reallocation state.
317
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
314
318
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
315
319
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
316
320
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -330,6 +334,7 @@ export class VaultV1ReallocationData {
330
334
  * @param marketId - Target market that would receive the liquidity.
331
335
  * @param options - Optional allocator discovery options.
332
336
  * @returns Total reallocatable assets in loan-token units; `0n` when none is available.
337
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
333
338
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
334
339
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
335
340
  * `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
@@ -386,6 +391,7 @@ export class VaultV1ReallocationData {
386
391
  * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
387
392
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
388
393
  * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
394
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
389
395
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
390
396
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
391
397
  * `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
@@ -443,25 +449,34 @@ export class VaultV1ReallocationData {
443
449
  getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
444
450
  return _try(() => {
445
451
  const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
452
+ const maxIn = publicAllocatorConfig?.maxIn ?? 0n;
446
453
  const validCap = pendingCap.validAt >= timestamp
447
454
  ? MathLib.min(pendingCap.value, cap)
448
455
  : cap;
456
+ if (maxIn === 0n || validCap === 0n)
457
+ return { vault };
449
458
  const suppliable = MathLib.zeroFloorSub(validCap, this.getAccrualPosition(vault, marketId).accrueInterest(timestamp)
450
459
  .supplyAssets);
460
+ if (suppliable === 0n)
461
+ return { vault };
451
462
  const marketWithdrawals = this.getVault(vault)
452
463
  .withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
453
464
  !withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
454
465
  .map((srcMarketId) => {
455
466
  const withdrawal = _try(() => {
456
- const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
457
- const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
458
- defaultMaxWithdrawalUtilization);
459
467
  const srcConfig = this.getVaultMarketConfig(vault, srcMarketId);
460
- if (!srcConfig.enabled)
468
+ const maxOut = srcConfig.publicAllocatorConfig?.maxOut ?? 0n;
469
+ if (!srcConfig.enabled || maxOut === 0n)
470
+ return { id: srcMarketId, assets: 0n };
471
+ const rawSrcPosition = this.getAccrualPosition(vault, srcMarketId);
472
+ if (rawSrcPosition.supplyShares === 0n)
461
473
  return { id: srcMarketId, assets: 0n };
474
+ const srcPosition = rawSrcPosition.accrueInterest(timestamp);
475
+ const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
476
+ defaultMaxWithdrawalUtilization);
462
477
  return {
463
478
  id: srcMarketId,
464
- assets: MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, publicAllocatorConfig?.maxIn ?? 0n, srcConfig.publicAllocatorConfig?.maxOut ?? 0n),
479
+ assets: MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, maxIn, maxOut),
465
480
  };
466
481
  }, UnknownDataError);
467
482
  return withdrawal ?? { id: srcMarketId, assets: 0n };
@@ -30,6 +30,7 @@ export interface VaultV2Actions {
30
30
  * @returns {Object} The result object.
31
31
  * @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
32
32
  * @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
33
+ * @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
33
34
  */
34
35
  deposit: (params: {
35
36
  userAddress: Address;
@@ -101,6 +102,7 @@ export interface VaultV2Actions {
101
102
  * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
102
103
  * @returns Lazy prerequisite resolution and a synchronous transaction builder.
103
104
  * @throws {ChainIdMismatchError} when the client and entity target different chains.
105
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
104
106
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
105
107
  * @throws {NonPositiveInputError} when `amount` is not positive.
106
108
  * @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
@@ -173,7 +173,9 @@ export class MorphoVaultV2 {
173
173
  if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
174
174
  throw new EmptyMarketParamsListError();
175
175
  }
176
- const assetsByMarket = new Map(soleAdapter.markets.map((market) => [
176
+ const assetsByMarket = new Map(soleAdapter.markets
177
+ .filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
178
+ .map((market) => [
177
179
  market.id,
178
180
  market
179
181
  .accrueInterest(now)
@@ -363,7 +363,11 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
363
363
  * utilization defaults to 90% and is configurable through
364
364
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
365
365
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
366
- * considered.
366
+ * considered. Targets with no remaining supply or allocator capacity are skipped before
367
+ * projecting source interest. The adapter's minimum share minting requirement, supply-share
368
+ * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
369
+ * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
370
+ * allocation does not increase after rounding.
367
371
  *
368
372
  * Shared-cap discovery is conservative. Operation planning searches at most
369
373
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -374,6 +378,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
374
378
  * @param marketId - Target Blue market id.
375
379
  * @param options - Optional discovery controls and operation to support.
376
380
  * @returns Flat action-ready reallocations and their post-simulation state.
381
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
377
382
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
378
383
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
379
384
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
@@ -430,6 +435,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
430
435
  * @param marketId - Target Blue market id.
431
436
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
432
437
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
438
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
433
439
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
434
440
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
435
441
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -470,6 +476,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
470
476
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
471
477
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
472
478
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
479
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
473
480
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
474
481
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
475
482
  * @throws {UnknownReallocationMarketError} when a required market is absent.