@morpho-org/morpho-sdk 10.0.2 → 10.1.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 (420) hide show
  1. package/README.md +6 -2
  2. package/lib/cjs/actions/blue/borrow.d.ts +2 -1
  3. package/lib/cjs/actions/blue/borrow.internal.d.ts +13 -0
  4. package/lib/cjs/actions/blue/borrow.internal.js +35 -0
  5. package/lib/cjs/actions/blue/borrow.js +4 -16
  6. package/lib/cjs/actions/blue/common.d.ts +50 -28
  7. package/lib/cjs/actions/blue/common.js +21 -34
  8. package/lib/cjs/actions/blue/encode.d.ts +23 -0
  9. package/lib/cjs/actions/blue/encode.js +171 -0
  10. package/lib/cjs/actions/blue/refinance.d.ts +3 -2
  11. package/lib/cjs/actions/blue/refinance.internal.d.ts +42 -0
  12. package/lib/cjs/actions/blue/refinance.internal.js +62 -0
  13. package/lib/cjs/actions/blue/refinance.js +5 -63
  14. package/lib/cjs/actions/blue/refinanceValidation.d.ts +4 -5
  15. package/lib/cjs/actions/blue/refinanceValidation.js +1 -3
  16. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  17. package/lib/cjs/actions/blue/repay.internal.d.ts +13 -0
  18. package/lib/cjs/actions/blue/repay.internal.js +38 -0
  19. package/lib/cjs/actions/blue/repay.js +2 -17
  20. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  21. package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
  22. package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.js +112 -0
  23. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -116
  24. package/lib/cjs/actions/blue/signatures.d.ts +30 -0
  25. package/lib/cjs/actions/blue/signatures.js +90 -0
  26. package/lib/cjs/actions/blue/supply.d.ts +1 -1
  27. package/lib/cjs/actions/blue/supply.internal.d.ts +32 -0
  28. package/lib/cjs/actions/blue/supply.internal.js +101 -0
  29. package/lib/cjs/actions/blue/supply.js +2 -67
  30. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -1
  31. package/lib/cjs/actions/blue/supplyCollateral.internal.d.ts +13 -0
  32. package/lib/cjs/actions/blue/supplyCollateral.internal.js +37 -0
  33. package/lib/cjs/actions/blue/supplyCollateral.js +2 -17
  34. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -3
  35. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +63 -0
  36. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +94 -0
  37. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +5 -106
  38. package/lib/cjs/actions/blue/withdraw.d.ts +4 -3
  39. package/lib/cjs/actions/blue/withdraw.internal.d.ts +56 -0
  40. package/lib/cjs/actions/blue/withdraw.internal.js +84 -0
  41. package/lib/cjs/actions/blue/withdraw.js +5 -78
  42. package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +2 -2
  43. package/lib/cjs/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
  44. package/lib/cjs/actions/blue/withdrawBuyCallback.internal.js +58 -0
  45. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -39
  46. package/lib/cjs/actions/blue/withdrawCollateral.internal.d.ts +16 -0
  47. package/lib/cjs/actions/blue/withdrawCollateral.internal.js +39 -0
  48. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -17
  49. package/lib/cjs/actions/bundles/common.d.ts +9 -0
  50. package/lib/cjs/actions/bundles/common.js +18 -6
  51. package/lib/cjs/actions/bundles/index.d.ts +1 -1
  52. package/lib/cjs/actions/bundles/index.js +3 -16
  53. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
  54. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +59 -60
  55. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +22 -1
  56. package/lib/cjs/actions/midnight/cancelAndMake.js +46 -87
  57. package/lib/cjs/actions/midnight/cancelOffers.d.ts +11 -0
  58. package/lib/cjs/actions/midnight/cancelOffers.js +22 -4
  59. package/lib/cjs/actions/midnight/encode.d.ts +36 -0
  60. package/lib/cjs/actions/midnight/encode.js +554 -0
  61. package/lib/cjs/actions/midnight/index.d.ts +14 -13
  62. package/lib/cjs/actions/midnight/index.js +29 -13
  63. package/lib/cjs/actions/midnight/parse.d.ts +35 -0
  64. package/lib/cjs/actions/midnight/parse.js +73 -0
  65. package/lib/cjs/actions/midnight/parseCollateralBatch.d.ts +58 -0
  66. package/lib/cjs/actions/midnight/parseCollateralBatch.js +216 -0
  67. package/lib/cjs/actions/midnight/redeem.d.ts +16 -3
  68. package/lib/cjs/actions/midnight/redeem.js +22 -51
  69. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
  70. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +42 -67
  71. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +40 -5
  72. package/lib/cjs/actions/midnight/supplyCollateral.js +60 -54
  73. package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +3 -3
  74. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +3 -62
  75. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
  76. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +39 -66
  77. package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
  78. package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +142 -0
  79. package/lib/cjs/actions/midnight/takeBorrow.d.ts +17 -2
  80. package/lib/cjs/actions/midnight/takeBorrow.js +25 -55
  81. package/lib/cjs/actions/midnight/takeLend.d.ts +21 -1
  82. package/lib/cjs/actions/midnight/takeLend.js +30 -57
  83. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
  84. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +34 -61
  85. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +17 -2
  86. package/lib/cjs/actions/midnight/takeWithdraw.js +78 -115
  87. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -3
  88. package/lib/cjs/actions/midnight/withdrawCollateral.js +25 -56
  89. package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
  90. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +3 -71
  91. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
  92. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +39 -19
  93. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -1
  94. package/lib/cjs/actions/requirements/blue/index.js +3 -15
  95. package/lib/cjs/actions/requirements/chainCheck.d.ts +5 -0
  96. package/lib/cjs/actions/requirements/chainCheck.js +10 -0
  97. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
  98. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +40 -27
  99. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
  100. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +36 -17
  101. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
  102. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +44 -9
  103. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
  104. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +61 -24
  105. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
  106. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +25 -4
  107. package/lib/cjs/actions/requirements/encode/index.d.ts +5 -5
  108. package/lib/cjs/actions/requirements/encode/index.js +11 -19
  109. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +26 -11
  110. package/lib/cjs/actions/requirements/getRequirementsApproval.js +40 -12
  111. package/lib/cjs/actions/requirements/index.d.ts +1 -1
  112. package/lib/cjs/actions/requirements/index.js +3 -1
  113. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
  114. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +34 -19
  115. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
  116. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +26 -12
  117. package/lib/cjs/actions/requirements/midnight/index.d.ts +2 -2
  118. package/lib/cjs/actions/requirements/midnight/index.js +5 -16
  119. package/lib/cjs/actions/vaultV1/deposit.d.ts +21 -0
  120. package/lib/cjs/actions/vaultV1/deposit.js +46 -10
  121. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +18 -1
  122. package/lib/cjs/actions/vaultV1/inKindRedeem.js +36 -16
  123. package/lib/cjs/actions/vaultV1/index.d.ts +5 -5
  124. package/lib/cjs/actions/vaultV1/index.js +11 -19
  125. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +21 -0
  126. package/lib/cjs/actions/vaultV1/migrateToV2.js +49 -11
  127. package/lib/cjs/actions/vaultV1/redeem.d.ts +19 -0
  128. package/lib/cjs/actions/vaultV1/redeem.js +28 -7
  129. package/lib/cjs/actions/vaultV1/withdraw.d.ts +19 -0
  130. package/lib/cjs/actions/vaultV1/withdraw.js +28 -7
  131. package/lib/cjs/actions/vaultV2/deposit.d.ts +21 -0
  132. package/lib/cjs/actions/vaultV2/deposit.js +46 -10
  133. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +20 -2
  134. package/lib/cjs/actions/vaultV2/forceRedeem.js +39 -8
  135. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +23 -1
  136. package/lib/cjs/actions/vaultV2/forceWithdraw.js +36 -14
  137. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +18 -1
  138. package/lib/cjs/actions/vaultV2/inKindRedeem.js +35 -15
  139. package/lib/cjs/actions/vaultV2/index.d.ts +6 -6
  140. package/lib/cjs/actions/vaultV2/index.js +13 -20
  141. package/lib/cjs/actions/vaultV2/redeem.d.ts +19 -0
  142. package/lib/cjs/actions/vaultV2/redeem.js +28 -7
  143. package/lib/cjs/actions/vaultV2/withdraw.d.ts +19 -0
  144. package/lib/cjs/actions/vaultV2/withdraw.js +28 -7
  145. package/lib/cjs/entities/blue/blue.d.ts +35 -8
  146. package/lib/cjs/entities/blue/blue.js +467 -406
  147. package/lib/cjs/entities/midnight/midnight.d.ts +117 -41
  148. package/lib/cjs/entities/midnight/midnight.js +472 -843
  149. package/lib/cjs/entities/midnight/parse.d.ts +74 -0
  150. package/lib/cjs/entities/midnight/parse.js +336 -0
  151. package/lib/cjs/entities/midnight/prepare.d.ts +47 -0
  152. package/lib/cjs/entities/midnight/prepare.js +293 -0
  153. package/lib/cjs/entities/midnight/publication.d.ts +7 -3
  154. package/lib/cjs/entities/midnight/publication.js +10 -7
  155. package/lib/cjs/entities/midnight/types.d.ts +7 -0
  156. package/lib/cjs/entities/requirements/assertContractCode.d.ts +10 -5
  157. package/lib/cjs/entities/requirements/assertContractCode.js +24 -15
  158. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
  159. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +59 -51
  160. package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -3
  161. package/lib/cjs/entities/requirements/getErc2612Permit.js +20 -4
  162. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
  163. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +24 -7
  164. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
  165. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +27 -7
  166. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
  167. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
  168. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
  169. package/lib/cjs/entities/requirements/index.d.ts +2 -2
  170. package/lib/cjs/entities/requirements/index.js +5 -16
  171. package/lib/cjs/entities/requirements/validateNativeRequirements.d.ts +21 -0
  172. package/lib/cjs/entities/requirements/validateNativeRequirements.js +37 -0
  173. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
  174. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +1 -7
  175. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +17 -40
  176. package/lib/cjs/entities/vaultV1/vaultV1.js +228 -159
  177. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
  178. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +9 -4
  179. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
  180. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +1 -7
  181. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +21 -52
  182. package/lib/cjs/entities/vaultV2/vaultV2.js +226 -150
  183. package/lib/cjs/helpers/parse.d.ts +33 -0
  184. package/lib/cjs/helpers/parse.js +71 -0
  185. package/lib/cjs/helpers/parseMidnight.d.ts +48 -0
  186. package/lib/cjs/helpers/parseMidnight.js +95 -0
  187. package/lib/cjs/helpers/parseMidnightMaker.d.ts +44 -0
  188. package/lib/cjs/helpers/parseMidnightMaker.js +154 -0
  189. package/lib/cjs/helpers/validate.d.ts +3 -2
  190. package/lib/cjs/helpers/validate.js +4 -0
  191. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
  192. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +4 -4
  193. package/lib/cjs/helpers/validateMidnightPublication.d.ts +17 -1
  194. package/lib/cjs/index.d.ts +1 -0
  195. package/lib/cjs/transactionPlan/blue/refinance.js +17 -9
  196. package/lib/cjs/transactionPlan/blue/repay.js +2 -1
  197. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +23 -4
  198. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +2 -2
  199. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -2
  200. package/lib/cjs/transactionPlan/blue/withdraw.js +3 -3
  201. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +6 -2
  202. package/lib/cjs/transactionPlan/validation.d.ts +1 -1
  203. package/lib/cjs/transactionPlan/validation.js +3 -0
  204. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +2 -2
  205. package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -2
  206. package/lib/cjs/types/action.d.ts +13 -2
  207. package/lib/cjs/types/error.d.ts +20 -2
  208. package/lib/cjs/types/error.js +32 -3
  209. package/lib/cjs/version.d.ts +1 -1
  210. package/lib/cjs/version.js +1 -1
  211. package/lib/esm/actions/blue/borrow.d.ts +2 -1
  212. package/lib/esm/actions/blue/borrow.internal.d.ts +13 -0
  213. package/lib/esm/actions/blue/borrow.internal.js +30 -0
  214. package/lib/esm/actions/blue/borrow.js +4 -16
  215. package/lib/esm/actions/blue/common.d.ts +50 -28
  216. package/lib/esm/actions/blue/common.js +21 -33
  217. package/lib/esm/actions/blue/encode.d.ts +23 -0
  218. package/lib/esm/actions/blue/encode.js +164 -0
  219. package/lib/esm/actions/blue/refinance.d.ts +3 -2
  220. package/lib/esm/actions/blue/refinance.internal.d.ts +42 -0
  221. package/lib/esm/actions/blue/refinance.internal.js +56 -0
  222. package/lib/esm/actions/blue/refinance.js +5 -63
  223. package/lib/esm/actions/blue/refinanceValidation.d.ts +4 -5
  224. package/lib/esm/actions/blue/refinanceValidation.js +2 -4
  225. package/lib/esm/actions/blue/repay.d.ts +1 -1
  226. package/lib/esm/actions/blue/repay.internal.d.ts +13 -0
  227. package/lib/esm/actions/blue/repay.internal.js +33 -0
  228. package/lib/esm/actions/blue/repay.js +2 -17
  229. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  230. package/lib/esm/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
  231. package/lib/esm/actions/blue/repayWithdrawCollateral.internal.js +104 -0
  232. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -116
  233. package/lib/esm/actions/blue/signatures.d.ts +30 -0
  234. package/lib/esm/actions/blue/signatures.js +82 -0
  235. package/lib/esm/actions/blue/supply.d.ts +1 -1
  236. package/lib/esm/actions/blue/supply.internal.d.ts +32 -0
  237. package/lib/esm/actions/blue/supply.internal.js +95 -0
  238. package/lib/esm/actions/blue/supply.js +2 -67
  239. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -1
  240. package/lib/esm/actions/blue/supplyCollateral.internal.d.ts +13 -0
  241. package/lib/esm/actions/blue/supplyCollateral.internal.js +32 -0
  242. package/lib/esm/actions/blue/supplyCollateral.js +2 -17
  243. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -3
  244. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +63 -0
  245. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +87 -0
  246. package/lib/esm/actions/blue/supplyCollateralBorrow.js +5 -106
  247. package/lib/esm/actions/blue/withdraw.d.ts +4 -3
  248. package/lib/esm/actions/blue/withdraw.internal.d.ts +56 -0
  249. package/lib/esm/actions/blue/withdraw.internal.js +77 -0
  250. package/lib/esm/actions/blue/withdraw.js +5 -78
  251. package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +2 -2
  252. package/lib/esm/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
  253. package/lib/esm/actions/blue/withdrawBuyCallback.internal.js +53 -0
  254. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -39
  255. package/lib/esm/actions/blue/withdrawCollateral.internal.d.ts +16 -0
  256. package/lib/esm/actions/blue/withdrawCollateral.internal.js +34 -0
  257. package/lib/esm/actions/blue/withdrawCollateral.js +2 -17
  258. package/lib/esm/actions/bundles/common.d.ts +9 -0
  259. package/lib/esm/actions/bundles/common.js +15 -4
  260. package/lib/esm/actions/bundles/index.d.ts +1 -1
  261. package/lib/esm/actions/bundles/index.js +1 -1
  262. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
  263. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +58 -61
  264. package/lib/esm/actions/midnight/cancelAndMake.d.ts +22 -1
  265. package/lib/esm/actions/midnight/cancelAndMake.js +43 -85
  266. package/lib/esm/actions/midnight/cancelOffers.d.ts +11 -0
  267. package/lib/esm/actions/midnight/cancelOffers.js +18 -2
  268. package/lib/esm/actions/midnight/encode.d.ts +36 -0
  269. package/lib/esm/actions/midnight/encode.js +539 -0
  270. package/lib/esm/actions/midnight/index.d.ts +14 -13
  271. package/lib/esm/actions/midnight/index.js +14 -13
  272. package/lib/esm/actions/midnight/parse.d.ts +35 -0
  273. package/lib/esm/actions/midnight/parse.js +68 -0
  274. package/lib/esm/actions/midnight/parseCollateralBatch.d.ts +58 -0
  275. package/lib/esm/actions/midnight/parseCollateralBatch.js +209 -0
  276. package/lib/esm/actions/midnight/redeem.d.ts +16 -3
  277. package/lib/esm/actions/midnight/redeem.js +20 -50
  278. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
  279. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +38 -64
  280. package/lib/esm/actions/midnight/supplyCollateral.d.ts +40 -5
  281. package/lib/esm/actions/midnight/supplyCollateral.js +57 -53
  282. package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +3 -3
  283. package/lib/esm/actions/midnight/supplyCollateralBatch.js +3 -62
  284. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
  285. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -61
  286. package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
  287. package/lib/esm/actions/midnight/supplyCollateralWithNative.js +137 -0
  288. package/lib/esm/actions/midnight/takeBorrow.d.ts +17 -2
  289. package/lib/esm/actions/midnight/takeBorrow.js +20 -51
  290. package/lib/esm/actions/midnight/takeLend.d.ts +21 -1
  291. package/lib/esm/actions/midnight/takeLend.js +26 -54
  292. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
  293. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +30 -58
  294. package/lib/esm/actions/midnight/takeWithdraw.d.ts +17 -2
  295. package/lib/esm/actions/midnight/takeWithdraw.js +76 -114
  296. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -3
  297. package/lib/esm/actions/midnight/withdrawCollateral.js +23 -55
  298. package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
  299. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +3 -71
  300. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
  301. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +36 -18
  302. package/lib/esm/actions/requirements/blue/index.d.ts +1 -1
  303. package/lib/esm/actions/requirements/blue/index.js +1 -1
  304. package/lib/esm/actions/requirements/chainCheck.d.ts +5 -0
  305. package/lib/esm/actions/requirements/chainCheck.js +6 -0
  306. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
  307. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +36 -25
  308. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
  309. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +33 -16
  310. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
  311. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +41 -8
  312. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
  313. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +59 -24
  314. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
  315. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +21 -2
  316. package/lib/esm/actions/requirements/encode/index.d.ts +5 -5
  317. package/lib/esm/actions/requirements/encode/index.js +5 -5
  318. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +26 -11
  319. package/lib/esm/actions/requirements/getRequirementsApproval.js +38 -12
  320. package/lib/esm/actions/requirements/index.d.ts +1 -1
  321. package/lib/esm/actions/requirements/index.js +1 -1
  322. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
  323. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +31 -18
  324. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
  325. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +22 -10
  326. package/lib/esm/actions/requirements/midnight/index.d.ts +2 -2
  327. package/lib/esm/actions/requirements/midnight/index.js +2 -2
  328. package/lib/esm/actions/vaultV1/deposit.d.ts +21 -0
  329. package/lib/esm/actions/vaultV1/deposit.js +43 -9
  330. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +18 -1
  331. package/lib/esm/actions/vaultV1/inKindRedeem.js +33 -15
  332. package/lib/esm/actions/vaultV1/index.d.ts +5 -5
  333. package/lib/esm/actions/vaultV1/index.js +5 -5
  334. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +21 -0
  335. package/lib/esm/actions/vaultV1/migrateToV2.js +47 -11
  336. package/lib/esm/actions/vaultV1/redeem.d.ts +19 -0
  337. package/lib/esm/actions/vaultV1/redeem.js +26 -7
  338. package/lib/esm/actions/vaultV1/withdraw.d.ts +19 -0
  339. package/lib/esm/actions/vaultV1/withdraw.js +26 -7
  340. package/lib/esm/actions/vaultV2/deposit.d.ts +21 -0
  341. package/lib/esm/actions/vaultV2/deposit.js +43 -9
  342. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +20 -2
  343. package/lib/esm/actions/vaultV2/forceRedeem.js +35 -6
  344. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +23 -1
  345. package/lib/esm/actions/vaultV2/forceWithdraw.js +33 -13
  346. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +18 -1
  347. package/lib/esm/actions/vaultV2/inKindRedeem.js +32 -14
  348. package/lib/esm/actions/vaultV2/index.d.ts +6 -6
  349. package/lib/esm/actions/vaultV2/index.js +6 -6
  350. package/lib/esm/actions/vaultV2/redeem.d.ts +19 -0
  351. package/lib/esm/actions/vaultV2/redeem.js +26 -7
  352. package/lib/esm/actions/vaultV2/withdraw.d.ts +19 -0
  353. package/lib/esm/actions/vaultV2/withdraw.js +26 -7
  354. package/lib/esm/entities/blue/blue.d.ts +35 -8
  355. package/lib/esm/entities/blue/blue.js +449 -388
  356. package/lib/esm/entities/midnight/midnight.d.ts +117 -41
  357. package/lib/esm/entities/midnight/midnight.js +455 -826
  358. package/lib/esm/entities/midnight/parse.d.ts +74 -0
  359. package/lib/esm/entities/midnight/parse.js +320 -0
  360. package/lib/esm/entities/midnight/prepare.d.ts +47 -0
  361. package/lib/esm/entities/midnight/prepare.js +282 -0
  362. package/lib/esm/entities/midnight/publication.d.ts +7 -3
  363. package/lib/esm/entities/midnight/publication.js +7 -3
  364. package/lib/esm/entities/midnight/types.d.ts +7 -0
  365. package/lib/esm/entities/requirements/assertContractCode.d.ts +10 -5
  366. package/lib/esm/entities/requirements/assertContractCode.js +24 -15
  367. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
  368. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +53 -47
  369. package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -3
  370. package/lib/esm/entities/requirements/getErc2612Permit.js +19 -4
  371. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
  372. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +20 -5
  373. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
  374. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +23 -5
  375. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
  376. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
  377. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
  378. package/lib/esm/entities/requirements/index.d.ts +2 -2
  379. package/lib/esm/entities/requirements/index.js +2 -2
  380. package/lib/esm/entities/requirements/validateNativeRequirements.d.ts +21 -0
  381. package/lib/esm/entities/requirements/validateNativeRequirements.js +33 -0
  382. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
  383. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +1 -7
  384. package/lib/esm/entities/vaultV1/vaultV1.d.ts +17 -40
  385. package/lib/esm/entities/vaultV1/vaultV1.js +208 -139
  386. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
  387. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +10 -5
  388. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
  389. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +1 -7
  390. package/lib/esm/entities/vaultV2/vaultV2.d.ts +21 -52
  391. package/lib/esm/entities/vaultV2/vaultV2.js +209 -133
  392. package/lib/esm/helpers/parse.d.ts +33 -0
  393. package/lib/esm/helpers/parse.js +61 -0
  394. package/lib/esm/helpers/parseMidnight.d.ts +48 -0
  395. package/lib/esm/helpers/parseMidnight.js +80 -0
  396. package/lib/esm/helpers/parseMidnightMaker.d.ts +44 -0
  397. package/lib/esm/helpers/parseMidnightMaker.js +147 -0
  398. package/lib/esm/helpers/validate.d.ts +3 -2
  399. package/lib/esm/helpers/validate.js +5 -1
  400. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
  401. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +2 -2
  402. package/lib/esm/helpers/validateMidnightPublication.d.ts +17 -1
  403. package/lib/esm/index.d.ts +1 -0
  404. package/lib/esm/transactionPlan/blue/refinance.js +18 -10
  405. package/lib/esm/transactionPlan/blue/repay.js +3 -2
  406. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +24 -5
  407. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +2 -2
  408. package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -2
  409. package/lib/esm/transactionPlan/blue/withdraw.js +3 -3
  410. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +6 -2
  411. package/lib/esm/transactionPlan/validation.d.ts +1 -1
  412. package/lib/esm/transactionPlan/validation.js +3 -0
  413. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +2 -2
  414. package/lib/esm/transactionPlan/vaultv1/deposit.js +2 -2
  415. package/lib/esm/types/action.d.ts +13 -2
  416. package/lib/esm/types/error.d.ts +20 -2
  417. package/lib/esm/types/error.js +27 -0
  418. package/lib/esm/version.d.ts +1 -1
  419. package/lib/esm/version.js +1 -1
  420. package/package.json +3 -3
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSupplyCollateralMakeBorrowParams = exports.parseSupplyBlueMakeLendParams = exports.parseMakeWithdrawParams = exports.parseMakeBorrowParams = exports.parseMakeRepayParams = exports.parseMakeLendParams = exports.getOffersDataInternal = exports.parseGetOffersDataParams = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
7
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
8
+ const cancelAndMake_js_1 = require("../../actions/midnight/cancelAndMake.js");
9
+ const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
10
+ const callback_js_1 = require("../../helpers/callback.js");
11
+ const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
12
+ const index_js_1 = require("../../helpers/index.js");
13
+ const metadata_js_1 = require("../../helpers/metadata.js");
14
+ const parse_js_1 = require("../../helpers/parse.js");
15
+ const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
16
+ const parseMidnightMaker_js_1 = require("../../helpers/parseMidnightMaker.js");
17
+ const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
18
+ const validateMidnightPublication_js_1 = require("../../helpers/validateMidnightPublication.js");
19
+ const validateOfferSides_js_1 = require("../../helpers/validateOfferSides.js");
20
+ const validatePositiveInput_js_1 = require("../../helpers/validatePositiveInput.js");
21
+ const index_js_2 = require("../../types/index.js");
22
+ const deadline_js_1 = require("./deadline.js");
23
+ const publication_js_1 = require("./publication.js");
24
+ const offersParams = Symbol();
25
+ const preparedMake = Symbol();
26
+ /** Validates the complete raw publication request before state reads. @internal */
27
+ const parseGetOffersDataParams = (params, { client, chainId }) => {
28
+ (0, index_js_1.validateChainId)(client.viemClient.chain?.id, chainId);
29
+ const accountAddress = (0, parseMidnight_js_1.parseMidnightAccount)("accountAddress", params.accountAddress);
30
+ const tree = (0, parseMidnightMaker_js_1.parseMidnightMakerTree)({
31
+ offers: params.offers,
32
+ accountAddress,
33
+ });
34
+ const { ratifier, ratifierType } = (0, parseMidnightMaker_js_1.parseMidnightMakerBinding)({
35
+ tree,
36
+ chainId,
37
+ accountAddress,
38
+ });
39
+ return Object.freeze({
40
+ tree,
41
+ accountAddress,
42
+ ratifier,
43
+ ratifierType,
44
+ validation: params.validation,
45
+ [offersParams]: true,
46
+ });
47
+ };
48
+ exports.parseGetOffersDataParams = parseGetOffersDataParams;
49
+ /** Reads publication state only from the complete constructed request. @internal */
50
+ const getOffersDataInternal = async (params, { client, chainId, marketCreationTime = "expiry", chainCheck = (0, chainCheck_js_1.createChainCheck)(client.viemClient, chainId), }) => {
51
+ const { tree, accountAddress, ratifier, ratifierType } = params;
52
+ const { states, now } = await (0, publication_js_1.fetchMidnightMakerOfferStatesWithChainCheck)({
53
+ client: client.viemClient,
54
+ chainId,
55
+ tree,
56
+ }, chainCheck);
57
+ // RPC facts are checked here, never encoded as a permanent static witness.
58
+ (0, publication_js_1.validateMidnightMakerOfferStates)({ tree, states, now, marketCreationTime });
59
+ const groups = [];
60
+ const seenGroups = new Set();
61
+ for (const offer of tree.offers) {
62
+ const key = offer.group.toLowerCase();
63
+ if (!seenGroups.has(key)) {
64
+ seenGroups.add(key);
65
+ groups.push(offer.group);
66
+ }
67
+ }
68
+ if (params.validation !== false) {
69
+ await tree.mempoolValidate({ ...params.validation, chainId });
70
+ }
71
+ const items = tree.type === "priceV1"
72
+ ? midnight_sdk_1.PriceRatifierV1.ratify({ tree })
73
+ : midnight_sdk_1.RateRatifierV1.ratify({ tree });
74
+ return {
75
+ accountAddress,
76
+ groups,
77
+ tree,
78
+ ratifierType,
79
+ ratifier,
80
+ payload: await midnight_sdk_1.Payload.encode(items),
81
+ };
82
+ };
83
+ exports.getOffersDataInternal = getOffersDataInternal;
84
+ async function parseMakeParams({ params, operation, }, context) {
85
+ const { client, chainId } = context;
86
+ (0, index_js_1.validateChainId)(client.viemClient.chain?.id, chainId);
87
+ const accountAddress = (0, parseMidnight_js_1.parseMidnightAccount)("accountAddress", params.accountAddress);
88
+ // Preserve account and local expiry precedence before constructing the tree.
89
+ (0, deadline_js_1.validateMidnightDeadline)(params.deadline, params.now);
90
+ const lend = operation === "makeLend" || operation === "makeRepay";
91
+ const intent = (0, parseMidnightMaker_js_1.parseMidnightMakerIntent)({
92
+ offers: params.offers,
93
+ accountAddress,
94
+ side: lend ? "lend" : "borrow",
95
+ reduceOnly: operation === "makeRepay" || operation === "makeWithdraw",
96
+ });
97
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(client.options.metadata, params.now);
98
+ let loanToken;
99
+ let approvalAmount = 0n;
100
+ if (operation === "makeLend" || operation === "makeRepay") {
101
+ loanToken = params.loanToken;
102
+ // Address and amounts precede opening-side and callback checks for lenders.
103
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("loanToken", loanToken);
104
+ // Validation only; funding positivity precedes the reserved amount and opening side.
105
+ (0, validatePositiveInput_js_1.validatePositiveInput)("loanAssets", params.loanAssets);
106
+ approvalAmount =
107
+ params.loanAssets +
108
+ (0, parse_js_1.parseNonnegative)("reservedLoanAssets", params.reservedLoanAssets ?? 0n);
109
+ }
110
+ if (!intent.reduceOnly) {
111
+ (0, validateOfferSides_js_1.validateOfferSides)(intent.tree.offers, lend);
112
+ }
113
+ (0, publication_js_1.validateMidnightMakerOfferCallbacks)(intent.tree.offers);
114
+ const data = await (0, exports.getOffersDataInternal)((0, exports.parseGetOffersDataParams)({ ...params, offers: intent.tree }, context), context);
115
+ if (loanToken != null) {
116
+ // Funding relationships deliberately follow pinned publication state and API validation.
117
+ (0, parseMidnightMaker_js_1.parseMidnightMakerFundingBinding)({ tree: data.tree, loanToken });
118
+ }
119
+ const action = (0, cancelAndMake_js_1.parseMidnightCancelAndMake)({
120
+ chainId,
121
+ cancellations: params.cancellations ?? [],
122
+ deadline: params.deadline,
123
+ metadata,
124
+ publication: {
125
+ ratifier: data.ratifier,
126
+ root: data.tree.root,
127
+ groups: data.groups,
128
+ payload: data.payload,
129
+ },
130
+ });
131
+ return Object.freeze({ action, data, loanToken, approvalAmount });
132
+ }
133
+ /** Constructs the complete lend publication and requirement inputs from raw params. @internal */
134
+ const parseMakeLendParams = async (params, context) => {
135
+ const parsed = await parseMakeParams({ params, operation: "makeLend" }, context);
136
+ return Object.freeze({
137
+ ...parsed,
138
+ [preparedMake]: "makeLend",
139
+ });
140
+ };
141
+ exports.parseMakeLendParams = parseMakeLendParams;
142
+ /** Constructs the complete reduce-only repayment publication from raw params. @internal */
143
+ const parseMakeRepayParams = async (params, context) => {
144
+ const parsed = await parseMakeParams({ params, operation: "makeRepay" }, context);
145
+ return Object.freeze({
146
+ ...parsed,
147
+ [preparedMake]: "makeRepay",
148
+ });
149
+ };
150
+ exports.parseMakeRepayParams = parseMakeRepayParams;
151
+ /** Constructs the complete borrow publication from raw params. @internal */
152
+ const parseMakeBorrowParams = (params, context) => parseMakeParams({ params, operation: "makeBorrow" }, context).then((parsed) => Object.freeze({ ...parsed, [preparedMake]: "makeBorrow" }));
153
+ exports.parseMakeBorrowParams = parseMakeBorrowParams;
154
+ /** Constructs the complete reduce-only credit-exit publication from raw params. @internal */
155
+ const parseMakeWithdrawParams = (params, context) => parseMakeParams({ params, operation: "makeWithdraw" }, context).then((parsed) => Object.freeze({ ...parsed, [preparedMake]: "makeWithdraw" }));
156
+ exports.parseMakeWithdrawParams = parseMakeWithdrawParams;
157
+ /** Constructs a complete Blue-funded publication while preserving its RPC/error order. @internal */
158
+ const parseSupplyBlueMakeLendParams = async (params, context) => {
159
+ const { client, chainId } = context;
160
+ const suppliedNow = params.now;
161
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(client.options.metadata, suppliedNow);
162
+ const accountAddress = (0, parseMidnight_js_1.parseMidnightAccount)("accountAddress", params.accountAddress);
163
+ // Preserve salt and amount error context before constructing the tree or reading state.
164
+ (0, validateMidnightPublication_js_1.validateMidnightBytes32)("callbackSalt", params.callbackSalt);
165
+ const assets = (0, parseMidnight_js_1.parseMidnightPositiveAmount)("assetsToPark", params.assetsToPark);
166
+ const { loanToken, collateralToken, oracle, irm, lltv } = params.blueMarket;
167
+ const blueSupply = (0, morpho_ts_1.deepFreeze)({
168
+ market: { loanToken, collateralToken, oracle, irm, lltv },
169
+ assets,
170
+ callbackSalt: params.callbackSalt,
171
+ });
172
+ const tree = (0, parseMidnightMaker_js_1.parseMidnightMakerTree)({
173
+ offers: params.offers,
174
+ accountAddress,
175
+ });
176
+ // Side errors precede reduce-only errors on this funded boundary.
177
+ (0, validateOfferSides_js_1.validateOfferSides)(tree.offers, true);
178
+ const intent = (0, parseMidnightMaker_js_1.parseMidnightMakerIntent)({
179
+ offers: tree,
180
+ accountAddress,
181
+ side: "lend",
182
+ reduceOnly: false,
183
+ });
184
+ const chainCheck = (0, chainCheck_js_1.createChainCheck)(client.viemClient, chainId);
185
+ await chainCheck();
186
+ // Freshness belongs to this invocation, after its chain check.
187
+ (0, deadline_js_1.validateMidnightDeadline)(params.deadline, suppliedNow);
188
+ const { callbackSalt, market: blueMarket, assets: assetsToPark } = blueSupply;
189
+ const callbackData = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("blueMarket", () => (0, callback_js_1.getMidnightBlueBuyCallbackData)(blueMarket));
190
+ const blueMarketId = blue_sdk_1.MarketUtils.getMarketId(blueMarket);
191
+ const callback = (0, callback_js_1.getMidnightBlueBuyCallbackAddress)({
192
+ chainId,
193
+ owner: accountAddress,
194
+ salt: callbackSalt,
195
+ });
196
+ const [data, fetched] = await Promise.all([
197
+ (0, exports.getOffersDataInternal)((0, exports.parseGetOffersDataParams)({ ...params, offers: intent.tree }, context), { ...context, chainCheck }),
198
+ (0, blue_sdk_viem_1.fetchMarket)(blueMarketId, client.viemClient, {
199
+ deployless: client.options.supportDeployless,
200
+ }),
201
+ ]);
202
+ const market = (0, morpho_ts_1._try)(() => fetched.accrueInterest(blue_sdk_1.MathLib.max(suppliedNow ?? morpho_ts_1.Time.timestamp(), fetched.lastUpdate)), blue_sdk_1.UnsupportedMarketIrmError) ?? fetched;
203
+ if (market.totalSupplyShares === 0n) {
204
+ throw new index_js_2.EmptyBlueParkingMarketError({ marketId: blueMarketId });
205
+ }
206
+ if (market.toSupplyShares(assetsToPark, "Down") === 0n) {
207
+ throw new index_js_2.ZeroBlueParkingSharesError({
208
+ marketId: blueMarketId,
209
+ assets: assetsToPark,
210
+ });
211
+ }
212
+ // Preserve late callback/loan-token relationship errors after the parking-state checks.
213
+ (0, parseMidnightMaker_js_1.parseMidnightMakerFundingBinding)({
214
+ tree: data.tree,
215
+ loanToken: blueMarket.loanToken,
216
+ callback: { address: callback, data: callbackData },
217
+ });
218
+ const action = (0, cancelAndMake_js_1.parseMidnightCancelAndMake)({
219
+ chainId,
220
+ publication: {
221
+ ratifier: data.ratifier,
222
+ root: data.tree.root,
223
+ groups: data.groups,
224
+ payload: data.payload,
225
+ blueSupply: { market: blueMarket, assets: assetsToPark, callbackSalt },
226
+ },
227
+ nativeAmount: params.nativeAmount,
228
+ cancellations: params.cancellations ?? [],
229
+ deadline: params.deadline,
230
+ metadata,
231
+ });
232
+ return Object.freeze({
233
+ action,
234
+ data,
235
+ loanToken: blueMarket.loanToken,
236
+ approvalAmount: assetsToPark,
237
+ [preparedMake]: "supplyBlueMakeLend",
238
+ });
239
+ };
240
+ exports.parseSupplyBlueMakeLendParams = parseSupplyBlueMakeLendParams;
241
+ /** Constructs the complete collateral-funded borrow publication from its raw request. @internal */
242
+ const parseSupplyCollateralMakeBorrowParams = async (params, context) => {
243
+ const { client, chainId } = context;
244
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(client.options.metadata, params.now);
245
+ (0, index_js_1.validateChainId)(client.viemClient.chain?.id, chainId);
246
+ const accountAddress = (0, parseMidnight_js_1.parseMidnightAccount)("accountAddress", params.accountAddress);
247
+ // Preserve local expiry before market/tree construction.
248
+ (0, deadline_js_1.validateMidnightDeadline)(params.deadline, params.now);
249
+ const market = params.collateral.market instanceof midnight_sdk_1.MarketParams
250
+ ? params.collateral.market
251
+ : midnight_sdk_1.MarketParams.from(params.collateral.market);
252
+ const tree = (0, parseMidnightMaker_js_1.parseMidnightMakerTree)({
253
+ offers: params.offers,
254
+ accountAddress,
255
+ });
256
+ // Borrow-side and callback guards precede reduce-only guards on this funded boundary.
257
+ (0, validateOfferSides_js_1.validateOfferSides)(tree.offers, false);
258
+ (0, publication_js_1.validateMidnightMakerOfferCallbacks)(tree.offers);
259
+ const intent = (0, parseMidnightMaker_js_1.parseMidnightMakerIntent)({
260
+ offers: tree,
261
+ accountAddress,
262
+ side: "borrow",
263
+ reduceOnly: false,
264
+ });
265
+ const data = await (0, exports.getOffersDataInternal)((0, exports.parseGetOffersDataParams)({ ...params, offers: intent.tree }, context), { ...context, marketCreationTime: "now" });
266
+ const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(market);
267
+ for (const offer of data.tree.offers) {
268
+ const offerMarketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(offer.market);
269
+ if (offerMarketId.toLowerCase() !== marketId.toLowerCase()) {
270
+ throw new index_js_2.MarketIdMismatchError(offerMarketId, marketId);
271
+ }
272
+ }
273
+ const action = (0, cancelAndMake_js_1.parseMidnightCancelAndMake)({
274
+ chainId,
275
+ nativeAmount: params.nativeAmount,
276
+ cancellations: params.cancellations ?? [],
277
+ deadline: params.deadline,
278
+ metadata,
279
+ publication: {
280
+ ratifier: data.ratifier,
281
+ root: data.tree.root,
282
+ groups: data.groups,
283
+ payload: data.payload,
284
+ collateral: { market, supplies: params.collateral.supplies },
285
+ },
286
+ });
287
+ return Object.freeze({
288
+ action,
289
+ data,
290
+ [preparedMake]: "supplyCollateralMakeBorrow",
291
+ });
292
+ };
293
+ exports.parseSupplyCollateralMakeBorrowParams = parseSupplyCollateralMakeBorrowParams;
@@ -1,7 +1,6 @@
1
- import { Market, MarketParams, type Offer, type Tree } from "@morpho-org/midnight-sdk";
1
+ import { Market, type Tree } from "@morpho-org/midnight-sdk";
2
2
  import { type Address, type Client } from "viem";
3
- /** @internal */
4
- export declare const offerMarketParams: (offer: Offer) => MarketParams;
3
+ import { type ChainCheck } from "../../actions/requirements/chainCheck.js";
5
4
  /** Onchain state used to validate one Midnight maker offer before publication.
6
5
  *
7
6
  * `market` supplies the market id for errors, the maturity used for Rate V1 sell-overflow timing,
@@ -118,6 +117,11 @@ export declare function fetchMidnightMakerOfferStates(params: {
118
117
  readonly states: readonly MidnightMakerOfferState[];
119
118
  readonly now: bigint;
120
119
  }>;
120
+ /** Reads maker state using the invocation's chain check. @internal */
121
+ export declare function fetchMidnightMakerOfferStatesWithChainCheck(params: Parameters<typeof fetchMidnightMakerOfferStates>[0], chainCheck: ChainCheck): Promise<{
122
+ readonly states: readonly MidnightMakerOfferState[];
123
+ readonly now: bigint;
124
+ }>;
121
125
  /**
122
126
  * Rejects offers with callbacks that the selected maker flow cannot execute.
123
127
  *
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.offerMarketParams = void 0;
4
3
  exports.validateMidnightMakerOfferStates = validateMidnightMakerOfferStates;
5
4
  exports.fetchMidnightMakerOfferStates = fetchMidnightMakerOfferStates;
5
+ exports.fetchMidnightMakerOfferStatesWithChainCheck = fetchMidnightMakerOfferStatesWithChainCheck;
6
6
  exports.validateMidnightMakerOfferCallbacks = validateMidnightMakerOfferCallbacks;
7
7
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
8
8
  const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
9
9
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
10
10
  const viem_1 = require("viem");
11
11
  const actions_1 = require("viem/actions");
12
- const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
+ const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
13
13
  const midnightPublicationError_js_1 = require("../../types/midnightPublicationError.js");
14
14
  // Midnight.sol `touchMarket` rejects markets maturing more than 100 years after creation.
15
15
  const MAX_TIME_TO_MATURITY = 100n * 365n * 86400n;
@@ -21,7 +21,6 @@ function requirePublicationState(value) {
21
21
  }
22
22
  /** @internal */
23
23
  const offerMarketParams = (offer) => "params" in offer.market ? offer.market.params : offer.market;
24
- exports.offerMarketParams = offerMarketParams;
25
24
  function validateOfferTerms({ offer, state, index, marketId, }) {
26
25
  const capacity = BigInt(offer.maxAssets) > 0n
27
26
  ? BigInt(offer.maxAssets)
@@ -148,7 +147,7 @@ function validateMidnightMakerOfferStates(params) {
148
147
  params.tree.offers.forEach((offer, index) => {
149
148
  const state = requirePublicationState(params.states[index]);
150
149
  const expiry = BigInt(offer.expiry);
151
- const offerMarket = (0, exports.offerMarketParams)(offer);
150
+ const offerMarket = offerMarketParams(offer);
152
151
  const maturity = BigInt(offerMarket.maturity);
153
152
  const marketId = state.market.id;
154
153
  if (expiry <= params.now) {
@@ -219,7 +218,11 @@ function validateMidnightMakerOfferStates(params) {
219
218
  * ```
220
219
  */
221
220
  async function fetchMidnightMakerOfferStates(params) {
222
- await (0, validateClientChainId_js_1.validateClientChainId)(params.client, params.chainId);
221
+ return fetchMidnightMakerOfferStatesWithChainCheck(params, (0, chainCheck_js_1.createChainCheck)(params.client, params.chainId));
222
+ }
223
+ /** Reads maker state using the invocation's chain check. @internal */
224
+ async function fetchMidnightMakerOfferStatesWithChainCheck(params, chainCheck) {
225
+ await chainCheck();
223
226
  const blockNumber = params.blockNumber ?? (await (0, actions_1.getBlockNumber)(params.client));
224
227
  const block = await (0, actions_1.getBlock)(params.client, { blockNumber });
225
228
  const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
@@ -258,7 +261,7 @@ async function fetchMidnightMakerOfferStates(params) {
258
261
  lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
259
262
  liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
260
263
  oracleHasCode: uncreated
261
- ? (0, exports.offerMarketParams)(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
264
+ ? offerMarketParams(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
262
265
  codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
263
266
  : [],
264
267
  };
@@ -269,7 +272,7 @@ async function fetchMidnightMakerOfferStates(params) {
269
272
  function collectPublicationReadTargets(tree) {
270
273
  const markets = [
271
274
  ...new Map(tree.offers.map((offer) => {
272
- const market = midnight_sdk_1.MarketParams.from((0, exports.offerMarketParams)(offer));
275
+ const market = midnight_sdk_1.MarketParams.from(offerMarketParams(offer));
273
276
  const id = midnight_sdk_1.MarketUtils.toId(market);
274
277
  return [id.toLowerCase(), { id, market }];
275
278
  })).values(),
@@ -235,6 +235,13 @@ export interface SupplyCollateralParams extends MarketActionParams {
235
235
  readonly reservedCollateralAssets?: bigint;
236
236
  readonly collateralIndex?: bigint;
237
237
  }
238
+ /** Parameters for a Midnight collateral supply with native wrapping. */
239
+ export interface SupplyCollateralWithNativeParams extends SupplyCollateralParams {
240
+ /** Positive native funding in wei, capped at the supplied wNative collateral. */
241
+ readonly nativeAmount: bigint;
242
+ /** Bundle execution deadline. Pass `maxUint256` explicitly for no expiry. */
243
+ readonly deadline: bigint;
244
+ }
238
245
  /** Parameters for an atomic direct Midnight collateral supply batch. */
239
246
  export interface SupplyCollateralBatchParams extends MarketActionParams {
240
247
  readonly collateralSupplies: readonly {
@@ -1,5 +1,6 @@
1
1
  import type { AddressLabel } from "@morpho-org/morpho-ts";
2
2
  import type { Address, Client } from "viem";
3
+ import { type ChainCheck } from "../../actions/requirements/chainCheck.js";
3
4
  /**
4
5
  * Asserts that a configured contract address holds deployed code on the client's chain.
5
6
  *
@@ -26,16 +27,20 @@ export declare const assertContractCode: (client: Client, params: {
26
27
  /**
27
28
  * Asserts that each distinct target in a flow's write-surface list holds code.
28
29
  *
29
- * One `eth_getCode` per distinct address runs before any other requirement read.
30
- * A wrong-chain RPC reports no code at every target, so on the first
31
- * {@link MissingContractCodeError} a single `eth_chainId` probe decides: a served
30
+ * One `eth_getCode` per distinct address launches concurrently, preserving the
31
+ * first occurrence's reporting order. Each read's rejection handler attaches
32
+ * immediately; outcomes are then consumed in target order, so a known earlier
33
+ * failure does not wait for later reads to settle. Later rejections stay observed
34
+ * even after this assertion returns early.
35
+ * Before any other requirement read, a selected {@link MissingContractCodeError}
36
+ * uses the invocation's lazy chain preflight (reusing an earlier result): a served
32
37
  * chain mismatch surfaces as {@link ChainIdMismatchError} (never as missing
33
38
  * code), a failed probe keeps the original missing-code error, and a matching
34
39
  * chain rethrows it unchanged. Other assertion errors propagate unwrapped.
35
40
  *
36
41
  * @param client - Connected viem client used for the `eth_getCode` reads.
37
42
  * @param chainId - Chain id the flow targets, reported on the errors.
38
- * @param targets - Distinct-by-address targets to check, in reporting order.
43
+ * @param targets - Targets to deduplicate by address and check, in reporting order.
39
44
  * @returns Nothing when every target holds code.
40
45
  * @throws {MissingContractCodeError} when a target has no deployed bytecode on
41
46
  * the endpoint's chain.
@@ -46,4 +51,4 @@ export declare const assertContractCode: (client: Client, params: {
46
51
  export declare const assertRegistryTargetsHaveCode: (client: Client, chainId: number, targets: readonly {
47
52
  readonly role: AddressLabel;
48
53
  readonly address: Address;
49
- }[]) => Promise<void>;
54
+ }[], chainCheck?: ChainCheck) => Promise<void>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertRegistryTargetsHaveCode = exports.assertContractCode = void 0;
4
4
  const actions_1 = require("viem/actions");
5
- const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
5
+ const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
6
6
  const index_js_1 = require("../../types/index.js");
7
7
  /**
8
8
  * Asserts that a configured contract address holds deployed code on the client's chain.
@@ -32,16 +32,20 @@ exports.assertContractCode = assertContractCode;
32
32
  /**
33
33
  * Asserts that each distinct target in a flow's write-surface list holds code.
34
34
  *
35
- * One `eth_getCode` per distinct address runs before any other requirement read.
36
- * A wrong-chain RPC reports no code at every target, so on the first
37
- * {@link MissingContractCodeError} a single `eth_chainId` probe decides: a served
35
+ * One `eth_getCode` per distinct address launches concurrently, preserving the
36
+ * first occurrence's reporting order. Each read's rejection handler attaches
37
+ * immediately; outcomes are then consumed in target order, so a known earlier
38
+ * failure does not wait for later reads to settle. Later rejections stay observed
39
+ * even after this assertion returns early.
40
+ * Before any other requirement read, a selected {@link MissingContractCodeError}
41
+ * uses the invocation's lazy chain preflight (reusing an earlier result): a served
38
42
  * chain mismatch surfaces as {@link ChainIdMismatchError} (never as missing
39
43
  * code), a failed probe keeps the original missing-code error, and a matching
40
44
  * chain rethrows it unchanged. Other assertion errors propagate unwrapped.
41
45
  *
42
46
  * @param client - Connected viem client used for the `eth_getCode` reads.
43
47
  * @param chainId - Chain id the flow targets, reported on the errors.
44
- * @param targets - Distinct-by-address targets to check, in reporting order.
48
+ * @param targets - Targets to deduplicate by address and check, in reporting order.
45
49
  * @returns Nothing when every target holds code.
46
50
  * @throws {MissingContractCodeError} when a target has no deployed bytecode on
47
51
  * the endpoint's chain.
@@ -50,26 +54,31 @@ exports.assertContractCode = assertContractCode;
50
54
  * @internal
51
55
  */
52
56
  // biome-ignore lint/complexity/useMaxParams: positional (client, chainId, targets) signature
53
- const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
57
+ const assertRegistryTargetsHaveCode = async (client, chainId, targets, chainCheck = (0, chainCheck_js_1.createChainCheck)(client, chainId)) => {
54
58
  const seen = new Set();
59
+ const checks = [];
55
60
  for (const target of targets) {
56
61
  if (seen.has(target.address)) {
57
62
  continue;
58
63
  }
59
64
  seen.add(target.address);
60
- try {
61
- await (0, exports.assertContractCode)(client, {
62
- address: target.address,
63
- chainId,
64
- role: target.role,
65
- });
66
- }
67
- catch (error) {
65
+ checks.push((0, exports.assertContractCode)(client, {
66
+ address: target.address,
67
+ chainId,
68
+ role: target.role,
69
+ }).then(() => ({ status: "fulfilled", value: undefined }), (reason) => ({ status: "rejected", reason })));
70
+ }
71
+ // Every started read is already observed; await only the next ordered outcome,
72
+ // not all reads together, so stalled later targets cannot hide an earlier error.
73
+ for (const check of checks) {
74
+ const result = await check;
75
+ if (result.status === "rejected") {
76
+ const error = result.reason;
68
77
  if (!(error instanceof index_js_1.MissingContractCodeError)) {
69
78
  throw error;
70
79
  }
71
80
  try {
72
- await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
81
+ await chainCheck();
73
82
  }
74
83
  catch (probeError) {
75
84
  throw probeError instanceof index_js_1.ChainIdMismatchError ? probeError : error;
@@ -1,4 +1,5 @@
1
1
  import { type Address, type Client } from "viem";
2
+ import { type ChainCheck } from "../../actions/requirements/chainCheck.js";
2
3
  import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type ReferenceTimestampParams, type Transaction } from "../../types/index.js";
3
4
  /** Parameters for {@link getBundlesTokenRequirements}. */
4
5
  export interface GetBundlesTokenRequirementsParams extends ReferenceTimestampParams {
@@ -23,6 +24,14 @@ export interface GetBundlesTokenRequirementsParams extends ReferenceTimestampPar
23
24
  /** @deprecated Ignored. The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
24
25
  readonly permit2Nonce?: bigint;
25
26
  }
27
+ declare const bundlesTokenRequirementsInput: unique symbol;
28
+ /** Complete checked token resolver invocation. @internal */
29
+ export type GetBundlesTokenRequirementsInput = Readonly<GetBundlesTokenRequirementsParams> & {
30
+ readonly useSimplePermit: boolean;
31
+ readonly [bundlesTokenRequirementsInput]: true;
32
+ };
33
+ /** Owns static checks and defaults without reading state. @internal */
34
+ export declare const parseGetBundlesTokenRequirements: (viemClient: Client, params: GetBundlesTokenRequirementsParams) => GetBundlesTokenRequirementsInput;
26
35
  /**
27
36
  * Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
28
37
  *
@@ -91,3 +100,9 @@ export interface GetBundlesTokenRequirementsParams extends ReferenceTimestampPar
91
100
  * ```
92
101
  */
93
102
  export declare const getBundlesTokenRequirements: (viemClient: Client, params: GetBundlesTokenRequirementsParams) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[]>;
103
+ /** Consumes a complete invocation while retaining dynamic freshness and RPC order. @internal */
104
+ export declare const getParsedBundlesTokenRequirements: ({ viemClient, chainCheck: providedChainCheck, }: {
105
+ readonly viemClient: Client;
106
+ readonly chainCheck?: ChainCheck;
107
+ }, params: GetBundlesTokenRequirementsInput) => ReturnType<typeof getBundlesTokenRequirements>;
108
+ export {};