@morpho-org/morpho-sdk 10.0.0-next.0 → 10.0.1

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 (282) hide show
  1. package/README.md +104 -12
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/common.js +4 -2
  5. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  6. package/lib/cjs/actions/bundles/common.js +20 -14
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
  8. package/lib/cjs/actions/midnight/cancelOffers.js +2 -1
  9. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  10. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
  11. package/lib/cjs/actions/midnight/takeBorrow.js +2 -1
  12. package/lib/cjs/actions/midnight/takeLend.js +2 -1
  13. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
  14. package/lib/cjs/actions/midnight/takeWithdraw.js +2 -1
  15. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -11
  17. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  18. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  19. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  20. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  21. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  22. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  23. package/lib/cjs/blue/abis.d.ts +1 -1
  24. package/lib/cjs/blue/abis.js +1 -5
  25. package/lib/cjs/blue/entities.d.ts +4 -4
  26. package/lib/cjs/blue/entities.js +1 -3
  27. package/lib/cjs/blue/errors.d.ts +2 -2
  28. package/lib/cjs/blue/errors.js +1 -5
  29. package/lib/cjs/blue/fetch.d.ts +2 -2
  30. package/lib/cjs/blue/fetch.js +1 -3
  31. package/lib/cjs/blue/utils.d.ts +1 -1
  32. package/lib/cjs/blue/utils.js +1 -2
  33. package/lib/cjs/entities/blue/blue.js +8 -4
  34. package/lib/cjs/entities/index.d.ts +4 -4
  35. package/lib/cjs/entities/index.js +1 -3
  36. package/lib/cjs/entities/midnight/deadline.js +2 -1
  37. package/lib/cjs/entities/midnight/midnight.js +14 -7
  38. package/lib/cjs/entities/midnight/publication.js +73 -44
  39. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  40. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +9 -13
  41. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  42. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
  43. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
  44. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  45. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  46. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  47. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  48. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  49. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  50. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  51. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  52. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  53. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +51 -181
  55. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  56. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  57. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  58. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  59. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +8 -34
  60. package/lib/cjs/entities/vaultV2/vaultV2.js +62 -429
  61. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
  62. package/lib/cjs/entities/vaultV2BlueReallocationData.js +346 -234
  63. package/lib/cjs/errors.d.ts +4 -4
  64. package/lib/cjs/errors.js +6 -7
  65. package/lib/cjs/fetch.d.ts +2 -2
  66. package/lib/cjs/fetch.js +1 -3
  67. package/lib/cjs/helpers/deadShares.js +34 -19
  68. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  69. package/lib/cjs/helpers/metadata.js +12 -6
  70. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -5
  71. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +6 -3
  72. package/lib/cjs/helpers/utilization.js +10 -5
  73. package/lib/cjs/helpers/validate.js +12 -6
  74. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  75. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  76. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  77. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +44 -22
  78. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  79. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +14 -7
  81. package/lib/cjs/index.d.ts +2 -2
  82. package/lib/cjs/index.js +10 -1
  83. package/lib/cjs/midnight/errors.d.ts +1 -2
  84. package/lib/cjs/midnight/errors.js +4 -5
  85. package/lib/cjs/transactionPlan/approval.js +12 -1
  86. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  87. package/lib/cjs/transactionPlan/deposit.js +139 -0
  88. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  89. package/lib/cjs/transactionPlan/error.js +10 -8
  90. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  91. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  92. package/lib/cjs/transactionPlan/index.js +23 -5
  93. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  94. package/lib/cjs/transactionPlan/intent.js +14 -7
  95. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  96. package/lib/cjs/transactionPlan/permit.js +86 -20
  97. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  98. package/lib/cjs/transactionPlan/plan.js +72 -22
  99. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  100. package/lib/cjs/transactionPlan/redeem.js +63 -0
  101. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  102. package/lib/cjs/transactionPlan/requirements.js +12 -6
  103. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  104. package/lib/cjs/transactionPlan/serde.js +41 -15
  105. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  106. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  107. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  108. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  109. package/lib/cjs/transactionPlan/validation.js +6 -3
  110. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  111. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  112. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  113. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  114. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  115. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  116. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  117. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  118. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  119. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  120. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +14 -31
  121. package/lib/cjs/transactionPlan/vaultv2/deposit.js +15 -141
  122. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  123. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  124. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  125. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  126. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  127. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  128. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  129. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  130. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +14 -27
  131. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +17 -124
  132. package/lib/cjs/transactionPlan/version.js +2 -1
  133. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  134. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  135. package/lib/cjs/types/action.js +16 -8
  136. package/lib/cjs/types/error.d.ts +8 -1
  137. package/lib/cjs/types/error.js +10 -1
  138. package/lib/cjs/utils.d.ts +2 -2
  139. package/lib/cjs/utils.js +2 -4
  140. package/lib/cjs/version.d.ts +1 -1
  141. package/lib/cjs/version.js +1 -1
  142. package/lib/esm/abis.d.ts +1 -1
  143. package/lib/esm/abis.js +1 -1
  144. package/lib/esm/actions/blue/common.js +4 -2
  145. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  146. package/lib/esm/actions/bundles/common.js +20 -14
  147. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
  148. package/lib/esm/actions/midnight/cancelOffers.js +2 -1
  149. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  150. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
  151. package/lib/esm/actions/midnight/takeBorrow.js +2 -1
  152. package/lib/esm/actions/midnight/takeLend.js +2 -1
  153. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
  154. package/lib/esm/actions/midnight/takeWithdraw.js +2 -1
  155. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +4 -13
  157. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  158. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  159. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  160. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  161. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  162. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  163. package/lib/esm/blue/abis.d.ts +1 -1
  164. package/lib/esm/blue/abis.js +1 -1
  165. package/lib/esm/blue/entities.d.ts +4 -4
  166. package/lib/esm/blue/entities.js +2 -2
  167. package/lib/esm/blue/errors.d.ts +2 -2
  168. package/lib/esm/blue/errors.js +2 -2
  169. package/lib/esm/blue/fetch.d.ts +2 -2
  170. package/lib/esm/blue/fetch.js +2 -2
  171. package/lib/esm/blue/utils.d.ts +1 -1
  172. package/lib/esm/blue/utils.js +1 -1
  173. package/lib/esm/entities/blue/blue.js +8 -4
  174. package/lib/esm/entities/index.d.ts +4 -4
  175. package/lib/esm/entities/index.js +2 -2
  176. package/lib/esm/entities/midnight/deadline.js +2 -1
  177. package/lib/esm/entities/midnight/midnight.js +14 -7
  178. package/lib/esm/entities/midnight/publication.js +73 -44
  179. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  180. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +10 -14
  181. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
  183. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
  184. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  185. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  186. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  187. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  188. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  189. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  190. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  191. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  192. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  193. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  194. package/lib/esm/entities/vaultV1/vaultV1.js +57 -187
  195. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  196. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  197. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  198. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  199. package/lib/esm/entities/vaultV2/vaultV2.d.ts +8 -34
  200. package/lib/esm/entities/vaultV2/vaultV2.js +70 -437
  201. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
  202. package/lib/esm/entities/vaultV2BlueReallocationData.js +346 -234
  203. package/lib/esm/errors.d.ts +4 -4
  204. package/lib/esm/errors.js +4 -4
  205. package/lib/esm/fetch.d.ts +2 -2
  206. package/lib/esm/fetch.js +2 -2
  207. package/lib/esm/helpers/deadShares.js +35 -20
  208. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  209. package/lib/esm/helpers/metadata.js +12 -6
  210. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -5
  211. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +6 -3
  212. package/lib/esm/helpers/utilization.js +10 -5
  213. package/lib/esm/helpers/validate.js +12 -6
  214. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  215. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  216. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  217. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +44 -22
  218. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  219. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  220. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +14 -7
  221. package/lib/esm/index.d.ts +2 -2
  222. package/lib/esm/index.js +1 -1
  223. package/lib/esm/midnight/errors.d.ts +1 -2
  224. package/lib/esm/midnight/errors.js +1 -2
  225. package/lib/esm/transactionPlan/approval.js +13 -2
  226. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  227. package/lib/esm/transactionPlan/deposit.js +135 -0
  228. package/lib/esm/transactionPlan/error.d.ts +10 -8
  229. package/lib/esm/transactionPlan/error.js +10 -8
  230. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  231. package/lib/esm/transactionPlan/index.d.ts +18 -0
  232. package/lib/esm/transactionPlan/index.js +9 -0
  233. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  234. package/lib/esm/transactionPlan/intent.js +14 -7
  235. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  236. package/lib/esm/transactionPlan/permit.js +86 -20
  237. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  238. package/lib/esm/transactionPlan/plan.js +68 -18
  239. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  240. package/lib/esm/transactionPlan/redeem.js +59 -0
  241. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  242. package/lib/esm/transactionPlan/requirements.js +12 -6
  243. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  244. package/lib/esm/transactionPlan/serde.js +41 -15
  245. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  246. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  247. package/lib/esm/transactionPlan/types.d.ts +117 -11
  248. package/lib/esm/transactionPlan/validateActions.js +11 -1
  249. package/lib/esm/transactionPlan/validation.js +6 -3
  250. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  251. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  252. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  253. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  254. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  255. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  256. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  257. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  258. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  259. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  260. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +14 -31
  261. package/lib/esm/transactionPlan/vaultv2/deposit.js +17 -142
  262. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  263. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  264. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  265. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  266. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  267. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  268. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  269. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  270. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +14 -27
  271. package/lib/esm/transactionPlan/vaultv2/withdraw.js +19 -125
  272. package/lib/esm/transactionPlan/version.js +2 -1
  273. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  274. package/lib/esm/transactionPlan/withdraw.js +90 -0
  275. package/lib/esm/types/action.js +16 -8
  276. package/lib/esm/types/error.d.ts +8 -1
  277. package/lib/esm/types/error.js +10 -1
  278. package/lib/esm/utils.d.ts +2 -2
  279. package/lib/esm/utils.js +2 -2
  280. package/lib/esm/version.d.ts +1 -1
  281. package/lib/esm/version.js +1 -1
  282. package/package.json +15 -15
@@ -1,5 +1,14 @@
1
1
  export { IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
2
2
  export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
3
3
  export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
4
+ export { prepareVaultV1Deposit } from "./vaultv1/deposit.js";
5
+ export { prepareVaultV1InKindRedeem } from "./vaultv1/inKindRedeem.js";
6
+ export { prepareVaultV1MigrateToV2 } from "./vaultv1/migrateToV2.js";
7
+ export { prepareVaultV1Redeem } from "./vaultv1/redeem.js";
8
+ export { prepareVaultV1Withdraw } from "./vaultv1/withdraw.js";
4
9
  export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
10
+ export { prepareVaultV2ForceRedeem } from "./vaultv2/forceRedeem.js";
11
+ export { prepareVaultV2ForceWithdraw } from "./vaultv2/forceWithdraw.js";
12
+ export { prepareVaultV2InKindRedeem } from "./vaultv2/inKindRedeem.js";
13
+ export { prepareVaultV2Redeem } from "./vaultv2/redeem.js";
5
14
  export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";
@@ -1,7 +1,7 @@
1
1
  import { type Address, type Hex } from "viem";
2
2
  /**
3
- * Which balance pays a deposit: the vault asset, or native currency the bundle wraps.
4
3
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
4
+ * Which balance pays a deposit: the vault asset, or native currency the bundle wraps.
5
5
  */
6
6
  export type Funding = {
7
7
  readonly type: "erc20";
@@ -9,16 +9,16 @@ export type Funding = {
9
9
  readonly type: "native";
10
10
  };
11
11
  /**
12
- * Referral fee in basis points of the gross amount, paid to `recipient`.
13
12
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
13
+ * Referral fee in basis points of the gross amount, paid to `recipient`.
14
14
  */
15
15
  export interface ReferralFee {
16
16
  readonly bps: number;
17
17
  readonly recipient: Address;
18
18
  }
19
19
  /**
20
- * Intent fields shared by every prepare function, mirroring the Actions API intent inputs.
21
20
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
21
+ * Intent fields shared by every prepare function, mirroring the Actions API intent inputs.
22
22
  */
23
23
  export interface IntentParams {
24
24
  readonly chainId: number;
@@ -5,8 +5,9 @@ import { InvalidCalldataOriginError, NonIntegerInputError, ZeroAccountError, } f
5
5
  const BASIS_POINTS = 10000n;
6
6
  const WAD_PER_BASIS_POINT = MathLib.WAD / BASIS_POINTS;
7
7
  function toSafeInteger(field, value) {
8
- if (!Number.isSafeInteger(value))
8
+ if (!Number.isSafeInteger(value)) {
9
9
  throw new NonIntegerInputError(field, value);
10
+ }
10
11
  return BigInt(value);
11
12
  }
12
13
  /**
@@ -14,31 +15,37 @@ function toSafeInteger(field, value) {
14
15
  * signature support and calldata origin. Throws on invalid values so a plan never carries them.
15
16
  */
16
17
  export function resolveIntent(params, now) {
17
- if (params.account === zeroAddress)
18
+ if (params.account === zeroAddress) {
18
19
  throw new ZeroAccountError(params.account);
20
+ }
19
21
  const expiresAt = params.expiresAt ?? Number(now + Time.s.from.h(2n));
20
22
  const deadline = toSafeInteger("expiresAt", expiresAt);
21
- if (deadline <= 0n)
23
+ if (deadline <= 0n) {
22
24
  throw new NonPositiveInputError("expiresAt", deadline);
23
- if (deadline <= now)
25
+ }
26
+ if (deadline <= now) {
24
27
  throw new ExpiredDeadlineError(deadline, now);
28
+ }
25
29
  const bps = params.referralFee === undefined
26
30
  ? 0n
27
31
  : toSafeInteger("referralFee.bps", params.referralFee.bps);
28
- if (bps < 0n)
32
+ if (bps < 0n) {
29
33
  throw new NegativeInputError("referralFee.bps", bps);
30
- if (bps > BASIS_POINTS)
34
+ }
35
+ if (bps > BASIS_POINTS) {
31
36
  throw new InputExceedsMaxError({
32
37
  field: "referralFee.bps",
33
38
  value: bps,
34
39
  max: BASIS_POINTS,
35
40
  });
41
+ }
36
42
  const { calldataOrigin } = params;
37
43
  if (calldataOrigin !== undefined &&
38
44
  (!isHex(calldataOrigin, { strict: true }) ||
39
45
  calldataOrigin.length <= 2 ||
40
- calldataOrigin.length % 2 !== 0))
46
+ calldataOrigin.length % 2 !== 0)) {
41
47
  throw new InvalidCalldataOriginError(calldataOrigin);
48
+ }
42
49
  return {
43
50
  expiresAt: Number(deadline),
44
51
  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. */
@@ -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,24 +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);
63
- if (request === undefined)
75
+ if (request === undefined) {
64
76
  throw new TransactionPlanSignatureMismatchError(id, "reference");
77
+ }
65
78
  const normalized = normalizeBundlesSignature(signature);
66
79
  let recovered;
67
80
  try {
68
81
  const ecdsa = new secp256k1.Signature(BigInt(normalized.r), BigInt(normalized.s));
69
- if (ecdsa.hasHighS())
82
+ if (ecdsa.hasHighS()) {
70
83
  throw new InvalidSignatureError();
84
+ }
71
85
  const publicKey = ecdsa
72
86
  .addRecoveryBit(normalized.v - 27)
73
87
  .recoverPublicKey(hashTypedData(request.typedData).slice(2));
@@ -76,8 +90,9 @@ export function applySignatures(plan, signatures) {
76
90
  catch {
77
91
  throw new InvalidSignatureError();
78
92
  }
79
- if (!isAddressEqual(recovered, request.typedData.message.owner))
93
+ if (!isAddressEqual(recovered, request.typedData.message.owner)) {
80
94
  throw new InvalidSignatureError();
95
+ }
81
96
  updates.set(id, serializeSignature({ ...normalized, v: BigInt(normalized.v) }));
82
97
  }
83
98
  return {
@@ -91,11 +106,13 @@ export function applySignatures(plan, signatures) {
91
106
  /** @internal Lists the signature request IDs a step's action names, in role order. */
92
107
  function getStepSignatureRequestIds(step) {
93
108
  const { action } = step;
94
- if (!("signatureRequestIds" in action))
109
+ if (!("signatureRequestIds" in action)) {
95
110
  return [];
111
+ }
96
112
  return Object.values(action.signatureRequestIds).filter((id) => id !== undefined);
97
113
  }
98
114
  /**
115
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
99
116
  * Lists pending signature requests once per request ID after checking each against every referencing action.
100
117
  * Sign each request's typed data with your wallet stack, then verify and attach the results with
101
118
  * {@link applySignatures}.
@@ -110,7 +127,6 @@ function getStepSignatureRequestIds(step) {
110
127
  * const prompts = (plan: TransactionPlan) =>
111
128
  * getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
112
129
  * ```
113
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
114
130
  */
115
131
  export function getPendingSignatureRequests(plan) {
116
132
  // Reject unknown formats before interpreting stored fields.
@@ -125,14 +141,16 @@ export function getPendingSignatureRequests(plan) {
125
141
  }
126
142
  for (const request of plan.signatureRequests) {
127
143
  const actions = referenced.get(request.id);
128
- if (actions === undefined)
144
+ if (actions === undefined) {
129
145
  throw new TransactionPlanSignatureMismatchError(request.id, "reference");
146
+ }
130
147
  if (request.signature === undefined) {
131
148
  for (const action of actions) {
132
149
  validateSignatureRequest(request, action);
133
- if (action.type !== "erc20Approval" &&
134
- request.args.deadline !== action.inputs.deadline)
150
+ if ("signatureRequestIds" in action &&
151
+ request.args.deadline !== action.inputs.deadline) {
135
152
  throw new TransactionPlanSignatureMismatchError(request.id, "args.deadline");
153
+ }
136
154
  }
137
155
  }
138
156
  }
@@ -143,15 +161,37 @@ export function getPendingSignatureRequests(plan) {
143
161
  }
144
162
  function encodeStep(action, requests) {
145
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);
146
170
  case "erc20Approval":
147
- 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);
148
177
  case "vaultV2Deposit":
149
178
  return buildVaultV2Deposit(action, requests);
150
179
  case "vaultV2Withdraw":
151
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);
152
191
  }
153
192
  }
154
193
  /**
194
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
155
195
  * Builds one transaction from a step, its fixed inputs and the signatures its action names.
156
196
  * Plans are trusted as given, whether restored or supplied directly. Signature checks establish
157
197
  * only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
@@ -163,11 +203,16 @@ function encodeStep(action, requests) {
163
203
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
164
204
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
165
205
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
166
- * @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.
167
211
  * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
168
212
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
169
213
  * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
170
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.
171
216
  * @example
172
217
  * ```ts
173
218
  * import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
@@ -176,7 +221,6 @@ function encodeStep(action, requests) {
176
221
  * return plan.steps.map((step) => buildTransaction(plan, step));
177
222
  * };
178
223
  * ```
179
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
180
224
  */
181
225
  export function buildTransaction(plan, step) {
182
226
  // Reject unknown formats before interpreting stored fields.
@@ -185,8 +229,9 @@ export function buildTransaction(plan, step) {
185
229
  validateTransactionPlanActions([...plan.steps, step]);
186
230
  const requests = getStepSignatureRequestIds(step).map((id) => {
187
231
  const request = plan.signatureRequests.find((candidate) => candidate.id === id);
188
- if (request === undefined)
232
+ if (request === undefined) {
189
233
  throw new IncompleteTransactionPlanError(id);
234
+ }
190
235
  validateSignatureRequest(request, step.action);
191
236
  return request;
192
237
  });
@@ -201,24 +246,29 @@ export function buildTransaction(plan, step) {
201
246
  });
202
247
  }
203
248
  /**
249
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
204
250
  * Builds every step of the plan in order.
205
251
  * @param plan - Plan whose referenced signature requests all carry a signature.
206
252
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
207
253
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
208
254
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
209
255
  * @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
210
- * @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.
211
261
  * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
212
262
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
213
263
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
214
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.
215
266
  * @example
216
267
  * ```ts
217
268
  * import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
218
269
  * const submit = (plan: TransactionPlan) => buildTransactions(plan);
219
270
  * // Simulate and send in order from plan.account on plan.chainId.
220
271
  * ```
221
- * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
222
272
  */
223
273
  export function buildTransactions(plan) {
224
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
+ }