@morpho-org/morpho-sdk 6.0.0-next.2 → 6.0.0-next.4

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 (277) hide show
  1. package/MIGRATION-v5-to-v6.md +88 -32
  2. package/README.md +9 -7
  3. package/lib/cjs/abis.d.ts +7 -2844
  4. package/lib/cjs/abis.js +3 -1951
  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 +1 -9
  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 +2 -2
  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 +6 -2
  25. package/lib/cjs/actions/bundles/common.js +31 -5
  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 +6 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -16
  30. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
  31. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +6 -11
  36. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  37. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  38. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  39. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  40. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  41. package/lib/cjs/actions/requirements/index.js +0 -1
  42. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  43. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  44. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +7 -5
  45. package/lib/cjs/actions/vaultV1/inKindRedeem.js +11 -7
  46. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  47. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  48. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  49. package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -3
  50. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +7 -5
  51. package/lib/cjs/actions/vaultV2/inKindRedeem.js +11 -7
  52. package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
  53. package/lib/cjs/augment.d.ts +0 -1
  54. package/lib/cjs/augment.js +0 -1
  55. package/lib/cjs/blue/abis.d.ts +5 -5
  56. package/lib/cjs/blue/abis.js +3 -7
  57. package/lib/cjs/blue/entities.d.ts +10 -8
  58. package/lib/cjs/blue/entities.js +3 -3
  59. package/lib/cjs/blue/errors.d.ts +4 -2
  60. package/lib/cjs/blue/errors.js +3 -1
  61. package/lib/cjs/blue/fetch.d.ts +5 -3
  62. package/lib/cjs/blue/fetch.js +3 -3
  63. package/lib/cjs/blue/types.d.ts +2 -4
  64. package/lib/cjs/blue/utils.d.ts +6 -4
  65. package/lib/cjs/blue/utils.js +3 -3
  66. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  67. package/lib/cjs/client/morphoViemExtension.js +1 -1
  68. package/lib/cjs/constants.d.ts +3 -37
  69. package/lib/cjs/constants.js +1 -39
  70. package/lib/cjs/entities/blue/blue.d.ts +30 -265
  71. package/lib/cjs/entities/blue/blue.js +1 -205
  72. package/lib/cjs/entities/index.d.ts +11 -66
  73. package/lib/cjs/entities/index.js +3 -21
  74. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  75. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  76. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +13 -5
  77. package/lib/cjs/entities/vaultV1/vaultV1.js +16 -10
  78. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +40 -19
  79. package/lib/cjs/entities/vaultV2/vaultV2.js +57 -26
  80. package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
  81. package/lib/cjs/errors.d.ts +5 -47
  82. package/lib/cjs/errors.js +4 -46
  83. package/lib/cjs/fetch.d.ts +5 -17
  84. package/lib/cjs/fetch.js +3 -17
  85. package/lib/cjs/helpers/constant.d.ts +0 -2
  86. package/lib/cjs/helpers/constant.js +0 -2
  87. package/lib/cjs/helpers/index.d.ts +2 -3
  88. package/lib/cjs/helpers/index.js +1 -9
  89. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +11 -5
  90. package/lib/cjs/helpers/slippage.d.ts +1 -103
  91. package/lib/cjs/helpers/slippage.js +0 -150
  92. package/lib/cjs/helpers/utilization.d.ts +12 -10
  93. package/lib/cjs/helpers/utilization.js +27 -12
  94. package/lib/cjs/helpers/validate.d.ts +1 -24
  95. package/lib/cjs/helpers/validate.js +2 -49
  96. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  97. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  98. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  99. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  100. package/lib/cjs/midnight/errors.d.ts +1 -1
  101. package/lib/cjs/midnight/errors.js +2 -1
  102. package/lib/cjs/types/action.d.ts +17 -65
  103. package/lib/cjs/types/action.js +11 -4
  104. package/lib/cjs/types/error.d.ts +50 -381
  105. package/lib/cjs/types/error.js +64 -395
  106. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  107. package/lib/cjs/types.d.ts +2 -18
  108. package/lib/cjs/utils.d.ts +10 -35
  109. package/lib/cjs/utils.js +4 -36
  110. package/lib/esm/abis.d.ts +7 -2844
  111. package/lib/esm/abis.js +7 -1950
  112. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  113. package/lib/esm/actions/blue/borrow.js +3 -2
  114. package/lib/esm/actions/blue/common.js +1 -9
  115. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  116. package/lib/esm/actions/blue/refinance.js +2 -2
  117. package/lib/esm/actions/blue/repay.d.ts +1 -1
  118. package/lib/esm/actions/blue/repay.js +1 -1
  119. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  120. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  121. package/lib/esm/actions/blue/supply.d.ts +2 -2
  122. package/lib/esm/actions/blue/supply.js +2 -2
  123. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  124. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  125. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  127. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  128. package/lib/esm/actions/blue/withdraw.js +3 -3
  129. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  130. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  131. package/lib/esm/actions/bundles/common.d.ts +6 -2
  132. package/lib/esm/actions/bundles/common.js +32 -6
  133. package/lib/esm/actions/index.d.ts +0 -1
  134. package/lib/esm/actions/index.js +0 -1
  135. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
  136. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +12 -17
  137. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
  138. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
  139. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  140. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  141. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
  142. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +6 -11
  143. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  144. package/lib/esm/actions/requirements/encode/index.js +0 -1
  145. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  146. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  147. package/lib/esm/actions/requirements/index.d.ts +0 -1
  148. package/lib/esm/actions/requirements/index.js +0 -1
  149. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  150. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  151. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +7 -5
  152. package/lib/esm/actions/vaultV1/inKindRedeem.js +11 -7
  153. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  154. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  155. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  156. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  157. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +7 -5
  158. package/lib/esm/actions/vaultV2/inKindRedeem.js +11 -7
  159. package/lib/esm/augment/AccrualPosition.d.ts +1 -0
  160. package/lib/esm/augment.d.ts +0 -1
  161. package/lib/esm/augment.js +0 -1
  162. package/lib/esm/blue/abis.d.ts +5 -5
  163. package/lib/esm/blue/abis.js +5 -5
  164. package/lib/esm/blue/entities.d.ts +10 -8
  165. package/lib/esm/blue/entities.js +5 -3
  166. package/lib/esm/blue/errors.d.ts +4 -2
  167. package/lib/esm/blue/errors.js +4 -2
  168. package/lib/esm/blue/fetch.d.ts +5 -3
  169. package/lib/esm/blue/fetch.js +5 -3
  170. package/lib/esm/blue/types.d.ts +2 -4
  171. package/lib/esm/blue/utils.d.ts +6 -4
  172. package/lib/esm/blue/utils.js +6 -4
  173. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  174. package/lib/esm/client/morphoViemExtension.js +1 -1
  175. package/lib/esm/constants.d.ts +3 -37
  176. package/lib/esm/constants.js +3 -37
  177. package/lib/esm/entities/blue/blue.d.ts +30 -265
  178. package/lib/esm/entities/blue/blue.js +4 -208
  179. package/lib/esm/entities/index.d.ts +11 -66
  180. package/lib/esm/entities/index.js +5 -18
  181. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  183. package/lib/esm/entities/vaultV1/vaultV1.d.ts +13 -5
  184. package/lib/esm/entities/vaultV1/vaultV1.js +19 -13
  185. package/lib/esm/entities/vaultV2/vaultV2.d.ts +40 -19
  186. package/lib/esm/entities/vaultV2/vaultV2.js +61 -30
  187. package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
  188. package/lib/esm/errors.d.ts +5 -47
  189. package/lib/esm/errors.js +5 -47
  190. package/lib/esm/fetch.d.ts +5 -17
  191. package/lib/esm/fetch.js +5 -17
  192. package/lib/esm/helpers/constant.d.ts +0 -2
  193. package/lib/esm/helpers/constant.js +0 -2
  194. package/lib/esm/helpers/index.d.ts +2 -3
  195. package/lib/esm/helpers/index.js +2 -3
  196. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +11 -5
  197. package/lib/esm/helpers/slippage.d.ts +1 -103
  198. package/lib/esm/helpers/slippage.js +1 -147
  199. package/lib/esm/helpers/utilization.d.ts +12 -10
  200. package/lib/esm/helpers/utilization.js +26 -11
  201. package/lib/esm/helpers/validate.d.ts +1 -24
  202. package/lib/esm/helpers/validate.js +2 -48
  203. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  204. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  205. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  206. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  207. package/lib/esm/midnight/errors.d.ts +1 -1
  208. package/lib/esm/midnight/errors.js +1 -1
  209. package/lib/esm/types/action.d.ts +17 -65
  210. package/lib/esm/types/action.js +12 -5
  211. package/lib/esm/types/error.d.ts +50 -381
  212. package/lib/esm/types/error.js +58 -377
  213. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  214. package/lib/esm/types.d.ts +2 -18
  215. package/lib/esm/utils.d.ts +10 -35
  216. package/lib/esm/utils.js +9 -34
  217. package/package.json +6 -17
  218. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
  219. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -88
  220. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  221. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -152
  222. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
  223. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -53
  224. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  225. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  226. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  227. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  228. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  229. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  230. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  231. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  232. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
  233. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -45
  234. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  235. package/lib/cjs/actions/signatures/index.js +0 -19
  236. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
  237. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  238. package/lib/cjs/bundler/actions.d.ts +0 -797
  239. package/lib/cjs/bundler/actions.js +0 -1371
  240. package/lib/cjs/bundler/index.d.ts +0 -2
  241. package/lib/cjs/bundler/index.js +0 -18
  242. package/lib/cjs/bundler/types.d.ts +0 -235
  243. package/lib/cjs/bundler/types.js +0 -2
  244. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -332
  245. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -557
  246. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -80
  247. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -245
  248. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
  249. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -84
  250. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  251. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -148
  252. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
  253. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -49
  254. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  255. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  256. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  257. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  258. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  259. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  260. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  261. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  262. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
  263. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -41
  264. package/lib/esm/actions/signatures/index.d.ts +0 -3
  265. package/lib/esm/actions/signatures/index.js +0 -3
  266. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
  267. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -7
  268. package/lib/esm/bundler/actions.d.ts +0 -797
  269. package/lib/esm/bundler/actions.js +0 -1368
  270. package/lib/esm/bundler/index.d.ts +0 -2
  271. package/lib/esm/bundler/index.js +0 -2
  272. package/lib/esm/bundler/types.d.ts +0 -235
  273. package/lib/esm/bundler/types.js +0 -1
  274. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -332
  275. package/lib/esm/entities/vaultV1ReallocationData.js +0 -559
  276. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -80
  277. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -241
@@ -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
  /**
@@ -21,8 +21,6 @@ exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 900000000000000000n;
21
21
  /**
22
22
  * The default target utilization above which shared liquidity reallocations are
23
23
  * triggered (and the level the target market is brought back to), scaled by WAD.
24
- * Still overridable through the deprecated `supplyTargetUtilization` /
25
- * `defaultSupplyTargetUtilization` options until the next major.
26
24
  */
27
25
  exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = 900000000000000000n;
28
26
  /**
@@ -1,12 +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";
4
3
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
5
4
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
6
5
  export { grossFromNetAssets } from "./referralFee.js";
7
6
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
8
- export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinForceWithdrawSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
9
- 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";
10
9
  export { validateOfferSides } from "./validateOfferSides.js";
11
10
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
12
11
  export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinWithdrawSharePrice = exports.computeMinForceWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeVaultV1Reallocations = exports.computeReallocations = void 0;
4
- var computeVaultV1Reallocations_js_1 = require("./computeVaultV1Reallocations.js");
5
- Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeVaultV1Reallocations_js_1.computeReallocations; } });
6
- Object.defineProperty(exports, "computeVaultV1Reallocations", { enumerable: true, get: function () { return computeVaultV1Reallocations_js_1.computeVaultV1Reallocations; } });
3
+ exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = void 0;
7
4
  var constant_js_1 = require("./constant.js");
8
5
  Object.defineProperty(exports, "APPROVE_ONLY_ONCE_TOKENS", { enumerable: true, get: function () { return constant_js_1.APPROVE_ONLY_ONCE_TOKENS; } });
9
6
  Object.defineProperty(exports, "DEFAULT_LLTV_BUFFER", { enumerable: true, get: function () { return constant_js_1.DEFAULT_LLTV_BUFFER; } });
@@ -25,11 +22,7 @@ Object.defineProperty(exports, "grossFromNetAssets", { enumerable: true, get: fu
25
22
  var signAndVerifyTypedData_js_1 = require("./signAndVerifyTypedData.js");
26
23
  Object.defineProperty(exports, "signAndVerifyTypedData", { enumerable: true, get: function () { return signAndVerifyTypedData_js_1.signAndVerifyTypedData; } });
27
24
  var slippage_js_1 = require("./slippage.js");
28
- Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxRepaySharePrice; } });
29
- Object.defineProperty(exports, "computeMaxSupplySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxSupplySharePrice; } });
30
- Object.defineProperty(exports, "computeMinBorrowSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinBorrowSharePrice; } });
31
25
  Object.defineProperty(exports, "computeMinForceWithdrawSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinForceWithdrawSharePrice; } });
32
- Object.defineProperty(exports, "computeMinWithdrawSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinWithdrawSharePrice; } });
33
26
  Object.defineProperty(exports, "computeVaultMaxShareAllowance", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxShareAllowance; } });
34
27
  Object.defineProperty(exports, "computeVaultMaxSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxSharePrice; } });
35
28
  var validate_js_1 = require("./validate.js");
@@ -39,7 +32,6 @@ Object.defineProperty(exports, "validateMidnightMarketChainId", { enumerable: tr
39
32
  Object.defineProperty(exports, "validateNativeAsset", { enumerable: true, get: function () { return validate_js_1.validateNativeAsset; } });
40
33
  Object.defineProperty(exports, "validatePositionHealth", { enumerable: true, get: function () { return validate_js_1.validatePositionHealth; } });
41
34
  Object.defineProperty(exports, "validatePositionHealthAfterWithdraw", { enumerable: true, get: function () { return validate_js_1.validatePositionHealthAfterWithdraw; } });
42
- Object.defineProperty(exports, "validateReallocations", { enumerable: true, get: function () { return validate_js_1.validateReallocations; } });
43
35
  Object.defineProperty(exports, "validateRepayAmount", { enumerable: true, get: function () { return validate_js_1.validateRepayAmount; } });
44
36
  Object.defineProperty(exports, "validateRepayShares", { enumerable: true, get: function () { return validate_js_1.validateRepayShares; } });
45
37
  Object.defineProperty(exports, "validateSlippageTolerance", { enumerable: true, get: function () { return validate_js_1.validateSlippageTolerance; } });
@@ -98,15 +98,21 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
98
98
  // zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
99
99
  // dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
100
100
  // `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
101
- // divides by (accrued to `timestamp` like the plan): a tolerance-free screen clears an exit whose
102
- // realized price is a single RAY-unit, yet the default tolerance scales that below 1 and rounds it
103
- // to zero — so the entity would reject with `VaultV2ForceWithdrawZeroSharePriceError` the very
101
+ // divides by (the larger of the raw snapshot burn and the net burn accrued to `timestamp` like
102
+ // the plan): a tolerance-free screen clears an exit whose realized price is a single RAY-unit, yet
103
+ // the default tolerance scales that below 1 and rounds it to zero — so the entity would reject
104
+ // with `VaultV2ForceWithdrawZeroSharePriceError` the very
104
105
  // `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
105
106
  // entity's own guard. The entity validates this derived value with
106
107
  // `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
107
108
  // cannot fit uint256.
108
109
  const { vault: accruedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(timestamp, vaultData.lastUpdate));
109
- const sharesBurnt = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
110
+ const sharesBurntRaw = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
111
+ vaultData,
112
+ deadlineVaultData: vaultData,
113
+ plan,
114
+ });
115
+ const sharesBurntAccrued = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
110
116
  vaultData: accruedVaultData,
111
117
  deadlineVaultData: accruedVaultData,
112
118
  plan,
@@ -135,7 +141,7 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
135
141
  return undefined;
136
142
  }
137
143
  }
138
- const sharesBurntForFloor = sharesBurnt - feeShares;
144
+ const sharesBurntForFloor = blue_sdk_1.MathLib.max(sharesBurntRaw, sharesBurntAccrued - feeShares);
139
145
  const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
140
146
  ? blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
141
147
  : 0n;
@@ -1,72 +1,4 @@
1
- import { type AccrualVault, AccrualVaultV2, type Market } from "@morpho-org/blue-sdk";
2
- /**
3
- * Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
4
- *
5
- * Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
6
- * ```solidity
7
- * require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
8
- * ```
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.
49
- *
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.
56
- *
57
- * @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.
60
- * @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;
1
+ import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
70
2
  /**
71
3
  * Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
72
4
  *
@@ -113,40 +45,6 @@ export declare function computeMinForceWithdrawSharePrice(params: {
113
45
  readonly sharesBurnt: bigint;
114
46
  readonly slippageTolerance: bigint;
115
47
  }): bigint;
116
- /**
117
- * Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
118
- *
119
- * Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
120
- * ```solidity
121
- * require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
122
- * ```
123
- *
124
- * Supports both assets and shares modes:
125
- * - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
126
- * withdrawer against over-burning shares).
127
- * - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
128
- * amount paid out).
129
- *
130
- * Direction is opposite of supply's `maxSharePrice`:
131
- * - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
132
- * - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
133
- * assets per share burned).
134
- *
135
- * @param params - Computation parameters.
136
- * @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
137
- * @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
138
- * @param params.market - The market to compute the minimum withdraw share price for.
139
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
140
- * @returns `minSharePriceE27` in RAY scale (1e27).
141
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
142
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
143
- */
144
- export declare function computeMinWithdrawSharePrice(params: {
145
- withdrawAssets: bigint;
146
- withdrawShares: bigint;
147
- market: Market;
148
- slippageTolerance: bigint;
149
- }): bigint;
150
48
  /**
151
49
  * Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
152
50
  *
@@ -1,111 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
4
- exports.computeMinBorrowSharePrice = computeMinBorrowSharePrice;
5
- exports.computeMaxRepaySharePrice = computeMaxRepaySharePrice;
6
- exports.computeMaxSupplySharePrice = computeMaxSupplySharePrice;
7
4
  exports.computeMinForceWithdrawSharePrice = computeMinForceWithdrawSharePrice;
8
- exports.computeMinWithdrawSharePrice = computeMinWithdrawSharePrice;
9
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
10
6
  const index_js_1 = require("../types/index.js");
11
7
  const constant_js_1 = require("./constant.js");
12
8
  const validate_js_1 = require("./validate.js");
13
- /**
14
- * Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
15
- *
16
- * Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
17
- * ```solidity
18
- * require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
19
- * ```
20
- *
21
- * @param params - Computation parameters.
22
- * @param params.borrowAmount - The amount of assets to borrow.
23
- * @param params.market - The market to compute the minimum borrow share price for.
24
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
25
- * @returns minSharePriceE27 in RAY scale (1e27).
26
- */
27
- function computeMinBorrowSharePrice(params) {
28
- const { borrowAmount, market, slippageTolerance } = params;
29
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
30
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
31
- }
32
- const expectedShares = market.toBorrowShares(borrowAmount, "Up");
33
- if (expectedShares === 0n) {
34
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
35
- }
36
- return blue_sdk_1.MathLib.mulDivDown(borrowAmount, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), expectedShares);
37
- }
38
- /**
39
- * Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
40
- *
41
- * Supports both repay-by-assets and repay-by-shares paths:
42
- * - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
43
- * - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
44
- *
45
- * Direction is opposite of borrow's `minSharePrice`:
46
- * - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
47
- * - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
48
- *
49
- * Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
50
- *
51
- * @param params - Computation parameters.
52
- * @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
53
- * @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
54
- * @param params.market - The market to compute the maximum repay share price for.
55
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
56
- * @returns maxSharePriceE27 in RAY scale (1e27).
57
- */
58
- function computeMaxRepaySharePrice(params) {
59
- const { repayAssets, repayShares, market, slippageTolerance } = params;
60
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
61
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
62
- }
63
- let assets;
64
- let shares;
65
- if (repayShares > 0n) {
66
- assets = market.toBorrowAssets(repayShares, "Up");
67
- shares = repayShares;
68
- }
69
- else {
70
- assets = repayAssets;
71
- shares = market.toBorrowShares(repayAssets, "Down");
72
- }
73
- if (shares === 0n) {
74
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
75
- }
76
- const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares);
77
- return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
78
- }
79
- /**
80
- * Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
81
- *
82
- * Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
83
- * ```solidity
84
- * require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
85
- * ```
86
- *
87
- * Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
88
- *
89
- * @param params - Computation parameters.
90
- * @param params.supplyAssets - The amount of loan assets to supply.
91
- * @param params.market - The market to compute the maximum supply share price for.
92
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
93
- * @returns `maxSharePriceE27` in RAY scale (1e27).
94
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
95
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
96
- */
97
- function computeMaxSupplySharePrice(params) {
98
- const { supplyAssets, market, slippageTolerance } = params;
99
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
100
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
101
- }
102
- const expectedShares = market.toSupplyShares(supplyAssets, "Down");
103
- if (expectedShares === 0n) {
104
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
105
- }
106
- const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(supplyAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), expectedShares);
107
- return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
108
- }
109
9
  /**
110
10
  * Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
111
11
  *
@@ -170,56 +70,6 @@ function computeMinForceWithdrawSharePrice(params) {
170
70
  }
171
71
  return minSharePriceE27;
172
72
  }
173
- /**
174
- * Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
175
- *
176
- * Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
177
- * ```solidity
178
- * require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
179
- * ```
180
- *
181
- * Supports both assets and shares modes:
182
- * - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
183
- * withdrawer against over-burning shares).
184
- * - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
185
- * amount paid out).
186
- *
187
- * Direction is opposite of supply's `maxSharePrice`:
188
- * - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
189
- * - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
190
- * assets per share burned).
191
- *
192
- * @param params - Computation parameters.
193
- * @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
194
- * @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
195
- * @param params.market - The market to compute the minimum withdraw share price for.
196
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
197
- * @returns `minSharePriceE27` in RAY scale (1e27).
198
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
199
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
200
- */
201
- function computeMinWithdrawSharePrice(params) {
202
- const { withdrawAssets, withdrawShares, market, slippageTolerance } = params;
203
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
204
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
205
- }
206
- let assets;
207
- let shares;
208
- if (withdrawShares > 0n) {
209
- assets = market.toSupplyAssets(withdrawShares, "Down");
210
- shares = withdrawShares;
211
- }
212
- else {
213
- assets = withdrawAssets;
214
- shares = market.toSupplyShares(withdrawAssets, "Up");
215
- }
216
- // Dust shares can round to `assets === 0n` here, which would make
217
- // `minSharePriceE27 = 0` and silently nullify the on-chain slippage cap.
218
- if (shares === 0n || assets === 0n) {
219
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
220
- }
221
- return blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
222
- }
223
73
  /**
224
74
  * Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
225
75
  *
@@ -1,12 +1,14 @@
1
- import type { MarketId } from "@morpho-org/blue-sdk";
2
- import type { ReallocationComputeOptions } from "../types/index.js";
3
1
  /**
4
- * Resolves the effective supply target utilization for a market: the per-market
5
- * override, then the global default override, then
6
- * {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
7
- *
8
- * @param marketId - The market whose supply target utilization to resolve.
9
- * @param options - Reallocation options carrying the per-market and default overrides.
10
- * @returns The supply target utilization, scaled by WAD.
2
+ * Resolves and validates a source withdrawal utilization ceiling.
3
+ * @internal
4
+ * @param value - Optional WAD-scaled utilization ceiling.
5
+ * @param field - Option name reported in validation errors.
6
+ * @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
7
+ * @throws {NegativeInputError} when the ceiling is negative.
8
+ * @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
9
+ * @example
10
+ * ```ts
11
+ * const ceiling = resolveMaxWithdrawalUtilization(undefined);
12
+ * ```
11
13
  */
12
- export declare const getSupplyTargetUtilization: (marketId: MarketId, options?: ReallocationComputeOptions) => bigint;
14
+ export declare const resolveMaxWithdrawalUtilization: (value: bigint | undefined, field?: "maxWithdrawalUtilization" | "defaultMaxWithdrawalUtilization") => bigint;
@@ -1,17 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSupplyTargetUtilization = void 0;
3
+ exports.resolveMaxWithdrawalUtilization = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ const index_js_1 = require("../types/index.js");
4
6
  const constant_js_1 = require("./constant.js");
5
7
  /**
6
- * Resolves the effective supply target utilization for a market: the per-market
7
- * override, then the global default override, then
8
- * {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
9
- *
10
- * @param marketId - The market whose supply target utilization to resolve.
11
- * @param options - Reallocation options carrying the per-market and default overrides.
12
- * @returns The supply target utilization, scaled by WAD.
8
+ * Resolves and validates a source withdrawal utilization ceiling.
9
+ * @internal
10
+ * @param value - Optional WAD-scaled utilization ceiling.
11
+ * @param field - Option name reported in validation errors.
12
+ * @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
13
+ * @throws {NegativeInputError} when the ceiling is negative.
14
+ * @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
15
+ * @example
16
+ * ```ts
17
+ * const ceiling = resolveMaxWithdrawalUtilization(undefined);
18
+ * ```
13
19
  */
14
- const getSupplyTargetUtilization = (marketId, options) => options?.supplyTargetUtilization?.[marketId] ??
15
- options?.defaultSupplyTargetUtilization ??
16
- constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION;
17
- exports.getSupplyTargetUtilization = getSupplyTargetUtilization;
20
+ const resolveMaxWithdrawalUtilization = (value, field = "maxWithdrawalUtilization") => {
21
+ const utilization = value ?? constant_js_1.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION;
22
+ if (utilization < 0n)
23
+ throw new index_js_1.NegativeInputError(field, utilization);
24
+ if (utilization > blue_sdk_1.MathLib.WAD)
25
+ throw new index_js_1.InputExceedsMaxError({
26
+ field,
27
+ value: utilization,
28
+ max: blue_sdk_1.MathLib.WAD,
29
+ });
30
+ return utilization;
31
+ };
32
+ exports.resolveMaxWithdrawalUtilization = resolveMaxWithdrawalUtilization;
@@ -1,7 +1,7 @@
1
1
  import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
2
  import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
3
3
  import { type Address } from "viem";
4
- import { type VaultV1Reallocation, type VaultV2BlueReallocation } from "../types/index.js";
4
+ import { type VaultV2BlueReallocation } from "../types/index.js";
5
5
  /** @internal */
6
6
  export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1;
7
7
  /**
@@ -209,29 +209,6 @@ export declare const validateRepayShares: (params: {
209
209
  repayShares: bigint;
210
210
  marketId: MarketId;
211
211
  }) => void;
212
- /**
213
- * Validates that Vault V1 PublicAllocator reallocations are well-formed.
214
- *
215
- * @param reallocations - Vault V1 reallocations to validate.
216
- * @param targetMarketId - The operation's target market ID.
217
- * @returns Nothing when every reallocation is valid.
218
- * @throws {NegativeInputError} when a reallocation fee is negative.
219
- * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
220
- * @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
221
- * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
222
- * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
223
- * @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
224
- * reallocations for new integrations.
225
- * @example
226
- * ```ts
227
- * import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
228
- * import { validateReallocations } from "@morpho-org/morpho-sdk";
229
- * import { zeroHash } from "viem";
230
- *
231
- * const result: void = validateReallocations([], zeroHash as BlueMarketId);
232
- * ```
233
- */
234
- export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
235
212
  /** @internal */
236
213
  export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
237
214
  /**
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = exports.compareMarketIds = void 0;
3
+ exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = exports.compareMarketIds = void 0;
4
4
  exports.validateUserAddress = validateUserAddress;
5
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
@@ -335,53 +335,6 @@ const validateRepayShares = (params) => {
335
335
  }
336
336
  };
337
337
  exports.validateRepayShares = validateRepayShares;
338
- /**
339
- * Validates that Vault V1 PublicAllocator reallocations are well-formed.
340
- *
341
- * @param reallocations - Vault V1 reallocations to validate.
342
- * @param targetMarketId - The operation's target market ID.
343
- * @returns Nothing when every reallocation is valid.
344
- * @throws {NegativeInputError} when a reallocation fee is negative.
345
- * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
346
- * @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
347
- * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
348
- * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
349
- * @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
350
- * reallocations for new integrations.
351
- * @example
352
- * ```ts
353
- * import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
354
- * import { validateReallocations } from "@morpho-org/morpho-sdk";
355
- * import { zeroHash } from "viem";
356
- *
357
- * const result: void = validateReallocations([], zeroHash as BlueMarketId);
358
- * ```
359
- */
360
- const validateReallocations = (reallocations, targetMarketId) => {
361
- for (const reallocation of reallocations) {
362
- if (reallocation.fee < 0n) {
363
- throw new index_js_1.NegativeInputError("reallocation.fee", reallocation.fee);
364
- }
365
- if (reallocation.withdrawals.length === 0) {
366
- throw new index_js_1.EmptyReallocationWithdrawalsError(reallocation.vault);
367
- }
368
- let previousMarketId;
369
- for (const withdrawal of reallocation.withdrawals) {
370
- if (withdrawal.amount <= 0n) {
371
- throw new index_js_1.NonPositiveInputError(`reallocation.withdrawals[${withdrawal.marketParams.id}].amount`, withdrawal.amount);
372
- }
373
- if (withdrawal.marketParams.id === targetMarketId) {
374
- throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(reallocation.vault, withdrawal.marketParams.id);
375
- }
376
- if (previousMarketId !== undefined &&
377
- (0, exports.compareMarketIds)(withdrawal.marketParams.id, previousMarketId) <= 0) {
378
- throw new index_js_1.UnsortedReallocationWithdrawalsError(reallocation.vault, withdrawal.marketParams.id);
379
- }
380
- previousMarketId = withdrawal.marketParams.id;
381
- }
382
- }
383
- };
384
- exports.validateReallocations = validateReallocations;
385
338
  /** @internal */
386
339
  const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
387
340
  const penaltyByVault = new Map();
@@ -393,7 +346,7 @@ const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
393
346
  reallocation === null ||
394
347
  "withdrawals" in reallocation ||
395
348
  "fee" in reallocation) {
396
- throw new index_js_1.InvalidReallocationShapeError();
349
+ throw new index_js_1.InvalidVaultV2BlueReallocationShapeError();
397
350
  }
398
351
  if (typeof reallocation.vault !== "string" ||
399
352
  !(0, viem_1.isAddress)(reallocation.vault)) {
@@ -1,6 +1,6 @@
1
1
  import { type Address } from "@morpho-org/blue-sdk";
2
2
  /** Supported spender slots that can be validated against the chain address registry. */
3
- export type RequirementSpenderKey = "generalAdapter1" | "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
3
+ export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
4
4
  /**
5
5
  * Validates that a requirement encoder spender matches one of the allowed chain addresses.
6
6
  *
@@ -27,9 +27,8 @@ const index_js_1 = require("../types/index.js");
27
27
  * ```
28
28
  */
29
29
  const validateRequirementSpender = (params) => {
30
- const { permit2, midnight, midnightBundles, bundler3: { generalAdapter1 }, bundles, } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
30
+ const { permit2, midnight, midnightBundles, bundles } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
31
31
  const addresses = {
32
- generalAdapter1,
33
32
  permit2,
34
33
  midnight,
35
34
  midnightBundles,
@@ -42,7 +41,6 @@ const validateRequirementSpender = (params) => {
42
41
  throw new index_js_1.UnsupportedErc20ApprovalSpenderError({
43
42
  spender: params.spender,
44
43
  chainId: params.chainId,
45
- generalAdapter1,
46
44
  permit2,
47
45
  midnight,
48
46
  midnightBundles,