@morpho-org/morpho-sdk 9.8.0 → 10.0.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 (303) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +109 -13
  3. package/lib/cjs/actions/blue/common.js +4 -2
  4. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  5. package/lib/cjs/actions/bundles/common.js +20 -14
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  8. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  9. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  10. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  11. package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
  12. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  13. package/lib/cjs/actions/midnight/index.js +1 -0
  14. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeLend.js +3 -2
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
  25. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  26. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  27. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
  34. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  35. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  36. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  37. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  38. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  39. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  40. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  41. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  42. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  43. package/lib/cjs/entities/blue/blue.js +107 -77
  44. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  45. package/lib/cjs/entities/midnight/deadline.js +4 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  47. package/lib/cjs/entities/midnight/midnight.js +158 -138
  48. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  49. package/lib/cjs/entities/midnight/publication.js +193 -138
  50. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  51. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  52. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  53. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
  54. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  55. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  57. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  58. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  59. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  60. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  61. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  62. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  63. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  64. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  65. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  66. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  67. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  68. package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
  69. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  70. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  71. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  72. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  73. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
  75. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
  76. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
  77. package/lib/cjs/errors.d.ts +1 -1
  78. package/lib/cjs/errors.js +2 -1
  79. package/lib/cjs/helpers/deadShares.js +83 -47
  80. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  81. package/lib/cjs/helpers/metadata.d.ts +14 -2
  82. package/lib/cjs/helpers/metadata.js +49 -8
  83. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
  84. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
  85. package/lib/cjs/helpers/utilization.js +10 -5
  86. package/lib/cjs/helpers/validate.js +88 -67
  87. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  88. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  89. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  90. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
  91. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  92. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  93. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  94. package/lib/cjs/index.d.ts +2 -2
  95. package/lib/cjs/index.js +10 -1
  96. package/lib/cjs/transactionPlan/approval.js +12 -1
  97. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  98. package/lib/cjs/transactionPlan/deposit.js +139 -0
  99. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  100. package/lib/cjs/transactionPlan/error.js +10 -8
  101. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  102. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  103. package/lib/cjs/transactionPlan/index.js +23 -5
  104. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  105. package/lib/cjs/transactionPlan/intent.js +14 -7
  106. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  107. package/lib/cjs/transactionPlan/permit.js +86 -20
  108. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  109. package/lib/cjs/transactionPlan/plan.js +77 -24
  110. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  111. package/lib/cjs/transactionPlan/redeem.js +63 -0
  112. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  113. package/lib/cjs/transactionPlan/requirements.js +12 -6
  114. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  115. package/lib/cjs/transactionPlan/serde.js +45 -19
  116. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  117. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  118. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  119. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  120. package/lib/cjs/transactionPlan/validation.js +6 -3
  121. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  122. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  123. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  124. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  125. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  126. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  127. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  128. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  129. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  130. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  131. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
  132. package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
  133. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  134. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  135. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  136. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  137. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  138. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  139. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  140. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  141. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  142. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
  143. package/lib/cjs/transactionPlan/version.js +2 -1
  144. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  145. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  146. package/lib/cjs/types/action.d.ts +26 -2
  147. package/lib/cjs/types/action.js +17 -9
  148. package/lib/cjs/types/error.d.ts +8 -1
  149. package/lib/cjs/types/error.js +21 -6
  150. package/lib/cjs/types/metadata.d.ts +12 -2
  151. package/lib/cjs/version.d.ts +1 -1
  152. package/lib/cjs/version.js +1 -1
  153. package/lib/esm/actions/blue/common.js +4 -2
  154. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  155. package/lib/esm/actions/bundles/common.js +20 -14
  156. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  157. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  158. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  159. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  160. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  161. package/lib/esm/actions/midnight/cancelOffers.js +104 -0
  162. package/lib/esm/actions/midnight/index.d.ts +1 -0
  163. package/lib/esm/actions/midnight/index.js +1 -0
  164. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  165. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  166. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  167. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  168. package/lib/esm/actions/midnight/takeBorrow.js +3 -2
  169. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  170. package/lib/esm/actions/midnight/takeLend.js +3 -2
  171. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  172. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  173. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  174. package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
  175. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  176. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  177. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  178. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  179. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  180. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  181. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  182. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  183. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
  184. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  185. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  186. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  187. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  188. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  189. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  190. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  191. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  192. package/lib/esm/entities/blue/blue.d.ts +34 -28
  193. package/lib/esm/entities/blue/blue.js +107 -77
  194. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  195. package/lib/esm/entities/midnight/deadline.js +4 -3
  196. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  197. package/lib/esm/entities/midnight/midnight.js +159 -139
  198. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  199. package/lib/esm/entities/midnight/publication.js +193 -138
  200. package/lib/esm/entities/midnight/types.d.ts +4 -4
  201. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  203. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
  204. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  205. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  206. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  207. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  208. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  209. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  210. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  211. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  212. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  213. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  214. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  215. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  216. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  217. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  218. package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
  219. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  220. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  221. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  222. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  223. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
  224. package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
  225. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
  226. package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
  227. package/lib/esm/errors.d.ts +1 -1
  228. package/lib/esm/errors.js +1 -1
  229. package/lib/esm/helpers/deadShares.js +83 -47
  230. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  231. package/lib/esm/helpers/metadata.d.ts +14 -2
  232. package/lib/esm/helpers/metadata.js +48 -8
  233. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
  234. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
  235. package/lib/esm/helpers/utilization.js +10 -5
  236. package/lib/esm/helpers/validate.js +88 -67
  237. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  238. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  239. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  240. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
  241. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  242. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  243. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  244. package/lib/esm/index.d.ts +2 -2
  245. package/lib/esm/index.js +1 -1
  246. package/lib/esm/transactionPlan/approval.js +13 -2
  247. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  248. package/lib/esm/transactionPlan/deposit.js +135 -0
  249. package/lib/esm/transactionPlan/error.d.ts +10 -8
  250. package/lib/esm/transactionPlan/error.js +10 -8
  251. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  252. package/lib/esm/transactionPlan/index.d.ts +18 -0
  253. package/lib/esm/transactionPlan/index.js +9 -0
  254. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  255. package/lib/esm/transactionPlan/intent.js +14 -7
  256. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  257. package/lib/esm/transactionPlan/permit.js +86 -20
  258. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  259. package/lib/esm/transactionPlan/plan.js +73 -20
  260. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  261. package/lib/esm/transactionPlan/redeem.js +59 -0
  262. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  263. package/lib/esm/transactionPlan/requirements.js +12 -6
  264. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  265. package/lib/esm/transactionPlan/serde.js +45 -19
  266. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  267. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  268. package/lib/esm/transactionPlan/types.d.ts +117 -11
  269. package/lib/esm/transactionPlan/validateActions.js +11 -1
  270. package/lib/esm/transactionPlan/validation.js +6 -3
  271. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  272. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  273. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  274. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  275. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  276. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  277. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  278. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  279. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  280. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  281. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
  282. package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
  283. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  284. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  285. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  286. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  287. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  288. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  289. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  290. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  291. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  292. package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
  293. package/lib/esm/transactionPlan/version.js +2 -1
  294. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  295. package/lib/esm/transactionPlan/withdraw.js +90 -0
  296. package/lib/esm/types/action.d.ts +26 -2
  297. package/lib/esm/types/action.js +17 -9
  298. package/lib/esm/types/error.d.ts +8 -1
  299. package/lib/esm/types/error.js +21 -6
  300. package/lib/esm/types/metadata.d.ts +12 -2
  301. package/lib/esm/version.d.ts +1 -1
  302. package/lib/esm/version.js +1 -1
  303. package/package.json +15 -14
@@ -17,8 +17,9 @@ const getTokenPermit_js_1 = require("./getTokenPermit.js");
17
17
  */
18
18
  function buildPermitSignatureRequest(requirement, id) {
19
19
  const { nonce, ...args } = requirement.action.args;
20
- if (nonce === undefined)
20
+ if (nonce === undefined) {
21
21
  throw new error_js_1.UnexpectedRequirementSignatureError(requirement.action.type);
22
+ }
22
23
  return {
23
24
  id,
24
25
  kind: "permit",
@@ -29,10 +30,10 @@ function buildPermitSignatureRequest(requirement, id) {
29
30
  /**
30
31
  * @internal Converts an approval transaction into a step with prepared chain/account inputs.
31
32
  * @param requirement - Direct token approval prerequisite.
32
- * @param params - Step ID, chain and account selected by the preparer.
33
+ * @param params - Step ID, chain, account and token denomination selected by the preparer.
33
34
  * @returns The approval recipe labeled for token spending.
34
35
  */
35
- function buildApprovalStep(requirement, { id, chainId, account, }) {
36
+ function buildApprovalStep(requirement, { id, chainId, account, denomination, }) {
36
37
  return {
37
38
  id,
38
39
  label: "Approve token spending",
@@ -40,7 +41,10 @@ function buildApprovalStep(requirement, { id, chainId, account, }) {
40
41
  type: "erc20Approval",
41
42
  inputs: {
42
43
  token: requirement.to,
43
- ...requirement.action.args,
44
+ spender: requirement.action.args.spender,
45
+ ...(denomination === "assets"
46
+ ? { assets: requirement.action.args.amount }
47
+ : { shares: requirement.action.args.amount }),
44
48
  chainId,
45
49
  account,
46
50
  },
@@ -60,15 +64,17 @@ async function getTokenRequirements(client, params) {
60
64
  functionName: "allowance",
61
65
  args: [params.owner, params.spender],
62
66
  });
63
- if (allowance >= params.amount)
67
+ if (allowance >= params.amount) {
64
68
  return [];
69
+ }
65
70
  if (params.supportSignature) {
66
71
  const permit = await (0, getTokenPermit_js_1.getTokenPermit)(client, {
67
72
  ...params,
68
73
  supportDeployless: params.deployless,
69
74
  });
70
- if (permit !== undefined)
75
+ if (permit !== undefined) {
71
76
  return [permit];
77
+ }
72
78
  }
73
79
  return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
74
80
  address: params.token,
@@ -1,5 +1,6 @@
1
1
  import type { TransactionPlan } from "./types.js";
2
2
  /**
3
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
3
4
  * Serializes plan data with a bigint replacer. No validation is performed.
4
5
  * @param plan - Plan to save.
5
6
  * @returns JSON with `$bigint` tags for bigint quantities.
@@ -8,10 +9,10 @@ import type { TransactionPlan } from "./types.js";
8
9
  * import { serializeTransactionPlan, type TransactionPlan } from "@morpho-org/morpho-sdk";
9
10
  * const save = (plan: TransactionPlan) => serializeTransactionPlan(plan);
10
11
  * ```
11
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
12
12
  */
13
13
  export declare function serializeTransactionPlan(plan: TransactionPlan): string;
14
14
  /**
15
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
15
16
  * Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
16
17
  * references, per-action chain/account and permit/action consistency, including signed requests.
17
18
  * Extra keys are allowed. No clock or RPC is used: expiry, live state, signature ownership and
@@ -28,6 +29,5 @@ export declare function serializeTransactionPlan(plan: TransactionPlan): string;
28
29
  * import { parseTransactionPlan } from "@morpho-org/morpho-sdk";
29
30
  * const restore = (saved: string) => parseTransactionPlan(saved);
30
31
  * ```
31
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
32
32
  */
33
33
  export declare function parseTransactionPlan(json: string): TransactionPlan;
@@ -4,20 +4,36 @@ exports.serializeTransactionPlan = serializeTransactionPlan;
4
4
  exports.parseTransactionPlan = parseTransactionPlan;
5
5
  const viem_1 = require("viem");
6
6
  const approval_js_1 = require("./approval.js");
7
+ const deposit_js_1 = require("./deposit.js");
7
8
  const error_js_1 = require("./error.js");
8
9
  const permit_js_1 = require("./permit.js");
9
10
  const plan_js_1 = require("./plan.js");
11
+ const redeem_js_1 = require("./redeem.js");
10
12
  const validateActions_js_1 = require("./validateActions.js");
11
13
  const validation_js_1 = require("./validation.js");
12
- const deposit_js_1 = require("./vaultv2/deposit.js");
13
- const withdraw_js_1 = require("./vaultv2/withdraw.js");
14
+ const inKindRedeem_js_1 = require("./vaultv1/inKindRedeem.js");
15
+ const migrateToV2_js_1 = require("./vaultv1/migrateToV2.js");
16
+ const forceRedeem_js_1 = require("./vaultv2/forceRedeem.js");
17
+ const forceWithdraw_js_1 = require("./vaultv2/forceWithdraw.js");
18
+ const inKindRedeem_js_2 = require("./vaultv2/inKindRedeem.js");
14
19
  const version_js_1 = require("./version.js");
20
+ const withdraw_js_1 = require("./withdraw.js");
15
21
  const actionValidators = {
22
+ vaultV1InKindRedeem: inKindRedeem_js_1.validateInKindRedeemPlanAction,
16
23
  erc20Approval: approval_js_1.validateApprovalPlanAction,
24
+ vaultV2Redeem: redeem_js_1.validateRedeemPlanAction,
25
+ vaultV2ForceWithdraw: forceWithdraw_js_1.validateForceWithdrawPlanAction,
26
+ vaultV1Deposit: deposit_js_1.validateDepositPlanAction,
27
+ vaultV1Redeem: redeem_js_1.validateRedeemPlanAction,
28
+ vaultV1MigrateToV2: migrateToV2_js_1.validateMigrateToV2PlanAction,
17
29
  vaultV2Deposit: deposit_js_1.validateDepositPlanAction,
18
30
  vaultV2Withdraw: withdraw_js_1.validateWithdrawPlanAction,
31
+ vaultV2ForceRedeem: forceRedeem_js_1.validateForceRedeemPlanAction,
32
+ vaultV1Withdraw: withdraw_js_1.validateWithdrawPlanAction,
33
+ vaultV2InKindRedeem: inKindRedeem_js_2.validateInKindRedeemPlanAction,
19
34
  };
20
35
  /**
36
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
21
37
  * Serializes plan data with a bigint replacer. No validation is performed.
22
38
  * @param plan - Plan to save.
23
39
  * @returns JSON with `$bigint` tags for bigint quantities.
@@ -26,7 +42,6 @@ const actionValidators = {
26
42
  * import { serializeTransactionPlan, type TransactionPlan } from "@morpho-org/morpho-sdk";
27
43
  * const save = (plan: TransactionPlan) => serializeTransactionPlan(plan);
28
44
  * ```
29
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
30
45
  */
31
46
  function serializeTransactionPlan(plan) {
32
47
  return JSON.stringify(plan, function (key) {
@@ -36,6 +51,7 @@ function serializeTransactionPlan(plan) {
36
51
  });
37
52
  }
38
53
  /**
54
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
39
55
  * Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
40
56
  * references, per-action chain/account and permit/action consistency, including signed requests.
41
57
  * Extra keys are allowed. No clock or RPC is used: expiry, live state, signature ownership and
@@ -52,7 +68,6 @@ function serializeTransactionPlan(plan) {
52
68
  * import { parseTransactionPlan } from "@morpho-org/morpho-sdk";
53
69
  * const restore = (saved: string) => parseTransactionPlan(saved);
54
70
  * ```
55
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
56
71
  */
57
72
  function parseTransactionPlan(json) {
58
73
  let restored;
@@ -84,11 +99,12 @@ function parseTransactionPlan(json) {
84
99
  signatureRequests: "array",
85
100
  },
86
101
  });
87
- if (plan.calldataOrigin !== undefined)
102
+ if (plan.calldataOrigin !== undefined) {
88
103
  (0, validation_js_1.validatePlanField)(plan.calldataOrigin, {
89
104
  path: "$.calldataOrigin",
90
105
  type: "hex",
91
106
  });
107
+ }
92
108
  const steps = plan.steps;
93
109
  const requests = plan.signatureRequests;
94
110
  const stepIds = new Set();
@@ -99,11 +115,12 @@ function parseTransactionPlan(json) {
99
115
  path,
100
116
  fields: { id: "string", label: "string" },
101
117
  });
102
- if (stepIds.has(step.id))
118
+ if (stepIds.has(step.id)) {
103
119
  throw new error_js_1.InvalidTransactionPlanError({
104
120
  path: `${path}.id`,
105
121
  reason: "expected a unique step ID",
106
122
  });
123
+ }
107
124
  stepIds.add(step.id);
108
125
  const action = (0, validation_js_1.getPlanObject)(step.action, `${path}.action`);
109
126
  (0, validation_js_1.validatePlanField)(action.type, {
@@ -122,16 +139,18 @@ function parseTransactionPlan(json) {
122
139
  fields: { chainId: "positive safe integer", account: "address" },
123
140
  });
124
141
  actionValidators[step.action.type](action, path);
125
- if (inputs.chainId !== plan.chainId)
142
+ if (inputs.chainId !== plan.chainId) {
126
143
  throw new error_js_1.InvalidTransactionPlanError({
127
144
  path: `${path}.inputs.chainId`,
128
145
  reason: "expected the plan chainId",
129
146
  });
130
- if (!(0, viem_1.isAddressEqual)(inputs.account, plan.account))
147
+ }
148
+ if (!(0, viem_1.isAddressEqual)(inputs.account, plan.account)) {
131
149
  throw new error_js_1.InvalidTransactionPlanError({
132
150
  path: `${path}.inputs.account`,
133
151
  reason: "expected the plan account",
134
152
  });
153
+ }
135
154
  }
136
155
  const requestIds = new Set();
137
156
  for (const [index, value] of requests.entries()) {
@@ -141,31 +160,35 @@ function parseTransactionPlan(json) {
141
160
  path,
142
161
  fields: { id: "string", kind: "string" },
143
162
  });
144
- if (requestIds.has(request.id))
163
+ if (requestIds.has(request.id)) {
145
164
  throw new error_js_1.InvalidTransactionPlanError({
146
165
  path: `${path}.id`,
147
166
  reason: "expected a unique signature request ID",
148
167
  });
168
+ }
149
169
  requestIds.add(request.id);
150
- if (request.kind !== "permit")
170
+ if (request.kind !== "permit") {
151
171
  throw new error_js_1.InvalidTransactionPlanError({
152
172
  path: `${path}.kind`,
153
173
  reason: "expected a supported signature request kind (permit)",
154
174
  });
175
+ }
155
176
  (0, permit_js_1.validatePermitPlanRequest)(request, path);
156
177
  }
157
178
  for (const [index, step] of steps.entries()) {
158
- if (!("signatureRequestIds" in step.action))
179
+ if (!("signatureRequestIds" in step.action)) {
159
180
  continue;
181
+ }
160
182
  const path = `$.steps[${index}].action.signatureRequestIds`;
161
183
  const ids = (0, validation_js_1.getPlanObject)(step.action.signatureRequestIds, path);
162
184
  for (const [role, id] of Object.entries(ids)) {
163
185
  (0, validation_js_1.validatePlanField)(id, { path: `${path}.${role}`, type: "string" });
164
- if (!requestIds.has(id))
186
+ if (!requestIds.has(id)) {
165
187
  throw new error_js_1.InvalidTransactionPlanError({
166
188
  path: `${path}.${role}`,
167
189
  reason: "expected an existing signature request ID",
168
190
  });
191
+ }
169
192
  }
170
193
  }
171
194
  const result = restored;
@@ -182,13 +205,16 @@ function parseTransactionPlan(json) {
182
205
  catch (cause) {
183
206
  if (cause instanceof error_js_1.TransactionPlanSignatureMismatchError) {
184
207
  const index = result.signatureRequests.findIndex((request) => request.id === cause.id);
185
- const field = cause.field === "reference"
186
- ? "id"
187
- : cause.field === "value"
188
- ? "args.amount"
189
- : cause.field.startsWith("args.")
190
- ? cause.field
191
- : `typedData.${cause.field}`;
208
+ let field = `typedData.${cause.field}`;
209
+ if (cause.field === "reference") {
210
+ field = "id";
211
+ }
212
+ else if (cause.field === "value") {
213
+ field = "args.amount";
214
+ }
215
+ else if (cause.field.startsWith("args.")) {
216
+ field = cause.field;
217
+ }
192
218
  throw new error_js_1.InvalidTransactionPlanError({
193
219
  path: `$.signatureRequests[${index}].${field}`,
194
220
  reason: "expected agreement with every referencing action",
@@ -0,0 +1,18 @@
1
+ import type { Token } from "@morpho-org/blue-sdk";
2
+ import type { Address, Client } from "viem";
3
+ import type { SignatureRequest, Step } from "./types.js";
4
+ /** @internal Resolves unlimited share authorization after chain validation in each read path. */
5
+ export declare function getVaultShareSpendingRequirements(client: Client, params: {
6
+ readonly type: "vaultV1MigrateToV2" | "vaultV1Withdraw" | "vaultV2Withdraw" | "vaultV1Redeem" | "vaultV2Redeem";
7
+ readonly shareToken: Token;
8
+ readonly account: Address;
9
+ readonly chainId: number;
10
+ readonly requiredShareAllowance: bigint;
11
+ readonly deadline: bigint;
12
+ readonly supportSignature: boolean;
13
+ readonly now: bigint;
14
+ }): Promise<{
15
+ approvals: Step<import("./types.js").Action>[];
16
+ signatureRequests: SignatureRequest[];
17
+ tokenPermitRequestId: string;
18
+ }>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVaultShareSpendingRequirements = getVaultShareSpendingRequirements;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const validateClientChainId_js_1 = require("../actions/requirements/validateClientChainId.js");
6
+ const assertContractCode_js_1 = require("../entities/requirements/assertContractCode.js");
7
+ const getVaultBundlesSharesRequirements_js_1 = require("../entities/requirements/getVaultBundlesSharesRequirements.js");
8
+ const validate_js_1 = require("../helpers/validate.js");
9
+ const requirements_js_1 = require("./requirements.js");
10
+ /** @internal Resolves unlimited share authorization after chain validation in each read path. */
11
+ async function getVaultShareSpendingRequirements(client, params) {
12
+ const { type, chainId, account } = params;
13
+ // Reject a declared chain mismatch before starting concurrent reads.
14
+ (0, validate_js_1.validateChainId)(client.chain?.id, chainId);
15
+ const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
16
+ const [, , requirements] = await Promise.all([
17
+ (0, validateClientChainId_js_1.validateClientChainId)(client, chainId),
18
+ (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
19
+ { role: "bundles.vaultBundlesV1", address: spender },
20
+ ]),
21
+ (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(client, {
22
+ vaultData: params.shareToken,
23
+ version: type.startsWith("vaultV1") ? "vaultV1" : "vaultV2",
24
+ owner: account,
25
+ chainId,
26
+ requiredShareAllowance: params.requiredShareAllowance,
27
+ deadline: params.deadline,
28
+ supportSignature: params.supportSignature,
29
+ now: params.now,
30
+ }),
31
+ ]);
32
+ const approvals = [];
33
+ const signatureRequests = [];
34
+ const tokenPermitRequestId = `${type}:tokenPermit`;
35
+ const requirement = requirements[0];
36
+ if (requirement !== undefined) {
37
+ if ("sign" in requirement) {
38
+ signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
39
+ }
40
+ else {
41
+ approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
42
+ id: `${type}:approval`,
43
+ chainId,
44
+ account,
45
+ denomination: "shares",
46
+ }));
47
+ }
48
+ }
49
+ return { approvals, signatureRequests, tokenPermitRequestId };
50
+ }
@@ -1,9 +1,16 @@
1
+ import type { InputMarketParams } from "@morpho-org/blue-sdk";
1
2
  import type { Address, Hex } from "viem";
2
- import type { BundlesFundingArgs, PermitAction, RequirementTypedData } from "../types/index.js";
3
+ import type { PermitAction, RequirementTypedData, VaultV1MigrateToV2AmountArgs } from "../types/index.js";
3
4
  interface ActionInputs {
4
5
  readonly chainId: number;
5
6
  readonly account: Address;
6
7
  }
8
+ /** Plain deallocation fields persisted by force-redeem plans, without class-derived values. */
9
+ interface StoredDeallocation {
10
+ readonly adapter: Address;
11
+ readonly assets: bigint;
12
+ readonly marketParams?: InputMarketParams;
13
+ }
7
14
  interface VaultInputs extends ActionInputs {
8
15
  readonly vault: Address;
9
16
  readonly deadline: bigint;
@@ -16,41 +23,140 @@ type VaultSignatureRequestIds = {
16
23
  readonly tokenPermit?: string;
17
24
  };
18
25
  /**
19
- * Recipes supported by Vault V2 plans. Each `type` equals the `action.type` of the
26
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
27
+ * Recipes supported by vault plans. Each `type` equals the `action.type` of the
20
28
  * {@link TransactionAction} it builds.
21
29
  * Snapshot-derived values such as the asset and the quote are fixed on `inputs` at preparation;
22
30
  * each action also carries its own chain and account on `inputs`.
23
31
  * the role map `signatureRequestIds` is a step's only request reference.
24
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
25
32
  */
26
33
  export type Action = {
34
+ readonly type: "vaultV2ForceRedeem";
35
+ readonly inputs: ActionInputs & {
36
+ readonly vault: Address;
37
+ readonly redeem: {
38
+ readonly shares: bigint;
39
+ };
40
+ readonly deallocations: readonly StoredDeallocation[];
41
+ };
42
+ } | {
43
+ readonly type: "vaultV1Redeem";
44
+ readonly inputs: VaultInputs & {
45
+ readonly shares: bigint;
46
+ };
47
+ readonly signatureRequestIds: VaultSignatureRequestIds;
48
+ } | {
49
+ readonly type: "vaultV1MigrateToV2";
50
+ readonly inputs: ActionInputs & VaultV1MigrateToV2AmountArgs & {
51
+ readonly sourceVault: Address;
52
+ readonly targetVault: Address;
53
+ readonly asset: Address;
54
+ readonly maxSharePrice: bigint;
55
+ readonly vault: Address;
56
+ readonly requiredShareAllowance: bigint;
57
+ readonly deadline: bigint;
58
+ readonly referralFeePct: bigint;
59
+ readonly referralFeeRecipient: Address;
60
+ };
61
+ readonly signatureRequestIds: VaultSignatureRequestIds;
62
+ } | {
63
+ readonly type: "vaultV1InKindRedeem";
64
+ readonly inputs: ActionInputs & {
65
+ readonly vault: Address;
66
+ readonly assets: bigint;
67
+ readonly deadline: bigint;
68
+ readonly marketParamsList: readonly InputMarketParams[];
69
+ };
70
+ readonly signatureRequestIds: VaultSignatureRequestIds;
71
+ } | {
27
72
  readonly type: "erc20Approval";
28
73
  readonly inputs: ActionInputs & {
29
74
  readonly token: Address;
30
75
  readonly spender: Address;
31
- readonly amount: bigint;
32
- };
76
+ } & ({
77
+ readonly assets: bigint;
78
+ readonly shares?: never;
79
+ } | {
80
+ readonly shares: bigint;
81
+ readonly assets?: never;
82
+ });
33
83
  } | {
34
84
  readonly type: "vaultV2Deposit";
35
- readonly inputs: VaultInputs & BundlesFundingArgs & {
85
+ readonly inputs: VaultInputs & ({
86
+ readonly assets: bigint;
87
+ readonly nativeAssets?: never;
88
+ } | {
89
+ readonly nativeAssets: bigint;
90
+ readonly assets?: never;
91
+ }) & {
92
+ /** Vault asset read from the snapshot. */
93
+ readonly asset: Address;
94
+ /** Deadline-accrued RAY-scaled bound quoted from the snapshot for the net deposit. */
95
+ readonly maxSharePrice: bigint;
96
+ };
97
+ readonly signatureRequestIds: VaultSignatureRequestIds;
98
+ } | {
99
+ readonly type: "vaultV1Deposit";
100
+ readonly inputs: VaultInputs & ({
101
+ readonly assets: bigint;
102
+ readonly nativeAssets?: never;
103
+ } | {
104
+ readonly nativeAssets: bigint;
105
+ readonly assets?: never;
106
+ }) & {
36
107
  /** Vault asset read from the snapshot. */
37
108
  readonly asset: Address;
38
109
  /** Deadline-accrued RAY-scaled bound quoted from the snapshot for the net deposit. */
39
110
  readonly maxSharePrice: bigint;
40
111
  };
41
112
  readonly signatureRequestIds: VaultSignatureRequestIds;
113
+ } | {
114
+ readonly type: "vaultV1Withdraw";
115
+ readonly inputs: VaultInputs & {
116
+ readonly assets: bigint;
117
+ /** Minimum share allowance quoted from the snapshot for the gross withdrawal. */
118
+ readonly requiredShareAllowance: bigint;
119
+ };
120
+ readonly signatureRequestIds: VaultSignatureRequestIds;
121
+ } | {
122
+ readonly type: "vaultV2InKindRedeem";
123
+ readonly inputs: ActionInputs & {
124
+ readonly vault: Address;
125
+ readonly adapter: Address;
126
+ readonly assets: bigint;
127
+ readonly deadline: bigint;
128
+ readonly marketParamsList: readonly InputMarketParams[];
129
+ };
130
+ readonly signatureRequestIds: VaultSignatureRequestIds;
42
131
  } | {
43
132
  readonly type: "vaultV2Withdraw";
44
133
  readonly inputs: VaultInputs & {
45
- readonly amount: bigint;
134
+ readonly assets: bigint;
46
135
  /** Minimum share allowance quoted from the snapshot for the gross withdrawal. */
47
136
  readonly requiredShareAllowance: bigint;
48
137
  };
49
138
  readonly signatureRequestIds: VaultSignatureRequestIds;
139
+ } | {
140
+ readonly type: "vaultV2Redeem";
141
+ readonly inputs: VaultInputs & {
142
+ /** Exact shares to burn; no quote is required. */
143
+ readonly shares: bigint;
144
+ };
145
+ readonly signatureRequestIds: VaultSignatureRequestIds;
146
+ } | {
147
+ readonly type: "vaultV2ForceWithdraw";
148
+ readonly inputs: VaultInputs & {
149
+ readonly adapter: Address;
150
+ /** Penalty-inclusive assets debited from the account's position. */
151
+ readonly assets: bigint;
152
+ /** Snapshot-derived lower bound on the realized exit share price. */
153
+ readonly minSharePriceE27: bigint;
154
+ };
155
+ readonly signatureRequestIds: VaultSignatureRequestIds;
50
156
  };
51
157
  /**
52
- * A recipe with a plan-unique `id`; its request dependencies are the roles its action names.
53
158
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
159
+ * A recipe with a plan-unique `id`; its request dependencies are the roles its action names.
54
160
  */
55
161
  export interface Step<TAction extends Action = Action> {
56
162
  readonly id: string;
@@ -58,9 +164,9 @@ export interface Step<TAction extends Action = Action> {
58
164
  readonly action: TAction;
59
165
  }
60
166
  /**
167
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
61
168
  * ERC-2612 permit request exposed as `{ id, kind, typedData }`. `signature` is undefined until the
62
169
  * account signs `typedData`. Protocol milestones add further `kind`s such as Blue authorization.
63
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
64
170
  */
65
171
  export interface SignatureRequest {
66
172
  readonly id: string;
@@ -72,13 +178,13 @@ export interface SignatureRequest {
72
178
  readonly signature?: Hex;
73
179
  }
74
180
  /**
181
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
75
182
  * Data-only operation prepared for one chain and account from the caller's intent and a vault
76
183
  * snapshot. Every step and signature request carries its own `id`, unique within the plan. Once
77
184
  * prepared, a plan is static: only signatures are added before building.
78
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
79
185
  */
80
186
  export interface TransactionPlan {
81
- readonly version: 1;
187
+ readonly version: 2;
82
188
  readonly chainId: number;
83
189
  readonly account: Address;
84
190
  /** Unix seconds. One expiry governs every step deadline and signature deadline. */
@@ -12,8 +12,18 @@ function validateTransactionPlanActions(steps) {
12
12
  for (const step of steps) {
13
13
  const actionType = step.action.type;
14
14
  if (actionType !== "erc20Approval" &&
15
+ actionType !== "vaultV1Deposit" &&
16
+ actionType !== "vaultV1MigrateToV2" &&
17
+ actionType !== "vaultV1InKindRedeem" &&
15
18
  actionType !== "vaultV2Deposit" &&
16
- actionType !== "vaultV2Withdraw")
19
+ actionType !== "vaultV2Withdraw" &&
20
+ actionType !== "vaultV2Redeem" &&
21
+ actionType !== "vaultV2ForceWithdraw" &&
22
+ actionType !== "vaultV2ForceRedeem" &&
23
+ actionType !== "vaultV1Withdraw" &&
24
+ actionType !== "vaultV1Redeem" &&
25
+ actionType !== "vaultV2InKindRedeem") {
17
26
  throw new error_js_1.UnsupportedTransactionPlanActionError(actionType);
27
+ }
18
28
  }
19
29
  }
@@ -35,22 +35,25 @@ function validatePlanField(value, options) {
35
35
  valid = Array.isArray(value);
36
36
  break;
37
37
  }
38
- if (!valid)
38
+ if (!valid) {
39
39
  throw new error_js_1.InvalidTransactionPlanError({ path, reason: `expected ${type}` });
40
+ }
40
41
  }
41
42
  /** @internal Requires a non-null, non-array JSON object. */
42
43
  function getPlanObject(value, path) {
43
- if (typeof value !== "object" || value === null || Array.isArray(value))
44
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
44
45
  throw new error_js_1.InvalidTransactionPlanError({
45
46
  path,
46
47
  reason: "expected an object",
47
48
  });
49
+ }
48
50
  return value;
49
51
  }
50
52
  /** @internal Validates required fields while permitting additional keys. */
51
53
  function validatePlanFields(value, options) {
52
- for (const [key, type] of Object.entries(options.fields))
54
+ for (const [key, type] of Object.entries(options.fields)) {
53
55
  validatePlanField(value[key], { path: `${options.path}.${key}`, type });
56
+ }
54
57
  }
55
58
  /** @internal Validates the shared stored vault-action fields and role map. */
56
59
  function validateVaultPlanAction(action, path) {
@@ -0,0 +1,93 @@
1
+ import type { AccrualVault } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import type { Transaction, VaultV1DepositAction } from "../../types/index.js";
4
+ import { type DepositPlanParams } from "../deposit.js";
5
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
6
+ /**
7
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
8
+ * Caller intent for a Vault V1 (MetaMorpho) deposit, mirroring the Actions API deposit inputs,
9
+ * plus the snapshot. The fields match `VaultV2DepositPlanParams` except for the snapshot type.
10
+ * @example
11
+ * ```ts
12
+ * import { vaults } from "@morpho-org/morpho-test";
13
+ * import type { VaultV1DepositPlanParams } from "@morpho-org/morpho-sdk";
14
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
15
+ * import { type Address, createPublicClient, http } from "viem";
16
+ * import { mainnet } from "viem/chains";
17
+ *
18
+ * export async function steakUsdcDepositParams(account: Address) {
19
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
20
+ * const vault = vaults[mainnet.id].steakUsdc.address;
21
+ * const params: VaultV1DepositPlanParams = {
22
+ * chainId: mainnet.id, account, assets: 1_000_000n,
23
+ * vault: await fetchAccrualVault(vault, client),
24
+ * };
25
+ * // params satisfies VaultV1DepositPlanParams
26
+ * return params;
27
+ * }
28
+ * ```
29
+ */
30
+ export interface VaultV1DepositPlanParams extends DepositPlanParams<AccrualVault> {
31
+ }
32
+ /**
33
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
34
+ * Prepares a Vault V1 (MetaMorpho) deposit plan through VaultBundlesV1 from caller intent and a
35
+ * vault snapshot, reading the token prerequisites directly. The built deposit matches the
36
+ * `vaultV1(...).deposit(...)` handle's `buildTx()` for the same inputs. The quote is fixed on the deposit step at preparation, so the returned plan is static:
37
+ * only signatures are added before building.
38
+ * @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
39
+ * @param params.vault - Caller-fetched AccrualVault snapshot used for the quote; its address identifies the vault.
40
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
41
+ * @param params.account - Non-zero account funding, signing and sending the deposit.
42
+ * @param params.assets - Positive gross deposit in asset base units, before referral fees.
43
+ * @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
44
+ * @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
45
+ * @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
46
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
47
+ * @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
48
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
49
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
50
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
51
+ * @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
52
+ * @returns A plan with approvals, concrete signature requests and the deposit step.
53
+ * @throws {ZeroAccountError} when `account` is the zero address.
54
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
55
+ * @throws {NonPositiveInputError} when `expiresAt`, `assets`, net assets or previewed shares are not positive.
56
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
57
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
58
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
59
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
60
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
61
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
62
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
63
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
64
+ * @throws {ChainIdMismatchError} when the client targets another chain.
65
+ * @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
66
+ * @see computeVaultMaxSharePrice for quote errors.
67
+ * @example
68
+ * ```ts
69
+ * import { vaults } from "@morpho-org/morpho-test";
70
+ * import { prepareVaultV1Deposit } from "@morpho-org/morpho-sdk";
71
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
72
+ * import { type Address, createPublicClient, http } from "viem";
73
+ * import { mainnet } from "viem/chains";
74
+ *
75
+ * export async function prepareSteakUsdcDeposit(account: Address) {
76
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
77
+ * const vault = vaults[mainnet.id].steakUsdc.address;
78
+ * const plan = await prepareVaultV1Deposit(client, {
79
+ * chainId: mainnet.id, account, assets: 1_000_000n, supportSignature: true,
80
+ * vault: await fetchAccrualVault(vault, client),
81
+ * now: (await client.getBlock()).timestamp,
82
+ * });
83
+ * // plan satisfies TransactionPlan: approval or permit request, then the vaultV1Deposit step.
84
+ * // Sign the pending requests, applySignatures, then build.
85
+ * return plan;
86
+ * }
87
+ * ```
88
+ */
89
+ export declare function prepareVaultV1Deposit(client: Client, params: VaultV1DepositPlanParams): Promise<TransactionPlan>;
90
+ /** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
91
+ export declare function buildVaultV1Deposit(action: Extract<Action, {
92
+ type: "vaultV1Deposit";
93
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1DepositAction>>;