@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
@@ -9,6 +9,7 @@ const common_js_1 = require("../../actions/blue/common.js");
9
9
  const index_js_1 = require("../../actions/index.js");
10
10
  const index_js_2 = require("../../helpers/index.js");
11
11
  const index_js_3 = require("../../types/index.js");
12
+ const index_js_4 = require("../requirements/index.js");
12
13
  const vaultV1ReallocationData_js_1 = require("../vaultV1ReallocationData.js");
13
14
  const vaultV2BlueReallocationData_js_1 = require("../vaultV2BlueReallocationData.js");
14
15
  class MorphoBlue {
@@ -50,8 +51,9 @@ class MorphoBlue {
50
51
  }
51
52
  async getTokenRequirements(params) {
52
53
  this.validateDeadline(params.deadline);
53
- return (0, index_js_1.getBlueBundlesV1TokenRequirements)(this.client.viemClient, {
54
+ return (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
54
55
  token: params.token,
56
+ spender: (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.blueBundlesV1"),
55
57
  amount: params.amount,
56
58
  owner: params.userAddress,
57
59
  chainId: this.chainId,
@@ -866,6 +868,7 @@ class MorphoBlue {
866
868
  * @param params.options - Optional allocator and utilization options.
867
869
  * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
868
870
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
871
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
869
872
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
870
873
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
871
874
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -912,6 +915,7 @@ class MorphoBlue {
912
915
  * @param params.options - Optional allocator and utilization options.
913
916
  * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
914
917
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
918
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
915
919
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
916
920
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
917
921
  * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
@@ -937,6 +941,7 @@ class MorphoBlue {
937
941
  * @param params.options - Optional allocator discovery controls and operation to support.
938
942
  * @returns Action-ready reallocations and their post-simulation state.
939
943
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
944
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
940
945
  * @throws {NegativeInputError} when a utilization or penalty limit is negative.
941
946
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
942
947
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
@@ -10,7 +10,11 @@ IPosition, IPreLiquidationParams as IBluePreLiquidationParams,
10
10
  /** @deprecated Use `IBluePreLiquidationParams` or the raw Blue subpath. */
11
11
  IPreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition,
12
12
  /** @deprecated Use `IBluePreLiquidationPosition` or the raw Blue subpath. */
13
- IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
13
+ IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig,
14
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BlueMarketPublicAllocatorConfig`. */
15
+ IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType,
16
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BluePublicAllocatorConfig`. */
17
+ VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
14
18
  export { AccrualPosition as BlueAccrualPosition,
15
19
  /** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
16
20
  AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
@@ -25,7 +29,9 @@ PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
25
29
  /** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
26
30
  PreLiquidationPosition, Token, User as BlueUser,
27
31
  /** @deprecated Use `BlueUser` or the raw Blue subpath. */
28
- User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
32
+ User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
33
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
34
+ VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
29
35
  export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
30
36
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
31
37
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
@@ -62,6 +68,7 @@ TakeBorrowParams, TakeLendParams as MidnightTakeLendParams,
62
68
  /** @deprecated Use `MidnightTakeLendParams`. */
63
69
  TakeLendParams, } from "./midnight/index.js";
64
70
  export { type MidnightActionOutput, type MidnightActionSignatures, type MidnightActions, MorphoMidnight, } from "./midnight/index.js";
71
+ export * from "./requirements/index.js";
65
72
  export { MorphoVaultV1 } from "./vaultV1/index.js";
66
73
  export { type InputReallocationData, type InputVaultV1ReallocationData, ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
67
74
  export { MorphoVaultV2 } from "./vaultV2/index.js";
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketPublicAllocatorConfig = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.User = exports.BlueUser = exports.Token = exports.PreLiquidationPosition = exports.BluePreLiquidationPosition = exports.PreLiquidationParams = exports.BluePreLiquidationParams = exports.Position = exports.BluePosition = exports.MarketParams = exports.BlueMarketParams = exports.Market = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.AccrualPosition = exports.BlueAccrualPosition = void 0;
4
18
  exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.VaultV1ReallocationData = exports.ReallocationData = void 0;
@@ -39,6 +53,7 @@ Object.defineProperty(exports, "Vault", { enumerable: true, get: function () { r
39
53
  Object.defineProperty(exports, "VaultConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultConfig; } });
40
54
  Object.defineProperty(exports, "VaultMarketAllocation", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketAllocation; } });
41
55
  Object.defineProperty(exports, "VaultMarketConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketConfig; } });
56
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
42
57
  Object.defineProperty(exports, "VaultMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketPublicAllocatorConfig; } });
43
58
  Object.defineProperty(exports, "VaultToken", { enumerable: true, get: function () { return blue_sdk_1.VaultToken; } });
44
59
  Object.defineProperty(exports, "VaultUser", { enumerable: true, get: function () { return blue_sdk_1.VaultUser; } });
@@ -62,6 +77,7 @@ var index_js_1 = require("./blue/index.js");
62
77
  Object.defineProperty(exports, "MorphoBlue", { enumerable: true, get: function () { return index_js_1.MorphoBlue; } });
63
78
  var index_js_2 = require("./midnight/index.js");
64
79
  Object.defineProperty(exports, "MorphoMidnight", { enumerable: true, get: function () { return index_js_2.MorphoMidnight; } });
80
+ __exportStar(require("./requirements/index.js"), exports);
65
81
  var index_js_3 = require("./vaultV1/index.js");
66
82
  Object.defineProperty(exports, "MorphoVaultV1", { enumerable: true, get: function () { return index_js_3.MorphoVaultV1; } });
67
83
  var vaultV1ReallocationData_js_1 = require("./vaultV1ReallocationData.js");
@@ -20,8 +20,8 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
20
20
  * const output = midnight.takeLend({
21
21
  * accountAddress: lender,
22
22
  * marketData,
23
- * assets: BigInt(quote.data.availableAssets),
24
- * minUnits: BigInt(quote.data.availableUnits),
23
+ * assets: 1_000_000n,
24
+ * minUnits: 900_000n,
25
25
  * takeableOffers: quote.data.takeableOffers,
26
26
  * deadline: maxUint256,
27
27
  * });
@@ -550,7 +550,6 @@ class MorphoMidnight {
550
550
  }
551
551
  });
552
552
  const midnight = (0, morpho_ts_1.getChainAddress)(this.chainId, "midnight");
553
- const signedPayloads = new Map();
554
553
  return {
555
554
  groups: data.groups,
556
555
  root: data.tree.root,
@@ -567,14 +566,12 @@ class MorphoMidnight {
567
566
  })));
568
567
  requirements.push(...(await this.getRatifierRequirements({
569
568
  offersData: data,
570
- signedPayloads,
571
569
  })));
572
570
  return requirements;
573
571
  },
574
572
  buildTx: (signatures) => this.buildSubmitOffersTx({
575
573
  offersData: data,
576
574
  signatures,
577
- signedPayloads,
578
575
  }),
579
576
  };
580
577
  }
@@ -605,7 +602,6 @@ class MorphoMidnight {
605
602
  validation: params.validation,
606
603
  });
607
604
  (0, validateOfferSides_js_1.validateOfferSides)(data.tree.offers, false);
608
- const signedPayloads = new Map();
609
605
  return {
610
606
  groups: data.groups,
611
607
  root: data.tree.root,
@@ -613,13 +609,11 @@ class MorphoMidnight {
613
609
  getRequirements: async () => {
614
610
  return await this.getRatifierRequirements({
615
611
  offersData: data,
616
- signedPayloads,
617
612
  });
618
613
  },
619
614
  buildTx: (signatures) => this.buildSubmitOffersTx({
620
615
  offersData: data,
621
616
  signatures,
622
- signedPayloads,
623
617
  }),
624
618
  };
625
619
  }
@@ -677,7 +671,6 @@ class MorphoMidnight {
677
671
  }
678
672
  }
679
673
  const midnight = (0, morpho_ts_1.getChainAddress)(this.chainId, "midnight");
680
- const signedPayloads = new Map();
681
674
  return {
682
675
  groups: data.groups,
683
676
  root: data.tree.root,
@@ -702,7 +695,6 @@ class MorphoMidnight {
702
695
  }),
703
696
  ...(await this.getRatifierRequirements({
704
697
  offersData: data,
705
- signedPayloads,
706
698
  })),
707
699
  ];
708
700
  return requirements;
@@ -710,7 +702,6 @@ class MorphoMidnight {
710
702
  buildTx: (signatures) => this.buildSubmitOffersTx({
711
703
  offersData: data,
712
704
  signatures,
713
- signedPayloads,
714
705
  }),
715
706
  };
716
707
  }
@@ -910,6 +901,18 @@ class MorphoMidnight {
910
901
  requirements.push(authorization);
911
902
  if (data.ratifierType === "ecrecover") {
912
903
  const chainId = this.chainId;
904
+ // The offer-tree EIP-712 payload is signed over the tree, not the signer, so it is fully
905
+ // determined at build time and stored on the action for external signing.
906
+ const treeTypedData = midnight_sdk_1.EcrecoverRatifierUtils.typedData({
907
+ tree: data.tree,
908
+ chainId,
909
+ });
910
+ const typedData = (0, morpho_ts_1.deepFreeze)({
911
+ domain: treeTypedData.domain,
912
+ types: treeTypedData.types,
913
+ primaryType: treeTypedData.primaryType,
914
+ message: treeTypedData.message,
915
+ });
913
916
  const action = {
914
917
  type: "midnightOfferRootSignature",
915
918
  args: {
@@ -917,32 +920,23 @@ class MorphoMidnight {
917
920
  ratifier: data.ratifier,
918
921
  offers: data.tree.offers.length,
919
922
  },
923
+ typedData,
920
924
  };
921
925
  requirements.push({
922
926
  action,
923
927
  async sign(client, userAddress) {
924
- const typedData = midnight_sdk_1.EcrecoverRatifierUtils.typedData({
925
- tree: data.tree,
926
- chainId,
927
- });
928
- const typedDataDefinition = {
929
- domain: typedData.domain,
930
- types: typedData.types,
931
- primaryType: typedData.primaryType,
932
- message: typedData.message,
933
- };
934
928
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
935
929
  client,
936
930
  userAddress,
937
- typedData: typedDataDefinition,
931
+ typedData,
938
932
  });
933
+ // Derive the ratification payload `buildTx()` submits.
939
934
  const items = await midnight_sdk_1.EcrecoverRatifierUtils.ratify({
940
935
  tree: data.tree,
941
936
  account: userAddress,
942
937
  signature,
943
938
  });
944
939
  const payload = await midnight_sdk_1.Payload.encode(items);
945
- params.signedPayloads.set(signature.toLowerCase(), payload);
946
940
  return (0, morpho_ts_1.deepFreeze)({
947
941
  args: {
948
942
  owner: userAddress,
@@ -1010,11 +1004,13 @@ class MorphoMidnight {
1010
1004
  actualOffers: signature.action.args.offers,
1011
1005
  });
1012
1006
  }
1013
- const signedPayload = params.signedPayloads.get(signature.args.signature.toLowerCase());
1014
- if (signedPayload == null) {
1007
+ // The payload is carried on the signature the caller hands to buildTx, so
1008
+ // a prepared offer-root requirement can be signed on one instance and
1009
+ // submitted from another without sharing in-memory state.
1010
+ if (signature.args.payload == null) {
1015
1011
  throw new index_js_4.UnpreparedMidnightOfferRootSignatureError();
1016
1012
  }
1017
- payload = signedPayload;
1013
+ payload = signature.args.payload;
1018
1014
  }
1019
1015
  else {
1020
1016
  (0, index_js_4.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,29 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBlueBundlesV1TokenRequirements = void 0;
3
+ exports.getBundlesTokenRequirements = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const actions_1 = require("viem/actions");
9
- const index_js_1 = require("../../../helpers/index.js");
10
- const index_js_2 = require("../../../types/index.js");
11
- const encodeErc20Permit_js_1 = require("../encode/encodeErc20Permit.js");
12
- const encodeErc20Permit2TransferFrom_js_1 = require("../encode/encodeErc20Permit2TransferFrom.js");
13
- const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
9
+ const index_js_1 = require("../../actions/bundles/index.js");
10
+ const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encodeErc20Permit.js");
11
+ const index_js_2 = require("../../helpers/index.js");
12
+ const index_js_3 = require("../../types/index.js");
13
+ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
14
14
  /**
15
15
  * Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
16
- * BlueBundlesV1.
16
+ * a registered fixed bundles contract.
17
17
  *
18
18
  * Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
19
- * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names BlueBundlesV1
20
- * as spender. Permit2 SignatureTransfer requires an explicit unused unordered nonce so concurrent
21
- * requirements never silently sign the same owner-global nonce.
19
+ * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
20
+ * as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
21
+ * the same owner should pass explicit nonces.
22
22
  *
23
23
  * @param viemClient - Connected viem client used for allowance and nonce reads.
24
24
  * @param params - Token requirement parameters.
25
25
  * @param params.token - ERC-20 token funded by the operation.
26
- * @param params.amount - Exact amount BlueBundlesV1 will pull; zero returns no requirements.
26
+ * @param params.spender - Registered fixed bundles contract that pulls the token.
27
+ * @param params.amount - Exact amount the contract will pull; zero returns no requirements.
27
28
  * @param params.approvalAmount - Classic approval amount; defaults to `amount` and is ignored by signature paths.
28
29
  * @param params.owner - Account funding the operation.
29
30
  * @param params.chainId - Target chain id; must match the client chain.
@@ -31,16 +32,19 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
31
32
  * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
32
33
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
33
34
  * @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
34
- * @param params.permit2Nonce - Explicit unused uint256 nonce required when Permit2 is selected.
35
+ * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
36
+ * found via {@link getUnusedPermit2Nonce}.
35
37
  * @returns Ordered deep-frozen approval transactions and/or signable token requirements.
36
38
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
37
39
  * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
38
40
  * @throws {NonPositiveInputError} when `deadline` is not positive.
39
41
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
40
42
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
41
- * @throws {UnknownAddressError} when BlueBundlesV1 is not registered for the chain.
42
- * @throws {MissingPermit2TransferFromNonceError} when Permit2 is selected without a nonce.
43
- * @throws {Permit2TransferFromNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
43
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
44
+ * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
45
+ * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
46
+ * was passed explicitly.
47
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
44
48
  * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
45
49
  * @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
46
50
  * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, or ERC-2612 metadata
@@ -48,42 +52,49 @@ const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
48
52
  * @example
49
53
  * ```ts
50
54
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
55
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
51
56
  * import { createPublicClient, http, zeroAddress } from "viem";
52
57
  * import { mainnet } from "viem/chains";
53
- * import { getBlueBundlesV1TokenRequirements } from "@morpho-org/morpho-sdk";
58
+ * import { getBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
54
59
  *
55
60
  * const client = createPublicClient({ chain: mainnet, transport: http() });
56
- * const requirements = await getBlueBundlesV1TokenRequirements(client, {
61
+ * const vaultBundlesV1 = getChainAddress(mainnet.id, "bundles.vaultBundlesV1");
62
+ * const requirements = await getBundlesTokenRequirements(client, {
57
63
  * token: addressesRegistry[mainnet.id].usdc,
64
+ * spender: vaultBundlesV1,
58
65
  * amount: 1_000_000n,
59
66
  * owner: zeroAddress,
60
67
  * chainId: mainnet.id,
61
68
  * deadline: 1_900_000_000n,
62
69
  * supportSignature: true,
63
- * permit2Nonce: 42n,
64
70
  * });
65
- * // requirements contains approvals and/or signable BlueBundlesV1 token requirements.
71
+ * // requirements contains approvals and/or signable bundles token requirements.
66
72
  * ```
67
73
  */
68
- const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
69
- (0, index_js_1.validateChainId)(viemClient.chain?.id, params.chainId);
74
+ const getBundlesTokenRequirements = async (viemClient, params) => {
75
+ (0, index_js_2.validateChainId)(viemClient.chain?.id, params.chainId);
76
+ (0, index_js_2.validateRequirementSpender)({
77
+ chainId: params.chainId,
78
+ spender: params.spender,
79
+ allowed: ["blueBundlesV1", "vaultBundlesV1"],
80
+ });
70
81
  if (params.amount < 0n) {
71
- throw new index_js_2.NegativeInputError("amount", params.amount);
82
+ throw new index_js_3.NegativeInputError("amount", params.amount);
72
83
  }
73
84
  // Reject oversized inputs before any RPC read so this resolver never asks the user to sign or
74
85
  // submit an approval/permit that the eventual BlueBundlesV1 call (uint256 ABI) would reject.
75
86
  if (params.amount > viem_1.maxUint256) {
76
- throw new index_js_2.InputExceedsMaxError({
87
+ throw new index_js_3.InputExceedsMaxError({
77
88
  field: "amount",
78
89
  value: params.amount,
79
90
  max: viem_1.maxUint256,
80
91
  });
81
92
  }
82
93
  if (params.deadline <= 0n) {
83
- throw new index_js_2.NonPositiveInputError("deadline", params.deadline);
94
+ throw new index_js_3.NonPositiveInputError("deadline", params.deadline);
84
95
  }
85
96
  if (params.deadline > viem_1.maxUint256) {
86
- throw new index_js_2.InputExceedsMaxError({
97
+ throw new index_js_3.InputExceedsMaxError({
87
98
  field: "deadline",
88
99
  value: params.deadline,
89
100
  max: viem_1.maxUint256,
@@ -94,11 +105,10 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
94
105
  // this too, but the exported resolver must guard its own callers.
95
106
  const timestamp = morpho_ts_1.Time.timestamp();
96
107
  if (params.deadline <= timestamp) {
97
- throw new index_js_2.ExpiredDeadlineError(params.deadline, timestamp);
108
+ throw new index_js_3.ExpiredDeadlineError(params.deadline, timestamp);
98
109
  }
99
110
  if (params.amount === 0n)
100
111
  return [];
101
- const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(params.chainId, "bundles.blueBundlesV1");
102
112
  const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
103
113
  if (params.supportSignature) {
104
114
  const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
@@ -113,7 +123,8 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
113
123
  return [
114
124
  await (0, encodeErc20Permit_js_1.encodeErc20Permit)(viemClient, {
115
125
  token: params.token,
116
- spender: blueBundlesV1,
126
+ owner: params.owner,
127
+ spender: params.spender,
117
128
  amount: params.amount,
118
129
  chainId: params.chainId,
119
130
  nonce,
@@ -124,21 +135,22 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
124
135
  }
125
136
  }
126
137
  if (permit2 != null) {
127
- if (params.permit2Nonce == null) {
128
- throw new index_js_2.MissingPermit2TransferFromNonceError();
129
- }
130
- if (params.permit2Nonce < 0n) {
131
- throw new index_js_2.NegativeInputError("permit2Nonce", params.permit2Nonce);
138
+ const permit2Nonce = params.permit2Nonce ??
139
+ (await (0, getUnusedPermit2Nonce_js_1.getUnusedPermit2Nonce)(viemClient, {
140
+ owner: params.owner,
141
+ chainId: params.chainId,
142
+ }));
143
+ if (permit2Nonce < 0n) {
144
+ throw new index_js_3.NegativeInputError("permit2Nonce", permit2Nonce);
132
145
  }
133
- if (params.permit2Nonce > viem_1.maxUint256) {
134
- throw new index_js_2.InputExceedsMaxError({
146
+ if (permit2Nonce > viem_1.maxUint256) {
147
+ throw new index_js_3.InputExceedsMaxError({
135
148
  field: "permit2Nonce",
136
- value: params.permit2Nonce,
149
+ value: permit2Nonce,
137
150
  max: viem_1.maxUint256,
138
151
  });
139
152
  }
140
- const wordPosition = params.permit2Nonce >> 8n;
141
- const bitPosition = params.permit2Nonce & 255n;
153
+ const wordPosition = permit2Nonce >> 8n;
142
154
  const [allowance, nonceBitmap] = await Promise.all([
143
155
  (0, actions_1.readContract)(viemClient, {
144
156
  abi: viem_1.erc20Abi,
@@ -153,55 +165,44 @@ const getBlueBundlesV1TokenRequirements = async (viemClient, params) => {
153
165
  args: [params.owner, wordPosition],
154
166
  }),
155
167
  ]);
156
- if ((nonceBitmap & (1n << bitPosition)) !== 0n) {
157
- throw new index_js_2.Permit2TransferFromNonceAlreadyUsedError(params.owner, params.permit2Nonce);
158
- }
159
- return [
160
- ...(0, getRequirementsApproval_js_1.getRequirementsApproval)({
161
- address: params.token,
162
- chainId: params.chainId,
163
- args: {
164
- spender: permit2,
165
- spendAmount: params.amount,
166
- approvalAmount: viem_1.maxUint256,
167
- },
168
- allowances: allowance,
169
- }),
170
- (0, encodeErc20Permit2TransferFrom_js_1.encodeErc20Permit2TransferFrom)({
171
- token: params.token,
172
- spender: blueBundlesV1,
173
- amount: params.amount,
174
- chainId: params.chainId,
175
- nonce: params.permit2Nonce,
176
- deadline: params.deadline,
177
- }),
178
- ];
168
+ return (0, index_js_1.resolveBundlesTokenRequirements)({
169
+ token: params.token,
170
+ spender: params.spender,
171
+ owner: params.owner,
172
+ chainId: params.chainId,
173
+ amount: params.amount,
174
+ deadline: params.deadline,
175
+ state: {
176
+ type: "permit2SignatureTransfer",
177
+ permit2Allowance: allowance,
178
+ permit2Nonce,
179
+ nonceBitmap,
180
+ },
181
+ });
179
182
  }
180
183
  }
181
184
  const approvalAmount = params.approvalAmount ?? params.amount;
182
185
  if (approvalAmount < params.amount) {
183
- throw new index_js_2.ApprovalAmountLessThanSpendAmountError();
186
+ throw new index_js_3.ApprovalAmountLessThanSpendAmountError();
184
187
  }
185
188
  const allowance = await (0, actions_1.readContract)(viemClient, {
186
189
  abi: viem_1.erc20Abi,
187
190
  address: params.token,
188
191
  functionName: "allowance",
189
- args: [params.owner, blueBundlesV1],
192
+ args: [params.owner, params.spender],
190
193
  });
191
- return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
192
- address: params.token,
194
+ return (0, index_js_1.resolveBundlesTokenRequirements)({
195
+ token: params.token,
196
+ spender: params.spender,
197
+ owner: params.owner,
193
198
  chainId: params.chainId,
194
- args: {
195
- spender: blueBundlesV1,
196
- // The pull the operation actually performs is `amount`; `approvalAmount`
197
- // is only the allowance to set when one is needed. Comparing the existing
198
- // allowance against `amount` (not `approvalAmount`) avoids emitting a
199
- // redundant approval — and a zero-reset on approve-only-once tokens like
200
- // USDT — when the current allowance already covers the pull.
201
- spendAmount: params.amount,
199
+ amount: params.amount,
200
+ deadline: params.deadline,
201
+ state: {
202
+ type: "approval",
203
+ allowance,
202
204
  approvalAmount,
203
205
  },
204
- allowances: allowance,
205
206
  });
206
207
  };
207
- exports.getBlueBundlesV1TokenRequirements = getBlueBundlesV1TokenRequirements;
208
+ exports.getBundlesTokenRequirements = getBundlesTokenRequirements;