@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
@@ -1,58 +1,77 @@
1
1
  import { type Address } from "viem";
2
- import { type Deallocation, type Metadata, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
2
+ import { type Metadata, type PermitRequirementSignature, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
3
3
  /** Parameters for {@link vaultV2ForceWithdraw}. */
4
4
  export interface VaultV2ForceWithdrawParams {
5
- vault: {
6
- address: Address;
5
+ readonly vault: {
6
+ readonly chainId: number;
7
+ readonly address: Address;
7
8
  };
8
- args: {
9
- deallocations: readonly Deallocation[];
10
- withdraw: {
11
- amount: bigint;
12
- recipient: Address;
13
- };
14
- onBehalf: Address;
9
+ readonly args: {
10
+ readonly adapter: Address;
11
+ readonly exitAssets: bigint;
12
+ readonly minSharePriceE27: bigint;
13
+ readonly userAddress: Address;
14
+ readonly deadline: bigint;
15
+ readonly referralFeePct?: bigint;
16
+ readonly referralFeeRecipient?: Address;
17
+ readonly requirementSignature?: PermitRequirementSignature;
15
18
  };
16
- metadata?: Metadata;
19
+ readonly metadata?: Metadata;
17
20
  }
18
21
  /**
19
- * Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
22
+ * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
20
23
  *
21
- * Encodes one or more `forceDeallocate` calls followed by a single `withdraw`, executed
22
- * atomically through VaultV2's `multicall`. Frees liquidity from non-liquidity adapters and
23
- * withdraws the resulting assets in one transaction.
24
+ * The contract first withdraws everything the vault can pay without a penalty — its idle assets
25
+ * plus the liquidity available through its liquidity adapter — then force-deallocates the remainder
26
+ * by looping over the adapter's markets.
24
27
  *
25
- * A penalty is taken from `onBehalf` for each deallocation to discourage allocation
26
- * manipulation. The penalty is applied as a share burn where assets are returned to the vault,
27
- * so the share price stays stable (except for rounding).
28
+ * `exitAssets` is **penalty-inclusive**: it is what the contract debits from the user's position,
29
+ * while the assets actually delivered are
30
+ * `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))` minus the
31
+ * referral fee. Use `previewVaultV2ForceWithdraw` to quote the split.
28
32
  *
29
- * @param params.vault.address - The VaultV2 address.
30
- * @param params.args.deallocations - The deallocations to perform before withdrawing. Must be
31
- * non-empty.
32
- * @param params.args.withdraw.amount - Amount of underlying assets to withdraw after the
33
- * deallocations complete.
34
- * @param params.args.withdraw.recipient - Address that receives the withdrawn assets.
35
- * @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
36
- * penalty is taken.
37
- * @param params.metadata - Optional analytics metadata attached to the multicall transaction.
38
- * @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
39
- * and the typed `action` discriminator the simulation layer consumes.
40
- * @throws {EmptyDeallocationsError} when `deallocations` is empty.
41
- * @throws {NonPositiveInputError} when `withdraw.amount <= 0n`, or when any
42
- * `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
33
+ * Without a signature this embeds the empty-permit sentinel and requires a sufficient vault-share
34
+ * approval to VaultExitBundlesV1.
35
+ *
36
+ * @param params - Force withdrawal parameters.
37
+ * @param params.vault.chainId - Chain containing the target Vault V2 and VaultExitBundlesV1.
38
+ * @param params.vault.address - Target Vault V2 address.
39
+ * @param params.args.adapter - Vault's sole MorphoMarketV1AdapterV2.
40
+ * @param params.args.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
41
+ * @param params.args.minSharePriceE27 - RAY-scaled lower bound on the realized exit share price
42
+ * (withdrawn assets per share burned). `0n` disables the on-chain bound; prefer the value the
43
+ * entity computes.
44
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
45
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares and pays out to `msg.sender`, so the
46
+ * submitting account must equal this address.
47
+ * @param params.args.deadline - Permit and bundle deadline.
48
+ * @param params.args.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
49
+ * `referralFeeRecipient`. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
50
+ * is outside that bound's protection.
51
+ * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
52
+ * address, which is only valid alongside a zero `referralFeePct`.
53
+ * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
54
+ * @param params.metadata - Optional analytics metadata.
55
+ * @returns A deep-frozen `Readonly<Transaction<VaultV2ForceWithdrawAction>>` with `to`, `value`,
56
+ * `data`, and the typed action discriminator.
57
+ * @throws {NonPositiveInputError} when `exitAssets` or `deadline` is not positive.
58
+ * @throws {NegativeInputError} when `referralFeePct` or `minSharePriceE27` is negative.
59
+ * @throws {InputExceedsMaxError} when `referralFeePct` is not below WAD (the contract rejects it
60
+ * with `PctExceeded`), or when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
61
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
62
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
63
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
64
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind,
65
+ * asset, owner, spender, or signature encoding.
43
66
  * @example
44
67
  * ```ts
45
68
  * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
46
69
  *
47
70
  * const tx = vaultV2ForceWithdraw({
48
- * vault: { address: vaultAddress },
49
- * args: {
50
- * deallocations: [{ adapter, marketParams, amount: 500_000n }],
51
- * withdraw: { amount: 500_000n, recipient },
52
- * onBehalf,
53
- * },
71
+ * vault: { chainId: 1, address: vault },
72
+ * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
54
73
  * });
55
74
  * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
56
75
  * ```
57
76
  */
58
- export declare const vaultV2ForceWithdraw: ({ vault: { address: vaultAddress }, args: { deallocations, withdraw, onBehalf }, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
77
+ export declare const vaultV2ForceWithdraw: ({ vault, args, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
@@ -1,90 +1,117 @@
1
- import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
2
- import { deepFreeze } from "@morpho-org/morpho-ts";
1
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
2
  import { encodeFunctionData } from "viem";
4
- import { encodeForceDeallocateCall } from "../../helpers/encodeDeallocation.js";
3
+ import { vaultExitBundlesV1Abi } from "../../abis.js";
5
4
  import { addTransactionMetadata } from "../../helpers/index.js";
6
- import { EmptyDeallocationsError, NonPositiveInputError, } from "../../types/index.js";
5
+ import { validateDeadline, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
6
+ import { NonPositiveInputError, } from "../../types/index.js";
7
+ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBundlesV1PermitStruct.js";
7
8
  /**
8
- * Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
9
+ * Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
9
10
  *
10
- * Encodes one or more `forceDeallocate` calls followed by a single `withdraw`, executed
11
- * atomically through VaultV2's `multicall`. Frees liquidity from non-liquidity adapters and
12
- * withdraws the resulting assets in one transaction.
11
+ * The contract first withdraws everything the vault can pay without a penalty — its idle assets
12
+ * plus the liquidity available through its liquidity adapter — then force-deallocates the remainder
13
+ * by looping over the adapter's markets.
13
14
  *
14
- * A penalty is taken from `onBehalf` for each deallocation to discourage allocation
15
- * manipulation. The penalty is applied as a share burn where assets are returned to the vault,
16
- * so the share price stays stable (except for rounding).
15
+ * `exitAssets` is **penalty-inclusive**: it is what the contract debits from the user's position,
16
+ * while the assets actually delivered are
17
+ * `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))` minus the
18
+ * referral fee. Use `previewVaultV2ForceWithdraw` to quote the split.
17
19
  *
18
- * @param params.vault.address - The VaultV2 address.
19
- * @param params.args.deallocations - The deallocations to perform before withdrawing. Must be
20
- * non-empty.
21
- * @param params.args.withdraw.amount - Amount of underlying assets to withdraw after the
22
- * deallocations complete.
23
- * @param params.args.withdraw.recipient - Address that receives the withdrawn assets.
24
- * @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
25
- * penalty is taken.
26
- * @param params.metadata - Optional analytics metadata attached to the multicall transaction.
27
- * @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
28
- * and the typed `action` discriminator the simulation layer consumes.
29
- * @throws {EmptyDeallocationsError} when `deallocations` is empty.
30
- * @throws {NonPositiveInputError} when `withdraw.amount <= 0n`, or when any
31
- * `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
20
+ * Without a signature this embeds the empty-permit sentinel and requires a sufficient vault-share
21
+ * approval to VaultExitBundlesV1.
22
+ *
23
+ * @param params - Force withdrawal parameters.
24
+ * @param params.vault.chainId - Chain containing the target Vault V2 and VaultExitBundlesV1.
25
+ * @param params.vault.address - Target Vault V2 address.
26
+ * @param params.args.adapter - Vault's sole MorphoMarketV1AdapterV2.
27
+ * @param params.args.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
28
+ * @param params.args.minSharePriceE27 - RAY-scaled lower bound on the realized exit share price
29
+ * (withdrawn assets per share burned). `0n` disables the on-chain bound; prefer the value the
30
+ * entity computes.
31
+ * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
32
+ * VaultExitBundlesV1 burns `msg.sender`'s vault shares and pays out to `msg.sender`, so the
33
+ * submitting account must equal this address.
34
+ * @param params.args.deadline - Permit and bundle deadline.
35
+ * @param params.args.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
36
+ * `referralFeeRecipient`. Defaults to `0n`. Deducted *after* the `minSharePriceE27` check, so it
37
+ * is outside that bound's protection.
38
+ * @param params.args.referralFeeRecipient - Optional referral fee recipient. Defaults to the zero
39
+ * address, which is only valid alongside a zero `referralFeePct`.
40
+ * @param params.args.requirementSignature - Optional bounded Vault V2 shares permit.
41
+ * @param params.metadata - Optional analytics metadata.
42
+ * @returns A deep-frozen `Readonly<Transaction<VaultV2ForceWithdrawAction>>` with `to`, `value`,
43
+ * `data`, and the typed action discriminator.
44
+ * @throws {NonPositiveInputError} when `exitAssets` or `deadline` is not positive.
45
+ * @throws {NegativeInputError} when `referralFeePct` or `minSharePriceE27` is negative.
46
+ * @throws {InputExceedsMaxError} when `referralFeePct` is not below WAD (the contract rejects it
47
+ * with `PctExceeded`), or when `exitAssets`, `deadline`, or `minSharePriceE27` exceeds `uint256`.
48
+ * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
49
+ * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
50
+ * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
51
+ * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind,
52
+ * asset, owner, spender, or signature encoding.
32
53
  * @example
33
54
  * ```ts
34
55
  * import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
35
56
  *
36
57
  * const tx = vaultV2ForceWithdraw({
37
- * vault: { address: vaultAddress },
38
- * args: {
39
- * deallocations: [{ adapter, marketParams, amount: 500_000n }],
40
- * withdraw: { amount: 500_000n, recipient },
41
- * onBehalf,
42
- * },
58
+ * vault: { chainId: 1, address: vault },
59
+ * args: { adapter, exitAssets: 1_000_000n, minSharePriceE27, userAddress, deadline },
43
60
  * });
44
61
  * // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
45
62
  * ```
46
63
  */
47
- export const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: { deallocations, withdraw, onBehalf }, metadata, }) => {
48
- if (deallocations.length === 0) {
49
- throw new EmptyDeallocationsError(vaultAddress);
50
- }
51
- const { amount: withdrawAmount, recipient: withdrawRecipient } = withdraw;
52
- if (withdrawAmount <= 0n) {
53
- throw new NonPositiveInputError("withdraw.amount", withdrawAmount);
54
- }
55
- const calls = [];
56
- for (const deallocation of deallocations) {
57
- calls.push(encodeForceDeallocateCall(deallocation, onBehalf));
58
- }
59
- calls.push(encodeFunctionData({
60
- abi: vaultV2Abi,
61
- functionName: "withdraw",
62
- args: [withdrawAmount, withdrawRecipient, onBehalf],
63
- }));
64
+ export const vaultV2ForceWithdraw = ({ vault, args, metadata, }) => {
65
+ if (args.exitAssets <= 0n)
66
+ throw new NonPositiveInputError("exitAssets", args.exitAssets);
67
+ validateUint256Field("exitAssets", args.exitAssets);
68
+ validateDeadline(args.deadline);
69
+ // `0n` stays valid — it is the intentional "no on-chain bound" opt-out — but a value the uint256
70
+ // slot cannot hold must fail with a dedicated error instead of viem's `IntegerOutOfRangeError`.
71
+ // The entity never emits these (it forbids a non-positive override); this guards direct callers.
72
+ validateUint256Field("minSharePriceE27", args.minSharePriceE27);
73
+ const { referralFeePct, referralFeeRecipient } = validateReferralFee(args);
74
+ const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
75
+ const sharesPermit = getVaultExitBundlesV1PermitStruct({
76
+ vault: vault.address,
77
+ deadline: args.deadline,
78
+ owner: args.userAddress,
79
+ spender: to,
80
+ requirementSignature: args.requirementSignature,
81
+ });
64
82
  let tx = {
65
- to: vaultAddress,
83
+ to,
84
+ value: 0n,
66
85
  data: encodeFunctionData({
67
- abi: vaultV2Abi,
68
- functionName: "multicall",
69
- args: [calls],
86
+ abi: vaultExitBundlesV1Abi,
87
+ functionName: "vaultExitBundlesV1ForceWithdrawVaultV2",
88
+ args: [
89
+ vault.address,
90
+ args.adapter,
91
+ args.exitAssets,
92
+ args.minSharePriceE27,
93
+ sharesPermit,
94
+ referralFeePct,
95
+ referralFeeRecipient,
96
+ args.deadline,
97
+ ],
70
98
  }),
71
- value: 0n,
72
99
  };
73
- if (metadata) {
100
+ if (metadata)
74
101
  tx = addTransactionMetadata(tx, metadata);
75
- }
76
102
  return deepFreeze({
77
103
  ...tx,
78
104
  action: {
79
105
  type: "vaultV2ForceWithdraw",
80
106
  args: {
81
- vault: vaultAddress,
82
- deallocations: deallocations.map((d) => ({ ...d })),
83
- withdraw: {
84
- amount: withdrawAmount,
85
- recipient: withdrawRecipient,
86
- },
87
- onBehalf,
107
+ vault: vault.address,
108
+ adapter: args.adapter,
109
+ exitAssets: args.exitAssets,
110
+ minSharePriceE27: args.minSharePriceE27,
111
+ referralFeePct,
112
+ referralFeeRecipient,
113
+ onBehalf: args.userAddress,
114
+ deadline: args.deadline,
88
115
  },
89
116
  },
90
117
  });
@@ -39,6 +39,7 @@ export interface VaultV2InKindRedeemParams {
39
39
  * @returns A deep-frozen `Readonly<Transaction<VaultV2InKindRedeemAction>>` with `to`, `value`,
40
40
  * `data`, and the typed action discriminator.
41
41
  * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
42
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
42
43
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
43
44
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
44
45
  * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
@@ -2,6 +2,7 @@ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { vaultExitBundlesV1Abi } from "../../abis.js";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateDeadline } from "../../helpers/validate.js";
5
6
  import { NonPositiveInputError, } from "../../types/index.js";
6
7
  import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBundlesV1PermitStruct.js";
7
8
  /**
@@ -26,6 +27,7 @@ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBun
26
27
  * @returns A deep-frozen `Readonly<Transaction<VaultV2InKindRedeemAction>>` with `to`, `value`,
27
28
  * `data`, and the typed action discriminator.
28
29
  * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
30
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
29
31
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
30
32
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
31
33
  * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
@@ -43,8 +45,7 @@ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBun
43
45
  export const vaultV2InKindRedeem = ({ vault, args, metadata, }) => {
44
46
  if (args.amount <= 0n)
45
47
  throw new NonPositiveInputError("amount", args.amount);
46
- if (args.deadline <= 0n)
47
- throw new NonPositiveInputError("deadline", args.deadline);
48
+ validateDeadline(args.deadline);
48
49
  const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
49
50
  const marketParamsList = args.marketParamsList.map((marketParams) => ({
50
51
  loanToken: marketParams.loanToken,
@@ -1,40 +1,46 @@
1
1
  import { type Address } from "viem";
2
- import { type Metadata, type Transaction, type VaultV2RedeemAction } from "../../types/index.js";
2
+ import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV2RedeemAction } from "../../types/index.js";
3
3
  /** Parameters for {@link vaultV2Redeem}. */
4
4
  export interface VaultV2RedeemParams {
5
- vault: {
6
- address: Address;
5
+ readonly vault: {
6
+ readonly chainId: number;
7
+ readonly address: Address;
7
8
  };
8
- args: {
9
- shares: bigint;
10
- recipient: Address;
11
- onBehalf: Address;
9
+ readonly args: {
10
+ readonly shares: bigint;
11
+ readonly userAddress: Address;
12
+ readonly recipient?: never;
13
+ readonly onBehalf?: never;
14
+ readonly requirementSignature?: Erc2612RequirementSignature;
15
+ readonly referralFeePct?: bigint;
16
+ readonly referralFeeRecipient?: Address;
17
+ readonly deadline: bigint;
12
18
  };
13
- metadata?: Metadata;
19
+ readonly metadata?: Metadata;
14
20
  }
15
21
  /**
16
- * Prepares a redeem transaction for a VaultV2 contract.
22
+ * Encodes an exact-shares Vault V2 redemption through VaultBundlesV1.
17
23
  *
18
- * Direct vault call — not routed through the bundler. Redeem has no inflation-attack surface,
19
- * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
20
- *
21
- * @param params.vault.address - The VaultV2 address.
22
- * @param params.args.shares - Amount of vault shares to redeem.
23
- * @param params.args.recipient - Address that receives the redeemed assets.
24
- * @param params.args.onBehalf - Address whose shares are burned.
25
- * @param params.metadata - Optional analytics metadata attached to the transaction.
26
- * @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
27
- * typed `action` discriminator the simulation layer consumes.
28
- * @throws {NonPositiveInputError} when `shares <= 0n`.
24
+ * @param params - Vault, shares, share permit, fee, and deadline values.
25
+ * @returns A deep-frozen VaultBundlesV1 redemption transaction.
26
+ * @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
27
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
28
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
29
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
30
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
31
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
32
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
33
+ * @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
29
34
  * @example
30
35
  * ```ts
31
36
  * import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
37
+ * import { zeroAddress } from "viem";
32
38
  *
33
39
  * const tx = vaultV2Redeem({
34
- * vault: { address: vaultAddress },
35
- * args: { shares: 1_000_000n, recipient, onBehalf },
40
+ * vault: { chainId: 1, address: zeroAddress },
41
+ * args: { shares: 1_000_000n, userAddress: zeroAddress, deadline: 1_900_000_000n },
36
42
  * });
37
- * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
43
+ * // tx.action.type === "vaultV2Redeem"
38
44
  * ```
39
45
  */
40
- export declare const vaultV2Redeem: ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }: VaultV2RedeemParams) => Readonly<Transaction<VaultV2RedeemAction>>;
46
+ export declare const vaultV2Redeem: (params: VaultV2RedeemParams) => Readonly<Transaction<VaultV2RedeemAction>>;
@@ -1,54 +1,76 @@
1
- import { vaultV2Abi } from "@morpho-org/blue-sdk-viem";
2
- import { deepFreeze } from "@morpho-org/morpho-ts";
1
+ import { getChainAddress } from "@morpho-org/morpho-ts";
3
2
  import { encodeFunctionData } from "viem";
4
- import { addTransactionMetadata } from "../../helpers/index.js";
3
+ import { vaultBundlesV1Abi } from "../../abis.js";
4
+ import { validateUint256Field } from "../../helpers/validate.js";
5
5
  import { NonPositiveInputError, } from "../../types/index.js";
6
+ import { finalizeVaultBundlesV1Transaction, getBundlesSharesPermit, normalizeBundlesCommonParams, } from "../bundles/common.js";
6
7
  /**
7
- * Prepares a redeem transaction for a VaultV2 contract.
8
+ * Encodes an exact-shares Vault V2 redemption through VaultBundlesV1.
8
9
  *
9
- * Direct vault call — not routed through the bundler. Redeem has no inflation-attack surface,
10
- * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
11
- *
12
- * @param params.vault.address - The VaultV2 address.
13
- * @param params.args.shares - Amount of vault shares to redeem.
14
- * @param params.args.recipient - Address that receives the redeemed assets.
15
- * @param params.args.onBehalf - Address whose shares are burned.
16
- * @param params.metadata - Optional analytics metadata attached to the transaction.
17
- * @returns A deep-frozen `Transaction<VaultV2RedeemAction>` with `to`, `value`, `data`, and the
18
- * typed `action` discriminator the simulation layer consumes.
19
- * @throws {NonPositiveInputError} when `shares <= 0n`.
10
+ * @param params - Vault, shares, share permit, fee, and deadline values.
11
+ * @returns A deep-frozen VaultBundlesV1 redemption transaction.
12
+ * @throws {NonPositiveInputError} when `shares` or `deadline` is not positive.
13
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
14
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
15
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
16
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
17
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
18
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
19
+ * @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
20
20
  * @example
21
21
  * ```ts
22
22
  * import { vaultV2Redeem } from "@morpho-org/morpho-sdk";
23
+ * import { zeroAddress } from "viem";
23
24
  *
24
25
  * const tx = vaultV2Redeem({
25
- * vault: { address: vaultAddress },
26
- * args: { shares: 1_000_000n, recipient, onBehalf },
26
+ * vault: { chainId: 1, address: zeroAddress },
27
+ * args: { shares: 1_000_000n, userAddress: zeroAddress, deadline: 1_900_000_000n },
27
28
  * });
28
- * // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
29
+ * // tx.action.type === "vaultV2Redeem"
29
30
  * ```
30
31
  */
31
- export const vaultV2Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
32
- if (shares <= 0n) {
33
- throw new NonPositiveInputError("shares", shares);
32
+ export const vaultV2Redeem = (params) => {
33
+ if (params.args.shares <= 0n) {
34
+ throw new NonPositiveInputError("shares", params.args.shares);
34
35
  }
35
- let tx = {
36
- to: vaultAddress,
36
+ // Reject ABI overflow with SDK errors before calldata encoding.
37
+ validateUint256Field("shares", params.args.shares);
38
+ const common = normalizeBundlesCommonParams(params.args);
39
+ const spender = getChainAddress(params.vault.chainId, "bundles.vaultBundlesV1");
40
+ const sharesPermit = getBundlesSharesPermit({
41
+ vault: params.vault.address,
42
+ deadline: common.deadline,
43
+ owner: params.args.userAddress,
44
+ spender,
45
+ amount: params.args.shares,
46
+ requirementSignature: params.args.requirementSignature,
47
+ });
48
+ return finalizeVaultBundlesV1Transaction({
49
+ chainId: params.vault.chainId,
50
+ value: 0n,
37
51
  data: encodeFunctionData({
38
- abi: vaultV2Abi,
39
- functionName: "redeem",
40
- args: [shares, recipient, onBehalf],
52
+ abi: vaultBundlesV1Abi,
53
+ functionName: "vaultBundlesV1Withdraw",
54
+ args: [
55
+ params.vault.address,
56
+ 0n,
57
+ params.args.shares,
58
+ sharesPermit,
59
+ common.referralFeePct,
60
+ common.referralFeeRecipient,
61
+ common.deadline,
62
+ ],
41
63
  }),
42
- value: 0n,
43
- };
44
- if (metadata) {
45
- tx = addTransactionMetadata(tx, metadata);
46
- }
47
- return deepFreeze({
48
- ...tx,
49
64
  action: {
50
65
  type: "vaultV2Redeem",
51
- args: { vault: vaultAddress, shares, recipient },
66
+ args: {
67
+ vault: params.vault.address,
68
+ shares: params.args.shares,
69
+ referralFeePct: common.referralFeePct,
70
+ referralFeeRecipient: common.referralFeeRecipient,
71
+ deadline: common.deadline,
72
+ },
52
73
  },
74
+ metadata: params.metadata,
53
75
  });
54
76
  };
@@ -1,40 +1,73 @@
1
1
  import { type Address } from "viem";
2
- import { type Metadata, type Transaction, type VaultV2WithdrawAction } from "../../types/index.js";
2
+ import { type Erc2612RequirementSignature, type Metadata, type Transaction, type VaultV2WithdrawAction } from "../../types/index.js";
3
3
  /** Parameters for {@link vaultV2Withdraw}. */
4
4
  export interface VaultV2WithdrawParams {
5
- vault: {
6
- address: Address;
5
+ readonly vault: {
6
+ readonly chainId: number;
7
+ readonly address: Address;
7
8
  };
8
- args: {
9
- amount: bigint;
10
- recipient: Address;
11
- onBehalf: Address;
9
+ readonly args: {
10
+ readonly amount: bigint;
11
+ readonly userAddress: Address;
12
+ readonly recipient?: never;
13
+ readonly onBehalf?: never;
14
+ readonly requirementSignature?: Erc2612RequirementSignature;
15
+ readonly referralFeePct?: bigint;
16
+ readonly referralFeeRecipient?: Address;
17
+ readonly deadline: bigint;
12
18
  };
13
- metadata?: Metadata;
19
+ readonly metadata?: Metadata;
14
20
  }
15
21
  /**
16
- * Prepares a withdraw transaction for a VaultV2 contract.
22
+ * Encodes an exact-assets Vault V2 withdrawal through VaultBundlesV1.
17
23
  *
18
- * Direct vault call — not routed through the bundler. Withdraw has no inflation-attack surface,
19
- * so skipping the bundler avoids an unnecessary approval and keeps the UX clean.
24
+ * This low-level builder does not bind `permit.value` to a share cap; use
25
+ * `MorphoVaultV2.withdraw().buildTx()` to validate it against the cap from `getRequirements()`.
20
26
  *
21
- * @param params.vault.address - The VaultV2 address.
22
- * @param params.args.amount - Amount of underlying assets to withdraw.
23
- * @param params.args.recipient - Address that receives the withdrawn assets.
24
- * @param params.args.onBehalf - Address whose shares are burned.
25
- * @param params.metadata - Optional analytics metadata attached to the transaction.
26
- * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` with `to`, `value`, `data`, and the
27
- * typed `action` discriminator the simulation layer consumes.
28
- * @throws {NonPositiveInputError} when `amount <= 0n`.
27
+ * @param params.vault.chainId - Chain containing the vault and its registered VaultBundlesV1 contract.
28
+ * @param params.vault.address - Vault V2 whose shares are burned for the withdrawal.
29
+ * @param params.args.amount - Positive gross withdrawal in underlying asset base units, before fees.
30
+ * @param params.args.userAddress - Share owner and transaction sender; receives the net withdrawn assets.
31
+ * @param params.args.recipient - Unsupported; net assets are always paid to the transaction sender.
32
+ * @param params.args.onBehalf - Unsupported; VaultBundlesV1 always burns the transaction sender's shares.
33
+ * @param params.args.requirementSignature - Optional ERC-2612 vault-share permit for `userAddress`
34
+ * and the registered VaultBundlesV1 spender. Omit when the exact share allowance is already set.
35
+ * @param params.args.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero.
36
+ * The fee is rounded down and deducted from the gross withdrawn assets.
37
+ * @param params.args.referralFeeRecipient - Optional fee recipient; a nonzero address is required
38
+ * when `referralFeePct > 0n`.
39
+ * @param params.args.deadline - Required positive uint256 Unix timestamp in seconds after which
40
+ * execution reverts. This pure builder does not check the current time.
41
+ * @param params.metadata - Optional analytics metadata appended to the transaction calldata.
42
+ * @param params.metadata.origin - Hex origin identifier of at most four bytes, with an optional `0x` prefix.
43
+ * @param params.metadata.timestamp - Optional flag to append the current timestamp; defaults to false.
44
+ * @returns A deep-frozen `Transaction<VaultV2WithdrawAction>` targeting VaultBundlesV1, with
45
+ * `to`, `value: 0n`, `data`, and gross/fee/net withdrawal action metadata.
46
+ * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
47
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
48
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
49
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
50
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
51
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
52
+ * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
53
+ * @throws {BundlesPermitMismatchError} when the optional share permit is incompatible.
54
+ * @throws {viem.BaseError} when transaction encoding fails.
29
55
  * @example
30
56
  * ```ts
31
57
  * import { vaultV2Withdraw } from "@morpho-org/morpho-sdk";
58
+ * import type { Address } from "viem";
59
+ * import { mainnet } from "viem/chains";
32
60
  *
33
- * const tx = vaultV2Withdraw({
34
- * vault: { address: vaultAddress },
35
- * args: { amount: 500_000n, recipient, onBehalf },
36
- * });
37
- * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
61
+ * export function buildUsdcWithdrawal(userAddress: Address, deadline: bigint) {
62
+ * const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
63
+ * // Set the exact vault-share allowance before submitting; the entity API derives that cap.
64
+ * const tx = vaultV2Withdraw({
65
+ * vault: { chainId: mainnet.id, address: vault },
66
+ * args: { amount: 1_000_000n, userAddress, deadline },
67
+ * });
68
+ * // tx satisfies Readonly<Transaction<VaultV2WithdrawAction>>
69
+ * return tx;
70
+ * }
38
71
  * ```
39
72
  */
40
- export declare const vaultV2Withdraw: ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }: VaultV2WithdrawParams) => Readonly<Transaction<VaultV2WithdrawAction>>;
73
+ export declare const vaultV2Withdraw: (params: VaultV2WithdrawParams) => Readonly<Transaction<VaultV2WithdrawAction>>;