@morpho-org/morpho-sdk 9.8.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +109 -13
  3. package/lib/cjs/actions/blue/common.js +4 -2
  4. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  5. package/lib/cjs/actions/bundles/common.js +20 -14
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  8. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  9. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  10. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  11. package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
  12. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  13. package/lib/cjs/actions/midnight/index.js +1 -0
  14. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeLend.js +3 -2
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
  25. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  26. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  27. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
  34. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  35. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  36. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  37. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  38. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  39. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  40. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  41. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  42. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  43. package/lib/cjs/entities/blue/blue.js +107 -77
  44. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  45. package/lib/cjs/entities/midnight/deadline.js +4 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  47. package/lib/cjs/entities/midnight/midnight.js +158 -138
  48. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  49. package/lib/cjs/entities/midnight/publication.js +193 -138
  50. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  51. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  52. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  53. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
  54. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  55. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  57. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  58. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  59. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  60. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  61. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  62. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  63. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  64. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  65. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  66. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  67. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  68. package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
  69. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  70. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  71. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  72. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  73. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
  75. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
  76. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
  77. package/lib/cjs/errors.d.ts +1 -1
  78. package/lib/cjs/errors.js +2 -1
  79. package/lib/cjs/helpers/deadShares.js +83 -47
  80. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  81. package/lib/cjs/helpers/metadata.d.ts +14 -2
  82. package/lib/cjs/helpers/metadata.js +49 -8
  83. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
  84. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
  85. package/lib/cjs/helpers/utilization.js +10 -5
  86. package/lib/cjs/helpers/validate.js +88 -67
  87. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  88. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  89. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  90. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
  91. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  92. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  93. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  94. package/lib/cjs/index.d.ts +2 -2
  95. package/lib/cjs/index.js +10 -1
  96. package/lib/cjs/transactionPlan/approval.js +12 -1
  97. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  98. package/lib/cjs/transactionPlan/deposit.js +139 -0
  99. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  100. package/lib/cjs/transactionPlan/error.js +10 -8
  101. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  102. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  103. package/lib/cjs/transactionPlan/index.js +23 -5
  104. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  105. package/lib/cjs/transactionPlan/intent.js +14 -7
  106. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  107. package/lib/cjs/transactionPlan/permit.js +86 -20
  108. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  109. package/lib/cjs/transactionPlan/plan.js +77 -24
  110. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  111. package/lib/cjs/transactionPlan/redeem.js +63 -0
  112. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  113. package/lib/cjs/transactionPlan/requirements.js +12 -6
  114. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  115. package/lib/cjs/transactionPlan/serde.js +45 -19
  116. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  117. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  118. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  119. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  120. package/lib/cjs/transactionPlan/validation.js +6 -3
  121. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  122. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  123. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  124. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  125. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  126. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  127. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  128. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  129. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  130. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  131. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
  132. package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
  133. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  134. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  135. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  136. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  137. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  138. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  139. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  140. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  141. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  142. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
  143. package/lib/cjs/transactionPlan/version.js +2 -1
  144. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  145. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  146. package/lib/cjs/types/action.d.ts +26 -2
  147. package/lib/cjs/types/action.js +17 -9
  148. package/lib/cjs/types/error.d.ts +8 -1
  149. package/lib/cjs/types/error.js +21 -6
  150. package/lib/cjs/types/metadata.d.ts +12 -2
  151. package/lib/cjs/version.d.ts +1 -1
  152. package/lib/cjs/version.js +1 -1
  153. package/lib/esm/actions/blue/common.js +4 -2
  154. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  155. package/lib/esm/actions/bundles/common.js +20 -14
  156. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  157. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
  158. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  159. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  160. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  161. package/lib/esm/actions/midnight/cancelOffers.js +104 -0
  162. package/lib/esm/actions/midnight/index.d.ts +1 -0
  163. package/lib/esm/actions/midnight/index.js +1 -0
  164. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  165. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  166. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
  167. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  168. package/lib/esm/actions/midnight/takeBorrow.js +3 -2
  169. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  170. package/lib/esm/actions/midnight/takeLend.js +3 -2
  171. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  172. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
  173. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  174. package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
  175. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  176. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  177. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  178. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  179. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  180. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  181. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  182. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  183. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
  184. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  185. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  186. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  187. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  188. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  189. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  190. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  191. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  192. package/lib/esm/entities/blue/blue.d.ts +34 -28
  193. package/lib/esm/entities/blue/blue.js +107 -77
  194. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  195. package/lib/esm/entities/midnight/deadline.js +4 -3
  196. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  197. package/lib/esm/entities/midnight/midnight.js +159 -139
  198. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  199. package/lib/esm/entities/midnight/publication.js +193 -138
  200. package/lib/esm/entities/midnight/types.d.ts +4 -4
  201. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  203. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
  204. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  205. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
  206. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  207. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  208. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  209. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  210. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  211. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  212. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  213. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  214. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  215. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  216. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  217. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  218. package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
  219. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  220. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  221. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  222. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  223. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
  224. package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
  225. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
  226. package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
  227. package/lib/esm/errors.d.ts +1 -1
  228. package/lib/esm/errors.js +1 -1
  229. package/lib/esm/helpers/deadShares.js +83 -47
  230. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  231. package/lib/esm/helpers/metadata.d.ts +14 -2
  232. package/lib/esm/helpers/metadata.js +48 -8
  233. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
  234. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
  235. package/lib/esm/helpers/utilization.js +10 -5
  236. package/lib/esm/helpers/validate.js +88 -67
  237. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  238. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  239. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  240. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
  241. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  242. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  243. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
  244. package/lib/esm/index.d.ts +2 -2
  245. package/lib/esm/index.js +1 -1
  246. package/lib/esm/transactionPlan/approval.js +13 -2
  247. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  248. package/lib/esm/transactionPlan/deposit.js +135 -0
  249. package/lib/esm/transactionPlan/error.d.ts +10 -8
  250. package/lib/esm/transactionPlan/error.js +10 -8
  251. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  252. package/lib/esm/transactionPlan/index.d.ts +18 -0
  253. package/lib/esm/transactionPlan/index.js +9 -0
  254. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  255. package/lib/esm/transactionPlan/intent.js +14 -7
  256. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  257. package/lib/esm/transactionPlan/permit.js +86 -20
  258. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  259. package/lib/esm/transactionPlan/plan.js +73 -20
  260. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  261. package/lib/esm/transactionPlan/redeem.js +59 -0
  262. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  263. package/lib/esm/transactionPlan/requirements.js +12 -6
  264. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  265. package/lib/esm/transactionPlan/serde.js +45 -19
  266. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  267. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  268. package/lib/esm/transactionPlan/types.d.ts +117 -11
  269. package/lib/esm/transactionPlan/validateActions.js +11 -1
  270. package/lib/esm/transactionPlan/validation.js +6 -3
  271. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  272. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  273. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  274. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  275. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  276. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  277. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  278. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  279. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  280. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  281. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
  282. package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
  283. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  284. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  285. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  286. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  287. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  288. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  289. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  290. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  291. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
  292. package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
  293. package/lib/esm/transactionPlan/version.js +2 -1
  294. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  295. package/lib/esm/transactionPlan/withdraw.js +90 -0
  296. package/lib/esm/types/action.d.ts +26 -2
  297. package/lib/esm/types/action.js +17 -9
  298. package/lib/esm/types/error.d.ts +8 -1
  299. package/lib/esm/types/error.js +21 -6
  300. package/lib/esm/types/metadata.d.ts +12 -2
  301. package/lib/esm/version.d.ts +1 -1
  302. package/lib/esm/version.js +1 -1
  303. package/package.json +15 -14
@@ -0,0 +1,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,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeVaultV1MigrateToV2Quote = computeVaultV1MigrateToV2Quote;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const common_js_1 = require("../../actions/bundles/common.js");
6
+ const slippage_js_1 = require("../../helpers/slippage.js");
7
+ /**
8
+ * @internal Quotes a migration from validated snapshots and intent without reading chain state.
9
+ * The source accrues interest and performance fees before a shares-mode conversion; the target
10
+ * price bound uses assets net of the referral fee. Neither snapshot is mutated.
11
+ * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
12
+ * @returns The destination maximum share price and minimum source share allowance.
13
+ */
14
+ function computeVaultV1MigrateToV2Quote(params) {
15
+ const { sourceVault, targetVault, assets, shares, referralFeePct, slippageTolerance, deadline, now, } = params;
16
+ const grossAssets = assets ??
17
+ sourceVault
18
+ .accrueInterest(sourceVault.allocations
19
+ .values()
20
+ .reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), now))
21
+ .toAssets(shares ?? 0n, "Down");
22
+ const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, referralFeePct);
23
+ const maxSharePriceVaultV2 = (0, slippage_js_1.computeVaultMaxSharePrice)({
24
+ vaultData: targetVault,
25
+ deadline,
26
+ assets: grossAssets - referralFeeAssets,
27
+ slippageTolerance,
28
+ });
29
+ const requiredShareAllowance = shares ??
30
+ (0, slippage_js_1.computeVaultMaxShareAllowance)({
31
+ vaultData: sourceVault,
32
+ deadline,
33
+ assets: assets ?? 0n,
34
+ slippageTolerance,
35
+ });
36
+ return { maxSharePriceVaultV2, requiredShareAllowance };
37
+ }
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2, type MarketParams } from "@morp
2
2
  import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
5
+ import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type ReferenceTimestampParams, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
6
6
  /** Action surface for Vault V1 reads and writes; writes route through VaultBundlesV1 and VaultExitBundlesV1. */
7
7
  export interface VaultV1Actions {
8
8
  /**
@@ -107,7 +107,7 @@ export interface VaultV1Actions {
107
107
  readonly referralFeePct?: bigint;
108
108
  readonly referralFeeRecipient?: Address;
109
109
  readonly deadline?: bigint;
110
- } & BundlesFundingArgs) => ActionOutput<VaultV1DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
110
+ } & ReferenceTimestampParams & BundlesFundingArgs) => ActionOutput<VaultV1DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
111
111
  /**
112
112
  * Prepares an exact-assets Vault V1 withdrawal through VaultBundlesV1.
113
113
  *
@@ -189,7 +189,7 @@ export interface VaultV1Actions {
189
189
  readonly referralFeePct?: bigint;
190
190
  readonly referralFeeRecipient?: Address;
191
191
  readonly deadline?: bigint;
192
- }) => ActionOutput<VaultV1WithdrawAction, readonly RequirementSignature[], undefined>;
192
+ } & ReferenceTimestampParams) => ActionOutput<VaultV1WithdrawAction, readonly RequirementSignature[], undefined>;
193
193
  /**
194
194
  * Prepares an exact-shares Vault V1 redemption through VaultBundlesV1.
195
195
  *
@@ -270,7 +270,7 @@ export interface VaultV1Actions {
270
270
  readonly referralFeePct?: bigint;
271
271
  readonly referralFeeRecipient?: Address;
272
272
  readonly deadline?: bigint;
273
- }) => ActionOutput<VaultV1RedeemAction, readonly RequirementSignature[], undefined>;
273
+ } & ReferenceTimestampParams) => ActionOutput<VaultV1RedeemAction, readonly RequirementSignature[], undefined>;
274
274
  /**
275
275
  * Prepares an illiquid Vault V1 exit into the vault's Morpho Blue supply positions.
276
276
  *
@@ -355,7 +355,7 @@ export interface VaultV1Actions {
355
355
  readonly vaultData: AccrualVault;
356
356
  readonly userAddress: Address;
357
357
  readonly deadline?: bigint;
358
- }) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
358
+ } & ReferenceTimestampParams) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
359
359
  /**
360
360
  * Prepares a Vault V1-to-Vault V2 migration through VaultBundlesV1.
361
361
  *
@@ -461,7 +461,7 @@ export interface VaultV1Actions {
461
461
  readonly referralFeePct?: bigint;
462
462
  readonly referralFeeRecipient?: Address;
463
463
  readonly deadline?: bigint;
464
- } & VaultV1MigrateToV2AmountArgs) => ActionOutput<VaultV1MigrateToV2Action, readonly RequirementSignature[], undefined>;
464
+ } & ReferenceTimestampParams & VaultV1MigrateToV2AmountArgs) => ActionOutput<VaultV1MigrateToV2Action, readonly RequirementSignature[], undefined>;
465
465
  }
466
466
  /** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
467
467
  export declare class MorphoVaultV1 implements VaultV1Actions {
@@ -487,7 +487,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
487
487
  readonly referralFeePct?: bigint;
488
488
  readonly referralFeeRecipient?: Address;
489
489
  readonly deadline?: bigint;
490
- } & BundlesFundingArgs): Readonly<{
490
+ } & ReferenceTimestampParams & BundlesFundingArgs): Readonly<{
491
491
  getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
492
492
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1DepositAction>>;
493
493
  }>;
@@ -499,7 +499,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
499
499
  readonly referralFeePct?: bigint;
500
500
  readonly referralFeeRecipient?: Address;
501
501
  readonly deadline?: bigint;
502
- }): Readonly<{
502
+ } & ReferenceTimestampParams): Readonly<{
503
503
  getRequirements: () => Promise<readonly (Readonly<import("../../index.js").Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
504
504
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1WithdrawAction>>;
505
505
  }>;
@@ -510,18 +510,18 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
510
510
  readonly referralFeePct?: bigint;
511
511
  readonly referralFeeRecipient?: Address;
512
512
  readonly deadline?: bigint;
513
- }): Readonly<{
513
+ } & ReferenceTimestampParams): Readonly<{
514
514
  getRequirements: () => Promise<readonly (Readonly<import("../../index.js").Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
515
515
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1RedeemAction>>;
516
516
  }>;
517
517
  /** {@inheritDoc VaultV1Actions.inKindRedeem} */
518
- inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }: {
518
+ inKindRedeem(params: {
519
519
  readonly amount: bigint;
520
520
  readonly marketParamsList: readonly MarketParams[];
521
521
  readonly vaultData: AccrualVault;
522
522
  readonly userAddress: Address;
523
523
  readonly deadline?: bigint;
524
- }): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
524
+ } & ReferenceTimestampParams): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
525
525
  /** {@inheritDoc VaultV1Actions.migrateToV2} */
526
526
  migrateToV2(params: {
527
527
  readonly userAddress: Address;
@@ -531,7 +531,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
531
531
  readonly referralFeePct?: bigint;
532
532
  readonly referralFeeRecipient?: Address;
533
533
  readonly deadline?: bigint;
534
- } & VaultV1MigrateToV2AmountArgs): Readonly<{
534
+ } & ReferenceTimestampParams & VaultV1MigrateToV2AmountArgs): Readonly<{
535
535
  getRequirements: () => Promise<readonly (Readonly<import("../../index.js").Transaction<import("../../index.js").ERC20ApprovalAction>> | import("../../index.js").Requirement<import("../../index.js").Erc2612RequirementSignature, undefined>)[]>;
536
536
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../index.js").Transaction<VaultV1MigrateToV2Action>>;
537
537
  }>;
@@ -5,16 +5,31 @@ 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");
12
11
  const index_js_2 = require("../../helpers/index.js");
12
+ const metadata_js_1 = require("../../helpers/metadata.js");
13
13
  const validate_js_1 = require("../../helpers/validate.js");
14
14
  const index_js_3 = require("../../types/index.js");
15
15
  const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
16
16
  const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
17
+ const getVaultV1InKindRedeemRequirements_js_1 = require("../requirements/getVaultV1InKindRedeemRequirements.js");
17
18
  const index_js_4 = require("../requirements/index.js");
19
+ const inKindRedeemQuote_js_1 = require("./inKindRedeemQuote.js");
20
+ const migrateToV2Quote_js_1 = require("./migrateToV2Quote.js");
21
+ function getMigrationAmounts(params) {
22
+ const assets = "assets" in params ? params.assets : undefined;
23
+ const shares = "shares" in params ? params.shares : undefined;
24
+ if ((assets == null) === (shares == null)) {
25
+ throw new index_js_3.AmountAndSharesExclusiveError();
26
+ }
27
+ const selectedAmount = assets ?? shares ?? 0n;
28
+ if (selectedAmount <= 0n) {
29
+ throw new index_js_3.NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
30
+ }
31
+ return { assets, shares };
32
+ }
18
33
  /** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
19
34
  class MorphoVaultV1 {
20
35
  client;
@@ -51,16 +66,19 @@ class MorphoVaultV1 {
51
66
  }
52
67
  /** {@inheritDoc VaultV1Actions.deposit} */
53
68
  deposit(params) {
69
+ const suppliedNow = params.now;
70
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
54
71
  const { userAddress, vaultData } = params;
55
72
  const { asset: vaultAsset } = vaultData;
56
73
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
57
74
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
58
75
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
59
76
  }
60
- const createdAt = morpho_ts_1.Time.timestamp();
77
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
61
78
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
62
- if (deadline <= createdAt)
79
+ if (deadline <= createdAt) {
63
80
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
81
+ }
64
82
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
65
83
  deadline,
66
84
  referralFeePct: params.referralFeePct,
@@ -84,11 +102,13 @@ class MorphoVaultV1 {
84
102
  let pendingRequirements;
85
103
  return Object.freeze({
86
104
  getRequirements: async (requirementOptions) => {
87
- const now = morpho_ts_1.Time.timestamp();
88
- if (deadline <= now)
105
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
106
+ if (deadline <= now) {
89
107
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
90
- if (pendingRequirements != null)
108
+ }
109
+ if (pendingRequirements != null) {
91
110
  return await pendingRequirements;
111
+ }
92
112
  // Memoize the in-flight promise so concurrent callers share one round of
93
113
  // allowance/nonce reads.
94
114
  const pending = (async () => {
@@ -114,8 +134,9 @@ class MorphoVaultV1 {
114
134
  }
115
135
  finally {
116
136
  // Later calls must re-read live allowances/nonces and honor their own options.
117
- if (pendingRequirements === pending)
137
+ if (pendingRequirements === pending) {
118
138
  pendingRequirements = undefined;
139
+ }
119
140
  }
120
141
  },
121
142
  buildTx: (signatures) => {
@@ -138,25 +159,29 @@ class MorphoVaultV1 {
138
159
  referralFeeRecipient: common.referralFeeRecipient,
139
160
  deadline,
140
161
  },
141
- metadata: this.client.options.metadata,
162
+ metadata,
142
163
  });
143
164
  },
144
165
  });
145
166
  }
146
167
  withdraw(params) {
168
+ const suppliedNow = params.now;
169
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
147
170
  const { amount, userAddress, vaultData } = params;
148
171
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
149
172
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
150
173
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
151
174
  }
152
- if (amount <= 0n)
175
+ if (amount <= 0n) {
153
176
  throw new index_js_3.NonPositiveInputError("amount", amount);
177
+ }
154
178
  // Reject values outside the ABI range before resolving any requirements.
155
179
  (0, validate_js_1.validateUint256Field)("amount", amount);
156
- const createdAt = morpho_ts_1.Time.timestamp();
180
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
157
181
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
158
- if (deadline <= createdAt)
182
+ if (deadline <= createdAt) {
159
183
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
184
+ }
160
185
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
161
186
  deadline,
162
187
  referralFeePct: params.referralFeePct,
@@ -174,9 +199,10 @@ class MorphoVaultV1 {
174
199
  });
175
200
  return Object.freeze({
176
201
  getRequirements: async () => {
177
- const now = morpho_ts_1.Time.timestamp();
178
- if (deadline <= now)
202
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
203
+ if (deadline <= now) {
179
204
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
205
+ }
180
206
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
181
207
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
182
208
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
@@ -206,21 +232,25 @@ class MorphoVaultV1 {
206
232
  referralFeeRecipient: common.referralFeeRecipient,
207
233
  deadline,
208
234
  },
209
- metadata: this.client.options.metadata,
235
+ metadata,
210
236
  });
211
237
  },
212
238
  });
213
239
  }
214
240
  /** {@inheritDoc VaultV1Actions.redeem} */
215
241
  redeem(params) {
242
+ const suppliedNow = params.now;
243
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
216
244
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
217
245
  const { shares, userAddress } = params;
218
- if (shares <= 0n)
246
+ if (shares <= 0n) {
219
247
  throw new index_js_3.NonPositiveInputError("shares", shares);
220
- const createdAt = morpho_ts_1.Time.timestamp();
248
+ }
249
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
221
250
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
222
- if (deadline <= createdAt)
251
+ if (deadline <= createdAt) {
223
252
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
253
+ }
224
254
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
225
255
  deadline,
226
256
  referralFeePct: params.referralFeePct,
@@ -229,9 +259,10 @@ class MorphoVaultV1 {
229
259
  const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
230
260
  return Object.freeze({
231
261
  getRequirements: async () => {
232
- const now = morpho_ts_1.Time.timestamp();
233
- if (deadline <= now)
262
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
263
+ if (deadline <= now) {
234
264
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
265
+ }
235
266
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
236
267
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
237
268
  vaultData: await this.getData(),
@@ -260,158 +291,40 @@ class MorphoVaultV1 {
260
291
  referralFeeRecipient: common.referralFeeRecipient,
261
292
  deadline,
262
293
  },
263
- metadata: this.client.options.metadata,
294
+ metadata,
264
295
  });
265
296
  },
266
297
  });
267
298
  }
268
299
  /** {@inheritDoc VaultV1Actions.inKindRedeem} */
269
- inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
300
+ inKindRedeem(params) {
301
+ const suppliedNow = params.now;
302
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
303
+ const { amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, } = params;
270
304
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
271
305
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
272
306
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
273
307
  }
274
- if (amount <= 0n)
275
- throw new index_js_3.NonPositiveInputError("amount", amount);
276
- if (marketParamsList.length === 0)
277
- throw new index_js_3.EmptyMarketParamsListError();
278
- const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
279
- loanToken,
280
- collateralToken,
281
- oracle,
282
- irm,
283
- lltv,
284
- }));
285
- const now = morpho_ts_1.Time.timestamp();
286
- const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
287
- // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
288
- // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
289
- (0, validate_js_1.validateDeadline)(deadline);
290
- if (deadline <= now)
291
- throw new index_js_3.ExpiredDeadlineError(deadline, now);
292
- const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
293
- const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
294
- let covered = 0n;
295
- const assignedByMarket = new Map();
296
- for (const marketParams of marketParamsListSnapshot) {
297
- if (covered === amount)
298
- break;
299
- const marketId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
300
- const allocation = vaultData.allocations.get(marketId);
301
- if (allocation?.config.enabled !== true)
302
- continue;
303
- if (allocation.position.supplyShares === 0n)
304
- continue;
305
- const market = allocation.position.market.accrueInterest(now);
306
- const available = market.toSupplyAssets(allocation.position.supplyShares);
307
- const assigned = assignedByMarket.get(marketId) ?? 0n;
308
- const chunk = blue_sdk_1.MathLib.min(available, amount - covered);
309
- if (assigned + chunk > available) {
310
- throw new index_js_3.InKindRedeemCoverageError({
311
- required: amount,
312
- covered,
313
- maxExitAssets: covered,
314
- });
315
- }
316
- assignedByMarket.set(marketId, assigned + chunk);
317
- covered += chunk;
318
- }
319
- if (covered < amount) {
320
- throw new index_js_3.InKindRedeemCoverageError({
321
- required: amount,
322
- covered,
323
- maxExitAssets: covered,
324
- });
325
- }
326
- const requiredShareAllowance = (0, index_js_2.computeVaultMaxShareAllowance)({
308
+ const { deadline, marketParamsListSnapshot, requiredShareAllowance, vaultExitBundlesV1, } = (0, inKindRedeemQuote_js_1.computeVaultV1InKindRedeemQuote)({
309
+ amount,
310
+ marketParamsList,
327
311
  vaultData,
328
- deadline: now,
329
- assets: amount,
330
- slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
312
+ deadline: deadlineOverride,
313
+ now: suppliedNow ?? morpho_ts_1.Time.timestamp(),
314
+ chainId: this.chainId,
331
315
  });
332
316
  return {
333
- getRequirements: async () => {
334
- const requirementsTimestamp = morpho_ts_1.Time.timestamp();
335
- if (deadline <= requirementsTimestamp) {
336
- throw new index_js_3.ExpiredDeadlineError(deadline, requirementsTimestamp);
337
- }
338
- await (0, validateClientChainId_js_1.validateClientChainId)(this.client.viemClient, this.chainId);
339
- await this.assertWriteTargets(["bundles.vaultExitBundlesV1", "blue"]);
340
- const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await Promise.all([
341
- (0, actions_1.readContract)(this.client.viemClient, {
342
- address: this.vault,
343
- abi: viem_1.erc20Abi,
344
- functionName: "allowance",
345
- args: [userAddress, vaultExitBundlesV1],
346
- }),
347
- (0, actions_1.readContract)(this.client.viemClient, {
348
- address: this.vault,
349
- abi: blue_sdk_viem_1.erc2612Abi,
350
- functionName: "nonces",
351
- args: [userAddress],
352
- }),
353
- (0, actions_1.readContract)(this.client.viemClient, {
354
- address: vaultData.asset,
355
- abi: viem_1.erc20Abi,
356
- functionName: "balanceOf",
357
- args: [blue],
358
- }),
359
- (0, actions_1.readContract)(this.client.viemClient, {
360
- address: this.vault,
361
- abi: blue_sdk_viem_1.metaMorphoAbi,
362
- functionName: "MORPHO",
363
- }),
364
- // feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
365
- (0, actions_1.readContract)(this.client.viemClient, {
366
- address: blue,
367
- abi: blue_sdk_viem_1.blueAbi,
368
- functionName: "feeRecipient",
369
- }),
370
- ]);
371
- if (!(0, viem_1.isAddressEqual)(morpho, blue)) {
372
- throw new index_js_3.VaultMorphoMismatchError({
373
- vault: this.vault,
374
- expected: blue,
375
- actual: morpho,
376
- });
377
- }
378
- // Reject this unsupported configuration before authorizing vault shares:
379
- // VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
380
- // vault position, so its callback can exhaust marketParamsList and panic on-chain.
381
- if ((0, viem_1.isAddressEqual)(blueFeeRecipient, this.vault)) {
382
- throw new index_js_3.VaultIsBlueFeeRecipientError(this.vault, blue);
383
- }
384
- if (blueBalance < amount) {
385
- throw new index_js_3.InsufficientBlueBalanceForInKindRedeemError({
386
- asset: vaultData.asset,
387
- available: blueBalance,
388
- required: amount,
389
- });
390
- }
391
- if (allowance >= requiredShareAllowance)
392
- return [];
393
- if (this.client.options.supportSignature) {
394
- return [
395
- (0, index_js_1.encodeVaultSharesPermit)({
396
- vault: vaultData,
397
- version: "vaultV1",
398
- spender: vaultExitBundlesV1,
399
- owner: userAddress,
400
- chainId: this.chainId,
401
- nonce,
402
- deadline,
403
- }),
404
- ];
405
- }
406
- return [
407
- (0, index_js_1.encodeErc20Approval)({
408
- token: this.vault,
409
- spender: vaultExitBundlesV1,
410
- amount: viem_1.maxUint256,
411
- chainId: this.chainId,
412
- }),
413
- ];
414
- },
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
+ }),
415
328
  buildTx: (signatures) => {
416
329
  const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
417
330
  spender: vaultExitBundlesV1,
@@ -427,13 +340,15 @@ class MorphoVaultV1 {
427
340
  deadline,
428
341
  requirementSignature: permit,
429
342
  },
430
- metadata: this.client.options.metadata,
343
+ metadata,
431
344
  });
432
345
  },
433
346
  };
434
347
  }
435
348
  /** {@inheritDoc VaultV1Actions.migrateToV2} */
436
349
  migrateToV2(params) {
350
+ const suppliedNow = params.now;
351
+ const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
437
352
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
438
353
  if (!(0, viem_1.isAddressEqual)(params.sourceVault.address, this.vault)) {
439
354
  throw new index_js_3.VaultAddressMismatchError(this.vault, params.sourceVault.address);
@@ -444,48 +359,28 @@ class MorphoVaultV1 {
444
359
  if ((0, viem_1.isAddressEqual)(this.vault, params.targetVault.address)) {
445
360
  throw new index_js_3.SameVaultMigrationError(this.vault);
446
361
  }
447
- const assets = "assets" in params ? params.assets : undefined;
448
- const shares = "shares" in params ? params.shares : undefined;
449
- if ((assets == null) === (shares == null)) {
450
- throw new index_js_3.AmountAndSharesExclusiveError();
451
- }
452
- const selectedAmount = assets ?? shares ?? 0n;
453
- if (selectedAmount <= 0n) {
454
- throw new index_js_3.NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
455
- }
362
+ const { assets, shares } = getMigrationAmounts(params);
456
363
  const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
457
364
  (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
458
- const createdAt = morpho_ts_1.Time.timestamp();
365
+ const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
459
366
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
460
- if (deadline <= createdAt)
367
+ if (deadline <= createdAt) {
461
368
  throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
369
+ }
462
370
  const common = (0, common_js_1.normalizeBundlesCommonParams)({
463
371
  deadline,
464
372
  referralFeePct: params.referralFeePct,
465
373
  referralFeeRecipient: params.referralFeeRecipient,
466
374
  });
467
- // Only the destination receives a deposit; the source vault is an exit.
468
- // V1 redeem accrues market interest and performance fees before converting shares.
469
- const grossAssets = assets ??
470
- params.sourceVault
471
- .accrueInterest(params.sourceVault.allocations
472
- .values()
473
- .reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), createdAt))
474
- .toAssets(shares ?? 0n, "Down");
475
- const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, common.referralFeePct);
476
- const maxSharePriceVaultV2 = (0, index_js_2.computeVaultMaxSharePrice)({
477
- 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,
478
380
  deadline,
479
- assets: grossAssets - referralFeeAssets,
480
381
  slippageTolerance,
382
+ now: createdAt,
481
383
  });
482
- const requiredShareAllowance = shares ??
483
- (0, index_js_2.computeVaultMaxShareAllowance)({
484
- vaultData: params.sourceVault,
485
- deadline,
486
- assets: assets ?? 0n,
487
- slippageTolerance,
488
- });
489
384
  const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
490
385
  const { userAddress } = params;
491
386
  const sourceAsset = params.sourceVault.asset;
@@ -504,9 +399,10 @@ class MorphoVaultV1 {
504
399
  });
505
400
  return Object.freeze({
506
401
  getRequirements: async () => {
507
- const now = morpho_ts_1.Time.timestamp();
508
- if (deadline <= now)
402
+ const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
403
+ if (deadline <= now) {
509
404
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
405
+ }
510
406
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
511
407
  // Re-read the live share allowance on every call instead of caching the resolved requirements.
512
408
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
@@ -535,7 +431,7 @@ class MorphoVaultV1 {
535
431
  args: {
536
432
  targetVault: targetAddress,
537
433
  targetAsset,
538
- ...(assets != null ? { assets } : { shares: shares ?? 0n }),
434
+ ...(assets == null ? { shares: shares ?? 0n } : { assets }),
539
435
  maxSharePriceVaultV2,
540
436
  userAddress,
541
437
  requirementSignature: permit,
@@ -543,7 +439,7 @@ class MorphoVaultV1 {
543
439
  referralFeeRecipient: common.referralFeeRecipient,
544
440
  deadline,
545
441
  },
546
- metadata: this.client.options.metadata,
442
+ metadata,
547
443
  });
548
444
  },
549
445
  });
@@ -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
+ };