@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,254 @@
1
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
2
+ import { midnightSupplyCollateralWithNative, parseMidnightSupplyCollateralWithNative, } from "../../actions/midnight/supplyCollateralWithNative.js";
3
+ import { createChainCheck } from "../../actions/requirements/chainCheck.js";
4
+ import { assertRegistryTargetsHaveCode } from "../../entities/requirements/assertContractCode.js";
5
+ import { validateReferenceTime } from "../../helpers/validate.js";
6
+ import { InvalidBigIntInputError, } from "../../types/index.js";
7
+ import { InvalidTransactionPlanError } from "../error.js";
8
+ import { resolveIntent } from "../intent.js";
9
+ import { getTokenRequirements } from "../requirements.js";
10
+ import { getPlanObject, validatePlanFields } from "../validation.js";
11
+ import { prepareMidnightBundleAuthorization, validateSignaturelessMidnightAction, } from "./authorization.js";
12
+ import { storedMarketTuple, validateStoredCollateralOrder } from "./market.js";
13
+ import { validateStoredMidnightMarket } from "./validation.js";
14
+ const actionId = "midnightSupplyCollateralWithNative";
15
+ /**
16
+ * Prepares a payable MidnightBundlesV2 collateral supply that wraps native currency, with no
17
+ * borrow or offer. Inputs go through `parseMidnightSupplyCollateralWithNative`, which applies
18
+ * the checks of the `midnightSupplyCollateralWithNative` builder the entity uses, in the same
19
+ * order, without encoding the call. The bundle wraps `nativeAmount` into wNative for the sender
20
+ * and pulls `collateralAssets` from the sender, so the plan adds an ERC-20 approval to
21
+ * MidnightBundlesV2 for the full collateral amount when the allowance is insufficient, even with
22
+ * full native funding, as the entity does. It adds the standalone bundle authorization only when
23
+ * missing and never requests signatures. The bundle enforces the plan expiry as its deadline.
24
+ * The plan reads no balances: the wallet needs `collateralAssets - nativeAmount` wNative plus the
25
+ * native value and gas, so simulate every step together before asking for the first approval.
26
+ * Unlike the entity, the allowance check keeps no `reservedCollateralAssets` reserve, so the
27
+ * supply can consume an allowance another operation relies on.
28
+ * @param client - Viem client used to check the network and deployments and read prerequisites.
29
+ * @param params - Market, wNative collateral selection, total amount, native funding and sending account.
30
+ * @param params.chainId - Chain containing the market, Midnight core and MidnightBundlesV2.
31
+ * @param params.account - Non-zero account that sends the value and receives the collateral position.
32
+ * @param params.market - Market configuration on the target chain.
33
+ * @param params.collateralIndex - Index of the registered wNative collateral in token-address order. Defaults to `0n`.
34
+ * @param params.collateralAssets - Positive total collateral in wNative base units.
35
+ * @param params.nativeAmount - Positive native funding in wei, at most `collateralAssets`; any rest is pulled as wNative.
36
+ * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
37
+ * @param params.expiresAt - Bundle execution deadline in Unix seconds; defaults to two hours after `now`.
38
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
39
+ * @returns A frozen plan whose steps must be submitted in order from `params.account`.
40
+ * @throws {InvalidBigIntInputError} If a supplied non-null `now`, the collateral amount or the index is not a bigint; checked before any request.
41
+ * @throws {ZeroAccountError} If the account is the zero address.
42
+ * @throws {NonIntegerInputError} If expiry is not a safe integer.
43
+ * @throws {ExpiredDeadlineError} If expiry is at or before the reference time.
44
+ * @throws {InvalidCalldataOriginError} If attribution bytes are empty or malformed.
45
+ * @throws {InvalidTransactionPlanError} If the account is malformed or attribution exceeds 1 MiB.
46
+ * @throws {NonPositiveInputError} If the collateral amount, native amount or expiry is not positive.
47
+ * @throws {InputExceedsMaxError} If the collateral amount exceeds uint128 or the native amount exceeds the collateral amount.
48
+ * @throws {ChainIdMismatchError} If the market, client or RPC targets another chain.
49
+ * @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
50
+ * @throws {InvalidMarketParameterError} If the market's chain ID or collateral configuration is invalid.
51
+ * @throws {MidnightCalldataEncodingError} If market fields cannot be ABI-encoded.
52
+ * @throws {UnknownCollateralIndexError} If the index is not configured on the market.
53
+ * @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
54
+ * @throws {NegativeInputError} If `nativeAmount` is negative.
55
+ * @throws {ChainWNativeMissingError} If the chain has no wrapped-native asset.
56
+ * @throws {NativeAmountOnNonWNativeAssetError} If the selected collateral is not wNative.
57
+ * @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
58
+ * @throws {UnknownAddressError} If Midnight core or MidnightBundlesV2 is not registered on the chain.
59
+ * @throws {MissingContractCodeError} If the registered bundle or Midnight core has no deployed code.
60
+ * @throws {viem.BaseError} If the chain ID, bytecode, allowance or authorization read fails.
61
+ * @example
62
+ * ```ts
63
+ * import {
64
+ * buildTransactions,
65
+ * prepareMidnightSupplyCollateralWithNative,
66
+ * type TransactionPlan,
67
+ * } from "@morpho-org/morpho-sdk";
68
+ * import { fetchMidnightMarketParams } from "@morpho-org/morpho-sdk/fetch";
69
+ * import { type Address, type Hash, createPublicClient, http } from "viem";
70
+ * import { base } from "viem/chains";
71
+ *
72
+ * // `collateralIndex` is the position of the chain's wNative in the market's collaterals.
73
+ * async function prepareNativeCollateralSupply(
74
+ * account: Address,
75
+ * marketId: Hash,
76
+ * collateralIndex: bigint,
77
+ * ) {
78
+ * const client = createPublicClient({ chain: base, transport: http() });
79
+ * const market = await fetchMidnightMarketParams(client, { marketId });
80
+ * const plan: TransactionPlan = await prepareMidnightSupplyCollateralWithNative(client, {
81
+ * chainId: base.id,
82
+ * account,
83
+ * market,
84
+ * collateralIndex,
85
+ * collateralAssets: 1_000_000_000_000_000n,
86
+ * nativeAmount: 1_000_000_000_000_000n,
87
+ * });
88
+ * // plan.steps: any wNative approval to MidnightBundlesV2, any bundle authorization, then
89
+ * // "midnightSupplyCollateralWithNative". Send them in order from plan.account on plan.chainId.
90
+ * return buildTransactions(plan);
91
+ * }
92
+ * ```
93
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
94
+ */
95
+ export async function prepareMidnightSupplyCollateralWithNative(client, params) {
96
+ const { account, chainId } = params;
97
+ const now = params.now ?? Time.timestamp();
98
+ validateReferenceTime(now);
99
+ const intent = resolveIntent({
100
+ account,
101
+ chainId,
102
+ expiresAt: params.expiresAt,
103
+ calldataOrigin: params.calldataOrigin,
104
+ }, now);
105
+ if (typeof params.collateralAssets !== "bigint") {
106
+ throw new InvalidBigIntInputError("collateralAssets", params.collateralAssets);
107
+ }
108
+ if (params.collateralIndex !== undefined &&
109
+ typeof params.collateralIndex !== "bigint") {
110
+ throw new InvalidBigIntInputError("collateralIndex", params.collateralIndex);
111
+ }
112
+ const parsed = parseMidnightSupplyCollateralWithNative({
113
+ chainId,
114
+ market: params.market,
115
+ collateralIndex: params.collateralIndex,
116
+ assets: params.collateralAssets,
117
+ accountAddress: account,
118
+ nativeAmount: params.nativeAmount,
119
+ deadline: intent.deadline,
120
+ }, "collateralAssets");
121
+ const chainCheck = createChainCheck(client, chainId);
122
+ await chainCheck();
123
+ const spender = getChainAddress(chainId, "midnightBundlesV2");
124
+ // Check deployments before an allowance or authorization read can fail decoding empty data.
125
+ await assertRegistryTargetsHaveCode(client, chainId, [
126
+ { role: "midnightBundlesV2", address: spender },
127
+ { role: "midnight", address: getChainAddress(chainId, "midnight") },
128
+ ], chainCheck);
129
+ const [{ approvals }, authorization] = await Promise.all([
130
+ getTokenRequirements(client, {
131
+ chainId,
132
+ token: parsed.token,
133
+ owner: account,
134
+ spender,
135
+ amount: parsed.assets,
136
+ approvalId: (index) => `${actionId}:approval:${index}`,
137
+ }),
138
+ prepareMidnightBundleAuthorization(client, { chainId, account }),
139
+ ]);
140
+ return deepFreeze({
141
+ version: 2,
142
+ chainId,
143
+ account,
144
+ expiresAt: intent.expiresAt,
145
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
146
+ steps: [
147
+ ...approvals,
148
+ ...(authorization === undefined ? [] : [authorization]),
149
+ {
150
+ id: actionId,
151
+ label: "Supply Midnight collateral with native currency",
152
+ action: {
153
+ type: actionId,
154
+ inputs: {
155
+ account,
156
+ chainId,
157
+ market: parsed.market,
158
+ collateralIndex: parsed.collateralIndex,
159
+ collateralAssets: parsed.assets,
160
+ nativeAssets: parsed.value,
161
+ deadline: parsed.deadline,
162
+ },
163
+ },
164
+ },
165
+ ],
166
+ signatureRequests: [],
167
+ });
168
+ }
169
+ /** @internal Encodes only the persisted inputs; no client or clock is needed. */
170
+ export function buildMidnightSupplyCollateralWithNative({ inputs, }) {
171
+ const { account, chainId, market, collateralIndex, collateralAssets, nativeAssets, deadline, } = inputs;
172
+ // The action builder defaults a missing index to 0n, which would switch the supplied token.
173
+ if (typeof collateralIndex !== "bigint") {
174
+ throw new InvalidTransactionPlanError({
175
+ path: "$.inputs.collateralIndex",
176
+ reason: "expected a bigint",
177
+ });
178
+ }
179
+ validateStoredCollateralOrder(market.collateralParams, "$.inputs.market.collateralParams");
180
+ return midnightSupplyCollateralWithNative({
181
+ chainId,
182
+ market: storedMarketTuple(market),
183
+ collateralIndex,
184
+ assets: collateralAssets,
185
+ accountAddress: account,
186
+ nativeAmount: nativeAssets,
187
+ deadline,
188
+ });
189
+ }
190
+ /** @internal Validates the stored native collateral supply recipe without RPC. */
191
+ export function validateMidnightSupplyCollateralWithNativePlanAction(action, path) {
192
+ const inputsPath = `${path}.inputs`;
193
+ const inputs = getPlanObject(action.inputs, inputsPath);
194
+ validatePlanFields(inputs, {
195
+ path: inputsPath,
196
+ fields: {
197
+ collateralAssets: "uint128 bigint",
198
+ collateralIndex: "uint256 bigint",
199
+ nativeAssets: "uint128 bigint",
200
+ deadline: "uint256 bigint",
201
+ },
202
+ });
203
+ const marketPath = `${inputsPath}.market`;
204
+ const market = getPlanObject(inputs.market, marketPath);
205
+ // Validate the tuple before reading its collateral tokens.
206
+ validateStoredMidnightMarket(market, {
207
+ path: marketPath,
208
+ chainId: inputs.chainId,
209
+ });
210
+ const collaterals = market.collateralParams;
211
+ validateStoredCollateralOrder(collaterals, `${marketPath}.collateralParams`);
212
+ if (inputs.collateralIndex >= BigInt(collaterals.length)) {
213
+ throw new InvalidTransactionPlanError({
214
+ path: `${inputsPath}.collateralIndex`,
215
+ reason: "expected an index configured in the market",
216
+ });
217
+ }
218
+ if (inputs.collateralAssets === 0n) {
219
+ throw new InvalidTransactionPlanError({
220
+ path: `${inputsPath}.collateralAssets`,
221
+ reason: "expected a positive amount",
222
+ });
223
+ }
224
+ if (inputs.nativeAssets === 0n ||
225
+ inputs.nativeAssets > inputs.collateralAssets) {
226
+ throw new InvalidTransactionPlanError({
227
+ path: `${inputsPath}.nativeAssets`,
228
+ reason: "expected a positive amount at most collateralAssets",
229
+ });
230
+ }
231
+ // Rerun the builder's parse step and bundle lookup so a restored plan can always build its supply step.
232
+ try {
233
+ const stored = action;
234
+ parseMidnightSupplyCollateralWithNative({
235
+ chainId: stored.inputs.chainId,
236
+ market: storedMarketTuple(stored.inputs.market),
237
+ collateralIndex: stored.inputs.collateralIndex,
238
+ assets: stored.inputs.collateralAssets,
239
+ accountAddress: stored.inputs.account,
240
+ nativeAmount: stored.inputs.nativeAssets,
241
+ deadline: stored.inputs.deadline,
242
+ }, "collateralAssets");
243
+ getChainAddress(stored.inputs.chainId, "midnightBundlesV2");
244
+ }
245
+ catch (cause) {
246
+ throw new InvalidTransactionPlanError({
247
+ path: inputsPath,
248
+ reason: "expected a valid Midnight native collateral supply",
249
+ cause,
250
+ });
251
+ }
252
+ // Midnight never consumes a signature reference.
253
+ validateSignaturelessMidnightAction(action, path);
254
+ }
@@ -0,0 +1,304 @@
1
+ import { AccrualPosition, type Market } from "@morpho-org/midnight-sdk";
2
+ import type { Address, Client } from "viem";
3
+ import { type MidnightSupplyCollateralTakeBorrowParams } from "../../actions/midnight/supplyCollateralTakeBorrow.js";
4
+ import { type MidnightTakeBorrowParams } from "../../actions/midnight/takeBorrow.js";
5
+ import { type IntentParams } from "../intent.js";
6
+ import type { Action, TransactionPlan } from "../types.js";
7
+ /**
8
+ * Inputs for preparing a fixed-rate borrow from caller-selected lend offers.
9
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
10
+ */
11
+ export interface MidnightTakeBorrowPlanParams extends Omit<IntentParams, "supportSignature" | "deployless">, Pick<MidnightTakeBorrowParams, "target" | "takeableOffers"> {
12
+ /** Hydrated market snapshot used to assess fill feasibility and collateral capacity. */
13
+ readonly marketData: Market;
14
+ /** Borrower's position snapshot for the same market. */
15
+ readonly positionData: AccrualPosition;
16
+ /** Oracle prices indexed by market collateral, scaled by ORACLE_PRICE_SCALE. */
17
+ readonly collateralPrices: readonly bigint[];
18
+ /** Recipient of the loan assets; defaults to account. */
19
+ readonly receiver?: Address;
20
+ /** Reference timestamp in seconds; defaults to the device clock. */
21
+ readonly now?: bigint;
22
+ /** Unix seconds; defaults to one hour after the reference timestamp. */
23
+ readonly expiresAt?: number;
24
+ }
25
+ /**
26
+ * Prepares a MidnightBundlesV2 borrow for the submitting account, using existing
27
+ * credit first and then filling lend offers under the given target and referral fee.
28
+ * Validates inputs with the same parse-once constructor, position binding, buffered health
29
+ * check and fill feasibility check as the entity `takeBorrow`, then reads the registry
30
+ * targets' bytecode and the bundle authorization. Feasibility uses the position's credit
31
+ * accrued to the reference timestamp against `marketData`, the same snapshot that caps
32
+ * withdrawable credit. On an assets target, offers that would revert the
33
+ * whole bundle are dropped from the stored fills. Like the entity check, fill feasibility counts
34
+ * units at par and does not price discounted bids after settlement fees, so a plan can pass
35
+ * preparation and still revert onchain; the onchain bounds keep funds safe. Simulate before sending.
36
+ * @param client - Viem client used to verify chain, deployments and authorization.
37
+ * @param params - Account, market and position snapshots, collateral prices, fills and intent.
38
+ * @param params.chainId - Chain containing the market and MidnightBundlesV2.
39
+ * @param params.account - Non-zero borrower that sends the plan and owns any new debt.
40
+ * @param params.marketData - Hydrated market snapshot used for fill feasibility and collateral capacity.
41
+ * @param params.positionData - Borrower's position snapshot for the same market.
42
+ * @param params.collateralPrices - Oracle prices indexed by market collateral, scaled by `ORACLE_PRICE_SCALE`.
43
+ * @param params.takeableOffers - ABI-ready lend offers from the caller's quote, in fill order.
44
+ * @param params.target.type - `"assets"` to receive loan assets, or `"units"` to sell exact units.
45
+ * @param params.target.assets - Exact loan assets paid to the receiver on an assets target; any referral fee is sold on top.
46
+ * @param params.target.maxUnits - Unit cap on an assets target; also bounds the buffered health check.
47
+ * @param params.target.units - Exact units to sell on a units target.
48
+ * @param params.target.minSellerAssets - Loan-asset floor on a units target, checked against the
49
+ * proceeds after any referral fee.
50
+ * @param params.receiver - Optional recipient of the loan assets; defaults to `account`.
51
+ * @param params.referralFee.bps - Optional referral fee in integer basis points, at most 10%.
52
+ * @param params.referralFee.recipient - Recipient required for a positive referral fee.
53
+ * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
54
+ * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
55
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
56
+ * @returns A frozen plan with a standalone authorization step if needed and no signature requests.
57
+ * @throws {InvalidBigIntInputError} If a supplied non-null `now`, or a target amount, is not a bigint;
58
+ * checked before any request.
59
+ * @throws {ZeroAccountError} If `account` is the zero address.
60
+ * @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
61
+ * @throws {NonPositiveInputError} If `expiresAt`, the target amount, `maxUnits` or
62
+ * `minSellerAssets` is not positive.
63
+ * @throws {ExpiredDeadlineError} If expiry is at or before the reference timestamp.
64
+ * @throws {NegativeInputError} If `referralFee.bps` or an offer cap is negative.
65
+ * @throws {InputExceedsMaxError} If `referralFee.bps` exceeds 1,000 (10%), or a target amount or
66
+ * offer cap exceeds uint128.
67
+ * @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
68
+ * @throws {MidnightTakeDeadlineTooFarError} If expiry is more than one hour away.
69
+ * @throws {InvalidTransactionPlanError} If `account` is malformed or the target type is neither assets nor units.
70
+ * @throws {ChainIdMismatchError} If the client, transport or market is on a different chain.
71
+ * @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
72
+ * @throws {EmptyMidnightTakeableOffersError} If no offers are supplied.
73
+ * @throws {MidnightOfferSideMismatchError} If an offer is not a lend offer.
74
+ * @throws {MidnightTakeableOfferMarketMismatchError} If an offer trades another market.
75
+ * @throws {MidnightCalldataEncodingError} If an offer field cannot be ABI-encoded.
76
+ * @throws {MidnightZeroReceiverError} If the receiver is the zero address.
77
+ * @throws {MidnightContractReceiverError} If the receiver, or the referral fee recipient of a
78
+ * positive fee, is a Midnight protocol or market token contract.
79
+ * @throws {UnboundedMidnightTakeInputError} If `target.units` or `target.maxUnits` is `maxUint256`.
80
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient.
81
+ * @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
82
+ * @throws {UnknownAddressError} If the chain has no `midnightBundlesV2` deployment.
83
+ * @throws {MarketIdMismatchError} If the position belongs to another market.
84
+ * @throws {AccrualPositionUserMismatchError} If the position is not owned by the account.
85
+ * @throws {BorrowExceedsSafeLtvError} If the debt bound exceeds buffered collateral capacity.
86
+ * @throws {MissingMarketPriceError} If any held collateral has no supplied price.
87
+ * @throws {InvalidMidnightPositionLossFactorError} If `marketData`'s loss factor is below the position's
88
+ * last loss factor; fetch the market and position at the same block.
89
+ * @throws {InvalidMidnightPositionAccrualStateError} If the position's credit and fee snapshot cannot be accrued.
90
+ * @throws {MidnightTakeableOffersNotFillableError} If the supplied offers cannot be used.
91
+ * @throws {MidnightTakeTargetUnreachableError} If the supplied target and bounds cannot be met.
92
+ * @throws {MissingContractCodeError} If either registered Midnight target has no deployed code.
93
+ * @throws {viem.BaseError} If an `eth_chainId` request or the authorization read fails.
94
+ * @example
95
+ * ```ts
96
+ * import { buildTransactions, prepareMidnightTakeBorrow, type TransactionPlan } from "@morpho-org/morpho-sdk";
97
+ * import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
98
+ * import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
99
+ * import { type Address, type Hash, createPublicClient, http, parseAbi } from "viem";
100
+ * import { base } from "viem/chains";
101
+ *
102
+ * async function prepareBorrow(account: Address, marketId: Hash) {
103
+ * const client = createPublicClient({ chain: base, transport: http() });
104
+ * const block = await client.getBlock();
105
+ * const positionData = await fetchMidnightAccrualPosition(client, {
106
+ * marketId,
107
+ * user: account,
108
+ * blockNumber: block.number,
109
+ * });
110
+ * const marketData = positionData.market;
111
+ * const collateralPrices = await Promise.all(
112
+ * marketData.params.collateralParams.map(({ oracle }) =>
113
+ * client.readContract({
114
+ * address: oracle,
115
+ * abi: parseAbi(["function price() view returns (uint256)"]),
116
+ * functionName: "price",
117
+ * blockNumber: block.number,
118
+ * }),
119
+ * ),
120
+ * );
121
+ * const assets = 1_000_000n;
122
+ * const maxUnits = 1_100_000n;
123
+ * // Quote the unit ceiling: fees come out of the proceeds, so fills sized to the net
124
+ * // assets could not deliver them.
125
+ * const quote = await new MidnightApi().fetchBookQuote({
126
+ * marketId,
127
+ * side: "bids",
128
+ * units: maxUnits,
129
+ * taker: account,
130
+ * });
131
+ * const plan: TransactionPlan = await prepareMidnightTakeBorrow(client, {
132
+ * chainId: base.id,
133
+ * account,
134
+ * marketData,
135
+ * positionData,
136
+ * collateralPrices,
137
+ * now: block.timestamp,
138
+ * target: { type: "assets", assets, maxUnits },
139
+ * takeableOffers: quote.data.takeableOffers,
140
+ * });
141
+ * // Simulate, then send in order from plan.account on plan.chainId.
142
+ * return buildTransactions(plan);
143
+ * }
144
+ * ```
145
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
146
+ */
147
+ export declare function prepareMidnightTakeBorrow(client: Client, params: MidnightTakeBorrowPlanParams): Promise<TransactionPlan>;
148
+ /**
149
+ * Inputs for supplying collateral and taking lend offers in one Midnight transaction.
150
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
151
+ */
152
+ export interface MidnightSupplyCollateralTakeBorrowPlanParams extends MidnightTakeBorrowPlanParams, Pick<MidnightSupplyCollateralTakeBorrowParams, "collateralSupplies" | "nativeAmount"> {
153
+ }
154
+ /**
155
+ * Prepares an atomic collateral supply and fixed-rate borrow on MidnightBundlesV2.
156
+ * Validates inputs with the same parse-once constructor, position binding, buffered health
157
+ * check and fill feasibility check as the entity `supplyCollateralTakeBorrow`. Pass the
158
+ * position before the supply: the health check adds the supplied collateral to it, and
159
+ * repeated collateral indexes are summed. Native ETH may fund wrapped-native collateral, but
160
+ * the ERC-20 allowance must cover the full pull. Approvals and authorization are separate
161
+ * steps, so they can remain even if the bundled transaction fails.
162
+ * @param client - Viem client used to verify chain, deployments, allowances and authorization.
163
+ * @param params - Account, market and pre-supply position snapshots, collateral prices,
164
+ * collateral supplies, optional native funding, fills and intent.
165
+ * @param params.chainId - Chain containing the market and MidnightBundlesV2.
166
+ * @param params.account - Non-zero borrower that supplies the collateral, sends the plan and owns any new debt.
167
+ * @param params.marketData - Hydrated market snapshot used for fill feasibility and collateral capacity.
168
+ * @param params.positionData - Borrower's position snapshot for the same market, taken before the supply.
169
+ * @param params.collateralPrices - Oracle prices indexed by market collateral, scaled by `ORACLE_PRICE_SCALE`.
170
+ * @param params.collateralSupplies - Positive collateral supplies; each `collateralIndex` indexes
171
+ * `marketData.params.collateralParams`, `assets` is in that token's base units, and repeated indexes are summed.
172
+ * @param params.nativeAmount - Optional native ETH in wei for wrapped-native collateral, capped by its pull.
173
+ * @param params.takeableOffers - ABI-ready lend offers from the caller's quote, in fill order.
174
+ * @param params.target.type - `"assets"` to receive loan assets, or `"units"` to sell exact units.
175
+ * @param params.target.assets - Exact loan assets paid to the receiver on an assets target; any referral fee is sold on top.
176
+ * @param params.target.maxUnits - Unit cap on an assets target; also bounds the buffered health check.
177
+ * @param params.target.units - Exact units to sell on a units target.
178
+ * @param params.target.minSellerAssets - Loan-asset floor on a units target, checked against the
179
+ * proceeds after any referral fee.
180
+ * @param params.receiver - Optional recipient of the loan assets; defaults to `account`.
181
+ * @param params.referralFee.bps - Optional referral fee in integer basis points, at most 10%.
182
+ * @param params.referralFee.recipient - Recipient required for a positive referral fee.
183
+ * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
184
+ * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
185
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
186
+ * @returns A frozen plan with any necessary approvals and authorization, without signature requests.
187
+ * @throws {InvalidBigIntInputError} If a supplied non-null `now`, a target amount or a collateral index
188
+ * is not a bigint; checked before any request.
189
+ * @throws {ZeroAccountError} If `account` is the zero address.
190
+ * @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
191
+ * @throws {NonPositiveInputError} If `expiresAt`, a supply amount, the target amount,
192
+ * `maxUnits` or `minSellerAssets` is not positive.
193
+ * @throws {ExpiredDeadlineError} If expiry is at or before the reference timestamp.
194
+ * @throws {NegativeInputError} If `referralFee.bps`, an offer cap or `nativeAmount` is negative.
195
+ * @throws {InputExceedsMaxError} If `referralFee.bps` exceeds 1,000 (10%), a supply amount, per-index
196
+ * sum, target amount or offer cap exceeds uint128, or `nativeAmount` exceeds the wrapped-native pull.
197
+ * @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
198
+ * @throws {MidnightTakeDeadlineTooFarError} If expiry is more than one hour away.
199
+ * @throws {InvalidTransactionPlanError} If `account` is malformed, `collateralSupplies` is not an
200
+ * array of objects, or the target type is neither assets nor units.
201
+ * @throws {ChainIdMismatchError} If the client, transport or market is on a different chain.
202
+ * @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
203
+ * @throws {EmptyMidnightCollateralSuppliesError} If no collateral is supplied.
204
+ * @throws {UnknownCollateralIndexError} If a supply names an unconfigured collateral index.
205
+ * @throws {EmptyMidnightTakeableOffersError} If no offers are supplied.
206
+ * @throws {MidnightOfferSideMismatchError} If an offer is not a lend offer.
207
+ * @throws {MidnightTakeableOfferMarketMismatchError} If an offer trades another market.
208
+ * @throws {MidnightCalldataEncodingError} If an offer field cannot be ABI-encoded.
209
+ * @throws {MidnightZeroReceiverError} If the receiver is the zero address.
210
+ * @throws {MidnightContractReceiverError} If the receiver, or the referral fee recipient of a
211
+ * positive fee, is a Midnight protocol or market token contract.
212
+ * @throws {UnboundedMidnightTakeInputError} If `target.units` or `target.maxUnits` is `maxUint256`.
213
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient.
214
+ * @throws {MidnightTakeTargetUnreachableError} If the supplied target and bounds cannot be met.
215
+ * @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
216
+ * @throws {ChainWNativeMissingError} If native funding is used on a chain without wrapped native.
217
+ * @throws {NativeAmountOnNonWNativeAssetError} If native funding is used without a wrapped-native supply.
218
+ * @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
219
+ * @throws {UnknownAddressError} If the chain has no `midnightBundlesV2` deployment.
220
+ * @throws {MarketIdMismatchError} If the position belongs to another market.
221
+ * @throws {AccrualPositionUserMismatchError} If the position is not owned by the account.
222
+ * @throws {BorrowExceedsSafeLtvError} If the debt bound exceeds the post-supply buffered capacity.
223
+ * @throws {MissingMarketPriceError} If any held collateral has no supplied price.
224
+ * @throws {InvalidMidnightPositionLossFactorError} If `marketData`'s loss factor is below the position's
225
+ * last loss factor; fetch the market and position at the same block.
226
+ * @throws {InvalidMidnightPositionAccrualStateError} If the position's credit and fee snapshot cannot be accrued.
227
+ * @throws {MidnightTakeableOffersNotFillableError} If the supplied offers cannot be used.
228
+ * @throws {MissingContractCodeError} If either registered Midnight target has no deployed code.
229
+ * @throws {viem.BaseError} If an `eth_chainId` request, an allowance read or the authorization read fails.
230
+ * @example
231
+ * ```ts
232
+ * import {
233
+ * buildTransactions,
234
+ * prepareMidnightSupplyCollateralTakeBorrow,
235
+ * type TransactionPlan,
236
+ * } from "@morpho-org/morpho-sdk";
237
+ * import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
238
+ * import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
239
+ * import { type Address, type Hash, createPublicClient, http, parseAbi } from "viem";
240
+ * import { base } from "viem/chains";
241
+ *
242
+ * async function prepareSupplyAndBorrow(account: Address, marketId: Hash, collateralAssets: bigint) {
243
+ * const client = createPublicClient({ chain: base, transport: http() });
244
+ * const block = await client.getBlock();
245
+ * // Read the position before the supply; the health check adds the supplied collateral.
246
+ * const positionData = await fetchMidnightAccrualPosition(client, {
247
+ * marketId,
248
+ * user: account,
249
+ * blockNumber: block.number,
250
+ * });
251
+ * const marketData = positionData.market;
252
+ * const collateralPrices = await Promise.all(
253
+ * marketData.params.collateralParams.map(({ oracle }) =>
254
+ * client.readContract({
255
+ * address: oracle,
256
+ * abi: parseAbi(["function price() view returns (uint256)"]),
257
+ * functionName: "price",
258
+ * blockNumber: block.number,
259
+ * }),
260
+ * ),
261
+ * );
262
+ * const assets = 1_000_000n;
263
+ * const maxUnits = 1_100_000n;
264
+ * // Quote the unit ceiling: fees come out of the proceeds.
265
+ * const quote = await new MidnightApi().fetchBookQuote({
266
+ * marketId,
267
+ * side: "bids",
268
+ * units: maxUnits,
269
+ * taker: account,
270
+ * });
271
+ * const plan: TransactionPlan = await prepareMidnightSupplyCollateralTakeBorrow(client, {
272
+ * chainId: base.id,
273
+ * account,
274
+ * marketData,
275
+ * positionData,
276
+ * collateralPrices,
277
+ * now: block.timestamp,
278
+ * collateralSupplies: [{ collateralIndex: 0n, assets: collateralAssets }],
279
+ * target: { type: "assets", assets, maxUnits },
280
+ * takeableOffers: quote.data.takeableOffers,
281
+ * });
282
+ * // Simulate, then send in order from plan.account on plan.chainId.
283
+ * return buildTransactions(plan);
284
+ * }
285
+ * ```
286
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
287
+ */
288
+ export declare function prepareMidnightSupplyCollateralTakeBorrow(client: Client, params: MidnightSupplyCollateralTakeBorrowPlanParams): Promise<TransactionPlan>;
289
+ declare const supplyActionId = "midnightSupplyCollateralTakeBorrow";
290
+ type TakeBorrowAction = Extract<Action, {
291
+ type: "midnightTakeBorrow";
292
+ }>;
293
+ type SupplyBorrowAction = Extract<Action, {
294
+ type: typeof supplyActionId;
295
+ }>;
296
+ /** @internal Encodes the prepared borrow from persisted inputs without state reads. */
297
+ export declare function buildMidnightTakeBorrow(action: TakeBorrowAction | SupplyBorrowAction): Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightSupplyCollateralTakeBorrowAction>> | Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightTakeBorrowAction>>;
298
+ /**
299
+ * @internal Validates a stored collateral supply and borrow recipe: the sell shape, the
300
+ * collateral order, the supply and native funding fields, then the action's clock-free parse
301
+ * checks on the stored inputs.
302
+ */
303
+ export declare function validateMidnightSupplyCollateralTakeBorrowPlanAction(action: Record<string, unknown>, path: string): void;
304
+ export {};