@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,90 @@
1
+ import { erc2612Abi } from "@morpho-org/blue-sdk-viem";
2
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { erc20Abi, maxUint256 } from "viem";
4
+ import { readContract } from "viem/actions";
5
+ import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
6
+ import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
7
+ import { ExpiredDeadlineError, InsufficientBlueBalanceForInKindRedeemError, } from "../../types/index.js";
8
+ import { assertRegistryTargetsHaveCode } from "./assertContractCode.js";
9
+ /**
10
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
11
+ * @param client - Client serving the requested chain.
12
+ * @param params - Snapshot and fixed quote used for authorization.
13
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
14
+ * @returns Share approvals or permit requirements.
15
+ */
16
+ export async function getVaultV2InKindRedeemRequirements(client, params) {
17
+ const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, peak, } = params;
18
+ const vaultExitBundlesV1 = getChainAddress(chainId, "bundles.vaultExitBundlesV1");
19
+ const blue = getChainAddress(chainId, "blue");
20
+ const requirementsTimestamp = params.now ?? Time.timestamp();
21
+ if (deadline <= requirementsTimestamp) {
22
+ throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
23
+ }
24
+ await validateClientChainId(client, chainId);
25
+ await assertRegistryTargetsHaveCode(client, chainId, [
26
+ {
27
+ role: "bundles.vaultExitBundlesV1",
28
+ address: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
29
+ },
30
+ { role: "blue", address: getChainAddress(chainId, "blue") },
31
+ ]);
32
+ // Vault gates are intentionally left to the final transaction. A receive gate may inspect
33
+ // VaultExitBundlesV1's transient `initiator`, which is populated only during the actual
34
+ // periphery call. A send-share gate is arbitrary external code and is evaluated repeatedly
35
+ // after intermediate penalty share burns, so one standalone read is not execution-equivalent
36
+ // either. Simulate the finalized transaction after authorization when gate compatibility
37
+ // must be checked before submission.
38
+ const [allowance, nonce, blueBalance] = await Promise.all([
39
+ readContract(client, {
40
+ address: vault,
41
+ abi: erc20Abi,
42
+ functionName: "allowance",
43
+ args: [userAddress, vaultExitBundlesV1],
44
+ }),
45
+ readContract(client, {
46
+ address: vault,
47
+ abi: erc2612Abi,
48
+ functionName: "nonces",
49
+ args: [userAddress],
50
+ }),
51
+ readContract(client, {
52
+ address: vaultData.asset,
53
+ abi: erc20Abi,
54
+ functionName: "balanceOf",
55
+ args: [blue],
56
+ }),
57
+ ]);
58
+ if (blueBalance < peak) {
59
+ throw new InsufficientBlueBalanceForInKindRedeemError({
60
+ asset: vaultData.asset,
61
+ available: blueBalance,
62
+ required: peak,
63
+ });
64
+ }
65
+ if (allowance >= requiredShareAllowance) {
66
+ return [];
67
+ }
68
+ if (supportSignature) {
69
+ return [
70
+ encodeVaultSharesPermit({
71
+ now: params.now,
72
+ vault: vaultData,
73
+ version: "vaultV2",
74
+ spender: vaultExitBundlesV1,
75
+ owner: userAddress,
76
+ chainId: chainId,
77
+ nonce,
78
+ deadline,
79
+ }),
80
+ ];
81
+ }
82
+ return [
83
+ encodeErc20Approval({
84
+ token: vault,
85
+ spender: vaultExitBundlesV1,
86
+ amount: maxUint256,
87
+ chainId: chainId,
88
+ }),
89
+ ];
90
+ }
@@ -0,0 +1,25 @@
1
+ import { type AccrualVault, type MarketParams } from "@morpho-org/blue-sdk";
2
+ /**
3
+ * @internal Computes the fixed exit quote from a snapshot without reads or signing.
4
+ * @param params - Snapshot, caller intent and explicit quote timestamp.
5
+ * @returns Fixed action fields and the minimum share allowance.
6
+ */
7
+ export declare function computeVaultV1InKindRedeemQuote({ amount, marketParamsList, vaultData, deadline: deadlineOverride, now, chainId, }: {
8
+ readonly amount: bigint;
9
+ readonly marketParamsList: readonly MarketParams[];
10
+ readonly vaultData: AccrualVault;
11
+ readonly deadline?: bigint;
12
+ readonly now: bigint;
13
+ readonly chainId: number;
14
+ }): {
15
+ deadline: bigint;
16
+ marketParamsListSnapshot: {
17
+ loanToken: `0x${string}`;
18
+ collateralToken: `0x${string}`;
19
+ oracle: `0x${string}`;
20
+ irm: `0x${string}`;
21
+ lltv: bigint;
22
+ }[];
23
+ requiredShareAllowance: bigint;
24
+ vaultExitBundlesV1: `0x${string}`;
25
+ };
@@ -0,0 +1,82 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
2
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { computeVaultMaxShareAllowance } from "../../helpers/index.js";
4
+ import { validateDeadline } from "../../helpers/validate.js";
5
+ import { EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, NonPositiveInputError, } from "../../types/index.js";
6
+ /**
7
+ * @internal Computes the fixed exit quote from a snapshot without reads or signing.
8
+ * @param params - Snapshot, caller intent and explicit quote timestamp.
9
+ * @returns Fixed action fields and the minimum share allowance.
10
+ */
11
+ export function computeVaultV1InKindRedeemQuote({ amount, marketParamsList, vaultData, deadline: deadlineOverride, now, chainId, }) {
12
+ if (amount <= 0n) {
13
+ throw new NonPositiveInputError("amount", amount);
14
+ }
15
+ if (marketParamsList.length === 0) {
16
+ throw new EmptyMarketParamsListError();
17
+ }
18
+ const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
19
+ loanToken,
20
+ collateralToken,
21
+ oracle,
22
+ irm,
23
+ lltv,
24
+ }));
25
+ const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
26
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
27
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
28
+ validateDeadline(deadline);
29
+ if (deadline <= now) {
30
+ throw new ExpiredDeadlineError(deadline, now);
31
+ }
32
+ const vaultExitBundlesV1 = getChainAddress(chainId, "bundles.vaultExitBundlesV1");
33
+ // Reject unsupported registry configurations before computing coverage.
34
+ getChainAddress(chainId, "blue");
35
+ let covered = 0n;
36
+ const assignedByMarket = new Map();
37
+ for (const marketParams of marketParamsListSnapshot) {
38
+ if (covered === amount) {
39
+ break;
40
+ }
41
+ const marketId = MarketUtils.getMarketId(marketParams);
42
+ const allocation = vaultData.allocations.get(marketId);
43
+ if (allocation?.config.enabled !== true) {
44
+ continue;
45
+ }
46
+ if (allocation.position.supplyShares === 0n) {
47
+ continue;
48
+ }
49
+ const market = allocation.position.market.accrueInterest(now);
50
+ const available = market.toSupplyAssets(allocation.position.supplyShares);
51
+ const assigned = assignedByMarket.get(marketId) ?? 0n;
52
+ const chunk = MathLib.min(available, amount - covered);
53
+ if (assigned + chunk > available) {
54
+ throw new InKindRedeemCoverageError({
55
+ required: amount,
56
+ covered,
57
+ maxExitAssets: covered,
58
+ });
59
+ }
60
+ assignedByMarket.set(marketId, assigned + chunk);
61
+ covered += chunk;
62
+ }
63
+ if (covered < amount) {
64
+ throw new InKindRedeemCoverageError({
65
+ required: amount,
66
+ covered,
67
+ maxExitAssets: covered,
68
+ });
69
+ }
70
+ const requiredShareAllowance = computeVaultMaxShareAllowance({
71
+ vaultData,
72
+ deadline: now,
73
+ assets: amount,
74
+ slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
75
+ });
76
+ return {
77
+ deadline,
78
+ marketParamsListSnapshot,
79
+ requiredShareAllowance,
80
+ vaultExitBundlesV1,
81
+ };
82
+ }
@@ -0,0 +1,20 @@
1
+ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import type { VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
3
+ /**
4
+ * @internal Quotes a migration from validated snapshots and intent without reading chain state.
5
+ * The source accrues interest and performance fees before a shares-mode conversion; the target
6
+ * price bound uses assets net of the referral fee. Neither snapshot is mutated.
7
+ * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
8
+ * @returns The destination maximum share price and minimum source share allowance.
9
+ */
10
+ export declare function computeVaultV1MigrateToV2Quote(params: VaultV1MigrateToV2AmountArgs & {
11
+ readonly sourceVault: AccrualVault;
12
+ readonly targetVault: AccrualVaultV2;
13
+ readonly referralFeePct: bigint;
14
+ readonly slippageTolerance: bigint;
15
+ readonly deadline: bigint;
16
+ readonly now: bigint;
17
+ }): {
18
+ readonly maxSharePriceVaultV2: bigint;
19
+ readonly requiredShareAllowance: bigint;
20
+ };
@@ -0,0 +1,34 @@
1
+ import { MathLib, } from "@morpho-org/blue-sdk";
2
+ import { getBundlesReferralFeeAssets } from "../../actions/bundles/common.js";
3
+ import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "../../helpers/slippage.js";
4
+ /**
5
+ * @internal Quotes a migration from validated snapshots and intent without reading chain state.
6
+ * The source accrues interest and performance fees before a shares-mode conversion; the target
7
+ * price bound uses assets net of the referral fee. Neither snapshot is mutated.
8
+ * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
9
+ * @returns The destination maximum share price and minimum source share allowance.
10
+ */
11
+ export function computeVaultV1MigrateToV2Quote(params) {
12
+ const { sourceVault, targetVault, assets, shares, referralFeePct, slippageTolerance, deadline, now, } = params;
13
+ const grossAssets = assets ??
14
+ sourceVault
15
+ .accrueInterest(sourceVault.allocations
16
+ .values()
17
+ .reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), now))
18
+ .toAssets(shares ?? 0n, "Down");
19
+ const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, referralFeePct);
20
+ const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
21
+ vaultData: targetVault,
22
+ deadline,
23
+ assets: grossAssets - referralFeeAssets,
24
+ slippageTolerance,
25
+ });
26
+ const requiredShareAllowance = shares ??
27
+ computeVaultMaxShareAllowance({
28
+ vaultData: sourceVault,
29
+ deadline,
30
+ assets: assets ?? 0n,
31
+ slippageTolerance,
32
+ });
33
+ return { maxSharePriceVaultV2, requiredShareAllowance };
34
+ }
@@ -1,52 +1,20 @@
1
- import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
2
- import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, Token, } from "@morpho-org/blue-sdk";
2
+ import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { getChainAddress, Time, } from "@morpho-org/morpho-ts";
4
- import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
5
- import { readContract } from "viem/actions";
4
+ import { isAddressEqual } from "viem";
6
5
  import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
7
- import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
6
+ import { vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
8
7
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
9
8
  import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
10
9
  import { resolveTransactionMetadata } from "../../helpers/metadata.js";
11
- import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
12
- import { AmountAndSharesExclusiveError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
10
+ import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
11
+ import { AmountAndSharesExclusiveError, ExpiredDeadlineError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
13
12
  import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
14
13
  import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
14
+ import { getVaultV1InKindRedeemRequirements } from "../requirements/getVaultV1InKindRedeemRequirements.js";
15
15
  import { getBundlesTokenRequirements } from "../requirements/index.js";
16
- function validateInKindCoverage({ amount, marketParamsListSnapshot, vaultData, now, }) {
17
- let covered = 0n;
18
- const assignedByMarket = new Map();
19
- for (const marketParams of marketParamsListSnapshot) {
20
- if (covered === amount)
21
- break;
22
- const marketId = MarketUtils.getMarketId(marketParams);
23
- const allocation = vaultData.allocations.get(marketId);
24
- if (allocation?.config.enabled !== true)
25
- continue;
26
- if (allocation.position.supplyShares === 0n)
27
- continue;
28
- const market = allocation.position.market.accrueInterest(now);
29
- const available = market.toSupplyAssets(allocation.position.supplyShares);
30
- const assigned = assignedByMarket.get(marketId) ?? 0n;
31
- const chunk = MathLib.min(available, amount - covered);
32
- if (assigned + chunk > available) {
33
- throw new InKindRedeemCoverageError({
34
- required: amount,
35
- covered,
36
- maxExitAssets: covered,
37
- });
38
- }
39
- assignedByMarket.set(marketId, assigned + chunk);
40
- covered += chunk;
41
- }
42
- if (covered < amount) {
43
- throw new InKindRedeemCoverageError({
44
- required: amount,
45
- covered,
46
- maxExitAssets: covered,
47
- });
48
- }
49
- }
16
+ import { computeVaultV1InKindRedeemQuote } from "./inKindRedeemQuote.js";
17
+ import { computeVaultV1MigrateToV2Quote } from "./migrateToV2Quote.js";
50
18
  function getMigrationAmounts(params) {
51
19
  const assets = "assets" in params ? params.assets : undefined;
52
20
  const shares = "shares" in params ? params.shares : undefined;
@@ -55,7 +23,7 @@ function getMigrationAmounts(params) {
55
23
  }
56
24
  const selectedAmount = assets ?? shares ?? 0n;
57
25
  if (selectedAmount <= 0n) {
58
- throw new NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
26
+ throw new NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
59
27
  }
60
28
  return { assets, shares };
61
29
  }
@@ -105,8 +73,9 @@ export class MorphoVaultV1 {
105
73
  }
106
74
  const createdAt = suppliedNow ?? Time.timestamp();
107
75
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
108
- if (deadline <= createdAt)
76
+ if (deadline <= createdAt) {
109
77
  throw new ExpiredDeadlineError(deadline, createdAt);
78
+ }
110
79
  const common = normalizeBundlesCommonParams({
111
80
  deadline,
112
81
  referralFeePct: params.referralFeePct,
@@ -131,10 +100,12 @@ export class MorphoVaultV1 {
131
100
  return Object.freeze({
132
101
  getRequirements: async (requirementOptions) => {
133
102
  const now = suppliedNow ?? Time.timestamp();
134
- if (deadline <= now)
103
+ if (deadline <= now) {
135
104
  throw new ExpiredDeadlineError(deadline, now);
136
- if (pendingRequirements != null)
105
+ }
106
+ if (pendingRequirements != null) {
137
107
  return await pendingRequirements;
108
+ }
138
109
  // Memoize the in-flight promise so concurrent callers share one round of
139
110
  // allowance/nonce reads.
140
111
  const pending = (async () => {
@@ -160,8 +131,9 @@ export class MorphoVaultV1 {
160
131
  }
161
132
  finally {
162
133
  // Later calls must re-read live allowances/nonces and honor their own options.
163
- if (pendingRequirements === pending)
134
+ if (pendingRequirements === pending) {
164
135
  pendingRequirements = undefined;
136
+ }
165
137
  }
166
138
  },
167
139
  buildTx: (signatures) => {
@@ -197,14 +169,16 @@ export class MorphoVaultV1 {
197
169
  if (!isAddressEqual(vaultData.address, this.vault)) {
198
170
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
199
171
  }
200
- if (amount <= 0n)
172
+ if (amount <= 0n) {
201
173
  throw new NonPositiveInputError("amount", amount);
174
+ }
202
175
  // Reject values outside the ABI range before resolving any requirements.
203
176
  validateUint256Field("amount", amount);
204
177
  const createdAt = suppliedNow ?? Time.timestamp();
205
178
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
206
- if (deadline <= createdAt)
179
+ if (deadline <= createdAt) {
207
180
  throw new ExpiredDeadlineError(deadline, createdAt);
181
+ }
208
182
  const common = normalizeBundlesCommonParams({
209
183
  deadline,
210
184
  referralFeePct: params.referralFeePct,
@@ -223,8 +197,9 @@ export class MorphoVaultV1 {
223
197
  return Object.freeze({
224
198
  getRequirements: async () => {
225
199
  const now = suppliedNow ?? Time.timestamp();
226
- if (deadline <= now)
200
+ if (deadline <= now) {
227
201
  throw new ExpiredDeadlineError(deadline, now);
202
+ }
228
203
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
229
204
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
230
205
  return getVaultBundlesSharesRequirements(this.client.viemClient, {
@@ -265,12 +240,14 @@ export class MorphoVaultV1 {
265
240
  const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
266
241
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
267
242
  const { shares, userAddress } = params;
268
- if (shares <= 0n)
243
+ if (shares <= 0n) {
269
244
  throw new NonPositiveInputError("shares", shares);
245
+ }
270
246
  const createdAt = suppliedNow ?? Time.timestamp();
271
247
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
272
- if (deadline <= createdAt)
248
+ if (deadline <= createdAt) {
273
249
  throw new ExpiredDeadlineError(deadline, createdAt);
250
+ }
274
251
  const common = normalizeBundlesCommonParams({
275
252
  deadline,
276
253
  referralFeePct: params.referralFeePct,
@@ -280,8 +257,9 @@ export class MorphoVaultV1 {
280
257
  return Object.freeze({
281
258
  getRequirements: async () => {
282
259
  const now = suppliedNow ?? Time.timestamp();
283
- if (deadline <= now)
260
+ if (deadline <= now) {
284
261
  throw new ExpiredDeadlineError(deadline, now);
262
+ }
285
263
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
286
264
  return getVaultBundlesSharesRequirements(this.client.viemClient, {
287
265
  vaultData: await this.getData(),
@@ -324,123 +302,26 @@ export class MorphoVaultV1 {
324
302
  if (!isAddressEqual(vaultData.address, this.vault)) {
325
303
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
326
304
  }
327
- if (amount <= 0n)
328
- throw new NonPositiveInputError("amount", amount);
329
- if (marketParamsList.length === 0)
330
- throw new EmptyMarketParamsListError();
331
- const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
332
- loanToken,
333
- collateralToken,
334
- oracle,
335
- irm,
336
- lltv,
337
- }));
338
- const now = suppliedNow ?? Time.timestamp();
339
- const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
340
- // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
341
- // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
342
- validateDeadline(deadline);
343
- if (deadline <= now)
344
- throw new ExpiredDeadlineError(deadline, now);
345
- const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
346
- const blue = getChainAddress(this.chainId, "blue");
347
- // Reject insufficient ordered market coverage before preparing share requirements.
348
- validateInKindCoverage({
305
+ const { deadline, marketParamsListSnapshot, requiredShareAllowance, vaultExitBundlesV1, } = computeVaultV1InKindRedeemQuote({
349
306
  amount,
350
- marketParamsListSnapshot,
307
+ marketParamsList,
351
308
  vaultData,
352
- now,
353
- });
354
- const requiredShareAllowance = computeVaultMaxShareAllowance({
355
- vaultData,
356
- deadline: now,
357
- assets: amount,
358
- slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
309
+ deadline: deadlineOverride,
310
+ now: suppliedNow ?? Time.timestamp(),
311
+ chainId: this.chainId,
359
312
  });
360
313
  return {
361
- getRequirements: async () => {
362
- const requirementsTimestamp = suppliedNow ?? Time.timestamp();
363
- if (deadline <= requirementsTimestamp) {
364
- throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
365
- }
366
- await validateClientChainId(this.client.viemClient, this.chainId);
367
- await this.assertWriteTargets(["bundles.vaultExitBundlesV1", "blue"]);
368
- const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await Promise.all([
369
- readContract(this.client.viemClient, {
370
- address: this.vault,
371
- abi: erc20Abi,
372
- functionName: "allowance",
373
- args: [userAddress, vaultExitBundlesV1],
374
- }),
375
- readContract(this.client.viemClient, {
376
- address: this.vault,
377
- abi: erc2612Abi,
378
- functionName: "nonces",
379
- args: [userAddress],
380
- }),
381
- readContract(this.client.viemClient, {
382
- address: vaultData.asset,
383
- abi: erc20Abi,
384
- functionName: "balanceOf",
385
- args: [blue],
386
- }),
387
- readContract(this.client.viemClient, {
388
- address: this.vault,
389
- abi: metaMorphoAbi,
390
- functionName: "MORPHO",
391
- }),
392
- // feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
393
- readContract(this.client.viemClient, {
394
- address: blue,
395
- abi: blueAbi,
396
- functionName: "feeRecipient",
397
- }),
398
- ]);
399
- if (!isAddressEqual(morpho, blue)) {
400
- throw new VaultMorphoMismatchError({
401
- vault: this.vault,
402
- expected: blue,
403
- actual: morpho,
404
- });
405
- }
406
- // Reject this unsupported configuration before authorizing vault shares:
407
- // VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
408
- // vault position, so its callback can exhaust marketParamsList and panic on-chain.
409
- if (isAddressEqual(blueFeeRecipient, this.vault)) {
410
- throw new VaultIsBlueFeeRecipientError(this.vault, blue);
411
- }
412
- if (blueBalance < amount) {
413
- throw new InsufficientBlueBalanceForInKindRedeemError({
414
- asset: vaultData.asset,
415
- available: blueBalance,
416
- required: amount,
417
- });
418
- }
419
- if (allowance >= requiredShareAllowance)
420
- return [];
421
- if (this.client.options.supportSignature) {
422
- return [
423
- encodeVaultSharesPermit({
424
- now: suppliedNow == null ? undefined : now,
425
- vault: vaultData,
426
- version: "vaultV1",
427
- spender: vaultExitBundlesV1,
428
- owner: userAddress,
429
- chainId: this.chainId,
430
- nonce,
431
- deadline,
432
- }),
433
- ];
434
- }
435
- return [
436
- encodeErc20Approval({
437
- token: this.vault,
438
- spender: vaultExitBundlesV1,
439
- amount: maxUint256,
440
- chainId: this.chainId,
441
- }),
442
- ];
443
- },
314
+ getRequirements: () => getVaultV1InKindRedeemRequirements(this.client.viemClient, {
315
+ vaultData,
316
+ vault: this.vault,
317
+ userAddress,
318
+ chainId: this.chainId,
319
+ deadline,
320
+ requiredShareAllowance,
321
+ supportSignature: this.client.options.supportSignature,
322
+ amount,
323
+ now: suppliedNow,
324
+ }),
444
325
  buildTx: (signatures) => {
445
326
  const permit = selectBundlesSharesPermitSignature(signatures, {
446
327
  spender: vaultExitBundlesV1,
@@ -480,35 +361,23 @@ export class MorphoVaultV1 {
480
361
  validateSlippageTolerance(slippageTolerance);
481
362
  const createdAt = suppliedNow ?? Time.timestamp();
482
363
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
483
- if (deadline <= createdAt)
364
+ if (deadline <= createdAt) {
484
365
  throw new ExpiredDeadlineError(deadline, createdAt);
366
+ }
485
367
  const common = normalizeBundlesCommonParams({
486
368
  deadline,
487
369
  referralFeePct: params.referralFeePct,
488
370
  referralFeeRecipient: params.referralFeeRecipient,
489
371
  });
490
- // Only the destination receives a deposit; the source vault is an exit.
491
- // V1 redeem accrues market interest and performance fees before converting shares.
492
- const grossAssets = assets ??
493
- params.sourceVault
494
- .accrueInterest(params.sourceVault.allocations
495
- .values()
496
- .reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), createdAt))
497
- .toAssets(shares ?? 0n, "Down");
498
- const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, common.referralFeePct);
499
- const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
500
- vaultData: params.targetVault,
372
+ const { maxSharePriceVaultV2, requiredShareAllowance } = computeVaultV1MigrateToV2Quote({
373
+ sourceVault: params.sourceVault,
374
+ targetVault: params.targetVault,
375
+ ...(assets == null ? { shares: shares ?? 0n } : { assets }),
376
+ referralFeePct: common.referralFeePct,
501
377
  deadline,
502
- assets: grossAssets - referralFeeAssets,
503
378
  slippageTolerance,
379
+ now: createdAt,
504
380
  });
505
- const requiredShareAllowance = shares ??
506
- computeVaultMaxShareAllowance({
507
- vaultData: params.sourceVault,
508
- deadline,
509
- assets: assets ?? 0n,
510
- slippageTolerance,
511
- });
512
381
  const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
513
382
  const { userAddress } = params;
514
383
  const sourceAsset = params.sourceVault.asset;
@@ -528,8 +397,9 @@ export class MorphoVaultV1 {
528
397
  return Object.freeze({
529
398
  getRequirements: async () => {
530
399
  const now = suppliedNow ?? Time.timestamp();
531
- if (deadline <= now)
400
+ if (deadline <= now) {
532
401
  throw new ExpiredDeadlineError(deadline, now);
402
+ }
533
403
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
534
404
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
535
405
  return getVaultBundlesSharesRequirements(this.client.viemClient, {
@@ -558,7 +428,7 @@ export class MorphoVaultV1 {
558
428
  args: {
559
429
  targetVault: targetAddress,
560
430
  targetAsset,
561
- ...(assets != null ? { assets } : { shares: shares ?? 0n }),
431
+ ...(assets == null ? { shares: shares ?? 0n } : { assets }),
562
432
  maxSharePriceVaultV2,
563
433
  userAddress,
564
434
  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
+ };