@morpho-org/morpho-sdk 9.1.0-next.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +7 -1
  2. package/lib/cjs/abis.d.ts +2 -2
  3. package/lib/cjs/abis.js +3 -5
  4. package/lib/cjs/actions/blue/borrow.d.ts +1 -0
  5. package/lib/cjs/actions/blue/borrow.js +1 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +1 -0
  7. package/lib/cjs/actions/blue/refinance.js +3 -0
  8. package/lib/cjs/actions/blue/repay.d.ts +1 -0
  9. package/lib/cjs/actions/blue/repay.js +1 -0
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
  12. package/lib/cjs/actions/blue/supply.d.ts +1 -0
  13. package/lib/cjs/actions/blue/supply.js +2 -0
  14. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
  15. package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
  16. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  17. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
  18. package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
  19. package/lib/cjs/actions/blue/withdraw.js +2 -0
  20. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
  21. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  23. package/lib/cjs/actions/midnight/takeLend.js +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  25. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  26. package/lib/cjs/blue/abis.d.ts +1 -1
  27. package/lib/cjs/blue/abis.js +1 -5
  28. package/lib/cjs/blue/constants.d.ts +1 -1
  29. package/lib/cjs/blue/constants.js +2 -1
  30. package/lib/cjs/blue/entities.d.ts +4 -4
  31. package/lib/cjs/blue/entities.js +1 -3
  32. package/lib/cjs/blue/errors.d.ts +2 -2
  33. package/lib/cjs/blue/errors.js +2 -5
  34. package/lib/cjs/blue/fetch.d.ts +2 -2
  35. package/lib/cjs/blue/fetch.js +1 -3
  36. package/lib/cjs/blue/utils.d.ts +1 -1
  37. package/lib/cjs/blue/utils.js +1 -2
  38. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  39. package/lib/cjs/client/morphoViemExtension.js +1 -7
  40. package/lib/cjs/constants.d.ts +2 -2
  41. package/lib/cjs/constants.js +4 -1
  42. package/lib/cjs/entities/blue/blue.d.ts +112 -21
  43. package/lib/cjs/entities/blue/blue.js +58 -6
  44. package/lib/cjs/entities/index.d.ts +4 -4
  45. package/lib/cjs/entities/index.js +1 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +9 -6
  47. package/lib/cjs/entities/midnight/midnight.js +12 -9
  48. package/lib/cjs/entities/midnight/types.d.ts +8 -1
  49. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +8 -0
  50. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -0
  51. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -34
  52. package/lib/cjs/entities/vaultV2/vaultV2.js +12 -38
  53. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +77 -19
  54. package/lib/cjs/entities/vaultV2BlueReallocationData.js +376 -80
  55. package/lib/cjs/errors.d.ts +4 -4
  56. package/lib/cjs/errors.js +6 -10
  57. package/lib/cjs/fetch.d.ts +2 -2
  58. package/lib/cjs/fetch.js +1 -3
  59. package/lib/cjs/helpers/constant.d.ts +7 -0
  60. package/lib/cjs/helpers/constant.js +8 -1
  61. package/lib/cjs/helpers/deadShares.d.ts +82 -0
  62. package/lib/cjs/helpers/deadShares.js +200 -0
  63. package/lib/cjs/helpers/index.d.ts +2 -1
  64. package/lib/cjs/helpers/index.js +7 -1
  65. package/lib/cjs/helpers/validate.d.ts +11 -1
  66. package/lib/cjs/helpers/validate.js +17 -1
  67. package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
  68. package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -1
  71. package/lib/cjs/midnight/errors.d.ts +1 -2
  72. package/lib/cjs/midnight/errors.js +4 -5
  73. package/lib/cjs/types/error.d.ts +60 -5
  74. package/lib/cjs/types/error.js +68 -6
  75. package/lib/cjs/types/sharedLiquidity.d.ts +31 -11
  76. package/lib/cjs/utils.d.ts +2 -2
  77. package/lib/cjs/utils.js +2 -4
  78. package/lib/esm/abis.d.ts +2 -2
  79. package/lib/esm/abis.js +2 -2
  80. package/lib/esm/actions/blue/borrow.d.ts +1 -0
  81. package/lib/esm/actions/blue/borrow.js +1 -0
  82. package/lib/esm/actions/blue/refinance.d.ts +1 -0
  83. package/lib/esm/actions/blue/refinance.js +4 -1
  84. package/lib/esm/actions/blue/repay.d.ts +1 -0
  85. package/lib/esm/actions/blue/repay.js +1 -0
  86. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  87. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
  88. package/lib/esm/actions/blue/supply.d.ts +1 -0
  89. package/lib/esm/actions/blue/supply.js +3 -1
  90. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
  91. package/lib/esm/actions/blue/supplyCollateral.js +1 -0
  92. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  93. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
  94. package/lib/esm/actions/blue/withdraw.d.ts +1 -0
  95. package/lib/esm/actions/blue/withdraw.js +3 -1
  96. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
  97. package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
  98. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  99. package/lib/esm/actions/midnight/takeLend.js +1 -0
  100. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  101. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  102. package/lib/esm/blue/abis.d.ts +1 -1
  103. package/lib/esm/blue/abis.js +1 -1
  104. package/lib/esm/blue/constants.d.ts +1 -1
  105. package/lib/esm/blue/constants.js +1 -1
  106. package/lib/esm/blue/entities.d.ts +4 -4
  107. package/lib/esm/blue/entities.js +2 -2
  108. package/lib/esm/blue/errors.d.ts +2 -2
  109. package/lib/esm/blue/errors.js +2 -2
  110. package/lib/esm/blue/fetch.d.ts +2 -2
  111. package/lib/esm/blue/fetch.js +2 -2
  112. package/lib/esm/blue/utils.d.ts +1 -1
  113. package/lib/esm/blue/utils.js +1 -1
  114. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  115. package/lib/esm/client/morphoViemExtension.js +1 -7
  116. package/lib/esm/constants.d.ts +2 -2
  117. package/lib/esm/constants.js +2 -2
  118. package/lib/esm/entities/blue/blue.d.ts +112 -21
  119. package/lib/esm/entities/blue/blue.js +60 -8
  120. package/lib/esm/entities/index.d.ts +4 -4
  121. package/lib/esm/entities/index.js +2 -2
  122. package/lib/esm/entities/midnight/midnight.d.ts +9 -6
  123. package/lib/esm/entities/midnight/midnight.js +13 -10
  124. package/lib/esm/entities/midnight/types.d.ts +8 -1
  125. package/lib/esm/entities/vaultV1/vaultV1.d.ts +8 -0
  126. package/lib/esm/entities/vaultV1/vaultV1.js +5 -0
  127. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -34
  128. package/lib/esm/entities/vaultV2/vaultV2.js +13 -39
  129. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +77 -19
  130. package/lib/esm/entities/vaultV2BlueReallocationData.js +377 -81
  131. package/lib/esm/errors.d.ts +4 -4
  132. package/lib/esm/errors.js +4 -4
  133. package/lib/esm/fetch.d.ts +2 -2
  134. package/lib/esm/fetch.js +2 -2
  135. package/lib/esm/helpers/constant.d.ts +7 -0
  136. package/lib/esm/helpers/constant.js +7 -0
  137. package/lib/esm/helpers/deadShares.d.ts +82 -0
  138. package/lib/esm/helpers/deadShares.js +195 -0
  139. package/lib/esm/helpers/index.d.ts +2 -1
  140. package/lib/esm/helpers/index.js +2 -1
  141. package/lib/esm/helpers/validate.d.ts +11 -1
  142. package/lib/esm/helpers/validate.js +15 -0
  143. package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
  144. package/lib/esm/helpers/validateTakeableOffers.js +13 -2
  145. package/lib/esm/midnight/abis.d.ts +1 -1
  146. package/lib/esm/midnight/abis.js +1 -1
  147. package/lib/esm/midnight/errors.d.ts +1 -2
  148. package/lib/esm/midnight/errors.js +1 -2
  149. package/lib/esm/types/error.d.ts +60 -5
  150. package/lib/esm/types/error.js +64 -5
  151. package/lib/esm/types/sharedLiquidity.d.ts +31 -11
  152. package/lib/esm/utils.d.ts +2 -2
  153. package/lib/esm/utils.js +2 -2
  154. package/package.json +9 -8
@@ -11,6 +11,7 @@ const index_js_2 = require("../../actions/requirements/index.js");
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
12
  const callback_js_1 = require("../../helpers/callback.js");
13
13
  const constant_js_1 = require("../../helpers/constant.js");
14
+ const deadShares_js_1 = require("../../helpers/deadShares.js");
14
15
  const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
15
16
  const index_js_3 = require("../../helpers/index.js");
16
17
  const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
@@ -342,6 +343,7 @@ class MorphoMidnight {
342
343
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
343
344
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
344
345
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
346
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
345
347
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
346
348
  * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
347
349
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
@@ -930,6 +932,7 @@ class MorphoMidnight {
930
932
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
931
933
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
932
934
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
935
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
933
936
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
934
937
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
935
938
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
@@ -1154,14 +1157,14 @@ class MorphoMidnight {
1154
1157
  * for a new publication. Calls the Midnight mempool validation API while preparing the tree;
1155
1158
  * `validation: false` skips that call.
1156
1159
  *
1157
- * @param params - Maker, lend-side offers, loan reserve, cancellations, and deadline.
1160
+ * @param params - Maker, lend-side offers, `loanAssets` and `reservedLoanAssets` allowance thresholds, cancellations, and deadline.
1158
1161
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
1159
1162
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
1160
1163
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
1161
1164
  * @param params.deadline - Bundle execution deadline timestamp.
1162
1165
  * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
1163
1166
  * @param params.loanToken - Loan token shared by every offer market.
1164
- * @param params.loanAssets - New loan reserve assigned to the published groups.
1167
+ * @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
1165
1168
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
1166
1169
  * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
1167
1170
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
@@ -1436,7 +1439,8 @@ class MorphoMidnight {
1436
1439
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1437
1440
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1438
1441
  * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1439
- * @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
1442
+ * @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
1443
+ * @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
1440
1444
  * @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
1441
1445
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1442
1446
  * @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
@@ -1492,9 +1496,8 @@ class MorphoMidnight {
1492
1496
  }),
1493
1497
  ]);
1494
1498
  const market = (0, morpho_ts_1._try)(() => fetched.accrueInterest(blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), fetched.lastUpdate)), blue_sdk_1.UnsupportedMarketIrmError) ?? fetched;
1495
- if (market.totalSupplyShares === 0n) {
1496
- throw new index_js_4.EmptyBlueParkingMarketError({ marketId: blueMarketId });
1497
- }
1499
+ // Throws when the parking market lacks a sufficient dead deposit; nothing to return.
1500
+ (0, deadShares_js_1.validateBlueMarketDeadShares)(fetched);
1498
1501
  if (market.toSupplyShares(params.assetsToPark, "Down") === 0n) {
1499
1502
  throw new index_js_4.ZeroBlueParkingSharesError({
1500
1503
  marketId: blueMarketId,
@@ -1680,7 +1683,7 @@ class MorphoMidnight {
1680
1683
  *
1681
1684
  * Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
1682
1685
  * Loan assets are pulled by Midnight when the offers fill, not during publication.
1683
- * The loan reserve uses the same approval sizing as `makeLend`.
1686
+ * `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
1684
1687
  * A partially consumed offer group remains publishable with its shared remaining cap reduced.
1685
1688
  * No repay offer can be live after market maturity; late borrowers should repay directly with
1686
1689
  * {@link MorphoMidnight.repayWithdrawCollateral}.
@@ -1688,14 +1691,14 @@ class MorphoMidnight {
1688
1691
  * Every offer must already have `buy = true` and `reduceOnly = true`.
1689
1692
  * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
1690
1693
  *
1691
- * @param params - Maker, reduce-only offers, optional cancellations, loan reserve, and deadline.
1694
+ * @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
1692
1695
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
1693
1696
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
1694
1697
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
1695
1698
  * @param params.deadline - Bundle execution deadline timestamp.
1696
1699
  * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
1697
1700
  * @param params.loanToken - Loan token shared by every offer market.
1698
- * @param params.loanAssets - New loan reserve assigned to the published groups.
1701
+ * @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
1699
1702
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
1700
1703
  * @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
1701
1704
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
@@ -51,7 +51,14 @@ export interface MakeOffersParams {
51
51
  /** Parameters for a Midnight lend maker flow. */
52
52
  export interface MakeLendParams extends MakeOffersParams {
53
53
  readonly loanToken: Address;
54
- /** New group loan reserve. For grouped OCA offers, pass the group reserve once instead of summing every leg. */
54
+ /**
55
+ * Minimum Midnight loan-token allowance, together with `reservedLoanAssets`, that `getRequirements()` checks.
56
+ * When the allowance is lower, it returns an unlimited approval (`maxUint256`, capped per token by `MAX_TOKEN_APPROVALS`).
57
+ * Not checked against the offers: their signed `maxAssets`/`maxUnits` caps, the maker's balance and the
58
+ * allowance bound what takers can fill, so size those caps to what you mean to lend
59
+ * (`maxAssets` counts loan assets, `maxUnits` counts position units).
60
+ * For grouped OCA offers, pass the group amount once instead of summing every leg.
61
+ */
55
62
  readonly loanAssets: bigint;
56
63
  /** Existing loan assets reserved across the maker's other open groups, including consumed amounts when available. Leave out groups listed in `cancellations`; this transaction cancels them. */
57
64
  readonly reservedLoanAssets?: bigint;
@@ -104,6 +104,10 @@ export interface VaultV1Actions {
104
104
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
105
105
  * // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
106
106
  * ```
107
+ * @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
108
+ * the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
109
+ * @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
110
+ * holds less than the required dead deposit.
107
111
  */
108
112
  deposit: (params: {
109
113
  readonly userAddress: Address;
@@ -457,6 +461,10 @@ export interface VaultV1Actions {
457
461
  * const tx = migration.buildTx(signatures);
458
462
  * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
459
463
  * ```
464
+ * @throws {MissingDeadSharesDataError} when `targetVault` lacks the dead-share, cap or adapter data
465
+ * the dead-deposit check needs. The source Vault V1 is not checked.
466
+ * @throws {InsufficientDeadSharesError} when `targetVault`, or a market or vault it can allocate
467
+ * to, holds less than the required dead deposit.
460
468
  */
461
469
  migrateToV2: (params: {
462
470
  readonly userAddress: Address;
@@ -9,6 +9,7 @@ const actions_1 = require("viem/actions");
9
9
  const common_js_1 = require("../../actions/bundles/common.js");
10
10
  const index_js_1 = require("../../actions/index.js");
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
+ const deadShares_js_1 = require("../../helpers/deadShares.js");
12
13
  const index_js_2 = require("../../helpers/index.js");
13
14
  const validate_js_1 = require("../../helpers/validate.js");
14
15
  const index_js_3 = require("../../types/index.js");
@@ -78,6 +79,8 @@ class MorphoVaultV1 {
78
79
  // The native path must target the chain's registered wrapped-native asset.
79
80
  (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
80
81
  }
82
+ // Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
83
+ (0, deadShares_js_1.validateVaultV1DeadShares)(vaultData);
81
84
  const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
82
85
  const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
83
86
  vaultData,
@@ -472,6 +475,8 @@ class MorphoVaultV1 {
472
475
  referralFeePct: params.referralFeePct,
473
476
  referralFeeRecipient: params.referralFeeRecipient,
474
477
  });
478
+ // Only the destination receives a deposit; the source vault is an exit.
479
+ (0, deadShares_js_1.validateVaultV2DeadShares)(params.targetVault);
475
480
  // V1 redeem accrues market interest and performance fees before converting shares.
476
481
  const grossAssets = assets ??
477
482
  params.sourceVault
@@ -1,4 +1,4 @@
1
- import { type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
1
+ import { type AccrualVaultV2, MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
@@ -69,9 +69,8 @@ export interface VaultV2Actions {
69
69
  * owner is consumed and none was passed explicitly.
70
70
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
71
71
  * explicit Permit2 nonce is consumed.
72
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, when the vault's
73
- * liquidity adapter is a Midnight adapter (it cannot receive vault allocations, so no deposit
74
- * fits and `max` is `0n`), or from `getRequirements()` when the Permit2 nonce exceeds uint256.
72
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
73
+ * `getRequirements()` when the Permit2 nonce exceeds uint256.
75
74
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
76
75
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
77
76
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -111,6 +110,10 @@ export interface VaultV2Actions {
111
110
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
112
111
  * // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
113
112
  * ```
113
+ * @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
114
+ * the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
115
+ * @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
116
+ * holds less than the required dead deposit.
114
117
  */
115
118
  deposit: (params: {
116
119
  readonly userAddress: Address;
@@ -153,9 +156,7 @@ export interface VaultV2Actions {
153
156
  * @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
154
157
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
155
158
  * at any `getRequirements()` call.
156
- * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation,
157
- * or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
158
- * idle assets.
159
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
159
160
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
160
161
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
161
162
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
@@ -221,24 +222,7 @@ export interface VaultV2Actions {
221
222
  * @throws {NonPositiveInputError} when `shares` is not positive.
222
223
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
223
224
  * requirement resolution.
224
- * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256, or from
225
- * `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
226
- * are worth more than the vault's idle assets.
227
- * @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
228
- * @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
229
- * configured factory.
230
- * @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
231
- * adapters uses an unsupported adapter class.
232
- * @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
233
- * is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
234
- * unsupported IRM.
235
- * @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
236
- * adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
237
- * allocation data.
238
- * @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
239
- * adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
240
- * @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
241
- * liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
225
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
242
226
  * @throws {NegativeInputError} when `referralFeePct` is negative.
243
227
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
244
228
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
@@ -246,7 +230,7 @@ export interface VaultV2Actions {
246
230
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
247
231
  * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
248
232
  * contract has no code at its registered address.
249
- * @throws {viem.BaseError} from `getRequirements()` when a vault-state, allowance, nonce, `eth_chainId`, or
233
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
250
234
  * `eth_getCode` read fails.
251
235
  * @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
252
236
  * `getData()` has unusable decimals.
@@ -324,11 +308,9 @@ export interface VaultV2Actions {
324
308
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
325
309
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
326
310
  * requirement resolution.
327
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter, including
328
- * a vault that mixes Blue and Midnight adapters.
311
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
329
312
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
330
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
331
- * including a Midnight adapter.
313
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
332
314
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
333
315
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
334
316
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -453,11 +435,9 @@ export interface VaultV2Actions {
453
435
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
454
436
  * requirement resolution.
455
437
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
456
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter,
457
- * including a vault that mixes Blue and Midnight adapters.
438
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
458
439
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
459
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
460
- * including a Midnight adapter.
440
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
461
441
  * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
462
442
  * another adapter.
463
443
  * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
@@ -528,6 +508,8 @@ export interface VaultV2Actions {
528
508
  * This is the share-based counterpart to forceWithdraw, useful for maximum withdrawal scenarios
529
509
  * where specifying an exact asset amount is impractical.
530
510
  *
511
+ * Inputs are copied when the handle is created, so later changes to them are not encoded.
512
+ *
531
513
  * The total assets passed to forceDeallocate calls must be greater than or equal to the
532
514
  * asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
533
515
  * amounts to account for share-price drift between submission and execution.
@@ -9,6 +9,7 @@ const actions_1 = require("viem/actions");
9
9
  const common_js_1 = require("../../actions/bundles/common.js");
10
10
  const index_js_1 = require("../../actions/index.js");
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
+ const deadShares_js_1 = require("../../helpers/deadShares.js");
12
13
  const index_js_2 = require("../../helpers/index.js");
13
14
  const validate_js_1 = require("../../helpers/validate.js");
14
15
  const index_js_3 = require("../../types/index.js");
@@ -18,11 +19,6 @@ const index_js_4 = require("../requirements/index.js");
18
19
  // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
19
20
  // accrual model stays well-defined inside it.
20
21
  const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
21
- /**
22
- * Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
23
- * vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
24
- */
25
- const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
26
22
  /** Binds a viem client to a Vault V2 vault's action builders. */
27
23
  class MorphoVaultV2 {
28
24
  client;
@@ -86,13 +82,8 @@ class MorphoVaultV2 {
86
82
  // The native path must target the chain's registered wrapped-native asset.
87
83
  (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
88
84
  }
89
- if (isMidnightLiquidityAdapter(vaultData)) {
90
- throw new index_js_3.InputExceedsMaxError({
91
- field: funding.value > 0n ? "nativeAmount" : "amount",
92
- value: funding.assets,
93
- max: 0n,
94
- });
95
- }
85
+ // Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
86
+ (0, deadShares_js_1.validateVaultV2DeadShares)(vaultData);
96
87
  const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
97
88
  const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
98
89
  vaultData,
@@ -176,14 +167,6 @@ class MorphoVaultV2 {
176
167
  throw new index_js_3.NonPositiveInputError("amount", amount);
177
168
  // Reject values outside the ABI range before resolving any requirements.
178
169
  (0, validate_js_1.validateUint256Field)("amount", amount);
179
- if (isMidnightLiquidityAdapter(vaultData) &&
180
- amount > vaultData.assetBalance) {
181
- throw new index_js_3.InputExceedsMaxError({
182
- field: "amount",
183
- value: amount,
184
- max: vaultData.assetBalance,
185
- });
186
- }
187
170
  const createdAt = morpho_ts_1.Time.timestamp();
188
171
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
189
172
  if (deadline <= createdAt)
@@ -264,20 +247,8 @@ class MorphoVaultV2 {
264
247
  if (deadline <= now)
265
248
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
266
249
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
267
- const vaultData = await this.getData();
268
- if (isMidnightLiquidityAdapter(vaultData)) {
269
- // Onchain redeem accrues interest before converting shares to assets.
270
- const { vault: accrued } = vaultData.accrueInterest(now);
271
- if (accrued.toAssets(shares) > accrued.assetBalance) {
272
- throw new index_js_3.InputExceedsMaxError({
273
- field: "shares",
274
- value: shares,
275
- max: accrued.toShares(accrued.assetBalance),
276
- });
277
- }
278
- }
279
250
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
280
- vaultData,
251
+ vaultData: await this.getData(),
281
252
  version: "vaultV2",
282
253
  owner: userAddress,
283
254
  chainId: this.chainId,
@@ -729,15 +700,18 @@ class MorphoVaultV2 {
729
700
  }
730
701
  forceRedeem({ deallocations, redeem, userAddress, }) {
731
702
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
703
+ const shares = redeem.shares;
704
+ const deallocationsSnapshot = deallocations.map(({ adapter, marketParams, amount }) => ({
705
+ adapter,
706
+ amount,
707
+ ...(marketParams && { marketParams: new blue_sdk_1.MarketParams(marketParams) }),
708
+ }));
732
709
  return {
733
710
  buildTx: () => (0, index_js_1.vaultV2ForceRedeem)({
734
711
  vault: { address: this.vault },
735
712
  args: {
736
- deallocations,
737
- redeem: {
738
- shares: redeem.shares,
739
- recipient: userAddress,
740
- },
713
+ deallocations: deallocationsSnapshot,
714
+ redeem: { shares, recipient: userAddress },
741
715
  onBehalf: userAddress,
742
716
  },
743
717
  metadata: this.client.options.metadata,
@@ -1,4 +1,4 @@
1
- import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
1
+ import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type BigIntish, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
2
2
  import { type Address, type Hash } from "viem";
3
3
  import type { VaultV2BluePublicAllocatorOptions, VaultV2BlueReallocation } from "../types/index.js";
4
4
  type ReadonlyMarketSnapshot = Readonly<Market>;
@@ -19,6 +19,23 @@ type ReadonlyVaultSnapshot = Readonly<Omit<AccrualVaultV2, "adapters" | "liquidi
19
19
  export interface InputVaultV2BlueReallocationData {
20
20
  /** Chain id associated with the fetched state. */
21
21
  readonly chainId: number;
22
+ /**
23
+ * Timestamp of the block the state was fetched at. When present, this is the
24
+ * default planning timestamp when `options.timestamp` is omitted, never
25
+ * earlier than the latest market/vault `lastUpdate`; when absent, planning
26
+ * defaults to the latest market/vault `lastUpdate`.
27
+ */
28
+ readonly timestamp?: BigIntish;
29
+ /**
30
+ * Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
31
+ * Explicit balances increase with idle-sourced reallocations in returned
32
+ * post-states. Sizing has zero margin over the snapshot balance, so activity
33
+ * on other Blue markets with the same loan token can make a plan revert;
34
+ * refetch close to submission. A missing token uses summed non-negative
35
+ * snapshot-market supply-minus-borrow only to size plans; balance-based
36
+ * rejection requires an explicit balance.
37
+ */
38
+ readonly blueBalances?: Readonly<Record<Address, BigIntish | undefined>>;
22
39
  /** Markets indexed by market id. */
23
40
  readonly markets?: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
24
41
  /** Accrued Vault V2 entities indexed by vault address. */
@@ -39,9 +56,8 @@ export interface InputVaultV2BlueReallocationData {
39
56
  /**
40
57
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
41
58
  *
42
- * Constructor inputs are cloned, except Midnight adapter snapshots: those are
43
- * shared by reference and must be treated as read-only. Every simulated
44
- * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
59
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
60
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
45
61
  * denominator outside the durable snapshot while applying reallocations in
46
62
  * contract order. Penalty donations update simulated vault accounting but are
47
63
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -77,8 +93,22 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
77
93
  private readonly mutableVaults;
78
94
  /** Mutable allocation state used only by cloned simulation transitions. */
79
95
  private readonly mutableAllocations;
96
+ /** Mutable Blue token balances used only by cloned simulation transitions. */
97
+ private readonly mutableBlueBalances;
80
98
  /** Chain id associated with this snapshot. */
81
99
  readonly chainId: number;
100
+ /** Timestamp of the block the state was fetched at. */
101
+ readonly timestamp?: bigint;
102
+ /**
103
+ * Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
104
+ * Explicit balances increase with idle-sourced reallocations in returned
105
+ * post-states. Sizing has zero margin over the snapshot balance, so activity
106
+ * on other Blue markets with the same loan token can make a plan revert;
107
+ * refetch close to submission. A missing token uses summed non-negative
108
+ * snapshot-market supply-minus-borrow only to size plans; balance-based
109
+ * rejection requires an explicit balance.
110
+ */
111
+ readonly blueBalances: Readonly<Record<Address, bigint | undefined>>;
82
112
  /** Markets indexed by market id. */
83
113
  readonly markets: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
84
114
  /** Vault V2 entities indexed by address. */
@@ -101,8 +131,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
101
131
  /**
102
132
  * Clones the complete simulation snapshot.
103
133
  *
104
- * @returns A deep clone of this simulation state. Midnight adapter snapshots are
105
- * shared by reference and must be treated as read-only.
134
+ * @returns A deep clone of this simulation state.
106
135
  * @example
107
136
  * ```ts
108
137
  * import { markets } from "@morpho-org/morpho-test";
@@ -358,16 +387,40 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
358
387
  * Computes Vault V2 BluePublicAllocator calls available for a target market.
359
388
  *
360
389
  * Without `options.operation`, discovers every friendly call. With an
361
- * operation, targets the amount required by that borrow or loan-asset
362
- * withdrawal and falls back to 100% source utilization only when friendly
363
- * liquidity cannot cover the absolute shortfall. A shared relative-cap lower
364
- * bound may require one call to exceed the targeted amount. Friendly source
365
- * utilization defaults to 90% and is configurable through
366
- * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
367
- * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
368
- * considered. Market/vault state and the returned post-state stay at
369
- * `timestamp`; only target-market cap checks reserve interest the vault's
370
- * existing allocation would accrue through `timestamp + capAccrualBuffer`
390
+ * operation, penalty tiers are considered ascending, starting with free
391
+ * vaults. The free tier aims to bring the target market back to 90%
392
+ * utilization; positive tiers cover the remaining absolute shortfall or,
393
+ * when larger, Blue's loan-token balance deficit while the penalty is
394
+ * flash-loaned. Within each tier, source markets go to the
395
+ * friendly source utilization (90% by default) before 100%. Free capacity
396
+ * inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
397
+ * it instead. Discovery and liquidity getters still count every vault up to
398
+ * `options.maxPenalty`. A shared relative-cap lower bound may require one call
399
+ * to exceed the targeted amount. For `refinance`, compute the plan on the
400
+ * destination-market handle (for example,
401
+ * `client.morpho.blue(destination.marketParams, chainId)`), not the source
402
+ * handle. Pass the source position's `borrowAssets` accrued to
403
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
404
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
405
+ * The planner includes the referral fee and its allocator-leg penalties in
406
+ * destination debt, so penalized legs also cover their own penalty.
407
+ * Refinance never uses vaults with a 100% penalty.
408
+ * BlueBundlesV1 flash-loans the plan's penalty from Blue before executing
409
+ * reallocation legs. When an explicit `blueBalances` value is supplied, plans
410
+ * throw `InsufficientSharedLiquidityError` if Blue cannot fund that flash
411
+ * loan or a market-sourced leg's withdrawal before later idle legs arrive.
412
+ * Legs are not reordered. A missing balance falls back to summed snapshot-
413
+ * market liquidity only to size plans and may make them larger; it cannot
414
+ * cause rejection for Blue-balance constraints.
415
+ * Sizing has zero margin over the snapshot balance; activity on other Blue
416
+ * markets with the same loan token can make a plan revert. Refetch close to
417
+ * submission; there is no balance-buffer option.
418
+ * Friendly source utilization defaults to 90% and is configurable through
419
+ * `options.maxWithdrawalUtilization`. Market/vault state and the returned
420
+ * post-state stay at `timestamp`. An enabled operation that needs no
421
+ * reallocation still returns a clone accrued to `timestamp`. Only
422
+ * target-market cap checks reserve interest the vault's existing allocation
423
+ * would accrue through `timestamp + capAccrualBuffer`
371
424
  * (two hours by default; `0n` disables it). When an operation's plan would
372
425
  * come within `allocatorCapHeadroom` (1% of the cap by default) of a target
373
426
  * BluePublicAllocator cap, the plan is reduced to the larger of the
@@ -408,8 +461,9 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
408
461
  * every leg of a plan.
409
462
  * @returns Flat action-ready reallocations and their post-simulation state.
410
463
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
411
- * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
412
- * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
464
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
465
+ * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
466
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
413
467
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
414
468
  * @throws {UnknownReallocationMarketError} when a required market is absent.
415
469
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -417,7 +471,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
417
471
  * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
418
472
  * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
419
473
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
420
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall.
474
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund the penalty flash loan, an earlier market-sourced withdrawal, or the final operation transfer.
421
475
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
422
476
  * @example
423
477
  * ```ts
@@ -452,6 +506,10 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
452
506
  readonly operation?: {
453
507
  readonly type: "borrow" | "withdraw";
454
508
  readonly amount: bigint;
509
+ } | {
510
+ readonly type: "refinance";
511
+ readonly amount: bigint;
512
+ readonly referralFeePct?: bigint;
455
513
  };
456
514
  }): {
457
515
  readonly reallocations: readonly VaultV2BlueReallocation[];