@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
@@ -5,7 +5,8 @@ import { readContract } from "viem/actions";
5
5
  import { resolveBundlesTokenRequirements } from "../../actions/bundles/index.js";
6
6
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
7
7
  import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
8
- import { ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
8
+ import { validateDeadline } from "../../helpers/validate.js";
9
+ import { ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, } from "../../types/index.js";
9
10
  import { getErc2612Permit } from "./getErc2612Permit.js";
10
11
  /**
11
12
  * Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
@@ -22,7 +23,7 @@ import { getErc2612Permit } from "./getErc2612Permit.js";
22
23
  * @param params.owner - Account funding the operation.
23
24
  * @param params.chainId - Target chain id; must match the client chain.
24
25
  * @param params.deadline - Final-call and signature deadline.
25
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
26
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
26
27
  * @param params.supportSignature - Whether ERC-2612 signatures may be requested.
27
28
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
28
29
  * @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
@@ -93,16 +94,8 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
93
94
  max: maxUint256,
94
95
  });
95
96
  }
96
- if (params.deadline <= 0n) {
97
- throw new NonPositiveInputError("deadline", params.deadline);
98
- }
99
- if (params.deadline > maxUint256) {
100
- throw new InputExceedsMaxError({
101
- field: "deadline",
102
- value: params.deadline,
103
- max: maxUint256,
104
- });
105
- }
97
+ // Reject deadlines outside the positive uint256 range before reading state.
98
+ validateDeadline(params.deadline);
106
99
  // Reject an already-expired deadline before the RPC reads so a direct caller of this resolver
107
100
  // never signs a permit for a supply the BlueBundlesV1 call would revert. The entity validates
108
101
  // this too, but the exported resolver must guard its own callers.
@@ -110,8 +103,9 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
110
103
  if (params.deadline <= timestamp) {
111
104
  throw new ExpiredDeadlineError(params.deadline, timestamp);
112
105
  }
113
- if (params.amount === 0n)
106
+ if (params.amount === 0n) {
114
107
  return [];
108
+ }
115
109
  await validateClientChainId(viemClient, params.chainId);
116
110
  const allowance = await readContract(viemClient, {
117
111
  abi: erc20Abi,
@@ -119,24 +113,26 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
119
113
  functionName: "allowance",
120
114
  args: [params.owner, params.spender],
121
115
  });
122
- if (allowance >= params.amount)
116
+ if (allowance >= params.amount) {
123
117
  return [];
118
+ }
124
119
  const { dai } = getChainAddresses(params.chainId);
125
- if (params.supportSignature) {
126
- const isDai = isDefined(dai) && isAddressEqual(params.token, dai);
127
- if ((params.useSimplePermit ?? true) && !isDai) {
128
- const permit = await getErc2612Permit(viemClient, {
129
- token: params.token,
130
- owner: params.owner,
131
- spender: params.spender,
132
- amount: params.amount,
133
- chainId: params.chainId,
134
- deadline: params.deadline,
135
- now: timestamp,
136
- supportDeployless: params.supportDeployless,
137
- });
138
- if (isDefined(permit))
139
- return [permit];
120
+ const isDai = params.supportSignature &&
121
+ isDefined(dai) &&
122
+ isAddressEqual(params.token, dai);
123
+ if (params.supportSignature && (params.useSimplePermit ?? true) && !isDai) {
124
+ const permit = await getErc2612Permit(viemClient, {
125
+ token: params.token,
126
+ owner: params.owner,
127
+ spender: params.spender,
128
+ amount: params.amount,
129
+ chainId: params.chainId,
130
+ deadline: params.deadline,
131
+ now: timestamp,
132
+ supportDeployless: params.supportDeployless,
133
+ });
134
+ if (isDefined(permit)) {
135
+ return [permit];
140
136
  }
141
137
  }
142
138
  return resolveBundlesTokenRequirements({
@@ -14,10 +14,12 @@ export async function getErc2612Permit(viemClient, params) {
14
14
  functionName: "nonces",
15
15
  args: [params.owner],
16
16
  }).catch((error) => {
17
- if (isTransportError(error))
17
+ if (isTransportError(error)) {
18
18
  throw error;
19
- if (isContractRevertError(error) || isUndecodableResultError(error))
19
+ }
20
+ if (isContractRevertError(error) || isUndecodableResultError(error)) {
20
21
  return undefined;
22
+ }
21
23
  throw error;
22
24
  });
23
25
  if (isDefined(nonce)) {
@@ -38,10 +40,12 @@ export async function getErc2612Permit(viemClient, params) {
38
40
  address: params.token,
39
41
  functionName: "DOMAIN_SEPARATOR",
40
42
  }).catch((error) => {
41
- if (isTransportError(error))
43
+ if (isTransportError(error)) {
42
44
  throw error;
43
- if (isContractRevertError(error) || isUndecodableResultError(error))
45
+ }
46
+ if (isContractRevertError(error) || isUndecodableResultError(error)) {
44
47
  return undefined;
48
+ }
45
49
  throw error;
46
50
  });
47
51
  const domain = permit.action.typedData.domain ?? {};
@@ -49,8 +53,9 @@ export async function getErc2612Permit(viemClient, params) {
49
53
  hashDomain({
50
54
  domain,
51
55
  types: { EIP712Domain: getTypesForEIP712Domain({ domain }) },
52
- }).toLowerCase())
56
+ }).toLowerCase()) {
53
57
  return permit;
58
+ }
54
59
  }
55
60
  }
56
61
  return undefined;
@@ -1,6 +1,6 @@
1
1
  import type { Token } from "@morpho-org/blue-sdk";
2
2
  import type { Address, Client } from "viem";
3
- import { type ERC20ApprovalAction, type PermitRequirementSignature, type Requirement, type Transaction } from "../../types/index.js";
3
+ import { type ERC20ApprovalAction, type PermitRequirementSignature, type ReferenceTimestampParams, type Requirement, type Transaction } from "../../types/index.js";
4
4
  /**
5
5
  * Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
6
6
  *
@@ -11,11 +11,13 @@ import { type ERC20ApprovalAction, type PermitRequirementSignature, type Require
11
11
  *
12
12
  * @param viemClient - Client used to read the current share allowance and permit nonce.
13
13
  * @param params - Vault snapshot, owner, minimum allowance, and deadline values.
14
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
14
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
15
15
  * @returns No requirement when the allowance is sufficient, otherwise one approval or permit.
16
16
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
17
17
  * another chain than `params.chainId`.
18
18
  * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
19
+ * @throws {NonPositiveInputError} when the deadline is not positive.
20
+ * @throws {InputExceedsMaxError} when the deadline exceeds `maxUint256`.
19
21
  * @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
20
22
  */
21
23
  export declare const getVaultBundlesSharesRequirements: (viemClient: Client, params: {
@@ -26,5 +28,4 @@ export declare const getVaultBundlesSharesRequirements: (viemClient: Client, par
26
28
  readonly requiredShareAllowance: bigint;
27
29
  readonly deadline: bigint;
28
30
  readonly supportSignature: boolean;
29
- readonly now?: bigint;
30
- }) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
31
+ } & ReferenceTimestampParams) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
@@ -5,6 +5,7 @@ import { readContract } from "viem/actions";
5
5
  import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
6
6
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
7
7
  import { validateChainId } from "../../helpers/index.js";
8
+ import { validateDeadline } from "../../helpers/validate.js";
8
9
  import { ExpiredDeadlineError, } from "../../types/index.js";
9
10
  /**
10
11
  * Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
@@ -16,15 +17,19 @@ import { ExpiredDeadlineError, } from "../../types/index.js";
16
17
  *
17
18
  * @param viemClient - Client used to read the current share allowance and permit nonce.
18
19
  * @param params - Vault snapshot, owner, minimum allowance, and deadline values.
19
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
20
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
20
21
  * @returns No requirement when the allowance is sufficient, otherwise one approval or permit.
21
22
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
22
23
  * another chain than `params.chainId`.
23
24
  * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
25
+ * @throws {NonPositiveInputError} when the deadline is not positive.
26
+ * @throws {InputExceedsMaxError} when the deadline exceeds `maxUint256`.
24
27
  * @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
25
28
  */
26
29
  export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
27
30
  validateChainId(viemClient.chain?.id, params.chainId);
31
+ // Reject deadlines outside the positive uint256 range before reading state.
32
+ validateDeadline(params.deadline);
28
33
  const now = params.now ?? Time.timestamp();
29
34
  if (params.deadline <= now) {
30
35
  throw new ExpiredDeadlineError(params.deadline, now);
@@ -38,8 +43,9 @@ export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
38
43
  functionName: "allowance",
39
44
  args: [params.owner, spender],
40
45
  });
41
- if (allowance >= params.requiredShareAllowance)
46
+ if (allowance >= params.requiredShareAllowance) {
42
47
  return [];
48
+ }
43
49
  if (params.supportSignature) {
44
50
  const nonce = await readContract(viemClient, {
45
51
  address: params.vaultData.address,
@@ -0,0 +1,21 @@
1
+ import type { AccrualVault } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import { type Address } from "viem";
4
+ import { type ActionRequirement, type ReferenceTimestampParams } from "../../types/index.js";
5
+ /**
6
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
7
+ * @param client - Client serving the requested chain.
8
+ * @param params - Snapshot and fixed quote used for authorization.
9
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
10
+ * @returns Share approvals or permit requirements.
11
+ */
12
+ export declare function getVaultV1InKindRedeemRequirements(client: Client, params: ReferenceTimestampParams & {
13
+ readonly vaultData: AccrualVault;
14
+ readonly vault: Address;
15
+ readonly userAddress: Address;
16
+ readonly chainId: number;
17
+ readonly deadline: bigint;
18
+ readonly requiredShareAllowance: bigint;
19
+ readonly supportSignature: boolean;
20
+ readonly amount: bigint;
21
+ }): Promise<readonly ActionRequirement[]>;
@@ -0,0 +1,108 @@
1
+ import { blueAbi, erc2612Abi, metaMorphoAbi } from "@morpho-org/blue-sdk-viem";
2
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { erc20Abi, isAddressEqual, 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, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } 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 getVaultV1InKindRedeemRequirements(client, params) {
17
+ const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, amount, } = 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
+ const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await Promise.all([
33
+ readContract(client, {
34
+ address: vault,
35
+ abi: erc20Abi,
36
+ functionName: "allowance",
37
+ args: [userAddress, vaultExitBundlesV1],
38
+ }),
39
+ readContract(client, {
40
+ address: vault,
41
+ abi: erc2612Abi,
42
+ functionName: "nonces",
43
+ args: [userAddress],
44
+ }),
45
+ readContract(client, {
46
+ address: vaultData.asset,
47
+ abi: erc20Abi,
48
+ functionName: "balanceOf",
49
+ args: [blue],
50
+ }),
51
+ readContract(client, {
52
+ address: vault,
53
+ abi: metaMorphoAbi,
54
+ functionName: "MORPHO",
55
+ }),
56
+ // feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
57
+ readContract(client, {
58
+ address: blue,
59
+ abi: blueAbi,
60
+ functionName: "feeRecipient",
61
+ }),
62
+ ]);
63
+ if (!isAddressEqual(morpho, blue)) {
64
+ throw new VaultMorphoMismatchError({
65
+ vault: vault,
66
+ expected: blue,
67
+ actual: morpho,
68
+ });
69
+ }
70
+ // Reject this unsupported configuration before authorizing vault shares:
71
+ // VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
72
+ // vault position, so its callback can exhaust marketParamsList and panic on-chain.
73
+ if (isAddressEqual(blueFeeRecipient, vault)) {
74
+ throw new VaultIsBlueFeeRecipientError(vault, blue);
75
+ }
76
+ if (blueBalance < amount) {
77
+ throw new InsufficientBlueBalanceForInKindRedeemError({
78
+ asset: vaultData.asset,
79
+ available: blueBalance,
80
+ required: amount,
81
+ });
82
+ }
83
+ if (allowance >= requiredShareAllowance) {
84
+ return [];
85
+ }
86
+ if (supportSignature) {
87
+ return [
88
+ encodeVaultSharesPermit({
89
+ now: params.now,
90
+ vault: vaultData,
91
+ version: "vaultV1",
92
+ spender: vaultExitBundlesV1,
93
+ owner: userAddress,
94
+ chainId: chainId,
95
+ nonce,
96
+ deadline,
97
+ }),
98
+ ];
99
+ }
100
+ return [
101
+ encodeErc20Approval({
102
+ token: vault,
103
+ spender: vaultExitBundlesV1,
104
+ amount: maxUint256,
105
+ chainId: chainId,
106
+ }),
107
+ ];
108
+ }
@@ -0,0 +1,20 @@
1
+ import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import { type Address } from "viem";
4
+ import { type ActionRequirement, type ReferenceTimestampParams } from "../../types/index.js";
5
+ /**
6
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
7
+ * @param client - Client serving the requested chain.
8
+ * @param params - Snapshot and fixed quote used for authorization.
9
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
10
+ * @returns Share approvals or permit requirements.
11
+ */
12
+ export declare function getVaultV2ForceWithdrawRequirements(client: Client, params: {
13
+ readonly vaultData: AccrualVaultV2;
14
+ readonly vault: Address;
15
+ readonly userAddress: Address;
16
+ readonly chainId: number;
17
+ readonly deadline: bigint;
18
+ readonly requiredShareAllowance: bigint;
19
+ readonly supportSignature: boolean;
20
+ } & ReferenceTimestampParams): Promise<readonly ActionRequirement[]>;
@@ -0,0 +1,73 @@
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, } 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 getVaultV2ForceWithdrawRequirements(client, params) {
17
+ const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, } = params;
18
+ const vaultExitBundlesV1 = getChainAddress(chainId, "bundles.vaultExitBundlesV1");
19
+ const requirementsTimestamp = params.now ?? Time.timestamp();
20
+ if (deadline <= requirementsTimestamp) {
21
+ throw new ExpiredDeadlineError(deadline, requirementsTimestamp);
22
+ }
23
+ await validateClientChainId(client, chainId);
24
+ await assertRegistryTargetsHaveCode(client, chainId, [
25
+ {
26
+ role: "bundles.vaultExitBundlesV1",
27
+ address: getChainAddress(chainId, "bundles.vaultExitBundlesV1"),
28
+ },
29
+ ]);
30
+ // Vault gates are intentionally left to the final transaction: the receive-assets gate may
31
+ // inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
32
+ // external code re-evaluated after each intermediate penalty burn, so neither is
33
+ // execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
34
+ // supplies into Morpho Blue, so no Blue token-balance check is needed.
35
+ const [allowance, nonce] = await Promise.all([
36
+ readContract(client, {
37
+ address: vault,
38
+ abi: erc20Abi,
39
+ functionName: "allowance",
40
+ args: [userAddress, vaultExitBundlesV1],
41
+ }),
42
+ readContract(client, {
43
+ address: vault,
44
+ abi: erc2612Abi,
45
+ functionName: "nonces",
46
+ args: [userAddress],
47
+ }),
48
+ ]);
49
+ if (allowance >= requiredShareAllowance) {
50
+ return [];
51
+ }
52
+ if (supportSignature) {
53
+ const requirement = encodeVaultSharesPermit({
54
+ now: params.now,
55
+ vault: vaultData,
56
+ version: "vaultV2",
57
+ spender: vaultExitBundlesV1,
58
+ owner: userAddress,
59
+ chainId: chainId,
60
+ nonce,
61
+ deadline,
62
+ });
63
+ return [requirement];
64
+ }
65
+ return [
66
+ encodeErc20Approval({
67
+ token: vault,
68
+ spender: vaultExitBundlesV1,
69
+ amount: maxUint256,
70
+ chainId: chainId,
71
+ }),
72
+ ];
73
+ }
@@ -0,0 +1,21 @@
1
+ import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import type { Client } from "viem";
3
+ import { type Address } from "viem";
4
+ import { type ActionRequirement, type ReferenceTimestampParams } from "../../types/index.js";
5
+ /**
6
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
7
+ * @param client - Client serving the requested chain.
8
+ * @param params - Snapshot and fixed quote used for authorization.
9
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
10
+ * @returns Share approvals or permit requirements.
11
+ */
12
+ export declare function getVaultV2InKindRedeemRequirements(client: Client, params: ReferenceTimestampParams & {
13
+ readonly vaultData: AccrualVaultV2;
14
+ readonly vault: Address;
15
+ readonly userAddress: Address;
16
+ readonly chainId: number;
17
+ readonly deadline: bigint;
18
+ readonly requiredShareAllowance: bigint;
19
+ readonly supportSignature: boolean;
20
+ readonly peak: bigint;
21
+ }): Promise<readonly ActionRequirement[]>;
@@ -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
+ }