@morpho-org/morpho-sdk 4.2.0 → 5.1.1

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 (191) hide show
  1. package/README.md +16 -16
  2. package/lib/cjs/actions/blue/borrow.d.ts +12 -2
  3. package/lib/cjs/actions/blue/borrow.js +7 -1
  4. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +47 -0
  5. package/lib/cjs/actions/blue/buildAssetFundingActions.js +63 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +13 -3
  7. package/lib/cjs/actions/blue/refinance.js +8 -2
  8. package/lib/cjs/actions/blue/repay.d.ts +44 -43
  9. package/lib/cjs/actions/blue/repay.js +70 -59
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +50 -41
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +75 -54
  12. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +69 -0
  13. package/lib/cjs/actions/blue/resolveRepayFunding.js +82 -0
  14. package/lib/cjs/actions/blue/supply.d.ts +8 -8
  15. package/lib/cjs/actions/blue/supply.js +11 -35
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +9 -9
  17. package/lib/cjs/actions/blue/supplyCollateral.js +12 -36
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +19 -7
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +17 -32
  20. package/lib/cjs/actions/blue/withdraw.d.ts +10 -2
  21. package/lib/cjs/actions/blue/withdraw.js +7 -1
  22. package/lib/cjs/actions/index.d.ts +1 -0
  23. package/lib/cjs/actions/index.js +1 -0
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  25. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +111 -0
  26. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  27. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  28. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  29. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +89 -0
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +17 -5
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +18 -4
  34. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  35. package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +10 -14
  36. package/lib/cjs/actions/requirements/encode/index.d.ts +2 -1
  37. package/lib/cjs/actions/requirements/encode/index.js +2 -1
  38. package/lib/cjs/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  39. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +151 -0
  40. package/lib/{esm/actions/requirements/getRequirementsPermit.d.ts → cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  41. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +50 -0
  42. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  43. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +74 -0
  44. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +3 -0
  45. package/lib/cjs/actions/requirements/generalAdapter/index.js +19 -0
  46. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  47. package/lib/cjs/actions/requirements/getRequirementsApproval.js +3 -2
  48. package/lib/cjs/actions/requirements/index.d.ts +2 -5
  49. package/lib/cjs/actions/requirements/index.js +2 -5
  50. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  51. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +48 -0
  52. package/lib/{esm/actions/requirements/getRequirementsAction.d.ts → cjs/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  53. package/lib/cjs/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +26 -13
  54. package/lib/cjs/actions/signatures/index.d.ts +2 -0
  55. package/lib/cjs/actions/signatures/index.js +18 -0
  56. package/lib/cjs/actions/vaultV1/deposit.d.ts +6 -8
  57. package/lib/cjs/actions/vaultV1/deposit.js +11 -21
  58. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +6 -6
  59. package/lib/cjs/actions/vaultV1/migrateToV2.js +12 -20
  60. package/lib/cjs/actions/vaultV2/deposit.d.ts +6 -8
  61. package/lib/cjs/actions/vaultV2/deposit.js +11 -21
  62. package/lib/cjs/addresses.d.ts +2 -2
  63. package/lib/cjs/addresses.js +2 -1
  64. package/lib/cjs/bundler/actions.d.ts +44 -4
  65. package/lib/cjs/bundler/actions.js +75 -2
  66. package/lib/cjs/bundler/types.d.ts +6 -0
  67. package/lib/cjs/constants.d.ts +2 -2
  68. package/lib/cjs/constants.js +3 -3
  69. package/lib/cjs/entities/blue/blue.d.ts +58 -33
  70. package/lib/cjs/entities/blue/blue.js +309 -189
  71. package/lib/cjs/entities/reallocationData.d.ts +0 -44
  72. package/lib/cjs/entities/reallocationData.js +3 -50
  73. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -9
  74. package/lib/cjs/entities/vaultV1/vaultV1.js +44 -34
  75. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +6 -6
  76. package/lib/cjs/entities/vaultV2/vaultV2.js +21 -16
  77. package/lib/cjs/errors.d.ts +3 -2
  78. package/lib/cjs/errors.js +5 -2
  79. package/lib/cjs/helpers/index.d.ts +1 -1
  80. package/lib/cjs/helpers/index.js +1 -2
  81. package/lib/cjs/helpers/validate.d.ts +2 -20
  82. package/lib/cjs/helpers/validate.js +2 -39
  83. package/lib/cjs/types/action.d.ts +164 -12
  84. package/lib/cjs/types/action.js +79 -5
  85. package/lib/cjs/types/error.d.ts +97 -2
  86. package/lib/cjs/types/error.js +113 -7
  87. package/lib/cjs/types.d.ts +2 -1
  88. package/lib/cjs/utils.d.ts +2 -2
  89. package/lib/cjs/utils.js +2 -4
  90. package/lib/esm/actions/blue/borrow.d.ts +12 -2
  91. package/lib/esm/actions/blue/borrow.js +7 -1
  92. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +47 -0
  93. package/lib/esm/actions/blue/buildAssetFundingActions.js +59 -0
  94. package/lib/esm/actions/blue/refinance.d.ts +13 -3
  95. package/lib/esm/actions/blue/refinance.js +8 -2
  96. package/lib/esm/actions/blue/repay.d.ts +44 -43
  97. package/lib/esm/actions/blue/repay.js +71 -60
  98. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +50 -41
  99. package/lib/esm/actions/blue/repayWithdrawCollateral.js +76 -55
  100. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +69 -0
  101. package/lib/esm/actions/blue/resolveRepayFunding.js +78 -0
  102. package/lib/esm/actions/blue/supply.d.ts +8 -8
  103. package/lib/esm/actions/blue/supply.js +12 -36
  104. package/lib/esm/actions/blue/supplyCollateral.d.ts +9 -9
  105. package/lib/esm/actions/blue/supplyCollateral.js +13 -37
  106. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +19 -7
  107. package/lib/esm/actions/blue/supplyCollateralBorrow.js +18 -33
  108. package/lib/esm/actions/blue/withdraw.d.ts +10 -2
  109. package/lib/esm/actions/blue/withdraw.js +7 -1
  110. package/lib/esm/actions/index.d.ts +1 -0
  111. package/lib/esm/actions/index.js +1 -0
  112. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +49 -0
  113. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +107 -0
  114. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  115. package/lib/esm/actions/requirements/blue/index.js +1 -0
  116. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +55 -0
  117. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +85 -0
  118. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +6 -5
  119. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +19 -7
  120. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +9 -7
  121. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +20 -6
  122. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.d.ts → encodeErc20Permit2Approve.d.ts} +11 -13
  123. package/lib/esm/actions/requirements/encode/{encodeErc20Permit2.js → encodeErc20Permit2Approve.js} +8 -12
  124. package/lib/esm/actions/requirements/encode/index.d.ts +2 -1
  125. package/lib/esm/actions/requirements/encode/index.js +2 -1
  126. package/lib/esm/actions/requirements/{getRequirements.d.ts → generalAdapter/getGeneralAdapterRequirements.d.ts} +34 -20
  127. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +147 -0
  128. package/lib/{cjs/actions/requirements/getRequirementsPermit.d.ts → esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts} +6 -14
  129. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +46 -0
  130. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +57 -0
  131. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +70 -0
  132. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +3 -0
  133. package/lib/esm/actions/requirements/generalAdapter/index.js +3 -0
  134. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  135. package/lib/esm/actions/requirements/getRequirementsApproval.js +3 -2
  136. package/lib/esm/actions/requirements/index.d.ts +2 -5
  137. package/lib/esm/actions/requirements/index.js +2 -5
  138. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +29 -0
  139. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +44 -0
  140. package/lib/{cjs/actions/requirements/getRequirementsAction.d.ts → esm/actions/signatures/getTokenRequirementActions.d.ts} +17 -17
  141. package/lib/esm/actions/{requirements/getRequirementsAction.js → signatures/getTokenRequirementActions.js} +24 -11
  142. package/lib/esm/actions/signatures/index.d.ts +2 -0
  143. package/lib/esm/actions/signatures/index.js +2 -0
  144. package/lib/esm/actions/vaultV1/deposit.d.ts +6 -8
  145. package/lib/esm/actions/vaultV1/deposit.js +11 -21
  146. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +6 -6
  147. package/lib/esm/actions/vaultV1/migrateToV2.js +12 -20
  148. package/lib/esm/actions/vaultV2/deposit.d.ts +6 -8
  149. package/lib/esm/actions/vaultV2/deposit.js +11 -21
  150. package/lib/esm/addresses.d.ts +2 -2
  151. package/lib/esm/addresses.js +1 -1
  152. package/lib/esm/bundler/actions.d.ts +44 -4
  153. package/lib/esm/bundler/actions.js +77 -4
  154. package/lib/esm/bundler/types.d.ts +6 -0
  155. package/lib/esm/constants.d.ts +2 -2
  156. package/lib/esm/constants.js +2 -2
  157. package/lib/esm/entities/blue/blue.d.ts +58 -33
  158. package/lib/esm/entities/blue/blue.js +311 -191
  159. package/lib/esm/entities/reallocationData.d.ts +0 -44
  160. package/lib/esm/entities/reallocationData.js +2 -49
  161. package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -9
  162. package/lib/esm/entities/vaultV1/vaultV1.js +46 -36
  163. package/lib/esm/entities/vaultV2/vaultV2.d.ts +6 -6
  164. package/lib/esm/entities/vaultV2/vaultV2.js +23 -18
  165. package/lib/esm/errors.d.ts +3 -2
  166. package/lib/esm/errors.js +2 -1
  167. package/lib/esm/helpers/index.d.ts +1 -1
  168. package/lib/esm/helpers/index.js +1 -1
  169. package/lib/esm/helpers/validate.d.ts +2 -20
  170. package/lib/esm/helpers/validate.js +2 -38
  171. package/lib/esm/types/action.d.ts +164 -12
  172. package/lib/esm/types/action.js +75 -4
  173. package/lib/esm/types/error.d.ts +97 -2
  174. package/lib/esm/types/error.js +107 -5
  175. package/lib/esm/types.d.ts +2 -1
  176. package/lib/esm/utils.d.ts +2 -2
  177. package/lib/esm/utils.js +2 -2
  178. package/package.json +22 -21
  179. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  180. package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +0 -71
  181. package/lib/cjs/actions/requirements/getRequirements.js +0 -112
  182. package/lib/cjs/actions/requirements/getRequirementsPermit.js +0 -57
  183. package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  184. package/lib/cjs/actions/requirements/getRequirementsPermit2.js +0 -85
  185. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -37
  186. package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +0 -67
  187. package/lib/esm/actions/requirements/getRequirements.js +0 -108
  188. package/lib/esm/actions/requirements/getRequirementsPermit.js +0 -53
  189. package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +0 -63
  190. package/lib/esm/actions/requirements/getRequirementsPermit2.js +0 -81
  191. package/src/index.ts +0 -4
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBlueAuthorizationRequirement = 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 index_js_1 = require("../../../types/index.js");
9
+ const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSignatureAuthorization.js");
10
+ /**
11
+ * Resolves whether `GeneralAdapter1` needs Blue authorization for the given user, and returns
12
+ * the requirement to satisfy it when it does.
13
+ *
14
+ * Reads `Morpho.isAuthorized(userAddress, generalAdapter1)` on the target chain. Required before
15
+ * any bundled Blue path that operates on behalf of the user (`borrow`, `withdraw`,
16
+ * `supplyCollateralBorrow`, `repayWithdrawCollateral`, `refinance`).
17
+ *
18
+ * - When `supportSignature` is falsy (default), returns the
19
+ * `setAuthorization(generalAdapter1, true)` transaction the user submits before the bundle.
20
+ * - When `supportSignature` is `true`, reads the user's Morpho `nonce` and returns a signable
21
+ * `Requirement`; the signed authorization is folded into the bundle via
22
+ * `setAuthorizationWithSig`, removing the standalone transaction.
23
+ *
24
+ * @param params.viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
25
+ * @param params.chainId - Target chain id (used to resolve Morpho and `GeneralAdapter1`).
26
+ * @param params.userAddress - The user that must authorize `GeneralAdapter1`.
27
+ * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
28
+ * transaction so authorization can be bundled via `setAuthorizationWithSig`.
29
+ * @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
30
+ * `Requirement` (when `supportSignature` is `true`), or `null` when authorization is already in
31
+ * place.
32
+ * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
33
+ * @example
34
+ * ```ts
35
+ * import { createPublicClient, http } from "viem";
36
+ * import { mainnet } from "viem/chains";
37
+ * import { getBlueAuthorizationRequirement } from "@morpho-org/morpho-sdk";
38
+ *
39
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
40
+ * const requirement = await getBlueAuthorizationRequirement({
41
+ * viemClient: client,
42
+ * chainId: 1,
43
+ * userAddress: borrower,
44
+ * supportSignature: true,
45
+ * });
46
+ * // requirement is null when already authorized, a Requirement when supportSignature is true,
47
+ * // otherwise Readonly<Transaction<BlueAuthorizationAction>>
48
+ * ```
49
+ */
50
+ const getBlueAuthorizationRequirement = async (params) => {
51
+ const { viemClient, chainId, userAddress, supportSignature } = params;
52
+ if (viemClient.chain?.id !== chainId) {
53
+ throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
54
+ }
55
+ const { morpho, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
56
+ const pc = viemClient.extend(viem_1.publicActions);
57
+ if (supportSignature) {
58
+ // The signable path needs the user's Morpho nonce; fetch it alongside the
59
+ // authorization status so both reads share a round-trip (batched into a
60
+ // single multicall when the client enables batching) instead of
61
+ // serializing the nonce read behind isAuthorized.
62
+ const [isAuthorized, nonce] = await Promise.all([
63
+ pc.readContract({
64
+ address: morpho,
65
+ abi: blue_sdk_viem_1.blueAbi,
66
+ functionName: "isAuthorized",
67
+ args: [userAddress, generalAdapter1],
68
+ }),
69
+ pc.readContract({
70
+ address: morpho,
71
+ abi: blue_sdk_viem_1.blueAbi,
72
+ functionName: "nonce",
73
+ args: [userAddress],
74
+ }),
75
+ ]);
76
+ if (isAuthorized) {
77
+ return null;
78
+ }
79
+ return (0, encodeBlueSignatureAuthorization_js_1.encodeBlueSignatureAuthorization)(viemClient, {
80
+ authorized: generalAdapter1,
81
+ chainId,
82
+ nonce,
83
+ });
84
+ }
85
+ const isAuthorized = await pc.readContract({
86
+ address: morpho,
87
+ abi: blue_sdk_viem_1.blueAbi,
88
+ functionName: "isAuthorized",
89
+ args: [userAddress, generalAdapter1],
90
+ });
91
+ if (isAuthorized) {
92
+ return null;
93
+ }
94
+ return (0, morpho_ts_1.deepFreeze)({
95
+ to: morpho,
96
+ data: (0, viem_1.encodeFunctionData)({
97
+ abi: blue_sdk_viem_1.blueAbi,
98
+ functionName: "setAuthorization",
99
+ args: [generalAdapter1, true],
100
+ }),
101
+ value: 0n,
102
+ action: {
103
+ type: "blueAuthorization",
104
+ args: {
105
+ authorized: generalAdapter1,
106
+ isAuthorized: true,
107
+ },
108
+ },
109
+ });
110
+ };
111
+ exports.getBlueAuthorizationRequirement = getBlueAuthorizationRequirement;
@@ -0,0 +1 @@
1
+ export * from "./getBlueAuthorizationRequirement.js";
@@ -0,0 +1,17 @@
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("./getBlueAuthorizationRequirement.js"), exports);
@@ -0,0 +1,55 @@
1
+ import type { Address } from "@morpho-org/blue-sdk";
2
+ import { type Client } from "viem";
3
+ import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
4
+ /** Parameters for {@link encodeBlueSignatureAuthorization}. */
5
+ interface EncodeBlueSignatureAuthorizationParams {
6
+ /** Account to authorize on Morpho (GeneralAdapter1). */
7
+ authorized: Address;
8
+ /** Target chain id; must match `viemClient.chain.id`. */
9
+ chainId: number;
10
+ /** The signer's current Morpho authorization nonce. */
11
+ nonce: bigint;
12
+ /** Whether to grant (`true`, default) or revoke (`false`) the authorization. */
13
+ isAuthorized?: boolean;
14
+ /** Signature deadline in seconds. Defaults to two hours from now. */
15
+ deadline?: bigint;
16
+ }
17
+ /**
18
+ * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
19
+ * Morpho on the signer's behalf through `setAuthorizationWithSig` — the offchain-signature
20
+ * alternative to a standalone `setAuthorization` transaction.
21
+ *
22
+ * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
23
+ * typed data, verifies it against the connected account, and returns a deep-frozen
24
+ * `RequirementSignature` the bundler action helpers consume. Deadline defaults to two hours from
25
+ * `Time.timestamp()`.
26
+ *
27
+ * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
28
+ * @param params - Authorization encoding parameters.
29
+ * @param params.authorized - Account to authorize (GeneralAdapter1).
30
+ * @param params.chainId - Target chain id.
31
+ * @param params.nonce - The signer's current Morpho authorization nonce.
32
+ * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
33
+ * @param params.deadline - Optional signature deadline in seconds.
34
+ * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
35
+ * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
36
+ * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
37
+ * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
38
+ * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
39
+ * @example
40
+ * ```ts
41
+ * import { createWalletClient, http } from "viem";
42
+ * import { mainnet } from "viem/chains";
43
+ * import { encodeBlueSignatureAuthorization } from "@morpho-org/morpho-sdk";
44
+ *
45
+ * const client = createWalletClient({ chain: mainnet, transport: http() });
46
+ * const requirement = await encodeBlueSignatureAuthorization(client, {
47
+ * authorized: generalAdapter1,
48
+ * chainId: 1,
49
+ * nonce: 0n,
50
+ * });
51
+ * // requirement satisfies Requirement
52
+ * ```
53
+ */
54
+ export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
55
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeBlueSignatureAuthorization = void 0;
4
+ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const actions_1 = require("viem/actions");
8
+ const validate_js_1 = require("../../../helpers/validate.js");
9
+ const index_js_1 = require("../../../types/index.js");
10
+ /**
11
+ * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
12
+ * Morpho on the signer's behalf through `setAuthorizationWithSig` — the offchain-signature
13
+ * alternative to a standalone `setAuthorization` transaction.
14
+ *
15
+ * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
16
+ * typed data, verifies it against the connected account, and returns a deep-frozen
17
+ * `RequirementSignature` the bundler action helpers consume. Deadline defaults to two hours from
18
+ * `Time.timestamp()`.
19
+ *
20
+ * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
21
+ * @param params - Authorization encoding parameters.
22
+ * @param params.authorized - Account to authorize (GeneralAdapter1).
23
+ * @param params.chainId - Target chain id.
24
+ * @param params.nonce - The signer's current Morpho authorization nonce.
25
+ * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
26
+ * @param params.deadline - Optional signature deadline in seconds.
27
+ * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
28
+ * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
29
+ * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
30
+ * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
31
+ * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
32
+ * @example
33
+ * ```ts
34
+ * import { createWalletClient, http } from "viem";
35
+ * import { mainnet } from "viem/chains";
36
+ * import { encodeBlueSignatureAuthorization } from "@morpho-org/morpho-sdk";
37
+ *
38
+ * const client = createWalletClient({ chain: mainnet, transport: http() });
39
+ * const requirement = await encodeBlueSignatureAuthorization(client, {
40
+ * authorized: generalAdapter1,
41
+ * chainId: 1,
42
+ * nonce: 0n,
43
+ * });
44
+ * // requirement satisfies Requirement
45
+ * ```
46
+ */
47
+ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
48
+ const { authorized, chainId, nonce, isAuthorized = true } = params;
49
+ if (viemClient.chain?.id !== chainId) {
50
+ throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
51
+ }
52
+ const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
53
+ const action = {
54
+ type: "authorization",
55
+ args: { authorized, isAuthorized, deadline },
56
+ };
57
+ return {
58
+ action,
59
+ async sign(client, userAddress) {
60
+ const account = client.account;
61
+ (0, validate_js_1.validateUserAddress)(account?.address, userAddress);
62
+ const typedData = (0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: userAddress, authorized, isAuthorized, nonce, deadline }, chainId);
63
+ const signature = await (0, actions_1.signTypedData)(client, {
64
+ ...typedData,
65
+ account,
66
+ });
67
+ const isValid = await (0, viem_1.verifyTypedData)({
68
+ ...typedData,
69
+ address: userAddress, // Verify against the authorizer.
70
+ signature,
71
+ });
72
+ if (!isValid) {
73
+ throw new index_js_1.InvalidSignatureError();
74
+ }
75
+ return (0, morpho_ts_1.deepFreeze)({
76
+ args: {
77
+ owner: userAddress,
78
+ authorized,
79
+ isAuthorized,
80
+ nonce,
81
+ deadline,
82
+ signature,
83
+ },
84
+ action,
85
+ });
86
+ },
87
+ };
88
+ };
89
+ exports.encodeBlueSignatureAuthorization = encodeBlueSignatureAuthorization;
@@ -1,5 +1,5 @@
1
1
  import { type Address } from "@morpho-org/blue-sdk";
2
- import type { ERC20ApprovalAction, Transaction } from "../../../types/index.js";
2
+ import { type ERC20ApprovalAction, type Transaction } from "../../../types/index.js";
3
3
  /** Parameters for {@link encodeErc20Approval}. */
4
4
  interface EncodeErc20ApprovalParams {
5
5
  token: Address;
@@ -8,17 +8,18 @@ interface EncodeErc20ApprovalParams {
8
8
  chainId: number;
9
9
  }
10
10
  /**
11
- * Encodes a deep-frozen ERC-20 `approve(spender, amount)` transaction.
11
+ * Encodes a deep-frozen ERC-20 approval transaction for GeneralAdapter1 or Permit2.
12
12
  *
13
13
  * Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
14
- * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getRequirementsPermit2}.
14
+ * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getGeneralAdapterRequirementsPermit2}.
15
15
  *
16
16
  * @param params - Encoding parameters.
17
17
  * @param params.token - ERC-20 token address to approve.
18
- * @param params.spender - Address granted the allowance.
18
+ * @param params.spender - Address granted the allowance. Must be GeneralAdapter1 or Permit2.
19
19
  * @param params.amount - Allowance amount before per-token cap.
20
- * @param params.chainId - The chain the transaction targets (used to resolve the per-token cap).
20
+ * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
21
21
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
22
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or Permit2 for `chainId`.
22
23
  * @example
23
24
  * ```ts
24
25
  * import { encodeErc20Approval } from "@morpho-org/morpho-sdk";
@@ -5,18 +5,20 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
7
  const constant_js_1 = require("../../../helpers/constant.js");
8
+ const index_js_1 = require("../../../types/index.js");
8
9
  /**
9
- * Encodes a deep-frozen ERC-20 `approve(spender, amount)` transaction.
10
+ * Encodes a deep-frozen ERC-20 approval transaction for GeneralAdapter1 or Permit2.
10
11
  *
11
12
  * Caps `amount` at the per-chain, per-token maximum from `MAX_TOKEN_APPROVALS` (defaults to
12
- * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getRequirementsPermit2}.
13
+ * `maxUint256`). Used by {@link getRequirementsApproval} and {@link getGeneralAdapterRequirementsPermit2}.
13
14
  *
14
15
  * @param params - Encoding parameters.
15
16
  * @param params.token - ERC-20 token address to approve.
16
- * @param params.spender - Address granted the allowance.
17
+ * @param params.spender - Address granted the allowance. Must be GeneralAdapter1 or Permit2.
17
18
  * @param params.amount - Allowance amount before per-token cap.
18
- * @param params.chainId - The chain the transaction targets (used to resolve the per-token cap).
19
+ * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
19
20
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
21
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or Permit2 for `chainId`.
20
22
  * @example
21
23
  * ```ts
22
24
  * import { encodeErc20Approval } from "@morpho-org/morpho-sdk";
@@ -32,6 +34,16 @@ const constant_js_1 = require("../../../helpers/constant.js");
32
34
  */
33
35
  const encodeErc20Approval = (params) => {
34
36
  const { token, spender, amount, chainId } = params;
37
+ const { permit2, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
38
+ if (!(0, viem_1.isAddressEqual)(spender, generalAdapter1) &&
39
+ (permit2 == null || !(0, viem_1.isAddressEqual)(spender, permit2))) {
40
+ throw new index_js_1.UnsupportedErc20ApprovalSpenderError({
41
+ spender,
42
+ chainId,
43
+ generalAdapter1,
44
+ permit2,
45
+ });
46
+ }
35
47
  const amountValue = blue_sdk_1.MathLib.min(amount, constant_js_1.MAX_TOKEN_APPROVALS[chainId]?.[token] ?? viem_1.maxUint256);
36
48
  return (0, morpho_ts_1.deepFreeze)({
37
49
  to: token,
@@ -43,7 +55,7 @@ const encodeErc20Approval = (params) => {
43
55
  value: 0n,
44
56
  action: {
45
57
  type: "erc20Approval",
46
- args: { spender: spender, amount: amountValue },
58
+ args: { spender, amount: amountValue },
47
59
  },
48
60
  });
49
61
  };
@@ -1,6 +1,6 @@
1
- import type { Address } from "@morpho-org/blue-sdk";
1
+ import { type Address } from "@morpho-org/blue-sdk";
2
2
  import { type Client } from "viem";
3
- import { type Requirement } from "../../../types/index.js";
3
+ import { type PermitRequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeErc20Permit}. */
5
5
  interface EncodeErc20PermitParams {
6
6
  token: Address;
@@ -11,8 +11,8 @@ interface EncodeErc20PermitParams {
11
11
  supportDeployless?: boolean;
12
12
  }
13
13
  /**
14
- * Builds an EIP-2612 permit `Requirement` that, once signed, lets `spender` pull `amount` of
15
- * `token`.
14
+ * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
15
+ * `amount` of `token`.
16
16
  *
17
17
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
18
18
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
@@ -21,13 +21,15 @@ interface EncodeErc20PermitParams {
21
21
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
22
22
  * @param params - Permit encoding parameters.
23
23
  * @param params.token - ERC-20 token address (must support EIP-2612).
24
- * @param params.spender - Address that will be granted the permit allowance.
24
+ * @param params.spender - Permit spender. Must be GeneralAdapter1 or MidnightBundles for the chain.
25
25
  * @param params.amount - Permit allowance amount.
26
26
  * @param params.chainId - Target chain id.
27
27
  * @param params.nonce - The user's current EIP-2612 nonce on `token`.
28
28
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
29
29
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
30
30
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
31
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or
32
+ * MidnightBundles for `chainId`.
31
33
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
32
34
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
33
35
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -39,7 +41,7 @@ interface EncodeErc20PermitParams {
39
41
  *
40
42
  * const client = createWalletClient({ chain: mainnet, transport: http() });
41
43
  * const requirement = await encodeErc20Permit(client, {
42
- * token: USDC, // L1 mainnet USDC. Bridged USDC.e on L2s often does not implement EIP-2612 — query token metadata before signing on other chains. DAI uses a non-standard permit signature.
44
+ * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
43
45
  * spender: generalAdapter1,
44
46
  * amount: 1_000_000n,
45
47
  * chainId: 1,
@@ -48,5 +50,5 @@ interface EncodeErc20PermitParams {
48
50
  * // requirement satisfies Requirement
49
51
  * ```
50
52
  */
51
- export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement>;
53
+ export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<PermitRequirementSignature>>;
52
54
  export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeErc20Permit = void 0;
4
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
4
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
7
  const viem_1 = require("viem");
@@ -8,8 +9,8 @@ const actions_1 = require("viem/actions");
8
9
  const validate_js_1 = require("../../../helpers/validate.js");
9
10
  const index_js_1 = require("../../../types/index.js");
10
11
  /**
11
- * Builds an EIP-2612 permit `Requirement` that, once signed, lets `spender` pull `amount` of
12
- * `token`.
12
+ * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
13
+ * `amount` of `token`.
13
14
  *
14
15
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
15
16
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
@@ -18,13 +19,15 @@ const index_js_1 = require("../../../types/index.js");
18
19
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
19
20
  * @param params - Permit encoding parameters.
20
21
  * @param params.token - ERC-20 token address (must support EIP-2612).
21
- * @param params.spender - Address that will be granted the permit allowance.
22
+ * @param params.spender - Permit spender. Must be GeneralAdapter1 or MidnightBundles for the chain.
22
23
  * @param params.amount - Permit allowance amount.
23
24
  * @param params.chainId - Target chain id.
24
25
  * @param params.nonce - The user's current EIP-2612 nonce on `token`.
25
26
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
26
27
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
27
28
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
29
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or
30
+ * MidnightBundles for `chainId`.
28
31
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
29
32
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
30
33
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -36,7 +39,7 @@ const index_js_1 = require("../../../types/index.js");
36
39
  *
37
40
  * const client = createWalletClient({ chain: mainnet, transport: http() });
38
41
  * const requirement = await encodeErc20Permit(client, {
39
- * token: USDC, // L1 mainnet USDC. Bridged USDC.e on L2s often does not implement EIP-2612 — query token metadata before signing on other chains. DAI uses a non-standard permit signature.
42
+ * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
40
43
  * spender: generalAdapter1,
41
44
  * amount: 1_000_000n,
42
45
  * chainId: 1,
@@ -50,6 +53,17 @@ const encodeErc20Permit = async (viemClient, params) => {
50
53
  if (viemClient.chain?.id !== chainId) {
51
54
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
52
55
  }
56
+ const { midnightBundles, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
57
+ if (!(0, viem_1.isAddressEqual)(spender, generalAdapter1) &&
58
+ (midnightBundles == null || !(0, viem_1.isAddressEqual)(spender, midnightBundles))) {
59
+ throw new index_js_1.UnsupportedErc20ApprovalSpenderError({
60
+ spender,
61
+ chainId,
62
+ generalAdapter1,
63
+ midnightBundles,
64
+ supportedSpenders: [generalAdapter1, midnightBundles],
65
+ });
66
+ }
53
67
  const now = morpho_ts_1.Time.timestamp();
54
68
  const deadline = now + morpho_ts_1.Time.s.from.h(2n);
55
69
  const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
@@ -1,25 +1,23 @@
1
1
  import { type Address } from "@morpho-org/blue-sdk";
2
- import { type Requirement } from "../../../types/index.js";
3
- /** Parameters for {@link encodeErc20Permit2}. */
4
- interface EncodeErc20Permit2Params {
2
+ import { type PermitRequirementSignature, type Requirement } from "../../../types/index.js";
3
+ /** Parameters for {@link encodeErc20Permit2Approve}. */
4
+ interface EncodeErc20Permit2ApproveParams {
5
5
  token: Address;
6
6
  amount: bigint;
7
7
  chainId: number;
8
8
  nonce: bigint;
9
- expiration: bigint;
9
+ expiration?: bigint;
10
10
  }
11
11
  /**
12
- * Builds a Permit2 `Requirement` that, once signed, lets `GeneralAdapter1` pull `amount` of
13
- * `token` via the Permit2 contract.
12
+ * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
13
+ * via the Permit2 contract.
14
14
  *
15
- * The Permit2 spender is hardcoded to `GeneralAdapter1` for the resolved chain — never another
16
- * address — otherwise the resulting signature could be reused independently of the Morpho
17
- * bundle. Deadline defaults to two hours from `Time.timestamp()`.
15
+ * Deadline defaults to two hours from `Time.timestamp()`.
18
16
  *
19
17
  * @param params - Permit2 encoding parameters.
20
18
  * @param params.token - ERC-20 token address.
21
19
  * @param params.amount - Permit2 allowance amount (per-call).
22
- * @param params.chainId - Target chain id (resolves `GeneralAdapter1`).
20
+ * @param params.chainId - Target chain id.
23
21
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
24
22
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
25
23
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
@@ -28,9 +26,9 @@ interface EncodeErc20Permit2Params {
28
26
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
29
27
  * @example
30
28
  * ```ts
31
- * import { encodeErc20Permit2 } from "@morpho-org/morpho-sdk";
29
+ * import { encodeErc20Permit2Approve } from "@morpho-org/morpho-sdk";
32
30
  *
33
- * const requirement = encodeErc20Permit2({
31
+ * const requirement = encodeErc20Permit2Approve({
34
32
  * token: USDC,
35
33
  * amount: 1_000_000n,
36
34
  * chainId: 1,
@@ -40,5 +38,5 @@ interface EncodeErc20Permit2Params {
40
38
  * // requirement satisfies Requirement
41
39
  * ```
42
40
  */
43
- export declare const encodeErc20Permit2: (params: EncodeErc20Permit2Params) => Requirement;
41
+ export declare const encodeErc20Permit2Approve: (params: EncodeErc20Permit2ApproveParams) => Requirement<PermitRequirementSignature>;
44
42
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeErc20Permit2 = void 0;
3
+ exports.encodeErc20Permit2Approve = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
@@ -9,17 +9,15 @@ const actions_1 = require("viem/actions");
9
9
  const validate_js_1 = require("../../../helpers/validate.js");
10
10
  const index_js_1 = require("../../../types/index.js");
11
11
  /**
12
- * Builds a Permit2 `Requirement` that, once signed, lets `GeneralAdapter1` pull `amount` of
13
- * `token` via the Permit2 contract.
12
+ * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
13
+ * via the Permit2 contract.
14
14
  *
15
- * The Permit2 spender is hardcoded to `GeneralAdapter1` for the resolved chain — never another
16
- * address — otherwise the resulting signature could be reused independently of the Morpho
17
- * bundle. Deadline defaults to two hours from `Time.timestamp()`.
15
+ * Deadline defaults to two hours from `Time.timestamp()`.
18
16
  *
19
17
  * @param params - Permit2 encoding parameters.
20
18
  * @param params.token - ERC-20 token address.
21
19
  * @param params.amount - Permit2 allowance amount (per-call).
22
- * @param params.chainId - Target chain id (resolves `GeneralAdapter1`).
20
+ * @param params.chainId - Target chain id.
23
21
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
24
22
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
25
23
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
@@ -28,9 +26,9 @@ const index_js_1 = require("../../../types/index.js");
28
26
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
29
27
  * @example
30
28
  * ```ts
31
- * import { encodeErc20Permit2 } from "@morpho-org/morpho-sdk";
29
+ * import { encodeErc20Permit2Approve } from "@morpho-org/morpho-sdk";
32
30
  *
33
- * const requirement = encodeErc20Permit2({
31
+ * const requirement = encodeErc20Permit2Approve({
34
32
  * token: USDC,
35
33
  * amount: 1_000_000n,
36
34
  * chainId: 1,
@@ -40,11 +38,11 @@ const index_js_1 = require("../../../types/index.js");
40
38
  * // requirement satisfies Requirement
41
39
  * ```
42
40
  */
43
- const encodeErc20Permit2 = (params) => {
41
+ const encodeErc20Permit2Approve = (params) => {
44
42
  const { token, amount, chainId, nonce, expiration = blue_sdk_1.MathLib.MAX_UINT_48, } = params;
43
+ const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
45
44
  const now = morpho_ts_1.Time.timestamp();
46
45
  const deadline = now + morpho_ts_1.Time.s.from.h(2n);
47
- const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
48
46
  const action = {
49
47
  type: "permit2",
50
48
  args: {
@@ -60,8 +58,6 @@ const encodeErc20Permit2 = (params) => {
60
58
  const account = client.account;
61
59
  (0, validate_js_1.validateUserAddress)(account?.address, userAddress);
62
60
  const typedData = (0, blue_sdk_viem_1.getPermit2PermitTypedData)({
63
- // Never permit any other address than the GeneralAdapter1 otherwise
64
- // the signature can be used independently.
65
61
  spender: generalAdapter1,
66
62
  allowance: amount,
67
63
  erc20: token,
@@ -96,4 +92,4 @@ const encodeErc20Permit2 = (params) => {
96
92
  },
97
93
  };
98
94
  };
99
- exports.encodeErc20Permit2 = encodeErc20Permit2;
95
+ exports.encodeErc20Permit2Approve = encodeErc20Permit2Approve;
@@ -1,3 +1,4 @@
1
+ export * from "./encodeBlueSignatureAuthorization.js";
1
2
  export * from "./encodeErc20Approval.js";
2
3
  export * from "./encodeErc20Permit.js";
3
- export * from "./encodeErc20Permit2.js";
4
+ export * from "./encodeErc20Permit2Approve.js";
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./encodeBlueSignatureAuthorization.js"), exports);
17
18
  __exportStar(require("./encodeErc20Approval.js"), exports);
18
19
  __exportStar(require("./encodeErc20Permit.js"), exports);
19
- __exportStar(require("./encodeErc20Permit2.js"), exports);
20
+ __exportStar(require("./encodeErc20Permit2Approve.js"), exports);