@morpho-org/morpho-sdk 10.0.0-next.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 (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
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateForceRedeemPlanAction = validateForceRedeemPlanAction;
4
+ exports.prepareVaultV2ForceRedeem = prepareVaultV2ForceRedeem;
5
+ exports.buildVaultV2ForceRedeem = buildVaultV2ForceRedeem;
6
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
8
+ const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
9
+ const forceRedeem_js_1 = require("../../actions/vaultV2/forceRedeem.js");
10
+ const intent_js_1 = require("../intent.js");
11
+ const validation_js_1 = require("../validation.js");
12
+ /** @internal Validates the stored force-redeem action's plain input shape. */
13
+ function validateForceRedeemPlanAction(action, path) {
14
+ const inputPath = `${path}.inputs`;
15
+ const inputs = (0, validation_js_1.getPlanObject)(action.inputs, inputPath);
16
+ (0, validation_js_1.validatePlanFields)(inputs, {
17
+ path: inputPath,
18
+ fields: { vault: "address", deallocations: "array" },
19
+ });
20
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(inputs.redeem, `${inputPath}.redeem`), {
21
+ path: `${inputPath}.redeem`,
22
+ fields: { shares: "uint256 bigint" },
23
+ });
24
+ for (const [index, value] of inputs.deallocations.entries()) {
25
+ const entryPath = `${inputPath}.deallocations[${index}]`;
26
+ const entry = (0, validation_js_1.getPlanObject)(value, entryPath);
27
+ (0, validation_js_1.validatePlanFields)(entry, {
28
+ path: entryPath,
29
+ fields: { adapter: "address", assets: "uint256 bigint" },
30
+ });
31
+ if (entry.marketParams !== undefined) {
32
+ (0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.marketParams, `${entryPath}.marketParams`), {
33
+ path: `${entryPath}.marketParams`,
34
+ fields: {
35
+ loanToken: "address",
36
+ collateralToken: "address",
37
+ oracle: "address",
38
+ irm: "address",
39
+ lltv: "uint256 bigint",
40
+ },
41
+ });
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
47
+ * Prepares one vault multicall, fixing the supplied deallocations and shares in the plan.
48
+ * Shares and deallocation penalties are burned from `account`; redeemed assets go to `account`.
49
+ * No permissions are requested, and expiry is plan metadata, not an onchain deadline.
50
+ * @param client - Client used to validate the chain, not retained by the plan.
51
+ * @param params.vaultAddress - Vault V2 whose shares are redeemed.
52
+ * @param params.chainId - Chain containing the vault.
53
+ * @param params.account - Share owner submitting the multicall and receiving the redeemed assets.
54
+ * @param params.shares - Positive shares to redeem, in vault share base units.
55
+ * @param params.deallocations - Non-empty, ordered deallocations with positive `assets` in asset base units, including any penalty buffer.
56
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
57
+ * @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` and is plan metadata only.
58
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
59
+ * @returns A deep-frozen `TransactionPlan` containing one `vaultV2ForceRedeem` step and no signature requests.
60
+ * @throws {ChainIdMismatchError} If the client targets another chain.
61
+ * @throws {EmptyDeallocationsError} If `deallocations` is empty.
62
+ * @throws {NonPositiveInputError} If expiry, shares or any deallocation assets are non-positive.
63
+ * @throws {ZeroAccountError} If `account` is the zero address.
64
+ * @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
65
+ * @throws {ExpiredDeadlineError} If `expiresAt` is not in the future.
66
+ * @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
67
+ * @example
68
+ * ```ts
69
+ * import { prepareVaultV2ForceRedeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
70
+ * import { createPublicClient, http } from "viem";
71
+ * import { mainnet } from "viem/chains";
72
+ *
73
+ * // Fixture addresses for preparation only; use your vault, adapter and share owner before execution.
74
+ * const IN_KIND_VAULT = "0x0000000000000000000000000000000000001001";
75
+ * const IN_KIND_ADAPTER = "0x0000000000000000000000000000000000001002";
76
+ * const IN_KIND_USER = "0x0000000000000000000000000000000000001004";
77
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
78
+ * const plan: TransactionPlan = await prepareVaultV2ForceRedeem(client, {
79
+ * vaultAddress: IN_KIND_VAULT, chainId: mainnet.id, account: IN_KIND_USER,
80
+ * shares: 100n,
81
+ * now: (await client.getBlock()).timestamp,
82
+ * deallocations: [{ adapter: IN_KIND_ADAPTER, assets: 100n }],
83
+ * });
84
+ * // plan.steps contains one step with action.type === "vaultV2ForceRedeem".
85
+ * // plan.signatureRequests is []; the caller signs and submits the built transaction.
86
+ * ```
87
+ */
88
+ async function prepareVaultV2ForceRedeem(client, params) {
89
+ const now = params.now ?? morpho_ts_1.Time.timestamp();
90
+ const intent = (0, intent_js_1.resolveIntent)(params, now);
91
+ const plan = structuredClone({
92
+ version: 2,
93
+ account: params.account,
94
+ chainId: params.chainId,
95
+ expiresAt: intent.expiresAt,
96
+ ...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
97
+ steps: [
98
+ {
99
+ id: "vaultV2ForceRedeem",
100
+ label: "Force redeem from vault",
101
+ action: {
102
+ type: "vaultV2ForceRedeem",
103
+ inputs: {
104
+ chainId: params.chainId,
105
+ account: params.account,
106
+ vault: params.vaultAddress,
107
+ redeem: { shares: params.shares },
108
+ deallocations: params.deallocations.map(({ adapter, assets, marketParams }) => ({
109
+ adapter,
110
+ assets,
111
+ ...(marketParams && {
112
+ marketParams: {
113
+ loanToken: marketParams.loanToken,
114
+ collateralToken: marketParams.collateralToken,
115
+ oracle: marketParams.oracle,
116
+ irm: marketParams.irm,
117
+ lltv: marketParams.lltv,
118
+ },
119
+ }),
120
+ })),
121
+ },
122
+ },
123
+ },
124
+ ],
125
+ signatureRequests: [],
126
+ });
127
+ // Validate the cloned inputs with the action encoder before returning a plan.
128
+ buildVaultV2ForceRedeem(plan.steps[0].action);
129
+ await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
130
+ return (0, morpho_ts_1.deepFreeze)(plan);
131
+ }
132
+ /** @internal Encodes the fixed multicall through the same action as the forceRedeem handle. */
133
+ function buildVaultV2ForceRedeem(action) {
134
+ return (0, forceRedeem_js_1.vaultV2ForceRedeem)({
135
+ vault: { address: action.inputs.vault },
136
+ args: {
137
+ deallocations: action.inputs.deallocations.map(({ adapter, assets, marketParams }) => ({
138
+ adapter,
139
+ amount: assets,
140
+ ...(marketParams && {
141
+ marketParams: {
142
+ ...marketParams,
143
+ id: blue_sdk_1.MarketUtils.getMarketId(marketParams),
144
+ liquidationIncentiveFactor: blue_sdk_1.MarketUtils.getLiquidationIncentiveFactor(marketParams),
145
+ },
146
+ }),
147
+ })),
148
+ redeem: {
149
+ shares: action.inputs.redeem.shares,
150
+ recipient: action.inputs.account,
151
+ },
152
+ onBehalf: action.inputs.account,
153
+ },
154
+ });
155
+ }
@@ -0,0 +1,98 @@
1
+ import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Client } from "viem";
3
+ import { type ReferenceTimestampParams, type Transaction, type VaultV2ForceWithdrawAction } 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 Vault V2 forced exit through VaultExitBundlesV1.
9
+ * @example
10
+ * ```ts
11
+ * import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
12
+ * import type { VaultV2ForceWithdrawPlanParams } from "@morpho-org/morpho-sdk";
13
+ * import type { Address } from "viem";
14
+ * const intent = (vault: AccrualVaultV2, account: Address): VaultV2ForceWithdrawPlanParams => ({
15
+ * vault, account, chainId: 1, assets: 1_000_000n,
16
+ * });
17
+ * ```
18
+ */
19
+ export interface VaultV2ForceWithdrawPlanParams extends Omit<IntentParams, "deployless">, ReferenceTimestampParams {
20
+ /** Snapshot fetched by the caller; never stored in the plan. */
21
+ readonly vault: AccrualVaultV2;
22
+ /** Penalty-inclusive assets debited; received assets exclude penalties and referral fees. */
23
+ readonly assets: bigint;
24
+ /** Optional assertion that this is the vault's sole supported adapter. */
25
+ readonly adapter?: Address;
26
+ /** WAD-scaled tolerance for the derived floor; omitted values use the entity default. */
27
+ readonly slippageTolerance?: bigint;
28
+ }
29
+ /**
30
+ * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
31
+ * Prepares a static forced-exit plan using shared snapshot quoting and requirement helpers.
32
+ * The adapter and realized share-price floor are fixed at preparation. VaultExitBundlesV1
33
+ * withdraws penalty-free liquidity first, then force-deallocates the remaining assets onchain.
34
+ * No fetch requests or Permit2 prerequisites are needed.
35
+ * @param client - Plain viem client for `params.chainId`, used for allowance, nonce and code reads.
36
+ * @param params.vault - Caller-fetched accrual snapshot used for the exit quote; its address identifies the vault.
37
+ * @param params.chainId - Chain containing the vault and registered VaultExitBundlesV1 contract.
38
+ * @param params.account - Non-zero account signing and sending the exit and receiving its assets.
39
+ * @param params.assets - Positive penalty-inclusive exit assets in asset base units; received assets exclude penalties and referral fees.
40
+ * @param params.adapter - Optional assertion that this address is the vault's sole supported adapter.
41
+ * @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`.
42
+ * @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.
43
+ * @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
44
+ * @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`.
45
+ * @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
46
+ * @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`.
47
+ * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
48
+ * @returns A deep-frozen plan containing ordered share approvals, if needed, followed by the forced exit and its concrete permit request, if needed.
49
+ * @throws {ZeroAccountError} when `account` is the zero address.
50
+ * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
51
+ * @throws {NonPositiveInputError} when `expiresAt` or `assets` is not positive.
52
+ * @throws {ExpiredDeadlineError} when the expiry has elapsed, including during requirement resolution.
53
+ * @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
54
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
55
+ * @throws {InputExceedsMaxError} when the fee exceeds 10,000 bps, an input exceeds uint256 or the expiry exceeds the fee-projection horizon.
56
+ * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
57
+ * @throws {ChainIdMismatchError} when the client declares or serves another chain.
58
+ * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
59
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
60
+ * @throws {VaultV2SingleAdapterRequiredError} when the snapshot does not have exactly one adapter.
61
+ * @throws {AdapterNotPartOfVaultError} when the adapter assertion does not match the vault's adapter.
62
+ * @throws {VaultV2UnsupportedExitAdapterError} when the sole adapter is not a MorphoMarketV1AdapterV2.
63
+ * @throws {VaultV2UnsupportedLiquidityAdapterError} when the liquidity adapter is neither unset nor the sole supported adapter.
64
+ * @throws {VaultV2UndecodableLiquidityDataError} when the configured liquidity data cannot be decoded as market parameters.
65
+ * @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit produces no assets after penalties.
66
+ * @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the required deallocation.
67
+ * @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when projected fee mints erase the net share burn.
68
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds to zero.
69
+ * @throws {UnsupportedChainIdError} when the chain has no address registry.
70
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the chain.
71
+ * @throws {MissingContractCodeError} when the registered exit bundle has no code.
72
+ * @throws {viem.BaseError} when a chain, code, allowance or nonce read fails.
73
+ * @throws {UnexpectedRequirementSignatureError} when a permit requirement omits its nonce.
74
+ * @throws {UnsupportedRequirementSignatureError} when a requirement is neither an approval nor an ERC-2612 permit.
75
+ * @example
76
+ * ```ts
77
+ * import { prepareVaultV2ForceWithdraw, buildTransactions } from "@morpho-org/morpho-sdk";
78
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
79
+ * import { createPublicClient, http, type Address } from "viem";
80
+ * import { mainnet } from "viem/chains";
81
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
82
+ * export async function forceWithdraw(vault: Address, account: Address) {
83
+ * const plan = await prepareVaultV2ForceWithdraw(client, {
84
+ * account, chainId: 1, assets: 1_000_000n,
85
+ * vault: await fetchAccrualVaultV2(vault, client),
86
+ * now: (await client.getBlock()).timestamp,
87
+ * });
88
+ * return buildTransactions(plan); // Submit approvals before the exit, from account.
89
+ * }
90
+ * ```
91
+ */
92
+ export declare function prepareVaultV2ForceWithdraw(client: Client, params: VaultV2ForceWithdrawPlanParams): Promise<TransactionPlan>;
93
+ /** @internal Encodes the forced exit from fixed inputs and its referenced vault-share permit. */
94
+ export declare function buildVaultV2ForceWithdraw(action: Extract<Action, {
95
+ type: "vaultV2ForceWithdraw";
96
+ }>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2ForceWithdrawAction>>;
97
+ /** @internal Validates the stored forced withdrawal inputs. */
98
+ export declare function validateForceWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
@@ -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;