@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,12 +1,15 @@
1
- import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, getChainAddresses, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
2
2
  import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
3
3
  import { getChainAddress, Time } from "@morpho-org/morpho-ts";
4
4
  import { erc20Abi, isAddressEqual } from "viem";
5
5
  import { multicall } from "viem/actions";
6
- import { encodeErc20Approval, encodeVaultSharesPermit, getGeneralAdapterRequirements, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
7
- import { MAX_ABSOLUTE_SHARE_PRICE } from "../../helpers/constant.js";
8
- import { validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
9
- import { ChainIdMismatchError, ChainWNativeMissingError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
6
+ import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
7
+ import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
8
+ import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
9
+ import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
10
+ import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
11
+ import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
12
+ import { getBundlesTokenRequirements } from "../requirements/index.js";
10
13
  export class MorphoVaultV1 {
11
14
  client;
12
15
  vault;
@@ -28,100 +31,242 @@ export class MorphoVaultV1 {
28
31
  deployless: this.client.options.supportDeployless,
29
32
  });
30
33
  }
31
- deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
34
+ /** {@inheritDoc VaultV1Actions.deposit} */
35
+ deposit(params) {
36
+ const { userAddress, vaultData } = params;
37
+ const { asset: vaultAsset } = vaultData;
32
38
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
33
39
  if (!isAddressEqual(vaultData.address, this.vault)) {
34
40
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
35
41
  }
36
- if (amount < 0n) {
37
- throw new NegativeInputError("amount", amount);
38
- }
39
- if (nativeAmount && nativeAmount < 0n) {
40
- throw new NegativeInputError("nativeAmount", nativeAmount);
41
- }
42
- let wNative;
43
- if (nativeAmount) {
44
- ({ wNative } = getChainAddresses(this.chainId));
45
- if (!wNative) {
46
- throw new ChainWNativeMissingError(this.chainId);
47
- }
48
- }
49
- validateSlippageTolerance(slippageTolerance);
50
- if (nativeAmount && wNative) {
51
- if (!isAddressEqual(vaultData.asset, wNative)) {
52
- throw new NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
53
- }
54
- }
55
- const totalAssets = amount + (nativeAmount ?? 0n);
56
- if (totalAssets === 0n) {
57
- throw new NonPositiveInputError("totalAssets", totalAssets);
58
- }
59
- const shares = vaultData.toShares(totalAssets);
60
- if (shares <= 0n) {
61
- throw new NonPositiveInputError("shares", shares);
42
+ const createdAt = Time.timestamp();
43
+ const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
44
+ if (deadline <= createdAt)
45
+ throw new ExpiredDeadlineError(deadline, createdAt);
46
+ const common = normalizeBundlesCommonParams({
47
+ deadline,
48
+ referralFeePct: params.referralFeePct,
49
+ referralFeeRecipient: params.referralFeeRecipient,
50
+ });
51
+ const funding = resolveBundlesFunding(params);
52
+ // Reject overflow before share-price math or native-only prerequisite resolution.
53
+ validateUint256Field(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
54
+ if (funding.value > 0n) {
55
+ // The native path must target the chain's registered wrapped-native asset.
56
+ validateNativeVaultAsset(this.chainId, vaultAsset);
62
57
  }
63
- const maxSharePrice = MathLib.min(MathLib.mulDivUp(totalAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares), MAX_ABSOLUTE_SHARE_PRICE);
64
- return {
65
- getRequirements: (params) => getGeneralAdapterRequirements(this.client.viemClient, {
66
- address: vaultData.asset,
67
- chainId: this.chainId,
68
- supportSignature: this.client.options.supportSignature,
69
- supportDeployless: this.client.options.supportDeployless,
70
- useSimplePermit: params?.useSimplePermit,
71
- args: {
72
- amount,
73
- from: userAddress,
74
- },
75
- }),
58
+ const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
59
+ const maxSharePrice = computeVaultMaxSharePrice({
60
+ vaultData,
61
+ deadline,
62
+ assets: funding.assets - referralFeeAssets,
63
+ slippageTolerance: params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE,
64
+ });
65
+ const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
66
+ let pendingRequirements;
67
+ let expectedRequirement;
68
+ return Object.freeze({
69
+ getRequirements: async (requirementOptions) => {
70
+ const now = Time.timestamp();
71
+ if (deadline <= now)
72
+ throw new ExpiredDeadlineError(deadline, now);
73
+ if (pendingRequirements != null)
74
+ return await pendingRequirements;
75
+ // Memoize the in-flight promise, not just its result: concurrent callers
76
+ // requesting different routes would otherwise both resolve requirements and
77
+ // the slower one would overwrite `expectedRequirement`, making `buildTx()`
78
+ // reject the signature returned by the other call.
79
+ const pending = (async () => {
80
+ const requirements = funding.value > 0n
81
+ ? []
82
+ : await getBundlesTokenRequirements(this.client.viemClient, {
83
+ token: vaultAsset,
84
+ spender,
85
+ amount: funding.assets,
86
+ owner: userAddress,
87
+ chainId: this.chainId,
88
+ deadline,
89
+ supportSignature: this.client.options.supportSignature,
90
+ supportDeployless: this.client.options.supportDeployless,
91
+ useSimplePermit: requirementOptions?.useSimplePermit,
92
+ permit2Nonce: requirementOptions?.permit2Nonce,
93
+ });
94
+ const signatureRequirement = requirements.find(isRequirementSignature);
95
+ expectedRequirement =
96
+ signatureRequirement?.action.type === "permit" ||
97
+ signatureRequirement?.action.type === "permit2SignatureTransfer"
98
+ ? signatureRequirement.action
99
+ : undefined;
100
+ return requirements;
101
+ })();
102
+ pendingRequirements = pending;
103
+ try {
104
+ return await pending;
105
+ }
106
+ finally {
107
+ // Later calls must re-read live allowances/nonces and honor their own options.
108
+ if (pendingRequirements === pending)
109
+ pendingRequirements = undefined;
110
+ }
111
+ },
76
112
  buildTx: (signatures) => {
77
- const { permit } = selectRequirementSignatures(signatures, {
78
- permit: true,
79
- });
113
+ const requirementSignature = selectBundlesTokenRequirementSignature(signatures, expectedRequirement);
80
114
  return vaultV1Deposit({
81
115
  vault: {
82
116
  chainId: this.chainId,
83
117
  address: this.vault,
84
- asset: vaultData.asset,
118
+ asset: vaultAsset,
85
119
  },
86
120
  args: {
87
- amount,
121
+ ...(funding.value > 0n
122
+ ? { nativeAmount: funding.assets }
123
+ : { amount: funding.assets }),
88
124
  maxSharePrice,
89
- recipient: userAddress,
90
- requirementSignature: permit,
91
- nativeAmount,
125
+ userAddress,
126
+ requirementSignature,
127
+ referralFeePct: common.referralFeePct,
128
+ referralFeeRecipient: common.referralFeeRecipient,
129
+ deadline,
92
130
  },
93
131
  metadata: this.client.options.metadata,
94
132
  });
95
133
  },
96
- };
134
+ });
97
135
  }
98
- withdraw({ amount, userAddress }) {
136
+ withdraw(params) {
137
+ const { amount, userAddress } = params;
99
138
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
100
- return {
101
- buildTx: () => vaultV1Withdraw({
102
- vault: { address: this.vault },
103
- args: {
104
- amount,
105
- recipient: userAddress,
106
- onBehalf: userAddress,
107
- },
108
- metadata: this.client.options.metadata,
109
- }),
110
- };
139
+ if (amount <= 0n)
140
+ throw new NonPositiveInputError("amount", amount);
141
+ // Reject values outside the ABI range before resolving any requirements.
142
+ validateUint256Field("amount", amount);
143
+ const createdAt = Time.timestamp();
144
+ const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
145
+ if (deadline <= createdAt)
146
+ throw new ExpiredDeadlineError(deadline, createdAt);
147
+ const common = normalizeBundlesCommonParams({
148
+ deadline,
149
+ referralFeePct: params.referralFeePct,
150
+ referralFeeRecipient: params.referralFeeRecipient,
151
+ });
152
+ const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
153
+ validateSlippageTolerance(slippageTolerance);
154
+ // Fail eagerly if VaultBundlesV1 is unavailable; only validation is needed here.
155
+ getChainAddress(this.chainId, "bundles.vaultBundlesV1");
156
+ let requiredShareAllowance;
157
+ let vaultSnapshot;
158
+ let expectedRequirement;
159
+ return Object.freeze({
160
+ getRequirements: async () => {
161
+ const now = Time.timestamp();
162
+ if (deadline <= now)
163
+ throw new ExpiredDeadlineError(deadline, now);
164
+ // Re-read the live share allowance on every call instead of caching the resolved
165
+ // requirements: the allowance is the sole cap on the burn, so a caller that executed the
166
+ // returned approval must see it satisfied on the next call, and an allowance revoked or
167
+ // raised afterwards must resurface as an outstanding requirement. Only the vault snapshot
168
+ // and the cap derived from it are pinned, so re-reading cannot move the cap this handle
169
+ // already committed to; the snapshot is used for immutable identity and permit-domain
170
+ // fields only.
171
+ const vaultData = (vaultSnapshot ??= await this.getData());
172
+ requiredShareAllowance ??= computeVaultMaxShareAllowance({
173
+ vaultData,
174
+ deadline,
175
+ assets: amount,
176
+ slippageTolerance,
177
+ });
178
+ const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
179
+ vaultData,
180
+ version: "vaultV1",
181
+ owner: userAddress,
182
+ chainId: this.chainId,
183
+ requiredShareAllowance,
184
+ deadline,
185
+ supportSignature: this.client.options.supportSignature,
186
+ });
187
+ const signatureRequirement = requirements.find(isRequirementSignature);
188
+ if (signatureRequirement?.action.type === "permit") {
189
+ expectedRequirement = signatureRequirement.action;
190
+ }
191
+ return requirements;
192
+ },
193
+ buildTx: (signatures) => {
194
+ const permit = selectBundlesSharesRequirementSignature(signatures, {
195
+ requiredShareAllowance,
196
+ expectedRequirement,
197
+ });
198
+ return vaultV1Withdraw({
199
+ vault: { chainId: this.chainId, address: this.vault },
200
+ args: {
201
+ amount,
202
+ userAddress,
203
+ requirementSignature: permit,
204
+ referralFeePct: common.referralFeePct,
205
+ referralFeeRecipient: common.referralFeeRecipient,
206
+ deadline,
207
+ },
208
+ metadata: this.client.options.metadata,
209
+ });
210
+ },
211
+ });
111
212
  }
112
- redeem({ shares, userAddress }) {
213
+ /** {@inheritDoc VaultV1Actions.redeem} */
214
+ redeem(params) {
113
215
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
114
- return {
115
- buildTx: () => vaultV1Redeem({
116
- vault: { address: this.vault },
117
- args: {
118
- shares,
119
- recipient: userAddress,
120
- onBehalf: userAddress,
121
- },
122
- metadata: this.client.options.metadata,
123
- }),
124
- };
216
+ const { shares, userAddress } = params;
217
+ if (shares <= 0n)
218
+ throw new NonPositiveInputError("shares", shares);
219
+ const createdAt = Time.timestamp();
220
+ const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
221
+ if (deadline <= createdAt)
222
+ throw new ExpiredDeadlineError(deadline, createdAt);
223
+ const common = normalizeBundlesCommonParams({
224
+ deadline,
225
+ referralFeePct: params.referralFeePct,
226
+ referralFeeRecipient: params.referralFeeRecipient,
227
+ });
228
+ getChainAddress(this.chainId, "bundles.vaultBundlesV1");
229
+ let expectedRequirement;
230
+ return Object.freeze({
231
+ getRequirements: async () => {
232
+ const now = Time.timestamp();
233
+ if (deadline <= now)
234
+ throw new ExpiredDeadlineError(deadline, now);
235
+ const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
236
+ vaultData: await this.getData(),
237
+ version: "vaultV1",
238
+ owner: userAddress,
239
+ chainId: this.chainId,
240
+ requiredShareAllowance: shares,
241
+ deadline,
242
+ supportSignature: this.client.options.supportSignature,
243
+ });
244
+ const signatureRequirement = requirements.find(isRequirementSignature);
245
+ expectedRequirement =
246
+ signatureRequirement?.action.type === "permit"
247
+ ? signatureRequirement.action
248
+ : undefined;
249
+ return requirements;
250
+ },
251
+ buildTx: (signatures) => {
252
+ const permit = selectBundlesSharesRequirementSignature(signatures, {
253
+ requiredShareAllowance: shares,
254
+ expectedRequirement,
255
+ });
256
+ return vaultV1Redeem({
257
+ vault: { chainId: this.chainId, address: this.vault },
258
+ args: {
259
+ shares,
260
+ userAddress,
261
+ requirementSignature: permit,
262
+ referralFeePct: common.referralFeePct,
263
+ referralFeeRecipient: common.referralFeeRecipient,
264
+ deadline,
265
+ },
266
+ metadata: this.client.options.metadata,
267
+ });
268
+ },
269
+ });
125
270
  }
126
271
  /** {@inheritDoc VaultV1Actions.inKindRedeem} */
127
272
  inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
@@ -142,6 +287,9 @@ export class MorphoVaultV1 {
142
287
  }));
143
288
  const now = Time.timestamp();
144
289
  const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
290
+ // Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
291
+ // through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
292
+ validateDeadline(deadline);
145
293
  if (deadline <= now)
146
294
  throw new ExpiredDeadlineError(deadline, now);
147
295
  const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
@@ -156,6 +304,8 @@ export class MorphoVaultV1 {
156
304
  const allocation = vaultData.allocations.get(marketId);
157
305
  if (allocation?.config.enabled !== true)
158
306
  continue;
307
+ if (allocation.position.supplyShares === 0n)
308
+ continue;
159
309
  const market = allocation.position.market.accrueInterest(now);
160
310
  const available = market.toSupplyAssets(allocation.position.supplyShares);
161
311
  const assigned = assignedByMarket.get(marketId) ?? 0n;
@@ -177,11 +327,12 @@ export class MorphoVaultV1 {
177
327
  maxExitAssets: covered,
178
328
  });
179
329
  }
180
- // Account for pending performance-fee shares before previewing the burn. Once accrued, future
181
- // V1 interest cannot lower the share price, so this upper-bounds execution.
182
- const requiredShareAllowance = vaultData
183
- .accrueInterest(now)
184
- .toShares(amount);
330
+ const requiredShareAllowance = computeVaultMaxShareAllowance({
331
+ vaultData,
332
+ deadline: now,
333
+ assets: amount,
334
+ slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
335
+ });
185
336
  return {
186
337
  getRequirements: async () => {
187
338
  const requirementsTimestamp = Time.timestamp();
@@ -284,65 +435,128 @@ export class MorphoVaultV1 {
284
435
  },
285
436
  };
286
437
  }
287
- migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, }) {
438
+ /** {@inheritDoc VaultV1Actions.migrateToV2} */
439
+ migrateToV2(params) {
288
440
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
289
- if (!isAddressEqual(sourceVault.address, this.vault)) {
290
- throw new VaultAddressMismatchError(this.vault, sourceVault.address);
441
+ if (!isAddressEqual(params.sourceVault.address, this.vault)) {
442
+ throw new VaultAddressMismatchError(this.vault, params.sourceVault.address);
291
443
  }
292
- if (!isAddressEqual(sourceVault.asset, targetVault.asset)) {
293
- throw new VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
444
+ if (!isAddressEqual(params.sourceVault.asset, params.targetVault.asset)) {
445
+ throw new VaultAssetMismatchError(params.sourceVault.asset, params.targetVault.asset);
294
446
  }
295
- if (shares <= 0n) {
296
- throw new NonPositiveInputError("shares", shares);
447
+ if (isAddressEqual(this.vault, params.targetVault.address)) {
448
+ throw new SameVaultMigrationError(this.vault);
297
449
  }
298
- validateSlippageTolerance(slippageTolerance);
299
- // Compute minSharePriceVaultV1 for V1 redeem (slippage downward)
300
- const v1RefAssets = sourceVault.toAssets(shares);
301
- const minSharePriceVaultV1 = MathLib.mulDivDown(v1RefAssets, MathLib.wToRay(MathLib.WAD - slippageTolerance), shares);
302
- // Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
303
- // Accrue VaultV2 interest forward to bound the on-chain share price at execution.
304
- const targetAccrualTimestamp = MathLib.max(Time.timestamp(), targetVault.lastUpdate) + Time.s.from.h(2n);
305
- const { vault: accruedTargetVault } = targetVault.accrueInterest(targetAccrualTimestamp);
306
- const v2RefShares = accruedTargetVault.toShares(v1RefAssets);
307
- if (v2RefShares <= 0n) {
308
- throw new NonPositiveInputError("targetVaultShares", v2RefShares);
450
+ const assets = "assets" in params ? params.assets : undefined;
451
+ const shares = "shares" in params ? params.shares : undefined;
452
+ if ((assets == null) === (shares == null)) {
453
+ throw new AmountAndSharesExclusiveError();
309
454
  }
310
- const maxSharePriceVaultV2 = MathLib.min(MathLib.mulDivUp(v1RefAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), v2RefShares), MAX_ABSOLUTE_SHARE_PRICE);
311
- return {
312
- getRequirements: () => getGeneralAdapterRequirements(this.client.viemClient, {
313
- address: this.vault,
314
- chainId: this.chainId,
315
- supportSignature: this.client.options.supportSignature,
316
- supportDeployless: this.client.options.supportDeployless,
317
- // V1 shares always implement EIP-2612.
318
- useSimplePermit: true,
319
- args: {
320
- amount: shares,
321
- from: userAddress,
322
- },
323
- }),
455
+ const selectedAmount = assets ?? shares ?? 0n;
456
+ if (selectedAmount <= 0n) {
457
+ throw new NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
458
+ }
459
+ const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
460
+ validateSlippageTolerance(slippageTolerance);
461
+ const createdAt = Time.timestamp();
462
+ const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
463
+ if (deadline <= createdAt)
464
+ throw new ExpiredDeadlineError(deadline, createdAt);
465
+ const common = normalizeBundlesCommonParams({
466
+ deadline,
467
+ referralFeePct: params.referralFeePct,
468
+ referralFeeRecipient: params.referralFeeRecipient,
469
+ });
470
+ // V1 redeem accrues market interest and performance fees before converting shares.
471
+ const grossAssets = assets ??
472
+ params.sourceVault
473
+ .accrueInterest(params.sourceVault.allocations
474
+ .values()
475
+ .reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), createdAt))
476
+ .toAssets(shares ?? 0n, "Down");
477
+ const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, common.referralFeePct);
478
+ const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
479
+ vaultData: params.targetVault,
480
+ deadline,
481
+ assets: grossAssets - referralFeeAssets,
482
+ slippageTolerance,
483
+ });
484
+ const requiredShareAllowance = shares ??
485
+ computeVaultMaxShareAllowance({
486
+ vaultData: params.sourceVault,
487
+ deadline,
488
+ assets: assets ?? 0n,
489
+ slippageTolerance,
490
+ });
491
+ getChainAddress(this.chainId, "bundles.vaultBundlesV1");
492
+ const { userAddress } = params;
493
+ const sourceAsset = params.sourceVault.asset;
494
+ const targetAddress = params.targetVault.address;
495
+ const targetAsset = params.targetVault.asset;
496
+ const domain = params.sourceVault.eip5267Domain;
497
+ const sourceToken = new Token({
498
+ address: params.sourceVault.address,
499
+ name: params.sourceVault.name,
500
+ eip5267Domain: domain == null
501
+ ? undefined
502
+ : new Eip5267Domain({
503
+ ...domain,
504
+ extensions: [...domain.extensions],
505
+ }),
506
+ });
507
+ let expectedRequirement;
508
+ return Object.freeze({
509
+ getRequirements: async () => {
510
+ const now = Time.timestamp();
511
+ if (deadline <= now)
512
+ throw new ExpiredDeadlineError(deadline, now);
513
+ // Re-read the live share allowance on every call instead of caching the resolved
514
+ // requirements: in assets mode the calldata carries no share limit, so the allowance is
515
+ // the sole cap on the burn. A caller that executed the returned approval must see it
516
+ // satisfied on the next call, and an allowance revoked or raised afterwards must resurface
517
+ // as an outstanding requirement. The pinned snapshot and the cap derived from it stay
518
+ // fixed, so re-reading cannot move the cap this handle already committed to.
519
+ const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
520
+ vaultData: sourceToken,
521
+ version: "vaultV1",
522
+ owner: userAddress,
523
+ chainId: this.chainId,
524
+ requiredShareAllowance,
525
+ deadline,
526
+ supportSignature: this.client.options.supportSignature,
527
+ });
528
+ const signatureRequirement = requirements.find(isRequirementSignature);
529
+ expectedRequirement =
530
+ signatureRequirement?.action.type === "permit"
531
+ ? signatureRequirement.action
532
+ : undefined;
533
+ return requirements;
534
+ },
324
535
  buildTx: (signatures) => {
325
- const { permit } = selectRequirementSignatures(signatures, {
326
- permit: true,
536
+ const permit = selectBundlesSharesRequirementSignature(signatures, {
537
+ requiredShareAllowance,
538
+ expectedRequirement,
327
539
  });
328
540
  return vaultV1MigrateToV2({
329
541
  vault: {
330
542
  chainId: this.chainId,
331
543
  address: this.vault,
332
- asset: sourceVault.asset,
544
+ asset: sourceAsset,
333
545
  },
334
546
  args: {
335
- targetVault: targetVault.address,
336
- targetAsset: targetVault.asset,
337
- shares,
338
- minSharePriceVaultV1,
547
+ targetVault: targetAddress,
548
+ targetAsset,
549
+ ...(assets != null ? { assets } : { shares: shares ?? 0n }),
339
550
  maxSharePriceVaultV2,
340
- recipient: userAddress,
551
+ userAddress,
341
552
  requirementSignature: permit,
553
+ referralFeePct: common.referralFeePct,
554
+ referralFeeRecipient: common.referralFeeRecipient,
555
+ deadline,
342
556
  },
343
557
  metadata: this.client.options.metadata,
344
558
  });
345
559
  },
346
- };
560
+ });
347
561
  }
348
562
  }
@@ -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`.