@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/MIGRATION-v5-to-v6.md +329 -15
  2. package/README.md +93 -47
  3. package/lib/cjs/abis.d.ts +227 -2
  4. package/lib/cjs/abis.js +156 -3
  5. package/lib/cjs/actions/blue/borrow.d.ts +1 -1
  6. package/lib/cjs/actions/blue/borrow.js +1 -1
  7. package/lib/cjs/actions/blue/common.d.ts +6 -19
  8. package/lib/cjs/actions/blue/common.js +28 -162
  9. package/lib/cjs/actions/blue/refinance.d.ts +1 -1
  10. package/lib/cjs/actions/blue/refinance.js +1 -1
  11. package/lib/cjs/actions/blue/repay.d.ts +3 -3
  12. package/lib/cjs/actions/blue/repay.js +1 -1
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
  15. package/lib/cjs/actions/blue/supply.d.ts +3 -3
  16. package/lib/cjs/actions/blue/supply.js +3 -8
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
  18. package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
  21. package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
  22. package/lib/cjs/actions/blue/withdraw.js +1 -1
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
  25. package/lib/cjs/actions/bundles/common.d.ts +230 -0
  26. package/lib/cjs/actions/bundles/common.js +507 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +1 -0
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  41. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
  42. package/lib/cjs/actions/requirements/blue/index.js +0 -2
  43. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  44. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  45. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  46. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  51. package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  52. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -1
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  58. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  59. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  60. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
  61. package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
  62. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  64. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
  65. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  66. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  67. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  68. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  69. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  70. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  71. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  72. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  73. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  74. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  75. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  76. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  77. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  78. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  79. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  80. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  81. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  82. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  83. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  84. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  85. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  86. package/lib/cjs/blue/abis.d.ts +5 -1
  87. package/lib/cjs/blue/abis.js +2 -0
  88. package/lib/cjs/blue/entities.d.ts +8 -2
  89. package/lib/cjs/blue/entities.js +1 -0
  90. package/lib/cjs/blue/errors.d.ts +1 -1
  91. package/lib/cjs/blue/errors.js +2 -1
  92. package/lib/cjs/blue/fetch.d.ts +3 -1
  93. package/lib/cjs/blue/fetch.js +1 -0
  94. package/lib/cjs/entities/blue/blue.d.ts +29 -20
  95. package/lib/cjs/entities/blue/blue.js +6 -1
  96. package/lib/cjs/entities/index.d.ts +9 -2
  97. package/lib/cjs/entities/index.js +16 -0
  98. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  99. package/lib/cjs/entities/midnight/midnight.js +20 -24
  100. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  101. package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
  102. package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  103. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  104. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  105. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  106. package/lib/cjs/entities/requirements/index.d.ts +2 -0
  107. package/lib/cjs/entities/requirements/index.js +18 -0
  108. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
  109. package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
  110. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  111. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  112. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
  113. package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
  114. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  115. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  116. package/lib/cjs/errors.d.ts +1 -1
  117. package/lib/cjs/errors.js +3 -2
  118. package/lib/cjs/fetch.d.ts +3 -1
  119. package/lib/cjs/fetch.js +1 -0
  120. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  121. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  122. package/lib/cjs/helpers/index.d.ts +4 -1
  123. package/lib/cjs/helpers/index.js +14 -1
  124. package/lib/cjs/helpers/metadata.d.ts +3 -5
  125. package/lib/cjs/helpers/metadata.js +4 -6
  126. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  127. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  128. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  129. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  130. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  131. package/lib/cjs/helpers/referralFee.js +35 -0
  132. package/lib/cjs/helpers/slippage.d.ts +136 -1
  133. package/lib/cjs/helpers/slippage.js +188 -0
  134. package/lib/cjs/helpers/validate.d.ts +67 -8
  135. package/lib/cjs/helpers/validate.js +94 -9
  136. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  137. package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
  138. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  139. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  140. package/lib/cjs/index.d.ts +1 -0
  141. package/lib/cjs/index.js +1 -0
  142. package/lib/cjs/types/action.d.ts +273 -82
  143. package/lib/cjs/types/action.js +12 -12
  144. package/lib/cjs/types/error.d.ts +349 -23
  145. package/lib/cjs/types/error.js +393 -39
  146. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  147. package/lib/cjs/utils.d.ts +3 -1
  148. package/lib/cjs/utils.js +10 -1
  149. package/lib/esm/abis.d.ts +227 -2
  150. package/lib/esm/abis.js +157 -2
  151. package/lib/esm/actions/blue/borrow.d.ts +1 -1
  152. package/lib/esm/actions/blue/borrow.js +1 -1
  153. package/lib/esm/actions/blue/common.d.ts +6 -19
  154. package/lib/esm/actions/blue/common.js +30 -164
  155. package/lib/esm/actions/blue/refinance.d.ts +1 -1
  156. package/lib/esm/actions/blue/refinance.js +1 -1
  157. package/lib/esm/actions/blue/repay.d.ts +3 -3
  158. package/lib/esm/actions/blue/repay.js +1 -1
  159. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
  160. package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
  161. package/lib/esm/actions/blue/supply.d.ts +3 -3
  162. package/lib/esm/actions/blue/supply.js +5 -10
  163. package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
  164. package/lib/esm/actions/blue/supplyCollateral.js +1 -1
  165. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
  166. package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
  167. package/lib/esm/actions/blue/withdraw.d.ts +1 -1
  168. package/lib/esm/actions/blue/withdraw.js +1 -1
  169. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
  170. package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
  171. package/lib/esm/actions/bundles/common.d.ts +230 -0
  172. package/lib/esm/actions/bundles/common.js +494 -0
  173. package/lib/esm/actions/bundles/index.d.ts +3 -0
  174. package/lib/esm/actions/bundles/index.js +2 -0
  175. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  176. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  177. package/lib/esm/actions/index.d.ts +1 -0
  178. package/lib/esm/actions/index.js +1 -0
  179. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  180. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  181. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  182. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  183. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  184. package/lib/esm/actions/midnight/takeLend.js +2 -2
  185. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  186. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  187. package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
  188. package/lib/esm/actions/requirements/blue/index.js +0 -2
  189. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  190. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
  191. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  192. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
  193. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
  194. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
  195. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  196. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  197. package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
  198. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
  199. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
  200. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
  201. package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
  202. package/lib/esm/actions/requirements/encode/index.js +1 -1
  203. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  204. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  205. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  206. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
  207. package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
  208. package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
  209. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
  210. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
  211. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  212. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  213. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  214. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  215. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  216. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  217. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  218. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  219. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  220. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  221. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  222. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  223. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  224. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  225. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  226. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  227. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  228. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  229. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  230. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  231. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  232. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  233. package/lib/esm/blue/abis.d.ts +5 -1
  234. package/lib/esm/blue/abis.js +5 -1
  235. package/lib/esm/blue/entities.d.ts +8 -2
  236. package/lib/esm/blue/entities.js +3 -1
  237. package/lib/esm/blue/errors.d.ts +1 -1
  238. package/lib/esm/blue/errors.js +1 -1
  239. package/lib/esm/blue/fetch.d.ts +3 -1
  240. package/lib/esm/blue/fetch.js +3 -1
  241. package/lib/esm/entities/blue/blue.d.ts +29 -20
  242. package/lib/esm/entities/blue/blue.js +7 -2
  243. package/lib/esm/entities/index.d.ts +9 -2
  244. package/lib/esm/entities/index.js +4 -1
  245. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  246. package/lib/esm/entities/midnight/midnight.js +20 -24
  247. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
  248. package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
  249. package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
  250. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
  251. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  252. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  253. package/lib/esm/entities/requirements/index.d.ts +2 -0
  254. package/lib/esm/entities/requirements/index.js +2 -0
  255. package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
  256. package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
  257. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  258. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  259. package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
  260. package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
  261. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  262. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  263. package/lib/esm/errors.d.ts +1 -1
  264. package/lib/esm/errors.js +1 -1
  265. package/lib/esm/fetch.d.ts +3 -1
  266. package/lib/esm/fetch.js +3 -1
  267. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  268. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  269. package/lib/esm/helpers/index.d.ts +4 -1
  270. package/lib/esm/helpers/index.js +4 -1
  271. package/lib/esm/helpers/metadata.d.ts +3 -5
  272. package/lib/esm/helpers/metadata.js +4 -6
  273. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  274. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  275. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  276. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  277. package/lib/esm/helpers/referralFee.d.ts +21 -0
  278. package/lib/esm/helpers/referralFee.js +31 -0
  279. package/lib/esm/helpers/slippage.d.ts +136 -1
  280. package/lib/esm/helpers/slippage.js +186 -2
  281. package/lib/esm/helpers/validate.d.ts +67 -8
  282. package/lib/esm/helpers/validate.js +92 -10
  283. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  284. package/lib/esm/helpers/validateRequirementSpender.js +1 -0
  285. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  286. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  287. package/lib/esm/index.d.ts +1 -0
  288. package/lib/esm/index.js +1 -0
  289. package/lib/esm/types/action.d.ts +273 -82
  290. package/lib/esm/types/action.js +11 -11
  291. package/lib/esm/types/error.d.ts +349 -23
  292. package/lib/esm/types/error.js +377 -31
  293. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  294. package/lib/esm/utils.d.ts +3 -1
  295. package/lib/esm/utils.js +3 -1
  296. package/package.json +7 -7
@@ -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, or
20
- * 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 GeneralAdapter1, MidnightBundles,
22
+ * VaultBundlesV1, or 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
32
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
30
- * MidnightBundles, or BlueBundlesV1 for `chainId`.
33
+ * MidnightBundles, 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,39 +48,38 @@ 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.
51
+ * owner,
47
52
  * spender: generalAdapter1,
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: ["generalAdapter1", "midnightBundles", "blueBundlesV1"],
70
+ allowed: [
71
+ "generalAdapter1",
72
+ "midnightBundles",
73
+ "vaultBundlesV1",
74
+ "blueBundlesV1",
75
+ ],
64
76
  });
65
77
  const now = Time.timestamp();
66
78
  // Validate an explicit deadline before the token-metadata read: this exported encoder can be
67
79
  // called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
68
80
  // deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
69
81
  if (params.deadline != null) {
70
- if (params.deadline <= 0n) {
71
- throw new NonPositiveInputError("deadline", params.deadline);
72
- }
73
- if (params.deadline > maxUint256) {
74
- throw new InputExceedsMaxError({
75
- field: "deadline",
76
- value: params.deadline,
77
- max: maxUint256,
78
- });
79
- }
82
+ validateDeadline(params.deadline);
80
83
  if (params.deadline <= now) {
81
84
  throw new ExpiredDeadlineError(params.deadline, now);
82
85
  }
@@ -85,25 +88,34 @@ export const encodeErc20Permit = async (viemClient, params) => {
85
88
  const tokenData = await fetchToken(token, viemClient, {
86
89
  deployless: supportDeployless,
87
90
  });
91
+ const permitTypedData = getPermitTypedData({
92
+ erc20: tokenData,
93
+ owner,
94
+ spender,
95
+ allowance: amount,
96
+ nonce,
97
+ deadline,
98
+ }, chainId);
99
+ const typedData = deepFreeze({
100
+ ...permitTypedData,
101
+ domain: { ...permitTypedData.domain },
102
+ });
88
103
  const action = {
89
104
  type: "permit",
90
105
  args: {
91
106
  spender,
92
107
  amount,
93
108
  deadline,
109
+ nonce,
94
110
  },
111
+ typedData,
95
112
  };
96
113
  return {
97
114
  action,
98
115
  async sign(client, userAddress) {
99
- const typedData = getPermitTypedData({
100
- erc20: tokenData,
101
- owner: userAddress,
102
- spender,
103
- allowance: amount,
104
- nonce,
105
- deadline,
106
- }, chainId);
116
+ // The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
117
+ // different signer cannot produce a valid signature for it.
118
+ validateUserAddress(userAddress, owner);
107
119
  const signature = await signAndVerifyTypedData({
108
120
  client,
109
121
  userAddress,
@@ -111,7 +123,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
111
123
  });
112
124
  return deepFreeze({
113
125
  args: {
114
- owner: userAddress,
126
+ owner,
115
127
  signature,
116
128
  deadline,
117
129
  amount,
@@ -12,7 +12,8 @@ interface EncodeErc20Permit2ApproveParams {
12
12
  * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
13
13
  * via the Permit2 contract.
14
14
  *
15
- * Deadline defaults to two hours from `Time.timestamp()`.
15
+ * The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
16
+ * displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
16
17
  *
17
18
  * @param params - Permit2 encoding parameters.
18
19
  * @param params.token - ERC-20 token address.
@@ -20,7 +21,8 @@ interface EncodeErc20Permit2ApproveParams {
20
21
  * @param params.chainId - Target chain id.
21
22
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
22
23
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
23
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
24
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
25
+ * `sign(client, userAddress)` produces the deep-frozen signature.
24
26
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
25
27
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
26
28
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -6,7 +6,8 @@ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.
6
6
  * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
7
7
  * via the Permit2 contract.
8
8
  *
9
- * Deadline defaults to two hours from `Time.timestamp()`.
9
+ * The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
10
+ * displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
10
11
  *
11
12
  * @param params - Permit2 encoding parameters.
12
13
  * @param params.token - ERC-20 token address.
@@ -14,7 +15,8 @@ import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.
14
15
  * @param params.chainId - Target chain id.
15
16
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
16
17
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
17
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
18
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
19
+ * `sign(client, userAddress)` produces the deep-frozen signature.
18
20
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
19
21
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
20
22
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -37,6 +39,16 @@ export const encodeErc20Permit2Approve = (params) => {
37
39
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
38
40
  const now = Time.timestamp();
39
41
  const deadline = now + Time.s.from.h(2n);
42
+ // Permit2 AllowanceTransfer signs over `PermitSingle` (token, spender, expiration, nonce), which
43
+ // does not include the owner, so the payload is fully determined at build time.
44
+ const typedData = deepFreeze(getPermit2PermitTypedData({
45
+ spender: generalAdapter1,
46
+ allowance: amount,
47
+ erc20: token,
48
+ nonce: Number(nonce),
49
+ deadline,
50
+ expiration: Number(expiration),
51
+ }, chainId));
40
52
  const action = {
41
53
  type: "permit2",
42
54
  args: {
@@ -45,18 +57,11 @@ export const encodeErc20Permit2Approve = (params) => {
45
57
  deadline,
46
58
  expiration,
47
59
  },
60
+ typedData,
48
61
  };
49
62
  return {
50
63
  action,
51
64
  async sign(client, userAddress) {
52
- const typedData = getPermit2PermitTypedData({
53
- spender: generalAdapter1,
54
- allowance: amount,
55
- erc20: token,
56
- nonce: Number(nonce),
57
- deadline,
58
- expiration: Number(expiration),
59
- }, chainId);
60
65
  const signature = await signAndVerifyTypedData({
61
66
  client,
62
67
  userAddress,
@@ -1,10 +1,10 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import { type Permit2TransferFromRequirementSignature, type Requirement } from "../../../types/index.js";
3
- /** Parameters for {@link encodeErc20Permit2TransferFrom}. */
4
- export interface EncodeErc20Permit2TransferFromParams {
2
+ import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
3
+ /** Parameters for {@link encodeErc20Permit2SignatureTransfer}. */
4
+ export interface EncodeErc20Permit2SignatureTransferParams {
5
5
  /** ERC-20 token pulled through Permit2. */
6
6
  readonly token: Address;
7
- /** BlueBundlesV1 deployment receiving permission to pull the token. */
7
+ /** Registered fixed bundles deployment receiving permission to pull the token. */
8
8
  readonly spender: Address;
9
9
  /** Exact token amount authorized by the one-time transfer. */
10
10
  readonly amount: bigint;
@@ -16,26 +16,28 @@ export interface EncodeErc20Permit2TransferFromParams {
16
16
  readonly deadline: bigint;
17
17
  }
18
18
  /**
19
- * Builds a Permit2 SignatureTransfer requirement for a direct BlueBundlesV1 token pull.
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.
26
- * @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
27
+ * @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
27
28
  * @param params.amount - Exact `uint256` token amount authorized.
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`.
35
37
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
36
38
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
37
39
  * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
38
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not BlueBundlesV1 for `chainId`.
40
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
39
41
  * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
40
42
  * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
41
43
  * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
@@ -43,19 +45,19 @@ export interface EncodeErc20Permit2TransferFromParams {
43
45
  * @example
44
46
  * ```ts
45
47
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
46
- * import { encodeErc20Permit2TransferFrom } from "@morpho-org/morpho-sdk";
48
+ * import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
47
49
  * import { getChainAddress } from "@morpho-org/morpho-ts";
48
50
  * import { mainnet } from "viem/chains";
49
51
  *
50
- * const requirement = encodeErc20Permit2TransferFrom({
52
+ * const requirement = encodeErc20Permit2SignatureTransfer({
51
53
  * token: addressesRegistry[mainnet.id].usdc,
52
- * spender: getChainAddress(mainnet.id, "bundles.blueBundlesV1"),
54
+ * spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
53
55
  * amount: 1_000_000n,
54
56
  * chainId: mainnet.id,
55
57
  * nonce: 0n,
56
58
  * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
57
59
  * });
58
- * // requirement satisfies Requirement<Permit2TransferFromRequirementSignature>
60
+ * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
59
61
  * ```
60
62
  */
61
- export declare const encodeErc20Permit2TransferFrom: (params: EncodeErc20Permit2TransferFromParams) => Requirement<Permit2TransferFromRequirementSignature>;
63
+ export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
@@ -6,26 +6,28 @@ import { validateUint256Field } from "../../../helpers/validate.js";
6
6
  import { validateRequirementSpender } from "../../../helpers/validateRequirementSpender.js";
7
7
  import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } from "../../../types/index.js";
8
8
  /**
9
- * Builds a Permit2 SignatureTransfer requirement for a direct BlueBundlesV1 token pull.
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.
16
- * @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
17
+ * @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
17
18
  * @param params.amount - Exact `uint256` token amount authorized.
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`.
25
27
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
26
28
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
27
29
  * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
28
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not BlueBundlesV1 for `chainId`.
30
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
29
31
  * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
30
32
  * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
31
33
  * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
@@ -33,22 +35,22 @@ import { ExpiredDeadlineError, InputExceedsMaxError, NonPositiveInputError, } fr
33
35
  * @example
34
36
  * ```ts
35
37
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
36
- * import { encodeErc20Permit2TransferFrom } from "@morpho-org/morpho-sdk";
38
+ * import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
37
39
  * import { getChainAddress } from "@morpho-org/morpho-ts";
38
40
  * import { mainnet } from "viem/chains";
39
41
  *
40
- * const requirement = encodeErc20Permit2TransferFrom({
42
+ * const requirement = encodeErc20Permit2SignatureTransfer({
41
43
  * token: addressesRegistry[mainnet.id].usdc,
42
- * spender: getChainAddress(mainnet.id, "bundles.blueBundlesV1"),
44
+ * spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
43
45
  * amount: 1_000_000n,
44
46
  * chainId: mainnet.id,
45
47
  * nonce: 0n,
46
48
  * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
47
49
  * });
48
- * // requirement satisfies Requirement<Permit2TransferFromRequirementSignature>
50
+ * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
49
51
  * ```
50
52
  */
51
- export const encodeErc20Permit2TransferFrom = (params) => {
53
+ export const encodeErc20Permit2SignatureTransfer = (params) => {
52
54
  const { token, spender, amount, chainId, nonce, deadline } = params;
53
55
  // Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
54
56
  // oversized allowance to maxUint256, which would desync the signed value from the requirement
@@ -76,7 +78,7 @@ export const encodeErc20Permit2TransferFrom = (params) => {
76
78
  validateRequirementSpender({
77
79
  chainId,
78
80
  spender,
79
- allowed: ["blueBundlesV1"],
81
+ allowed: ["vaultBundlesV1", "blueBundlesV1"],
80
82
  });
81
83
  // getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
82
84
  // getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
@@ -84,20 +86,23 @@ export const encodeErc20Permit2TransferFrom = (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
- type: "permit2TransferFrom",
89
- args: { spender, amount, deadline },
99
+ type: "permit2SignatureTransfer",
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,
@@ -6,7 +6,7 @@ export interface EncodeVaultSharesPermitParams {
6
6
  readonly vault: Token;
7
7
  /** Vault generation, which selects the standard V1 or two-field V2 domain. */
8
8
  readonly version: "vaultV1" | "vaultV2";
9
- /** VaultExitBundlesV1 spender. */
9
+ /** Registered fixed vault bundles spender. */
10
10
  readonly spender: Address;
11
11
  /** Account that owns the vault shares. */
12
12
  readonly owner: Address;
@@ -23,26 +23,29 @@ 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.
30
- * @param params.spender - Registered VaultExitBundlesV1 spender.
31
+ * @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
31
32
  * @param params.owner - Account that owns and authorizes spending of the vault shares.
32
33
  * @param params.chainId - Chain on which the vault and spender are deployed.
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 VaultExitBundlesV1 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
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
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,26 +9,29 @@ 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.
16
- * @param params.spender - Registered VaultExitBundlesV1 spender.
17
+ * @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
17
18
  * @param params.owner - Account that owns and authorizes spending of the vault shares.
18
19
  * @param params.chainId - Chain on which the vault and spender are deployed.
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 VaultExitBundlesV1 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
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
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";
@@ -76,11 +79,23 @@ export const encodeVaultSharesPermit = (params) => {
76
79
  extensions: [...inputDomain.extensions],
77
80
  }),
78
81
  });
79
- // Bind the permit to the standalone vault-exit deployment for this chain.
82
+ // Bind the permit to one of the registered fixed vault bundles deployments.
80
83
  validateRequirementSpender({
81
84
  chainId,
82
85
  spender,
83
- allowed: ["vaultExitBundlesV1"],
86
+ allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
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 },
84
99
  });
85
100
  const action = {
86
101
  type: "permit",
@@ -88,24 +103,15 @@ export const encodeVaultSharesPermit = (params) => {
88
103
  spender,
89
104
  amount,
90
105
  deadline,
106
+ nonce,
91
107
  },
108
+ typedData,
92
109
  };
93
110
  return {
94
111
  action,
95
112
  async sign(client, userAddress) {
96
113
  // The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
97
114
  validateUserAddress(userAddress, owner);
98
- const permit = {
99
- owner,
100
- spender,
101
- allowance: amount,
102
- nonce,
103
- deadline,
104
- };
105
- const typedData = getPermitTypedData({
106
- ...permit,
107
- erc20: vault,
108
- }, chainId);
109
115
  const signature = await signAndVerifyTypedData({
110
116
  client,
111
117
  userAddress,
@@ -2,5 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
4
  export * from "./encodeErc20Permit2Approve.js";
5
- export * from "./encodeErc20Permit2TransferFrom.js";
5
+ export * from "./encodeErc20Permit2SignatureTransfer.js";
6
6
  export * from "./encodeVaultSharesPermit.js";
@@ -2,5 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
4
  export * from "./encodeErc20Permit2Approve.js";
5
- export * from "./encodeErc20Permit2TransferFrom.js";
5
+ export * from "./encodeErc20Permit2SignatureTransfer.js";
6
6
  export * from "./encodeVaultSharesPermit.js";
@@ -92,6 +92,7 @@ export const getGeneralAdapterRequirements = async (viemClient, params) => {
92
92
  // the pulled amount leaves no residual direct allowance after inclusion.
93
93
  return getGeneralAdapterRequirementsPermit(viemClient, {
94
94
  token: address,
95
+ owner: from,
95
96
  chainId,
96
97
  args: { amount },
97
98
  nonce: erc2612Nonce,
@@ -5,9 +5,10 @@ import type { Address, Client } from "viem";
5
5
  *
6
6
  * @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
7
7
  * @param params.token - ERC-20 token address (must support EIP-2612).
8
+ * @param params.owner - Account that owns the tokens and signs the permit.
8
9
  * @param params.chainId - The chain the bundle targets.
9
10
  * @param params.args.amount - Required token amount.
10
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
11
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
11
12
  * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
12
13
  * @returns A single-element array containing the exact-amount `Requirement` to sign.
13
14
  * @example
@@ -19,6 +20,7 @@ import type { Address, Client } from "viem";
19
20
  * const client = createWalletClient({ chain: mainnet, transport: http() });
20
21
  * const reqs = await getGeneralAdapterRequirementsPermit(client, {
21
22
  * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
23
+ * owner,
22
24
  * chainId: 1,
23
25
  * args: { amount: 1_000_000n },
24
26
  * nonce: 0n,
@@ -28,6 +30,7 @@ import type { Address, Client } from "viem";
28
30
  */
29
31
  export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, params: {
30
32
  token: Address;
33
+ owner: Address;
31
34
  chainId: number;
32
35
  args: {
33
36
  amount: bigint;
@@ -6,9 +6,10 @@ import { encodeErc20Permit } from "../encode/index.js";
6
6
  *
7
7
  * @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
8
8
  * @param params.token - ERC-20 token address (must support EIP-2612).
9
+ * @param params.owner - Account that owns the tokens and signs the permit.
9
10
  * @param params.chainId - The chain the bundle targets.
10
11
  * @param params.args.amount - Required token amount.
11
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
12
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
12
13
  * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
13
14
  * @returns A single-element array containing the exact-amount `Requirement` to sign.
14
15
  * @example
@@ -20,6 +21,7 @@ import { encodeErc20Permit } from "../encode/index.js";
20
21
  * const client = createWalletClient({ chain: mainnet, transport: http() });
21
22
  * const reqs = await getGeneralAdapterRequirementsPermit(client, {
22
23
  * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
24
+ * owner,
23
25
  * chainId: 1,
24
26
  * args: { amount: 1_000_000n },
25
27
  * nonce: 0n,
@@ -28,7 +30,7 @@ import { encodeErc20Permit } from "../encode/index.js";
28
30
  * ```
29
31
  */
30
32
  export const getGeneralAdapterRequirementsPermit = async (viemClient, params) => {
31
- const { token, chainId, args: { amount }, nonce, supportDeployless, } = params;
33
+ const { token, owner, chainId, args: { amount }, nonce, supportDeployless, } = params;
32
34
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
33
35
  // Existing direct ERC-20 allowance is intentionally not an input here. ERC-2612 overwrites the
34
36
  // allowance with the signed amount, and the bundle spends exactly `amount`, leaving no residual
@@ -36,6 +38,7 @@ export const getGeneralAdapterRequirementsPermit = async (viemClient, params) =>
36
38
  return [
37
39
  await encodeErc20Permit(viemClient, {
38
40
  token,
41
+ owner,
39
42
  spender: generalAdapter1,
40
43
  amount,
41
44
  chainId,