@morpho-org/morpho-sdk 9.8.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +109 -13
  3. package/lib/cjs/actions/blue/common.js +4 -2
  4. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  5. package/lib/cjs/actions/bundles/common.js +20 -14
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  8. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  9. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  10. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  11. package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
  12. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  13. package/lib/cjs/actions/midnight/index.js +1 -0
  14. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeLend.js +3 -2
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
  25. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  26. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  27. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
  34. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  35. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  36. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  37. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  38. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  39. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  40. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  41. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  42. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  43. package/lib/cjs/entities/blue/blue.js +107 -77
  44. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  45. package/lib/cjs/entities/midnight/deadline.js +4 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  47. package/lib/cjs/entities/midnight/midnight.js +158 -138
  48. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  49. package/lib/cjs/entities/midnight/publication.js +193 -138
  50. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  51. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  52. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  53. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
  54. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  55. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  57. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  58. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  59. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  60. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  61. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  62. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  63. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  64. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  65. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  66. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  67. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  68. package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
  69. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  70. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  71. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  72. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  73. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
  75. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
  76. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
  77. package/lib/cjs/errors.d.ts +1 -1
  78. package/lib/cjs/errors.js +2 -1
  79. package/lib/cjs/helpers/deadShares.js +83 -47
  80. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  81. package/lib/cjs/helpers/metadata.d.ts +14 -2
  82. package/lib/cjs/helpers/metadata.js +49 -8
  83. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
  84. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
  85. package/lib/cjs/helpers/utilization.js +10 -5
  86. package/lib/cjs/helpers/validate.js +88 -67
  87. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  88. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  89. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  90. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
  91. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  92. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  93. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  94. package/lib/cjs/index.d.ts +2 -2
  95. package/lib/cjs/index.js +10 -1
  96. package/lib/cjs/transactionPlan/approval.js +12 -1
  97. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  98. package/lib/cjs/transactionPlan/deposit.js +139 -0
  99. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  100. package/lib/cjs/transactionPlan/error.js +10 -8
  101. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  102. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  103. package/lib/cjs/transactionPlan/index.js +23 -5
  104. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  105. package/lib/cjs/transactionPlan/intent.js +14 -7
  106. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  107. package/lib/cjs/transactionPlan/permit.js +86 -20
  108. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  109. package/lib/cjs/transactionPlan/plan.js +77 -24
  110. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  111. package/lib/cjs/transactionPlan/redeem.js +63 -0
  112. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  113. package/lib/cjs/transactionPlan/requirements.js +12 -6
  114. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  115. package/lib/cjs/transactionPlan/serde.js +45 -19
  116. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  117. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  118. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  119. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  120. package/lib/cjs/transactionPlan/validation.js +6 -3
  121. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  122. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  123. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  124. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  125. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  126. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  127. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  128. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  129. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  130. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  131. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
  132. package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
  133. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  134. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  135. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  136. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  137. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  138. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  139. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  140. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  141. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  142. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
  143. package/lib/cjs/transactionPlan/version.js +2 -1
  144. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  145. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  146. package/lib/cjs/types/action.d.ts +26 -2
  147. package/lib/cjs/types/action.js +17 -9
  148. package/lib/cjs/types/error.d.ts +8 -1
  149. package/lib/cjs/types/error.js +21 -6
  150. package/lib/cjs/types/metadata.d.ts +12 -2
  151. package/lib/cjs/version.d.ts +1 -1
  152. package/lib/cjs/version.js +1 -1
  153. package/lib/esm/actions/blue/common.js +4 -2
  154. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  155. package/lib/esm/actions/bundles/common.js +20 -14
  156. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  157. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  158. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  159. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  160. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  161. package/lib/esm/actions/midnight/cancelOffers.js +104 -0
  162. package/lib/esm/actions/midnight/index.d.ts +1 -0
  163. package/lib/esm/actions/midnight/index.js +1 -0
  164. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  165. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  166. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  167. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  168. package/lib/esm/actions/midnight/takeBorrow.js +3 -2
  169. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  170. package/lib/esm/actions/midnight/takeLend.js +3 -2
  171. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  172. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  173. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  174. package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
  175. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  176. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  177. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  178. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  179. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  180. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  181. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  182. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  183. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
  184. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  185. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  186. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  187. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  188. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  189. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  190. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  191. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  192. package/lib/esm/entities/blue/blue.d.ts +34 -28
  193. package/lib/esm/entities/blue/blue.js +107 -77
  194. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  195. package/lib/esm/entities/midnight/deadline.js +4 -3
  196. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  197. package/lib/esm/entities/midnight/midnight.js +159 -139
  198. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  199. package/lib/esm/entities/midnight/publication.js +193 -138
  200. package/lib/esm/entities/midnight/types.d.ts +4 -4
  201. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  203. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
  204. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  205. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  206. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  207. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  208. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  209. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  210. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  211. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  212. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  213. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  214. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  215. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  216. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  217. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  218. package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
  219. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  220. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  221. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  222. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  223. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
  224. package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
  225. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
  226. package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
  227. package/lib/esm/errors.d.ts +1 -1
  228. package/lib/esm/errors.js +1 -1
  229. package/lib/esm/helpers/deadShares.js +83 -47
  230. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  231. package/lib/esm/helpers/metadata.d.ts +14 -2
  232. package/lib/esm/helpers/metadata.js +48 -8
  233. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
  234. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
  235. package/lib/esm/helpers/utilization.js +10 -5
  236. package/lib/esm/helpers/validate.js +88 -67
  237. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  238. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  239. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  240. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
  241. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  242. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  243. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  244. package/lib/esm/index.d.ts +2 -2
  245. package/lib/esm/index.js +1 -1
  246. package/lib/esm/transactionPlan/approval.js +13 -2
  247. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  248. package/lib/esm/transactionPlan/deposit.js +135 -0
  249. package/lib/esm/transactionPlan/error.d.ts +10 -8
  250. package/lib/esm/transactionPlan/error.js +10 -8
  251. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  252. package/lib/esm/transactionPlan/index.d.ts +18 -0
  253. package/lib/esm/transactionPlan/index.js +9 -0
  254. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  255. package/lib/esm/transactionPlan/intent.js +14 -7
  256. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  257. package/lib/esm/transactionPlan/permit.js +86 -20
  258. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  259. package/lib/esm/transactionPlan/plan.js +73 -20
  260. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  261. package/lib/esm/transactionPlan/redeem.js +59 -0
  262. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  263. package/lib/esm/transactionPlan/requirements.js +12 -6
  264. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  265. package/lib/esm/transactionPlan/serde.js +45 -19
  266. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  267. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  268. package/lib/esm/transactionPlan/types.d.ts +117 -11
  269. package/lib/esm/transactionPlan/validateActions.js +11 -1
  270. package/lib/esm/transactionPlan/validation.js +6 -3
  271. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  272. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  273. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  274. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  275. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  276. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  277. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  278. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  279. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  280. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  281. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
  282. package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
  283. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  284. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  285. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  286. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  287. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  288. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  289. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  290. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  291. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  292. package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
  293. package/lib/esm/transactionPlan/version.js +2 -1
  294. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  295. package/lib/esm/transactionPlan/withdraw.js +90 -0
  296. package/lib/esm/types/action.d.ts +26 -2
  297. package/lib/esm/types/action.js +17 -9
  298. package/lib/esm/types/error.d.ts +8 -1
  299. package/lib/esm/types/error.js +21 -6
  300. package/lib/esm/types/metadata.d.ts +12 -2
  301. package/lib/esm/version.d.ts +1 -1
  302. package/lib/esm/version.js +1 -1
  303. package/package.json +15 -14
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareVaultV2ForceWithdraw = prepareVaultV2ForceWithdraw;
4
+ exports.buildVaultV2ForceWithdraw = buildVaultV2ForceWithdraw;
5
+ exports.validateForceWithdrawPlanAction = validateForceWithdrawPlanAction;
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const viem_1 = require("viem");
8
+ const common_js_1 = require("../../actions/bundles/common.js");
9
+ const forceWithdraw_js_1 = require("../../actions/vaultV2/forceWithdraw.js");
10
+ const getVaultV2ForceWithdrawRequirements_js_1 = require("../../entities/requirements/getVaultV2ForceWithdrawRequirements.js");
11
+ const forceWithdrawQuote_js_1 = require("../../entities/vaultV2/forceWithdrawQuote.js");
12
+ const validate_js_1 = require("../../helpers/validate.js");
13
+ const index_js_1 = require("../../types/index.js");
14
+ const error_js_1 = require("../error.js");
15
+ const intent_js_1 = require("../intent.js");
16
+ const permit_js_1 = require("../permit.js");
17
+ const requirements_js_1 = require("../requirements.js");
18
+ const validation_js_1 = require("../validation.js");
19
+ /**
20
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
21
+ * Prepares a static forced-exit plan using shared snapshot quoting and requirement helpers.
22
+ * The adapter and realized share-price floor are fixed at preparation. VaultExitBundlesV1
23
+ * withdraws penalty-free liquidity first, then force-deallocates the remaining assets onchain.
24
+ * No fetch requests or Permit2 prerequisites are needed.
25
+ * @param client - Plain viem client for `params.chainId`, used for allowance, nonce and code reads.
26
+ * @param params.vault - Caller-fetched accrual snapshot used for the exit quote; its address identifies the vault.
27
+ * @param params.chainId - Chain containing the vault and registered VaultExitBundlesV1 contract.
28
+ * @param params.account - Non-zero account signing and sending the exit and receiving its assets.
29
+ * @param params.assets - Positive penalty-inclusive exit assets in asset base units; received assets exclude penalties and referral fees.
30
+ * @param params.adapter - Optional assertion that this address is the vault's sole supported adapter.
31
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance used to derive the realized share-price floor; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
32
+ * @param params.referralFee.bps - Optional integer fee in basis points of withdrawn assets, after penalties; defaults to zero and must be below 10,000. The fee is deducted after the share-price check.
33
+ * @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
34
+ * @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; insufficient allowance produces an unlimited direct share approval, or an unlimited share permit when `true`.
35
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
36
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now` and within the fee-projection horizon; defaults to `now + 2h`.
37
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
38
+ * @returns A deep-frozen plan containing ordered share approvals, if needed, followed by the forced exit and its concrete permit request, if needed.
39
+ * @throws {ZeroAccountError} when `account` is the zero address.
40
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
41
+ * @throws {NonPositiveInputError} when `expiresAt` or `assets` is not positive.
42
+ * @throws {ExpiredDeadlineError} when the expiry has elapsed, including during requirement resolution.
43
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
44
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
45
+ * @throws {InputExceedsMaxError} when the fee exceeds 10,000 bps, an input exceeds uint256 or the expiry exceeds the fee-projection horizon.
46
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
47
+ * @throws {ChainIdMismatchError} when the client declares or serves another chain.
48
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
49
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
50
+ * @throws {VaultV2SingleAdapterRequiredError} when the snapshot does not have exactly one adapter.
51
+ * @throws {AdapterNotPartOfVaultError} when the adapter assertion does not match the vault's adapter.
52
+ * @throws {VaultV2UnsupportedExitAdapterError} when the sole adapter is not a MorphoMarketV1AdapterV2.
53
+ * @throws {VaultV2UnsupportedLiquidityAdapterError} when the liquidity adapter is neither unset nor the sole supported adapter.
54
+ * @throws {VaultV2UndecodableLiquidityDataError} when the configured liquidity data cannot be decoded as market parameters.
55
+ * @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit produces no assets after penalties.
56
+ * @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the required deallocation.
57
+ * @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when projected fee mints erase the net share burn.
58
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds to zero.
59
+ * @throws {UnsupportedChainIdError} when the chain has no address registry.
60
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the chain.
61
+ * @throws {MissingContractCodeError} when the registered exit bundle has no code.
62
+ * @throws {viem.BaseError} when a chain, code, allowance or nonce read fails.
63
+ * @throws {UnexpectedRequirementSignatureError} when a permit requirement omits its nonce.
64
+ * @throws {UnsupportedRequirementSignatureError} when a requirement is neither an approval nor an ERC-2612 permit.
65
+ * @example
66
+ * ```ts
67
+ * import { prepareVaultV2ForceWithdraw, buildTransactions } from "@morpho-org/morpho-sdk";
68
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
69
+ * import { createPublicClient, http, type Address } from "viem";
70
+ * import { mainnet } from "viem/chains";
71
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
72
+ * export async function forceWithdraw(vault: Address, account: Address) {
73
+ * const plan = await prepareVaultV2ForceWithdraw(client, {
74
+ * account, chainId: 1, assets: 1_000_000n,
75
+ * vault: await fetchAccrualVaultV2(vault, client),
76
+ * now: (await client.getBlock()).timestamp,
77
+ * });
78
+ * return buildTransactions(plan); // Submit approvals before the exit, from account.
79
+ * }
80
+ * ```
81
+ */
82
+ async function prepareVaultV2ForceWithdraw(client, params) {
83
+ const { chainId, account } = params;
84
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
85
+ const intent = (0, intent_js_1.resolveIntent)(params, now);
86
+ (0, validate_js_1.validateChainId)(client.chain?.id, chainId);
87
+ const quote = (0, forceWithdrawQuote_js_1.computeVaultV2ForceWithdrawQuote)({
88
+ vaultData: params.vault,
89
+ vault: params.vault.address,
90
+ userAddress: account,
91
+ deadline: intent.deadline,
92
+ now,
93
+ exitAssets: params.assets,
94
+ adapter: params.adapter,
95
+ slippageTolerance: params.slippageTolerance,
96
+ referralFeePct: intent.referralFeePct,
97
+ referralFeeRecipient: intent.referralFeeRecipient,
98
+ });
99
+ const { onBehalf: _onBehalf, exitAssets: assets, ...inputs } = (0, forceWithdraw_js_1.vaultV2ForceWithdraw)({
100
+ vault: { chainId, address: params.vault.address },
101
+ args: {
102
+ exitAssets: params.assets,
103
+ adapter: quote.adapter,
104
+ minSharePriceE27: quote.minSharePriceE27,
105
+ userAddress: account,
106
+ deadline: quote.deadline,
107
+ referralFeePct: intent.referralFeePct,
108
+ referralFeeRecipient: intent.referralFeeRecipient,
109
+ },
110
+ }).action.args;
111
+ const requirements = await (0, getVaultV2ForceWithdrawRequirements_js_1.getVaultV2ForceWithdrawRequirements)(client, {
112
+ vaultData: params.vault,
113
+ vault: params.vault.address,
114
+ userAddress: account,
115
+ chainId,
116
+ deadline: quote.deadline,
117
+ requiredShareAllowance: quote.requiredShareAllowance,
118
+ supportSignature: intent.supportSignature,
119
+ now,
120
+ });
121
+ const approvals = [];
122
+ const signatureRequests = [];
123
+ const tokenPermitRequestId = "vaultV2ForceWithdraw:tokenPermit";
124
+ for (const requirement of requirements) {
125
+ if ((0, index_js_1.isRequirementApproval)(requirement)) {
126
+ approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
127
+ id: "vaultV2ForceWithdraw:approval",
128
+ chainId,
129
+ account,
130
+ denomination: "shares",
131
+ }));
132
+ }
133
+ else if (requirement.action.type === "permit") {
134
+ signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)({ action: requirement.action }, tokenPermitRequestId));
135
+ }
136
+ else {
137
+ throw new index_js_1.UnsupportedRequirementSignatureError(requirement.action.type);
138
+ }
139
+ }
140
+ return (0, morpho_ts_1.deepFreeze)(structuredClone({
141
+ version: 2,
142
+ account,
143
+ chainId,
144
+ expiresAt: intent.expiresAt,
145
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
146
+ steps: [
147
+ ...approvals,
148
+ {
149
+ id: "vaultV2ForceWithdraw",
150
+ label: "Force withdraw from vault",
151
+ action: {
152
+ type: "vaultV2ForceWithdraw",
153
+ inputs: { ...inputs, assets, chainId, account },
154
+ signatureRequestIds: signatureRequests.length > 0
155
+ ? { tokenPermit: tokenPermitRequestId }
156
+ : {},
157
+ },
158
+ },
159
+ ],
160
+ signatureRequests,
161
+ }));
162
+ }
163
+ /** @internal Encodes the forced exit from fixed inputs and its referenced vault-share permit. */
164
+ function buildVaultV2ForceWithdraw(action, requests) {
165
+ const { chainId, account, assets, ...args } = action.inputs;
166
+ if (args.minSharePriceE27 <= 0n) {
167
+ throw new index_js_1.NonPositiveInputError("minSharePriceE27", args.minSharePriceE27);
168
+ }
169
+ const signature = (0, permit_js_1.getVaultPermit)(requests, {
170
+ id: action.signatureRequestIds.tokenPermit,
171
+ asset: action.inputs.vault,
172
+ owner: account,
173
+ });
174
+ const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
175
+ spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1"),
176
+ amount: viem_1.maxUint256,
177
+ deadline: action.inputs.deadline,
178
+ });
179
+ return (0, forceWithdraw_js_1.vaultV2ForceWithdraw)({
180
+ vault: { chainId, address: action.inputs.vault },
181
+ args: {
182
+ ...args,
183
+ exitAssets: assets,
184
+ userAddress: account,
185
+ requirementSignature: permit,
186
+ },
187
+ });
188
+ }
189
+ /** @internal Validates the stored forced withdrawal inputs. */
190
+ function validateForceWithdrawPlanAction(action, path) {
191
+ const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
192
+ (0, validation_js_1.validatePlanFields)(inputs, {
193
+ path: `${path}.inputs`,
194
+ fields: {
195
+ adapter: "address",
196
+ assets: "uint256 bigint",
197
+ minSharePriceE27: "uint256 bigint",
198
+ },
199
+ });
200
+ if (inputs.minSharePriceE27 === 0n) {
201
+ throw new error_js_1.InvalidTransactionPlanError({
202
+ path: `${path}.inputs.minSharePriceE27`,
203
+ reason: "expected a positive share-price floor",
204
+ });
205
+ }
206
+ }
@@ -0,0 +1,113 @@
1
+ import type { AccrualVaultV2, MarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Client } from "viem";
3
+ import { type ReferenceTimestampParams, type Transaction, type VaultV2InKindRedeemAction } from "../../types/index.js";
4
+ import { type IntentParams } from "../intent.js";
5
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
6
+ /**
7
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
8
+ * Caller intent for a penalty-inclusive Vault V2 in-kind exit. The ordered markets and adapter
9
+ * snapshot are validated during preparation; only plain encoding inputs are saved in the plan.
10
+ * @example
11
+ * ```ts
12
+ * import {
13
+ * buildTransactions, parseTransactionPlan, prepareVaultV2InKindRedeem,
14
+ * serializeTransactionPlan, type VaultV2InKindRedeemPlanParams,
15
+ * } from "@morpho-org/morpho-sdk";
16
+ * import { AccrualVaultV2MorphoMarketV1AdapterV2 } from "@morpho-org/morpho-sdk/blue/entities";
17
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
18
+ * import { createPublicClient, http } from "viem";
19
+ * import { base } from "viem/chains";
20
+ *
21
+ * const client = createPublicClient({ chain: base, transport: http() });
22
+ * const vaultAddress = "0x4C7b69b4a82e9E5D8ec60E96516f7A0E17CBC55C";
23
+ * const account = "0x0000000000000000000000000000000000000001";
24
+ * const vault = await fetchAccrualVaultV2(vaultAddress, client);
25
+ * const marketParamsList = vault.accrualAdapters.flatMap((adapter) =>
26
+ * adapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2
27
+ * ? adapter.markets.map(({ params }) => params) : [],
28
+ * );
29
+ * const params: VaultV2InKindRedeemPlanParams = {
30
+ * vault, marketParamsList, chainId: base.id, account, assets: 1_000_000n,
31
+ * };
32
+ * const plan = await prepareVaultV2InKindRedeem(client, params);
33
+ * const restored = parseTransactionPlan(serializeTransactionPlan(plan));
34
+ * const transactions = buildTransactions(restored);
35
+ * ```
36
+ */
37
+ export interface VaultV2InKindRedeemPlanParams extends Omit<IntentParams, "referralFee" | "deployless">, ReferenceTimestampParams {
38
+ readonly vault: AccrualVaultV2;
39
+ /** Penalty-inclusive asset amount, not a number of vault shares. */
40
+ readonly assets: bigint;
41
+ /** Ordered markets consumed greedily after the vault's idle assets. */
42
+ readonly marketParamsList: readonly MarketParams[];
43
+ /** Defaults to the snapshot's sole MorphoMarketV1AdapterV2. */
44
+ readonly adapter?: Address;
45
+ }
46
+ /**
47
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
48
+ * Prepares the existing Vault V2 in-kind exit through VaultExitBundlesV1. Preparation validates
49
+ * the snapshot, fixes adapter/market routing, and reads share allowance, nonce and Blue liquidity.
50
+ * No deferred fetch is needed. Sufficient allowance needs no request; otherwise preparation
51
+ * selects an unlimited direct approval or, with signature support, an unlimited ERC-2612 permit.
52
+ * Permit2 is never used. Building the saved plan performs no RPC or signing.
53
+ * The asset-denominated exit has no on-chain share-price or max-shares bound; a price drop before
54
+ * inclusion can burn more shares than quoted.
55
+ * @param client - Client used only during preparation.
56
+ * @param params - Account, snapshot, ordered markets and penalty-inclusive exit amount.
57
+ * @param params.vault - Caller-fetched AccrualVaultV2 snapshot; its address identifies the vault.
58
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
59
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
60
+ * @returns A static, serializable plan with optional share authorization prerequisites.
61
+ * @throws {ZeroAccountError} when `account` is the zero address.
62
+ * @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
63
+ * @throws {NonPositiveInputError} when `expiresAt` or `assets` is not positive.
64
+ * @throws {ExpiredDeadlineError} when the deadline has elapsed before preparation or permit creation finishes.
65
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
66
+ * @throws {ChainIdMismatchError} when the client declares or its endpoint serves another chain.
67
+ * @throws {VaultV2SingleAdapterRequiredError} when the snapshot does not contain exactly one adapter.
68
+ * @throws {AdapterNotPartOfVaultError} when `adapter` differs from the snapshot's sole adapter.
69
+ * @throws {VaultV2UnsupportedExitAdapterError} when the sole adapter is not a MorphoMarketV1AdapterV2.
70
+ * @throws {InKindRedeemZeroDeallocationError} when the exit yields neither idle assets nor a nonzero deallocation after penalties.
71
+ * @throws {EmptyMarketParamsListError} when deallocation is needed but no markets are supplied.
72
+ * @throws {InKindRedeemCoverageError} when the supplied markets cannot cover the non-idle exit amount.
73
+ * @throws {UnsupportedMarketIrmError} when snapshot accrual needs to project an unsupported nonzero market IRM.
74
+ * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
75
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 or Blue is not registered on the chain.
76
+ * @throws {MissingContractCodeError} when a registered VaultExitBundlesV1 or Blue target has no deployed bytecode.
77
+ * @throws {InsufficientBlueBalanceForInKindRedeemError} when Blue's asset balance cannot fund the largest market leg.
78
+ * @throws {UnsupportedRequirementSignatureError} when the wrapped flow returns a signature requirement other than an ERC-2612 permit.
79
+ * @throws {UnexpectedRequirementSignatureError} when a returned permit requirement omits its nonce.
80
+ * @throws {viem.BaseError} when an RPC read fails or the amount or market inputs cannot be ABI-encoded.
81
+ * @example
82
+ * ```ts
83
+ * import {
84
+ * buildTransactions, parseTransactionPlan, prepareVaultV2InKindRedeem,
85
+ * serializeTransactionPlan,
86
+ * } from "@morpho-org/morpho-sdk";
87
+ * import { AccrualVaultV2MorphoMarketV1AdapterV2 } from "@morpho-org/morpho-sdk/blue/entities";
88
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
89
+ * import { createPublicClient, http } from "viem";
90
+ * import { base } from "viem/chains";
91
+ *
92
+ * const client = createPublicClient({ chain: base, transport: http() });
93
+ * const vaultAddress = "0x4C7b69b4a82e9E5D8ec60E96516f7A0E17CBC55C";
94
+ * const account = "0x0000000000000000000000000000000000000001";
95
+ * const vault = await fetchAccrualVaultV2(vaultAddress, client);
96
+ * const marketParamsList = vault.accrualAdapters.flatMap((adapter) =>
97
+ * adapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2
98
+ * ? adapter.markets.map(({ params }) => params) : [],
99
+ * );
100
+ * const plan = await prepareVaultV2InKindRedeem(client, {
101
+ * vault, marketParamsList, chainId: base.id, account, assets: 1_000_000n,
102
+ * });
103
+ * const restored = parseTransactionPlan(serializeTransactionPlan(plan));
104
+ * const transactions = buildTransactions(restored);
105
+ * ```
106
+ */
107
+ export declare function prepareVaultV2InKindRedeem(client: Client, params: VaultV2InKindRedeemPlanParams): Promise<TransactionPlan>;
108
+ /** @internal Encodes only the saved inputs and referenced unlimited share permit. */
109
+ export declare function buildVaultV2InKindRedeem(action: Extract<Action, {
110
+ type: "vaultV2InKindRedeem";
111
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2InKindRedeemAction>>;
112
+ /** @internal Validates the stored in-kind exit's plain encoding inputs. */
113
+ export declare function validateInKindRedeemPlanAction(action: Record<string, unknown>, path: string): void;
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareVaultV2InKindRedeem = prepareVaultV2InKindRedeem;
4
+ exports.buildVaultV2InKindRedeem = buildVaultV2InKindRedeem;
5
+ exports.validateInKindRedeemPlanAction = validateInKindRedeemPlanAction;
6
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
+ const viem_1 = require("viem");
8
+ const common_js_1 = require("../../actions/bundles/common.js");
9
+ const inKindRedeem_js_1 = require("../../actions/vaultV2/inKindRedeem.js");
10
+ const getVaultV2InKindRedeemRequirements_js_1 = require("../../entities/requirements/getVaultV2InKindRedeemRequirements.js");
11
+ const inKindRedeemQuote_js_1 = require("../../entities/vaultV2/inKindRedeemQuote.js");
12
+ const validate_js_1 = require("../../helpers/validate.js");
13
+ const index_js_1 = require("../../types/index.js");
14
+ const intent_js_1 = require("../intent.js");
15
+ const permit_js_1 = require("../permit.js");
16
+ const requirements_js_1 = require("../requirements.js");
17
+ const validation_js_1 = require("../validation.js");
18
+ /**
19
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
20
+ * Prepares the existing Vault V2 in-kind exit through VaultExitBundlesV1. Preparation validates
21
+ * the snapshot, fixes adapter/market routing, and reads share allowance, nonce and Blue liquidity.
22
+ * No deferred fetch is needed. Sufficient allowance needs no request; otherwise preparation
23
+ * selects an unlimited direct approval or, with signature support, an unlimited ERC-2612 permit.
24
+ * Permit2 is never used. Building the saved plan performs no RPC or signing.
25
+ * The asset-denominated exit has no on-chain share-price or max-shares bound; a price drop before
26
+ * inclusion can burn more shares than quoted.
27
+ * @param client - Client used only during preparation.
28
+ * @param params - Account, snapshot, ordered markets and penalty-inclusive exit amount.
29
+ * @param params.vault - Caller-fetched AccrualVaultV2 snapshot; its address identifies the vault.
30
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
31
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
32
+ * @returns A static, serializable plan with optional share authorization prerequisites.
33
+ * @throws {ZeroAccountError} when `account` is the zero address.
34
+ * @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
35
+ * @throws {NonPositiveInputError} when `expiresAt` or `assets` is not positive.
36
+ * @throws {ExpiredDeadlineError} when the deadline has elapsed before preparation or permit creation finishes.
37
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
38
+ * @throws {ChainIdMismatchError} when the client declares or its endpoint serves another chain.
39
+ * @throws {VaultV2SingleAdapterRequiredError} when the snapshot does not contain exactly one adapter.
40
+ * @throws {AdapterNotPartOfVaultError} when `adapter` differs from the snapshot's sole adapter.
41
+ * @throws {VaultV2UnsupportedExitAdapterError} when the sole adapter is not a MorphoMarketV1AdapterV2.
42
+ * @throws {InKindRedeemZeroDeallocationError} when the exit yields neither idle assets nor a nonzero deallocation after penalties.
43
+ * @throws {EmptyMarketParamsListError} when deallocation is needed but no markets are supplied.
44
+ * @throws {InKindRedeemCoverageError} when the supplied markets cannot cover the non-idle exit amount.
45
+ * @throws {UnsupportedMarketIrmError} when snapshot accrual needs to project an unsupported nonzero market IRM.
46
+ * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
47
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 or Blue is not registered on the chain.
48
+ * @throws {MissingContractCodeError} when a registered VaultExitBundlesV1 or Blue target has no deployed bytecode.
49
+ * @throws {InsufficientBlueBalanceForInKindRedeemError} when Blue's asset balance cannot fund the largest market leg.
50
+ * @throws {UnsupportedRequirementSignatureError} when the wrapped flow returns a signature requirement other than an ERC-2612 permit.
51
+ * @throws {UnexpectedRequirementSignatureError} when a returned permit requirement omits its nonce.
52
+ * @throws {viem.BaseError} when an RPC read fails or the amount or market inputs cannot be ABI-encoded.
53
+ * @example
54
+ * ```ts
55
+ * import {
56
+ * buildTransactions, parseTransactionPlan, prepareVaultV2InKindRedeem,
57
+ * serializeTransactionPlan,
58
+ * } from "@morpho-org/morpho-sdk";
59
+ * import { AccrualVaultV2MorphoMarketV1AdapterV2 } from "@morpho-org/morpho-sdk/blue/entities";
60
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
61
+ * import { createPublicClient, http } from "viem";
62
+ * import { base } from "viem/chains";
63
+ *
64
+ * const client = createPublicClient({ chain: base, transport: http() });
65
+ * const vaultAddress = "0x4C7b69b4a82e9E5D8ec60E96516f7A0E17CBC55C";
66
+ * const account = "0x0000000000000000000000000000000000000001";
67
+ * const vault = await fetchAccrualVaultV2(vaultAddress, client);
68
+ * const marketParamsList = vault.accrualAdapters.flatMap((adapter) =>
69
+ * adapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2
70
+ * ? adapter.markets.map(({ params }) => params) : [],
71
+ * );
72
+ * const plan = await prepareVaultV2InKindRedeem(client, {
73
+ * vault, marketParamsList, chainId: base.id, account, assets: 1_000_000n,
74
+ * });
75
+ * const restored = parseTransactionPlan(serializeTransactionPlan(plan));
76
+ * const transactions = buildTransactions(restored);
77
+ * ```
78
+ */
79
+ async function prepareVaultV2InKindRedeem(client, params) {
80
+ const { vault, chainId, account } = params;
81
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
82
+ const intent = (0, intent_js_1.resolveIntent)(params, now);
83
+ (0, validate_js_1.validateChainId)(client.chain?.id, chainId);
84
+ const quote = (0, inKindRedeemQuote_js_1.computeVaultV2InKindRedeemQuote)({
85
+ vaultData: vault,
86
+ vault: vault.address,
87
+ deadline: intent.deadline,
88
+ now,
89
+ amount: params.assets,
90
+ marketParamsList: params.marketParamsList,
91
+ adapter: params.adapter,
92
+ });
93
+ const { onBehalf: _onBehalf, amount: assets, ...inputs } = (0, inKindRedeem_js_1.vaultV2InKindRedeem)({
94
+ vault: { chainId, address: vault.address },
95
+ args: {
96
+ amount: params.assets,
97
+ marketParamsList: quote.marketParamsListSnapshot,
98
+ userAddress: account,
99
+ deadline: quote.deadline,
100
+ adapter: quote.adapter,
101
+ },
102
+ }).action.args;
103
+ const requirements = await (0, getVaultV2InKindRedeemRequirements_js_1.getVaultV2InKindRedeemRequirements)(client, {
104
+ vaultData: vault,
105
+ vault: vault.address,
106
+ userAddress: account,
107
+ chainId,
108
+ deadline: quote.deadline,
109
+ requiredShareAllowance: quote.requiredShareAllowance,
110
+ supportSignature: intent.supportSignature,
111
+ peak: quote.peak,
112
+ now,
113
+ });
114
+ const approvals = [];
115
+ const signatureRequests = [];
116
+ const tokenPermit = "vaultV2InKindRedeem:tokenPermit";
117
+ for (const requirement of requirements) {
118
+ if ((0, index_js_1.isRequirementApproval)(requirement)) {
119
+ approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
120
+ id: "vaultV2InKindRedeem:approval",
121
+ chainId,
122
+ account,
123
+ denomination: "shares",
124
+ }));
125
+ }
126
+ else if (requirement.action.type === "permit") {
127
+ signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)({ action: requirement.action }, tokenPermit));
128
+ }
129
+ else {
130
+ throw new index_js_1.UnsupportedRequirementSignatureError(requirement.action.type);
131
+ }
132
+ }
133
+ return (0, morpho_ts_1.deepFreeze)(structuredClone({
134
+ version: 2,
135
+ chainId,
136
+ account,
137
+ expiresAt: intent.expiresAt,
138
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
139
+ steps: [
140
+ ...approvals,
141
+ {
142
+ id: "vaultV2InKindRedeem",
143
+ label: "Redeem vault in kind",
144
+ action: {
145
+ type: "vaultV2InKindRedeem",
146
+ inputs: { ...inputs, assets, chainId, account },
147
+ signatureRequestIds: signatureRequests.length
148
+ ? { tokenPermit }
149
+ : {},
150
+ },
151
+ },
152
+ ],
153
+ signatureRequests,
154
+ }));
155
+ }
156
+ /** @internal Encodes only the saved inputs and referenced unlimited share permit. */
157
+ function buildVaultV2InKindRedeem(action, requests) {
158
+ const { chainId, account, assets, ...args } = action.inputs;
159
+ const signature = (0, permit_js_1.getVaultPermit)(requests, {
160
+ id: action.signatureRequestIds.tokenPermit,
161
+ asset: args.vault,
162
+ owner: account,
163
+ });
164
+ const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
165
+ spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1"),
166
+ amount: viem_1.maxUint256,
167
+ deadline: args.deadline,
168
+ });
169
+ return (0, inKindRedeem_js_1.vaultV2InKindRedeem)({
170
+ vault: { chainId, address: args.vault },
171
+ args: {
172
+ ...args,
173
+ amount: assets,
174
+ userAddress: account,
175
+ requirementSignature: permit,
176
+ },
177
+ });
178
+ }
179
+ /** @internal Validates the stored in-kind exit's plain encoding inputs. */
180
+ function validateInKindRedeemPlanAction(action, path) {
181
+ const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
182
+ (0, validation_js_1.validatePlanFields)(inputs, {
183
+ path: `${path}.inputs`,
184
+ fields: {
185
+ vault: "address",
186
+ adapter: "address",
187
+ assets: "uint256 bigint",
188
+ deadline: "uint256 bigint",
189
+ marketParamsList: "array",
190
+ },
191
+ });
192
+ (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
193
+ for (const [index, value] of inputs.marketParamsList.entries()) {
194
+ const marketPath = `${path}.inputs.marketParamsList[${index}]`;
195
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(value, marketPath), {
196
+ path: marketPath,
197
+ fields: {
198
+ loanToken: "address",
199
+ collateralToken: "address",
200
+ oracle: "address",
201
+ irm: "address",
202
+ lltv: "uint256 bigint",
203
+ },
204
+ });
205
+ }
206
+ }
@@ -0,0 +1,84 @@
1
+ import type { Client } from "viem";
2
+ import type { Transaction, VaultV2RedeemAction } from "../../types/index.js";
3
+ import { type RedeemPlanParams } from "../redeem.js";
4
+ import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
5
+ /**
6
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
7
+ * Caller intent for redeeming an exact number of Vault V2 shares.
8
+ * No minimum assets received is enforced, matching `vaultV2.redeem()`.
9
+ * @example
10
+ * ```ts
11
+ * import { Token } from "@morpho-org/morpho-sdk/blue/entities";
12
+ * import type { VaultV2RedeemPlanParams } from "@morpho-org/morpho-sdk";
13
+ * import type { Address } from "viem";
14
+ * import { mainnet } from "viem/chains";
15
+ *
16
+ * // Supply a non-zero share owner and positive shares in share base units.
17
+ * export function redeemParams(account: Address, shares: bigint): VaultV2RedeemPlanParams {
18
+ * const params: VaultV2RedeemPlanParams = {
19
+ * shareToken: new Token({ address: "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" }),
20
+ * chainId: mainnet.id, account, shares, supportSignature: false,
21
+ * };
22
+ * // params: VaultV2RedeemPlanParams = { shareToken, chainId: 1, account, shares, supportSignature: false }.
23
+ * return params;
24
+ * }
25
+ * ```
26
+ */
27
+ export interface VaultV2RedeemPlanParams extends RedeemPlanParams {
28
+ }
29
+ /**
30
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
31
+ * Prepares an exact-share redemption through VaultBundlesV1. Reads share allowance and, when a
32
+ * permit is needed, the vault nonce. No quote or fetch request is needed for an exact share count.
33
+ * @param client - Viem client targeting `params.chainId`.
34
+ * @param params.shareToken - Vault share token; an address-only Token is sufficient, without an accrual snapshot.
35
+ * @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
36
+ * @param params.account - Non-zero share owner, permit signer and transaction sender; receives the net assets.
37
+ * @param params.shares - Positive exact shares to burn, in share base units; use the account's balance for full redemption.
38
+ * @param params.referralFee.bps - Optional integer fee in basis points of gross redeemed assets; defaults to zero and must be below 10,000.
39
+ * @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
40
+ * @param params.supportSignature - Optional ERC-2612 share-permit preference; defaults to `false` for direct approval.
41
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
42
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
43
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
44
+ * @returns A deep-frozen, serializable `TransactionPlan` with version, chain, account, expiry,
45
+ * ordered approval/redeem steps and signature requests. Any required share approval or permit is unlimited.
46
+ * @throws {ZeroAccountError} when `account` is the zero address.
47
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
48
+ * @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
49
+ * @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
50
+ * @throws {NegativeInputError} when `referralFee.bps` is negative.
51
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
52
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
53
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
54
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
55
+ * @throws {ChainIdMismatchError} when the declared or RPC chain differs from `chainId`.
56
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
57
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
58
+ * @throws {MissingContractCodeError} when VaultBundlesV1 is absent on the target chain.
59
+ * @throws {viem.BaseError} when a chain, bytecode, allowance or permit nonce read fails.
60
+ * @example
61
+ * ```ts
62
+ * import { Token } from "@morpho-org/morpho-sdk/blue/entities";
63
+ * import { prepareVaultV2Redeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
64
+ * import { type Address, createPublicClient, http } from "viem";
65
+ * import { mainnet } from "viem/chains";
66
+ *
67
+ * // Supply a non-zero share owner and its desired redemption shares in share base units.
68
+ * export async function prepareRedeem(account: Address, shares: bigint): Promise<TransactionPlan> {
69
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
70
+ * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
71
+ * const plan = await prepareVaultV2Redeem(client, {
72
+ * shareToken: new Token({ address: vault }), chainId: mainnet.id, account, shares, supportSignature: false,
73
+ * });
74
+ * // plan: TransactionPlan = { version: 2, chainId: 1, account, expiresAt,
75
+ * // steps: [optional unlimited approval, vaultV2Redeem], signatureRequests: [] }.
76
+ * return plan;
77
+ * }
78
+ * ```
79
+ */
80
+ export declare function prepareVaultV2Redeem(client: Client, params: VaultV2RedeemPlanParams): Promise<TransactionPlan>;
81
+ /** @internal Encodes a redemption from its fixed inputs and referenced share permit. */
82
+ export declare function buildVaultV2Redeem(action: Extract<Action, {
83
+ type: "vaultV2Redeem";
84
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2RedeemAction>>;