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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/MIGRATION-v5-to-v6.md +199 -34
  2. package/README.md +23 -15
  3. package/lib/cjs/abis.d.ts +3 -2829
  4. package/lib/cjs/abis.js +1 -1938
  5. package/lib/cjs/actions/blue/borrow.d.ts +3 -2
  6. package/lib/cjs/actions/blue/borrow.js +3 -2
  7. package/lib/cjs/actions/blue/common.js +6 -35
  8. package/lib/cjs/actions/blue/refinance.d.ts +2 -2
  9. package/lib/cjs/actions/blue/refinance.js +2 -2
  10. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  11. package/lib/cjs/actions/blue/repay.js +1 -1
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  14. package/lib/cjs/actions/blue/supply.d.ts +2 -2
  15. package/lib/cjs/actions/blue/supply.js +4 -9
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
  17. package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
  20. package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
  21. package/lib/cjs/actions/blue/withdraw.js +3 -3
  22. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
  23. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  24. package/lib/cjs/actions/bundles/common.d.ts +38 -4
  25. package/lib/cjs/actions/bundles/common.js +91 -35
  26. package/lib/cjs/actions/index.d.ts +0 -1
  27. package/lib/cjs/actions/index.js +0 -1
  28. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
  30. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  31. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  32. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  33. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  40. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  41. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  42. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  43. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  44. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  45. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  46. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  47. package/lib/cjs/actions/requirements/index.js +0 -1
  48. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  49. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  50. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
  51. package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
  52. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  53. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  54. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  55. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  56. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
  57. package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
  58. package/lib/cjs/augment.d.ts +0 -1
  59. package/lib/cjs/augment.js +0 -1
  60. package/lib/cjs/blue/abis.d.ts +1 -1
  61. package/lib/cjs/blue/abis.js +1 -5
  62. package/lib/cjs/blue/entities.d.ts +2 -2
  63. package/lib/cjs/blue/entities.js +1 -2
  64. package/lib/cjs/blue/errors.d.ts +1 -1
  65. package/lib/cjs/blue/errors.js +2 -1
  66. package/lib/cjs/blue/fetch.d.ts +1 -1
  67. package/lib/cjs/blue/fetch.js +1 -2
  68. package/lib/cjs/blue/types.d.ts +2 -4
  69. package/lib/cjs/blue/utils.d.ts +1 -3
  70. package/lib/cjs/blue/utils.js +1 -3
  71. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  72. package/lib/cjs/client/morphoViemExtension.js +1 -1
  73. package/lib/cjs/constants.d.ts +3 -37
  74. package/lib/cjs/constants.js +1 -39
  75. package/lib/cjs/entities/blue/blue.d.ts +38 -264
  76. package/lib/cjs/entities/blue/blue.js +2 -203
  77. package/lib/cjs/entities/index.d.ts +3 -60
  78. package/lib/cjs/entities/index.js +1 -20
  79. package/lib/cjs/entities/midnight/midnight.js +20 -24
  80. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  81. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  82. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  83. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  84. package/lib/cjs/entities/requirements/index.js +1 -0
  85. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
  86. package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
  87. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
  88. package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
  89. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  90. package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
  91. package/lib/cjs/errors.d.ts +2 -46
  92. package/lib/cjs/errors.js +2 -46
  93. package/lib/cjs/fetch.d.ts +1 -15
  94. package/lib/cjs/fetch.js +1 -16
  95. package/lib/cjs/helpers/constant.d.ts +0 -2
  96. package/lib/cjs/helpers/constant.js +0 -2
  97. package/lib/cjs/helpers/index.d.ts +4 -3
  98. package/lib/cjs/helpers/index.js +10 -9
  99. package/lib/cjs/helpers/metadata.d.ts +3 -5
  100. package/lib/cjs/helpers/metadata.js +4 -6
  101. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  102. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  103. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  104. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  105. package/lib/cjs/helpers/slippage.d.ts +34 -90
  106. package/lib/cjs/helpers/slippage.js +52 -137
  107. package/lib/cjs/helpers/utilization.d.ts +12 -10
  108. package/lib/cjs/helpers/utilization.js +27 -12
  109. package/lib/cjs/helpers/validate.d.ts +66 -32
  110. package/lib/cjs/helpers/validate.js +84 -57
  111. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  112. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  113. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  114. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  115. package/lib/cjs/types/action.d.ts +102 -68
  116. package/lib/cjs/types/action.js +11 -4
  117. package/lib/cjs/types/error.d.ts +332 -385
  118. package/lib/cjs/types/error.js +369 -412
  119. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  120. package/lib/cjs/types.d.ts +2 -18
  121. package/lib/cjs/utils.d.ts +8 -35
  122. package/lib/cjs/utils.js +11 -36
  123. package/lib/esm/abis.d.ts +3 -2829
  124. package/lib/esm/abis.js +3 -1935
  125. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/borrow.js +3 -2
  127. package/lib/esm/actions/blue/common.js +8 -37
  128. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  129. package/lib/esm/actions/blue/refinance.js +2 -2
  130. package/lib/esm/actions/blue/repay.d.ts +1 -1
  131. package/lib/esm/actions/blue/repay.js +1 -1
  132. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  133. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  134. package/lib/esm/actions/blue/supply.d.ts +2 -2
  135. package/lib/esm/actions/blue/supply.js +6 -11
  136. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  137. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  138. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  139. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  140. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  141. package/lib/esm/actions/blue/withdraw.js +3 -3
  142. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  143. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  144. package/lib/esm/actions/bundles/common.d.ts +38 -4
  145. package/lib/esm/actions/bundles/common.js +91 -36
  146. package/lib/esm/actions/index.d.ts +0 -1
  147. package/lib/esm/actions/index.js +0 -1
  148. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  149. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
  150. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  151. package/lib/esm/actions/requirements/blue/index.js +0 -1
  152. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  153. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
  154. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  155. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  157. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
  158. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  159. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  160. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  161. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  162. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  163. package/lib/esm/actions/requirements/encode/index.js +0 -1
  164. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  165. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  166. package/lib/esm/actions/requirements/index.d.ts +0 -1
  167. package/lib/esm/actions/requirements/index.js +0 -1
  168. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  169. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  170. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
  171. package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
  172. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  173. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  174. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  175. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  176. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
  177. package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
  178. package/lib/esm/augment.d.ts +0 -1
  179. package/lib/esm/augment.js +0 -1
  180. package/lib/esm/blue/abis.d.ts +1 -1
  181. package/lib/esm/blue/abis.js +1 -1
  182. package/lib/esm/blue/entities.d.ts +2 -2
  183. package/lib/esm/blue/entities.js +1 -1
  184. package/lib/esm/blue/errors.d.ts +1 -1
  185. package/lib/esm/blue/errors.js +1 -1
  186. package/lib/esm/blue/fetch.d.ts +1 -1
  187. package/lib/esm/blue/fetch.js +1 -1
  188. package/lib/esm/blue/types.d.ts +2 -4
  189. package/lib/esm/blue/utils.d.ts +1 -3
  190. package/lib/esm/blue/utils.js +1 -3
  191. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  192. package/lib/esm/client/morphoViemExtension.js +1 -1
  193. package/lib/esm/constants.d.ts +3 -37
  194. package/lib/esm/constants.js +3 -37
  195. package/lib/esm/entities/blue/blue.d.ts +38 -264
  196. package/lib/esm/entities/blue/blue.js +5 -206
  197. package/lib/esm/entities/index.d.ts +3 -60
  198. package/lib/esm/entities/index.js +1 -16
  199. package/lib/esm/entities/midnight/midnight.js +20 -24
  200. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  202. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  203. package/lib/esm/entities/requirements/index.d.ts +1 -0
  204. package/lib/esm/entities/requirements/index.js +1 -0
  205. package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
  206. package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
  207. package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
  208. package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
  209. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  210. package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
  211. package/lib/esm/errors.d.ts +2 -46
  212. package/lib/esm/errors.js +2 -46
  213. package/lib/esm/fetch.d.ts +1 -15
  214. package/lib/esm/fetch.js +1 -15
  215. package/lib/esm/helpers/constant.d.ts +0 -2
  216. package/lib/esm/helpers/constant.js +0 -2
  217. package/lib/esm/helpers/index.d.ts +4 -3
  218. package/lib/esm/helpers/index.js +4 -3
  219. package/lib/esm/helpers/metadata.d.ts +3 -5
  220. package/lib/esm/helpers/metadata.js +4 -6
  221. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  222. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  223. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  224. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  225. package/lib/esm/helpers/slippage.d.ts +34 -90
  226. package/lib/esm/helpers/slippage.js +52 -134
  227. package/lib/esm/helpers/utilization.d.ts +12 -10
  228. package/lib/esm/helpers/utilization.js +26 -11
  229. package/lib/esm/helpers/validate.d.ts +66 -32
  230. package/lib/esm/helpers/validate.js +83 -57
  231. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  232. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  233. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  234. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  235. package/lib/esm/types/action.d.ts +102 -68
  236. package/lib/esm/types/action.js +12 -5
  237. package/lib/esm/types/error.d.ts +332 -385
  238. package/lib/esm/types/error.js +355 -392
  239. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  240. package/lib/esm/types.d.ts +2 -18
  241. package/lib/esm/utils.d.ts +8 -35
  242. package/lib/esm/utils.js +7 -34
  243. package/package.json +7 -15
  244. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  245. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
  246. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  247. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
  248. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  249. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
  250. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  251. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  252. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  253. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  254. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  255. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  256. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  257. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  258. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  259. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
  260. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  261. package/lib/cjs/actions/signatures/index.js +0 -19
  262. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  263. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  264. package/lib/cjs/bundler/actions.d.ts +0 -797
  265. package/lib/cjs/bundler/actions.js +0 -1371
  266. package/lib/cjs/bundler/index.d.ts +0 -2
  267. package/lib/cjs/bundler/index.js +0 -18
  268. package/lib/cjs/bundler/types.d.ts +0 -235
  269. package/lib/cjs/bundler/types.js +0 -2
  270. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
  271. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
  272. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
  273. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
  274. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  275. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
  276. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  277. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
  278. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  279. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
  280. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  281. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  282. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  283. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  284. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  285. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  286. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  287. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  288. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  289. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
  290. package/lib/esm/actions/signatures/index.d.ts +0 -3
  291. package/lib/esm/actions/signatures/index.js +0 -3
  292. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  293. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
  294. package/lib/esm/bundler/actions.d.ts +0 -797
  295. package/lib/esm/bundler/actions.js +0 -1368
  296. package/lib/esm/bundler/index.d.ts +0 -2
  297. package/lib/esm/bundler/index.js +0 -2
  298. package/lib/esm/bundler/types.d.ts +0 -235
  299. package/lib/esm/bundler/types.js +0 -1
  300. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
  301. package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
  302. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
  303. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
  304. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  305. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -1,105 +1,49 @@
1
- import { type AccrualVault, AccrualVaultV2, type Market } from "@morpho-org/blue-sdk";
1
+ import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
2
2
  /**
3
- * Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
3
+ * Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
4
4
  *
5
- * Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
5
+ * Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
6
6
  * ```solidity
7
- * require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
7
+ * require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
8
8
  * ```
9
9
  *
10
- * @param params - Computation parameters.
11
- * @param params.borrowAmount - The amount of assets to borrow.
12
- * @param params.market - The market to compute the minimum borrow share price for.
13
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
14
- * @returns minSharePriceE27 in RAY scale (1e27).
15
- */
16
- export declare function computeMinBorrowSharePrice(params: {
17
- borrowAmount: bigint;
18
- market: Market;
19
- slippageTolerance: bigint;
20
- }): bigint;
21
- /**
22
- * Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
23
- *
24
- * Supports both repay-by-assets and repay-by-shares paths:
25
- * - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
26
- * - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
27
- *
28
- * Direction is opposite of borrow's `minSharePrice`:
29
- * - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
30
- * - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
31
- *
32
- * Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
33
- *
34
- * @param params - Computation parameters.
35
- * @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
36
- * @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
37
- * @param params.market - The market to compute the maximum repay share price for.
38
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
39
- * @returns maxSharePriceE27 in RAY scale (1e27).
40
- */
41
- export declare function computeMaxRepaySharePrice(params: {
42
- repayAssets: bigint;
43
- repayShares: bigint;
44
- market: Market;
45
- slippageTolerance: bigint;
46
- }): bigint;
47
- /**
48
- * Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
10
+ * The realized price sits structurally *below* the vault's share price because the
11
+ * force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
12
+ * from the raw share price would reject every penalised exit. Both inputs are therefore taken from
13
+ * the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
14
+ * `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
15
+ * faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
16
+ * shifting from the penalty-free leg to the penalised leg all do.
49
17
  *
50
- * Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
51
- * ```solidity
52
- * require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
53
- * ```
54
- *
55
- * Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
18
+ * The referral fee is deducted *after* this check, so it is outside the bound's protection.
56
19
  *
57
20
  * @param params - Computation parameters.
58
- * @param params.supplyAssets - The amount of loan assets to supply.
59
- * @param params.market - The market to compute the maximum supply share price for.
21
+ * @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
22
+ * @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
60
23
  * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
61
- * @returns `maxSharePriceE27` in RAY scale (1e27).
62
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
63
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
64
- */
65
- export declare function computeMaxSupplySharePrice(params: {
66
- supplyAssets: bigint;
67
- market: Market;
68
- slippageTolerance: bigint;
69
- }): bigint;
70
- /**
71
- * Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
24
+ * @returns `minSharePriceE27` in RAY scale (1e27).
25
+ * @throws {NegativeInputError} when `slippageTolerance` is negative.
26
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
27
+ * `MAX_SLIPPAGE_TOLERANCE`.
28
+ * @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
29
+ * would silently nullify the on-chain bound.
30
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
31
+ * would nullify the bound just as a non-positive input would.
32
+ * @example
33
+ * ```ts
34
+ * import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
72
35
  *
73
- * Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
74
- * ```solidity
75
- * require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
36
+ * const minSharePriceE27 = computeMinForceWithdrawSharePrice({
37
+ * withdrawnAssets: plan.withdrawnAssets,
38
+ * sharesBurnt,
39
+ * slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
40
+ * });
76
41
  * ```
77
- *
78
- * Supports both assets and shares modes:
79
- * - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
80
- * withdrawer against over-burning shares).
81
- * - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
82
- * amount paid out).
83
- *
84
- * Direction is opposite of supply's `maxSharePrice`:
85
- * - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
86
- * - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
87
- * assets per share burned).
88
- *
89
- * @param params - Computation parameters.
90
- * @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
91
- * @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
92
- * @param params.market - The market to compute the minimum withdraw share price for.
93
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
94
- * @returns `minSharePriceE27` in RAY scale (1e27).
95
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
96
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
97
42
  */
98
- export declare function computeMinWithdrawSharePrice(params: {
99
- withdrawAssets: bigint;
100
- withdrawShares: bigint;
101
- market: Market;
102
- slippageTolerance: bigint;
43
+ export declare function computeMinForceWithdrawSharePrice(params: {
44
+ readonly withdrawnAssets: bigint;
45
+ readonly sharesBurnt: bigint;
46
+ readonly slippageTolerance: bigint;
103
47
  }): bigint;
104
48
  /**
105
49
  * Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
@@ -1,159 +1,74 @@
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
- exports.computeMinWithdrawSharePrice = computeMinWithdrawSharePrice;
4
+ exports.computeMinForceWithdrawSharePrice = computeMinForceWithdrawSharePrice;
8
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
9
6
  const index_js_1 = require("../types/index.js");
10
7
  const constant_js_1 = require("./constant.js");
11
8
  const validate_js_1 = require("./validate.js");
12
9
  /**
13
- * Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
10
+ * Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
14
11
  *
15
- * Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
12
+ * Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
16
13
  * ```solidity
17
- * require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
14
+ * require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
18
15
  * ```
19
16
  *
20
- * @param params - Computation parameters.
21
- * @param params.borrowAmount - The amount of assets to borrow.
22
- * @param params.market - The market to compute the minimum borrow share price for.
23
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
24
- * @returns minSharePriceE27 in RAY scale (1e27).
25
- */
26
- function computeMinBorrowSharePrice(params) {
27
- const { borrowAmount, market, slippageTolerance } = params;
28
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
29
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
30
- }
31
- const expectedShares = market.toBorrowShares(borrowAmount, "Up");
32
- if (expectedShares === 0n) {
33
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
34
- }
35
- return blue_sdk_1.MathLib.mulDivDown(borrowAmount, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), expectedShares);
36
- }
37
- /**
38
- * Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
39
- *
40
- * Supports both repay-by-assets and repay-by-shares paths:
41
- * - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
42
- * - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
43
- *
44
- * Direction is opposite of borrow's `minSharePrice`:
45
- * - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
46
- * - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
47
- *
48
- * Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
49
- *
50
- * @param params - Computation parameters.
51
- * @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
52
- * @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
53
- * @param params.market - The market to compute the maximum repay share price for.
54
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
55
- * @returns maxSharePriceE27 in RAY scale (1e27).
56
- */
57
- function computeMaxRepaySharePrice(params) {
58
- const { repayAssets, repayShares, market, slippageTolerance } = params;
59
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
60
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
61
- }
62
- let assets;
63
- let shares;
64
- if (repayShares > 0n) {
65
- assets = market.toBorrowAssets(repayShares, "Up");
66
- shares = repayShares;
67
- }
68
- else {
69
- assets = repayAssets;
70
- shares = market.toBorrowShares(repayAssets, "Down");
71
- }
72
- if (shares === 0n) {
73
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
74
- }
75
- const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares);
76
- return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
77
- }
78
- /**
79
- * Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
80
- *
81
- * Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
82
- * ```solidity
83
- * require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
84
- * ```
17
+ * The realized price sits structurally *below* the vault's share price because the
18
+ * force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
19
+ * from the raw share price would reject every penalised exit. Both inputs are therefore taken from
20
+ * the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
21
+ * `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
22
+ * faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
23
+ * shifting from the penalty-free leg to the penalised leg all do.
85
24
  *
86
- * Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
25
+ * The referral fee is deducted *after* this check, so it is outside the bound's protection.
87
26
  *
88
27
  * @param params - Computation parameters.
89
- * @param params.supplyAssets - The amount of loan assets to supply.
90
- * @param params.market - The market to compute the maximum supply share price for.
28
+ * @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
29
+ * @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
91
30
  * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
92
- * @returns `maxSharePriceE27` in RAY scale (1e27).
93
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
94
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
95
- */
96
- function computeMaxSupplySharePrice(params) {
97
- const { supplyAssets, market, slippageTolerance } = params;
98
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
99
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
100
- }
101
- const expectedShares = market.toSupplyShares(supplyAssets, "Down");
102
- if (expectedShares === 0n) {
103
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
104
- }
105
- const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(supplyAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), expectedShares);
106
- return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
107
- }
108
- /**
109
- * Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
31
+ * @returns `minSharePriceE27` in RAY scale (1e27).
32
+ * @throws {NegativeInputError} when `slippageTolerance` is negative.
33
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
34
+ * `MAX_SLIPPAGE_TOLERANCE`.
35
+ * @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
36
+ * would silently nullify the on-chain bound.
37
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
38
+ * would nullify the bound just as a non-positive input would.
39
+ * @example
40
+ * ```ts
41
+ * import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
110
42
  *
111
- * Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
112
- * ```solidity
113
- * require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
43
+ * const minSharePriceE27 = computeMinForceWithdrawSharePrice({
44
+ * withdrawnAssets: plan.withdrawnAssets,
45
+ * sharesBurnt,
46
+ * slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
47
+ * });
114
48
  * ```
115
- *
116
- * Supports both assets and shares modes:
117
- * - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
118
- * withdrawer against over-burning shares).
119
- * - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
120
- * amount paid out).
121
- *
122
- * Direction is opposite of supply's `maxSharePrice`:
123
- * - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
124
- * - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
125
- * assets per share burned).
126
- *
127
- * @param params - Computation parameters.
128
- * @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
129
- * @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
130
- * @param params.market - The market to compute the minimum withdraw share price for.
131
- * @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
132
- * @returns `minSharePriceE27` in RAY scale (1e27).
133
- * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
134
- * @throws {ShareDivideByZeroError} when expected shares round down to zero.
135
49
  */
136
- function computeMinWithdrawSharePrice(params) {
137
- const { withdrawAssets, withdrawShares, market, slippageTolerance } = params;
138
- if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
139
- throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
140
- }
141
- let assets;
142
- let shares;
143
- if (withdrawShares > 0n) {
144
- assets = market.toSupplyAssets(withdrawShares, "Down");
145
- shares = withdrawShares;
146
- }
147
- else {
148
- assets = withdrawAssets;
149
- shares = market.toSupplyShares(withdrawAssets, "Up");
150
- }
151
- // Dust shares can round to `assets === 0n` here, which would make
152
- // `minSharePriceE27 = 0` and silently nullify the on-chain slippage cap.
153
- if (shares === 0n || assets === 0n) {
154
- throw new index_js_1.ShareDivideByZeroError(market.params.id);
155
- }
156
- return blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
50
+ function computeMinForceWithdrawSharePrice(params) {
51
+ const { withdrawnAssets, sharesBurnt, slippageTolerance } = params;
52
+ (0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
53
+ // A zero on either side would yield `minSharePriceE27 = 0`, i.e. no bound at all.
54
+ if (withdrawnAssets <= 0n) {
55
+ throw new index_js_1.NonPositiveInputError("withdrawnAssets", withdrawnAssets);
56
+ }
57
+ if (sharesBurnt <= 0n) {
58
+ throw new index_js_1.NonPositiveInputError("sharesBurnt", sharesBurnt);
59
+ }
60
+ const minSharePriceE27 = blue_sdk_1.MathLib.mulDivDown(withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), sharesBurnt);
61
+ // Positive inputs are not enough: the ratio itself can round down to zero once the burn exceeds
62
+ // what the withdrawn assets can price at RAY scale, which would reintroduce the very opt-out the
63
+ // guards above exist to prevent.
64
+ if (minSharePriceE27 === 0n) {
65
+ throw new index_js_1.VaultV2ForceWithdrawZeroSharePriceError({
66
+ withdrawnAssets,
67
+ sharesBurnt,
68
+ slippageTolerance,
69
+ });
70
+ }
71
+ return minSharePriceE27;
157
72
  }
158
73
  /**
159
74
  * Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
@@ -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
  /**
@@ -17,6 +17,41 @@ export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0
17
17
  * @internal
18
18
  */
19
19
  export declare const validateUint256Field: (field: string, value: bigint) => void;
20
+ /**
21
+ * Rejects a deadline that no periphery can honour: the contracts read `0` as "unset" and the ABI
22
+ * slot is a `uint256`. Callers that also need the deadline to be in the future layer their own
23
+ * `ExpiredDeadlineError` on top — this check stays clock-free so transaction builders can use it.
24
+ *
25
+ * @param deadline - Candidate deadline, in seconds.
26
+ * @returns Nothing when `deadline` is a positive `uint256`.
27
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
28
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `maxUint256`.
29
+ * @internal
30
+ */
31
+ export declare const validateDeadline: (deadline: bigint) => void;
32
+ /**
33
+ * Validates an optional referral fee and returns the pair every referral-fee-bearing periphery
34
+ * encodes. Shared by the direct BlueBundlesV1 writes and the VaultExitBundlesV1 force withdrawal,
35
+ * whose contracts apply the same `[0, WAD)` bound and both transfer the fee unconditionally.
36
+ *
37
+ * @param params - Referral fee inputs.
38
+ * @param params.referralFeePct - Optional WAD-scaled fee share. Defaults to `0n`.
39
+ * @param params.referralFeeRecipient - Optional fee recipient. Defaults to the zero address, which
40
+ * is only valid alongside a zero `referralFeePct`.
41
+ * @returns The normalized `{ referralFeePct, referralFeeRecipient }` pair.
42
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
43
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contracts reject
44
+ * it with `PctExceeded`); it extends `InputExceedsMaxError`, preserving that pattern-match.
45
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
46
+ * @internal
47
+ */
48
+ export declare const validateReferralFee: (params: {
49
+ readonly referralFeePct?: bigint;
50
+ readonly referralFeeRecipient?: Address;
51
+ }) => {
52
+ readonly referralFeePct: bigint;
53
+ readonly referralFeeRecipient: Address;
54
+ };
20
55
  /**
21
56
  * Validates that a raw or hydrated Midnight market belongs to the expected chain.
22
57
  *
@@ -36,22 +71,44 @@ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput
36
71
  * Asserts that the client has a connected account AND that it matches
37
72
  * the provided user address.
38
73
  *
39
- * Used internally by the signature requirements (`encodeErc20Permit`,
40
- * `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
41
- * the signing flow is the only path where an account/address mismatch
42
- * is a real security concern (rather than just an integrator footgun).
74
+ * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
75
+ * backs the permit, Permit2, Blue authorization, and Midnight offer-root
76
+ * signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
77
+ * signer: the signing flow is
78
+ * the only path where an account/address mismatch is a real security concern
79
+ * (rather than just an integrator footgun).
43
80
  *
44
81
  * Transaction builders no longer call this helper — callers are
45
82
  * responsible for keeping `userAddress` aligned with the signing account
46
83
  * at the builder layer.
47
84
  *
48
- * Throws {@link MissingClientPropertyError} if the client has no account.
49
- * Throws {@link AddressMismatchError} if the client account differs from
50
- * `userAddress`.
51
- *
52
85
  * @param clientAccountAddress - The client's account address; if undefined,
53
86
  * `MissingClientPropertyError` is thrown.
54
87
  * @param userAddress - The user address provided by the caller.
88
+ * @returns Nothing; narrows `clientAccountAddress` to a defined `Address` when
89
+ * it is present and equal to `userAddress`.
90
+ * @throws {MissingClientPropertyError} when the client has no connected account.
91
+ * @throws {AddressMismatchError} when the client account differs from
92
+ * `userAddress`.
93
+ * @example
94
+ * ```ts
95
+ * import { createWalletClient, http } from "viem";
96
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
97
+ * import { mainnet } from "viem/chains";
98
+ * import { validateUserAddress } from "@morpho-org/morpho-sdk";
99
+ *
100
+ * const account = privateKeyToAccount(generatePrivateKey());
101
+ * const walletClient = createWalletClient({
102
+ * account,
103
+ * chain: mainnet,
104
+ * transport: http(),
105
+ * });
106
+ *
107
+ * // Inside a `sign()` flow, before producing a typed-data signature:
108
+ * validateUserAddress(walletClient.account?.address, account.address);
109
+ * // Passes when the connected account equals the expected signer;
110
+ * // throws if the wallet has no account or signs for a different address.
111
+ * ```
55
112
  */
56
113
  export declare function validateUserAddress(clientAccountAddress: Address | undefined, userAddress: Address): asserts clientAccountAddress is Address;
57
114
  /**
@@ -152,29 +209,6 @@ export declare const validateRepayShares: (params: {
152
209
  repayShares: bigint;
153
210
  marketId: MarketId;
154
211
  }) => void;
155
- /**
156
- * Validates that Vault V1 PublicAllocator reallocations are well-formed.
157
- *
158
- * @param reallocations - Vault V1 reallocations to validate.
159
- * @param targetMarketId - The operation's target market ID.
160
- * @returns Nothing when every reallocation is valid.
161
- * @throws {NegativeInputError} when a reallocation fee is negative.
162
- * @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
163
- * @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
164
- * @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
165
- * @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
166
- * @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
167
- * reallocations for new integrations.
168
- * @example
169
- * ```ts
170
- * import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
171
- * import { validateReallocations } from "@morpho-org/morpho-sdk";
172
- * import { zeroHash } from "viem";
173
- *
174
- * const result: void = validateReallocations([], zeroHash as BlueMarketId);
175
- * ```
176
- */
177
- export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
178
212
  /** @internal */
179
213
  export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
180
214
  /**