@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
@@ -210,10 +210,13 @@ export class VaultV1ReallocationData {
210
210
  * Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
211
211
  * on-chain `reallocateTo` fee semantics: one fee charge per vault with at
212
212
  * least one computed withdrawal.
213
+ * Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
214
+ * are skipped before projecting source interest.
213
215
  *
214
216
  * @param marketId - Target market to supply with shared liquidity.
215
217
  * @param options - Optional allocator discovery options.
216
218
  * @returns Computed source-market withdrawals and the post-reallocation state.
219
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
217
220
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
218
221
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
219
222
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -311,6 +314,7 @@ export class VaultV1ReallocationData {
311
314
  * @param marketId - Target market to supply with shared liquidity.
312
315
  * @param options - Optional allocator discovery options.
313
316
  * @returns Computed source-market withdrawals and the post-reallocation state.
317
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
314
318
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
315
319
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
316
320
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -330,6 +334,7 @@ export class VaultV1ReallocationData {
330
334
  * @param marketId - Target market that would receive the liquidity.
331
335
  * @param options - Optional allocator discovery options.
332
336
  * @returns Total reallocatable assets in loan-token units; `0n` when none is available.
337
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
333
338
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
334
339
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
335
340
  * `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
@@ -386,6 +391,7 @@ export class VaultV1ReallocationData {
386
391
  * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
387
392
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
388
393
  * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
394
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
389
395
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
390
396
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
391
397
  * `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
@@ -443,25 +449,34 @@ export class VaultV1ReallocationData {
443
449
  getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
444
450
  return _try(() => {
445
451
  const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
452
+ const maxIn = publicAllocatorConfig?.maxIn ?? 0n;
446
453
  const validCap = pendingCap.validAt >= timestamp
447
454
  ? MathLib.min(pendingCap.value, cap)
448
455
  : cap;
456
+ if (maxIn === 0n || validCap === 0n)
457
+ return { vault };
449
458
  const suppliable = MathLib.zeroFloorSub(validCap, this.getAccrualPosition(vault, marketId).accrueInterest(timestamp)
450
459
  .supplyAssets);
460
+ if (suppliable === 0n)
461
+ return { vault };
451
462
  const marketWithdrawals = this.getVault(vault)
452
463
  .withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
453
464
  !withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
454
465
  .map((srcMarketId) => {
455
466
  const withdrawal = _try(() => {
456
- const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
457
- const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
458
- defaultMaxWithdrawalUtilization);
459
467
  const srcConfig = this.getVaultMarketConfig(vault, srcMarketId);
460
- if (!srcConfig.enabled)
468
+ const maxOut = srcConfig.publicAllocatorConfig?.maxOut ?? 0n;
469
+ if (!srcConfig.enabled || maxOut === 0n)
470
+ return { id: srcMarketId, assets: 0n };
471
+ const rawSrcPosition = this.getAccrualPosition(vault, srcMarketId);
472
+ if (rawSrcPosition.supplyShares === 0n)
461
473
  return { id: srcMarketId, assets: 0n };
474
+ const srcPosition = rawSrcPosition.accrueInterest(timestamp);
475
+ const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
476
+ defaultMaxWithdrawalUtilization);
462
477
  return {
463
478
  id: srcMarketId,
464
- assets: MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, publicAllocatorConfig?.maxIn ?? 0n, srcConfig.publicAllocatorConfig?.maxOut ?? 0n),
479
+ assets: MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, maxIn, maxOut),
465
480
  };
466
481
  }, UnknownDataError);
467
482
  return withdrawal ?? { id: srcMarketId, assets: 0n };
@@ -2,7 +2,7 @@ import { type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
3
3
  import { type Address } from "viem";
4
4
  import type { FetchParameters } from "../../types/data.js";
5
- import { type ActionOutput, type Deallocation, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
5
+ import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type Deallocation, type MorphoClientType, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
6
6
  export interface VaultV2Actions {
7
7
  /**
8
8
  * Fetches the latest vault data.
@@ -14,67 +14,209 @@ export interface VaultV2Actions {
14
14
  */
15
15
  getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
16
16
  /**
17
- * Prepares a deposit transaction for the VaultV2 contract.
17
+ * Prepares a Vault V2 deposit through the registered VaultBundlesV1 contract.
18
18
  *
19
- * This function constructs the transaction data required to deposit a specified amount of assets into the vault.
20
- * Uses pre-fetched vault data for accurate calculations of slippage and asset address,
21
- * then returns the prepared deposit transaction and a function for retrieving all required approval transactions.
22
- * Bundler Integration: This flow uses the bundler to atomically execute the user's asset transfer and vault deposit in a single transaction for slippage protection.
19
+ * Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
20
+ * `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612 or
21
+ * Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
22
+ * always minted to the transaction sender, which must be `userAddress`.
23
+ * Concurrent requirement reads share the first caller's options; later calls refresh on-chain
24
+ * state using their own options. `buildTx()` accepts signatures from the latest completed read.
23
25
  *
24
- * @param {Object} params - The deposit parameters.
25
- * @param {bigint} [params.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided.
26
- * @param {Address} params.userAddress - User address initiating the deposit.
27
- * @param {AccrualVaultV2} params.vaultData - Pre-fetched vault data with asset address and share conversion.
28
- * @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Optional slippage tolerance value. Default is 0.03%. Slippage tolerance must be less than 10%.
29
- * @param {bigint} [params.nativeAmount] - Amount of native token to wrap into wNative. Vault asset must be wNative.
30
- * @returns {Object} The result object.
31
- * @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
32
- * @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
26
+ * @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
27
+ * @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
28
+ * @param params.amount - Optional gross ERC-20 assets; exclusive with `nativeAmount`.
29
+ * @param params.nativeAmount - Optional gross native assets; exclusive with `amount` and valid
30
+ * only for a wNative vault.
31
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
32
+ * exceed 10%.
33
+ * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted before
34
+ * the vault deposit.
35
+ * @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
36
+ * @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
37
+ * two hours from handle creation.
38
+ * @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
39
+ * transaction builder.
40
+ * @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
41
+ * @throws {ChainIdMismatchError} when the connected client targets another chain.
42
+ * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
43
+ * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
44
+ * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
45
+ * @throws {NegativeInputError} when funding, slippage, the referral fee, or a Permit2 nonce is negative.
46
+ * @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
47
+ * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
48
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
49
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
50
+ * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
51
+ * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
52
+ * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
53
+ * owner is consumed and none was passed explicitly.
54
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
55
+ * explicit Permit2 nonce is consumed.
56
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
57
+ * `getRequirements()` when the Permit2 nonce exceeds uint256.
58
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
59
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
60
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature was not produced for
61
+ * this prepared handle.
62
+ * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
63
+ * @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
64
+ * @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
65
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
66
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
67
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
68
+ * @example
69
+ * ```ts
70
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
71
+ * import { createPublicClient, http, type Address, zeroAddress } from "viem";
72
+ * import { mainnet } from "viem/chains";
73
+ *
74
+ * const keyrockUsdcVaultV2 =
75
+ * "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
76
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
77
+ * .extend(morphoViemExtension());
78
+ * const vault = client.morpho.vaultV2(keyrockUsdcVaultV2, mainnet.id);
79
+ * const vaultData = await vault.getData();
80
+ * const action = vault.deposit({
81
+ * amount: 1_000_000n,
82
+ * userAddress: zeroAddress,
83
+ * vaultData,
84
+ * });
85
+ * const requirements = await action.getRequirements(); // Satisfy these first.
86
+ * const tx = action.buildTx(); // For a client configured with supportSignature: false.
87
+ * // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
88
+ * ```
33
89
  */
34
90
  deposit: (params: {
35
- userAddress: Address;
36
- vaultData: AccrualVaultV2;
37
- slippageTolerance?: bigint;
38
- } & DepositAmountArgs) => {
39
- buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
40
- getRequirements: (params?: {
41
- useSimplePermit?: boolean;
42
- }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
43
- };
91
+ readonly userAddress: Address;
92
+ readonly vaultData: AccrualVaultV2;
93
+ readonly slippageTolerance?: bigint;
94
+ readonly referralFeePct?: bigint;
95
+ readonly referralFeeRecipient?: Address;
96
+ readonly deadline?: bigint;
97
+ } & BundlesFundingArgs) => ActionOutput<VaultV2DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
44
98
  /**
45
- * Prepares a withdraw transaction for the VaultV2 contract.
99
+ * Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
46
100
  *
47
- * This function constructs the transaction data required to withdraw a specified amount of assets from the vault.
101
+ * Reads the vault accrual state on the first `getRequirements()` call, then reads the live
102
+ * vault-share allowance and, when a signature is needed, the permit nonce on each call.
103
+ * Captures the requested amount and owner at creation, so later changes to `params` do not
104
+ * change this handle's requirements or transaction.
48
105
  *
49
- * @param {Object} params - The withdraw parameters.
50
- * @param {bigint} params.amount - The amount of assets to withdraw.
51
- * @param {Address} params.userAddress - User address initiating the withdraw.
52
- * @returns {Object} The result object.
53
- * @returns {Readonly<Transaction<VaultV2WithdrawAction>>} returns.tx The prepared withdraw transaction.
106
+ * @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
107
+ * @param params.userAddress - Share owner that must sign and submit; receives the net assets.
108
+ * @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
109
+ * the share cap.
110
+ * Defaults to 0.03% and cannot exceed 10%.
111
+ * @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
112
+ * rounded down and deducted from the gross withdrawn assets.
113
+ * @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
114
+ * @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
115
+ * defaults to two hours from handle creation.
116
+ * @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
117
+ * which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
118
+ * when the allowance equals the cap; otherwise they contain an exact approval or, with
119
+ * signature support, an ERC-2612 request. The cap stays pinned to the first resolution while
120
+ * each call re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
121
+ * @throws {ChainIdMismatchError} when the connected client targets another chain.
122
+ * @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
123
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
124
+ * at any `getRequirements()` call.
125
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
126
+ * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
127
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
128
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
129
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
130
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
131
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
132
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
133
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
134
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed,
135
+ * was not resolved for this handle, or has incompatible vault, owner, spender, amount,
136
+ * deadline, or nonce values.
137
+ * @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
138
+ * @example
139
+ * ```ts
140
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
141
+ * import { createPublicClient, http, type Address } from "viem";
142
+ * import { mainnet } from "viem/chains";
143
+ *
144
+ * export async function prepareUsdcWithdrawal(userAddress: Address) {
145
+ * const vaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
146
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
147
+ * .extend(morphoViemExtension({ supportSignature: false }));
148
+ * const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
149
+ * const action = vault.withdraw({ amount: 1_000_000n, userAddress });
150
+ * const requirements = await action.getRequirements();
151
+ * // Send and confirm each approval before calling action.buildTx().
152
+ * // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
153
+ * return { action, requirements }; // Prepared handle and its outstanding share approvals.
154
+ * }
155
+ * ```
54
156
  */
55
157
  withdraw: (params: {
56
- amount: bigint;
57
- userAddress: Address;
58
- }) => {
59
- buildTx: () => Readonly<Transaction<VaultV2WithdrawAction>>;
60
- };
158
+ readonly amount: bigint;
159
+ readonly userAddress: Address;
160
+ readonly slippageTolerance?: bigint;
161
+ readonly referralFeePct?: bigint;
162
+ readonly referralFeeRecipient?: Address;
163
+ readonly deadline?: bigint;
164
+ }) => ActionOutput<VaultV2WithdrawAction, readonly RequirementSignature[], undefined>;
61
165
  /**
62
- * Prepares a redeem transaction for the VaultV2 contract.
166
+ * Prepares an exact-shares Vault V2 redemption through VaultBundlesV1.
63
167
  *
64
- * This function constructs the transaction data required to redeem a specified amount of shares from the vault.
168
+ * Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
169
+ * The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
170
+ * `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
171
+ * `buildTx()` accepts permits from the latest completed requirement resolution.
65
172
  *
66
173
  * @param {Object} params - The redeem parameters.
67
- * @param {bigint} params.shares - The amount of shares to redeem.
68
- * @param {Address} params.userAddress - User address initiating the redeem.
69
- * @returns {Object} The result object.
70
- * @returns {Readonly<Transaction<VaultV2RedeemAction>>} returns.tx The prepared redeem transaction.
174
+ * @param {bigint} params.shares - Exact vault shares to burn.
175
+ * @param {Address} params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
176
+ * @param {bigint} [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
177
+ * @param {Address} [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
178
+ * @param {bigint} [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
179
+ * @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
180
+ * @throws {ChainIdMismatchError} when the client and entity target different chains.
181
+ * @throws {NonPositiveInputError} when `shares` is not positive.
182
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
183
+ * requirement resolution.
184
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
185
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
186
+ * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
187
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
188
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
189
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
190
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
191
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
192
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit does not match the
193
+ * resolved share cap, spender, owner, nonce, or deadline.
194
+ * @example
195
+ * ```ts
196
+ * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
197
+ *
198
+ * const vault = client.morpho.vaultV2(vaultAddress, 1);
199
+ * const redemption = vault.redeem({ shares: 1_000_000n, userAddress });
200
+ * const signatures = [];
201
+ * for (const requirement of await redemption.getRequirements()) {
202
+ * if (isRequirementSignature(requirement)) {
203
+ * signatures.push(await requirement.sign(walletClient, userAddress));
204
+ * } else {
205
+ * const hash = await walletClient.sendTransaction(requirement);
206
+ * await client.waitForTransactionReceipt({ hash });
207
+ * }
208
+ * }
209
+ * const tx = redemption.buildTx(signatures);
210
+ * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
211
+ * ```
71
212
  */
72
213
  redeem: (params: {
73
- shares: bigint;
74
- userAddress: Address;
75
- }) => {
76
- buildTx: () => Readonly<Transaction<VaultV2RedeemAction>>;
77
- };
214
+ readonly shares: bigint;
215
+ readonly userAddress: Address;
216
+ readonly referralFeePct?: bigint;
217
+ readonly referralFeeRecipient?: Address;
218
+ readonly deadline?: bigint;
219
+ }) => ActionOutput<VaultV2RedeemAction, readonly RequirementSignature[], undefined>;
78
220
  /**
79
221
  * Prepares an illiquid Vault V2 exit into idle assets and Morpho Blue supply positions.
80
222
  *
@@ -101,16 +243,18 @@ export interface VaultV2Actions {
101
243
  * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
102
244
  * @returns Lazy prerequisite resolution and a synchronous transaction builder.
103
245
  * @throws {ChainIdMismatchError} when the client and entity target different chains.
246
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
104
247
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
105
- * @throws {NonPositiveInputError} when `amount` is not positive.
248
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
106
249
  * @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
107
250
  * penalty-adjusted amount rounds to zero deallocated assets.
108
251
  * @throws {EmptyMarketParamsListError} when assets must be deallocated and the market list is empty.
252
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
109
253
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
110
254
  * requirement resolution.
111
- * @throws {InKindRedeemRequiresSingleAdapterError} when the vault does not have one adapter.
255
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
112
256
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
113
- * @throws {UnsupportedInKindAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
257
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
114
258
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
115
259
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
116
260
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -153,29 +297,129 @@ export interface VaultV2Actions {
153
297
  readonly deadline?: bigint;
154
298
  }) => ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
155
299
  /**
156
- * Prepares a force withdraw transaction for the VaultV2 contract using the vault's native multicall.
300
+ * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
157
301
  *
158
- * This function encodes one or more on-chain forceDeallocate calls followed by a single withdraw,
159
- * executed atomically via VaultV2's multicall. This allows a user to free liquidity from multiple
160
- * illiquid markets and withdraw the resulting assets in one transaction.
302
+ * The contract withdraws everything the vault can pay without a penalty — its idle assets plus
303
+ * the liquidity available through its liquidity adapter — then force-deallocates the remainder by
304
+ * looping over the adapter's markets. It computes the deallocations itself: the caller supplies
305
+ * neither a market list nor an order.
161
306
  *
162
- * @param {Object} params - The force withdraw parameters.
163
- * @param {readonly Deallocation[]} params.deallocations - The typed list of deallocations to perform.
164
- * @param {Object} params.withdraw - The withdraw parameters applied after deallocations.
165
- * @param {bigint} params.withdraw.amount - The amount of assets to withdraw.
166
- * @param {Address} params.userAddress - User address (penalty source and withdraw recipient).
167
- * @returns {Object} The result object.
168
- * @returns {Readonly<Transaction<VaultV2ForceWithdrawAction>>} returns.buildTx The prepared multicall transaction.
307
+ * `exitAssets` is **penalty-inclusive**, matching `inKindRedeem`. The contract debits it from the
308
+ * user's position but pays out only
309
+ * `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))`, minus the
310
+ * referral fee. Quote the split with `previewVaultV2ForceWithdraw`.
311
+ *
312
+ * The vault must have exactly one `MorphoMarketV1AdapterV2` and route liquidity through that same
313
+ * adapter or none at all. Call `getRequirements()` before `buildTx()` so the vault-share allowance
314
+ * and permit nonce are read on-chain.
315
+ *
316
+ * Unless `minSharePriceE27` is overridden, the SDK derives a conservative lower bound on the
317
+ * realized exit share price from the snapshot and `slippageTolerance`. The bound rejects a share
318
+ * price drop, a penalty increase, and liquidity shifting from the penalty-free leg to the
319
+ * penalised leg. It does **not** cover the referral fee, which the contract deducts afterwards.
320
+ *
321
+ * Vault gates are enforced by the final transaction and are not preflighted: the receive-assets
322
+ * gate must allow VaultExitBundlesV1 and may depend on its transient initiator, while a
323
+ * send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
324
+ * validate the user's share balance. Per-market penalties and each vault withdrawal round the
325
+ * share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
326
+ * implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` — the approved
327
+ * share allowance this handle returns is the exact upper bound on the burn — so a full-balance
328
+ * exit does not revert for insufficient shares.
329
+ *
330
+ * Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
331
+ * an on-chain revert remains possible if vault state changes between preparation and inclusion.
332
+ * A fee-recipient `userAddress` gets a floor from the net share burn after fee mints at `now`,
333
+ * and a guard against fee mints reaching the lower burn bound by the deadline. Its allowance
334
+ * includes the projected fee shares through that same deadline. Deadlines beyond one year after
335
+ * handle creation are rejected, so the guard and allowance cover the whole accepted window.
336
+ *
337
+ * @param params - Force withdrawal parameters.
338
+ * @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
339
+ * @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
340
+ * @param params.userAddress - Account that signs and submits the exit, and receives the assets.
341
+ * @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
342
+ * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
343
+ * Deadlines more than one year after handle creation are rejected.
344
+ * @param params.slippageTolerance - Optional WAD-scaled tolerance applied to the derived share
345
+ * price bound. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`, capped at `MAX_SLIPPAGE_TOLERANCE`.
346
+ * @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound. Must be
347
+ * positive: the contract reads `0` as "no bound", so it cannot be used to opt out.
348
+ * @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
349
+ * `referralFeeRecipient`. Defaults to `0n`.
350
+ * @param params.referralFeeRecipient - Optional referral fee recipient, required when
351
+ * `referralFeePct` is positive.
352
+ * @returns Lazy prerequisite resolution and a synchronous transaction builder.
353
+ * @throws {ChainIdMismatchError} when the client and entity target different chains.
354
+ * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
355
+ * @throws {NonPositiveInputError} when `exitAssets`, `deadline`, or a supplied
356
+ * `minSharePriceE27` is not positive.
357
+ * @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
358
+ * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
359
+ * `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `referralFeePct` is not
360
+ * below WAD, or when `deadline` is more than one year after handle creation.
361
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
362
+ * requirement resolution.
363
+ * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
364
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
365
+ * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
366
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
367
+ * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
368
+ * another adapter.
369
+ * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
370
+ * as `MarketParams`.
371
+ * @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit would withdraw nothing.
372
+ * @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the exit,
373
+ * which would overrun the contract's unbounded loop.
374
+ * @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds down
375
+ * to zero, which the contract would read as no bound at all.
376
+ * @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when fee shares are minted to a
377
+ * fee-recipient `userAddress` and reach the lower-bound share burn at the deadline.
378
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
379
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
380
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
381
+ * @throws {viem.BaseError} from `getRequirements()` when an RPC or multicall contract read fails.
382
+ * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
383
+ * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
384
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
385
+ * deadline differs from this operation. Any handle built from the same inputs accepts the
386
+ * permit; the nonce is verified onchain by the vault's `permit`.
387
+ * @throws {VaultExitBundlesV1PermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
388
+ * @example
389
+ * ```ts
390
+ * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
391
+ *
392
+ * const vault = client.morpho.vaultV2(vaultAddress, 1);
393
+ * const vaultData = await vault.getData();
394
+ * const exit = vault.forceWithdraw({
395
+ * exitAssets: 1_000_000n,
396
+ * vaultData,
397
+ * userAddress,
398
+ * });
399
+ * const signatures = [];
400
+ * for (const requirement of await exit.getRequirements()) {
401
+ * if (isRequirementSignature(requirement)) {
402
+ * signatures.push(await requirement.sign(walletClient, userAddress));
403
+ * } else {
404
+ * const hash = await walletClient.sendTransaction(requirement);
405
+ * await client.waitForTransactionReceipt({ hash });
406
+ * }
407
+ * }
408
+ * const tx = exit.buildTx(signatures);
409
+ * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
410
+ * ```
169
411
  */
170
- forceWithdraw: (params: {
171
- deallocations: readonly Deallocation[];
172
- withdraw: {
173
- amount: bigint;
174
- };
175
- userAddress: Address;
176
- }) => {
177
- buildTx: () => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
178
- };
412
+ readonly forceWithdraw: (params: {
413
+ readonly exitAssets: bigint;
414
+ readonly vaultData: AccrualVaultV2;
415
+ readonly userAddress: Address;
416
+ readonly adapter?: Address;
417
+ readonly deadline?: bigint;
418
+ readonly slippageTolerance?: bigint;
419
+ readonly minSharePriceE27?: bigint;
420
+ readonly referralFeePct?: bigint;
421
+ readonly referralFeeRecipient?: Address;
422
+ }) => ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
179
423
  /**
180
424
  * Prepares a force redeem transaction for the VaultV2 contract using the vault's native multicall.
181
425
  *
@@ -214,28 +458,40 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
214
458
  private readonly chainId;
215
459
  constructor(client: MorphoClientType, vault: Address, chainId: number);
216
460
  getData(parameters?: FetchParameters): Promise<AccrualVaultV2>;
217
- deposit({ amount, userAddress, vaultData, slippageTolerance, nativeAmount, }: {
218
- userAddress: Address;
219
- vaultData: AccrualVaultV2;
220
- slippageTolerance?: bigint;
221
- } & DepositAmountArgs): {
222
- getRequirements: (params?: {
223
- useSimplePermit?: boolean;
224
- }) => Promise<(import("../../types/action.js").Bundler3TokenSignatureRequirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
461
+ /** {@inheritDoc VaultV2Actions.deposit} */
462
+ deposit(params: {
463
+ readonly userAddress: Address;
464
+ readonly vaultData: AccrualVaultV2;
465
+ readonly slippageTolerance?: bigint;
466
+ readonly referralFeePct?: bigint;
467
+ readonly referralFeeRecipient?: Address;
468
+ readonly deadline?: bigint;
469
+ } & BundlesFundingArgs): Readonly<{
470
+ getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
225
471
  buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
226
- };
227
- withdraw({ amount, userAddress }: {
228
- amount: bigint;
229
- userAddress: Address;
230
- }): {
231
- buildTx: () => Readonly<Transaction<VaultV2WithdrawAction>>;
232
- };
233
- redeem({ shares, userAddress }: {
234
- shares: bigint;
235
- userAddress: Address;
236
- }): {
237
- buildTx: () => Readonly<Transaction<VaultV2RedeemAction>>;
238
- };
472
+ }>;
473
+ withdraw(params: {
474
+ readonly amount: bigint;
475
+ readonly userAddress: Address;
476
+ readonly slippageTolerance?: bigint;
477
+ readonly referralFeePct?: bigint;
478
+ readonly referralFeeRecipient?: Address;
479
+ readonly deadline?: bigint;
480
+ }): Readonly<{
481
+ getRequirements: () => Promise<readonly ActionRequirement[]>;
482
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2WithdrawAction>>;
483
+ }>;
484
+ /** {@inheritDoc VaultV2Actions.redeem} */
485
+ redeem(params: {
486
+ readonly shares: bigint;
487
+ readonly userAddress: Address;
488
+ readonly referralFeePct?: bigint;
489
+ readonly referralFeeRecipient?: Address;
490
+ readonly deadline?: bigint;
491
+ }): Readonly<{
492
+ getRequirements: () => Promise<readonly ActionRequirement[]>;
493
+ buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2RedeemAction>>;
494
+ }>;
239
495
  /** {@inheritDoc VaultV2Actions.inKindRedeem} */
240
496
  inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }: {
241
497
  readonly amount: bigint;
@@ -245,15 +501,18 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
245
501
  readonly adapter?: Address;
246
502
  readonly deadline?: bigint;
247
503
  }): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
248
- forceWithdraw({ deallocations, withdraw, userAddress, }: {
249
- deallocations: readonly Deallocation[];
250
- withdraw: {
251
- amount: bigint;
252
- };
253
- userAddress: Address;
254
- }): {
255
- buildTx: () => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
256
- };
504
+ /** {@inheritDoc VaultV2Actions.forceWithdraw} */
505
+ forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, }: {
506
+ readonly exitAssets: bigint;
507
+ readonly vaultData: AccrualVaultV2;
508
+ readonly userAddress: Address;
509
+ readonly adapter?: Address;
510
+ readonly deadline?: bigint;
511
+ readonly slippageTolerance?: bigint;
512
+ readonly minSharePriceE27?: bigint;
513
+ readonly referralFeePct?: bigint;
514
+ readonly referralFeeRecipient?: Address;
515
+ }): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
257
516
  forceRedeem({ deallocations, redeem, userAddress, }: {
258
517
  deallocations: readonly Deallocation[];
259
518
  redeem: {