@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.3

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 (305) hide show
  1. package/MIGRATION-v5-to-v6.md +199 -34
  2. package/README.md +23 -15
  3. package/lib/cjs/abis.d.ts +3 -2829
  4. package/lib/cjs/abis.js +1 -1938
  5. package/lib/cjs/actions/blue/borrow.d.ts +3 -2
  6. package/lib/cjs/actions/blue/borrow.js +3 -2
  7. package/lib/cjs/actions/blue/common.js +6 -35
  8. package/lib/cjs/actions/blue/refinance.d.ts +2 -2
  9. package/lib/cjs/actions/blue/refinance.js +2 -2
  10. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  11. package/lib/cjs/actions/blue/repay.js +1 -1
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  14. package/lib/cjs/actions/blue/supply.d.ts +2 -2
  15. package/lib/cjs/actions/blue/supply.js +4 -9
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
  17. package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
  20. package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
  21. package/lib/cjs/actions/blue/withdraw.js +3 -3
  22. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
  23. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  24. package/lib/cjs/actions/bundles/common.d.ts +38 -4
  25. package/lib/cjs/actions/bundles/common.js +91 -35
  26. package/lib/cjs/actions/index.d.ts +0 -1
  27. package/lib/cjs/actions/index.js +0 -1
  28. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
  30. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  31. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  32. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  33. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  40. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  41. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  42. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  43. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  44. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  45. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  46. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  47. package/lib/cjs/actions/requirements/index.js +0 -1
  48. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  49. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  50. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
  51. package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
  52. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  53. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  54. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  55. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  56. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
  57. package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
  58. package/lib/cjs/augment.d.ts +0 -1
  59. package/lib/cjs/augment.js +0 -1
  60. package/lib/cjs/blue/abis.d.ts +1 -1
  61. package/lib/cjs/blue/abis.js +1 -5
  62. package/lib/cjs/blue/entities.d.ts +2 -2
  63. package/lib/cjs/blue/entities.js +1 -2
  64. package/lib/cjs/blue/errors.d.ts +1 -1
  65. package/lib/cjs/blue/errors.js +2 -1
  66. package/lib/cjs/blue/fetch.d.ts +1 -1
  67. package/lib/cjs/blue/fetch.js +1 -2
  68. package/lib/cjs/blue/types.d.ts +2 -4
  69. package/lib/cjs/blue/utils.d.ts +1 -3
  70. package/lib/cjs/blue/utils.js +1 -3
  71. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  72. package/lib/cjs/client/morphoViemExtension.js +1 -1
  73. package/lib/cjs/constants.d.ts +3 -37
  74. package/lib/cjs/constants.js +1 -39
  75. package/lib/cjs/entities/blue/blue.d.ts +38 -264
  76. package/lib/cjs/entities/blue/blue.js +2 -203
  77. package/lib/cjs/entities/index.d.ts +3 -60
  78. package/lib/cjs/entities/index.js +1 -20
  79. package/lib/cjs/entities/midnight/midnight.js +20 -24
  80. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  81. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  82. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  83. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  84. package/lib/cjs/entities/requirements/index.js +1 -0
  85. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
  86. package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
  87. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
  88. package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
  89. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  90. package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
  91. package/lib/cjs/errors.d.ts +2 -46
  92. package/lib/cjs/errors.js +2 -46
  93. package/lib/cjs/fetch.d.ts +1 -15
  94. package/lib/cjs/fetch.js +1 -16
  95. package/lib/cjs/helpers/constant.d.ts +0 -2
  96. package/lib/cjs/helpers/constant.js +0 -2
  97. package/lib/cjs/helpers/index.d.ts +4 -3
  98. package/lib/cjs/helpers/index.js +10 -9
  99. package/lib/cjs/helpers/metadata.d.ts +3 -5
  100. package/lib/cjs/helpers/metadata.js +4 -6
  101. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  102. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  103. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  104. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  105. package/lib/cjs/helpers/slippage.d.ts +34 -90
  106. package/lib/cjs/helpers/slippage.js +52 -137
  107. package/lib/cjs/helpers/utilization.d.ts +12 -10
  108. package/lib/cjs/helpers/utilization.js +27 -12
  109. package/lib/cjs/helpers/validate.d.ts +66 -32
  110. package/lib/cjs/helpers/validate.js +84 -57
  111. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  112. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  113. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  114. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  115. package/lib/cjs/types/action.d.ts +102 -68
  116. package/lib/cjs/types/action.js +11 -4
  117. package/lib/cjs/types/error.d.ts +332 -385
  118. package/lib/cjs/types/error.js +369 -412
  119. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  120. package/lib/cjs/types.d.ts +2 -18
  121. package/lib/cjs/utils.d.ts +8 -35
  122. package/lib/cjs/utils.js +11 -36
  123. package/lib/esm/abis.d.ts +3 -2829
  124. package/lib/esm/abis.js +3 -1935
  125. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/borrow.js +3 -2
  127. package/lib/esm/actions/blue/common.js +8 -37
  128. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  129. package/lib/esm/actions/blue/refinance.js +2 -2
  130. package/lib/esm/actions/blue/repay.d.ts +1 -1
  131. package/lib/esm/actions/blue/repay.js +1 -1
  132. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  133. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  134. package/lib/esm/actions/blue/supply.d.ts +2 -2
  135. package/lib/esm/actions/blue/supply.js +6 -11
  136. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  137. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  138. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  139. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  140. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  141. package/lib/esm/actions/blue/withdraw.js +3 -3
  142. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  143. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  144. package/lib/esm/actions/bundles/common.d.ts +38 -4
  145. package/lib/esm/actions/bundles/common.js +91 -36
  146. package/lib/esm/actions/index.d.ts +0 -1
  147. package/lib/esm/actions/index.js +0 -1
  148. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  149. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
  150. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  151. package/lib/esm/actions/requirements/blue/index.js +0 -1
  152. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  153. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
  154. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  155. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  157. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
  158. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  159. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  160. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  161. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  162. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  163. package/lib/esm/actions/requirements/encode/index.js +0 -1
  164. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  165. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  166. package/lib/esm/actions/requirements/index.d.ts +0 -1
  167. package/lib/esm/actions/requirements/index.js +0 -1
  168. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  169. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  170. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
  171. package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
  172. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  173. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  174. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  175. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  176. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
  177. package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
  178. package/lib/esm/augment.d.ts +0 -1
  179. package/lib/esm/augment.js +0 -1
  180. package/lib/esm/blue/abis.d.ts +1 -1
  181. package/lib/esm/blue/abis.js +1 -1
  182. package/lib/esm/blue/entities.d.ts +2 -2
  183. package/lib/esm/blue/entities.js +1 -1
  184. package/lib/esm/blue/errors.d.ts +1 -1
  185. package/lib/esm/blue/errors.js +1 -1
  186. package/lib/esm/blue/fetch.d.ts +1 -1
  187. package/lib/esm/blue/fetch.js +1 -1
  188. package/lib/esm/blue/types.d.ts +2 -4
  189. package/lib/esm/blue/utils.d.ts +1 -3
  190. package/lib/esm/blue/utils.js +1 -3
  191. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  192. package/lib/esm/client/morphoViemExtension.js +1 -1
  193. package/lib/esm/constants.d.ts +3 -37
  194. package/lib/esm/constants.js +3 -37
  195. package/lib/esm/entities/blue/blue.d.ts +38 -264
  196. package/lib/esm/entities/blue/blue.js +5 -206
  197. package/lib/esm/entities/index.d.ts +3 -60
  198. package/lib/esm/entities/index.js +1 -16
  199. package/lib/esm/entities/midnight/midnight.js +20 -24
  200. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  202. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  203. package/lib/esm/entities/requirements/index.d.ts +1 -0
  204. package/lib/esm/entities/requirements/index.js +1 -0
  205. package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
  206. package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
  207. package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
  208. package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
  209. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  210. package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
  211. package/lib/esm/errors.d.ts +2 -46
  212. package/lib/esm/errors.js +2 -46
  213. package/lib/esm/fetch.d.ts +1 -15
  214. package/lib/esm/fetch.js +1 -15
  215. package/lib/esm/helpers/constant.d.ts +0 -2
  216. package/lib/esm/helpers/constant.js +0 -2
  217. package/lib/esm/helpers/index.d.ts +4 -3
  218. package/lib/esm/helpers/index.js +4 -3
  219. package/lib/esm/helpers/metadata.d.ts +3 -5
  220. package/lib/esm/helpers/metadata.js +4 -6
  221. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  222. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  223. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  224. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  225. package/lib/esm/helpers/slippage.d.ts +34 -90
  226. package/lib/esm/helpers/slippage.js +52 -134
  227. package/lib/esm/helpers/utilization.d.ts +12 -10
  228. package/lib/esm/helpers/utilization.js +26 -11
  229. package/lib/esm/helpers/validate.d.ts +66 -32
  230. package/lib/esm/helpers/validate.js +83 -57
  231. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  232. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  233. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  234. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  235. package/lib/esm/types/action.d.ts +102 -68
  236. package/lib/esm/types/action.js +12 -5
  237. package/lib/esm/types/error.d.ts +332 -385
  238. package/lib/esm/types/error.js +355 -392
  239. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  240. package/lib/esm/types.d.ts +2 -18
  241. package/lib/esm/utils.d.ts +8 -35
  242. package/lib/esm/utils.js +7 -34
  243. package/package.json +7 -15
  244. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  245. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
  246. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  247. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
  248. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  249. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
  250. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  251. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  252. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  253. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  254. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  255. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  256. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  257. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  258. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  259. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
  260. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  261. package/lib/cjs/actions/signatures/index.js +0 -19
  262. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  263. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  264. package/lib/cjs/bundler/actions.d.ts +0 -797
  265. package/lib/cjs/bundler/actions.js +0 -1371
  266. package/lib/cjs/bundler/index.d.ts +0 -2
  267. package/lib/cjs/bundler/index.js +0 -18
  268. package/lib/cjs/bundler/types.d.ts +0 -235
  269. package/lib/cjs/bundler/types.js +0 -2
  270. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
  271. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
  272. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
  273. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
  274. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  275. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
  276. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  277. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
  278. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  279. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
  280. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  281. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  282. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  283. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  284. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  285. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  286. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  287. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  288. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  289. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
  290. package/lib/esm/actions/signatures/index.d.ts +0 -3
  291. package/lib/esm/actions/signatures/index.js +0 -3
  292. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  293. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
  294. package/lib/esm/bundler/actions.d.ts +0 -797
  295. package/lib/esm/bundler/actions.js +0 -1368
  296. package/lib/esm/bundler/index.d.ts +0 -2
  297. package/lib/esm/bundler/index.js +0 -2
  298. package/lib/esm/bundler/types.d.ts +0 -235
  299. package/lib/esm/bundler/types.js +0 -1
  300. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
  301. package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
  302. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
  303. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
  304. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  305. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -0,0 +1,369 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveVaultV2ForceWithdrawEligibility = resolveVaultV2ForceWithdrawEligibility;
4
+ exports.computeVaultV2ForceWithdrawFeeSharesMinted = computeVaultV2ForceWithdrawFeeSharesMinted;
5
+ exports.computeVaultV2ForceWithdrawPlan = computeVaultV2ForceWithdrawPlan;
6
+ exports.computeVaultV2ForceWithdrawSharesBurnt = computeVaultV2ForceWithdrawSharesBurnt;
7
+ exports.computeVaultV2ForceWithdrawMinSharesBurnt = computeVaultV2ForceWithdrawMinSharesBurnt;
8
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
9
+ const viem_1 = require("viem");
10
+ const index_js_1 = require("../types/index.js");
11
+ /**
12
+ * Resolves whether a Vault V2 snapshot can be force-withdrawn through VaultExitBundlesV1.
13
+ *
14
+ * Mirrors the contract's four preconditions: `adaptersLength() == 1`, `isAdapter(adapter)`,
15
+ * `adapter.morpho() == BLUE` (implied by the adapter type, whose factory pins Blue), and a
16
+ * `liquidityAdapter` the contract can cast to `IMorphoMarketV1AdapterV2` and whose `liquidityData`
17
+ * decodes as `MarketParams`. Because the exit already requires a single adapter, the only
18
+ * resolvable liquidity configurations are unset or that same adapter.
19
+ *
20
+ * Pure: reads only the supplied snapshot and never throws.
21
+ *
22
+ * @param vaultData - Pre-fetched Vault V2 accrual snapshot.
23
+ * @param adapterOverride - Optional adapter the caller expects; defaults to the vault's sole adapter.
24
+ * @returns The `"eligible"` variant with the resolved adapter and liquidity market, or the tag
25
+ * describing which precondition failed.
26
+ * @example
27
+ * ```ts
28
+ * import { resolveVaultV2ForceWithdrawEligibility } from "@morpho-org/morpho-sdk";
29
+ *
30
+ * const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
31
+ * if (eligibility.type === "eligible") {
32
+ * console.log(eligibility.adapter.address, eligibility.liquidityMarketId);
33
+ * }
34
+ * ```
35
+ */
36
+ function resolveVaultV2ForceWithdrawEligibility(vaultData, adapterOverride) {
37
+ const [soleAdapter] = vaultData.accrualAdapters;
38
+ if (vaultData.accrualAdapters.length !== 1 || soleAdapter == null) {
39
+ return { type: "adapterCount", adapters: vaultData.accrualAdapters.length };
40
+ }
41
+ const adapter = adapterOverride ?? soleAdapter.address;
42
+ if (!(0, viem_1.isAddressEqual)(adapter, soleAdapter.address)) {
43
+ return { type: "adapterMismatch", adapter };
44
+ }
45
+ if (!(soleAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2)) {
46
+ return { type: "unsupportedAdapter", adapter };
47
+ }
48
+ const { liquidityAdapter } = vaultData;
49
+ if ((0, viem_1.isAddressEqual)(liquidityAdapter, viem_1.zeroAddress)) {
50
+ return {
51
+ type: "eligible",
52
+ adapter: soleAdapter,
53
+ liquidityMarketId: undefined,
54
+ };
55
+ }
56
+ if (!(0, viem_1.isAddressEqual)(liquidityAdapter, soleAdapter.address)) {
57
+ return { type: "unsupportedLiquidityAdapter", liquidityAdapter, adapter };
58
+ }
59
+ let liquidityMarketId;
60
+ try {
61
+ liquidityMarketId = blue_sdk_1.MarketParams.fromHex(vaultData.liquidityData).id;
62
+ }
63
+ catch (cause) {
64
+ // Undecodable `liquidityData` reverts the contract's `abi.decode`. Reported separately from a
65
+ // foreign adapter: the adapter here is the right one, only its stored market params are unusable.
66
+ return {
67
+ type: "undecodableLiquidityData",
68
+ liquidityAdapter,
69
+ liquidityData: vaultData.liquidityData,
70
+ cause,
71
+ };
72
+ }
73
+ return { type: "eligible", adapter: soleAdapter, liquidityMarketId };
74
+ }
75
+ /**
76
+ * Computes the Vault V2 shares that accruing a vault snapshot mints to its owner as management
77
+ * and/or performance fees.
78
+ *
79
+ * Fee shares are minted to the matching recipient during the first withdrawal after accrual.
80
+ * When the owner is both recipients, both fee-share amounts are included. Timestamps before the
81
+ * snapshot's last update are clamped because Vault V2 cannot accrue backwards.
82
+ *
83
+ * @param params - Vault fee-share accrual inputs.
84
+ * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
85
+ * @param params.owner - Account whose fee-recipient share mints are measured.
86
+ * @param params.timestamp - Target accrual timestamp, clamped to `vaultData.lastUpdate`.
87
+ * @returns Shares minted to `owner` by the management and/or performance fees, or `0n` when the
88
+ * owner is not a fee recipient.
89
+ * @example
90
+ * ```ts
91
+ * import { computeVaultV2ForceWithdrawFeeSharesMinted } from "@morpho-org/morpho-sdk";
92
+ *
93
+ * const feeShares = computeVaultV2ForceWithdrawFeeSharesMinted({
94
+ * vaultData,
95
+ * owner,
96
+ * timestamp,
97
+ * });
98
+ * ```
99
+ */
100
+ function computeVaultV2ForceWithdrawFeeSharesMinted(params) {
101
+ const { vault: accruedVault, managementFeeShares, performanceFeeShares, } = params.vaultData.accrueInterest(blue_sdk_1.MathLib.max(params.timestamp, params.vaultData.lastUpdate));
102
+ return (((0, viem_1.isAddressEqual)(accruedVault.managementFeeRecipient, params.owner)
103
+ ? managementFeeShares
104
+ : 0n) +
105
+ ((0, viem_1.isAddressEqual)(accruedVault.performanceFeeRecipient, params.owner)
106
+ ? performanceFeeShares
107
+ : 0n));
108
+ }
109
+ /**
110
+ * Computes every Vault V2 force-withdraw amount from a vault snapshot, without any RPC.
111
+ *
112
+ * Reproduces `vaultExitBundlesV1ForceWithdrawVaultV2` arithmetic:
113
+ *
114
+ * ```solidity
115
+ * withdrawableAssets = idle + min(liquidityAdapterAssets, liquidityMarketLiquidity);
116
+ * assetsToWithdraw = min(exitAssets, withdrawableAssets);
117
+ * assetsToDeallocate = mulDivDown(exitAssets - assetsToWithdraw, WAD, WAD + penalty);
118
+ * ```
119
+ *
120
+ * `coveredAssets` sums `min(adapterPosition, marketLiquidity)` over the adapter's markets, minus
121
+ * whatever the penalty-free leg already drained from the liquidity market. The sum is deliberately
122
+ * order-independent: the contract's loop visits every market taking `min(available, remaining)`, so
123
+ * total capacity does not depend on the adapter's storage order — which matters because a drained
124
+ * market is removed from that list mid-loop.
125
+ *
126
+ * That order-independence assumes `VaultExitBundlesV1` copies `adapter.marketIds` into memory
127
+ * *before* the loop. If it instead re-read adapter storage each iteration,
128
+ * `MorphoMarketV1AdapterV2.deallocate`'s swap-and-pop removal of a drained market would make the
129
+ * loop skip markets, and this sum would overstate real capacity — letting an exit through that
130
+ * panics on-chain. The claim is load-bearing for the coverage guard and is verified only by the
131
+ * fork suite, not by any in-repo contract source.
132
+ *
133
+ * @param params - Plan inputs.
134
+ * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
135
+ * @param params.adapter - The vault's sole MorphoMarketV1AdapterV2, from
136
+ * {@link resolveVaultV2ForceWithdrawEligibility}.
137
+ * @param params.liquidityMarketId - Market the vault routes penalty-free liquidity through, or
138
+ * `undefined` when the vault has no liquidity adapter.
139
+ * @param params.exitAssets - Penalty-inclusive amount to exit.
140
+ * @param params.timestamp - Timestamp used to accrue every Morpho Blue market before converting
141
+ * adapter shares.
142
+ * @returns The resolved plan. `coveredAssets < assetsToDeallocate` means the exit would overrun the
143
+ * contract's unbounded loop; the caller decides how to report that.
144
+ * @throws {NonPositiveInputError} when `exitAssets` is not positive.
145
+ * @example
146
+ * ```ts
147
+ * import {
148
+ * computeVaultV2ForceWithdrawPlan,
149
+ * resolveVaultV2ForceWithdrawEligibility,
150
+ * } from "@morpho-org/morpho-sdk";
151
+ *
152
+ * const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
153
+ * if (eligibility.type === "eligible") {
154
+ * const plan = computeVaultV2ForceWithdrawPlan({
155
+ * vaultData,
156
+ * adapter: eligibility.adapter,
157
+ * liquidityMarketId: eligibility.liquidityMarketId,
158
+ * exitAssets: 1_000_000n,
159
+ * timestamp: 1_800_000_000n,
160
+ * });
161
+ * // plan.withdrawnAssets is what the user receives before the referral fee
162
+ * }
163
+ * ```
164
+ */
165
+ function computeVaultV2ForceWithdrawPlan(params) {
166
+ const { vaultData, adapter, liquidityMarketId, exitAssets, timestamp } = params;
167
+ // Guard the exported planner: a non-positive `exitAssets` would flow a negative through
168
+ // `min(exitAssets, withdrawable)` and return a plan with negative amounts. The entity and preview
169
+ // reject it upstream; this protects direct importers of the advertised helper.
170
+ if (exitAssets <= 0n)
171
+ throw new index_js_1.NonPositiveInputError("exitAssets", exitAssets);
172
+ const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
173
+ const idleAssets = vaultData.assetBalance;
174
+ // `min(adapterPosition, marketLiquidity)` per market, on interest-accrued market state — the
175
+ // contract reads `expectedMarketBalances`, so the un-accrued `maxWithdraw` helpers on
176
+ // `AccrualVaultV2` would understate capacity.
177
+ const availableByMarket = new Map(adapter.markets.map((market) => {
178
+ const accrued = market.accrueInterest(blue_sdk_1.MathLib.max(timestamp, market.lastUpdate));
179
+ return [
180
+ market.id,
181
+ blue_sdk_1.MathLib.min(accrued.toSupplyAssets(adapter.supplyShares[market.id] ?? 0n), accrued.liquidity),
182
+ ];
183
+ }));
184
+ const liquidityCapacity = liquidityMarketId == null
185
+ ? 0n
186
+ : (availableByMarket.get(liquidityMarketId) ?? 0n);
187
+ const withdrawableAssets = idleAssets + liquidityCapacity;
188
+ const assetsToWithdraw = blue_sdk_1.MathLib.min(exitAssets, withdrawableAssets);
189
+ const assetsToDeallocate = blue_sdk_1.MathLib.mulDivDown(exitAssets - assetsToWithdraw, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD + penalty);
190
+ // The penalty-free leg pulls its shortfall through the liquidity adapter, draining that market
191
+ // before the force-deallocation loop reaches it.
192
+ const drainedFromLiquidityMarket = blue_sdk_1.MathLib.zeroFloorSub(assetsToWithdraw, idleAssets);
193
+ if (liquidityMarketId != null && drainedFromLiquidityMarket > 0n) {
194
+ availableByMarket.set(liquidityMarketId, blue_sdk_1.MathLib.zeroFloorSub(liquidityCapacity, drainedFromLiquidityMarket));
195
+ }
196
+ let coveredAssets = 0n;
197
+ const nonEmpty = [];
198
+ for (const available of availableByMarket.values()) {
199
+ if (available <= 0n)
200
+ continue;
201
+ coveredAssets += available;
202
+ nonEmpty.push(available);
203
+ }
204
+ // `maxExitAssets` must not depend on the requested amount. At the ceiling the penalty-free leg
205
+ // always drains the liquidity market completely, so that market contributes nothing to the
206
+ // force-deallocation loop — whereas a small request leaves part of it, which would overstate the
207
+ // ceiling for callers using it to cap an input.
208
+ let saturatedCoveredAssets = 0n;
209
+ for (const [marketId, available] of availableByMarket) {
210
+ if (marketId === liquidityMarketId)
211
+ continue;
212
+ if (available > 0n)
213
+ saturatedCoveredAssets += available;
214
+ }
215
+ // Worst-case leg count is the ascending walk: the most markets the loop can touch is the number
216
+ // of smallest positions that together reach `assetsToDeallocate`. Deliberately an upper bound, not
217
+ // a replay of the contract's prefetched `marketIds` order (where an earlier market may cover the
218
+ // whole request in one leg): this count feeds the share-burn *upper* bound behind the slippage
219
+ // floor, so it must hold for any execution order. Replaying a snapshot order that then diverges at
220
+ // inclusion (a market added or drained between `getData()` and execution) would under-count legs,
221
+ // over-state the floor, and false-revert a valid distressed exit — a worse failure than the
222
+ // bounded looseness (≤ `penaltyLegs - 1` asset-units, absorbed by `slippageTolerance`) the
223
+ // ascending walk leaves. Tightening it to the exact walk is a separate change needing fork
224
+ // coverage of the snapshot-vs-execution divergence.
225
+ let penaltyLegs = 0;
226
+ let remaining = assetsToDeallocate;
227
+ for (const available of nonEmpty.toSorted((a, b) => a === b ? 0 : a > b ? 1 : -1)) {
228
+ if (remaining <= 0n)
229
+ break;
230
+ penaltyLegs += 1;
231
+ remaining -= blue_sdk_1.MathLib.min(available, remaining);
232
+ }
233
+ return {
234
+ penalty,
235
+ exitAssets,
236
+ assetsToWithdraw,
237
+ assetsToDeallocate,
238
+ // `sum(ceil(assetsᵢ·penalty/WAD)) <= ceil(sum(assetsᵢ)·penalty/WAD) + legs - 1`. The per-leg
239
+ // slack only exists because each chunk rounds its own charge up; at a zero penalty every chunk
240
+ // charges exactly nothing, so carrying the slack would invent penalty assets the contract never
241
+ // debits — inflating the share-burn denominator and weakening the derived bound.
242
+ penaltyAssets: penaltyLegs === 0 || penalty === 0n
243
+ ? 0n
244
+ : blue_sdk_1.MathLib.wMulUp(assetsToDeallocate, penalty) + BigInt(penaltyLegs - 1),
245
+ withdrawnAssets: assetsToWithdraw + assetsToDeallocate,
246
+ coveredAssets,
247
+ // Both bounds keep the ceiling *actionable*, since callers cap an input field with it and the
248
+ // coverage error tells them to reduce to it. A vault with nothing to give reports zero: the
249
+ // inversion rounds up to `1n` at a positive penalty, and `1n` withdraws nothing, which the
250
+ // entity rejects. And the gross-up can exceed the ABI slot on an enormous snapshot, which the
251
+ // entity also rejects — so it saturates rather than advertising an unusable amount.
252
+ maxExitAssets: withdrawableAssets === 0n && saturatedCoveredAssets === 0n
253
+ ? 0n
254
+ : blue_sdk_1.MathLib.min(withdrawableAssets +
255
+ blue_sdk_1.MathLib.wMulUp(saturatedCoveredAssets + 1n, blue_sdk_1.MathLib.WAD + penalty) -
256
+ 1n, viem_1.maxUint256),
257
+ penaltyLegs,
258
+ };
259
+ }
260
+ /**
261
+ * Upper-bounds the vault shares a Vault V2 force withdrawal burns.
262
+ *
263
+ * The contract splits the burn across up to `penaltyLegs + 2` separate `VaultV2.withdraw` calls (the
264
+ * penalty-free leg, one per `forceDeallocate`, and the final deallocated leg), each rounding its own
265
+ * share burn up. Converting the aggregate already spends one ceiling, so the bound adds one share
266
+ * per *additional* leg that moves a positive amount — a zero-amount leg burns `toShares(0, "Up")`
267
+ * and rounds nothing.
268
+ *
269
+ * The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
270
+ * burn the realized exit price is measured against. It takes the max over the two supplied snapshots
271
+ * because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
272
+ * execution. The entity passes both accrued to `now` (execution time): the raw `lastUpdate` snapshot
273
+ * underestimates the burn a stale fee-bearing vault realizes — the first withdrawal accrues pending
274
+ * management fees before burning shares — which lifts the floor above the faithful price and trips
275
+ * `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`, tracks execution without
276
+ * letting a long deadline silently weaken the guard; `slippageTolerance` absorbs the residual drift
277
+ * until inclusion. Pass distinct snapshots to bound the burn across an accrual window.
278
+ *
279
+ * This is **not** the share allowance to authorize. The price floor's denominator is this bound
280
+ * minus `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`: the
281
+ * contract measures the *net* burn, which fee mints to `owner` shrink. The allowance is
282
+ * `min(mulDivUp(exitAssets, RAY, minSharePriceE27) + computeVaultV2ForceWithdrawFeeSharesMinted({
283
+ * vaultData, owner, timestamp: deadline }), maxUint256)`: the permit pays for the *gross* burn.
284
+ *
285
+ * @param params - Share-bound inputs.
286
+ * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
287
+ * @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
288
+ * share burns is returned. The entity passes the `now`-accrued snapshot for both.
289
+ * @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
290
+ * @returns An upper bound, in vault shares, of what the exit burns.
291
+ * @example
292
+ * ```ts
293
+ * import { MathLib } from "@morpho-org/blue-sdk";
294
+ * import {
295
+ * computeVaultV2ForceWithdrawFeeSharesMinted,
296
+ * computeVaultV2ForceWithdrawSharesBurnt,
297
+ * } from "@morpho-org/morpho-sdk";
298
+ *
299
+ * const { vault: nowVaultData } = vaultData.accrueInterest(now);
300
+ * const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
301
+ * vaultData: nowVaultData,
302
+ * deadlineVaultData: nowVaultData,
303
+ * plan,
304
+ * });
305
+ * const feeSharesNow = computeVaultV2ForceWithdrawFeeSharesMinted({
306
+ * vaultData,
307
+ * owner,
308
+ * timestamp: now,
309
+ * });
310
+ * const sharesBurntForFloor = sharesBurnt - feeSharesNow;
311
+ * const requiredShareAllowance = MathLib.min(
312
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) +
313
+ * computeVaultV2ForceWithdrawFeeSharesMinted({
314
+ * vaultData,
315
+ * owner,
316
+ * timestamp: deadline,
317
+ * }),
318
+ * maxUint256,
319
+ * );
320
+ * ```
321
+ */
322
+ function computeVaultV2ForceWithdrawSharesBurnt(params) {
323
+ const { vaultData, deadlineVaultData, plan } = params;
324
+ // `penaltyAssets` already carries the per-market ceil accumulation, so this is the full
325
+ // penalty-inclusive amount debited from the user's position.
326
+ const grossDebited = plan.withdrawnAssets + plan.penaltyAssets;
327
+ // Only withdrawals that move a positive amount round anything: `toShares(0, "Up")` is `0`. So the
328
+ // penalty-free leg counts only when it pays out, the `forceDeallocate` burns count only at a
329
+ // positive penalty, and the deallocated leg counts only when the loop deallocated something.
330
+ const positiveLegs = (plan.assetsToWithdraw > 0n ? 1 : 0) +
331
+ (plan.penalty > 0n ? plan.penaltyLegs : 0) +
332
+ (plan.assetsToDeallocate > 0n ? 1 : 0);
333
+ return (blue_sdk_1.MathLib.max(vaultData.toShares(grossDebited, "Up"), deadlineVaultData.toShares(grossDebited, "Up")) +
334
+ // `sum(ceil(sharesᵢ)) <= ceil(sum(sharesᵢ)) + (positiveLegs - 1)`: the aggregate conversion above
335
+ // already spends one ceiling, so only the *additional* positive legs can each cost one more
336
+ // share. A fixed `penaltyLegs + 2` overcounts every zero-amount leg, and because this value is
337
+ // the slippage denominator an overcount silently widens the price drop the bound accepts —
338
+ // worst on a dust exit, where two phantom shares can dominate the real burn.
339
+ BigInt(positiveLegs > 0 ? positiveLegs - 1 : 0));
340
+ }
341
+ /**
342
+ * Computes a lower bound of the Vault V2 shares that a force withdrawal burns.
343
+ *
344
+ * The penalty-free/penalised split can move as liquidity accrues between planning and inclusion.
345
+ * This lower bound is used to reject fee-recipient exits whose fee mints could reach the burn
346
+ * measured by VaultExitBundlesV1, independently of that split.
347
+ *
348
+ * @param params - Lower-bound inputs.
349
+ * @param params.vaultData - Vault V2 snapshot already accrued to the execution timestamp.
350
+ * @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
351
+ * @returns A lower bound, in vault shares, of the burn measured by the contract.
352
+ * @example
353
+ * ```ts
354
+ * import { computeVaultV2ForceWithdrawMinSharesBurnt } from "@morpho-org/morpho-sdk";
355
+ *
356
+ * const minSharesBurnt = computeVaultV2ForceWithdrawMinSharesBurnt({
357
+ * vaultData,
358
+ * plan,
359
+ * });
360
+ * ```
361
+ */
362
+ function computeVaultV2ForceWithdrawMinSharesBurnt(params) {
363
+ const { vaultData, plan } = params;
364
+ // The penalty-free/penalised split moves as the liquidity market accrues, but any split debits
365
+ // within `1 + penalty` (< 2 asset units) of `exitAssets`, so `exitAssets - 1` lower-bounds every
366
+ // execution-time split.
367
+ return vaultData.toShares(blue_sdk_1.MathLib.min(plan.withdrawnAssets +
368
+ blue_sdk_1.MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty), blue_sdk_1.MathLib.zeroFloorSub(plan.exitAssets, 1n)), "Down");
369
+ }