@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
@@ -0,0 +1,81 @@
1
+ import { AbiEncodingBytesSizeMismatchError, BaseError, IntegerOutOfRangeError, InvalidHexValueError, isHex, maxUint256, } from "viem";
2
+ import { MidnightCalldataEncodingError } from "../types/index.js";
3
+ import { validateMidnightAddress } from "./validateMidnightAccount.js";
4
+ const OFFER_ADDRESS_FIELDS = [
5
+ "maker",
6
+ "callback",
7
+ "receiverIfMakerIsSeller",
8
+ "ratifier",
9
+ ];
10
+ const OFFER_UINT256_FIELDS = [
11
+ "start",
12
+ "expiry",
13
+ "tick",
14
+ "continuousFeeCap",
15
+ ];
16
+ const OFFER_CAP_FIELDS = ["maxUnits", "maxAssets"];
17
+ const BYTES32_PATTERN = /^0x[0-9a-fA-F]{64}$/;
18
+ const validateUint256 = (field, value) => {
19
+ if (typeof value !== "bigint") {
20
+ throw new MidnightCalldataEncodingError(field, new BaseError(`Invalid bigint value: "${String(value)}".`));
21
+ }
22
+ if (value < 0n || value > maxUint256) {
23
+ throw new MidnightCalldataEncodingError(field, new IntegerOutOfRangeError({
24
+ max: `${maxUint256}n`,
25
+ min: "0n",
26
+ signed: false,
27
+ size: 32,
28
+ value: `${value}n`,
29
+ }));
30
+ }
31
+ };
32
+ const validateBytes = (field, value) => {
33
+ if (!isHex(value) || value.length % 2 !== 0) {
34
+ throw new MidnightCalldataEncodingError(field, new InvalidHexValueError(value));
35
+ }
36
+ };
37
+ /**
38
+ * Parses the fields of each taken offer fill that `MidnightBundlesV2` ABI-encodes and that the
39
+ * side, market and cap guards do not already check, so a malformed offer is rejected before any
40
+ * read or encoding.
41
+ *
42
+ * Integer and address bounds are the ABI's: `start`, `expiry`, `tick`, `continuousFeeCap` and
43
+ * the fill's `units` are `uint256` bigints; the `maxUnits` and `maxAssets` caps are bigints whose
44
+ * `uint128` bounds the action parser checks; `maker`, `callback`, `receiverIfMakerIsSeller` and
45
+ * `ratifier` are addresses (checksummed when mixed-case); `group` is exactly 32 bytes of `0x` hex;
46
+ * `reduceOnly` is a boolean. `callbackData` and `ratifierData` must be even-length `0x` hex.
47
+ *
48
+ * @param takeableOffers - Offers selected for a Midnight take.
49
+ * @returns Nothing when every offer field can be encoded.
50
+ * @throws {MidnightCalldataEncodingError} when a field is malformed; `input` is its path, such as
51
+ * `"takeableOffers[0].offer.maker"`.
52
+ * @internal
53
+ */
54
+ export const validateMidnightTakeableOfferFields = (takeableOffers) => {
55
+ for (const [index, { units, offer, ratifierData },] of takeableOffers.entries()) {
56
+ const path = `takeableOffers[${index}]`;
57
+ for (const field of OFFER_ADDRESS_FIELDS) {
58
+ validateMidnightAddress(`${path}.offer.${field}`, offer[field]);
59
+ }
60
+ for (const field of OFFER_UINT256_FIELDS) {
61
+ validateUint256(`${path}.offer.${field}`, offer[field]);
62
+ }
63
+ for (const field of OFFER_CAP_FIELDS) {
64
+ validateUint256(`${path}.offer.${field}`, offer[field]);
65
+ }
66
+ if (typeof offer.group !== "string" || !BYTES32_PATTERN.test(offer.group)) {
67
+ throw new MidnightCalldataEncodingError(`${path}.offer.group`, isHex(offer.group, { strict: true })
68
+ ? new AbiEncodingBytesSizeMismatchError({
69
+ expectedSize: 32,
70
+ value: offer.group,
71
+ })
72
+ : new InvalidHexValueError(offer.group));
73
+ }
74
+ validateBytes(`${path}.offer.callbackData`, offer.callbackData);
75
+ if (typeof offer.reduceOnly !== "boolean") {
76
+ throw new MidnightCalldataEncodingError(`${path}.offer.reduceOnly`, new BaseError(`Invalid boolean value: "${offer.reduceOnly}".`));
77
+ }
78
+ validateBytes(`${path}.ratifierData`, ratifierData);
79
+ validateUint256(`${path}.units`, units);
80
+ }
81
+ };
@@ -4,7 +4,7 @@ export * from "./client/index.js";
4
4
  export type { SupplyCollateralWithNativeParams } from "./entities/midnight/types.js";
5
5
  export * from "./entities/requirements/index.js";
6
6
  export * from "./helpers/index.js";
7
- export type { Action, BlueBorrowPlanParams, BlueMarketSnapshot, BluePositionSnapshot, BlueRefinancePlanParams, BlueRepayPlanParams, BlueRepayWithdrawCollateralPlanParams, BlueSupplyCollateralBorrowPlanParams, BlueSupplyCollateralPlanParams, BlueSupplyPlanParams, BlueWithdrawCollateralPlanParams, BlueWithdrawPlanParams, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV1DepositPlanParams, VaultV1InKindRedeemPlanParams, VaultV1MigrateToV2PlanParams, VaultV1RedeemPlanParams, VaultV1WithdrawPlanParams, VaultV2DepositPlanParams, VaultV2ForceRedeemPlanParams, VaultV2ForceWithdrawPlanParams, VaultV2InKindRedeemPlanParams, VaultV2RedeemPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
8
- export { applySignatures, BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareBlueBorrow, prepareBlueRefinance, prepareBlueRepay, prepareBlueRepayWithdrawCollateral, prepareBlueSupply, prepareBlueSupplyCollateral, prepareBlueSupplyCollateralBorrow, prepareBlueWithdraw, prepareBlueWithdrawCollateral, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, validateBlueMarketSnapshot, ZeroAccountError, } from "./transactionPlan/index.js";
7
+ export type { Action, BlueBorrowPlanParams, BlueMarketSnapshot, BluePositionSnapshot, BlueRefinancePlanParams, BlueRepayPlanParams, BlueRepayWithdrawCollateralPlanParams, BlueSupplyCollateralBorrowPlanParams, BlueSupplyCollateralPlanParams, BlueSupplyPlanParams, BlueWithdrawBuyCallbackPlanParams, BlueWithdrawCollateralPlanParams, BlueWithdrawPlanParams, Funding, IntentParams, MidnightCancelOffersPlanParams, MidnightMakeBorrowPlanParams, MidnightMakeLendPlanParams, MidnightMakeRepayPlanParams, MidnightMakerPublicationPlanParams, MidnightMakeWithdrawPlanParams, MidnightRedeemPlanParams, MidnightRepayWithdrawCollateralPlanParams, MidnightSupplyBlueMakeLendPlanParams, MidnightSupplyCollateralBatchPlanParams, MidnightSupplyCollateralMakeBorrowPlanParams, MidnightSupplyCollateralPlanParams, MidnightSupplyCollateralTakeBorrowPlanParams, MidnightSupplyCollateralWithNativePlanParams, MidnightTakeBorrowPlanParams, MidnightTakeLendPlanParams, MidnightTakeRepayWithdrawCollateralPlanParams, MidnightTakeWithdrawPlanParams, MidnightWithdrawCollateralBatchPlanParams, MidnightWithdrawCollateralPlanParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV1DepositPlanParams, VaultV1InKindRedeemPlanParams, VaultV1MigrateToV2PlanParams, VaultV1RedeemPlanParams, VaultV1WithdrawPlanParams, VaultV2DepositPlanParams, VaultV2ForceRedeemPlanParams, VaultV2ForceWithdrawPlanParams, VaultV2InKindRedeemPlanParams, VaultV2RedeemPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
8
+ export { applySignatures, BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, MidnightTakeCreditInsufficientError, NonIntegerInputError, parseTransactionPlan, prepareBlueBorrow, prepareBlueRefinance, prepareBlueRepay, prepareBlueRepayWithdrawCollateral, prepareBlueSupply, prepareBlueSupplyCollateral, prepareBlueSupplyCollateralBorrow, prepareBlueWithdraw, prepareBlueWithdrawBuyCallback, prepareBlueWithdrawCollateral, prepareMidnightCancelOffers, prepareMidnightMakeBorrow, prepareMidnightMakeLend, prepareMidnightMakeRepay, prepareMidnightMakeWithdraw, prepareMidnightRedeem, prepareMidnightRepayWithdrawCollateral, prepareMidnightSupplyBlueMakeLend, prepareMidnightSupplyCollateral, prepareMidnightSupplyCollateralBatch, prepareMidnightSupplyCollateralMakeBorrow, prepareMidnightSupplyCollateralTakeBorrow, prepareMidnightSupplyCollateralWithNative, prepareMidnightTakeBorrow, prepareMidnightTakeLend, prepareMidnightTakeRepayWithdrawCollateral, prepareMidnightTakeWithdraw, prepareMidnightWithdrawCollateral, prepareMidnightWithdrawCollateralBatch, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, validateBlueMarketSnapshot, ZeroAccountError, } from "./transactionPlan/index.js";
9
9
  export * from "./types/index.js";
10
10
  export { version } from "./version.js";
package/lib/esm/index.js CHANGED
@@ -3,6 +3,6 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
3
3
  export * from "./client/index.js";
4
4
  export * from "./entities/requirements/index.js";
5
5
  export * from "./helpers/index.js";
6
- export { applySignatures, BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareBlueBorrow, prepareBlueRefinance, prepareBlueRepay, prepareBlueRepayWithdrawCollateral, prepareBlueSupply, prepareBlueSupplyCollateral, prepareBlueSupplyCollateralBorrow, prepareBlueWithdraw, prepareBlueWithdrawCollateral, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, validateBlueMarketSnapshot, ZeroAccountError, } from "./transactionPlan/index.js";
6
+ export { applySignatures, BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, MidnightTakeCreditInsufficientError, NonIntegerInputError, parseTransactionPlan, prepareBlueBorrow, prepareBlueRefinance, prepareBlueRepay, prepareBlueRepayWithdrawCollateral, prepareBlueSupply, prepareBlueSupplyCollateral, prepareBlueSupplyCollateralBorrow, prepareBlueWithdraw, prepareBlueWithdrawBuyCallback, prepareBlueWithdrawCollateral, prepareMidnightCancelOffers, prepareMidnightMakeBorrow, prepareMidnightMakeLend, prepareMidnightMakeRepay, prepareMidnightMakeWithdraw, prepareMidnightRedeem, prepareMidnightRepayWithdrawCollateral, prepareMidnightSupplyBlueMakeLend, prepareMidnightSupplyCollateral, prepareMidnightSupplyCollateralBatch, prepareMidnightSupplyCollateralMakeBorrow, prepareMidnightSupplyCollateralTakeBorrow, prepareMidnightSupplyCollateralWithNative, prepareMidnightTakeBorrow, prepareMidnightTakeLend, prepareMidnightTakeRepayWithdrawCollateral, prepareMidnightTakeWithdraw, prepareMidnightWithdrawCollateral, prepareMidnightWithdrawCollateralBatch, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, validateBlueMarketSnapshot, ZeroAccountError, } from "./transactionPlan/index.js";
7
7
  export * from "./types/index.js";
8
8
  export { version } from "./version.js";
@@ -1 +1,2 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
+ export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
@@ -1 +1,2 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
+ export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
@@ -1,6 +1,6 @@
1
1
  export { EcrecoverRatifier,
2
2
  /** @deprecated Use EcrecoverRatifier with a tagged tree. */
3
- EcrecoverRatifierUtils, eip712Digest, GroupUtils, MarketUtils, OfferChainUtils, OfferUtils, Payload, PositionUtils, PriceRatifierV1,
3
+ EcrecoverRatifierUtils, eip712Digest, GroupUtils, getBlueBuyCallbackAddress, MarketUtils, OfferChainUtils, OfferUtils, Payload, PositionUtils, PriceRatifierV1,
4
4
  /** @deprecated Use PriceRatifierV1. */
5
5
  PriceRatifierV1Utils, RateRatifierV1,
6
6
  /** @deprecated Use RateRatifierV1. */
@@ -1,6 +1,6 @@
1
1
  export { EcrecoverRatifier,
2
2
  /** @deprecated Use EcrecoverRatifier with a tagged tree. */
3
- EcrecoverRatifierUtils, eip712Digest, GroupUtils, MarketUtils, OfferChainUtils, OfferUtils, Payload, PositionUtils, PriceRatifierV1,
3
+ EcrecoverRatifierUtils, eip712Digest, GroupUtils, getBlueBuyCallbackAddress, MarketUtils, OfferChainUtils, OfferUtils, Payload, PositionUtils, PriceRatifierV1,
4
4
  /** @deprecated Use PriceRatifierV1. */
5
5
  PriceRatifierV1Utils, RateRatifierV1,
6
6
  /** @deprecated Use RateRatifierV1. */
@@ -0,0 +1,24 @@
1
+ import type { Address } from "viem";
2
+ import type { Intent } from "./intent.js";
3
+ import type { TransactionPlan } from "./types.js";
4
+ /**
5
+ * @internal The stored plan header: version, chain, account, expiry, and the calldata origin when
6
+ * the intent has one.
7
+ */
8
+ export declare function planHeader({ chainId, account }: {
9
+ readonly chainId: number;
10
+ readonly account: Address;
11
+ }, { expiresAt, calldataOrigin }: Pick<Intent, "expiresAt" | "calldataOrigin">): {
12
+ readonly version: 2;
13
+ readonly chainId: number;
14
+ readonly account: `0x${string}`;
15
+ readonly expiresAt: number;
16
+ readonly calldataOrigin?: `0x${string}` | undefined;
17
+ };
18
+ /**
19
+ * @internal Deeply freezes a prepared plan. `detach` copies it first, so no object the caller
20
+ * passed in is frozen or shared with the plan.
21
+ */
22
+ export declare function freezePlan(plan: TransactionPlan, { detach }: {
23
+ readonly detach: boolean;
24
+ }): TransactionPlan;
@@ -0,0 +1,21 @@
1
+ import { deepFreeze } from "@morpho-org/morpho-ts";
2
+ /**
3
+ * @internal The stored plan header: version, chain, account, expiry, and the calldata origin when
4
+ * the intent has one.
5
+ */
6
+ export function planHeader({ chainId, account }, { expiresAt, calldataOrigin }) {
7
+ return {
8
+ version: 2,
9
+ chainId,
10
+ account,
11
+ expiresAt,
12
+ ...(calldataOrigin && { calldataOrigin }),
13
+ };
14
+ }
15
+ /**
16
+ * @internal Deeply freezes a prepared plan. `detach` copies it first, so no object the caller
17
+ * passed in is frozen or shared with the plan.
18
+ */
19
+ export function freezePlan(plan, { detach }) {
20
+ return deepFreeze(detach ? structuredClone(plan) : plan);
21
+ }
@@ -1,12 +1,14 @@
1
- import { deepFreeze, MathLib, Time } from "@morpho-org/morpho-ts";
1
+ import { MathLib, Time } from "@morpho-org/morpho-ts";
2
2
  import { blueBorrow } from "../../actions/blue/borrow.js";
3
3
  import { normalizeBundlesCommonParams } from "../../actions/bundles/common.js";
4
4
  import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1QuoteTimestamp.js";
5
5
  import { DEFAULT_LLTV_BUFFER } from "../../helpers/index.js";
6
6
  import { validatePositionHealth } from "../../helpers/validate.js";
7
+ import { freezePlan, planHeader } from "../assemble.js";
7
8
  import { IncompleteTransactionPlanError, InvalidTransactionPlanError, } from "../error.js";
8
9
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
9
10
  import { prepareBlue, } from "./prepare.js";
11
+ import { BUNDLES_COMMON_FIELDS, signatureRoles, validateStoredBlueMarket, validateStoredReallocations, } from "./stored.js";
10
12
  /**
11
13
  * Prepares a BlueBundlesV1 borrow against existing collateral. No token allowance is needed.
12
14
  * Health uses the expiry, floored at max(now, lastUpdate), like the entity handle.
@@ -118,12 +120,8 @@ export async function prepareBlueBorrow(client, { chainId, account, marketId, ma
118
120
  reason: "expected prepared borrow inputs",
119
121
  });
120
122
  }
121
- return deepFreeze(structuredClone({
122
- version: 2,
123
- account: inputs.account,
124
- chainId: inputs.chainId,
125
- expiresAt: intent.expiresAt,
126
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
123
+ return freezePlan({
124
+ ...planHeader({ chainId: inputs.chainId, account: inputs.account }, intent),
127
125
  steps: [
128
126
  ...steps,
129
127
  {
@@ -135,14 +133,14 @@ export async function prepareBlueBorrow(client, { chainId, account, marketId, ma
135
133
  ...inputs,
136
134
  authorizationNonce: signatureRequests.find((request) => request.id === morphoAuthorizationRequestId)?.args.nonce ?? 0n,
137
135
  },
138
- signatureRequestIds: morphoAuthorizationRequestId
139
- ? { morphoAuthorization: morphoAuthorizationRequestId }
140
- : {},
136
+ signatureRequestIds: signatureRoles({
137
+ morphoAuthorization: morphoAuthorizationRequestId,
138
+ }),
141
139
  },
142
140
  },
143
141
  ],
144
142
  signatureRequests,
145
- }));
143
+ }, { detach: true });
146
144
  }
147
145
  /** @internal Encodes a prepared borrow without state reads or signing. */
148
146
  export function buildBlueBorrow(action, requests) {
@@ -185,26 +183,6 @@ export function buildBlueBorrow(action, requests) {
185
183
  },
186
184
  });
187
185
  }
188
- function validateMarket(value, path) {
189
- const market = getPlanObject(value, path);
190
- validatePlanFields(market, {
191
- path,
192
- fields: {
193
- id: "hex",
194
- loanToken: "address",
195
- collateralToken: "address",
196
- oracle: "address",
197
- irm: "address",
198
- lltv: "uint256 bigint",
199
- },
200
- });
201
- if (typeof market.id !== "string" || market.id.length !== 66) {
202
- throw new InvalidTransactionPlanError({
203
- path: `${path}.id`,
204
- reason: "expected a 32-byte market ID",
205
- });
206
- }
207
- }
208
186
  /** @internal Validates the stored borrow recipe, including each allocator input. */
209
187
  export function validateBorrowPlanAction(action, path) {
210
188
  const inputs = getPlanObject(action.inputs, `${path}.inputs`);
@@ -215,47 +193,19 @@ export function validateBorrowPlanAction(action, path) {
215
193
  borrowAssets: "uint256 bigint",
216
194
  authorizationNonce: "uint256 bigint",
217
195
  maxLtv: "uint256 bigint",
218
- deadline: "uint256 bigint",
219
- referralFeePct: "uint256 bigint",
220
- referralFeeRecipient: "address",
196
+ ...BUNDLES_COMMON_FIELDS,
221
197
  reallocations: "array",
222
198
  },
223
199
  });
224
- validateMarket(inputs.marketParams, `${path}.inputs.marketParams`);
200
+ validateStoredBlueMarket(inputs.marketParams, `${path}.inputs.marketParams`);
225
201
  if (inputs.maxPenalty !== undefined) {
226
202
  validatePlanField(inputs.maxPenalty, {
227
203
  path: `${path}.inputs.maxPenalty`,
228
204
  type: "uint256 bigint",
229
205
  });
230
206
  }
231
- for (const [index, value] of inputs.reallocations.entries()) {
232
- const entryPath = `${path}.inputs.reallocations[${index}]`;
233
- const entry = getPlanObject(value, entryPath);
234
- validatePlanFields(entry, {
235
- path: entryPath,
236
- fields: {
237
- vault: "address",
238
- assets: "uint256 bigint",
239
- penalty: "uint256 bigint",
240
- },
241
- });
242
- validatePlanFields(getPlanObject(entry.to, `${entryPath}.to`), {
243
- path: `${entryPath}.to`,
244
- fields: { adapter: "address" },
245
- });
246
- const from = getPlanObject(entry.from, `${entryPath}.from`);
247
- if (from.type !== "market" && from.type !== "idle") {
248
- throw new InvalidTransactionPlanError({
249
- path: `${entryPath}.from.type`,
250
- reason: "expected market or idle",
251
- });
252
- }
253
- if (from.type === "market") {
254
- validatePlanFields(from, {
255
- path: `${entryPath}.from`,
256
- fields: { adapter: "address" },
257
- });
258
- validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
259
- }
260
- }
207
+ validateStoredReallocations(inputs.reallocations, {
208
+ path: `${path}.inputs.reallocations`,
209
+ marketParams: validateStoredBlueMarket,
210
+ });
261
211
  }
@@ -1,14 +1,16 @@
1
1
  import { 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 { parseBlueAllocations, parseBlueBundlesV1Common, } from "../../actions/blue/common.js";
4
4
  import { blueRefinance } from "../../actions/blue/refinance.js";
5
5
  import { validateBlueRefinanceQuote, validateBlueRefinanceSource, } from "../../actions/blue/refinanceValidation.js";
6
6
  import { DEFAULT_LLTV_BUFFER } from "../../helpers/index.js";
7
7
  import { parseBlueMarket } from "../../helpers/parse.js";
8
+ import { freezePlan, planHeader } from "../assemble.js";
8
9
  import { IncompleteTransactionPlanError, InvalidTransactionPlanError, } from "../error.js";
9
10
  import { getPlanObject, validatePlanField, validatePlanFields, } from "../validation.js";
10
11
  import { prepareBlue, } from "./prepare.js";
11
12
  import { validateBlueRefinanceDestination } from "./refinanceValidation.js";
13
+ import { BUNDLES_COMMON_FIELDS, signatureRoles } from "./stored.js";
12
14
  /**
13
15
  * Prepares a full Blue borrow-position migration. Fetch both market and position snapshots at the
14
16
  * same block and pass that block's timestamp as `now`. Penalties and fees increase destination debt;
@@ -152,20 +154,18 @@ export async function prepareBlueRefinance(client, params) {
152
154
  ...(maxPenalty !== undefined && { maxPenalty }),
153
155
  ...(request && { authorizationNonce: request.args.nonce }),
154
156
  },
155
- signatureRequestIds: request === undefined ? {} : { morphoAuthorization: request.id },
157
+ signatureRequestIds: signatureRoles({
158
+ morphoAuthorization: request?.id,
159
+ }),
156
160
  };
157
- return deepFreeze(structuredClone({
158
- version: 2,
159
- account,
160
- chainId,
161
- expiresAt: intent.expiresAt,
162
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
161
+ return freezePlan({
162
+ ...planHeader({ chainId, account }, intent),
163
163
  steps: [
164
164
  ...steps,
165
165
  { id, label: "Refinance Blue borrow position", action },
166
166
  ],
167
167
  signatureRequests,
168
- }));
168
+ }, { detach: true });
169
169
  }
170
170
  function validatePlanMarketParams(value, path) {
171
171
  const params = getPlanObject(value, path);
@@ -241,9 +241,7 @@ export function validateRefinancePlanAction(action, path) {
241
241
  path: `${path}.inputs`,
242
242
  fields: {
243
243
  maxLtv: "uint256 bigint",
244
- deadline: "uint256 bigint",
245
- referralFeePct: "uint256 bigint",
246
- referralFeeRecipient: "address",
244
+ ...BUNDLES_COMMON_FIELDS,
247
245
  reallocations: "array",
248
246
  },
249
247
  });
@@ -1,5 +1,5 @@
1
1
  import { AccrualPosition, MarketParams, } 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 { maxUint256 } from "viem";
4
4
  import { getBlueBundlesV1ReferralFeeAssets } from "../../actions/blue/common.js";
5
5
  import { blueRepay } from "../../actions/blue/repay.js";
@@ -8,10 +8,12 @@ import { parseNativeFunding } from "../../helpers/parse.js";
8
8
  import { quoteBlueRepayFunding } from "../../helpers/quoteBlueRepay.js";
9
9
  import { validateReferralFee } from "../../helpers/validate.js";
10
10
  import { NonPositiveInputError } from "../../types/index.js";
11
+ import { freezePlan, planHeader } from "../assemble.js";
11
12
  import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "../error.js";
12
13
  import { getVaultPermit, validateTokenPermitRequest } from "../permit.js";
13
14
  import { getPlanObject, validatePlanFields } from "../validation.js";
14
15
  import { prepareBlue, } from "./prepare.js";
16
+ import { BUNDLES_COMMON_FIELDS, signatureRoles, validateStoredBlueMarketParams, } from "./stored.js";
15
17
  /**
16
18
  * Prepares an asset, share, or full Blue repayment through BlueBundlesV1, never Permit2.
17
19
  * Share quotes accrue the supplied position to expiry, at most two hours from the reference time.
@@ -133,12 +135,8 @@ export async function prepareBlueRepay(client, { chainId, account, marketId, mar
133
135
  reason: "expected resolved repayment inputs",
134
136
  });
135
137
  }
136
- return deepFreeze(structuredClone({
137
- version: 2,
138
- chainId: params.chainId,
139
- account: params.account,
140
- expiresAt: resolvedIntent.expiresAt,
141
- calldataOrigin: resolvedIntent.calldataOrigin,
138
+ return freezePlan({
139
+ ...planHeader({ chainId: params.chainId, account: params.account }, resolvedIntent),
142
140
  steps: [
143
141
  ...steps,
144
142
  {
@@ -147,14 +145,14 @@ export async function prepareBlueRepay(client, { chainId, account, marketId, mar
147
145
  action: {
148
146
  type: "blueRepay",
149
147
  inputs,
150
- signatureRequestIds: signatureRequests.length
151
- ? { tokenPermit: signatureRequests[0]?.id }
152
- : {},
148
+ signatureRequestIds: signatureRoles({
149
+ tokenPermit: signatureRequests[0]?.id,
150
+ }),
153
151
  },
154
152
  },
155
153
  ],
156
154
  signatureRequests,
157
- }));
155
+ }, { detach: true });
158
156
  }
159
157
  /** @internal Checks a repayment permit against the fixed token pull. */
160
158
  export function validateBlueRepayPermit(request, action) {
@@ -197,9 +195,7 @@ export function validateBlueRepayPlanAction(action, path) {
197
195
  repayAssets: "uint256 bigint",
198
196
  repayShares: "uint256 bigint",
199
197
  maxRepayAssets: "uint256 bigint",
200
- deadline: "uint256 bigint",
201
- referralFeePct: "uint256 bigint",
202
- referralFeeRecipient: "address",
198
+ ...BUNDLES_COMMON_FIELDS,
203
199
  },
204
200
  });
205
201
  if (inputs.nativeAssets !== undefined) {
@@ -208,16 +204,6 @@ export function validateBlueRepayPlanAction(action, path) {
208
204
  fields: { nativeAssets: "uint256 bigint" },
209
205
  });
210
206
  }
211
- const market = getPlanObject(inputs.marketParams, `${path}.inputs.marketParams`);
212
- validatePlanFields(market, {
213
- path: `${path}.inputs.marketParams`,
214
- fields: {
215
- loanToken: "address",
216
- collateralToken: "address",
217
- oracle: "address",
218
- irm: "address",
219
- lltv: "uint256 bigint",
220
- },
221
- });
207
+ validateStoredBlueMarketParams(inputs.marketParams, `${path}.inputs.marketParams`);
222
208
  getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
223
209
  }