@morpho-org/morpho-sdk 10.4.0 → 10.5.0-next.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 (221) hide show
  1. package/lib/cjs/abis.d.ts +1 -1
  2. package/lib/cjs/abis.js +5 -1
  3. package/lib/cjs/actions/blue/common.js +12 -3
  4. package/lib/cjs/blue/abis.d.ts +1 -1
  5. package/lib/cjs/blue/abis.js +5 -1
  6. package/lib/cjs/blue/entities.d.ts +4 -4
  7. package/lib/cjs/blue/entities.js +3 -1
  8. package/lib/cjs/blue/errors.d.ts +2 -2
  9. package/lib/cjs/blue/errors.js +5 -1
  10. package/lib/cjs/blue/fetch.d.ts +2 -2
  11. package/lib/cjs/blue/fetch.js +3 -1
  12. package/lib/cjs/blue/utils.d.ts +1 -1
  13. package/lib/cjs/blue/utils.js +2 -1
  14. package/lib/cjs/entities/index.d.ts +4 -4
  15. package/lib/cjs/entities/index.js +3 -1
  16. package/lib/cjs/entities/midnight/midnight.d.ts +100 -103
  17. package/lib/cjs/entities/midnight/midnight.js +99 -99
  18. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
  19. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  20. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -2
  21. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
  22. package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
  23. package/lib/cjs/errors.d.ts +4 -4
  24. package/lib/cjs/errors.js +7 -5
  25. package/lib/cjs/fetch.d.ts +2 -2
  26. package/lib/cjs/fetch.js +3 -1
  27. package/lib/cjs/helpers/deadShares.js +3 -0
  28. package/lib/cjs/helpers/validate.d.ts +11 -1
  29. package/lib/cjs/midnight/errors.d.ts +2 -1
  30. package/lib/cjs/midnight/errors.js +5 -4
  31. package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
  32. package/lib/cjs/transactionPlan/assemble.js +25 -0
  33. package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
  34. package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
  35. package/lib/cjs/transactionPlan/blue/repay.js +10 -24
  36. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
  37. package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
  38. package/lib/cjs/transactionPlan/blue/stored.js +87 -0
  39. package/lib/cjs/transactionPlan/blue/supply.js +7 -22
  40. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  41. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
  42. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
  43. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
  44. package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
  45. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  46. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
  47. package/lib/cjs/transactionPlan/deposit.js +4 -7
  48. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  49. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  50. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +1 -1
  51. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +1 -1
  52. package/lib/cjs/transactionPlan/midnight/makeLend.js +1 -1
  53. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +1 -1
  54. package/lib/cjs/transactionPlan/midnight/makeRepay.js +1 -1
  55. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  56. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  57. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  58. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  59. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  60. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +1 -1
  61. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  62. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  63. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  64. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  65. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  66. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  67. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +2 -2
  68. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +2 -2
  69. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  70. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  71. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  72. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +1 -1
  73. package/lib/cjs/transactionPlan/permit.d.ts +15 -2
  74. package/lib/cjs/transactionPlan/permit.js +26 -68
  75. package/lib/cjs/transactionPlan/plan.d.ts +51 -1
  76. package/lib/cjs/transactionPlan/plan.js +56 -13
  77. package/lib/cjs/transactionPlan/redeem.js +4 -7
  78. package/lib/cjs/transactionPlan/types.d.ts +4 -3
  79. package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
  80. package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
  81. package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
  82. package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
  83. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
  84. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
  85. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  86. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
  87. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  88. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
  89. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
  90. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  91. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
  92. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
  93. package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
  94. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  95. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
  96. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  97. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
  98. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  99. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
  100. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
  101. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
  102. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  103. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
  104. package/lib/cjs/transactionPlan/withdraw.js +4 -7
  105. package/lib/cjs/types/error.d.ts +2 -1
  106. package/lib/cjs/types/error.js +3 -2
  107. package/lib/cjs/utils.d.ts +2 -2
  108. package/lib/cjs/utils.js +4 -2
  109. package/lib/cjs/version.d.ts +1 -1
  110. package/lib/cjs/version.js +1 -1
  111. package/lib/esm/abis.d.ts +1 -1
  112. package/lib/esm/abis.js +1 -1
  113. package/lib/esm/actions/blue/common.js +13 -4
  114. package/lib/esm/blue/abis.d.ts +1 -1
  115. package/lib/esm/blue/abis.js +1 -1
  116. package/lib/esm/blue/entities.d.ts +4 -4
  117. package/lib/esm/blue/entities.js +2 -2
  118. package/lib/esm/blue/errors.d.ts +2 -2
  119. package/lib/esm/blue/errors.js +2 -2
  120. package/lib/esm/blue/fetch.d.ts +2 -2
  121. package/lib/esm/blue/fetch.js +2 -2
  122. package/lib/esm/blue/utils.d.ts +1 -1
  123. package/lib/esm/blue/utils.js +1 -1
  124. package/lib/esm/entities/index.d.ts +4 -4
  125. package/lib/esm/entities/index.js +2 -2
  126. package/lib/esm/entities/midnight/midnight.d.ts +100 -103
  127. package/lib/esm/entities/midnight/midnight.js +99 -99
  128. package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
  129. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  130. package/lib/esm/entities/vaultV2/vaultV2.js +40 -3
  131. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
  132. package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
  133. package/lib/esm/errors.d.ts +4 -4
  134. package/lib/esm/errors.js +4 -4
  135. package/lib/esm/fetch.d.ts +2 -2
  136. package/lib/esm/fetch.js +2 -2
  137. package/lib/esm/helpers/deadShares.js +4 -1
  138. package/lib/esm/helpers/validate.d.ts +11 -1
  139. package/lib/esm/midnight/errors.d.ts +2 -1
  140. package/lib/esm/midnight/errors.js +2 -1
  141. package/lib/esm/transactionPlan/assemble.d.ts +24 -0
  142. package/lib/esm/transactionPlan/assemble.js +21 -0
  143. package/lib/esm/transactionPlan/blue/borrow.js +15 -65
  144. package/lib/esm/transactionPlan/blue/refinance.js +10 -12
  145. package/lib/esm/transactionPlan/blue/repay.js +11 -25
  146. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
  147. package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
  148. package/lib/esm/transactionPlan/blue/stored.js +80 -0
  149. package/lib/esm/transactionPlan/blue/supply.js +7 -22
  150. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  151. package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
  152. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
  153. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
  154. package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
  155. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  156. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
  157. package/lib/esm/transactionPlan/deposit.js +5 -8
  158. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  159. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +1 -1
  160. package/lib/esm/transactionPlan/midnight/makeBorrow.js +1 -1
  161. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +1 -1
  162. package/lib/esm/transactionPlan/midnight/makeLend.js +1 -1
  163. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +1 -1
  164. package/lib/esm/transactionPlan/midnight/makeRepay.js +1 -1
  165. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +1 -1
  166. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +1 -1
  167. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +1 -1
  168. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +1 -1
  169. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +1 -1
  170. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +1 -1
  171. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +1 -1
  172. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +1 -1
  173. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +1 -1
  174. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +1 -1
  175. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +1 -1
  176. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +1 -1
  177. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +2 -2
  178. package/lib/esm/transactionPlan/midnight/takeBorrow.js +2 -2
  179. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  180. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +1 -1
  181. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +1 -1
  182. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +1 -1
  183. package/lib/esm/transactionPlan/permit.d.ts +15 -2
  184. package/lib/esm/transactionPlan/permit.js +25 -68
  185. package/lib/esm/transactionPlan/plan.d.ts +51 -1
  186. package/lib/esm/transactionPlan/plan.js +55 -13
  187. package/lib/esm/transactionPlan/redeem.js +5 -8
  188. package/lib/esm/transactionPlan/types.d.ts +4 -3
  189. package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
  190. package/lib/esm/transactionPlan/vaultBinding.js +65 -0
  191. package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
  192. package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
  193. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
  194. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
  195. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  196. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
  197. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  198. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
  199. package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
  200. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  201. package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
  202. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
  203. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
  204. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  205. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
  206. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  207. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
  208. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  209. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
  210. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
  211. package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
  212. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  213. package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
  214. package/lib/esm/transactionPlan/withdraw.js +5 -8
  215. package/lib/esm/types/error.d.ts +2 -1
  216. package/lib/esm/types/error.js +3 -2
  217. package/lib/esm/utils.d.ts +2 -2
  218. package/lib/esm/utils.js +2 -2
  219. package/lib/esm/version.d.ts +1 -1
  220. package/lib/esm/version.js +1 -1
  221. package/package.json +7 -7
@@ -166,22 +166,22 @@ class MorphoMidnight {
166
166
  * On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
167
167
  * above one are dropped from the transaction because one of them would revert the whole bundle.
168
168
  *
169
- * @param params - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
170
- * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
171
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
172
- * @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
173
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
169
+ * @param raw - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
170
+ * @param raw.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
171
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
172
+ * @param raw.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
173
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
174
174
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
175
175
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
176
176
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
177
177
  * required for the full pulled amount.
178
- * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
179
- * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
178
+ * @param raw.takeableOffers - Borrow-side offers returned by the Midnight API.
179
+ * @param raw.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
180
180
  * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
181
181
  * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
182
- * @param params.deadline - Bundle execution deadline timestamp.
183
- * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
184
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
182
+ * @param raw.deadline - Bundle execution deadline timestamp.
183
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
184
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
185
185
  * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
186
186
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
187
187
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -229,7 +229,7 @@ class MorphoMidnight {
229
229
  * marketData,
230
230
  * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
231
231
  * takeableOffers: quote.data.takeableOffers,
232
- * maxContinuousFee: maxUint256,
232
+ * maxContinuousFee: BigInt(marketData.continuousFee),
233
233
  * now: (await client.getBlock()).timestamp,
234
234
  * deadline: (await client.getBlock()).timestamp + 600n,
235
235
  * });
@@ -289,26 +289,26 @@ class MorphoMidnight {
289
289
  * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
290
290
  * revert the whole bundle.
291
291
  *
292
- * @param params - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
293
- * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
294
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
295
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
292
+ * @param raw - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
293
+ * @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
294
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
295
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
296
296
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
297
297
  * does not see transactions mined or prices moved since, so two transactions built from one
298
298
  * snapshot can together end inside the buffer. Midnight still rejects any position above
299
299
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
300
- * @param params.collateralPrices - Values from `price()` on each
300
+ * @param raw.collateralPrices - Values from `price()` on each
301
301
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
302
302
  * scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
303
303
  * index, because debt after a borrow is always positive.
304
- * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
305
- * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
304
+ * @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
305
+ * @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
306
306
  * Midnight protocol and market token contracts are rejected.
307
- * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
308
- * @param params.deadline - Bounded bundle execution deadline timestamp.
309
- * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the sale
307
+ * @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
308
+ * @param raw.deadline - Bounded bundle execution deadline timestamp.
309
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
310
310
  * proceeds; on an assets target it is added on top of `target.assets`.
311
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
311
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
312
312
  * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
313
313
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
314
314
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -434,17 +434,17 @@ class MorphoMidnight {
434
434
  * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
435
435
  * revert the whole bundle.
436
436
  *
437
- * @param params - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
438
- * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
439
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
440
- * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
441
- * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
437
+ * @param raw - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
438
+ * @param raw.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
439
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
440
+ * @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
441
+ * @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
442
442
  * Midnight protocol and market token contracts are rejected.
443
- * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
444
- * @param params.deadline - Bundle execution deadline timestamp.
445
- * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the sale
443
+ * @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
444
+ * @param raw.deadline - Bundle execution deadline timestamp.
445
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
446
446
  * proceeds; on an assets target it is added on top of `target.assets`.
447
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
447
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
448
448
  * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
449
449
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
450
450
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -531,32 +531,32 @@ class MorphoMidnight {
531
531
  * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
532
532
  * revert the whole bundle.
533
533
  *
534
- * @param params - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
535
- * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
536
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
537
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
534
+ * @param raw - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
535
+ * @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
536
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
537
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
538
538
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
539
539
  * does not see transactions mined or prices moved since, so two transactions built from one
540
540
  * snapshot can together end inside the buffer. Midnight still rejects any position above
541
541
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
542
- * @param params.collateralPrices - Values from `price()` on each
542
+ * @param raw.collateralPrices - Values from `price()` on each
543
543
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
544
544
  * scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
545
545
  * index, because debt after a borrow is always positive.
546
- * @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
547
- * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
548
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
546
+ * @param raw.collateralSupplies - Collateral index and assets per supply; must not be empty.
547
+ * @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
548
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
549
549
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
550
550
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
551
551
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
552
552
  * required for the full pulled amount.
553
- * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
553
+ * @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
554
554
  * Midnight protocol and market token contracts are rejected.
555
- * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
556
- * @param params.deadline - Bounded bundle execution deadline timestamp.
557
- * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the sale
555
+ * @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
556
+ * @param raw.deadline - Bounded bundle execution deadline timestamp.
557
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
558
558
  * proceeds; on an assets target it is added on top of `target.assets`.
559
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
559
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
560
560
  * @returns Lazy collateral approvals and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
561
561
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
562
562
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -699,37 +699,37 @@ class MorphoMidnight {
699
699
  * On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
700
700
  * above one are dropped from the transaction because one of them would revert the whole bundle.
701
701
  *
702
- * @param params - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
703
- * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
704
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
705
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
702
+ * @param raw - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
703
+ * @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
704
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
705
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
706
706
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
707
707
  * does not see transactions mined or prices moved since, so two transactions built from one
708
708
  * snapshot can together end inside the buffer. Midnight still rejects any position above
709
709
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
710
- * @param params.collateralPrices - Values from `price()` on each
710
+ * @param raw.collateralPrices - Values from `price()` on each
711
711
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
712
712
  * scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
713
713
  * `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a units
714
714
  * `target` covering `positionData.debt`, or an assets target whose `minUnits` covers it.
715
- * @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`; `units: maxUint256` targets the sender's whole debt, capped by `maxBuyerAssets` (must be finite; `units: maxUint256` already selects the whole debt).
716
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
715
+ * @param raw.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`; `units: maxUint256` targets the sender's whole debt, capped by `maxBuyerAssets` (must be finite; `units: maxUint256` already selects the whole debt).
716
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
717
717
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
718
718
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
719
719
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
720
720
  * required for the full pulled amount.
721
- * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
722
- * @param params.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
723
- * @param params.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
724
- * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
721
+ * @param raw.takeableOffers - Borrow-side offers returned by the Midnight API.
722
+ * @param raw.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
723
+ * @param raw.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
724
+ * @param raw.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
725
725
  * must be non-zero and not a Midnight protocol or market token contract when
726
726
  * `collateralWithdrawals` is non-empty, and is unused otherwise.
727
- * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
727
+ * @param raw.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
728
728
  * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
729
729
  * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
730
- * @param params.deadline - Bundle execution deadline timestamp.
731
- * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
732
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
730
+ * @param raw.deadline - Bundle execution deadline timestamp.
731
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
732
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
733
733
  * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
734
734
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
735
735
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
@@ -793,7 +793,7 @@ class MorphoMidnight {
793
793
  * takeableOffers: quote.data.takeableOffers,
794
794
  * repayEnabled: true,
795
795
  * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
796
- * maxContinuousFee: maxUint256,
796
+ * maxContinuousFee: BigInt(marketData.continuousFee),
797
797
  * now: (await client.getBlock()).timestamp,
798
798
  * deadline: (await client.getBlock()).timestamp + 600n,
799
799
  * });
@@ -893,18 +893,18 @@ class MorphoMidnight {
893
893
  * Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
894
894
  * No requirements or RPC reads are needed. The signing account must be accountAddress.
895
895
  *
896
- * @param params - Market, owner-bound position, collateral prices and withdrawal amount.
897
- * @param params.accountAddress - Collateral owner. This account must send the transaction.
898
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
899
- * @param params.positionData - Owner-bound position snapshot returned by getPositionData.
900
- * @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
896
+ * @param raw - Market, owner-bound position, collateral prices and withdrawal amount.
897
+ * @param raw.accountAddress - Collateral owner. This account must send the transaction.
898
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
899
+ * @param raw.positionData - Owner-bound position snapshot returned by getPositionData.
900
+ * @param raw.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
901
901
  * ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
902
- * @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
902
+ * @param raw.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
903
903
  * market's collateral parameters, which Midnight sorts by token address, not the order they were
904
904
  * listed in when the market was built; check marketData.getCollateralByIndex(index).token.
905
- * @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
905
+ * @param raw.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
906
906
  * the selected collateral from positionData before building the transaction.
907
- * @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
907
+ * @param raw.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
908
908
  * @returns Lazy handles for a direct Midnight withdrawal.
909
909
  * @throws {ChainIdMismatchError} when the client or market targets another chain.
910
910
  * @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
@@ -973,15 +973,15 @@ class MorphoMidnight {
973
973
  * Duplicates are rejected, unlike bundle flows which sum them.
974
974
  * No requirements or RPC reads are needed. The signing account must be accountAddress.
975
975
  *
976
- * @param params - Market, owner-bound position, collateral prices and withdrawal amount.
977
- * @param params.accountAddress - Collateral owner. This account must send the transaction.
978
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
979
- * @param params.positionData - Owner-bound position snapshot returned by getPositionData.
980
- * @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
976
+ * @param raw - Market, owner-bound position, collateral prices and withdrawal amount.
977
+ * @param raw.accountAddress - Collateral owner. This account must send the transaction.
978
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
979
+ * @param raw.positionData - Owner-bound position snapshot returned by getPositionData.
980
+ * @param raw.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
981
981
  * ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
982
- * @param params.collateralWithdrawals - Nonempty ordered withdrawals, one per index.
982
+ * @param raw.collateralWithdrawals - Nonempty ordered withdrawals, one per index.
983
983
  * maxUint256 resolves that index's full snapshot balance.
984
- * @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
984
+ * @param raw.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
985
985
  * @returns Lazy handles for a direct Midnight withdrawal.
986
986
  * @throws {ChainIdMismatchError} when the client or market targets another chain.
987
987
  * @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
@@ -1051,18 +1051,18 @@ class MorphoMidnight {
1051
1051
  /**
1052
1052
  * Prepares a direct collateral supply using a caller-provided market snapshot.
1053
1053
  *
1054
- * @param params.accountAddress - Account receiving the supplied collateral position. It must send
1054
+ * @param raw.accountAddress - Account receiving the supplied collateral position. It must send
1055
1055
  * the transaction: Midnight pulls the collateral from `msg.sender` and only lets the position owner
1056
1056
  * or its operators supply for it, and the approval requirements are resolved for this account.
1057
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
1058
- * @param params.collateralAssets - Collateral assets supplied in this transaction.
1059
- * @param params.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
1057
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
1058
+ * @param raw.collateralAssets - Collateral assets supplied in this transaction.
1059
+ * @param raw.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
1060
1060
  * Only raises the approval requirement so those groups keep their allowance; the transaction
1061
1061
  * transfers only `collateralAssets`.
1062
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`. Indexes follow the
1062
+ * @param raw.collateralIndex - Optional collateral index; defaults to `0n`. Indexes follow the
1063
1063
  * market's collateral parameters, which Midnight sorts by token address, not the order they were
1064
1064
  * listed in when the market was built; check `marketData.getCollateralByIndex(index).token`.
1065
- * @param params.now - Optional reference timestamp in seconds; used for metadata only when the
1065
+ * @param raw.now - Optional reference timestamp in seconds; used for metadata only when the
1066
1066
  * client sets `metadata.timestamp: true`.
1067
1067
  * @returns Lazy token-approval requirements and a synchronous transaction builder.
1068
1068
  * @throws {NegativeInputError} when the resolved metadata timestamp is negative, or the reserve is negative.
@@ -1260,9 +1260,9 @@ class MorphoMidnight {
1260
1260
  * Prepares ordered direct collateral supplies in one Midnight multicall.
1261
1261
  * Pass one entry per index: duplicates are rejected, unlike bundle flows which sum them.
1262
1262
  *
1263
- * @param params.accountAddress - Sender and collateral beneficiary.
1264
- * @param params.marketData - Snapshot of the target market.
1265
- * @param params.collateralSupplies - Ordered supplies with optional reserved allowance amounts.
1263
+ * @param raw.accountAddress - Sender and collateral beneficiary.
1264
+ * @param raw.marketData - Snapshot of the target market.
1265
+ * @param raw.collateralSupplies - Ordered supplies with optional reserved allowance amounts.
1266
1266
  * @returns A lazy approval resolver and synchronous stateless transaction builder.
1267
1267
  * @throws {ChainIdMismatchError} when the client or market targets another chain.
1268
1268
  * @throws {MidnightMarketAddressMismatchError} when the deployment differs.
@@ -1911,14 +1911,14 @@ class MorphoMidnight {
1911
1911
  /**
1912
1912
  * Prepares redemption of accrued Midnight credit from a position snapshot.
1913
1913
  *
1914
- * @param params - Position owner, accrued position, optional unit amount, and receiver.
1915
- * @param params.accountAddress - Position owner whose credit is redeemed. It must send the
1914
+ * @param raw - Position owner, accrued position, optional unit amount, and receiver.
1915
+ * @param raw.accountAddress - Position owner whose credit is redeemed. It must send the
1916
1916
  * transaction (or authorize the sender): Midnight reverts `Unauthorized()` otherwise, which
1917
1917
  * `getRequirements()` cannot detect because it does not know the sender.
1918
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`.
1919
- * @param params.receiver - Optional credit receiver; defaults to the position owner.
1918
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`.
1919
+ * @param raw.receiver - Optional credit receiver; defaults to the position owner.
1920
1920
  * Midnight protocol and market token contracts are rejected.
1921
- * @param params.units - Optional credit units to redeem; defaults to the position face value.
1921
+ * @param raw.units - Optional credit units to redeem; defaults to the position face value.
1922
1922
  * Credit is checked after applying the realized losses and continuous fees that Midnight
1923
1923
  * charges before a withdrawal, accrued up to now. Fees keep accruing until maturity, so `units` close to the accrued
1924
1924
  * credit can still revert when the transaction lands later. The default face value does not
@@ -1967,30 +1967,30 @@ class MorphoMidnight {
1967
1967
  /**
1968
1968
  * Prepares a direct `MidnightBundlesV2` repayment, collateral withdrawal, or both, for `accountAddress`.
1969
1969
  *
1970
- * @param params - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
1971
- * @param params.accountAddress - Position owner and transaction sender.
1972
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
1973
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
1970
+ * @param raw - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
1971
+ * @param raw.accountAddress - Position owner and transaction sender.
1972
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
1973
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
1974
1974
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
1975
1975
  * does not see transactions mined or prices moved since, so two transactions built from one
1976
1976
  * snapshot can together end inside the buffer. Midnight still rejects any position above
1977
1977
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
1978
- * @param params.collateralPrices - Values from `price()` on each
1978
+ * @param raw.collateralPrices - Values from `price()` on each
1979
1979
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
1980
1980
  * scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
1981
1981
  * `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a `full`
1982
1982
  * repay, or `repay.assets` covering `positionData.debt`.
1983
- * @param params.repay - `{ type: "assets", assets }` (`0n` to only withdraw) or `{ type: "full", maxBuyerAssets }`; a loan-token approval to `MidnightBundlesV2` is required when the allowance is below the pulled amount (unlimited: `maxUint256`, capped per token by `MAX_TOKEN_APPROVALS`), and any unused part is refunded.
1984
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
1983
+ * @param raw.repay - `{ type: "assets", assets }` (`0n` to only withdraw) or `{ type: "full", maxBuyerAssets }`; a loan-token approval to `MidnightBundlesV2` is required when the allowance is below the pulled amount (unlimited: `maxUint256`, capped per token by `MAX_TOKEN_APPROVALS`), and any unused part is refunded.
1984
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
1985
1985
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
1986
1986
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
1987
1987
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
1988
1988
  * required for the full pulled amount.
1989
- * @param params.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
1990
- * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
1989
+ * @param raw.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
1990
+ * @param raw.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
1991
1991
  * must be non-zero and not a Midnight protocol or market token contract when
1992
1992
  * `collateralWithdrawals` is non-empty, and is unused otherwise.
1993
- * @param params.deadline - Bundle execution deadline timestamp. Unlike taker builders,
1993
+ * @param raw.deadline - Bundle execution deadline timestamp. Unlike taker builders,
1994
1994
  * `maxUint256` is accepted because no offers are filled; the pull remains bounded by
1995
1995
  * `repay.assets` or `repay.maxBuyerAssets`.
1996
1996
  * @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
@@ -198,7 +198,6 @@ class MorphoVaultV1 {
198
198
  if (amount <= 0n) {
199
199
  throw new index_js_2.NonPositiveInputError("amount", amount);
200
200
  }
201
- // Reject values outside the ABI range before resolving any requirements.
202
201
  const parsedAmount = (0, parse_js_1.parseUint256)("amount", amount);
203
202
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
204
203
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
@@ -67,7 +67,9 @@ export interface VaultV2Actions {
67
67
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
68
68
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
69
69
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
70
- * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or the deadline exceeds uint256.
70
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or
71
+ * the deadline exceeds uint256, or when the vault's liquidity adapter is a Midnight adapter (it
72
+ * cannot receive vault allocations, so no deposit fits and `max` is `0n`).
71
73
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
72
74
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
73
75
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -149,7 +151,9 @@ export interface VaultV2Actions {
149
151
  * @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
150
152
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
151
153
  * at any `getRequirements()` call.
152
- * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
154
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation,
155
+ * or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
156
+ * idle assets plus what the adapter can withdraw from the liquidity market.
153
157
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
154
158
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
155
159
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
@@ -216,7 +220,25 @@ export interface VaultV2Actions {
216
220
  * @throws {NonPositiveInputError} when `shares` is not positive.
217
221
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
218
222
  * requirement resolution.
219
- * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
223
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256, or from
224
+ * `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
225
+ * are worth more than the vault's idle assets plus what the adapter can withdraw from the
226
+ * liquidity market.
227
+ * @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
228
+ * @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
229
+ * configured factory.
230
+ * @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
231
+ * adapters uses an unsupported adapter class.
232
+ * @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
233
+ * is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
234
+ * unsupported IRM.
235
+ * @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
236
+ * adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
237
+ * allocation data.
238
+ * @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
239
+ * adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
240
+ * @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
241
+ * liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
220
242
  * @throws {NegativeInputError} when `referralFeePct` is negative.
221
243
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
222
244
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
@@ -225,7 +247,7 @@ export interface VaultV2Actions {
225
247
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
226
248
  * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
227
249
  * contract has no code at its registered address.
228
- * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
250
+ * @throws {viem.BaseError} from `getRequirements()` when a vault-state, allowance, nonce, `eth_chainId`, or
229
251
  * `eth_getCode` read fails.
230
252
  * @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
231
253
  * `getData()` has unusable decimals.
@@ -303,9 +325,11 @@ export interface VaultV2Actions {
303
325
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
304
326
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
305
327
  * requirement resolution.
306
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
328
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter, including
329
+ * a vault that mixes Blue and Midnight adapters.
307
330
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
308
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
331
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
332
+ * including a Midnight adapter.
309
333
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
310
334
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
311
335
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -431,9 +455,11 @@ export interface VaultV2Actions {
431
455
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
432
456
  * requirement resolution.
433
457
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
434
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
458
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter,
459
+ * including a vault that mixes Blue and Midnight adapters.
435
460
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
436
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
461
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
462
+ * including a Midnight adapter.
437
463
  * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
438
464
  * another adapter.
439
465
  * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
@@ -26,6 +26,16 @@ const getVaultV2InKindRedeemRequirements_js_1 = require("../requirements/getVaul
26
26
  const validateNativeRequirements_js_1 = require("../requirements/validateNativeRequirements.js");
27
27
  const forceWithdrawQuote_js_1 = require("./forceWithdrawQuote.js");
28
28
  const inKindRedeemQuote_js_1 = require("./inKindRedeemQuote.js");
29
+ /**
30
+ * Midnight adapters revert vault-initiated `allocate` (`SelfAllocationOnly`), so a vault routing
31
+ * liquidity through one accepts no deposit. Exits are served from idle assets plus what the adapter's
32
+ * `withdrawToVault` path can withdraw from the liquidity market.
33
+ */
34
+ const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
35
+ /** Idle assets plus what the Midnight liquidity adapter can withdraw to the vault onchain. */
36
+ const midnightWithdrawLiquidity = (vaultData) => vaultData.assetBalance +
37
+ (vaultData.accrualLiquidityAdapter?.maxWithdraw(vaultData.liquidityData)
38
+ .value ?? 0n);
29
39
  /** Binds a viem client to a Vault V2 vault's action builders. */
30
40
  class MorphoVaultV2 {
31
41
  client;
@@ -94,6 +104,13 @@ class MorphoVaultV2 {
94
104
  if (funding.value > 0n) {
95
105
  (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
96
106
  }
107
+ if (isMidnightLiquidityAdapter(vaultData)) {
108
+ throw new index_js_2.InputExceedsMaxError({
109
+ field: funding.value > 0n ? "nativeAmount" : "amount",
110
+ value: funding.assets,
111
+ max: 0n,
112
+ });
113
+ }
97
114
  const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
98
115
  // Bound forward accrual before deriving the deposit price protection.
99
116
  (0, validate_js_1.validateVaultDepositDeadline)(deadline, { now: createdAt });
@@ -199,8 +216,15 @@ class MorphoVaultV2 {
199
216
  if (amount <= 0n) {
200
217
  throw new index_js_2.NonPositiveInputError("amount", amount);
201
218
  }
202
- // Reject values outside the ABI range before resolving any requirements.
203
219
  const parsedAmount = (0, parse_js_1.parseUint256)("amount", amount);
220
+ if (isMidnightLiquidityAdapter(vaultData) &&
221
+ amount > midnightWithdrawLiquidity(vaultData)) {
222
+ throw new index_js_2.InputExceedsMaxError({
223
+ field: "amount",
224
+ value: amount,
225
+ max: midnightWithdrawLiquidity(vaultData),
226
+ });
227
+ }
204
228
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
205
229
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
206
230
  if (deadline <= createdAt) {
@@ -310,8 +334,21 @@ class MorphoVaultV2 {
310
334
  }
311
335
  const chainCheck = (0, chainCheck_js_1.createChainCheck)(this.client.viemClient, this.chainId);
312
336
  await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
337
+ const vaultData = await this.getDataWithChainCheck(chainCheck);
338
+ if (isMidnightLiquidityAdapter(vaultData)) {
339
+ // Onchain redeem accrues interest before converting shares to assets.
340
+ const { vault: accrued } = vaultData.accrueInterest(now);
341
+ const liquidity = midnightWithdrawLiquidity(accrued);
342
+ if (accrued.toAssets(shares) > liquidity) {
343
+ throw new index_js_2.InputExceedsMaxError({
344
+ field: "shares",
345
+ value: shares,
346
+ max: accrued.toShares(liquidity),
347
+ });
348
+ }
349
+ }
313
350
  return (0, getVaultBundlesSharesRequirements_js_1.getParsedVaultBundlesSharesRequirements)({ viemClient: this.client.viemClient, chainCheck }, (0, getVaultBundlesSharesRequirements_js_1.parseVaultBundlesSharesRequirements)(this.client.viemClient, {
314
- vaultData: await this.getDataWithChainCheck(chainCheck),
351
+ vaultData,
315
352
  version: "vaultV2",
316
353
  owner: userAddress,
317
354
  chainId: this.chainId,
@@ -56,7 +56,8 @@ export interface InputVaultV2BlueReallocationData {
56
56
  /**
57
57
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
58
58
  *
59
- * Constructor inputs are cloned. Every simulated reallocation returns a new
59
+ * Constructor inputs are cloned, except read-only Midnight adapter snapshots, which are
60
+ * shared by reference. Every simulated reallocation returns a new
60
61
  * instance. Planning keeps the transaction-scoped `firstTotalAssets`
61
62
  * denominator outside the durable snapshot while applying reallocations in
62
63
  * contract order. Penalty donations update simulated vault accounting but are
@@ -133,7 +134,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
133
134
  /**
134
135
  * Clones the complete simulation snapshot.
135
136
  *
136
- * @returns A deep clone of this simulation state.
137
+ * @returns A deep clone of this simulation state; read-only Midnight adapter snapshots are shared by reference.
137
138
  * @example
138
139
  * ```ts
139
140
  * import { markets } from "@morpho-org/morpho-test";
@@ -83,6 +83,9 @@ const cloneAccrualVault = (vault, markets) => new blue_sdk_1.AccrualVault({
83
83
  position: clonePosition(position, markets),
84
84
  })));
85
85
  const cloneAdapter = (adapter, markets) => {
86
+ if (adapter.type === "VaultV2MidnightAdapter") {
87
+ return adapter;
88
+ }
86
89
  const base = {
87
90
  address: adapter.address,
88
91
  parentVault: adapter.parentVault,
@@ -134,7 +137,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
134
137
  /**
135
138
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
136
139
  *
137
- * Constructor inputs are cloned. Every simulated reallocation returns a new
140
+ * Constructor inputs are cloned, except read-only Midnight adapter snapshots, which are
141
+ * shared by reference. Every simulated reallocation returns a new
138
142
  * instance. Planning keeps the transaction-scoped `firstTotalAssets`
139
143
  * denominator outside the durable snapshot while applying reallocations in
140
144
  * contract order. Penalty donations update simulated vault accounting but are
@@ -265,7 +269,7 @@ class VaultV2BlueReallocationData {
265
269
  /**
266
270
  * Clones the complete simulation snapshot.
267
271
  *
268
- * @returns A deep clone of this simulation state.
272
+ * @returns A deep clone of this simulation state; read-only Midnight adapter snapshots are shared by reference.
269
273
  * @example
270
274
  * ```ts
271
275
  * import { markets } from "@morpho-org/morpho-test";
@@ -1,7 +1,7 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, InvalidVaultV2MidnightAdapterMarketsError as InvalidBlueVaultV2MidnightAdapterMarketsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, MissingLocalePartError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, MissingLocalePartError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";