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