@morpho-org/morpho-sdk 10.3.1 → 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 (344) hide show
  1. package/README.md +169 -5
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +5 -1
  4. package/lib/cjs/actions/blue/common.js +12 -3
  5. package/lib/cjs/actions/midnight/redeem.d.ts +20 -3
  6. package/lib/cjs/actions/midnight/redeem.js +58 -1
  7. package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
  8. package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +41 -0
  9. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -2
  10. package/lib/cjs/actions/midnight/withdrawCollateral.js +26 -1
  11. package/lib/cjs/blue/abis.d.ts +1 -1
  12. package/lib/cjs/blue/abis.js +5 -1
  13. package/lib/cjs/blue/entities.d.ts +4 -4
  14. package/lib/cjs/blue/entities.js +3 -1
  15. package/lib/cjs/blue/errors.d.ts +2 -2
  16. package/lib/cjs/blue/errors.js +5 -1
  17. package/lib/cjs/blue/fetch.d.ts +2 -2
  18. package/lib/cjs/blue/fetch.js +3 -1
  19. package/lib/cjs/blue/utils.d.ts +1 -1
  20. package/lib/cjs/blue/utils.js +2 -1
  21. package/lib/cjs/entities/index.d.ts +4 -4
  22. package/lib/cjs/entities/index.js +3 -1
  23. package/lib/cjs/entities/midnight/midnight.d.ts +100 -103
  24. package/lib/cjs/entities/midnight/midnight.js +99 -99
  25. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -1
  26. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  27. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -2
  28. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -2
  29. package/lib/cjs/entities/vaultV2BlueReallocationData.js +6 -2
  30. package/lib/cjs/errors.d.ts +4 -4
  31. package/lib/cjs/errors.js +7 -5
  32. package/lib/cjs/fetch.d.ts +2 -2
  33. package/lib/cjs/fetch.js +3 -1
  34. package/lib/cjs/helpers/callback.d.ts +3 -2
  35. package/lib/cjs/helpers/callback.js +4 -20
  36. package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
  37. package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.js +30 -0
  38. package/lib/cjs/helpers/deadShares.js +3 -0
  39. package/lib/cjs/helpers/parseMidnightMaker.d.ts +21 -0
  40. package/lib/cjs/helpers/parseMidnightMaker.js +41 -1
  41. package/lib/cjs/helpers/validate.d.ts +60 -2
  42. package/lib/cjs/helpers/validate.js +87 -1
  43. package/lib/cjs/helpers/validateMidnightPublication.d.ts +10 -0
  44. package/lib/cjs/helpers/validateMidnightPublication.js +18 -1
  45. package/lib/cjs/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
  46. package/lib/cjs/helpers/validateMidnightTakeableOfferFields.js +85 -0
  47. package/lib/cjs/index.d.ts +2 -2
  48. package/lib/cjs/index.js +23 -1
  49. package/lib/cjs/midnight/errors.d.ts +2 -1
  50. package/lib/cjs/midnight/errors.js +5 -4
  51. package/lib/cjs/midnight/utils.d.ts +1 -1
  52. package/lib/cjs/midnight/utils.js +2 -1
  53. package/lib/cjs/transactionPlan/assemble.d.ts +24 -0
  54. package/lib/cjs/transactionPlan/assemble.js +25 -0
  55. package/lib/cjs/transactionPlan/blue/borrow.js +14 -64
  56. package/lib/cjs/transactionPlan/blue/refinance.js +9 -11
  57. package/lib/cjs/transactionPlan/blue/repay.js +10 -24
  58. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +49 -45
  59. package/lib/cjs/transactionPlan/blue/stored.d.ts +26 -0
  60. package/lib/cjs/transactionPlan/blue/stored.js +87 -0
  61. package/lib/cjs/transactionPlan/blue/supply.js +7 -22
  62. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  63. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +10 -15
  64. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +14 -64
  65. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -3
  66. package/lib/cjs/transactionPlan/blue/withdraw.js +67 -79
  67. package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
  68. package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
  69. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  70. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +31 -30
  71. package/lib/cjs/transactionPlan/deposit.js +4 -7
  72. package/lib/cjs/transactionPlan/error.d.ts +27 -0
  73. package/lib/cjs/transactionPlan/error.js +30 -1
  74. package/lib/cjs/transactionPlan/index.d.ts +40 -1
  75. package/lib/cjs/transactionPlan/index.js +46 -5
  76. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  77. package/lib/cjs/transactionPlan/midnight/authorization.d.ts +15 -0
  78. package/lib/cjs/transactionPlan/midnight/authorization.js +45 -0
  79. package/lib/cjs/transactionPlan/midnight/cancelOffers.d.ts +80 -0
  80. package/lib/cjs/transactionPlan/midnight/cancelOffers.js +125 -0
  81. package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +104 -0
  82. package/lib/cjs/transactionPlan/midnight/makeBorrow.js +126 -0
  83. package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +140 -0
  84. package/lib/cjs/transactionPlan/midnight/makeLend.js +176 -0
  85. package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +118 -0
  86. package/lib/cjs/transactionPlan/midnight/makeRepay.js +118 -0
  87. package/lib/cjs/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
  88. package/lib/cjs/transactionPlan/midnight/makeWithdraw.js +126 -0
  89. package/lib/cjs/transactionPlan/midnight/makerPublication.d.ts +55 -0
  90. package/lib/cjs/transactionPlan/midnight/makerPublication.js +315 -0
  91. package/lib/cjs/transactionPlan/midnight/market.d.ts +49 -0
  92. package/lib/cjs/transactionPlan/midnight/market.js +120 -0
  93. package/lib/cjs/transactionPlan/midnight/prepare.d.ts +244 -0
  94. package/lib/cjs/transactionPlan/midnight/prepare.js +547 -0
  95. package/lib/cjs/transactionPlan/midnight/publicationState.d.ts +24 -0
  96. package/lib/cjs/transactionPlan/midnight/publicationState.js +50 -0
  97. package/lib/cjs/transactionPlan/midnight/redeem.d.ts +102 -0
  98. package/lib/cjs/transactionPlan/midnight/redeem.js +170 -0
  99. package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
  100. package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.js +51 -0
  101. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
  102. package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +328 -0
  103. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
  104. package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +199 -0
  105. package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
  106. package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +190 -0
  107. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
  108. package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +221 -0
  109. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
  110. package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +179 -0
  111. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
  112. package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +259 -0
  113. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +304 -0
  114. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +545 -0
  115. package/lib/cjs/transactionPlan/midnight/takeLend.d.ts +99 -0
  116. package/lib/cjs/transactionPlan/midnight/takeLend.js +263 -0
  117. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
  118. package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +440 -0
  119. package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
  120. package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +240 -0
  121. package/lib/cjs/transactionPlan/midnight/validation.d.ts +22 -0
  122. package/lib/cjs/transactionPlan/midnight/validation.js +158 -0
  123. package/lib/cjs/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
  124. package/lib/cjs/transactionPlan/midnight/withdrawCollateral.js +228 -0
  125. package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
  126. package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.js +232 -0
  127. package/lib/cjs/transactionPlan/permit.d.ts +15 -2
  128. package/lib/cjs/transactionPlan/permit.js +26 -68
  129. package/lib/cjs/transactionPlan/plan.d.ts +99 -15
  130. package/lib/cjs/transactionPlan/plan.js +159 -31
  131. package/lib/cjs/transactionPlan/redeem.js +4 -7
  132. package/lib/cjs/transactionPlan/requirements.d.ts +7 -4
  133. package/lib/cjs/transactionPlan/requirements.js +2 -2
  134. package/lib/cjs/transactionPlan/serde.d.ts +13 -2
  135. package/lib/cjs/transactionPlan/serde.js +68 -21
  136. package/lib/cjs/transactionPlan/types.d.ts +151 -3
  137. package/lib/cjs/transactionPlan/validateActions.d.ts +3 -1
  138. package/lib/cjs/transactionPlan/validateActions.js +31 -3
  139. package/lib/cjs/transactionPlan/validation.d.ts +1 -1
  140. package/lib/cjs/transactionPlan/validation.js +37 -1
  141. package/lib/cjs/transactionPlan/vaultBinding.d.ts +29 -0
  142. package/lib/cjs/transactionPlan/vaultBinding.js +69 -0
  143. package/lib/cjs/transactionPlan/vaultRequirements.d.ts +20 -0
  144. package/lib/cjs/transactionPlan/vaultRequirements.js +37 -0
  145. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +1 -1
  146. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -13
  147. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  148. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +10 -41
  149. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  150. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +6 -18
  151. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -12
  152. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  153. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -13
  154. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +1 -1
  155. package/lib/cjs/transactionPlan/vaultv2/deposit.js +2 -13
  156. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  157. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +4 -7
  158. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  159. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +12 -42
  160. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  161. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +10 -41
  162. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +1 -1
  163. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -13
  164. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  165. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -13
  166. package/lib/cjs/transactionPlan/withdraw.js +4 -7
  167. package/lib/cjs/types/error.d.ts +4 -1
  168. package/lib/cjs/types/error.js +5 -2
  169. package/lib/cjs/utils.d.ts +2 -2
  170. package/lib/cjs/utils.js +4 -2
  171. package/lib/cjs/version.d.ts +1 -1
  172. package/lib/cjs/version.js +1 -1
  173. package/lib/esm/abis.d.ts +1 -1
  174. package/lib/esm/abis.js +1 -1
  175. package/lib/esm/actions/blue/common.js +13 -4
  176. package/lib/esm/actions/midnight/redeem.d.ts +20 -3
  177. package/lib/esm/actions/midnight/redeem.js +56 -0
  178. package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
  179. package/lib/esm/actions/midnight/supplyCollateralWithNative.js +40 -0
  180. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -2
  181. package/lib/esm/actions/midnight/withdrawCollateral.js +25 -1
  182. package/lib/esm/blue/abis.d.ts +1 -1
  183. package/lib/esm/blue/abis.js +1 -1
  184. package/lib/esm/blue/entities.d.ts +4 -4
  185. package/lib/esm/blue/entities.js +2 -2
  186. package/lib/esm/blue/errors.d.ts +2 -2
  187. package/lib/esm/blue/errors.js +2 -2
  188. package/lib/esm/blue/fetch.d.ts +2 -2
  189. package/lib/esm/blue/fetch.js +2 -2
  190. package/lib/esm/blue/utils.d.ts +1 -1
  191. package/lib/esm/blue/utils.js +1 -1
  192. package/lib/esm/entities/index.d.ts +4 -4
  193. package/lib/esm/entities/index.js +2 -2
  194. package/lib/esm/entities/midnight/midnight.d.ts +100 -103
  195. package/lib/esm/entities/midnight/midnight.js +99 -99
  196. package/lib/esm/entities/vaultV1/vaultV1.js +0 -1
  197. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  198. package/lib/esm/entities/vaultV2/vaultV2.js +40 -3
  199. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -2
  200. package/lib/esm/entities/vaultV2BlueReallocationData.js +6 -2
  201. package/lib/esm/errors.d.ts +4 -4
  202. package/lib/esm/errors.js +4 -4
  203. package/lib/esm/fetch.d.ts +2 -2
  204. package/lib/esm/fetch.js +2 -2
  205. package/lib/esm/helpers/callback.d.ts +3 -2
  206. package/lib/esm/helpers/callback.js +5 -21
  207. package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
  208. package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.js +27 -0
  209. package/lib/esm/helpers/deadShares.js +4 -1
  210. package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
  211. package/lib/esm/helpers/parseMidnightMaker.js +40 -1
  212. package/lib/esm/helpers/validate.d.ts +60 -2
  213. package/lib/esm/helpers/validate.js +84 -1
  214. package/lib/esm/helpers/validateMidnightPublication.d.ts +10 -0
  215. package/lib/esm/helpers/validateMidnightPublication.js +16 -0
  216. package/lib/esm/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
  217. package/lib/esm/helpers/validateMidnightTakeableOfferFields.js +81 -0
  218. package/lib/esm/index.d.ts +2 -2
  219. package/lib/esm/index.js +1 -1
  220. package/lib/esm/midnight/errors.d.ts +2 -1
  221. package/lib/esm/midnight/errors.js +2 -1
  222. package/lib/esm/midnight/utils.d.ts +1 -1
  223. package/lib/esm/midnight/utils.js +1 -1
  224. package/lib/esm/transactionPlan/assemble.d.ts +24 -0
  225. package/lib/esm/transactionPlan/assemble.js +21 -0
  226. package/lib/esm/transactionPlan/blue/borrow.js +15 -65
  227. package/lib/esm/transactionPlan/blue/refinance.js +10 -12
  228. package/lib/esm/transactionPlan/blue/repay.js +11 -25
  229. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +50 -46
  230. package/lib/esm/transactionPlan/blue/stored.d.ts +26 -0
  231. package/lib/esm/transactionPlan/blue/stored.js +80 -0
  232. package/lib/esm/transactionPlan/blue/supply.js +7 -22
  233. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +1 -1
  234. package/lib/esm/transactionPlan/blue/supplyCollateral.js +10 -15
  235. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +15 -65
  236. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -3
  237. package/lib/esm/transactionPlan/blue/withdraw.js +70 -82
  238. package/lib/esm/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
  239. package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
  240. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +2 -3
  241. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +32 -31
  242. package/lib/esm/transactionPlan/deposit.js +5 -8
  243. package/lib/esm/transactionPlan/error.d.ts +27 -0
  244. package/lib/esm/transactionPlan/error.js +28 -0
  245. package/lib/esm/transactionPlan/index.d.ts +40 -1
  246. package/lib/esm/transactionPlan/index.js +20 -1
  247. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  248. package/lib/esm/transactionPlan/midnight/authorization.d.ts +15 -0
  249. package/lib/esm/transactionPlan/midnight/authorization.js +40 -0
  250. package/lib/esm/transactionPlan/midnight/cancelOffers.d.ts +80 -0
  251. package/lib/esm/transactionPlan/midnight/cancelOffers.js +120 -0
  252. package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +104 -0
  253. package/lib/esm/transactionPlan/midnight/makeBorrow.js +123 -0
  254. package/lib/esm/transactionPlan/midnight/makeLend.d.ts +140 -0
  255. package/lib/esm/transactionPlan/midnight/makeLend.js +172 -0
  256. package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +118 -0
  257. package/lib/esm/transactionPlan/midnight/makeRepay.js +115 -0
  258. package/lib/esm/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
  259. package/lib/esm/transactionPlan/midnight/makeWithdraw.js +123 -0
  260. package/lib/esm/transactionPlan/midnight/makerPublication.d.ts +55 -0
  261. package/lib/esm/transactionPlan/midnight/makerPublication.js +310 -0
  262. package/lib/esm/transactionPlan/midnight/market.d.ts +49 -0
  263. package/lib/esm/transactionPlan/midnight/market.js +112 -0
  264. package/lib/esm/transactionPlan/midnight/prepare.d.ts +244 -0
  265. package/lib/esm/transactionPlan/midnight/prepare.js +536 -0
  266. package/lib/esm/transactionPlan/midnight/publicationState.d.ts +24 -0
  267. package/lib/esm/transactionPlan/midnight/publicationState.js +47 -0
  268. package/lib/esm/transactionPlan/midnight/redeem.d.ts +102 -0
  269. package/lib/esm/transactionPlan/midnight/redeem.js +165 -0
  270. package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
  271. package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.js +47 -0
  272. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
  273. package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +323 -0
  274. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
  275. package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +196 -0
  276. package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
  277. package/lib/esm/transactionPlan/midnight/supplyCollateral.js +185 -0
  278. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
  279. package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +216 -0
  280. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
  281. package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +176 -0
  282. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
  283. package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +254 -0
  284. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +304 -0
  285. package/lib/esm/transactionPlan/midnight/takeBorrow.js +539 -0
  286. package/lib/esm/transactionPlan/midnight/takeLend.d.ts +99 -0
  287. package/lib/esm/transactionPlan/midnight/takeLend.js +258 -0
  288. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
  289. package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +435 -0
  290. package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
  291. package/lib/esm/transactionPlan/midnight/takeWithdraw.js +236 -0
  292. package/lib/esm/transactionPlan/midnight/validation.d.ts +22 -0
  293. package/lib/esm/transactionPlan/midnight/validation.js +151 -0
  294. package/lib/esm/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
  295. package/lib/esm/transactionPlan/midnight/withdrawCollateral.js +223 -0
  296. package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
  297. package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.js +227 -0
  298. package/lib/esm/transactionPlan/permit.d.ts +15 -2
  299. package/lib/esm/transactionPlan/permit.js +25 -68
  300. package/lib/esm/transactionPlan/plan.d.ts +99 -15
  301. package/lib/esm/transactionPlan/plan.js +154 -27
  302. package/lib/esm/transactionPlan/redeem.js +5 -8
  303. package/lib/esm/transactionPlan/requirements.d.ts +7 -4
  304. package/lib/esm/transactionPlan/requirements.js +2 -2
  305. package/lib/esm/transactionPlan/serde.d.ts +13 -2
  306. package/lib/esm/transactionPlan/serde.js +49 -2
  307. package/lib/esm/transactionPlan/types.d.ts +151 -3
  308. package/lib/esm/transactionPlan/validateActions.d.ts +3 -1
  309. package/lib/esm/transactionPlan/validateActions.js +31 -3
  310. package/lib/esm/transactionPlan/validation.d.ts +1 -1
  311. package/lib/esm/transactionPlan/validation.js +38 -2
  312. package/lib/esm/transactionPlan/vaultBinding.d.ts +29 -0
  313. package/lib/esm/transactionPlan/vaultBinding.js +65 -0
  314. package/lib/esm/transactionPlan/vaultRequirements.d.ts +20 -0
  315. package/lib/esm/transactionPlan/vaultRequirements.js +34 -0
  316. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +1 -1
  317. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -14
  318. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +2 -2
  319. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +12 -43
  320. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +1 -1
  321. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +9 -21
  322. package/lib/esm/transactionPlan/vaultv1/redeem.js +2 -13
  323. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +1 -1
  324. package/lib/esm/transactionPlan/vaultv1/withdraw.js +3 -14
  325. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +1 -1
  326. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -14
  327. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +1 -1
  328. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +5 -8
  329. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +2 -2
  330. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +15 -45
  331. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +2 -2
  332. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +12 -43
  333. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +1 -1
  334. package/lib/esm/transactionPlan/vaultv2/redeem.js +3 -14
  335. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +1 -1
  336. package/lib/esm/transactionPlan/vaultv2/withdraw.js +3 -14
  337. package/lib/esm/transactionPlan/withdraw.js +5 -8
  338. package/lib/esm/types/error.d.ts +4 -1
  339. package/lib/esm/types/error.js +5 -2
  340. package/lib/esm/utils.d.ts +2 -2
  341. package/lib/esm/utils.js +2 -2
  342. package/lib/esm/version.d.ts +1 -1
  343. package/lib/esm/version.js +1 -1
  344. package/package.json +7 -7
@@ -163,22 +163,22 @@ export class MorphoMidnight {
163
163
  * On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
164
164
  * above one are dropped from the transaction because one of them would revert the whole bundle.
165
165
  *
166
- * @param params - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
167
- * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
168
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
169
- * @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
170
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
166
+ * @param raw - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
167
+ * @param raw.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
168
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
169
+ * @param raw.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
170
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
171
171
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
172
172
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
173
173
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
174
174
  * required for the full pulled amount.
175
- * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
176
- * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
175
+ * @param raw.takeableOffers - Borrow-side offers returned by the Midnight API.
176
+ * @param raw.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
177
177
  * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
178
178
  * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
179
- * @param params.deadline - Bundle execution deadline timestamp.
180
- * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
181
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
179
+ * @param raw.deadline - Bundle execution deadline timestamp.
180
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
181
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
182
182
  * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
183
183
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
184
184
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -226,7 +226,7 @@ export class MorphoMidnight {
226
226
  * marketData,
227
227
  * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
228
228
  * takeableOffers: quote.data.takeableOffers,
229
- * maxContinuousFee: maxUint256,
229
+ * maxContinuousFee: BigInt(marketData.continuousFee),
230
230
  * now: (await client.getBlock()).timestamp,
231
231
  * deadline: (await client.getBlock()).timestamp + 600n,
232
232
  * });
@@ -286,26 +286,26 @@ export class MorphoMidnight {
286
286
  * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
287
287
  * revert the whole bundle.
288
288
  *
289
- * @param params - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
290
- * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
291
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
292
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
289
+ * @param raw - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
290
+ * @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
291
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
292
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
293
293
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
294
294
  * does not see transactions mined or prices moved since, so two transactions built from one
295
295
  * snapshot can together end inside the buffer. Midnight still rejects any position above
296
296
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
297
- * @param params.collateralPrices - Values from `price()` on each
297
+ * @param raw.collateralPrices - Values from `price()` on each
298
298
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
299
299
  * scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
300
300
  * index, because debt after a borrow is always positive.
301
- * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
302
- * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
301
+ * @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
302
+ * @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
303
303
  * Midnight protocol and market token contracts are rejected.
304
- * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
305
- * @param params.deadline - Bounded bundle execution deadline timestamp.
306
- * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the sale
304
+ * @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
305
+ * @param raw.deadline - Bounded bundle execution deadline timestamp.
306
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
307
307
  * proceeds; on an assets target it is added on top of `target.assets`.
308
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
308
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
309
309
  * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
310
310
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
311
311
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -431,17 +431,17 @@ export class MorphoMidnight {
431
431
  * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
432
432
  * revert the whole bundle.
433
433
  *
434
- * @param params - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
435
- * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
436
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
437
- * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
438
- * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
434
+ * @param raw - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
435
+ * @param raw.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
436
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
437
+ * @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
438
+ * @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
439
439
  * Midnight protocol and market token contracts are rejected.
440
- * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
441
- * @param params.deadline - Bundle execution deadline timestamp.
442
- * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the sale
440
+ * @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
441
+ * @param raw.deadline - Bundle execution deadline timestamp.
442
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
443
443
  * proceeds; on an assets target it is added on top of `target.assets`.
444
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
444
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
445
445
  * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
446
446
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
447
447
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -528,32 +528,32 @@ export class MorphoMidnight {
528
528
  * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
529
529
  * revert the whole bundle.
530
530
  *
531
- * @param params - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
532
- * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
533
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
534
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
531
+ * @param raw - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
532
+ * @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
533
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
534
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
535
535
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
536
536
  * does not see transactions mined or prices moved since, so two transactions built from one
537
537
  * snapshot can together end inside the buffer. Midnight still rejects any position above
538
538
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
539
- * @param params.collateralPrices - Values from `price()` on each
539
+ * @param raw.collateralPrices - Values from `price()` on each
540
540
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
541
541
  * scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
542
542
  * index, because debt after a borrow is always positive.
543
- * @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
544
- * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
545
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
543
+ * @param raw.collateralSupplies - Collateral index and assets per supply; must not be empty.
544
+ * @param raw.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
545
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
546
546
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
547
547
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
548
548
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
549
549
  * required for the full pulled amount.
550
- * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
550
+ * @param raw.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
551
551
  * Midnight protocol and market token contracts are rejected.
552
- * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
553
- * @param params.deadline - Bounded bundle execution deadline timestamp.
554
- * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the sale
552
+ * @param raw.takeableOffers - Lend-side offers returned by the Midnight API.
553
+ * @param raw.deadline - Bounded bundle execution deadline timestamp.
554
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee taken from the sale
555
555
  * proceeds; on an assets target it is added on top of `target.assets`.
556
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
556
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
557
557
  * @returns Lazy collateral approvals and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
558
558
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
559
559
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
@@ -696,37 +696,37 @@ export class MorphoMidnight {
696
696
  * On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
697
697
  * above one are dropped from the transaction because one of them would revert the whole bundle.
698
698
  *
699
- * @param params - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
700
- * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
701
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
702
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
699
+ * @param raw - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
700
+ * @param raw.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
701
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
702
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
703
703
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
704
704
  * does not see transactions mined or prices moved since, so two transactions built from one
705
705
  * snapshot can together end inside the buffer. Midnight still rejects any position above
706
706
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
707
- * @param params.collateralPrices - Values from `price()` on each
707
+ * @param raw.collateralPrices - Values from `price()` on each
708
708
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
709
709
  * scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
710
710
  * `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a units
711
711
  * `target` covering `positionData.debt`, or an assets target whose `minUnits` covers it.
712
- * @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).
713
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
712
+ * @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).
713
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
714
714
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
715
715
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
716
716
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
717
717
  * required for the full pulled amount.
718
- * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
719
- * @param params.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
720
- * @param params.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
721
- * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
718
+ * @param raw.takeableOffers - Borrow-side offers returned by the Midnight API.
719
+ * @param raw.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
720
+ * @param raw.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
721
+ * @param raw.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
722
722
  * must be non-zero and not a Midnight protocol or market token contract when
723
723
  * `collateralWithdrawals` is non-empty, and is unused otherwise.
724
- * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
724
+ * @param raw.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
725
725
  * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
726
726
  * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
727
- * @param params.deadline - Bundle execution deadline timestamp.
728
- * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
729
- * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
727
+ * @param raw.deadline - Bundle execution deadline timestamp.
728
+ * @param raw.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
729
+ * @param raw.referralFeeRecipient - Referral fee recipient; required with a positive fee.
730
730
  * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
731
731
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
732
732
  * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
@@ -790,7 +790,7 @@ export class MorphoMidnight {
790
790
  * takeableOffers: quote.data.takeableOffers,
791
791
  * repayEnabled: true,
792
792
  * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
793
- * maxContinuousFee: maxUint256,
793
+ * maxContinuousFee: BigInt(marketData.continuousFee),
794
794
  * now: (await client.getBlock()).timestamp,
795
795
  * deadline: (await client.getBlock()).timestamp + 600n,
796
796
  * });
@@ -890,18 +890,18 @@ export class MorphoMidnight {
890
890
  * Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
891
891
  * No requirements or RPC reads are needed. The signing account must be accountAddress.
892
892
  *
893
- * @param params - Market, owner-bound position, collateral prices and withdrawal amount.
894
- * @param params.accountAddress - Collateral owner. This account must send the transaction.
895
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
896
- * @param params.positionData - Owner-bound position snapshot returned by getPositionData.
897
- * @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
893
+ * @param raw - Market, owner-bound position, collateral prices and withdrawal amount.
894
+ * @param raw.accountAddress - Collateral owner. This account must send the transaction.
895
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
896
+ * @param raw.positionData - Owner-bound position snapshot returned by getPositionData.
897
+ * @param raw.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
898
898
  * ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
899
- * @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
899
+ * @param raw.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
900
900
  * market's collateral parameters, which Midnight sorts by token address, not the order they were
901
901
  * listed in when the market was built; check marketData.getCollateralByIndex(index).token.
902
- * @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
902
+ * @param raw.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
903
903
  * the selected collateral from positionData before building the transaction.
904
- * @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
904
+ * @param raw.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
905
905
  * @returns Lazy handles for a direct Midnight withdrawal.
906
906
  * @throws {ChainIdMismatchError} when the client or market targets another chain.
907
907
  * @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
@@ -970,15 +970,15 @@ export class MorphoMidnight {
970
970
  * Duplicates are rejected, unlike bundle flows which sum them.
971
971
  * No requirements or RPC reads are needed. The signing account must be accountAddress.
972
972
  *
973
- * @param params - Market, owner-bound position, collateral prices and withdrawal amount.
974
- * @param params.accountAddress - Collateral owner. This account must send the transaction.
975
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
976
- * @param params.positionData - Owner-bound position snapshot returned by getPositionData.
977
- * @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
973
+ * @param raw - Market, owner-bound position, collateral prices and withdrawal amount.
974
+ * @param raw.accountAddress - Collateral owner. This account must send the transaction.
975
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
976
+ * @param raw.positionData - Owner-bound position snapshot returned by getPositionData.
977
+ * @param raw.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
978
978
  * ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
979
- * @param params.collateralWithdrawals - Nonempty ordered withdrawals, one per index.
979
+ * @param raw.collateralWithdrawals - Nonempty ordered withdrawals, one per index.
980
980
  * maxUint256 resolves that index's full snapshot balance.
981
- * @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
981
+ * @param raw.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
982
982
  * @returns Lazy handles for a direct Midnight withdrawal.
983
983
  * @throws {ChainIdMismatchError} when the client or market targets another chain.
984
984
  * @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
@@ -1048,18 +1048,18 @@ export class MorphoMidnight {
1048
1048
  /**
1049
1049
  * Prepares a direct collateral supply using a caller-provided market snapshot.
1050
1050
  *
1051
- * @param params.accountAddress - Account receiving the supplied collateral position. It must send
1051
+ * @param raw.accountAddress - Account receiving the supplied collateral position. It must send
1052
1052
  * the transaction: Midnight pulls the collateral from `msg.sender` and only lets the position owner
1053
1053
  * or its operators supply for it, and the approval requirements are resolved for this account.
1054
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
1055
- * @param params.collateralAssets - Collateral assets supplied in this transaction.
1056
- * @param params.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
1054
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
1055
+ * @param raw.collateralAssets - Collateral assets supplied in this transaction.
1056
+ * @param raw.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
1057
1057
  * Only raises the approval requirement so those groups keep their allowance; the transaction
1058
1058
  * transfers only `collateralAssets`.
1059
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`. Indexes follow the
1059
+ * @param raw.collateralIndex - Optional collateral index; defaults to `0n`. Indexes follow the
1060
1060
  * market's collateral parameters, which Midnight sorts by token address, not the order they were
1061
1061
  * listed in when the market was built; check `marketData.getCollateralByIndex(index).token`.
1062
- * @param params.now - Optional reference timestamp in seconds; used for metadata only when the
1062
+ * @param raw.now - Optional reference timestamp in seconds; used for metadata only when the
1063
1063
  * client sets `metadata.timestamp: true`.
1064
1064
  * @returns Lazy token-approval requirements and a synchronous transaction builder.
1065
1065
  * @throws {NegativeInputError} when the resolved metadata timestamp is negative, or the reserve is negative.
@@ -1257,9 +1257,9 @@ export class MorphoMidnight {
1257
1257
  * Prepares ordered direct collateral supplies in one Midnight multicall.
1258
1258
  * Pass one entry per index: duplicates are rejected, unlike bundle flows which sum them.
1259
1259
  *
1260
- * @param params.accountAddress - Sender and collateral beneficiary.
1261
- * @param params.marketData - Snapshot of the target market.
1262
- * @param params.collateralSupplies - Ordered supplies with optional reserved allowance amounts.
1260
+ * @param raw.accountAddress - Sender and collateral beneficiary.
1261
+ * @param raw.marketData - Snapshot of the target market.
1262
+ * @param raw.collateralSupplies - Ordered supplies with optional reserved allowance amounts.
1263
1263
  * @returns A lazy approval resolver and synchronous stateless transaction builder.
1264
1264
  * @throws {ChainIdMismatchError} when the client or market targets another chain.
1265
1265
  * @throws {MidnightMarketAddressMismatchError} when the deployment differs.
@@ -1908,14 +1908,14 @@ export class MorphoMidnight {
1908
1908
  /**
1909
1909
  * Prepares redemption of accrued Midnight credit from a position snapshot.
1910
1910
  *
1911
- * @param params - Position owner, accrued position, optional unit amount, and receiver.
1912
- * @param params.accountAddress - Position owner whose credit is redeemed. It must send the
1911
+ * @param raw - Position owner, accrued position, optional unit amount, and receiver.
1912
+ * @param raw.accountAddress - Position owner whose credit is redeemed. It must send the
1913
1913
  * transaction (or authorize the sender): Midnight reverts `Unauthorized()` otherwise, which
1914
1914
  * `getRequirements()` cannot detect because it does not know the sender.
1915
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`.
1916
- * @param params.receiver - Optional credit receiver; defaults to the position owner.
1915
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`.
1916
+ * @param raw.receiver - Optional credit receiver; defaults to the position owner.
1917
1917
  * Midnight protocol and market token contracts are rejected.
1918
- * @param params.units - Optional credit units to redeem; defaults to the position face value.
1918
+ * @param raw.units - Optional credit units to redeem; defaults to the position face value.
1919
1919
  * Credit is checked after applying the realized losses and continuous fees that Midnight
1920
1920
  * charges before a withdrawal, accrued up to now. Fees keep accruing until maturity, so `units` close to the accrued
1921
1921
  * credit can still revert when the transaction lands later. The default face value does not
@@ -1964,30 +1964,30 @@ export class MorphoMidnight {
1964
1964
  /**
1965
1965
  * Prepares a direct `MidnightBundlesV2` repayment, collateral withdrawal, or both, for `accountAddress`.
1966
1966
  *
1967
- * @param params - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
1968
- * @param params.accountAddress - Position owner and transaction sender.
1969
- * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
1970
- * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
1967
+ * @param raw - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
1968
+ * @param raw.accountAddress - Position owner and transaction sender.
1969
+ * @param raw.marketData - Hydrated market snapshot used for validation and transaction construction.
1970
+ * @param raw.positionData - Owner-bound position snapshot returned by `getPositionData`. The
1971
1971
  * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
1972
1972
  * does not see transactions mined or prices moved since, so two transactions built from one
1973
1973
  * snapshot can together end inside the buffer. Midnight still rejects any position above
1974
1974
  * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
1975
- * @param params.collateralPrices - Values from `price()` on each
1975
+ * @param raw.collateralPrices - Values from `price()` on each
1976
1976
  * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
1977
1977
  * scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
1978
1978
  * `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a `full`
1979
1979
  * repay, or `repay.assets` covering `positionData.debt`.
1980
- * @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.
1981
- * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
1980
+ * @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.
1981
+ * @param raw.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
1982
1982
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
1983
1983
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
1984
1984
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
1985
1985
  * required for the full pulled amount.
1986
- * @param params.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
1987
- * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
1986
+ * @param raw.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
1987
+ * @param raw.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
1988
1988
  * must be non-zero and not a Midnight protocol or market token contract when
1989
1989
  * `collateralWithdrawals` is non-empty, and is unused otherwise.
1990
- * @param params.deadline - Bundle execution deadline timestamp. Unlike taker builders,
1990
+ * @param raw.deadline - Bundle execution deadline timestamp. Unlike taker builders,
1991
1991
  * `maxUint256` is accepted because no offers are filled; the pull remains bounded by
1992
1992
  * `repay.assets` or `repay.maxBuyerAssets`.
1993
1993
  * @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
@@ -195,7 +195,6 @@ export class MorphoVaultV1 {
195
195
  if (amount <= 0n) {
196
196
  throw new NonPositiveInputError("amount", amount);
197
197
  }
198
- // Reject values outside the ABI range before resolving any requirements.
199
198
  const parsedAmount = parseUint256("amount", amount);
200
199
  const createdAt = suppliedNow ?? Time.timestamp();
201
200
  const deadline = params.deadline ?? createdAt + 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
@@ -14,7 +14,7 @@ import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChain
14
14
  import { resolveTransactionMetadata } from "../../helpers/metadata.js";
15
15
  import { parseUint256 } from "../../helpers/parse.js";
16
16
  import { validateNativeVaultAsset, validateReferenceTime, validateVaultDepositDeadline, } from "../../helpers/validate.js";
17
- import { ExpiredDeadlineError, NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
17
+ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
18
18
  import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
19
19
  import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
20
20
  import { getParsedVaultBundlesSharesRequirements, parseVaultBundlesSharesRequirements, } from "../requirements/getVaultBundlesSharesRequirements.js";
@@ -23,6 +23,16 @@ import { getVaultV2InKindRedeemRequirements } from "../requirements/getVaultV2In
23
23
  import { validateNativeRequirements } from "../requirements/validateNativeRequirements.js";
24
24
  import { computeVaultV2ForceWithdrawQuote } from "./forceWithdrawQuote.js";
25
25
  import { computeVaultV2InKindRedeemQuote } from "./inKindRedeemQuote.js";
26
+ /**
27
+ * Midnight adapters revert vault-initiated `allocate` (`SelfAllocationOnly`), so a vault routing
28
+ * liquidity through one accepts no deposit. Exits are served from idle assets plus what the adapter's
29
+ * `withdrawToVault` path can withdraw from the liquidity market.
30
+ */
31
+ const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
32
+ /** Idle assets plus what the Midnight liquidity adapter can withdraw to the vault onchain. */
33
+ const midnightWithdrawLiquidity = (vaultData) => vaultData.assetBalance +
34
+ (vaultData.accrualLiquidityAdapter?.maxWithdraw(vaultData.liquidityData)
35
+ .value ?? 0n);
26
36
  /** Binds a viem client to a Vault V2 vault's action builders. */
27
37
  export class MorphoVaultV2 {
28
38
  client;
@@ -91,6 +101,13 @@ export class MorphoVaultV2 {
91
101
  if (funding.value > 0n) {
92
102
  validateNativeVaultAsset(this.chainId, vaultAsset);
93
103
  }
104
+ if (isMidnightLiquidityAdapter(vaultData)) {
105
+ throw new InputExceedsMaxError({
106
+ field: funding.value > 0n ? "nativeAmount" : "amount",
107
+ value: funding.assets,
108
+ max: 0n,
109
+ });
110
+ }
94
111
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
95
112
  // Bound forward accrual before deriving the deposit price protection.
96
113
  validateVaultDepositDeadline(deadline, { now: createdAt });
@@ -196,8 +213,15 @@ export class MorphoVaultV2 {
196
213
  if (amount <= 0n) {
197
214
  throw new NonPositiveInputError("amount", amount);
198
215
  }
199
- // Reject values outside the ABI range before resolving any requirements.
200
216
  const parsedAmount = parseUint256("amount", amount);
217
+ if (isMidnightLiquidityAdapter(vaultData) &&
218
+ amount > midnightWithdrawLiquidity(vaultData)) {
219
+ throw new InputExceedsMaxError({
220
+ field: "amount",
221
+ value: amount,
222
+ max: midnightWithdrawLiquidity(vaultData),
223
+ });
224
+ }
201
225
  const createdAt = suppliedNow ?? Time.timestamp();
202
226
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
203
227
  if (deadline <= createdAt) {
@@ -307,8 +331,21 @@ export class MorphoVaultV2 {
307
331
  }
308
332
  const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
309
333
  await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
334
+ const vaultData = await this.getDataWithChainCheck(chainCheck);
335
+ if (isMidnightLiquidityAdapter(vaultData)) {
336
+ // Onchain redeem accrues interest before converting shares to assets.
337
+ const { vault: accrued } = vaultData.accrueInterest(now);
338
+ const liquidity = midnightWithdrawLiquidity(accrued);
339
+ if (accrued.toAssets(shares) > liquidity) {
340
+ throw new InputExceedsMaxError({
341
+ field: "shares",
342
+ value: shares,
343
+ max: accrued.toShares(liquidity),
344
+ });
345
+ }
346
+ }
310
347
  return getParsedVaultBundlesSharesRequirements({ viemClient: this.client.viemClient, chainCheck }, parseVaultBundlesSharesRequirements(this.client.viemClient, {
311
- vaultData: await this.getDataWithChainCheck(chainCheck),
348
+ vaultData,
312
349
  version: "vaultV2",
313
350
  owner: userAddress,
314
351
  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";
@@ -80,6 +80,9 @@ const cloneAccrualVault = (vault, markets) => new AccrualVault({
80
80
  position: clonePosition(position, markets),
81
81
  })));
82
82
  const cloneAdapter = (adapter, markets) => {
83
+ if (adapter.type === "VaultV2MidnightAdapter") {
84
+ return adapter;
85
+ }
83
86
  const base = {
84
87
  address: adapter.address,
85
88
  parentVault: adapter.parentVault,
@@ -131,7 +134,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
131
134
  /**
132
135
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
133
136
  *
134
- * Constructor inputs are cloned. Every simulated reallocation returns a new
137
+ * Constructor inputs are cloned, except read-only Midnight adapter snapshots, which are
138
+ * shared by reference. Every simulated reallocation returns a new
135
139
  * instance. Planning keeps the transaction-scoped `firstTotalAssets`
136
140
  * denominator outside the durable snapshot while applying reallocations in
137
141
  * contract order. Penalty donations update simulated vault accounting but are
@@ -262,7 +266,7 @@ export class VaultV2BlueReallocationData {
262
266
  /**
263
267
  * Clones the complete simulation snapshot.
264
268
  *
265
- * @returns A deep clone of this simulation state.
269
+ * @returns A deep clone of this simulation state; read-only Midnight adapter snapshots are shared by reference.
266
270
  * @example
267
271
  * ```ts
268
272
  * import { markets } from "@morpho-org/morpho-test";