@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.3

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 (305) hide show
  1. package/MIGRATION-v5-to-v6.md +199 -34
  2. package/README.md +23 -15
  3. package/lib/cjs/abis.d.ts +3 -2829
  4. package/lib/cjs/abis.js +1 -1938
  5. package/lib/cjs/actions/blue/borrow.d.ts +3 -2
  6. package/lib/cjs/actions/blue/borrow.js +3 -2
  7. package/lib/cjs/actions/blue/common.js +6 -35
  8. package/lib/cjs/actions/blue/refinance.d.ts +2 -2
  9. package/lib/cjs/actions/blue/refinance.js +2 -2
  10. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  11. package/lib/cjs/actions/blue/repay.js +1 -1
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  14. package/lib/cjs/actions/blue/supply.d.ts +2 -2
  15. package/lib/cjs/actions/blue/supply.js +4 -9
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
  17. package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
  20. package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
  21. package/lib/cjs/actions/blue/withdraw.js +3 -3
  22. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
  23. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  24. package/lib/cjs/actions/bundles/common.d.ts +38 -4
  25. package/lib/cjs/actions/bundles/common.js +91 -35
  26. package/lib/cjs/actions/index.d.ts +0 -1
  27. package/lib/cjs/actions/index.js +0 -1
  28. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
  30. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  31. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  32. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  33. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  40. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  41. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  42. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  43. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  44. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  45. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  46. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  47. package/lib/cjs/actions/requirements/index.js +0 -1
  48. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  49. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  50. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
  51. package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
  52. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  53. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  54. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  55. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  56. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
  57. package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
  58. package/lib/cjs/augment.d.ts +0 -1
  59. package/lib/cjs/augment.js +0 -1
  60. package/lib/cjs/blue/abis.d.ts +1 -1
  61. package/lib/cjs/blue/abis.js +1 -5
  62. package/lib/cjs/blue/entities.d.ts +2 -2
  63. package/lib/cjs/blue/entities.js +1 -2
  64. package/lib/cjs/blue/errors.d.ts +1 -1
  65. package/lib/cjs/blue/errors.js +2 -1
  66. package/lib/cjs/blue/fetch.d.ts +1 -1
  67. package/lib/cjs/blue/fetch.js +1 -2
  68. package/lib/cjs/blue/types.d.ts +2 -4
  69. package/lib/cjs/blue/utils.d.ts +1 -3
  70. package/lib/cjs/blue/utils.js +1 -3
  71. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  72. package/lib/cjs/client/morphoViemExtension.js +1 -1
  73. package/lib/cjs/constants.d.ts +3 -37
  74. package/lib/cjs/constants.js +1 -39
  75. package/lib/cjs/entities/blue/blue.d.ts +38 -264
  76. package/lib/cjs/entities/blue/blue.js +2 -203
  77. package/lib/cjs/entities/index.d.ts +3 -60
  78. package/lib/cjs/entities/index.js +1 -20
  79. package/lib/cjs/entities/midnight/midnight.js +20 -24
  80. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  81. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  82. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  83. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  84. package/lib/cjs/entities/requirements/index.js +1 -0
  85. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
  86. package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
  87. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
  88. package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
  89. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  90. package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
  91. package/lib/cjs/errors.d.ts +2 -46
  92. package/lib/cjs/errors.js +2 -46
  93. package/lib/cjs/fetch.d.ts +1 -15
  94. package/lib/cjs/fetch.js +1 -16
  95. package/lib/cjs/helpers/constant.d.ts +0 -2
  96. package/lib/cjs/helpers/constant.js +0 -2
  97. package/lib/cjs/helpers/index.d.ts +4 -3
  98. package/lib/cjs/helpers/index.js +10 -9
  99. package/lib/cjs/helpers/metadata.d.ts +3 -5
  100. package/lib/cjs/helpers/metadata.js +4 -6
  101. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  102. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  103. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  104. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  105. package/lib/cjs/helpers/slippage.d.ts +34 -90
  106. package/lib/cjs/helpers/slippage.js +52 -137
  107. package/lib/cjs/helpers/utilization.d.ts +12 -10
  108. package/lib/cjs/helpers/utilization.js +27 -12
  109. package/lib/cjs/helpers/validate.d.ts +66 -32
  110. package/lib/cjs/helpers/validate.js +84 -57
  111. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  112. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  113. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  114. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  115. package/lib/cjs/types/action.d.ts +102 -68
  116. package/lib/cjs/types/action.js +11 -4
  117. package/lib/cjs/types/error.d.ts +332 -385
  118. package/lib/cjs/types/error.js +369 -412
  119. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  120. package/lib/cjs/types.d.ts +2 -18
  121. package/lib/cjs/utils.d.ts +8 -35
  122. package/lib/cjs/utils.js +11 -36
  123. package/lib/esm/abis.d.ts +3 -2829
  124. package/lib/esm/abis.js +3 -1935
  125. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/borrow.js +3 -2
  127. package/lib/esm/actions/blue/common.js +8 -37
  128. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  129. package/lib/esm/actions/blue/refinance.js +2 -2
  130. package/lib/esm/actions/blue/repay.d.ts +1 -1
  131. package/lib/esm/actions/blue/repay.js +1 -1
  132. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  133. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  134. package/lib/esm/actions/blue/supply.d.ts +2 -2
  135. package/lib/esm/actions/blue/supply.js +6 -11
  136. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  137. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  138. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  139. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  140. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  141. package/lib/esm/actions/blue/withdraw.js +3 -3
  142. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  143. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  144. package/lib/esm/actions/bundles/common.d.ts +38 -4
  145. package/lib/esm/actions/bundles/common.js +91 -36
  146. package/lib/esm/actions/index.d.ts +0 -1
  147. package/lib/esm/actions/index.js +0 -1
  148. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  149. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
  150. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  151. package/lib/esm/actions/requirements/blue/index.js +0 -1
  152. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  153. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
  154. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  155. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  157. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
  158. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  159. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  160. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  161. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  162. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  163. package/lib/esm/actions/requirements/encode/index.js +0 -1
  164. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  165. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  166. package/lib/esm/actions/requirements/index.d.ts +0 -1
  167. package/lib/esm/actions/requirements/index.js +0 -1
  168. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  169. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  170. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
  171. package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
  172. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  173. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  174. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  175. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  176. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
  177. package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
  178. package/lib/esm/augment.d.ts +0 -1
  179. package/lib/esm/augment.js +0 -1
  180. package/lib/esm/blue/abis.d.ts +1 -1
  181. package/lib/esm/blue/abis.js +1 -1
  182. package/lib/esm/blue/entities.d.ts +2 -2
  183. package/lib/esm/blue/entities.js +1 -1
  184. package/lib/esm/blue/errors.d.ts +1 -1
  185. package/lib/esm/blue/errors.js +1 -1
  186. package/lib/esm/blue/fetch.d.ts +1 -1
  187. package/lib/esm/blue/fetch.js +1 -1
  188. package/lib/esm/blue/types.d.ts +2 -4
  189. package/lib/esm/blue/utils.d.ts +1 -3
  190. package/lib/esm/blue/utils.js +1 -3
  191. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  192. package/lib/esm/client/morphoViemExtension.js +1 -1
  193. package/lib/esm/constants.d.ts +3 -37
  194. package/lib/esm/constants.js +3 -37
  195. package/lib/esm/entities/blue/blue.d.ts +38 -264
  196. package/lib/esm/entities/blue/blue.js +5 -206
  197. package/lib/esm/entities/index.d.ts +3 -60
  198. package/lib/esm/entities/index.js +1 -16
  199. package/lib/esm/entities/midnight/midnight.js +20 -24
  200. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  202. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  203. package/lib/esm/entities/requirements/index.d.ts +1 -0
  204. package/lib/esm/entities/requirements/index.js +1 -0
  205. package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
  206. package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
  207. package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
  208. package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
  209. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  210. package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
  211. package/lib/esm/errors.d.ts +2 -46
  212. package/lib/esm/errors.js +2 -46
  213. package/lib/esm/fetch.d.ts +1 -15
  214. package/lib/esm/fetch.js +1 -15
  215. package/lib/esm/helpers/constant.d.ts +0 -2
  216. package/lib/esm/helpers/constant.js +0 -2
  217. package/lib/esm/helpers/index.d.ts +4 -3
  218. package/lib/esm/helpers/index.js +4 -3
  219. package/lib/esm/helpers/metadata.d.ts +3 -5
  220. package/lib/esm/helpers/metadata.js +4 -6
  221. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  222. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  223. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  224. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  225. package/lib/esm/helpers/slippage.d.ts +34 -90
  226. package/lib/esm/helpers/slippage.js +52 -134
  227. package/lib/esm/helpers/utilization.d.ts +12 -10
  228. package/lib/esm/helpers/utilization.js +26 -11
  229. package/lib/esm/helpers/validate.d.ts +66 -32
  230. package/lib/esm/helpers/validate.js +83 -57
  231. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  232. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  233. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  234. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  235. package/lib/esm/types/action.d.ts +102 -68
  236. package/lib/esm/types/action.js +12 -5
  237. package/lib/esm/types/error.d.ts +332 -385
  238. package/lib/esm/types/error.js +355 -392
  239. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  240. package/lib/esm/types.d.ts +2 -18
  241. package/lib/esm/utils.d.ts +8 -35
  242. package/lib/esm/utils.js +7 -34
  243. package/package.json +7 -15
  244. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  245. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
  246. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  247. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
  248. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  249. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
  250. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  251. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  252. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  253. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  254. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  255. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  256. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  257. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  258. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  259. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
  260. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  261. package/lib/cjs/actions/signatures/index.js +0 -19
  262. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  263. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  264. package/lib/cjs/bundler/actions.d.ts +0 -797
  265. package/lib/cjs/bundler/actions.js +0 -1371
  266. package/lib/cjs/bundler/index.d.ts +0 -2
  267. package/lib/cjs/bundler/index.js +0 -18
  268. package/lib/cjs/bundler/types.d.ts +0 -235
  269. package/lib/cjs/bundler/types.js +0 -2
  270. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
  271. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
  272. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
  273. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
  274. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  275. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
  276. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  277. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
  278. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  279. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
  280. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  281. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  282. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  283. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  284. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  285. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  286. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  287. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  288. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  289. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
  290. package/lib/esm/actions/signatures/index.d.ts +0 -3
  291. package/lib/esm/actions/signatures/index.js +0 -3
  292. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  293. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
  294. package/lib/esm/bundler/actions.d.ts +0 -797
  295. package/lib/esm/bundler/actions.js +0 -1368
  296. package/lib/esm/bundler/index.d.ts +0 -2
  297. package/lib/esm/bundler/index.js +0 -2
  298. package/lib/esm/bundler/types.d.ts +0 -235
  299. package/lib/esm/bundler/types.js +0 -1
  300. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
  301. package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
  302. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
  303. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
  304. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  305. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -1,8 +1,9 @@
1
1
  import { MathLib } from "@morpho-org/blue-sdk";
2
2
  import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
- import { compactSignatureToSignature, encodeAbiParameters, isAddressEqual, maxUint256, parseCompactSignature, parseSignature, size, zeroAddress, zeroHash, } from "viem";
3
+ import { compactSignatureToSignature, encodeAbiParameters, isAddressEqual, parseCompactSignature, parseSignature, size, zeroHash, } from "viem";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
5
- import { AmbiguousRequirementSignaturesError, BundlesPermitMismatchError, BundlesRequirementSignatureMismatchError, DepositAmountMismatchError, DepositAssetMismatchError, DepositOwnerMismatchError, DepositSpenderMismatchError, InputExceedsMaxError, MixedBundlesFundingError, NegativeInputError, NonPositiveInputError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, selectRequirementSignatures, UnexpectedRequirementSignatureError, } from "../../types/index.js";
5
+ import { validateDeadline, validateReferralFee, } from "../../helpers/validate.js";
6
+ import { AmbiguousRequirementSignaturesError, BundlesPermitMismatchError, BundlesRequirementSignatureMismatchError, DepositAmountMismatchError, DepositAssetMismatchError, DepositOwnerMismatchError, DepositSpenderMismatchError, MixedBundlesFundingError, NegativeInputError, NonPositiveInputError, selectRequirementSignatures, UnexpectedRequirementSignatureError, UnsupportedRequirementSignatureError, } from "../../types/index.js";
6
7
  /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
7
8
  export const BundlesPermitKind = {
8
9
  None: 0,
@@ -27,32 +28,12 @@ const EMPTY_TOKEN_PERMIT = {
27
28
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
28
29
  */
29
30
  export const normalizeBundlesCommonParams = (params) => {
30
- if (params.deadline <= 0n) {
31
- throw new NonPositiveInputError("deadline", params.deadline);
32
- }
33
- if (params.deadline > maxUint256) {
34
- throw new InputExceedsMaxError({
35
- field: "deadline",
36
- value: params.deadline,
37
- max: maxUint256,
38
- });
39
- }
40
- const referralFeePct = params.referralFeePct ?? 0n;
41
- if (referralFeePct < 0n) {
42
- throw new NegativeInputError("referralFeePct", referralFeePct);
43
- }
44
- if (referralFeePct >= MathLib.WAD) {
45
- throw new ReferralFeePctExceededError(referralFeePct);
46
- }
47
- if (referralFeePct > 0n &&
48
- (params.referralFeeRecipient == null ||
49
- isAddressEqual(params.referralFeeRecipient, zeroAddress))) {
50
- throw new ReferralFeeRecipientMissingError();
51
- }
31
+ validateDeadline(params.deadline);
32
+ const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
52
33
  return {
53
34
  deadline: params.deadline,
54
35
  referralFeePct,
55
- referralFeeRecipient: params.referralFeeRecipient ?? zeroAddress,
36
+ referralFeeRecipient,
56
37
  };
57
38
  };
58
39
  /**
@@ -98,11 +79,12 @@ export const resolveBundlesFunding = (params) => {
98
79
  * @param params.amount - Exact pull amount in the token's smallest unit; must match both signed amount fields.
99
80
  * @param params.requirementSignature - Optional signed ERC-2612 or Permit2 SignatureTransfer requirement; omit for allowance funding.
100
81
  * @returns An empty, ERC-2612, or Permit2 SignatureTransfer token permit.
101
- * @throws {UnexpectedRequirementSignatureError} when Permit2 AllowanceTransfer is supplied.
102
82
  * @throws {DepositOwnerMismatchError} when the signature owner differs from `userAddress`.
103
83
  * @throws {DepositAssetMismatchError} when the signed token differs from `token`.
104
84
  * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
105
85
  * @throws {DepositSpenderMismatchError} when the signed spender differs from `spender`.
86
+ * @throws {UnsupportedRequirementSignatureError} when the signature's action type is neither
87
+ * "permit" nor "permit2SignatureTransfer".
106
88
  * @throws {BundlesRequirementSignatureMismatchError} when signature metadata is malformed.
107
89
  * @example
108
90
  * ```ts
@@ -122,9 +104,9 @@ export const getBundlesTokenPermit = (params) => {
122
104
  const { requirementSignature } = params;
123
105
  if (requirementSignature == null)
124
106
  return { ...EMPTY_TOKEN_PERMIT };
125
- if (requirementSignature.action.type === "permit2") {
126
- throw new UnexpectedRequirementSignatureError("permit");
127
- }
107
+ const { type } = requirementSignature.action;
108
+ if (type !== "permit" && type !== "permit2SignatureTransfer")
109
+ throw new UnsupportedRequirementSignatureError(type);
128
110
  if (!isAddressEqual(requirementSignature.args.owner, params.userAddress)) {
129
111
  throw new DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
130
112
  }
@@ -198,8 +180,17 @@ export const getBundlesTokenPermit = (params) => {
198
180
  ]),
199
181
  };
200
182
  };
201
- /** @internal Normalizes a compact or serialized ECDSA signature for bundles permit tuples. */
202
- export const normalizeBundlesSignature = (serializedSignature) => {
183
+ /**
184
+ * Normalizes a compact or serialized ECDSA signature for bundles permit tuples.
185
+ *
186
+ * @internal
187
+ *
188
+ * @param serializedSignature - Compact or serialized ECDSA signature.
189
+ * @param onInvalid - Error factory used when parsing or extracting the recovery identifier fails.
190
+ * @returns The normalized signature tuple.
191
+ * @throws {BundlesPermitMismatchError} when the signature is malformed.
192
+ */
193
+ export const normalizeBundlesSignature = (serializedSignature, onInvalid = (details) => new BundlesPermitMismatchError({ field: "signature", ...details })) => {
203
194
  let parsed;
204
195
  try {
205
196
  parsed =
@@ -208,8 +199,7 @@ export const normalizeBundlesSignature = (serializedSignature) => {
208
199
  : parseSignature(serializedSignature);
209
200
  }
210
201
  catch (cause) {
211
- throw new BundlesPermitMismatchError({
212
- field: "signature",
202
+ throw onInvalid({
213
203
  expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
214
204
  actual: serializedSignature,
215
205
  cause,
@@ -218,8 +208,7 @@ export const normalizeBundlesSignature = (serializedSignature) => {
218
208
  const normalizedV = parsed.v ??
219
209
  (parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
220
210
  if (normalizedV == null) {
221
- throw new BundlesPermitMismatchError({
222
- field: "signature",
211
+ throw onInvalid({
223
212
  expected: "a signature containing v or yParity",
224
213
  actual: serializedSignature,
225
214
  });
@@ -237,7 +226,10 @@ export const normalizeBundlesSignature = (serializedSignature) => {
237
226
  * @param params.amount - Optional exact share allowance in the vault share token's smallest unit.
238
227
  * @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
239
228
  * @returns The signed share permit or the contract's empty-permit sentinel.
240
- * @throws {BundlesPermitMismatchError} when the requirement kind, token, or signature is invalid.
229
+ * @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
230
+ * @throws {InputExceedsMaxError} when a bundle or permit deadline exceeds uint256.
231
+ * @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount or
232
+ * deadline, or signature is invalid.
241
233
  * @example
242
234
  * ```ts
243
235
  * import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
@@ -252,6 +244,12 @@ export const normalizeBundlesSignature = (serializedSignature) => {
252
244
  */
253
245
  export const getBundlesSharesPermit = (params) => {
254
246
  const { requirementSignature } = params;
247
+ // Require a positive uint256 for the fallback permit deadline.
248
+ validateDeadline(params.deadline);
249
+ if (requirementSignature != null) {
250
+ // Require a positive uint256 for the signed permit deadline too.
251
+ validateDeadline(requirementSignature.args.deadline);
252
+ }
255
253
  if (requirementSignature == null) {
256
254
  return {
257
255
  value: 0n,
@@ -301,6 +299,14 @@ export const getBundlesSharesPermit = (params) => {
301
299
  actual: String(requirementSignature.args.amount),
302
300
  });
303
301
  }
302
+ if ((params.owner != null || params.spender != null || params.amount != null) &&
303
+ requirementSignature.action.args.amount !== requirementSignature.args.amount) {
304
+ throw new BundlesPermitMismatchError({
305
+ field: "amount",
306
+ expected: String(requirementSignature.args.amount),
307
+ actual: String(requirementSignature.action.args.amount),
308
+ });
309
+ }
304
310
  if ((params.owner != null || params.spender != null || params.amount != null) &&
305
311
  requirementSignature.action.args.deadline !==
306
312
  requirementSignature.args.deadline) {
@@ -441,6 +447,55 @@ export const selectBundlesSharesRequirementSignature = (signatures, prepared) =>
441
447
  validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
442
448
  return selectedPermit;
443
449
  };
450
+ /**
451
+ * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
452
+ *
453
+ * @internal
454
+ *
455
+ * @param signatures - Signatures passed to the operation's `buildTx` function.
456
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
457
+ * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
458
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
459
+ * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
460
+ * vault's `permit` verifies at execution.
461
+ */
462
+ export const selectBundlesSharesPermitSignature = (signatures, expected) => {
463
+ const { permit } = selectRequirementSignatures(signatures, { permit: true });
464
+ if (permit == null)
465
+ return undefined;
466
+ const { action } = permit;
467
+ if (action.type !== "permit") {
468
+ throw new BundlesPermitMismatchError({
469
+ field: "type",
470
+ expected: "permit",
471
+ actual: action.type,
472
+ });
473
+ }
474
+ if (!isAddressEqual(action.args.spender, expected.spender)) {
475
+ throw new BundlesPermitMismatchError({
476
+ field: "spender",
477
+ expected: expected.spender,
478
+ actual: action.args.spender,
479
+ });
480
+ }
481
+ if (permit.args.amount !== expected.amount ||
482
+ action.args.amount !== expected.amount) {
483
+ throw new BundlesPermitMismatchError({
484
+ field: "amount",
485
+ expected: String(expected.amount),
486
+ actual: String(permit.args.amount),
487
+ });
488
+ }
489
+ if (permit.args.deadline !== expected.deadline ||
490
+ action.args.deadline !== expected.deadline) {
491
+ throw new BundlesPermitMismatchError({
492
+ field: "deadline",
493
+ expected: String(expected.deadline),
494
+ actual: String(permit.args.deadline),
495
+ });
496
+ }
497
+ return { args: permit.args, action };
498
+ };
444
499
  /** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
445
500
  export const getBundlesReferralFeeAssets = (assets, referralFeePct) => MathLib.mulDivDown(assets, referralFeePct, MathLib.WAD);
446
501
  /** @internal Finalizes a direct VaultBundlesV1 transaction with metadata and immutable action data. */
@@ -6,6 +6,5 @@ export * from "./blue/index.js";
6
6
  export * from "./bundles/index.js";
7
7
  export * from "./midnight/index.js";
8
8
  export * from "./requirements/index.js";
9
- export * from "./signatures/index.js";
10
9
  export * from "./vaultV1/index.js";
11
10
  export * from "./vaultV2/index.js";
@@ -2,6 +2,5 @@ export * from "./blue/index.js";
2
2
  export * from "./bundles/index.js";
3
3
  export * from "./midnight/index.js";
4
4
  export * from "./requirements/index.js";
5
- export * from "./signatures/index.js";
6
5
  export * from "./vaultV1/index.js";
7
6
  export * from "./vaultV2/index.js";
@@ -10,15 +10,13 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
10
10
  * - When `supportSignature` is falsy (default), returns the
11
11
  * `setAuthorization(authorized, true)` transaction the user submits before the operation.
12
12
  * - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
13
- * `Requirement`. The selected route consumes the result: Bundler3 emits
14
- * `setAuthorizationWithSig`, while BlueBundlesV1 embeds its signed-authorization struct.
13
+ * `Requirement` consumed by BlueBundlesV1.
15
14
  *
16
15
  * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
17
- * @param params.chainId - Target chain id used to resolve Morpho and the default GeneralAdapter1.
16
+ * @param params.chainId - Target chain id used to resolve Morpho and BlueBundlesV1.
18
17
  * @param params.userAddress - The user granting authorization.
19
- * @param params.authorized - Operator to authorize. Defaults to GeneralAdapter1; direct Blue
20
- * writes pass the registered BlueBundlesV1 deployment. Must be the chain's registered
21
- * GeneralAdapter1 or BlueBundlesV1 operator.
18
+ * @param params.authorized - Operator to authorize. Defaults to the chain's registered
19
+ * BlueBundlesV1 deployment and must match it.
22
20
  * @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
23
21
  * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
24
22
  * transaction so the destination route can consume the signed authorization.
@@ -26,8 +24,11 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
26
24
  * `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
27
25
  * place.
28
26
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
29
- * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
30
- * GeneralAdapter1 nor its BlueBundlesV1 operator.
27
+ * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is not the chain's
28
+ * BlueBundlesV1 operator.
29
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
30
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
31
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
31
32
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
32
33
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
33
34
  * @example
@@ -1,8 +1,9 @@
1
1
  import { getChainAddresses } from "@morpho-org/blue-sdk";
2
2
  import { blueAbi } from "@morpho-org/blue-sdk-viem";
3
- import { deepFreeze, Time } from "@morpho-org/morpho-ts";
4
- import { encodeFunctionData, isAddressEqual, maxUint256, publicActions, } from "viem";
5
- import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, UnsupportedAuthorizationOperatorError, } from "../../../types/index.js";
3
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
4
+ import { encodeFunctionData, isAddressEqual, publicActions, } from "viem";
5
+ import { validateDeadline } from "../../../helpers/validate.js";
6
+ import { ChainIdMismatchError, ExpiredDeadlineError, UnsupportedAuthorizationOperatorError, } from "../../../types/index.js";
6
7
  import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureAuthorization.js";
7
8
  /**
8
9
  * Resolves whether a supported operator needs Blue authorization for the given user, and returns
@@ -13,15 +14,13 @@ import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureA
13
14
  * - When `supportSignature` is falsy (default), returns the
14
15
  * `setAuthorization(authorized, true)` transaction the user submits before the operation.
15
16
  * - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
16
- * `Requirement`. The selected route consumes the result: Bundler3 emits
17
- * `setAuthorizationWithSig`, while BlueBundlesV1 embeds its signed-authorization struct.
17
+ * `Requirement` consumed by BlueBundlesV1.
18
18
  *
19
19
  * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
- * @param params.chainId - Target chain id used to resolve Morpho and the default GeneralAdapter1.
20
+ * @param params.chainId - Target chain id used to resolve Morpho and BlueBundlesV1.
21
21
  * @param params.userAddress - The user granting authorization.
22
- * @param params.authorized - Operator to authorize. Defaults to GeneralAdapter1; direct Blue
23
- * writes pass the registered BlueBundlesV1 deployment. Must be the chain's registered
24
- * GeneralAdapter1 or BlueBundlesV1 operator.
22
+ * @param params.authorized - Operator to authorize. Defaults to the chain's registered
23
+ * BlueBundlesV1 deployment and must match it.
25
24
  * @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
26
25
  * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
27
26
  * transaction so the destination route can consume the signed authorization.
@@ -29,8 +28,11 @@ import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureA
29
28
  * `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
30
29
  * place.
31
30
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
32
- * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
33
- * GeneralAdapter1 nor its BlueBundlesV1 operator.
31
+ * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is not the chain's
32
+ * BlueBundlesV1 operator.
33
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
34
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
35
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
34
36
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
35
37
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
36
38
  * @example
@@ -59,16 +61,13 @@ export const getBlueAuthorizationRequirement = async (params) => {
59
61
  if (viemClient.chain?.id !== chainId) {
60
62
  throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
61
63
  }
62
- const { morpho, bundler3: { generalAdapter1 }, bundles, } = getChainAddresses(chainId);
63
- const authorized = params.authorized ?? generalAdapter1;
64
- // The SDK only ever authorizes the chain's registered GeneralAdapter1 or BlueBundlesV1 operator;
64
+ const { blue: morpho } = getChainAddresses(chainId);
65
+ const blueBundlesV1 = getChainAddress(chainId, "bundles.blueBundlesV1");
66
+ const authorized = params.authorized ?? blueBundlesV1;
67
+ // The SDK only ever authorizes the chain's registered BlueBundlesV1 operator;
65
68
  // reject any other override so a misconfigured `authorized` cannot grant an arbitrary address
66
69
  // control over the user's Morpho positions.
67
- const supportedOperators = [generalAdapter1];
68
- if (bundles?.blueBundlesV1 != null) {
69
- supportedOperators.push(bundles.blueBundlesV1);
70
- }
71
- if (!supportedOperators.some((operator) => isAddressEqual(operator, authorized))) {
70
+ if (!isAddressEqual(blueBundlesV1, authorized)) {
72
71
  throw new UnsupportedAuthorizationOperatorError(authorized, chainId);
73
72
  }
74
73
  const pc = viemClient.extend(publicActions);
@@ -77,16 +76,7 @@ export const getBlueAuthorizationRequirement = async (params) => {
77
76
  // one before the RPC reads so the caller never signs an authorization that cannot be encoded
78
77
  // or would revert on-chain. An omitted deadline defaults downstream to two hours from now.
79
78
  if (params.deadline != null) {
80
- if (params.deadline <= 0n) {
81
- throw new NonPositiveInputError("deadline", params.deadline);
82
- }
83
- if (params.deadline > maxUint256) {
84
- throw new InputExceedsMaxError({
85
- field: "deadline",
86
- value: params.deadline,
87
- max: maxUint256,
88
- });
89
- }
79
+ validateDeadline(params.deadline);
90
80
  const timestamp = Time.timestamp();
91
81
  if (params.deadline <= timestamp) {
92
82
  throw new ExpiredDeadlineError(params.deadline, timestamp);
@@ -114,6 +104,7 @@ export const getBlueAuthorizationRequirement = async (params) => {
114
104
  return null;
115
105
  }
116
106
  return encodeBlueSignatureAuthorization(viemClient, {
107
+ owner: userAddress,
117
108
  authorized,
118
109
  chainId,
119
110
  nonce,
@@ -1,2 +1 @@
1
1
  export * from "./getBlueAuthorizationRequirement.js";
2
- export * from "./getUnusedPermit2Nonce.js";
@@ -1,2 +1 @@
1
1
  export * from "./getBlueAuthorizationRequirement.js";
2
- export * from "./getUnusedPermit2Nonce.js";
@@ -1,13 +1,15 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import { type Client } from "viem";
2
+ import type { Client } from "viem";
3
3
  import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeBlueSignatureAuthorization}. */
5
5
  interface EncodeBlueSignatureAuthorizationParams {
6
- /** Operator to authorize on Morpho, such as GeneralAdapter1 or BlueBundlesV1. */
6
+ /** Account granting the authorization and signing it (the Morpho `authorizer`). */
7
+ owner: Address;
8
+ /** BlueBundlesV1 operator to authorize on Morpho. */
7
9
  authorized: Address;
8
10
  /** Target chain id; must match `viemClient.chain.id`. */
9
11
  chainId: number;
10
- /** The signer's current Morpho authorization nonce. */
12
+ /** The owner's current Morpho authorization nonce. */
11
13
  nonce: bigint;
12
14
  /** Whether to grant (`true`, default) or revoke (`false`) the authorization. */
13
15
  isAuthorized?: boolean;
@@ -15,29 +17,32 @@ interface EncodeBlueSignatureAuthorizationParams {
15
17
  deadline?: bigint;
16
18
  }
17
19
  /**
18
- * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
19
- * Morpho on the signer's behalf. Bundler3 consumes the result through `setAuthorizationWithSig`;
20
- * BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
20
+ * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
21
+ * Morpho on the signer's behalf.
21
22
  *
22
23
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
23
24
  * typed data, verifies it against the connected account, and returns a deep-frozen
24
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
25
- * from `Time.timestamp()`.
25
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
26
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
27
+ * Deadline defaults to two hours from `Time.timestamp()`.
26
28
  *
27
29
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
28
30
  * @param params - Authorization encoding parameters.
29
- * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
31
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
32
+ * @param params.authorized - BlueBundlesV1 operator to authorize.
30
33
  * @param params.chainId - Target chain id.
31
- * @param params.nonce - The signer's current Morpho authorization nonce.
34
+ * @param params.nonce - The owner's current Morpho authorization nonce.
32
35
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
33
36
  * @param params.deadline - Optional signature deadline in seconds.
34
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
37
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
38
+ * `sign(client, userAddress)` produces the deep-frozen signature.
35
39
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
36
40
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
37
41
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
38
42
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
39
43
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
40
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
44
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
45
+ * client account differs from `userAddress`.
41
46
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
42
47
  * @example
43
48
  * ```ts
@@ -47,11 +52,12 @@ interface EncodeBlueSignatureAuthorizationParams {
47
52
  *
48
53
  * const client = createWalletClient({ chain: mainnet, transport: http() });
49
54
  * const requirement = await encodeBlueSignatureAuthorization(client, {
50
- * authorized: generalAdapter1,
55
+ * owner,
56
+ * authorized: blueBundlesV1,
51
57
  * chainId: 1,
52
58
  * nonce: 0n,
53
59
  * });
54
- * // requirement satisfies Requirement
60
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
55
61
  * ```
56
62
  */
57
63
  export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
@@ -1,32 +1,35 @@
1
1
  import { getAuthorizationTypedData } from "@morpho-org/blue-sdk-viem";
2
2
  import { deepFreeze, Time } from "@morpho-org/morpho-ts";
3
- import { maxUint256 } from "viem";
4
3
  import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
5
- import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
4
+ import { validateDeadline, validateUserAddress, } from "../../../helpers/validate.js";
5
+ import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/index.js";
6
6
  /**
7
- * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
8
- * Morpho on the signer's behalf. Bundler3 consumes the result through `setAuthorizationWithSig`;
9
- * BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
7
+ * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
8
+ * Morpho on the signer's behalf.
10
9
  *
11
10
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
12
11
  * typed data, verifies it against the connected account, and returns a deep-frozen
13
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
14
- * from `Time.timestamp()`.
12
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
13
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
14
+ * Deadline defaults to two hours from `Time.timestamp()`.
15
15
  *
16
16
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
17
17
  * @param params - Authorization encoding parameters.
18
- * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
18
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
19
+ * @param params.authorized - BlueBundlesV1 operator to authorize.
19
20
  * @param params.chainId - Target chain id.
20
- * @param params.nonce - The signer's current Morpho authorization nonce.
21
+ * @param params.nonce - The owner's current Morpho authorization nonce.
21
22
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
22
23
  * @param params.deadline - Optional signature deadline in seconds.
23
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
24
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
25
+ * `sign(client, userAddress)` produces the deep-frozen signature.
24
26
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
25
27
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
26
28
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
27
29
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
28
30
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
29
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
31
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
32
+ * client account differs from `userAddress`.
30
33
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
31
34
  * @example
32
35
  * ```ts
@@ -36,15 +39,16 @@ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPo
36
39
  *
37
40
  * const client = createWalletClient({ chain: mainnet, transport: http() });
38
41
  * const requirement = await encodeBlueSignatureAuthorization(client, {
39
- * authorized: generalAdapter1,
42
+ * owner,
43
+ * authorized: blueBundlesV1,
40
44
  * chainId: 1,
41
45
  * nonce: 0n,
42
46
  * });
43
- * // requirement satisfies Requirement
47
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
44
48
  * ```
45
49
  */
46
50
  export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
47
- const { authorized, chainId, nonce, isAuthorized = true } = params;
51
+ const { owner, authorized, chainId, nonce, isAuthorized = true } = params;
48
52
  if (viemClient.chain?.id !== chainId) {
49
53
  throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
50
54
  }
@@ -54,30 +58,25 @@ export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
54
58
  // `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
55
59
  // from now and is always valid.
56
60
  if (params.deadline != null) {
57
- if (params.deadline <= 0n) {
58
- throw new NonPositiveInputError("deadline", params.deadline);
59
- }
60
- if (params.deadline > maxUint256) {
61
- throw new InputExceedsMaxError({
62
- field: "deadline",
63
- value: params.deadline,
64
- max: maxUint256,
65
- });
66
- }
61
+ validateDeadline(params.deadline);
67
62
  const timestamp = Time.timestamp();
68
63
  if (params.deadline <= timestamp) {
69
64
  throw new ExpiredDeadlineError(params.deadline, timestamp);
70
65
  }
71
66
  }
72
67
  const deadline = params.deadline ?? Time.timestamp() + Time.s.from.h(2n);
68
+ const typedData = deepFreeze(getAuthorizationTypedData({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
73
69
  const action = {
74
70
  type: "authorization",
75
71
  args: { authorized, isAuthorized, deadline },
72
+ typedData,
76
73
  };
77
74
  return {
78
75
  action,
79
76
  async sign(client, userAddress) {
80
- const typedData = getAuthorizationTypedData({ authorizer: userAddress, authorized, isAuthorized, nonce, deadline }, chainId);
77
+ // The authorizer is fixed at build time (the fetched nonce is owner-specific), so a different
78
+ // signer cannot produce a valid authorization for it.
79
+ validateUserAddress(userAddress, owner);
81
80
  const signature = await signAndVerifyTypedData({
82
81
  client,
83
82
  userAddress,
@@ -85,7 +84,7 @@ export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
85
84
  });
86
85
  return deepFreeze({
87
86
  args: {
88
- owner: userAddress,
87
+ owner,
89
88
  authorized,
90
89
  isAuthorized,
91
90
  nonce,
@@ -11,12 +11,12 @@ interface EncodeErc20ApprovalParams {
11
11
  * Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
12
12
  *
13
13
  * Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
14
- * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getGeneralAdapterRequirementsPermit2}.
14
+ * `maxUint256`). Used by {@link getRequirementsApproval}.
15
15
  *
16
16
  * @param params - Encoding parameters.
17
17
  * @param params.token - ERC-20 token address to approve.
18
- * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
19
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
18
+ * @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
19
+ * MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
20
20
  * @param params.amount - Allowance amount before per-token cap.
21
21
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
22
22
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -28,7 +28,7 @@ interface EncodeErc20ApprovalParams {
28
28
  *
29
29
  * const tx = encodeErc20Approval({
30
30
  * token: USDC,
31
- * spender: generalAdapter1,
31
+ * spender: blueBundlesV1,
32
32
  * amount: 1_000_000n,
33
33
  * chainId: 1,
34
34
  * });
@@ -7,12 +7,12 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
7
7
  * Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
8
8
  *
9
9
  * Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
10
- * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getGeneralAdapterRequirementsPermit2}.
10
+ * `maxUint256`). Used by {@link getRequirementsApproval}.
11
11
  *
12
12
  * @param params - Encoding parameters.
13
13
  * @param params.token - ERC-20 token address to approve.
14
- * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
15
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
14
+ * @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
15
+ * MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
16
16
  * @param params.amount - Allowance amount before per-token cap.
17
17
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
18
18
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -24,7 +24,7 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
24
24
  *
25
25
  * const tx = encodeErc20Approval({
26
26
  * token: USDC,
27
- * spender: generalAdapter1,
27
+ * spender: blueBundlesV1,
28
28
  * amount: 1_000_000n,
29
29
  * chainId: 1,
30
30
  * });
@@ -38,7 +38,6 @@ export const encodeErc20Approval = (params) => {
38
38
  chainId,
39
39
  spender,
40
40
  allowed: [
41
- "generalAdapter1",
42
41
  "permit2",
43
42
  "midnight",
44
43
  "midnightBundles",