@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
@@ -547,7 +547,6 @@ export class MorphoMidnight {
547
547
  }
548
548
  });
549
549
  const midnight = getChainAddress(this.chainId, "midnight");
550
- const signedPayloads = new Map();
551
550
  return {
552
551
  groups: data.groups,
553
552
  root: data.tree.root,
@@ -564,14 +563,12 @@ export class MorphoMidnight {
564
563
  })));
565
564
  requirements.push(...(await this.getRatifierRequirements({
566
565
  offersData: data,
567
- signedPayloads,
568
566
  })));
569
567
  return requirements;
570
568
  },
571
569
  buildTx: (signatures) => this.buildSubmitOffersTx({
572
570
  offersData: data,
573
571
  signatures,
574
- signedPayloads,
575
572
  }),
576
573
  };
577
574
  }
@@ -602,7 +599,6 @@ export class MorphoMidnight {
602
599
  validation: params.validation,
603
600
  });
604
601
  validateOfferSides(data.tree.offers, false);
605
- const signedPayloads = new Map();
606
602
  return {
607
603
  groups: data.groups,
608
604
  root: data.tree.root,
@@ -610,13 +606,11 @@ export class MorphoMidnight {
610
606
  getRequirements: async () => {
611
607
  return await this.getRatifierRequirements({
612
608
  offersData: data,
613
- signedPayloads,
614
609
  });
615
610
  },
616
611
  buildTx: (signatures) => this.buildSubmitOffersTx({
617
612
  offersData: data,
618
613
  signatures,
619
- signedPayloads,
620
614
  }),
621
615
  };
622
616
  }
@@ -674,7 +668,6 @@ export class MorphoMidnight {
674
668
  }
675
669
  }
676
670
  const midnight = getChainAddress(this.chainId, "midnight");
677
- const signedPayloads = new Map();
678
671
  return {
679
672
  groups: data.groups,
680
673
  root: data.tree.root,
@@ -699,7 +692,6 @@ export class MorphoMidnight {
699
692
  }),
700
693
  ...(await this.getRatifierRequirements({
701
694
  offersData: data,
702
- signedPayloads,
703
695
  })),
704
696
  ];
705
697
  return requirements;
@@ -707,7 +699,6 @@ export class MorphoMidnight {
707
699
  buildTx: (signatures) => this.buildSubmitOffersTx({
708
700
  offersData: data,
709
701
  signatures,
710
- signedPayloads,
711
702
  }),
712
703
  };
713
704
  }
@@ -907,6 +898,18 @@ export class MorphoMidnight {
907
898
  requirements.push(authorization);
908
899
  if (data.ratifierType === "ecrecover") {
909
900
  const chainId = this.chainId;
901
+ // The offer-tree EIP-712 payload is signed over the tree, not the signer, so it is fully
902
+ // determined at build time and stored on the action for external signing.
903
+ const treeTypedData = EcrecoverRatifierUtils.typedData({
904
+ tree: data.tree,
905
+ chainId,
906
+ });
907
+ const typedData = deepFreeze({
908
+ domain: treeTypedData.domain,
909
+ types: treeTypedData.types,
910
+ primaryType: treeTypedData.primaryType,
911
+ message: treeTypedData.message,
912
+ });
910
913
  const action = {
911
914
  type: "midnightOfferRootSignature",
912
915
  args: {
@@ -914,32 +917,23 @@ export class MorphoMidnight {
914
917
  ratifier: data.ratifier,
915
918
  offers: data.tree.offers.length,
916
919
  },
920
+ typedData,
917
921
  };
918
922
  requirements.push({
919
923
  action,
920
924
  async sign(client, userAddress) {
921
- const typedData = EcrecoverRatifierUtils.typedData({
922
- tree: data.tree,
923
- chainId,
924
- });
925
- const typedDataDefinition = {
926
- domain: typedData.domain,
927
- types: typedData.types,
928
- primaryType: typedData.primaryType,
929
- message: typedData.message,
930
- };
931
925
  const signature = await signAndVerifyTypedData({
932
926
  client,
933
927
  userAddress,
934
- typedData: typedDataDefinition,
928
+ typedData,
935
929
  });
930
+ // Derive the ratification payload `buildTx()` submits.
936
931
  const items = await EcrecoverRatifierUtils.ratify({
937
932
  tree: data.tree,
938
933
  account: userAddress,
939
934
  signature,
940
935
  });
941
936
  const payload = await Payload.encode(items);
942
- params.signedPayloads.set(signature.toLowerCase(), payload);
943
937
  return deepFreeze({
944
938
  args: {
945
939
  owner: userAddress,
@@ -1007,11 +1001,13 @@ export class MorphoMidnight {
1007
1001
  actualOffers: signature.action.args.offers,
1008
1002
  });
1009
1003
  }
1010
- const signedPayload = params.signedPayloads.get(signature.args.signature.toLowerCase());
1011
- if (signedPayload == null) {
1004
+ // The payload is carried on the signature the caller hands to buildTx, so
1005
+ // a prepared offer-root requirement can be signed on one instance and
1006
+ // submitted from another without sharing in-memory state.
1007
+ if (signature.args.payload == null) {
1012
1008
  throw new UnpreparedMidnightOfferRootSignatureError();
1013
1009
  }
1014
- payload = signedPayload;
1010
+ payload = signature.args.payload;
1015
1011
  }
1016
1012
  else {
1017
1013
  selectRequirementSignatures(collectedSignatures, {});
@@ -1,10 +1,12 @@
1
1
  import { type Address, type Client } from "viem";
2
- import { type BlueBundlesV1TokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../../types/index.js";
3
- /** Parameters for {@link getBlueBundlesV1TokenRequirements}. */
4
- export interface GetBlueBundlesV1TokenRequirementsParams {
2
+ import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
3
+ /** Parameters for {@link getBundlesTokenRequirements}. */
4
+ export interface GetBundlesTokenRequirementsParams {
5
5
  /** ERC-20 token funded by the operation. */
6
6
  readonly token: Address;
7
- /** Exact amount BlueBundlesV1 will pull. */
7
+ /** Registered fixed bundles contract that pulls the token. */
8
+ readonly spender: Address;
9
+ /** Exact amount the bundles contract will pull. */
8
10
  readonly amount: bigint;
9
11
  /** Classic approval amount; defaults to the exact pull amount. */
10
12
  readonly approvalAmount?: bigint;
@@ -20,22 +22,23 @@ export interface GetBlueBundlesV1TokenRequirementsParams {
20
22
  readonly supportDeployless?: boolean;
21
23
  /** Prefer ERC-2612 when the token exposes a compatible nonce. */
22
24
  readonly useSimplePermit?: boolean;
23
- /** Explicit unused Permit2 SignatureTransfer unordered nonce. */
25
+ /** Explicit unused uint256 nonce; defaults to the lowest unused nonce found via getUnusedPermit2Nonce. */
24
26
  readonly permit2Nonce?: bigint;
25
27
  }
26
28
  /**
27
29
  * Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
28
- * BlueBundlesV1.
30
+ * a registered fixed bundles contract.
29
31
  *
30
32
  * Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
31
- * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names BlueBundlesV1
32
- * as spender. Permit2 SignatureTransfer requires an explicit unused unordered nonce so concurrent
33
- * requirements never silently sign the same owner-global nonce.
33
+ * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
34
+ * as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
35
+ * the same owner should pass explicit nonces.
34
36
  *
35
37
  * @param viemClient - Connected viem client used for allowance and nonce reads.
36
38
  * @param params - Token requirement parameters.
37
39
  * @param params.token - ERC-20 token funded by the operation.
38
- * @param params.amount - Exact amount BlueBundlesV1 will pull; zero returns no requirements.
40
+ * @param params.spender - Registered fixed bundles contract that pulls the token.
41
+ * @param params.amount - Exact amount the contract will pull; zero returns no requirements.
39
42
  * @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
40
43
  * @param params.owner - Account funding the operation.
41
44
  * @param params.chainId - Target chain id; must match the client chain.
@@ -43,16 +46,19 @@ export interface GetBlueBundlesV1TokenRequirementsParams {
43
46
  * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
44
47
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
45
48
  * @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
46
- * @param params.permit2Nonce - Explicit unused uint256 nonce required when Permit2 is selected.
49
+ * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
50
+ * found via {@link getUnusedPermit2Nonce}.
47
51
  * @returns Ordered deep-frozen approval transactions and/or signable token requirements.
48
52
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
49
53
  * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
50
54
  * @throws {NonPositiveInputError} when `deadline` is not positive.
51
55
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
52
56
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
53
- * @throws {UnknownAddressError} when BlueBundlesV1 is not registered for the chain.
54
- * @throws {MissingPermit2TransferFromNonceError} when Permit2 is selected without a nonce.
55
- * @throws {Permit2TransferFromNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
57
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
58
+ * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
59
+ * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
60
+ * was passed explicitly.
61
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
56
62
  * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
57
63
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
58
64
  * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, or ERC-2612 metadata
@@ -60,21 +66,23 @@ export interface GetBlueBundlesV1TokenRequirementsParams {
60
66
  * @example
61
67
  * ```ts
62
68
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
69
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
63
70
  * import { createPublicClient, http, zeroAddress } from "viem";
64
71
  * import { mainnet } from "viem/chains";
65
- * import { getBlueBundlesV1TokenRequirements } from "@morpho-org/morpho-sdk";
72
+ * import { getBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
66
73
  *
67
74
  * const client = createPublicClient({ chain: mainnet, transport: http() });
68
- * const requirements = await getBlueBundlesV1TokenRequirements(client, {
75
+ * const vaultBundlesV1 = getChainAddress(mainnet.id, "bundles.vaultBundlesV1");
76
+ * const requirements = await getBundlesTokenRequirements(client, {
69
77
  * token: addressesRegistry[mainnet.id].usdc,
78
+ * spender: vaultBundlesV1,
70
79
  * amount: 1_000_000n,
71
80
  * owner: zeroAddress,
72
81
  * chainId: mainnet.id,
73
82
  * deadline: 1_900_000_000n,
74
83
  * supportSignature: true,
75
- * permit2Nonce: 42n,
76
84
  * });
77
- * // requirements contains approvals and/or signable BlueBundlesV1 token requirements.
85
+ * // requirements contains approvals and/or signable bundles token requirements.
78
86
  * ```
79
87
  */
80
- export declare const getBlueBundlesV1TokenRequirements: (viemClient: Client, params: GetBlueBundlesV1TokenRequirementsParams) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | BlueBundlesV1TokenSignatureRequirement)[]>;
88
+ export declare const getBundlesTokenRequirements: (viemClient: Client, params: GetBundlesTokenRequirementsParams) => Promise<readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[]>;
@@ -1,26 +1,27 @@
1
1
  import { getChainAddresses } from "@morpho-org/blue-sdk";
2
2
  import { erc2612Abi, permit2Abi } from "@morpho-org/blue-sdk-viem";
3
- import { getChainAddress, isDefined, Time } from "@morpho-org/morpho-ts";
3
+ import { isDefined, Time } from "@morpho-org/morpho-ts";
4
4
  import { erc20Abi, isAddressEqual, maxUint256, } from "viem";
5
5
  import { readContract } from "viem/actions";
6
- import { validateChainId } from "../../../helpers/index.js";
7
- import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExceedsMaxError, MissingPermit2TransferFromNonceError, NegativeInputError, NonPositiveInputError, Permit2TransferFromNonceAlreadyUsedError, } from "../../../types/index.js";
8
- import { encodeErc20Permit } from "../encode/encodeErc20Permit.js";
9
- import { encodeErc20Permit2TransferFrom } from "../encode/encodeErc20Permit2TransferFrom.js";
10
- import { getRequirementsApproval } from "../getRequirementsApproval.js";
6
+ import { resolveBundlesTokenRequirements } from "../../actions/bundles/index.js";
7
+ import { encodeErc20Permit } from "../../actions/requirements/encode/encodeErc20Permit.js";
8
+ import { validateChainId, validateRequirementSpender, } from "../../helpers/index.js";
9
+ import { ApprovalAmountLessThanSpendAmountError, ExpiredDeadlineError, InputExceedsMaxError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
10
+ import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
11
11
  /**
12
12
  * Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
13
- * BlueBundlesV1.
13
+ * a registered fixed bundles contract.
14
14
  *
15
15
  * Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
16
- * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names BlueBundlesV1
17
- * as spender. Permit2 SignatureTransfer requires an explicit unused unordered nonce so concurrent
18
- * requirements never silently sign the same owner-global nonce.
16
+ * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
17
+ * as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
18
+ * the same owner should pass explicit nonces.
19
19
  *
20
20
  * @param viemClient - Connected viem client used for allowance and nonce reads.
21
21
  * @param params - Token requirement parameters.
22
22
  * @param params.token - ERC-20 token funded by the operation.
23
- * @param params.amount - Exact amount BlueBundlesV1 will pull; zero returns no requirements.
23
+ * @param params.spender - Registered fixed bundles contract that pulls the token.
24
+ * @param params.amount - Exact amount the contract will pull; zero returns no requirements.
24
25
  * @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
25
26
  * @param params.owner - Account funding the operation.
26
27
  * @param params.chainId - Target chain id; must match the client chain.
@@ -28,16 +29,19 @@ import { getRequirementsApproval } from "../getRequirementsApproval.js";
28
29
  * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
29
30
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
30
31
  * @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
31
- * @param params.permit2Nonce - Explicit unused uint256 nonce required when Permit2 is selected.
32
+ * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
33
+ * found via {@link getUnusedPermit2Nonce}.
32
34
  * @returns Ordered deep-frozen approval transactions and/or signable token requirements.
33
35
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
34
36
  * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
35
37
  * @throws {NonPositiveInputError} when `deadline` is not positive.
36
38
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
37
39
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
- * @throws {UnknownAddressError} when BlueBundlesV1 is not registered for the chain.
39
- * @throws {MissingPermit2TransferFromNonceError} when Permit2 is selected without a nonce.
40
- * @throws {Permit2TransferFromNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
40
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
41
+ * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
42
+ * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
43
+ * was passed explicitly.
44
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
41
45
  * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
42
46
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
43
47
  * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, or ERC-2612 metadata
@@ -45,25 +49,32 @@ import { getRequirementsApproval } from "../getRequirementsApproval.js";
45
49
  * @example
46
50
  * ```ts
47
51
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
52
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
48
53
  * import { createPublicClient, http, zeroAddress } from "viem";
49
54
  * import { mainnet } from "viem/chains";
50
- * import { getBlueBundlesV1TokenRequirements } from "@morpho-org/morpho-sdk";
55
+ * import { getBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
51
56
  *
52
57
  * const client = createPublicClient({ chain: mainnet, transport: http() });
53
- * const requirements = await getBlueBundlesV1TokenRequirements(client, {
58
+ * const vaultBundlesV1 = getChainAddress(mainnet.id, "bundles.vaultBundlesV1");
59
+ * const requirements = await getBundlesTokenRequirements(client, {
54
60
  * token: addressesRegistry[mainnet.id].usdc,
61
+ * spender: vaultBundlesV1,
55
62
  * amount: 1_000_000n,
56
63
  * owner: zeroAddress,
57
64
  * chainId: mainnet.id,
58
65
  * deadline: 1_900_000_000n,
59
66
  * supportSignature: true,
60
- * permit2Nonce: 42n,
61
67
  * });
62
- * // requirements contains approvals and/or signable BlueBundlesV1 token requirements.
68
+ * // requirements contains approvals and/or signable bundles token requirements.
63
69
  * ```
64
70
  */
65
- export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
71
+ export const getBundlesTokenRequirements = async (viemClient, params) => {
66
72
  validateChainId(viemClient.chain?.id, params.chainId);
73
+ validateRequirementSpender({
74
+ chainId: params.chainId,
75
+ spender: params.spender,
76
+ allowed: ["blueBundlesV1", "vaultBundlesV1"],
77
+ });
67
78
  if (params.amount < 0n) {
68
79
  throw new NegativeInputError("amount", params.amount);
69
80
  }
@@ -95,7 +106,6 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
95
106
  }
96
107
  if (params.amount === 0n)
97
108
  return [];
98
- const blueBundlesV1 = getChainAddress(params.chainId, "bundles.blueBundlesV1");
99
109
  const { permit2, dai } = getChainAddresses(params.chainId);
100
110
  if (params.supportSignature) {
101
111
  const isDai = isDefined(dai) && isAddressEqual(params.token, dai);
@@ -110,7 +120,8 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
110
120
  return [
111
121
  await encodeErc20Permit(viemClient, {
112
122
  token: params.token,
113
- spender: blueBundlesV1,
123
+ owner: params.owner,
124
+ spender: params.spender,
114
125
  amount: params.amount,
115
126
  chainId: params.chainId,
116
127
  nonce,
@@ -121,21 +132,22 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
121
132
  }
122
133
  }
123
134
  if (permit2 != null) {
124
- if (params.permit2Nonce == null) {
125
- throw new MissingPermit2TransferFromNonceError();
126
- }
127
- if (params.permit2Nonce < 0n) {
128
- throw new NegativeInputError("permit2Nonce", params.permit2Nonce);
135
+ const permit2Nonce = params.permit2Nonce ??
136
+ (await getUnusedPermit2Nonce(viemClient, {
137
+ owner: params.owner,
138
+ chainId: params.chainId,
139
+ }));
140
+ if (permit2Nonce < 0n) {
141
+ throw new NegativeInputError("permit2Nonce", permit2Nonce);
129
142
  }
130
- if (params.permit2Nonce > maxUint256) {
143
+ if (permit2Nonce > maxUint256) {
131
144
  throw new InputExceedsMaxError({
132
145
  field: "permit2Nonce",
133
- value: params.permit2Nonce,
146
+ value: permit2Nonce,
134
147
  max: maxUint256,
135
148
  });
136
149
  }
137
- const wordPosition = params.permit2Nonce >> 8n;
138
- const bitPosition = params.permit2Nonce & 255n;
150
+ const wordPosition = permit2Nonce >> 8n;
139
151
  const [allowance, nonceBitmap] = await Promise.all([
140
152
  readContract(viemClient, {
141
153
  abi: erc20Abi,
@@ -150,29 +162,20 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
150
162
  args: [params.owner, wordPosition],
151
163
  }),
152
164
  ]);
153
- if ((nonceBitmap & (1n << bitPosition)) !== 0n) {
154
- throw new Permit2TransferFromNonceAlreadyUsedError(params.owner, params.permit2Nonce);
155
- }
156
- return [
157
- ...getRequirementsApproval({
158
- address: params.token,
159
- chainId: params.chainId,
160
- args: {
161
- spender: permit2,
162
- spendAmount: params.amount,
163
- approvalAmount: maxUint256,
164
- },
165
- allowances: allowance,
166
- }),
167
- encodeErc20Permit2TransferFrom({
168
- token: params.token,
169
- spender: blueBundlesV1,
170
- amount: params.amount,
171
- chainId: params.chainId,
172
- nonce: params.permit2Nonce,
173
- deadline: params.deadline,
174
- }),
175
- ];
165
+ return resolveBundlesTokenRequirements({
166
+ token: params.token,
167
+ spender: params.spender,
168
+ owner: params.owner,
169
+ chainId: params.chainId,
170
+ amount: params.amount,
171
+ deadline: params.deadline,
172
+ state: {
173
+ type: "permit2SignatureTransfer",
174
+ permit2Allowance: allowance,
175
+ permit2Nonce,
176
+ nonceBitmap,
177
+ },
178
+ });
176
179
  }
177
180
  }
178
181
  const approvalAmount = params.approvalAmount ?? params.amount;
@@ -183,21 +186,19 @@ export const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
183
186
  abi: erc20Abi,
184
187
  address: params.token,
185
188
  functionName: "allowance",
186
- args: [params.owner, blueBundlesV1],
189
+ args: [params.owner, params.spender],
187
190
  });
188
- return getRequirementsApproval({
189
- address: params.token,
191
+ return resolveBundlesTokenRequirements({
192
+ token: params.token,
193
+ spender: params.spender,
194
+ owner: params.owner,
190
195
  chainId: params.chainId,
191
- args: {
192
- spender: blueBundlesV1,
193
- // The pull the operation actually performs is `amount`; `approvalAmount`
194
- // is only the allowance to set when one is needed. Comparing the existing
195
- // allowance against `amount` (not `approvalAmount`) avoids emitting a
196
- // redundant approval — and a zero-reset on approve-only-once tokens like
197
- // USDT — when the current allowance already covers the pull.
198
- spendAmount: params.amount,
196
+ amount: params.amount,
197
+ deadline: params.deadline,
198
+ state: {
199
+ type: "approval",
200
+ allowance,
199
201
  approvalAmount,
200
202
  },
201
- allowances: allowance,
202
203
  });
203
204
  };
@@ -10,7 +10,7 @@ export interface GetUnusedPermit2NonceParams {
10
10
  }
11
11
  /**
12
12
  * Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
13
- * {@link getBlueBundlesV1TokenRequirements} or as `nonce` to {@link encodeErc20Permit2TransferFrom}.
13
+ * {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
14
14
  *
15
15
  * Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
16
16
  * `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
@@ -2,14 +2,14 @@ import { permit2Abi } from "@morpho-org/blue-sdk-viem";
2
2
  import { getChainAddress } from "@morpho-org/morpho-ts";
3
3
  import { maxUint256 } from "viem";
4
4
  import { readContract } from "viem/actions";
5
- import { validateChainId } from "../../../helpers/index.js";
6
- import { validateUint256Field } from "../../../helpers/validate.js";
7
- import { NoUnusedPermit2NonceError } from "../../../types/index.js";
5
+ import { validateChainId } from "../../helpers/index.js";
6
+ import { validateUint256Field } from "../../helpers/validate.js";
7
+ import { NoUnusedPermit2NonceError } from "../../types/index.js";
8
8
  /** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
9
9
  const MAX_PERMIT2_NONCE_WORD = maxUint256 >> 8n;
10
10
  /**
11
11
  * Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
12
- * {@link getBlueBundlesV1TokenRequirements} or as `nonce` to {@link encodeErc20Permit2TransferFrom}.
12
+ * {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
13
13
  *
14
14
  * Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
15
15
  * `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
@@ -0,0 +1,28 @@
1
+ import type { Token } from "@morpho-org/blue-sdk";
2
+ import type { Address, Client } from "viem";
3
+ import { type ActionRequirement } from "../../types/index.js";
4
+ /**
5
+ * Resolves the exact vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
6
+ *
7
+ * The exit burns however many shares the vault prices at execution time, so the share allowance is
8
+ * the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
9
+ * satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
10
+ *
11
+ * @internal
12
+ *
13
+ * @param viemClient - Client used to read the current share allowance and permit nonce.
14
+ * @param params - Vault snapshot, owner, exact allowance, and deadline values.
15
+ * @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
16
+ * permit or approval that sets it to exactly that cap.
17
+ * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
18
+ * @throws {viem.BaseError} when an allowance or nonce read fails.
19
+ */
20
+ export declare const getVaultBundlesSharesRequirements: (viemClient: Client, params: {
21
+ readonly vaultData: Token;
22
+ readonly version: "vaultV1" | "vaultV2";
23
+ readonly owner: Address;
24
+ readonly chainId: number;
25
+ readonly requiredShareAllowance: bigint;
26
+ readonly deadline: bigint;
27
+ readonly supportSignature: boolean;
28
+ }) => Promise<readonly ActionRequirement[]>;
@@ -0,0 +1,70 @@
1
+ import { erc2612Abi } from "@morpho-org/blue-sdk-viem";
2
+ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { erc20Abi } from "viem";
4
+ import { readContract } from "viem/actions";
5
+ import { encodeErc20Approval, encodeVaultSharesPermit, } from "../../actions/index.js";
6
+ import { validateChainId } from "../../helpers/index.js";
7
+ import { ExpiredDeadlineError, } from "../../types/index.js";
8
+ /**
9
+ * Resolves the exact vault-share approval or ERC-2612 requirement for a VaultBundlesV1 exit.
10
+ *
11
+ * The exit burns however many shares the vault prices at execution time, so the share allowance is
12
+ * the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
13
+ * satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
14
+ *
15
+ * @internal
16
+ *
17
+ * @param viemClient - Client used to read the current share allowance and permit nonce.
18
+ * @param params - Vault snapshot, owner, exact allowance, and deadline values.
19
+ * @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
20
+ * permit or approval that sets it to exactly that cap.
21
+ * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
22
+ * @throws {viem.BaseError} when an allowance or nonce read fails.
23
+ */
24
+ export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
25
+ validateChainId(viemClient.chain?.id, params.chainId);
26
+ const now = Time.timestamp();
27
+ if (params.deadline <= now) {
28
+ throw new ExpiredDeadlineError(params.deadline, now);
29
+ }
30
+ const spender = getChainAddress(params.chainId, "bundles.vaultBundlesV1");
31
+ const allowance = await readContract(viemClient, {
32
+ address: params.vaultData.address,
33
+ abi: erc20Abi,
34
+ functionName: "allowance",
35
+ args: [params.owner, spender],
36
+ });
37
+ // Asset-mode withdrawals carry no onchain share cap, so the allowance itself is the cap. A
38
+ // larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`,
39
+ // so only an exact match skips the approval or permit that resets it to the computed cap.
40
+ if (allowance === params.requiredShareAllowance)
41
+ return [];
42
+ if (params.supportSignature) {
43
+ const nonce = await readContract(viemClient, {
44
+ address: params.vaultData.address,
45
+ abi: erc2612Abi,
46
+ functionName: "nonces",
47
+ args: [params.owner],
48
+ });
49
+ return [
50
+ encodeVaultSharesPermit({
51
+ vault: params.vaultData,
52
+ version: params.version,
53
+ spender,
54
+ owner: params.owner,
55
+ chainId: params.chainId,
56
+ nonce,
57
+ amount: params.requiredShareAllowance,
58
+ deadline: params.deadline,
59
+ }),
60
+ ];
61
+ }
62
+ return [
63
+ encodeErc20Approval({
64
+ token: params.vaultData.address,
65
+ spender,
66
+ amount: params.requiredShareAllowance,
67
+ chainId: params.chainId,
68
+ }),
69
+ ];
70
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./getBundlesTokenRequirements.js";
2
+ export * from "./getUnusedPermit2Nonce.js";
@@ -0,0 +1,2 @@
1
+ export * from "./getBundlesTokenRequirements.js";
2
+ export * from "./getUnusedPermit2Nonce.js";