@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
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeErc20Permit = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
6
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
+ const validate_js_1 = require("../../../helpers/validate.js");
8
8
  const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
9
9
  const index_js_1 = require("../../../types/index.js");
10
10
  /**
@@ -13,30 +13,34 @@ const index_js_1 = require("../../../types/index.js");
13
13
  *
14
14
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
15
15
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
16
- * the selected transaction route can consume. Deadline defaults to two hours from
17
- * `Time.timestamp()`.
16
+ * the selected transaction route can consume. The requirement's `action.typedData` holds that
17
+ * EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
18
+ * hours from `Time.timestamp()`.
18
19
  *
19
20
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
21
  * @param params - Permit encoding parameters.
21
22
  * @param params.token - ERC-20 token address (must support EIP-2612).
22
- * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles, or
23
- * BlueBundlesV1 for the chain.
23
+ * @param params.owner - Account that owns the tokens and signs the permit.
24
+ * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
25
+ * VaultBundlesV1, or BlueBundlesV1 for the chain.
24
26
  * @param params.amount - Permit allowance amount.
25
27
  * @param params.chainId - Target chain id.
26
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
28
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
27
29
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
28
30
  * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
29
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
31
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
32
+ * `sign(client, userAddress)` produces the deep-frozen signature.
30
33
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
31
34
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
32
35
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
33
- * MidnightBundles, or BlueBundlesV1 for `chainId`.
36
+ * MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
34
37
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
35
38
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
36
39
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
37
40
  * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
38
41
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
39
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
42
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
43
+ * client account differs from `userAddress`.
40
44
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
41
45
  * @example
42
46
  * ```ts
@@ -47,39 +51,38 @@ const index_js_1 = require("../../../types/index.js");
47
51
  * const client = createWalletClient({ chain: mainnet, transport: http() });
48
52
  * const requirement = await encodeErc20Permit(client, {
49
53
  * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
54
+ * owner,
50
55
  * spender: generalAdapter1,
51
56
  * amount: 1_000_000n,
52
57
  * chainId: 1,
53
58
  * nonce: 0n,
54
59
  * });
55
- * // requirement satisfies Requirement
60
+ * // Inspect the EIP-712 payload, then sign via the requirement:
61
+ * const typedData = requirement.action.typedData;
62
+ * const signed = await requirement.sign(client, owner);
56
63
  * ```
57
64
  */
58
65
  const encodeErc20Permit = async (viemClient, params) => {
59
- const { token, spender, amount, chainId, nonce, supportDeployless } = params;
66
+ const { token, owner, spender, amount, chainId, nonce, supportDeployless } = params;
60
67
  if (viemClient.chain?.id !== chainId) {
61
68
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
62
69
  }
63
70
  (0, validateRequirementSpender_js_1.validateRequirementSpender)({
64
71
  chainId,
65
72
  spender,
66
- allowed: ["generalAdapter1", "midnightBundles", "blueBundlesV1"],
73
+ allowed: [
74
+ "generalAdapter1",
75
+ "midnightBundles",
76
+ "vaultBundlesV1",
77
+ "blueBundlesV1",
78
+ ],
67
79
  });
68
80
  const now = morpho_ts_1.Time.timestamp();
69
81
  // Validate an explicit deadline before the token-metadata read: this exported encoder can be
70
82
  // called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
71
83
  // deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
72
84
  if (params.deadline != null) {
73
- if (params.deadline <= 0n) {
74
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
75
- }
76
- if (params.deadline > viem_1.maxUint256) {
77
- throw new index_js_1.InputExceedsMaxError({
78
- field: "deadline",
79
- value: params.deadline,
80
- max: viem_1.maxUint256,
81
- });
82
- }
85
+ (0, validate_js_1.validateDeadline)(params.deadline);
83
86
  if (params.deadline <= now) {
84
87
  throw new index_js_1.ExpiredDeadlineError(params.deadline, now);
85
88
  }
@@ -88,25 +91,34 @@ const encodeErc20Permit = async (viemClient, params) => {
88
91
  const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
89
92
  deployless: supportDeployless,
90
93
  });
94
+ const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
95
+ erc20: tokenData,
96
+ owner,
97
+ spender,
98
+ allowance: amount,
99
+ nonce,
100
+ deadline,
101
+ }, chainId);
102
+ const typedData = (0, morpho_ts_1.deepFreeze)({
103
+ ...permitTypedData,
104
+ domain: { ...permitTypedData.domain },
105
+ });
91
106
  const action = {
92
107
  type: "permit",
93
108
  args: {
94
109
  spender,
95
110
  amount,
96
111
  deadline,
112
+ nonce,
97
113
  },
114
+ typedData,
98
115
  };
99
116
  return {
100
117
  action,
101
118
  async sign(client, userAddress) {
102
- const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
103
- erc20: tokenData,
104
- owner: userAddress,
105
- spender,
106
- allowance: amount,
107
- nonce,
108
- deadline,
109
- }, chainId);
119
+ // The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
120
+ // different signer cannot produce a valid signature for it.
121
+ (0, validate_js_1.validateUserAddress)(userAddress, owner);
110
122
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
111
123
  client,
112
124
  userAddress,
@@ -114,7 +126,7 @@ const encodeErc20Permit = async (viemClient, params) => {
114
126
  });
115
127
  return (0, morpho_ts_1.deepFreeze)({
116
128
  args: {
117
- owner: userAddress,
129
+ owner,
118
130
  signature,
119
131
  deadline,
120
132
  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.
@@ -9,7 +9,8 @@ const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTyped
9
9
  * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
10
10
  * via the Permit2 contract.
11
11
  *
12
- * Deadline defaults to two hours from `Time.timestamp()`.
12
+ * The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
13
+ * displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
13
14
  *
14
15
  * @param params - Permit2 encoding parameters.
15
16
  * @param params.token - ERC-20 token address.
@@ -17,7 +18,8 @@ const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTyped
17
18
  * @param params.chainId - Target chain id.
18
19
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
19
20
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
20
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
21
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
22
+ * `sign(client, userAddress)` produces the deep-frozen signature.
21
23
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
22
24
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
23
25
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -40,6 +42,16 @@ const encodeErc20Permit2Approve = (params) => {
40
42
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
41
43
  const now = morpho_ts_1.Time.timestamp();
42
44
  const deadline = now + morpho_ts_1.Time.s.from.h(2n);
45
+ // Permit2 AllowanceTransfer signs over `PermitSingle` (token, spender, expiration, nonce), which
46
+ // does not include the owner, so the payload is fully determined at build time.
47
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getPermit2PermitTypedData)({
48
+ spender: generalAdapter1,
49
+ allowance: amount,
50
+ erc20: token,
51
+ nonce: Number(nonce),
52
+ deadline,
53
+ expiration: Number(expiration),
54
+ }, chainId));
43
55
  const action = {
44
56
  type: "permit2",
45
57
  args: {
@@ -48,18 +60,11 @@ const encodeErc20Permit2Approve = (params) => {
48
60
  deadline,
49
61
  expiration,
50
62
  },
63
+ typedData,
51
64
  };
52
65
  return {
53
66
  action,
54
67
  async sign(client, userAddress) {
55
- const typedData = (0, blue_sdk_viem_1.getPermit2PermitTypedData)({
56
- spender: generalAdapter1,
57
- allowance: amount,
58
- erc20: token,
59
- nonce: Number(nonce),
60
- deadline,
61
- expiration: Number(expiration),
62
- }, chainId);
63
68
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
64
69
  client,
65
70
  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>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeErc20Permit2TransferFrom = void 0;
3
+ exports.encodeErc20Permit2SignatureTransfer = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
@@ -9,26 +9,28 @@ const validate_js_1 = require("../../../helpers/validate.js");
9
9
  const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
10
10
  const index_js_1 = require("../../../types/index.js");
11
11
  /**
12
- * Builds a Permit2 SignatureTransfer requirement for a direct BlueBundlesV1 token pull.
12
+ * Builds a Permit2 SignatureTransfer requirement for a direct fixed-bundles token pull.
13
13
  *
14
14
  * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
15
- * it has no managed allowance expiration.
15
+ * it has no managed allowance expiration. The requirement's `action.typedData` holds the EIP-712
16
+ * payload so it can be inspected or displayed before signing.
16
17
  *
17
18
  * @param params - SignatureTransfer parameters.
18
19
  * @param params.token - ERC-20 token pulled through Permit2.
19
- * @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
20
+ * @param params.spender - Registered BlueBundlesV1 or VaultBundlesV1 deployment that performs the pull.
20
21
  * @param params.amount - Exact `uint256` token amount authorized.
21
22
  * @param params.chainId - Target chain id.
22
23
  * @param params.nonce - Unused Permit2 unordered nonce.
23
24
  * @param params.deadline - Signature expiration timestamp in seconds.
24
- * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
25
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose
26
+ * `sign(client, userAddress)` returns a deep-frozen signature result.
25
27
  * @throws {NegativeInputError} when `amount` or `nonce` is negative.
26
28
  * @throws {NonPositiveInputError} when `deadline` is not positive.
27
29
  * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
28
30
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
29
31
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
30
32
  * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
31
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not BlueBundlesV1 for `chainId`.
33
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed bundles deployment for `chainId`.
32
34
  * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
33
35
  * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
34
36
  * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
@@ -36,22 +38,22 @@ const index_js_1 = require("../../../types/index.js");
36
38
  * @example
37
39
  * ```ts
38
40
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
39
- * import { encodeErc20Permit2TransferFrom } from "@morpho-org/morpho-sdk";
41
+ * import { encodeErc20Permit2SignatureTransfer } from "@morpho-org/morpho-sdk";
40
42
  * import { getChainAddress } from "@morpho-org/morpho-ts";
41
43
  * import { mainnet } from "viem/chains";
42
44
  *
43
- * const requirement = encodeErc20Permit2TransferFrom({
45
+ * const requirement = encodeErc20Permit2SignatureTransfer({
44
46
  * token: addressesRegistry[mainnet.id].usdc,
45
- * spender: getChainAddress(mainnet.id, "bundles.blueBundlesV1"),
47
+ * spender: getChainAddress(mainnet.id, "bundles.vaultBundlesV1"),
46
48
  * amount: 1_000_000n,
47
49
  * chainId: mainnet.id,
48
50
  * nonce: 0n,
49
51
  * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
50
52
  * });
51
- * // requirement satisfies Requirement<Permit2TransferFromRequirementSignature>
53
+ * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
52
54
  * ```
53
55
  */
54
- const encodeErc20Permit2TransferFrom = (params) => {
56
+ const encodeErc20Permit2SignatureTransfer = (params) => {
55
57
  const { token, spender, amount, chainId, nonce, deadline } = params;
56
58
  // Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
57
59
  // oversized allowance to maxUint256, which would desync the signed value from the requirement
@@ -79,7 +81,7 @@ const encodeErc20Permit2TransferFrom = (params) => {
79
81
  (0, validateRequirementSpender_js_1.validateRequirementSpender)({
80
82
  chainId,
81
83
  spender,
82
- allowed: ["blueBundlesV1"],
84
+ allowed: ["vaultBundlesV1", "blueBundlesV1"],
83
85
  });
84
86
  // getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
85
87
  // getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
@@ -87,20 +89,23 @@ const encodeErc20Permit2TransferFrom = (params) => {
87
89
  // sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
88
90
  // this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
89
91
  (0, morpho_ts_1.getChainAddress)(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
92
+ // Permit2 SignatureTransfer signs over `PermitTransferFrom` (permitted, spender, nonce,
93
+ // deadline), which does not include the owner, so the payload is fully determined at build time.
94
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
95
+ erc20: token,
96
+ allowance: amount,
97
+ spender,
98
+ nonce,
99
+ deadline,
100
+ }, chainId));
90
101
  const action = {
91
- type: "permit2TransferFrom",
92
- args: { spender, amount, deadline },
102
+ type: "permit2SignatureTransfer",
103
+ args: { spender, amount, nonce, deadline },
104
+ typedData,
93
105
  };
94
106
  return {
95
107
  action,
96
108
  async sign(client, userAddress) {
97
- const typedData = (0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
98
- erc20: token,
99
- allowance: amount,
100
- spender,
101
- nonce,
102
- deadline,
103
- }, chainId);
104
109
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
105
110
  client,
106
111
  userAddress,
@@ -120,4 +125,4 @@ const encodeErc20Permit2TransferFrom = (params) => {
120
125
  },
121
126
  };
122
127
  };
123
- exports.encodeErc20Permit2TransferFrom = encodeErc20Permit2TransferFrom;
128
+ exports.encodeErc20Permit2SignatureTransfer = encodeErc20Permit2SignatureTransfer;
@@ -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";
@@ -12,26 +12,29 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
12
12
  * Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
13
13
  *
14
14
  * Vault V1 uses the standard token permit domain. Vault V2 uses its protocol-specific domain with
15
- * only `chainId` and `verifyingContract`.
15
+ * only `chainId` and `verifyingContract`. The requirement's `action.typedData` holds the EIP-712
16
+ * payload so it can be inspected or displayed before signing.
16
17
  *
17
18
  * @param params.vault - Vault share token, including V1 permit-domain metadata when available.
18
19
  * @param params.version - Vault generation selecting the standard V1 or two-field V2 domain.
19
- * @param params.spender - Registered VaultExitBundlesV1 spender.
20
+ * @param params.spender - Registered VaultBundlesV1 or VaultExitBundlesV1 spender.
20
21
  * @param params.owner - Account that owns and authorizes spending of the vault shares.
21
22
  * @param params.chainId - Chain on which the vault and spender are deployed.
22
23
  * @param params.nonce - Current vault permit nonce for the owner.
23
24
  * @param params.amount - Vault-share allowance to authorize.
24
25
  * @param params.deadline - Shared permit and bundle deadline.
25
- * @returns A requirement whose `sign()` result can be embedded in VaultExitBundlesV1 calldata.
26
+ * @returns A requirement whose `action.typedData` is the EIP-712 payload and whose `sign()` result
27
+ * can be embedded in fixed vault-bundles calldata.
26
28
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
27
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the registered VaultExitBundlesV1.
29
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
28
30
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
29
- * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `owner`.
31
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
32
+ * wallet account differs from `userAddress`.
30
33
  * @throws {ChainIdMismatchError} from `sign()` when the wallet targets another chain.
31
34
  * @throws {InvalidSignatureError} from `sign()` when signature recovery fails.
32
- * @throws {InvalidPermitDomainChainIdError} from `sign()` when a Vault V1 permit domain targets another chain or omits `chainId`.
33
- * @throws {InvalidPermitDomainVerifyingContractError} from `sign()` when a Vault V1 permit domain targets another token or omits `verifyingContract`.
34
- * @throws {UnsupportedPermitDomainExtensionsError} from `sign()` when a Vault V1 permit domain advertises unsupported extensions.
35
+ * @throws {InvalidPermitDomainChainIdError} when a Vault V1 permit domain targets another chain or omits `chainId`.
36
+ * @throws {InvalidPermitDomainVerifyingContractError} when a Vault V1 permit domain targets another token or omits `verifyingContract`.
37
+ * @throws {UnsupportedPermitDomainExtensionsError} when a Vault V1 permit domain advertises unsupported extensions.
35
38
  * @example
36
39
  * ```ts
37
40
  * import { encodeVaultSharesPermit } from "@morpho-org/morpho-sdk";
@@ -79,11 +82,23 @@ const encodeVaultSharesPermit = (params) => {
79
82
  extensions: [...inputDomain.extensions],
80
83
  }),
81
84
  });
82
- // Bind the permit to the standalone vault-exit deployment for this chain.
85
+ // Bind the permit to one of the registered fixed vault bundles deployments.
83
86
  (0, validateRequirementSpender_js_1.validateRequirementSpender)({
84
87
  chainId,
85
88
  spender,
86
- allowed: ["vaultExitBundlesV1"],
89
+ allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
90
+ });
91
+ const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
92
+ owner,
93
+ spender,
94
+ allowance: amount,
95
+ nonce,
96
+ deadline,
97
+ erc20: vault,
98
+ }, chainId);
99
+ const typedData = (0, morpho_ts_1.deepFreeze)({
100
+ ...permitTypedData,
101
+ domain: { ...permitTypedData.domain },
87
102
  });
88
103
  const action = {
89
104
  type: "permit",
@@ -91,24 +106,15 @@ const encodeVaultSharesPermit = (params) => {
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
116
  // The bundle spends msg.sender's shares, so another signer cannot authorize this exit.
100
117
  (0, validate_js_1.validateUserAddress)(userAddress, owner);
101
- const permit = {
102
- owner,
103
- spender,
104
- allowance: amount,
105
- nonce,
106
- deadline,
107
- };
108
- const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
109
- ...permit,
110
- erc20: vault,
111
- }, chainId);
112
118
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
113
119
  client,
114
120
  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";
@@ -18,5 +18,5 @@ __exportStar(require("./encodeBlueSignatureAuthorization.js"), exports);
18
18
  __exportStar(require("./encodeErc20Approval.js"), exports);
19
19
  __exportStar(require("./encodeErc20Permit.js"), exports);
20
20
  __exportStar(require("./encodeErc20Permit2Approve.js"), exports);
21
- __exportStar(require("./encodeErc20Permit2TransferFrom.js"), exports);
21
+ __exportStar(require("./encodeErc20Permit2SignatureTransfer.js"), exports);
22
22
  __exportStar(require("./encodeVaultSharesPermit.js"), exports);
@@ -95,6 +95,7 @@ const getGeneralAdapterRequirements = async (viemClient, params) => {
95
95
  // the pulled amount leaves no residual direct allowance after inclusion.
96
96
  return (0, getGeneralAdapterRequirementsPermit_js_1.getGeneralAdapterRequirementsPermit)(viemClient, {
97
97
  token: address,
98
+ owner: from,
98
99
  chainId,
99
100
  args: { amount },
100
101
  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;