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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/MIGRATION-v5-to-v6.md +329 -15
  2. package/README.md +93 -47
  3. package/lib/cjs/abis.d.ts +227 -2
  4. package/lib/cjs/abis.js +156 -3
  5. package/lib/cjs/actions/blue/borrow.d.ts +1 -1
  6. package/lib/cjs/actions/blue/borrow.js +1 -1
  7. package/lib/cjs/actions/blue/common.d.ts +6 -19
  8. package/lib/cjs/actions/blue/common.js +28 -162
  9. package/lib/cjs/actions/blue/refinance.d.ts +1 -1
  10. package/lib/cjs/actions/blue/refinance.js +1 -1
  11. package/lib/cjs/actions/blue/repay.d.ts +3 -3
  12. package/lib/cjs/actions/blue/repay.js +1 -1
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
  15. package/lib/cjs/actions/blue/supply.d.ts +3 -3
  16. package/lib/cjs/actions/blue/supply.js +3 -8
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
  18. package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
  21. package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
  22. package/lib/cjs/actions/blue/withdraw.js +1 -1
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
  25. package/lib/cjs/actions/bundles/common.d.ts +230 -0
  26. package/lib/cjs/actions/bundles/common.js +507 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +1 -0
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  41. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
  42. package/lib/cjs/actions/requirements/blue/index.js +0 -2
  43. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  44. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  45. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  46. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  51. package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  52. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -1
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  58. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  59. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  60. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
  61. package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
  62. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  64. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
  65. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  66. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  67. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  68. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  69. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  70. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  71. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  72. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  73. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  74. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  75. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  76. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  77. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  78. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  79. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  80. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  81. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  82. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  83. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  84. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  85. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  86. package/lib/cjs/blue/abis.d.ts +5 -1
  87. package/lib/cjs/blue/abis.js +2 -0
  88. package/lib/cjs/blue/entities.d.ts +8 -2
  89. package/lib/cjs/blue/entities.js +1 -0
  90. package/lib/cjs/blue/errors.d.ts +1 -1
  91. package/lib/cjs/blue/errors.js +2 -1
  92. package/lib/cjs/blue/fetch.d.ts +3 -1
  93. package/lib/cjs/blue/fetch.js +1 -0
  94. package/lib/cjs/entities/blue/blue.d.ts +29 -20
  95. package/lib/cjs/entities/blue/blue.js +6 -1
  96. package/lib/cjs/entities/index.d.ts +9 -2
  97. package/lib/cjs/entities/index.js +16 -0
  98. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  99. package/lib/cjs/entities/midnight/midnight.js +20 -24
  100. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  101. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
  102. package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  103. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  104. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  105. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  106. package/lib/cjs/entities/requirements/index.d.ts +2 -0
  107. package/lib/cjs/entities/requirements/index.js +18 -0
  108. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
  109. package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
  110. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  111. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  112. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
  113. package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
  114. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  115. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  116. package/lib/cjs/errors.d.ts +1 -1
  117. package/lib/cjs/errors.js +3 -2
  118. package/lib/cjs/fetch.d.ts +3 -1
  119. package/lib/cjs/fetch.js +1 -0
  120. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  121. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  122. package/lib/cjs/helpers/index.d.ts +4 -1
  123. package/lib/cjs/helpers/index.js +14 -1
  124. package/lib/cjs/helpers/metadata.d.ts +3 -5
  125. package/lib/cjs/helpers/metadata.js +4 -6
  126. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  127. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  128. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  129. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  130. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  131. package/lib/cjs/helpers/referralFee.js +35 -0
  132. package/lib/cjs/helpers/slippage.d.ts +136 -1
  133. package/lib/cjs/helpers/slippage.js +188 -0
  134. package/lib/cjs/helpers/validate.d.ts +67 -8
  135. package/lib/cjs/helpers/validate.js +94 -9
  136. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  137. package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
  138. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  139. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  140. package/lib/cjs/index.d.ts +1 -0
  141. package/lib/cjs/index.js +1 -0
  142. package/lib/cjs/types/action.d.ts +273 -82
  143. package/lib/cjs/types/action.js +12 -12
  144. package/lib/cjs/types/error.d.ts +349 -23
  145. package/lib/cjs/types/error.js +393 -39
  146. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  147. package/lib/cjs/utils.d.ts +3 -1
  148. package/lib/cjs/utils.js +10 -1
  149. package/lib/esm/abis.d.ts +227 -2
  150. package/lib/esm/abis.js +157 -2
  151. package/lib/esm/actions/blue/borrow.d.ts +1 -1
  152. package/lib/esm/actions/blue/borrow.js +1 -1
  153. package/lib/esm/actions/blue/common.d.ts +6 -19
  154. package/lib/esm/actions/blue/common.js +30 -164
  155. package/lib/esm/actions/blue/refinance.d.ts +1 -1
  156. package/lib/esm/actions/blue/refinance.js +1 -1
  157. package/lib/esm/actions/blue/repay.d.ts +3 -3
  158. package/lib/esm/actions/blue/repay.js +1 -1
  159. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  160. package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
  161. package/lib/esm/actions/blue/supply.d.ts +3 -3
  162. package/lib/esm/actions/blue/supply.js +5 -10
  163. package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
  164. package/lib/esm/actions/blue/supplyCollateral.js +1 -1
  165. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  166. package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
  167. package/lib/esm/actions/blue/withdraw.d.ts +1 -1
  168. package/lib/esm/actions/blue/withdraw.js +1 -1
  169. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  170. package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
  171. package/lib/esm/actions/bundles/common.d.ts +230 -0
  172. package/lib/esm/actions/bundles/common.js +494 -0
  173. package/lib/esm/actions/bundles/index.d.ts +3 -0
  174. package/lib/esm/actions/bundles/index.js +2 -0
  175. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  176. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  177. package/lib/esm/actions/index.d.ts +1 -0
  178. package/lib/esm/actions/index.js +1 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  180. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  181. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  182. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  183. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  184. package/lib/esm/actions/midnight/takeLend.js +2 -2
  185. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  186. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  187. package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
  188. package/lib/esm/actions/requirements/blue/index.js +0 -2
  189. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  190. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
  191. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  192. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  194. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
  195. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  196. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  197. package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  198. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
  199. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  200. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  201. package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
  202. package/lib/esm/actions/requirements/encode/index.js +1 -1
  203. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  204. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  205. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  206. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
  207. package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
  208. package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
  209. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  210. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
  211. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  212. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  213. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  214. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  215. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  216. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  217. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  218. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  219. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  220. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  221. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  222. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  223. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  224. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  225. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  226. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  227. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  228. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  229. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  230. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  231. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  232. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  233. package/lib/esm/blue/abis.d.ts +5 -1
  234. package/lib/esm/blue/abis.js +5 -1
  235. package/lib/esm/blue/entities.d.ts +8 -2
  236. package/lib/esm/blue/entities.js +3 -1
  237. package/lib/esm/blue/errors.d.ts +1 -1
  238. package/lib/esm/blue/errors.js +1 -1
  239. package/lib/esm/blue/fetch.d.ts +3 -1
  240. package/lib/esm/blue/fetch.js +3 -1
  241. package/lib/esm/entities/blue/blue.d.ts +29 -20
  242. package/lib/esm/entities/blue/blue.js +7 -2
  243. package/lib/esm/entities/index.d.ts +9 -2
  244. package/lib/esm/entities/index.js +4 -1
  245. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  246. package/lib/esm/entities/midnight/midnight.js +20 -24
  247. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  248. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
  249. package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  250. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  251. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  252. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  253. package/lib/esm/entities/requirements/index.d.ts +2 -0
  254. package/lib/esm/entities/requirements/index.js +2 -0
  255. package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
  256. package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
  257. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  258. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  259. package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
  260. package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
  261. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  262. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  263. package/lib/esm/errors.d.ts +1 -1
  264. package/lib/esm/errors.js +1 -1
  265. package/lib/esm/fetch.d.ts +3 -1
  266. package/lib/esm/fetch.js +3 -1
  267. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  268. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  269. package/lib/esm/helpers/index.d.ts +4 -1
  270. package/lib/esm/helpers/index.js +4 -1
  271. package/lib/esm/helpers/metadata.d.ts +3 -5
  272. package/lib/esm/helpers/metadata.js +4 -6
  273. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  274. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  275. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  276. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  277. package/lib/esm/helpers/referralFee.d.ts +21 -0
  278. package/lib/esm/helpers/referralFee.js +31 -0
  279. package/lib/esm/helpers/slippage.d.ts +136 -1
  280. package/lib/esm/helpers/slippage.js +186 -2
  281. package/lib/esm/helpers/validate.d.ts +67 -8
  282. package/lib/esm/helpers/validate.js +92 -10
  283. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  284. package/lib/esm/helpers/validateRequirementSpender.js +1 -0
  285. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  286. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  287. package/lib/esm/index.d.ts +1 -0
  288. package/lib/esm/index.js +1 -0
  289. package/lib/esm/types/action.d.ts +273 -82
  290. package/lib/esm/types/action.js +11 -11
  291. package/lib/esm/types/error.d.ts +349 -23
  292. package/lib/esm/types/error.js +377 -31
  293. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  294. package/lib/esm/utils.d.ts +3 -1
  295. package/lib/esm/utils.js +3 -1
  296. package/package.json +7 -7
@@ -6,10 +6,13 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const actions_1 = require("viem/actions");
9
+ const common_js_1 = require("../../actions/bundles/common.js");
9
10
  const index_js_1 = require("../../actions/index.js");
10
- const constant_js_1 = require("../../helpers/constant.js");
11
11
  const index_js_2 = require("../../helpers/index.js");
12
+ const validate_js_1 = require("../../helpers/validate.js");
12
13
  const index_js_3 = require("../../types/index.js");
14
+ const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
15
+ const index_js_4 = require("../requirements/index.js");
13
16
  class MorphoVaultV1 {
14
17
  client;
15
18
  vault;
@@ -31,100 +34,242 @@ class MorphoVaultV1 {
31
34
  deployless: this.client.options.supportDeployless,
32
35
  });
33
36
  }
34
- deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
37
+ /** {@inheritDoc VaultV1Actions.deposit} */
38
+ deposit(params) {
39
+ const { userAddress, vaultData } = params;
40
+ const { asset: vaultAsset } = vaultData;
35
41
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
36
42
  if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
37
43
  throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
38
44
  }
39
- if (amount < 0n) {
40
- throw new index_js_3.NegativeInputError("amount", amount);
41
- }
42
- if (nativeAmount && nativeAmount < 0n) {
43
- throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
44
- }
45
- let wNative;
46
- if (nativeAmount) {
47
- ({ wNative } = (0, blue_sdk_1.getChainAddresses)(this.chainId));
48
- if (!wNative) {
49
- throw new index_js_3.ChainWNativeMissingError(this.chainId);
50
- }
51
- }
52
- (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
53
- if (nativeAmount && wNative) {
54
- if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
55
- throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
56
- }
57
- }
58
- const totalAssets = amount + (nativeAmount ?? 0n);
59
- if (totalAssets === 0n) {
60
- throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
61
- }
62
- const shares = vaultData.toShares(totalAssets);
63
- if (shares <= 0n) {
64
- throw new index_js_3.NonPositiveInputError("shares", shares);
45
+ const createdAt = morpho_ts_1.Time.timestamp();
46
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
47
+ if (deadline <= createdAt)
48
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
49
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
50
+ deadline,
51
+ referralFeePct: params.referralFeePct,
52
+ referralFeeRecipient: params.referralFeeRecipient,
53
+ });
54
+ const funding = (0, common_js_1.resolveBundlesFunding)(params);
55
+ // Reject overflow before share-price math or native-only prerequisite resolution.
56
+ (0, validate_js_1.validateUint256Field)(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
57
+ if (funding.value > 0n) {
58
+ // The native path must target the chain's registered wrapped-native asset.
59
+ (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
65
60
  }
66
- const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(totalAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
67
- return {
68
- getRequirements: (params) => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
69
- address: vaultData.asset,
70
- chainId: this.chainId,
71
- supportSignature: this.client.options.supportSignature,
72
- supportDeployless: this.client.options.supportDeployless,
73
- useSimplePermit: params?.useSimplePermit,
74
- args: {
75
- amount,
76
- from: userAddress,
77
- },
78
- }),
61
+ const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
62
+ const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
63
+ vaultData,
64
+ deadline,
65
+ assets: funding.assets - referralFeeAssets,
66
+ slippageTolerance: params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
67
+ });
68
+ const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
69
+ let pendingRequirements;
70
+ let expectedRequirement;
71
+ return Object.freeze({
72
+ getRequirements: async (requirementOptions) => {
73
+ const now = morpho_ts_1.Time.timestamp();
74
+ if (deadline <= now)
75
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
76
+ if (pendingRequirements != null)
77
+ return await pendingRequirements;
78
+ // Memoize the in-flight promise, not just its result: concurrent callers
79
+ // requesting different routes would otherwise both resolve requirements and
80
+ // the slower one would overwrite `expectedRequirement`, making `buildTx()`
81
+ // reject the signature returned by the other call.
82
+ const pending = (async () => {
83
+ const requirements = funding.value > 0n
84
+ ? []
85
+ : await (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
86
+ token: vaultAsset,
87
+ spender,
88
+ amount: funding.assets,
89
+ owner: userAddress,
90
+ chainId: this.chainId,
91
+ deadline,
92
+ supportSignature: this.client.options.supportSignature,
93
+ supportDeployless: this.client.options.supportDeployless,
94
+ useSimplePermit: requirementOptions?.useSimplePermit,
95
+ permit2Nonce: requirementOptions?.permit2Nonce,
96
+ });
97
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
98
+ expectedRequirement =
99
+ signatureRequirement?.action.type === "permit" ||
100
+ signatureRequirement?.action.type === "permit2SignatureTransfer"
101
+ ? signatureRequirement.action
102
+ : undefined;
103
+ return requirements;
104
+ })();
105
+ pendingRequirements = pending;
106
+ try {
107
+ return await pending;
108
+ }
109
+ finally {
110
+ // Later calls must re-read live allowances/nonces and honor their own options.
111
+ if (pendingRequirements === pending)
112
+ pendingRequirements = undefined;
113
+ }
114
+ },
79
115
  buildTx: (signatures) => {
80
- const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
81
- permit: true,
82
- });
116
+ const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expectedRequirement);
83
117
  return (0, index_js_1.vaultV1Deposit)({
84
118
  vault: {
85
119
  chainId: this.chainId,
86
120
  address: this.vault,
87
- asset: vaultData.asset,
121
+ asset: vaultAsset,
88
122
  },
89
123
  args: {
90
- amount,
124
+ ...(funding.value > 0n
125
+ ? { nativeAmount: funding.assets }
126
+ : { amount: funding.assets }),
91
127
  maxSharePrice,
92
- recipient: userAddress,
93
- requirementSignature: permit,
94
- nativeAmount,
128
+ userAddress,
129
+ requirementSignature,
130
+ referralFeePct: common.referralFeePct,
131
+ referralFeeRecipient: common.referralFeeRecipient,
132
+ deadline,
95
133
  },
96
134
  metadata: this.client.options.metadata,
97
135
  });
98
136
  },
99
- };
137
+ });
100
138
  }
101
- withdraw({ amount, userAddress }) {
139
+ withdraw(params) {
140
+ const { amount, userAddress } = params;
102
141
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
103
- return {
104
- buildTx: () => (0, index_js_1.vaultV1Withdraw)({
105
- vault: { address: this.vault },
106
- args: {
107
- amount,
108
- recipient: userAddress,
109
- onBehalf: userAddress,
110
- },
111
- metadata: this.client.options.metadata,
112
- }),
113
- };
142
+ if (amount <= 0n)
143
+ throw new index_js_3.NonPositiveInputError("amount", amount);
144
+ // Reject values outside the ABI range before resolving any requirements.
145
+ (0, validate_js_1.validateUint256Field)("amount", amount);
146
+ const createdAt = morpho_ts_1.Time.timestamp();
147
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
148
+ if (deadline <= createdAt)
149
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
150
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
151
+ deadline,
152
+ referralFeePct: params.referralFeePct,
153
+ referralFeeRecipient: params.referralFeeRecipient,
154
+ });
155
+ const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
156
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
157
+ // Fail eagerly if VaultBundlesV1 is unavailable; only validation is needed here.
158
+ (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
159
+ let requiredShareAllowance;
160
+ let vaultSnapshot;
161
+ let expectedRequirement;
162
+ return Object.freeze({
163
+ getRequirements: async () => {
164
+ const now = morpho_ts_1.Time.timestamp();
165
+ if (deadline <= now)
166
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
167
+ // Re-read the live share allowance on every call instead of caching the resolved
168
+ // requirements: the allowance is the sole cap on the burn, so a caller that executed the
169
+ // returned approval must see it satisfied on the next call, and an allowance revoked or
170
+ // raised afterwards must resurface as an outstanding requirement. Only the vault snapshot
171
+ // and the cap derived from it are pinned, so re-reading cannot move the cap this handle
172
+ // already committed to; the snapshot is used for immutable identity and permit-domain
173
+ // fields only.
174
+ const vaultData = (vaultSnapshot ??= await this.getData());
175
+ requiredShareAllowance ??= (0, index_js_2.computeVaultMaxShareAllowance)({
176
+ vaultData,
177
+ deadline,
178
+ assets: amount,
179
+ slippageTolerance,
180
+ });
181
+ const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
182
+ vaultData,
183
+ version: "vaultV1",
184
+ owner: userAddress,
185
+ chainId: this.chainId,
186
+ requiredShareAllowance,
187
+ deadline,
188
+ supportSignature: this.client.options.supportSignature,
189
+ });
190
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
191
+ if (signatureRequirement?.action.type === "permit") {
192
+ expectedRequirement = signatureRequirement.action;
193
+ }
194
+ return requirements;
195
+ },
196
+ buildTx: (signatures) => {
197
+ const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
198
+ requiredShareAllowance,
199
+ expectedRequirement,
200
+ });
201
+ return (0, index_js_1.vaultV1Withdraw)({
202
+ vault: { chainId: this.chainId, address: this.vault },
203
+ args: {
204
+ amount,
205
+ userAddress,
206
+ requirementSignature: permit,
207
+ referralFeePct: common.referralFeePct,
208
+ referralFeeRecipient: common.referralFeeRecipient,
209
+ deadline,
210
+ },
211
+ metadata: this.client.options.metadata,
212
+ });
213
+ },
214
+ });
114
215
  }
115
- redeem({ shares, userAddress }) {
216
+ /** {@inheritDoc VaultV1Actions.redeem} */
217
+ redeem(params) {
116
218
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
117
- return {
118
- buildTx: () => (0, index_js_1.vaultV1Redeem)({
119
- vault: { address: this.vault },
120
- args: {
121
- shares,
122
- recipient: userAddress,
123
- onBehalf: userAddress,
124
- },
125
- metadata: this.client.options.metadata,
126
- }),
127
- };
219
+ const { shares, userAddress } = params;
220
+ if (shares <= 0n)
221
+ throw new index_js_3.NonPositiveInputError("shares", shares);
222
+ const createdAt = morpho_ts_1.Time.timestamp();
223
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
224
+ if (deadline <= createdAt)
225
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
226
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
227
+ deadline,
228
+ referralFeePct: params.referralFeePct,
229
+ referralFeeRecipient: params.referralFeeRecipient,
230
+ });
231
+ (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
232
+ let expectedRequirement;
233
+ return Object.freeze({
234
+ getRequirements: async () => {
235
+ const now = morpho_ts_1.Time.timestamp();
236
+ if (deadline <= now)
237
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
238
+ const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
239
+ vaultData: await this.getData(),
240
+ version: "vaultV1",
241
+ owner: userAddress,
242
+ chainId: this.chainId,
243
+ requiredShareAllowance: shares,
244
+ deadline,
245
+ supportSignature: this.client.options.supportSignature,
246
+ });
247
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
248
+ expectedRequirement =
249
+ signatureRequirement?.action.type === "permit"
250
+ ? signatureRequirement.action
251
+ : undefined;
252
+ return requirements;
253
+ },
254
+ buildTx: (signatures) => {
255
+ const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
256
+ requiredShareAllowance: shares,
257
+ expectedRequirement,
258
+ });
259
+ return (0, index_js_1.vaultV1Redeem)({
260
+ vault: { chainId: this.chainId, address: this.vault },
261
+ args: {
262
+ shares,
263
+ userAddress,
264
+ requirementSignature: permit,
265
+ referralFeePct: common.referralFeePct,
266
+ referralFeeRecipient: common.referralFeeRecipient,
267
+ deadline,
268
+ },
269
+ metadata: this.client.options.metadata,
270
+ });
271
+ },
272
+ });
128
273
  }
129
274
  /** {@inheritDoc VaultV1Actions.inKindRedeem} */
130
275
  inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
@@ -145,6 +290,9 @@ class MorphoVaultV1 {
145
290
  }));
146
291
  const now = morpho_ts_1.Time.timestamp();
147
292
  const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
293
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
294
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
295
+ (0, validate_js_1.validateDeadline)(deadline);
148
296
  if (deadline <= now)
149
297
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
150
298
  const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
@@ -159,6 +307,8 @@ class MorphoVaultV1 {
159
307
  const allocation = vaultData.allocations.get(marketId);
160
308
  if (allocation?.config.enabled !== true)
161
309
  continue;
310
+ if (allocation.position.supplyShares === 0n)
311
+ continue;
162
312
  const market = allocation.position.market.accrueInterest(now);
163
313
  const available = market.toSupplyAssets(allocation.position.supplyShares);
164
314
  const assigned = assignedByMarket.get(marketId) ?? 0n;
@@ -180,11 +330,12 @@ class MorphoVaultV1 {
180
330
  maxExitAssets: covered,
181
331
  });
182
332
  }
183
- // Account for pending performance-fee shares before previewing the burn. Once accrued, future
184
- // V1 interest cannot lower the share price, so this upper-bounds execution.
185
- const requiredShareAllowance = vaultData
186
- .accrueInterest(now)
187
- .toShares(amount);
333
+ const requiredShareAllowance = (0, index_js_2.computeVaultMaxShareAllowance)({
334
+ vaultData,
335
+ deadline: now,
336
+ assets: amount,
337
+ slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
338
+ });
188
339
  return {
189
340
  getRequirements: async () => {
190
341
  const requirementsTimestamp = morpho_ts_1.Time.timestamp();
@@ -287,66 +438,129 @@ class MorphoVaultV1 {
287
438
  },
288
439
  };
289
440
  }
290
- migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, }) {
441
+ /** {@inheritDoc VaultV1Actions.migrateToV2} */
442
+ migrateToV2(params) {
291
443
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
292
- if (!(0, viem_1.isAddressEqual)(sourceVault.address, this.vault)) {
293
- throw new index_js_3.VaultAddressMismatchError(this.vault, sourceVault.address);
444
+ if (!(0, viem_1.isAddressEqual)(params.sourceVault.address, this.vault)) {
445
+ throw new index_js_3.VaultAddressMismatchError(this.vault, params.sourceVault.address);
294
446
  }
295
- if (!(0, viem_1.isAddressEqual)(sourceVault.asset, targetVault.asset)) {
296
- throw new index_js_3.VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
447
+ if (!(0, viem_1.isAddressEqual)(params.sourceVault.asset, params.targetVault.asset)) {
448
+ throw new index_js_3.VaultAssetMismatchError(params.sourceVault.asset, params.targetVault.asset);
297
449
  }
298
- if (shares <= 0n) {
299
- throw new index_js_3.NonPositiveInputError("shares", shares);
450
+ if ((0, viem_1.isAddressEqual)(this.vault, params.targetVault.address)) {
451
+ throw new index_js_3.SameVaultMigrationError(this.vault);
300
452
  }
301
- (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
302
- // Compute minSharePriceVaultV1 for V1 redeem (slippage downward)
303
- const v1RefAssets = sourceVault.toAssets(shares);
304
- const minSharePriceVaultV1 = blue_sdk_1.MathLib.mulDivDown(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
305
- // Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
306
- // Accrue VaultV2 interest forward to bound the on-chain share price at execution.
307
- const targetAccrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), targetVault.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
308
- const { vault: accruedTargetVault } = targetVault.accrueInterest(targetAccrualTimestamp);
309
- const v2RefShares = accruedTargetVault.toShares(v1RefAssets);
310
- if (v2RefShares <= 0n) {
311
- throw new index_js_3.NonPositiveInputError("targetVaultShares", v2RefShares);
453
+ const assets = "assets" in params ? params.assets : undefined;
454
+ const shares = "shares" in params ? params.shares : undefined;
455
+ if ((assets == null) === (shares == null)) {
456
+ throw new index_js_3.AmountAndSharesExclusiveError();
312
457
  }
313
- const maxSharePriceVaultV2 = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), v2RefShares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
314
- return {
315
- getRequirements: () => (0, index_js_1.getGeneralAdapterRequirements)(this.client.viemClient, {
316
- address: this.vault,
317
- chainId: this.chainId,
318
- supportSignature: this.client.options.supportSignature,
319
- supportDeployless: this.client.options.supportDeployless,
320
- // V1 shares always implement EIP-2612.
321
- useSimplePermit: true,
322
- args: {
323
- amount: shares,
324
- from: userAddress,
325
- },
326
- }),
458
+ const selectedAmount = assets ?? shares ?? 0n;
459
+ if (selectedAmount <= 0n) {
460
+ throw new index_js_3.NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
461
+ }
462
+ const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
463
+ (0, index_js_2.validateSlippageTolerance)(slippageTolerance);
464
+ const createdAt = morpho_ts_1.Time.timestamp();
465
+ const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
466
+ if (deadline <= createdAt)
467
+ throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
468
+ const common = (0, common_js_1.normalizeBundlesCommonParams)({
469
+ deadline,
470
+ referralFeePct: params.referralFeePct,
471
+ referralFeeRecipient: params.referralFeeRecipient,
472
+ });
473
+ // V1 redeem accrues market interest and performance fees before converting shares.
474
+ const grossAssets = assets ??
475
+ params.sourceVault
476
+ .accrueInterest(params.sourceVault.allocations
477
+ .values()
478
+ .reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), createdAt))
479
+ .toAssets(shares ?? 0n, "Down");
480
+ const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, common.referralFeePct);
481
+ const maxSharePriceVaultV2 = (0, index_js_2.computeVaultMaxSharePrice)({
482
+ vaultData: params.targetVault,
483
+ deadline,
484
+ assets: grossAssets - referralFeeAssets,
485
+ slippageTolerance,
486
+ });
487
+ const requiredShareAllowance = shares ??
488
+ (0, index_js_2.computeVaultMaxShareAllowance)({
489
+ vaultData: params.sourceVault,
490
+ deadline,
491
+ assets: assets ?? 0n,
492
+ slippageTolerance,
493
+ });
494
+ (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
495
+ const { userAddress } = params;
496
+ const sourceAsset = params.sourceVault.asset;
497
+ const targetAddress = params.targetVault.address;
498
+ const targetAsset = params.targetVault.asset;
499
+ const domain = params.sourceVault.eip5267Domain;
500
+ const sourceToken = new blue_sdk_1.Token({
501
+ address: params.sourceVault.address,
502
+ name: params.sourceVault.name,
503
+ eip5267Domain: domain == null
504
+ ? undefined
505
+ : new blue_sdk_1.Eip5267Domain({
506
+ ...domain,
507
+ extensions: [...domain.extensions],
508
+ }),
509
+ });
510
+ let expectedRequirement;
511
+ return Object.freeze({
512
+ getRequirements: async () => {
513
+ const now = morpho_ts_1.Time.timestamp();
514
+ if (deadline <= now)
515
+ throw new index_js_3.ExpiredDeadlineError(deadline, now);
516
+ // Re-read the live share allowance on every call instead of caching the resolved
517
+ // requirements: in assets mode the calldata carries no share limit, so the allowance is
518
+ // the sole cap on the burn. A caller that executed the returned approval must see it
519
+ // satisfied on the next call, and an allowance revoked or raised afterwards must resurface
520
+ // as an outstanding requirement. The pinned snapshot and the cap derived from it stay
521
+ // fixed, so re-reading cannot move the cap this handle already committed to.
522
+ const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
523
+ vaultData: sourceToken,
524
+ version: "vaultV1",
525
+ owner: userAddress,
526
+ chainId: this.chainId,
527
+ requiredShareAllowance,
528
+ deadline,
529
+ supportSignature: this.client.options.supportSignature,
530
+ });
531
+ const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
532
+ expectedRequirement =
533
+ signatureRequirement?.action.type === "permit"
534
+ ? signatureRequirement.action
535
+ : undefined;
536
+ return requirements;
537
+ },
327
538
  buildTx: (signatures) => {
328
- const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
329
- permit: true,
539
+ const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
540
+ requiredShareAllowance,
541
+ expectedRequirement,
330
542
  });
331
543
  return (0, index_js_1.vaultV1MigrateToV2)({
332
544
  vault: {
333
545
  chainId: this.chainId,
334
546
  address: this.vault,
335
- asset: sourceVault.asset,
547
+ asset: sourceAsset,
336
548
  },
337
549
  args: {
338
- targetVault: targetVault.address,
339
- targetAsset: targetVault.asset,
340
- shares,
341
- minSharePriceVaultV1,
550
+ targetVault: targetAddress,
551
+ targetAsset,
552
+ ...(assets != null ? { assets } : { shares: shares ?? 0n }),
342
553
  maxSharePriceVaultV2,
343
- recipient: userAddress,
554
+ userAddress,
344
555
  requirementSignature: permit,
556
+ referralFeePct: common.referralFeePct,
557
+ referralFeeRecipient: common.referralFeeRecipient,
558
+ deadline,
345
559
  },
346
560
  metadata: this.client.options.metadata,
347
561
  });
348
562
  },
349
- };
563
+ });
350
564
  }
351
565
  }
352
566
  exports.MorphoVaultV1 = MorphoVaultV1;
@@ -130,10 +130,13 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
130
130
  * Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
131
131
  * on-chain `reallocateTo` fee semantics: one fee charge per vault with at
132
132
  * least one computed withdrawal.
133
+ * Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
134
+ * are skipped before projecting source interest.
133
135
  *
134
136
  * @param marketId - Target market to supply with shared liquidity.
135
137
  * @param options - Optional allocator discovery options.
136
138
  * @returns Computed source-market withdrawals and the post-reallocation state.
139
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
137
140
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
138
141
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
139
142
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -179,6 +182,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
179
182
  * @param marketId - Target market to supply with shared liquidity.
180
183
  * @param options - Optional allocator discovery options.
181
184
  * @returns Computed source-market withdrawals and the post-reallocation state.
185
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
182
186
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
183
187
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
184
188
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -199,6 +203,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
199
203
  * @param marketId - Target market that would receive the liquidity.
200
204
  * @param options - Optional allocator discovery options.
201
205
  * @returns Total reallocatable assets in loan-token units; `0n` when none is available.
206
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
202
207
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
203
208
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
204
209
  * `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
@@ -252,6 +257,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
252
257
  * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
253
258
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
254
259
  * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
260
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
255
261
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
256
262
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
257
263
  * `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.