@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,263 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareMidnightTakeLend = prepareMidnightTakeLend;
4
+ exports.buildMidnightTakeLend = buildMidnightTakeLend;
5
+ exports.validateMidnightTakeLendPlanAction = validateMidnightTakeLendPlanAction;
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const takeLend_js_1 = require("../../actions/midnight/takeLend.js");
8
+ const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
9
+ const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
10
+ const constant_js_1 = require("../../helpers/constant.js");
11
+ const validate_js_1 = require("../../helpers/validate.js");
12
+ const validateMidnightTakeableOfferFields_js_1 = require("../../helpers/validateMidnightTakeableOfferFields.js");
13
+ const validateMidnightTakeFeasibility_js_1 = require("../../helpers/validateMidnightTakeFeasibility.js");
14
+ const error_js_1 = require("../../types/error.js");
15
+ const error_js_2 = require("../error.js");
16
+ const intent_js_1 = require("../intent.js");
17
+ const requirements_js_1 = require("../requirements.js");
18
+ const validation_js_1 = require("../validation.js");
19
+ const authorization_js_1 = require("./authorization.js");
20
+ const market_js_1 = require("./market.js");
21
+ const validation_js_2 = require("./validation.js");
22
+ /**
23
+ * Prepares an ordered plan to lend through MidnightBundlesV2. Validates inputs with the same
24
+ * parse-once constructor and fill feasibility check as the entity `takeLend`, then reads the
25
+ * registry targets' bytecode, allowance, and authorization. It does not read live fill availability.
26
+ * On an assets target, an offer is dropped from the stored fills only when its price would revert
27
+ * the bundle at every time up to the deadline; one that is invalid for part of that window stays, so
28
+ * simulate before sending.
29
+ * Even with native input, the bundle needs allowance for the full loan-token pull.
30
+ * @param client - Viem client connected to the intent chain for prerequisite reads.
31
+ * @param params - Sender, market snapshot, ABI-ready fills, target bounds, funding and expiry.
32
+ * @param params.now - Optional reference timestamp in Unix seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
33
+ * @returns A frozen plan with any approval and authorization steps before the lend.
34
+ * @throws {InvalidBigIntInputError} If a supplied non-null `now`, `maxContinuousFee` or a target amount
35
+ * is not a bigint.
36
+ * @throws {ZeroAccountError} If `account` is the zero address.
37
+ * @throws {NonIntegerInputError} If `expiresAt` or `referralFee.bps` is not a safe integer.
38
+ * @throws {NonPositiveInputError} If `expiresAt`, the target amount, `minUnits` or
39
+ * `maxBuyerAssets` is not positive.
40
+ * @throws {ExpiredDeadlineError} If expiry is at or before the reference timestamp.
41
+ * @throws {NegativeInputError} If `referralFee.bps`, an offer cap, `maxContinuousFee` or
42
+ * `nativeAmount` is negative.
43
+ * @throws {InputExceedsMaxError} If `referralFee.bps` exceeds 1,000 (10%), a target amount or offer
44
+ * cap exceeds uint128, `maxContinuousFee` exceeds uint256, or `nativeAmount` exceeds the pull.
45
+ * @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
46
+ * @throws {MidnightTakeDeadlineTooFarError} If expiry is more than one hour away.
47
+ * @throws {InvalidTransactionPlanError} If `account` is malformed or the target type is neither assets nor units.
48
+ * @throws {ChainIdMismatchError} If the client, transport or market is on a different chain.
49
+ * @throws {UnsupportedChainIdError} If the chain is absent from the address registry.
50
+ * @throws {UnknownAddressError} If the chain has no `midnightBundlesV2` deployment.
51
+ * @throws {MidnightMarketAddressMismatchError} If the market targets another Midnight deployment.
52
+ * @throws {EmptyMidnightTakeableOffersError} If no offers are supplied.
53
+ * @throws {MidnightOfferSideMismatchError} If an offer is not borrow-side.
54
+ * @throws {MidnightTakeableOfferMarketMismatchError} If an offer trades a different market.
55
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} If an offer routes seller proceeds to the zero address.
56
+ * @throws {UnboundedMidnightTakeInputError} If `target.units` or `target.maxBuyerAssets` is `maxUint256`.
57
+ * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no recipient.
58
+ * @throws {MidnightContractReceiverError} If the referral fee recipient is a Midnight protocol or market token contract.
59
+ * @throws {InvalidMidnightNativeAmountTypeError} If `nativeAmount` is not a bigint.
60
+ * @throws {MidnightCalldataEncodingError} If an offer field, including a `maxUnits` or
61
+ * `maxAssets` cap that is not a bigint, cannot be ABI-encoded.
62
+ * @throws {ChainWNativeMissingError} If wNative is not configured for the chain.
63
+ * @throws {NativeAmountOnNonWNativeAssetError} If positive native input is used with another loan token.
64
+ * @throws {MidnightContinuousFeeAboveMaxError} If `maxContinuousFee` is below the market's continuous fee.
65
+ * @throws {MidnightTakeableOffersNotFillableError} If every offer is expired, not yet started,
66
+ * self-made, capped below the market fee or otherwise dead.
67
+ * @throws {MidnightTakeTargetUnreachableError} If the live offers cannot meet the target and its bounds.
68
+ * @throws {MissingContractCodeError} If either registered Midnight target has no deployed code.
69
+ * @throws {viem.BaseError} If an `eth_chainId` request or prerequisite read fails.
70
+ * @example
71
+ * ```ts
72
+ * import { buildTransactions, prepareMidnightTakeLend } from "@morpho-org/morpho-sdk";
73
+ * import { fetchMidnightMarket } from "@morpho-org/morpho-sdk/fetch";
74
+ * import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
75
+ * import { type Address, createPublicClient, type Hex, http, maxUint256 } from "viem";
76
+ * import { base } from "viem/chains";
77
+ *
78
+ * export async function takeLendTransactions(marketId: Hex, account: Address) {
79
+ * const client = createPublicClient({ chain: base, transport: http() });
80
+ * const marketData = await fetchMidnightMarket(client, { marketId });
81
+ * const quote = await new MidnightApi().fetchBookQuote({
82
+ * marketId, side: "asks", units: 1_000_000n, taker: account,
83
+ * });
84
+ * const plan = await prepareMidnightTakeLend(client, {
85
+ * chainId: base.id, account, marketData, takeableOffers: quote.data.takeableOffers,
86
+ * target: { type: "units", units: 1_000_000n, maxBuyerAssets: 990_000n },
87
+ * maxContinuousFee: maxUint256,
88
+ * });
89
+ * // Simulate, then send 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
+ async function prepareMidnightTakeLend(client, params) {
96
+ const { chainId, account, marketData, target, nativeAmount } = params;
97
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
98
+ // Reject a non-bigint clock before the deadline window sum can mix types.
99
+ (0, validate_js_1.validateReferenceTime)(now);
100
+ const maxDeadline = now + constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS;
101
+ const intent = (0, intent_js_1.resolveIntent)({ ...params, expiresAt: params.expiresAt ?? Number(maxDeadline) }, now);
102
+ if (intent.deadline > maxDeadline) {
103
+ throw new error_js_1.MidnightTakeDeadlineTooFarError({
104
+ deadline: intent.deadline,
105
+ maxDeadline,
106
+ });
107
+ }
108
+ if (target.type !== "assets" && target.type !== "units") {
109
+ throw invalidTargetType("$.target");
110
+ }
111
+ if (typeof params.maxContinuousFee !== "bigint") {
112
+ throw new error_js_1.InvalidBigIntInputError("maxContinuousFee", params.maxContinuousFee);
113
+ }
114
+ (0, validation_js_2.validateMidnightTargetAmountTypes)(target, target.type === "assets"
115
+ ? ["assets", "minUnits"]
116
+ : ["units", "maxBuyerAssets"]);
117
+ const parsed = (0, takeLend_js_1.parseMidnightTakeLend)({
118
+ chainId,
119
+ market: marketData.params,
120
+ target,
121
+ takeableOffers: params.takeableOffers,
122
+ maxContinuousFee: params.maxContinuousFee,
123
+ nativeAmount,
124
+ deadline: intent.deadline,
125
+ referralFeePct: intent.referralFeePct,
126
+ referralFeeRecipient: intent.referralFeeRecipient,
127
+ });
128
+ (0, validateMidnightTakeableOfferFields_js_1.validateMidnightTakeableOfferFields)(parsed.takeableOffers);
129
+ const bundle = (0, morpho_ts_1.getChainAddress)(chainId, "midnightBundlesV2");
130
+ const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
131
+ side: "buy",
132
+ takeableOffers: parsed.takeableOffers,
133
+ accountAddress: account,
134
+ marketData,
135
+ now,
136
+ deadline: parsed.deadline,
137
+ referralFeePct: parsed.referralFeePct,
138
+ fallbackUnits: 0n,
139
+ target: parsed.target,
140
+ maxContinuousFee: parsed.maxContinuousFee,
141
+ });
142
+ const chainCheck = (0, chainCheck_js_1.createChainCheck)(client, chainId);
143
+ await chainCheck();
144
+ // Check deployments before allowance or authorization reads can fail decoding empty data.
145
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
146
+ { role: "midnightBundlesV2", address: bundle },
147
+ { role: "midnight", address: (0, morpho_ts_1.getChainAddress)(chainId, "midnight") },
148
+ ], chainCheck);
149
+ const [{ approvals }, authorization] = await Promise.all([
150
+ (0, requirements_js_1.getTokenRequirements)(client, {
151
+ chainId,
152
+ token: parsed.market.loanToken,
153
+ owner: account,
154
+ spender: bundle,
155
+ amount: parsed.target.type === "assets"
156
+ ? parsed.target.assets
157
+ : parsed.target.maxBuyerAssets,
158
+ approvalId: (index) => `midnightTakeLend:approval:${index}`,
159
+ }),
160
+ (0, authorization_js_1.prepareMidnightBundleAuthorization)(client, { chainId, account }),
161
+ ]);
162
+ return (0, morpho_ts_1.deepFreeze)({
163
+ version: 2,
164
+ chainId,
165
+ account,
166
+ expiresAt: intent.expiresAt,
167
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
168
+ steps: [
169
+ ...approvals,
170
+ ...(authorization === undefined ? [] : [authorization]),
171
+ {
172
+ id: "midnightTakeLend",
173
+ label: "Lend on Midnight",
174
+ action: {
175
+ type: "midnightTakeLend",
176
+ inputs: {
177
+ chainId,
178
+ account,
179
+ market: parsed.market,
180
+ target: parsed.target,
181
+ takeableOffers,
182
+ maxContinuousFee: parsed.maxContinuousFee,
183
+ ...(nativeAmount !== undefined && { nativeAssets: nativeAmount }),
184
+ deadline: parsed.deadline,
185
+ referralFeePct: parsed.referralFeePct,
186
+ referralFeeRecipient: parsed.referralFeeRecipient,
187
+ },
188
+ },
189
+ },
190
+ ],
191
+ signatureRequests: [],
192
+ });
193
+ }
194
+ function invalidTargetType(targetPath) {
195
+ return new error_js_2.InvalidTransactionPlanError({
196
+ path: `${targetPath}.type`,
197
+ reason: "expected assets or units",
198
+ });
199
+ }
200
+ /** @internal Encodes the prepared lend from persisted inputs without state reads. */
201
+ function buildMidnightTakeLend({ inputs: { chainId, market, target, takeableOffers, maxContinuousFee, deadline, referralFeePct, referralFeeRecipient, nativeAssets, }, }) {
202
+ if (target.type !== "assets" && target.type !== "units") {
203
+ throw invalidTargetType("$.inputs.target");
204
+ }
205
+ return (0, takeLend_js_1.midnightTakeLend)({
206
+ chainId,
207
+ market: (0, market_js_1.storedMarketTuple)(market),
208
+ target,
209
+ takeableOffers: (0, market_js_1.storedFills)(takeableOffers),
210
+ maxContinuousFee,
211
+ deadline,
212
+ referralFeePct,
213
+ referralFeeRecipient,
214
+ nativeAmount: nativeAssets,
215
+ });
216
+ }
217
+ /** @internal Validates the restored recipe shape without encoding or fetching offers. */
218
+ function validateMidnightTakeLendPlanAction(action, path) {
219
+ const inputsPath = `${path}.inputs`;
220
+ const inputs = (0, validation_js_1.getPlanObject)(action.inputs, inputsPath);
221
+ (0, validation_js_1.validatePlanFields)(inputs, {
222
+ path: inputsPath,
223
+ fields: {
224
+ maxContinuousFee: "uint256 bigint",
225
+ deadline: "uint256 bigint",
226
+ referralFeePct: "uint256 bigint",
227
+ referralFeeRecipient: "address",
228
+ ...(inputs.nativeAssets !== undefined && {
229
+ nativeAssets: "uint256 bigint",
230
+ }),
231
+ },
232
+ });
233
+ const targetPath = `${inputsPath}.target`;
234
+ const target = (0, validation_js_1.getPlanObject)(inputs.target, targetPath);
235
+ switch (target.type) {
236
+ case "assets":
237
+ (0, validation_js_1.validatePlanFields)(target, {
238
+ path: targetPath,
239
+ fields: { assets: "uint256 bigint", minUnits: "uint256 bigint" },
240
+ });
241
+ break;
242
+ case "units":
243
+ (0, validation_js_1.validatePlanFields)(target, {
244
+ path: targetPath,
245
+ fields: { units: "uint256 bigint", maxBuyerAssets: "uint256 bigint" },
246
+ });
247
+ break;
248
+ default:
249
+ throw invalidTargetType(targetPath);
250
+ }
251
+ // Validate nested market and quote fields without a chain registry or RPC.
252
+ const chainId = inputs.chainId; // Checked by the parse dispatcher.
253
+ (0, validation_js_2.validateStoredMidnightMarket)(inputs.market, {
254
+ path: `${inputsPath}.market`,
255
+ chainId,
256
+ });
257
+ (0, validation_js_2.validateStoredMidnightFills)(inputs.takeableOffers, {
258
+ path: `${inputsPath}.takeableOffers`,
259
+ chainId,
260
+ });
261
+ // Midnight never consumes a signature reference.
262
+ (0, authorization_js_1.validateSignaturelessMidnightAction)(action, path);
263
+ }
@@ -0,0 +1,175 @@
1
+ import type { AccrualPosition, Market } from "@morpho-org/midnight-sdk";
2
+ import type { Client } from "viem";
3
+ import { type MidnightTakeRepayWithdrawCollateralParams } from "../../actions/midnight/takeRepayWithdrawCollateral.js";
4
+ import { type IntentParams } from "../intent.js";
5
+ import type { Action, TransactionPlan } from "../types.js";
6
+ declare const actionId = "midnightTakeRepayWithdrawCollateral";
7
+ type RepayAction = Extract<Action, {
8
+ type: typeof actionId;
9
+ }>;
10
+ type RawParams = MidnightTakeRepayWithdrawCollateralParams;
11
+ /**
12
+ * Inputs for reducing Midnight debt with a borrow-side quote.
13
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
14
+ */
15
+ export interface MidnightTakeRepayWithdrawCollateralPlanParams extends Omit<IntentParams, "supportSignature" | "deployless">, Pick<RawParams, "target" | "takeableOffers" | "repayEnabled" | "nativeAmount" | "maxContinuousFee">, Partial<Pick<RawParams, "collateralWithdrawals" | "collateralReceiver">> {
16
+ /** Hydrated market snapshot used to assess fill feasibility and collateral capacity. */
17
+ readonly marketData: Market;
18
+ /** Borrower's position snapshot for the same market. */
19
+ readonly positionData: AccrualPosition;
20
+ /** Oracle prices indexed by market collateral, scaled by ORACLE_PRICE_SCALE. */
21
+ readonly collateralPrices: readonly bigint[];
22
+ /** Reference Unix timestamp in seconds; defaults to the device clock. */
23
+ readonly now?: bigint;
24
+ /** Unix seconds; defaults to one hour after the reference timestamp. */
25
+ readonly expiresAt?: number;
26
+ }
27
+ /**
28
+ * Prepares a reduce-only buy on MidnightBundlesV2. The bundle fills borrow offers,
29
+ * repays the unfilled remainder at par if enabled, then withdraws collateral.
30
+ * The collateral receiver defaults to the submitting account. Validates inputs with the same
31
+ * parse-once constructor, position binding, buffered post-withdrawal health check and fill
32
+ * feasibility check as the entity `takeRepayWithdrawCollateral`, including its buy-budget bound:
33
+ * a units target's `maxBuyerAssets` must cover the units at the cheapest live price, and an
34
+ * assets target has no budget check. Offers whose price conversion fails throughout the plan
35
+ * window are dropped from the stored fills; an offer that converts only at a later fee can still
36
+ * revert the bundle if sent earlier. Preparation does not see live cancellations either, so
37
+ * simulate before sending to catch these price-conversion reverts and cancelled or consumed
38
+ * offers. Native funding still requires allowance for the full
39
+ * wrapped-native pull.
40
+ * @param client - Viem client used to check the chain and deployments and read prerequisites.
41
+ * @param params - Borrower, snapshots, buy target, quote, optional withdrawals and intent.
42
+ * @param params.chainId - Chain containing the market and MidnightBundlesV2.
43
+ * @param params.account - Non-zero borrower whose debt is repaid; it funds the repayment and sends the plan.
44
+ * @param params.marketData - Hydrated market snapshot used for fill feasibility and collateral capacity.
45
+ * @param params.positionData - Borrower's position snapshot for the same market.
46
+ * @param params.collateralPrices - Oracle prices indexed by market collateral, scaled by `ORACLE_PRICE_SCALE`.
47
+ * @param params.takeableOffers - ABI-ready borrow offers from the caller's quote, in fill order.
48
+ * @param params.target.type - `"assets"` to pay exact loan assets, or `"units"` to buy exact units.
49
+ * @param params.target.assets - Loan assets paid on an assets target, referral fee included.
50
+ * @param params.target.minUnits - Unit floor on an assets target.
51
+ * @param params.target.units - Exact units bought on a units target; `maxUint256` targets the account's whole debt.
52
+ * @param params.target.maxBuyerAssets - Loan-asset cap pulled on a units target, referral fee included; the unused remainder is returned.
53
+ * @param params.repayEnabled - Whether the bundle repays the unfilled remainder directly to Midnight.
54
+ * @param params.maxContinuousFee - Largest market continuous fee accepted when taking offers; pass `maxUint256` for no cap.
55
+ * @param params.nativeAmount - Optional native ETH in wei for a wrapped-native loan, capped by the pull.
56
+ * @param params.collateralWithdrawals - Optional withdrawals after the repayment; defaults to none. Each
57
+ * `collateralIndex` indexes `marketData.params.collateralParams`, and `assets` is in that token's base units;
58
+ * `maxUint256` withdraws the account's whole balance of that collateral.
59
+ * @param params.collateralReceiver - Optional recipient of withdrawn collateral; defaults to `account`.
60
+ * @param params.referralFee.bps - Optional referral fee in integer basis points, at most 10%.
61
+ * @param params.referralFee.recipient - Recipient required for a positive referral fee.
62
+ * @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
63
+ * @param params.expiresAt - Onchain deadline in Unix seconds; defaults to, and may not exceed, one hour after `now`.
64
+ * @param params.calldataOrigin - Optional attribution bytes appended to each operation transaction's calldata; approval and authorization steps carry none.
65
+ * @returns A frozen plan with any needed approval and standalone authorization, without signatures.
66
+ * @throws {InvalidBigIntInputError} when a supplied non-null `now`, `maxContinuousFee`, a target amount, or a withdrawal's collateral index or amount is not a bigint; checked before any request.
67
+ * @throws {ZeroAccountError} when the sender is the zero address.
68
+ * @throws {InvalidTransactionPlanError} when the sender address, attribution length, target discriminator or `repayEnabled` flag is invalid.
69
+ * @throws {InvalidMidnightNativeAmountTypeError} when `nativeAmount` is supplied as a non-bigint.
70
+ * @throws {NonIntegerInputError} when expiry or referral fee basis points are not safe integers.
71
+ * @throws {NonPositiveInputError} when expiry, a target amount or bound, or a withdrawal amount is nonpositive.
72
+ * @throws {ExpiredDeadlineError} when expiry is at or before the reference timestamp.
73
+ * @throws {NegativeInputError} when the referral fee, offer cap, continuous fee cap or native amount is negative.
74
+ * @throws {InputExceedsMaxError} when referral fee basis points exceed 1,000 (10%), an amount or cap exceeds its
75
+ * bound, or native funding exceeds the pull.
76
+ * @throws {InvalidCalldataOriginError} when attribution bytes are empty or malformed.
77
+ * @throws {MidnightTakeDeadlineTooFarError} when expiry is more than one hour away.
78
+ * @throws {ChainIdMismatchError} when the market, configured client or transport is on another chain.
79
+ * @throws {UnsupportedChainIdError} when the chain is not registered.
80
+ * @throws {UnknownAddressError} when a required Midnight deployment is not registered on the chain.
81
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
82
+ * @throws {InvalidMarketParameterError} when the market configuration is invalid.
83
+ * @throws {UnknownCollateralIndexError} when a withdrawal targets an unconfigured collateral index.
84
+ * @throws {MidnightCalldataEncodingError} when an address is malformed or calldata cannot be encoded.
85
+ * @throws {MidnightZeroReceiverError} when withdrawn collateral is sent to the zero address.
86
+ * @throws {MidnightContractReceiverError} when withdrawn collateral or a positive referral fee is sent to a blocked contract.
87
+ * @throws {EmptyMidnightTakeableOffersError} when the quote is empty.
88
+ * @throws {MidnightOfferSideMismatchError} when an offer is not a borrow offer.
89
+ * @throws {MidnightTakeableOfferMarketMismatchError} when an offer trades another market.
90
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when an offer sends seller proceeds to the zero address.
91
+ * @throws {UnboundedMidnightTakeInputError} when the bundle deadline is `maxUint256`.
92
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
93
+ * @throws {ChainWNativeMissingError} when native funding is requested without a registered wrapped-native token.
94
+ * @throws {NativeAmountOnNonWNativeAssetError} when native funding is requested for a different loan token.
95
+ * @throws {MarketIdMismatchError} when the position belongs to another market.
96
+ * @throws {AccrualPositionUserMismatchError} when another account owns the position.
97
+ * @throws {WithdrawExceedsCollateralError} when withdrawals exceed the collateral balance.
98
+ * @throws {MissingMarketPriceError} when the health check needs a missing oracle price.
99
+ * @throws {WithdrawMakesPositionUnhealthyError} when remaining debt exceeds buffered collateral capacity.
100
+ * @throws {MidnightContinuousFeeAboveMaxError} when the market's continuous fee exceeds the caller's cap.
101
+ * @throws {MidnightRepayExceedsDebtError} when the target exceeds the snapshot debt.
102
+ * @throws {MidnightTakeableOffersNotFillableError} when the supplied offers cannot be used.
103
+ * @throws {MidnightTakeTargetUnreachableError} when the target cannot be met within its bounds.
104
+ * @throws {viem.BaseError} when a chain, bytecode, allowance or authorization read fails.
105
+ * @throws {MissingContractCodeError} when a registered Midnight target has no code.
106
+ * @example
107
+ * ```ts
108
+ * import {
109
+ * buildTransactions,
110
+ * prepareMidnightTakeRepayWithdrawCollateral,
111
+ * type MidnightTakeRepayWithdrawCollateralPlanParams,
112
+ * } from "@morpho-org/morpho-sdk";
113
+ * import { blueOracleAbi } from "@morpho-org/morpho-sdk/abis";
114
+ * import { fetchMidnightAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
115
+ * import { MidnightApi } from "@morpho-org/morpho-sdk/midnight-api";
116
+ *
117
+ * type SnapshotParams = Parameters<typeof fetchMidnightAccrualPosition>[1];
118
+ * type PublicClient = Parameters<typeof fetchMidnightAccrualPosition>[0] & {
119
+ * getBlock(): Promise<{ number: bigint; timestamp: bigint }>;
120
+ * readContract(params: {
121
+ * address: SnapshotParams["user"];
122
+ * abi: typeof blueOracleAbi;
123
+ * functionName: "price";
124
+ * blockNumber: bigint;
125
+ * }): Promise<bigint>;
126
+ * };
127
+ *
128
+ * async function prepareRepayment(
129
+ * client: PublicClient,
130
+ * marketId: SnapshotParams["marketId"],
131
+ * params: Pick<MidnightTakeRepayWithdrawCollateralPlanParams,
132
+ * "chainId" | "account" | "maxContinuousFee" | "collateralWithdrawals">,
133
+ * assets: bigint,
134
+ * minUnits: bigint,
135
+ * ) {
136
+ * const block = await client.getBlock();
137
+ * const positionData = await fetchMidnightAccrualPosition(client, {
138
+ * marketId, user: params.account, blockNumber: block.number,
139
+ * });
140
+ * const marketData = positionData.market;
141
+ * const collateralPrices = await Promise.all(
142
+ * marketData.params.collateralParams.map(({ oracle }) =>
143
+ * client.readContract({
144
+ * address: oracle, abi: blueOracleAbi, functionName: "price", blockNumber: block.number,
145
+ * }),
146
+ * ),
147
+ * );
148
+ * const quote = await new MidnightApi().fetchBookQuote({
149
+ * marketId, side: "asks", assets, taker: params.account,
150
+ * });
151
+ * const plan = await prepareMidnightTakeRepayWithdrawCollateral(client, {
152
+ * ...params, marketData, positionData, collateralPrices, now: block.timestamp,
153
+ * target: { type: "assets", assets, minUnits },
154
+ * takeableOffers: quote.data.takeableOffers,
155
+ * repayEnabled: true,
156
+ * });
157
+ * // Simulate, then send in order from plan.account on plan.chainId.
158
+ * return buildTransactions(plan);
159
+ * }
160
+ * ```
161
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
162
+ */
163
+ export declare function prepareMidnightTakeRepayWithdrawCollateral(client: Client, params: MidnightTakeRepayWithdrawCollateralPlanParams): Promise<TransactionPlan>;
164
+ /**
165
+ * @internal Encodes the prepared buy and withdrawals from persisted fields alone.
166
+ * @throws {InvalidTransactionPlanError} If the market's collateral tokens are not in strictly
167
+ * ascending address order, or the target is not an object whose type is `assets` or `units`.
168
+ */
169
+ export declare function buildMidnightTakeRepayWithdrawCollateral({ inputs, }: RepayAction): Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightTakeRepayWithdrawCollateralAction>>;
170
+ /**
171
+ * @internal Validates a stored reduce-only buy recipe without fetching any state: the field
172
+ * shapes and collateral order, then the action's clock-free parse checks on the stored inputs.
173
+ */
174
+ export declare function validateMidnightTakeRepayWithdrawCollateralPlanAction(action: Record<string, unknown>, path: string): void;
175
+ export {};