@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,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesRequirementSignature = exports.selectBundlesTokenRequirementSignature = exports.getBundlesSharesPermit = exports.normalizeBundlesSignature = exports.getBundlesTokenPermit = exports.resolveBundlesFunding = exports.normalizeBundlesCommonParams = exports.BundlesPermitKind = void 0;
3
+ exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesPermitSignature = exports.selectBundlesSharesRequirementSignature = exports.selectBundlesTokenRequirementSignature = exports.getBundlesSharesPermit = exports.normalizeBundlesSignature = exports.getBundlesTokenPermit = exports.resolveBundlesFunding = exports.normalizeBundlesCommonParams = exports.BundlesPermitKind = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
7
  const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
8
9
  const index_js_2 = require("../../types/index.js");
9
10
  /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
10
11
  exports.BundlesPermitKind = {
@@ -30,32 +31,12 @@ const EMPTY_TOKEN_PERMIT = {
30
31
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
31
32
  */
32
33
  const normalizeBundlesCommonParams = (params) => {
33
- if (params.deadline <= 0n) {
34
- throw new index_js_2.NonPositiveInputError("deadline", params.deadline);
35
- }
36
- if (params.deadline > viem_1.maxUint256) {
37
- throw new index_js_2.InputExceedsMaxError({
38
- field: "deadline",
39
- value: params.deadline,
40
- max: viem_1.maxUint256,
41
- });
42
- }
43
- const referralFeePct = params.referralFeePct ?? 0n;
44
- if (referralFeePct < 0n) {
45
- throw new index_js_2.NegativeInputError("referralFeePct", referralFeePct);
46
- }
47
- if (referralFeePct >= blue_sdk_1.MathLib.WAD) {
48
- throw new index_js_2.ReferralFeePctExceededError(referralFeePct);
49
- }
50
- if (referralFeePct > 0n &&
51
- (params.referralFeeRecipient == null ||
52
- (0, viem_1.isAddressEqual)(params.referralFeeRecipient, viem_1.zeroAddress))) {
53
- throw new index_js_2.ReferralFeeRecipientMissingError();
54
- }
34
+ (0, validate_js_1.validateDeadline)(params.deadline);
35
+ const { referralFeePct, referralFeeRecipient } = (0, validate_js_1.validateReferralFee)(params);
55
36
  return {
56
37
  deadline: params.deadline,
57
38
  referralFeePct,
58
- referralFeeRecipient: params.referralFeeRecipient ?? viem_1.zeroAddress,
39
+ referralFeeRecipient,
59
40
  };
60
41
  };
61
42
  exports.normalizeBundlesCommonParams = normalizeBundlesCommonParams;
@@ -103,11 +84,12 @@ exports.resolveBundlesFunding = resolveBundlesFunding;
103
84
  * @param params.amount - Exact pull amount in the token's smallest unit; must match both signed amount fields.
104
85
  * @param params.requirementSignature - Optional signed ERC-2612 or Permit2 SignatureTransfer requirement; omit for allowance funding.
105
86
  * @returns An empty, ERC-2612, or Permit2 SignatureTransfer token permit.
106
- * @throws {UnexpectedRequirementSignatureError} when Permit2 AllowanceTransfer is supplied.
107
87
  * @throws {DepositOwnerMismatchError} when the signature owner differs from `userAddress`.
108
88
  * @throws {DepositAssetMismatchError} when the signed token differs from `token`.
109
89
  * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
110
90
  * @throws {DepositSpenderMismatchError} when the signed spender differs from `spender`.
91
+ * @throws {UnsupportedRequirementSignatureError} when the signature's action type is neither
92
+ * "permit" nor "permit2SignatureTransfer".
111
93
  * @throws {BundlesRequirementSignatureMismatchError} when signature metadata is malformed.
112
94
  * @example
113
95
  * ```ts
@@ -127,9 +109,9 @@ const getBundlesTokenPermit = (params) => {
127
109
  const { requirementSignature } = params;
128
110
  if (requirementSignature == null)
129
111
  return { ...EMPTY_TOKEN_PERMIT };
130
- if (requirementSignature.action.type === "permit2") {
131
- throw new index_js_2.UnexpectedRequirementSignatureError("permit");
132
- }
112
+ const { type } = requirementSignature.action;
113
+ if (type !== "permit" && type !== "permit2SignatureTransfer")
114
+ throw new index_js_2.UnsupportedRequirementSignatureError(type);
133
115
  if (!(0, viem_1.isAddressEqual)(requirementSignature.args.owner, params.userAddress)) {
134
116
  throw new index_js_2.DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
135
117
  }
@@ -204,8 +186,17 @@ const getBundlesTokenPermit = (params) => {
204
186
  };
205
187
  };
206
188
  exports.getBundlesTokenPermit = getBundlesTokenPermit;
207
- /** @internal Normalizes a compact or serialized ECDSA signature for bundles permit tuples. */
208
- const normalizeBundlesSignature = (serializedSignature) => {
189
+ /**
190
+ * Normalizes a compact or serialized ECDSA signature for bundles permit tuples.
191
+ *
192
+ * @internal
193
+ *
194
+ * @param serializedSignature - Compact or serialized ECDSA signature.
195
+ * @param onInvalid - Error factory used when parsing or extracting the recovery identifier fails.
196
+ * @returns The normalized signature tuple.
197
+ * @throws {BundlesPermitMismatchError} when the signature is malformed.
198
+ */
199
+ const normalizeBundlesSignature = (serializedSignature, onInvalid = (details) => new index_js_2.BundlesPermitMismatchError({ field: "signature", ...details })) => {
209
200
  let parsed;
210
201
  try {
211
202
  parsed =
@@ -214,8 +205,7 @@ const normalizeBundlesSignature = (serializedSignature) => {
214
205
  : (0, viem_1.parseSignature)(serializedSignature);
215
206
  }
216
207
  catch (cause) {
217
- throw new index_js_2.BundlesPermitMismatchError({
218
- field: "signature",
208
+ throw onInvalid({
219
209
  expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
220
210
  actual: serializedSignature,
221
211
  cause,
@@ -224,8 +214,7 @@ const normalizeBundlesSignature = (serializedSignature) => {
224
214
  const normalizedV = parsed.v ??
225
215
  (parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
226
216
  if (normalizedV == null) {
227
- throw new index_js_2.BundlesPermitMismatchError({
228
- field: "signature",
217
+ throw onInvalid({
229
218
  expected: "a signature containing v or yParity",
230
219
  actual: serializedSignature,
231
220
  });
@@ -244,7 +233,10 @@ exports.normalizeBundlesSignature = normalizeBundlesSignature;
244
233
  * @param params.amount - Optional exact share allowance in the vault share token's smallest unit.
245
234
  * @param params.requirementSignature - Optional signed ERC-2612 share requirement; omit for the empty-permit sentinel.
246
235
  * @returns The signed share permit or the contract's empty-permit sentinel.
247
- * @throws {BundlesPermitMismatchError} when the requirement kind, token, or signature is invalid.
236
+ * @throws {NonPositiveInputError} when a bundle or permit deadline is not positive.
237
+ * @throws {InputExceedsMaxError} when a bundle or permit deadline exceeds uint256.
238
+ * @throws {BundlesPermitMismatchError} when the requirement kind, token, owner, spender, amount or
239
+ * deadline, or signature is invalid.
248
240
  * @example
249
241
  * ```ts
250
242
  * import { getBundlesSharesPermit } from "@morpho-org/morpho-sdk";
@@ -259,6 +251,12 @@ exports.normalizeBundlesSignature = normalizeBundlesSignature;
259
251
  */
260
252
  const getBundlesSharesPermit = (params) => {
261
253
  const { requirementSignature } = params;
254
+ // Require a positive uint256 for the fallback permit deadline.
255
+ (0, validate_js_1.validateDeadline)(params.deadline);
256
+ if (requirementSignature != null) {
257
+ // Require a positive uint256 for the signed permit deadline too.
258
+ (0, validate_js_1.validateDeadline)(requirementSignature.args.deadline);
259
+ }
262
260
  if (requirementSignature == null) {
263
261
  return {
264
262
  value: 0n,
@@ -308,6 +306,14 @@ const getBundlesSharesPermit = (params) => {
308
306
  actual: String(requirementSignature.args.amount),
309
307
  });
310
308
  }
309
+ if ((params.owner != null || params.spender != null || params.amount != null) &&
310
+ requirementSignature.action.args.amount !== requirementSignature.args.amount) {
311
+ throw new index_js_2.BundlesPermitMismatchError({
312
+ field: "amount",
313
+ expected: String(requirementSignature.args.amount),
314
+ actual: String(requirementSignature.action.args.amount),
315
+ });
316
+ }
311
317
  if ((params.owner != null || params.spender != null || params.amount != null) &&
312
318
  requirementSignature.action.args.deadline !==
313
319
  requirementSignature.args.deadline) {
@@ -451,6 +457,56 @@ const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
451
457
  return selectedPermit;
452
458
  };
453
459
  exports.selectBundlesSharesRequirementSignature = selectBundlesSharesRequirementSignature;
460
+ /**
461
+ * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
462
+ *
463
+ * @internal
464
+ *
465
+ * @param signatures - Signatures passed to the operation's `buildTx` function.
466
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
467
+ * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
468
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
469
+ * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
470
+ * vault's `permit` verifies at execution.
471
+ */
472
+ const selectBundlesSharesPermitSignature = (signatures, expected) => {
473
+ const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
474
+ if (permit == null)
475
+ return undefined;
476
+ const { action } = permit;
477
+ if (action.type !== "permit") {
478
+ throw new index_js_2.BundlesPermitMismatchError({
479
+ field: "type",
480
+ expected: "permit",
481
+ actual: action.type,
482
+ });
483
+ }
484
+ if (!(0, viem_1.isAddressEqual)(action.args.spender, expected.spender)) {
485
+ throw new index_js_2.BundlesPermitMismatchError({
486
+ field: "spender",
487
+ expected: expected.spender,
488
+ actual: action.args.spender,
489
+ });
490
+ }
491
+ if (permit.args.amount !== expected.amount ||
492
+ action.args.amount !== expected.amount) {
493
+ throw new index_js_2.BundlesPermitMismatchError({
494
+ field: "amount",
495
+ expected: String(expected.amount),
496
+ actual: String(permit.args.amount),
497
+ });
498
+ }
499
+ if (permit.args.deadline !== expected.deadline ||
500
+ action.args.deadline !== expected.deadline) {
501
+ throw new index_js_2.BundlesPermitMismatchError({
502
+ field: "deadline",
503
+ expected: String(expected.deadline),
504
+ actual: String(permit.args.deadline),
505
+ });
506
+ }
507
+ return { args: permit.args, action };
508
+ };
509
+ exports.selectBundlesSharesPermitSignature = selectBundlesSharesPermitSignature;
454
510
  /** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
455
511
  const getBundlesReferralFeeAssets = (assets, referralFeePct) => blue_sdk_1.MathLib.mulDivDown(assets, referralFeePct, blue_sdk_1.MathLib.WAD);
456
512
  exports.getBundlesReferralFeeAssets = getBundlesReferralFeeAssets;
@@ -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";
@@ -18,6 +18,5 @@ __exportStar(require("./blue/index.js"), exports);
18
18
  __exportStar(require("./bundles/index.js"), exports);
19
19
  __exportStar(require("./midnight/index.js"), exports);
20
20
  __exportStar(require("./requirements/index.js"), exports);
21
- __exportStar(require("./signatures/index.js"), exports);
22
21
  __exportStar(require("./vaultV1/index.js"), exports);
23
22
  __exportStar(require("./vaultV2/index.js"), exports);
@@ -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
@@ -5,6 +5,7 @@ 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
+ const validate_js_1 = require("../../../helpers/validate.js");
8
9
  const index_js_1 = require("../../../types/index.js");
9
10
  const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSignatureAuthorization.js");
10
11
  /**
@@ -16,15 +17,13 @@ const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSigna
16
17
  * - When `supportSignature` is falsy (default), returns the
17
18
  * `setAuthorization(authorized, true)` transaction the user submits before the operation.
18
19
  * - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
19
- * `Requirement`. The selected route consumes the result: Bundler3 emits
20
- * `setAuthorizationWithSig`, while BlueBundlesV1 embeds its signed-authorization struct.
20
+ * `Requirement` consumed by BlueBundlesV1.
21
21
  *
22
22
  * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
23
- * @param params.chainId - Target chain id used to resolve Morpho and the default GeneralAdapter1.
23
+ * @param params.chainId - Target chain id used to resolve Morpho and BlueBundlesV1.
24
24
  * @param params.userAddress - The user granting authorization.
25
- * @param params.authorized - Operator to authorize. Defaults to GeneralAdapter1; direct Blue
26
- * writes pass the registered BlueBundlesV1 deployment. Must be the chain's registered
27
- * GeneralAdapter1 or BlueBundlesV1 operator.
25
+ * @param params.authorized - Operator to authorize. Defaults to the chain's registered
26
+ * BlueBundlesV1 deployment and must match it.
28
27
  * @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
29
28
  * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
30
29
  * transaction so the destination route can consume the signed authorization.
@@ -32,8 +31,11 @@ const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSigna
32
31
  * `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
33
32
  * place.
34
33
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
- * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
36
- * GeneralAdapter1 nor its BlueBundlesV1 operator.
34
+ * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is not the chain's
35
+ * BlueBundlesV1 operator.
36
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
37
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
38
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
37
39
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
40
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
39
41
  * @example
@@ -62,16 +64,13 @@ const getBlueAuthorizationRequirement = async (params) => {
62
64
  if (viemClient.chain?.id !== chainId) {
63
65
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
64
66
  }
65
- const { morpho, bundler3: { generalAdapter1 }, bundles, } = (0, blue_sdk_1.getChainAddresses)(chainId);
66
- const authorized = params.authorized ?? generalAdapter1;
67
- // The SDK only ever authorizes the chain's registered GeneralAdapter1 or BlueBundlesV1 operator;
67
+ const { blue: morpho } = (0, blue_sdk_1.getChainAddresses)(chainId);
68
+ const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.blueBundlesV1");
69
+ const authorized = params.authorized ?? blueBundlesV1;
70
+ // The SDK only ever authorizes the chain's registered BlueBundlesV1 operator;
68
71
  // reject any other override so a misconfigured `authorized` cannot grant an arbitrary address
69
72
  // control over the user's Morpho positions.
70
- const supportedOperators = [generalAdapter1];
71
- if (bundles?.blueBundlesV1 != null) {
72
- supportedOperators.push(bundles.blueBundlesV1);
73
- }
74
- if (!supportedOperators.some((operator) => (0, viem_1.isAddressEqual)(operator, authorized))) {
73
+ if (!(0, viem_1.isAddressEqual)(blueBundlesV1, authorized)) {
75
74
  throw new index_js_1.UnsupportedAuthorizationOperatorError(authorized, chainId);
76
75
  }
77
76
  const pc = viemClient.extend(viem_1.publicActions);
@@ -80,16 +79,7 @@ const getBlueAuthorizationRequirement = async (params) => {
80
79
  // one before the RPC reads so the caller never signs an authorization that cannot be encoded
81
80
  // or would revert on-chain. An omitted deadline defaults downstream to two hours from now.
82
81
  if (params.deadline != null) {
83
- if (params.deadline <= 0n) {
84
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
85
- }
86
- if (params.deadline > viem_1.maxUint256) {
87
- throw new index_js_1.InputExceedsMaxError({
88
- field: "deadline",
89
- value: params.deadline,
90
- max: viem_1.maxUint256,
91
- });
92
- }
82
+ (0, validate_js_1.validateDeadline)(params.deadline);
93
83
  const timestamp = morpho_ts_1.Time.timestamp();
94
84
  if (params.deadline <= timestamp) {
95
85
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
@@ -117,6 +107,7 @@ const getBlueAuthorizationRequirement = async (params) => {
117
107
  return null;
118
108
  }
119
109
  return (0, encodeBlueSignatureAuthorization_js_1.encodeBlueSignatureAuthorization)(viemClient, {
110
+ owner: userAddress,
120
111
  authorized,
121
112
  chainId,
122
113
  nonce,
@@ -1,2 +1 @@
1
1
  export * from "./getBlueAuthorizationRequirement.js";
2
- export * from "./getUnusedPermit2Nonce.js";
@@ -15,4 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
18
- __exportStar(require("./getUnusedPermit2Nonce.js"), exports);
@@ -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>>;
@@ -3,33 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeBlueSignatureAuthorization = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
6
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
+ const validate_js_1 = require("../../../helpers/validate.js");
8
8
  const index_js_1 = require("../../../types/index.js");
9
9
  /**
10
- * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
11
- * Morpho on the signer's behalf. Bundler3 consumes the result through `setAuthorizationWithSig`;
12
- * BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
10
+ * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
11
+ * Morpho on the signer's behalf.
13
12
  *
14
13
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
15
14
  * typed data, verifies it against the connected account, and returns a deep-frozen
16
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
17
- * from `Time.timestamp()`.
15
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
16
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
17
+ * Deadline defaults to two hours from `Time.timestamp()`.
18
18
  *
19
19
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
20
  * @param params - Authorization encoding parameters.
21
- * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
21
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
22
+ * @param params.authorized - BlueBundlesV1 operator to authorize.
22
23
  * @param params.chainId - Target chain id.
23
- * @param params.nonce - The signer's current Morpho authorization nonce.
24
+ * @param params.nonce - The owner's current Morpho authorization nonce.
24
25
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
25
26
  * @param params.deadline - Optional signature deadline in seconds.
26
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
27
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
28
+ * `sign(client, userAddress)` produces the deep-frozen signature.
27
29
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
28
30
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
29
31
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
30
32
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
31
33
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
32
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
34
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
35
+ * client account differs from `userAddress`.
33
36
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
34
37
  * @example
35
38
  * ```ts
@@ -39,15 +42,16 @@ const index_js_1 = require("../../../types/index.js");
39
42
  *
40
43
  * const client = createWalletClient({ chain: mainnet, transport: http() });
41
44
  * const requirement = await encodeBlueSignatureAuthorization(client, {
42
- * authorized: generalAdapter1,
45
+ * owner,
46
+ * authorized: blueBundlesV1,
43
47
  * chainId: 1,
44
48
  * nonce: 0n,
45
49
  * });
46
- * // requirement satisfies Requirement
50
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
47
51
  * ```
48
52
  */
49
53
  const encodeBlueSignatureAuthorization = async (viemClient, params) => {
50
- const { authorized, chainId, nonce, isAuthorized = true } = params;
54
+ const { owner, authorized, chainId, nonce, isAuthorized = true } = params;
51
55
  if (viemClient.chain?.id !== chainId) {
52
56
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
53
57
  }
@@ -57,30 +61,25 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
57
61
  // `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
58
62
  // from now and is always valid.
59
63
  if (params.deadline != null) {
60
- if (params.deadline <= 0n) {
61
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
62
- }
63
- if (params.deadline > viem_1.maxUint256) {
64
- throw new index_js_1.InputExceedsMaxError({
65
- field: "deadline",
66
- value: params.deadline,
67
- max: viem_1.maxUint256,
68
- });
69
- }
64
+ (0, validate_js_1.validateDeadline)(params.deadline);
70
65
  const timestamp = morpho_ts_1.Time.timestamp();
71
66
  if (params.deadline <= timestamp) {
72
67
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
73
68
  }
74
69
  }
75
70
  const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
71
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
76
72
  const action = {
77
73
  type: "authorization",
78
74
  args: { authorized, isAuthorized, deadline },
75
+ typedData,
79
76
  };
80
77
  return {
81
78
  action,
82
79
  async sign(client, userAddress) {
83
- const typedData = (0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: userAddress, authorized, isAuthorized, nonce, deadline }, chainId);
80
+ // The authorizer is fixed at build time (the fetched nonce is owner-specific), so a different
81
+ // signer cannot produce a valid authorization for it.
82
+ (0, validate_js_1.validateUserAddress)(userAddress, owner);
84
83
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
85
84
  client,
86
85
  userAddress,
@@ -88,7 +87,7 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
88
87
  });
89
88
  return (0, morpho_ts_1.deepFreeze)({
90
89
  args: {
91
- owner: userAddress,
90
+ owner,
92
91
  authorized,
93
92
  isAuthorized,
94
93
  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
  * });
@@ -10,12 +10,12 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
10
10
  * Encodes a deep-frozen ERC-20 approval transaction for a supported SDK spender.
11
11
  *
12
12
  * Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
13
- * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getGeneralAdapterRequirementsPermit2}.
13
+ * `maxUint256`). Used by {@link getRequirementsApproval}.
14
14
  *
15
15
  * @param params - Encoding parameters.
16
16
  * @param params.token - ERC-20 token address to approve.
17
- * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
18
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
17
+ * @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
18
+ * MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
19
19
  * @param params.amount - Allowance amount before per-token cap.
20
20
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
21
21
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -27,7 +27,7 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
27
27
  *
28
28
  * const tx = encodeErc20Approval({
29
29
  * token: USDC,
30
- * spender: generalAdapter1,
30
+ * spender: blueBundlesV1,
31
31
  * amount: 1_000_000n,
32
32
  * chainId: 1,
33
33
  * });
@@ -41,7 +41,6 @@ const encodeErc20Approval = (params) => {
41
41
  chainId,
42
42
  spender,
43
43
  allowed: [
44
- "generalAdapter1",
45
44
  "permit2",
46
45
  "midnight",
47
46
  "midnightBundles",