@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
@@ -511,8 +511,8 @@ export interface VaultV2Actions {
511
511
  * @returns An object whose `buildTx()` returns a deep-frozen `Transaction<VaultV2ForceRedeemAction>`
512
512
  * encoding the vault `multicall`.
513
513
  * @throws {ChainIdMismatchError} when the connected client declares another chain or none.
514
- * @throws {EmptyDeallocationsError} from `buildTx()` when `deallocations` is empty.
515
- * @throws {NonPositiveInputError} from `buildTx()` when `redeem.shares <= 0n` or any deallocation
514
+ * @throws {EmptyDeallocationsError} when creating the handle if `deallocations` is empty.
515
+ * @throws {NonPositiveInputError} when creating the handle if `redeem.shares <= 0n` or any deallocation
516
516
  * amount is non-positive.
517
517
  * @example
518
518
  * ```ts
@@ -544,6 +544,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
544
544
  private readonly chainId;
545
545
  constructor(client: MorphoClientType, vault: Address, chainId: number);
546
546
  getData(parameters?: FetchParameters): Promise<AccrualVaultV2>;
547
+ private getDataWithChainCheck;
547
548
  /**
548
549
  * Asserts that every registry contract this flow's transaction targets or names as
549
550
  * spender/authorized operator holds code, with one `eth_getCode` per distinct address
@@ -554,68 +555,36 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
554
555
  */
555
556
  private assertWriteTargets;
556
557
  /** {@inheritDoc VaultV2Actions.deposit} */
557
- deposit(params: {
558
- readonly userAddress: Address;
559
- readonly vaultData: AccrualVaultV2;
560
- readonly slippageTolerance?: bigint;
561
- readonly referralFeePct?: bigint;
562
- readonly referralFeeRecipient?: Address;
563
- readonly deadline?: bigint;
564
- } & ReferenceTimestampParams & BundlesFundingArgs): Readonly<{
558
+ deposit(params: Parameters<VaultV2Actions["deposit"]>[0]): Readonly<{
565
559
  getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
566
560
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
567
561
  }>;
568
- withdraw(params: {
569
- readonly amount: bigint;
570
- readonly userAddress: Address;
571
- readonly vaultData: AccrualVaultV2;
572
- readonly slippageTolerance?: bigint;
573
- readonly referralFeePct?: bigint;
574
- readonly referralFeeRecipient?: Address;
575
- readonly deadline?: bigint;
576
- } & ReferenceTimestampParams): Readonly<{
562
+ private parseDeposit;
563
+ private buildDeposit;
564
+ withdraw(params: Parameters<VaultV2Actions["withdraw"]>[0]): Readonly<{
577
565
  getRequirements: () => Promise<readonly (Readonly<Transaction<import("../../types/action.js").ERC20ApprovalAction>> | import("../../types/action.js").Requirement<import("../../types/action.js").Erc2612RequirementSignature, undefined>)[]>;
578
566
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2WithdrawAction>>;
579
567
  }>;
568
+ private parseWithdraw;
569
+ private buildWithdraw;
580
570
  /** {@inheritDoc VaultV2Actions.redeem} */
581
- redeem(params: {
582
- readonly shares: bigint;
583
- readonly userAddress: Address;
584
- readonly referralFeePct?: bigint;
585
- readonly referralFeeRecipient?: Address;
586
- readonly deadline?: bigint;
587
- } & ReferenceTimestampParams): Readonly<{
571
+ redeem(params: Parameters<VaultV2Actions["redeem"]>[0]): Readonly<{
588
572
  getRequirements: () => Promise<readonly (Readonly<Transaction<import("../../types/action.js").ERC20ApprovalAction>> | import("../../types/action.js").Requirement<import("../../types/action.js").Erc2612RequirementSignature, undefined>)[]>;
589
573
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2RedeemAction>>;
590
574
  }>;
575
+ private parseRedeem;
576
+ private buildRedeem;
591
577
  /** {@inheritDoc VaultV2Actions.inKindRedeem} */
592
- inKindRedeem(params: {
593
- readonly amount: bigint;
594
- readonly marketParamsList: readonly MarketParams[];
595
- readonly vaultData: AccrualVaultV2;
596
- readonly userAddress: Address;
597
- readonly adapter?: Address;
598
- readonly deadline?: bigint;
599
- } & ReferenceTimestampParams): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
578
+ inKindRedeem(params: Parameters<VaultV2Actions["inKindRedeem"]>[0]): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
579
+ private parseInKindRedeem;
580
+ private buildInKindRedeem;
600
581
  /** {@inheritDoc VaultV2Actions.forceWithdraw} */
601
- forceWithdraw(params: {
602
- readonly exitAssets: bigint;
603
- readonly vaultData: AccrualVaultV2;
604
- readonly userAddress: Address;
605
- readonly adapter?: Address;
606
- readonly deadline?: bigint;
607
- readonly slippageTolerance?: bigint;
608
- readonly minSharePriceE27?: bigint;
609
- readonly referralFeePct?: bigint;
610
- readonly referralFeeRecipient?: Address;
611
- } & ReferenceTimestampParams): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
612
- forceRedeem(params: {
613
- deallocations: readonly Deallocation[];
614
- redeem: {
615
- shares: bigint;
616
- };
617
- userAddress: Address;
618
- } & ReferenceTimestampParams): {
582
+ forceWithdraw(params: Parameters<VaultV2Actions["forceWithdraw"]>[0]): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
583
+ private parseForceWithdraw;
584
+ private buildForceWithdraw;
585
+ forceRedeem(params: Parameters<VaultV2Actions["forceRedeem"]>[0]): {
619
586
  buildTx: () => Readonly<Transaction<VaultV2ForceRedeemAction>>;
620
587
  };
588
+ private parseForceRedeem;
589
+ private buildForceRedeem;
621
590
  }
@@ -2,18 +2,25 @@ import { DEFAULT_SLIPPAGE_TOLERANCE, MarketParams, } from "@morpho-org/blue-sdk"
2
2
  import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { getChainAddress, Time, } from "@morpho-org/morpho-ts";
4
4
  import { isAddressEqual } from "viem";
5
- import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
6
- import { vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
7
- import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
5
+ import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams as parseBundlesCommon, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
6
+ import { createChainCheck, } from "../../actions/requirements/chainCheck.js";
7
+ import { buildVaultV2Deposit, } from "../../actions/vaultV2/deposit.js";
8
+ import { buildVaultV2ForceRedeem, parseVaultV2ForceRedeem, } from "../../actions/vaultV2/forceRedeem.js";
9
+ import { buildVaultV2ForceWithdraw, } from "../../actions/vaultV2/forceWithdraw.js";
10
+ import { buildVaultV2InKindRedeem, } from "../../actions/vaultV2/inKindRedeem.js";
11
+ import { buildVaultV2Redeem, } from "../../actions/vaultV2/redeem.js";
12
+ import { buildVaultV2Withdraw, } from "../../actions/vaultV2/withdraw.js";
8
13
  import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
9
14
  import { resolveTransactionMetadata } from "../../helpers/metadata.js";
10
- import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
15
+ import { parseUint256 } from "../../helpers/parse.js";
16
+ import { validateNativeVaultAsset } from "../../helpers/validate.js";
11
17
  import { ExpiredDeadlineError, NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
12
18
  import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
13
- import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
19
+ import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
20
+ import { getParsedVaultBundlesSharesRequirements, parseVaultBundlesSharesRequirements, } from "../requirements/getVaultBundlesSharesRequirements.js";
14
21
  import { getVaultV2ForceWithdrawRequirements } from "../requirements/getVaultV2ForceWithdrawRequirements.js";
15
22
  import { getVaultV2InKindRedeemRequirements } from "../requirements/getVaultV2InKindRedeemRequirements.js";
16
- import { getBundlesTokenRequirements } from "../requirements/index.js";
23
+ import { validateNativeRequirements } from "../requirements/validateNativeRequirements.js";
17
24
  import { computeVaultV2ForceWithdrawQuote } from "./forceWithdrawQuote.js";
18
25
  import { computeVaultV2InKindRedeemQuote } from "./inKindRedeemQuote.js";
19
26
  /** Binds a viem client to a Vault V2 vault's action builders. */
@@ -28,7 +35,10 @@ export class MorphoVaultV2 {
28
35
  this.chainId = chainId;
29
36
  }
30
37
  async getData(parameters) {
31
- await validateClientChainId(this.client.viemClient, this.chainId);
38
+ return this.getDataWithChainCheck(createChainCheck(this.client.viemClient, this.chainId), parameters);
39
+ }
40
+ async getDataWithChainCheck(chainCheck, parameters) {
41
+ await chainCheck();
32
42
  return fetchAccrualVaultV2(this.vault, this.client.viemClient, {
33
43
  ...parameters,
34
44
  deployless: this.client.options.supportDeployless,
@@ -42,16 +52,19 @@ export class MorphoVaultV2 {
42
52
  *
43
53
  * @param roles - Registry labels to resolve and check.
44
54
  */
45
- async assertWriteTargets(roles) {
55
+ async assertWriteTargets(roles, chainCheck) {
46
56
  const targets = [];
47
57
  for (const role of roles) {
48
58
  const address = getChainAddress(this.chainId, role);
49
59
  targets.push({ role, address });
50
60
  }
51
- await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets);
61
+ await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets, chainCheck);
52
62
  }
53
63
  /** {@inheritDoc VaultV2Actions.deposit} */
54
64
  deposit(params) {
65
+ return this.buildDeposit(this.parseDeposit(params));
66
+ }
67
+ parseDeposit(params) {
55
68
  const suppliedNow = params.now;
56
69
  const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
57
70
  const { userAddress, vaultData } = params;
@@ -65,16 +78,15 @@ export class MorphoVaultV2 {
65
78
  if (deadline <= createdAt) {
66
79
  throw new ExpiredDeadlineError(deadline, createdAt);
67
80
  }
68
- const common = normalizeBundlesCommonParams({
81
+ const common = parseBundlesCommon({
69
82
  deadline,
70
83
  referralFeePct: params.referralFeePct,
71
84
  referralFeeRecipient: params.referralFeeRecipient,
72
85
  });
73
86
  const funding = resolveBundlesFunding(params);
74
- // Reject overflow before share-price math or native-only prerequisite resolution.
75
- validateUint256Field(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
87
+ // Reject invalid funding before preparing a lazy handle.
88
+ parseUint256(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
76
89
  if (funding.value > 0n) {
77
- // The native path must target the chain's registered wrapped-native asset.
78
90
  validateNativeVaultAsset(this.chainId, vaultAsset);
79
91
  }
80
92
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
@@ -85,35 +97,69 @@ export class MorphoVaultV2 {
85
97
  slippageTolerance: params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE,
86
98
  });
87
99
  const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
100
+ if (maxSharePrice <= 0n) {
101
+ throw new NonPositiveInputError("maxSharePrice", maxSharePrice);
102
+ }
103
+ // Computed bounds also have to fit uint256.
104
+ parseUint256("maxSharePrice", maxSharePrice);
105
+ const parsed = {
106
+ vault: { chainId: this.chainId, address: this.vault, asset: vaultAsset },
107
+ userAddress,
108
+ funding,
109
+ maxSharePrice,
110
+ common,
111
+ metadata,
112
+ };
113
+ return {
114
+ suppliedNow,
115
+ parsed,
116
+ spender,
117
+ vaultAsset,
118
+ userAddress,
119
+ funding,
120
+ deadline,
121
+ };
122
+ }
123
+ buildDeposit(input) {
124
+ const { parsed, spender, vaultAsset, userAddress, funding, deadline } = input;
88
125
  let pendingRequirements;
89
126
  return Object.freeze({
90
127
  getRequirements: async (requirementOptions) => {
91
- const now = suppliedNow ?? Time.timestamp();
128
+ const now = input.suppliedNow ?? Time.timestamp();
92
129
  if (deadline <= now) {
93
130
  throw new ExpiredDeadlineError(deadline, now);
94
131
  }
132
+ const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
133
+ if (funding.value > 0n) {
134
+ // Native funding skips the token resolver's chain validation.
135
+ await validateNativeRequirements(this.client.viemClient, {
136
+ chainId: this.chainId,
137
+ chainCheck,
138
+ assertWriteTargets: () => this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck),
139
+ });
140
+ return [];
141
+ }
142
+ await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
143
+ const tokenInput = parseGetBundlesTokenRequirements(this.client.viemClient, {
144
+ token: vaultAsset,
145
+ spender,
146
+ amount: funding.assets,
147
+ owner: userAddress,
148
+ chainId: this.chainId,
149
+ deadline,
150
+ supportSignature: this.client.options.supportSignature,
151
+ supportDeployless: this.client.options.supportDeployless,
152
+ useSimplePermit: requirementOptions?.useSimplePermit,
153
+ now,
154
+ });
155
+ // Check each non-no-op invocation before sharing an in-flight state read.
156
+ if (tokenInput.amount > 0n) {
157
+ await chainCheck();
158
+ }
95
159
  if (pendingRequirements != null) {
96
160
  return await pendingRequirements;
97
161
  }
98
- // Memoize the in-flight promise so concurrent callers share one round of
99
- // allowance/nonce reads.
100
- const pending = (async () => {
101
- await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
102
- return funding.value > 0n
103
- ? []
104
- : getBundlesTokenRequirements(this.client.viemClient, {
105
- token: vaultAsset,
106
- spender,
107
- amount: funding.assets,
108
- owner: userAddress,
109
- chainId: this.chainId,
110
- deadline,
111
- supportSignature: this.client.options.supportSignature,
112
- supportDeployless: this.client.options.supportDeployless,
113
- useSimplePermit: requirementOptions?.useSimplePermit,
114
- now,
115
- });
116
- })();
162
+ const pending = getParsedBundlesTokenRequirements({ viemClient: this.client.viemClient, chainCheck }, tokenInput);
117
163
  pendingRequirements = pending;
118
164
  try {
119
165
  return await pending;
@@ -128,29 +174,14 @@ export class MorphoVaultV2 {
128
174
  buildTx: (signatures) => {
129
175
  // The pure deposit action rejects a token signature supplied alongside native funding.
130
176
  const requirementSignature = selectBundlesTokenRequirementSignature(signatures, { spender, amount: funding.assets, deadline });
131
- return vaultV2Deposit({
132
- vault: {
133
- chainId: this.chainId,
134
- address: this.vault,
135
- asset: vaultAsset,
136
- },
137
- args: {
138
- ...(funding.value > 0n
139
- ? { nativeAmount: funding.assets }
140
- : { amount: funding.assets }),
141
- maxSharePrice,
142
- userAddress,
143
- requirementSignature,
144
- referralFeePct: common.referralFeePct,
145
- referralFeeRecipient: common.referralFeeRecipient,
146
- deadline,
147
- },
148
- metadata,
149
- });
177
+ return buildVaultV2Deposit(parsed, { requirementSignature });
150
178
  },
151
179
  });
152
180
  }
153
181
  withdraw(params) {
182
+ return this.buildWithdraw(this.parseWithdraw(params));
183
+ }
184
+ parseWithdraw(params) {
154
185
  const suppliedNow = params.now;
155
186
  const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
156
187
  const { amount, userAddress, vaultData } = params;
@@ -162,13 +193,13 @@ export class MorphoVaultV2 {
162
193
  throw new NonPositiveInputError("amount", amount);
163
194
  }
164
195
  // Reject values outside the ABI range before resolving any requirements.
165
- validateUint256Field("amount", amount);
196
+ const parsedAmount = parseUint256("amount", amount);
166
197
  const createdAt = suppliedNow ?? Time.timestamp();
167
198
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
168
199
  if (deadline <= createdAt) {
169
200
  throw new ExpiredDeadlineError(deadline, createdAt);
170
201
  }
171
- const common = normalizeBundlesCommonParams({
202
+ const common = parseBundlesCommon({
172
203
  deadline,
173
204
  referralFeePct: params.referralFeePct,
174
205
  referralFeeRecipient: params.referralFeeRecipient,
@@ -183,15 +214,34 @@ export class MorphoVaultV2 {
183
214
  assets: amount,
184
215
  slippageTolerance,
185
216
  });
217
+ const parsed = {
218
+ vault: { chainId: this.chainId, address: this.vault },
219
+ args: { amount: parsedAmount, userAddress, ...common },
220
+ common,
221
+ metadata,
222
+ };
223
+ return {
224
+ suppliedNow,
225
+ parsed,
226
+ spender,
227
+ vaultData,
228
+ userAddress,
229
+ requiredShareAllowance,
230
+ deadline,
231
+ };
232
+ }
233
+ buildWithdraw(input) {
234
+ const { parsed, spender, vaultData, userAddress, requiredShareAllowance, deadline, } = input;
186
235
  return Object.freeze({
187
236
  getRequirements: async () => {
188
- const now = suppliedNow ?? Time.timestamp();
237
+ const now = input.suppliedNow ?? Time.timestamp();
189
238
  if (deadline <= now) {
190
239
  throw new ExpiredDeadlineError(deadline, now);
191
240
  }
192
- await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
241
+ const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
242
+ await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
193
243
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
194
- return getVaultBundlesSharesRequirements(this.client.viemClient, {
244
+ return getParsedVaultBundlesSharesRequirements({ viemClient: this.client.viemClient, chainCheck }, parseVaultBundlesSharesRequirements(this.client.viemClient, {
195
245
  vaultData,
196
246
  version: "vaultV2",
197
247
  owner: userAddress,
@@ -200,7 +250,7 @@ export class MorphoVaultV2 {
200
250
  deadline,
201
251
  supportSignature: this.client.options.supportSignature,
202
252
  now,
203
- });
253
+ }));
204
254
  },
205
255
  buildTx: (signatures) => {
206
256
  const permit = selectBundlesSharesPermitSignature(signatures, {
@@ -208,23 +258,15 @@ export class MorphoVaultV2 {
208
258
  amount: requiredShareAllowance,
209
259
  deadline,
210
260
  });
211
- return vaultV2Withdraw({
212
- vault: { chainId: this.chainId, address: this.vault },
213
- args: {
214
- amount,
215
- userAddress,
216
- requirementSignature: permit,
217
- referralFeePct: common.referralFeePct,
218
- referralFeeRecipient: common.referralFeeRecipient,
219
- deadline,
220
- },
221
- metadata,
222
- });
261
+ return buildVaultV2Withdraw(parsed, { requirementSignature: permit });
223
262
  },
224
263
  });
225
264
  }
226
265
  /** {@inheritDoc VaultV2Actions.redeem} */
227
266
  redeem(params) {
267
+ return this.buildRedeem(this.parseRedeem(params));
268
+ }
269
+ parseRedeem(params) {
228
270
  const suppliedNow = params.now;
229
271
  const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
230
272
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
@@ -237,21 +279,32 @@ export class MorphoVaultV2 {
237
279
  if (deadline <= createdAt) {
238
280
  throw new ExpiredDeadlineError(deadline, createdAt);
239
281
  }
240
- const common = normalizeBundlesCommonParams({
282
+ const common = parseBundlesCommon({
241
283
  deadline,
242
284
  referralFeePct: params.referralFeePct,
243
285
  referralFeeRecipient: params.referralFeeRecipient,
244
286
  });
245
287
  const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
288
+ const parsed = {
289
+ vault: { chainId: this.chainId, address: this.vault },
290
+ args: { shares: parseUint256("shares", shares), userAddress, ...common },
291
+ common,
292
+ metadata,
293
+ };
294
+ return { suppliedNow, parsed, spender, shares, userAddress, deadline };
295
+ }
296
+ buildRedeem(input) {
297
+ const { parsed, spender, shares, userAddress, deadline } = input;
246
298
  return Object.freeze({
247
299
  getRequirements: async () => {
248
- const now = suppliedNow ?? Time.timestamp();
300
+ const now = input.suppliedNow ?? Time.timestamp();
249
301
  if (deadline <= now) {
250
302
  throw new ExpiredDeadlineError(deadline, now);
251
303
  }
252
- await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
253
- return getVaultBundlesSharesRequirements(this.client.viemClient, {
254
- vaultData: await this.getData(),
304
+ const chainCheck = createChainCheck(this.client.viemClient, this.chainId);
305
+ await this.assertWriteTargets(["bundles.vaultBundlesV1"], chainCheck);
306
+ return getParsedVaultBundlesSharesRequirements({ viemClient: this.client.viemClient, chainCheck }, parseVaultBundlesSharesRequirements(this.client.viemClient, {
307
+ vaultData: await this.getDataWithChainCheck(chainCheck),
255
308
  version: "vaultV2",
256
309
  owner: userAddress,
257
310
  chainId: this.chainId,
@@ -259,7 +312,7 @@ export class MorphoVaultV2 {
259
312
  deadline,
260
313
  supportSignature: this.client.options.supportSignature,
261
314
  now,
262
- });
315
+ }));
263
316
  },
264
317
  buildTx: (signatures) => {
265
318
  const permit = selectBundlesSharesPermitSignature(signatures, {
@@ -267,26 +320,16 @@ export class MorphoVaultV2 {
267
320
  amount: shares,
268
321
  deadline,
269
322
  });
270
- return vaultV2Redeem({
271
- vault: { chainId: this.chainId, address: this.vault },
272
- args: {
273
- shares,
274
- userAddress,
275
- requirementSignature: permit,
276
- referralFeePct: common.referralFeePct,
277
- referralFeeRecipient: common.referralFeeRecipient,
278
- deadline,
279
- },
280
- metadata,
281
- });
323
+ return buildVaultV2Redeem(parsed, { requirementSignature: permit });
282
324
  },
283
325
  });
284
326
  }
285
327
  /** {@inheritDoc VaultV2Actions.inKindRedeem} */
286
328
  inKindRedeem(params) {
287
- const suppliedNow = params.now;
329
+ return this.buildInKindRedeem(this.parseInKindRedeem(params));
330
+ }
331
+ parseInKindRedeem({ now: suppliedNow, amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }) {
288
332
  const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
289
- const { amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, } = params;
290
333
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
291
334
  if (!isAddressEqual(vaultData.address, this.vault)) {
292
335
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
@@ -295,12 +338,36 @@ export class MorphoVaultV2 {
295
338
  amount,
296
339
  marketParamsList,
297
340
  vaultData,
298
- deadline: deadlineOverride,
299
341
  adapter: adapterOverride,
342
+ deadline: deadlineOverride,
300
343
  now: suppliedNow ?? Time.timestamp(),
301
344
  vault: this.vault,
302
345
  });
303
346
  const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
347
+ const parsed = {
348
+ vault: { chainId: this.chainId, address: this.vault },
349
+ args: {
350
+ adapter,
351
+ amount,
352
+ marketParamsList: marketParamsListSnapshot,
353
+ userAddress,
354
+ deadline,
355
+ },
356
+ metadata,
357
+ };
358
+ return {
359
+ suppliedNow,
360
+ parsed,
361
+ deadline,
362
+ userAddress,
363
+ vaultData,
364
+ vaultExitBundlesV1,
365
+ peak,
366
+ requiredShareAllowance,
367
+ };
368
+ }
369
+ buildInKindRedeem(input) {
370
+ const { parsed, deadline, userAddress, vaultData, vaultExitBundlesV1, peak, requiredShareAllowance, } = input;
304
371
  return {
305
372
  getRequirements: () => getVaultV2InKindRedeemRequirements(this.client.viemClient, {
306
373
  vaultData,
@@ -311,7 +378,7 @@ export class MorphoVaultV2 {
311
378
  requiredShareAllowance,
312
379
  supportSignature: this.client.options.supportSignature,
313
380
  peak,
314
- now: suppliedNow,
381
+ now: input.suppliedNow,
315
382
  }),
316
383
  buildTx: (signatures) => {
317
384
  const permit = selectBundlesSharesPermitSignature(signatures, {
@@ -319,31 +386,23 @@ export class MorphoVaultV2 {
319
386
  amount: requiredShareAllowance,
320
387
  deadline,
321
388
  });
322
- return vaultV2InKindRedeem({
323
- vault: { chainId: this.chainId, address: this.vault },
324
- args: {
325
- adapter,
326
- amount,
327
- marketParamsList: marketParamsListSnapshot,
328
- userAddress,
329
- deadline,
330
- requirementSignature: permit,
331
- },
332
- metadata,
389
+ return buildVaultV2InKindRedeem(parsed, {
390
+ requirementSignature: permit,
333
391
  });
334
392
  },
335
393
  };
336
394
  }
337
395
  /** {@inheritDoc VaultV2Actions.forceWithdraw} */
338
396
  forceWithdraw(params) {
339
- const suppliedNow = params.now;
397
+ return this.buildForceWithdraw(this.parseForceWithdraw(params));
398
+ }
399
+ parseForceWithdraw({ now: suppliedNow, exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, }) {
340
400
  const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
341
- const { exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, } = params;
342
401
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
343
402
  if (!isAddressEqual(vaultData.address, this.vault)) {
344
403
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
345
404
  }
346
- const { deadline, adapter, minSharePriceE27, requiredShareAllowance } = computeVaultV2ForceWithdrawQuote({
405
+ const { deadline, adapter, minSharePriceE27, requiredShareAllowance, referral, } = computeVaultV2ForceWithdrawQuote({
347
406
  exitAssets,
348
407
  vaultData,
349
408
  userAddress,
@@ -357,6 +416,30 @@ export class MorphoVaultV2 {
357
416
  vault: this.vault,
358
417
  });
359
418
  const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
419
+ const parsed = {
420
+ vault: { chainId: this.chainId, address: this.vault },
421
+ args: {
422
+ adapter,
423
+ exitAssets,
424
+ minSharePriceE27,
425
+ userAddress,
426
+ deadline,
427
+ },
428
+ referral,
429
+ metadata,
430
+ };
431
+ return {
432
+ suppliedNow,
433
+ parsed,
434
+ deadline,
435
+ userAddress,
436
+ vaultData,
437
+ vaultExitBundlesV1,
438
+ requiredShareAllowance,
439
+ };
440
+ }
441
+ buildForceWithdraw(input) {
442
+ const { parsed, deadline, userAddress, vaultData, vaultExitBundlesV1, requiredShareAllowance, } = input;
360
443
  return {
361
444
  getRequirements: () => getVaultV2ForceWithdrawRequirements(this.client.viemClient, {
362
445
  vaultData,
@@ -366,7 +449,7 @@ export class MorphoVaultV2 {
366
449
  deadline,
367
450
  requiredShareAllowance,
368
451
  supportSignature: this.client.options.supportSignature,
369
- now: suppliedNow,
452
+ now: input.suppliedNow,
370
453
  }),
371
454
  buildTx: (signatures) => {
372
455
  const permit = selectBundlesSharesPermitSignature(signatures, {
@@ -374,26 +457,17 @@ export class MorphoVaultV2 {
374
457
  amount: requiredShareAllowance,
375
458
  deadline,
376
459
  });
377
- return vaultV2ForceWithdraw({
378
- vault: { chainId: this.chainId, address: this.vault },
379
- args: {
380
- adapter,
381
- exitAssets,
382
- minSharePriceE27,
383
- userAddress,
384
- deadline,
385
- referralFeePct,
386
- referralFeeRecipient,
387
- requirementSignature: permit,
388
- },
389
- metadata,
460
+ return buildVaultV2ForceWithdraw(parsed, {
461
+ requirementSignature: permit,
390
462
  });
391
463
  },
392
464
  };
393
465
  }
394
466
  forceRedeem(params) {
395
- const metadata = resolveTransactionMetadata(this.client.options.metadata, params.now);
396
- const { deallocations, redeem, userAddress } = params;
467
+ return this.buildForceRedeem(this.parseForceRedeem(params));
468
+ }
469
+ parseForceRedeem({ now: suppliedNow, deallocations, redeem, userAddress, }) {
470
+ const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
397
471
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
398
472
  const shares = redeem.shares;
399
473
  const deallocationsSnapshot = deallocations.map(({ adapter, marketParams, amount }) => ({
@@ -401,16 +475,18 @@ export class MorphoVaultV2 {
401
475
  amount,
402
476
  ...(marketParams && { marketParams: new MarketParams(marketParams) }),
403
477
  }));
404
- return {
405
- buildTx: () => vaultV2ForceRedeem({
406
- vault: { address: this.vault },
407
- args: {
408
- deallocations: deallocationsSnapshot,
409
- redeem: { shares, recipient: userAddress },
410
- onBehalf: userAddress,
411
- },
412
- metadata,
413
- }),
414
- };
478
+ const parsed = parseVaultV2ForceRedeem({
479
+ vault: { address: this.vault },
480
+ args: {
481
+ deallocations: deallocationsSnapshot,
482
+ redeem: { shares, recipient: userAddress },
483
+ onBehalf: userAddress,
484
+ },
485
+ metadata,
486
+ });
487
+ return parsed;
488
+ }
489
+ buildForceRedeem(parsed) {
490
+ return { buildTx: () => buildVaultV2ForceRedeem(parsed) };
415
491
  }
416
492
  }