@morpho-org/morpho-sdk 10.4.0 → 10.5.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 (193) hide show
  1. package/lib/cjs/actions/blue/common.js +12 -3
  2. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  3. package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
  4. package/lib/cjs/actions/midnight/takeLend.js +15 -9
  5. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  6. package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
  7. package/lib/cjs/constants.d.ts +1 -1
  8. package/lib/cjs/constants.js +3 -2
  9. package/lib/cjs/entities/midnight/midnight.d.ts +106 -103
  10. package/lib/cjs/entities/midnight/midnight.js +120 -101
  11. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
  12. package/lib/cjs/entities/vaultV2/vaultV2.js +0 -1
  13. package/lib/cjs/helpers/constant.d.ts +7 -0
  14. package/lib/cjs/helpers/constant.js +8 -1
  15. package/lib/cjs/helpers/index.d.ts +1 -1
  16. package/lib/cjs/helpers/index.js +2 -1
  17. package/lib/cjs/helpers/validate.d.ts +25 -1
  18. package/lib/cjs/helpers/validate.js +25 -1
  19. package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
  20. package/lib/cjs/transactionPlan/assemble.js +25 -0
  21. package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
  22. package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
  23. package/lib/cjs/transactionPlan/blue/repay.js +10 -24
  24. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
  25. package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
  26. package/lib/cjs/transactionPlan/blue/stored.js +87 -0
  27. package/lib/cjs/transactionPlan/blue/supply.js +7 -22
  28. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  29. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
  30. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
  31. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
  32. package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
  33. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  34. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
  35. package/lib/cjs/transactionPlan/deposit.js +4 -7
  36. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  37. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  38. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
  39. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
  40. package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
  41. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
  42. package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
  43. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  44. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  45. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  46. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  47. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  48. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
  49. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  50. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  51. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  52. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  53. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  54. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  55. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +6 -2
  56. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +10 -4
  57. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  58. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  59. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  60. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
  61. package/lib/cjs/transactionPlan/permit.d.ts +15 -2
  62. package/lib/cjs/transactionPlan/permit.js +26 -68
  63. package/lib/cjs/transactionPlan/plan.d.ts +51 -1
  64. package/lib/cjs/transactionPlan/plan.js +56 -13
  65. package/lib/cjs/transactionPlan/redeem.js +4 -7
  66. package/lib/cjs/transactionPlan/types.d.ts +4 -3
  67. package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
  68. package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
  69. package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
  70. package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
  71. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
  72. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
  73. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  74. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
  75. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  76. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
  77. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
  78. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  79. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
  80. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
  81. package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
  82. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  83. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
  84. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  85. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
  86. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  87. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
  88. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
  89. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
  90. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  91. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
  92. package/lib/cjs/transactionPlan/withdraw.js +4 -7
  93. package/lib/cjs/types/error.d.ts +27 -1
  94. package/lib/cjs/types/error.js +32 -3
  95. package/lib/cjs/version.d.ts +1 -1
  96. package/lib/cjs/version.js +1 -1
  97. package/lib/esm/actions/blue/common.js +13 -4
  98. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  99. package/lib/esm/actions/midnight/takeBorrow.js +14 -8
  100. package/lib/esm/actions/midnight/takeLend.js +15 -9
  101. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  102. package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
  103. package/lib/esm/constants.d.ts +1 -1
  104. package/lib/esm/constants.js +1 -1
  105. package/lib/esm/entities/midnight/midnight.d.ts +106 -103
  106. package/lib/esm/entities/midnight/midnight.js +120 -101
  107. package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
  108. package/lib/esm/entities/vaultV2/vaultV2.js +0 -1
  109. package/lib/esm/helpers/constant.d.ts +7 -0
  110. package/lib/esm/helpers/constant.js +7 -0
  111. package/lib/esm/helpers/index.d.ts +1 -1
  112. package/lib/esm/helpers/index.js +1 -1
  113. package/lib/esm/helpers/validate.d.ts +25 -1
  114. package/lib/esm/helpers/validate.js +25 -2
  115. package/lib/esm/transactionPlan/assemble.d.ts +24 -0
  116. package/lib/esm/transactionPlan/assemble.js +21 -0
  117. package/lib/esm/transactionPlan/blue/borrow.js +15 -65
  118. package/lib/esm/transactionPlan/blue/refinance.js +10 -12
  119. package/lib/esm/transactionPlan/blue/repay.js +11 -25
  120. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
  121. package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
  122. package/lib/esm/transactionPlan/blue/stored.js +80 -0
  123. package/lib/esm/transactionPlan/blue/supply.js +7 -22
  124. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  125. package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
  126. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
  127. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
  128. package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
  129. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  130. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
  131. package/lib/esm/transactionPlan/deposit.js +5 -8
  132. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  133. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  134. package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
  135. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
  136. package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
  137. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
  138. package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
  139. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  140. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  141. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  142. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  143. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  144. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
  145. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  146. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  147. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  148. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  149. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  150. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  151. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +6 -2
  152. package/lib/esm/transactionPlan/midnight/takeBorrow.js +11 -5
  153. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  154. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  155. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  156. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
  157. package/lib/esm/transactionPlan/permit.d.ts +15 -2
  158. package/lib/esm/transactionPlan/permit.js +25 -68
  159. package/lib/esm/transactionPlan/plan.d.ts +51 -1
  160. package/lib/esm/transactionPlan/plan.js +55 -13
  161. package/lib/esm/transactionPlan/redeem.js +5 -8
  162. package/lib/esm/transactionPlan/types.d.ts +4 -3
  163. package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
  164. package/lib/esm/transactionPlan/vaultBinding.js +65 -0
  165. package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
  166. package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
  167. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
  168. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
  169. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  170. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
  171. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  172. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
  173. package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
  174. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  175. package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
  176. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
  177. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
  178. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  179. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
  180. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  181. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
  182. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  183. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
  184. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
  185. package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
  186. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  187. package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
  188. package/lib/esm/transactionPlan/withdraw.js +5 -8
  189. package/lib/esm/types/error.d.ts +27 -1
  190. package/lib/esm/types/error.js +30 -2
  191. package/lib/esm/version.d.ts +1 -1
  192. package/lib/esm/version.js +1 -1
  193. package/package.json +3 -3
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prepareVaultV2Withdraw = prepareVaultV2Withdraw;
4
4
  exports.buildVaultV2Withdraw = buildVaultV2Withdraw;
5
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const common_js_1 = require("../../actions/bundles/common.js");
7
5
  const withdraw_js_1 = require("../../actions/vaultV2/withdraw.js");
8
6
  const permit_js_1 = require("../permit.js");
9
7
  const withdraw_js_2 = require("../withdraw.js");
@@ -26,7 +24,7 @@ const withdraw_js_2 = require("../withdraw.js");
26
24
  * @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
27
25
  * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
28
26
  * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
29
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
27
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
30
28
  * @returns A plan with the withdrawal step and any required share approval or signature request.
31
29
  * @throws {ZeroAccountError} when `account` is the zero address.
32
30
  * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
@@ -63,16 +61,7 @@ async function prepareVaultV2Withdraw(client, params) {
63
61
  /** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
64
62
  function buildVaultV2Withdraw(action, requests) {
65
63
  const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
66
- const signature = (0, permit_js_1.getVaultPermit)(requests, {
67
- id: action.signatureRequestIds.tokenPermit,
68
- asset: action.inputs.vault,
69
- owner: account,
70
- });
71
- const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
72
- spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
73
- amount: requiredShareAllowance,
74
- deadline: action.inputs.deadline,
75
- });
64
+ const permit = (0, permit_js_1.selectVaultPermit)(action, requests);
76
65
  return (0, withdraw_js_1.vaultV2Withdraw)({
77
66
  vault: { chainId, address: action.inputs.vault },
78
67
  args: {
@@ -8,6 +8,7 @@ const common_js_1 = require("../actions/bundles/common.js");
8
8
  const index_js_1 = require("../helpers/index.js");
9
9
  const validate_js_1 = require("../helpers/validate.js");
10
10
  const index_js_2 = require("../types/index.js");
11
+ const assemble_js_1 = require("./assemble.js");
11
12
  const intent_js_1 = require("./intent.js");
12
13
  const shareSpending_js_1 = require("./shareSpending.js");
13
14
  const validation_js_1 = require("./validation.js");
@@ -62,12 +63,8 @@ async function prepareVaultWithdraw(client, params) {
62
63
  supportSignature: intent.supportSignature,
63
64
  now,
64
65
  });
65
- return (0, morpho_ts_1.deepFreeze)(structuredClone({
66
- version: 2,
67
- account,
68
- chainId,
69
- expiresAt: intent.expiresAt,
70
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
66
+ return (0, assemble_js_1.freezePlan)({
67
+ ...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
71
68
  steps: [
72
69
  ...approvals,
73
70
  {
@@ -90,5 +87,5 @@ async function prepareVaultWithdraw(client, params) {
90
87
  },
91
88
  ],
92
89
  signatureRequests,
93
- }));
90
+ }, { detach: true });
94
91
  }
@@ -840,7 +840,8 @@ export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
840
840
  * ```
841
841
  */
842
842
  export declare class InvalidVaultV2BlueReallocationShapeError extends Error {
843
- constructor();
843
+ /** @param options - Optional underlying failure, kept as `cause`. */
844
+ constructor(options?: ErrorOptions);
844
845
  }
845
846
  /**
846
847
  * Thrown when a Blue Public Allocator reallocation contains a malformed vault
@@ -1327,6 +1328,31 @@ export declare class MidnightTakeDeadlineTooFarError extends Error {
1327
1328
  readonly maxDeadline: bigint;
1328
1329
  });
1329
1330
  }
1331
+ /**
1332
+ * Thrown when a Midnight borrow prepared at or before maturity could execute less than
1333
+ * `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` (2 hours) before it, when unpaid debt becomes liquidatable.
1334
+ * Credit covering the target at preparation does not exempt the borrow, because the sell is not
1335
+ * reduce-only; sell credit only inside the window with `takeWithdraw`.
1336
+ */
1337
+ export declare class MidnightBorrowTooCloseToMaturityError extends Error {
1338
+ /** Deadline supplied by the caller. */
1339
+ readonly deadline: bigint;
1340
+ /** Market maturity timestamp. */
1341
+ readonly maturity: bigint;
1342
+ /** Latest accepted deadline for this maturity. */
1343
+ readonly latestDeadline: bigint;
1344
+ /**
1345
+ * @param params - Supplied deadline, market maturity and latest accepted deadline.
1346
+ * @param params.deadline - Deadline supplied by the caller.
1347
+ * @param params.maturity - Market maturity timestamp.
1348
+ * @param params.latestDeadline - Latest accepted deadline for this maturity.
1349
+ */
1350
+ constructor(params: {
1351
+ readonly deadline: bigint;
1352
+ readonly maturity: bigint;
1353
+ readonly latestDeadline: bigint;
1354
+ });
1355
+ }
1330
1356
  /** Thrown when a Midnight maker offer targets a different chain than the action flow. */
1331
1357
  export declare class MidnightOfferMarketChainMismatchError extends Error {
1332
1358
  constructor(params: {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.UnsupportedMidnightAuthorizationTargetError = exports.UnsupportedErc20ApprovalSpenderError = exports.MissingClientPropertyError = exports.CryptoUnavailableError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.UnsupportedRequirementSignatureError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.MaxRepayAssetsBelowRepayAssetsError = exports.ReallocationsRequireBorrowError = exports.UnsupportedAuthorizationOperatorError = exports.ReallocationLoanTokenMismatchError = exports.SameVaultMigrationError = exports.AmountAndSharesExclusiveError = exports.MixedBundlesFundingError = exports.MidnightReferralFeePctExceededError = exports.ReferralFeePctExceededError = exports.ReferralFeeRecipientMissingError = exports.NativeFundingAmountMismatchError = exports.NoUnusedPermit2NonceError = exports.Permit2SignatureTransferNonceAlreadyUsedError = exports.BundlesRequirementSignatureMismatchError = exports.BundlesPermitMismatchError = exports.VaultIsBlueFeeRecipientError = exports.VaultMorphoMismatchError = exports.InsufficientBlueBalanceForInKindRedeemError = exports.InKindRedeemCoverageError = exports.InKindRedeemZeroDeallocationError = exports.VaultV2ForceWithdrawFeeSharesExceedBurnError = exports.VaultV2ForceWithdrawSharePriceBelowFloorError = exports.VaultV2ForceWithdrawZeroSharePriceError = exports.VaultV2ForceWithdrawZeroWithdrawalError = exports.VaultV2ForceWithdrawCoverageError = exports.VaultV2UndecodableLiquidityDataError = exports.VaultV2UnsupportedLiquidityAdapterError = exports.VaultV2UnsupportedExitAdapterError = exports.AdapterNotPartOfVaultError = exports.VaultV2SingleAdapterRequiredError = exports.ExpiredDeadlineError = exports.EmptyMarketParamsListError = exports.InputExceedsMaxError = exports.InvalidMidnightNativeAmountTypeError = exports.InvalidBigIntInputError = exports.NonPositiveInputError = exports.NegativeInputError = void 0;
4
4
  exports.MidnightZeroReceiverError = exports.MidnightRepayExceedsDebtError = exports.MidnightContinuousFeeAboveMaxError = exports.MidnightTakeTargetUnreachableError = exports.MidnightTakeableOffersNotFillableError = exports.UnboundedMidnightTakeInputError = exports.MidnightOfferSellerReceiverMismatchError = exports.MidnightOfferContinuousFeeCapError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferReduceOnlyError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.DuplicateMidnightGroupCancellationError = exports.DuplicateMidnightCollateralIndexError = exports.EmptyMidnightCollateralWithdrawalsError = exports.EmptyMidnightCollateralSuppliesError = exports.EmptyMidnightGroupCancellationsError = exports.ReallocationAdapterSupplySharesUnderflowError = exports.ReallocationAllocationUnderflowError = exports.UnknownReallocationAdapterError = exports.UnknownReallocationMarketPublicAllocatorConfigError = exports.UnknownReallocationActiveAdaptersError = exports.UnknownReallocationPublicAllocatorConfigError = exports.UnknownReallocationAllocationError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.RepaySharesExceedDebtError = exports.MalformedSignatureError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.MutuallyExclusiveRepayAmountsError = exports.InconsistentReallocationPenaltyError = exports.InvalidReallocationSourceTypeError = exports.InvalidReallocationAddressError = exports.InvalidVaultV2BlueReallocationShapeError = exports.ReallocationWithdrawalOnTargetMarketError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeAssetError = exports.VaultAddressMismatchError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositSpenderMismatchError = exports.DepositOwnerMismatchError = exports.DepositAssetMismatchError = void 0;
5
- exports.MidnightCalldataEncodingError = exports.MidnightZeroAccountError = exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.BlueBuyCallbackUnauthorizedError = exports.BlueBuyCallbackOwnerMismatchError = exports.NotBlueBuyCallbackError = exports.InsufficientBlueLiquidityError = exports.EmptyBlueSupplyPositionError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferZeroSellerReceiverError = exports.MidnightTakeableOfferMarketMismatchError = exports.MissingDeadSharesDataError = exports.InsufficientDeadSharesError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightTakeDeadlineTooFarError = exports.MidnightContractReceiverError = exports.MidnightZeroOnBehalfError = void 0;
5
+ exports.MidnightCalldataEncodingError = exports.MidnightZeroAccountError = exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.BlueBuyCallbackUnauthorizedError = exports.BlueBuyCallbackOwnerMismatchError = exports.NotBlueBuyCallbackError = exports.InsufficientBlueLiquidityError = exports.EmptyBlueSupplyPositionError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferZeroSellerReceiverError = exports.MidnightTakeableOfferMarketMismatchError = exports.MissingDeadSharesDataError = exports.InsufficientDeadSharesError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightBorrowTooCloseToMaturityError = exports.MidnightTakeDeadlineTooFarError = exports.MidnightContractReceiverError = exports.MidnightZeroOnBehalfError = void 0;
6
6
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
7
  const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
8
8
  const constant_js_1 = require("../helpers/constant.js");
@@ -1113,8 +1113,9 @@ exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTarg
1113
1113
  * ```
1114
1114
  */
1115
1115
  class InvalidVaultV2BlueReallocationShapeError extends Error {
1116
- constructor() {
1117
- super("Reallocation entry is not a valid Vault V2 reallocation. High-level Blue writes accept only VaultV2BlueReallocation entries (e.g. from getVaultV2BlueReallocations()). Use morpho-sdk v5 if Vault V1 reallocations are required.");
1116
+ /** @param options - Optional underlying failure, kept as `cause`. */
1117
+ constructor(options) {
1118
+ super("Reallocation entry is not a valid Vault V2 reallocation. High-level Blue writes accept only VaultV2BlueReallocation entries (e.g. from getVaultV2BlueReallocations()). Use morpho-sdk v5 if Vault V1 reallocations are required.", options);
1118
1119
  this.name = "InvalidVaultV2BlueReallocationShapeError";
1119
1120
  }
1120
1121
  }
@@ -1737,6 +1738,34 @@ class MidnightTakeDeadlineTooFarError extends Error {
1737
1738
  }
1738
1739
  }
1739
1740
  exports.MidnightTakeDeadlineTooFarError = MidnightTakeDeadlineTooFarError;
1741
+ /**
1742
+ * Thrown when a Midnight borrow prepared at or before maturity could execute less than
1743
+ * `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` (2 hours) before it, when unpaid debt becomes liquidatable.
1744
+ * Credit covering the target at preparation does not exempt the borrow, because the sell is not
1745
+ * reduce-only; sell credit only inside the window with `takeWithdraw`.
1746
+ */
1747
+ class MidnightBorrowTooCloseToMaturityError extends Error {
1748
+ /** Deadline supplied by the caller. */
1749
+ deadline;
1750
+ /** Market maturity timestamp. */
1751
+ maturity;
1752
+ /** Latest accepted deadline for this maturity. */
1753
+ latestDeadline;
1754
+ /**
1755
+ * @param params - Supplied deadline, market maturity and latest accepted deadline.
1756
+ * @param params.deadline - Deadline supplied by the caller.
1757
+ * @param params.maturity - Market maturity timestamp.
1758
+ * @param params.latestDeadline - Latest accepted deadline for this maturity.
1759
+ */
1760
+ constructor(params) {
1761
+ super(`Midnight borrow deadline "${params.deadline}" is less than two hours before market maturity "${params.maturity}", when unpaid debt becomes liquidatable. Borrow on a later maturity, sell credit only with takeWithdraw, or, while "${params.latestDeadline}" is still in the future, use a deadline no later than it.`);
1762
+ this.deadline = params.deadline;
1763
+ this.maturity = params.maturity;
1764
+ this.latestDeadline = params.latestDeadline;
1765
+ this.name = "MidnightBorrowTooCloseToMaturityError";
1766
+ }
1767
+ }
1768
+ exports.MidnightBorrowTooCloseToMaturityError = MidnightBorrowTooCloseToMaturityError;
1740
1769
  /** Thrown when a Midnight maker offer targets a different chain than the action flow. */
1741
1770
  class MidnightOfferMarketChainMismatchError extends Error {
1742
1771
  constructor(params) {
@@ -1,2 +1,2 @@
1
1
  /** Installed @morpho-org/morpho-sdk package version. */
2
- export declare const version = "10.4.0";
2
+ export declare const version = "10.5.0";
@@ -3,4 +3,4 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.version = void 0;
5
5
  /** Installed @morpho-org/morpho-sdk package version. */
6
- exports.version = "10.4.0";
6
+ exports.version = "10.5.0";
@@ -1,4 +1,4 @@
1
- import { MarketParams, MathLib, VaultV2BluePublicAllocatorConfigUtils, } from "@morpho-org/blue-sdk";
1
+ import { MarketUtils, MathLib, VaultV2BluePublicAllocatorConfigUtils, } from "@morpho-org/blue-sdk";
2
2
  import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
3
  import { isAddressEqual, zeroAddress, zeroHash, } from "viem";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
@@ -103,9 +103,18 @@ export const parseBlueAllocations = (reallocations, { marketParams: targetMarket
103
103
  targetMarketId: targetMarketParams.id,
104
104
  maxPenalty,
105
105
  });
106
- // Hoisted out of the map: idle sources all reference the same synthetic idle market, whose
107
- // construction eagerly hashes the market id — computing it once per call instead of per entry.
108
- const idleMarketParams = parseBlueMarket(MarketParams.idle(targetMarketParams.loanToken));
106
+ const idle = {
107
+ loanToken: targetMarketParams.loanToken,
108
+ collateralToken: zeroAddress,
109
+ oracle: zeroAddress,
110
+ irm: zeroAddress,
111
+ lltv: 0n,
112
+ };
113
+ const idleMarketParams = parseBlueMarket({
114
+ ...idle,
115
+ id: MarketUtils.getMarketId(idle),
116
+ liquidationIncentiveFactor: MarketUtils.getLiquidationIncentiveFactor(idle),
117
+ });
109
118
  const publicAllocations = snapshots.map((reallocation) => {
110
119
  if (reallocation.from.type === "market" &&
111
120
  !isAddressEqual(reallocation.from.marketParams.loanToken, targetMarketParams.loanToken)) {
@@ -97,31 +97,31 @@ export const midnightSupplyCollateralTakeBorrow = (params) => encodeMidnightSupp
97
97
  const parsedSupplyCollateralTakeBorrow = Symbol();
98
98
  /** Parses the static SupplyCollateralTakeBorrow constraints in the standalone builder's existing order. @internal */
99
99
  export const parseMidnightSupplyCollateralTakeBorrow = (params) => {
100
+ const { market, target, takeableOffers } = params;
100
101
  // Reject markets from another chain deployment before checking offers against them.
101
- validateMidnightMarket({ market: params.market, chainId: params.chainId });
102
+ validateMidnightMarket({ market, chainId: params.chainId });
102
103
  if (params.collateralSupplies.length === 0) {
103
104
  throw new EmptyMidnightCollateralSuppliesError();
104
105
  }
105
106
  // Validation only; retain main's canonical per-entry and per-index collateral checks.
106
107
  validateMidnightCollateralSupplies({
107
- market: params.market,
108
+ market,
108
109
  field: "collateralSupplies",
109
110
  supplies: params.collateralSupplies,
110
111
  });
111
112
  const marketId = validateTakeableOffers({
112
- market: params.market,
113
- takeableOffers: params.takeableOffers,
113
+ market,
114
+ takeableOffers,
114
115
  expectedBuy: true,
115
116
  });
116
- validateMidnightTakeableOfferBounds(params.takeableOffers);
117
+ validateMidnightTakeableOfferBounds(takeableOffers);
117
118
  // Rejects receivers that would strand the borrowed assets in a contract.
118
119
  validateMidnightReceiver({
119
120
  chainId: params.chainId,
120
- market: params.market,
121
+ market,
121
122
  field: "receiver",
122
123
  receiver: params.receiver,
123
124
  });
124
- const { target } = params;
125
125
  switch (target.type) {
126
126
  case "assets": {
127
127
  // Validation only; rejects non-positive amounts.
@@ -161,7 +161,7 @@ export const parseMidnightSupplyCollateralTakeBorrow = (params) => {
161
161
  // Rejects fee recipients that would strand the fee in a contract.
162
162
  validateMidnightReceiver({
163
163
  chainId: params.chainId,
164
- market: params.market,
164
+ market,
165
165
  field: "referralFeeRecipient",
166
166
  receiver: referralFeeRecipient,
167
167
  });
@@ -169,15 +169,20 @@ export const parseMidnightSupplyCollateralTakeBorrow = (params) => {
169
169
  const collateralSupplies = params.collateralSupplies.map(({ collateralIndex, assets }) => ({
170
170
  collateralIndex,
171
171
  assets,
172
- token: MarketUtils.getCollateralByIndex(params.market, collateralIndex)
173
- .token,
172
+ token: MarketUtils.getCollateralByIndex(market, collateralIndex).token,
174
173
  }));
175
174
  const nativeFunding = parseMidnightNativeFunding({
176
175
  chainId: params.chainId,
177
176
  nativeAmount: params.nativeAmount,
178
177
  pulls: collateralSupplies,
179
178
  });
180
- const snapshot = snapshotMidnightTakeParams({ ...params, direction: "sell" });
179
+ const snapshot = snapshotMidnightTakeParams({
180
+ direction: "sell",
181
+ market,
182
+ target,
183
+ takeableOffers,
184
+ metadata: params.metadata,
185
+ });
181
186
  return deepFreeze({
182
187
  ...snapshot,
183
188
  chainId: params.chainId,
@@ -81,22 +81,22 @@ export const midnightTakeBorrow = (params) => encodeMidnightTakeBorrow(parseMidn
81
81
  const parsedTakeBorrow = Symbol();
82
82
  /** Parses the static TakeBorrow constraints in the standalone builder's existing order. @internal */
83
83
  export const parseMidnightTakeBorrow = (params) => {
84
+ const { market, target, takeableOffers } = params;
84
85
  // Reject markets from another chain deployment before checking offers against them.
85
- validateMidnightMarket({ market: params.market, chainId: params.chainId });
86
+ validateMidnightMarket({ market, chainId: params.chainId });
86
87
  const marketId = validateTakeableOffers({
87
- market: params.market,
88
- takeableOffers: params.takeableOffers,
88
+ market,
89
+ takeableOffers,
89
90
  expectedBuy: true,
90
91
  });
91
- validateMidnightTakeableOfferBounds(params.takeableOffers);
92
+ validateMidnightTakeableOfferBounds(takeableOffers);
92
93
  // Rejects receivers that would strand the borrowed assets in a contract.
93
94
  validateMidnightReceiver({
94
95
  chainId: params.chainId,
95
- market: params.market,
96
+ market,
96
97
  field: "receiver",
97
98
  receiver: params.receiver,
98
99
  });
99
- const { target } = params;
100
100
  switch (target.type) {
101
101
  case "assets": {
102
102
  // Validation only; rejects non-positive amounts.
@@ -136,12 +136,18 @@ export const parseMidnightTakeBorrow = (params) => {
136
136
  // Rejects fee recipients that would strand the fee in a contract.
137
137
  validateMidnightReceiver({
138
138
  chainId: params.chainId,
139
- market: params.market,
139
+ market,
140
140
  field: "referralFeeRecipient",
141
141
  receiver: referralFeeRecipient,
142
142
  });
143
143
  }
144
- const snapshot = snapshotMidnightTakeParams({ ...params, direction: "sell" });
144
+ const snapshot = snapshotMidnightTakeParams({
145
+ direction: "sell",
146
+ market,
147
+ target,
148
+ takeableOffers,
149
+ metadata: params.metadata,
150
+ });
145
151
  return deepFreeze({
146
152
  ...snapshot,
147
153
  chainId: params.chainId,
@@ -81,15 +81,15 @@ export const midnightTakeLend = (params) => encodeMidnightTakeLend(parseMidnight
81
81
  const parsedTakeLend = Symbol();
82
82
  /** Parses the static TakeLend constraints in the standalone builder's existing order. @internal */
83
83
  export const parseMidnightTakeLend = (params) => {
84
+ const { market, target, takeableOffers } = params;
84
85
  // Reject markets from another chain deployment before checking offers against them.
85
- validateMidnightMarket({ market: params.market, chainId: params.chainId });
86
+ validateMidnightMarket({ market, chainId: params.chainId });
86
87
  const marketId = validateTakeableOffers({
87
- market: params.market,
88
- takeableOffers: params.takeableOffers,
88
+ market,
89
+ takeableOffers,
89
90
  expectedBuy: false,
90
91
  });
91
- validateMidnightTakeableOfferBounds(params.takeableOffers);
92
- const { target } = params;
92
+ validateMidnightTakeableOfferBounds(takeableOffers);
93
93
  switch (target.type) {
94
94
  case "assets": {
95
95
  // Validation only; rejects non-positive amounts.
@@ -129,23 +129,29 @@ export const parseMidnightTakeLend = (params) => {
129
129
  // Rejects fee recipients that would strand the fee in a contract.
130
130
  validateMidnightReceiver({
131
131
  chainId: params.chainId,
132
- market: params.market,
132
+ market,
133
133
  field: "referralFeeRecipient",
134
134
  receiver: referralFeeRecipient,
135
135
  });
136
136
  }
137
- const market = MarketUtils.toStruct(params.market);
137
+ const marketStruct = MarketUtils.toStruct(market);
138
138
  const nativeFunding = parseMidnightNativeFunding({
139
139
  chainId: params.chainId,
140
140
  nativeAmount: params.nativeAmount,
141
141
  pulls: [
142
142
  {
143
- token: market.loanToken,
143
+ token: marketStruct.loanToken,
144
144
  assets: target.type === "assets" ? target.assets : target.maxBuyerAssets,
145
145
  },
146
146
  ],
147
147
  });
148
- const snapshot = snapshotMidnightTakeParams({ ...params, direction: "buy" });
148
+ const snapshot = snapshotMidnightTakeParams({
149
+ direction: "buy",
150
+ market,
151
+ target,
152
+ takeableOffers,
153
+ metadata: params.metadata,
154
+ });
149
155
  return deepFreeze({
150
156
  ...snapshot,
151
157
  chainId: params.chainId,
@@ -100,11 +100,12 @@ export const midnightTakeRepayWithdrawCollateral = (params) => encodeMidnightTak
100
100
  const parsedTakeRepayWithdrawCollateral = Symbol();
101
101
  /** Parses the static TakeRepayWithdrawCollateral constraints in the standalone builder's existing order. @internal */
102
102
  export const parseMidnightTakeRepayWithdrawCollateral = (params) => {
103
- if (params.target.type === "assets" && params.target.assets <= 0n) {
104
- throw new NonPositiveInputError("target.assets", params.target.assets);
103
+ const { market, target, takeableOffers } = params;
104
+ if (target.type === "assets" && target.assets <= 0n) {
105
+ throw new NonPositiveInputError("target.assets", target.assets);
105
106
  }
106
107
  // Reject markets from another chain deployment before checking offers against them.
107
- validateMidnightMarket({ market: params.market, chainId: params.chainId });
108
+ validateMidnightMarket({ market, chainId: params.chainId });
108
109
  for (const [index, { collateralIndex, assets },] of params.collateralWithdrawals.entries()) {
109
110
  // Validation only; rejects non-positive amounts.
110
111
  validatePositiveInput(`collateralWithdrawals[${index}].assets`, assets);
@@ -112,25 +113,24 @@ export const parseMidnightTakeRepayWithdrawCollateral = (params) => {
112
113
  validateMidnightUint128Field(`collateralWithdrawals[${index}].assets`, assets);
113
114
  }
114
115
  // Throws UnknownCollateralIndexError when the index is not configured on the market.
115
- MarketUtils.getCollateralByIndex(params.market, collateralIndex);
116
+ MarketUtils.getCollateralByIndex(market, collateralIndex);
116
117
  }
117
118
  validateMidnightAddress("collateralReceiver", params.collateralReceiver);
118
119
  if (params.collateralWithdrawals.length > 0) {
119
120
  // Rejects receivers that would strand the withdrawn collateral in a contract.
120
121
  validateMidnightReceiver({
121
122
  chainId: params.chainId,
122
- market: params.market,
123
+ market,
123
124
  field: "collateralReceiver",
124
125
  receiver: params.collateralReceiver,
125
126
  });
126
127
  }
127
128
  const marketId = validateTakeableOffers({
128
- market: params.market,
129
- takeableOffers: params.takeableOffers,
129
+ market,
130
+ takeableOffers,
130
131
  expectedBuy: false,
131
132
  });
132
- validateMidnightTakeableOfferBounds(params.takeableOffers);
133
- const { target } = params;
133
+ validateMidnightTakeableOfferBounds(takeableOffers);
134
134
  switch (target.type) {
135
135
  case "assets": {
136
136
  // Validation only; rejects non-positive amounts.
@@ -164,23 +164,29 @@ export const parseMidnightTakeRepayWithdrawCollateral = (params) => {
164
164
  // Rejects fee recipients that would strand the fee in a contract.
165
165
  validateMidnightReceiver({
166
166
  chainId: params.chainId,
167
- market: params.market,
167
+ market,
168
168
  field: "referralFeeRecipient",
169
169
  receiver: referralFeeRecipient,
170
170
  });
171
171
  }
172
- const market = MarketUtils.toStruct(params.market);
172
+ const marketStruct = MarketUtils.toStruct(market);
173
173
  const nativeFunding = parseMidnightNativeFunding({
174
174
  chainId: params.chainId,
175
175
  nativeAmount: params.nativeAmount,
176
176
  pulls: [
177
177
  {
178
- token: market.loanToken,
178
+ token: marketStruct.loanToken,
179
179
  assets: target.type === "assets" ? target.assets : target.maxBuyerAssets,
180
180
  },
181
181
  ],
182
182
  });
183
- const snapshot = snapshotMidnightTakeParams({ ...params, direction: "buy" });
183
+ const snapshot = snapshotMidnightTakeParams({
184
+ direction: "buy",
185
+ market,
186
+ target,
187
+ takeableOffers,
188
+ metadata: params.metadata,
189
+ });
184
190
  return deepFreeze({
185
191
  ...snapshot,
186
192
  chainId: params.chainId,
@@ -77,23 +77,23 @@ export const midnightTakeWithdraw = (params) => encodeMidnightTakeWithdraw(parse
77
77
  const parsedTakeWithdraw = Symbol();
78
78
  /** Parses the static TakeWithdraw constraints in the standalone builder's existing order. @internal */
79
79
  export const parseMidnightTakeWithdraw = (params) => {
80
+ const { market, target, takeableOffers } = params;
80
81
  // Reject markets from another chain deployment before checking offers against them.
81
- validateMidnightMarket({ market: params.market, chainId: params.chainId });
82
+ validateMidnightMarket({ market, chainId: params.chainId });
82
83
  const marketId = validateTakeableOffers({
83
- market: params.market,
84
- takeableOffers: params.takeableOffers,
84
+ market,
85
+ takeableOffers,
85
86
  expectedBuy: true,
86
87
  });
87
88
  validateMidnightAddress("receiver", params.receiver);
88
- validateMidnightTakeableOfferBounds(params.takeableOffers);
89
+ validateMidnightTakeableOfferBounds(takeableOffers);
89
90
  // Rejects receivers that would strand the withdrawn assets in a contract.
90
91
  validateMidnightReceiver({
91
92
  chainId: params.chainId,
92
- market: params.market,
93
+ market,
93
94
  field: "receiver",
94
95
  receiver: params.receiver,
95
96
  });
96
- const { target } = params;
97
97
  switch (target.type) {
98
98
  case "assets": {
99
99
  // Validation only; preserve main's positive-target and finite-cap order.
@@ -131,12 +131,18 @@ export const parseMidnightTakeWithdraw = (params) => {
131
131
  // Rejects fee recipients that would strand the fee in a contract.
132
132
  validateMidnightReceiver({
133
133
  chainId: params.chainId,
134
- market: params.market,
134
+ market,
135
135
  field: "referralFeeRecipient",
136
136
  receiver: referralFeeRecipient,
137
137
  });
138
138
  }
139
- const snapshot = snapshotMidnightTakeParams({ ...params, direction: "sell" });
139
+ const snapshot = snapshotMidnightTakeParams({
140
+ direction: "sell",
141
+ market,
142
+ target,
143
+ takeableOffers,
144
+ metadata: params.metadata,
145
+ });
140
146
  return deepFreeze({
141
147
  ...snapshot,
142
148
  chainId: params.chainId,
@@ -1,4 +1,4 @@
1
1
  export { DEAD_ADDRESS, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
2
2
  export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
3
3
  export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
4
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";
4
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";
@@ -1,4 +1,4 @@
1
1
  export { DEAD_ADDRESS, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
2
2
  export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
3
3
  export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
4
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";
4
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./helpers/constant.js";