@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
@@ -1,15 +1,17 @@
1
1
  import { AccrualPosition, MarketParams, MathLib, } from "@morpho-org/blue-sdk";
2
- import { deepFreeze, Time } from "@morpho-org/morpho-ts";
2
+ import { Time } from "@morpho-org/morpho-ts";
3
3
  import { blueWithdrawCollateral } from "../../actions/blue/withdrawCollateral.js";
4
4
  import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
5
5
  import { DEFAULT_LLTV_BUFFER } from "../../helpers/constant.js";
6
6
  import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1QuoteTimestamp.js";
7
7
  import { validatePositionHealthAfterWithdraw, validateUint256Field, } from "../../helpers/validate.js";
8
8
  import { NonPositiveInputError, } from "../../types/index.js";
9
+ import { freezePlan, planHeader } from "../assemble.js";
9
10
  import { IncompleteTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
10
11
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
11
12
  import { validateMorphoAuthorizationRequest } from "./authorization.js";
12
13
  import { prepareBlue, } from "./prepare.js";
14
+ import { BUNDLES_COMMON_FIELDS, signatureRoles, validateStoredBlueMarketParams, } from "./stored.js";
13
15
  /**
14
16
  * Prepares a BlueBundlesV1 collateral withdrawal with direct or inline signed Morpho authorization.
15
17
  * Health uses the expiry floored at max(now, lastUpdate), with the entity's LLTV buffer.
@@ -30,7 +32,7 @@ import { prepareBlue, } from "./prepare.js";
30
32
  * @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
31
33
  * @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
32
34
  * @param params.expiresAt - Optional safe-integer Unix expiry later than `now`; defaults to `now + 2h` and governs every deadline.
33
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to every built transaction.
35
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended verbatim to the action transaction's calldata; approval and authorization steps carry none.
34
36
  * @param params.deployless - Optional shared intent field; unused because this operation reads no token metadata or allowances.
35
37
  * @returns A deep-frozen, data-only `TransactionPlan` with chain, account, expiry, withdrawal step,
36
38
  * and any preceding Morpho authorization step and signature request. The caller signs; the SDK never does.
@@ -56,7 +58,6 @@ import { prepareBlue, } from "./prepare.js";
56
58
  * @throws {viem.BaseError} when a contract-code, chain ID, authorization or nonce RPC read fails.
57
59
  * @example
58
60
  * ```ts
59
- * import assert from "node:assert/strict";
60
61
  * import { markets } from "@morpho-org/morpho-test";
61
62
  * import { fetchAccrualPosition } from "@morpho-org/morpho-sdk/blue/fetch";
62
63
  * import {
@@ -71,7 +72,7 @@ import { prepareBlue, } from "./prepare.js";
71
72
  * if (!ethereum) throw new Error("Install an Ethereum wallet to continue.");
72
73
  * const wallet = createWalletClient({ chain: mainnet, transport: custom(ethereum) });
73
74
  * const [account] = await wallet.requestAddresses();
74
- * assert(account, "Connect a wallet holding collateral in this market.");
75
+ * if (!account) throw new Error("Connect a wallet holding collateral in this market.");
75
76
  * const market = markets[mainnet.id].usdc_wbtc;
76
77
  * const position = await fetchAccrualPosition(account, market.id, client);
77
78
  * const plan = await prepareBlueWithdrawCollateral(client, {
@@ -92,10 +93,25 @@ import { prepareBlue, } from "./prepare.js";
92
93
  */
93
94
  export async function prepareBlueWithdrawCollateral(client, params) {
94
95
  const now = params.now ?? Time.timestamp();
95
- const { chainId, account, collateralAssets, marketId } = params;
96
- const { loanToken, collateralToken, oracle, irm, lltv } = params.marketData.market.params;
96
+ const { chainId, account, collateralAssets, marketId, marketData, positionData, expiresAt, supportSignature, referralFee, calldataOrigin, deployless, } = params;
97
+ const { loanToken, collateralToken, oracle, irm, lltv } = marketData.market.params;
97
98
  const marketParams = { loanToken, collateralToken, oracle, irm, lltv };
98
- const { intent, steps, signatureRequests, morphoAuthorizationRequestId } = await prepareBlue({ client, params: { ...params, now } }, (resolvedIntent) => {
99
+ const { intent, steps, signatureRequests, morphoAuthorizationRequestId } = await prepareBlue({
100
+ client,
101
+ params: {
102
+ chainId,
103
+ account,
104
+ marketId,
105
+ marketData,
106
+ positionData,
107
+ now,
108
+ expiresAt,
109
+ supportSignature,
110
+ referralFee,
111
+ calldataOrigin,
112
+ deployless,
113
+ },
114
+ }, (resolvedIntent) => {
99
115
  // Reject invalid fees and deadlines before authorization reads.
100
116
  normalizeBundlesCommonParams(resolvedIntent);
101
117
  if (collateralAssets <= 0n) {
@@ -103,7 +119,7 @@ export async function prepareBlueWithdrawCollateral(client, params) {
103
119
  }
104
120
  // Reject amounts outside the ABI range before reading authorization state.
105
121
  validateUint256Field("collateralAssets", collateralAssets);
106
- const position = params.positionData.position;
122
+ const { position } = positionData;
107
123
  // Validate health against the same accrual horizon used by the existing handle.
108
124
  validatePositionHealthAfterWithdraw({
109
125
  positionData: position.borrowShares === 0n
@@ -119,12 +135,8 @@ export async function prepareBlueWithdrawCollateral(client, params) {
119
135
  });
120
136
  return { id: "blueWithdrawCollateral", needsAuthorization: true };
121
137
  });
122
- return deepFreeze({
123
- version: 2,
124
- chainId,
125
- account,
126
- expiresAt: intent.expiresAt,
127
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
138
+ return freezePlan({
139
+ ...planHeader({ chainId, account }, intent),
128
140
  steps: [
129
141
  ...steps,
130
142
  {
@@ -132,9 +144,9 @@ export async function prepareBlueWithdrawCollateral(client, params) {
132
144
  label: "Withdraw Blue collateral",
133
145
  action: {
134
146
  type: "blueWithdrawCollateral",
135
- signatureRequestIds: morphoAuthorizationRequestId === undefined
136
- ? {}
137
- : { morphoAuthorization: morphoAuthorizationRequestId },
147
+ signatureRequestIds: signatureRoles({
148
+ morphoAuthorization: morphoAuthorizationRequestId,
149
+ }),
138
150
  inputs: {
139
151
  chainId,
140
152
  account,
@@ -152,7 +164,7 @@ export async function prepareBlueWithdrawCollateral(client, params) {
152
164
  },
153
165
  ],
154
166
  signatureRequests,
155
- });
167
+ }, { detach: false });
156
168
  }
157
169
  /** @internal Binds an inline authorization to the collateral withdrawal that consumes it. */
158
170
  export function validateBlueWithdrawCollateralAuthorizationRequest(request, action) {
@@ -230,19 +242,8 @@ export function validateBlueWithdrawCollateralPlanAction(action, path) {
230
242
  fields: {
231
243
  collateralAssets: "uint256 bigint",
232
244
  maxLtv: "uint256 bigint",
233
- deadline: "uint256 bigint",
234
- referralFeePct: "uint256 bigint",
235
- referralFeeRecipient: "address",
236
- },
237
- });
238
- validatePlanFields(getPlanObject(inputs.marketParams, `${path}.inputs.marketParams`), {
239
- path: `${path}.inputs.marketParams`,
240
- fields: {
241
- loanToken: "address",
242
- collateralToken: "address",
243
- oracle: "address",
244
- irm: "address",
245
- lltv: "uint256 bigint",
245
+ ...BUNDLES_COMMON_FIELDS,
246
246
  },
247
247
  });
248
+ validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
248
249
  }
@@ -1,11 +1,12 @@
1
1
  import { DEFAULT_SLIPPAGE_TOLERANCE, } from "@morpho-org/blue-sdk";
2
- import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
2
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
3
3
  import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, } from "../actions/bundles/common.js";
4
4
  import { validateClientChainId } from "../actions/requirements/validateClientChainId.js";
5
5
  import { assertRegistryTargetsHaveCode } from "../entities/requirements/assertContractCode.js";
6
6
  import { computeVaultMaxSharePrice } from "../helpers/index.js";
7
7
  import { validateNativeVaultAsset, validateReferenceTime, validateSlippageTolerance, validateUint256Field, validateVaultDepositDeadline, } from "../helpers/validate.js";
8
8
  import { NonPositiveInputError, } from "../types/index.js";
9
+ import { freezePlan, planHeader } from "./assemble.js";
9
10
  import { InvalidTransactionPlanError } from "./error.js";
10
11
  import { resolveIntent } from "./intent.js";
11
12
  import { getTokenRequirements } from "./requirements.js";
@@ -95,12 +96,8 @@ export async function prepareVaultDeposit(client, params) {
95
96
  ]);
96
97
  const approvals = requirements?.approvals ?? [];
97
98
  const signatureRequests = requirements?.permit === undefined ? [] : [requirements.permit];
98
- return deepFreeze(structuredClone({
99
- version: 2,
100
- account,
101
- chainId,
102
- expiresAt: intent.expiresAt,
103
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
99
+ return freezePlan({
100
+ ...planHeader({ chainId, account }, intent),
104
101
  steps: [
105
102
  ...approvals,
106
103
  {
@@ -124,5 +121,5 @@ export async function prepareVaultDeposit(client, params) {
124
121
  },
125
122
  ],
126
123
  signatureRequests,
127
- }));
124
+ }, { detach: true });
128
125
  }
@@ -195,3 +195,30 @@ export declare class NonIntegerInputError extends Error {
195
195
  */
196
196
  constructor(field: string, value: number);
197
197
  }
198
+ /**
199
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
200
+ * A reduce-only Midnight withdrawal needs more credit units than the position's accrued credit
201
+ * holds, so no quote or market liquidity can reach the target.
202
+ */
203
+ export declare class MidnightTakeCreditInsufficientError extends Error {
204
+ /** Position credit accrued to the reference timestamp. */
205
+ readonly credit: bigint;
206
+ /** Credit units the target needs. */
207
+ readonly requiredUnits: bigint;
208
+ /**
209
+ * @param params - Accrued credit, the units the target needs and optional underlying error.
210
+ * @param params.credit - Position credit accrued to the reference timestamp.
211
+ * @param params.requiredUnits - Credit units the target needs.
212
+ * @param params.cause - Offer-shortfall error that the credit shortfall replaces.
213
+ * @example
214
+ * ```ts
215
+ * import { MidnightTakeCreditInsufficientError } from "@morpho-org/morpho-sdk";
216
+ * const error = new MidnightTakeCreditInsufficientError({ credit: 40n, requiredUnits: 50n });
217
+ * ```
218
+ */
219
+ constructor({ credit, requiredUnits, cause, }: {
220
+ readonly credit: bigint;
221
+ readonly requiredUnits: bigint;
222
+ readonly cause?: unknown;
223
+ });
224
+ }
@@ -232,3 +232,31 @@ export class NonIntegerInputError extends Error {
232
232
  this.name = "NonIntegerInputError";
233
233
  }
234
234
  }
235
+ /**
236
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
237
+ * A reduce-only Midnight withdrawal needs more credit units than the position's accrued credit
238
+ * holds, so no quote or market liquidity can reach the target.
239
+ */
240
+ export class MidnightTakeCreditInsufficientError extends Error {
241
+ /** Position credit accrued to the reference timestamp. */
242
+ credit;
243
+ /** Credit units the target needs. */
244
+ requiredUnits;
245
+ /**
246
+ * @param params - Accrued credit, the units the target needs and optional underlying error.
247
+ * @param params.credit - Position credit accrued to the reference timestamp.
248
+ * @param params.requiredUnits - Credit units the target needs.
249
+ * @param params.cause - Offer-shortfall error that the credit shortfall replaces.
250
+ * @example
251
+ * ```ts
252
+ * import { MidnightTakeCreditInsufficientError } from "@morpho-org/morpho-sdk";
253
+ * const error = new MidnightTakeCreditInsufficientError({ credit: 40n, requiredUnits: 50n });
254
+ * ```
255
+ */
256
+ constructor({ credit, requiredUnits, cause, }) {
257
+ super(`Midnight position credit "${credit}" is below the "${requiredUnits}" units the target needs. Lower the target to at most the position's credit.`, { cause });
258
+ this.credit = credit;
259
+ this.requiredUnits = requiredUnits;
260
+ this.name = "MidnightTakeCreditInsufficientError";
261
+ }
262
+ }
@@ -16,10 +16,49 @@ export type { BlueSupplyCollateralBorrowPlanParams } from "./blue/supplyCollater
16
16
  export { prepareBlueSupplyCollateralBorrow } from "./blue/supplyCollateralBorrow.js";
17
17
  export type { BlueWithdrawPlanParams } from "./blue/withdraw.js";
18
18
  export { prepareBlueWithdraw } from "./blue/withdraw.js";
19
+ export type { BlueWithdrawBuyCallbackPlanParams } from "./blue/withdrawBuyCallback.js";
20
+ export { prepareBlueWithdrawBuyCallback } from "./blue/withdrawBuyCallback.js";
19
21
  export type { BlueWithdrawCollateralPlanParams } from "./blue/withdrawCollateral.js";
20
22
  export { prepareBlueWithdrawCollateral } from "./blue/withdrawCollateral.js";
21
- export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
23
+ export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, MidnightTakeCreditInsufficientError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
22
24
  export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
25
+ export type { MidnightCancelOffersPlanParams } from "./midnight/cancelOffers.js";
26
+ export { prepareMidnightCancelOffers } from "./midnight/cancelOffers.js";
27
+ export type { MidnightMakeBorrowPlanParams } from "./midnight/makeBorrow.js";
28
+ export { prepareMidnightMakeBorrow } from "./midnight/makeBorrow.js";
29
+ export type { MidnightMakeLendPlanParams } from "./midnight/makeLend.js";
30
+ export { prepareMidnightMakeLend } from "./midnight/makeLend.js";
31
+ export type { MidnightMakeRepayPlanParams } from "./midnight/makeRepay.js";
32
+ export { prepareMidnightMakeRepay } from "./midnight/makeRepay.js";
33
+ export type { MidnightMakerPublicationPlanParams } from "./midnight/makerPublication.js";
34
+ export type { MidnightMakeWithdrawPlanParams } from "./midnight/makeWithdraw.js";
35
+ export { prepareMidnightMakeWithdraw } from "./midnight/makeWithdraw.js";
36
+ export type { MidnightRedeemPlanParams } from "./midnight/redeem.js";
37
+ export { prepareMidnightRedeem } from "./midnight/redeem.js";
38
+ export type { MidnightRepayWithdrawCollateralPlanParams } from "./midnight/repayWithdrawCollateral.js";
39
+ export { prepareMidnightRepayWithdrawCollateral } from "./midnight/repayWithdrawCollateral.js";
40
+ export type { MidnightSupplyBlueMakeLendPlanParams } from "./midnight/supplyBlueMakeLend.js";
41
+ export { prepareMidnightSupplyBlueMakeLend } from "./midnight/supplyBlueMakeLend.js";
42
+ export type { MidnightSupplyCollateralPlanParams } from "./midnight/supplyCollateral.js";
43
+ export { prepareMidnightSupplyCollateral } from "./midnight/supplyCollateral.js";
44
+ export type { MidnightSupplyCollateralBatchPlanParams } from "./midnight/supplyCollateralBatch.js";
45
+ export { prepareMidnightSupplyCollateralBatch } from "./midnight/supplyCollateralBatch.js";
46
+ export type { MidnightSupplyCollateralMakeBorrowPlanParams } from "./midnight/supplyCollateralMakeBorrow.js";
47
+ export { prepareMidnightSupplyCollateralMakeBorrow } from "./midnight/supplyCollateralMakeBorrow.js";
48
+ export type { MidnightSupplyCollateralWithNativePlanParams } from "./midnight/supplyCollateralWithNative.js";
49
+ export { prepareMidnightSupplyCollateralWithNative } from "./midnight/supplyCollateralWithNative.js";
50
+ export type { MidnightSupplyCollateralTakeBorrowPlanParams, MidnightTakeBorrowPlanParams, } from "./midnight/takeBorrow.js";
51
+ export { prepareMidnightSupplyCollateralTakeBorrow, prepareMidnightTakeBorrow, } from "./midnight/takeBorrow.js";
52
+ export type { MidnightTakeLendPlanParams } from "./midnight/takeLend.js";
53
+ export { prepareMidnightTakeLend } from "./midnight/takeLend.js";
54
+ export type { MidnightTakeRepayWithdrawCollateralPlanParams } from "./midnight/takeRepayWithdrawCollateral.js";
55
+ export { prepareMidnightTakeRepayWithdrawCollateral } from "./midnight/takeRepayWithdrawCollateral.js";
56
+ export type { MidnightTakeWithdrawPlanParams } from "./midnight/takeWithdraw.js";
57
+ export { prepareMidnightTakeWithdraw } from "./midnight/takeWithdraw.js";
58
+ export type { MidnightWithdrawCollateralPlanParams } from "./midnight/withdrawCollateral.js";
59
+ export { prepareMidnightWithdrawCollateral } from "./midnight/withdrawCollateral.js";
60
+ export type { MidnightWithdrawCollateralBatchPlanParams } from "./midnight/withdrawCollateralBatch.js";
61
+ export { prepareMidnightWithdrawCollateralBatch } from "./midnight/withdrawCollateralBatch.js";
23
62
  export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
24
63
  export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
25
64
  export type { Action, SignatureRequest, Step, TransactionPlan, } from "./types.js";
@@ -7,8 +7,27 @@ export { prepareBlueSupply } from "./blue/supply.js";
7
7
  export { prepareBlueSupplyCollateral } from "./blue/supplyCollateral.js";
8
8
  export { prepareBlueSupplyCollateralBorrow } from "./blue/supplyCollateralBorrow.js";
9
9
  export { prepareBlueWithdraw } from "./blue/withdraw.js";
10
+ export { prepareBlueWithdrawBuyCallback } from "./blue/withdrawBuyCallback.js";
10
11
  export { prepareBlueWithdrawCollateral } from "./blue/withdrawCollateral.js";
11
- export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
12
+ export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, MidnightTakeCreditInsufficientError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
13
+ export { prepareMidnightCancelOffers } from "./midnight/cancelOffers.js";
14
+ export { prepareMidnightMakeBorrow } from "./midnight/makeBorrow.js";
15
+ export { prepareMidnightMakeLend } from "./midnight/makeLend.js";
16
+ export { prepareMidnightMakeRepay } from "./midnight/makeRepay.js";
17
+ export { prepareMidnightMakeWithdraw } from "./midnight/makeWithdraw.js";
18
+ export { prepareMidnightRedeem } from "./midnight/redeem.js";
19
+ export { prepareMidnightRepayWithdrawCollateral } from "./midnight/repayWithdrawCollateral.js";
20
+ export { prepareMidnightSupplyBlueMakeLend } from "./midnight/supplyBlueMakeLend.js";
21
+ export { prepareMidnightSupplyCollateral } from "./midnight/supplyCollateral.js";
22
+ export { prepareMidnightSupplyCollateralBatch } from "./midnight/supplyCollateralBatch.js";
23
+ export { prepareMidnightSupplyCollateralMakeBorrow } from "./midnight/supplyCollateralMakeBorrow.js";
24
+ export { prepareMidnightSupplyCollateralWithNative } from "./midnight/supplyCollateralWithNative.js";
25
+ export { prepareMidnightSupplyCollateralTakeBorrow, prepareMidnightTakeBorrow, } from "./midnight/takeBorrow.js";
26
+ export { prepareMidnightTakeLend } from "./midnight/takeLend.js";
27
+ export { prepareMidnightTakeRepayWithdrawCollateral } from "./midnight/takeRepayWithdrawCollateral.js";
28
+ export { prepareMidnightTakeWithdraw } from "./midnight/takeWithdraw.js";
29
+ export { prepareMidnightWithdrawCollateral } from "./midnight/withdrawCollateral.js";
30
+ export { prepareMidnightWithdrawCollateralBatch } from "./midnight/withdrawCollateralBatch.js";
12
31
  export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
13
32
  export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
14
33
  export { prepareVaultV1Deposit } from "./vaultv1/deposit.js";
@@ -29,7 +29,7 @@ export interface IntentParams {
29
29
  readonly supportSignature?: boolean;
30
30
  /** Unix seconds. Defaults to two hours from now. */
31
31
  readonly expiresAt?: number;
32
- /** Optional attribution bytes (at most 1 MiB) appended verbatim to every built transaction's calldata. */
32
+ /** Optional attribution bytes (at most 1 MiB) appended verbatim to the action transaction's calldata; ERC-20 approval, Morpho authorization and Midnight authorization steps carry none. */
33
33
  readonly calldataOrigin?: Hex;
34
34
  /** Whether token metadata reads for permits may use deployless aggregation. */
35
35
  readonly deployless?: boolean;
@@ -0,0 +1,15 @@
1
+ import type { Address, Client } from "viem";
2
+ import type { Action, Step } from "../types.js";
3
+ type Authorization = Extract<Action, {
4
+ type: "midnightAuthorization";
5
+ }>;
6
+ /** @internal Resolves the ordinary registry bundle grant after the RPC chain has been checked. */
7
+ export declare function prepareMidnightBundleAuthorization(client: Client, inputs: {
8
+ readonly chainId: number;
9
+ readonly account: Address;
10
+ }): Promise<Step<Authorization> | undefined>;
11
+ /** @internal Derives the authorization target from the chain, not from a stored operator. */
12
+ export declare function buildMidnightAuthorization({ inputs }: Authorization): Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightAuthorizationAction>>;
13
+ /** @internal Midnight steps never use signature requests. */
14
+ export declare function validateSignaturelessMidnightAction(action: Record<string, unknown>, path: string): void;
15
+ export {};
@@ -0,0 +1,40 @@
1
+ import { midnightAbi } from "@morpho-org/midnight-sdk";
2
+ import { getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { readContract } from "viem/actions";
4
+ import { midnightSetIsAuthorized } from "../../actions/midnight/authorization.js";
5
+ import { InvalidTransactionPlanError } from "../error.js";
6
+ /** @internal Resolves the ordinary registry bundle grant after the RPC chain has been checked. */
7
+ export async function prepareMidnightBundleAuthorization(client, inputs) {
8
+ const { chainId, account } = inputs;
9
+ const isAuthorized = await readContract(client, {
10
+ address: getChainAddress(chainId, "midnight"),
11
+ abi: midnightAbi,
12
+ functionName: "isAuthorized",
13
+ args: [account, getChainAddress(chainId, "midnightBundlesV2")],
14
+ });
15
+ if (isAuthorized) {
16
+ return undefined;
17
+ }
18
+ return {
19
+ id: "midnightAuthorization",
20
+ label: "Authorize Midnight bundle",
21
+ action: { type: "midnightAuthorization", inputs },
22
+ };
23
+ }
24
+ /** @internal Derives the authorization target from the chain, not from a stored operator. */
25
+ export function buildMidnightAuthorization({ inputs }) {
26
+ return midnightSetIsAuthorized({
27
+ chainId: inputs.chainId,
28
+ onBehalf: inputs.account,
29
+ authorized: getChainAddress(inputs.chainId, "midnightBundlesV2"),
30
+ });
31
+ }
32
+ /** @internal Midnight steps never use signature requests. */
33
+ export function validateSignaturelessMidnightAction(action, path) {
34
+ if ("signatureRequestIds" in action) {
35
+ throw new InvalidTransactionPlanError({
36
+ path: `${path}.signatureRequestIds`,
37
+ reason: "Midnight steps do not consume signatures",
38
+ });
39
+ }
40
+ }
@@ -0,0 +1,80 @@
1
+ import type { Client, Hex } from "viem";
2
+ import type { MidnightCancelOffersAction, ReferenceTimestampParams, Transaction } from "../../types/index.js";
3
+ import { type IntentParams } from "../intent.js";
4
+ import type { Action, TransactionPlan } from "../types.js";
5
+ /**
6
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
7
+ * Offer groups to cancel in full for `account` through a direct Midnight call.
8
+ * No authorization, approval or signature is needed.
9
+ * @example
10
+ * ```ts
11
+ * import type { MidnightCancelOffersPlanParams } from "@morpho-org/morpho-sdk";
12
+ * import type { Address, Hex } from "viem";
13
+ *
14
+ * declare const maker: Address;
15
+ * declare const group: Hex;
16
+ * const params: MidnightCancelOffersPlanParams = { chainId: 8453, account: maker, groups: [group] };
17
+ * ```
18
+ */
19
+ export interface MidnightCancelOffersPlanParams extends Pick<IntentParams, "chainId" | "account" | "expiresAt" | "calldataOrigin">, ReferenceTimestampParams {
20
+ /** Nonempty list of distinct 32-byte offer groups, cancelled in list order. */
21
+ readonly groups: readonly Hex[];
22
+ }
23
+ /**
24
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
25
+ * Prepares a full cancellation of `account`'s offer groups as one direct Midnight transaction.
26
+ * One group builds a bare `setConsumed(group, maxUint128, account)`; two or more build one Midnight
27
+ * core `multicall` of those calls, which cancels every group or none. The transaction never targets
28
+ * MidnightBundlesV2, so it builds on every chain with a Midnight deployment. `account`, or an
29
+ * operator it authorized on Midnight, must send it. Validates the groups with the same parse
30
+ * constructor as the entity `cancelOffers`, in the same order. Expiry is plan metadata, not an
31
+ * onchain deadline.
32
+ * @param client - Client used to validate the chain and Midnight core code, not retained by the plan.
33
+ * @param params.chainId - Chain containing the Midnight deployment.
34
+ * @param params.account - Non-zero maker whose groups are cancelled.
35
+ * @param params.groups - Nonempty list of distinct 32-byte offer groups.
36
+ * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
37
+ * @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
38
+ * @param params.calldataOrigin - Optional non-empty hex bytes appended to the built transaction.
39
+ * @returns A deep-frozen plan with one `midnightCancelOffers` step and no signature requests.
40
+ * @throws {InvalidBigIntInputError} when a supplied non-null `now` is not a bigint.
41
+ * @throws {ZeroAccountError} when `account` is the zero address.
42
+ * @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
43
+ * @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
44
+ * @throws {NonPositiveInputError} when `expiresAt` is not positive.
45
+ * @throws {ExpiredDeadlineError} when `expiresAt` is at or before the reference time.
46
+ * @throws {InvalidCalldataOriginError} when attribution bytes are empty or malformed.
47
+ * @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
48
+ * @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
49
+ * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
50
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
51
+ * @throws {UnknownAddressError} when the chain has no `midnight` deployment.
52
+ * @throws {ChainIdMismatchError} when the client declares or serves another chain.
53
+ * @throws {MissingContractCodeError} when the registered Midnight core has no deployed code.
54
+ * @throws {viem.BaseError} when the RPC chain ID or bytecode read fails.
55
+ * @example
56
+ * ```ts
57
+ * import { buildTransactions, prepareMidnightCancelOffers } from "@morpho-org/morpho-sdk";
58
+ * import { createPublicClient, http, type Address, type Hex } from "viem";
59
+ * import { base } from "viem/chains";
60
+ *
61
+ * declare const maker: Address;
62
+ * declare const group: Hex;
63
+ * const client = createPublicClient({ chain: base, transport: http() });
64
+ * const plan = await prepareMidnightCancelOffers(client, {
65
+ * chainId: base.id,
66
+ * account: maker,
67
+ * groups: [group],
68
+ * now: (await client.getBlock()).timestamp,
69
+ * });
70
+ * // One transaction: setConsumed(group, maxUint128, maker) on Midnight.
71
+ * const [tx] = buildTransactions(plan);
72
+ * ```
73
+ */
74
+ export declare function prepareMidnightCancelOffers(client: Client, params: MidnightCancelOffersPlanParams): Promise<TransactionPlan>;
75
+ /** @internal Validates the stored cancellation's plain input shape. */
76
+ export declare function validateMidnightCancelOffersPlanAction(action: Record<string, unknown>, path: string): void;
77
+ /** @internal Encodes the stored cancellation through the same action as `cancelOffers`. */
78
+ export declare function buildMidnightCancelOffers(action: Extract<Action, {
79
+ type: "midnightCancelOffers";
80
+ }>): Readonly<Transaction<MidnightCancelOffersAction>>;
@@ -0,0 +1,120 @@
1
+ import { deepFreeze, Time } from "@morpho-org/morpho-ts";
2
+ import { midnightCancelOffers, parseMidnightCancelOffers, } from "../../actions/midnight/cancelOffers.js";
3
+ import { createChainCheck } from "../../actions/requirements/chainCheck.js";
4
+ import { assertRegistryTargetsHaveCode } from "../../entities/requirements/assertContractCode.js";
5
+ import { validateReferenceTime } from "../../helpers/validate.js";
6
+ import { resolveIntent } from "../intent.js";
7
+ import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
8
+ import { validateSignaturelessMidnightAction } from "./authorization.js";
9
+ /**
10
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
11
+ * Prepares a full cancellation of `account`'s offer groups as one direct Midnight transaction.
12
+ * One group builds a bare `setConsumed(group, maxUint128, account)`; two or more build one Midnight
13
+ * core `multicall` of those calls, which cancels every group or none. The transaction never targets
14
+ * MidnightBundlesV2, so it builds on every chain with a Midnight deployment. `account`, or an
15
+ * operator it authorized on Midnight, must send it. Validates the groups with the same parse
16
+ * constructor as the entity `cancelOffers`, in the same order. Expiry is plan metadata, not an
17
+ * onchain deadline.
18
+ * @param client - Client used to validate the chain and Midnight core code, not retained by the plan.
19
+ * @param params.chainId - Chain containing the Midnight deployment.
20
+ * @param params.account - Non-zero maker whose groups are cancelled.
21
+ * @param params.groups - Nonempty list of distinct 32-byte offer groups.
22
+ * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
23
+ * @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
24
+ * @param params.calldataOrigin - Optional non-empty hex bytes appended to the built transaction.
25
+ * @returns A deep-frozen plan with one `midnightCancelOffers` step and no signature requests.
26
+ * @throws {InvalidBigIntInputError} when a supplied non-null `now` is not a bigint.
27
+ * @throws {ZeroAccountError} when `account` is the zero address.
28
+ * @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
29
+ * @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
30
+ * @throws {NonPositiveInputError} when `expiresAt` is not positive.
31
+ * @throws {ExpiredDeadlineError} when `expiresAt` is at or before the reference time.
32
+ * @throws {InvalidCalldataOriginError} when attribution bytes are empty or malformed.
33
+ * @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
34
+ * @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
35
+ * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
36
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
37
+ * @throws {UnknownAddressError} when the chain has no `midnight` deployment.
38
+ * @throws {ChainIdMismatchError} when the client declares or serves another chain.
39
+ * @throws {MissingContractCodeError} when the registered Midnight core has no deployed code.
40
+ * @throws {viem.BaseError} when the RPC chain ID or bytecode read fails.
41
+ * @example
42
+ * ```ts
43
+ * import { buildTransactions, prepareMidnightCancelOffers } from "@morpho-org/morpho-sdk";
44
+ * import { createPublicClient, http, type Address, type Hex } from "viem";
45
+ * import { base } from "viem/chains";
46
+ *
47
+ * declare const maker: Address;
48
+ * declare const group: Hex;
49
+ * const client = createPublicClient({ chain: base, transport: http() });
50
+ * const plan = await prepareMidnightCancelOffers(client, {
51
+ * chainId: base.id,
52
+ * account: maker,
53
+ * groups: [group],
54
+ * now: (await client.getBlock()).timestamp,
55
+ * });
56
+ * // One transaction: setConsumed(group, maxUint128, maker) on Midnight.
57
+ * const [tx] = buildTransactions(plan);
58
+ * ```
59
+ */
60
+ export async function prepareMidnightCancelOffers(client, params) {
61
+ const { account, chainId } = params;
62
+ const now = params.now ?? Time.timestamp();
63
+ // Reject a non-bigint clock before deriving the default expiry.
64
+ validateReferenceTime(now);
65
+ const { expiresAt, calldataOrigin } = resolveIntent({
66
+ account,
67
+ chainId,
68
+ expiresAt: params.expiresAt,
69
+ calldataOrigin: params.calldataOrigin,
70
+ }, now);
71
+ const parsed = parseMidnightCancelOffers({
72
+ chainId,
73
+ groups: params.groups,
74
+ onBehalf: account,
75
+ });
76
+ const chainCheck = createChainCheck(client, chainId);
77
+ await chainCheck();
78
+ // A code-less core would accept the cancellation as a silent no-op, leaving every offer fillable.
79
+ await assertRegistryTargetsHaveCode(client, chainId, [{ role: "midnight", address: parsed.midnight }], chainCheck);
80
+ return deepFreeze({
81
+ version: 2,
82
+ account,
83
+ chainId,
84
+ expiresAt,
85
+ ...(calldataOrigin && { calldataOrigin }),
86
+ steps: [
87
+ {
88
+ id: "midnightCancelOffers",
89
+ label: "Cancel Midnight offers",
90
+ action: {
91
+ type: "midnightCancelOffers",
92
+ inputs: { chainId, account, groups: [...parsed.groups] },
93
+ },
94
+ },
95
+ ],
96
+ signatureRequests: [],
97
+ });
98
+ }
99
+ /** @internal Validates the stored cancellation's plain input shape. */
100
+ export function validateMidnightCancelOffersPlanAction(action, path) {
101
+ const inputsPath = `${path}.inputs`;
102
+ const inputs = getPlanObject(action.inputs, inputsPath);
103
+ validatePlanFields(inputs, {
104
+ path: inputsPath,
105
+ fields: { groups: "array" },
106
+ });
107
+ for (const [index, group] of inputs.groups.entries()) {
108
+ validatePlanField(group, {
109
+ path: `${inputsPath}.groups[${index}]`,
110
+ type: "bytes32",
111
+ });
112
+ }
113
+ // Midnight never consumes a signature reference.
114
+ validateSignaturelessMidnightAction(action, path);
115
+ }
116
+ /** @internal Encodes the stored cancellation through the same action as `cancelOffers`. */
117
+ export function buildMidnightCancelOffers(action) {
118
+ const { chainId, account, groups } = action.inputs;
119
+ return midnightCancelOffers({ chainId, groups, onBehalf: account });
120
+ }