@morpho-org/morpho-sdk 10.0.0-next.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +104 -12
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/common.js +4 -2
  5. package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
  6. package/lib/cjs/actions/bundles/common.js +20 -14
  7. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
  8. package/lib/cjs/actions/midnight/cancelOffers.js +2 -1
  9. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
  10. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
  11. package/lib/cjs/actions/midnight/takeBorrow.js +2 -1
  12. package/lib/cjs/actions/midnight/takeLend.js +2 -1
  13. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
  14. package/lib/cjs/actions/midnight/takeWithdraw.js +2 -1
  15. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -11
  17. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  18. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  19. package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
  20. package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
  21. package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
  22. package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
  23. package/lib/cjs/blue/abis.d.ts +1 -1
  24. package/lib/cjs/blue/abis.js +1 -5
  25. package/lib/cjs/blue/entities.d.ts +4 -4
  26. package/lib/cjs/blue/entities.js +1 -3
  27. package/lib/cjs/blue/errors.d.ts +2 -2
  28. package/lib/cjs/blue/errors.js +1 -5
  29. package/lib/cjs/blue/fetch.d.ts +2 -2
  30. package/lib/cjs/blue/fetch.js +1 -3
  31. package/lib/cjs/blue/utils.d.ts +1 -1
  32. package/lib/cjs/blue/utils.js +1 -2
  33. package/lib/cjs/entities/blue/blue.js +8 -4
  34. package/lib/cjs/entities/index.d.ts +4 -4
  35. package/lib/cjs/entities/index.js +1 -3
  36. package/lib/cjs/entities/midnight/deadline.js +2 -1
  37. package/lib/cjs/entities/midnight/midnight.js +14 -7
  38. package/lib/cjs/entities/midnight/publication.js +73 -44
  39. package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
  40. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +9 -13
  41. package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
  42. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
  43. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
  44. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  45. package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
  46. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  47. package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
  48. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  49. package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
  50. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  51. package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
  52. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  53. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +51 -181
  55. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  56. package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
  57. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  58. package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
  59. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +8 -34
  60. package/lib/cjs/entities/vaultV2/vaultV2.js +62 -429
  61. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
  62. package/lib/cjs/entities/vaultV2BlueReallocationData.js +346 -234
  63. package/lib/cjs/errors.d.ts +4 -4
  64. package/lib/cjs/errors.js +6 -7
  65. package/lib/cjs/fetch.d.ts +2 -2
  66. package/lib/cjs/fetch.js +1 -3
  67. package/lib/cjs/helpers/deadShares.js +34 -19
  68. package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
  69. package/lib/cjs/helpers/metadata.js +12 -6
  70. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -5
  71. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +6 -3
  72. package/lib/cjs/helpers/utilization.js +10 -5
  73. package/lib/cjs/helpers/validate.js +12 -6
  74. package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
  75. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
  76. package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
  77. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +44 -22
  78. package/lib/cjs/helpers/validatePositiveInput.js +2 -1
  79. package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +14 -7
  81. package/lib/cjs/index.d.ts +2 -2
  82. package/lib/cjs/index.js +10 -1
  83. package/lib/cjs/midnight/errors.d.ts +1 -2
  84. package/lib/cjs/midnight/errors.js +4 -5
  85. package/lib/cjs/transactionPlan/approval.js +12 -1
  86. package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
  87. package/lib/cjs/transactionPlan/deposit.js +139 -0
  88. package/lib/cjs/transactionPlan/error.d.ts +10 -8
  89. package/lib/cjs/transactionPlan/error.js +10 -8
  90. package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
  91. package/lib/cjs/transactionPlan/index.d.ts +18 -0
  92. package/lib/cjs/transactionPlan/index.js +23 -5
  93. package/lib/cjs/transactionPlan/intent.d.ts +3 -3
  94. package/lib/cjs/transactionPlan/intent.js +14 -7
  95. package/lib/cjs/transactionPlan/permit.d.ts +1 -1
  96. package/lib/cjs/transactionPlan/permit.js +86 -20
  97. package/lib/cjs/transactionPlan/plan.d.ts +16 -6
  98. package/lib/cjs/transactionPlan/plan.js +72 -22
  99. package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
  100. package/lib/cjs/transactionPlan/redeem.js +63 -0
  101. package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
  102. package/lib/cjs/transactionPlan/requirements.js +12 -6
  103. package/lib/cjs/transactionPlan/serde.d.ts +2 -2
  104. package/lib/cjs/transactionPlan/serde.js +41 -15
  105. package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
  106. package/lib/cjs/transactionPlan/shareSpending.js +50 -0
  107. package/lib/cjs/transactionPlan/types.d.ts +117 -11
  108. package/lib/cjs/transactionPlan/validateActions.js +11 -1
  109. package/lib/cjs/transactionPlan/validation.js +6 -3
  110. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
  111. package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
  112. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  113. package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
  114. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  115. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
  116. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
  117. package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
  118. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  119. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
  120. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +14 -31
  121. package/lib/cjs/transactionPlan/vaultv2/deposit.js +15 -141
  122. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  123. package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
  124. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  125. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
  126. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  127. package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
  128. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
  129. package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
  130. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +14 -27
  131. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +17 -124
  132. package/lib/cjs/transactionPlan/version.js +2 -1
  133. package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
  134. package/lib/cjs/transactionPlan/withdraw.js +94 -0
  135. package/lib/cjs/types/action.js +16 -8
  136. package/lib/cjs/types/error.d.ts +8 -1
  137. package/lib/cjs/types/error.js +10 -1
  138. package/lib/cjs/utils.d.ts +2 -2
  139. package/lib/cjs/utils.js +2 -4
  140. package/lib/cjs/version.d.ts +1 -1
  141. package/lib/cjs/version.js +1 -1
  142. package/lib/esm/abis.d.ts +1 -1
  143. package/lib/esm/abis.js +1 -1
  144. package/lib/esm/actions/blue/common.js +4 -2
  145. package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
  146. package/lib/esm/actions/bundles/common.js +20 -14
  147. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -1
  148. package/lib/esm/actions/midnight/cancelOffers.js +2 -1
  149. package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
  150. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
  151. package/lib/esm/actions/midnight/takeBorrow.js +2 -1
  152. package/lib/esm/actions/midnight/takeLend.js +2 -1
  153. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
  154. package/lib/esm/actions/midnight/takeWithdraw.js +2 -1
  155. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +4 -13
  157. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
  158. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
  159. package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
  160. package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
  161. package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
  162. package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
  163. package/lib/esm/blue/abis.d.ts +1 -1
  164. package/lib/esm/blue/abis.js +1 -1
  165. package/lib/esm/blue/entities.d.ts +4 -4
  166. package/lib/esm/blue/entities.js +2 -2
  167. package/lib/esm/blue/errors.d.ts +2 -2
  168. package/lib/esm/blue/errors.js +2 -2
  169. package/lib/esm/blue/fetch.d.ts +2 -2
  170. package/lib/esm/blue/fetch.js +2 -2
  171. package/lib/esm/blue/utils.d.ts +1 -1
  172. package/lib/esm/blue/utils.js +1 -1
  173. package/lib/esm/entities/blue/blue.js +8 -4
  174. package/lib/esm/entities/index.d.ts +4 -4
  175. package/lib/esm/entities/index.js +2 -2
  176. package/lib/esm/entities/midnight/deadline.js +2 -1
  177. package/lib/esm/entities/midnight/midnight.js +14 -7
  178. package/lib/esm/entities/midnight/publication.js +73 -44
  179. package/lib/esm/entities/requirements/assertContractCode.js +4 -2
  180. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +10 -14
  181. package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
  183. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
  184. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
  185. package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
  186. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
  187. package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
  188. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
  189. package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
  190. package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
  191. package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
  192. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
  193. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
  194. package/lib/esm/entities/vaultV1/vaultV1.js +57 -187
  195. package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
  196. package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
  197. package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
  198. package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
  199. package/lib/esm/entities/vaultV2/vaultV2.d.ts +8 -34
  200. package/lib/esm/entities/vaultV2/vaultV2.js +70 -437
  201. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
  202. package/lib/esm/entities/vaultV2BlueReallocationData.js +346 -234
  203. package/lib/esm/errors.d.ts +4 -4
  204. package/lib/esm/errors.js +4 -4
  205. package/lib/esm/fetch.d.ts +2 -2
  206. package/lib/esm/fetch.js +2 -2
  207. package/lib/esm/helpers/deadShares.js +35 -20
  208. package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
  209. package/lib/esm/helpers/metadata.js +12 -6
  210. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -5
  211. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +6 -3
  212. package/lib/esm/helpers/utilization.js +10 -5
  213. package/lib/esm/helpers/validate.js +12 -6
  214. package/lib/esm/helpers/validateMidnightBounds.js +2 -1
  215. package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
  216. package/lib/esm/helpers/validateMidnightPublication.js +4 -2
  217. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +44 -22
  218. package/lib/esm/helpers/validatePositiveInput.js +2 -1
  219. package/lib/esm/helpers/validateTakeableOffers.js +2 -1
  220. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +14 -7
  221. package/lib/esm/index.d.ts +2 -2
  222. package/lib/esm/index.js +1 -1
  223. package/lib/esm/midnight/errors.d.ts +1 -2
  224. package/lib/esm/midnight/errors.js +1 -2
  225. package/lib/esm/transactionPlan/approval.js +13 -2
  226. package/lib/esm/transactionPlan/deposit.d.ts +22 -0
  227. package/lib/esm/transactionPlan/deposit.js +135 -0
  228. package/lib/esm/transactionPlan/error.d.ts +10 -8
  229. package/lib/esm/transactionPlan/error.js +10 -8
  230. package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
  231. package/lib/esm/transactionPlan/index.d.ts +18 -0
  232. package/lib/esm/transactionPlan/index.js +9 -0
  233. package/lib/esm/transactionPlan/intent.d.ts +3 -3
  234. package/lib/esm/transactionPlan/intent.js +14 -7
  235. package/lib/esm/transactionPlan/permit.d.ts +1 -1
  236. package/lib/esm/transactionPlan/permit.js +86 -20
  237. package/lib/esm/transactionPlan/plan.d.ts +16 -6
  238. package/lib/esm/transactionPlan/plan.js +68 -18
  239. package/lib/esm/transactionPlan/redeem.d.ts +18 -0
  240. package/lib/esm/transactionPlan/redeem.js +59 -0
  241. package/lib/esm/transactionPlan/requirements.d.ts +4 -3
  242. package/lib/esm/transactionPlan/requirements.js +12 -6
  243. package/lib/esm/transactionPlan/serde.d.ts +2 -2
  244. package/lib/esm/transactionPlan/serde.js +41 -15
  245. package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
  246. package/lib/esm/transactionPlan/shareSpending.js +47 -0
  247. package/lib/esm/transactionPlan/types.d.ts +117 -11
  248. package/lib/esm/transactionPlan/validateActions.js +11 -1
  249. package/lib/esm/transactionPlan/validation.js +6 -3
  250. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
  251. package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
  252. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
  253. package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
  254. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
  255. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
  256. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
  257. package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
  258. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
  259. package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
  260. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +14 -31
  261. package/lib/esm/transactionPlan/vaultv2/deposit.js +17 -142
  262. package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
  263. package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
  264. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
  265. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
  266. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
  267. package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
  268. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
  269. package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
  270. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +14 -27
  271. package/lib/esm/transactionPlan/vaultv2/withdraw.js +19 -125
  272. package/lib/esm/transactionPlan/version.js +2 -1
  273. package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
  274. package/lib/esm/transactionPlan/withdraw.js +90 -0
  275. package/lib/esm/types/action.js +16 -8
  276. package/lib/esm/types/error.d.ts +8 -1
  277. package/lib/esm/types/error.js +10 -1
  278. package/lib/esm/utils.d.ts +2 -2
  279. package/lib/esm/utils.js +2 -2
  280. package/lib/esm/version.d.ts +1 -1
  281. package/lib/esm/version.js +1 -1
  282. package/package.json +15 -15
@@ -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;
@@ -16,6 +16,8 @@ import { type ERC20ApprovalAction, type PermitRequirementSignature, type Referen
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: {
@@ -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.
@@ -24,10 +25,14 @@ const index_js_3 = require("../../types/index.js");
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
+ }
@@ -0,0 +1,20 @@
1
+ import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
+ import type { VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
3
+ /**
4
+ * @internal Quotes a migration from validated snapshots and intent without reading chain state.
5
+ * The source accrues interest and performance fees before a shares-mode conversion; the target
6
+ * price bound uses assets net of the referral fee. Neither snapshot is mutated.
7
+ * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
8
+ * @returns The destination maximum share price and minimum source share allowance.
9
+ */
10
+ export declare function computeVaultV1MigrateToV2Quote(params: VaultV1MigrateToV2AmountArgs & {
11
+ readonly sourceVault: AccrualVault;
12
+ readonly targetVault: AccrualVaultV2;
13
+ readonly referralFeePct: bigint;
14
+ readonly slippageTolerance: bigint;
15
+ readonly deadline: bigint;
16
+ readonly now: bigint;
17
+ }): {
18
+ readonly maxSharePriceVaultV2: bigint;
19
+ readonly requiredShareAllowance: bigint;
20
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeVaultV1MigrateToV2Quote = computeVaultV1MigrateToV2Quote;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const common_js_1 = require("../../actions/bundles/common.js");
6
+ const slippage_js_1 = require("../../helpers/slippage.js");
7
+ /**
8
+ * @internal Quotes a migration from validated snapshots and intent without reading chain state.
9
+ * The source accrues interest and performance fees before a shares-mode conversion; the target
10
+ * price bound uses assets net of the referral fee. Neither snapshot is mutated.
11
+ * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
12
+ * @returns The destination maximum share price and minimum source share allowance.
13
+ */
14
+ function computeVaultV1MigrateToV2Quote(params) {
15
+ const { sourceVault, targetVault, assets, shares, referralFeePct, slippageTolerance, deadline, now, } = params;
16
+ const grossAssets = assets ??
17
+ sourceVault
18
+ .accrueInterest(sourceVault.allocations
19
+ .values()
20
+ .reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), now))
21
+ .toAssets(shares ?? 0n, "Down");
22
+ const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, referralFeePct);
23
+ const maxSharePriceVaultV2 = (0, slippage_js_1.computeVaultMaxSharePrice)({
24
+ vaultData: targetVault,
25
+ deadline,
26
+ assets: grossAssets - referralFeeAssets,
27
+ slippageTolerance,
28
+ });
29
+ const requiredShareAllowance = shares ??
30
+ (0, slippage_js_1.computeVaultMaxShareAllowance)({
31
+ vaultData: sourceVault,
32
+ deadline,
33
+ assets: assets ?? 0n,
34
+ slippageTolerance,
35
+ });
36
+ return { maxSharePriceVaultV2, requiredShareAllowance };
37
+ }