@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
@@ -8,8 +8,9 @@ const error_js_1 = require("./error.js");
8
8
  const BASIS_POINTS = 10000n;
9
9
  const WAD_PER_BASIS_POINT = morpho_ts_1.MathLib.WAD / BASIS_POINTS;
10
10
  function toSafeInteger(field, value) {
11
- if (!Number.isSafeInteger(value))
11
+ if (!Number.isSafeInteger(value)) {
12
12
  throw new error_js_1.NonIntegerInputError(field, value);
13
+ }
13
14
  return BigInt(value);
14
15
  }
15
16
  /**
@@ -17,31 +18,37 @@ function toSafeInteger(field, value) {
17
18
  * signature support and calldata origin. Throws on invalid values so a plan never carries them.
18
19
  */
19
20
  function resolveIntent(params, now) {
20
- if (params.account === viem_1.zeroAddress)
21
+ if (params.account === viem_1.zeroAddress) {
21
22
  throw new error_js_1.ZeroAccountError(params.account);
23
+ }
22
24
  const expiresAt = params.expiresAt ?? Number(now + morpho_ts_1.Time.s.from.h(2n));
23
25
  const deadline = toSafeInteger("expiresAt", expiresAt);
24
- if (deadline <= 0n)
26
+ if (deadline <= 0n) {
25
27
  throw new index_js_1.NonPositiveInputError("expiresAt", deadline);
26
- if (deadline <= now)
28
+ }
29
+ if (deadline <= now) {
27
30
  throw new index_js_1.ExpiredDeadlineError(deadline, now);
31
+ }
28
32
  const bps = params.referralFee === undefined
29
33
  ? 0n
30
34
  : toSafeInteger("referralFee.bps", params.referralFee.bps);
31
- if (bps < 0n)
35
+ if (bps < 0n) {
32
36
  throw new index_js_1.NegativeInputError("referralFee.bps", bps);
33
- if (bps > BASIS_POINTS)
37
+ }
38
+ if (bps > BASIS_POINTS) {
34
39
  throw new index_js_1.InputExceedsMaxError({
35
40
  field: "referralFee.bps",
36
41
  value: bps,
37
42
  max: BASIS_POINTS,
38
43
  });
44
+ }
39
45
  const { calldataOrigin } = params;
40
46
  if (calldataOrigin !== undefined &&
41
47
  (!(0, viem_1.isHex)(calldataOrigin, { strict: true }) ||
42
48
  calldataOrigin.length <= 2 ||
43
- calldataOrigin.length % 2 !== 0))
49
+ calldataOrigin.length % 2 !== 0)) {
44
50
  throw new error_js_1.InvalidCalldataOriginError(calldataOrigin);
51
+ }
45
52
  return {
46
53
  expiresAt: Number(deadline),
47
54
  deadline,
@@ -1,4 +1,4 @@
1
- import type { Address } from "viem";
1
+ import { type Address } from "viem";
2
2
  import type { Erc2612RequirementSignature } from "../types/index.js";
3
3
  import type { Action, SignatureRequest } from "./types.js";
4
4
  /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
@@ -4,6 +4,7 @@ exports.validatePermitPlanRequest = validatePermitPlanRequest;
4
4
  exports.validateSignatureRequest = validateSignatureRequest;
5
5
  exports.getVaultPermit = getVaultPermit;
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const viem_1 = require("viem");
7
8
  const error_js_1 = require("./error.js");
8
9
  const validation_js_1 = require("./validation.js");
9
10
  /** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
@@ -28,17 +29,20 @@ function validatePermitPlanRequest(request, path) {
28
29
  path: `${path}.typedData.domain`,
29
30
  fields: { chainId: "positive safe integer", verifyingContract: "address" },
30
31
  });
31
- for (const field of ["name", "version"])
32
- if (domain[field] !== undefined)
32
+ for (const field of ["name", "version"]) {
33
+ if (domain[field] !== undefined) {
33
34
  (0, validation_js_1.validatePlanField)(domain[field], {
34
35
  path: `${path}.typedData.domain.${field}`,
35
36
  type: "string",
36
37
  });
37
- if (domain.salt !== undefined)
38
+ }
39
+ }
40
+ if (domain.salt !== undefined) {
38
41
  (0, validation_js_1.validatePlanField)(domain.salt, {
39
42
  path: `${path}.typedData.domain.salt`,
40
43
  type: "hex",
41
44
  });
45
+ }
42
46
  const types = (0, validation_js_1.getPlanObject)(typedData.types, `${path}.typedData.types`);
43
47
  (0, validation_js_1.validatePlanField)(types[typedData.primaryType], {
44
48
  path: `${path}.typedData.types.${typedData.primaryType}`,
@@ -66,23 +70,87 @@ function validatePermitPlanRequest(request, path) {
66
70
  deadline: "uint256 bigint",
67
71
  },
68
72
  });
69
- if (request.signature !== undefined)
73
+ if (request.signature !== undefined) {
70
74
  (0, validation_js_1.validatePlanField)(request.signature, {
71
75
  path: `${path}.signature`,
72
76
  type: "hex",
73
77
  });
78
+ }
74
79
  }
75
80
  /** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
76
81
  function validateSignatureRequest(request, action) {
77
- if (action.type === "erc20Approval" ||
78
- action.signatureRequestIds.tokenPermit !== request.id)
79
- throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
80
82
  const { chainId, account } = action.inputs;
81
83
  const { domain, message, primaryType } = request.typedData;
82
- const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
83
- const asset = action.type === "vaultV2Deposit"
84
- ? action.inputs.asset
85
- : action.inputs.vault;
84
+ let spenderKey;
85
+ let asset;
86
+ let amountMatches;
87
+ switch (action.type) {
88
+ case "vaultV2ForceRedeem":
89
+ throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
90
+ case "erc20Approval":
91
+ throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
92
+ case "vaultV2Deposit":
93
+ spenderKey = "bundles.vaultBundlesV1";
94
+ asset = action.inputs.asset;
95
+ amountMatches = request.args.amount === action.inputs.assets;
96
+ break;
97
+ case "vaultV1Deposit":
98
+ spenderKey = "bundles.vaultBundlesV1";
99
+ asset = action.inputs.asset;
100
+ amountMatches = request.args.amount === action.inputs.assets;
101
+ break;
102
+ case "vaultV1Withdraw":
103
+ spenderKey = "bundles.vaultBundlesV1";
104
+ asset = action.inputs.vault;
105
+ amountMatches =
106
+ request.args.amount >= action.inputs.requiredShareAllowance;
107
+ break;
108
+ case "vaultV2Withdraw":
109
+ spenderKey = "bundles.vaultBundlesV1";
110
+ asset = action.inputs.vault;
111
+ amountMatches =
112
+ request.args.amount >= action.inputs.requiredShareAllowance;
113
+ break;
114
+ case "vaultV2Redeem":
115
+ spenderKey = "bundles.vaultBundlesV1";
116
+ asset = action.inputs.vault;
117
+ amountMatches = request.args.amount >= action.inputs.shares;
118
+ break;
119
+ case "vaultV1Redeem":
120
+ spenderKey = "bundles.vaultBundlesV1";
121
+ asset = action.inputs.vault;
122
+ amountMatches = request.args.amount >= action.inputs.shares;
123
+ break;
124
+ case "vaultV2ForceWithdraw":
125
+ spenderKey = "bundles.vaultExitBundlesV1";
126
+ asset = action.inputs.vault;
127
+ amountMatches = request.args.amount === viem_1.maxUint256;
128
+ break;
129
+ case "vaultV1MigrateToV2":
130
+ spenderKey = "bundles.vaultBundlesV1";
131
+ asset = action.inputs.sourceVault;
132
+ amountMatches =
133
+ request.args.amount >= action.inputs.requiredShareAllowance;
134
+ break;
135
+ case "vaultV2InKindRedeem":
136
+ spenderKey = "bundles.vaultExitBundlesV1";
137
+ asset = action.inputs.vault;
138
+ amountMatches = request.args.amount === viem_1.maxUint256;
139
+ break;
140
+ case "vaultV1InKindRedeem":
141
+ spenderKey = "bundles.vaultExitBundlesV1";
142
+ asset = action.inputs.vault;
143
+ amountMatches = request.args.amount === viem_1.maxUint256;
144
+ break;
145
+ default: {
146
+ const _exhaustive = action;
147
+ throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
148
+ }
149
+ }
150
+ if (action.signatureRequestIds.tokenPermit !== request.id) {
151
+ throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
152
+ }
153
+ const spender = (0, morpho_ts_1.getChainAddress)(chainId, spenderKey);
86
154
  const checks = [
87
155
  ["domain.chainId", domain?.chainId === chainId],
88
156
  [
@@ -106,27 +174,25 @@ function validateSignatureRequest(request, action) {
106
174
  request.args.spender.toLowerCase() === spender.toLowerCase(),
107
175
  ],
108
176
  ["message.value", message?.value === request.args.amount],
109
- [
110
- "value",
111
- action.type === "vaultV2Deposit"
112
- ? request.args.amount === action.inputs.amount
113
- : request.args.amount >= action.inputs.requiredShareAllowance,
114
- ],
177
+ ["value", amountMatches],
115
178
  ["message.nonce", message?.nonce === request.args.nonce],
116
179
  ["message.deadline", message?.deadline === request.args.deadline],
117
180
  ["primaryType", primaryType === "Permit"],
118
181
  ];
119
182
  const mismatch = checks.find(([, matches]) => !matches);
120
- if (mismatch)
183
+ if (mismatch) {
121
184
  throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, mismatch[0]);
185
+ }
122
186
  }
123
187
  /** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
124
188
  function getVaultPermit(requests, { id, asset, owner, }) {
125
- if (id === undefined)
189
+ if (id === undefined) {
126
190
  return undefined;
191
+ }
127
192
  const request = requests.find((candidate) => candidate.id === id);
128
- if (request?.signature === undefined)
193
+ if (request?.signature === undefined) {
129
194
  throw new error_js_1.IncompleteTransactionPlanError(id);
195
+ }
130
196
  return {
131
197
  action: {
132
198
  type: request.kind,
@@ -2,6 +2,7 @@ import { type Hex } from "viem";
2
2
  import type { Transaction } from "../types/index.js";
3
3
  import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
4
4
  /**
5
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
5
6
  * Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
6
7
  * and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
7
8
  * binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
@@ -24,13 +25,13 @@ import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
24
25
  * const complete = (plan: TransactionPlan, signature: Hex) =>
25
26
  * applySignatures(plan, [{ id: "vaultV2Deposit:tokenPermit", signature }]);
26
27
  * ```
27
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
28
28
  */
29
29
  export declare function applySignatures(plan: TransactionPlan, signatures: readonly {
30
30
  readonly id: string;
31
31
  readonly signature: Hex;
32
32
  }[]): TransactionPlan;
33
33
  /**
34
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
34
35
  * Lists pending signature requests once per request ID after checking each against every referencing action.
35
36
  * Sign each request's typed data with your wallet stack, then verify and attach the results with
36
37
  * {@link applySignatures}.
@@ -45,10 +46,10 @@ export declare function applySignatures(plan: TransactionPlan, signatures: reado
45
46
  * const prompts = (plan: TransactionPlan) =>
46
47
  * getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
47
48
  * ```
48
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
49
49
  */
50
50
  export declare function getPendingSignatureRequests(plan: TransactionPlan): readonly SignatureRequest[];
51
51
  /**
52
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
52
53
  * Builds one transaction from a step, its fixed inputs and the signatures its action names.
53
54
  * Plans are trusted as given, whether restored or supplied directly. Signature checks establish
54
55
  * only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
@@ -60,11 +61,16 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
60
61
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
61
62
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
62
63
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
63
- * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
64
+ * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
65
+ * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
66
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
67
+ * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
68
+ * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
64
69
  * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
65
70
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
66
71
  * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
67
72
  * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
73
+ * @throws {BundlesPermitMismatchError} If a signed permit's spender, amount or deadline doesn't match the step.
68
74
  * @example
69
75
  * ```ts
70
76
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -73,27 +79,31 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
73
79
  * return plan.steps.map((step) => buildTransaction(plan, step));
74
80
  * };
75
81
  * ```
76
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
77
82
  */
78
83
  export declare function buildTransaction(plan: TransactionPlan, step: Step): Readonly<Transaction>;
79
84
  /**
85
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
80
86
  * Builds every step of the plan in order.
81
87
  * @param plan - Plan whose referenced signature requests all carry a signature.
82
88
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
83
89
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
84
90
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
85
91
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
86
- * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
92
+ * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
93
+ * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
94
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
95
+ * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
96
+ * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
87
97
  * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
88
98
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
89
99
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
90
100
  * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
101
+ * @throws {BundlesPermitMismatchError} If a signed permit's spender, amount or deadline doesn't match the step.
91
102
  * @example
92
103
  * ```ts
93
104
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
94
105
  * const submit = (plan: TransactionPlan) => buildTransactions(plan);
95
106
  * // Simulate and send in order from plan.account on plan.chainId.
96
107
  * ```
97
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
98
108
  */
99
109
  export declare function buildTransactions(plan: TransactionPlan): readonly Readonly<Transaction>[];
@@ -14,10 +14,20 @@ const error_js_1 = require("../types/error.js");
14
14
  const error_js_2 = require("./error.js");
15
15
  const permit_js_1 = require("./permit.js");
16
16
  const validateActions_js_1 = require("./validateActions.js");
17
- const deposit_js_1 = require("./vaultv2/deposit.js");
18
- const withdraw_js_1 = require("./vaultv2/withdraw.js");
17
+ const deposit_js_1 = require("./vaultv1/deposit.js");
18
+ const inKindRedeem_js_1 = require("./vaultv1/inKindRedeem.js");
19
+ const migrateToV2_js_1 = require("./vaultv1/migrateToV2.js");
20
+ const redeem_js_1 = require("./vaultv1/redeem.js");
21
+ const withdraw_js_1 = require("./vaultv1/withdraw.js");
22
+ const deposit_js_2 = require("./vaultv2/deposit.js");
23
+ const forceRedeem_js_1 = require("./vaultv2/forceRedeem.js");
24
+ const forceWithdraw_js_1 = require("./vaultv2/forceWithdraw.js");
25
+ const inKindRedeem_js_2 = require("./vaultv2/inKindRedeem.js");
26
+ const redeem_js_2 = require("./vaultv2/redeem.js");
27
+ const withdraw_js_2 = require("./vaultv2/withdraw.js");
19
28
  const version_js_1 = require("./version.js");
20
29
  /**
30
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
21
31
  * Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
22
32
  * and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
23
33
  * binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
@@ -40,7 +50,6 @@ const version_js_1 = require("./version.js");
40
50
  * const complete = (plan: TransactionPlan, signature: Hex) =>
41
51
  * applySignatures(plan, [{ id: "vaultV2Deposit:tokenPermit", signature }]);
42
52
  * ```
43
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
44
53
  */
45
54
  function applySignatures(plan, signatures) {
46
55
  // Reject unknown formats before interpreting stored fields or signature updates.
@@ -56,22 +65,29 @@ function applySignatures(plan, signatures) {
56
65
  });
57
66
  const updates = new Map();
58
67
  for (const { id, signature } of signatures) {
59
- if (!requests.some((request) => request.id === id))
68
+ if (!requests.some((request) => request.id === id)) {
60
69
  throw new error_js_2.TransactionPlanSignatureMismatchError(id, "reference");
61
- if (updates.has(id))
70
+ }
71
+ if (updates.has(id)) {
62
72
  throw new error_js_2.TransactionPlanSignatureMismatchError(id, "duplicate");
73
+ }
63
74
  updates.set(id, signature);
64
75
  }
65
- if (updates.size === 0)
76
+ if (updates.size === 0) {
66
77
  return plan;
78
+ }
67
79
  for (const [id, signature] of updates) {
68
80
  const request = requests.find((candidate) => candidate.id === id);
81
+ if (request === undefined) {
82
+ throw new error_js_2.TransactionPlanSignatureMismatchError(id, "reference");
83
+ }
69
84
  const normalized = (0, common_js_1.normalizeBundlesSignature)(signature);
70
85
  let recovered;
71
86
  try {
72
87
  const ecdsa = new secp256k1_1.secp256k1.Signature(BigInt(normalized.r), BigInt(normalized.s));
73
- if (ecdsa.hasHighS())
88
+ if (ecdsa.hasHighS()) {
74
89
  throw new error_js_1.InvalidSignatureError();
90
+ }
75
91
  const publicKey = ecdsa
76
92
  .addRecoveryBit(normalized.v - 27)
77
93
  .recoverPublicKey((0, viem_1.hashTypedData)(request.typedData).slice(2));
@@ -80,25 +96,29 @@ function applySignatures(plan, signatures) {
80
96
  catch {
81
97
  throw new error_js_1.InvalidSignatureError();
82
98
  }
83
- if (!(0, viem_1.isAddressEqual)(recovered, request.typedData.message.owner))
99
+ if (!(0, viem_1.isAddressEqual)(recovered, request.typedData.message.owner)) {
84
100
  throw new error_js_1.InvalidSignatureError();
101
+ }
85
102
  updates.set(id, (0, viem_1.serializeSignature)({ ...normalized, v: BigInt(normalized.v) }));
86
103
  }
87
104
  return {
88
105
  ...plan,
89
- signatureRequests: plan.signatureRequests.map((request) => updates.has(request.id)
90
- ? { ...request, signature: updates.get(request.id) }
91
- : request),
106
+ signatureRequests: plan.signatureRequests.map((request) => {
107
+ const signature = updates.get(request.id);
108
+ return signature === undefined ? request : { ...request, signature };
109
+ }),
92
110
  };
93
111
  }
94
112
  /** @internal Lists the signature request IDs a step's action names, in role order. */
95
113
  function getStepSignatureRequestIds(step) {
96
114
  const { action } = step;
97
- if (!("signatureRequestIds" in action))
115
+ if (!("signatureRequestIds" in action)) {
98
116
  return [];
117
+ }
99
118
  return Object.values(action.signatureRequestIds).filter((id) => id !== undefined);
100
119
  }
101
120
  /**
121
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
102
122
  * Lists pending signature requests once per request ID after checking each against every referencing action.
103
123
  * Sign each request's typed data with your wallet stack, then verify and attach the results with
104
124
  * {@link applySignatures}.
@@ -113,7 +133,6 @@ function getStepSignatureRequestIds(step) {
113
133
  * const prompts = (plan: TransactionPlan) =>
114
134
  * getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
115
135
  * ```
116
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
117
136
  */
118
137
  function getPendingSignatureRequests(plan) {
119
138
  // Reject unknown formats before interpreting stored fields.
@@ -128,14 +147,16 @@ function getPendingSignatureRequests(plan) {
128
147
  }
129
148
  for (const request of plan.signatureRequests) {
130
149
  const actions = referenced.get(request.id);
131
- if (actions === undefined)
150
+ if (actions === undefined) {
132
151
  throw new error_js_2.TransactionPlanSignatureMismatchError(request.id, "reference");
152
+ }
133
153
  if (request.signature === undefined) {
134
154
  for (const action of actions) {
135
155
  (0, permit_js_1.validateSignatureRequest)(request, action);
136
- if (action.type !== "erc20Approval" &&
137
- request.args.deadline !== action.inputs.deadline)
156
+ if ("signatureRequestIds" in action &&
157
+ request.args.deadline !== action.inputs.deadline) {
138
158
  throw new error_js_2.TransactionPlanSignatureMismatchError(request.id, "args.deadline");
159
+ }
139
160
  }
140
161
  }
141
162
  }
@@ -146,15 +167,37 @@ function getPendingSignatureRequests(plan) {
146
167
  }
147
168
  function encodeStep(action, requests) {
148
169
  switch (action.type) {
170
+ case "vaultV2ForceRedeem":
171
+ return (0, forceRedeem_js_1.buildVaultV2ForceRedeem)(action);
172
+ case "vaultV1MigrateToV2":
173
+ return (0, migrateToV2_js_1.buildVaultV1MigrateToV2)(action, requests);
174
+ case "vaultV1InKindRedeem":
175
+ return (0, inKindRedeem_js_1.buildVaultV1InKindRedeem)(action, requests);
149
176
  case "erc20Approval":
150
- return (0, index_js_1.encodeErc20Approval)(action.inputs);
177
+ return (0, index_js_1.encodeErc20Approval)({
178
+ ...action.inputs,
179
+ amount: action.inputs.assets ?? action.inputs.shares,
180
+ });
181
+ case "vaultV1Deposit":
182
+ return (0, deposit_js_1.buildVaultV1Deposit)(action, requests);
151
183
  case "vaultV2Deposit":
152
- return (0, deposit_js_1.buildVaultV2Deposit)(action, requests);
184
+ return (0, deposit_js_2.buildVaultV2Deposit)(action, requests);
153
185
  case "vaultV2Withdraw":
154
- return (0, withdraw_js_1.buildVaultV2Withdraw)(action, requests);
186
+ return (0, withdraw_js_2.buildVaultV2Withdraw)(action, requests);
187
+ case "vaultV2Redeem":
188
+ return (0, redeem_js_2.buildVaultV2Redeem)(action, requests);
189
+ case "vaultV2ForceWithdraw":
190
+ return (0, forceWithdraw_js_1.buildVaultV2ForceWithdraw)(action, requests);
191
+ case "vaultV1Withdraw":
192
+ return (0, withdraw_js_1.buildVaultV1Withdraw)(action, requests);
193
+ case "vaultV1Redeem":
194
+ return (0, redeem_js_1.buildVaultV1Redeem)(action, requests);
195
+ case "vaultV2InKindRedeem":
196
+ return (0, inKindRedeem_js_2.buildVaultV2InKindRedeem)(action, requests);
155
197
  }
156
198
  }
157
199
  /**
200
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
158
201
  * Builds one transaction from a step, its fixed inputs and the signatures its action names.
159
202
  * Plans are trusted as given, whether restored or supplied directly. Signature checks establish
160
203
  * only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
@@ -166,11 +209,16 @@ function encodeStep(action, requests) {
166
209
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
167
210
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
168
211
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
169
- * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
212
+ * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
213
+ * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
214
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
215
+ * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
216
+ * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
170
217
  * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
171
218
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
172
219
  * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
173
220
  * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
221
+ * @throws {BundlesPermitMismatchError} If a signed permit's spender, amount or deadline doesn't match the step.
174
222
  * @example
175
223
  * ```ts
176
224
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -179,7 +227,6 @@ function encodeStep(action, requests) {
179
227
  * return plan.steps.map((step) => buildTransaction(plan, step));
180
228
  * };
181
229
  * ```
182
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
183
230
  */
184
231
  function buildTransaction(plan, step) {
185
232
  // Reject unknown formats before interpreting stored fields.
@@ -188,8 +235,9 @@ function buildTransaction(plan, step) {
188
235
  (0, validateActions_js_1.validateTransactionPlanActions)([...plan.steps, step]);
189
236
  const requests = getStepSignatureRequestIds(step).map((id) => {
190
237
  const request = plan.signatureRequests.find((candidate) => candidate.id === id);
191
- if (request === undefined)
238
+ if (request === undefined) {
192
239
  throw new error_js_2.IncompleteTransactionPlanError(id);
240
+ }
193
241
  (0, permit_js_1.validateSignatureRequest)(request, step.action);
194
242
  return request;
195
243
  });
@@ -204,24 +252,29 @@ function buildTransaction(plan, step) {
204
252
  });
205
253
  }
206
254
  /**
255
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
207
256
  * Builds every step of the plan in order.
208
257
  * @param plan - Plan whose referenced signature requests all carry a signature.
209
258
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
210
259
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
211
260
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
212
261
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
213
- * @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
262
+ * @throws {SameVaultMigrationError} If a migration's source and destination vaults are identical.
263
+ * @throws {AmountAndSharesExclusiveError} If a migration supplies both `assets` and `shares`, or neither.
264
+ * @throws {NonPositiveInputError} If a deposit, withdrawal or migration amount, a deposit or migration destination share-price bound, a deadline, force-redeem shares or deallocation amount is not positive.
265
+ * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
266
+ * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
214
267
  * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
215
268
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
216
269
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
217
270
  * @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
271
+ * @throws {BundlesPermitMismatchError} If a signed permit's spender, amount or deadline doesn't match the step.
218
272
  * @example
219
273
  * ```ts
220
274
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
221
275
  * const submit = (plan: TransactionPlan) => buildTransactions(plan);
222
276
  * // Simulate and send in order from plan.account on plan.chainId.
223
277
  * ```
224
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
225
278
  */
226
279
  function buildTransactions(plan) {
227
280
  // Reject unknown formats even when there are no steps to build.
@@ -0,0 +1,18 @@
1
+ import type { Token } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import { type ReferenceTimestampParams } from "../types/index.js";
4
+ import { type IntentParams } from "./intent.js";
5
+ import type { TransactionPlan } from "./types.js";
6
+ /** @internal Shared exact-share intent; V1 callers must supply permit-domain metadata. */
7
+ export interface RedeemPlanParams extends Omit<IntentParams, "deployless">, ReferenceTimestampParams {
8
+ /** Vault share token; V1 permits also use its caller-supplied domain metadata. */
9
+ readonly shareToken: Token;
10
+ /** Exact shares burned, in share base units. */
11
+ readonly shares: bigint;
12
+ }
13
+ /** @internal Prepares an exact-share redemption without fetching a snapshot or asset quote. */
14
+ export declare function prepareVaultRedeem(client: Client, params: RedeemPlanParams & {
15
+ readonly type: "vaultV1Redeem" | "vaultV2Redeem";
16
+ }): Promise<TransactionPlan>;
17
+ /** @internal Validates stored V1 and V2 exact-share redemption inputs. */
18
+ export declare function validateRedeemPlanAction(action: Record<string, unknown>, path: string): void;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareVaultRedeem = prepareVaultRedeem;
4
+ exports.validateRedeemPlanAction = validateRedeemPlanAction;
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const common_js_1 = require("../actions/bundles/common.js");
7
+ const validate_js_1 = require("../helpers/validate.js");
8
+ const index_js_1 = require("../types/index.js");
9
+ const intent_js_1 = require("./intent.js");
10
+ const shareSpending_js_1 = require("./shareSpending.js");
11
+ const validation_js_1 = require("./validation.js");
12
+ /** @internal Prepares an exact-share redemption without fetching a snapshot or asset quote. */
13
+ async function prepareVaultRedeem(client, params) {
14
+ const { type, shareToken, chainId, account, shares } = params;
15
+ const vault = shareToken.address;
16
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
17
+ const intent = (0, intent_js_1.resolveIntent)(params, now);
18
+ if (shares <= 0n) {
19
+ throw new index_js_1.NonPositiveInputError("shares", shares);
20
+ }
21
+ (0, validate_js_1.validateUint256Field)("shares", shares);
22
+ const common = (0, common_js_1.normalizeBundlesCommonParams)(intent);
23
+ const { approvals, signatureRequests, tokenPermitRequestId } = await (0, shareSpending_js_1.getVaultShareSpendingRequirements)(client, {
24
+ type,
25
+ shareToken,
26
+ chainId,
27
+ account,
28
+ requiredShareAllowance: shares,
29
+ deadline: intent.deadline,
30
+ supportSignature: intent.supportSignature,
31
+ now,
32
+ });
33
+ return (0, morpho_ts_1.deepFreeze)(structuredClone({
34
+ version: 2,
35
+ account,
36
+ chainId,
37
+ expiresAt: intent.expiresAt,
38
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
39
+ steps: [
40
+ ...approvals,
41
+ {
42
+ id: type,
43
+ label: "Redeem vault shares",
44
+ action: {
45
+ type,
46
+ inputs: { chainId, account, vault, shares, ...common },
47
+ signatureRequestIds: signatureRequests.length > 0
48
+ ? { tokenPermit: tokenPermitRequestId }
49
+ : {},
50
+ },
51
+ },
52
+ ],
53
+ signatureRequests,
54
+ }));
55
+ }
56
+ /** @internal Validates stored V1 and V2 exact-share redemption inputs. */
57
+ function validateRedeemPlanAction(action, path) {
58
+ const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
59
+ (0, validation_js_1.validatePlanFields)(inputs, {
60
+ path: `${path}.inputs`,
61
+ fields: { shares: "uint256 bigint" },
62
+ });
63
+ }
@@ -8,17 +8,18 @@ import type { Action, SignatureRequest, Step } from "./types.js";
8
8
  * @returns The unsigned request with a concrete nonce.
9
9
  * @throws {UnexpectedRequirementSignatureError} If the permit requirement has no nonce.
10
10
  */
11
- export declare function buildPermitSignatureRequest(requirement: Requirement<Erc2612RequirementSignature>, id: string): SignatureRequest;
11
+ export declare function buildPermitSignatureRequest(requirement: Pick<Requirement<Erc2612RequirementSignature>, "action">, id: string): SignatureRequest;
12
12
  /**
13
13
  * @internal Converts an approval transaction into a step with prepared chain/account inputs.
14
14
  * @param requirement - Direct token approval prerequisite.
15
- * @param params - Step ID, chain and account selected by the preparer.
15
+ * @param params - Step ID, chain, account and token denomination selected by the preparer.
16
16
  * @returns The approval recipe labeled for token spending.
17
17
  */
18
- export declare function buildApprovalStep(requirement: Readonly<Transaction<ERC20ApprovalAction>>, { id, chainId, account, }: {
18
+ export declare function buildApprovalStep(requirement: Readonly<Transaction<ERC20ApprovalAction>>, { id, chainId, account, denomination, }: {
19
19
  readonly id: string;
20
20
  readonly chainId: number;
21
21
  readonly account: Address;
22
+ readonly denomination: "assets" | "shares";
22
23
  }): Step<Extract<Action, {
23
24
  type: "erc20Approval";
24
25
  }>>;