@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
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveBundlesTokenRequirements = void 0;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const viem_1 = require("viem");
6
+ const validate_js_1 = require("../../helpers/validate.js");
7
+ const validateRequirementSpender_js_1 = require("../../helpers/validateRequirementSpender.js");
8
+ const index_js_1 = require("../../types/index.js");
9
+ const index_js_2 = require("../requirements/encode/index.js");
10
+ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApproval.js");
11
+ /**
12
+ * Resolves pre-fetched allowance and Permit2 nonce state into ordered bundles requirements.
13
+ *
14
+ * `spender` is validated against the chain registry's fixed bundles deployments, and the
15
+ * SignatureTransfer branch resolves canonical Permit2 from that same registry, so no caller can
16
+ * route an approval or a signed pull to an address the SDK does not know.
17
+ *
18
+ * The SignatureTransfer branch always places any ERC-20 approval to canonical Permit2 before the
19
+ * one-time signature requirement.
20
+ *
21
+ * @param params - Funding values, expected bundles spender, and pre-fetched state.
22
+ * @param params.token - ERC-20 token funded by the operation.
23
+ * @param params.spender - Registered fixed bundles contract that pulls the token; must be the
24
+ * chain's BlueBundlesV1 or VaultBundlesV1 deployment.
25
+ * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
26
+ * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
27
+ * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
28
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
29
+ * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
30
+ * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
31
+ * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
32
+ * @param params.state.approvalAmount - In the approval branch, allowance to set if needed; must cover `amount`.
33
+ * @param params.state.permit2Allowance - In the SignatureTransfer branch, current token allowance from `owner` to canonical Permit2.
34
+ * @param params.state.permit2Nonce - In the SignatureTransfer branch, caller-selected unused uint256 unordered nonce.
35
+ * @param params.state.nonceBitmap - In the SignatureTransfer branch, owner's Permit2 bitmap word at `permit2Nonce >> 8n`.
36
+ * @returns Ordered approval transactions and/or a Permit2 SignatureTransfer requirement.
37
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
38
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
39
+ * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
40
+ * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
41
+ * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
42
+ * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
43
+ * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
44
+ * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
45
+ * @example
46
+ * ```ts
47
+ * import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
48
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
49
+ * import { zeroAddress } from "viem";
50
+ *
51
+ * const requirements = resolveBundlesTokenRequirements({
52
+ * token: zeroAddress,
53
+ * spender: getChainAddress(1, "bundles.vaultBundlesV1"),
54
+ * owner: zeroAddress,
55
+ * chainId: 1,
56
+ * amount: 1_000_000n,
57
+ * deadline: 1_900_000_000n,
58
+ * state: { type: "approval", allowance: 1_000_000n, approvalAmount: 1_000_000n },
59
+ * });
60
+ * // requirements is empty because the allowance already covers the amount.
61
+ * ```
62
+ */
63
+ const resolveBundlesTokenRequirements = (params) => {
64
+ (0, validateRequirementSpender_js_1.validateRequirementSpender)({
65
+ chainId: params.chainId,
66
+ spender: params.spender,
67
+ allowed: ["blueBundlesV1", "vaultBundlesV1"],
68
+ });
69
+ // Reject invalid pulls before an approval encoder can cap the requested amount.
70
+ (0, validate_js_1.validateUint256Field)("amount", params.amount);
71
+ if (params.amount === 0n)
72
+ return [];
73
+ if (params.state.type === "approval") {
74
+ if (params.state.approvalAmount < params.amount) {
75
+ throw new index_js_1.ApprovalAmountLessThanSpendAmountError();
76
+ }
77
+ return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
78
+ address: params.token,
79
+ chainId: params.chainId,
80
+ args: {
81
+ // Compare against the bounded pull to avoid redundant approvals and USDT zero-resets.
82
+ spender: params.spender,
83
+ spendAmount: params.amount,
84
+ approvalAmount: params.state.approvalAmount,
85
+ },
86
+ allowances: params.state.allowance,
87
+ });
88
+ }
89
+ if (params.state.permit2Nonce < 0n) {
90
+ throw new index_js_1.NegativeInputError("permit2Nonce", params.state.permit2Nonce);
91
+ }
92
+ if (params.state.permit2Nonce > viem_1.maxUint256) {
93
+ throw new index_js_1.InputExceedsMaxError({
94
+ field: "permit2Nonce",
95
+ value: params.state.permit2Nonce,
96
+ max: viem_1.maxUint256,
97
+ });
98
+ }
99
+ const bitPosition = params.state.permit2Nonce & 255n;
100
+ if ((params.state.nonceBitmap & (1n << bitPosition)) !== 0n) {
101
+ throw new index_js_1.Permit2SignatureTransferNonceAlreadyUsedError(params.owner, params.state.permit2Nonce);
102
+ }
103
+ const permit2 = (0, morpho_ts_1.getChainAddress)(params.chainId, "permit2");
104
+ return [
105
+ ...(0, getRequirementsApproval_js_1.getRequirementsApproval)({
106
+ address: params.token,
107
+ chainId: params.chainId,
108
+ args: {
109
+ spender: permit2,
110
+ spendAmount: params.amount,
111
+ approvalAmount: viem_1.maxUint256,
112
+ },
113
+ allowances: params.state.permit2Allowance,
114
+ }),
115
+ (0, index_js_2.encodeErc20Permit2SignatureTransfer)({
116
+ token: params.token,
117
+ spender: params.spender,
118
+ amount: params.amount,
119
+ chainId: params.chainId,
120
+ nonce: params.state.permit2Nonce,
121
+ deadline: params.deadline,
122
+ }),
123
+ ];
124
+ };
125
+ exports.resolveBundlesTokenRequirements = resolveBundlesTokenRequirements;
@@ -3,6 +3,7 @@ export type { MidnightActions } from "../entities/midnight/index.js";
3
3
  export type { VaultV1Actions } from "../entities/vaultV1/index.js";
4
4
  export type { VaultV2Actions } from "../entities/vaultV2/index.js";
5
5
  export * from "./blue/index.js";
6
+ export * from "./bundles/index.js";
6
7
  export * from "./midnight/index.js";
7
8
  export * from "./requirements/index.js";
8
9
  export * from "./signatures/index.js";
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./blue/index.js"), exports);
18
+ __exportStar(require("./bundles/index.js"), exports);
18
19
  __exportStar(require("./midnight/index.js"), exports);
19
20
  __exportStar(require("./requirements/index.js"), exports);
20
21
  __exportStar(require("./signatures/index.js"), exports);
@@ -40,8 +40,8 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
40
40
  * chainId: 8453,
41
41
  * market: marketData.params,
42
42
  * collateralAssets: 2_000_000n,
43
- * loanAssets: BigInt(quote.data.availableAssets),
44
- * maxUnits: BigInt(quote.data.availableUnits),
43
+ * loanAssets: 1_000_000n,
44
+ * maxUnits: 1_100_000n,
45
45
  * taker: borrower,
46
46
  * takeableOffers: quote.data.takeableOffers,
47
47
  * deadline: maxUint256,
@@ -44,8 +44,8 @@ const types_js_1 = require("./types.js");
44
44
  * chainId: 8453,
45
45
  * market: marketData.params,
46
46
  * collateralAssets: 2_000_000n,
47
- * loanAssets: BigInt(quote.data.availableAssets),
48
- * maxUnits: BigInt(quote.data.availableUnits),
47
+ * loanAssets: 1_000_000n,
48
+ * maxUnits: 1_100_000n,
49
49
  * taker: borrower,
50
50
  * takeableOffers: quote.data.takeableOffers,
51
51
  * deadline: maxUint256,
@@ -46,8 +46,8 @@ export interface MidnightTakeBorrowParams {
46
46
  * const tx = midnightTakeBorrow({
47
47
  * chainId: 8453,
48
48
  * market: marketData.params,
49
- * loanAssets: BigInt(quote.data.availableAssets),
50
- * maxUnits: BigInt(quote.data.availableUnits),
49
+ * loanAssets: 1_000_000n,
50
+ * maxUnits: 1_100_000n,
51
51
  * taker: borrower,
52
52
  * takeableOffers: quote.data.takeableOffers,
53
53
  * deadline: maxUint256,
@@ -40,8 +40,8 @@ const index_js_2 = require("../../types/index.js");
40
40
  * const tx = midnightTakeBorrow({
41
41
  * chainId: 8453,
42
42
  * market: marketData.params,
43
- * loanAssets: BigInt(quote.data.availableAssets),
44
- * maxUnits: BigInt(quote.data.availableUnits),
43
+ * loanAssets: 1_000_000n,
44
+ * maxUnits: 1_100_000n,
45
45
  * taker: borrower,
46
46
  * takeableOffers: quote.data.takeableOffers,
47
47
  * deadline: maxUint256,
@@ -46,8 +46,8 @@ export interface MidnightTakeLendParams {
46
46
  * const tx = midnightTakeLend({
47
47
  * chainId: 8453,
48
48
  * market: marketData.params,
49
- * assets: BigInt(quote.data.availableAssets),
50
- * minUnits: BigInt(quote.data.availableUnits),
49
+ * assets: 1_000_000n,
50
+ * minUnits: 900_000n,
51
51
  * taker: lender,
52
52
  * takeableOffers: quote.data.takeableOffers,
53
53
  * deadline: maxUint256,
@@ -41,8 +41,8 @@ const types_js_1 = require("./types.js");
41
41
  * const tx = midnightTakeLend({
42
42
  * chainId: 8453,
43
43
  * market: marketData.params,
44
- * assets: BigInt(quote.data.availableAssets),
45
- * minUnits: BigInt(quote.data.availableUnits),
44
+ * assets: 1_000_000n,
45
+ * minUnits: 900_000n,
46
46
  * taker: lender,
47
47
  * takeableOffers: quote.data.takeableOffers,
48
48
  * deadline: maxUint256,
@@ -28,6 +28,9 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
28
28
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
29
29
  * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
30
30
  * GeneralAdapter1 nor its BlueBundlesV1 operator.
31
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
32
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
33
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
31
34
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
32
35
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
33
36
  * @example
@@ -5,6 +5,7 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
+ const validate_js_1 = require("../../../helpers/validate.js");
8
9
  const index_js_1 = require("../../../types/index.js");
9
10
  const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSignatureAuthorization.js");
10
11
  /**
@@ -34,6 +35,9 @@ const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSigna
34
35
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
36
  * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
36
37
  * GeneralAdapter1 nor its BlueBundlesV1 operator.
38
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
39
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
40
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
37
41
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
42
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
39
43
  * @example
@@ -80,16 +84,7 @@ const getBlueAuthorizationRequirement = async (params) => {
80
84
  // one before the RPC reads so the caller never signs an authorization that cannot be encoded
81
85
  // or would revert on-chain. An omitted deadline defaults downstream to two hours from now.
82
86
  if (params.deadline != null) {
83
- if (params.deadline <= 0n) {
84
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
85
- }
86
- if (params.deadline > viem_1.maxUint256) {
87
- throw new index_js_1.InputExceedsMaxError({
88
- field: "deadline",
89
- value: params.deadline,
90
- max: viem_1.maxUint256,
91
- });
92
- }
87
+ (0, validate_js_1.validateDeadline)(params.deadline);
93
88
  const timestamp = morpho_ts_1.Time.timestamp();
94
89
  if (params.deadline <= timestamp) {
95
90
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
@@ -117,6 +112,7 @@ const getBlueAuthorizationRequirement = async (params) => {
117
112
  return null;
118
113
  }
119
114
  return (0, encodeBlueSignatureAuthorization_js_1.encodeBlueSignatureAuthorization)(viemClient, {
115
+ owner: userAddress,
120
116
  authorized,
121
117
  chainId,
122
118
  nonce,
@@ -1,3 +1 @@
1
1
  export * from "./getBlueAuthorizationRequirement.js";
2
- export * from "./getBlueBundlesV1TokenRequirements.js";
3
- export * from "./getUnusedPermit2Nonce.js";
@@ -15,5 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
18
- __exportStar(require("./getBlueBundlesV1TokenRequirements.js"), exports);
19
- __exportStar(require("./getUnusedPermit2Nonce.js"), exports);
@@ -1,13 +1,15 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import { type Client } from "viem";
2
+ import type { Client } from "viem";
3
3
  import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeBlueSignatureAuthorization}. */
5
5
  interface EncodeBlueSignatureAuthorizationParams {
6
+ /** Account granting the authorization and signing it (the Morpho `authorizer`). */
7
+ owner: Address;
6
8
  /** Operator to authorize on Morpho, such as GeneralAdapter1 or BlueBundlesV1. */
7
9
  authorized: Address;
8
10
  /** Target chain id; must match `viemClient.chain.id`. */
9
11
  chainId: number;
10
- /** The signer's current Morpho authorization nonce. */
12
+ /** The owner's current Morpho authorization nonce. */
11
13
  nonce: bigint;
12
14
  /** Whether to grant (`true`, default) or revoke (`false`) the authorization. */
13
15
  isAuthorized?: boolean;
@@ -21,23 +23,27 @@ interface EncodeBlueSignatureAuthorizationParams {
21
23
  *
22
24
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
23
25
  * typed data, verifies it against the connected account, and returns a deep-frozen
24
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
25
- * from `Time.timestamp()`.
26
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
27
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
28
+ * Deadline defaults to two hours from `Time.timestamp()`.
26
29
  *
27
30
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
28
31
  * @param params - Authorization encoding parameters.
32
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
29
33
  * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
30
34
  * @param params.chainId - Target chain id.
31
- * @param params.nonce - The signer's current Morpho authorization nonce.
35
+ * @param params.nonce - The owner's current Morpho authorization nonce.
32
36
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
33
37
  * @param params.deadline - Optional signature deadline in seconds.
34
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
38
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
39
+ * `sign(client, userAddress)` produces the deep-frozen signature.
35
40
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
36
41
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
37
42
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
38
43
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
39
44
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
40
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
45
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
46
+ * client account differs from `userAddress`.
41
47
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
42
48
  * @example
43
49
  * ```ts
@@ -47,11 +53,12 @@ interface EncodeBlueSignatureAuthorizationParams {
47
53
  *
48
54
  * const client = createWalletClient({ chain: mainnet, transport: http() });
49
55
  * const requirement = await encodeBlueSignatureAuthorization(client, {
56
+ * owner,
50
57
  * authorized: generalAdapter1,
51
58
  * chainId: 1,
52
59
  * nonce: 0n,
53
60
  * });
54
- * // requirement satisfies Requirement
61
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
55
62
  * ```
56
63
  */
57
64
  export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeBlueSignatureAuthorization = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
6
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
+ const validate_js_1 = require("../../../helpers/validate.js");
8
8
  const index_js_1 = require("../../../types/index.js");
9
9
  /**
10
10
  * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
@@ -13,23 +13,27 @@ const index_js_1 = require("../../../types/index.js");
13
13
  *
14
14
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
15
15
  * typed data, verifies it against the connected account, and returns a deep-frozen
16
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
17
- * from `Time.timestamp()`.
16
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
17
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
18
+ * Deadline defaults to two hours from `Time.timestamp()`.
18
19
  *
19
20
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
21
  * @param params - Authorization encoding parameters.
22
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
21
23
  * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
22
24
  * @param params.chainId - Target chain id.
23
- * @param params.nonce - The signer's current Morpho authorization nonce.
25
+ * @param params.nonce - The owner's current Morpho authorization nonce.
24
26
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
25
27
  * @param params.deadline - Optional signature deadline in seconds.
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 {NonPositiveInputError} when a provided `deadline` is not positive.
29
32
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
30
33
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
31
34
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
32
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
35
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
36
+ * client account differs from `userAddress`.
33
37
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
34
38
  * @example
35
39
  * ```ts
@@ -39,48 +43,44 @@ const index_js_1 = require("../../../types/index.js");
39
43
  *
40
44
  * const client = createWalletClient({ chain: mainnet, transport: http() });
41
45
  * const requirement = await encodeBlueSignatureAuthorization(client, {
46
+ * owner,
42
47
  * authorized: generalAdapter1,
43
48
  * chainId: 1,
44
49
  * nonce: 0n,
45
50
  * });
46
- * // requirement satisfies Requirement
51
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
47
52
  * ```
48
53
  */
49
54
  const encodeBlueSignatureAuthorization = async (viemClient, params) => {
50
- const { authorized, chainId, nonce, isAuthorized = true } = params;
55
+ const { owner, authorized, chainId, nonce, isAuthorized = true } = params;
51
56
  if (viemClient.chain?.id !== chainId) {
52
57
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
53
58
  }
54
59
  // Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
55
60
  // is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
56
- // `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2TransferFrom` and the
61
+ // `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2SignatureTransfer` and the
57
62
  // `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
58
63
  // from now and is always valid.
59
64
  if (params.deadline != null) {
60
- if (params.deadline <= 0n) {
61
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
62
- }
63
- if (params.deadline > viem_1.maxUint256) {
64
- throw new index_js_1.InputExceedsMaxError({
65
- field: "deadline",
66
- value: params.deadline,
67
- max: viem_1.maxUint256,
68
- });
69
- }
65
+ (0, validate_js_1.validateDeadline)(params.deadline);
70
66
  const timestamp = morpho_ts_1.Time.timestamp();
71
67
  if (params.deadline <= timestamp) {
72
68
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
73
69
  }
74
70
  }
75
71
  const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
72
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
76
73
  const action = {
77
74
  type: "authorization",
78
75
  args: { authorized, isAuthorized, deadline },
76
+ typedData,
79
77
  };
80
78
  return {
81
79
  action,
82
80
  async sign(client, userAddress) {
83
- const typedData = (0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: userAddress, authorized, isAuthorized, nonce, deadline }, chainId);
81
+ // The authorizer is fixed at build time (the fetched nonce is owner-specific), so a different
82
+ // signer cannot produce a valid authorization for it.
83
+ (0, validate_js_1.validateUserAddress)(userAddress, owner);
84
84
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
85
85
  client,
86
86
  userAddress,
@@ -88,7 +88,7 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
88
88
  });
89
89
  return (0, morpho_ts_1.deepFreeze)({
90
90
  args: {
91
- owner: userAddress,
91
+ owner,
92
92
  authorized,
93
93
  isAuthorized,
94
94
  nonce,
@@ -16,7 +16,7 @@ interface EncodeErc20ApprovalParams {
16
16
  * @param params - Encoding parameters.
17
17
  * @param params.token - ERC-20 token address to approve.
18
18
  * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
19
- * Midnight, MidnightBundles, VaultExitBundlesV1, or BlueBundlesV1 for the chain.
19
+ * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
20
20
  * @param params.amount - Allowance amount before per-token cap.
21
21
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
22
22
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -15,7 +15,7 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
15
15
  * @param params - Encoding parameters.
16
16
  * @param params.token - ERC-20 token address to approve.
17
17
  * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
18
- * Midnight, MidnightBundles, VaultExitBundlesV1, or BlueBundlesV1 for the chain.
18
+ * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
19
19
  * @param params.amount - Allowance amount before per-token cap.
20
20
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
21
21
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -46,6 +46,7 @@ const encodeErc20Approval = (params) => {
46
46
  "midnight",
47
47
  "midnightBundles",
48
48
  "vaultExitBundlesV1",
49
+ "vaultBundlesV1",
49
50
  "blueBundlesV1",
50
51
  ],
51
52
  });
@@ -1,9 +1,11 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import { type Client } from "viem";
2
+ import type { Client } from "viem";
3
3
  import { type Erc2612RequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeErc20Permit}. */
5
5
  interface EncodeErc20PermitParams {
6
6
  token: Address;
7
+ /** Account that owns the tokens and signs the permit. */
8
+ owner: Address;
7
9
  spender: Address;
8
10
  amount: bigint;
9
11
  chainId: number;
@@ -17,30 +19,34 @@ interface EncodeErc20PermitParams {
17
19
  *
18
20
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
19
21
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
20
- * the selected transaction route can consume. Deadline defaults to two hours from
21
- * `Time.timestamp()`.
22
+ * the selected transaction route can consume. The requirement's `action.typedData` holds that
23
+ * EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
24
+ * hours from `Time.timestamp()`.
22
25
  *
23
26
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
24
27
  * @param params - Permit encoding parameters.
25
28
  * @param params.token - ERC-20 token address (must support EIP-2612).
26
- * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles, or
27
- * BlueBundlesV1 for the chain.
29
+ * @param params.owner - Account that owns the tokens and signs the permit.
30
+ * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
31
+ * VaultBundlesV1, or BlueBundlesV1 for the chain.
28
32
  * @param params.amount - Permit allowance amount.
29
33
  * @param params.chainId - Target chain id.
30
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
34
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
31
35
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
32
36
  * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
33
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
37
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
38
+ * `sign(client, userAddress)` produces the deep-frozen signature.
34
39
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
40
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
36
41
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
37
- * MidnightBundles, or BlueBundlesV1 for `chainId`.
42
+ * MidnightBundles, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
38
43
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
39
44
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
40
45
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
41
46
  * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
42
47
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
43
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
48
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
49
+ * client account differs from `userAddress`.
44
50
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
45
51
  * @example
46
52
  * ```ts
@@ -51,12 +57,15 @@ interface EncodeErc20PermitParams {
51
57
  * const client = createWalletClient({ chain: mainnet, transport: http() });
52
58
  * const requirement = await encodeErc20Permit(client, {
53
59
  * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
60
+ * owner,
54
61
  * spender: generalAdapter1,
55
62
  * amount: 1_000_000n,
56
63
  * chainId: 1,
57
64
  * nonce: 0n,
58
65
  * });
59
- * // requirement satisfies Requirement
66
+ * // Inspect the EIP-712 payload, then sign via the requirement:
67
+ * const typedData = requirement.action.typedData;
68
+ * const signed = await requirement.sign(client, owner);
60
69
  * ```
61
70
  */
62
71
  export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;