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

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 (277) hide show
  1. package/MIGRATION-v5-to-v6.md +88 -32
  2. package/README.md +9 -7
  3. package/lib/cjs/abis.d.ts +7 -2844
  4. package/lib/cjs/abis.js +3 -1951
  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 +1 -9
  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 +2 -2
  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 +6 -2
  25. package/lib/cjs/actions/bundles/common.js +31 -5
  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 +6 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -16
  30. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
  31. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +6 -11
  36. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  37. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  38. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  39. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  40. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  41. package/lib/cjs/actions/requirements/index.js +0 -1
  42. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  43. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  44. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +7 -5
  45. package/lib/cjs/actions/vaultV1/inKindRedeem.js +11 -7
  46. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  47. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  48. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  49. package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -3
  50. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +7 -5
  51. package/lib/cjs/actions/vaultV2/inKindRedeem.js +11 -7
  52. package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
  53. package/lib/cjs/augment.d.ts +0 -1
  54. package/lib/cjs/augment.js +0 -1
  55. package/lib/cjs/blue/abis.d.ts +5 -5
  56. package/lib/cjs/blue/abis.js +3 -7
  57. package/lib/cjs/blue/entities.d.ts +10 -8
  58. package/lib/cjs/blue/entities.js +3 -3
  59. package/lib/cjs/blue/errors.d.ts +4 -2
  60. package/lib/cjs/blue/errors.js +3 -1
  61. package/lib/cjs/blue/fetch.d.ts +5 -3
  62. package/lib/cjs/blue/fetch.js +3 -3
  63. package/lib/cjs/blue/types.d.ts +2 -4
  64. package/lib/cjs/blue/utils.d.ts +6 -4
  65. package/lib/cjs/blue/utils.js +3 -3
  66. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  67. package/lib/cjs/client/morphoViemExtension.js +1 -1
  68. package/lib/cjs/constants.d.ts +3 -37
  69. package/lib/cjs/constants.js +1 -39
  70. package/lib/cjs/entities/blue/blue.d.ts +30 -265
  71. package/lib/cjs/entities/blue/blue.js +1 -205
  72. package/lib/cjs/entities/index.d.ts +11 -66
  73. package/lib/cjs/entities/index.js +3 -21
  74. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  75. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  76. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +13 -5
  77. package/lib/cjs/entities/vaultV1/vaultV1.js +16 -10
  78. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +40 -19
  79. package/lib/cjs/entities/vaultV2/vaultV2.js +57 -26
  80. package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
  81. package/lib/cjs/errors.d.ts +5 -47
  82. package/lib/cjs/errors.js +4 -46
  83. package/lib/cjs/fetch.d.ts +5 -17
  84. package/lib/cjs/fetch.js +3 -17
  85. package/lib/cjs/helpers/constant.d.ts +0 -2
  86. package/lib/cjs/helpers/constant.js +0 -2
  87. package/lib/cjs/helpers/index.d.ts +2 -3
  88. package/lib/cjs/helpers/index.js +1 -9
  89. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +11 -5
  90. package/lib/cjs/helpers/slippage.d.ts +1 -103
  91. package/lib/cjs/helpers/slippage.js +0 -150
  92. package/lib/cjs/helpers/utilization.d.ts +12 -10
  93. package/lib/cjs/helpers/utilization.js +27 -12
  94. package/lib/cjs/helpers/validate.d.ts +1 -24
  95. package/lib/cjs/helpers/validate.js +2 -49
  96. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  97. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  98. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  99. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  100. package/lib/cjs/midnight/errors.d.ts +1 -1
  101. package/lib/cjs/midnight/errors.js +2 -1
  102. package/lib/cjs/types/action.d.ts +17 -65
  103. package/lib/cjs/types/action.js +11 -4
  104. package/lib/cjs/types/error.d.ts +50 -381
  105. package/lib/cjs/types/error.js +64 -395
  106. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  107. package/lib/cjs/types.d.ts +2 -18
  108. package/lib/cjs/utils.d.ts +10 -35
  109. package/lib/cjs/utils.js +4 -36
  110. package/lib/esm/abis.d.ts +7 -2844
  111. package/lib/esm/abis.js +7 -1950
  112. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  113. package/lib/esm/actions/blue/borrow.js +3 -2
  114. package/lib/esm/actions/blue/common.js +1 -9
  115. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  116. package/lib/esm/actions/blue/refinance.js +2 -2
  117. package/lib/esm/actions/blue/repay.d.ts +1 -1
  118. package/lib/esm/actions/blue/repay.js +1 -1
  119. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  120. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  121. package/lib/esm/actions/blue/supply.d.ts +2 -2
  122. package/lib/esm/actions/blue/supply.js +2 -2
  123. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  124. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  125. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  127. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  128. package/lib/esm/actions/blue/withdraw.js +3 -3
  129. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  130. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  131. package/lib/esm/actions/bundles/common.d.ts +6 -2
  132. package/lib/esm/actions/bundles/common.js +32 -6
  133. package/lib/esm/actions/index.d.ts +0 -1
  134. package/lib/esm/actions/index.js +0 -1
  135. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
  136. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +12 -17
  137. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
  138. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
  139. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  140. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  141. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
  142. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +6 -11
  143. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  144. package/lib/esm/actions/requirements/encode/index.js +0 -1
  145. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  146. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  147. package/lib/esm/actions/requirements/index.d.ts +0 -1
  148. package/lib/esm/actions/requirements/index.js +0 -1
  149. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  150. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  151. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +7 -5
  152. package/lib/esm/actions/vaultV1/inKindRedeem.js +11 -7
  153. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  154. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  155. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  156. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  157. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +7 -5
  158. package/lib/esm/actions/vaultV2/inKindRedeem.js +11 -7
  159. package/lib/esm/augment/AccrualPosition.d.ts +1 -0
  160. package/lib/esm/augment.d.ts +0 -1
  161. package/lib/esm/augment.js +0 -1
  162. package/lib/esm/blue/abis.d.ts +5 -5
  163. package/lib/esm/blue/abis.js +5 -5
  164. package/lib/esm/blue/entities.d.ts +10 -8
  165. package/lib/esm/blue/entities.js +5 -3
  166. package/lib/esm/blue/errors.d.ts +4 -2
  167. package/lib/esm/blue/errors.js +4 -2
  168. package/lib/esm/blue/fetch.d.ts +5 -3
  169. package/lib/esm/blue/fetch.js +5 -3
  170. package/lib/esm/blue/types.d.ts +2 -4
  171. package/lib/esm/blue/utils.d.ts +6 -4
  172. package/lib/esm/blue/utils.js +6 -4
  173. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  174. package/lib/esm/client/morphoViemExtension.js +1 -1
  175. package/lib/esm/constants.d.ts +3 -37
  176. package/lib/esm/constants.js +3 -37
  177. package/lib/esm/entities/blue/blue.d.ts +30 -265
  178. package/lib/esm/entities/blue/blue.js +4 -208
  179. package/lib/esm/entities/index.d.ts +11 -66
  180. package/lib/esm/entities/index.js +5 -18
  181. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  183. package/lib/esm/entities/vaultV1/vaultV1.d.ts +13 -5
  184. package/lib/esm/entities/vaultV1/vaultV1.js +19 -13
  185. package/lib/esm/entities/vaultV2/vaultV2.d.ts +40 -19
  186. package/lib/esm/entities/vaultV2/vaultV2.js +61 -30
  187. package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
  188. package/lib/esm/errors.d.ts +5 -47
  189. package/lib/esm/errors.js +5 -47
  190. package/lib/esm/fetch.d.ts +5 -17
  191. package/lib/esm/fetch.js +5 -17
  192. package/lib/esm/helpers/constant.d.ts +0 -2
  193. package/lib/esm/helpers/constant.js +0 -2
  194. package/lib/esm/helpers/index.d.ts +2 -3
  195. package/lib/esm/helpers/index.js +2 -3
  196. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +11 -5
  197. package/lib/esm/helpers/slippage.d.ts +1 -103
  198. package/lib/esm/helpers/slippage.js +1 -147
  199. package/lib/esm/helpers/utilization.d.ts +12 -10
  200. package/lib/esm/helpers/utilization.js +26 -11
  201. package/lib/esm/helpers/validate.d.ts +1 -24
  202. package/lib/esm/helpers/validate.js +2 -48
  203. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  204. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  205. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  206. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  207. package/lib/esm/midnight/errors.d.ts +1 -1
  208. package/lib/esm/midnight/errors.js +1 -1
  209. package/lib/esm/types/action.d.ts +17 -65
  210. package/lib/esm/types/action.js +12 -5
  211. package/lib/esm/types/error.d.ts +50 -381
  212. package/lib/esm/types/error.js +58 -377
  213. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  214. package/lib/esm/types.d.ts +2 -18
  215. package/lib/esm/utils.d.ts +10 -35
  216. package/lib/esm/utils.js +9 -34
  217. package/package.json +6 -17
  218. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
  219. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -88
  220. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  221. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -152
  222. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
  223. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -53
  224. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  225. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  226. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  227. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  228. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  229. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  230. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  231. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  232. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
  233. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -45
  234. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  235. package/lib/cjs/actions/signatures/index.js +0 -19
  236. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
  237. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  238. package/lib/cjs/bundler/actions.d.ts +0 -797
  239. package/lib/cjs/bundler/actions.js +0 -1371
  240. package/lib/cjs/bundler/index.d.ts +0 -2
  241. package/lib/cjs/bundler/index.js +0 -18
  242. package/lib/cjs/bundler/types.d.ts +0 -235
  243. package/lib/cjs/bundler/types.js +0 -2
  244. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -332
  245. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -557
  246. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -80
  247. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -245
  248. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
  249. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -84
  250. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  251. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -148
  252. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
  253. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -49
  254. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  255. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  256. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  257. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  258. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  259. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  260. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  261. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  262. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
  263. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -41
  264. package/lib/esm/actions/signatures/index.d.ts +0 -3
  265. package/lib/esm/actions/signatures/index.js +0 -3
  266. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
  267. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -7
  268. package/lib/esm/bundler/actions.d.ts +0 -797
  269. package/lib/esm/bundler/actions.js +0 -1368
  270. package/lib/esm/bundler/index.d.ts +0 -2
  271. package/lib/esm/bundler/index.js +0 -2
  272. package/lib/esm/bundler/types.d.ts +0 -235
  273. package/lib/esm/bundler/types.js +0 -1
  274. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -332
  275. package/lib/esm/entities/vaultV1ReallocationData.js +0 -559
  276. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -80
  277. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -241
@@ -1,152 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGeneralAdapterRequirements = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
- const viem_1 = require("viem");
8
- const actions_1 = require("viem/actions");
9
- const index_js_1 = require("../../../types/index.js");
10
- const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
11
- const getGeneralAdapterRequirementsPermit_js_1 = require("./getGeneralAdapterRequirementsPermit.js");
12
- const getGeneralAdapterRequirementsPermit2_js_1 = require("./getGeneralAdapterRequirementsPermit2.js");
13
- /**
14
- * Resolves the approval requirements an integrator must satisfy before a bundled action pulls
15
- * tokens through `GeneralAdapter1`.
16
- *
17
- * Reads the minimum token allowance / nonce state needed from the chain, then picks one of three
18
- * flows:
19
- *
20
- * 1. **`supportSignature: false`** — classic ERC-20 `approve` transaction (or no-op when the
21
- * direct allowance is already large enough).
22
- * 2. **`supportSignature: true` + EIP-2612 nonce detected + `useSimplePermit`** — single permit
23
- * signature against the token itself. DAI is excluded from this branch (its non-standard
24
- * permit signature is incompatible) and falls through to Permit2 even with
25
- * `useSimplePermit: true`.
26
- * 3. **`supportSignature: true`, default** — Permit2 flow: classic approval to the Permit2
27
- * contract (if needed), followed by a Permit2 signature against `GeneralAdapter1`.
28
- *
29
- * The simple-permit compatibility check is intentionally shallow: when requested, it probes
30
- * whether the token exposes a readable ERC-2612 `nonces(owner)` value.
31
- * Leaving `useSimplePermit` unset, or passing `false`, is the caller escape hatch for tokens
32
- * that expose `nonces` but are still incompatible with the SDK's ERC-2612 encoder. This opt-out
33
- * has proven useful in the past, but the SDK does not encode a token-specific example here.
34
- * DAI is handled as a built-in version of that incompatibility: it exposes `nonces(owner)` but is
35
- * always routed to Permit2/classic approval instead of DAI-specific permit signing.
36
- *
37
- * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
38
- * @param params - Requirement resolution parameters.
39
- * @param params.address - ERC-20 token address.
40
- * @param params.chainId - Chain id; must match `viemClient.chain.id`.
41
- * @param params.args.amount - Required token amount. Returns `[]` when zero.
42
- * @param params.args.from - Account that will grant the approval.
43
- * @param params.supportSignature - Whether the integrator can collect a signature; controls
44
- * permit / permit2 vs. classic approval.
45
- * @param params.supportDeployless - Whether ERC-2612 permit metadata reads may use deployless multicall.
46
- * @param params.useSimplePermit - When `supportSignature` is `true`, prefer EIP-2612 permit if
47
- * the nonce probe detects support. Leave unset or pass `false` to force the Permit2 fallback
48
- * for tokens known to be incompatible despite passing that probe.
49
- * @returns Promise resolving to an array of either deep-frozen approval transactions or
50
- * `Requirement` objects (signature requirements with a `sign()` method). Empty when `amount`
51
- * is zero or when the classic-approval path can reuse sufficient direct allowance.
52
- * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`. No other typed
53
- * error is reachable through this entry point: the values passed into
54
- * `getRequirementsApproval` always satisfy `approvalAmount >= spendAmount` (direct path uses
55
- * `approvalAmount === spendAmount === amount`; Permit2 path uses `MAX_UINT_160`), so
56
- * `ApprovalAmountLessThanSpendAmountError` cannot fire from here.
57
- * @example
58
- * ```ts
59
- * import { createPublicClient, http } from "viem";
60
- * import { mainnet } from "viem/chains";
61
- * import { getGeneralAdapterRequirements } from "@morpho-org/morpho-sdk";
62
- *
63
- * const client = createPublicClient({ chain: mainnet, transport: http() });
64
- * const requirements = await getGeneralAdapterRequirements(client, {
65
- * address: USDC,
66
- * chainId: 1,
67
- * supportSignature: true,
68
- * args: { amount: 1_000_000n, from: user },
69
- * });
70
- * // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction>> | Bundler3TokenSignatureRequirement)[]
71
- * ```
72
- */
73
- const getGeneralAdapterRequirements = async (viemClient, params) => {
74
- const { address, chainId, supportSignature, args: { amount, from }, } = params;
75
- if (viemClient.chain?.id !== chainId) {
76
- throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
77
- }
78
- if (amount === 0n) {
79
- return [];
80
- }
81
- const { permit2, dai, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
82
- if (supportSignature) {
83
- const { useSimplePermit } = params;
84
- const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(address, dai);
85
- if (useSimplePermit && !isDai) {
86
- const erc2612Nonce = await (0, actions_1.readContract)(viemClient, {
87
- abi: blue_sdk_viem_1.erc2612Abi,
88
- address,
89
- functionName: "nonces",
90
- args: [from],
91
- }).catch(() => undefined);
92
- if ((0, morpho_ts_1.isDefined)(erc2612Nonce)) {
93
- // Do not skip this exact permit because a previous ERC-20 allowance is already enough.
94
- // ERC-2612 overwrites the allowance, and the bundle spends exactly `amount`, so signing
95
- // the pulled amount leaves no residual direct allowance after inclusion.
96
- return (0, getGeneralAdapterRequirementsPermit_js_1.getGeneralAdapterRequirementsPermit)(viemClient, {
97
- token: address,
98
- owner: from,
99
- chainId,
100
- args: { amount },
101
- nonce: erc2612Nonce,
102
- supportDeployless: params.supportDeployless,
103
- });
104
- }
105
- }
106
- if (permit2) {
107
- // Do not check the existing Permit2-managed amount/expiration. Permit2 allowance signatures
108
- // overwrite the tuple, and the bundle spends exactly `amount`, so a fresh exact signature
109
- // leaves no residual Permit2 allowance. The tuple is still read because Permit2 requires
110
- // its nonce in the signed allowance payload.
111
- const [permit2Erc20Allowance, [, , permit2Nonce]] = await Promise.all([
112
- (0, actions_1.readContract)(viemClient, {
113
- abi: viem_1.erc20Abi,
114
- address,
115
- functionName: "allowance",
116
- args: [from, permit2],
117
- }),
118
- (0, actions_1.readContract)(viemClient, {
119
- abi: blue_sdk_viem_1.permit2Abi,
120
- address: permit2,
121
- functionName: "allowance",
122
- args: [from, address, generalAdapter1],
123
- }),
124
- ]);
125
- return (0, getGeneralAdapterRequirementsPermit2_js_1.getGeneralAdapterRequirementsPermit2)({
126
- address,
127
- chainId,
128
- permit2,
129
- args: { amount },
130
- erc20Allowances: { permit2: permit2Erc20Allowance },
131
- permit2Nonce: BigInt(permit2Nonce),
132
- });
133
- }
134
- }
135
- const generalAdapterAllowance = await (0, actions_1.readContract)(viemClient, {
136
- abi: viem_1.erc20Abi,
137
- address,
138
- functionName: "allowance",
139
- args: [from, generalAdapter1],
140
- });
141
- return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
142
- address,
143
- chainId,
144
- args: {
145
- spendAmount: amount,
146
- approvalAmount: amount,
147
- spender: generalAdapter1,
148
- },
149
- allowances: generalAdapterAllowance,
150
- });
151
- };
152
- exports.getGeneralAdapterRequirements = getGeneralAdapterRequirements;
@@ -1,40 +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.owner - Account that owns the tokens and signs the permit.
9
- * @param params.chainId - The chain the bundle targets.
10
- * @param params.args.amount - Required token amount.
11
- * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
12
- * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
13
- * @returns A single-element array containing the exact-amount `Requirement` to sign.
14
- * @example
15
- * ```ts
16
- * import { createWalletClient, http } from "viem";
17
- * import { mainnet } from "viem/chains";
18
- * import { getGeneralAdapterRequirementsPermit } from "@morpho-org/morpho-sdk";
19
- *
20
- * const client = createWalletClient({ chain: mainnet, transport: http() });
21
- * const reqs = await getGeneralAdapterRequirementsPermit(client, {
22
- * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
23
- * owner,
24
- * chainId: 1,
25
- * args: { amount: 1_000_000n },
26
- * nonce: 0n,
27
- * });
28
- * // reqs satisfies Requirement[]
29
- * ```
30
- */
31
- export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, params: {
32
- token: Address;
33
- owner: Address;
34
- chainId: number;
35
- args: {
36
- amount: bigint;
37
- };
38
- nonce: bigint;
39
- supportDeployless?: boolean;
40
- }) => Promise<import("../../../index.js").Requirement<import("../../../index.js").Erc2612RequirementSignature, undefined>[]>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGeneralAdapterRequirementsPermit = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const index_js_1 = require("../encode/index.js");
6
- /**
7
- * Computes the EIP-2612 permit `Requirement` an integrator must sign so that `GeneralAdapter1`
8
- * can pull `amount` of `token`.
9
- *
10
- * @param viemClient - Connected viem `Client` (used by the returned `Requirement.sign()`).
11
- * @param params.token - ERC-20 token address (must support EIP-2612).
12
- * @param params.owner - Account that owns the tokens and signs the permit.
13
- * @param params.chainId - The chain the bundle targets.
14
- * @param params.args.amount - Required token amount.
15
- * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
16
- * @param params.supportDeployless - Whether to fetch token metadata via deployless multicall.
17
- * @returns A single-element array containing the exact-amount `Requirement` to sign.
18
- * @example
19
- * ```ts
20
- * import { createWalletClient, http } from "viem";
21
- * import { mainnet } from "viem/chains";
22
- * import { getGeneralAdapterRequirementsPermit } from "@morpho-org/morpho-sdk";
23
- *
24
- * const client = createWalletClient({ chain: mainnet, transport: http() });
25
- * const reqs = await getGeneralAdapterRequirementsPermit(client, {
26
- * token: USDC, // an ERC-2612-compatible token; DAI is excluded by getGeneralAdapterRequirements
27
- * owner,
28
- * chainId: 1,
29
- * args: { amount: 1_000_000n },
30
- * nonce: 0n,
31
- * });
32
- * // reqs satisfies Requirement[]
33
- * ```
34
- */
35
- const getGeneralAdapterRequirementsPermit = async (viemClient, params) => {
36
- const { token, owner, chainId, args: { amount }, nonce, supportDeployless, } = params;
37
- const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
38
- // Existing direct ERC-20 allowance is intentionally not an input here. ERC-2612 overwrites the
39
- // allowance with the signed amount, and the bundle spends exactly `amount`, leaving no residual
40
- // allowance after inclusion.
41
- return [
42
- await (0, index_js_1.encodeErc20Permit)(viemClient, {
43
- token,
44
- owner,
45
- spender: generalAdapter1,
46
- amount,
47
- chainId,
48
- nonce,
49
- supportDeployless,
50
- }),
51
- ];
52
- };
53
- exports.getGeneralAdapterRequirementsPermit = getGeneralAdapterRequirementsPermit;
@@ -1,57 +0,0 @@
1
- import { type Address } from "@morpho-org/blue-sdk";
2
- import type { Bundler3TokenSignatureRequirement, ERC20ApprovalAction, Transaction } from "../../../types/index.js";
3
- interface GeneralAdapterPermit2Erc20Allowances {
4
- readonly permit2: bigint;
5
- }
6
- /**
7
- * Computes the Permit2 prerequisites for `GeneralAdapter1` to pull `amount` of `address`.
8
- *
9
- * Emits two ordered prerequisites:
10
- *
11
- * 1. A classic ERC-20 approval to the Permit2 contract (infinite, if not already in place).
12
- * 2. A Permit2 `Requirement` signed against `GeneralAdapter1`.
13
- *
14
- * The Permit2 signature is always requested for the exact transfer amount when this path is
15
- * selected. Permit2 allowance signatures overwrite the existing allowance, so relying on
16
- * residual Permit2-managed allowance would make the final transfer path depend on stale state and
17
- * could leave allowance behind after a partial spend.
18
- *
19
- * @param params.address - ERC-20 token address.
20
- * @param params.chainId - The chain the bundle targets.
21
- * @param params.permit2 - The Permit2 contract address for the chain.
22
- * @param params.args.amount - Required token amount.
23
- * @param params.erc20Allowances - Current ERC-20 allowances keyed by spender contract name.
24
- * @param params.permit2Nonce - Current Permit2 nonce for the token owner / token / GeneralAdapter1 tuple.
25
- * @returns Ordered list of approval transactions and/or `Requirement` objects to satisfy before
26
- * bundling.
27
- * @throws {ApprovalAmountLessThanSpendAmountError} from the inner approval helper when its
28
- * bookkeeping invariants break (should not happen with the values this function passes).
29
- * @example
30
- * ```ts
31
- * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
32
- * import { getGeneralAdapterRequirementsPermit2 } from "@morpho-org/morpho-sdk";
33
- *
34
- * const { permit2 } = getChainAddresses(1);
35
- * if (!permit2) throw new Error("Permit2 not configured for this chain");
36
- * const requirements = getGeneralAdapterRequirementsPermit2({
37
- * address: USDC,
38
- * chainId: 1,
39
- * permit2,
40
- * args: { amount: 1_000_000n },
41
- * erc20Allowances: { permit2: 0n },
42
- * permit2Nonce: 0n,
43
- * });
44
- * // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction> | Bundler3TokenSignatureRequirement>)[]
45
- * ```
46
- */
47
- export declare const getGeneralAdapterRequirementsPermit2: (params: {
48
- address: Address;
49
- chainId: number;
50
- permit2: Address;
51
- args: {
52
- amount: bigint;
53
- };
54
- erc20Allowances: GeneralAdapterPermit2Erc20Allowances;
55
- permit2Nonce: bigint;
56
- }) => Readonly<Transaction<ERC20ApprovalAction> | Bundler3TokenSignatureRequirement>[];
57
- export {};
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGeneralAdapterRequirementsPermit2 = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const encodeErc20Permit2Approve_js_1 = require("../encode/encodeErc20Permit2Approve.js");
6
- const getRequirementsApproval_js_1 = require("../getRequirementsApproval.js");
7
- /**
8
- * Computes the Permit2 prerequisites for `GeneralAdapter1` to pull `amount` of `address`.
9
- *
10
- * Emits two ordered prerequisites:
11
- *
12
- * 1. A classic ERC-20 approval to the Permit2 contract (infinite, if not already in place).
13
- * 2. A Permit2 `Requirement` signed against `GeneralAdapter1`.
14
- *
15
- * The Permit2 signature is always requested for the exact transfer amount when this path is
16
- * selected. Permit2 allowance signatures overwrite the existing allowance, so relying on
17
- * residual Permit2-managed allowance would make the final transfer path depend on stale state and
18
- * could leave allowance behind after a partial spend.
19
- *
20
- * @param params.address - ERC-20 token address.
21
- * @param params.chainId - The chain the bundle targets.
22
- * @param params.permit2 - The Permit2 contract address for the chain.
23
- * @param params.args.amount - Required token amount.
24
- * @param params.erc20Allowances - Current ERC-20 allowances keyed by spender contract name.
25
- * @param params.permit2Nonce - Current Permit2 nonce for the token owner / token / GeneralAdapter1 tuple.
26
- * @returns Ordered list of approval transactions and/or `Requirement` objects to satisfy before
27
- * bundling.
28
- * @throws {ApprovalAmountLessThanSpendAmountError} from the inner approval helper when its
29
- * bookkeeping invariants break (should not happen with the values this function passes).
30
- * @example
31
- * ```ts
32
- * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
33
- * import { getGeneralAdapterRequirementsPermit2 } from "@morpho-org/morpho-sdk";
34
- *
35
- * const { permit2 } = getChainAddresses(1);
36
- * if (!permit2) throw new Error("Permit2 not configured for this chain");
37
- * const requirements = getGeneralAdapterRequirementsPermit2({
38
- * address: USDC,
39
- * chainId: 1,
40
- * permit2,
41
- * args: { amount: 1_000_000n },
42
- * erc20Allowances: { permit2: 0n },
43
- * permit2Nonce: 0n,
44
- * });
45
- * // requirements satisfies (Readonly<Transaction<ERC20ApprovalAction> | Bundler3TokenSignatureRequirement>)[]
46
- * ```
47
- */
48
- const getGeneralAdapterRequirementsPermit2 = (params) => {
49
- const { address, chainId, permit2, args: { amount }, erc20Allowances, permit2Nonce, } = params;
50
- const requirements = [];
51
- const approvalRequirements = (0, getRequirementsApproval_js_1.getRequirementsApproval)({
52
- address,
53
- chainId,
54
- args: {
55
- approvalAmount: blue_sdk_1.MathLib.MAX_UINT_160, // Always approve infinite.
56
- spendAmount: amount,
57
- spender: permit2,
58
- },
59
- allowances: erc20Allowances.permit2,
60
- });
61
- requirements.push(...approvalRequirements);
62
- // Existing Permit2-managed allowance is intentionally not checked for sufficiency. Permit2
63
- // overwrites the allowance with this signed amount, and the bundle spends exactly `amount`,
64
- // leaving no residual Permit2 allowance after inclusion.
65
- requirements.push((0, encodeErc20Permit2Approve_js_1.encodeErc20Permit2Approve)({
66
- token: address,
67
- amount,
68
- chainId,
69
- nonce: permit2Nonce,
70
- expiration: blue_sdk_1.MathLib.MAX_UINT_48, // Always approve indefinitely.
71
- }));
72
- return requirements;
73
- };
74
- exports.getGeneralAdapterRequirementsPermit2 = getGeneralAdapterRequirementsPermit2;
@@ -1,3 +0,0 @@
1
- export * from "./getGeneralAdapterRequirements.js";
2
- export * from "./getGeneralAdapterRequirementsPermit.js";
3
- export * from "./getGeneralAdapterRequirementsPermit2.js";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./getGeneralAdapterRequirements.js"), exports);
18
- __exportStar(require("./getGeneralAdapterRequirementsPermit.js"), exports);
19
- __exportStar(require("./getGeneralAdapterRequirementsPermit2.js"), exports);
@@ -1,29 +0,0 @@
1
- import type { Action } from "../../bundler/index.js";
2
- import { type AuthorizationRequirementSignature } from "../../types/index.js";
3
- /**
4
- * Encodes the bundler action that consumes a signed Morpho authorization, granting
5
- * `authorized` (GeneralAdapter1) operator rights on behalf of the signer via
6
- * `setAuthorizationWithSig` — replacing a standalone `setAuthorization` transaction.
7
- *
8
- * The signature's `authorized` is pinned to the chain's `GeneralAdapter1`: an authorization
9
- * targeting any other account is rejected so the bundle can never hand operator rights over the
10
- * user's Morpho position to an unintended address. The action is emitted with `skipRevert: false`
11
- * so a rejected or stale authorization fails the whole bundle rather than letting a later
12
- * on-behalf Morpho call revert opaquely.
13
- *
14
- * @param chainId - Chain whose `GeneralAdapter1` the signature must authorize.
15
- * @param signature - The signed authorization produced by `Requirement.sign()`.
16
- * @returns A single `morphoSetAuthorizationWithSig` bundler `Action`.
17
- * @throws {BundlerErrors.UnexpectedSignature} when `signature.args.authorized` is not the chain's
18
- * `GeneralAdapter1`.
19
- * @example
20
- * ```ts
21
- * import { getBlueAuthorizationAction } from "@morpho-org/morpho-sdk";
22
- *
23
- * // `requirement` comes from `getBlueAuthorizationRequirement` with `supportSignature: true`.
24
- * const signed = await requirement.sign(walletClient, borrower);
25
- * const action = getBlueAuthorizationAction(1, signed);
26
- * // action satisfies { type: "morphoSetAuthorizationWithSig"; args: [...] }
27
- * ```
28
- */
29
- export declare const getBlueAuthorizationAction: (chainId: number, signature: AuthorizationRequirementSignature) => Action;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBlueAuthorizationAction = void 0;
4
- const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
- const viem_1 = require("viem");
6
- const index_js_1 = require("../../types/index.js");
7
- /**
8
- * Encodes the bundler action that consumes a signed Morpho authorization, granting
9
- * `authorized` (GeneralAdapter1) operator rights on behalf of the signer via
10
- * `setAuthorizationWithSig` — replacing a standalone `setAuthorization` transaction.
11
- *
12
- * The signature's `authorized` is pinned to the chain's `GeneralAdapter1`: an authorization
13
- * targeting any other account is rejected so the bundle can never hand operator rights over the
14
- * user's Morpho position to an unintended address. The action is emitted with `skipRevert: false`
15
- * so a rejected or stale authorization fails the whole bundle rather than letting a later
16
- * on-behalf Morpho call revert opaquely.
17
- *
18
- * @param chainId - Chain whose `GeneralAdapter1` the signature must authorize.
19
- * @param signature - The signed authorization produced by `Requirement.sign()`.
20
- * @returns A single `morphoSetAuthorizationWithSig` bundler `Action`.
21
- * @throws {BundlerErrors.UnexpectedSignature} when `signature.args.authorized` is not the chain's
22
- * `GeneralAdapter1`.
23
- * @example
24
- * ```ts
25
- * import { getBlueAuthorizationAction } from "@morpho-org/morpho-sdk";
26
- *
27
- * // `requirement` comes from `getBlueAuthorizationRequirement` with `supportSignature: true`.
28
- * const signed = await requirement.sign(walletClient, borrower);
29
- * const action = getBlueAuthorizationAction(1, signed);
30
- * // action satisfies { type: "morphoSetAuthorizationWithSig"; args: [...] }
31
- * ```
32
- */
33
- const getBlueAuthorizationAction = (chainId, signature) => {
34
- const { owner, authorized, isAuthorized, nonce, deadline } = signature.args;
35
- const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
36
- if (!(0, viem_1.isAddressEqual)(authorized, generalAdapter1)) {
37
- throw new index_js_1.BundlerErrors.UnexpectedSignature(authorized);
38
- }
39
- return {
40
- type: "morphoSetAuthorizationWithSig",
41
- args: [
42
- { authorizer: owner, authorized, isAuthorized, nonce, deadline },
43
- signature.args.signature,
44
- false /* skipRevert */,
45
- ],
46
- };
47
- };
48
- exports.getBlueAuthorizationAction = getBlueAuthorizationAction;
@@ -1,58 +0,0 @@
1
- import { type Address } from "viem";
2
- import type { Action } from "../../bundler/index.js";
3
- import { type PermitRequirementSignature } from "../../types/index.js";
4
- interface GetTokenRequirementActionsParams {
5
- asset: Address;
6
- amount: bigint;
7
- recipient: Address;
8
- requirementSignature?: PermitRequirementSignature;
9
- }
10
- /**
11
- * Encodes the bundler actions that pull the asset to `recipient`, optionally consuming a
12
- * pre-signed permit / permit2 requirement first.
13
- *
14
- * Permit2 path emits `approve2` + `transferFrom2`; classic permit path emits `permit` +
15
- * `erc20TransferFrom`. When no signature is provided, the function emits a plain
16
- * `erc20TransferFrom` against an existing ERC-20 allowance.
17
- *
18
- * The signed `asset` and `amount` must match the pulled `asset` and `amount` exactly, otherwise
19
- * the function throws so the caller does not silently spend a wider-than-expected approval.
20
- *
21
- * @param params.asset - The ERC-20 to pull.
22
- * @param params.amount - The amount to pull, in the asset's smallest unit.
23
- * @param params.recipient - The address that receives the transfer.
24
- * @param params.requirementSignature - Optional signed permit / permit2 to apply before the transfer.
25
- * @returns Bundler `Action`s needed to pull the token.
26
- * @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
27
- * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
28
- * @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
29
- * @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
30
- * @example
31
- * ```ts
32
- * import { createWalletClient, http } from "viem";
33
- * import { mainnet } from "viem/chains";
34
- * import { getTokenRequirementActions } from "@morpho-org/morpho-sdk";
35
- *
36
- * const walletClient = createWalletClient({
37
- * chain: mainnet,
38
- * transport: http(),
39
- * account: borrower,
40
- * });
41
- *
42
- * // `requirement` comes from a requirement helper; signing produces a `RequirementSignature`.
43
- * const requirementSignature = await requirement.sign(walletClient, borrower);
44
- *
45
- * const actions = getTokenRequirementActions({
46
- * asset: loanToken,
47
- * amount: 1_000_000n,
48
- * recipient: generalAdapter1,
49
- * requirementSignature,
50
- * });
51
- * // actions satisfies Action[]
52
- * // - permit2 path: [{ type: "approve2", ... }, { type: "transferFrom2", ... }]
53
- * // - classic permit path: [{ type: "permit", ... }, { type: "erc20TransferFrom", ... }]
54
- * // - no signature: [{ type: "erc20TransferFrom", ... }]
55
- * ```
56
- */
57
- export declare const getTokenRequirementActions: ({ asset, amount, recipient, requirementSignature, }: GetTokenRequirementActionsParams) => Action[];
58
- export {};
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokenRequirementActions = void 0;
4
- const viem_1 = require("viem");
5
- const index_js_1 = require("../../types/index.js");
6
- /**
7
- * Encodes the bundler actions that pull the asset to `recipient`, optionally consuming a
8
- * pre-signed permit / permit2 requirement first.
9
- *
10
- * Permit2 path emits `approve2` + `transferFrom2`; classic permit path emits `permit` +
11
- * `erc20TransferFrom`. When no signature is provided, the function emits a plain
12
- * `erc20TransferFrom` against an existing ERC-20 allowance.
13
- *
14
- * The signed `asset` and `amount` must match the pulled `asset` and `amount` exactly, otherwise
15
- * the function throws so the caller does not silently spend a wider-than-expected approval.
16
- *
17
- * @param params.asset - The ERC-20 to pull.
18
- * @param params.amount - The amount to pull, in the asset's smallest unit.
19
- * @param params.recipient - The address that receives the transfer.
20
- * @param params.requirementSignature - Optional signed permit / permit2 to apply before the transfer.
21
- * @returns Bundler `Action`s needed to pull the token.
22
- * @throws {DepositAssetMismatchError} when the signed asset differs from `asset`.
23
- * @throws {DepositAmountMismatchError} when the signed amount differs from `amount`.
24
- * @throws {UnexpectedRequirementSignatureError} when passed a BlueBundlesV1-only SignatureTransfer result.
25
- * @throws {Permit2ExpirationMissingError} when `action.type === "permit2"` but `args.expiration` is missing.
26
- * @example
27
- * ```ts
28
- * import { createWalletClient, http } from "viem";
29
- * import { mainnet } from "viem/chains";
30
- * import { getTokenRequirementActions } from "@morpho-org/morpho-sdk";
31
- *
32
- * const walletClient = createWalletClient({
33
- * chain: mainnet,
34
- * transport: http(),
35
- * account: borrower,
36
- * });
37
- *
38
- * // `requirement` comes from a requirement helper; signing produces a `RequirementSignature`.
39
- * const requirementSignature = await requirement.sign(walletClient, borrower);
40
- *
41
- * const actions = getTokenRequirementActions({
42
- * asset: loanToken,
43
- * amount: 1_000_000n,
44
- * recipient: generalAdapter1,
45
- * requirementSignature,
46
- * });
47
- * // actions satisfies Action[]
48
- * // - permit2 path: [{ type: "approve2", ... }, { type: "transferFrom2", ... }]
49
- * // - classic permit path: [{ type: "permit", ... }, { type: "erc20TransferFrom", ... }]
50
- * // - no signature: [{ type: "erc20TransferFrom", ... }]
51
- * ```
52
- */
53
- const getTokenRequirementActions = ({ asset, amount, recipient, requirementSignature, }) => {
54
- if (requirementSignature == null) {
55
- return [
56
- {
57
- type: "erc20TransferFrom",
58
- args: [asset, amount, recipient, false /* skipRevert */],
59
- },
60
- ];
61
- }
62
- if ((0, index_js_1.isPermit2SignatureTransferSignature)(requirementSignature)) {
63
- throw new index_js_1.UnexpectedRequirementSignatureError("permit2SignatureTransfer");
64
- }
65
- if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, asset)) {
66
- throw new index_js_1.DepositAssetMismatchError(asset, requirementSignature.args.asset);
67
- }
68
- // Permit2 and ERC-2612 overwrite the previous allowance with the signed amount.
69
- // It must exactly cover the transfer: less would fail, more would leave residual allowance.
70
- if (requirementSignature.args.amount !== amount) {
71
- throw new index_js_1.DepositAmountMismatchError(amount, requirementSignature.args.amount);
72
- }
73
- if (requirementSignature.action.type === "permit2") {
74
- if (!("expiration" in requirementSignature.args)) {
75
- throw new index_js_1.Permit2ExpirationMissingError();
76
- }
77
- return [
78
- {
79
- type: "approve2",
80
- args: [
81
- requirementSignature.args.owner,
82
- {
83
- details: {
84
- token: requirementSignature.args.asset,
85
- amount: requirementSignature.args.amount,
86
- nonce: Number(requirementSignature.args.nonce),
87
- expiration: Number(requirementSignature.args.expiration),
88
- },
89
- sigDeadline: requirementSignature.args.deadline,
90
- },
91
- requirementSignature.args.signature,
92
- false /* skipRevert */,
93
- ],
94
- },
95
- {
96
- type: "transferFrom2",
97
- args: [asset, amount, recipient, false /* skipRevert */],
98
- },
99
- ];
100
- }
101
- return [
102
- {
103
- type: "permit",
104
- args: [
105
- requirementSignature.args.owner,
106
- requirementSignature.args.asset,
107
- requirementSignature.args.amount,
108
- requirementSignature.args.deadline,
109
- requirementSignature.args.signature,
110
- false /* skipRevert */,
111
- ],
112
- },
113
- {
114
- type: "erc20TransferFrom",
115
- args: [asset, amount, recipient, false /* skipRevert */],
116
- },
117
- ];
118
- };
119
- exports.getTokenRequirementActions = getTokenRequirementActions;