@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
@@ -95,15 +95,21 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
95
95
  // zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
96
96
  // dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
97
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
98
+ // divides by (the larger of the raw snapshot burn and the net burn accrued to `timestamp` like
99
+ // the plan): a tolerance-free screen clears an exit whose realized price is a single RAY-unit, yet
100
+ // the default tolerance scales that below 1 and rounds it to zero — so the entity would reject
101
+ // with `VaultV2ForceWithdrawZeroSharePriceError` the very
101
102
  // `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
102
103
  // entity's own guard. The entity validates this derived value with
103
104
  // `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
104
105
  // cannot fit uint256.
105
106
  const { vault: accruedVaultData } = vaultData.accrueInterest(MathLib.max(timestamp, vaultData.lastUpdate));
106
- const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
107
+ const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
108
+ vaultData,
109
+ deadlineVaultData: vaultData,
110
+ plan,
111
+ });
112
+ const sharesBurntAccrued = computeVaultV2ForceWithdrawSharesBurnt({
107
113
  vaultData: accruedVaultData,
108
114
  deadlineVaultData: accruedVaultData,
109
115
  plan,
@@ -132,7 +138,7 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
132
138
  return undefined;
133
139
  }
134
140
  }
135
- const sharesBurntForFloor = sharesBurnt - feeShares;
141
+ const sharesBurntForFloor = MathLib.max(sharesBurntRaw, sharesBurntAccrued - feeShares);
136
142
  const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
137
143
  ? MathLib.mulDivDown(plan.withdrawnAssets, MathLib.wToRay(MathLib.WAD - DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
138
144
  : 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,103 +1,7 @@
1
1
  import { AccrualVaultV2, MathLib, } from "@morpho-org/blue-sdk";
2
- import { ExcessiveSlippageToleranceError, NonPositiveInputError, ShareDivideByZeroError, VaultV2ForceWithdrawZeroSharePriceError, } from "../types/index.js";
2
+ import { NonPositiveInputError, VaultV2ForceWithdrawZeroSharePriceError, } from "../types/index.js";
3
3
  import { MAX_ABSOLUTE_SHARE_PRICE } from "./constant.js";
4
4
  import { validateSlippageTolerance } from "./validate.js";
5
- /**
6
- * Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
7
- *
8
- * Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
9
- * ```solidity
10
- * require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
11
- * ```
12
- *
13
- * @param params - Computation parameters.
14
- * @param params.borrowAmount - The amount of assets to borrow.
15
- * @param params.market - The market to compute the minimum borrow share price for.
16
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
17
- * @returns minSharePriceE27 in RAY scale (1e27).
18
- */
19
- export function computeMinBorrowSharePrice(params) {
20
- const { borrowAmount, market, slippageTolerance } = params;
21
- if (slippageTolerance >= MathLib.WAD) {
22
- throw new ExcessiveSlippageToleranceError(slippageTolerance);
23
- }
24
- const expectedShares = market.toBorrowShares(borrowAmount, "Up");
25
- if (expectedShares === 0n) {
26
- throw new ShareDivideByZeroError(market.params.id);
27
- }
28
- return MathLib.mulDivDown(borrowAmount, MathLib.wToRay(MathLib.WAD - slippageTolerance), expectedShares);
29
- }
30
- /**
31
- * Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
32
- *
33
- * Supports both repay-by-assets and repay-by-shares paths:
34
- * - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
35
- * - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
36
- *
37
- * Direction is opposite of borrow's `minSharePrice`:
38
- * - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
39
- * - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
40
- *
41
- * Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
42
- *
43
- * @param params - Computation parameters.
44
- * @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
45
- * @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
46
- * @param params.market - The market to compute the maximum repay share price for.
47
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
48
- * @returns maxSharePriceE27 in RAY scale (1e27).
49
- */
50
- export function computeMaxRepaySharePrice(params) {
51
- const { repayAssets, repayShares, market, slippageTolerance } = params;
52
- if (slippageTolerance >= MathLib.WAD) {
53
- throw new ExcessiveSlippageToleranceError(slippageTolerance);
54
- }
55
- let assets;
56
- let shares;
57
- if (repayShares > 0n) {
58
- assets = market.toBorrowAssets(repayShares, "Up");
59
- shares = repayShares;
60
- }
61
- else {
62
- assets = repayAssets;
63
- shares = market.toBorrowShares(repayAssets, "Down");
64
- }
65
- if (shares === 0n) {
66
- throw new ShareDivideByZeroError(market.params.id);
67
- }
68
- const maxSharePrice = MathLib.mulDivUp(assets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares);
69
- return MathLib.min(maxSharePrice, MAX_ABSOLUTE_SHARE_PRICE);
70
- }
71
- /**
72
- * Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
73
- *
74
- * Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
75
- * ```solidity
76
- * require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
77
- * ```
78
- *
79
- * Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
80
- *
81
- * @param params - Computation parameters.
82
- * @param params.supplyAssets - The amount of loan assets to supply.
83
- * @param params.market - The market to compute the maximum supply share price for.
84
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
85
- * @returns `maxSharePriceE27` in RAY scale (1e27).
86
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
87
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
88
- */
89
- export function computeMaxSupplySharePrice(params) {
90
- const { supplyAssets, market, slippageTolerance } = params;
91
- if (slippageTolerance >= MathLib.WAD) {
92
- throw new ExcessiveSlippageToleranceError(slippageTolerance);
93
- }
94
- const expectedShares = market.toSupplyShares(supplyAssets, "Down");
95
- if (expectedShares === 0n) {
96
- throw new ShareDivideByZeroError(market.params.id);
97
- }
98
- const maxSharePrice = MathLib.mulDivUp(supplyAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), expectedShares);
99
- return MathLib.min(maxSharePrice, MAX_ABSOLUTE_SHARE_PRICE);
100
- }
101
5
  /**
102
6
  * Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
103
7
  *
@@ -162,56 +66,6 @@ export function computeMinForceWithdrawSharePrice(params) {
162
66
  }
163
67
  return minSharePriceE27;
164
68
  }
165
- /**
166
- * Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
167
- *
168
- * Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
169
- * ```solidity
170
- * require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
171
- * ```
172
- *
173
- * Supports both assets and shares modes:
174
- * - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
175
- * withdrawer against over-burning shares).
176
- * - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
177
- * amount paid out).
178
- *
179
- * Direction is opposite of supply's `maxSharePrice`:
180
- * - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
181
- * - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
182
- * assets per share burned).
183
- *
184
- * @param params - Computation parameters.
185
- * @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
186
- * @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
187
- * @param params.market - The market to compute the minimum withdraw share price for.
188
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
189
- * @returns `minSharePriceE27` in RAY scale (1e27).
190
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
191
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
192
- */
193
- export function computeMinWithdrawSharePrice(params) {
194
- const { withdrawAssets, withdrawShares, market, slippageTolerance } = params;
195
- if (slippageTolerance >= MathLib.WAD) {
196
- throw new ExcessiveSlippageToleranceError(slippageTolerance);
197
- }
198
- let assets;
199
- let shares;
200
- if (withdrawShares > 0n) {
201
- assets = market.toSupplyAssets(withdrawShares, "Down");
202
- shares = withdrawShares;
203
- }
204
- else {
205
- assets = withdrawAssets;
206
- shares = market.toSupplyShares(withdrawAssets, "Up");
207
- }
208
- // Dust shares can round to `assets === 0n` here, which would make
209
- // `minSharePriceE27 = 0` and silently nullify the on-chain slippage cap.
210
- if (shares === 0n || assets === 0n) {
211
- throw new ShareDivideByZeroError(market.params.id);
212
- }
213
- return MathLib.mulDivDown(assets, MathLib.wToRay(MathLib.WAD - slippageTolerance), shares);
214
- }
215
69
  /**
216
70
  * Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
217
71
  *
@@ -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,13 +1,28 @@
1
- import { DEFAULT_SUPPLY_TARGET_UTILIZATION } from "./constant.js";
1
+ import { MathLib } from "@morpho-org/blue-sdk";
2
+ import { InputExceedsMaxError, NegativeInputError } from "../types/index.js";
3
+ import { DEFAULT_WITHDRAWAL_TARGET_UTILIZATION } from "./constant.js";
2
4
  /**
3
- * Resolves the effective supply target utilization for a market: the per-market
4
- * override, then the global default override, then
5
- * {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
6
- *
7
- * @param marketId - The market whose supply target utilization to resolve.
8
- * @param options - Reallocation options carrying the per-market and default overrides.
9
- * @returns The supply target utilization, scaled by WAD.
5
+ * Resolves and validates a source withdrawal utilization ceiling.
6
+ * @internal
7
+ * @param value - Optional WAD-scaled utilization ceiling.
8
+ * @param field - Option name reported in validation errors.
9
+ * @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
10
+ * @throws {NegativeInputError} when the ceiling is negative.
11
+ * @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
12
+ * @example
13
+ * ```ts
14
+ * const ceiling = resolveMaxWithdrawalUtilization(undefined);
15
+ * ```
10
16
  */
11
- export const getSupplyTargetUtilization = (marketId, options) => options?.supplyTargetUtilization?.[marketId] ??
12
- options?.defaultSupplyTargetUtilization ??
13
- DEFAULT_SUPPLY_TARGET_UTILIZATION;
17
+ export const resolveMaxWithdrawalUtilization = (value, field = "maxWithdrawalUtilization") => {
18
+ const utilization = value ?? DEFAULT_WITHDRAWAL_TARGET_UTILIZATION;
19
+ if (utilization < 0n)
20
+ throw new NegativeInputError(field, utilization);
21
+ if (utilization > MathLib.WAD)
22
+ throw new InputExceedsMaxError({
23
+ field,
24
+ value: utilization,
25
+ max: MathLib.WAD,
26
+ });
27
+ return utilization;
28
+ };
@@ -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,7 +1,7 @@
1
1
  import { getChainAddresses, MarketUtils, MathLib, ORACLE_PRICE_SCALE, } from "@morpho-org/blue-sdk";
2
2
  import { isDefined } from "@morpho-org/morpho-ts";
3
3
  import { isAddress, isAddressEqual, maxUint128, maxUint256, zeroAddress, } from "viem";
4
- import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidReallocationAddressError, InvalidReallocationShapeError, InvalidReallocationSourceTypeError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
4
+ import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidReallocationAddressError, InvalidReallocationSourceTypeError, InvalidVaultV2BlueReallocationShapeError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
5
5
  import { DEFAULT_LLTV_BUFFER, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, } from "./constant.js";
6
6
  /** @internal */
7
7
  export const compareMarketIds = (idA, idB) => {
@@ -318,52 +318,6 @@ export const validateRepayShares = (params) => {
318
318
  });
319
319
  }
320
320
  };
321
- /**
322
- * Validates that Vault V1 PublicAllocator reallocations are well-formed.
323
- *
324
- * @param reallocations - Vault V1 reallocations to validate.
325
- * @param targetMarketId - The operation's target market ID.
326
- * @returns Nothing when every reallocation is valid.
327
- * @throws {NegativeInputError} when a reallocation fee is negative.
328
- * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
329
- * @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
330
- * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
331
- * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
332
- * @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
333
- * reallocations for new integrations.
334
- * @example
335
- * ```ts
336
- * import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
337
- * import { validateReallocations } from "@morpho-org/morpho-sdk";
338
- * import { zeroHash } from "viem";
339
- *
340
- * const result: void = validateReallocations([], zeroHash as BlueMarketId);
341
- * ```
342
- */
343
- export const validateReallocations = (reallocations, targetMarketId) => {
344
- for (const reallocation of reallocations) {
345
- if (reallocation.fee < 0n) {
346
- throw new NegativeInputError("reallocation.fee", reallocation.fee);
347
- }
348
- if (reallocation.withdrawals.length === 0) {
349
- throw new EmptyReallocationWithdrawalsError(reallocation.vault);
350
- }
351
- let previousMarketId;
352
- for (const withdrawal of reallocation.withdrawals) {
353
- if (withdrawal.amount <= 0n) {
354
- throw new NonPositiveInputError(`reallocation.withdrawals[${withdrawal.marketParams.id}].amount`, withdrawal.amount);
355
- }
356
- if (withdrawal.marketParams.id === targetMarketId) {
357
- throw new ReallocationWithdrawalOnTargetMarketError(reallocation.vault, withdrawal.marketParams.id);
358
- }
359
- if (previousMarketId !== undefined &&
360
- compareMarketIds(withdrawal.marketParams.id, previousMarketId) <= 0) {
361
- throw new UnsortedReallocationWithdrawalsError(reallocation.vault, withdrawal.marketParams.id);
362
- }
363
- previousMarketId = withdrawal.marketParams.id;
364
- }
365
- }
366
- };
367
321
  /** @internal */
368
322
  export const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
369
323
  const penaltyByVault = new Map();
@@ -375,7 +329,7 @@ export const validateVaultV2BlueReallocations = (reallocations, targetMarketId)
375
329
  reallocation === null ||
376
330
  "withdrawals" in reallocation ||
377
331
  "fee" in reallocation) {
378
- throw new InvalidReallocationShapeError();
332
+ throw new InvalidVaultV2BlueReallocationShapeError();
379
333
  }
380
334
  if (typeof reallocation.vault !== "string" ||
381
335
  !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
  *
@@ -24,9 +24,8 @@ import { UnsupportedErc20ApprovalSpenderError } from "../types/index.js";
24
24
  * ```
25
25
  */
26
26
  export const validateRequirementSpender = (params) => {
27
- const { permit2, midnight, midnightBundles, bundler3: { generalAdapter1 }, bundles, } = getChainAddresses(params.chainId);
27
+ const { permit2, midnight, midnightBundles, bundles } = getChainAddresses(params.chainId);
28
28
  const addresses = {
29
- generalAdapter1,
30
29
  permit2,
31
30
  midnight,
32
31
  midnightBundles,
@@ -39,7 +38,6 @@ export const validateRequirementSpender = (params) => {
39
38
  throw new UnsupportedErc20ApprovalSpenderError({
40
39
  spender: params.spender,
41
40
  chainId: params.chainId,
42
- generalAdapter1,
43
41
  permit2,
44
42
  midnight,
45
43
  midnightBundles,
@@ -192,23 +192,34 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
192
192
  * The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
193
193
  * burn the realized exit price is measured against. It takes the max over the two supplied snapshots
194
194
  * because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
195
- * execution. The entity passes both accrued to `now` (execution time): the raw `lastUpdate` snapshot
196
- * underestimates the burn a stale fee-bearing vault realizes — the first withdrawal accrues pending
197
- * management fees before burning shares — which lifts the floor above the faithful price and trips
198
- * `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`, tracks execution without
199
- * letting a long deadline silently weaken the guard; `slippageTolerance` absorbs the residual drift
200
- * until inclusion. Pass distinct snapshots to bound the burn across an accrual window.
195
+ * execution. The entity passes the raw `lastUpdate` snapshot and the same vault accrued to `now`
196
+ * (execution time): the raw snapshot underestimates the burn a stale fee-bearing vault realizes —
197
+ * the first withdrawal accrues pending management fees before burning shares — while the `now`
198
+ * accrual underestimates it when it projects interest the chain has not realized (a wall clock
199
+ * running ahead of the chain, or a capped `maxRate`); either alone would lift the floor above the
200
+ * faithful price and trip `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`,
201
+ * tracks execution without letting a long deadline silently weaken the guard; `slippageTolerance`
202
+ * absorbs the residual drift until inclusion.
201
203
  *
202
- * This is **not** the share allowance to authorize. The price floor's denominator is this bound
203
- * minus `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`: the
204
- * contract measures the *net* burn, which fee mints to `owner` shrink. The allowance is
205
- * `min(mulDivUp(exitAssets, RAY, minSharePriceE27) + computeVaultV2ForceWithdrawFeeSharesMinted({
206
- * vaultData, owner, timestamp: deadline }), maxUint256)`: the permit pays for the *gross* burn.
204
+ * This is **not** the share allowance to authorize. The contract measures the *net* burn, which
205
+ * fee mints to `owner` shrink, and the raw snapshot mints none while the `now` accrual mints
206
+ * `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`; so the
207
+ * entity nets each endpoint before taking the max (`max(burnRaw, burnNow - feeSharesNow)`) rather
208
+ * than subtracting the `now` fee from a gross max. The allowance is
209
+ * `min(max(mulDivUp(exitAssets, RAY, max(min(mulDivDown(minSharePriceE27, WAD - slippageTolerance,
210
+ * WAD), minSharePriceE27 - 1), 1)), mulDivUp(exitAssets, RAY, minSharePriceE27) + 1)
211
+ * + computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: deadline }),
212
+ * maxUint256)`: the permit pays for the *gross* burn, covering a burn at least one tolerance step
213
+ * below the floor whenever the floor exceeds one RAY unit and, in any case, at least one share
214
+ * above the burn at the floor, so a price within that headroom below the floor reverts on the
215
+ * contract's `minSharePriceE27` check rather than on the allowance; a deeper drop can still
216
+ * surface as an ERC-20 allowance underflow.
207
217
  *
208
218
  * @param params - Share-bound inputs.
209
219
  * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
210
220
  * @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
211
- * share burns is returned. The entity passes the `now`-accrued snapshot for both.
221
+ * share burns is returned. The entity calls this twice — the raw snapshot for both parameters,
222
+ * then the `now` accrual for both — and nets each result before taking the max.
212
223
  * @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
213
224
  * @returns An upper bound, in vault shares, of what the exit burns.
214
225
  * @example
@@ -220,7 +231,12 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
220
231
  * } from "@morpho-org/morpho-sdk";
221
232
  *
222
233
  * const { vault: nowVaultData } = vaultData.accrueInterest(now);
223
- * const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
234
+ * const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
235
+ * vaultData,
236
+ * deadlineVaultData: vaultData,
237
+ * plan,
238
+ * });
239
+ * const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
224
240
  * vaultData: nowVaultData,
225
241
  * deadlineVaultData: nowVaultData,
226
242
  * plan,
@@ -230,9 +246,26 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
230
246
  * owner,
231
247
  * timestamp: now,
232
248
  * });
233
- * const sharesBurntForFloor = sharesBurnt - feeSharesNow;
249
+ * const sharesBurntForFloor = MathLib.max(
250
+ * sharesBurntRaw,
251
+ * sharesBurntNow - feeSharesNow,
252
+ * );
253
+ * const allowanceSharePriceE27 = MathLib.max(
254
+ * MathLib.min(
255
+ * MathLib.mulDivDown(
256
+ * minSharePriceE27,
257
+ * MathLib.WAD - slippageTolerance,
258
+ * MathLib.WAD,
259
+ * ),
260
+ * minSharePriceE27 - 1n,
261
+ * ),
262
+ * 1n,
263
+ * );
234
264
  * const requiredShareAllowance = MathLib.min(
235
- * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) +
265
+ * MathLib.max(
266
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
267
+ * MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
268
+ * ) +
236
269
  * computeVaultV2ForceWithdrawFeeSharesMinted({
237
270
  * vaultData,
238
271
  * owner,