@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
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.midnightWithdrawCollateral = void 0;
4
- const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
3
+ exports.parseMidnightWithdrawCollateral = exports.midnightWithdrawCollateral = void 0;
5
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
- const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
8
- const index_js_1 = require("../../helpers/index.js");
9
- const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
10
- const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
11
- const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
5
+ const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
12
6
  const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
13
- const index_js_2 = require("../../types/index.js");
7
+ const encode_js_1 = require("./encode.js");
8
+ const parse_js_1 = require("./parse.js");
14
9
  /**
15
10
  * Encodes a direct Midnight collateral withdrawal.
16
11
  *
@@ -47,59 +42,33 @@ const index_js_2 = require("../../types/index.js");
47
42
  * });
48
43
  * ```
49
44
  */
50
- const midnightWithdrawCollateral = (params) => {
51
- // Reject a malformed account before comparing it with the zero address.
52
- (0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", params.onBehalf);
53
- if (params.assets <= 0n) {
54
- throw new index_js_2.NonPositiveInputError("assets", params.assets);
55
- }
56
- (0, validateMidnightBounds_js_1.validateMidnightUint128Field)("assets", params.assets);
57
- if ((0, viem_1.isAddressEqual)(params.onBehalf, viem_1.zeroAddress)) {
58
- throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
59
- }
45
+ const midnightWithdrawCollateral = (params) => (0, encode_js_1.encodeMidnightWithdrawCollateral)((0, exports.parseMidnightWithdrawCollateral)(params));
46
+ exports.midnightWithdrawCollateral = midnightWithdrawCollateral;
47
+ const parsedWithdrawCollateral = Symbol();
48
+ /** Parses static withdrawCollateral constraints using the existing error order. @internal */
49
+ const parseMidnightWithdrawCollateral = (params) => {
50
+ const address = (0, parseMidnight_js_1.parseMidnightAddress)("onBehalf", params.onBehalf);
51
+ const assets = (0, parseMidnight_js_1.parseMidnightPositiveAmount)("assets", params.assets);
52
+ const onBehalf = (0, parseMidnight_js_1.parseMidnightOwner)(address);
60
53
  // Reject markets from another chain deployment before encoding the call.
61
- (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
62
- const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
63
- const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
64
- const collateralIndex = params.collateralIndex ?? 0n;
65
- // Validate that the supplied collateral index is configured before encoding.
66
- midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
54
+ const market = (0, parseMidnight_js_1.parseMidnightMarket)(params.market, params.chainId);
55
+ const collateral = (0, parseMidnight_js_1.parseMidnightCollateral)(market, params.collateralIndex ?? 0n);
56
+ const collateralIndex = collateral.index;
67
57
  (0, validateMidnightReceiver_js_1.validateMidnightReceiver)({
68
58
  chainId: params.chainId,
69
- market: params.market,
59
+ market: market.struct,
70
60
  field: "receiver",
71
61
  receiver: params.receiver,
72
62
  });
73
- let tx = {
74
- to: midnight,
75
- value: 0n,
76
- data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
77
- abi: midnight_sdk_1.midnightAbi,
78
- functionName: "withdrawCollateral",
79
- args: [
80
- midnight_sdk_1.MarketUtils.toStruct(params.market),
81
- collateralIndex,
82
- params.assets,
83
- params.onBehalf,
84
- params.receiver,
85
- ],
86
- }),
87
- };
88
- if (params.metadata) {
89
- tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
90
- }
91
63
  return (0, morpho_ts_1.deepFreeze)({
92
- ...tx,
93
- action: {
94
- type: "midnightWithdrawCollateral",
95
- args: {
96
- market: marketId,
97
- collateralIndex,
98
- assets: params.assets,
99
- onBehalf: params.onBehalf,
100
- receiver: params.receiver,
101
- },
102
- },
64
+ chainId: params.chainId,
65
+ market,
66
+ onBehalf,
67
+ assets,
68
+ collateralIndex,
69
+ receiver: params.receiver,
70
+ metadata: (0, parse_js_1.snapshotMidnightMetadata)(params.metadata),
71
+ [parsedWithdrawCollateral]: true,
103
72
  });
104
73
  };
105
- exports.midnightWithdrawCollateral = midnightWithdrawCollateral;
74
+ exports.parseMidnightWithdrawCollateral = parseMidnightWithdrawCollateral;
@@ -1,6 +1,6 @@
1
- import { type MarketInput } from "@morpho-org/midnight-sdk";
2
- import { type Address } from "viem";
3
- import { type Metadata, type MidnightCollateralTransfer, type MidnightWithdrawCollateralBatchAction, type Transaction } from "../../types/index.js";
1
+ import type { MarketInput } from "@morpho-org/midnight-sdk";
2
+ import type { Address } from "viem";
3
+ import type { Metadata, MidnightCollateralTransfer, MidnightWithdrawCollateralBatchAction, Transaction } from "../../types/index.js";
4
4
  /** Parameters for an atomic direct Midnight collateral withdrawal batch. */
5
5
  export interface MidnightWithdrawCollateralBatchParams {
6
6
  readonly chainId: number;
@@ -1,17 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.midnightWithdrawCollateralBatch = void 0;
4
- const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
- const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
8
- const index_js_1 = require("../../helpers/index.js");
9
- const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
10
- const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
11
- const validateMidnightCollateralBatch_js_1 = require("../../helpers/validateMidnightCollateralBatch.js");
12
- const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
13
- const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
14
- const index_js_2 = require("../../types/index.js");
4
+ const encode_js_1 = require("./encode.js");
5
+ const parseCollateralBatch_js_1 = require("./parseCollateralBatch.js");
15
6
  /**
16
7
  * Encodes ordered collateral withdrawals in one Midnight multicall, even for one entry.
17
8
  * Duplicates are rejected: pass one entry per index, unlike bundle flows which sum them.
@@ -43,64 +34,5 @@ const index_js_2 = require("../../types/index.js");
43
34
  * });
44
35
  * ```
45
36
  */
46
- const midnightWithdrawCollateralBatch = (params) => {
47
- // Reject malformed addresses before comparing with zero.
48
- (0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", params.onBehalf);
49
- if ((0, viem_1.isAddressEqual)(params.onBehalf, viem_1.zeroAddress)) {
50
- throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
51
- }
52
- // Reject markets from another deployment before encoding.
53
- (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
54
- (0, validateMidnightReceiver_js_1.validateMidnightReceiver)({
55
- chainId: params.chainId,
56
- market: params.market,
57
- field: "receiver",
58
- receiver: params.receiver,
59
- });
60
- // Direct batches require one entry per index rather than summing duplicates.
61
- (0, validateMidnightCollateralBatch_js_1.validateMidnightCollateralBatch)(params.collateralWithdrawals, new index_js_2.EmptyMidnightCollateralWithdrawalsError());
62
- const calls = params.collateralWithdrawals.map(({ collateralIndex, assets }) => {
63
- if (assets <= 0n) {
64
- throw new index_js_2.NonPositiveInputError("assets", assets);
65
- }
66
- (0, validateMidnightBounds_js_1.validateMidnightUint128Field)("assets", assets);
67
- // Reject indexes not configured on the market.
68
- midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
69
- return (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
70
- abi: midnight_sdk_1.midnightAbi,
71
- functionName: "withdrawCollateral",
72
- args: [
73
- midnight_sdk_1.MarketUtils.toStruct(params.market),
74
- collateralIndex,
75
- assets,
76
- params.onBehalf,
77
- params.receiver,
78
- ],
79
- });
80
- });
81
- let tx = {
82
- to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight"),
83
- value: 0n,
84
- data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
85
- abi: midnight_sdk_1.midnightAbi,
86
- functionName: "multicall",
87
- args: [calls],
88
- }),
89
- };
90
- if (params.metadata) {
91
- tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
92
- }
93
- return (0, morpho_ts_1.deepFreeze)({
94
- ...tx,
95
- action: {
96
- type: "midnightWithdrawCollateralBatch",
97
- args: {
98
- market: (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market),
99
- collateralWithdrawals: params.collateralWithdrawals.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
100
- onBehalf: params.onBehalf,
101
- receiver: params.receiver,
102
- },
103
- },
104
- });
105
- };
37
+ const midnightWithdrawCollateralBatch = (params) => (0, encode_js_1.encodeMidnightWithdrawCollateralBatch)((0, parseCollateralBatch_js_1.parseMidnightWithdrawCollateralBatch)(params));
106
38
  exports.midnightWithdrawCollateralBatch = midnightWithdrawCollateralBatch;
@@ -1,6 +1,16 @@
1
1
  import type { Client } from "viem";
2
2
  import { type Address } from "viem";
3
3
  import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type ReferenceTimestampParams, type Requirement, type Transaction } from "../../../types/index.js";
4
+ import { type ChainCheck } from "../chainCheck.js";
5
+ declare const blueAuthorizationRequirementInput: unique symbol;
6
+ /** Complete checked authorization resolver invocation. @internal */
7
+ export type BlueAuthorizationRequirementInput = Readonly<Parameters<typeof getBlueAuthorizationRequirement>[0]> & {
8
+ readonly authorized: Address;
9
+ readonly morpho: Address;
10
+ readonly [blueAuthorizationRequirementInput]: true;
11
+ };
12
+ /** Owns operator defaults and static checks for this complete resolver call. @internal */
13
+ export declare const parseBlueAuthorizationRequirement: (params: Parameters<typeof getBlueAuthorizationRequirement>[0]) => BlueAuthorizationRequirementInput;
4
14
  /**
5
15
  * Resolves whether a supported operator needs Blue authorization for the given user, and returns
6
16
  * the requirement to satisfy it when it does.
@@ -64,3 +74,6 @@ export declare const getBlueAuthorizationRequirement: (params: {
64
74
  readonly authorized?: Address;
65
75
  readonly deadline?: bigint;
66
76
  } & ReferenceTimestampParams) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
77
+ /** Reads authorization from the complete checked invocation, preserving RPC order. @internal */
78
+ export declare const getParsedBlueAuthorizationRequirement: (params: BlueAuthorizationRequirementInput, chainCheck?: ChainCheck) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
79
+ export {};
@@ -1,14 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBlueAuthorizationRequirement = void 0;
3
+ exports.getParsedBlueAuthorizationRequirement = exports.getBlueAuthorizationRequirement = exports.parseBlueAuthorizationRequirement = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const validate_js_1 = require("../../../helpers/validate.js");
9
9
  const index_js_1 = require("../../../types/index.js");
10
+ const chainCheck_js_1 = require("../chainCheck.js");
10
11
  const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSignatureAuthorization.js");
11
- const validateClientChainId_js_1 = require("../validateClientChainId.js");
12
+ /** Owns operator defaults and static checks for this complete resolver call. @internal */
13
+ const parseBlueAuthorizationRequirement = (params) => {
14
+ const input = {
15
+ viemClient: params.viemClient,
16
+ chainId: params.chainId,
17
+ userAddress: params.userAddress,
18
+ supportSignature: params.supportSignature,
19
+ authorized: params.authorized,
20
+ deadline: params.deadline,
21
+ now: params.now,
22
+ };
23
+ (0, validate_js_1.validateChainId)(input.viemClient.chain?.id, input.chainId);
24
+ const { blue: morpho } = (0, blue_sdk_1.getChainAddresses)(input.chainId);
25
+ const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(input.chainId, "bundles.blueBundlesV1");
26
+ const authorized = input.authorized ?? blueBundlesV1;
27
+ if (!(0, viem_1.isAddressEqual)(blueBundlesV1, authorized)) {
28
+ throw new index_js_1.UnsupportedAuthorizationOperatorError(authorized, input.chainId);
29
+ }
30
+ if (input.supportSignature && input.deadline != null) {
31
+ (0, validate_js_1.validateDeadline)(input.deadline);
32
+ }
33
+ return { ...input, authorized, morpho };
34
+ };
35
+ exports.parseBlueAuthorizationRequirement = parseBlueAuthorizationRequirement;
12
36
  /**
13
37
  * Resolves whether a supported operator needs Blue authorization for the given user, and returns
14
38
  * the requirement to satisfy it when it does.
@@ -65,30 +89,24 @@ const validateClientChainId_js_1 = require("../validateClientChainId.js");
65
89
  * ```
66
90
  */
67
91
  const getBlueAuthorizationRequirement = async (params) => {
68
- const { viemClient, chainId, userAddress, supportSignature } = params;
69
- (0, validate_js_1.validateChainId)(viemClient.chain?.id, chainId);
70
- const { blue: morpho } = (0, blue_sdk_1.getChainAddresses)(chainId);
71
- const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.blueBundlesV1");
72
- const authorized = params.authorized ?? blueBundlesV1;
73
- // The SDK only ever authorizes the chain's registered BlueBundlesV1 operator;
74
- // reject any other override so a misconfigured `authorized` cannot grant an arbitrary address
75
- // control over the user's Morpho positions.
76
- if (!(0, viem_1.isAddressEqual)(blueBundlesV1, authorized)) {
77
- throw new index_js_1.UnsupportedAuthorizationOperatorError(authorized, chainId);
78
- }
92
+ return (0, exports.getParsedBlueAuthorizationRequirement)((0, exports.parseBlueAuthorizationRequirement)(params));
93
+ };
94
+ exports.getBlueAuthorizationRequirement = getBlueAuthorizationRequirement;
95
+ /** Reads authorization from the complete checked invocation, preserving RPC order. @internal */
96
+ const getParsedBlueAuthorizationRequirement = async (params, chainCheck = (0, chainCheck_js_1.createChainCheck)(params.viemClient, params.chainId)) => {
97
+ const { viemClient, chainId, userAddress, supportSignature, morpho, authorized, } = params;
79
98
  const pc = viemClient.extend(viem_1.publicActions);
80
99
  if (supportSignature) {
81
100
  // The forwarded deadline is only consumed on the signable path; reject an invalid or expired
82
101
  // one before the RPC reads so the caller never signs an authorization that cannot be encoded
83
102
  // or would revert on-chain. An omitted deadline defaults downstream to two hours from now.
84
103
  if (params.deadline != null) {
85
- (0, validate_js_1.validateDeadline)(params.deadline);
86
104
  const timestamp = params.now ?? morpho_ts_1.Time.timestamp();
87
105
  if (params.deadline <= timestamp) {
88
106
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
89
107
  }
90
108
  }
91
- await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, chainId);
109
+ await chainCheck();
92
110
  // The signable path needs the user's Morpho nonce; fetch it alongside the
93
111
  // authorization status so both reads share a round-trip (batched into a
94
112
  // single multicall when the client enables batching) instead of
@@ -110,16 +128,18 @@ const getBlueAuthorizationRequirement = async (params) => {
110
128
  if (isAuthorized) {
111
129
  return null;
112
130
  }
113
- return (0, encodeBlueSignatureAuthorization_js_1.encodeBlueSignatureAuthorization)(viemClient, {
131
+ // Construct the complete child operation with the fresh nonce; its encoder rechecks expiry now.
132
+ return (0, encodeBlueSignatureAuthorization_js_1.encodeParsedBlueSignatureAuthorization)((0, encodeBlueSignatureAuthorization_js_1.parseBlueSignatureAuthorization)(viemClient, {
114
133
  owner: userAddress,
115
134
  authorized,
116
135
  chainId,
117
136
  nonce,
118
137
  deadline: params.deadline,
119
138
  now: params.now,
120
- });
139
+ isAuthorized: true,
140
+ }));
121
141
  }
122
- await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, chainId);
142
+ await chainCheck();
123
143
  const isAuthorized = await pc.readContract({
124
144
  address: morpho,
125
145
  abi: blue_sdk_viem_1.blueAbi,
@@ -146,4 +166,4 @@ const getBlueAuthorizationRequirement = async (params) => {
146
166
  },
147
167
  });
148
168
  };
149
- exports.getBlueAuthorizationRequirement = getBlueAuthorizationRequirement;
169
+ exports.getParsedBlueAuthorizationRequirement = getParsedBlueAuthorizationRequirement;
@@ -1 +1 @@
1
- export * from "./getBlueAuthorizationRequirement.js";
1
+ export { getBlueAuthorizationRequirement } from "./getBlueAuthorizationRequirement.js";
@@ -1,17 +1,5 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
3
+ exports.getBlueAuthorizationRequirement = void 0;
4
+ var getBlueAuthorizationRequirement_js_1 = require("./getBlueAuthorizationRequirement.js");
5
+ Object.defineProperty(exports, "getBlueAuthorizationRequirement", { enumerable: true, get: function () { return getBlueAuthorizationRequirement_js_1.getBlueAuthorizationRequirement; } });
@@ -0,0 +1,5 @@
1
+ import type { Client } from "viem";
2
+ /** A lazy chain validation shared only within one invocation. @internal */
3
+ export type ChainCheck = () => Promise<void>;
4
+ /** Creates an invocation-local check, retaining both success and failure. @internal */
5
+ export declare const createChainCheck: (client: Client, chainId: number) => ChainCheck;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createChainCheck = void 0;
4
+ const validateClientChainId_js_1 = require("./validateClientChainId.js");
5
+ /** Creates an invocation-local check, retaining both success and failure. @internal */
6
+ const createChainCheck = (client, chainId) => {
7
+ let pending;
8
+ return () => (pending ??= (0, validateClientChainId_js_1.validateClientChainId)(client, chainId));
9
+ };
10
+ exports.createChainCheck = createChainCheck;
@@ -16,6 +16,14 @@ interface EncodeBlueSignatureAuthorizationParams extends ReferenceTimestampParam
16
16
  /** Signature deadline in seconds. Defaults to two hours from now. */
17
17
  deadline?: bigint;
18
18
  }
19
+ declare const blueSignatureAuthorizationInput: unique symbol;
20
+ /** Complete checked authorization signature invocation. @internal */
21
+ export type BlueSignatureAuthorizationInput = Readonly<EncodeBlueSignatureAuthorizationParams> & {
22
+ readonly isAuthorized: boolean;
23
+ readonly [blueSignatureAuthorizationInput]: true;
24
+ };
25
+ /** Checks the standalone invocation without defaulting the required operator. @internal */
26
+ export declare const parseBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => BlueSignatureAuthorizationInput;
19
27
  /**
20
28
  * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
21
29
  * Morpho on the signer's behalf.
@@ -71,4 +79,6 @@ interface EncodeBlueSignatureAuthorizationParams extends ReferenceTimestampParam
71
79
  * ```
72
80
  */
73
81
  export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
82
+ /** Completes dynamic deadline defaults and builds the checked authorization. @internal */
83
+ export declare const encodeParsedBlueSignatureAuthorization: (params: BlueSignatureAuthorizationInput) => Promise<Requirement<AuthorizationRequirementSignature>>;
74
84
  export {};
@@ -1,12 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeBlueSignatureAuthorization = void 0;
3
+ exports.encodeParsedBlueSignatureAuthorization = exports.encodeBlueSignatureAuthorization = exports.parseBlueSignatureAuthorization = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
7
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
8
8
  const validate_js_1 = require("../../../helpers/validate.js");
9
9
  const index_js_1 = require("../../../types/index.js");
10
+ /** Checks the standalone invocation without defaulting the required operator. @internal */
11
+ const parseBlueSignatureAuthorization = (viemClient, params) => {
12
+ const input = {
13
+ owner: params.owner,
14
+ authorized: params.authorized,
15
+ chainId: params.chainId,
16
+ nonce: params.nonce,
17
+ isAuthorized: params.isAuthorized,
18
+ deadline: params.deadline,
19
+ now: params.now,
20
+ };
21
+ if (viemClient.chain?.id !== input.chainId) {
22
+ throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, input.chainId);
23
+ }
24
+ const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(input.chainId, "bundles.blueBundlesV1");
25
+ if (!(0, viem_1.isAddressEqual)(blueBundlesV1, input.authorized)) {
26
+ throw new index_js_1.UnsupportedAuthorizationOperatorError(input.authorized, input.chainId);
27
+ }
28
+ if (input.deadline != null) {
29
+ (0, validate_js_1.validateDeadline)(input.deadline);
30
+ }
31
+ const { isAuthorized = true } = input;
32
+ return {
33
+ ...input,
34
+ isAuthorized,
35
+ };
36
+ };
37
+ exports.parseBlueSignatureAuthorization = parseBlueSignatureAuthorization;
10
38
  /**
11
39
  * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
12
40
  * Morpho on the signer's behalf.
@@ -62,32 +90,17 @@ const index_js_1 = require("../../../types/index.js");
62
90
  * ```
63
91
  */
64
92
  const encodeBlueSignatureAuthorization = async (viemClient, params) => {
65
- const { owner, authorized, chainId, nonce, isAuthorized = true } = params;
66
- if (viemClient.chain?.id !== chainId) {
67
- throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
68
- }
69
- // Pin the authorized operator to the chain's registered BlueBundlesV1 so a direct caller
70
- // cannot sign an authorization granting an arbitrary address control over the signer's Morpho
71
- // positions. Mirrors the `getBlueAuthorizationRequirement` resolver guard and applies to grant
72
- // and revoke payloads alike: the registry is pinned per release, so revoking a rotated-out
73
- // operator is outside this helper's scope.
74
- const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.blueBundlesV1");
75
- if (!(0, viem_1.isAddressEqual)(blueBundlesV1, authorized)) {
76
- throw new index_js_1.UnsupportedAuthorizationOperatorError(authorized, chainId);
77
- }
78
- // Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
79
- // is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
80
- // `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2SignatureTransfer` and the
81
- // `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
82
- // from now and is always valid.
83
- if (params.deadline != null) {
84
- (0, validate_js_1.validateDeadline)(params.deadline);
85
- const timestamp = params.now ?? morpho_ts_1.Time.timestamp();
86
- if (params.deadline <= timestamp) {
87
- throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
88
- }
93
+ return (0, exports.encodeParsedBlueSignatureAuthorization)((0, exports.parseBlueSignatureAuthorization)(viemClient, params));
94
+ };
95
+ exports.encodeBlueSignatureAuthorization = encodeBlueSignatureAuthorization;
96
+ /** Completes dynamic deadline defaults and builds the checked authorization. @internal */
97
+ const encodeParsedBlueSignatureAuthorization = async (params) => {
98
+ const { owner, authorized, chainId, nonce, isAuthorized } = params;
99
+ const timestamp = params.now ?? morpho_ts_1.Time.timestamp();
100
+ if (params.deadline != null && params.deadline <= timestamp) {
101
+ throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
89
102
  }
90
- const deadline = params.deadline ?? (params.now ?? morpho_ts_1.Time.timestamp()) + morpho_ts_1.Time.s.from.h(2n);
103
+ const deadline = params.deadline ?? timestamp + morpho_ts_1.Time.s.from.h(2n);
91
104
  const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
92
105
  const action = {
93
106
  type: "authorization",
@@ -119,4 +132,4 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
119
132
  },
120
133
  };
121
134
  };
122
- exports.encodeBlueSignatureAuthorization = encodeBlueSignatureAuthorization;
135
+ exports.encodeParsedBlueSignatureAuthorization = encodeParsedBlueSignatureAuthorization;
@@ -1,4 +1,4 @@
1
- import type { Address } from "@morpho-org/blue-sdk";
1
+ import { type Address } from "@morpho-org/blue-sdk";
2
2
  import type { ERC20ApprovalAction, Transaction } from "../../../types/index.js";
3
3
  /** Parameters for {@link encodeErc20Approval}. */
4
4
  interface EncodeErc20ApprovalParams {
@@ -7,6 +7,14 @@ interface EncodeErc20ApprovalParams {
7
7
  amount: bigint;
8
8
  chainId: number;
9
9
  }
10
+ declare const erc20ApprovalInput: unique symbol;
11
+ /** Complete checked approval and its token-specific cap. @internal */
12
+ export type Erc20ApprovalInput = Readonly<EncodeErc20ApprovalParams> & {
13
+ readonly maxApproval: bigint;
14
+ readonly [erc20ApprovalInput]: true;
15
+ };
16
+ /** Checks the complete standalone approval before encoding. @internal */
17
+ export declare const parseErc20Approval: (params: EncodeErc20ApprovalParams) => Erc20ApprovalInput;
10
18
  /**
11
19
  * Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
12
20
  *
@@ -37,4 +45,6 @@ interface EncodeErc20ApprovalParams {
37
45
  * ```
38
46
  */
39
47
  export declare const encodeErc20Approval: (params: EncodeErc20ApprovalParams) => Transaction<ERC20ApprovalAction>;
48
+ /** Encodes the complete checked approval without repeating static checks. @internal */
49
+ export declare const encodeParsedErc20Approval: (params: Erc20ApprovalInput) => Transaction<ERC20ApprovalAction>;
40
50
  export {};
@@ -1,10 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeErc20Approval = void 0;
3
+ exports.encodeParsedErc20Approval = exports.encodeErc20Approval = exports.parseErc20Approval = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
4
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
6
  const viem_1 = require("viem");
6
7
  const tokenApproval_js_1 = require("../../../helpers/tokenApproval.js");
7
8
  const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
9
+ /** Checks the complete standalone approval before encoding. @internal */
10
+ const parseErc20Approval = (params) => {
11
+ const input = {
12
+ token: params.token,
13
+ spender: params.spender,
14
+ amount: params.amount,
15
+ chainId: params.chainId,
16
+ };
17
+ (0, validateRequirementSpender_js_1.validateRequirementSpender)({
18
+ chainId: input.chainId,
19
+ spender: input.spender,
20
+ allowed: [
21
+ "permit2",
22
+ "midnight",
23
+ "midnightBundlesV2",
24
+ "vaultExitBundlesV1",
25
+ "vaultBundlesV1",
26
+ "blueBundlesV1",
27
+ ],
28
+ });
29
+ return {
30
+ ...input,
31
+ maxApproval: (0, tokenApproval_js_1.capTokenApproval)({ ...input, amount: viem_1.maxUint256 }),
32
+ };
33
+ };
34
+ exports.parseErc20Approval = parseErc20Approval;
8
35
  /**
9
36
  * Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
10
37
  *
@@ -35,21 +62,13 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
35
62
  * ```
36
63
  */
37
64
  const encodeErc20Approval = (params) => {
38
- const { token, spender, chainId } = params;
39
- // Reject approval targets outside the SDK's registered protocol spenders.
40
- (0, validateRequirementSpender_js_1.validateRequirementSpender)({
41
- chainId,
42
- spender,
43
- allowed: [
44
- "permit2",
45
- "midnight",
46
- "midnightBundlesV2",
47
- "vaultExitBundlesV1",
48
- "vaultBundlesV1",
49
- "blueBundlesV1",
50
- ],
51
- });
52
- const amountValue = (0, tokenApproval_js_1.capTokenApproval)(params);
65
+ return (0, exports.encodeParsedErc20Approval)((0, exports.parseErc20Approval)(params));
66
+ };
67
+ exports.encodeErc20Approval = encodeErc20Approval;
68
+ /** Encodes the complete checked approval without repeating static checks. @internal */
69
+ const encodeParsedErc20Approval = (params) => {
70
+ const { token, spender, amount, maxApproval } = params;
71
+ const amountValue = blue_sdk_1.MathLib.min(amount, maxApproval);
53
72
  return (0, morpho_ts_1.deepFreeze)({
54
73
  to: token,
55
74
  data: (0, viem_1.encodeFunctionData)({
@@ -64,4 +83,4 @@ const encodeErc20Approval = (params) => {
64
83
  },
65
84
  });
66
85
  };
67
- exports.encodeErc20Approval = encodeErc20Approval;
86
+ exports.encodeParsedErc20Approval = encodeParsedErc20Approval;
@@ -1,6 +1,7 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
2
  import type { Client } from "viem";
3
- import type { Erc2612RequirementSignature, ReferenceTimestampParams, Requirement } from "../../../types/index.js";
3
+ import { type Erc2612RequirementSignature, type ReferenceTimestampParams, type Requirement } from "../../../types/index.js";
4
+ import { type ChainCheck } from "../chainCheck.js";
4
5
  /** Parameters for {@link encodeErc20Permit}. */
5
6
  interface EncodeErc20PermitParams extends ReferenceTimestampParams {
6
7
  token: Address;
@@ -13,6 +14,13 @@ interface EncodeErc20PermitParams extends ReferenceTimestampParams {
13
14
  supportDeployless?: boolean;
14
15
  deadline?: bigint;
15
16
  }
17
+ declare const erc20PermitInput: unique symbol;
18
+ /** Complete checked ERC-2612 invocation; token metadata remains an RPC concern. @internal */
19
+ export type Erc20PermitInput = Readonly<EncodeErc20PermitParams> & {
20
+ readonly [erc20PermitInput]: true;
21
+ };
22
+ /** Checks the complete direct encoder invocation before RPC. @internal */
23
+ export declare const parseErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Erc20PermitInput;
16
24
  /**
17
25
  * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
18
26
  * `amount` of `token`.
@@ -82,4 +90,9 @@ interface EncodeErc20PermitParams extends ReferenceTimestampParams {
82
90
  * ```
83
91
  */
84
92
  export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;
93
+ /** Completes dynamic time defaults and consumes the checked permit before RPC. @internal */
94
+ export declare const encodeParsedErc20Permit: ({ viemClient, chainCheck: providedChainCheck, }: {
95
+ readonly viemClient: Client;
96
+ readonly chainCheck?: ChainCheck;
97
+ }, params: Erc20PermitInput) => Promise<Requirement<Erc2612RequirementSignature>>;
85
98
  export {};