@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/MIGRATION-v5-to-v6.md +199 -34
  2. package/README.md +23 -15
  3. package/lib/cjs/abis.d.ts +3 -2829
  4. package/lib/cjs/abis.js +1 -1938
  5. package/lib/cjs/actions/blue/borrow.d.ts +3 -2
  6. package/lib/cjs/actions/blue/borrow.js +3 -2
  7. package/lib/cjs/actions/blue/common.js +6 -35
  8. package/lib/cjs/actions/blue/refinance.d.ts +2 -2
  9. package/lib/cjs/actions/blue/refinance.js +2 -2
  10. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  11. package/lib/cjs/actions/blue/repay.js +1 -1
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  14. package/lib/cjs/actions/blue/supply.d.ts +2 -2
  15. package/lib/cjs/actions/blue/supply.js +4 -9
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
  17. package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
  20. package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
  21. package/lib/cjs/actions/blue/withdraw.js +3 -3
  22. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
  23. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  24. package/lib/cjs/actions/bundles/common.d.ts +38 -4
  25. package/lib/cjs/actions/bundles/common.js +91 -35
  26. package/lib/cjs/actions/index.d.ts +0 -1
  27. package/lib/cjs/actions/index.js +0 -1
  28. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
  30. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  31. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  32. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  33. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  40. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  41. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  42. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  43. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  44. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  45. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  46. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  47. package/lib/cjs/actions/requirements/index.js +0 -1
  48. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  49. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  50. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
  51. package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
  52. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  53. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  54. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  55. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  56. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
  57. package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
  58. package/lib/cjs/augment.d.ts +0 -1
  59. package/lib/cjs/augment.js +0 -1
  60. package/lib/cjs/blue/abis.d.ts +1 -1
  61. package/lib/cjs/blue/abis.js +1 -5
  62. package/lib/cjs/blue/entities.d.ts +2 -2
  63. package/lib/cjs/blue/entities.js +1 -2
  64. package/lib/cjs/blue/errors.d.ts +1 -1
  65. package/lib/cjs/blue/errors.js +2 -1
  66. package/lib/cjs/blue/fetch.d.ts +1 -1
  67. package/lib/cjs/blue/fetch.js +1 -2
  68. package/lib/cjs/blue/types.d.ts +2 -4
  69. package/lib/cjs/blue/utils.d.ts +1 -3
  70. package/lib/cjs/blue/utils.js +1 -3
  71. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  72. package/lib/cjs/client/morphoViemExtension.js +1 -1
  73. package/lib/cjs/constants.d.ts +3 -37
  74. package/lib/cjs/constants.js +1 -39
  75. package/lib/cjs/entities/blue/blue.d.ts +38 -264
  76. package/lib/cjs/entities/blue/blue.js +2 -203
  77. package/lib/cjs/entities/index.d.ts +3 -60
  78. package/lib/cjs/entities/index.js +1 -20
  79. package/lib/cjs/entities/midnight/midnight.js +20 -24
  80. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  81. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  82. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  83. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  84. package/lib/cjs/entities/requirements/index.js +1 -0
  85. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
  86. package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
  87. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
  88. package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
  89. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  90. package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
  91. package/lib/cjs/errors.d.ts +2 -46
  92. package/lib/cjs/errors.js +2 -46
  93. package/lib/cjs/fetch.d.ts +1 -15
  94. package/lib/cjs/fetch.js +1 -16
  95. package/lib/cjs/helpers/constant.d.ts +0 -2
  96. package/lib/cjs/helpers/constant.js +0 -2
  97. package/lib/cjs/helpers/index.d.ts +4 -3
  98. package/lib/cjs/helpers/index.js +10 -9
  99. package/lib/cjs/helpers/metadata.d.ts +3 -5
  100. package/lib/cjs/helpers/metadata.js +4 -6
  101. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  102. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  103. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  104. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  105. package/lib/cjs/helpers/slippage.d.ts +34 -90
  106. package/lib/cjs/helpers/slippage.js +52 -137
  107. package/lib/cjs/helpers/utilization.d.ts +12 -10
  108. package/lib/cjs/helpers/utilization.js +27 -12
  109. package/lib/cjs/helpers/validate.d.ts +66 -32
  110. package/lib/cjs/helpers/validate.js +84 -57
  111. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  112. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  113. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  114. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  115. package/lib/cjs/types/action.d.ts +102 -68
  116. package/lib/cjs/types/action.js +11 -4
  117. package/lib/cjs/types/error.d.ts +332 -385
  118. package/lib/cjs/types/error.js +369 -412
  119. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  120. package/lib/cjs/types.d.ts +2 -18
  121. package/lib/cjs/utils.d.ts +8 -35
  122. package/lib/cjs/utils.js +11 -36
  123. package/lib/esm/abis.d.ts +3 -2829
  124. package/lib/esm/abis.js +3 -1935
  125. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/borrow.js +3 -2
  127. package/lib/esm/actions/blue/common.js +8 -37
  128. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  129. package/lib/esm/actions/blue/refinance.js +2 -2
  130. package/lib/esm/actions/blue/repay.d.ts +1 -1
  131. package/lib/esm/actions/blue/repay.js +1 -1
  132. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  133. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  134. package/lib/esm/actions/blue/supply.d.ts +2 -2
  135. package/lib/esm/actions/blue/supply.js +6 -11
  136. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  137. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  138. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  139. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  140. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  141. package/lib/esm/actions/blue/withdraw.js +3 -3
  142. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  143. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  144. package/lib/esm/actions/bundles/common.d.ts +38 -4
  145. package/lib/esm/actions/bundles/common.js +91 -36
  146. package/lib/esm/actions/index.d.ts +0 -1
  147. package/lib/esm/actions/index.js +0 -1
  148. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
  149. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
  150. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  151. package/lib/esm/actions/requirements/blue/index.js +0 -1
  152. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
  153. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
  154. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  155. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  156. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
  157. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
  158. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  159. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  160. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  161. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  162. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  163. package/lib/esm/actions/requirements/encode/index.js +0 -1
  164. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  165. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  166. package/lib/esm/actions/requirements/index.d.ts +0 -1
  167. package/lib/esm/actions/requirements/index.js +0 -1
  168. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  169. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  170. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
  171. package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
  172. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  173. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  174. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  175. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  176. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
  177. package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
  178. package/lib/esm/augment.d.ts +0 -1
  179. package/lib/esm/augment.js +0 -1
  180. package/lib/esm/blue/abis.d.ts +1 -1
  181. package/lib/esm/blue/abis.js +1 -1
  182. package/lib/esm/blue/entities.d.ts +2 -2
  183. package/lib/esm/blue/entities.js +1 -1
  184. package/lib/esm/blue/errors.d.ts +1 -1
  185. package/lib/esm/blue/errors.js +1 -1
  186. package/lib/esm/blue/fetch.d.ts +1 -1
  187. package/lib/esm/blue/fetch.js +1 -1
  188. package/lib/esm/blue/types.d.ts +2 -4
  189. package/lib/esm/blue/utils.d.ts +1 -3
  190. package/lib/esm/blue/utils.js +1 -3
  191. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  192. package/lib/esm/client/morphoViemExtension.js +1 -1
  193. package/lib/esm/constants.d.ts +3 -37
  194. package/lib/esm/constants.js +3 -37
  195. package/lib/esm/entities/blue/blue.d.ts +38 -264
  196. package/lib/esm/entities/blue/blue.js +5 -206
  197. package/lib/esm/entities/index.d.ts +3 -60
  198. package/lib/esm/entities/index.js +1 -16
  199. package/lib/esm/entities/midnight/midnight.js +20 -24
  200. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  202. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  203. package/lib/esm/entities/requirements/index.d.ts +1 -0
  204. package/lib/esm/entities/requirements/index.js +1 -0
  205. package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
  206. package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
  207. package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
  208. package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
  209. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  210. package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
  211. package/lib/esm/errors.d.ts +2 -46
  212. package/lib/esm/errors.js +2 -46
  213. package/lib/esm/fetch.d.ts +1 -15
  214. package/lib/esm/fetch.js +1 -15
  215. package/lib/esm/helpers/constant.d.ts +0 -2
  216. package/lib/esm/helpers/constant.js +0 -2
  217. package/lib/esm/helpers/index.d.ts +4 -3
  218. package/lib/esm/helpers/index.js +4 -3
  219. package/lib/esm/helpers/metadata.d.ts +3 -5
  220. package/lib/esm/helpers/metadata.js +4 -6
  221. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  222. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  223. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  224. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  225. package/lib/esm/helpers/slippage.d.ts +34 -90
  226. package/lib/esm/helpers/slippage.js +52 -134
  227. package/lib/esm/helpers/utilization.d.ts +12 -10
  228. package/lib/esm/helpers/utilization.js +26 -11
  229. package/lib/esm/helpers/validate.d.ts +66 -32
  230. package/lib/esm/helpers/validate.js +83 -57
  231. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  232. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  233. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  234. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  235. package/lib/esm/types/action.d.ts +102 -68
  236. package/lib/esm/types/action.js +12 -5
  237. package/lib/esm/types/error.d.ts +332 -385
  238. package/lib/esm/types/error.js +355 -392
  239. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  240. package/lib/esm/types.d.ts +2 -18
  241. package/lib/esm/utils.d.ts +8 -35
  242. package/lib/esm/utils.js +7 -34
  243. package/package.json +7 -15
  244. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  245. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
  246. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  247. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
  248. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  249. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
  250. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  251. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  252. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  253. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  254. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  255. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  256. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  257. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  258. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  259. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
  260. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  261. package/lib/cjs/actions/signatures/index.js +0 -19
  262. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  263. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  264. package/lib/cjs/bundler/actions.d.ts +0 -797
  265. package/lib/cjs/bundler/actions.js +0 -1371
  266. package/lib/cjs/bundler/index.d.ts +0 -2
  267. package/lib/cjs/bundler/index.js +0 -18
  268. package/lib/cjs/bundler/types.d.ts +0 -235
  269. package/lib/cjs/bundler/types.js +0 -2
  270. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
  271. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
  272. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
  273. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
  274. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
  275. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
  276. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  277. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
  278. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
  279. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
  280. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  281. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  282. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  283. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  284. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  285. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  286. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  287. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  288. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
  289. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
  290. package/lib/esm/actions/signatures/index.d.ts +0 -3
  291. package/lib/esm/actions/signatures/index.js +0 -3
  292. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
  293. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
  294. package/lib/esm/bundler/actions.d.ts +0 -797
  295. package/lib/esm/bundler/actions.js +0 -1368
  296. package/lib/esm/bundler/index.d.ts +0 -2
  297. package/lib/esm/bundler/index.js +0 -2
  298. package/lib/esm/bundler/types.d.ts +0 -235
  299. package/lib/esm/bundler/types.js +0 -1
  300. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
  301. package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
  302. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
  303. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
  304. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  305. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -1,243 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computeReallocations = exports.computeVaultV1Reallocations = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const index_js_1 = require("../types/index.js");
6
- const utilization_js_1 = require("./utilization.js");
7
- const validate_js_1 = require("./validate.js");
8
- const groupWithdrawalsByVault = (withdrawals) => {
9
- const groups = [];
10
- const groupsByVault = new Map();
11
- for (const [index, { vault, id, assets }] of withdrawals.entries()) {
12
- if (assets <= 0n)
13
- continue;
14
- let group = groupsByVault.get(vault);
15
- if (group == null) {
16
- group = {
17
- vault,
18
- firstIndex: index,
19
- totalAssets: 0n,
20
- withdrawals: [],
21
- };
22
- groupsByVault.set(vault, group);
23
- groups.push(group);
24
- }
25
- group.totalAssets += assets;
26
- group.withdrawals.push({ id, assets });
27
- }
28
- return groups.sort((a, b) => {
29
- if (a.totalAssets > b.totalAssets)
30
- return -1;
31
- if (a.totalAssets < b.totalAssets)
32
- return 1;
33
- return a.firstIndex - b.firstIndex;
34
- });
35
- };
36
- const capVaultWithdrawals = (withdrawals, assets) => {
37
- const cappedWithdrawals = [];
38
- let remainingAssets = assets;
39
- for (const withdrawal of withdrawals) {
40
- const cappedAssets = blue_sdk_1.MathLib.min(withdrawal.assets, remainingAssets);
41
- /* v8 ignore next: grouped withdrawals and positive reallocation cap keep this defensive guard unreachable. */
42
- if (cappedAssets <= 0n)
43
- continue;
44
- const existing = cappedWithdrawals.find((item) => item.id === withdrawal.id);
45
- if (existing != null) {
46
- existing.assets += cappedAssets;
47
- }
48
- else {
49
- cappedWithdrawals.push({
50
- id: withdrawal.id,
51
- assets: cappedAssets,
52
- });
53
- }
54
- remainingAssets -= cappedAssets;
55
- if (remainingAssets === 0n)
56
- break;
57
- }
58
- return cappedWithdrawals;
59
- };
60
- /**
61
- * Computes vault reallocations for a `borrow` or `withdraw` on a target market.
62
- *
63
- * First attempts "friendly" reallocations respecting withdrawal utilization
64
- * targets, then falls back to aggressive reallocations (100% withdrawal
65
- * utilization) if liquidity is still insufficient.
66
- *
67
- * Algebra branches on `operation`:
68
- * - `"borrow"`: `S' = S`, `B' = B + amount` (additional borrow demand).
69
- * - `"withdraw"`: `S' = S − amount`, `B' = B` (supply-side shrinkage).
70
- *
71
- * In both cases reallocated assets are added on the supply side; `requiredAssets`
72
- * and `absoluteShortfall` are derived from the operation-specific post-state.
73
- *
74
- * @remarks Pass `options.timestamp` from the same block used to fetch `reallocationData`; when omitted, market accrual falls back to the target market's `lastUpdate`, which can diverge from the source rows' fetch block. Per-market `maxWithdrawalUtilization` overrides apply only to phase 1; phase 2 forces 100% utilization on every source market.
75
- * @param params.reallocationData - The local state containing market, vault, and position data.
76
- * @param params.marketId - The target market to reallocate liquidity into.
77
- * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
78
- * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
79
- * @param params.options - Optional reallocation computation options.
80
- * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
81
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
82
- * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
83
- * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
84
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
85
- * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
86
- * @example
87
- * ```ts
88
- * import { createPublicClient, http, parseUnits } from "viem";
89
- * import { mainnet } from "viem/chains";
90
- * import { markets, vaults } from "@morpho-org/morpho-test";
91
- * import {
92
- * computeVaultV1Reallocations,
93
- * morphoViemExtension,
94
- * } from "@morpho-org/morpho-sdk";
95
- *
96
- * const client = createPublicClient({
97
- * chain: mainnet,
98
- * transport: http(),
99
- * }).extend(morphoViemExtension());
100
- *
101
- * const marketParams = markets[mainnet.id].usdc_wbtc;
102
- * const market = client.morpho.blue(marketParams, mainnet.id);
103
- * const block = await client.getBlock();
104
- * const reallocationData = await market.getVaultV1ReallocationData({
105
- * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
106
- * block: { number: block.number, timestamp: block.timestamp },
107
- * });
108
- * const borrowAmount = parseUnits("1000", 6);
109
- * const reallocations = computeVaultV1Reallocations({
110
- * reallocationData,
111
- * marketId: marketParams.id,
112
- * operation: "borrow",
113
- * amount: borrowAmount,
114
- * options: { timestamp: block.timestamp },
115
- * });
116
- * // Encode `reallocations` explicitly with
117
- * // BundlerAction.publicAllocatorReallocateTo(...) when composing a low-level bundle.
118
- * // High-level Blue writes accept Vault V2 reallocations only.
119
- * ```
120
- */
121
- const computeVaultV1Reallocations = ({ reallocationData: data, marketId, operation, amount, options, }) => {
122
- if (options?.enabled === false)
123
- return [];
124
- const normalizedOptions = {
125
- ...options,
126
- reallocatableVaults: options?.reallocatableVaults == null
127
- ? undefined
128
- : [...options.reallocatableVaults],
129
- };
130
- // VaultV1ReallocationData does not retain the fetch block; pass that block timestamp
131
- // to compute against the same accrued state, otherwise Market defaults to lastUpdate.
132
- const market = data
133
- .getMarket(marketId)
134
- .accrueInterest(normalizedOptions.timestamp);
135
- // Reject unreachable withdraws before any utilization math: a negative
136
- // post-supply yields a negative utilization that short-circuits the
137
- // utilization gate below and silently returns `[]` — masking a sure revert.
138
- if (operation === "withdraw" && amount > market.totalSupplyAssets) {
139
- throw new index_js_1.ReallocationWithdrawExceedsMarketSupplyError({
140
- marketId,
141
- withdrawAmount: amount,
142
- totalSupplyAssets: market.totalSupplyAssets,
143
- });
144
- }
145
- // Post-state utilization is operation-dependent.
146
- const newTotalBorrowAssets = operation === "borrow"
147
- ? market.totalBorrowAssets + amount
148
- : market.totalBorrowAssets;
149
- const newTotalSupplyAssets = operation === "withdraw"
150
- ? market.totalSupplyAssets - amount
151
- : market.totalSupplyAssets;
152
- const supplyTargetUtilization = (0, utilization_js_1.getSupplyTargetUtilization)(market.params.id, normalizedOptions);
153
- if (blue_sdk_1.MarketUtils.getUtilization({
154
- totalSupplyAssets: newTotalSupplyAssets,
155
- totalBorrowAssets: newTotalBorrowAssets,
156
- }) <= supplyTargetUtilization)
157
- return [];
158
- // Solve: newTotalBorrowAssets / (newTotalSupplyAssets + reallocatedAssets) = supplyTargetUtilization
159
- let requiredAssets = supplyTargetUtilization === 0n
160
- ? blue_sdk_1.MathLib.MAX_UINT_160
161
- : blue_sdk_1.MathLib.wDivDown(newTotalBorrowAssets, supplyTargetUtilization) -
162
- newTotalSupplyAssets;
163
- // Phase 1: "friendly" reallocations respecting withdrawal utilization targets.
164
- const { withdrawals: friendlyWithdrawals, data: friendlyReallocationData } = data.computeVaultV1Reallocations(market.id, normalizedOptions);
165
- const withdrawals = [...friendlyWithdrawals];
166
- const friendlyReallocationMarket = friendlyReallocationData.getMarket(market.id);
167
- // Operation-specific post-friendly check: would the on-chain call still revert?
168
- const friendlyBorrow = operation === "borrow"
169
- ? friendlyReallocationMarket.totalBorrowAssets + amount
170
- : friendlyReallocationMarket.totalBorrowAssets;
171
- const friendlySupply = operation === "withdraw"
172
- ? friendlyReallocationMarket.totalSupplyAssets - amount
173
- : friendlyReallocationMarket.totalSupplyAssets;
174
- if (friendlyBorrow > friendlySupply) {
175
- // Phase 2: "aggressive" — fully withdraw from every market (100% utilization).
176
- requiredAssets = newTotalBorrowAssets - newTotalSupplyAssets;
177
- withdrawals.push(...friendlyReallocationData.computeVaultV1Reallocations(market.id, {
178
- ...normalizedOptions,
179
- defaultMaxWithdrawalUtilization: blue_sdk_1.MathLib.WAD,
180
- maxWithdrawalUtilization: {},
181
- }).withdrawals);
182
- }
183
- if (requiredAssets <= 0n)
184
- return [];
185
- // Liquidity strictly required for the on-chain call to succeed.
186
- const absoluteShortfall = newTotalBorrowAssets > newTotalSupplyAssets
187
- ? newTotalBorrowAssets - newTotalSupplyAssets
188
- : 0n;
189
- const reallocations = [];
190
- let totalReallocated = 0n;
191
- let remainingRequiredAssets = requiredAssets;
192
- for (const group of groupWithdrawalsByVault(withdrawals)) {
193
- const reallocatedAssets = blue_sdk_1.MathLib.min(group.totalAssets, remainingRequiredAssets);
194
- /* v8 ignore next: groups with non-positive assets are filtered before this point. */
195
- if (reallocatedAssets <= 0n)
196
- continue;
197
- reallocations.push({
198
- vault: group.vault,
199
- withdrawals: capVaultWithdrawals(group.withdrawals, reallocatedAssets),
200
- });
201
- remainingRequiredAssets -= reallocatedAssets;
202
- totalReallocated += reallocatedAssets;
203
- if (remainingRequiredAssets === 0n)
204
- break;
205
- }
206
- // Refuse fee-bearing partial plans for an unreachable operation.
207
- if (totalReallocated < absoluteShortfall) {
208
- throw new index_js_1.InsufficientSharedLiquidityError({
209
- marketId,
210
- shortfall: absoluteShortfall,
211
- available: totalReallocated,
212
- });
213
- }
214
- // Transform into VaultV1Reallocation[] format.
215
- return reallocations
216
- .filter(({ withdrawals: vaultWithdrawals }) => vaultWithdrawals.length > 0)
217
- .map(({ vault, withdrawals: vaultWithdrawals }) => ({
218
- vault,
219
- fee: (() => {
220
- const config = data.getVault(vault).publicAllocatorConfig;
221
- if (config == null) {
222
- throw new index_js_1.MissingPublicAllocatorConfigError(vault);
223
- }
224
- return config.fee;
225
- })(),
226
- withdrawals: vaultWithdrawals
227
- // Reallocation withdrawals must be sorted by market id in ascending
228
- // order. Normalize first because `MarketId` can be mixed-case hex.
229
- .sort(({ id: idA }, { id: idB }) => (0, validate_js_1.compareMarketIds)(idA, idB))
230
- .map(({ id, assets }) => ({
231
- marketParams: data.getMarket(id).params,
232
- amount: assets,
233
- })),
234
- }));
235
- };
236
- exports.computeVaultV1Reallocations = computeVaultV1Reallocations;
237
- /**
238
- * Deprecated name for the Vault V1 amount-aware reallocation planner.
239
- *
240
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
241
- * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
242
- */
243
- exports.computeReallocations = exports.computeVaultV1Reallocations;
@@ -1,42 +0,0 @@
1
- import { type Address } from "@morpho-org/blue-sdk";
2
- import type { PermitRequirementSignature, Requirement } from "../../../types/index.js";
3
- /** Parameters for {@link encodeErc20Permit2Approve}. */
4
- interface EncodeErc20Permit2ApproveParams {
5
- token: Address;
6
- amount: bigint;
7
- chainId: number;
8
- nonce: bigint;
9
- expiration?: bigint;
10
- }
11
- /**
12
- * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
13
- * via the Permit2 contract.
14
- *
15
- * Deadline defaults to two hours from `Time.timestamp()`.
16
- *
17
- * @param params - Permit2 encoding parameters.
18
- * @param params.token - ERC-20 token address.
19
- * @param params.amount - Permit2 allowance amount (per-call).
20
- * @param params.chainId - Target chain id.
21
- * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
22
- * @param params.expiration - Permit2-managed allowance expiration timestamp.
23
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
24
- * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
25
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
26
- * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
27
- * @example
28
- * ```ts
29
- * import { encodeErc20Permit2Approve } from "@morpho-org/morpho-sdk";
30
- *
31
- * const requirement = encodeErc20Permit2Approve({
32
- * token: USDC,
33
- * amount: 1_000_000n,
34
- * chainId: 1,
35
- * nonce: 0n,
36
- * expiration: 281_474_976_710_655n, // MAX_UINT_48 (2^48 - 1, effectively indefinite)
37
- * });
38
- * // requirement satisfies Requirement
39
- * ```
40
- */
41
- export declare const encodeErc20Permit2Approve: (params: EncodeErc20Permit2ApproveParams) => Requirement<PermitRequirementSignature>;
42
- export {};
@@ -1,79 +0,0 @@
1
- import { getChainAddresses, MathLib } from "@morpho-org/blue-sdk";
2
- import { getPermit2PermitTypedData } from "@morpho-org/blue-sdk-viem";
3
- import { deepFreeze, Time } from "@morpho-org/morpho-ts";
4
- import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
5
- /**
6
- * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
7
- * via the Permit2 contract.
8
- *
9
- * Deadline defaults to two hours from `Time.timestamp()`.
10
- *
11
- * @param params - Permit2 encoding parameters.
12
- * @param params.token - ERC-20 token address.
13
- * @param params.amount - Permit2 allowance amount (per-call).
14
- * @param params.chainId - Target chain id.
15
- * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
16
- * @param params.expiration - Permit2-managed allowance expiration timestamp.
17
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
18
- * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
19
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
20
- * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
21
- * @example
22
- * ```ts
23
- * import { encodeErc20Permit2Approve } from "@morpho-org/morpho-sdk";
24
- *
25
- * const requirement = encodeErc20Permit2Approve({
26
- * token: USDC,
27
- * amount: 1_000_000n,
28
- * chainId: 1,
29
- * nonce: 0n,
30
- * expiration: 281_474_976_710_655n, // MAX_UINT_48 (2^48 - 1, effectively indefinite)
31
- * });
32
- * // requirement satisfies Requirement
33
- * ```
34
- */
35
- export const encodeErc20Permit2Approve = (params) => {
36
- const { token, amount, chainId, nonce, expiration = MathLib.MAX_UINT_48, } = params;
37
- const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
38
- const now = Time.timestamp();
39
- const deadline = now + Time.s.from.h(2n);
40
- const action = {
41
- type: "permit2",
42
- args: {
43
- spender: generalAdapter1,
44
- amount,
45
- deadline,
46
- expiration,
47
- },
48
- };
49
- return {
50
- action,
51
- async sign(client, userAddress) {
52
- const typedData = getPermit2PermitTypedData({
53
- spender: generalAdapter1,
54
- allowance: amount,
55
- erc20: token,
56
- nonce: Number(nonce),
57
- deadline,
58
- expiration: Number(expiration),
59
- }, chainId);
60
- const signature = await signAndVerifyTypedData({
61
- client,
62
- userAddress,
63
- typedData,
64
- });
65
- return deepFreeze({
66
- args: {
67
- owner: userAddress,
68
- signature,
69
- deadline,
70
- amount,
71
- asset: token,
72
- expiration,
73
- nonce,
74
- },
75
- action,
76
- });
77
- },
78
- };
79
- };
@@ -1,88 +0,0 @@
1
- import { type Address } from "@morpho-org/blue-sdk";
2
- import { type Client } from "viem";
3
- import type { Bundler3TokenSignatureRequirement, ERC20ApprovalAction, Transaction } from "../../../types/index.js";
4
- /** Shared parameters for GeneralAdapter1 token requirement resolution. */
5
- export type GetGeneralAdapterRequirementsBaseParams = {
6
- address: Address;
7
- chainId: number;
8
- supportDeployless?: boolean;
9
- args: {
10
- amount: bigint;
11
- from: Address;
12
- };
13
- };
14
- /** Parameters for {@link getGeneralAdapterRequirements}. */
15
- export type GetGeneralAdapterRequirementsParams = (GetGeneralAdapterRequirementsBaseParams & {
16
- /** Signature-based approvals are not supported. Classic approval (transaction) will be used. */
17
- supportSignature: false;
18
- }) | (GetGeneralAdapterRequirementsBaseParams & {
19
- /** Signature-based approvals are supported. Will try permit (EIP-2612), else fallback to permit2. */
20
- supportSignature: true;
21
- /**
22
- * Prefer the ERC-2612 simple-permit path when the SDK detects support.
23
- * Leave unset or set to `false` to force the Permit2 fallback when a token is known to be
24
- * incompatible despite passing the SDK's shallow nonce probe.
25
- */
26
- useSimplePermit?: boolean;
27
- });
28
- /**
29
- * Resolves the approval requirements an integrator must satisfy before a bundled action pulls
30
- * tokens through `GeneralAdapter1`.
31
- *
32
- * Reads the minimum token allowance / nonce state needed from the chain, then picks one of three
33
- * flows:
34
- *
35
- * 1. **`supportSignature: false`** — classic ERC-20 `approve` transaction (or no-op when the
36
- * direct allowance is already large enough).
37
- * 2. **`supportSignature: true` + EIP-2612 nonce detected + `useSimplePermit`** — single permit
38
- * signature against the token itself. DAI is excluded from this branch (its non-standard
39
- * permit signature is incompatible) and falls through to Permit2 even with
40
- * `useSimplePermit: true`.
41
- * 3. **`supportSignature: true`, default** — Permit2 flow: classic approval to the Permit2
42
- * contract (if needed), followed by a Permit2 signature against `GeneralAdapter1`.
43
- *
44
- * The simple-permit compatibility check is intentionally shallow: when requested, it probes
45
- * whether the token exposes a readable ERC-2612 `nonces(owner)` value.
46
- * Leaving `useSimplePermit` unset, or passing `false`, is the caller escape hatch for tokens
47
- * that expose `nonces` but are still incompatible with the SDK's ERC-2612 encoder. This opt-out
48
- * has proven useful in the past, but the SDK does not encode a token-specific example here.
49
- * DAI is handled as a built-in version of that incompatibility: it exposes `nonces(owner)` but is
50
- * always routed to Permit2/classic approval instead of DAI-specific permit signing.
51
- *
52
- * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
53
- * @param params - Requirement resolution parameters.
54
- * @param params.address - ERC-20 token address.
55
- * @param params.chainId - Chain id; must match `viemClient.chain.id`.
56
- * @param params.args.amount - Required token amount. Returns `[]` when zero.
57
- * @param params.args.from - Account that will grant the approval.
58
- * @param params.supportSignature - Whether the integrator can collect a signature; controls
59
- * permit / permit2 vs. classic approval.
60
- * @param params.supportDeployless - Whether ERC-2612 permit metadata reads may use deployless multicall.
61
- * @param params.useSimplePermit - When `supportSignature` is `true`, prefer EIP-2612 permit if
62
- * the nonce probe detects support. Leave unset or pass `false` to force the Permit2 fallback
63
- * for tokens known to be incompatible despite passing that probe.
64
- * @returns Promise resolving to an array of either deep-frozen approval transactions or
65
- * `Requirement` objects (signature requirements with a `sign()` method). Empty when `amount`
66
- * is zero or when the classic-approval path can reuse sufficient direct allowance.
67
- * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`. No other typed
68
- * error is reachable through this entry point: the values passed into
69
- * `getRequirementsApproval` always satisfy `approvalAmount >= spendAmount` (direct path uses
70
- * `approvalAmount === spendAmount === amount`; Permit2 path uses `MAX_UINT_160`), so
71
- * `ApprovalAmountLessThanSpendAmountError` cannot fire from here.
72
- * @example
73
- * ```ts
74
- * import { createPublicClient, http } from "viem";
75
- * import { mainnet } from "viem/chains";
76
- * import { getGeneralAdapterRequirements } from "@morpho-org/morpho-sdk";
77
- *
78
- * const client = createPublicClient({ chain: mainnet, transport: http() });
79
- * const requirements = await getGeneralAdapterRequirements(client, {
80
- * address: USDC,
81
- * chainId: 1,
82
- * supportSignature: true,
83
- * args: { amount: 1_000_000n, from: user },
84
- * });
85
- * // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction>> | Bundler3TokenSignatureRequirement)[]
86
- * ```
87
- */
88
- export declare const getGeneralAdapterRequirements: (viemClient: Client, params: GetGeneralAdapterRequirementsParams) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Bundler3TokenSignatureRequirement)[]>;
@@ -1,147 +0,0 @@
1
- import { getChainAddresses } from "@morpho-org/blue-sdk";
2
- import { erc2612Abi, permit2Abi } from "@morpho-org/blue-sdk-viem";
3
- import { isDefined } from "@morpho-org/morpho-ts";
4
- import { erc20Abi, isAddressEqual } from "viem";
5
- import { readContract } from "viem/actions";
6
- import { ChainIdMismatchError } from "../../../types/index.js";
7
- import { getRequirementsApproval } from "../getRequirementsApproval.js";
8
- import { getGeneralAdapterRequirementsPermit } from "./getGeneralAdapterRequirementsPermit.js";
9
- import { getGeneralAdapterRequirementsPermit2 } from "./getGeneralAdapterRequirementsPermit2.js";
10
- /**
11
- * Resolves the approval requirements an integrator must satisfy before a bundled action pulls
12
- * tokens through `GeneralAdapter1`.
13
- *
14
- * Reads the minimum token allowance / nonce state needed from the chain, then picks one of three
15
- * flows:
16
- *
17
- * 1. **`supportSignature: false`** — classic ERC-20 `approve` transaction (or no-op when the
18
- * direct allowance is already large enough).
19
- * 2. **`supportSignature: true` + EIP-2612 nonce detected + `useSimplePermit`** — single permit
20
- * signature against the token itself. DAI is excluded from this branch (its non-standard
21
- * permit signature is incompatible) and falls through to Permit2 even with
22
- * `useSimplePermit: true`.
23
- * 3. **`supportSignature: true`, default** — Permit2 flow: classic approval to the Permit2
24
- * contract (if needed), followed by a Permit2 signature against `GeneralAdapter1`.
25
- *
26
- * The simple-permit compatibility check is intentionally shallow: when requested, it probes
27
- * whether the token exposes a readable ERC-2612 `nonces(owner)` value.
28
- * Leaving `useSimplePermit` unset, or passing `false`, is the caller escape hatch for tokens
29
- * that expose `nonces` but are still incompatible with the SDK's ERC-2612 encoder. This opt-out
30
- * has proven useful in the past, but the SDK does not encode a token-specific example here.
31
- * DAI is handled as a built-in version of that incompatibility: it exposes `nonces(owner)` but is
32
- * always routed to Permit2/classic approval instead of DAI-specific permit signing.
33
- *
34
- * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
35
- * @param params - Requirement resolution parameters.
36
- * @param params.address - ERC-20 token address.
37
- * @param params.chainId - Chain id; must match `viemClient.chain.id`.
38
- * @param params.args.amount - Required token amount. Returns `[]` when zero.
39
- * @param params.args.from - Account that will grant the approval.
40
- * @param params.supportSignature - Whether the integrator can collect a signature; controls
41
- * permit / permit2 vs. classic approval.
42
- * @param params.supportDeployless - Whether ERC-2612 permit metadata reads may use deployless multicall.
43
- * @param params.useSimplePermit - When `supportSignature` is `true`, prefer EIP-2612 permit if
44
- * the nonce probe detects support. Leave unset or pass `false` to force the Permit2 fallback
45
- * for tokens known to be incompatible despite passing that probe.
46
- * @returns Promise resolving to an array of either deep-frozen approval transactions or
47
- * `Requirement` objects (signature requirements with a `sign()` method). Empty when `amount`
48
- * is zero or when the classic-approval path can reuse sufficient direct allowance.
49
- * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`. No other typed
50
- * error is reachable through this entry point: the values passed into
51
- * `getRequirementsApproval` always satisfy `approvalAmount >= spendAmount` (direct path uses
52
- * `approvalAmount === spendAmount === amount`; Permit2 path uses `MAX_UINT_160`), so
53
- * `ApprovalAmountLessThanSpendAmountError` cannot fire from here.
54
- * @example
55
- * ```ts
56
- * import { createPublicClient, http } from "viem";
57
- * import { mainnet } from "viem/chains";
58
- * import { getGeneralAdapterRequirements } from "@morpho-org/morpho-sdk";
59
- *
60
- * const client = createPublicClient({ chain: mainnet, transport: http() });
61
- * const requirements = await getGeneralAdapterRequirements(client, {
62
- * address: USDC,
63
- * chainId: 1,
64
- * supportSignature: true,
65
- * args: { amount: 1_000_000n, from: user },
66
- * });
67
- * // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction>> | Bundler3TokenSignatureRequirement)[]
68
- * ```
69
- */
70
- export const getGeneralAdapterRequirements = async (viemClient, params) => {
71
- const { address, chainId, supportSignature, args: { amount, from }, } = params;
72
- if (viemClient.chain?.id !== chainId) {
73
- throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
74
- }
75
- if (amount === 0n) {
76
- return [];
77
- }
78
- const { permit2, dai, bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
79
- if (supportSignature) {
80
- const { useSimplePermit } = params;
81
- const isDai = isDefined(dai) && isAddressEqual(address, dai);
82
- if (useSimplePermit && !isDai) {
83
- const erc2612Nonce = await readContract(viemClient, {
84
- abi: erc2612Abi,
85
- address,
86
- functionName: "nonces",
87
- args: [from],
88
- }).catch(() => undefined);
89
- if (isDefined(erc2612Nonce)) {
90
- // Do not skip this exact permit because a previous ERC-20 allowance is already enough.
91
- // ERC-2612 overwrites the allowance, and the bundle spends exactly `amount`, so signing
92
- // the pulled amount leaves no residual direct allowance after inclusion.
93
- return getGeneralAdapterRequirementsPermit(viemClient, {
94
- token: address,
95
- chainId,
96
- args: { amount },
97
- nonce: erc2612Nonce,
98
- supportDeployless: params.supportDeployless,
99
- });
100
- }
101
- }
102
- if (permit2) {
103
- // Do not check the existing Permit2-managed amount/expiration. Permit2 allowance signatures
104
- // overwrite the tuple, and the bundle spends exactly `amount`, so a fresh exact signature
105
- // leaves no residual Permit2 allowance. The tuple is still read because Permit2 requires
106
- // its nonce in the signed allowance payload.
107
- const [permit2Erc20Allowance, [, , permit2Nonce]] = await Promise.all([
108
- readContract(viemClient, {
109
- abi: erc20Abi,
110
- address,
111
- functionName: "allowance",
112
- args: [from, permit2],
113
- }),
114
- readContract(viemClient, {
115
- abi: permit2Abi,
116
- address: permit2,
117
- functionName: "allowance",
118
- args: [from, address, generalAdapter1],
119
- }),
120
- ]);
121
- return getGeneralAdapterRequirementsPermit2({
122
- address,
123
- chainId,
124
- permit2,
125
- args: { amount },
126
- erc20Allowances: { permit2: permit2Erc20Allowance },
127
- permit2Nonce: BigInt(permit2Nonce),
128
- });
129
- }
130
- }
131
- const generalAdapterAllowance = await readContract(viemClient, {
132
- abi: erc20Abi,
133
- address,
134
- functionName: "allowance",
135
- args: [from, generalAdapter1],
136
- });
137
- return getRequirementsApproval({
138
- address,
139
- chainId,
140
- args: {
141
- spendAmount: amount,
142
- approvalAmount: amount,
143
- spender: generalAdapter1,
144
- },
145
- allowances: generalAdapterAllowance,
146
- });
147
- };
@@ -1,37 +0,0 @@
1
- import type { Address, Client } from "viem";
2
- /**
3
- * Computes the EIP-2612 permit `Requirement` an integrator must sign so that `GeneralAdapter1`
4
- * can pull `amount` of `token`.
5
- *
6
- * @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
7
- * @param params.token - ERC-20 token address (must support EIP-2612).
8
- * @param params.chainId - The chain the bundle targets.
9
- * @param params.args.amount - Required token amount.
10
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
11
- * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
12
- * @returns A single-element array containing the exact-amount `Requirement` to sign.
13
- * @example
14
- * ```ts
15
- * import { createWalletClient, http } from "viem";
16
- * import { mainnet } from "viem/chains";
17
- * import { getGeneralAdapterRequirementsPermit } from "@morpho-org/morpho-sdk";
18
- *
19
- * const client = createWalletClient({ chain: mainnet, transport: http() });
20
- * const reqs = await getGeneralAdapterRequirementsPermit(client, {
21
- * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
22
- * chainId: 1,
23
- * args: { amount: 1_000_000n },
24
- * nonce: 0n,
25
- * });
26
- * // reqs satisfies Requirement[]
27
- * ```
28
- */
29
- export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, params: {
30
- token: Address;
31
- chainId: number;
32
- args: {
33
- amount: bigint;
34
- };
35
- nonce: bigint;
36
- supportDeployless?: boolean;
37
- }) => Promise<import("../../../index.js").Requirement<import("../../../index.js").Erc2612RequirementSignature, undefined>[]>;