@morpho-org/morpho-sdk 10.3.1 → 10.4.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 (188) hide show
  1. package/README.md +169 -5
  2. package/lib/cjs/actions/midnight/redeem.d.ts +20 -3
  3. package/lib/cjs/actions/midnight/redeem.js +58 -1
  4. package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
  5. package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +41 -0
  6. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -2
  7. package/lib/cjs/actions/midnight/withdrawCollateral.js +26 -1
  8. package/lib/cjs/helpers/callback.d.ts +3 -2
  9. package/lib/cjs/helpers/callback.js +4 -20
  10. package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
  11. package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.js +30 -0
  12. package/lib/cjs/helpers/parseMidnightMaker.d.ts +21 -0
  13. package/lib/cjs/helpers/parseMidnightMaker.js +41 -1
  14. package/lib/cjs/helpers/validate.d.ts +49 -1
  15. package/lib/cjs/helpers/validate.js +87 -1
  16. package/lib/cjs/helpers/validateMidnightPublication.d.ts +10 -0
  17. package/lib/cjs/helpers/validateMidnightPublication.js +18 -1
  18. package/lib/cjs/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
  19. package/lib/cjs/helpers/validateMidnightTakeableOfferFields.js +85 -0
  20. package/lib/cjs/index.d.ts +2 -2
  21. package/lib/cjs/index.js +23 -1
  22. package/lib/cjs/midnight/utils.d.ts +1 -1
  23. package/lib/cjs/midnight/utils.js +2 -1
  24. package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
  25. package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
  26. package/lib/cjs/transactionPlan/error.d.ts +27 -0
  27. package/lib/cjs/transactionPlan/error.js +30 -1
  28. package/lib/cjs/transactionPlan/index.d.ts +40 -1
  29. package/lib/cjs/transactionPlan/index.js +46 -5
  30. package/lib/cjs/transactionPlan/midnight/authorization.d.ts +15 -0
  31. package/lib/cjs/transactionPlan/midnight/authorization.js +45 -0
  32. package/lib/cjs/transactionPlan/midnight/cancelOffers.d.ts +80 -0
  33. package/lib/cjs/transactionPlan/midnight/cancelOffers.js +125 -0
  34. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +104 -0
  35. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +126 -0
  36. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +140 -0
  37. package/lib/cjs/transactionPlan/midnight/makeLend.js +176 -0
  38. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +118 -0
  39. package/lib/cjs/transactionPlan/midnight/makeRepay.js +118 -0
  40. package/lib/cjs/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
  41. package/lib/cjs/transactionPlan/midnight/makeWithdraw.js +126 -0
  42. package/lib/cjs/transactionPlan/midnight/makerPublication.d.ts +55 -0
  43. package/lib/cjs/transactionPlan/midnight/makerPublication.js +315 -0
  44. package/lib/cjs/transactionPlan/midnight/market.d.ts +49 -0
  45. package/lib/cjs/transactionPlan/midnight/market.js +120 -0
  46. package/lib/cjs/transactionPlan/midnight/prepare.d.ts +244 -0
  47. package/lib/cjs/transactionPlan/midnight/prepare.js +547 -0
  48. package/lib/cjs/transactionPlan/midnight/publicationState.d.ts +24 -0
  49. package/lib/cjs/transactionPlan/midnight/publicationState.js +50 -0
  50. package/lib/cjs/transactionPlan/midnight/redeem.d.ts +102 -0
  51. package/lib/cjs/transactionPlan/midnight/redeem.js +170 -0
  52. package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
  53. package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.js +51 -0
  54. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
  55. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +328 -0
  56. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
  57. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +199 -0
  58. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
  59. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +190 -0
  60. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
  61. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +221 -0
  62. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
  63. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +179 -0
  64. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
  65. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +259 -0
  66. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +304 -0
  67. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +545 -0
  68. package/lib/cjs/transactionPlan/midnight/takeLend.d.ts +99 -0
  69. package/lib/cjs/transactionPlan/midnight/takeLend.js +263 -0
  70. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
  71. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +440 -0
  72. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
  73. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +240 -0
  74. package/lib/cjs/transactionPlan/midnight/validation.d.ts +22 -0
  75. package/lib/cjs/transactionPlan/midnight/validation.js +158 -0
  76. package/lib/cjs/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
  77. package/lib/cjs/transactionPlan/midnight/withdrawCollateral.js +228 -0
  78. package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
  79. package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.js +232 -0
  80. package/lib/cjs/transactionPlan/plan.d.ts +48 -14
  81. package/lib/cjs/transactionPlan/plan.js +103 -18
  82. package/lib/cjs/transactionPlan/requirements.d.ts +7 -4
  83. package/lib/cjs/transactionPlan/requirements.js +2 -2
  84. package/lib/cjs/transactionPlan/serde.d.ts +13 -2
  85. package/lib/cjs/transactionPlan/serde.js +68 -21
  86. package/lib/cjs/transactionPlan/types.d.ts +147 -0
  87. package/lib/cjs/transactionPlan/validateActions.d.ts +3 -1
  88. package/lib/cjs/transactionPlan/validateActions.js +31 -3
  89. package/lib/cjs/transactionPlan/validation.d.ts +1 -1
  90. package/lib/cjs/transactionPlan/validation.js +37 -1
  91. package/lib/cjs/types/error.d.ts +2 -0
  92. package/lib/cjs/types/error.js +2 -0
  93. package/lib/cjs/version.d.ts +1 -1
  94. package/lib/cjs/version.js +1 -1
  95. package/lib/esm/actions/midnight/redeem.d.ts +20 -3
  96. package/lib/esm/actions/midnight/redeem.js +56 -0
  97. package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
  98. package/lib/esm/actions/midnight/supplyCollateralWithNative.js +40 -0
  99. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -2
  100. package/lib/esm/actions/midnight/withdrawCollateral.js +25 -1
  101. package/lib/esm/helpers/callback.d.ts +3 -2
  102. package/lib/esm/helpers/callback.js +5 -21
  103. package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
  104. package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.js +27 -0
  105. package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
  106. package/lib/esm/helpers/parseMidnightMaker.js +40 -1
  107. package/lib/esm/helpers/validate.d.ts +49 -1
  108. package/lib/esm/helpers/validate.js +84 -1
  109. package/lib/esm/helpers/validateMidnightPublication.d.ts +10 -0
  110. package/lib/esm/helpers/validateMidnightPublication.js +16 -0
  111. package/lib/esm/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
  112. package/lib/esm/helpers/validateMidnightTakeableOfferFields.js +81 -0
  113. package/lib/esm/index.d.ts +2 -2
  114. package/lib/esm/index.js +1 -1
  115. package/lib/esm/midnight/utils.d.ts +1 -1
  116. package/lib/esm/midnight/utils.js +1 -1
  117. package/lib/esm/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
  118. package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
  119. package/lib/esm/transactionPlan/error.d.ts +27 -0
  120. package/lib/esm/transactionPlan/error.js +28 -0
  121. package/lib/esm/transactionPlan/index.d.ts +40 -1
  122. package/lib/esm/transactionPlan/index.js +20 -1
  123. package/lib/esm/transactionPlan/midnight/authorization.d.ts +15 -0
  124. package/lib/esm/transactionPlan/midnight/authorization.js +40 -0
  125. package/lib/esm/transactionPlan/midnight/cancelOffers.d.ts +80 -0
  126. package/lib/esm/transactionPlan/midnight/cancelOffers.js +120 -0
  127. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +104 -0
  128. package/lib/esm/transactionPlan/midnight/makeBorrow.js +123 -0
  129. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +140 -0
  130. package/lib/esm/transactionPlan/midnight/makeLend.js +172 -0
  131. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +118 -0
  132. package/lib/esm/transactionPlan/midnight/makeRepay.js +115 -0
  133. package/lib/esm/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
  134. package/lib/esm/transactionPlan/midnight/makeWithdraw.js +123 -0
  135. package/lib/esm/transactionPlan/midnight/makerPublication.d.ts +55 -0
  136. package/lib/esm/transactionPlan/midnight/makerPublication.js +310 -0
  137. package/lib/esm/transactionPlan/midnight/market.d.ts +49 -0
  138. package/lib/esm/transactionPlan/midnight/market.js +112 -0
  139. package/lib/esm/transactionPlan/midnight/prepare.d.ts +244 -0
  140. package/lib/esm/transactionPlan/midnight/prepare.js +536 -0
  141. package/lib/esm/transactionPlan/midnight/publicationState.d.ts +24 -0
  142. package/lib/esm/transactionPlan/midnight/publicationState.js +47 -0
  143. package/lib/esm/transactionPlan/midnight/redeem.d.ts +102 -0
  144. package/lib/esm/transactionPlan/midnight/redeem.js +165 -0
  145. package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
  146. package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.js +47 -0
  147. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
  148. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +323 -0
  149. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
  150. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +196 -0
  151. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
  152. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +185 -0
  153. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
  154. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +216 -0
  155. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
  156. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +176 -0
  157. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
  158. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +254 -0
  159. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +304 -0
  160. package/lib/esm/transactionPlan/midnight/takeBorrow.js +539 -0
  161. package/lib/esm/transactionPlan/midnight/takeLend.d.ts +99 -0
  162. package/lib/esm/transactionPlan/midnight/takeLend.js +258 -0
  163. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
  164. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +435 -0
  165. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
  166. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +236 -0
  167. package/lib/esm/transactionPlan/midnight/validation.d.ts +22 -0
  168. package/lib/esm/transactionPlan/midnight/validation.js +151 -0
  169. package/lib/esm/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
  170. package/lib/esm/transactionPlan/midnight/withdrawCollateral.js +223 -0
  171. package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
  172. package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.js +227 -0
  173. package/lib/esm/transactionPlan/plan.d.ts +48 -14
  174. package/lib/esm/transactionPlan/plan.js +99 -14
  175. package/lib/esm/transactionPlan/requirements.d.ts +7 -4
  176. package/lib/esm/transactionPlan/requirements.js +2 -2
  177. package/lib/esm/transactionPlan/serde.d.ts +13 -2
  178. package/lib/esm/transactionPlan/serde.js +49 -2
  179. package/lib/esm/transactionPlan/types.d.ts +147 -0
  180. package/lib/esm/transactionPlan/validateActions.d.ts +3 -1
  181. package/lib/esm/transactionPlan/validateActions.js +31 -3
  182. package/lib/esm/transactionPlan/validation.d.ts +1 -1
  183. package/lib/esm/transactionPlan/validation.js +38 -2
  184. package/lib/esm/types/error.d.ts +2 -0
  185. package/lib/esm/types/error.js +2 -0
  186. package/lib/esm/version.d.ts +1 -1
  187. package/lib/esm/version.js +1 -1
  188. package/package.json +2 -2
@@ -69,16 +69,24 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
69
69
  * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
70
70
  * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
71
71
  * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
72
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
73
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
72
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
73
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
74
74
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
75
75
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
76
76
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
77
77
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
78
78
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
79
79
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
80
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
80
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
81
81
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
82
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
83
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
84
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
85
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
86
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
87
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
88
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
89
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
82
90
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
83
91
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
84
92
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -90,8 +98,10 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
90
98
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
91
99
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
92
100
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
93
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
94
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
101
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
102
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
103
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
104
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
95
105
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
96
106
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
97
107
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -104,8 +114,15 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
104
114
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
105
115
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
106
116
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
107
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
108
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
117
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
118
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
119
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
120
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
121
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
122
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
123
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
124
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
125
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
109
126
  * @example
110
127
  * ```ts
111
128
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -121,16 +138,23 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
121
138
  * Builds every step of the plan in order.
122
139
  * @param plan - Plan whose referenced signature requests all carry a signature.
123
140
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
124
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
125
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
141
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
142
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
126
143
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
127
144
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
128
145
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
129
146
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
130
147
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
131
148
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
132
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
149
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
133
150
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
151
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
152
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
153
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
154
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
155
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
156
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
157
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
134
158
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
135
159
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
136
160
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -139,11 +163,14 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
139
163
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
140
164
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
141
165
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
166
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
142
167
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
143
168
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
144
169
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
145
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
146
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
170
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
171
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
172
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
173
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
147
174
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
148
175
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
149
176
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -156,8 +183,15 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
156
183
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
157
184
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
158
185
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
159
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
160
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
186
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
187
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
188
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
189
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
190
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
191
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
192
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
193
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
194
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
161
195
  * @example
162
196
  * ```ts
163
197
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
@@ -14,8 +14,23 @@ import { buildBlueSupply, validateBlueSupplyPermitRequest, } from "./blue/supply
14
14
  import { buildBlueSupplyCollateral, validateSupplyCollateralPermitRequest, } from "./blue/supplyCollateral.js";
15
15
  import { buildBlueSupplyCollateralBorrow, validateSupplyCollateralBorrowRequest, } from "./blue/supplyCollateralBorrow.js";
16
16
  import { buildBlueWithdraw, validateBlueWithdrawAuthorizationRequest, } from "./blue/withdraw.js";
17
+ import { buildBlueWithdrawBuyCallback } from "./blue/withdrawBuyCallback.js";
17
18
  import { buildBlueWithdrawCollateral, validateBlueWithdrawCollateralAuthorizationRequest, } from "./blue/withdrawCollateral.js";
18
19
  import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
20
+ import { buildMidnightAuthorization } from "./midnight/authorization.js";
21
+ import { buildMidnightCancelOffers } from "./midnight/cancelOffers.js";
22
+ import { buildMidnightMakerPublication } from "./midnight/makerPublication.js";
23
+ import { buildMidnightRedeem } from "./midnight/redeem.js";
24
+ import { buildMidnightRepayWithdrawCollateral } from "./midnight/repayWithdrawCollateral.js";
25
+ import { buildMidnightSupplyCollateral } from "./midnight/supplyCollateral.js";
26
+ import { buildMidnightSupplyCollateralBatch } from "./midnight/supplyCollateralBatch.js";
27
+ import { buildMidnightSupplyCollateralWithNative } from "./midnight/supplyCollateralWithNative.js";
28
+ import { buildMidnightTakeBorrow } from "./midnight/takeBorrow.js";
29
+ import { buildMidnightTakeLend } from "./midnight/takeLend.js";
30
+ import { buildMidnightTakeRepayWithdrawCollateral } from "./midnight/takeRepayWithdrawCollateral.js";
31
+ import { buildMidnightTakeWithdraw } from "./midnight/takeWithdraw.js";
32
+ import { buildMidnightWithdrawCollateral } from "./midnight/withdrawCollateral.js";
33
+ import { buildMidnightWithdrawCollateralBatch } from "./midnight/withdrawCollateralBatch.js";
19
34
  import { validateVaultPermitRequest } from "./permit.js";
20
35
  import { validateTransactionPlanActions } from "./validateActions.js";
21
36
  import { validateTransactionPlanHeader } from "./validation.js";
@@ -322,6 +337,8 @@ function encodeStep(action, requests) {
322
337
  return buildBlueWithdraw(action, requests);
323
338
  case "blueWithdrawCollateral":
324
339
  return buildBlueWithdrawCollateral(action, requests);
340
+ case "blueWithdrawBuyCallback":
341
+ return buildBlueWithdrawBuyCallback(action);
325
342
  case "blueRepayWithdrawCollateral":
326
343
  return buildBlueRepayWithdrawCollateral(action, requests);
327
344
  case "blueRefinance":
@@ -335,6 +352,40 @@ function encodeStep(action, requests) {
335
352
  return buildVaultV1Deposit(action, requests);
336
353
  case "morphoAuthorization":
337
354
  return buildMorphoAuthorization(action);
355
+ case "midnightAuthorization":
356
+ return buildMidnightAuthorization(action);
357
+ case "midnightMakeBorrow":
358
+ case "midnightMakeLend":
359
+ case "midnightMakeRepay":
360
+ case "midnightMakeWithdraw":
361
+ case "midnightSupplyCollateralMakeBorrow":
362
+ case "midnightSupplyBlueMakeLend":
363
+ return buildMidnightMakerPublication(action);
364
+ case "midnightTakeBorrow":
365
+ case "midnightSupplyCollateralTakeBorrow":
366
+ return buildMidnightTakeBorrow(action);
367
+ case "midnightTakeWithdraw":
368
+ return buildMidnightTakeWithdraw(action);
369
+ case "midnightRepayWithdrawCollateral":
370
+ return buildMidnightRepayWithdrawCollateral(action);
371
+ case "midnightTakeLend":
372
+ return buildMidnightTakeLend(action);
373
+ case "midnightSupplyCollateral":
374
+ return buildMidnightSupplyCollateral(action);
375
+ case "midnightSupplyCollateralBatch":
376
+ return buildMidnightSupplyCollateralBatch(action);
377
+ case "midnightSupplyCollateralWithNative":
378
+ return buildMidnightSupplyCollateralWithNative(action);
379
+ case "midnightWithdrawCollateral":
380
+ return buildMidnightWithdrawCollateral(action);
381
+ case "midnightWithdrawCollateralBatch":
382
+ return buildMidnightWithdrawCollateralBatch(action);
383
+ case "midnightRedeem":
384
+ return buildMidnightRedeem(action);
385
+ case "midnightTakeRepayWithdrawCollateral":
386
+ return buildMidnightTakeRepayWithdrawCollateral(action);
387
+ case "midnightCancelOffers":
388
+ return buildMidnightCancelOffers(action);
338
389
  case "vaultV2Deposit":
339
390
  return buildVaultV2Deposit(action, requests);
340
391
  case "vaultV2Withdraw":
@@ -363,16 +414,24 @@ function encodeStep(action, requests) {
363
414
  * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
364
415
  * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
365
416
  * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
366
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
367
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
417
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
418
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
368
419
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
369
420
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
370
421
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
371
422
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
372
423
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
373
424
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
374
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
425
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
375
426
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
427
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
428
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
429
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
430
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
431
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
432
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
433
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
434
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
376
435
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
377
436
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
378
437
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -384,8 +443,10 @@ function encodeStep(action, requests) {
384
443
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
385
444
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
386
445
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
387
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
388
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
446
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
447
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
448
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
449
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
389
450
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
390
451
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
391
452
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -398,8 +459,15 @@ function encodeStep(action, requests) {
398
459
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
399
460
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
400
461
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
401
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
402
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
462
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
463
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
464
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
465
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
466
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
467
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
468
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
469
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
470
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
403
471
  * @example
404
472
  * ```ts
405
473
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -461,16 +529,23 @@ export function buildTransaction(plan, step) {
461
529
  * Builds every step of the plan in order.
462
530
  * @param plan - Plan whose referenced signature requests all carry a signature.
463
531
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
464
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
465
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
532
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
533
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
466
534
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
467
535
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
468
536
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
469
537
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
470
538
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
471
539
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
472
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
540
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
473
541
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
542
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
543
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
544
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
545
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
546
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
547
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
548
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
474
549
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
475
550
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
476
551
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -479,11 +554,14 @@ export function buildTransaction(plan, step) {
479
554
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
480
555
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
481
556
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
557
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
482
558
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
483
559
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
484
560
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
485
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
486
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
561
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
562
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
563
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
564
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
487
565
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
488
566
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
489
567
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -496,8 +574,15 @@ export function buildTransaction(plan, step) {
496
574
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
497
575
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
498
576
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
499
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
500
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
577
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
578
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
579
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
580
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
581
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
582
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
583
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
584
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
585
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
501
586
  * @example
502
587
  * ```ts
503
588
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
@@ -25,19 +25,22 @@ export declare function buildApprovalStep(requirement: Readonly<Transaction<ERC2
25
25
  }): Step<Extract<Action, {
26
26
  type: "erc20Approval";
27
27
  }>>;
28
- interface TokenRequirementsParams {
28
+ type TokenRequirementsParams = {
29
29
  readonly token: Address;
30
30
  readonly spender: Address;
31
31
  readonly amount: bigint;
32
32
  readonly owner: Address;
33
33
  readonly chainId: number;
34
+ readonly approvalId: (index: number) => string;
35
+ } & ({
36
+ readonly supportSignature?: false;
37
+ } | {
38
+ readonly supportSignature: boolean;
34
39
  readonly deadline: bigint;
35
40
  readonly now: bigint;
36
- readonly supportSignature: boolean;
37
41
  readonly deployless: boolean | undefined;
38
42
  readonly permitId: string;
39
- readonly approvalId: (index: number) => string;
40
- }
43
+ });
41
44
  /**
42
45
  * @internal Resolves the token prerequisite of a bundles pull without Permit2. A sufficient
43
46
  * direct allowance yields nothing. Otherwise signature support prefers an ERC-2612 permit when
@@ -52,7 +52,7 @@ export function buildApprovalStep(requirement, { id, chainId, account, denominat
52
52
  * available and falls back to a direct unlimited approval. Without signature support, always approve.
53
53
  */
54
54
  export async function getTokenRequirements(client, params) {
55
- const { token, spender, amount, owner, chainId, permitId, approvalId } = params;
55
+ const { token, spender, amount, owner, chainId, approvalId } = params;
56
56
  // The allowance is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
57
57
  const allowance = await readContract(client, {
58
58
  abi: erc20Abi,
@@ -66,7 +66,7 @@ export async function getTokenRequirements(client, params) {
66
66
  if (params.supportSignature) {
67
67
  const permit = await getTokenPermit(client, {
68
68
  ...params,
69
- id: permitId,
69
+ id: params.permitId,
70
70
  supportDeployless: params.deployless,
71
71
  });
72
72
  if (permit !== undefined) {
@@ -15,8 +15,19 @@ export declare function serializeTransactionPlan(plan: TransactionPlan): string;
15
15
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
16
16
  * Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
17
17
  * references, per-action chain/account and signature-request consistency, including signed requests.
18
- * Extra keys are allowed. No clock or RPC is used: current expiry, live state and
19
- * action-layer business constraints are not checked. Stored signatures are recovered offline.
18
+ * Extra keys are allowed. Midnight maker publications, `midnightSupplyCollateralTakeBorrow`,
19
+ * `midnightTakeRepayWithdrawCollateral` and `midnightSupplyCollateralWithNative` also rerun their
20
+ * builders' static input checks, so a stored recipe that fails those checks throws here. Restore compares the stored market of
21
+ * `midnightSupplyCollateralMakeBorrow`, `midnightSupplyCollateralTakeBorrow` and
22
+ * `midnightTakeRepayWithdrawCollateral` with the registered Midnight deployment, and each maker
23
+ * publication's ratifier with the registry. It does not decode maker offer payloads, so their offer
24
+ * markets are not checked, and other Midnight actions check only the stored market's shape and
25
+ * chain. Restoring `midnightSupplyCollateralWithNative` also looks up the chain's Midnight core,
26
+ * wNative and MidnightBundlesV2 registry entries, so register custom deployments before parsing.
27
+ * Building can still fail: other deployment lookups, such as the Midnight bundle address of other
28
+ * actions, run only in `buildTransactions`. No clock or RPC is used:
29
+ * current expiry, live state and other action-layer business constraints are not checked. Stored
30
+ * signatures are recovered offline.
20
31
  * Permits bind owner, token, spender, value, nonce, deadline and chain; Morpho authorizations bind
21
32
  * owner, authorized address, nonce, deadline and chain, not operation amounts, markets or referral fees/recipients.
22
33
  * Parsing does not prove authenticity or intent for unsigned fields;
@@ -9,9 +9,24 @@ import { validateBlueSupplyPlanAction } from "./blue/supply.js";
9
9
  import { validateSupplyCollateralPlanAction } from "./blue/supplyCollateral.js";
10
10
  import { validateSupplyCollateralBorrowPlanAction } from "./blue/supplyCollateralBorrow.js";
11
11
  import { validateBlueWithdrawPlanAction } from "./blue/withdraw.js";
12
+ import { validateBlueWithdrawBuyCallbackPlanAction } from "./blue/withdrawBuyCallback.js";
12
13
  import { validateBlueWithdrawCollateralPlanAction } from "./blue/withdrawCollateral.js";
13
14
  import { validateDepositPlanAction } from "./deposit.js";
14
15
  import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
16
+ import { validateSignaturelessMidnightAction } from "./midnight/authorization.js";
17
+ import { validateMidnightCancelOffersPlanAction } from "./midnight/cancelOffers.js";
18
+ import { validateMidnightMakerPublicationPlanAction } from "./midnight/makerPublication.js";
19
+ import { validateMidnightRedeemPlanAction } from "./midnight/redeem.js";
20
+ import { validateMidnightRepayWithdrawCollateralPlanAction } from "./midnight/repayWithdrawCollateral.js";
21
+ import { validateMidnightSupplyCollateralPlanAction } from "./midnight/supplyCollateral.js";
22
+ import { validateMidnightSupplyCollateralBatchPlanAction } from "./midnight/supplyCollateralBatch.js";
23
+ import { validateMidnightSupplyCollateralWithNativePlanAction } from "./midnight/supplyCollateralWithNative.js";
24
+ import { validateMidnightSupplyCollateralTakeBorrowPlanAction } from "./midnight/takeBorrow.js";
25
+ import { validateMidnightTakeLendPlanAction } from "./midnight/takeLend.js";
26
+ import { validateMidnightTakeRepayWithdrawCollateralPlanAction } from "./midnight/takeRepayWithdrawCollateral.js";
27
+ import { validateMidnightSellPlanAction } from "./midnight/validation.js";
28
+ import { validateMidnightWithdrawCollateralPlanAction } from "./midnight/withdrawCollateral.js";
29
+ import { validateMidnightWithdrawCollateralBatchPlanAction } from "./midnight/withdrawCollateralBatch.js";
15
30
  import { validatePermitPlanRequest } from "./permit.js";
16
31
  import { getPendingSignatureRequests, verifyPlanSignature } from "./plan.js";
17
32
  import { validateRedeemPlanAction } from "./redeem.js";
@@ -33,6 +48,7 @@ const actionValidators = {
33
48
  blueRepay: validateBlueRepayPlanAction,
34
49
  blueWithdraw: validateBlueWithdrawPlanAction,
35
50
  blueWithdrawCollateral: validateBlueWithdrawCollateralPlanAction,
51
+ blueWithdrawBuyCallback: validateBlueWithdrawBuyCallbackPlanAction,
36
52
  blueRepayWithdrawCollateral: validateRepayWithdrawCollateralPlanAction,
37
53
  blueRefinance: validateRefinancePlanAction,
38
54
  erc20Approval: validateApprovalPlanAction,
@@ -42,6 +58,26 @@ const actionValidators = {
42
58
  vaultV1Redeem: validateRedeemPlanAction,
43
59
  vaultV1MigrateToV2: validateMigrateToV2PlanAction,
44
60
  morphoAuthorization: validateMorphoAuthorizationPlanAction,
61
+ midnightAuthorization: validateSignaturelessMidnightAction,
62
+ midnightMakeBorrow: validateMidnightMakerPublicationPlanAction,
63
+ midnightMakeLend: validateMidnightMakerPublicationPlanAction,
64
+ midnightMakeRepay: validateMidnightMakerPublicationPlanAction,
65
+ midnightMakeWithdraw: validateMidnightMakerPublicationPlanAction,
66
+ midnightSupplyBlueMakeLend: validateMidnightMakerPublicationPlanAction,
67
+ midnightSupplyCollateralMakeBorrow: validateMidnightMakerPublicationPlanAction,
68
+ midnightTakeBorrow: validateMidnightSellPlanAction,
69
+ midnightSupplyCollateralTakeBorrow: validateMidnightSupplyCollateralTakeBorrowPlanAction,
70
+ midnightTakeLend: validateMidnightTakeLendPlanAction,
71
+ midnightSupplyCollateral: validateMidnightSupplyCollateralPlanAction,
72
+ midnightSupplyCollateralBatch: validateMidnightSupplyCollateralBatchPlanAction,
73
+ midnightSupplyCollateralWithNative: validateMidnightSupplyCollateralWithNativePlanAction,
74
+ midnightWithdrawCollateral: validateMidnightWithdrawCollateralPlanAction,
75
+ midnightWithdrawCollateralBatch: validateMidnightWithdrawCollateralBatchPlanAction,
76
+ midnightRedeem: validateMidnightRedeemPlanAction,
77
+ midnightTakeRepayWithdrawCollateral: validateMidnightTakeRepayWithdrawCollateralPlanAction,
78
+ midnightTakeWithdraw: validateMidnightSellPlanAction,
79
+ midnightRepayWithdrawCollateral: validateMidnightRepayWithdrawCollateralPlanAction,
80
+ midnightCancelOffers: validateMidnightCancelOffersPlanAction,
45
81
  vaultV2Deposit: validateDepositPlanAction,
46
82
  vaultV2Withdraw: validateWithdrawPlanAction,
47
83
  vaultV2ForceRedeem: validateForceRedeemPlanAction,
@@ -70,8 +106,19 @@ export function serializeTransactionPlan(plan) {
70
106
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
71
107
  * Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
72
108
  * references, per-action chain/account and signature-request consistency, including signed requests.
73
- * Extra keys are allowed. No clock or RPC is used: current expiry, live state and
74
- * action-layer business constraints are not checked. Stored signatures are recovered offline.
109
+ * Extra keys are allowed. Midnight maker publications, `midnightSupplyCollateralTakeBorrow`,
110
+ * `midnightTakeRepayWithdrawCollateral` and `midnightSupplyCollateralWithNative` also rerun their
111
+ * builders' static input checks, so a stored recipe that fails those checks throws here. Restore compares the stored market of
112
+ * `midnightSupplyCollateralMakeBorrow`, `midnightSupplyCollateralTakeBorrow` and
113
+ * `midnightTakeRepayWithdrawCollateral` with the registered Midnight deployment, and each maker
114
+ * publication's ratifier with the registry. It does not decode maker offer payloads, so their offer
115
+ * markets are not checked, and other Midnight actions check only the stored market's shape and
116
+ * chain. Restoring `midnightSupplyCollateralWithNative` also looks up the chain's Midnight core,
117
+ * wNative and MidnightBundlesV2 registry entries, so register custom deployments before parsing.
118
+ * Building can still fail: other deployment lookups, such as the Midnight bundle address of other
119
+ * actions, run only in `buildTransactions`. No clock or RPC is used:
120
+ * current expiry, live state and other action-layer business constraints are not checked. Stored
121
+ * signatures are recovered offline.
75
122
  * Permits bind owner, token, spender, value, nonce, deadline and chain; Morpho authorizations bind
76
123
  * owner, authorized address, nonce, deadline and chain, not operation amounts, markets or referral fees/recipients.
77
124
  * Parsing does not prove authenticity or intent for unsigned fields;