@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
@@ -5,7 +5,6 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
- const actions_1 = require("viem/actions");
9
8
  const common_js_1 = require("../../actions/bundles/common.js");
10
9
  const index_js_1 = require("../../actions/index.js");
11
10
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
@@ -15,41 +14,10 @@ const validate_js_1 = require("../../helpers/validate.js");
15
14
  const index_js_3 = require("../../types/index.js");
16
15
  const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
17
16
  const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
17
+ const getVaultV1InKindRedeemRequirements_js_1 = require("../requirements/getVaultV1InKindRedeemRequirements.js");
18
18
  const index_js_4 = require("../requirements/index.js");
19
- function validateInKindCoverage({ amount, marketParamsListSnapshot, vaultData, now, }) {
20
- let covered = 0n;
21
- const assignedByMarket = new Map();
22
- for (const marketParams of marketParamsListSnapshot) {
23
- if (covered === amount)
24
- break;
25
- const marketId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
26
- const allocation = vaultData.allocations.get(marketId);
27
- if (allocation?.config.enabled !== true)
28
- continue;
29
- if (allocation.position.supplyShares === 0n)
30
- continue;
31
- const market = allocation.position.market.accrueInterest(now);
32
- const available = market.toSupplyAssets(allocation.position.supplyShares);
33
- const assigned = assignedByMarket.get(marketId) ?? 0n;
34
- const chunk = blue_sdk_1.MathLib.min(available, amount - covered);
35
- if (assigned + chunk > available) {
36
- throw new index_js_3.InKindRedeemCoverageError({
37
- required: amount,
38
- covered,
39
- maxExitAssets: covered,
40
- });
41
- }
42
- assignedByMarket.set(marketId, assigned + chunk);
43
- covered += chunk;
44
- }
45
- if (covered < amount) {
46
- throw new index_js_3.InKindRedeemCoverageError({
47
- required: amount,
48
- covered,
49
- maxExitAssets: covered,
50
- });
51
- }
52
- }
19
+ const inKindRedeemQuote_js_1 = require("./inKindRedeemQuote.js");
20
+ const migrateToV2Quote_js_1 = require("./migrateToV2Quote.js");
53
21
  function getMigrationAmounts(params) {
54
22
  const assets = "assets" in params ? params.assets : undefined;
55
23
  const shares = "shares" in params ? params.shares : undefined;
@@ -58,7 +26,7 @@ function getMigrationAmounts(params) {
58
26
  }
59
27
  const selectedAmount = assets ?? shares ?? 0n;
60
28
  if (selectedAmount <= 0n) {
61
- throw new index_js_3.NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
29
+ throw new index_js_3.NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
62
30
  }
63
31
  return { assets, shares };
64
32
  }
@@ -108,8 +76,9 @@ class MorphoVaultV1 {
108
76
  }
109
77
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
110
78
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
111
- if (deadline <= createdAt)
79
+ if (deadline <= createdAt) {
112
80
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
81
+ }
113
82
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
114
83
  deadline,
115
84
  referralFeePct: params.referralFeePct,
@@ -134,10 +103,12 @@ class MorphoVaultV1 {
134
103
  return Object.freeze({
135
104
  getRequirements: async (requirementOptions) => {
136
105
  const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
137
- if (deadline <= now)
106
+ if (deadline <= now) {
138
107
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
139
- if (pendingRequirements != null)
108
+ }
109
+ if (pendingRequirements != null) {
140
110
  return await pendingRequirements;
111
+ }
141
112
  // Memoize the in-flight promise so concurrent callers share one round of
142
113
  // allowance/nonce reads.
143
114
  const pending = (async () => {
@@ -163,8 +134,9 @@ class MorphoVaultV1 {
163
134
  }
164
135
  finally {
165
136
  // Later calls must re-read live allowances/nonces and honor their own options.
166
- if (pendingRequirements === pending)
137
+ if (pendingRequirements === pending) {
167
138
  pendingRequirements = undefined;
139
+ }
168
140
  }
169
141
  },
170
142
  buildTx: (signatures) => {
@@ -200,14 +172,16 @@ class MorphoVaultV1 {
200
172
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
201
173
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
202
174
  }
203
- if (amount <= 0n)
175
+ if (amount <= 0n) {
204
176
  throw new index_js_3.NonPositiveInputError("amount", amount);
177
+ }
205
178
  // Reject values outside the ABI range before resolving any requirements.
206
179
  (0, validate_js_1.validateUint256Field)("amount", amount);
207
180
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
208
181
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
209
- if (deadline <= createdAt)
182
+ if (deadline <= createdAt) {
210
183
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
184
+ }
211
185
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
212
186
  deadline,
213
187
  referralFeePct: params.referralFeePct,
@@ -226,8 +200,9 @@ class MorphoVaultV1 {
226
200
  return Object.freeze({
227
201
  getRequirements: async () => {
228
202
  const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
229
- if (deadline <= now)
203
+ if (deadline <= now) {
230
204
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
205
+ }
231
206
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
232
207
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
233
208
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
@@ -268,12 +243,14 @@ class MorphoVaultV1 {
268
243
  const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
269
244
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
270
245
  const { shares, userAddress } = params;
271
- if (shares <= 0n)
246
+ if (shares <= 0n) {
272
247
  throw new index_js_3.NonPositiveInputError("shares", shares);
248
+ }
273
249
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
274
250
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
275
- if (deadline <= createdAt)
251
+ if (deadline <= createdAt) {
276
252
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
253
+ }
277
254
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
278
255
  deadline,
279
256
  referralFeePct: params.referralFeePct,
@@ -283,8 +260,9 @@ class MorphoVaultV1 {
283
260
  return Object.freeze({
284
261
  getRequirements: async () => {
285
262
  const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
286
- if (deadline <= now)
263
+ if (deadline <= now) {
287
264
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
265
+ }
288
266
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
289
267
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
290
268
  vaultData: await this.getData(),
@@ -327,123 +305,26 @@ class MorphoVaultV1 {
327
305
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
328
306
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
329
307
  }
330
- if (amount <= 0n)
331
- throw new index_js_3.NonPositiveInputError("amount", amount);
332
- if (marketParamsList.length === 0)
333
- throw new index_js_3.EmptyMarketParamsListError();
334
- const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
335
- loanToken,
336
- collateralToken,
337
- oracle,
338
- irm,
339
- lltv,
340
- }));
341
- const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
342
- const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
343
- // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
344
- // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
345
- (0, validate_js_1.validateDeadline)(deadline);
346
- if (deadline <= now)
347
- throw new index_js_3.ExpiredDeadlineError(deadline, now);
348
- const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
349
- const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
350
- // Reject insufficient ordered market coverage before preparing share requirements.
351
- validateInKindCoverage({
308
+ const { deadline, marketParamsListSnapshot, requiredShareAllowance, vaultExitBundlesV1, } = (0, inKindRedeemQuote_js_1.computeVaultV1InKindRedeemQuote)({
352
309
  amount,
353
- marketParamsListSnapshot,
310
+ marketParamsList,
354
311
  vaultData,
355
- now,
356
- });
357
- const requiredShareAllowance = (0, index_js_2.computeVaultMaxShareAllowance)({
358
- vaultData,
359
- deadline: now,
360
- assets: amount,
361
- slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
312
+ deadline: deadlineOverride,
313
+ now: suppliedNow ?? morpho_ts_1.Time.timestamp(),
314
+ chainId: this.chainId,
362
315
  });
363
316
  return {
364
- getRequirements: async () => {
365
- const requirementsTimestamp = suppliedNow ?? morpho_ts_1.Time.timestamp();
366
- if (deadline <= requirementsTimestamp) {
367
- throw new index_js_3.ExpiredDeadlineError(deadline, requirementsTimestamp);
368
- }
369
- await (0, validateClientChainId_js_1.validateClientChainId)(this.client.viemClient, this.chainId);
370
- await this.assertWriteTargets(["bundles.vaultExitBundlesV1", "blue"]);
371
- const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await Promise.all([
372
- (0, actions_1.readContract)(this.client.viemClient, {
373
- address: this.vault,
374
- abi: viem_1.erc20Abi,
375
- functionName: "allowance",
376
- args: [userAddress, vaultExitBundlesV1],
377
- }),
378
- (0, actions_1.readContract)(this.client.viemClient, {
379
- address: this.vault,
380
- abi: blue_sdk_viem_1.erc2612Abi,
381
- functionName: "nonces",
382
- args: [userAddress],
383
- }),
384
- (0, actions_1.readContract)(this.client.viemClient, {
385
- address: vaultData.asset,
386
- abi: viem_1.erc20Abi,
387
- functionName: "balanceOf",
388
- args: [blue],
389
- }),
390
- (0, actions_1.readContract)(this.client.viemClient, {
391
- address: this.vault,
392
- abi: blue_sdk_viem_1.metaMorphoAbi,
393
- functionName: "MORPHO",
394
- }),
395
- // feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
396
- (0, actions_1.readContract)(this.client.viemClient, {
397
- address: blue,
398
- abi: blue_sdk_viem_1.blueAbi,
399
- functionName: "feeRecipient",
400
- }),
401
- ]);
402
- if (!(0, viem_1.isAddressEqual)(morpho, blue)) {
403
- throw new index_js_3.VaultMorphoMismatchError({
404
- vault: this.vault,
405
- expected: blue,
406
- actual: morpho,
407
- });
408
- }
409
- // Reject this unsupported configuration before authorizing vault shares:
410
- // VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
411
- // vault position, so its callback can exhaust marketParamsList and panic on-chain.
412
- if ((0, viem_1.isAddressEqual)(blueFeeRecipient, this.vault)) {
413
- throw new index_js_3.VaultIsBlueFeeRecipientError(this.vault, blue);
414
- }
415
- if (blueBalance < amount) {
416
- throw new index_js_3.InsufficientBlueBalanceForInKindRedeemError({
417
- asset: vaultData.asset,
418
- available: blueBalance,
419
- required: amount,
420
- });
421
- }
422
- if (allowance >= requiredShareAllowance)
423
- return [];
424
- if (this.client.options.supportSignature) {
425
- return [
426
- (0, index_js_1.encodeVaultSharesPermit)({
427
- now: suppliedNow == null ? undefined : now,
428
- vault: vaultData,
429
- version: "vaultV1",
430
- spender: vaultExitBundlesV1,
431
- owner: userAddress,
432
- chainId: this.chainId,
433
- nonce,
434
- deadline,
435
- }),
436
- ];
437
- }
438
- return [
439
- (0, index_js_1.encodeErc20Approval)({
440
- token: this.vault,
441
- spender: vaultExitBundlesV1,
442
- amount: viem_1.maxUint256,
443
- chainId: this.chainId,
444
- }),
445
- ];
446
- },
317
+ getRequirements: () => (0, getVaultV1InKindRedeemRequirements_js_1.getVaultV1InKindRedeemRequirements)(this.client.viemClient, {
318
+ vaultData,
319
+ vault: this.vault,
320
+ userAddress,
321
+ chainId: this.chainId,
322
+ deadline,
323
+ requiredShareAllowance,
324
+ supportSignature: this.client.options.supportSignature,
325
+ amount,
326
+ now: suppliedNow,
327
+ }),
447
328
  buildTx: (signatures) => {
448
329
  const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
449
330
  spender: vaultExitBundlesV1,
@@ -483,35 +364,23 @@ class MorphoVaultV1 {
483
364
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
484
365
  const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
485
366
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
486
- if (deadline <= createdAt)
367
+ if (deadline <= createdAt) {
487
368
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
369
+ }
488
370
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
489
371
  deadline,
490
372
  referralFeePct: params.referralFeePct,
491
373
  referralFeeRecipient: params.referralFeeRecipient,
492
374
  });
493
- // Only the destination receives a deposit; the source vault is an exit.
494
- // V1 redeem accrues market interest and performance fees before converting shares.
495
- const grossAssets = assets ??
496
- params.sourceVault
497
- .accrueInterest(params.sourceVault.allocations
498
- .values()
499
- .reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), createdAt))
500
- .toAssets(shares ?? 0n, "Down");
501
- const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, common.referralFeePct);
502
- const maxSharePriceVaultV2 = (0, index_js_2.computeVaultMaxSharePrice)({
503
- vaultData: params.targetVault,
375
+ const { maxSharePriceVaultV2, requiredShareAllowance } = (0, migrateToV2Quote_js_1.computeVaultV1MigrateToV2Quote)({
376
+ sourceVault: params.sourceVault,
377
+ targetVault: params.targetVault,
378
+ ...(assets == null ? { shares: shares ?? 0n } : { assets }),
379
+ referralFeePct: common.referralFeePct,
504
380
  deadline,
505
- assets: grossAssets - referralFeeAssets,
506
381
  slippageTolerance,
382
+ now: createdAt,
507
383
  });
508
- const requiredShareAllowance = shares ??
509
- (0, index_js_2.computeVaultMaxShareAllowance)({
510
- vaultData: params.sourceVault,
511
- deadline,
512
- assets: assets ?? 0n,
513
- slippageTolerance,
514
- });
515
384
  const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
516
385
  const { userAddress } = params;
517
386
  const sourceAsset = params.sourceVault.asset;
@@ -531,8 +400,9 @@ class MorphoVaultV1 {
531
400
  return Object.freeze({
532
401
  getRequirements: async () => {
533
402
  const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
534
- if (deadline <= now)
403
+ if (deadline <= now) {
535
404
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
405
+ }
536
406
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
537
407
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
538
408
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
@@ -561,7 +431,7 @@ class MorphoVaultV1 {
561
431
  args: {
562
432
  targetVault: targetAddress,
563
433
  targetAsset,
564
- ...(assets != null ? { assets } : { shares: shares ?? 0n }),
434
+ ...(assets == null ? { shares: shares ?? 0n } : { assets }),
565
435
  maxSharePriceVaultV2,
566
436
  userAddress,
567
437
  requirementSignature: permit,
@@ -0,0 +1,25 @@
1
+ import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
+ /**
4
+ * @internal Computes the fixed exit quote from a snapshot without reads or signing.
5
+ * @param params - Snapshot, caller intent and explicit quote timestamp.
6
+ * @returns Fixed action fields and the minimum share allowance.
7
+ */
8
+ export declare function computeVaultV2ForceWithdrawQuote({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, now, vault, }: {
9
+ readonly exitAssets: bigint;
10
+ readonly vaultData: AccrualVaultV2;
11
+ readonly userAddress: Address;
12
+ readonly adapter?: Address;
13
+ readonly deadline?: bigint;
14
+ readonly slippageTolerance?: bigint;
15
+ readonly minSharePriceE27?: bigint;
16
+ readonly referralFeePct?: bigint;
17
+ readonly referralFeeRecipient?: Address;
18
+ readonly now: bigint;
19
+ readonly vault: Address;
20
+ }): {
21
+ deadline: bigint;
22
+ adapter: `0x${string}`;
23
+ minSharePriceE27: bigint;
24
+ requiredShareAllowance: bigint;
25
+ };
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeVaultV2ForceWithdrawQuote = computeVaultV2ForceWithdrawQuote;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
9
+ const index_js_2 = require("../../types/index.js");
10
+ const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
11
+ /** Resolves the supported adapter or reports the existing eligibility error. @internal */
12
+ function resolveForceWithdrawAdapter({ vaultData, adapterOverride, vault, }) {
13
+ const eligibility = (0, index_js_1.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
14
+ switch (eligibility.type) {
15
+ case "eligible":
16
+ return eligibility;
17
+ case "adapterCount":
18
+ throw new index_js_2.VaultV2SingleAdapterRequiredError(vault, eligibility.adapters);
19
+ case "adapterMismatch":
20
+ throw new index_js_2.AdapterNotPartOfVaultError(vault, eligibility.adapter);
21
+ case "unsupportedAdapter":
22
+ throw new index_js_2.VaultV2UnsupportedExitAdapterError(eligibility.adapter);
23
+ case "unsupportedLiquidityAdapter":
24
+ throw new index_js_2.VaultV2UnsupportedLiquidityAdapterError({
25
+ vault: vault,
26
+ liquidityAdapter: eligibility.liquidityAdapter,
27
+ adapter: eligibility.adapter,
28
+ });
29
+ case "undecodableLiquidityData":
30
+ throw new index_js_2.VaultV2UndecodableLiquidityDataError({
31
+ vault: vault,
32
+ liquidityAdapter: eligibility.liquidityAdapter,
33
+ liquidityData: eligibility.liquidityData,
34
+ cause: eligibility.cause,
35
+ });
36
+ }
37
+ }
38
+ /** Validates and resolves the quote's execution and fee-projection deadline. @internal */
39
+ function resolveForceWithdrawDeadline({ deadlineOverride, now, }) {
40
+ const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
41
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
42
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
43
+ (0, validate_js_1.validateDeadline)(deadline);
44
+ if (deadline <= now) {
45
+ throw new index_js_2.ExpiredDeadlineError(deadline, now);
46
+ }
47
+ const maxDeadline = now + VAULT_V2_FEE_PROJECTION_HORIZON;
48
+ if (deadline > maxDeadline) {
49
+ throw new index_js_2.InputExceedsMaxError({
50
+ field: "deadline",
51
+ value: deadline,
52
+ max: maxDeadline,
53
+ });
54
+ }
55
+ return deadline;
56
+ }
57
+ /**
58
+ * @internal Computes the fixed exit quote from a snapshot without reads or signing.
59
+ * @param params - Snapshot, caller intent and explicit quote timestamp.
60
+ * @returns Fixed action fields and the minimum share allowance.
61
+ */
62
+ function computeVaultV2ForceWithdrawQuote({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, now, vault, }) {
63
+ if (exitAssets <= 0n) {
64
+ throw new index_js_2.NonPositiveInputError("exitAssets", exitAssets);
65
+ }
66
+ (0, validate_js_1.validateUint256Field)("exitAssets", exitAssets);
67
+ (0, index_js_1.validateSlippageTolerance)(slippageTolerance);
68
+ // Called for its throws only: the raw pair is forwarded to the action, which normalizes it
69
+ // again on the encode path so a direct action caller gets the same guarantees.
70
+ (0, validate_js_1.validateReferralFee)({ referralFeePct, referralFeeRecipient });
71
+ if (minSharePriceE27Override != null) {
72
+ // An unbounded override reopens the exact hole this path closes: the contract reads
73
+ // `minSharePriceE27 == 0` as "no bound".
74
+ if (minSharePriceE27Override <= 0n) {
75
+ throw new index_js_2.NonPositiveInputError("minSharePriceE27", minSharePriceE27Override);
76
+ }
77
+ // And an override the uint256 slot cannot hold must fail here rather than after
78
+ // `getRequirements()` has already asked for an approval or a permit signature.
79
+ (0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27Override);
80
+ }
81
+ const deadline = resolveForceWithdrawDeadline({ deadlineOverride, now });
82
+ const eligibility = resolveForceWithdrawAdapter({
83
+ vaultData,
84
+ adapterOverride,
85
+ vault,
86
+ });
87
+ const { adapter: accrualAdapter, liquidityMarketId } = eligibility;
88
+ const adapter = accrualAdapter.address;
89
+ const plan = (0, index_js_1.computeVaultV2ForceWithdrawPlan)({
90
+ vaultData,
91
+ adapter: accrualAdapter,
92
+ liquidityMarketId,
93
+ exitAssets,
94
+ timestamp: now,
95
+ });
96
+ if (plan.withdrawnAssets <= 0n) {
97
+ throw new index_js_2.VaultV2ForceWithdrawZeroWithdrawalError({
98
+ vault: vault,
99
+ exitAssets,
100
+ penalty: plan.penalty,
101
+ });
102
+ }
103
+ // The contract's force-deallocation loop is unbounded: under-coverage panics on-chain.
104
+ if (plan.coveredAssets < plan.assetsToDeallocate) {
105
+ throw new index_js_2.VaultV2ForceWithdrawCoverageError({
106
+ required: plan.assetsToDeallocate,
107
+ covered: plan.coveredAssets,
108
+ maxExitAssets: plan.maxExitAssets,
109
+ });
110
+ }
111
+ const projectionTimestamp = deadline;
112
+ // VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
113
+ // accrues the vault before burning. The realized price sits between the raw snapshot price
114
+ // (pending fee mints not yet diluting it) and the `now` projection (interest the chain may not
115
+ // have accrued yet, e.g. when the wall clock runs ahead of the chain). Price the floor off the
116
+ // larger *net* burn of the two endpoints — the raw snapshot mints no fee shares, the `now`
117
+ // accrual mints `feeSharesNow` — so it never exceeds either, and use the projected deadline
118
+ // accrual for the fee-mint guard.
119
+ const { vault: nowVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(now, vaultData.lastUpdate));
120
+ const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(projectionTimestamp, vaultData.lastUpdate));
121
+ const sharesBurntRaw = (0, index_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
122
+ vaultData,
123
+ deadlineVaultData: vaultData,
124
+ plan,
125
+ });
126
+ const sharesBurntNow = (0, index_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
127
+ vaultData: nowVaultData,
128
+ deadlineVaultData: nowVaultData,
129
+ plan,
130
+ });
131
+ const feeSharesNow = (0, index_js_1.computeVaultV2ForceWithdrawFeeSharesMinted)({
132
+ vaultData,
133
+ owner: userAddress,
134
+ timestamp: now,
135
+ });
136
+ const feeSharesProjected = (0, index_js_1.computeVaultV2ForceWithdrawFeeSharesMinted)({
137
+ vaultData,
138
+ owner: userAddress,
139
+ timestamp: projectionTimestamp,
140
+ });
141
+ const minSharesBurntProjected = (0, index_js_1.computeVaultV2ForceWithdrawMinSharesBurnt)({
142
+ vaultData: projectedVaultData,
143
+ plan,
144
+ });
145
+ // When fee shares are minted, the projected pair bounds every execution time in the window.
146
+ if (feeSharesProjected > 0n &&
147
+ feeSharesProjected >= minSharesBurntProjected) {
148
+ throw new index_js_2.VaultV2ForceWithdrawFeeSharesExceedBurnError({
149
+ vault: vault,
150
+ userAddress,
151
+ sharesBurnt: minSharesBurntProjected,
152
+ feeShares: feeSharesProjected,
153
+ });
154
+ }
155
+ // sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
156
+ const sharesBurntForFloor = blue_sdk_1.MathLib.max(sharesBurntRaw, sharesBurntNow - feeSharesNow);
157
+ if (minSharePriceE27Override != null) {
158
+ // The maximum-slippage threshold only bounds the override; unlike the transaction floor it
159
+ // may round to zero, in which case every positive override is acceptable.
160
+ const minAllowedSharePriceE27 = (0, morpho_ts_1._try)(() => (0, index_js_1.computeMinForceWithdrawSharePrice)({
161
+ withdrawnAssets: plan.withdrawnAssets,
162
+ sharesBurnt: sharesBurntForFloor,
163
+ slippageTolerance: index_js_1.MAX_SLIPPAGE_TOLERANCE,
164
+ }), index_js_2.VaultV2ForceWithdrawZeroSharePriceError) ?? 1n;
165
+ if (minSharePriceE27Override < minAllowedSharePriceE27) {
166
+ throw new index_js_2.VaultV2ForceWithdrawSharePriceBelowFloorError({
167
+ minSharePriceE27: minSharePriceE27Override,
168
+ floorE27: minAllowedSharePriceE27,
169
+ });
170
+ }
171
+ }
172
+ const minSharePriceE27 = minSharePriceE27Override ??
173
+ (0, index_js_1.computeMinForceWithdrawSharePrice)({
174
+ withdrawnAssets: plan.withdrawnAssets,
175
+ sharesBurnt: sharesBurntForFloor,
176
+ slippageTolerance,
177
+ });
178
+ // The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
179
+ // lowering a lower bound weakens it, so any vault whose share price grew past that would be left
180
+ // with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
181
+ // only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
182
+ (0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27);
183
+ // This is the minimum allowance needed for successful execution, not an exit cap: the bundle
184
+ // independently rejects a realized share price below `minSharePriceE27`. Include the fee
185
+ // shares minted by the first withdrawal and enough headroom for the configured tolerance.
186
+ const allowanceSharePriceE27 = blue_sdk_1.MathLib.max(blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivDown(minSharePriceE27, blue_sdk_1.MathLib.WAD - slippageTolerance, blue_sdk_1.MathLib.WAD), minSharePriceE27 - 1n), 1n);
187
+ const requiredShareAllowance = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.max(blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, allowanceSharePriceE27), blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, minSharePriceE27) + 1n) + feeSharesProjected, viem_1.maxUint256);
188
+ return { deadline, adapter, minSharePriceE27, requiredShareAllowance };
189
+ }
@@ -0,0 +1,28 @@
1
+ import { type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
+ /**
4
+ * @internal Computes the fixed exit quote from a snapshot without reads or signing.
5
+ * @param params - Snapshot, caller intent and explicit quote timestamp.
6
+ * @returns Fixed action fields and the minimum share allowance.
7
+ */
8
+ export declare function computeVaultV2InKindRedeemQuote({ amount, marketParamsList, vaultData, adapter: adapterOverride, deadline: deadlineOverride, now, vault, }: {
9
+ readonly amount: bigint;
10
+ readonly marketParamsList: readonly MarketParams[];
11
+ readonly vaultData: AccrualVaultV2;
12
+ readonly adapter?: Address;
13
+ readonly deadline?: bigint;
14
+ readonly now: bigint;
15
+ readonly vault: Address;
16
+ }): {
17
+ deadline: bigint;
18
+ adapter: `0x${string}`;
19
+ marketParamsListSnapshot: {
20
+ loanToken: `0x${string}`;
21
+ collateralToken: `0x${string}`;
22
+ oracle: `0x${string}`;
23
+ irm: `0x${string}`;
24
+ lltv: bigint;
25
+ }[];
26
+ requiredShareAllowance: bigint;
27
+ peak: bigint;
28
+ };