@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
@@ -6,9 +6,16 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const actions_1 = require("viem/actions");
9
+ const common_js_1 = require("../../actions/bundles/common.js");
9
10
  const index_js_1 = require("../../actions/index.js");
10
11
  const index_js_2 = require("../../helpers/index.js");
12
+ const validate_js_1 = require("../../helpers/validate.js");
11
13
  const index_js_3 = require("../../types/index.js");
14
+ const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
15
+ const index_js_4 = require("../requirements/index.js");
16
+ // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
17
+ // accrual model stays well-defined inside it.
18
+ const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
12
19
  class MorphoVaultV2 {
13
20
  client;
14
21
  vault;
@@ -30,104 +37,242 @@ class MorphoVaultV2 {
30
37
  deployless: this.client.options.supportDeployless,
31
38
  });
32
39
  }
33
- deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
40
+ /** {@inheritDoc VaultV2Actions.deposit} */
41
+ deposit(params) {
42
+ const { userAddress, vaultData } = params;
43
+ const { asset: vaultAsset } = vaultData;
34
44
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
35
45
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
36
46
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
37
47
  }
38
- if (amount < 0n) {
39
- throw new index_js_3.NegativeInputError("amount", amount);
40
- }
41
- if (nativeAmount && nativeAmount < 0n) {
42
- throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
43
- }
44
- let wNative;
45
- if (nativeAmount) {
46
- ({ wNative } = (0, blue_sdk_1.getChainAddresses)(this.chainId));
47
- if (!wNative) {
48
- throw new index_js_3.ChainWNativeMissingError(this.chainId);
49
- }
50
- }
51
- (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
52
- if (nativeAmount && wNative) {
53
- if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
54
- throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
55
- }
56
- }
57
- const totalAssets = amount + (nativeAmount ?? 0n);
58
- if (totalAssets === 0n) {
59
- throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
60
- }
61
- // Accrue interest forward to bound the on-chain share price at execution.
62
- // Mirrors blue repay's 2h forward-accrual buffer.
63
- const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), vaultData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
64
- const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
65
- const shares = accruedVault.toShares(totalAssets);
66
- if (shares <= 0n) {
67
- throw new index_js_3.NonPositiveInputError("shares", shares);
48
+ const createdAt = morpho_ts_1.Time.timestamp();
49
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
50
+ if (deadline <= createdAt)
51
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
52
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
53
+ deadline,
54
+ referralFeePct: params.referralFeePct,
55
+ referralFeeRecipient: params.referralFeeRecipient,
56
+ });
57
+ const funding = (0, common_js_1.resolveBundlesFunding)(params);
58
+ // Reject overflow before share-price math or native-only prerequisite resolution.
59
+ (0, validate_js_1.validateUint256Field)(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
60
+ if (funding.value > 0n) {
61
+ // The native path must target the chain's registered wrapped-native asset.
62
+ (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
68
63
  }
69
- const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), blue_sdk_1.MathLib.RAY * 100n);
70
- return {
71
- getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
72
- address: vaultData.asset,
73
- chainId: this.chainId,
74
- supportSignature: this.client.options.supportSignature,
75
- supportDeployless: this.client.options.supportDeployless,
76
- useSimplePermit: params?.useSimplePermit,
77
- args: {
78
- amount,
79
- from: userAddress,
80
- },
81
- }),
64
+ const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
65
+ const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
66
+ vaultData,
67
+ deadline,
68
+ assets: funding.assets - referralFeeAssets,
69
+ slippageTolerance: params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
70
+ });
71
+ const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
72
+ let pendingRequirements;
73
+ let expectedRequirement;
74
+ return Object.freeze({
75
+ getRequirements: async (requirementOptions) => {
76
+ const now = morpho_ts_1.Time.timestamp();
77
+ if (deadline <= now)
78
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
79
+ if (pendingRequirements != null)
80
+ return await pendingRequirements;
81
+ // Memoize the in-flight promise, not just its result: concurrent callers
82
+ // requesting different routes would otherwise both resolve requirements and
83
+ // the slower one would overwrite `expectedRequirement`, making `buildTx()`
84
+ // reject the signature returned by the other call.
85
+ const pending = (async () => {
86
+ const requirements = funding.value > 0n
87
+ ? []
88
+ : await (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
89
+ token: vaultAsset,
90
+ spender,
91
+ amount: funding.assets,
92
+ owner: userAddress,
93
+ chainId: this.chainId,
94
+ deadline,
95
+ supportSignature: this.client.options.supportSignature,
96
+ supportDeployless: this.client.options.supportDeployless,
97
+ useSimplePermit: requirementOptions?.useSimplePermit,
98
+ permit2Nonce: requirementOptions?.permit2Nonce,
99
+ });
100
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
101
+ expectedRequirement =
102
+ signatureRequirement?.action.type === "permit" ||
103
+ signatureRequirement?.action.type === "permit2SignatureTransfer"
104
+ ? signatureRequirement.action
105
+ : undefined;
106
+ return requirements;
107
+ })();
108
+ pendingRequirements = pending;
109
+ try {
110
+ return await pending;
111
+ }
112
+ finally {
113
+ // Later calls must re-read live allowances/nonces and honor their own options.
114
+ if (pendingRequirements === pending)
115
+ pendingRequirements = undefined;
116
+ }
117
+ },
82
118
  buildTx: (signatures) => {
83
- const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
84
- permit: true,
85
- });
119
+ const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expectedRequirement);
86
120
  return (0, index_js_1.vaultV2Deposit)({
87
121
  vault: {
88
122
  chainId: this.chainId,
89
123
  address: this.vault,
90
- asset: vaultData.asset,
124
+ asset: vaultAsset,
91
125
  },
92
126
  args: {
93
- amount,
127
+ ...(funding.value > 0n
128
+ ? { nativeAmount: funding.assets }
129
+ : { amount: funding.assets }),
94
130
  maxSharePrice,
95
- recipient: userAddress,
96
- requirementSignature: permit,
97
- nativeAmount,
131
+ userAddress,
132
+ requirementSignature,
133
+ referralFeePct: common.referralFeePct,
134
+ referralFeeRecipient: common.referralFeeRecipient,
135
+ deadline,
98
136
  },
99
137
  metadata: this.client.options.metadata,
100
138
  });
101
139
  },
102
- };
140
+ });
103
141
  }
104
- withdraw({ amount, userAddress }) {
142
+ withdraw(params) {
143
+ const { amount, userAddress } = params;
105
144
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
106
- return {
107
- buildTx: () => (0, index_js_1.vaultV2Withdraw)({
108
- vault: { address: this.vault },
109
- args: {
110
- amount,
111
- recipient: userAddress,
112
- onBehalf: userAddress,
113
- },
114
- metadata: this.client.options.metadata,
115
- }),
116
- };
145
+ if (amount <= 0n)
146
+ throw new index_js_3.NonPositiveInputError("amount", amount);
147
+ // Reject values outside the ABI range before resolving any requirements.
148
+ (0, validate_js_1.validateUint256Field)("amount", amount);
149
+ const createdAt = morpho_ts_1.Time.timestamp();
150
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
151
+ if (deadline <= createdAt)
152
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
153
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
154
+ deadline,
155
+ referralFeePct: params.referralFeePct,
156
+ referralFeeRecipient: params.referralFeeRecipient,
157
+ });
158
+ const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
159
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
160
+ // Fail eagerly if VaultBundlesV1 is unavailable; only validation is needed here.
161
+ (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
162
+ let requiredShareAllowance;
163
+ let vaultSnapshot;
164
+ let expectedRequirement;
165
+ return Object.freeze({
166
+ getRequirements: async () => {
167
+ const now = morpho_ts_1.Time.timestamp();
168
+ if (deadline <= now)
169
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
170
+ // Re-read the live share allowance on every call instead of caching the resolved
171
+ // requirements: the allowance is the sole cap on the burn, so a caller that executed the
172
+ // returned approval must see it satisfied on the next call, and an allowance revoked or
173
+ // raised afterwards must resurface as an outstanding requirement. Only the vault snapshot
174
+ // and the cap derived from it are pinned, so re-reading cannot move the cap this handle
175
+ // already committed to; the snapshot is used for immutable identity and permit-domain
176
+ // fields only.
177
+ const vaultData = (vaultSnapshot ??= await this.getData());
178
+ requiredShareAllowance ??= (0, index_js_2.computeVaultMaxShareAllowance)({
179
+ vaultData,
180
+ deadline,
181
+ assets: amount,
182
+ slippageTolerance,
183
+ });
184
+ const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
185
+ vaultData,
186
+ version: "vaultV2",
187
+ owner: userAddress,
188
+ chainId: this.chainId,
189
+ requiredShareAllowance,
190
+ deadline,
191
+ supportSignature: this.client.options.supportSignature,
192
+ });
193
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
194
+ if (signatureRequirement?.action.type === "permit") {
195
+ expectedRequirement = signatureRequirement.action;
196
+ }
197
+ return requirements;
198
+ },
199
+ buildTx: (signatures) => {
200
+ const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
201
+ requiredShareAllowance,
202
+ expectedRequirement,
203
+ });
204
+ return (0, index_js_1.vaultV2Withdraw)({
205
+ vault: { chainId: this.chainId, address: this.vault },
206
+ args: {
207
+ amount,
208
+ userAddress,
209
+ requirementSignature: permit,
210
+ referralFeePct: common.referralFeePct,
211
+ referralFeeRecipient: common.referralFeeRecipient,
212
+ deadline,
213
+ },
214
+ metadata: this.client.options.metadata,
215
+ });
216
+ },
217
+ });
117
218
  }
118
- redeem({ shares, userAddress }) {
219
+ /** {@inheritDoc VaultV2Actions.redeem} */
220
+ redeem(params) {
119
221
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
120
- return {
121
- buildTx: () => (0, index_js_1.vaultV2Redeem)({
122
- vault: { address: this.vault },
123
- args: {
124
- shares,
125
- recipient: userAddress,
126
- onBehalf: userAddress,
127
- },
128
- metadata: this.client.options.metadata,
129
- }),
130
- };
222
+ const { shares, userAddress } = params;
223
+ if (shares <= 0n)
224
+ throw new index_js_3.NonPositiveInputError("shares", shares);
225
+ const createdAt = morpho_ts_1.Time.timestamp();
226
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
227
+ if (deadline <= createdAt)
228
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
229
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
230
+ deadline,
231
+ referralFeePct: params.referralFeePct,
232
+ referralFeeRecipient: params.referralFeeRecipient,
233
+ });
234
+ (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
235
+ let expectedRequirement;
236
+ return Object.freeze({
237
+ getRequirements: async () => {
238
+ const now = morpho_ts_1.Time.timestamp();
239
+ if (deadline <= now)
240
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
241
+ const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
242
+ vaultData: await this.getData(),
243
+ version: "vaultV2",
244
+ owner: userAddress,
245
+ chainId: this.chainId,
246
+ requiredShareAllowance: shares,
247
+ deadline,
248
+ supportSignature: this.client.options.supportSignature,
249
+ });
250
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
251
+ expectedRequirement =
252
+ signatureRequirement?.action.type === "permit"
253
+ ? signatureRequirement.action
254
+ : undefined;
255
+ return requirements;
256
+ },
257
+ buildTx: (signatures) => {
258
+ const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
259
+ requiredShareAllowance: shares,
260
+ expectedRequirement,
261
+ });
262
+ return (0, index_js_1.vaultV2Redeem)({
263
+ vault: { chainId: this.chainId, address: this.vault },
264
+ args: {
265
+ shares,
266
+ userAddress,
267
+ requirementSignature: permit,
268
+ referralFeePct: common.referralFeePct,
269
+ referralFeeRecipient: common.referralFeeRecipient,
270
+ deadline,
271
+ },
272
+ metadata: this.client.options.metadata,
273
+ });
274
+ },
275
+ });
131
276
  }
132
277
  /** {@inheritDoc VaultV2Actions.inKindRedeem} */
133
278
  inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }) {
@@ -147,21 +292,24 @@ class MorphoVaultV2 {
147
292
  const marketIdListSnapshot = marketParamsListSnapshot.map((marketParams) => blue_sdk_1.MarketUtils.getMarketId(marketParams));
148
293
  const now = morpho_ts_1.Time.timestamp();
149
294
  const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
295
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
296
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
297
+ (0, validate_js_1.validateDeadline)(deadline);
150
298
  if (deadline <= now)
151
299
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
152
300
  if (vaultData.accrualAdapters.length !== 1) {
153
- throw new index_js_3.InKindRedeemRequiresSingleAdapterError(this.vault, vaultData.accrualAdapters.length);
301
+ throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, vaultData.accrualAdapters.length);
154
302
  }
155
303
  const soleAdapter = vaultData.accrualAdapters[0];
156
304
  if (soleAdapter == null) {
157
- throw new index_js_3.InKindRedeemRequiresSingleAdapterError(this.vault, 0);
305
+ throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, 0);
158
306
  }
159
307
  const adapter = adapterOverride ?? soleAdapter.address;
160
308
  if (!(0, viem_1.isAddressEqual)(adapter, soleAdapter.address)) {
161
309
  throw new index_js_3.AdapterNotPartOfVaultError(this.vault, adapter);
162
310
  }
163
311
  if (!(soleAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2)) {
164
- throw new index_js_3.UnsupportedInKindAdapterError(adapter);
312
+ throw new index_js_3.VaultV2UnsupportedExitAdapterError(adapter);
165
313
  }
166
314
  const penalty = vaultData.forceDeallocatePenalties[soleAdapter.address] ?? 0n;
167
315
  const idleAssets = blue_sdk_1.MathLib.min(vaultData.assetBalance, amount);
@@ -176,7 +324,9 @@ class MorphoVaultV2 {
176
324
  if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
177
325
  throw new index_js_3.EmptyMarketParamsListError();
178
326
  }
179
- const assetsByMarket = new Map(soleAdapter.markets.map((market) => [
327
+ const assetsByMarket = new Map(soleAdapter.markets
328
+ .filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
329
+ .map((market) => [
180
330
  market.id,
181
331
  market
182
332
  .accrueInterest(now)
@@ -307,21 +457,226 @@ class MorphoVaultV2 {
307
457
  },
308
458
  };
309
459
  }
310
- forceWithdraw({ deallocations, withdraw, userAddress, }) {
460
+ /** {@inheritDoc VaultV2Actions.forceWithdraw} */
461
+ forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, }) {
311
462
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
463
+ if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
464
+ throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
465
+ }
466
+ if (exitAssets <= 0n)
467
+ throw new index_js_3.NonPositiveInputError("exitAssets", exitAssets);
468
+ (0, validate_js_1.validateUint256Field)("exitAssets", exitAssets);
469
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
470
+ // Called for its throws only: the raw pair is forwarded to the action, which normalizes it
471
+ // again on the encode path so a direct action caller gets the same guarantees.
472
+ (0, validate_js_1.validateReferralFee)({ referralFeePct, referralFeeRecipient });
473
+ if (minSharePriceE27Override != null) {
474
+ // An unbounded override reopens the exact hole this path closes: the contract reads
475
+ // `minSharePriceE27 == 0` as "no bound".
476
+ if (minSharePriceE27Override <= 0n) {
477
+ throw new index_js_3.NonPositiveInputError("minSharePriceE27", minSharePriceE27Override);
478
+ }
479
+ // And an override the uint256 slot cannot hold must fail here rather than after
480
+ // `getRequirements()` has already asked for an approval or a permit signature.
481
+ (0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27Override);
482
+ }
483
+ const now = morpho_ts_1.Time.timestamp();
484
+ const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
485
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
486
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
487
+ (0, validate_js_1.validateDeadline)(deadline);
488
+ if (deadline <= now)
489
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
490
+ const maxDeadline = now + VAULT_V2_FEE_PROJECTION_HORIZON;
491
+ if (deadline > maxDeadline) {
492
+ throw new index_js_3.InputExceedsMaxError({
493
+ field: "deadline",
494
+ value: deadline,
495
+ max: maxDeadline,
496
+ });
497
+ }
498
+ const eligibility = (0, index_js_2.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
499
+ switch (eligibility.type) {
500
+ case "eligible":
501
+ break;
502
+ case "adapterCount":
503
+ throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, eligibility.adapters);
504
+ case "adapterMismatch":
505
+ throw new index_js_3.AdapterNotPartOfVaultError(this.vault, eligibility.adapter);
506
+ case "unsupportedAdapter":
507
+ throw new index_js_3.VaultV2UnsupportedExitAdapterError(eligibility.adapter);
508
+ case "unsupportedLiquidityAdapter":
509
+ throw new index_js_3.VaultV2UnsupportedLiquidityAdapterError({
510
+ vault: this.vault,
511
+ liquidityAdapter: eligibility.liquidityAdapter,
512
+ adapter: eligibility.adapter,
513
+ });
514
+ case "undecodableLiquidityData":
515
+ throw new index_js_3.VaultV2UndecodableLiquidityDataError({
516
+ vault: this.vault,
517
+ liquidityAdapter: eligibility.liquidityAdapter,
518
+ liquidityData: eligibility.liquidityData,
519
+ cause: eligibility.cause,
520
+ });
521
+ }
522
+ const { adapter: accrualAdapter, liquidityMarketId } = eligibility;
523
+ const adapter = accrualAdapter.address;
524
+ const plan = (0, index_js_2.computeVaultV2ForceWithdrawPlan)({
525
+ vaultData,
526
+ adapter: accrualAdapter,
527
+ liquidityMarketId,
528
+ exitAssets,
529
+ timestamp: now,
530
+ });
531
+ if (plan.withdrawnAssets <= 0n) {
532
+ throw new index_js_3.VaultV2ForceWithdrawZeroWithdrawalError({
533
+ vault: this.vault,
534
+ exitAssets,
535
+ penalty: plan.penalty,
536
+ });
537
+ }
538
+ // The contract's force-deallocation loop is unbounded: under-coverage panics on-chain.
539
+ if (plan.coveredAssets < plan.assetsToDeallocate) {
540
+ throw new index_js_3.VaultV2ForceWithdrawCoverageError({
541
+ required: plan.assetsToDeallocate,
542
+ covered: plan.coveredAssets,
543
+ maxExitAssets: plan.maxExitAssets,
544
+ });
545
+ }
546
+ const projectionTimestamp = deadline;
547
+ // VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
548
+ // accrues the vault before burning. Use the `now` accrual for the floor and the projected
549
+ // deadline accrual for the fee-mint guard.
550
+ const { vault: nowVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(now, vaultData.lastUpdate));
551
+ const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(projectionTimestamp, vaultData.lastUpdate));
552
+ const sharesBurntNow = (0, index_js_2.computeVaultV2ForceWithdrawSharesBurnt)({
553
+ vaultData: nowVaultData,
554
+ deadlineVaultData: nowVaultData,
555
+ plan,
556
+ });
557
+ const feeSharesNow = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
558
+ vaultData,
559
+ owner: userAddress,
560
+ timestamp: now,
561
+ });
562
+ const feeSharesProjected = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
563
+ vaultData,
564
+ owner: userAddress,
565
+ timestamp: projectionTimestamp,
566
+ });
567
+ const minSharesBurntProjected = (0, index_js_2.computeVaultV2ForceWithdrawMinSharesBurnt)({
568
+ vaultData: projectedVaultData,
569
+ plan,
570
+ });
571
+ // When fee shares are minted, the projected pair bounds every execution time in the window.
572
+ if (feeSharesProjected > 0n &&
573
+ feeSharesProjected >= minSharesBurntProjected) {
574
+ throw new index_js_3.VaultV2ForceWithdrawFeeSharesExceedBurnError({
575
+ vault: this.vault,
576
+ userAddress,
577
+ sharesBurnt: minSharesBurntProjected,
578
+ feeShares: feeSharesProjected,
579
+ });
580
+ }
581
+ // sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
582
+ const netSharesBurntNow = sharesBurntNow - feeSharesNow;
583
+ const minSharePriceE27 = minSharePriceE27Override ??
584
+ (0, index_js_2.computeMinForceWithdrawSharePrice)({
585
+ withdrawnAssets: plan.withdrawnAssets,
586
+ sharesBurnt: netSharesBurntNow,
587
+ slippageTolerance,
588
+ });
589
+ // The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
590
+ // lowering a lower bound weakens it, so any vault whose share price grew past that would be left
591
+ // with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
592
+ // only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
593
+ //
594
+ // It still has to fit the ABI slot though. Defense-in-depth rather than a reachable input error:
595
+ // with `exitAssets` bounded above, the derived floor only exceeds `uint256` on a vault whose
596
+ // share price passed ~1e50 assets/share, which no fixture here can construct.
597
+ (0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27);
598
+ // VaultExitBundlesV1's burn bound includes fee shares minted by the first withdrawal. Add the
599
+ // projected fee shares to the price-floor ceiling so the approval covers that mint.
600
+ // Saturated at `maxUint256`: a tiny accepted floor scales this above the ABI slot, and the
601
+ // approval encoder clamps what it emits — so an uncapped requirement would sit permanently above
602
+ // any allowance the user can actually grant and `getRequirements()` would return the same
603
+ // approval forever. No account can hold or burn more shares than that anyway.
604
+ const requiredShareAllowance = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, minSharePriceE27) +
605
+ feeSharesProjected, viem_1.maxUint256);
606
+ const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
312
607
  return {
313
- buildTx: () => (0, index_js_1.vaultV2ForceWithdraw)({
314
- vault: { address: this.vault },
315
- args: {
316
- deallocations,
317
- withdraw: {
318
- amount: withdraw.amount,
319
- recipient: userAddress,
608
+ getRequirements: async () => {
609
+ const requirementsTimestamp = morpho_ts_1.Time.timestamp();
610
+ if (deadline <= requirementsTimestamp) {
611
+ throw new index_js_3.ExpiredDeadlineError(deadline, requirementsTimestamp);
612
+ }
613
+ // Vault gates are intentionally left to the final transaction: the receive-assets gate may
614
+ // inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
615
+ // external code re-evaluated after each intermediate penalty burn, so neither is
616
+ // execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
617
+ // supplies into Morpho Blue, so no Blue token-balance check is needed.
618
+ const [allowance, nonce] = await (0, actions_1.multicall)(this.client.viemClient, {
619
+ allowFailure: false,
620
+ contracts: [
621
+ {
622
+ address: this.vault,
623
+ abi: viem_1.erc20Abi,
624
+ functionName: "allowance",
625
+ args: [userAddress, vaultExitBundlesV1],
626
+ },
627
+ {
628
+ address: this.vault,
629
+ abi: blue_sdk_viem_1.erc2612Abi,
630
+ functionName: "nonces",
631
+ args: [userAddress],
632
+ },
633
+ ],
634
+ });
635
+ if (allowance >= requiredShareAllowance)
636
+ return [];
637
+ if (this.client.options.supportSignature) {
638
+ const requirement = (0, index_js_1.encodeVaultSharesPermit)({
639
+ vault: vaultData,
640
+ version: "vaultV2",
641
+ spender: vaultExitBundlesV1,
642
+ owner: userAddress,
643
+ chainId: this.chainId,
644
+ nonce,
645
+ amount: requiredShareAllowance,
646
+ deadline,
647
+ });
648
+ return [requirement];
649
+ }
650
+ return [
651
+ (0, index_js_1.encodeErc20Approval)({
652
+ token: this.vault,
653
+ spender: vaultExitBundlesV1,
654
+ amount: requiredShareAllowance,
655
+ chainId: this.chainId,
656
+ }),
657
+ ];
658
+ },
659
+ buildTx: (signatures) => {
660
+ const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
661
+ spender: vaultExitBundlesV1,
662
+ amount: requiredShareAllowance,
663
+ deadline,
664
+ });
665
+ return (0, index_js_1.vaultV2ForceWithdraw)({
666
+ vault: { chainId: this.chainId, address: this.vault },
667
+ args: {
668
+ adapter,
669
+ exitAssets,
670
+ minSharePriceE27,
671
+ userAddress,
672
+ deadline,
673
+ referralFeePct,
674
+ referralFeeRecipient,
675
+ requirementSignature: permit,
320
676
  },
321
- onBehalf: userAddress,
322
- },
323
- metadata: this.client.options.metadata,
324
- }),
677
+ metadata: this.client.options.metadata,
678
+ });
679
+ },
325
680
  };
326
681
  }
327
682
  forceRedeem({ deallocations, redeem, userAddress, }) {
@@ -363,7 +363,11 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
363
363
  * utilization defaults to 90% and is configurable through
364
364
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
365
365
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
366
- * considered.
366
+ * considered. Targets with no remaining supply or allocator capacity are skipped before
367
+ * projecting source interest. The adapter's minimum share minting requirement, supply-share
368
+ * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
369
+ * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
370
+ * allocation does not increase after rounding.
367
371
  *
368
372
  * Shared-cap discovery is conservative. Operation planning searches at most
369
373
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -374,6 +378,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
374
378
  * @param marketId - Target Blue market id.
375
379
  * @param options - Optional discovery controls and operation to support.
376
380
  * @returns Flat action-ready reallocations and their post-simulation state.
381
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
377
382
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
378
383
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
379
384
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
@@ -430,6 +435,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
430
435
  * @param marketId - Target Blue market id.
431
436
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
432
437
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
438
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
433
439
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
434
440
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
435
441
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -470,6 +476,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
470
476
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
471
477
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
472
478
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
479
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
473
480
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
474
481
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
475
482
  * @throws {UnknownReallocationMarketError} when a required market is absent.