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

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 (296) hide show
  1. package/MIGRATION-v5-to-v6.md +329 -15
  2. package/README.md +93 -47
  3. package/lib/cjs/abis.d.ts +227 -2
  4. package/lib/cjs/abis.js +156 -3
  5. package/lib/cjs/actions/blue/borrow.d.ts +1 -1
  6. package/lib/cjs/actions/blue/borrow.js +1 -1
  7. package/lib/cjs/actions/blue/common.d.ts +6 -19
  8. package/lib/cjs/actions/blue/common.js +28 -162
  9. package/lib/cjs/actions/blue/refinance.d.ts +1 -1
  10. package/lib/cjs/actions/blue/refinance.js +1 -1
  11. package/lib/cjs/actions/blue/repay.d.ts +3 -3
  12. package/lib/cjs/actions/blue/repay.js +1 -1
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
  15. package/lib/cjs/actions/blue/supply.d.ts +3 -3
  16. package/lib/cjs/actions/blue/supply.js +3 -8
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
  18. package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
  21. package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
  22. package/lib/cjs/actions/blue/withdraw.js +1 -1
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
  25. package/lib/cjs/actions/bundles/common.d.ts +230 -0
  26. package/lib/cjs/actions/bundles/common.js +507 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +1 -0
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  41. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
  42. package/lib/cjs/actions/requirements/blue/index.js +0 -2
  43. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  44. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  45. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  46. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  51. package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  52. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -1
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  58. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  59. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  60. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
  61. package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
  62. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  64. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
  65. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  66. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  67. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  68. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  69. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  70. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  71. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  72. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  73. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  74. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  75. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  76. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  77. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  78. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  79. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  80. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  81. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  82. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  83. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  84. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  85. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  86. package/lib/cjs/blue/abis.d.ts +5 -1
  87. package/lib/cjs/blue/abis.js +2 -0
  88. package/lib/cjs/blue/entities.d.ts +8 -2
  89. package/lib/cjs/blue/entities.js +1 -0
  90. package/lib/cjs/blue/errors.d.ts +1 -1
  91. package/lib/cjs/blue/errors.js +2 -1
  92. package/lib/cjs/blue/fetch.d.ts +3 -1
  93. package/lib/cjs/blue/fetch.js +1 -0
  94. package/lib/cjs/entities/blue/blue.d.ts +29 -20
  95. package/lib/cjs/entities/blue/blue.js +6 -1
  96. package/lib/cjs/entities/index.d.ts +9 -2
  97. package/lib/cjs/entities/index.js +16 -0
  98. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  99. package/lib/cjs/entities/midnight/midnight.js +20 -24
  100. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  101. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
  102. package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  103. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  104. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  105. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  106. package/lib/cjs/entities/requirements/index.d.ts +2 -0
  107. package/lib/cjs/entities/requirements/index.js +18 -0
  108. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
  109. package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
  110. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  111. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  112. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
  113. package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
  114. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  115. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  116. package/lib/cjs/errors.d.ts +1 -1
  117. package/lib/cjs/errors.js +3 -2
  118. package/lib/cjs/fetch.d.ts +3 -1
  119. package/lib/cjs/fetch.js +1 -0
  120. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  121. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  122. package/lib/cjs/helpers/index.d.ts +4 -1
  123. package/lib/cjs/helpers/index.js +14 -1
  124. package/lib/cjs/helpers/metadata.d.ts +3 -5
  125. package/lib/cjs/helpers/metadata.js +4 -6
  126. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  127. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  128. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  129. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  130. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  131. package/lib/cjs/helpers/referralFee.js +35 -0
  132. package/lib/cjs/helpers/slippage.d.ts +136 -1
  133. package/lib/cjs/helpers/slippage.js +188 -0
  134. package/lib/cjs/helpers/validate.d.ts +67 -8
  135. package/lib/cjs/helpers/validate.js +94 -9
  136. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  137. package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
  138. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  139. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  140. package/lib/cjs/index.d.ts +1 -0
  141. package/lib/cjs/index.js +1 -0
  142. package/lib/cjs/types/action.d.ts +273 -82
  143. package/lib/cjs/types/action.js +12 -12
  144. package/lib/cjs/types/error.d.ts +349 -23
  145. package/lib/cjs/types/error.js +393 -39
  146. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  147. package/lib/cjs/utils.d.ts +3 -1
  148. package/lib/cjs/utils.js +10 -1
  149. package/lib/esm/abis.d.ts +227 -2
  150. package/lib/esm/abis.js +157 -2
  151. package/lib/esm/actions/blue/borrow.d.ts +1 -1
  152. package/lib/esm/actions/blue/borrow.js +1 -1
  153. package/lib/esm/actions/blue/common.d.ts +6 -19
  154. package/lib/esm/actions/blue/common.js +30 -164
  155. package/lib/esm/actions/blue/refinance.d.ts +1 -1
  156. package/lib/esm/actions/blue/refinance.js +1 -1
  157. package/lib/esm/actions/blue/repay.d.ts +3 -3
  158. package/lib/esm/actions/blue/repay.js +1 -1
  159. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  160. package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
  161. package/lib/esm/actions/blue/supply.d.ts +3 -3
  162. package/lib/esm/actions/blue/supply.js +5 -10
  163. package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
  164. package/lib/esm/actions/blue/supplyCollateral.js +1 -1
  165. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  166. package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
  167. package/lib/esm/actions/blue/withdraw.d.ts +1 -1
  168. package/lib/esm/actions/blue/withdraw.js +1 -1
  169. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  170. package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
  171. package/lib/esm/actions/bundles/common.d.ts +230 -0
  172. package/lib/esm/actions/bundles/common.js +494 -0
  173. package/lib/esm/actions/bundles/index.d.ts +3 -0
  174. package/lib/esm/actions/bundles/index.js +2 -0
  175. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  176. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  177. package/lib/esm/actions/index.d.ts +1 -0
  178. package/lib/esm/actions/index.js +1 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  180. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  181. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  182. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  183. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  184. package/lib/esm/actions/midnight/takeLend.js +2 -2
  185. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  186. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  187. package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
  188. package/lib/esm/actions/requirements/blue/index.js +0 -2
  189. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  190. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
  191. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  192. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  194. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
  195. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  196. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  197. package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  198. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
  199. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  200. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  201. package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
  202. package/lib/esm/actions/requirements/encode/index.js +1 -1
  203. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  204. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  205. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  206. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
  207. package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
  208. package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
  209. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  210. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
  211. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  212. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  213. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  214. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  215. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  216. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  217. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  218. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  219. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  220. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  221. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  222. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  223. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  224. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  225. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  226. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  227. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  228. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  229. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  230. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  231. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  232. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  233. package/lib/esm/blue/abis.d.ts +5 -1
  234. package/lib/esm/blue/abis.js +5 -1
  235. package/lib/esm/blue/entities.d.ts +8 -2
  236. package/lib/esm/blue/entities.js +3 -1
  237. package/lib/esm/blue/errors.d.ts +1 -1
  238. package/lib/esm/blue/errors.js +1 -1
  239. package/lib/esm/blue/fetch.d.ts +3 -1
  240. package/lib/esm/blue/fetch.js +3 -1
  241. package/lib/esm/entities/blue/blue.d.ts +29 -20
  242. package/lib/esm/entities/blue/blue.js +7 -2
  243. package/lib/esm/entities/index.d.ts +9 -2
  244. package/lib/esm/entities/index.js +4 -1
  245. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  246. package/lib/esm/entities/midnight/midnight.js +20 -24
  247. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  248. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
  249. package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  250. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  251. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  252. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  253. package/lib/esm/entities/requirements/index.d.ts +2 -0
  254. package/lib/esm/entities/requirements/index.js +2 -0
  255. package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
  256. package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
  257. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  258. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  259. package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
  260. package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
  261. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  262. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  263. package/lib/esm/errors.d.ts +1 -1
  264. package/lib/esm/errors.js +1 -1
  265. package/lib/esm/fetch.d.ts +3 -1
  266. package/lib/esm/fetch.js +3 -1
  267. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  268. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  269. package/lib/esm/helpers/index.d.ts +4 -1
  270. package/lib/esm/helpers/index.js +4 -1
  271. package/lib/esm/helpers/metadata.d.ts +3 -5
  272. package/lib/esm/helpers/metadata.js +4 -6
  273. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  274. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  275. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  276. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  277. package/lib/esm/helpers/referralFee.d.ts +21 -0
  278. package/lib/esm/helpers/referralFee.js +31 -0
  279. package/lib/esm/helpers/slippage.d.ts +136 -1
  280. package/lib/esm/helpers/slippage.js +186 -2
  281. package/lib/esm/helpers/validate.d.ts +67 -8
  282. package/lib/esm/helpers/validate.js +92 -10
  283. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  284. package/lib/esm/helpers/validateRequirementSpender.js +1 -0
  285. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  286. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  287. package/lib/esm/index.d.ts +1 -0
  288. package/lib/esm/index.js +1 -0
  289. package/lib/esm/types/action.d.ts +273 -82
  290. package/lib/esm/types/action.js +11 -11
  291. package/lib/esm/types/error.d.ts +349 -23
  292. package/lib/esm/types/error.js +377 -31
  293. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  294. package/lib/esm/utils.d.ts +3 -1
  295. package/lib/esm/utils.js +3 -1
  296. package/package.json +7 -7
@@ -104,7 +104,11 @@ const cloneAdapter = (adapter, markets) => {
104
104
  if (adapter instanceof AccrualVaultV2MorphoMarketV1Adapter)
105
105
  return new AccrualVaultV2MorphoMarketV1Adapter({ ...base, marketParamsList: [...adapter.marketParamsList] }, adapter.positions.map((position) => clonePosition(position, markets)));
106
106
  if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter)
107
- return new AccrualVaultV2MorphoVaultV1Adapter({ ...base, morphoVaultV1: adapter.morphoVaultV1 }, cloneAccrualVault(adapter.accrualVaultV1, markets), adapter.shares);
107
+ return new AccrualVaultV2MorphoVaultV1Adapter({
108
+ ...base,
109
+ morphoVaultV1: adapter.morphoVaultV1,
110
+ parentAllocation: adapter.parentAllocation,
111
+ }, cloneAccrualVault(adapter.accrualVaultV1, markets), adapter.shares);
108
112
  throw new UnsupportedVaultV2AdapterError(adapter.address);
109
113
  };
110
114
  const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
@@ -568,7 +572,11 @@ export class VaultV2BlueReallocationData {
568
572
  * utilization defaults to 90% and is configurable through
569
573
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
570
574
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
571
- * considered.
575
+ * considered. Targets with no remaining supply or allocator capacity are skipped before
576
+ * projecting source interest. The adapter's minimum share minting requirement, supply-share
577
+ * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
578
+ * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
579
+ * allocation does not increase after rounding.
572
580
  *
573
581
  * Shared-cap discovery is conservative. Operation planning searches at most
574
582
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -579,6 +587,7 @@ export class VaultV2BlueReallocationData {
579
587
  * @param marketId - Target Blue market id.
580
588
  * @param options - Optional discovery controls and operation to support.
581
589
  * @returns Flat action-ready reallocations and their post-simulation state.
590
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
582
591
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
583
592
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
584
593
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
@@ -719,9 +728,7 @@ export class VaultV2BlueReallocationData {
719
728
  : BigInt(options.timestamp);
720
729
  let data = this;
721
730
  let simulationContext = context;
722
- data.setMarkets(Object.values(data.markets)
723
- .filter((market) => market != null)
724
- .map((market) => market.accrueInterest(timestamp)));
731
+ data.setMarkets([data.getMarket(marketId).accrueInterest(timestamp)]);
725
732
  const reallocations = [];
726
733
  const configuredVaults = Object.keys(data.vaults);
727
734
  const vaultKeyByLower = new Map(configuredVaults.map((vault) => [vault.toLowerCase(), vault]));
@@ -756,6 +763,7 @@ export class VaultV2BlueReallocationData {
756
763
  activeAdaptersCache.set(vaultAddress, activeAdapters);
757
764
  }
758
765
  const targetSupplyHeadroom = MathLib.zeroFloorSub(MathLib.MAX_UINT_128, targetMarket.totalSupplyAssets);
766
+ const minimumSupply = targetMarket.supply(1n, 0n);
759
767
  const rawCandidates = [];
760
768
  // Missing nested allocator state means the snapshot is incomplete, so
761
769
  // typed getter errors below must propagate. Only explicit zero caps or
@@ -777,17 +785,35 @@ export class VaultV2BlueReallocationData {
777
785
  const adapterCapAllocation = data.getAllocation(vaultAddress, adapterCapId);
778
786
  const collateralCapAllocation = data.getAllocation(vaultAddress, collateralCapId);
779
787
  const adapterMarketCapAllocation = data.getAllocation(vaultAddress, adapterMarketCapId);
780
- if ([
788
+ const targetAllocations = [
781
789
  adapterCapAllocation,
782
790
  collateralCapAllocation,
783
791
  adapterMarketCapAllocation,
784
- ].some(({ absoluteCap }) => absoluteCap === 0n))
792
+ ];
793
+ if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
785
794
  continue;
786
795
  const expectedSupplyAssets = targetMarket.toSupplyAssets(adapter.supplyShares[marketId] ?? 0n);
787
796
  const untracked = MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
788
797
  const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation + untracked);
798
+ const minimumAllocation = minimumSupply.market.toSupplyAssets((adapter.supplyShares[marketId] ?? 0n) + minimumSupply.shares);
799
+ const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
800
+ const blockedTargetIds = targetAllocations
801
+ .filter(({ allocation, absoluteCap, relativeCap }) => {
802
+ const nextAllocation = allocation + minimumAllocationChange;
803
+ return (nextAllocation > absoluteCap ||
804
+ (relativeCap === 0n && nextAllocation > 0n));
805
+ })
806
+ .map(({ id }) => id);
807
+ // MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
808
+ if (targetSupplyHeadroom === 0n ||
809
+ allocatorHeadroom === 0n ||
810
+ minimumSupply.shares < minimumSupply.assets ||
811
+ minimumSupply.market.totalSupplyShares > MathLib.MAX_UINT_128 ||
812
+ blockedTargetIds.includes(adapterMarketCapId))
813
+ continue;
789
814
  if (publicAllocatorConfig.canPullFromIdle &&
790
- availableIdleAssets > 0n) {
815
+ availableIdleAssets > 0n &&
816
+ blockedTargetIds.length === 0) {
791
817
  const assets = MathLib.min(MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
792
818
  if (assets > 0n) {
793
819
  rawCandidates.push({
@@ -823,8 +849,16 @@ export class VaultV2BlueReallocationData {
823
849
  const sourceAllocations = sourceIds.map((id) => data.getAllocation(vaultAddress, id));
824
850
  if (sourceAllocations.some(({ allocation }) => allocation === 0n))
825
851
  continue;
826
- const expectedSourceSupplyAssets = sourceMarket.toSupplyAssets(sourceAdapter.supplyShares[sourceMarket.id] ?? 0n);
827
- const assets = MathLib.min(MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, expectedSourceSupplyAssets, sourceMarket.getWithdrawToUtilization(maxWithdrawalUtilization));
852
+ const sourceSupplyShares = sourceAdapter.supplyShares[sourceMarket.id] ?? 0n;
853
+ if (sourceSupplyShares === 0n)
854
+ continue;
855
+ // A withdrawal can create target headroom only for shared cap IDs.
856
+ if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
857
+ continue;
858
+ const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
859
+ data.setMarkets([accruedSourceMarket]);
860
+ const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
861
+ const assets = MathLib.min(MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, expectedSourceSupplyAssets, accruedSourceMarket.getWithdrawToUtilization(maxWithdrawalUtilization));
828
862
  if (assets <= 0n)
829
863
  continue;
830
864
  rawCandidates.push({
@@ -845,9 +879,6 @@ export class VaultV2BlueReallocationData {
845
879
  for (const reallocation of rawCandidates) {
846
880
  let lower = 0n;
847
881
  let upper = reallocation.assets;
848
- // MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
849
- if (targetMarket.toSupplyShares(upper, "Down") < upper)
850
- continue;
851
882
  const reallocationAdapter = data.getAdapter(reallocation.vault, reallocation.to.adapter);
852
883
  const targetIds = getAdapterIds(adapterIdsCache, reallocationAdapter, targetMarket);
853
884
  const sourceIds = new Set();
@@ -951,6 +982,7 @@ export class VaultV2BlueReallocationData {
951
982
  * @param marketId - Target Blue market id.
952
983
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
953
984
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
985
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
954
986
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
955
987
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
956
988
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -1003,6 +1035,7 @@ export class VaultV2BlueReallocationData {
1003
1035
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
1004
1036
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
1005
1037
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
1038
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1006
1039
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
1007
1040
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
1008
1041
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -14,7 +14,7 @@ UnknownTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError,
14
14
  /** @deprecated Use UnknownBlueTokenPriceError or the raw protocol subpath. */
15
15
  UnknownTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError,
16
16
  /** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
17
- UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
17
+ UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
18
18
  /** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
19
19
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError,
20
20
  /** @deprecated Use UnsupportedBlueVaultV2AdapterError or the raw protocol subpath. */
package/lib/esm/errors.js CHANGED
@@ -14,7 +14,7 @@ UnknownTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError,
14
14
  /** @deprecated Use UnknownBlueTokenPriceError or the raw protocol subpath. */
15
15
  UnknownTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError,
16
16
  /** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
17
- UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
17
+ UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
18
18
  /** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
19
19
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError,
20
20
  /** @deprecated Use UnsupportedBlueVaultV2AdapterError or the raw protocol subpath. */
@@ -12,5 +12,7 @@ fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidatio
12
12
  /** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
13
13
  fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
14
14
  /** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
15
- fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
15
+ fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
16
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
17
+ fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
16
18
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/esm/fetch.js CHANGED
@@ -12,5 +12,7 @@ fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidatio
12
12
  /** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
13
13
  fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
14
14
  /** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
15
- fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
15
+ fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
16
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
17
+ fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
16
18
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
@@ -22,6 +22,7 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
22
22
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
23
23
  * @param params.options - Optional reallocation computation options.
24
24
  * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
25
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
25
26
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
26
27
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
27
28
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -72,6 +73,7 @@ export declare const computeVaultV1Reallocations: ({ reallocationData: data, mar
72
73
  /**
73
74
  * Deprecated name for the Vault V1 amount-aware reallocation planner.
74
75
  *
76
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
75
77
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
76
78
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
77
79
  */
@@ -75,6 +75,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
75
75
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
76
76
  * @param params.options - Optional reallocation computation options.
77
77
  * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
78
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
78
79
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
79
80
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
80
81
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -233,6 +234,7 @@ export const computeVaultV1Reallocations = ({ reallocationData: data, marketId,
233
234
  /**
234
235
  * Deprecated name for the Vault V1 amount-aware reallocation planner.
235
236
  *
237
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
236
238
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
237
239
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
238
240
  */
@@ -1,9 +1,12 @@
1
1
  export { computeReallocations, computeVaultV1Reallocations, } from "./computeVaultV1Reallocations.js";
2
2
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
3
3
  export { addTransactionMetadata } from "./metadata.js";
4
+ export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
4
5
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
6
+ export { grossFromNetAssets } from "./referralFee.js";
5
7
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
6
- export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
8
+ export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinForceWithdrawSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
7
9
  export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
8
10
  export { validateOfferSides } from "./validateOfferSides.js";
9
11
  export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
12
+ export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
@@ -1,9 +1,12 @@
1
1
  export { computeReallocations, computeVaultV1Reallocations, } from "./computeVaultV1Reallocations.js";
2
2
  export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
3
3
  export { addTransactionMetadata } from "./metadata.js";
4
+ export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
4
5
  export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
6
+ export { grossFromNetAssets } from "./referralFee.js";
5
7
  export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
6
- export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
8
+ export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinForceWithdrawSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
7
9
  export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
8
10
  export { validateOfferSides } from "./validateOfferSides.js";
9
11
  export { validateRequirementSpender, } from "./validateRequirementSpender.js";
12
+ export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
@@ -26,11 +26,9 @@ import type { Metadata } from "../types/index.js";
26
26
  * @param {Metadata} metadata - An object containing optional metadata fields
27
27
  * such as `timestamp` and `origin`.
28
28
  *
29
- * @returns {Object} - A new transaction object with the modified `data` field
30
- * including the concatenated metadata.
31
- *
32
- * If no `data` is present in the original transaction, the function returns
33
- * the transaction unmodified.
29
+ * @returns The same `tx` object when `data` is missing, an empty string, or
30
+ * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
+ * with `data` containing any appended metadata. The input is never mutated.
34
32
  */
35
33
  export declare function addTransactionMetadata(tx: {
36
34
  data: Hex;
@@ -26,15 +26,13 @@ import { concatHex, isHex, numberToHex } from "viem";
26
26
  * @param {Metadata} metadata - An object containing optional metadata fields
27
27
  * such as `timestamp` and `origin`.
28
28
  *
29
- * @returns {Object} - A new transaction object with the modified `data` field
30
- * including the concatenated metadata.
31
- *
32
- * If no `data` is present in the original transaction, the function returns
33
- * the transaction unmodified.
29
+ * @returns The same `tx` object when `data` is missing, an empty string, or
30
+ * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
+ * with `data` containing any appended metadata. The input is never mutated.
34
32
  */
35
33
  export function addTransactionMetadata(tx, metadata) {
36
34
  const { data, ..._tx } = tx;
37
- if (!data)
35
+ if (!data || data === "0x")
38
36
  return tx;
39
37
  const concatItems = [data];
40
38
  if (metadata.timestamp) {
@@ -0,0 +1,107 @@
1
+ import { type AccrualVaultV2, type Address } from "@morpho-org/blue-sdk";
2
+ /** Inputs used to preview a Vault V2 force withdrawal. */
3
+ export interface PreviewVaultV2ForceWithdrawParams {
4
+ /** Penalty-inclusive amount the user wants to exit. */
5
+ readonly requestedExitAssets: bigint;
6
+ /** Timestamp used to accrue every Morpho Blue market before converting adapter shares. */
7
+ readonly timestamp: bigint;
8
+ /** Optional adapter override; defaults to the vault's sole adapter. */
9
+ readonly adapter?: Address;
10
+ /**
11
+ * Account that will call `forceWithdraw`; fee-recipient mints are mirrored when provided. The
12
+ * entity projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it.
13
+ */
14
+ readonly userAddress?: Address;
15
+ /**
16
+ * Timestamp the fee-recipient mint guard is projected to; defaults to `timestamp`. Pass the
17
+ * `forceWithdraw` deadline you will submit to mirror the entity's guard exactly. The entity
18
+ * rejects deadlines more than one year after handle creation (`InputExceedsMaxError`) rather
19
+ * than clamping them, so a quote projected past that horizon cannot be submitted. Ignored
20
+ * without `userAddress`.
21
+ */
22
+ readonly feeProjectionTimestamp?: bigint;
23
+ /** Optional WAD-scaled referral fee percentage. Defaults to `0n`. */
24
+ readonly referralFeePct?: bigint;
25
+ /** Optional referral fee recipient. Required when `referralFeePct` is positive, as the entity
26
+ * enforces (`ReferralFeeRecipientMissingError`). When it equals `userAddress`, the fee is paid
27
+ * back to the exiting account and `netAssets` includes it. */
28
+ readonly referralFeeRecipient?: Address;
29
+ }
30
+ /** Frontend-ready preview of a Vault V2 force withdrawal through VaultExitBundlesV1. */
31
+ export interface VaultV2ForceWithdrawPreview {
32
+ /** Largest penalty-inclusive exit the current vault state supports. */
33
+ readonly maxExitAssets: bigint;
34
+ /** Penalty-inclusive exit amount this preview is computed for, capped at `maxExitAssets`. */
35
+ readonly exitAssets: bigint;
36
+ /** Requested penalty-inclusive amount left uncovered by `exitAssets`. */
37
+ readonly remainingExitAssets: bigint;
38
+ /** Portion withdrawn without a force-deallocation penalty (vault idle plus liquidity adapter). */
39
+ readonly assetsToWithdraw: bigint;
40
+ /** Portion force-deallocated from the adapter's markets, net of the penalty. */
41
+ readonly assetsToDeallocate: bigint;
42
+ /**
43
+ * Lower-bound estimate of the assets charged as the force-deallocation penalty,
44
+ * `ceil(assetsToDeallocate × penalty)`. Exact for a single-market exit. Across multiple markets
45
+ * the contract charges `Σ ceil(chunkᵢ × penalty)`, which this order-independent plan cannot
46
+ * reproduce without committing to the adapter's execution order (reordered mid-loop by
47
+ * swap-and-pop); the true charge is at most `penaltyLegs − 1` wei higher. It is never the inflated
48
+ * allowance bound. `netAssets` is exact and does not depend on this field, so the residual never
49
+ * affects the quoted payout.
50
+ */
51
+ readonly penaltyAssets: bigint;
52
+ /** Assets routed to the referral fee recipient. */
53
+ readonly referralFeeAssets: bigint;
54
+ /** Assets the exiting account actually receives: `withdrawnAssets` minus the referral fee, unless
55
+ * the fee is paid back to `userAddress` itself. */
56
+ readonly netAssets: bigint;
57
+ }
58
+ /**
59
+ * Previews what a Vault V2 force withdrawal delivers, without any RPC.
60
+ *
61
+ * `exitAssets` is **penalty-inclusive**: the contract debits it from the user's position but pays
62
+ * out only `assetsToWithdraw + assetsToDeallocate`. Use `netAssets` to quote what the user
63
+ * receives and `maxExitAssets` to cap an input field.
64
+ *
65
+ * @param vaultData - Pre-fetched Vault V2 accrual snapshot.
66
+ * @param params - Preview parameters.
67
+ * @param params.requestedExitAssets - Penalty-inclusive amount the user wants to exit.
68
+ * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before computing capacity.
69
+ * Must not run ahead of the wall clock at the subsequent `forceWithdraw()` call: market accrual
70
+ * grows the adapter's position, so a forward timestamp reports a `maxExitAssets` the entity will
71
+ * reject.
72
+ * @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
73
+ * @param params.userAddress - Optional account that will call `forceWithdraw`; when provided,
74
+ * fee shares minted to it by the accrual are mirrored exactly as the entity does. The entity
75
+ * projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it. Omit
76
+ * only for non-fee-recipient users.
77
+ * @param params.feeProjectionTimestamp - Timestamp for the fee-recipient mint guard; defaults to
78
+ * `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
79
+ * more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
80
+ * keep the deadline itself within that horizon. Ignored without `userAddress`.
81
+ * @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
82
+ * @param params.referralFeeRecipient - Optional referral fee recipient. Required when
83
+ * `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
84
+ * When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
85
+ * includes it.
86
+ * @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
87
+ * `adapter` override that is not the vault's sole adapter, an adapter that is not a
88
+ * MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
89
+ * `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
90
+ * `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
91
+ * whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
92
+ * exit whose realized share price rounds down to zero at the default slippage tolerance (which
93
+ * the entity rejects with `VaultV2ForceWithdrawZeroSharePriceError`), or whose derived default
94
+ * floor cannot fit `uint256`.
95
+ * @example
96
+ * ```ts
97
+ * import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
98
+ *
99
+ * const preview = previewVaultV2ForceWithdraw(vaultData, {
100
+ * requestedExitAssets: 1_000_000n,
101
+ * timestamp: block.timestamp,
102
+ * });
103
+ * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
104
+ * // preview?.netAssets is what the user receives
105
+ * ```
106
+ */
107
+ export declare function previewVaultV2ForceWithdraw(vaultData: AccrualVaultV2, params: PreviewVaultV2ForceWithdrawParams): VaultV2ForceWithdrawPreview | undefined;
@@ -0,0 +1,161 @@
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
2
+ import { isAddressEqual, maxUint256, zeroAddress } from "viem";
3
+ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
4
+ /**
5
+ * Previews what a Vault V2 force withdrawal delivers, without any RPC.
6
+ *
7
+ * `exitAssets` is **penalty-inclusive**: the contract debits it from the user's position but pays
8
+ * out only `assetsToWithdraw + assetsToDeallocate`. Use `netAssets` to quote what the user
9
+ * receives and `maxExitAssets` to cap an input field.
10
+ *
11
+ * @param vaultData - Pre-fetched Vault V2 accrual snapshot.
12
+ * @param params - Preview parameters.
13
+ * @param params.requestedExitAssets - Penalty-inclusive amount the user wants to exit.
14
+ * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before computing capacity.
15
+ * Must not run ahead of the wall clock at the subsequent `forceWithdraw()` call: market accrual
16
+ * grows the adapter's position, so a forward timestamp reports a `maxExitAssets` the entity will
17
+ * reject.
18
+ * @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
19
+ * @param params.userAddress - Optional account that will call `forceWithdraw`; when provided,
20
+ * fee shares minted to it by the accrual are mirrored exactly as the entity does. The entity
21
+ * projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it. Omit
22
+ * only for non-fee-recipient users.
23
+ * @param params.feeProjectionTimestamp - Timestamp for the fee-recipient mint guard; defaults to
24
+ * `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
25
+ * more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
26
+ * keep the deadline itself within that horizon. Ignored without `userAddress`.
27
+ * @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
28
+ * @param params.referralFeeRecipient - Optional referral fee recipient. Required when
29
+ * `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
30
+ * When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
31
+ * includes it.
32
+ * @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
33
+ * `adapter` override that is not the vault's sole adapter, an adapter that is not a
34
+ * MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
35
+ * `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
36
+ * `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
37
+ * whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
38
+ * exit whose realized share price rounds down to zero at the default slippage tolerance (which
39
+ * the entity rejects with `VaultV2ForceWithdrawZeroSharePriceError`), or whose derived default
40
+ * floor cannot fit `uint256`.
41
+ * @example
42
+ * ```ts
43
+ * import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
44
+ *
45
+ * const preview = previewVaultV2ForceWithdraw(vaultData, {
46
+ * requestedExitAssets: 1_000_000n,
47
+ * timestamp: block.timestamp,
48
+ * });
49
+ * // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
50
+ * // preview?.netAssets is what the user receives
51
+ * ```
52
+ */
53
+ export function previewVaultV2ForceWithdraw(vaultData, params) {
54
+ const { requestedExitAssets, timestamp, adapter: adapterOverride, userAddress, feeProjectionTimestamp = timestamp, referralFeePct = 0n, referralFeeRecipient, } = params;
55
+ if (requestedExitAssets <= 0n)
56
+ return undefined;
57
+ // Out of the range the action accepts, `netAssets` would quote a payout the contract can never
58
+ // deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
59
+ if (referralFeePct < 0n || referralFeePct >= MathLib.WAD)
60
+ return undefined;
61
+ if (referralFeePct > 0n &&
62
+ (referralFeeRecipient == null ||
63
+ isAddressEqual(referralFeeRecipient, zeroAddress))) {
64
+ return undefined;
65
+ }
66
+ const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData, adapterOverride);
67
+ if (eligibility.type !== "eligible")
68
+ return undefined;
69
+ const capacity = computeVaultV2ForceWithdrawPlan({
70
+ vaultData,
71
+ adapter: eligibility.adapter,
72
+ liquidityMarketId: eligibility.liquidityMarketId,
73
+ exitAssets: requestedExitAssets,
74
+ timestamp,
75
+ });
76
+ const exitAssets = MathLib.min(requestedExitAssets, capacity.maxExitAssets);
77
+ // A vault with no exitable capacity caps `maxExitAssets` to `0`; the planner rejects a
78
+ // non-positive amount, so short-circuit to the "not previewable" verdict before re-planning.
79
+ if (exitAssets <= 0n)
80
+ return undefined;
81
+ // Re-plan at the capped amount so every returned leg describes the same exit.
82
+ const plan = exitAssets === requestedExitAssets
83
+ ? capacity
84
+ : computeVaultV2ForceWithdrawPlan({
85
+ vaultData,
86
+ adapter: eligibility.adapter,
87
+ liquidityMarketId: eligibility.liquidityMarketId,
88
+ exitAssets,
89
+ timestamp,
90
+ });
91
+ if (plan.withdrawnAssets <= 0n)
92
+ return undefined;
93
+ // Mirror the entity's zero-floor guard. `forceWithdraw()` derives its slippage floor from
94
+ // `withdrawnAssets / sharesBurnt` and rejects an exit whose realized share price rounds down to
95
+ // zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
96
+ // dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
97
+ // `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
98
+ // divides by (accrued to `timestamp` like the plan): a tolerance-free screen clears an exit whose
99
+ // realized price is a single RAY-unit, yet the default tolerance scales that below 1 and rounds it
100
+ // to zero — so the entity would reject with `VaultV2ForceWithdrawZeroSharePriceError` the very
101
+ // `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
102
+ // entity's own guard. The entity validates this derived value with
103
+ // `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
104
+ // cannot fit uint256.
105
+ const { vault: accruedVaultData } = vaultData.accrueInterest(MathLib.max(timestamp, vaultData.lastUpdate));
106
+ const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
107
+ vaultData: accruedVaultData,
108
+ deadlineVaultData: accruedVaultData,
109
+ plan,
110
+ });
111
+ const feeShares = userAddress
112
+ ? computeVaultV2ForceWithdrawFeeSharesMinted({
113
+ vaultData,
114
+ owner: userAddress,
115
+ timestamp,
116
+ })
117
+ : 0n;
118
+ const effectiveFeeProjectionTimestamp = MathLib.max(timestamp, feeProjectionTimestamp);
119
+ if (userAddress) {
120
+ const { vault: projectedVaultData } = vaultData.accrueInterest(MathLib.max(effectiveFeeProjectionTimestamp, vaultData.lastUpdate));
121
+ const feeSharesProjected = computeVaultV2ForceWithdrawFeeSharesMinted({
122
+ vaultData,
123
+ owner: userAddress,
124
+ timestamp: effectiveFeeProjectionTimestamp,
125
+ });
126
+ const minSharesBurntProjected = computeVaultV2ForceWithdrawMinSharesBurnt({
127
+ vaultData: projectedVaultData,
128
+ plan,
129
+ });
130
+ if (feeSharesProjected > 0n &&
131
+ feeSharesProjected >= minSharesBurntProjected) {
132
+ return undefined;
133
+ }
134
+ }
135
+ const sharesBurntForFloor = sharesBurnt - feeShares;
136
+ const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
137
+ ? MathLib.mulDivDown(plan.withdrawnAssets, MathLib.wToRay(MathLib.WAD - DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
138
+ : 0n;
139
+ if (defaultMinSharePriceE27 <= 0n || defaultMinSharePriceE27 > maxUint256) {
140
+ return undefined;
141
+ }
142
+ const referralFeeAssets = MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, MathLib.WAD);
143
+ const selfPaidReferralFee = userAddress != null &&
144
+ referralFeeRecipient != null &&
145
+ isAddressEqual(userAddress, referralFeeRecipient);
146
+ return {
147
+ maxExitAssets: capacity.maxExitAssets,
148
+ exitAssets,
149
+ remainingExitAssets: requestedExitAssets - exitAssets,
150
+ assetsToWithdraw: plan.assetsToWithdraw,
151
+ assetsToDeallocate: plan.assetsToDeallocate,
152
+ // The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
153
+ // bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
154
+ // break reconciliation with `exitAssets` for a multi-market exit.
155
+ penaltyAssets: MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
156
+ referralFeeAssets,
157
+ netAssets: selfPaidReferralFee
158
+ ? plan.withdrawnAssets
159
+ : plan.withdrawnAssets - referralFeeAssets,
160
+ };
161
+ }
@@ -35,6 +35,7 @@ export interface VaultV2InKindRedeemMarketPreview {
35
35
  * @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
36
36
  * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
37
37
  * @returns Frontend-ready market choices, or an empty list when no choices are available.
38
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
38
39
  * @example
39
40
  * ```ts
40
41
  * import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -11,6 +11,7 @@ import { AccrualVaultV2MorphoMarketV1AdapterV2, MathLib, } from "@morpho-org/blu
11
11
  * @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
12
12
  * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
13
13
  * @returns Frontend-ready market choices, or an empty list when no choices are available.
14
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
14
15
  * @example
15
16
  * ```ts
16
17
  * import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -37,6 +38,7 @@ export function previewVaultV2InKindRedeem(vaultData, params) {
37
38
  const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
38
39
  const availableIdleAssets = vaultData.assetBalance;
39
40
  const allocations = adapter.markets
41
+ .filter((market) => (adapter.supplyShares[market.id] ?? 0n) !== 0n)
40
42
  .map((market) => ({
41
43
  market,
42
44
  allocationAssets: market
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
3
+ *
4
+ * @param params - Net target and WAD-scaled referral fee.
5
+ * @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
6
+ * @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); must be below WAD.
7
+ * @returns The gross asset amount to pass to a bundles entrypoint.
8
+ * @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
9
+ * @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
10
+ * @example
11
+ * ```ts
12
+ * import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
13
+ *
14
+ * const gross = grossFromNetAssets({ netAssets: 990n, referralFeePct: 10_000000000000000n });
15
+ * // gross satisfies bigint
16
+ * ```
17
+ */
18
+ export declare const grossFromNetAssets: (params: {
19
+ readonly netAssets: bigint;
20
+ readonly referralFeePct: bigint;
21
+ }) => bigint;
@@ -0,0 +1,31 @@
1
+ import { MathLib } from "@morpho-org/blue-sdk";
2
+ import { NegativeInputError, ReferralFeePctExceededError, } from "../types/index.js";
3
+ /**
4
+ * Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
5
+ *
6
+ * @param params - Net target and WAD-scaled referral fee.
7
+ * @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
8
+ * @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); must be below WAD.
9
+ * @returns The gross asset amount to pass to a bundles entrypoint.
10
+ * @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
11
+ * @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
12
+ * @example
13
+ * ```ts
14
+ * import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
15
+ *
16
+ * const gross = grossFromNetAssets({ netAssets: 990n, referralFeePct: 10_000000000000000n });
17
+ * // gross satisfies bigint
18
+ * ```
19
+ */
20
+ export const grossFromNetAssets = (params) => {
21
+ if (params.netAssets < 0n) {
22
+ throw new NegativeInputError("netAssets", params.netAssets);
23
+ }
24
+ if (params.referralFeePct < 0n) {
25
+ throw new NegativeInputError("referralFeePct", params.referralFeePct);
26
+ }
27
+ if (params.referralFeePct >= MathLib.WAD) {
28
+ throw new ReferralFeePctExceededError(params.referralFeePct);
29
+ }
30
+ return MathLib.mulDivDown(params.netAssets, MathLib.WAD, MathLib.WAD - params.referralFeePct);
31
+ };