@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.2

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 (174) hide show
  1. package/MIGRATION-v5-to-v6.md +127 -16
  2. package/README.md +17 -11
  3. package/lib/cjs/abis.d.ts +17 -2
  4. package/lib/cjs/abis.js +14 -1
  5. package/lib/cjs/actions/blue/common.js +5 -26
  6. package/lib/cjs/actions/blue/supply.js +2 -7
  7. package/lib/cjs/actions/bundles/common.d.ts +32 -2
  8. package/lib/cjs/actions/bundles/common.js +68 -30
  9. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  10. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  11. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  12. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  13. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  14. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  18. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  19. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  20. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  21. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  22. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  23. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  24. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  25. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  26. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  27. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  30. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  31. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  34. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  35. package/lib/cjs/blue/abis.d.ts +5 -1
  36. package/lib/cjs/blue/abis.js +2 -0
  37. package/lib/cjs/blue/entities.d.ts +8 -2
  38. package/lib/cjs/blue/entities.js +1 -0
  39. package/lib/cjs/blue/errors.d.ts +1 -1
  40. package/lib/cjs/blue/errors.js +2 -1
  41. package/lib/cjs/blue/fetch.d.ts +3 -1
  42. package/lib/cjs/blue/fetch.js +1 -0
  43. package/lib/cjs/entities/blue/blue.d.ts +15 -6
  44. package/lib/cjs/entities/blue/blue.js +3 -0
  45. package/lib/cjs/entities/index.d.ts +8 -2
  46. package/lib/cjs/entities/index.js +1 -0
  47. package/lib/cjs/entities/midnight/midnight.js +20 -24
  48. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  49. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  50. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  51. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  52. package/lib/cjs/entities/requirements/index.js +1 -0
  53. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +10 -5
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
  55. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  56. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  57. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +140 -34
  58. package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
  59. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  61. package/lib/cjs/errors.d.ts +1 -1
  62. package/lib/cjs/errors.js +3 -2
  63. package/lib/cjs/fetch.d.ts +3 -1
  64. package/lib/cjs/fetch.js +1 -0
  65. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  66. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  67. package/lib/cjs/helpers/index.d.ts +3 -1
  68. package/lib/cjs/helpers/index.js +10 -1
  69. package/lib/cjs/helpers/metadata.d.ts +3 -5
  70. package/lib/cjs/helpers/metadata.js +4 -6
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  72. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  73. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  74. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  75. package/lib/cjs/helpers/slippage.d.ts +46 -0
  76. package/lib/cjs/helpers/slippage.js +65 -0
  77. package/lib/cjs/helpers/validate.d.ts +65 -8
  78. package/lib/cjs/helpers/validate.js +83 -9
  79. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  81. package/lib/cjs/types/action.d.ts +95 -13
  82. package/lib/cjs/types/error.d.ts +290 -12
  83. package/lib/cjs/types/error.js +312 -24
  84. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  85. package/lib/cjs/utils.d.ts +3 -1
  86. package/lib/cjs/utils.js +10 -1
  87. package/lib/esm/abis.d.ts +17 -2
  88. package/lib/esm/abis.js +17 -2
  89. package/lib/esm/actions/blue/common.js +7 -28
  90. package/lib/esm/actions/blue/supply.js +4 -9
  91. package/lib/esm/actions/bundles/common.d.ts +32 -2
  92. package/lib/esm/actions/bundles/common.js +68 -31
  93. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  94. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  95. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  96. package/lib/esm/actions/requirements/blue/index.js +0 -1
  97. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  98. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  99. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  100. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
  101. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  102. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  105. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  106. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  107. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  108. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  109. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  110. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  111. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  112. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  113. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  114. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  115. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  116. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  117. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  118. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  119. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  120. package/lib/esm/blue/abis.d.ts +5 -1
  121. package/lib/esm/blue/abis.js +5 -1
  122. package/lib/esm/blue/entities.d.ts +8 -2
  123. package/lib/esm/blue/entities.js +3 -1
  124. package/lib/esm/blue/errors.d.ts +1 -1
  125. package/lib/esm/blue/errors.js +1 -1
  126. package/lib/esm/blue/fetch.d.ts +3 -1
  127. package/lib/esm/blue/fetch.js +3 -1
  128. package/lib/esm/entities/blue/blue.d.ts +15 -6
  129. package/lib/esm/entities/blue/blue.js +3 -0
  130. package/lib/esm/entities/index.d.ts +8 -2
  131. package/lib/esm/entities/index.js +3 -1
  132. package/lib/esm/entities/midnight/midnight.js +20 -24
  133. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  134. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  135. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  136. package/lib/esm/entities/requirements/index.d.ts +1 -0
  137. package/lib/esm/entities/requirements/index.js +1 -0
  138. package/lib/esm/entities/vaultV1/vaultV1.d.ts +10 -5
  139. package/lib/esm/entities/vaultV1/vaultV1.js +14 -2
  140. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  141. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  142. package/lib/esm/entities/vaultV2/vaultV2.d.ts +140 -34
  143. package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
  144. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  145. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  146. package/lib/esm/errors.d.ts +1 -1
  147. package/lib/esm/errors.js +1 -1
  148. package/lib/esm/fetch.d.ts +3 -1
  149. package/lib/esm/fetch.js +3 -1
  150. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  151. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  152. package/lib/esm/helpers/index.d.ts +3 -1
  153. package/lib/esm/helpers/index.js +3 -1
  154. package/lib/esm/helpers/metadata.d.ts +3 -5
  155. package/lib/esm/helpers/metadata.js +4 -6
  156. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  157. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  158. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  159. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  160. package/lib/esm/helpers/slippage.d.ts +46 -0
  161. package/lib/esm/helpers/slippage.js +65 -1
  162. package/lib/esm/helpers/validate.d.ts +65 -8
  163. package/lib/esm/helpers/validate.js +82 -10
  164. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  165. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  166. package/lib/esm/types/action.d.ts +95 -13
  167. package/lib/esm/types/error.d.ts +290 -12
  168. package/lib/esm/types/error.js +301 -19
  169. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  170. package/lib/esm/utils.d.ts +3 -1
  171. package/lib/esm/utils.js +3 -1
  172. package/package.json +7 -7
  173. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  174. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -37,6 +37,7 @@ export interface VaultV2Actions {
37
37
  * two hours from handle creation.
38
38
  * @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
39
39
  * transaction builder.
40
+ * @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
40
41
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
41
42
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
42
43
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
@@ -48,8 +49,8 @@ export interface VaultV2Actions {
48
49
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
49
50
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
50
51
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
51
- * @throws {MissingPermit2SignatureTransferNonceError} from `getRequirements()` when Permit2 is
52
- * selected without an explicit nonce.
52
+ * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
53
+ * owner is consumed and none was passed explicitly.
53
54
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
54
55
  * explicit Permit2 nonce is consumed.
55
56
  * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
@@ -242,16 +243,18 @@ export interface VaultV2Actions {
242
243
  * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
243
244
  * @returns Lazy prerequisite resolution and a synchronous transaction builder.
244
245
  * @throws {ChainIdMismatchError} when the client and entity target different chains.
246
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
245
247
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
246
- * @throws {NonPositiveInputError} when `amount` is not positive.
248
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
247
249
  * @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
248
250
  * penalty-adjusted amount rounds to zero deallocated assets.
249
251
  * @throws {EmptyMarketParamsListError} when assets must be deallocated and the market list is empty.
252
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
250
253
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
251
254
  * requirement resolution.
252
- * @throws {InKindRedeemRequiresSingleAdapterError} when the vault does not have one adapter.
255
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
253
256
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
254
- * @throws {UnsupportedInKindAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
257
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
255
258
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
256
259
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
257
260
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -294,29 +297,129 @@ export interface VaultV2Actions {
294
297
  readonly deadline?: bigint;
295
298
  }) => ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
296
299
  /**
297
- * Prepares a force withdraw transaction for the VaultV2 contract using the vault's native multicall.
300
+ * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
298
301
  *
299
- * This function encodes one or more on-chain forceDeallocate calls followed by a single withdraw,
300
- * executed atomically via VaultV2's multicall. This allows a user to free liquidity from multiple
301
- * illiquid markets and withdraw the resulting assets in one transaction.
302
+ * The contract withdraws everything the vault can pay without a penalty — its idle assets plus
303
+ * the liquidity available through its liquidity adapter — then force-deallocates the remainder by
304
+ * looping over the adapter's markets. It computes the deallocations itself: the caller supplies
305
+ * neither a market list nor an order.
302
306
  *
303
- * @param {Object} params - The force withdraw parameters.
304
- * @param {readonly Deallocation[]} params.deallocations - The typed list of deallocations to perform.
305
- * @param {Object} params.withdraw - The withdraw parameters applied after deallocations.
306
- * @param {bigint} params.withdraw.amount - The amount of assets to withdraw.
307
- * @param {Address} params.userAddress - User address (penalty source and withdraw recipient).
308
- * @returns {Object} The result object.
309
- * @returns {Readonly<Transaction<VaultV2ForceWithdrawAction>>} returns.buildTx The prepared multicall transaction.
307
+ * `exitAssets` is **penalty-inclusive**, matching `inKindRedeem`. The contract debits it from the
308
+ * user's position but pays out only
309
+ * `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))`, minus the
310
+ * referral fee. Quote the split with `previewVaultV2ForceWithdraw`.
311
+ *
312
+ * The vault must have exactly one `MorphoMarketV1AdapterV2` and route liquidity through that same
313
+ * adapter or none at all. Call `getRequirements()` before `buildTx()` so the vault-share allowance
314
+ * and permit nonce are read on-chain.
315
+ *
316
+ * Unless `minSharePriceE27` is overridden, the SDK derives a conservative lower bound on the
317
+ * realized exit share price from the snapshot and `slippageTolerance`. The bound rejects a share
318
+ * price drop, a penalty increase, and liquidity shifting from the penalty-free leg to the
319
+ * penalised leg. It does **not** cover the referral fee, which the contract deducts afterwards.
320
+ *
321
+ * Vault gates are enforced by the final transaction and are not preflighted: the receive-assets
322
+ * gate must allow VaultExitBundlesV1 and may depend on its transient initiator, while a
323
+ * send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
324
+ * validate the user's share balance. Per-market penalties and each vault withdrawal round the
325
+ * share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
326
+ * implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` — the approved
327
+ * share allowance this handle returns is the exact upper bound on the burn — so a full-balance
328
+ * exit does not revert for insufficient shares.
329
+ *
330
+ * Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
331
+ * an on-chain revert remains possible if vault state changes between preparation and inclusion.
332
+ * A fee-recipient `userAddress` gets a floor from the net share burn after fee mints at `now`,
333
+ * and a guard against fee mints reaching the lower burn bound by the deadline. Its allowance
334
+ * includes the projected fee shares through that same deadline. Deadlines beyond one year after
335
+ * handle creation are rejected, so the guard and allowance cover the whole accepted window.
336
+ *
337
+ * @param params - Force withdrawal parameters.
338
+ * @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
339
+ * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
340
+ * @param params.userAddress - Account that signs and submits the exit, and receives the assets.
341
+ * @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
342
+ * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
343
+ * Deadlines more than one year after handle creation are rejected.
344
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance applied to the derived share
345
+ * price bound. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`, capped at `MAX_SLIPPAGE_TOLERANCE`.
346
+ * @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound. Must be
347
+ * positive: the contract reads `0` as "no bound", so it cannot be used to opt out.
348
+ * @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
349
+ * `referralFeeRecipient`. Defaults to `0n`.
350
+ * @param params.referralFeeRecipient - Optional referral fee recipient, required when
351
+ * `referralFeePct` is positive.
352
+ * @returns Lazy prerequisite resolution and a synchronous transaction builder.
353
+ * @throws {ChainIdMismatchError} when the client and entity target different chains.
354
+ * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
355
+ * @throws {NonPositiveInputError} when `exitAssets`, `deadline`, or a supplied
356
+ * `minSharePriceE27` is not positive.
357
+ * @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
358
+ * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
359
+ * `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `referralFeePct` is not
360
+ * below WAD, or when `deadline` is more than one year after handle creation.
361
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
362
+ * requirement resolution.
363
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
364
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
365
+ * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
366
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
367
+ * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
368
+ * another adapter.
369
+ * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
370
+ * as `MarketParams`.
371
+ * @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit would withdraw nothing.
372
+ * @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the exit,
373
+ * which would overrun the contract's unbounded loop.
374
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds down
375
+ * to zero, which the contract would read as no bound at all.
376
+ * @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when fee shares are minted to a
377
+ * fee-recipient `userAddress` and reach the lower-bound share burn at the deadline.
378
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
379
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
380
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
381
+ * @throws {viem.BaseError} from `getRequirements()` when an RPC or multicall contract read fails.
382
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
383
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
384
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
385
+ * deadline differs from this operation. Any handle built from the same inputs accepts the
386
+ * permit; the nonce is verified onchain by the vault's `permit`.
387
+ * @throws {VaultExitBundlesV1PermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
388
+ * @example
389
+ * ```ts
390
+ * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
391
+ *
392
+ * const vault = client.morpho.vaultV2(vaultAddress, 1);
393
+ * const vaultData = await vault.getData();
394
+ * const exit = vault.forceWithdraw({
395
+ * exitAssets: 1_000_000n,
396
+ * vaultData,
397
+ * userAddress,
398
+ * });
399
+ * const signatures = [];
400
+ * for (const requirement of await exit.getRequirements()) {
401
+ * if (isRequirementSignature(requirement)) {
402
+ * signatures.push(await requirement.sign(walletClient, userAddress));
403
+ * } else {
404
+ * const hash = await walletClient.sendTransaction(requirement);
405
+ * await client.waitForTransactionReceipt({ hash });
406
+ * }
407
+ * }
408
+ * const tx = exit.buildTx(signatures);
409
+ * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
410
+ * ```
310
411
  */
311
- forceWithdraw: (params: {
312
- deallocations: readonly Deallocation[];
313
- withdraw: {
314
- amount: bigint;
315
- };
316
- userAddress: Address;
317
- }) => {
318
- buildTx: () => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
319
- };
412
+ readonly forceWithdraw: (params: {
413
+ readonly exitAssets: bigint;
414
+ readonly vaultData: AccrualVaultV2;
415
+ readonly userAddress: Address;
416
+ readonly adapter?: Address;
417
+ readonly deadline?: bigint;
418
+ readonly slippageTolerance?: bigint;
419
+ readonly minSharePriceE27?: bigint;
420
+ readonly referralFeePct?: bigint;
421
+ readonly referralFeeRecipient?: Address;
422
+ }) => ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
320
423
  /**
321
424
  * Prepares a force redeem transaction for the VaultV2 contract using the vault's native multicall.
322
425
  *
@@ -398,15 +501,18 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
398
501
  readonly adapter?: Address;
399
502
  readonly deadline?: bigint;
400
503
  }): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
401
- forceWithdraw({ deallocations, withdraw, userAddress, }: {
402
- deallocations: readonly Deallocation[];
403
- withdraw: {
404
- amount: bigint;
405
- };
406
- userAddress: Address;
407
- }): {
408
- buildTx: () => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
409
- };
504
+ /** {@inheritDoc VaultV2Actions.forceWithdraw} */
505
+ forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, }: {
506
+ readonly exitAssets: bigint;
507
+ readonly vaultData: AccrualVaultV2;
508
+ readonly userAddress: Address;
509
+ readonly adapter?: Address;
510
+ readonly deadline?: bigint;
511
+ readonly slippageTolerance?: bigint;
512
+ readonly minSharePriceE27?: bigint;
513
+ readonly referralFeePct?: bigint;
514
+ readonly referralFeeRecipient?: Address;
515
+ }): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
410
516
  forceRedeem({ deallocations, redeem, userAddress, }: {
411
517
  deallocations: readonly Deallocation[];
412
518
  redeem: {
@@ -13,6 +13,9 @@ const validate_js_1 = require("../../helpers/validate.js");
13
13
  const index_js_3 = require("../../types/index.js");
14
14
  const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
15
15
  const index_js_4 = require("../requirements/index.js");
16
+ // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
17
+ // accrual model stays well-defined inside it.
18
+ const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
16
19
  class MorphoVaultV2 {
17
20
  client;
18
21
  vault;
@@ -289,21 +292,24 @@ class MorphoVaultV2 {
289
292
  const marketIdListSnapshot = marketParamsListSnapshot.map((marketParams) => blue_sdk_1.MarketUtils.getMarketId(marketParams));
290
293
  const now = morpho_ts_1.Time.timestamp();
291
294
  const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
295
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
296
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
297
+ (0, validate_js_1.validateDeadline)(deadline);
292
298
  if (deadline <= now)
293
299
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
294
300
  if (vaultData.accrualAdapters.length !== 1) {
295
- throw new index_js_3.InKindRedeemRequiresSingleAdapterError(this.vault, vaultData.accrualAdapters.length);
301
+ throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, vaultData.accrualAdapters.length);
296
302
  }
297
303
  const soleAdapter = vaultData.accrualAdapters[0];
298
304
  if (soleAdapter == null) {
299
- throw new index_js_3.InKindRedeemRequiresSingleAdapterError(this.vault, 0);
305
+ throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, 0);
300
306
  }
301
307
  const adapter = adapterOverride ?? soleAdapter.address;
302
308
  if (!(0, viem_1.isAddressEqual)(adapter, soleAdapter.address)) {
303
309
  throw new index_js_3.AdapterNotPartOfVaultError(this.vault, adapter);
304
310
  }
305
311
  if (!(soleAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2)) {
306
- throw new index_js_3.UnsupportedInKindAdapterError(adapter);
312
+ throw new index_js_3.VaultV2UnsupportedExitAdapterError(adapter);
307
313
  }
308
314
  const penalty = vaultData.forceDeallocatePenalties[soleAdapter.address] ?? 0n;
309
315
  const idleAssets = blue_sdk_1.MathLib.min(vaultData.assetBalance, amount);
@@ -318,7 +324,9 @@ class MorphoVaultV2 {
318
324
  if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
319
325
  throw new index_js_3.EmptyMarketParamsListError();
320
326
  }
321
- const assetsByMarket = new Map(soleAdapter.markets.map((market) => [
327
+ const assetsByMarket = new Map(soleAdapter.markets
328
+ .filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
329
+ .map((market) => [
322
330
  market.id,
323
331
  market
324
332
  .accrueInterest(now)
@@ -449,21 +457,226 @@ class MorphoVaultV2 {
449
457
  },
450
458
  };
451
459
  }
452
- forceWithdraw({ deallocations, withdraw, userAddress, }) {
460
+ /** {@inheritDoc VaultV2Actions.forceWithdraw} */
461
+ forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, }) {
453
462
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
463
+ if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
464
+ throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
465
+ }
466
+ if (exitAssets <= 0n)
467
+ throw new index_js_3.NonPositiveInputError("exitAssets", exitAssets);
468
+ (0, validate_js_1.validateUint256Field)("exitAssets", exitAssets);
469
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
470
+ // Called for its throws only: the raw pair is forwarded to the action, which normalizes it
471
+ // again on the encode path so a direct action caller gets the same guarantees.
472
+ (0, validate_js_1.validateReferralFee)({ referralFeePct, referralFeeRecipient });
473
+ if (minSharePriceE27Override != null) {
474
+ // An unbounded override reopens the exact hole this path closes: the contract reads
475
+ // `minSharePriceE27 == 0` as "no bound".
476
+ if (minSharePriceE27Override <= 0n) {
477
+ throw new index_js_3.NonPositiveInputError("minSharePriceE27", minSharePriceE27Override);
478
+ }
479
+ // And an override the uint256 slot cannot hold must fail here rather than after
480
+ // `getRequirements()` has already asked for an approval or a permit signature.
481
+ (0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27Override);
482
+ }
483
+ const now = morpho_ts_1.Time.timestamp();
484
+ const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
485
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
486
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
487
+ (0, validate_js_1.validateDeadline)(deadline);
488
+ if (deadline <= now)
489
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
490
+ const maxDeadline = now + VAULT_V2_FEE_PROJECTION_HORIZON;
491
+ if (deadline > maxDeadline) {
492
+ throw new index_js_3.InputExceedsMaxError({
493
+ field: "deadline",
494
+ value: deadline,
495
+ max: maxDeadline,
496
+ });
497
+ }
498
+ const eligibility = (0, index_js_2.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
499
+ switch (eligibility.type) {
500
+ case "eligible":
501
+ break;
502
+ case "adapterCount":
503
+ throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, eligibility.adapters);
504
+ case "adapterMismatch":
505
+ throw new index_js_3.AdapterNotPartOfVaultError(this.vault, eligibility.adapter);
506
+ case "unsupportedAdapter":
507
+ throw new index_js_3.VaultV2UnsupportedExitAdapterError(eligibility.adapter);
508
+ case "unsupportedLiquidityAdapter":
509
+ throw new index_js_3.VaultV2UnsupportedLiquidityAdapterError({
510
+ vault: this.vault,
511
+ liquidityAdapter: eligibility.liquidityAdapter,
512
+ adapter: eligibility.adapter,
513
+ });
514
+ case "undecodableLiquidityData":
515
+ throw new index_js_3.VaultV2UndecodableLiquidityDataError({
516
+ vault: this.vault,
517
+ liquidityAdapter: eligibility.liquidityAdapter,
518
+ liquidityData: eligibility.liquidityData,
519
+ cause: eligibility.cause,
520
+ });
521
+ }
522
+ const { adapter: accrualAdapter, liquidityMarketId } = eligibility;
523
+ const adapter = accrualAdapter.address;
524
+ const plan = (0, index_js_2.computeVaultV2ForceWithdrawPlan)({
525
+ vaultData,
526
+ adapter: accrualAdapter,
527
+ liquidityMarketId,
528
+ exitAssets,
529
+ timestamp: now,
530
+ });
531
+ if (plan.withdrawnAssets <= 0n) {
532
+ throw new index_js_3.VaultV2ForceWithdrawZeroWithdrawalError({
533
+ vault: this.vault,
534
+ exitAssets,
535
+ penalty: plan.penalty,
536
+ });
537
+ }
538
+ // The contract's force-deallocation loop is unbounded: under-coverage panics on-chain.
539
+ if (plan.coveredAssets < plan.assetsToDeallocate) {
540
+ throw new index_js_3.VaultV2ForceWithdrawCoverageError({
541
+ required: plan.assetsToDeallocate,
542
+ covered: plan.coveredAssets,
543
+ maxExitAssets: plan.maxExitAssets,
544
+ });
545
+ }
546
+ const projectionTimestamp = deadline;
547
+ // VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
548
+ // accrues the vault before burning. Use the `now` accrual for the floor and the projected
549
+ // deadline accrual for the fee-mint guard.
550
+ const { vault: nowVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(now, vaultData.lastUpdate));
551
+ const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(projectionTimestamp, vaultData.lastUpdate));
552
+ const sharesBurntNow = (0, index_js_2.computeVaultV2ForceWithdrawSharesBurnt)({
553
+ vaultData: nowVaultData,
554
+ deadlineVaultData: nowVaultData,
555
+ plan,
556
+ });
557
+ const feeSharesNow = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
558
+ vaultData,
559
+ owner: userAddress,
560
+ timestamp: now,
561
+ });
562
+ const feeSharesProjected = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
563
+ vaultData,
564
+ owner: userAddress,
565
+ timestamp: projectionTimestamp,
566
+ });
567
+ const minSharesBurntProjected = (0, index_js_2.computeVaultV2ForceWithdrawMinSharesBurnt)({
568
+ vaultData: projectedVaultData,
569
+ plan,
570
+ });
571
+ // When fee shares are minted, the projected pair bounds every execution time in the window.
572
+ if (feeSharesProjected > 0n &&
573
+ feeSharesProjected >= minSharesBurntProjected) {
574
+ throw new index_js_3.VaultV2ForceWithdrawFeeSharesExceedBurnError({
575
+ vault: this.vault,
576
+ userAddress,
577
+ sharesBurnt: minSharesBurntProjected,
578
+ feeShares: feeSharesProjected,
579
+ });
580
+ }
581
+ // sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
582
+ const netSharesBurntNow = sharesBurntNow - feeSharesNow;
583
+ const minSharePriceE27 = minSharePriceE27Override ??
584
+ (0, index_js_2.computeMinForceWithdrawSharePrice)({
585
+ withdrawnAssets: plan.withdrawnAssets,
586
+ sharesBurnt: netSharesBurntNow,
587
+ slippageTolerance,
588
+ });
589
+ // The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
590
+ // lowering a lower bound weakens it, so any vault whose share price grew past that would be left
591
+ // with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
592
+ // only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
593
+ //
594
+ // It still has to fit the ABI slot though. Defense-in-depth rather than a reachable input error:
595
+ // with `exitAssets` bounded above, the derived floor only exceeds `uint256` on a vault whose
596
+ // share price passed ~1e50 assets/share, which no fixture here can construct.
597
+ (0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27);
598
+ // VaultExitBundlesV1's burn bound includes fee shares minted by the first withdrawal. Add the
599
+ // projected fee shares to the price-floor ceiling so the approval covers that mint.
600
+ // Saturated at `maxUint256`: a tiny accepted floor scales this above the ABI slot, and the
601
+ // approval encoder clamps what it emits — so an uncapped requirement would sit permanently above
602
+ // any allowance the user can actually grant and `getRequirements()` would return the same
603
+ // approval forever. No account can hold or burn more shares than that anyway.
604
+ const requiredShareAllowance = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, minSharePriceE27) +
605
+ feeSharesProjected, viem_1.maxUint256);
606
+ const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
454
607
  return {
455
- buildTx: () => (0, index_js_1.vaultV2ForceWithdraw)({
456
- vault: { address: this.vault },
457
- args: {
458
- deallocations,
459
- withdraw: {
460
- amount: withdraw.amount,
461
- recipient: userAddress,
608
+ getRequirements: async () => {
609
+ const requirementsTimestamp = morpho_ts_1.Time.timestamp();
610
+ if (deadline <= requirementsTimestamp) {
611
+ throw new index_js_3.ExpiredDeadlineError(deadline, requirementsTimestamp);
612
+ }
613
+ // Vault gates are intentionally left to the final transaction: the receive-assets gate may
614
+ // inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
615
+ // external code re-evaluated after each intermediate penalty burn, so neither is
616
+ // execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
617
+ // supplies into Morpho Blue, so no Blue token-balance check is needed.
618
+ const [allowance, nonce] = await (0, actions_1.multicall)(this.client.viemClient, {
619
+ allowFailure: false,
620
+ contracts: [
621
+ {
622
+ address: this.vault,
623
+ abi: viem_1.erc20Abi,
624
+ functionName: "allowance",
625
+ args: [userAddress, vaultExitBundlesV1],
626
+ },
627
+ {
628
+ address: this.vault,
629
+ abi: blue_sdk_viem_1.erc2612Abi,
630
+ functionName: "nonces",
631
+ args: [userAddress],
632
+ },
633
+ ],
634
+ });
635
+ if (allowance >= requiredShareAllowance)
636
+ return [];
637
+ if (this.client.options.supportSignature) {
638
+ const requirement = (0, index_js_1.encodeVaultSharesPermit)({
639
+ vault: vaultData,
640
+ version: "vaultV2",
641
+ spender: vaultExitBundlesV1,
642
+ owner: userAddress,
643
+ chainId: this.chainId,
644
+ nonce,
645
+ amount: requiredShareAllowance,
646
+ deadline,
647
+ });
648
+ return [requirement];
649
+ }
650
+ return [
651
+ (0, index_js_1.encodeErc20Approval)({
652
+ token: this.vault,
653
+ spender: vaultExitBundlesV1,
654
+ amount: requiredShareAllowance,
655
+ chainId: this.chainId,
656
+ }),
657
+ ];
658
+ },
659
+ buildTx: (signatures) => {
660
+ const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
661
+ spender: vaultExitBundlesV1,
662
+ amount: requiredShareAllowance,
663
+ deadline,
664
+ });
665
+ return (0, index_js_1.vaultV2ForceWithdraw)({
666
+ vault: { chainId: this.chainId, address: this.vault },
667
+ args: {
668
+ adapter,
669
+ exitAssets,
670
+ minSharePriceE27,
671
+ userAddress,
672
+ deadline,
673
+ referralFeePct,
674
+ referralFeeRecipient,
675
+ requirementSignature: permit,
462
676
  },
463
- onBehalf: userAddress,
464
- },
465
- metadata: this.client.options.metadata,
466
- }),
677
+ metadata: this.client.options.metadata,
678
+ });
679
+ },
467
680
  };
468
681
  }
469
682
  forceRedeem({ deallocations, redeem, userAddress, }) {
@@ -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.