@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
@@ -5,12 +5,14 @@ exports.validateVaultPermitRequest = validateVaultPermitRequest;
5
5
  exports.validateTokenPermitRequest = validateTokenPermitRequest;
6
6
  exports.getSignedTokenPermit = getSignedTokenPermit;
7
7
  exports.getVaultPermit = getSignedTokenPermit;
8
+ exports.selectVaultPermit = selectVaultPermit;
8
9
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
9
10
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
10
11
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
11
- const viem_1 = require("viem");
12
+ const common_js_1 = require("../actions/bundles/common.js");
12
13
  const error_js_1 = require("./error.js");
13
14
  const validation_js_1 = require("./validation.js");
15
+ const vaultBinding_js_1 = require("./vaultBinding.js");
14
16
  /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
15
17
  function validatePermitPlanRequest(request, path) {
16
18
  const args = (0, validation_js_1.getPlanObject)(request.args, `${path}.args`);
@@ -83,72 +85,10 @@ function validatePermitPlanRequest(request, path) {
83
85
  }
84
86
  /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
85
87
  function validateVaultPermitRequest(request, action) {
86
- if (request.kind !== "permit") {
88
+ if (request.kind !== "permit" || !(0, vaultBinding_js_1.isVaultPermitAction)(action)) {
87
89
  throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
88
90
  }
89
- let spenderKey;
90
- let asset;
91
- let amount;
92
- let exact = false;
93
- switch (action.type) {
94
- case "vaultV2Deposit":
95
- spenderKey = "bundles.vaultBundlesV1";
96
- asset = action.inputs.asset;
97
- amount = action.inputs.assets;
98
- exact = true;
99
- break;
100
- case "vaultV1Deposit":
101
- spenderKey = "bundles.vaultBundlesV1";
102
- asset = action.inputs.asset;
103
- amount = action.inputs.assets;
104
- exact = true;
105
- break;
106
- case "vaultV1Withdraw":
107
- spenderKey = "bundles.vaultBundlesV1";
108
- asset = action.inputs.vault;
109
- amount = action.inputs.requiredShareAllowance;
110
- break;
111
- case "vaultV2Withdraw":
112
- spenderKey = "bundles.vaultBundlesV1";
113
- asset = action.inputs.vault;
114
- amount = action.inputs.requiredShareAllowance;
115
- break;
116
- case "vaultV2Redeem":
117
- spenderKey = "bundles.vaultBundlesV1";
118
- asset = action.inputs.vault;
119
- amount = action.inputs.shares;
120
- break;
121
- case "vaultV1Redeem":
122
- spenderKey = "bundles.vaultBundlesV1";
123
- asset = action.inputs.vault;
124
- amount = action.inputs.shares;
125
- break;
126
- case "vaultV2ForceWithdraw":
127
- spenderKey = "bundles.vaultExitBundlesV1";
128
- asset = action.inputs.vault;
129
- amount = viem_1.maxUint256;
130
- exact = true;
131
- break;
132
- case "vaultV1MigrateToV2":
133
- spenderKey = "bundles.vaultBundlesV1";
134
- asset = action.inputs.sourceVault;
135
- amount = action.inputs.requiredShareAllowance;
136
- break;
137
- case "vaultV2InKindRedeem":
138
- spenderKey = "bundles.vaultExitBundlesV1";
139
- asset = action.inputs.vault;
140
- amount = viem_1.maxUint256;
141
- exact = true;
142
- break;
143
- case "vaultV1InKindRedeem":
144
- spenderKey = "bundles.vaultExitBundlesV1";
145
- asset = action.inputs.vault;
146
- amount = viem_1.maxUint256;
147
- exact = true;
148
- break;
149
- default:
150
- throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
151
- }
91
+ const { bundler, asset, restore } = (0, vaultBinding_js_1.getVaultPermitBinding)(action);
152
92
  if (action.signatureRequestIds.tokenPermit !== request.id) {
153
93
  throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
154
94
  }
@@ -156,10 +96,10 @@ function validateVaultPermitRequest(request, action) {
156
96
  chainId: action.inputs.chainId,
157
97
  account: action.inputs.account,
158
98
  deadline: action.inputs.deadline,
159
- bundler: spenderKey,
99
+ bundler,
160
100
  asset,
161
- amount,
162
- exact,
101
+ amount: restore.amount,
102
+ exact: restore.exact,
163
103
  });
164
104
  }
165
105
  /** @internal Binds the signing payload and encoding arguments to a registered bundle's token pull. */
@@ -241,3 +181,21 @@ function getSignedTokenPermit(requests, { id, asset, owner, }) {
241
181
  },
242
182
  };
243
183
  }
184
+ function selectVaultPermit(action, requests) {
185
+ const { chainId, account, deadline } = action.inputs;
186
+ const { bundler, asset, build } = (0, vaultBinding_js_1.getVaultPermitBinding)(action);
187
+ const signature = getSignedTokenPermit(requests, {
188
+ id: action.signatureRequestIds.tokenPermit,
189
+ asset,
190
+ owner: account,
191
+ });
192
+ const signatures = signature ? [signature] : [];
193
+ const expected = {
194
+ spender: (0, morpho_ts_1.getChainAddress)(chainId, bundler),
195
+ amount: build.amount,
196
+ deadline,
197
+ };
198
+ return build.pull === "token"
199
+ ? (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expected)
200
+ : (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, expected);
201
+ }
@@ -57,6 +57,56 @@ export declare function verifyPlanSignature(request: SignatureRequest, signature
57
57
  * ```
58
58
  */
59
59
  export declare function getPendingSignatureRequests(plan: TransactionPlan): readonly SignatureRequest[];
60
+ /**
61
+ * @internal Whether a step's transaction carries the plan's `calldataOrigin`. Operation steps do;
62
+ * approval and authorization prerequisites never do, matching the entity path. Every action type
63
+ * must be listed, so a new type does not compile until its role is chosen.
64
+ */
65
+ export declare const CALLDATA_ORIGIN_ROLE: {
66
+ readonly blueBorrow: "operation";
67
+ readonly blueRefinance: "operation";
68
+ readonly blueRepay: "operation";
69
+ readonly blueRepayWithdrawCollateral: "operation";
70
+ readonly blueSupply: "operation";
71
+ readonly blueSupplyCollateral: "operation";
72
+ readonly blueSupplyCollateralBorrow: "operation";
73
+ readonly blueWithdraw: "operation";
74
+ readonly blueWithdrawBuyCallback: "operation";
75
+ readonly blueWithdrawCollateral: "operation";
76
+ readonly erc20Approval: "prerequisite";
77
+ readonly midnightAuthorization: "prerequisite";
78
+ readonly midnightCancelOffers: "operation";
79
+ readonly midnightMakeBorrow: "operation";
80
+ readonly midnightMakeLend: "operation";
81
+ readonly midnightMakeRepay: "operation";
82
+ readonly midnightMakeWithdraw: "operation";
83
+ readonly midnightRedeem: "operation";
84
+ readonly midnightRepayWithdrawCollateral: "operation";
85
+ readonly midnightSupplyBlueMakeLend: "operation";
86
+ readonly midnightSupplyCollateral: "operation";
87
+ readonly midnightSupplyCollateralBatch: "operation";
88
+ readonly midnightSupplyCollateralMakeBorrow: "operation";
89
+ readonly midnightSupplyCollateralTakeBorrow: "operation";
90
+ readonly midnightSupplyCollateralWithNative: "operation";
91
+ readonly midnightTakeBorrow: "operation";
92
+ readonly midnightTakeLend: "operation";
93
+ readonly midnightTakeRepayWithdrawCollateral: "operation";
94
+ readonly midnightTakeWithdraw: "operation";
95
+ readonly midnightWithdrawCollateral: "operation";
96
+ readonly midnightWithdrawCollateralBatch: "operation";
97
+ readonly morphoAuthorization: "prerequisite";
98
+ readonly vaultV1Deposit: "operation";
99
+ readonly vaultV1InKindRedeem: "operation";
100
+ readonly vaultV1MigrateToV2: "operation";
101
+ readonly vaultV1Redeem: "operation";
102
+ readonly vaultV1Withdraw: "operation";
103
+ readonly vaultV2Deposit: "operation";
104
+ readonly vaultV2ForceRedeem: "operation";
105
+ readonly vaultV2ForceWithdraw: "operation";
106
+ readonly vaultV2InKindRedeem: "operation";
107
+ readonly vaultV2Redeem: "operation";
108
+ readonly vaultV2Withdraw: "operation";
109
+ };
60
110
  /**
61
111
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
62
112
  * Builds one transaction from a step, its fixed inputs and the signatures its action names.
@@ -68,17 +118,25 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
68
118
  * not operation amounts, market parameters or referral fees/recipients. Protect those unsigned fields.
69
119
  * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
70
120
  * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
71
- * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
72
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
73
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
121
+ * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set, except for ERC-20 approval, Morpho authorization and Midnight authorization prerequisite steps.
122
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
123
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
74
124
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
75
125
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
76
126
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
77
127
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
78
128
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
79
129
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
80
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
130
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
81
131
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
132
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
133
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
134
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
135
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
136
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
137
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
138
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
139
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
82
140
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
83
141
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
84
142
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -90,8 +148,10 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
90
148
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
91
149
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
92
150
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
93
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
94
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
151
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
152
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
153
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
154
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
95
155
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
96
156
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
97
157
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -104,8 +164,15 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
104
164
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
105
165
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
106
166
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
107
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
108
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
167
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
168
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
169
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
170
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
171
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
172
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
173
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
174
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
175
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
109
176
  * @example
110
177
  * ```ts
111
178
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -121,16 +188,23 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
121
188
  * Builds every step of the plan in order.
122
189
  * @param plan - Plan whose referenced signature requests all carry a signature.
123
190
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
124
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
125
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
191
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
192
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
126
193
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
127
194
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
128
195
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
129
196
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
130
197
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
131
198
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
132
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
199
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
133
200
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
201
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
202
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
203
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
204
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
205
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
206
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
207
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
134
208
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
135
209
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
136
210
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -139,11 +213,14 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
139
213
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
140
214
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
141
215
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
216
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
142
217
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
143
218
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
144
219
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
145
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
146
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
220
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
221
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
222
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
223
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
147
224
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
148
225
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
149
226
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -156,8 +233,15 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
156
233
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
157
234
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
158
235
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
159
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
160
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
236
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
237
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
238
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
239
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
240
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
241
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
242
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
243
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
244
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
161
245
  * @example
162
246
  * ```ts
163
247
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CALLDATA_ORIGIN_ROLE = void 0;
3
4
  exports.applySignatures = applySignatures;
4
5
  exports.verifyPlanSignature = verifyPlanSignature;
5
6
  exports.getPendingSignatureRequests = getPendingSignatureRequests;
@@ -21,21 +22,37 @@ const supply_js_1 = require("./blue/supply.js");
21
22
  const supplyCollateral_js_1 = require("./blue/supplyCollateral.js");
22
23
  const supplyCollateralBorrow_js_1 = require("./blue/supplyCollateralBorrow.js");
23
24
  const withdraw_js_1 = require("./blue/withdraw.js");
25
+ const withdrawBuyCallback_js_1 = require("./blue/withdrawBuyCallback.js");
24
26
  const withdrawCollateral_js_1 = require("./blue/withdrawCollateral.js");
25
27
  const error_js_2 = require("./error.js");
28
+ const authorization_js_2 = require("./midnight/authorization.js");
29
+ const cancelOffers_js_1 = require("./midnight/cancelOffers.js");
30
+ const makerPublication_js_1 = require("./midnight/makerPublication.js");
31
+ const redeem_js_1 = require("./midnight/redeem.js");
32
+ const repayWithdrawCollateral_js_2 = require("./midnight/repayWithdrawCollateral.js");
33
+ const supplyCollateral_js_2 = require("./midnight/supplyCollateral.js");
34
+ const supplyCollateralBatch_js_1 = require("./midnight/supplyCollateralBatch.js");
35
+ const supplyCollateralWithNative_js_1 = require("./midnight/supplyCollateralWithNative.js");
36
+ const takeBorrow_js_1 = require("./midnight/takeBorrow.js");
37
+ const takeLend_js_1 = require("./midnight/takeLend.js");
38
+ const takeRepayWithdrawCollateral_js_1 = require("./midnight/takeRepayWithdrawCollateral.js");
39
+ const takeWithdraw_js_1 = require("./midnight/takeWithdraw.js");
40
+ const withdrawCollateral_js_2 = require("./midnight/withdrawCollateral.js");
41
+ const withdrawCollateralBatch_js_1 = require("./midnight/withdrawCollateralBatch.js");
26
42
  const permit_js_1 = require("./permit.js");
27
43
  const validateActions_js_1 = require("./validateActions.js");
28
44
  const validation_js_1 = require("./validation.js");
45
+ const vaultBinding_js_1 = require("./vaultBinding.js");
29
46
  const deposit_js_1 = require("./vaultv1/deposit.js");
30
47
  const inKindRedeem_js_1 = require("./vaultv1/inKindRedeem.js");
31
48
  const migrateToV2_js_1 = require("./vaultv1/migrateToV2.js");
32
- const redeem_js_1 = require("./vaultv1/redeem.js");
49
+ const redeem_js_2 = require("./vaultv1/redeem.js");
33
50
  const withdraw_js_2 = require("./vaultv1/withdraw.js");
34
51
  const deposit_js_2 = require("./vaultv2/deposit.js");
35
52
  const forceRedeem_js_1 = require("./vaultv2/forceRedeem.js");
36
53
  const forceWithdraw_js_1 = require("./vaultv2/forceWithdraw.js");
37
54
  const inKindRedeem_js_2 = require("./vaultv2/inKindRedeem.js");
38
- const redeem_js_2 = require("./vaultv2/redeem.js");
55
+ const redeem_js_3 = require("./vaultv2/redeem.js");
39
56
  const withdraw_js_3 = require("./vaultv2/withdraw.js");
40
57
  const version_js_1 = require("./version.js");
41
58
  /**
@@ -236,17 +253,7 @@ function validateSignatureRequest(request, action) {
236
253
  nonce: action.inputs.authorizationNonce,
237
254
  });
238
255
  }
239
- if (request.kind === "permit" &&
240
- (action.type === "vaultV2Deposit" ||
241
- action.type === "vaultV1Deposit" ||
242
- action.type === "vaultV1Withdraw" ||
243
- action.type === "vaultV2Withdraw" ||
244
- action.type === "vaultV2Redeem" ||
245
- action.type === "vaultV1Redeem" ||
246
- action.type === "vaultV2ForceWithdraw" ||
247
- action.type === "vaultV1MigrateToV2" ||
248
- action.type === "vaultV2InKindRedeem" ||
249
- action.type === "vaultV1InKindRedeem")) {
256
+ if (request.kind === "permit" && (0, vaultBinding_js_1.isVaultPermitAction)(action)) {
250
257
  (0, permit_js_1.validateVaultPermitRequest)(request, action);
251
258
  return;
252
259
  }
@@ -329,6 +336,8 @@ function encodeStep(action, requests) {
329
336
  return (0, withdraw_js_1.buildBlueWithdraw)(action, requests);
330
337
  case "blueWithdrawCollateral":
331
338
  return (0, withdrawCollateral_js_1.buildBlueWithdrawCollateral)(action, requests);
339
+ case "blueWithdrawBuyCallback":
340
+ return (0, withdrawBuyCallback_js_1.buildBlueWithdrawBuyCallback)(action);
332
341
  case "blueRepayWithdrawCollateral":
333
342
  return (0, repayWithdrawCollateral_js_1.buildBlueRepayWithdrawCollateral)(action, requests);
334
343
  case "blueRefinance":
@@ -342,22 +351,106 @@ function encodeStep(action, requests) {
342
351
  return (0, deposit_js_1.buildVaultV1Deposit)(action, requests);
343
352
  case "morphoAuthorization":
344
353
  return (0, authorization_js_1.buildMorphoAuthorization)(action);
354
+ case "midnightAuthorization":
355
+ return (0, authorization_js_2.buildMidnightAuthorization)(action);
356
+ case "midnightMakeBorrow":
357
+ case "midnightMakeLend":
358
+ case "midnightMakeRepay":
359
+ case "midnightMakeWithdraw":
360
+ case "midnightSupplyCollateralMakeBorrow":
361
+ case "midnightSupplyBlueMakeLend":
362
+ return (0, makerPublication_js_1.buildMidnightMakerPublication)(action);
363
+ case "midnightTakeBorrow":
364
+ case "midnightSupplyCollateralTakeBorrow":
365
+ return (0, takeBorrow_js_1.buildMidnightTakeBorrow)(action);
366
+ case "midnightTakeWithdraw":
367
+ return (0, takeWithdraw_js_1.buildMidnightTakeWithdraw)(action);
368
+ case "midnightRepayWithdrawCollateral":
369
+ return (0, repayWithdrawCollateral_js_2.buildMidnightRepayWithdrawCollateral)(action);
370
+ case "midnightTakeLend":
371
+ return (0, takeLend_js_1.buildMidnightTakeLend)(action);
372
+ case "midnightSupplyCollateral":
373
+ return (0, supplyCollateral_js_2.buildMidnightSupplyCollateral)(action);
374
+ case "midnightSupplyCollateralBatch":
375
+ return (0, supplyCollateralBatch_js_1.buildMidnightSupplyCollateralBatch)(action);
376
+ case "midnightSupplyCollateralWithNative":
377
+ return (0, supplyCollateralWithNative_js_1.buildMidnightSupplyCollateralWithNative)(action);
378
+ case "midnightWithdrawCollateral":
379
+ return (0, withdrawCollateral_js_2.buildMidnightWithdrawCollateral)(action);
380
+ case "midnightWithdrawCollateralBatch":
381
+ return (0, withdrawCollateralBatch_js_1.buildMidnightWithdrawCollateralBatch)(action);
382
+ case "midnightRedeem":
383
+ return (0, redeem_js_1.buildMidnightRedeem)(action);
384
+ case "midnightTakeRepayWithdrawCollateral":
385
+ return (0, takeRepayWithdrawCollateral_js_1.buildMidnightTakeRepayWithdrawCollateral)(action);
386
+ case "midnightCancelOffers":
387
+ return (0, cancelOffers_js_1.buildMidnightCancelOffers)(action);
345
388
  case "vaultV2Deposit":
346
389
  return (0, deposit_js_2.buildVaultV2Deposit)(action, requests);
347
390
  case "vaultV2Withdraw":
348
391
  return (0, withdraw_js_3.buildVaultV2Withdraw)(action, requests);
349
392
  case "vaultV2Redeem":
350
- return (0, redeem_js_2.buildVaultV2Redeem)(action, requests);
393
+ return (0, redeem_js_3.buildVaultV2Redeem)(action, requests);
351
394
  case "vaultV2ForceWithdraw":
352
395
  return (0, forceWithdraw_js_1.buildVaultV2ForceWithdraw)(action, requests);
353
396
  case "vaultV1Withdraw":
354
397
  return (0, withdraw_js_2.buildVaultV1Withdraw)(action, requests);
355
398
  case "vaultV1Redeem":
356
- return (0, redeem_js_1.buildVaultV1Redeem)(action, requests);
399
+ return (0, redeem_js_2.buildVaultV1Redeem)(action, requests);
357
400
  case "vaultV2InKindRedeem":
358
401
  return (0, inKindRedeem_js_2.buildVaultV2InKindRedeem)(action, requests);
359
402
  }
360
403
  }
404
+ /**
405
+ * @internal Whether a step's transaction carries the plan's `calldataOrigin`. Operation steps do;
406
+ * approval and authorization prerequisites never do, matching the entity path. Every action type
407
+ * must be listed, so a new type does not compile until its role is chosen.
408
+ */
409
+ exports.CALLDATA_ORIGIN_ROLE = {
410
+ blueBorrow: "operation",
411
+ blueRefinance: "operation",
412
+ blueRepay: "operation",
413
+ blueRepayWithdrawCollateral: "operation",
414
+ blueSupply: "operation",
415
+ blueSupplyCollateral: "operation",
416
+ blueSupplyCollateralBorrow: "operation",
417
+ blueWithdraw: "operation",
418
+ blueWithdrawBuyCallback: "operation",
419
+ blueWithdrawCollateral: "operation",
420
+ erc20Approval: "prerequisite",
421
+ midnightAuthorization: "prerequisite",
422
+ midnightCancelOffers: "operation",
423
+ midnightMakeBorrow: "operation",
424
+ midnightMakeLend: "operation",
425
+ midnightMakeRepay: "operation",
426
+ midnightMakeWithdraw: "operation",
427
+ midnightRedeem: "operation",
428
+ midnightRepayWithdrawCollateral: "operation",
429
+ midnightSupplyBlueMakeLend: "operation",
430
+ midnightSupplyCollateral: "operation",
431
+ midnightSupplyCollateralBatch: "operation",
432
+ midnightSupplyCollateralMakeBorrow: "operation",
433
+ midnightSupplyCollateralTakeBorrow: "operation",
434
+ midnightSupplyCollateralWithNative: "operation",
435
+ midnightTakeBorrow: "operation",
436
+ midnightTakeLend: "operation",
437
+ midnightTakeRepayWithdrawCollateral: "operation",
438
+ midnightTakeWithdraw: "operation",
439
+ midnightWithdrawCollateral: "operation",
440
+ midnightWithdrawCollateralBatch: "operation",
441
+ morphoAuthorization: "prerequisite",
442
+ vaultV1Deposit: "operation",
443
+ vaultV1InKindRedeem: "operation",
444
+ vaultV1MigrateToV2: "operation",
445
+ vaultV1Redeem: "operation",
446
+ vaultV1Withdraw: "operation",
447
+ vaultV2Deposit: "operation",
448
+ vaultV2ForceRedeem: "operation",
449
+ vaultV2ForceWithdraw: "operation",
450
+ vaultV2InKindRedeem: "operation",
451
+ vaultV2Redeem: "operation",
452
+ vaultV2Withdraw: "operation",
453
+ };
361
454
  /**
362
455
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
363
456
  * Builds one transaction from a step, its fixed inputs and the signatures its action names.
@@ -369,17 +462,25 @@ function encodeStep(action, requests) {
369
462
  * not operation amounts, market parameters or referral fees/recipients. Protect those unsigned fields.
370
463
  * @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
371
464
  * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
372
- * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
373
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
374
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
465
+ * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set, except for ERC-20 approval, Morpho authorization and Midnight authorization prerequisite steps.
466
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
467
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
375
468
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
376
469
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
377
470
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
378
471
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
379
472
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
380
473
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
381
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
474
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
382
475
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
476
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
477
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
478
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
479
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
480
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
481
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
482
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
483
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
383
484
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
384
485
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
385
486
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -391,8 +492,10 @@ function encodeStep(action, requests) {
391
492
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
392
493
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
393
494
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
394
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
395
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
495
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
496
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
497
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
498
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
396
499
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
397
500
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
398
501
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -405,8 +508,15 @@ function encodeStep(action, requests) {
405
508
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
406
509
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
407
510
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
408
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
409
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
511
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
512
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
513
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
514
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
515
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
516
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
517
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
518
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
519
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
410
520
  * @example
411
521
  * ```ts
412
522
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -457,7 +567,8 @@ function buildTransaction(plan, step) {
457
567
  return (0, morpho_ts_1.deepFreeze)({
458
568
  to,
459
569
  value,
460
- data: plan.calldataOrigin === undefined
570
+ data: plan.calldataOrigin === undefined ||
571
+ exports.CALLDATA_ORIGIN_ROLE[step.action.type] === "prerequisite"
461
572
  ? data
462
573
  : (0, viem_1.concatHex)([data, plan.calldataOrigin]),
463
574
  action,
@@ -468,16 +579,23 @@ function buildTransaction(plan, step) {
468
579
  * Builds every step of the plan in order.
469
580
  * @param plan - Plan whose referenced signature requests all carry a signature.
470
581
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
471
- * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
472
- * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
582
+ * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent, a Midnight repayment type is unsupported, a Midnight market lists its collateral out of ascending token order, a Midnight single-collateral step has no bigint `collateralIndex`, or a Midnight collateral batch's list is not an array or holds a non-object entry (path under `$.inputs`).
583
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty, or a Midnight collateral batch entry's `collateralIndex` or `assets`, is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
473
584
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
474
585
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
475
586
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
476
587
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
477
588
  * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
478
589
  * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
479
- * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a Blue collateral amount, a deadline, force-redeem shares or deallocation amount is not positive.
590
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a collateral amount, Midnight redeem units, a deadline, force-redeem shares or deallocation amount is not positive, or a Midnight repayment step has a nonpositive full repayment cap or neither repays nor withdraws.
480
591
  * @throws {MarketIdMismatchError} If a Blue collateral step's market ID doesn't match its market parameters.
592
+ * @throws {MidnightMarketAddressMismatchError} If a Midnight collateral, redeem or repayment step's market targets another Midnight deployment.
593
+ * @throws {ChainIdMismatchError} If a Midnight redeem or repayment step's market targets another chain.
594
+ * @throws {MidnightZeroOnBehalfError} If a Midnight redeem, `midnightWithdrawCollateral`, `midnightWithdrawCollateralBatch` or `midnightSupplyCollateralWithNative` step names the zero address as its account.
595
+ * @throws {MidnightZeroReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names the zero address as its receiver.
596
+ * @throws {MidnightContractReceiverError} If a Midnight redeem, `midnightWithdrawCollateral` or `midnightWithdrawCollateralBatch` step, or a `midnightRepayWithdrawCollateral` step that withdraws collateral, names a blocked protocol or token contract as its receiver.
597
+ * @throws {MidnightCalldataEncodingError} If the market tuple or withdrawal arguments cannot be encoded for a Midnight redeem step, or a Midnight repayment step has malformed addresses or other unencodable inputs.
598
+ * @throws {UnknownCollateralIndexError} If a Midnight collateral or repayment step targets an index not configured on its market.
481
599
  * @throws {NativeAmountOnNonWNativeAssetError} If a native-funded Blue collateral step targets a token other than wNative.
482
600
  * @throws {ChainWNativeMissingError} If a native-funded Blue collateral step targets a chain without registered wNative.
483
601
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
@@ -486,11 +604,14 @@ function buildTransaction(plan, step) {
486
604
  * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
487
605
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
488
606
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
607
+ * @throws {InvalidMarketParameterError} If a Midnight collateral, redeem, take or repayment step has an invalid market configuration.
489
608
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
490
609
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
491
610
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
492
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
493
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
611
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative, or a Midnight repayment's exact asset amount or native funding is negative.
612
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), withdrawal-only funding is nonzero, Midnight redeem units exceed uint128, or a Midnight batch collateral supply amount exceeds uint128.
613
+ * For `midnightRepayWithdrawCollateral`, if `repay.assets` or `repay.maxBuyerAssets` is at least `maxUint256`,
614
+ * a withdrawal amount or deadline exceeds uint256, or native funding exceeds the repayment pull.
494
615
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
495
616
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
496
617
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -503,8 +624,15 @@ function buildTransaction(plan, step) {
503
624
  * @throws {DepositSpenderMismatchError} If a token signature names another spender.
504
625
  * @throws {UnsupportedRequirementSignatureError} If a token signature has an unsupported action type.
505
626
  * @throws {BundlesRequirementSignatureMismatchError} If a Blue signature cannot be bound or parsed safely.
506
- * @throws {UnsupportedChainIdError} If a Blue action's chain is absent from the registry.
507
- * @throws {UnknownAddressError} If BlueBundlesV1 is not registered on the action's chain.
627
+ * @throws {UnsupportedChainIdError} If a Blue or Midnight action's chain is absent from the registry.
628
+ * @throws {UnknownAddressError} If BlueBundlesV1, Midnight core, or MidnightBundlesV2 for a Midnight repayment step is not registered on the action's chain.
629
+ * @throws {EmptyMidnightGroupCancellationsError} If a Midnight cancellation lists no groups.
630
+ * @throws {InvalidMidnightHexInputError} If a Midnight cancellation group is not 32 bytes.
631
+ * @throws {DuplicateMidnightGroupCancellationError} If a Midnight cancellation lists a group twice.
632
+ * @throws {EmptyMidnightCollateralWithdrawalsError} If a Midnight batch collateral withdrawal lists no withdrawals.
633
+ * @throws {EmptyMidnightCollateralSuppliesError} If a Midnight batch collateral supply lists no supplies.
634
+ * @throws {DuplicateMidnightCollateralIndexError} If a Midnight batch collateral supply or withdrawal repeats a collateral index.
635
+ * @throws {MidnightZeroOnBehalfError} If a Midnight cancellation's account is the zero address.
508
636
  * @example
509
637
  * ```ts
510
638
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";