@morpho-org/morpho-sdk 10.1.0-next.0 → 10.2.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 (580) hide show
  1. package/README.md +6 -2
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/borrow.d.ts +13 -4
  5. package/lib/cjs/actions/blue/borrow.internal.d.ts +13 -0
  6. package/lib/cjs/actions/blue/borrow.internal.js +36 -0
  7. package/lib/cjs/actions/blue/borrow.js +12 -18
  8. package/lib/cjs/actions/blue/common.d.ts +53 -28
  9. package/lib/cjs/actions/blue/common.js +36 -35
  10. package/lib/cjs/actions/blue/encode.d.ts +23 -0
  11. package/lib/cjs/actions/blue/encode.js +171 -0
  12. package/lib/cjs/actions/blue/refinance.d.ts +14 -5
  13. package/lib/cjs/actions/blue/refinance.internal.d.ts +42 -0
  14. package/lib/cjs/actions/blue/refinance.internal.js +65 -0
  15. package/lib/cjs/actions/blue/refinance.js +13 -65
  16. package/lib/cjs/actions/blue/refinanceValidation.d.ts +6 -6
  17. package/lib/cjs/actions/blue/refinanceValidation.js +10 -8
  18. package/lib/cjs/actions/blue/repay.d.ts +5 -4
  19. package/lib/cjs/actions/blue/repay.internal.d.ts +13 -0
  20. package/lib/cjs/actions/blue/repay.internal.js +38 -0
  21. package/lib/cjs/actions/blue/repay.js +5 -19
  22. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +6 -5
  23. package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
  24. package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.js +112 -0
  25. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +6 -118
  26. package/lib/cjs/actions/blue/signatures.d.ts +30 -0
  27. package/lib/cjs/actions/blue/signatures.js +90 -0
  28. package/lib/cjs/actions/blue/supply.d.ts +6 -4
  29. package/lib/cjs/actions/blue/supply.internal.d.ts +32 -0
  30. package/lib/cjs/actions/blue/supply.internal.js +101 -0
  31. package/lib/cjs/actions/blue/supply.js +6 -69
  32. package/lib/cjs/actions/blue/supplyCollateral.d.ts +5 -4
  33. package/lib/cjs/actions/blue/supplyCollateral.internal.d.ts +13 -0
  34. package/lib/cjs/actions/blue/supplyCollateral.internal.js +37 -0
  35. package/lib/cjs/actions/blue/supplyCollateral.js +5 -19
  36. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +15 -6
  37. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +65 -0
  38. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +98 -0
  39. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +13 -108
  40. package/lib/cjs/actions/blue/withdraw.d.ts +15 -6
  41. package/lib/cjs/actions/blue/withdraw.internal.d.ts +56 -0
  42. package/lib/cjs/actions/blue/withdraw.internal.js +87 -0
  43. package/lib/cjs/actions/blue/withdraw.js +13 -80
  44. package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +2 -2
  45. package/lib/cjs/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
  46. package/lib/cjs/actions/blue/withdrawBuyCallback.internal.js +58 -0
  47. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -39
  48. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +4 -3
  49. package/lib/cjs/actions/blue/withdrawCollateral.internal.d.ts +16 -0
  50. package/lib/cjs/actions/blue/withdrawCollateral.internal.js +39 -0
  51. package/lib/cjs/actions/blue/withdrawCollateral.js +5 -19
  52. package/lib/cjs/actions/bundles/common.d.ts +9 -0
  53. package/lib/cjs/actions/bundles/common.js +18 -6
  54. package/lib/cjs/actions/bundles/index.d.ts +1 -1
  55. package/lib/cjs/actions/bundles/index.js +3 -16
  56. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
  57. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +59 -60
  58. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +22 -1
  59. package/lib/cjs/actions/midnight/cancelAndMake.js +46 -87
  60. package/lib/cjs/actions/midnight/cancelOffers.d.ts +11 -0
  61. package/lib/cjs/actions/midnight/cancelOffers.js +22 -4
  62. package/lib/cjs/actions/midnight/encode.d.ts +36 -0
  63. package/lib/cjs/actions/midnight/encode.js +554 -0
  64. package/lib/cjs/actions/midnight/index.d.ts +14 -13
  65. package/lib/cjs/actions/midnight/index.js +29 -13
  66. package/lib/cjs/actions/midnight/parse.d.ts +35 -0
  67. package/lib/cjs/actions/midnight/parse.js +73 -0
  68. package/lib/cjs/actions/midnight/parseCollateralBatch.d.ts +58 -0
  69. package/lib/cjs/actions/midnight/parseCollateralBatch.js +216 -0
  70. package/lib/cjs/actions/midnight/redeem.d.ts +16 -3
  71. package/lib/cjs/actions/midnight/redeem.js +22 -51
  72. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
  73. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +42 -67
  74. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +40 -5
  75. package/lib/cjs/actions/midnight/supplyCollateral.js +60 -54
  76. package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +3 -3
  77. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +3 -62
  78. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
  79. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +39 -67
  80. package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
  81. package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +142 -0
  82. package/lib/cjs/actions/midnight/takeBorrow.d.ts +17 -2
  83. package/lib/cjs/actions/midnight/takeBorrow.js +25 -56
  84. package/lib/cjs/actions/midnight/takeLend.d.ts +21 -1
  85. package/lib/cjs/actions/midnight/takeLend.js +30 -58
  86. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
  87. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +34 -62
  88. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +17 -2
  89. package/lib/cjs/actions/midnight/takeWithdraw.js +77 -115
  90. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -3
  91. package/lib/cjs/actions/midnight/withdrawCollateral.js +25 -56
  92. package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
  93. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +3 -71
  94. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
  95. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +39 -19
  96. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -1
  97. package/lib/cjs/actions/requirements/blue/index.js +3 -15
  98. package/lib/cjs/actions/requirements/chainCheck.d.ts +5 -0
  99. package/lib/cjs/actions/requirements/chainCheck.js +10 -0
  100. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
  101. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +40 -27
  102. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
  103. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +36 -17
  104. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
  105. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +44 -9
  106. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
  107. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +61 -24
  108. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
  109. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +25 -4
  110. package/lib/cjs/actions/requirements/encode/index.d.ts +5 -5
  111. package/lib/cjs/actions/requirements/encode/index.js +11 -19
  112. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +26 -11
  113. package/lib/cjs/actions/requirements/getRequirementsApproval.js +40 -12
  114. package/lib/cjs/actions/requirements/index.d.ts +1 -1
  115. package/lib/cjs/actions/requirements/index.js +3 -1
  116. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
  117. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +34 -19
  118. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
  119. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +26 -12
  120. package/lib/cjs/actions/requirements/midnight/index.d.ts +2 -2
  121. package/lib/cjs/actions/requirements/midnight/index.js +5 -16
  122. package/lib/cjs/actions/vaultV1/deposit.d.ts +23 -1
  123. package/lib/cjs/actions/vaultV1/deposit.js +48 -11
  124. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +18 -1
  125. package/lib/cjs/actions/vaultV1/inKindRedeem.js +36 -16
  126. package/lib/cjs/actions/vaultV1/index.d.ts +5 -5
  127. package/lib/cjs/actions/vaultV1/index.js +11 -19
  128. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +24 -2
  129. package/lib/cjs/actions/vaultV1/migrateToV2.js +51 -12
  130. package/lib/cjs/actions/vaultV1/redeem.d.ts +22 -2
  131. package/lib/cjs/actions/vaultV1/redeem.js +30 -8
  132. package/lib/cjs/actions/vaultV1/withdraw.d.ts +21 -1
  133. package/lib/cjs/actions/vaultV1/withdraw.js +30 -8
  134. package/lib/cjs/actions/vaultV2/deposit.d.ts +23 -1
  135. package/lib/cjs/actions/vaultV2/deposit.js +48 -11
  136. package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +20 -2
  137. package/lib/cjs/actions/vaultV2/forceRedeem.js +39 -8
  138. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +25 -2
  139. package/lib/cjs/actions/vaultV2/forceWithdraw.js +38 -15
  140. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +18 -1
  141. package/lib/cjs/actions/vaultV2/inKindRedeem.js +35 -15
  142. package/lib/cjs/actions/vaultV2/index.d.ts +6 -6
  143. package/lib/cjs/actions/vaultV2/index.js +13 -20
  144. package/lib/cjs/actions/vaultV2/redeem.d.ts +22 -2
  145. package/lib/cjs/actions/vaultV2/redeem.js +30 -8
  146. package/lib/cjs/actions/vaultV2/withdraw.d.ts +21 -1
  147. package/lib/cjs/actions/vaultV2/withdraw.js +30 -8
  148. package/lib/cjs/blue/abis.d.ts +1 -1
  149. package/lib/cjs/blue/abis.js +1 -5
  150. package/lib/cjs/blue/entities.d.ts +4 -4
  151. package/lib/cjs/blue/entities.js +1 -3
  152. package/lib/cjs/blue/errors.d.ts +2 -2
  153. package/lib/cjs/blue/errors.js +1 -5
  154. package/lib/cjs/blue/fetch.d.ts +2 -2
  155. package/lib/cjs/blue/fetch.js +1 -3
  156. package/lib/cjs/blue/utils.d.ts +1 -1
  157. package/lib/cjs/blue/utils.js +1 -2
  158. package/lib/cjs/constants.d.ts +1 -1
  159. package/lib/cjs/constants.js +2 -0
  160. package/lib/cjs/entities/blue/blue.d.ts +118 -28
  161. package/lib/cjs/entities/blue/blue.js +503 -416
  162. package/lib/cjs/entities/index.d.ts +4 -4
  163. package/lib/cjs/entities/index.js +1 -3
  164. package/lib/cjs/entities/midnight/midnight.d.ts +117 -41
  165. package/lib/cjs/entities/midnight/midnight.js +472 -843
  166. package/lib/cjs/entities/midnight/parse.d.ts +74 -0
  167. package/lib/cjs/entities/midnight/parse.js +336 -0
  168. package/lib/cjs/entities/midnight/prepare.d.ts +47 -0
  169. package/lib/cjs/entities/midnight/prepare.js +293 -0
  170. package/lib/cjs/entities/midnight/publication.d.ts +7 -3
  171. package/lib/cjs/entities/midnight/publication.js +10 -7
  172. package/lib/cjs/entities/midnight/types.d.ts +7 -0
  173. package/lib/cjs/entities/requirements/assertContractCode.d.ts +10 -5
  174. package/lib/cjs/entities/requirements/assertContractCode.js +24 -15
  175. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
  176. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +59 -51
  177. package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -3
  178. package/lib/cjs/entities/requirements/getErc2612Permit.js +20 -4
  179. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
  180. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +24 -7
  181. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
  182. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +27 -7
  183. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
  184. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
  185. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
  186. package/lib/cjs/entities/requirements/index.d.ts +2 -2
  187. package/lib/cjs/entities/requirements/index.js +5 -16
  188. package/lib/cjs/entities/requirements/validateNativeRequirements.d.ts +21 -0
  189. package/lib/cjs/entities/requirements/validateNativeRequirements.js +37 -0
  190. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
  191. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +1 -7
  192. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  193. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +5 -0
  194. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +29 -46
  195. package/lib/cjs/entities/vaultV1/vaultV1.js +234 -159
  196. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
  197. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +9 -4
  198. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
  199. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +1 -7
  200. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +40 -92
  201. package/lib/cjs/entities/vaultV2/vaultV2.js +230 -188
  202. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +13 -5
  203. package/lib/cjs/entities/vaultV2BlueReallocationData.js +21 -27
  204. package/lib/cjs/errors.d.ts +4 -4
  205. package/lib/cjs/errors.js +5 -7
  206. package/lib/cjs/fetch.d.ts +2 -2
  207. package/lib/cjs/fetch.js +1 -3
  208. package/lib/cjs/helpers/constant.d.ts +2 -0
  209. package/lib/cjs/helpers/constant.js +3 -1
  210. package/lib/cjs/helpers/deadShares.js +0 -3
  211. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  212. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.js +18 -0
  213. package/lib/cjs/helpers/index.d.ts +1 -1
  214. package/lib/cjs/helpers/index.js +2 -1
  215. package/lib/cjs/helpers/parse.d.ts +33 -0
  216. package/lib/cjs/helpers/parse.js +71 -0
  217. package/lib/cjs/helpers/parseMidnight.d.ts +48 -0
  218. package/lib/cjs/helpers/parseMidnight.js +95 -0
  219. package/lib/cjs/helpers/parseMidnightMaker.d.ts +44 -0
  220. package/lib/cjs/helpers/parseMidnightMaker.js +154 -0
  221. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  222. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +4 -5
  223. package/lib/cjs/helpers/quoteBlueRepay.d.ts +7 -3
  224. package/lib/cjs/helpers/quoteBlueRepay.js +20 -7
  225. package/lib/cjs/helpers/reallocationPenalty.d.ts +10 -0
  226. package/lib/cjs/helpers/reallocationPenalty.js +32 -0
  227. package/lib/cjs/helpers/referralFee.d.ts +2 -1
  228. package/lib/cjs/helpers/referralFee.js +5 -1
  229. package/lib/cjs/helpers/validate.d.ts +34 -6
  230. package/lib/cjs/helpers/validate.js +52 -9
  231. package/lib/cjs/helpers/validateMidnightBounds.d.ts +1 -2
  232. package/lib/cjs/helpers/validateMidnightBounds.js +1 -2
  233. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
  234. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +4 -4
  235. package/lib/cjs/helpers/validateMidnightPublication.d.ts +17 -1
  236. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  237. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +1 -1
  238. package/lib/cjs/index.d.ts +1 -0
  239. package/lib/cjs/midnight/errors.d.ts +1 -2
  240. package/lib/cjs/midnight/errors.js +4 -5
  241. package/lib/cjs/transactionPlan/blue/borrow.d.ts +11 -5
  242. package/lib/cjs/transactionPlan/blue/borrow.js +26 -8
  243. package/lib/cjs/transactionPlan/blue/refinance.d.ts +9 -2
  244. package/lib/cjs/transactionPlan/blue/refinance.js +36 -11
  245. package/lib/cjs/transactionPlan/blue/repay.d.ts +1 -2
  246. package/lib/cjs/transactionPlan/blue/repay.js +3 -3
  247. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  248. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +35 -7
  249. package/lib/cjs/transactionPlan/blue/supply.d.ts +1 -2
  250. package/lib/cjs/transactionPlan/blue/supply.js +1 -2
  251. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  252. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +2 -3
  253. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  254. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +25 -8
  255. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +17 -7
  256. package/lib/cjs/transactionPlan/blue/withdraw.js +28 -9
  257. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  258. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +17 -9
  259. package/lib/cjs/transactionPlan/deposit.js +4 -0
  260. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  261. package/lib/cjs/transactionPlan/intent.js +4 -2
  262. package/lib/cjs/transactionPlan/plan.d.ts +8 -4
  263. package/lib/cjs/transactionPlan/plan.js +8 -4
  264. package/lib/cjs/transactionPlan/types.d.ts +6 -0
  265. package/lib/cjs/transactionPlan/validation.d.ts +1 -1
  266. package/lib/cjs/transactionPlan/validation.js +3 -0
  267. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +5 -5
  268. package/lib/cjs/transactionPlan/vaultv1/deposit.js +5 -5
  269. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  270. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +7 -3
  271. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -2
  272. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -2
  273. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  274. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -3
  275. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +3 -3
  276. package/lib/cjs/transactionPlan/vaultv2/deposit.js +3 -3
  277. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  278. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  279. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +2 -3
  280. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -3
  281. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  282. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -3
  283. package/lib/cjs/types/action.d.ts +13 -2
  284. package/lib/cjs/types/error.d.ts +27 -8
  285. package/lib/cjs/types/error.js +42 -12
  286. package/lib/cjs/types/sharedLiquidity.d.ts +7 -2
  287. package/lib/cjs/utils.d.ts +2 -2
  288. package/lib/cjs/utils.js +2 -4
  289. package/lib/cjs/version.d.ts +1 -1
  290. package/lib/cjs/version.js +1 -1
  291. package/lib/esm/abis.d.ts +1 -1
  292. package/lib/esm/abis.js +1 -1
  293. package/lib/esm/actions/blue/borrow.d.ts +13 -4
  294. package/lib/esm/actions/blue/borrow.internal.d.ts +13 -0
  295. package/lib/esm/actions/blue/borrow.internal.js +31 -0
  296. package/lib/esm/actions/blue/borrow.js +12 -18
  297. package/lib/esm/actions/blue/common.d.ts +53 -28
  298. package/lib/esm/actions/blue/common.js +36 -34
  299. package/lib/esm/actions/blue/encode.d.ts +23 -0
  300. package/lib/esm/actions/blue/encode.js +164 -0
  301. package/lib/esm/actions/blue/refinance.d.ts +14 -5
  302. package/lib/esm/actions/blue/refinance.internal.d.ts +42 -0
  303. package/lib/esm/actions/blue/refinance.internal.js +59 -0
  304. package/lib/esm/actions/blue/refinance.js +13 -65
  305. package/lib/esm/actions/blue/refinanceValidation.d.ts +6 -6
  306. package/lib/esm/actions/blue/refinanceValidation.js +11 -9
  307. package/lib/esm/actions/blue/repay.d.ts +5 -4
  308. package/lib/esm/actions/blue/repay.internal.d.ts +13 -0
  309. package/lib/esm/actions/blue/repay.internal.js +33 -0
  310. package/lib/esm/actions/blue/repay.js +5 -19
  311. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +6 -5
  312. package/lib/esm/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
  313. package/lib/esm/actions/blue/repayWithdrawCollateral.internal.js +104 -0
  314. package/lib/esm/actions/blue/repayWithdrawCollateral.js +6 -118
  315. package/lib/esm/actions/blue/signatures.d.ts +30 -0
  316. package/lib/esm/actions/blue/signatures.js +82 -0
  317. package/lib/esm/actions/blue/supply.d.ts +6 -4
  318. package/lib/esm/actions/blue/supply.internal.d.ts +32 -0
  319. package/lib/esm/actions/blue/supply.internal.js +95 -0
  320. package/lib/esm/actions/blue/supply.js +6 -69
  321. package/lib/esm/actions/blue/supplyCollateral.d.ts +5 -4
  322. package/lib/esm/actions/blue/supplyCollateral.internal.d.ts +13 -0
  323. package/lib/esm/actions/blue/supplyCollateral.internal.js +32 -0
  324. package/lib/esm/actions/blue/supplyCollateral.js +5 -19
  325. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +15 -6
  326. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +65 -0
  327. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +91 -0
  328. package/lib/esm/actions/blue/supplyCollateralBorrow.js +13 -108
  329. package/lib/esm/actions/blue/withdraw.d.ts +15 -6
  330. package/lib/esm/actions/blue/withdraw.internal.d.ts +56 -0
  331. package/lib/esm/actions/blue/withdraw.internal.js +80 -0
  332. package/lib/esm/actions/blue/withdraw.js +13 -80
  333. package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +2 -2
  334. package/lib/esm/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
  335. package/lib/esm/actions/blue/withdrawBuyCallback.internal.js +53 -0
  336. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -39
  337. package/lib/esm/actions/blue/withdrawCollateral.d.ts +4 -3
  338. package/lib/esm/actions/blue/withdrawCollateral.internal.d.ts +16 -0
  339. package/lib/esm/actions/blue/withdrawCollateral.internal.js +34 -0
  340. package/lib/esm/actions/blue/withdrawCollateral.js +5 -19
  341. package/lib/esm/actions/bundles/common.d.ts +9 -0
  342. package/lib/esm/actions/bundles/common.js +15 -4
  343. package/lib/esm/actions/bundles/index.d.ts +1 -1
  344. package/lib/esm/actions/bundles/index.js +1 -1
  345. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
  346. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +58 -61
  347. package/lib/esm/actions/midnight/cancelAndMake.d.ts +22 -1
  348. package/lib/esm/actions/midnight/cancelAndMake.js +43 -85
  349. package/lib/esm/actions/midnight/cancelOffers.d.ts +11 -0
  350. package/lib/esm/actions/midnight/cancelOffers.js +18 -2
  351. package/lib/esm/actions/midnight/encode.d.ts +36 -0
  352. package/lib/esm/actions/midnight/encode.js +539 -0
  353. package/lib/esm/actions/midnight/index.d.ts +14 -13
  354. package/lib/esm/actions/midnight/index.js +14 -13
  355. package/lib/esm/actions/midnight/parse.d.ts +35 -0
  356. package/lib/esm/actions/midnight/parse.js +68 -0
  357. package/lib/esm/actions/midnight/parseCollateralBatch.d.ts +58 -0
  358. package/lib/esm/actions/midnight/parseCollateralBatch.js +209 -0
  359. package/lib/esm/actions/midnight/redeem.d.ts +16 -3
  360. package/lib/esm/actions/midnight/redeem.js +20 -50
  361. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
  362. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +38 -64
  363. package/lib/esm/actions/midnight/supplyCollateral.d.ts +40 -5
  364. package/lib/esm/actions/midnight/supplyCollateral.js +57 -53
  365. package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +3 -3
  366. package/lib/esm/actions/midnight/supplyCollateralBatch.js +3 -62
  367. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
  368. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +34 -63
  369. package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
  370. package/lib/esm/actions/midnight/supplyCollateralWithNative.js +137 -0
  371. package/lib/esm/actions/midnight/takeBorrow.d.ts +17 -2
  372. package/lib/esm/actions/midnight/takeBorrow.js +21 -53
  373. package/lib/esm/actions/midnight/takeLend.d.ts +21 -1
  374. package/lib/esm/actions/midnight/takeLend.js +27 -56
  375. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
  376. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +31 -60
  377. package/lib/esm/actions/midnight/takeWithdraw.d.ts +17 -2
  378. package/lib/esm/actions/midnight/takeWithdraw.js +76 -115
  379. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -3
  380. package/lib/esm/actions/midnight/withdrawCollateral.js +23 -55
  381. package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
  382. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +3 -71
  383. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
  384. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +36 -18
  385. package/lib/esm/actions/requirements/blue/index.d.ts +1 -1
  386. package/lib/esm/actions/requirements/blue/index.js +1 -1
  387. package/lib/esm/actions/requirements/chainCheck.d.ts +5 -0
  388. package/lib/esm/actions/requirements/chainCheck.js +6 -0
  389. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
  390. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +36 -25
  391. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
  392. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +33 -16
  393. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
  394. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +41 -8
  395. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
  396. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +59 -24
  397. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
  398. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +21 -2
  399. package/lib/esm/actions/requirements/encode/index.d.ts +5 -5
  400. package/lib/esm/actions/requirements/encode/index.js +5 -5
  401. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +26 -11
  402. package/lib/esm/actions/requirements/getRequirementsApproval.js +38 -12
  403. package/lib/esm/actions/requirements/index.d.ts +1 -1
  404. package/lib/esm/actions/requirements/index.js +1 -1
  405. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
  406. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +31 -18
  407. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
  408. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +22 -10
  409. package/lib/esm/actions/requirements/midnight/index.d.ts +2 -2
  410. package/lib/esm/actions/requirements/midnight/index.js +2 -2
  411. package/lib/esm/actions/vaultV1/deposit.d.ts +23 -1
  412. package/lib/esm/actions/vaultV1/deposit.js +45 -10
  413. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +18 -1
  414. package/lib/esm/actions/vaultV1/inKindRedeem.js +33 -15
  415. package/lib/esm/actions/vaultV1/index.d.ts +5 -5
  416. package/lib/esm/actions/vaultV1/index.js +5 -5
  417. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +24 -2
  418. package/lib/esm/actions/vaultV1/migrateToV2.js +49 -12
  419. package/lib/esm/actions/vaultV1/redeem.d.ts +22 -2
  420. package/lib/esm/actions/vaultV1/redeem.js +28 -8
  421. package/lib/esm/actions/vaultV1/withdraw.d.ts +21 -1
  422. package/lib/esm/actions/vaultV1/withdraw.js +28 -8
  423. package/lib/esm/actions/vaultV2/deposit.d.ts +23 -1
  424. package/lib/esm/actions/vaultV2/deposit.js +45 -10
  425. package/lib/esm/actions/vaultV2/forceRedeem.d.ts +20 -2
  426. package/lib/esm/actions/vaultV2/forceRedeem.js +35 -6
  427. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +25 -2
  428. package/lib/esm/actions/vaultV2/forceWithdraw.js +35 -14
  429. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +18 -1
  430. package/lib/esm/actions/vaultV2/inKindRedeem.js +32 -14
  431. package/lib/esm/actions/vaultV2/index.d.ts +6 -6
  432. package/lib/esm/actions/vaultV2/index.js +6 -6
  433. package/lib/esm/actions/vaultV2/redeem.d.ts +22 -2
  434. package/lib/esm/actions/vaultV2/redeem.js +28 -8
  435. package/lib/esm/actions/vaultV2/withdraw.d.ts +21 -1
  436. package/lib/esm/actions/vaultV2/withdraw.js +28 -8
  437. package/lib/esm/blue/abis.d.ts +1 -1
  438. package/lib/esm/blue/abis.js +1 -1
  439. package/lib/esm/blue/entities.d.ts +4 -4
  440. package/lib/esm/blue/entities.js +2 -2
  441. package/lib/esm/blue/errors.d.ts +2 -2
  442. package/lib/esm/blue/errors.js +2 -2
  443. package/lib/esm/blue/fetch.d.ts +2 -2
  444. package/lib/esm/blue/fetch.js +2 -2
  445. package/lib/esm/blue/utils.d.ts +1 -1
  446. package/lib/esm/blue/utils.js +1 -1
  447. package/lib/esm/constants.d.ts +1 -1
  448. package/lib/esm/constants.js +1 -1
  449. package/lib/esm/entities/blue/blue.d.ts +118 -28
  450. package/lib/esm/entities/blue/blue.js +485 -398
  451. package/lib/esm/entities/index.d.ts +4 -4
  452. package/lib/esm/entities/index.js +2 -2
  453. package/lib/esm/entities/midnight/midnight.d.ts +117 -41
  454. package/lib/esm/entities/midnight/midnight.js +455 -826
  455. package/lib/esm/entities/midnight/parse.d.ts +74 -0
  456. package/lib/esm/entities/midnight/parse.js +320 -0
  457. package/lib/esm/entities/midnight/prepare.d.ts +47 -0
  458. package/lib/esm/entities/midnight/prepare.js +282 -0
  459. package/lib/esm/entities/midnight/publication.d.ts +7 -3
  460. package/lib/esm/entities/midnight/publication.js +7 -3
  461. package/lib/esm/entities/midnight/types.d.ts +7 -0
  462. package/lib/esm/entities/requirements/assertContractCode.d.ts +10 -5
  463. package/lib/esm/entities/requirements/assertContractCode.js +24 -15
  464. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
  465. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +53 -47
  466. package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -3
  467. package/lib/esm/entities/requirements/getErc2612Permit.js +19 -4
  468. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
  469. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +20 -5
  470. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
  471. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +23 -5
  472. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
  473. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
  474. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
  475. package/lib/esm/entities/requirements/index.d.ts +2 -2
  476. package/lib/esm/entities/requirements/index.js +2 -2
  477. package/lib/esm/entities/requirements/validateNativeRequirements.d.ts +21 -0
  478. package/lib/esm/entities/requirements/validateNativeRequirements.js +33 -0
  479. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
  480. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +1 -7
  481. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  482. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +5 -0
  483. package/lib/esm/entities/vaultV1/vaultV1.d.ts +29 -46
  484. package/lib/esm/entities/vaultV1/vaultV1.js +214 -139
  485. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
  486. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +10 -5
  487. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
  488. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +1 -7
  489. package/lib/esm/entities/vaultV2/vaultV2.d.ts +40 -92
  490. package/lib/esm/entities/vaultV2/vaultV2.js +214 -172
  491. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +13 -5
  492. package/lib/esm/entities/vaultV2BlueReallocationData.js +19 -25
  493. package/lib/esm/errors.d.ts +4 -4
  494. package/lib/esm/errors.js +4 -4
  495. package/lib/esm/fetch.d.ts +2 -2
  496. package/lib/esm/fetch.js +2 -2
  497. package/lib/esm/helpers/constant.d.ts +2 -0
  498. package/lib/esm/helpers/constant.js +2 -0
  499. package/lib/esm/helpers/deadShares.js +1 -4
  500. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  501. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.js +15 -0
  502. package/lib/esm/helpers/index.d.ts +1 -1
  503. package/lib/esm/helpers/index.js +1 -1
  504. package/lib/esm/helpers/parse.d.ts +33 -0
  505. package/lib/esm/helpers/parse.js +61 -0
  506. package/lib/esm/helpers/parseMidnight.d.ts +48 -0
  507. package/lib/esm/helpers/parseMidnight.js +80 -0
  508. package/lib/esm/helpers/parseMidnightMaker.d.ts +44 -0
  509. package/lib/esm/helpers/parseMidnightMaker.js +147 -0
  510. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  511. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +4 -5
  512. package/lib/esm/helpers/quoteBlueRepay.d.ts +7 -3
  513. package/lib/esm/helpers/quoteBlueRepay.js +21 -8
  514. package/lib/esm/helpers/reallocationPenalty.d.ts +10 -0
  515. package/lib/esm/helpers/reallocationPenalty.js +28 -0
  516. package/lib/esm/helpers/referralFee.d.ts +2 -1
  517. package/lib/esm/helpers/referralFee.js +5 -1
  518. package/lib/esm/helpers/validate.d.ts +34 -6
  519. package/lib/esm/helpers/validate.js +52 -11
  520. package/lib/esm/helpers/validateMidnightBounds.d.ts +1 -2
  521. package/lib/esm/helpers/validateMidnightBounds.js +1 -2
  522. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
  523. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +2 -2
  524. package/lib/esm/helpers/validateMidnightPublication.d.ts +17 -1
  525. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  526. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +1 -1
  527. package/lib/esm/index.d.ts +1 -0
  528. package/lib/esm/midnight/errors.d.ts +1 -2
  529. package/lib/esm/midnight/errors.js +1 -2
  530. package/lib/esm/transactionPlan/blue/borrow.d.ts +11 -5
  531. package/lib/esm/transactionPlan/blue/borrow.js +27 -9
  532. package/lib/esm/transactionPlan/blue/refinance.d.ts +9 -2
  533. package/lib/esm/transactionPlan/blue/refinance.js +37 -12
  534. package/lib/esm/transactionPlan/blue/repay.d.ts +1 -2
  535. package/lib/esm/transactionPlan/blue/repay.js +4 -4
  536. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  537. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +36 -8
  538. package/lib/esm/transactionPlan/blue/supply.d.ts +1 -2
  539. package/lib/esm/transactionPlan/blue/supply.js +1 -2
  540. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  541. package/lib/esm/transactionPlan/blue/supplyCollateral.js +2 -3
  542. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  543. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +25 -8
  544. package/lib/esm/transactionPlan/blue/withdraw.d.ts +17 -7
  545. package/lib/esm/transactionPlan/blue/withdraw.js +28 -9
  546. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  547. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +17 -9
  548. package/lib/esm/transactionPlan/deposit.js +5 -1
  549. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  550. package/lib/esm/transactionPlan/intent.js +4 -2
  551. package/lib/esm/transactionPlan/plan.d.ts +8 -4
  552. package/lib/esm/transactionPlan/plan.js +8 -4
  553. package/lib/esm/transactionPlan/types.d.ts +6 -0
  554. package/lib/esm/transactionPlan/validation.d.ts +1 -1
  555. package/lib/esm/transactionPlan/validation.js +3 -0
  556. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +5 -5
  557. package/lib/esm/transactionPlan/vaultv1/deposit.js +5 -5
  558. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  559. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +8 -4
  560. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -2
  561. package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -2
  562. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  563. package/lib/esm/transactionPlan/vaultv1/withdraw.js +2 -3
  564. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +3 -3
  565. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -3
  566. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  567. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  568. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +2 -3
  569. package/lib/esm/transactionPlan/vaultv2/redeem.js +2 -3
  570. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  571. package/lib/esm/transactionPlan/vaultv2/withdraw.js +2 -3
  572. package/lib/esm/types/action.d.ts +13 -2
  573. package/lib/esm/types/error.d.ts +27 -8
  574. package/lib/esm/types/error.js +38 -10
  575. package/lib/esm/types/sharedLiquidity.d.ts +7 -2
  576. package/lib/esm/utils.d.ts +2 -2
  577. package/lib/esm/utils.js +2 -2
  578. package/lib/esm/version.d.ts +1 -1
  579. package/lib/esm/version.js +1 -1
  580. package/package.json +7 -7
@@ -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: {
@@ -19,7 +20,7 @@ export interface VaultV1RedeemParams {
19
20
  readonly onBehalf?: never;
20
21
  /** Optional ERC-2612 vault-share permit for the redeemed shares. */
21
22
  readonly requirementSignature?: Erc2612RequirementSignature;
22
- /** Optional WAD-scaled fee in [0, 1e18), defaulting to zero. */
23
+ /** Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero. */
23
24
  readonly referralFeePct?: bigint;
24
25
  /** Optional fee recipient; a nonzero address is required when `referralFeePct > 0n`. */
25
26
  readonly referralFeeRecipient?: Address;
@@ -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
  *
@@ -40,7 +54,7 @@ export interface VaultV1RedeemParams {
40
54
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
41
55
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
42
56
  * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
43
- * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
57
+ * @param params.args.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero.
44
58
  * The fee is rounded down and deducted from the gross redeemed assets.
45
59
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
46
60
  * when `referralFeePct > 0n`.
@@ -54,6 +68,7 @@ export interface VaultV1RedeemParams {
54
68
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
55
69
  * @throws {NegativeInputError} when `referralFeePct` is negative.
56
70
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
71
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
57
72
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
58
73
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
59
74
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
@@ -71,3 +86,8 @@ export interface VaultV1RedeemParams {
71
86
  * ```
72
87
  */
73
88
  export declare const vaultV1Redeem: (params: VaultV1RedeemParams) => Readonly<Transaction<VaultV1RedeemAction>>;
89
+ /** Parses the amount and common fields in standalone order. @internal */
90
+ export declare const parseVaultV1Redeem: (params: VaultV1RedeemParams) => VaultV1RedeemInput;
91
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
92
+ export declare const buildVaultV1Redeem: (parsed: VaultV1RedeemInput, signatures?: Pick<VaultV1RedeemParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV1RedeemAction>>;
93
+ 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
  *
@@ -15,7 +15,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBun
15
15
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
16
16
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
17
17
  * and the registered VaultBundlesV1 spender. Omit when the share allowance is already set.
18
- * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
18
+ * @param params.args.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero.
19
19
  * The fee is rounded down and deducted from the gross redeemed assets.
20
20
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
21
21
  * when `referralFeePct > 0n`.
@@ -29,6 +29,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBun
29
29
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
30
30
  * @throws {NegativeInputError} when `referralFeePct` is negative.
31
31
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
32
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
32
33
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
33
34
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
34
35
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
@@ -45,15 +46,34 @@ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBun
45
46
  * // tx.action.type === "vaultV1Redeem"
46
47
  * ```
47
48
  */
48
- export const vaultV1Redeem = (params) => {
49
+ export const vaultV1Redeem = (params) => buildVaultV1Redeem(parseVaultV1Redeem(params));
50
+ /** Parses the amount and common fields in standalone order. @internal */
51
+ export const parseVaultV1Redeem = (params) => {
49
52
  if (params.args.shares <= 0n) {
50
53
  throw new NonPositiveInputError("shares", params.args.shares);
51
54
  }
52
- // Reject ABI overflow with SDK errors before calldata encoding.
53
- validateUint256Field("shares", params.args.shares);
54
- const common = normalizeBundlesCommonParams(params.args);
55
+ const shares = parseUint256("shares", params.args.shares);
56
+ const common = parseBundlesCommon(params.args);
57
+ return {
58
+ vault: { chainId: params.vault.chainId, address: params.vault.address },
59
+ args: { shares, userAddress: params.args.userAddress, ...common },
60
+ common,
61
+ metadata: params.metadata,
62
+ requirementSignature: params.args.requirementSignature,
63
+ };
64
+ };
65
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
66
+ export const buildVaultV1Redeem = (parsed, signatures = parsed) => {
67
+ const { common } = parsed;
68
+ const params = {
69
+ ...parsed,
70
+ args: {
71
+ ...parsed.args,
72
+ requirementSignature: signatures.requirementSignature,
73
+ },
74
+ };
55
75
  const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
56
- const sharesPermit = getBundlesSharesPermit({
76
+ const sharesPermit = getParsedBundlesSharesPermit({
57
77
  vault: params.vault.address,
58
78
  deadline: common.deadline,
59
79
  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
  *
@@ -32,7 +46,7 @@ export interface VaultV1WithdrawParams {
32
46
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
33
47
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
34
48
  * and the registered VaultBundlesV1 spender. Omit when the share allowance meets the required amount.
35
- * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
49
+ * @param params.args.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero.
36
50
  * The fee is rounded down and deducted from the gross withdrawn assets.
37
51
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
38
52
  * when `referralFeePct > 0n`.
@@ -47,6 +61,7 @@ export interface VaultV1WithdrawParams {
47
61
  * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
48
62
  * @throws {NegativeInputError} when `referralFeePct` is negative.
49
63
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
64
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
50
65
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
51
66
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
52
67
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
@@ -71,3 +86,8 @@ export interface VaultV1WithdrawParams {
71
86
  * ```
72
87
  */
73
88
  export declare const vaultV1Withdraw: (params: VaultV1WithdrawParams) => Readonly<Transaction<VaultV1WithdrawAction>>;
89
+ /** Parses the amount and common fields in standalone order. @internal */
90
+ export declare const parseVaultV1Withdraw: (params: VaultV1WithdrawParams) => VaultV1WithdrawInput;
91
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
92
+ export declare const buildVaultV1Withdraw: (parsed: VaultV1WithdrawInput, signatures?: Pick<VaultV1WithdrawParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV1WithdrawAction>>;
93
+ 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
  *
@@ -18,7 +18,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
18
18
  * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
19
19
  * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
20
20
  * and the registered VaultBundlesV1 spender. Omit when the share allowance meets the required amount.
21
- * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
21
+ * @param params.args.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero.
22
22
  * The fee is rounded down and deducted from the gross withdrawn assets.
23
23
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
24
24
  * when `referralFeePct > 0n`.
@@ -33,6 +33,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
33
33
  * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
34
34
  * @throws {NegativeInputError} when `referralFeePct` is negative.
35
35
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
36
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
36
37
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
37
38
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
39
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
@@ -56,15 +57,34 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
56
57
  * }
57
58
  * ```
58
59
  */
59
- export const vaultV1Withdraw = (params) => {
60
+ export const vaultV1Withdraw = (params) => buildVaultV1Withdraw(parseVaultV1Withdraw(params));
61
+ /** Parses the amount and common fields in standalone order. @internal */
62
+ export const parseVaultV1Withdraw = (params) => {
60
63
  if (params.args.amount <= 0n) {
61
64
  throw new NonPositiveInputError("amount", params.args.amount);
62
65
  }
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);
66
+ const amount = parseUint256("amount", params.args.amount);
67
+ const common = parseBundlesCommon(params.args);
68
+ return {
69
+ vault: { chainId: params.vault.chainId, address: params.vault.address },
70
+ args: { amount, userAddress: params.args.userAddress, ...common },
71
+ common,
72
+ metadata: params.metadata,
73
+ requirementSignature: params.args.requirementSignature,
74
+ };
75
+ };
76
+ /** Encodes parsed inputs and validates a fresh share signature. @internal */
77
+ export const buildVaultV1Withdraw = (parsed, signatures = parsed) => {
78
+ const { common } = parsed;
79
+ const params = {
80
+ ...parsed,
81
+ args: {
82
+ ...parsed.args,
83
+ requirementSignature: signatures.requirementSignature,
84
+ },
85
+ };
66
86
  const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
67
- const sharesPermit = getBundlesSharesPermit({
87
+ const sharesPermit = getParsedBundlesSharesPermit({
68
88
  vault: params.vault.address,
69
89
  deadline: common.deadline,
70
90
  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
  *
@@ -33,7 +49,7 @@ export interface VaultV2DepositParams {
33
49
  * @param params.args.recipient - Unsupported; shares are always minted to the transaction sender.
34
50
  * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer signature
35
51
  * for the gross amount, vault asset, `userAddress`, and VaultBundlesV1 spender.
36
- * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
52
+ * @param params.args.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero.
37
53
  * The fee is rounded down and deducted from gross assets before depositing.
38
54
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
39
55
  * when `referralFeePct > 0n`.
@@ -51,6 +67,7 @@ export interface VaultV2DepositParams {
51
67
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
52
68
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
53
69
  * {@link InputExceedsMaxError}, so either class catches it.
70
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
54
71
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
55
72
  * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit.
56
73
  * @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
@@ -85,3 +102,8 @@ export interface VaultV2DepositParams {
85
102
  * ```
86
103
  */
87
104
  export declare const vaultV2Deposit: (params: VaultV2DepositParams) => Readonly<Transaction<VaultV2DepositAction>>;
105
+ /** Constructs the complete standalone deposit from raw funding and bounds. @internal */
106
+ export declare const parseVaultV2DepositInput: (params: VaultV2DepositParams) => VaultV2DepositInput;
107
+ /** Encodes parsed funding and binds the supplied token signature. @internal */
108
+ export declare const buildVaultV2Deposit: (parsed: VaultV2DepositInput, signatures?: Pick<VaultV2DepositParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV2DepositAction>>;
109
+ 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
  /**
@@ -19,7 +20,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
19
20
  * @param params.args.recipient - Unsupported; shares are always minted to the transaction sender.
20
21
  * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer signature
21
22
  * for the gross amount, vault asset, `userAddress`, and VaultBundlesV1 spender.
22
- * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
23
+ * @param params.args.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero.
23
24
  * The fee is rounded down and deducted from gross assets before depositing.
24
25
  * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
25
26
  * when `referralFeePct > 0n`.
@@ -37,6 +38,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
37
38
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
38
39
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
39
40
  * {@link InputExceedsMaxError}, so either class catches it.
41
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
40
42
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
41
43
  * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit.
42
44
  * @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
@@ -70,22 +72,55 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
70
72
  * }
71
73
  * ```
72
74
  */
73
- export const vaultV2Deposit = (params) => {
75
+ export const vaultV2Deposit = (params) => buildVaultV2Deposit(parseVaultV2DepositInput(params));
76
+ /** Constructs the complete standalone deposit from raw funding and bounds. @internal */
77
+ export const parseVaultV2DepositInput = (params) => {
74
78
  const funding = resolveBundlesFunding(params.args);
75
79
  if (params.args.maxSharePrice <= 0n) {
76
80
  throw new NonPositiveInputError("maxSharePrice", params.args.maxSharePrice);
77
81
  }
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);
82
+ // Check ABI bounds after both positive-only checks, preserving first-error order.
83
+ parseUint256(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
84
+ const maxSharePrice = parseUint256("maxSharePrice", params.args.maxSharePrice);
81
85
  if (funding.value > 0n) {
82
- // Reject native funding unless the vault accepts the chain's wrapped-native asset.
86
+ // Native deposits must wrap the vault's underlying asset.
83
87
  validateNativeVaultAsset(params.vault.chainId, params.vault.asset);
84
- if (params.args.requirementSignature != null) {
85
- throw new UnexpectedRequirementSignatureError(params.args.requirementSignature.action.type);
86
- }
88
+ }
89
+ // Standalone native/signature exclusivity precedes common-field validation.
90
+ if (funding.value > 0n && params.args.requirementSignature != null) {
91
+ throw new UnexpectedRequirementSignatureError(params.args.requirementSignature.action.type);
87
92
  }
88
93
  const common = normalizeBundlesCommonParams(params.args);
94
+ return {
95
+ vault: {
96
+ chainId: params.vault.chainId,
97
+ address: params.vault.address,
98
+ asset: params.vault.asset,
99
+ },
100
+ userAddress: params.args.userAddress,
101
+ funding,
102
+ maxSharePrice,
103
+ common,
104
+ metadata: params.metadata,
105
+ requirementSignature: params.args.requirementSignature,
106
+ };
107
+ };
108
+ /** Encodes parsed funding and binds the supplied token signature. @internal */
109
+ export const buildVaultV2Deposit = (parsed, signatures = parsed) => {
110
+ const { funding, common, maxSharePrice, vault, userAddress, metadata } = parsed;
111
+ const params = {
112
+ vault,
113
+ args: {
114
+ maxSharePrice,
115
+ userAddress,
116
+ requirementSignature: signatures.requirementSignature,
117
+ },
118
+ metadata,
119
+ };
120
+ // Signatures are supplied independently of parsed funding.
121
+ if (funding.value > 0n && signatures.requirementSignature != null) {
122
+ throw new UnexpectedRequirementSignatureError(signatures.requirementSignature.action.type);
123
+ }
89
124
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
90
125
  const netAssets = funding.assets - referralFeeAssets;
91
126
  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
  *
@@ -46,7 +63,7 @@ export interface VaultV2ForceWithdrawParams {
46
63
  * submitting account must equal this address.
47
64
  * @param params.args.deadline - Permit and bundle deadline.
48
65
  * @param params.args.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
49
- * `referralFeeRecipient`. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
66
+ * `referralFeeRecipient`, at most 10%. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
50
67
  * is outside that bound's protection.
51
68
  * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
52
69
  * address, which is only valid alongside a zero `referralFeePct`.
@@ -58,6 +75,7 @@ export interface VaultV2ForceWithdrawParams {
58
75
  * @throws {NegativeInputError} when `referralFeePct` or `minSharePriceE27` is negative.
59
76
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contract
60
77
  * rejects it with `PctExceeded`); it extends {@link InputExceedsMaxError}.
78
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
61
79
  * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
62
80
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
63
81
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
@@ -86,4 +104,9 @@ export interface VaultV2ForceWithdrawParams {
86
104
  * }
87
105
  * ```
88
106
  */
89
- export declare const vaultV2ForceWithdraw: ({ vault, args, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
107
+ export declare const vaultV2ForceWithdraw: (params: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
108
+ /** Runs standalone force-withdraw stages in their established order. @internal */
109
+ export declare const parseVaultV2ForceWithdraw: (params: VaultV2ForceWithdrawParams) => VaultV2ForceWithdrawInput;
110
+ /** Encodes parsed fields and binds a fresh share permit. @internal */
111
+ export declare const buildVaultV2ForceWithdraw: (parsed: VaultV2ForceWithdrawInput, signatures?: Pick<VaultV2ForceWithdrawParams["args"], "requirementSignature">) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
112
+ 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
  *
@@ -33,7 +33,7 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
33
33
  * submitting account must equal this address.
34
34
  * @param params.args.deadline - Permit and bundle deadline.
35
35
  * @param params.args.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
36
- * `referralFeeRecipient`. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
36
+ * `referralFeeRecipient`, at most 10%. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
37
37
  * is outside that bound's protection.
38
38
  * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
39
39
  * address, which is only valid alongside a zero `referralFeePct`.
@@ -45,6 +45,7 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
45
45
  * @throws {NegativeInputError} when `referralFeePct` or `minSharePriceE27` is negative.
46
46
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contract
47
47
  * rejects it with `PctExceeded`); it extends {@link InputExceedsMaxError}.
48
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
48
49
  * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
49
50
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
50
51
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
@@ -73,19 +74,39 @@ import { getBundlesSharesPermit } from "../bundles/common.js";
73
74
  * }
74
75
  * ```
75
76
  */
76
- export const vaultV2ForceWithdraw = ({ vault, args, metadata, }) => {
77
- if (args.exitAssets <= 0n) {
78
- throw new NonPositiveInputError("exitAssets", args.exitAssets);
77
+ export const vaultV2ForceWithdraw = (params) => buildVaultV2ForceWithdraw(parseVaultV2ForceWithdraw(params));
78
+ /** Runs standalone force-withdraw stages in their established order. @internal */
79
+ export const parseVaultV2ForceWithdraw = (params) => {
80
+ if (params.args.exitAssets <= 0n) {
81
+ throw new NonPositiveInputError("exitAssets", params.args.exitAssets);
79
82
  }
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);
83
+ const exitAssets = parseUint256("exitAssets", params.args.exitAssets);
84
+ const deadline = parseDeadline(params.args.deadline);
85
+ const minSharePriceE27 = parseUint256("minSharePriceE27", params.args.minSharePriceE27);
86
+ const referral = parseReferralFee(params.args);
87
+ return {
88
+ vault: { chainId: params.vault.chainId, address: params.vault.address },
89
+ args: {
90
+ adapter: params.args.adapter,
91
+ userAddress: params.args.userAddress,
92
+ exitAssets,
93
+ deadline,
94
+ minSharePriceE27,
95
+ },
96
+ referral,
97
+ metadata: params.metadata,
98
+ requirementSignature: params.args.requirementSignature,
99
+ };
100
+ };
101
+ /** Encodes parsed fields and binds a fresh share permit. @internal */
102
+ export const buildVaultV2ForceWithdraw = (parsed, signatures = parsed) => {
103
+ const { vault, metadata, referral: { referralFeePct, referralFeeRecipient }, } = parsed;
104
+ const args = {
105
+ ...parsed.args,
106
+ requirementSignature: signatures.requirementSignature,
107
+ };
87
108
  const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
88
- const sharesPermit = getBundlesSharesPermit({
109
+ const sharesPermit = getParsedBundlesSharesPermit({
89
110
  vault: vault.address,
90
111
  deadline: args.deadline,
91
112
  owner: args.userAddress,