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