@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,10 +1,10 @@
1
1
  import { getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData, isAddressEqual } from "viem";
3
3
  import { vaultBundlesV1Abi } from "../../abis.js";
4
- import { validateUint256Field } from "../../helpers/validate.js";
4
+ import { parseUint256 } from "../../helpers/parse.js";
5
5
  import { validatePositiveInput } from "../../helpers/validatePositiveInput.js";
6
6
  import { AmountAndSharesExclusiveError, SameVaultMigrationError, VaultAssetMismatchError, } from "../../types/index.js";
7
- import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
7
+ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getParsedBundlesSharesPermit, normalizeBundlesCommonParams as parseBundlesCommon, } from "../bundles/common.js";
8
8
  /**
9
9
  * Encodes an assets-or-shares Vault V1 to Vault V2 migration through VaultBundlesV1.
10
10
  *
@@ -74,7 +74,9 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
74
74
  * }
75
75
  * ```
76
76
  */
77
- export const vaultV1MigrateToV2 = (params) => {
77
+ export const vaultV1MigrateToV2 = (params) => buildVaultV1MigrateToV2(parseVaultV1MigrateToV2(params));
78
+ /** Parses standalone migration fields in their original validation order. @internal */
79
+ export const parseVaultV1MigrateToV2 = (params) => {
78
80
  if (!isAddressEqual(params.vault.asset, params.args.targetAsset)) {
79
81
  throw new VaultAssetMismatchError(params.vault.asset, params.args.targetAsset);
80
82
  }
@@ -86,18 +88,52 @@ export const vaultV1MigrateToV2 = (params) => {
86
88
  if ((assets == null) === (shares == null)) {
87
89
  throw new AmountAndSharesExclusiveError();
88
90
  }
89
- const selectedAmount = assets ?? shares ?? 0n;
91
+ const selected = assets ?? shares ?? 0n;
90
92
  const amountField = assets == null ? "shares" : "assets";
91
93
  // Validation only; rejects non-positive migration amounts.
92
- validatePositiveInput(amountField, selectedAmount);
93
- // Validation only; rejects non-positive share-price bounds.
94
+ validatePositiveInput(amountField, selected);
95
+ // Validation only; rejects non-positive share-price bounds before either ABI bound.
94
96
  validatePositiveInput("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2);
95
- // Reject ABI overflow with SDK errors before calldata encoding.
96
- validateUint256Field(amountField, selectedAmount);
97
- validateUint256Field("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2);
98
- const common = normalizeBundlesCommonParams(params.args);
97
+ // ABI bounds follow both positive-only guards, preserving first-error order.
98
+ parseUint256(assets == null ? "shares" : "assets", selected);
99
+ const bounds = {
100
+ assets,
101
+ shares,
102
+ maxSharePriceVaultV2: parseUint256("maxSharePriceVaultV2", params.args.maxSharePriceVaultV2),
103
+ };
104
+ const common = parseBundlesCommon(params.args);
105
+ const input = {
106
+ vault: {
107
+ chainId: params.vault.chainId,
108
+ address: params.vault.address,
109
+ asset: params.vault.asset,
110
+ },
111
+ args: {
112
+ targetVault: params.args.targetVault,
113
+ targetAsset: params.args.targetAsset,
114
+ userAddress: params.args.userAddress,
115
+ ...common,
116
+ },
117
+ bounds,
118
+ common,
119
+ metadata: params.metadata,
120
+ requirementSignature: params.args.requirementSignature,
121
+ };
122
+ return input;
123
+ };
124
+ /** Encodes parsed migration inputs and validates a fresh share permit. @internal */
125
+ export const buildVaultV1MigrateToV2 = (parsed, signatures = parsed) => {
126
+ const { common, bounds: { assets, shares }, } = parsed;
127
+ const params = {
128
+ ...parsed,
129
+ args: {
130
+ ...parsed.args,
131
+ ...parsed.bounds,
132
+ requirementSignature: signatures.requirementSignature,
133
+ },
134
+ };
99
135
  const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
100
- const sharesPermit = getBundlesSharesPermit({
136
+ const sharesPermit = getParsedBundlesSharesPermit({
101
137
  vault: params.vault.address,
102
138
  deadline: common.deadline,
103
139
  owner: params.args.userAddress,
@@ -1,5 +1,6 @@
1
1
  import { type Address } from "viem";
2
2
  import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV1RedeemAction } from "../../types/index.js";
3
+ import { normalizeBundlesCommonParams as parseBundlesCommon } from "../bundles/common.js";
3
4
  /** Parameters for {@link vaultV1Redeem}. */
4
5
  export interface VaultV1RedeemParams {
5
6
  readonly vault: {
@@ -29,6 +30,19 @@ export interface VaultV1RedeemParams {
29
30
  /** Optional analytics metadata appended to the transaction calldata. */
30
31
  readonly metadata?: Metadata;
31
32
  }
33
+ declare const parsedVaultV1Redeem: unique symbol;
34
+ /** Validated redeem inputs, independent of signatures. @internal */
35
+ export type VaultV1RedeemInput = {
36
+ readonly vault: Readonly<VaultV1RedeemParams["vault"]>;
37
+ readonly args: Omit<VaultV1RedeemParams["args"], "requirementSignature" | "shares" | "deadline"> & {
38
+ readonly shares: bigint;
39
+ readonly deadline: ReturnType<typeof parseBundlesCommon>["deadline"];
40
+ };
41
+ readonly common: ReturnType<typeof parseBundlesCommon>;
42
+ readonly metadata?: Metadata;
43
+ readonly requirementSignature?: VaultV1RedeemParams["args"]["requirementSignature"];
44
+ readonly [parsedVaultV1Redeem]: true;
45
+ };
32
46
  /**
33
47
  * Encodes an exact-shares Vault V1 redemption through VaultBundlesV1.
34
48
  *
@@ -71,3 +85,8 @@ export interface VaultV1RedeemParams {
71
85
  * ```
72
86
  */
73
87
  export declare const vaultV1Redeem: (params: VaultV1RedeemParams) => Readonly<Transaction<VaultV1RedeemAction>>;
88
+ /** Parses the amount and common fields in standalone order. @internal */
89
+ export declare const parseVaultV1Redeem: (params: VaultV1RedeemParams) => VaultV1RedeemInput;
90
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
91
+ export declare const buildVaultV1Redeem: (parsed: VaultV1RedeemInput, signatures?: Pick<VaultV1RedeemParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV1RedeemAction>>;
92
+ export {};
@@ -1,9 +1,9 @@
1
1
  import { getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { vaultBundlesV1Abi } from "../../abis.js";
4
- import { validateUint256Field } from "../../helpers/validate.js";
4
+ import { parseUint256 } from "../../helpers/parse.js";
5
5
  import { NonPositiveInputError, } from "../../types/index.js";
6
- import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
6
+ import { finalizeVaultBundlesV1Transaction, getParsedBundlesSharesPermit, normalizeBundlesCommonParams as parseBundlesCommon, } from "../bundles/common.js";
7
7
  /**
8
8
  * Encodes an exact-shares Vault V1 redemption through VaultBundlesV1.
9
9
  *
@@ -45,15 +45,34 @@ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBun
45
45
  * // tx.action.type === "vaultV1Redeem"
46
46
  * ```
47
47
  */
48
- export const vaultV1Redeem = (params) => {
48
+ export const vaultV1Redeem = (params) => buildVaultV1Redeem(parseVaultV1Redeem(params));
49
+ /** Parses the amount and common fields in standalone order. @internal */
50
+ export const parseVaultV1Redeem = (params) => {
49
51
  if (params.args.shares <= 0n) {
50
52
  throw new NonPositiveInputError("shares", params.args.shares);
51
53
  }
52
- // Reject ABI overflow with SDK errors before calldata encoding.
53
- validateUint256Field("shares", params.args.shares);
54
- const common = normalizeBundlesCommonParams(params.args);
54
+ const shares = parseUint256("shares", params.args.shares);
55
+ const common = parseBundlesCommon(params.args);
56
+ return {
57
+ vault: { chainId: params.vault.chainId, address: params.vault.address },
58
+ args: { shares, userAddress: params.args.userAddress, ...common },
59
+ common,
60
+ metadata: params.metadata,
61
+ requirementSignature: params.args.requirementSignature,
62
+ };
63
+ };
64
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
65
+ export const buildVaultV1Redeem = (parsed, signatures = parsed) => {
66
+ const { common } = parsed;
67
+ const params = {
68
+ ...parsed,
69
+ args: {
70
+ ...parsed.args,
71
+ requirementSignature: signatures.requirementSignature,
72
+ },
73
+ };
55
74
  const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
56
- const sharesPermit = getBundlesSharesPermit({
75
+ const sharesPermit = getParsedBundlesSharesPermit({
57
76
  vault: params.vault.address,
58
77
  deadline: common.deadline,
59
78
  owner: params.args.userAddress,
@@ -1,5 +1,6 @@
1
1
  import { type Address } from "viem";
2
2
  import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV1WithdrawAction } from "../../types/index.js";
3
+ import { normalizeBundlesCommonParams as parseBundlesCommon } from "../bundles/common.js";
3
4
  /** Parameters for {@link vaultV1Withdraw}. */
4
5
  export interface VaultV1WithdrawParams {
5
6
  readonly vault: {
@@ -18,6 +19,19 @@ export interface VaultV1WithdrawParams {
18
19
  };
19
20
  readonly metadata?: Metadata;
20
21
  }
22
+ declare const parsedVaultV1Withdraw: unique symbol;
23
+ /** Validated withdraw inputs, independent of signatures. @internal */
24
+ export type VaultV1WithdrawInput = {
25
+ readonly vault: Readonly<VaultV1WithdrawParams["vault"]>;
26
+ readonly args: Omit<VaultV1WithdrawParams["args"], "requirementSignature" | "amount" | "deadline"> & {
27
+ readonly amount: bigint;
28
+ readonly deadline: ReturnType<typeof parseBundlesCommon>["deadline"];
29
+ };
30
+ readonly common: ReturnType<typeof parseBundlesCommon>;
31
+ readonly metadata?: Metadata;
32
+ readonly requirementSignature?: VaultV1WithdrawParams["args"]["requirementSignature"];
33
+ readonly [parsedVaultV1Withdraw]: true;
34
+ };
21
35
  /**
22
36
  * Encodes an exact-assets Vault V1 withdrawal through VaultBundlesV1.
23
37
  *
@@ -71,3 +85,8 @@ export interface VaultV1WithdrawParams {
71
85
  * ```
72
86
  */
73
87
  export declare const vaultV1Withdraw: (params: VaultV1WithdrawParams) => Readonly<Transaction<VaultV1WithdrawAction>>;
88
+ /** Parses the amount and common fields in standalone order. @internal */
89
+ export declare const parseVaultV1Withdraw: (params: VaultV1WithdrawParams) => VaultV1WithdrawInput;
90
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
91
+ export declare const buildVaultV1Withdraw: (parsed: VaultV1WithdrawInput, signatures?: Pick<VaultV1WithdrawParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV1WithdrawAction>>;
92
+ export {};
@@ -1,9 +1,9 @@
1
1
  import { getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { vaultBundlesV1Abi } from "../../abis.js";
4
- import { validateUint256Field } from "../../helpers/validate.js";
4
+ import { parseUint256 } from "../../helpers/parse.js";
5
5
  import { NonPositiveInputError, } from "../../types/index.js";
6
- import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
6
+ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getParsedBundlesSharesPermit, normalizeBundlesCommonParams as parseBundlesCommon, } from "../bundles/common.js";
7
7
  /**
8
8
  * Encodes an exact-assets Vault V1 withdrawal through VaultBundlesV1.
9
9
  *
@@ -56,15 +56,34 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
56
56
  * }
57
57
  * ```
58
58
  */
59
- export const vaultV1Withdraw = (params) => {
59
+ export const vaultV1Withdraw = (params) => buildVaultV1Withdraw(parseVaultV1Withdraw(params));
60
+ /** Parses the amount and common fields in standalone order. @internal */
61
+ export const parseVaultV1Withdraw = (params) => {
60
62
  if (params.args.amount <= 0n) {
61
63
  throw new NonPositiveInputError("amount", params.args.amount);
62
64
  }
63
- // Validate the ABI bound before encoding to preserve the SDK's typed errors.
64
- validateUint256Field("amount", params.args.amount);
65
- const common = normalizeBundlesCommonParams(params.args);
65
+ const amount = parseUint256("amount", params.args.amount);
66
+ const common = parseBundlesCommon(params.args);
67
+ return {
68
+ vault: { chainId: params.vault.chainId, address: params.vault.address },
69
+ args: { amount, userAddress: params.args.userAddress, ...common },
70
+ common,
71
+ metadata: params.metadata,
72
+ requirementSignature: params.args.requirementSignature,
73
+ };
74
+ };
75
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
76
+ export const buildVaultV1Withdraw = (parsed, signatures = parsed) => {
77
+ const { common } = parsed;
78
+ const params = {
79
+ ...parsed,
80
+ args: {
81
+ ...parsed.args,
82
+ requirementSignature: signatures.requirementSignature,
83
+ },
84
+ };
66
85
  const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
67
- const sharesPermit = getBundlesSharesPermit({
86
+ const sharesPermit = getParsedBundlesSharesPermit({
68
87
  vault: params.vault.address,
69
88
  deadline: common.deadline,
70
89
  owner: params.args.userAddress,
@@ -1,5 +1,6 @@
1
1
  import { type Address } from "viem";
2
2
  import { type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Metadata, type Transaction, type VaultV2DepositAction } from "../../types/index.js";
3
+ import { normalizeBundlesCommonParams } from "../bundles/common.js";
3
4
  /** Parameters for {@link vaultV2Deposit}. */
4
5
  export interface VaultV2DepositParams {
5
6
  readonly vault: {
@@ -18,6 +19,21 @@ export interface VaultV2DepositParams {
18
19
  };
19
20
  readonly metadata?: Metadata;
20
21
  }
22
+ declare const vaultV2DepositInput: unique symbol;
23
+ /** Validated deposit values without a carried signature. @internal */
24
+ export interface VaultV2DepositInput {
25
+ readonly vault: Readonly<VaultV2DepositParams["vault"]>;
26
+ readonly userAddress: Address;
27
+ readonly funding: {
28
+ readonly assets: bigint;
29
+ readonly value: bigint;
30
+ };
31
+ readonly maxSharePrice: bigint;
32
+ readonly common: ReturnType<typeof normalizeBundlesCommonParams>;
33
+ readonly metadata?: Metadata;
34
+ readonly requirementSignature?: VaultV2DepositParams["args"]["requirementSignature"];
35
+ readonly [vaultV2DepositInput]: true;
36
+ }
21
37
  /**
22
38
  * Encodes a Vault V2 deposit through the registered VaultBundlesV1 contract.
23
39
  *
@@ -85,3 +101,8 @@ export interface VaultV2DepositParams {
85
101
  * ```
86
102
  */
87
103
  export declare const vaultV2Deposit: (params: VaultV2DepositParams) => Readonly<Transaction<VaultV2DepositAction>>;
104
+ /** Constructs the complete standalone deposit from raw funding and bounds. @internal */
105
+ export declare const parseVaultV2DepositInput: (params: VaultV2DepositParams) => VaultV2DepositInput;
106
+ /** Encodes parsed funding and binds the supplied token signature. @internal */
107
+ export declare const buildVaultV2Deposit: (parsed: VaultV2DepositInput, signatures?: Pick<VaultV2DepositParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV2DepositAction>>;
108
+ export {};
@@ -1,7 +1,8 @@
1
1
  import { getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { vaultBundlesV1Abi } from "../../abis.js";
4
- import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
4
+ import { parseUint256 } from "../../helpers/parse.js";
5
+ import { validateNativeVaultAsset } from "../../helpers/validate.js";
5
6
  import { NonPositiveInputError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
6
7
  import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBundlesTokenPermit, normalizeBundlesCommonParams, resolveBundlesFunding, } from "../bundles/common.js";
7
8
  /**
@@ -70,22 +71,55 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
70
71
  * }
71
72
  * ```
72
73
  */
73
- export const vaultV2Deposit = (params) => {
74
+ export const vaultV2Deposit = (params) => buildVaultV2Deposit(parseVaultV2DepositInput(params));
75
+ /** Constructs the complete standalone deposit from raw funding and bounds. @internal */
76
+ export const parseVaultV2DepositInput = (params) => {
74
77
  const funding = resolveBundlesFunding(params.args);
75
78
  if (params.args.maxSharePrice <= 0n) {
76
79
  throw new NonPositiveInputError("maxSharePrice", params.args.maxSharePrice);
77
80
  }
78
- // Reject ABI overflow with SDK errors before calldata encoding.
79
- validateUint256Field(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
80
- validateUint256Field("maxSharePrice", params.args.maxSharePrice);
81
+ // Check ABI bounds after both positive-only checks, preserving first-error order.
82
+ parseUint256(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
83
+ const maxSharePrice = parseUint256("maxSharePrice", params.args.maxSharePrice);
81
84
  if (funding.value > 0n) {
82
- // Reject native funding unless the vault accepts the chain's wrapped-native asset.
85
+ // Native deposits must wrap the vault's underlying asset.
83
86
  validateNativeVaultAsset(params.vault.chainId, params.vault.asset);
84
- if (params.args.requirementSignature != null) {
85
- throw new UnexpectedRequirementSignatureError(params.args.requirementSignature.action.type);
86
- }
87
+ }
88
+ // Standalone native/signature exclusivity precedes common-field validation.
89
+ if (funding.value > 0n && params.args.requirementSignature != null) {
90
+ throw new UnexpectedRequirementSignatureError(params.args.requirementSignature.action.type);
87
91
  }
88
92
  const common = normalizeBundlesCommonParams(params.args);
93
+ return {
94
+ vault: {
95
+ chainId: params.vault.chainId,
96
+ address: params.vault.address,
97
+ asset: params.vault.asset,
98
+ },
99
+ userAddress: params.args.userAddress,
100
+ funding,
101
+ maxSharePrice,
102
+ common,
103
+ metadata: params.metadata,
104
+ requirementSignature: params.args.requirementSignature,
105
+ };
106
+ };
107
+ /** Encodes parsed funding and binds the supplied token signature. @internal */
108
+ export const buildVaultV2Deposit = (parsed, signatures = parsed) => {
109
+ const { funding, common, maxSharePrice, vault, userAddress, metadata } = parsed;
110
+ const params = {
111
+ vault,
112
+ args: {
113
+ maxSharePrice,
114
+ userAddress,
115
+ requirementSignature: signatures.requirementSignature,
116
+ },
117
+ metadata,
118
+ };
119
+ // Signatures are supplied independently of parsed funding.
120
+ if (funding.value > 0n && signatures.requirementSignature != null) {
121
+ throw new UnexpectedRequirementSignatureError(signatures.requirementSignature.action.type);
122
+ }
89
123
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
90
124
  const netAssets = funding.assets - referralFeeAssets;
91
125
  const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
@@ -1,4 +1,4 @@
1
- import { type Address } from "viem";
1
+ import { type Address, type Hex } from "viem";
2
2
  import { type Deallocation, type Metadata, type Transaction, type VaultV2ForceRedeemAction } from "../../types/index.js";
3
3
  /** Parameters for {@link vaultV2ForceRedeem}. */
4
4
  export interface VaultV2ForceRedeemParams {
@@ -15,6 +15,19 @@ export interface VaultV2ForceRedeemParams {
15
15
  };
16
16
  metadata?: Metadata;
17
17
  }
18
+ declare const vaultV2ForceRedeemInput: unique symbol;
19
+ /** Owned force-redeem inputs whose positive-only checks have completed. @internal */
20
+ export type VaultV2ForceRedeemInput = {
21
+ readonly vault: Readonly<VaultV2ForceRedeemParams["vault"]>;
22
+ readonly args: {
23
+ readonly deallocations: readonly Readonly<Deallocation>[];
24
+ readonly redeem: Readonly<VaultV2ForceRedeemParams["args"]["redeem"]>;
25
+ readonly onBehalf: Address;
26
+ };
27
+ readonly deallocationCalls: readonly Hex[];
28
+ readonly metadata?: Metadata;
29
+ readonly [vaultV2ForceRedeemInput]: true;
30
+ };
18
31
  /**
19
32
  * Prepares a force-redeem transaction for a VaultV2 contract via the vault's native `multicall`.
20
33
  *
@@ -60,4 +73,9 @@ export interface VaultV2ForceRedeemParams {
60
73
  * // tx satisfies Readonly<Transaction<VaultV2ForceRedeemAction>>
61
74
  * ```
62
75
  */
63
- export declare const vaultV2ForceRedeem: ({ vault: { address: vaultAddress }, args: { deallocations, redeem, onBehalf }, metadata, }: VaultV2ForceRedeemParams) => Readonly<Transaction<VaultV2ForceRedeemAction>>;
76
+ export declare const vaultV2ForceRedeem: (params: VaultV2ForceRedeemParams) => Readonly<Transaction<VaultV2ForceRedeemAction>>;
77
+ /** Preserves empty-list, shares, then per-deallocation validation and ABI order. @internal */
78
+ export declare const parseVaultV2ForceRedeem: (params: VaultV2ForceRedeemParams) => VaultV2ForceRedeemInput;
79
+ /** Encodes owned force-redeem inputs without rechecking them. @internal */
80
+ export declare const buildVaultV2ForceRedeem: ({ vault: { address: vaultAddress }, args: { deallocations, redeem, onBehalf }, deallocationCalls, metadata, }: VaultV2ForceRedeemInput) => Readonly<Transaction<VaultV2ForceRedeemAction>>;
81
+ export {};
@@ -49,17 +49,46 @@ import { EmptyDeallocationsError, NonPositiveInputError, } from "../../types/ind
49
49
  * // tx satisfies Readonly<Transaction<VaultV2ForceRedeemAction>>
50
50
  * ```
51
51
  */
52
- export const vaultV2ForceRedeem = ({ vault: { address: vaultAddress }, args: { deallocations, redeem, onBehalf }, metadata, }) => {
52
+ export const vaultV2ForceRedeem = (params) => buildVaultV2ForceRedeem(parseVaultV2ForceRedeem(params));
53
+ /** Preserves empty-list, shares, then per-deallocation validation and ABI order. @internal */
54
+ export const parseVaultV2ForceRedeem = (params) => {
55
+ const { vault, args: { deallocations, redeem, onBehalf }, metadata, } = params;
53
56
  if (deallocations.length === 0) {
54
- throw new EmptyDeallocationsError(vaultAddress);
57
+ throw new EmptyDeallocationsError(vault.address);
55
58
  }
56
59
  if (redeem.shares <= 0n) {
57
60
  throw new NonPositiveInputError("redeem.shares", redeem.shares);
58
61
  }
59
- const calls = [];
60
- for (const deallocation of deallocations) {
61
- calls.push(encodeForceDeallocateCall(deallocation, onBehalf));
62
- }
62
+ // Encode the same owned entry used in metadata, even for caller-owned getters.
63
+ // Preserve the original per-deallocation validation and ABI error order.
64
+ const deallocationCalls = [];
65
+ const deallocationSnapshots = Object.freeze(
66
+ // Visit sparse entries too: a missing deallocation must fail before encoding a transaction.
67
+ Array.from(deallocations, ({ adapter, marketParams, amount }) => {
68
+ const snapshot = Object.freeze({
69
+ adapter,
70
+ amount,
71
+ ...(marketParams && {
72
+ marketParams: Object.freeze({ ...marketParams }),
73
+ }),
74
+ });
75
+ deallocationCalls.push(encodeForceDeallocateCall(snapshot, onBehalf));
76
+ return snapshot;
77
+ }));
78
+ return {
79
+ vault: { address: vault.address },
80
+ args: {
81
+ deallocations: deallocationSnapshots,
82
+ redeem: { shares: redeem.shares, recipient: redeem.recipient },
83
+ onBehalf,
84
+ },
85
+ deallocationCalls: Object.freeze(deallocationCalls),
86
+ metadata,
87
+ };
88
+ };
89
+ /** Encodes owned force-redeem inputs without rechecking them. @internal */
90
+ export const buildVaultV2ForceRedeem = ({ vault: { address: vaultAddress }, args: { deallocations, redeem, onBehalf }, deallocationCalls, metadata, }) => {
91
+ const calls = [...deallocationCalls];
63
92
  calls.push(encodeFunctionData({
64
93
  abi: vaultV2Abi,
65
94
  functionName: "redeem",
@@ -18,6 +18,23 @@ export interface VaultV2ForceWithdrawParams {
18
18
  };
19
19
  readonly metadata?: Metadata;
20
20
  }
21
+ declare const vaultV2ForceWithdrawInput: unique symbol;
22
+ /** Checked force-withdraw fields, independent of snapshot and clock checks. @internal */
23
+ export type VaultV2ForceWithdrawInput = {
24
+ readonly vault: Readonly<VaultV2ForceWithdrawParams["vault"]>;
25
+ readonly args: Omit<VaultV2ForceWithdrawParams["args"], "requirementSignature" | "exitAssets" | "minSharePriceE27" | "deadline" | "referralFeePct" | "referralFeeRecipient"> & {
26
+ readonly exitAssets: bigint;
27
+ readonly minSharePriceE27: bigint;
28
+ readonly deadline: bigint;
29
+ };
30
+ readonly referral: {
31
+ readonly referralFeePct: bigint;
32
+ readonly referralFeeRecipient: Address;
33
+ };
34
+ readonly metadata?: Metadata;
35
+ readonly requirementSignature?: VaultV2ForceWithdrawParams["args"]["requirementSignature"];
36
+ readonly [vaultV2ForceWithdrawInput]: true;
37
+ };
21
38
  /**
22
39
  * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
23
40
  *
@@ -86,4 +103,9 @@ export interface VaultV2ForceWithdrawParams {
86
103
  * }
87
104
  * ```
88
105
  */
89
- export declare const vaultV2ForceWithdraw: ({ vault, args, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
106
+ export declare const vaultV2ForceWithdraw: (params: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
107
+ /** Runs standalone force-withdraw stages in their established order. @internal */
108
+ export declare const parseVaultV2ForceWithdraw: (params: VaultV2ForceWithdrawParams) => VaultV2ForceWithdrawInput;
109
+ /** Encodes parsed fields and binds a fresh share permit. @internal */
110
+ export declare const buildVaultV2ForceWithdraw: (parsed: VaultV2ForceWithdrawInput, signatures?: Pick<VaultV2ForceWithdrawParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
111
+ export {};
@@ -2,9 +2,9 @@ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { vaultExitBundlesV1Abi } from "../../abis.js";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
5
- import { validateDeadline, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
5
+ import { parseDeadline, parseReferralFee, parseUint256, } from "../../helpers/parse.js";
6
6
  import { NonPositiveInputError, } from "../../types/index.js";
7
- import { getBundlesSharesPermit } from "../bundles/common.js";
7
+ import { getParsedBundlesSharesPermit } from "../bundles/common.js";
8
8
  /**
9
9
  * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
10
10
  *
@@ -73,19 +73,39 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
73
73
  * }
74
74
  * ```
75
75
  */
76
- export const vaultV2ForceWithdraw = ({ vault, args, metadata, }) => {
77
- if (args.exitAssets <= 0n) {
78
- throw new NonPositiveInputError("exitAssets", args.exitAssets);
76
+ export const vaultV2ForceWithdraw = (params) => buildVaultV2ForceWithdraw(parseVaultV2ForceWithdraw(params));
77
+ /** Runs standalone force-withdraw stages in their established order. @internal */
78
+ export const parseVaultV2ForceWithdraw = (params) => {
79
+ if (params.args.exitAssets <= 0n) {
80
+ throw new NonPositiveInputError("exitAssets", params.args.exitAssets);
79
81
  }
80
- validateUint256Field("exitAssets", args.exitAssets);
81
- validateDeadline(args.deadline);
82
- // `0n` stays valid — it is the intentional "no on-chain bound" opt-out — but a value the uint256
83
- // slot cannot hold must fail with a dedicated error instead of viem's `IntegerOutOfRangeError`.
84
- // The entity never emits these (it forbids a non-positive override); this guards direct callers.
85
- validateUint256Field("minSharePriceE27", args.minSharePriceE27);
86
- const { referralFeePct, referralFeeRecipient } = validateReferralFee(args);
82
+ const exitAssets = parseUint256("exitAssets", params.args.exitAssets);
83
+ const deadline = parseDeadline(params.args.deadline);
84
+ const minSharePriceE27 = parseUint256("minSharePriceE27", params.args.minSharePriceE27);
85
+ const referral = parseReferralFee(params.args);
86
+ return {
87
+ vault: { chainId: params.vault.chainId, address: params.vault.address },
88
+ args: {
89
+ adapter: params.args.adapter,
90
+ userAddress: params.args.userAddress,
91
+ exitAssets,
92
+ deadline,
93
+ minSharePriceE27,
94
+ },
95
+ referral,
96
+ metadata: params.metadata,
97
+ requirementSignature: params.args.requirementSignature,
98
+ };
99
+ };
100
+ /** Encodes parsed fields and binds a fresh share permit. @internal */
101
+ export const buildVaultV2ForceWithdraw = (parsed, signatures = parsed) => {
102
+ const { vault, metadata, referral: { referralFeePct, referralFeeRecipient }, } = parsed;
103
+ const args = {
104
+ ...parsed.args,
105
+ requirementSignature: signatures.requirementSignature,
106
+ };
87
107
  const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
88
- const sharesPermit = getBundlesSharesPermit({
108
+ const sharesPermit = getParsedBundlesSharesPermit({
89
109
  vault: vault.address,
90
110
  deadline: args.deadline,
91
111
  owner: args.userAddress,
@@ -17,6 +17,18 @@ export interface VaultV2InKindRedeemParams {
17
17
  };
18
18
  readonly metadata?: Metadata;
19
19
  }
20
+ declare const vaultV2InKindRedeemInput: unique symbol;
21
+ /** Checked static in-kind fields; signatures and snapshots remain untrusted. @internal */
22
+ export type VaultV2InKindRedeemInput = {
23
+ readonly vault: Readonly<VaultV2InKindRedeemParams["vault"]>;
24
+ readonly args: Omit<VaultV2InKindRedeemParams["args"], "requirementSignature" | "amount" | "deadline"> & {
25
+ readonly amount: bigint;
26
+ readonly deadline: bigint;
27
+ };
28
+ readonly metadata?: Metadata;
29
+ readonly requirementSignature?: VaultV2InKindRedeemParams["args"]["requirementSignature"];
30
+ readonly [vaultV2InKindRedeemInput]: true;
31
+ };
20
32
  /**
21
33
  * Prepares a Vault V2 in-kind redemption into idle assets and Morpho Blue supply positions.
22
34
  *
@@ -56,4 +68,9 @@ export interface VaultV2InKindRedeemParams {
56
68
  * // tx satisfies Readonly<Transaction<VaultV2InKindRedeemAction>>
57
69
  * ```
58
70
  */
59
- export declare const vaultV2InKindRedeem: ({ vault, args, metadata, }: VaultV2InKindRedeemParams) => Readonly<Transaction<VaultV2InKindRedeemAction>>;
71
+ export declare const vaultV2InKindRedeem: (params: VaultV2InKindRedeemParams) => Readonly<Transaction<VaultV2InKindRedeemAction>>;
72
+ /** Constructs a complete in-kind operation, owning the ordered market tuples. @internal */
73
+ export declare const parseVaultV2InKindRedeem: (params: VaultV2InKindRedeemParams) => VaultV2InKindRedeemInput;
74
+ /** Encodes parsed fields and independently binds a fresh share permit. @internal */
75
+ export declare const buildVaultV2InKindRedeem: (parsed: VaultV2InKindRedeemInput, signatures?: Pick<VaultV2InKindRedeemParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV2InKindRedeemAction>>;
76
+ export {};