@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
@@ -15,11 +15,13 @@ const index_js_1 = require("../../helpers/index.js");
15
15
  const parse_js_1 = require("../../helpers/parse.js");
16
16
  const quoteBlueRepay_js_1 = require("../../helpers/quoteBlueRepay.js");
17
17
  const index_js_2 = require("../../types/index.js");
18
+ const assemble_js_1 = require("../assemble.js");
18
19
  const error_js_1 = require("../error.js");
19
20
  const permit_js_1 = require("../permit.js");
20
21
  const validation_js_1 = require("../validation.js");
21
22
  const authorization_js_1 = require("./authorization.js");
22
23
  const prepare_js_1 = require("./prepare.js");
24
+ const stored_js_1 = require("./stored.js");
23
25
  /**
24
26
  * Prepares one BlueBundlesV1 repayment and collateral withdrawal from caller-fetched snapshots.
25
27
  * Withdrawal health uses the expiry floored at max(now, lastUpdate); expiries more than
@@ -79,23 +81,24 @@ const prepare_js_1 = require("./prepare.js");
79
81
  */
80
82
  async function prepareBlueRepayWithdrawCollateral(client, params) {
81
83
  const id = "blueRepayWithdrawCollateral";
82
- const now = params.now ?? morpho_ts_1.Time.timestamp();
84
+ const captured = captureRepayWithdrawInputs(params);
85
+ const { chainId, account, marketId, marketData, now } = captured;
83
86
  let inputs;
84
- const prepared = await (0, prepare_js_1.prepareBlue)({ client, params: { ...params, now } }, (intent) => {
85
- const marketParams = params.marketData.market.params;
87
+ const prepared = await (0, prepare_js_1.prepareBlue)({ client, params: captured }, (intent) => {
88
+ const marketParams = marketData.market.params;
86
89
  // Reject chain and referral mismatches before deriving a repayment quote.
87
- (0, index_js_1.validateChainId)(client.chain?.id, params.chainId);
90
+ (0, index_js_1.validateChainId)(client.chain?.id, chainId);
88
91
  const common = (0, common_js_1.parseBlueBundlesV1Common)({
89
- chainId: params.chainId,
90
- userAddress: params.account,
92
+ chainId,
93
+ userAddress: account,
91
94
  deadline: intent.deadline,
92
95
  referralFeePct: intent.referralFeePct,
93
96
  referralFeeRecipient: intent.referralFeeRecipient,
94
97
  });
95
- const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params);
98
+ const { repayAssets, repayShares, collateralAssets, hasRepay } = getRepayWithdrawAmounts(params, marketId);
96
99
  const quoteParams = {
97
- positionData: getMatchingPosition(params),
98
- marketId: params.marketId,
100
+ positionData: getMatchingPosition(captured),
101
+ marketId,
99
102
  repayAssets,
100
103
  repayShares,
101
104
  deadline: intent.deadline,
@@ -106,7 +109,7 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
106
109
  const maxRepayAssets = expectedRepayAssets +
107
110
  (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, common.referralFeePct);
108
111
  const nativeValue = (0, parse_js_1.parseNativeFunding)({
109
- chainId: params.chainId,
112
+ chainId,
110
113
  token: marketParams.loanToken,
111
114
  fundedAmount: maxRepayAssets,
112
115
  nativeAmount: params.funding?.type === "native" ? maxRepayAssets : undefined,
@@ -121,13 +124,13 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
121
124
  positionData: postRepayPosition,
122
125
  withdrawAmount: collateralAssets,
123
126
  lltv: marketParams.lltv,
124
- marketId: params.marketData.market.id,
127
+ marketId,
125
128
  });
126
129
  }
127
130
  const tx = (0, repayWithdrawCollateral_js_1.blueRepayWithdrawCollateral)({
128
- market: { chainId: params.chainId, marketParams },
131
+ market: { chainId, marketParams },
129
132
  args: {
130
- userAddress: params.account,
133
+ userAddress: account,
131
134
  repayAssets,
132
135
  repayShares,
133
136
  maxRepayAssets,
@@ -143,8 +146,8 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
143
146
  inputs = {
144
147
  ...args,
145
148
  ...(nativeAmount !== undefined && { nativeAssets: nativeAmount }),
146
- chainId: params.chainId,
147
- account: params.account,
149
+ chainId,
150
+ account,
148
151
  marketParams: {
149
152
  loanToken: marketParams.loanToken,
150
153
  collateralToken: marketParams.collateralToken,
@@ -161,27 +164,20 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
161
164
  needsAuthorization: args.collateralAssets > 0n,
162
165
  };
163
166
  });
164
- await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
167
+ await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
165
168
  if (inputs === undefined) {
166
169
  throw new error_js_1.IncompleteTransactionPlanError(id);
167
170
  }
168
- const signatureRequestIds = Object.fromEntries(prepared.signatureRequests
169
- .filter((request) => request.kind === "permit")
170
- .map((request) => ["tokenPermit", request.id]));
171
- if (prepared.morphoAuthorizationRequestId !== undefined) {
172
- signatureRequestIds.morphoAuthorization =
173
- prepared.morphoAuthorizationRequestId;
174
- }
171
+ const signatureRequestIds = (0, stored_js_1.signatureRoles)({
172
+ tokenPermit: prepared.signatureRequests.find((request) => request.kind === "permit")?.id,
173
+ morphoAuthorization: prepared.morphoAuthorizationRequestId,
174
+ });
175
175
  const authorization = prepared.signatureRequests.find((request) => request.kind === "morphoAuthorization");
176
176
  if (authorization !== undefined) {
177
177
  inputs = { ...inputs, authorizationNonce: authorization.args.nonce };
178
178
  }
179
- return (0, morpho_ts_1.deepFreeze)(structuredClone({
180
- version: 2,
181
- chainId: params.chainId,
182
- account: params.account,
183
- expiresAt: prepared.intent.expiresAt,
184
- calldataOrigin: prepared.intent.calldataOrigin,
179
+ return (0, assemble_js_1.freezePlan)({
180
+ ...(0, assemble_js_1.planHeader)({ chainId, account }, prepared.intent),
185
181
  steps: [
186
182
  ...prepared.steps,
187
183
  {
@@ -191,7 +187,7 @@ async function prepareBlueRepayWithdrawCollateral(client, params) {
191
187
  },
192
188
  ],
193
189
  signatureRequests: prepared.signatureRequests,
194
- }));
190
+ }, { detach: true });
195
191
  }
196
192
  function getRepayWithdrawLabel(inputs) {
197
193
  if (inputs.collateralAssets === 0n) {
@@ -212,6 +208,25 @@ const MARKET_STATE_FIELDS = [
212
208
  "price",
213
209
  "rateAtTarget",
214
210
  ];
211
+ function captureRepayWithdrawInputs(params) {
212
+ const { chainId, account, marketId, marketData, positionData } = params;
213
+ return {
214
+ chainId,
215
+ account,
216
+ marketId,
217
+ marketData: { chainId: marketData.chainId, market: marketData.market },
218
+ positionData: {
219
+ chainId: positionData.chainId,
220
+ position: positionData.position,
221
+ },
222
+ now: params.now ?? morpho_ts_1.Time.timestamp(),
223
+ expiresAt: params.expiresAt,
224
+ supportSignature: params.supportSignature,
225
+ referralFee: params.referralFee,
226
+ calldataOrigin: params.calldataOrigin,
227
+ deployless: params.deployless,
228
+ };
229
+ }
215
230
  function getMatchingPosition(params) {
216
231
  const { position } = params.positionData;
217
232
  const positionMarket = position.market;
@@ -253,8 +268,8 @@ function quoteWithdrawal(quoteParams, collateralAssets) {
253
268
  }),
254
269
  });
255
270
  }
256
- function getRepayWithdrawAmounts(params) {
257
- const { collateralAssets, marketId } = params;
271
+ function getRepayWithdrawAmounts(params, marketId) {
272
+ const { collateralAssets } = params;
258
273
  const repayAssets = params.repayAssets ?? 0n;
259
274
  const repayShares = params.repayShares ?? 0n;
260
275
  if (repayAssets < 0n) {
@@ -368,9 +383,7 @@ function validateRepayWithdrawCollateralPlanAction(action, path) {
368
383
  maxRepayAssets: "uint256 bigint",
369
384
  collateralAssets: "uint256 bigint",
370
385
  maxLtv: "uint256 bigint",
371
- deadline: "uint256 bigint",
372
- referralFeePct: "uint256 bigint",
373
- referralFeeRecipient: "address",
386
+ ...stored_js_1.BUNDLES_COMMON_FIELDS,
374
387
  },
375
388
  });
376
389
  if (inputs.repayAssets > 0n &&
@@ -386,16 +399,7 @@ function validateRepayWithdrawCollateralPlanAction(action, path) {
386
399
  fields: { nativeAssets: "uint256 bigint" },
387
400
  });
388
401
  }
389
- (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(inputs.marketParams, `${path}.inputs.marketParams`), {
390
- path: `${path}.inputs.marketParams`,
391
- fields: {
392
- loanToken: "address",
393
- collateralToken: "address",
394
- oracle: "address",
395
- irm: "address",
396
- lltv: "uint256 bigint",
397
- },
398
- });
402
+ (0, stored_js_1.validateStoredBlueMarketParams)(inputs.marketParams, `${path}.inputs.marketParams`);
399
403
  const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
400
404
  if (inputs.authorizationNonce !== undefined ||
401
405
  ids.morphoAuthorization !== undefined) {
@@ -0,0 +1,26 @@
1
+ /** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
2
+ export declare const BUNDLES_COMMON_FIELDS: {
3
+ readonly deadline: "uint256 bigint";
4
+ readonly referralFeePct: "uint256 bigint";
5
+ readonly referralFeeRecipient: "address";
6
+ };
7
+ /** @internal Validates a stored five-field Blue market tuple at `path`. */
8
+ export declare function validateStoredBlueMarketParams(value: unknown, path: string): void;
9
+ /** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
10
+ export declare function validateStoredBlueMarket(value: unknown, path: string): void;
11
+ /**
12
+ * @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
13
+ * with `marketParams`.
14
+ */
15
+ export declare function validateStoredReallocations(reallocations: readonly unknown[], { path, marketParams, }: {
16
+ readonly path: string;
17
+ readonly marketParams: (value: unknown, path: string) => void;
18
+ }): void;
19
+ /** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
20
+ export declare function signatureRoles({ tokenPermit, morphoAuthorization, }: {
21
+ readonly tokenPermit?: string;
22
+ readonly morphoAuthorization?: string;
23
+ }): {
24
+ tokenPermit?: string | undefined;
25
+ morphoAuthorization?: string | undefined;
26
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BUNDLES_COMMON_FIELDS = void 0;
4
+ exports.validateStoredBlueMarketParams = validateStoredBlueMarketParams;
5
+ exports.validateStoredBlueMarket = validateStoredBlueMarket;
6
+ exports.validateStoredReallocations = validateStoredReallocations;
7
+ exports.signatureRoles = signatureRoles;
8
+ const error_js_1 = require("../error.js");
9
+ const validation_js_1 = require("../validation.js");
10
+ /** @internal The stored BlueBundlesV1 deadline and referral fields, in their validation order. */
11
+ exports.BUNDLES_COMMON_FIELDS = {
12
+ deadline: "uint256 bigint",
13
+ referralFeePct: "uint256 bigint",
14
+ referralFeeRecipient: "address",
15
+ };
16
+ const MARKET_PARAMS_FIELDS = {
17
+ loanToken: "address",
18
+ collateralToken: "address",
19
+ oracle: "address",
20
+ irm: "address",
21
+ lltv: "uint256 bigint",
22
+ };
23
+ /** @internal Validates a stored five-field Blue market tuple at `path`. */
24
+ function validateStoredBlueMarketParams(value, path) {
25
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(value, path), {
26
+ path,
27
+ fields: MARKET_PARAMS_FIELDS,
28
+ });
29
+ }
30
+ /** @internal Validates a stored Blue market tuple that also carries its 32-byte market ID. */
31
+ function validateStoredBlueMarket(value, path) {
32
+ const market = (0, validation_js_1.getPlanObject)(value, path);
33
+ (0, validation_js_1.validatePlanFields)(market, {
34
+ path,
35
+ fields: { id: "hex", ...MARKET_PARAMS_FIELDS },
36
+ });
37
+ if (typeof market.id !== "string" || market.id.length !== 66) {
38
+ throw new error_js_1.InvalidTransactionPlanError({
39
+ path: `${path}.id`,
40
+ reason: "expected a 32-byte market ID",
41
+ });
42
+ }
43
+ }
44
+ /**
45
+ * @internal Validates stored Vault V2 reallocations at `path`, checking each source market tuple
46
+ * with `marketParams`.
47
+ */
48
+ function validateStoredReallocations(reallocations, { path, marketParams, }) {
49
+ for (const [index, value] of reallocations.entries()) {
50
+ const entryPath = `${path}[${index}]`;
51
+ const entry = (0, validation_js_1.getPlanObject)(value, entryPath);
52
+ (0, validation_js_1.validatePlanFields)(entry, {
53
+ path: entryPath,
54
+ fields: {
55
+ vault: "address",
56
+ assets: "uint256 bigint",
57
+ penalty: "uint256 bigint",
58
+ },
59
+ });
60
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.to, `${entryPath}.to`), {
61
+ path: `${entryPath}.to`,
62
+ fields: { adapter: "address" },
63
+ });
64
+ const from = (0, validation_js_1.getPlanObject)(entry.from, `${entryPath}.from`);
65
+ if (from.type === "idle") {
66
+ continue;
67
+ }
68
+ if (from.type !== "market") {
69
+ throw new error_js_1.InvalidTransactionPlanError({
70
+ path: `${entryPath}.from.type`,
71
+ reason: "expected market or idle",
72
+ });
73
+ }
74
+ (0, validation_js_1.validatePlanFields)(from, {
75
+ path: `${entryPath}.from`,
76
+ fields: { adapter: "address" },
77
+ });
78
+ marketParams(from.marketParams, `${entryPath}.from.marketParams`);
79
+ }
80
+ }
81
+ /** @internal Builds an action's role map with only the roles that reference a request, in argument order. */
82
+ function signatureRoles({ tokenPermit, morphoAuthorization, }) {
83
+ return {
84
+ ...(tokenPermit !== undefined && { tokenPermit }),
85
+ ...(morphoAuthorization !== undefined && { morphoAuthorization }),
86
+ };
87
+ }
@@ -5,14 +5,15 @@ exports.prepareBlueSupply = prepareBlueSupply;
5
5
  exports.validateBlueSupplyPermitRequest = validateBlueSupplyPermitRequest;
6
6
  exports.buildBlueSupply = buildBlueSupply;
7
7
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
8
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
9
8
  const supply_js_1 = require("../../actions/blue/supply.js");
10
9
  const common_js_1 = require("../../actions/bundles/common.js");
11
10
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
11
+ const assemble_js_1 = require("../assemble.js");
12
12
  const error_js_1 = require("../error.js");
13
13
  const permit_js_1 = require("../permit.js");
14
14
  const validation_js_1 = require("../validation.js");
15
15
  const prepare_js_1 = require("./prepare.js");
16
+ const stored_js_1 = require("./stored.js");
16
17
  /** @internal Validates the stored supply recipe without requiring class instances. */
17
18
  function validateBlueSupplyPlanAction(action, path) {
18
19
  const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
@@ -20,9 +21,7 @@ function validateBlueSupplyPlanAction(action, path) {
20
21
  path: `${path}.inputs`,
21
22
  fields: {
22
23
  assets: "uint256 bigint",
23
- deadline: "uint256 bigint",
24
- referralFeePct: "uint256 bigint",
25
- referralFeeRecipient: "address",
24
+ ...stored_js_1.BUNDLES_COMMON_FIELDS,
26
25
  },
27
26
  });
28
27
  if (inputs.nativeAssets !== undefined) {
@@ -32,17 +31,7 @@ function validateBlueSupplyPlanAction(action, path) {
32
31
  });
33
32
  validateNativeAssets(inputs, `${path}.inputs.nativeAssets`);
34
33
  }
35
- const market = (0, validation_js_1.getPlanObject)(inputs.marketParams, `${path}.inputs.marketParams`);
36
- (0, validation_js_1.validatePlanFields)(market, {
37
- path: `${path}.inputs.marketParams`,
38
- fields: {
39
- loanToken: "address",
40
- collateralToken: "address",
41
- oracle: "address",
42
- irm: "address",
43
- lltv: "uint256 bigint",
44
- },
45
- });
34
+ (0, stored_js_1.validateStoredBlueMarketParams)(inputs.marketParams, `${path}.inputs.marketParams`);
46
35
  (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
47
36
  }
48
37
  /**
@@ -157,12 +146,8 @@ async function prepareBlueSupply(client, params) {
157
146
  });
158
147
  await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
159
148
  const { intent, steps, signatureRequests } = prepared;
160
- return (0, morpho_ts_1.deepFreeze)(structuredClone({
161
- version: 2,
162
- chainId,
163
- account,
164
- expiresAt: intent.expiresAt,
165
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
149
+ return (0, assemble_js_1.freezePlan)({
150
+ ...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
166
151
  steps: [
167
152
  ...steps,
168
153
  {
@@ -185,7 +170,7 @@ async function prepareBlueSupply(client, params) {
185
170
  },
186
171
  ],
187
172
  signatureRequests,
188
- }));
173
+ }, { detach: true });
189
174
  }
190
175
  /** @internal Binds an exact token permit to this supply's pull. */
191
176
  function validateBlueSupplyPermitRequest(request, action) {
@@ -45,7 +45,7 @@ export interface BlueSupplyCollateralPlanParams extends IntentParams, ReferenceT
45
45
  * @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
46
46
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
47
47
  * @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
48
- * @param params.calldataOrigin - Optional non-empty hex bytes appended to each built transaction.
48
+ * @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
49
49
  * @param params.deployless - Whether permit metadata reads may use deployless aggregation.
50
50
  * @returns A frozen plan containing the collateral supply step and any token prerequisites.
51
51
  * @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
@@ -5,16 +5,17 @@ exports.validateSupplyCollateralPlanAction = validateSupplyCollateralPlanAction;
5
5
  exports.validateSupplyCollateralPermitRequest = validateSupplyCollateralPermitRequest;
6
6
  exports.buildBlueSupplyCollateral = buildBlueSupplyCollateral;
7
7
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
8
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
9
8
  const viem_1 = require("viem");
10
9
  const supplyCollateral_js_1 = require("../../actions/blue/supplyCollateral.js");
11
10
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
11
  const validate_js_1 = require("../../helpers/validate.js");
13
12
  const index_js_1 = require("../../types/index.js");
13
+ const assemble_js_1 = require("../assemble.js");
14
14
  const error_js_1 = require("../error.js");
15
15
  const permit_js_1 = require("../permit.js");
16
16
  const validation_js_1 = require("../validation.js");
17
17
  const prepare_js_1 = require("./prepare.js");
18
+ const stored_js_1 = require("./stored.js");
18
19
  const actionId = "blueSupplyCollateral";
19
20
  /**
20
21
  * Prepares a collateral-only supply through BlueBundlesV1 from a caller-fetched market snapshot.
@@ -34,7 +35,7 @@ const actionId = "blueSupplyCollateral";
34
35
  * @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
35
36
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
36
37
  * @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
37
- * @param params.calldataOrigin - Optional non-empty hex bytes appended to each built transaction.
38
+ * @param params.calldataOrigin - Optional non-empty hex bytes appended to the action transaction's calldata; approval and authorization steps carry none.
38
39
  * @param params.deployless - Whether permit metadata reads may use deployless aggregation.
39
40
  * @returns A frozen plan containing the collateral supply step and any token prerequisites.
40
41
  * @throws {BlueSnapshotChainMismatchError} when the snapshot comes from another chain.
@@ -99,12 +100,8 @@ async function prepareBlueSupplyCollateral(client, params) {
99
100
  await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
100
101
  }
101
102
  const tokenPermit = signatureRequests.find(({ kind }) => kind === "permit");
102
- return (0, morpho_ts_1.deepFreeze)(structuredClone({
103
- version: 2,
104
- chainId,
105
- account,
106
- expiresAt: intent.expiresAt,
107
- ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
103
+ return (0, assemble_js_1.freezePlan)({
104
+ ...(0, assemble_js_1.planHeader)({ chainId, account }, intent),
108
105
  steps: [
109
106
  ...steps,
110
107
  {
@@ -122,14 +119,14 @@ async function prepareBlueSupplyCollateral(client, params) {
122
119
  referralFeePct: intent.referralFeePct,
123
120
  referralFeeRecipient: intent.referralFeeRecipient ?? viem_1.zeroAddress,
124
121
  },
125
- signatureRequestIds: tokenPermit
126
- ? { tokenPermit: tokenPermit.id }
127
- : {},
122
+ signatureRequestIds: (0, stored_js_1.signatureRoles)({
123
+ tokenPermit: tokenPermit?.id,
124
+ }),
128
125
  },
129
126
  },
130
127
  ],
131
128
  signatureRequests,
132
- }));
129
+ }, { detach: true });
133
130
  }
134
131
  /** @internal Validates the stored collateral supply action and its token permit role. */
135
132
  function validateSupplyCollateralPlanAction(action, path) {
@@ -139,9 +136,7 @@ function validateSupplyCollateralPlanAction(action, path) {
139
136
  path: inputsPath,
140
137
  fields: {
141
138
  collateralAssets: "uint256 bigint",
142
- deadline: "uint256 bigint",
143
- referralFeePct: "uint256 bigint",
144
- referralFeeRecipient: "address",
139
+ ...stored_js_1.BUNDLES_COMMON_FIELDS,
145
140
  },
146
141
  });
147
142
  const marketPath = `${inputsPath}.marketParams`;
@@ -13,11 +13,13 @@ const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundle
13
13
  const index_js_1 = require("../../helpers/index.js");
14
14
  const parse_js_1 = require("../../helpers/parse.js");
15
15
  const index_js_2 = require("../../types/index.js");
16
+ const assemble_js_1 = require("../assemble.js");
16
17
  const error_js_1 = require("../error.js");
17
18
  const permit_js_1 = require("../permit.js");
18
19
  const validation_js_1 = require("../validation.js");
19
20
  const authorization_js_1 = require("./authorization.js");
20
21
  const prepare_js_1 = require("./prepare.js");
22
+ const stored_js_1 = require("./stored.js");
21
23
  /**
22
24
  * Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
23
25
  * are validated before reads; health uses the expiry floored at max(now, lastUpdate).
@@ -162,14 +164,8 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
162
164
  await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
163
165
  const authorization = prepared.signatureRequests.find((request) => request.id === prepared.morphoAuthorizationRequestId);
164
166
  const permit = prepared.signatureRequests.find((request) => request.kind === "permit");
165
- return (0, morpho_ts_1.deepFreeze)(structuredClone({
166
- version: 2,
167
- chainId,
168
- account,
169
- expiresAt: prepared.intent.expiresAt,
170
- ...(prepared.intent.calldataOrigin && {
171
- calldataOrigin: prepared.intent.calldataOrigin,
172
- }),
167
+ return (0, assemble_js_1.freezePlan)({
168
+ ...(0, assemble_js_1.planHeader)({ chainId, account }, prepared.intent),
173
169
  steps: [
174
170
  ...prepared.steps,
175
171
  {
@@ -205,15 +201,15 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
205
201
  authorizationNonce: authorization.args.nonce,
206
202
  }),
207
203
  },
208
- signatureRequestIds: {
209
- ...(permit && { tokenPermit: permit.id }),
210
- ...(authorization && { morphoAuthorization: authorization.id }),
211
- },
204
+ signatureRequestIds: (0, stored_js_1.signatureRoles)({
205
+ tokenPermit: permit?.id,
206
+ morphoAuthorization: authorization?.id,
207
+ }),
212
208
  },
213
209
  },
214
210
  ],
215
211
  signatureRequests: prepared.signatureRequests,
216
- }));
212
+ }, { detach: true });
217
213
  }
218
214
  function captureSupplyBorrowIntent(params) {
219
215
  const { chainId, account, marketId, marketData, positionData, expiresAt, referralFee, supportSignature, calldataOrigin, deployless, now = morpho_ts_1.Time.timestamp(), } = params;
@@ -300,26 +296,6 @@ function buildBlueSupplyCollateralBorrow(action, requests) {
300
296
  },
301
297
  });
302
298
  }
303
- function validateMarket(value, path) {
304
- const market = (0, validation_js_1.getPlanObject)(value, path);
305
- (0, validation_js_1.validatePlanFields)(market, {
306
- path,
307
- fields: {
308
- id: "hex",
309
- loanToken: "address",
310
- collateralToken: "address",
311
- oracle: "address",
312
- irm: "address",
313
- lltv: "uint256 bigint",
314
- },
315
- });
316
- if (typeof market.id !== "string" || market.id.length !== 66) {
317
- throw new error_js_1.InvalidTransactionPlanError({
318
- path: `${path}.id`,
319
- reason: "expected a 32-byte market ID",
320
- });
321
- }
322
- }
323
299
  /** @internal Validates the complete stored input and reallocation shape. */
324
300
  function validateSupplyCollateralBorrowPlanAction(action, path) {
325
301
  const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
@@ -352,7 +328,7 @@ function validateSupplyCollateralBorrowPlanAction(action, path) {
352
328
  type: "address",
353
329
  });
354
330
  }
355
- validateMarket(inputs.marketParams, `${path}.inputs.marketParams`);
331
+ (0, stored_js_1.validateStoredBlueMarket)(inputs.marketParams, `${path}.inputs.marketParams`);
356
332
  const ids = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
357
333
  for (const key of Object.keys(ids)) {
358
334
  if (key !== "tokenPermit" && key !== "morphoAuthorization") {
@@ -379,34 +355,8 @@ function validateSupplyCollateralBorrowPlanAction(action, path) {
379
355
  type: "uint256 bigint",
380
356
  });
381
357
  }
382
- for (const [index, value] of inputs.reallocations.entries()) {
383
- const entryPath = `${path}.inputs.reallocations[${index}]`;
384
- const entry = (0, validation_js_1.getPlanObject)(value, entryPath);
385
- (0, validation_js_1.validatePlanFields)(entry, {
386
- path: entryPath,
387
- fields: {
388
- vault: "address",
389
- assets: "uint256 bigint",
390
- penalty: "uint256 bigint",
391
- },
392
- });
393
- (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.to, `${entryPath}.to`), {
394
- path: `${entryPath}.to`,
395
- fields: { adapter: "address" },
396
- });
397
- const from = (0, validation_js_1.getPlanObject)(entry.from, `${entryPath}.from`);
398
- if (from.type === "market") {
399
- (0, validation_js_1.validatePlanFields)(from, {
400
- path: `${entryPath}.from`,
401
- fields: { adapter: "address" },
402
- });
403
- validateMarket(from.marketParams, `${entryPath}.from.marketParams`);
404
- }
405
- else if (from.type !== "idle") {
406
- throw new error_js_1.InvalidTransactionPlanError({
407
- path: `${entryPath}.from.type`,
408
- reason: "expected market or idle",
409
- });
410
- }
411
- }
358
+ (0, stored_js_1.validateStoredReallocations)(inputs.reallocations, {
359
+ path: `${path}.inputs.reallocations`,
360
+ marketParams: stored_js_1.validateStoredBlueMarket,
361
+ });
412
362
  }
@@ -69,7 +69,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
69
69
  * @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
70
70
  * @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
71
71
  * @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`.
72
- * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to every built transaction; omitted by default.
72
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the action transaction's calldata, not to approval or authorization steps; omitted by default.
73
73
  * @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
74
74
  * @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
75
75
  * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
@@ -100,7 +100,6 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
100
100
  * @throws {WithdrawSharesExceedSupplyError} when `shares` exceeds the position's supply shares.
101
101
  * @throws {MissingContractCodeError} when registered BlueBundlesV1 or Blue has no deployed code.
102
102
  * @throws {viem.BaseError} when a chain, bytecode, authorization or nonce RPC read fails, or ABI encoding rejects malformed input.
103
- * @throws {UnexpectedRequirementSignatureError} when an authorization requirement returns a nonce that is not a bigint.
104
103
  * @throws {TransactionPlanSignatureMismatchError} when the authorization requirement does not match the prepared account, chain, nonce or deadline.
105
104
  * @example
106
105
  * ```ts
@@ -120,7 +119,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
120
119
  * positionData: { chainId: mainnet.id, position },
121
120
  * now: (await client.getBlock()).timestamp,
122
121
  * });
123
- * // plan: { version: 1, chainId, account, expiresAt, steps, signatureRequests }
122
+ * // plan: { version: 2, chainId, account, expiresAt, steps, signatureRequests }
124
123
  * // Sign any pending Morpho authorization request, then build and submit each step in order.
125
124
  * ```
126
125
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.