@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,9 +1,11 @@
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 Erc2612RequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeErc20Permit}. */
5
5
  interface EncodeErc20PermitParams {
6
6
  token: Address;
7
+ /** Account that owns the tokens and signs the permit. */
8
+ owner: Address;
7
9
  spender: Address;
8
10
  amount: bigint;
9
11
  chainId: number;
@@ -17,30 +19,34 @@ interface EncodeErc20PermitParams {
17
19
  *
18
20
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
19
21
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
20
- * the selected transaction route can consume. Deadline defaults to two hours from
21
- * `Time.timestamp()`.
22
+ * the selected transaction route can consume. The requirement's `action.typedData` holds that
23
+ * EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
24
+ * hours from `Time.timestamp()`.
22
25
  *
23
26
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
24
27
  * @param params - Permit encoding parameters.
25
28
  * @param params.token - ERC-20 token address (must support EIP-2612).
26
- * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
27
- * VaultBundlesV1, or BlueBundlesV1 for the chain.
29
+ * @param params.owner - Account that owns the tokens and signs the permit.
30
+ * @param params.spender - Permit spender. Must be MidnightBundles, VaultBundlesV1, or
31
+ * BlueBundlesV1 for the chain.
28
32
  * @param params.amount - Permit allowance amount.
29
33
  * @param params.chainId - Target chain id.
30
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
34
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
31
35
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
32
36
  * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
33
- * @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.
34
39
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
40
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
36
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
37
- * MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
41
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not MidnightBundles,
42
+ * VaultBundlesV1, or BlueBundlesV1 for `chainId`.
38
43
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
39
44
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
40
45
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
41
46
  * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
42
47
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
43
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
48
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
49
+ * client account differs from `userAddress`.
44
50
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
45
51
  * @example
46
52
  * ```ts
@@ -51,12 +57,15 @@ interface EncodeErc20PermitParams {
51
57
  * const client = createWalletClient({ chain: mainnet, transport: http() });
52
58
  * const requirement = await encodeErc20Permit(client, {
53
59
  * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
54
- * spender: generalAdapter1,
60
+ * owner,
61
+ * spender: blueBundlesV1,
55
62
  * amount: 1_000_000n,
56
63
  * chainId: 1,
57
64
  * nonce: 0n,
58
65
  * });
59
- * // requirement satisfies Requirement
66
+ * // Inspect the EIP-712 payload, then sign via the requirement:
67
+ * const typedData = requirement.action.typedData;
68
+ * const signed = await requirement.sign(client, owner);
60
69
  * ```
61
70
  */
62
71
  export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;
@@ -1,39 +1,43 @@
1
1
  import { fetchToken, getPermitTypedData } 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";
4
+ import { validateDeadline, validateUserAddress, } from "../../../helpers/validate.js";
5
5
  import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
6
- import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
6
+ import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/index.js";
7
7
  /**
8
8
  * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
9
9
  * `amount` of `token`.
10
10
  *
11
11
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
12
12
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
13
- * the selected transaction route can consume. Deadline defaults to two hours from
14
- * `Time.timestamp()`.
13
+ * the selected transaction route can consume. The requirement's `action.typedData` holds that
14
+ * EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
15
+ * hours from `Time.timestamp()`.
15
16
  *
16
17
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
17
18
  * @param params - Permit encoding parameters.
18
19
  * @param params.token - ERC-20 token address (must support EIP-2612).
19
- * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
20
- * VaultBundlesV1, or BlueBundlesV1 for the chain.
20
+ * @param params.owner - Account that owns the tokens and signs the permit.
21
+ * @param params.spender - Permit spender. Must be MidnightBundles, VaultBundlesV1, or
22
+ * BlueBundlesV1 for the chain.
21
23
  * @param params.amount - Permit allowance amount.
22
24
  * @param params.chainId - Target chain id.
23
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
25
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
24
26
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
25
27
  * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
26
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
28
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
29
+ * `sign(client, userAddress)` produces the deep-frozen signature.
27
30
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
28
31
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
29
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
30
- * MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
32
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not MidnightBundles,
33
+ * VaultBundlesV1, or BlueBundlesV1 for `chainId`.
31
34
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
32
35
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
33
36
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
34
37
  * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
35
38
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
36
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
39
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
40
+ * client account differs from `userAddress`.
37
41
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
38
42
  * @example
39
43
  * ```ts
@@ -44,44 +48,33 @@ import { ChainIdMismatchError, ExpiredDeadlineError, InputExceedsMaxError, NonPo
44
48
  * const client = createWalletClient({ chain: mainnet, transport: http() });
45
49
  * const requirement = await encodeErc20Permit(client, {
46
50
  * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
47
- * spender: generalAdapter1,
51
+ * owner,
52
+ * spender: blueBundlesV1,
48
53
  * amount: 1_000_000n,
49
54
  * chainId: 1,
50
55
  * nonce: 0n,
51
56
  * });
52
- * // requirement satisfies Requirement
57
+ * // Inspect the EIP-712 payload, then sign via the requirement:
58
+ * const typedData = requirement.action.typedData;
59
+ * const signed = await requirement.sign(client, owner);
53
60
  * ```
54
61
  */
55
62
  export const encodeErc20Permit = async (viemClient, params) => {
56
- const { token, spender, amount, chainId, nonce, supportDeployless } = params;
63
+ const { token, owner, spender, amount, chainId, nonce, supportDeployless } = params;
57
64
  if (viemClient.chain?.id !== chainId) {
58
65
  throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
59
66
  }
60
67
  validateRequirementSpender({
61
68
  chainId,
62
69
  spender,
63
- allowed: [
64
- "generalAdapter1",
65
- "midnightBundles",
66
- "vaultBundlesV1",
67
- "blueBundlesV1",
68
- ],
70
+ allowed: ["midnightBundles", "vaultBundlesV1", "blueBundlesV1"],
69
71
  });
70
72
  const now = Time.timestamp();
71
73
  // Validate an explicit deadline before the token-metadata read: this exported encoder can be
72
74
  // called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
73
75
  // deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
74
76
  if (params.deadline != null) {
75
- if (params.deadline <= 0n) {
76
- throw new NonPositiveInputError("deadline", params.deadline);
77
- }
78
- if (params.deadline > maxUint256) {
79
- throw new InputExceedsMaxError({
80
- field: "deadline",
81
- value: params.deadline,
82
- max: maxUint256,
83
- });
84
- }
77
+ validateDeadline(params.deadline);
85
78
  if (params.deadline <= now) {
86
79
  throw new ExpiredDeadlineError(params.deadline, now);
87
80
  }
@@ -90,6 +83,18 @@ export const encodeErc20Permit = async (viemClient, params) => {
90
83
  const tokenData = await fetchToken(token, viemClient, {
91
84
  deployless: supportDeployless,
92
85
  });
86
+ const permitTypedData = getPermitTypedData({
87
+ erc20: tokenData,
88
+ owner,
89
+ spender,
90
+ allowance: amount,
91
+ nonce,
92
+ deadline,
93
+ }, chainId);
94
+ const typedData = deepFreeze({
95
+ ...permitTypedData,
96
+ domain: { ...permitTypedData.domain },
97
+ });
93
98
  const action = {
94
99
  type: "permit",
95
100
  args: {
@@ -98,18 +103,14 @@ export const encodeErc20Permit = async (viemClient, params) => {
98
103
  deadline,
99
104
  nonce,
100
105
  },
106
+ typedData,
101
107
  };
102
108
  return {
103
109
  action,
104
110
  async sign(client, userAddress) {
105
- const typedData = getPermitTypedData({
106
- erc20: tokenData,
107
- owner: userAddress,
108
- spender,
109
- allowance: amount,
110
- nonce,
111
- deadline,
112
- }, chainId);
111
+ // The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
112
+ // different signer cannot produce a valid signature for it.
113
+ validateUserAddress(userAddress, owner);
113
114
  const signature = await signAndVerifyTypedData({
114
115
  client,
115
116
  userAddress,
@@ -117,7 +118,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
117
118
  });
118
119
  return deepFreeze({
119
120
  args: {
120
- owner: userAddress,
121
+ owner,
121
122
  signature,
122
123
  deadline,
123
124
  amount,
@@ -19,7 +19,8 @@ export interface EncodeErc20Permit2SignatureTransferParams {
19
19
  * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
20
20
  *
21
21
  * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
22
- * it has no managed allowance expiration.
22
+ * it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
23
+ * payload so it can be inspected or displayed before signing.
23
24
  *
24
25
  * @param params - SignatureTransfer parameters.
25
26
  * @param params.token - ERC-20 token pulled through Permit2.
@@ -28,7 +29,8 @@ export interface EncodeErc20Permit2SignatureTransferParams {
28
29
  * @param params.chainId - Target chain id.
29
30
  * @param params.nonce - Unused Permit2 unordered nonce.
30
31
  * @param params.deadline - Signature expiration timestamp in seconds.
31
- * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
32
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
33
+ * `sign(client, userAddress)` returns a deep-frozen signature result.
32
34
  * @throws {NegativeInputError} when `amount` or `nonce` is negative.
33
35
  * @throws {NonPositiveInputError} when `deadline` is not positive.
34
36
  * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
@@ -9,7 +9,8 @@ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } fr
9
9
  * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
10
10
  *
11
11
  * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
12
- * it has no managed allowance expiration.
12
+ * it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
13
+ * payload so it can be inspected or displayed before signing.
13
14
  *
14
15
  * @param params - SignatureTransfer parameters.
15
16
  * @param params.token - ERC-20 token pulled through Permit2.
@@ -18,7 +19,8 @@ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } fr
18
19
  * @param params.chainId - Target chain id.
19
20
  * @param params.nonce - Unused Permit2 unordered nonce.
20
21
  * @param params.deadline - Signature expiration timestamp in seconds.
21
- * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
22
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
23
+ * `sign(client, userAddress)` returns a deep-frozen signature result.
22
24
  * @throws {NegativeInputError} when `amount` or `nonce` is negative.
23
25
  * @throws {NonPositiveInputError} when `deadline` is not positive.
24
26
  * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
@@ -84,20 +86,23 @@ export const encodeErc20Permit2SignatureTransfer = (params) => {
84
86
  // sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
85
87
  // this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
86
88
  getChainAddress(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
89
+ // Permit2 SignatureTransfer signs over `PermitTransferFrom` (permitted, spender, nonce,
90
+ // deadline), which does not include the owner, so the payload is fully determined at build time.
91
+ const typedData = deepFreeze(getPermit2TransferFromTypedData({
92
+ erc20: token,
93
+ allowance: amount,
94
+ spender,
95
+ nonce,
96
+ deadline,
97
+ }, chainId));
87
98
  const action = {
88
99
  type: "permit2SignatureTransfer",
89
100
  args: { spender, amount, nonce, deadline },
101
+ typedData,
90
102
  };
91
103
  return {
92
104
  action,
93
105
  async sign(client, userAddress) {
94
- const typedData = getPermit2TransferFromTypedData({
95
- erc20: token,
96
- allowance: amount,
97
- spender,
98
- nonce,
99
- deadline,
100
- }, chainId);
101
106
  const signature = await signAndVerifyTypedData({
102
107
  client,
103
108
  userAddress,
@@ -23,7 +23,8 @@ export interface EncodeVaultSharesPermitParams {
23
23
  * Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
24
24
  *
25
25
  * Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
26
- * only `chainId` and `verifyingContract`.
26
+ * only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
27
+ * payload so it can be inspected or displayed before signing.
27
28
  *
28
29
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
29
30
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
@@ -33,16 +34,18 @@ export interface EncodeVaultSharesPermitParams {
33
34
  * @param params.nonce - Current vault permit nonce for the owner.
34
35
  * @param params.amount - Vault-share allowance to authorize.
35
36
  * @param params.deadline - Shared permit and bundle deadline.
36
- * @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
37
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
38
+ * can be embedded in fixed vault-bundles calldata.
37
39
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
38
40
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
39
41
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
40
- * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
42
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
43
+ * wallet account differs from `userAddress`.
41
44
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
42
45
  * @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
43
- * @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
44
- * @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
45
- * @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
46
+ * @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
47
+ * @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
48
+ * @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
46
49
  * @example
47
50
  * ```ts
48
51
  * import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
@@ -9,7 +9,8 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
9
9
  * Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
10
10
  *
11
11
  * Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
12
- * only `chainId` and `verifyingContract`.
12
+ * only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
13
+ * payload so it can be inspected or displayed before signing.
13
14
  *
14
15
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
15
16
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
@@ -19,16 +20,18 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
19
20
  * @param params.nonce - Current vault permit nonce for the owner.
20
21
  * @param params.amount - Vault-share allowance to authorize.
21
22
  * @param params.deadline - Shared permit and bundle deadline.
22
- * @returns A requirement whose `sign()` result can be embedded in fixed vault-bundles calldata.
23
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
24
+ * can be embedded in fixed vault-bundles calldata.
23
25
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
24
26
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
25
27
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
26
- * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
28
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
29
+ * wallet account differs from `userAddress`.
27
30
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
28
31
  * @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
29
- * @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
30
- * @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
31
- * @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
32
+ * @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
33
+ * @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
34
+ * @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
32
35
  * @example
33
36
  * ```ts
34
37
  * import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
@@ -82,6 +85,18 @@ export const encodeVaultSharesPermit = (params) => {
82
85
  spender,
83
86
  allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
84
87
  });
88
+ const permitTypedData = getPermitTypedData({
89
+ owner,
90
+ spender,
91
+ allowance: amount,
92
+ nonce,
93
+ deadline,
94
+ erc20: vault,
95
+ }, chainId);
96
+ const typedData = deepFreeze({
97
+ ...permitTypedData,
98
+ domain: { ...permitTypedData.domain },
99
+ });
85
100
  const action = {
86
101
  type: "permit",
87
102
  args: {
@@ -90,23 +105,13 @@ export const encodeVaultSharesPermit = (params) => {
90
105
  deadline,
91
106
  nonce,
92
107
  },
108
+ typedData,
93
109
  };
94
110
  return {
95
111
  action,
96
112
  async sign(client, userAddress) {
97
113
  // The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
98
114
  validateUserAddress(userAddress, owner);
99
- const permit = {
100
- owner,
101
- spender,
102
- allowance: amount,
103
- nonce,
104
- deadline,
105
- };
106
- const typedData = getPermitTypedData({
107
- ...permit,
108
- erc20: vault,
109
- }, chainId);
110
115
  const signature = await signAndVerifyTypedData({
111
116
  client,
112
117
  userAddress,
@@ -1,6 +1,5 @@
1
1
  export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
- export * from "./encodeErc20Permit2Approve.js";
5
4
  export * from "./encodeErc20Permit2SignatureTransfer.js";
6
5
  export * from "./encodeVaultSharesPermit.js";
@@ -1,6 +1,5 @@
1
1
  export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
- export * from "./encodeErc20Permit2Approve.js";
5
4
  export * from "./encodeErc20Permit2SignatureTransfer.js";
6
5
  export * from "./encodeVaultSharesPermit.js";
@@ -5,8 +5,8 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
5
5
  * allowance.
6
6
  *
7
7
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
8
- * GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
9
- * BlueBundlesV1 addresses when configured.
8
+ * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
9
+ * addresses when configured.
10
10
  *
11
11
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
12
12
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -19,9 +19,8 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
19
19
  * @param params.args.spendAmount - The amount the bundle will actually pull.
20
20
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
21
21
  * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
22
- * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
23
- * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
24
- * `chainId`.
22
+ * @param params.args.spender - Address that will be granted the approval. Must be Permit2,
23
+ * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
25
24
  * @param params.allowances - The user's current allowance of `address` for `spender`.
26
25
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
27
26
  * followed by the new approval. Empty when no approval is needed.
@@ -35,7 +34,7 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
35
34
  * const txs = getRequirementsApproval({
36
35
  * address: USDC,
37
36
  * chainId: 1,
38
- * args: { approvalAmount: 1_000_000n, spendAmount: 1_000_000n, spender: generalAdapter1 },
37
+ * args: { approvalAmount: 1_000_000n, spendAmount: 1_000_000n, spender: blueBundlesV1 },
39
38
  * allowances: 0n,
40
39
  * });
41
40
  * // txs satisfies Readonly<Transaction<ERC20ApprovalAction>>[]
@@ -7,8 +7,8 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
7
7
  * allowance.
8
8
  *
9
9
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
10
- * GeneralAdapter1, Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and
11
- * BlueBundlesV1 addresses when configured.
10
+ * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
11
+ * addresses when configured.
12
12
  *
13
13
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
14
14
  * `APPROVE_ONLY_ONCE_TOKENS` (e.g. USDT) and the existing allowance is non-zero, prepends a
@@ -21,9 +21,8 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
21
21
  * @param params.args.spendAmount - The amount the bundle will actually pull.
22
22
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
23
23
  * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
24
- * @param params.args.spender - Address that will be granted the approval. Must be GeneralAdapter1,
25
- * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
26
- * `chainId`.
24
+ * @param params.args.spender - Address that will be granted the approval. Must be Permit2,
25
+ * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
27
26
  * @param params.allowances - The user's current allowance of `address` for `spender`.
28
27
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
29
28
  * followed by the new approval. Empty when no approval is needed.
@@ -37,7 +36,7 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
37
36
  * const txs = getRequirementsApproval({
38
37
  * address: USDC,
39
38
  * chainId: 1,
40
- * args: { approvalAmount: 1_000_000n, spendAmount: 1_000_000n, spender: generalAdapter1 },
39
+ * args: { approvalAmount: 1_000_000n, spendAmount: 1_000_000n, spender: blueBundlesV1 },
41
40
  * allowances: 0n,
42
41
  * });
43
42
  * // txs satisfies Readonly<Transaction<ERC20ApprovalAction>>[]
@@ -1,5 +1,4 @@
1
1
  export * from "./blue/index.js";
2
2
  export * from "./encode/index.js";
3
- export * from "./generalAdapter/index.js";
4
3
  export * from "./getRequirementsApproval.js";
5
4
  export * from "./midnight/index.js";
@@ -1,5 +1,4 @@
1
1
  export * from "./blue/index.js";
2
2
  export * from "./encode/index.js";
3
- export * from "./generalAdapter/index.js";
4
3
  export * from "./getRequirementsApproval.js";
5
4
  export * from "./midnight/index.js";
@@ -52,8 +52,7 @@ export interface VaultV1DepositParams {
52
52
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
53
53
  * {@link InputExceedsMaxError}, so either class catches it.
54
54
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
55
- * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit or a
56
- * Permit2 AllowanceTransfer signature is supplied.
55
+ * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit.
57
56
  * @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
58
57
  * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
59
58
  * @throws {DepositAssetMismatchError} when the signed asset differs from the vault asset.
@@ -38,8 +38,7 @@ import { finalizeVaultBundlesV1Transaction, getBundlesReferralFeeAssets, getBund
38
38
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
39
39
  * {@link InputExceedsMaxError}, so either class catches it.
40
40
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
41
- * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit or a
42
- * Permit2 AllowanceTransfer signature is supplied.
41
+ * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit.
43
42
  * @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
44
43
  * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
45
44
  * @throws {DepositAssetMismatchError} when the signed asset differs from the vault asset.
@@ -27,19 +27,21 @@ export interface VaultV1InKindRedeemParams {
27
27
  * @param params.vault.address - Target Vault V1 address.
28
28
  * @param params.args.amount - Asset-denominated amount to exit.
29
29
  * @param params.args.marketParamsList - Ordered markets consumed greedily by the contract.
30
- * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
31
- * VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
32
- * address.
30
+ * @param params.args.userAddress - Redeeming account, recorded in action metadata and validated as
31
+ * the expected owner of an optional `requirementSignature` permit. VaultExitBundlesV1 burns
32
+ * `msg.sender`'s vault shares, so the submitting account must equal this address.
33
33
  * @param params.args.deadline - Permit and bundle deadline.
34
34
  * @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
35
35
  * @param params.metadata - Optional analytics metadata.
36
36
  * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
37
37
  * `data`, and the typed action discriminator.
38
38
  * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
39
+ * @throws {InputExceedsMaxError} when the bundle or permit deadline exceeds `uint256`.
39
40
  * @throws {EmptyMarketParamsListError} when no markets are supplied.
40
41
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
41
42
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
42
- * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
43
+ * @throws {BundlesPermitMismatchError} when the requirement has the wrong permit kind, asset, owner,
44
+ * spender, or signature encoding, or when its signed and action amounts or deadlines disagree.
43
45
  * @example
44
46
  * ```ts
45
47
  * import { vaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -2,8 +2,9 @@ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { encodeFunctionData } from "viem";
3
3
  import { vaultExitBundlesV1Abi } from "../../abis.js";
4
4
  import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateDeadline } from "../../helpers/validate.js";
5
6
  import { EmptyMarketParamsListError, NonPositiveInputError, } from "../../types/index.js";
6
- import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBundlesV1PermitStruct.js";
7
+ import { getBundlesSharesPermit } from "../bundles/common.js";
7
8
  /**
8
9
  * Prepares a Vault V1 in-kind redemption into Morpho Blue supply positions.
9
10
  *
@@ -15,19 +16,21 @@ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBun
15
16
  * @param params.vault.address - Target Vault V1 address.
16
17
  * @param params.args.amount - Asset-denominated amount to exit.
17
18
  * @param params.args.marketParamsList - Ordered markets consumed greedily by the contract.
18
- * @param params.args.userAddress - Expected transaction sender, recorded in action metadata only.
19
- * VaultExitBundlesV1 burns `msg.sender`'s vault shares, so the submitting account must equal this
20
- * address.
19
+ * @param params.args.userAddress - Redeeming account, recorded in action metadata and validated as
20
+ * the expected owner of an optional `requirementSignature` permit. VaultExitBundlesV1 burns
21
+ * `msg.sender`'s vault shares, so the submitting account must equal this address.
21
22
  * @param params.args.deadline - Permit and bundle deadline.
22
23
  * @param params.args.requirementSignature - Optional bounded Vault V1 shares permit.
23
24
  * @param params.metadata - Optional analytics metadata.
24
25
  * @returns A deep-frozen `Readonly<Transaction<VaultV1InKindRedeemAction>>` with `to`, `value`,
25
26
  * `data`, and the typed action discriminator.
26
27
  * @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
28
+ * @throws {InputExceedsMaxError} when the bundle or permit deadline exceeds `uint256`.
27
29
  * @throws {EmptyMarketParamsListError} when no markets are supplied.
28
30
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
29
31
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
30
- * @throws {VaultExitBundlesV1PermitMismatchError} when the requirement has the wrong permit kind, asset, or signature encoding.
32
+ * @throws {BundlesPermitMismatchError} when the requirement has the wrong permit kind, asset, owner,
33
+ * spender, or signature encoding, or when its signed and action amounts or deadlines disagree.
31
34
  * @example
32
35
  * ```ts
33
36
  * import { vaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -42,8 +45,7 @@ import { getVaultExitBundlesV1PermitStruct } from "../signatures/getVaultExitBun
42
45
  export const vaultV1InKindRedeem = ({ vault, args, metadata, }) => {
43
46
  if (args.amount <= 0n)
44
47
  throw new NonPositiveInputError("amount", args.amount);
45
- if (args.deadline <= 0n)
46
- throw new NonPositiveInputError("deadline", args.deadline);
48
+ validateDeadline(args.deadline);
47
49
  if (args.marketParamsList.length === 0)
48
50
  throw new EmptyMarketParamsListError();
49
51
  const to = getChainAddress(vault.chainId, "bundles.vaultExitBundlesV1");
@@ -54,9 +56,11 @@ export const vaultV1InKindRedeem = ({ vault, args, metadata, }) => {
54
56
  irm: marketParams.irm,
55
57
  lltv: marketParams.lltv,
56
58
  }));
57
- const sharesPermit = getVaultExitBundlesV1PermitStruct({
59
+ const sharesPermit = getBundlesSharesPermit({
58
60
  vault: vault.address,
59
61
  deadline: args.deadline,
62
+ owner: args.userAddress,
63
+ spender: to,
60
64
  requirementSignature: args.requirementSignature,
61
65
  });
62
66
  let tx = {
@@ -52,8 +52,7 @@ export interface VaultV2DepositParams {
52
52
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD; it extends
53
53
  * {@link InputExceedsMaxError}, so either class catches it.
54
54
  * @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
55
- * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit or a
56
- * Permit2 AllowanceTransfer signature is supplied.
55
+ * @throws {UnexpectedRequirementSignatureError} when native funding carries a token permit.
57
56
  * @throws {InputExceedsMaxError} when funding, `maxSharePrice`, or `deadline` exceeds uint256.
58
57
  * @throws {DepositOwnerMismatchError} when the signed owner differs from `userAddress`.
59
58
  * @throws {DepositAssetMismatchError} when the signed asset differs from the vault asset.