@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
package/lib/esm/errors.js CHANGED
@@ -1,48 +1,4 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError,
2
- /** @deprecated Use InvalidBlueMarketParamsError or the raw protocol subpath. */
3
- InvalidMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError,
4
- /** @deprecated Use UnknownBlueDataError or the raw protocol subpath. */
5
- UnknownDataError, UnknownFactory as UnknownBlueFactory,
6
- /** @deprecated Use UnknownBlueFactory or the raw protocol subpath. */
7
- UnknownFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError,
8
- /** @deprecated Use UnknownBlueMarketParamsError or the raw protocol subpath. */
9
- UnknownMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory,
10
- /** @deprecated Use UnknownBlueOfFactory or the raw protocol subpath. */
11
- UnknownOfFactory, UnknownTokenError as UnknownBlueTokenError,
12
- /** @deprecated Use UnknownBlueTokenError or the raw protocol subpath. */
13
- UnknownTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError,
14
- /** @deprecated Use UnknownBlueTokenPriceError or the raw protocol subpath. */
15
- UnknownTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError,
16
- /** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
17
- UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
18
- /** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
19
- UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError,
20
- /** @deprecated Use UnsupportedBlueVaultV2AdapterError or the raw protocol subpath. */
21
- UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
22
2
  export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
23
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError,
24
- /** @deprecated Use InvalidMidnightOfferGroupError or the raw protocol subpath. */
25
- InvalidOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError,
26
- /** @deprecated Use InvalidMidnightOfferParameterError or the raw protocol subpath. */
27
- InvalidOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError,
28
- /** @deprecated Use InvalidMidnightPositionAccrualStateError or the raw protocol subpath. */
29
- InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError,
30
- /** @deprecated Use InvalidMidnightPositionAccrualTimestampError or the raw protocol subpath. */
31
- InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError,
32
- /** @deprecated Use InvalidMidnightPositionLossFactorError or the raw protocol subpath. */
33
- InvalidPositionLossFactorError, InvalidTickSpacingError as InvalidMidnightTickSpacingError,
34
- /** @deprecated Use InvalidMidnightTickSpacingError or the raw protocol subpath. */
35
- InvalidTickSpacingError, InvalidTreeError as InvalidMidnightTreeError,
36
- /** @deprecated Use InvalidMidnightTreeError or the raw protocol subpath. */
37
- InvalidTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError,
38
- /** @deprecated Use InvalidMidnightTreeHeightError or the raw protocol subpath. */
39
- InvalidTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError,
40
- /** @deprecated Use MidnightPriceGreaterThanOneError or the raw protocol subpath. */
41
- PriceGreaterThanOneError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError,
42
- /** @deprecated Use MidnightSettlementFeeExceedsPriceError or the raw protocol subpath. */
43
- SettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError,
44
- /** @deprecated Use MidnightTickOutOfRangeError or the raw protocol subpath. */
45
- TickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError,
46
- /** @deprecated Use UnknownMidnightCollateralIndexError or the raw protocol subpath. */
47
- UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
3
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
48
4
  export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
@@ -1,16 +1,2 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition,
2
- /** @deprecated Use `fetchBlueAccrualPosition` or the raw `/blue/fetch` subpath. */
3
- fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket,
4
- /** @deprecated Use `fetchBlueMarket` or the raw `/blue/fetch` subpath. */
5
- fetchMarket, fetchMarketParams as fetchBlueMarketParams,
6
- /** @deprecated Use `fetchBlueMarketParams` or the raw `/blue/fetch` subpath. */
7
- fetchMarketParams, fetchPosition as fetchBluePosition,
8
- /** @deprecated Use `fetchBluePosition` or the raw `/blue/fetch` subpath. */
9
- fetchPosition, fetchPreLiquidationParams as fetchBluePreLiquidationParams,
10
- /** @deprecated Use `fetchBluePreLiquidationParams` or the raw `/blue/fetch` subpath. */
11
- fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidationPosition,
12
- /** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
13
- fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
14
- /** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
15
- fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition, fetchPreLiquidationParams as fetchBluePreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
16
2
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/esm/fetch.js CHANGED
@@ -1,16 +1,2 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition,
2
- /** @deprecated Use `fetchBlueAccrualPosition` or the raw `/blue/fetch` subpath. */
3
- fetchAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket,
4
- /** @deprecated Use `fetchBlueMarket` or the raw `/blue/fetch` subpath. */
5
- fetchMarket, fetchMarketParams as fetchBlueMarketParams,
6
- /** @deprecated Use `fetchBlueMarketParams` or the raw `/blue/fetch` subpath. */
7
- fetchMarketParams, fetchPosition as fetchBluePosition,
8
- /** @deprecated Use `fetchBluePosition` or the raw `/blue/fetch` subpath. */
9
- fetchPosition, fetchPreLiquidationParams as fetchBluePreLiquidationParams,
10
- /** @deprecated Use `fetchBluePreLiquidationParams` or the raw `/blue/fetch` subpath. */
11
- fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidationPosition,
12
- /** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
13
- fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
14
- /** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
15
- fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition, fetchPreLiquidationParams as fetchBluePreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
16
2
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
@@ -17,8 +17,6 @@ export declare const DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 900000000000000000n
17
17
  /**
18
18
  * The default target utilization above which shared liquidity reallocations are
19
19
  * triggered (and the level the target market is brought back to), scaled by WAD.
20
- * Still overridable through the deprecated `supplyTargetUtilization` /
21
- * `defaultSupplyTargetUtilization` options until the next major.
22
20
  */
23
21
  export declare const DEFAULT_SUPPLY_TARGET_UTILIZATION = 900000000000000000n;
24
22
  /**
@@ -18,8 +18,6 @@ export const DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 900000000000000000n;
18
18
  /**
19
19
  * The default target utilization above which shared liquidity reallocations are
20
20
  * triggered (and the level the target market is brought back to), scaled by WAD.
21
- * Still overridable through the deprecated `supplyTargetUtilization` /
22
- * `defaultSupplyTargetUtilization` options until the next major.
23
21
  */
24
22
  export const DEFAULT_SUPPLY_TARGET_UTILIZATION = 900000000000000000n;
25
23
  /**
@@ -1,10 +1,11 @@
1
- export { computeReallocations, computeVaultV1Reallocations, } from "./computeVaultV1Reallocations.js";
2
1
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
3
2
  export { addTransactionMetadata } from "./metadata.js";
3
+ export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
4
4
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
5
5
  export { grossFromNetAssets } from "./referralFee.js";
6
6
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
7
- export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
- export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
7
+ export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
9
  export { validateOfferSides } from "./validateOfferSides.js";
10
10
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
11
+ export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
@@ -1,10 +1,11 @@
1
- export { computeReallocations, computeVaultV1Reallocations, } from "./computeVaultV1Reallocations.js";
2
1
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
3
2
  export { addTransactionMetadata } from "./metadata.js";
3
+ export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
4
4
  export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
5
5
  export { grossFromNetAssets } from "./referralFee.js";
6
6
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
7
- export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
- export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
7
+ export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
8
+ export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
9
9
  export { validateOfferSides } from "./validateOfferSides.js";
10
10
  export { validateRequirementSpender, } from "./validateRequirementSpender.js";
11
+ export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
@@ -26,11 +26,9 @@ import type { Metadata } from "../types/index.js";
26
26
  * @param {Metadata} metadata - An object containing optional metadata fields
27
27
  * such as `timestamp` and `origin`.
28
28
  *
29
- * @returns {Object} - A new transaction object with the modified `data` field
30
- * including the concatenated metadata.
31
- *
32
- * If no `data` is present in the original transaction, the function returns
33
- * the transaction unmodified.
29
+ * @returns The same `tx` object when `data` is missing, an empty string, or
30
+ * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
+ * with `data` containing any appended metadata. The input is never mutated.
34
32
  */
35
33
  export declare function addTransactionMetadata(tx: {
36
34
  data: Hex;
@@ -26,15 +26,13 @@ import { concatHex, isHex, numberToHex } from "viem";
26
26
  * @param {Metadata} metadata - An object containing optional metadata fields
27
27
  * such as `timestamp` and `origin`.
28
28
  *
29
- * @returns {Object} - A new transaction object with the modified `data` field
30
- * including the concatenated metadata.
31
- *
32
- * If no `data` is present in the original transaction, the function returns
33
- * the transaction unmodified.
29
+ * @returns The same `tx` object when `data` is missing, an empty string, or
30
+ * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
+ * with `data` containing any appended metadata. The input is never mutated.
34
32
  */
35
33
  export function addTransactionMetadata(tx, metadata) {
36
34
  const { data, ..._tx } = tx;
37
- if (!data)
35
+ if (!data || data === "0x")
38
36
  return tx;
39
37
  const concatItems = [data];
40
38
  if (metadata.timestamp) {
@@ -0,0 +1,107 @@
1
+ import { type AccrualVaultV2, type Address } from "@morpho-org/blue-sdk";
2
+ /** Inputs used to preview a Vault V2 force withdrawal. */
3
+ export interface PreviewVaultV2ForceWithdrawParams {
4
+ /** Penalty-inclusive amount the user wants to exit. */
5
+ readonly requestedExitAssets: bigint;
6
+ /** Timestamp used to accrue every Morpho Blue market before converting adapter shares. */
7
+ readonly timestamp: bigint;
8
+ /** Optional adapter override; defaults to the vault's sole adapter. */
9
+ readonly adapter?: Address;
10
+ /**
11
+ * Account that will call `forceWithdraw`; fee-recipient mints are mirrored when provided. The
12
+ * entity projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it.
13
+ */
14
+ readonly userAddress?: Address;
15
+ /**
16
+ * Timestamp the fee-recipient mint guard is projected to; defaults to `timestamp`. Pass the
17
+ * `forceWithdraw` deadline you will submit to mirror the entity's guard exactly. The entity
18
+ * rejects deadlines more than one year after handle creation (`InputExceedsMaxError`) rather
19
+ * than clamping them, so a quote projected past that horizon cannot be submitted. Ignored
20
+ * without `userAddress`.
21
+ */
22
+ readonly feeProjectionTimestamp?: bigint;
23
+ /** Optional WAD-scaled referral fee percentage. Defaults to `0n`. */
24
+ readonly referralFeePct?: bigint;
25
+ /** Optional referral fee recipient. Required when `referralFeePct` is positive, as the entity
26
+ * enforces (`ReferralFeeRecipientMissingError`). When it equals `userAddress`, the fee is paid
27
+ * back to the exiting account and `netAssets` includes it. */
28
+ readonly referralFeeRecipient?: Address;
29
+ }
30
+ /** Frontend-ready preview of a Vault V2 force withdrawal through VaultExitBundlesV1. */
31
+ export interface VaultV2ForceWithdrawPreview {
32
+ /** Largest penalty-inclusive exit the current vault state supports. */
33
+ readonly maxExitAssets: bigint;
34
+ /** Penalty-inclusive exit amount this preview is computed for, capped at `maxExitAssets`. */
35
+ readonly exitAssets: bigint;
36
+ /** Requested penalty-inclusive amount left uncovered by `exitAssets`. */
37
+ readonly remainingExitAssets: bigint;
38
+ /** Portion withdrawn without a force-deallocation penalty (vault idle plus liquidity adapter). */
39
+ readonly assetsToWithdraw: bigint;
40
+ /** Portion force-deallocated from the adapter's markets, net of the penalty. */
41
+ readonly assetsToDeallocate: bigint;
42
+ /**
43
+ * Lower-bound estimate of the assets charged as the force-deallocation penalty,
44
+ * `ceil(assetsToDeallocate × penalty)`. Exact for a single-market exit. Across multiple markets
45
+ * the contract charges `Σ ceil(chunkᵢ × penalty)`, which this order-independent plan cannot
46
+ * reproduce without committing to the adapter's execution order (reordered mid-loop by
47
+ * swap-and-pop); the true charge is at most `penaltyLegs − 1` wei higher. It is never the inflated
48
+ * allowance bound. `netAssets` is exact and does not depend on this field, so the residual never
49
+ * affects the quoted payout.
50
+ */
51
+ readonly penaltyAssets: bigint;
52
+ /** Assets routed to the referral fee recipient. */
53
+ readonly referralFeeAssets: bigint;
54
+ /** Assets the exiting account actually receives: `withdrawnAssets` minus the referral fee, unless
55
+ * the fee is paid back to `userAddress` itself. */
56
+ readonly netAssets: bigint;
57
+ }
58
+ /**
59
+ * Previews what a Vault V2 force withdrawal delivers, without any RPC.
60
+ *
61
+ * `exitAssets` is **penalty-inclusive**: the contract debits it from the user's position but pays
62
+ * out only `assetsToWithdraw + assetsToDeallocate`. Use `netAssets` to quote what the user
63
+ * receives and `maxExitAssets` to cap an input field.
64
+ *
65
+ * @param vaultData - Pre-fetched Vault V2 accrual snapshot.
66
+ * @param params - Preview parameters.
67
+ * @param params.requestedExitAssets - Penalty-inclusive amount the user wants to exit.
68
+ * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before computing capacity.
69
+ * Must not run ahead of the wall clock at the subsequent `forceWithdraw()` call: market accrual
70
+ * grows the adapter's position, so a forward timestamp reports a `maxExitAssets` the entity will
71
+ * reject.
72
+ * @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
73
+ * @param params.userAddress - Optional account that will call `forceWithdraw`; when provided,
74
+ * fee shares minted to it by the accrual are mirrored exactly as the entity does. The entity
75
+ * projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it. Omit
76
+ * only for non-fee-recipient users.
77
+ * @param params.feeProjectionTimestamp - Timestamp for the fee-recipient mint guard; defaults to
78
+ * `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
79
+ * more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
80
+ * keep the deadline itself within that horizon. Ignored without `userAddress`.
81
+ * @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
82
+ * @param params.referralFeeRecipient - Optional referral fee recipient. Required when
83
+ * `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
84
+ * When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
85
+ * includes it.
86
+ * @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
87
+ * `adapter` override that is not the vault's sole adapter, an adapter that is not a
88
+ * MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
89
+ * `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
90
+ * `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
91
+ * whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
92
+ * exit whose realized share price rounds down to zero at the default slippage tolerance (which
93
+ * the entity rejects with `VaultV2ForceWithdrawZeroSharePriceError`), or whose derived default
94
+ * floor cannot fit `uint256`.
95
+ * @example
96
+ * ```ts
97
+ * import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
98
+ *
99
+ * const preview = previewVaultV2ForceWithdraw(vaultData, {
100
+ * requestedExitAssets: 1_000_000n,
101
+ * timestamp: block.timestamp,
102
+ * });
103
+ * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
104
+ * // preview?.netAssets is what the user receives
105
+ * ```
106
+ */
107
+ export declare function previewVaultV2ForceWithdraw(vaultData: AccrualVaultV2, params: PreviewVaultV2ForceWithdrawParams): VaultV2ForceWithdrawPreview | undefined;
@@ -0,0 +1,161 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
2
+ import { isAddressEqual, maxUint256, zeroAddress } from "viem";
3
+ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
4
+ /**
5
+ * Previews what a Vault V2 force withdrawal delivers, without any RPC.
6
+ *
7
+ * `exitAssets` is **penalty-inclusive**: the contract debits it from the user's position but pays
8
+ * out only `assetsToWithdraw + assetsToDeallocate`. Use `netAssets` to quote what the user
9
+ * receives and `maxExitAssets` to cap an input field.
10
+ *
11
+ * @param vaultData - Pre-fetched Vault V2 accrual snapshot.
12
+ * @param params - Preview parameters.
13
+ * @param params.requestedExitAssets - Penalty-inclusive amount the user wants to exit.
14
+ * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before computing capacity.
15
+ * Must not run ahead of the wall clock at the subsequent `forceWithdraw()` call: market accrual
16
+ * grows the adapter's position, so a forward timestamp reports a `maxExitAssets` the entity will
17
+ * reject.
18
+ * @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
19
+ * @param params.userAddress - Optional account that will call `forceWithdraw`; when provided,
20
+ * fee shares minted to it by the accrual are mirrored exactly as the entity does. The entity
21
+ * projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it. Omit
22
+ * only for non-fee-recipient users.
23
+ * @param params.feeProjectionTimestamp - Timestamp for the fee-recipient mint guard; defaults to
24
+ * `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
25
+ * more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
26
+ * keep the deadline itself within that horizon. Ignored without `userAddress`.
27
+ * @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
28
+ * @param params.referralFeeRecipient - Optional referral fee recipient. Required when
29
+ * `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
30
+ * When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
31
+ * includes it.
32
+ * @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
33
+ * `adapter` override that is not the vault's sole adapter, an adapter that is not a
34
+ * MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
35
+ * `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
36
+ * `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
37
+ * whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
38
+ * exit whose realized share price rounds down to zero at the default slippage tolerance (which
39
+ * the entity rejects with `VaultV2ForceWithdrawZeroSharePriceError`), or whose derived default
40
+ * floor cannot fit `uint256`.
41
+ * @example
42
+ * ```ts
43
+ * import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
44
+ *
45
+ * const preview = previewVaultV2ForceWithdraw(vaultData, {
46
+ * requestedExitAssets: 1_000_000n,
47
+ * timestamp: block.timestamp,
48
+ * });
49
+ * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
50
+ * // preview?.netAssets is what the user receives
51
+ * ```
52
+ */
53
+ export function previewVaultV2ForceWithdraw(vaultData, params) {
54
+ const { requestedExitAssets, timestamp, adapter: adapterOverride, userAddress, feeProjectionTimestamp = timestamp, referralFeePct = 0n, referralFeeRecipient, } = params;
55
+ if (requestedExitAssets <= 0n)
56
+ return undefined;
57
+ // Out of the range the action accepts, `netAssets` would quote a payout the contract can never
58
+ // deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
59
+ if (referralFeePct < 0n || referralFeePct >= MathLib.WAD)
60
+ return undefined;
61
+ if (referralFeePct > 0n &&
62
+ (referralFeeRecipient == null ||
63
+ isAddressEqual(referralFeeRecipient, zeroAddress))) {
64
+ return undefined;
65
+ }
66
+ const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData, adapterOverride);
67
+ if (eligibility.type !== "eligible")
68
+ return undefined;
69
+ const capacity = computeVaultV2ForceWithdrawPlan({
70
+ vaultData,
71
+ adapter: eligibility.adapter,
72
+ liquidityMarketId: eligibility.liquidityMarketId,
73
+ exitAssets: requestedExitAssets,
74
+ timestamp,
75
+ });
76
+ const exitAssets = MathLib.min(requestedExitAssets, capacity.maxExitAssets);
77
+ // A vault with no exitable capacity caps `maxExitAssets` to `0`; the planner rejects a
78
+ // non-positive amount, so short-circuit to the "not previewable" verdict before re-planning.
79
+ if (exitAssets <= 0n)
80
+ return undefined;
81
+ // Re-plan at the capped amount so every returned leg describes the same exit.
82
+ const plan = exitAssets === requestedExitAssets
83
+ ? capacity
84
+ : computeVaultV2ForceWithdrawPlan({
85
+ vaultData,
86
+ adapter: eligibility.adapter,
87
+ liquidityMarketId: eligibility.liquidityMarketId,
88
+ exitAssets,
89
+ timestamp,
90
+ });
91
+ if (plan.withdrawnAssets <= 0n)
92
+ return undefined;
93
+ // Mirror the entity's zero-floor guard. `forceWithdraw()` derives its slippage floor from
94
+ // `withdrawnAssets / sharesBurnt` and rejects an exit whose realized share price rounds down to
95
+ // zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
96
+ // dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
97
+ // `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
98
+ // divides by (accrued to `timestamp` like the plan): a tolerance-free screen clears an exit whose
99
+ // realized price is a single RAY-unit, yet the default tolerance scales that below 1 and rounds it
100
+ // to zero — so the entity would reject with `VaultV2ForceWithdrawZeroSharePriceError` the very
101
+ // `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
102
+ // entity's own guard. The entity validates this derived value with
103
+ // `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
104
+ // cannot fit uint256.
105
+ const { vault: accruedVaultData } = vaultData.accrueInterest(MathLib.max(timestamp, vaultData.lastUpdate));
106
+ const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
107
+ vaultData: accruedVaultData,
108
+ deadlineVaultData: accruedVaultData,
109
+ plan,
110
+ });
111
+ const feeShares = userAddress
112
+ ? computeVaultV2ForceWithdrawFeeSharesMinted({
113
+ vaultData,
114
+ owner: userAddress,
115
+ timestamp,
116
+ })
117
+ : 0n;
118
+ const effectiveFeeProjectionTimestamp = MathLib.max(timestamp, feeProjectionTimestamp);
119
+ if (userAddress) {
120
+ const { vault: projectedVaultData } = vaultData.accrueInterest(MathLib.max(effectiveFeeProjectionTimestamp, vaultData.lastUpdate));
121
+ const feeSharesProjected = computeVaultV2ForceWithdrawFeeSharesMinted({
122
+ vaultData,
123
+ owner: userAddress,
124
+ timestamp: effectiveFeeProjectionTimestamp,
125
+ });
126
+ const minSharesBurntProjected = computeVaultV2ForceWithdrawMinSharesBurnt({
127
+ vaultData: projectedVaultData,
128
+ plan,
129
+ });
130
+ if (feeSharesProjected > 0n &&
131
+ feeSharesProjected >= minSharesBurntProjected) {
132
+ return undefined;
133
+ }
134
+ }
135
+ const sharesBurntForFloor = sharesBurnt - feeShares;
136
+ const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
137
+ ? MathLib.mulDivDown(plan.withdrawnAssets, MathLib.wToRay(MathLib.WAD - DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
138
+ : 0n;
139
+ if (defaultMinSharePriceE27 <= 0n || defaultMinSharePriceE27 > maxUint256) {
140
+ return undefined;
141
+ }
142
+ const referralFeeAssets = MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, MathLib.WAD);
143
+ const selfPaidReferralFee = userAddress != null &&
144
+ referralFeeRecipient != null &&
145
+ isAddressEqual(userAddress, referralFeeRecipient);
146
+ return {
147
+ maxExitAssets: capacity.maxExitAssets,
148
+ exitAssets,
149
+ remainingExitAssets: requestedExitAssets - exitAssets,
150
+ assetsToWithdraw: plan.assetsToWithdraw,
151
+ assetsToDeallocate: plan.assetsToDeallocate,
152
+ // The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
153
+ // bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
154
+ // break reconciliation with `exitAssets` for a multi-market exit.
155
+ penaltyAssets: MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
156
+ referralFeeAssets,
157
+ netAssets: selfPaidReferralFee
158
+ ? plan.withdrawnAssets
159
+ : plan.withdrawnAssets - referralFeeAssets,
160
+ };
161
+ }
@@ -35,6 +35,7 @@ export interface VaultV2InKindRedeemMarketPreview {
35
35
  * @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
36
36
  * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
37
37
  * @returns Frontend-ready market choices, or an empty list when no choices are available.
38
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
38
39
  * @example
39
40
  * ```ts
40
41
  * import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -11,6 +11,7 @@ import { AccrualVaultV2MorphoMarketV1AdapterV2, MathLib, } from "@morpho-org/blu
11
11
  * @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
12
12
  * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
13
13
  * @returns Frontend-ready market choices, or an empty list when no choices are available.
14
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
14
15
  * @example
15
16
  * ```ts
16
17
  * import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -37,6 +38,7 @@ export function previewVaultV2InKindRedeem(vaultData, params) {
37
38
  const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
38
39
  const availableIdleAssets = vaultData.assetBalance;
39
40
  const allocations = adapter.markets
41
+ .filter((market) => (adapter.supplyShares[market.id] ?? 0n) !== 0n)
40
42
  .map((market) => ({
41
43
  market,
42
44
  allocationAssets: market
@@ -1,105 +1,49 @@
1
- import { type AccrualVault, AccrualVaultV2, type Market } from "@morpho-org/blue-sdk";
1
+ import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
2
  /**
3
- * Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
3
+ * Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
4
4
  *
5
- * Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
5
+ * Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
6
6
  * ```solidity
7
- * require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
7
+ * require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
8
8
  * ```
9
9
  *
10
- * @param params - Computation parameters.
11
- * @param params.borrowAmount - The amount of assets to borrow.
12
- * @param params.market - The market to compute the minimum borrow share price for.
13
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
14
- * @returns minSharePriceE27 in RAY scale (1e27).
15
- */
16
- export declare function computeMinBorrowSharePrice(params: {
17
- borrowAmount: bigint;
18
- market: Market;
19
- slippageTolerance: bigint;
20
- }): bigint;
21
- /**
22
- * Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
23
- *
24
- * Supports both repay-by-assets and repay-by-shares paths:
25
- * - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
26
- * - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
27
- *
28
- * Direction is opposite of borrow's `minSharePrice`:
29
- * - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
30
- * - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
31
- *
32
- * Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
33
- *
34
- * @param params - Computation parameters.
35
- * @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
36
- * @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
37
- * @param params.market - The market to compute the maximum repay share price for.
38
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
39
- * @returns maxSharePriceE27 in RAY scale (1e27).
40
- */
41
- export declare function computeMaxRepaySharePrice(params: {
42
- repayAssets: bigint;
43
- repayShares: bigint;
44
- market: Market;
45
- slippageTolerance: bigint;
46
- }): bigint;
47
- /**
48
- * Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
10
+ * The realized price sits structurally *below* the vault's share price because the
11
+ * force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
12
+ * from the raw share price would reject every penalised exit. Both inputs are therefore taken from
13
+ * the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
14
+ * `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
15
+ * faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
16
+ * shifting from the penalty-free leg to the penalised leg all do.
49
17
  *
50
- * Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
51
- * ```solidity
52
- * require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
53
- * ```
54
- *
55
- * Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
18
+ * The referral fee is deducted *after* this check, so it is outside the bound's protection.
56
19
  *
57
20
  * @param params - Computation parameters.
58
- * @param params.supplyAssets - The amount of loan assets to supply.
59
- * @param params.market - The market to compute the maximum supply share price for.
21
+ * @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
22
+ * @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
60
23
  * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
61
- * @returns `maxSharePriceE27` in RAY scale (1e27).
62
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
63
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
64
- */
65
- export declare function computeMaxSupplySharePrice(params: {
66
- supplyAssets: bigint;
67
- market: Market;
68
- slippageTolerance: bigint;
69
- }): bigint;
70
- /**
71
- * Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
24
+ * @returns `minSharePriceE27` in RAY scale (1e27).
25
+ * @throws {NegativeInputError} when `slippageTolerance` is negative.
26
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
27
+ * `MAX_SLIPPAGE_TOLERANCE`.
28
+ * @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
29
+ * would silently nullify the on-chain bound.
30
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
31
+ * would nullify the bound just as a non-positive input would.
32
+ * @example
33
+ * ```ts
34
+ * import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
72
35
  *
73
- * Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
74
- * ```solidity
75
- * require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
36
+ * const minSharePriceE27 = computeMinForceWithdrawSharePrice({
37
+ * withdrawnAssets: plan.withdrawnAssets,
38
+ * sharesBurnt,
39
+ * slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
40
+ * });
76
41
  * ```
77
- *
78
- * Supports both assets and shares modes:
79
- * - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
80
- * withdrawer against over-burning shares).
81
- * - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
82
- * amount paid out).
83
- *
84
- * Direction is opposite of supply's `maxSharePrice`:
85
- * - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
86
- * - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
87
- * assets per share burned).
88
- *
89
- * @param params - Computation parameters.
90
- * @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
91
- * @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
92
- * @param params.market - The market to compute the minimum withdraw share price for.
93
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
94
- * @returns `minSharePriceE27` in RAY scale (1e27).
95
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
96
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
97
42
  */
98
- export declare function computeMinWithdrawSharePrice(params: {
99
- withdrawAssets: bigint;
100
- withdrawShares: bigint;
101
- market: Market;
102
- slippageTolerance: bigint;
43
+ export declare function computeMinForceWithdrawSharePrice(params: {
44
+ readonly withdrawnAssets: bigint;
45
+ readonly sharesBurnt: bigint;
46
+ readonly slippageTolerance: bigint;
103
47
  }): bigint;
104
48
  /**
105
49
  * Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.