@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
@@ -8,6 +8,7 @@ const actions_1 = require("viem/actions");
8
8
  const index_js_1 = require("../../actions/bundles/index.js");
9
9
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
10
10
  const index_js_2 = require("../../helpers/index.js");
11
+ const validate_js_1 = require("../../helpers/validate.js");
11
12
  const index_js_3 = require("../../types/index.js");
12
13
  const getErc2612Permit_js_1 = require("./getErc2612Permit.js");
13
14
  /**
@@ -25,7 +26,7 @@ const getErc2612Permit_js_1 = require("./getErc2612Permit.js");
25
26
  * @param params.owner - Account funding the operation.
26
27
  * @param params.chainId - Target chain id; must match the client chain.
27
28
  * @param params.deadline - Final-call and signature deadline.
28
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
29
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
29
30
  * @param params.supportSignature - Whether ERC-2612 signatures may be requested.
30
31
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
31
32
  * @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
@@ -96,16 +97,8 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
96
97
  max: viem_1.maxUint256,
97
98
  });
98
99
  }
99
- if (params.deadline <= 0n) {
100
- throw new index_js_3.NonPositiveInputError("deadline", params.deadline);
101
- }
102
- if (params.deadline > viem_1.maxUint256) {
103
- throw new index_js_3.InputExceedsMaxError({
104
- field: "deadline",
105
- value: params.deadline,
106
- max: viem_1.maxUint256,
107
- });
108
- }
100
+ // Reject deadlines outside the positive uint256 range before reading state.
101
+ (0, validate_js_1.validateDeadline)(params.deadline);
109
102
  // Reject an already-expired deadline before the RPC reads so a direct caller of this resolver
110
103
  // never signs a permit for a supply the BlueBundlesV1 call would revert. The entity validates
111
104
  // this too, but the exported resolver must guard its own callers.
@@ -113,8 +106,9 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
113
106
  if (params.deadline <= timestamp) {
114
107
  throw new index_js_3.ExpiredDeadlineError(params.deadline, timestamp);
115
108
  }
116
- if (params.amount === 0n)
109
+ if (params.amount === 0n) {
117
110
  return [];
111
+ }
118
112
  await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
119
113
  const allowance = await (0, actions_1.readContract)(viemClient, {
120
114
  abi: viem_1.erc20Abi,
@@ -122,24 +116,26 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
122
116
  functionName: "allowance",
123
117
  args: [params.owner, params.spender],
124
118
  });
125
- if (allowance >= params.amount)
119
+ if (allowance >= params.amount) {
126
120
  return [];
121
+ }
127
122
  const { dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
128
- if (params.supportSignature) {
129
- const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
130
- if ((params.useSimplePermit ?? true) && !isDai) {
131
- const permit = await (0, getErc2612Permit_js_1.getErc2612Permit)(viemClient, {
132
- token: params.token,
133
- owner: params.owner,
134
- spender: params.spender,
135
- amount: params.amount,
136
- chainId: params.chainId,
137
- deadline: params.deadline,
138
- now: timestamp,
139
- supportDeployless: params.supportDeployless,
140
- });
141
- if ((0, morpho_ts_1.isDefined)(permit))
142
- return [permit];
123
+ const isDai = params.supportSignature &&
124
+ (0, morpho_ts_1.isDefined)(dai) &&
125
+ (0, viem_1.isAddressEqual)(params.token, dai);
126
+ if (params.supportSignature && (params.useSimplePermit ?? true) && !isDai) {
127
+ const permit = await (0, getErc2612Permit_js_1.getErc2612Permit)(viemClient, {
128
+ token: params.token,
129
+ owner: params.owner,
130
+ spender: params.spender,
131
+ amount: params.amount,
132
+ chainId: params.chainId,
133
+ deadline: params.deadline,
134
+ now: timestamp,
135
+ supportDeployless: params.supportDeployless,
136
+ });
137
+ if ((0, morpho_ts_1.isDefined)(permit)) {
138
+ return [permit];
143
139
  }
144
140
  }
145
141
  return (0, index_js_1.resolveBundlesTokenRequirements)({
@@ -17,10 +17,12 @@ async function getErc2612Permit(viemClient, params) {
17
17
  functionName: "nonces",
18
18
  args: [params.owner],
19
19
  }).catch((error) => {
20
- if ((0, blue_sdk_viem_1.isTransportError)(error))
20
+ if ((0, blue_sdk_viem_1.isTransportError)(error)) {
21
21
  throw error;
22
- if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
22
+ }
23
+ if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error)) {
23
24
  return undefined;
25
+ }
24
26
  throw error;
25
27
  });
26
28
  if ((0, morpho_ts_1.isDefined)(nonce)) {
@@ -41,10 +43,12 @@ async function getErc2612Permit(viemClient, params) {
41
43
  address: params.token,
42
44
  functionName: "DOMAIN_SEPARATOR",
43
45
  }).catch((error) => {
44
- if ((0, blue_sdk_viem_1.isTransportError)(error))
46
+ if ((0, blue_sdk_viem_1.isTransportError)(error)) {
45
47
  throw error;
46
- if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
48
+ }
49
+ if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error)) {
47
50
  return undefined;
51
+ }
48
52
  throw error;
49
53
  });
50
54
  const domain = permit.action.typedData.domain ?? {};
@@ -52,8 +56,9 @@ async function getErc2612Permit(viemClient, params) {
52
56
  (0, viem_1.hashDomain)({
53
57
  domain,
54
58
  types: { EIP712Domain: (0, viem_1.getTypesForEIP712Domain)({ domain }) },
55
- }).toLowerCase())
59
+ }).toLowerCase()) {
56
60
  return permit;
61
+ }
57
62
  }
58
63
  }
59
64
  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>)[]>;
@@ -8,6 +8,7 @@ const actions_1 = require("viem/actions");
8
8
  const index_js_1 = require("../../actions/index.js");
9
9
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
10
10
  const index_js_2 = require("../../helpers/index.js");
11
+ const validate_js_1 = require("../../helpers/validate.js");
11
12
  const index_js_3 = require("../../types/index.js");
12
13
  /**
13
14
  * Resolves the vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
@@ -19,15 +20,19 @@ const index_js_3 = require("../../types/index.js");
19
20
  *
20
21
  * @param viemClient - Client used to read the current share allowance and permit nonce.
21
22
  * @param params - Vault snapshot, owner, minimum allowance, and deadline values.
22
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
23
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
23
24
  * @returns No requirement when the allowance is sufficient, otherwise one approval or permit.
24
25
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
25
26
  * another chain than `params.chainId`.
26
27
  * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
28
+ * @throws {NonPositiveInputError} when the deadline is not positive.
29
+ * @throws {InputExceedsMaxError} when the deadline exceeds `maxUint256`.
27
30
  * @throws {viem.BaseError} when an allowance, permit nonce, or `eth_chainId` read fails.
28
31
  */
29
32
  const getVaultBundlesSharesRequirements = async (viemClient, params) => {
30
33
  (0, index_js_2.validateChainId)(viemClient.chain?.id, params.chainId);
34
+ // Reject deadlines outside the positive uint256 range before reading state.
35
+ (0, validate_js_1.validateDeadline)(params.deadline);
31
36
  const now = params.now ?? morpho_ts_1.Time.timestamp();
32
37
  if (params.deadline <= now) {
33
38
  throw new index_js_3.ExpiredDeadlineError(params.deadline, now);
@@ -41,8 +46,9 @@ const getVaultBundlesSharesRequirements = async (viemClient, params) => {
41
46
  functionName: "allowance",
42
47
  args: [params.owner, spender],
43
48
  });
44
- if (allowance >= params.requiredShareAllowance)
49
+ if (allowance >= params.requiredShareAllowance) {
45
50
  return [];
51
+ }
46
52
  if (params.supportSignature) {
47
53
  const nonce = await (0, actions_1.readContract)(viemClient, {
48
54
  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,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVaultV1InKindRedeemRequirements = getVaultV1InKindRedeemRequirements;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const index_js_1 = require("../../actions/index.js");
9
+ const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
10
+ const index_js_2 = require("../../types/index.js");
11
+ const assertContractCode_js_1 = require("./assertContractCode.js");
12
+ /**
13
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
14
+ * @param client - Client serving the requested chain.
15
+ * @param params - Snapshot and fixed quote used for authorization.
16
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
17
+ * @returns Share approvals or permit requirements.
18
+ */
19
+ async function getVaultV1InKindRedeemRequirements(client, params) {
20
+ const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, amount, } = params;
21
+ const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1");
22
+ const blue = (0, morpho_ts_1.getChainAddress)(chainId, "blue");
23
+ const requirementsTimestamp = params.now ?? morpho_ts_1.Time.timestamp();
24
+ if (deadline <= requirementsTimestamp) {
25
+ throw new index_js_2.ExpiredDeadlineError(deadline, requirementsTimestamp);
26
+ }
27
+ await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
28
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
29
+ {
30
+ role: "bundles.vaultExitBundlesV1",
31
+ address: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1"),
32
+ },
33
+ { role: "blue", address: (0, morpho_ts_1.getChainAddress)(chainId, "blue") },
34
+ ]);
35
+ const [allowance, nonce, blueBalance, morpho, blueFeeRecipient] = await Promise.all([
36
+ (0, actions_1.readContract)(client, {
37
+ address: vault,
38
+ abi: viem_1.erc20Abi,
39
+ functionName: "allowance",
40
+ args: [userAddress, vaultExitBundlesV1],
41
+ }),
42
+ (0, actions_1.readContract)(client, {
43
+ address: vault,
44
+ abi: blue_sdk_viem_1.erc2612Abi,
45
+ functionName: "nonces",
46
+ args: [userAddress],
47
+ }),
48
+ (0, actions_1.readContract)(client, {
49
+ address: vaultData.asset,
50
+ abi: viem_1.erc20Abi,
51
+ functionName: "balanceOf",
52
+ args: [blue],
53
+ }),
54
+ (0, actions_1.readContract)(client, {
55
+ address: vault,
56
+ abi: blue_sdk_viem_1.metaMorphoAbi,
57
+ functionName: "MORPHO",
58
+ }),
59
+ // feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
60
+ (0, actions_1.readContract)(client, {
61
+ address: blue,
62
+ abi: blue_sdk_viem_1.blueAbi,
63
+ functionName: "feeRecipient",
64
+ }),
65
+ ]);
66
+ if (!(0, viem_1.isAddressEqual)(morpho, blue)) {
67
+ throw new index_js_2.VaultMorphoMismatchError({
68
+ vault: vault,
69
+ expected: blue,
70
+ actual: morpho,
71
+ });
72
+ }
73
+ // Reject this unsupported configuration before authorizing vault shares:
74
+ // VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
75
+ // vault position, so its callback can exhaust marketParamsList and panic on-chain.
76
+ if ((0, viem_1.isAddressEqual)(blueFeeRecipient, vault)) {
77
+ throw new index_js_2.VaultIsBlueFeeRecipientError(vault, blue);
78
+ }
79
+ if (blueBalance < amount) {
80
+ throw new index_js_2.InsufficientBlueBalanceForInKindRedeemError({
81
+ asset: vaultData.asset,
82
+ available: blueBalance,
83
+ required: amount,
84
+ });
85
+ }
86
+ if (allowance >= requiredShareAllowance) {
87
+ return [];
88
+ }
89
+ if (supportSignature) {
90
+ return [
91
+ (0, index_js_1.encodeVaultSharesPermit)({
92
+ now: params.now,
93
+ vault: vaultData,
94
+ version: "vaultV1",
95
+ spender: vaultExitBundlesV1,
96
+ owner: userAddress,
97
+ chainId: chainId,
98
+ nonce,
99
+ deadline,
100
+ }),
101
+ ];
102
+ }
103
+ return [
104
+ (0, index_js_1.encodeErc20Approval)({
105
+ token: vault,
106
+ spender: vaultExitBundlesV1,
107
+ amount: viem_1.maxUint256,
108
+ chainId: chainId,
109
+ }),
110
+ ];
111
+ }
@@ -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,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVaultV2ForceWithdrawRequirements = getVaultV2ForceWithdrawRequirements;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const index_js_1 = require("../../actions/index.js");
9
+ const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
10
+ const index_js_2 = require("../../types/index.js");
11
+ const assertContractCode_js_1 = require("./assertContractCode.js");
12
+ /**
13
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
14
+ * @param client - Client serving the requested chain.
15
+ * @param params - Snapshot and fixed quote used for authorization.
16
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
17
+ * @returns Share approvals or permit requirements.
18
+ */
19
+ async function getVaultV2ForceWithdrawRequirements(client, params) {
20
+ const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, } = params;
21
+ const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1");
22
+ const requirementsTimestamp = params.now ?? morpho_ts_1.Time.timestamp();
23
+ if (deadline <= requirementsTimestamp) {
24
+ throw new index_js_2.ExpiredDeadlineError(deadline, requirementsTimestamp);
25
+ }
26
+ await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
27
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
28
+ {
29
+ role: "bundles.vaultExitBundlesV1",
30
+ address: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1"),
31
+ },
32
+ ]);
33
+ // Vault gates are intentionally left to the final transaction: the receive-assets gate may
34
+ // inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
35
+ // external code re-evaluated after each intermediate penalty burn, so neither is
36
+ // execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
37
+ // supplies into Morpho Blue, so no Blue token-balance check is needed.
38
+ const [allowance, nonce] = await Promise.all([
39
+ (0, actions_1.readContract)(client, {
40
+ address: vault,
41
+ abi: viem_1.erc20Abi,
42
+ functionName: "allowance",
43
+ args: [userAddress, vaultExitBundlesV1],
44
+ }),
45
+ (0, actions_1.readContract)(client, {
46
+ address: vault,
47
+ abi: blue_sdk_viem_1.erc2612Abi,
48
+ functionName: "nonces",
49
+ args: [userAddress],
50
+ }),
51
+ ]);
52
+ if (allowance >= requiredShareAllowance) {
53
+ return [];
54
+ }
55
+ if (supportSignature) {
56
+ const requirement = (0, index_js_1.encodeVaultSharesPermit)({
57
+ now: params.now,
58
+ vault: vaultData,
59
+ version: "vaultV2",
60
+ spender: vaultExitBundlesV1,
61
+ owner: userAddress,
62
+ chainId: chainId,
63
+ nonce,
64
+ deadline,
65
+ });
66
+ return [requirement];
67
+ }
68
+ return [
69
+ (0, index_js_1.encodeErc20Approval)({
70
+ token: vault,
71
+ spender: vaultExitBundlesV1,
72
+ amount: viem_1.maxUint256,
73
+ chainId: chainId,
74
+ }),
75
+ ];
76
+ }
@@ -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,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVaultV2InKindRedeemRequirements = getVaultV2InKindRedeemRequirements;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const index_js_1 = require("../../actions/index.js");
9
+ const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
10
+ const index_js_2 = require("../../types/index.js");
11
+ const assertContractCode_js_1 = require("./assertContractCode.js");
12
+ /**
13
+ * @internal Resolves exit preflight reads and share authorization without an entity handle.
14
+ * @param client - Client serving the requested chain.
15
+ * @param params - Snapshot and fixed quote used for authorization.
16
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
17
+ * @returns Share approvals or permit requirements.
18
+ */
19
+ async function getVaultV2InKindRedeemRequirements(client, params) {
20
+ const { vaultData, vault, userAddress, chainId, deadline, requiredShareAllowance, supportSignature, peak, } = params;
21
+ const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1");
22
+ const blue = (0, morpho_ts_1.getChainAddress)(chainId, "blue");
23
+ const requirementsTimestamp = params.now ?? morpho_ts_1.Time.timestamp();
24
+ if (deadline <= requirementsTimestamp) {
25
+ throw new index_js_2.ExpiredDeadlineError(deadline, requirementsTimestamp);
26
+ }
27
+ await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
28
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
29
+ {
30
+ role: "bundles.vaultExitBundlesV1",
31
+ address: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1"),
32
+ },
33
+ { role: "blue", address: (0, morpho_ts_1.getChainAddress)(chainId, "blue") },
34
+ ]);
35
+ // Vault gates are intentionally left to the final transaction. A receive gate may inspect
36
+ // VaultExitBundlesV1's transient `initiator`, which is populated only during the actual
37
+ // periphery call. A send-share gate is arbitrary external code and is evaluated repeatedly
38
+ // after intermediate penalty share burns, so one standalone read is not execution-equivalent
39
+ // either. Simulate the finalized transaction after authorization when gate compatibility
40
+ // must be checked before submission.
41
+ const [allowance, nonce, blueBalance] = await Promise.all([
42
+ (0, actions_1.readContract)(client, {
43
+ address: vault,
44
+ abi: viem_1.erc20Abi,
45
+ functionName: "allowance",
46
+ args: [userAddress, vaultExitBundlesV1],
47
+ }),
48
+ (0, actions_1.readContract)(client, {
49
+ address: vault,
50
+ abi: blue_sdk_viem_1.erc2612Abi,
51
+ functionName: "nonces",
52
+ args: [userAddress],
53
+ }),
54
+ (0, actions_1.readContract)(client, {
55
+ address: vaultData.asset,
56
+ abi: viem_1.erc20Abi,
57
+ functionName: "balanceOf",
58
+ args: [blue],
59
+ }),
60
+ ]);
61
+ if (blueBalance < peak) {
62
+ throw new index_js_2.InsufficientBlueBalanceForInKindRedeemError({
63
+ asset: vaultData.asset,
64
+ available: blueBalance,
65
+ required: peak,
66
+ });
67
+ }
68
+ if (allowance >= requiredShareAllowance) {
69
+ return [];
70
+ }
71
+ if (supportSignature) {
72
+ return [
73
+ (0, index_js_1.encodeVaultSharesPermit)({
74
+ now: params.now,
75
+ vault: vaultData,
76
+ version: "vaultV2",
77
+ spender: vaultExitBundlesV1,
78
+ owner: userAddress,
79
+ chainId: chainId,
80
+ nonce,
81
+ deadline,
82
+ }),
83
+ ];
84
+ }
85
+ return [
86
+ (0, index_js_1.encodeErc20Approval)({
87
+ token: vault,
88
+ spender: vaultExitBundlesV1,
89
+ amount: viem_1.maxUint256,
90
+ chainId: chainId,
91
+ }),
92
+ ];
93
+ }
@@ -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,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeVaultV1InKindRedeemQuote = computeVaultV1InKindRedeemQuote;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const index_js_1 = require("../../helpers/index.js");
7
+ const validate_js_1 = require("../../helpers/validate.js");
8
+ const index_js_2 = require("../../types/index.js");
9
+ /**
10
+ * @internal Computes the fixed exit quote from a snapshot without reads or signing.
11
+ * @param params - Snapshot, caller intent and explicit quote timestamp.
12
+ * @returns Fixed action fields and the minimum share allowance.
13
+ */
14
+ function computeVaultV1InKindRedeemQuote({ amount, marketParamsList, vaultData, deadline: deadlineOverride, now, chainId, }) {
15
+ if (amount <= 0n) {
16
+ throw new index_js_2.NonPositiveInputError("amount", amount);
17
+ }
18
+ if (marketParamsList.length === 0) {
19
+ throw new index_js_2.EmptyMarketParamsListError();
20
+ }
21
+ const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
22
+ loanToken,
23
+ collateralToken,
24
+ oracle,
25
+ irm,
26
+ lltv,
27
+ }));
28
+ const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
29
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
30
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
31
+ (0, validate_js_1.validateDeadline)(deadline);
32
+ if (deadline <= now) {
33
+ throw new index_js_2.ExpiredDeadlineError(deadline, now);
34
+ }
35
+ const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1");
36
+ // Reject unsupported registry configurations before computing coverage.
37
+ (0, morpho_ts_1.getChainAddress)(chainId, "blue");
38
+ let covered = 0n;
39
+ const assignedByMarket = new Map();
40
+ for (const marketParams of marketParamsListSnapshot) {
41
+ if (covered === amount) {
42
+ break;
43
+ }
44
+ const marketId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
45
+ const allocation = vaultData.allocations.get(marketId);
46
+ if (allocation?.config.enabled !== true) {
47
+ continue;
48
+ }
49
+ if (allocation.position.supplyShares === 0n) {
50
+ continue;
51
+ }
52
+ const market = allocation.position.market.accrueInterest(now);
53
+ const available = market.toSupplyAssets(allocation.position.supplyShares);
54
+ const assigned = assignedByMarket.get(marketId) ?? 0n;
55
+ const chunk = blue_sdk_1.MathLib.min(available, amount - covered);
56
+ if (assigned + chunk > available) {
57
+ throw new index_js_2.InKindRedeemCoverageError({
58
+ required: amount,
59
+ covered,
60
+ maxExitAssets: covered,
61
+ });
62
+ }
63
+ assignedByMarket.set(marketId, assigned + chunk);
64
+ covered += chunk;
65
+ }
66
+ if (covered < amount) {
67
+ throw new index_js_2.InKindRedeemCoverageError({
68
+ required: amount,
69
+ covered,
70
+ maxExitAssets: covered,
71
+ });
72
+ }
73
+ const requiredShareAllowance = (0, index_js_1.computeVaultMaxShareAllowance)({
74
+ vaultData,
75
+ deadline: now,
76
+ assets: amount,
77
+ slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
78
+ });
79
+ return {
80
+ deadline,
81
+ marketParamsListSnapshot,
82
+ requiredShareAllowance,
83
+ vaultExitBundlesV1,
84
+ };
85
+ }