@morpho-org/morpho-sdk 5.9.0 → 6.0.0-next.0

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 (141) hide show
  1. package/MIGRATION-v5-to-v6.md +201 -0
  2. package/README.md +58 -40
  3. package/lib/cjs/actions/blue/borrow.d.ts +62 -61
  4. package/lib/cjs/actions/blue/borrow.js +48 -80
  5. package/lib/cjs/actions/blue/common.d.ts +99 -0
  6. package/lib/cjs/actions/blue/common.js +318 -0
  7. package/lib/cjs/actions/blue/refinance.d.ts +72 -112
  8. package/lib/cjs/actions/blue/refinance.js +97 -199
  9. package/lib/cjs/actions/blue/repay.d.ts +72 -68
  10. package/lib/cjs/actions/blue/repay.js +56 -118
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
  13. package/lib/cjs/actions/blue/supply.d.ts +62 -45
  14. package/lib/cjs/actions/blue/supply.js +94 -70
  15. package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
  16. package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
  17. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
  19. package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
  20. package/lib/cjs/actions/blue/withdraw.js +101 -97
  21. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
  22. package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
  23. package/lib/cjs/actions/index.d.ts +1 -1
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  25. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  26. package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
  27. package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
  28. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  29. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  30. package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
  31. package/lib/cjs/actions/requirements/blue/index.js +2 -0
  32. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  33. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
  40. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  41. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  42. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  43. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
  44. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
  45. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  46. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  47. package/lib/cjs/bundler/actions.d.ts +4 -4
  48. package/lib/cjs/bundler/actions.js +4 -4
  49. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  50. package/lib/cjs/client/morphoViemExtension.js +2 -1
  51. package/lib/cjs/entities/blue/blue.d.ts +806 -374
  52. package/lib/cjs/entities/blue/blue.js +447 -696
  53. package/lib/cjs/entities/index.d.ts +1 -0
  54. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
  55. package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
  56. package/lib/cjs/helpers/validate.d.ts +14 -23
  57. package/lib/cjs/helpers/validate.js +30 -48
  58. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  59. package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
  60. package/lib/cjs/types/action.d.ts +146 -162
  61. package/lib/cjs/types/action.js +29 -2
  62. package/lib/cjs/types/client.d.ts +9 -0
  63. package/lib/cjs/types/error.d.ts +141 -14
  64. package/lib/cjs/types/error.js +198 -21
  65. package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
  66. package/lib/esm/actions/blue/borrow.d.ts +62 -61
  67. package/lib/esm/actions/blue/borrow.js +48 -80
  68. package/lib/esm/actions/blue/common.d.ts +99 -0
  69. package/lib/esm/actions/blue/common.js +306 -0
  70. package/lib/esm/actions/blue/refinance.d.ts +72 -112
  71. package/lib/esm/actions/blue/refinance.js +98 -200
  72. package/lib/esm/actions/blue/repay.d.ts +72 -68
  73. package/lib/esm/actions/blue/repay.js +56 -118
  74. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  75. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  76. package/lib/esm/actions/blue/supply.d.ts +62 -45
  77. package/lib/esm/actions/blue/supply.js +94 -70
  78. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  79. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  80. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  81. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
  82. package/lib/esm/actions/blue/withdraw.d.ts +68 -79
  83. package/lib/esm/actions/blue/withdraw.js +100 -96
  84. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  85. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  86. package/lib/esm/actions/index.d.ts +1 -1
  87. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  88. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  89. package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
  90. package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
  91. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  92. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  93. package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
  94. package/lib/esm/actions/requirements/blue/index.js +2 -0
  95. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  96. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  97. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  98. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
  99. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  100. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
  101. package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
  102. package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
  103. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  104. package/lib/esm/actions/requirements/encode/index.js +1 -0
  105. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  106. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
  107. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
  108. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  109. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  110. package/lib/esm/bundler/actions.d.ts +4 -4
  111. package/lib/esm/bundler/actions.js +4 -4
  112. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  113. package/lib/esm/client/morphoViemExtension.js +2 -1
  114. package/lib/esm/entities/blue/blue.d.ts +806 -374
  115. package/lib/esm/entities/blue/blue.js +453 -702
  116. package/lib/esm/entities/index.d.ts +1 -0
  117. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
  118. package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
  119. package/lib/esm/helpers/validate.d.ts +14 -23
  120. package/lib/esm/helpers/validate.js +30 -48
  121. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  122. package/lib/esm/helpers/validateRequirementSpender.js +2 -0
  123. package/lib/esm/types/action.d.ts +146 -162
  124. package/lib/esm/types/action.js +28 -2
  125. package/lib/esm/types/client.d.ts +9 -0
  126. package/lib/esm/types/error.d.ts +141 -14
  127. package/lib/esm/types/error.js +184 -17
  128. package/lib/esm/types/sharedLiquidity.d.ts +0 -7
  129. package/package.json +4 -3
  130. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  131. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  132. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  133. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  134. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  135. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  136. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  137. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  138. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  139. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  140. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  141. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
@@ -0,0 +1,48 @@
1
+ import { type Address, type Client } from "viem";
2
+ /** Parameters for {@link getUnusedPermit2Nonce}. */
3
+ export interface GetUnusedPermit2NonceParams {
4
+ /** Account that will sign the Permit2 SignatureTransfer. */
5
+ readonly owner: Address;
6
+ /** Target chain id; must match the connected client chain. */
7
+ readonly chainId: number;
8
+ /** Lowest nonce to consider; defaults to 0. */
9
+ readonly startNonce?: bigint;
10
+ }
11
+ /**
12
+ * Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
13
+ * {@link getBlueBundlesV1TokenRequirements} or as `nonce` to {@link encodeErc20Permit2TransferFrom}.
14
+ *
15
+ * Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
16
+ * `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
17
+ * (one RPC read per 256 nonces) and returns the first free nonce, so integrators do not reimplement
18
+ * the scan. Concurrent flows for the same owner should advance `startNonce` (or read once, then
19
+ * partition locally) so two signatures never race on the same owner-global nonce.
20
+ *
21
+ * @param viemClient - Connected viem client used for the bitmap reads.
22
+ * @param params - Lookup parameters.
23
+ * @param params.owner - Account that will sign the SignatureTransfer.
24
+ * @param params.chainId - Target chain id; must match the client chain.
25
+ * @param params.startNonce - Lowest nonce to consider; defaults to 0.
26
+ * @returns The lowest unused Permit2 nonce at or after `startNonce`.
27
+ * @throws {ChainIdMismatchError} when the connected client targets another chain.
28
+ * @throws {NegativeInputError} when `startNonce` is negative.
29
+ * @throws {InputExceedsMaxError} when `startNonce` exceeds `uint256`.
30
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
31
+ * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
32
+ * @throws {viem.BaseError} when a Permit2 nonce-bitmap RPC read fails.
33
+ * @throws {NoUnusedPermit2NonceError} when every nonce at or after `startNonce` is consumed.
34
+ * @example
35
+ * ```ts
36
+ * import { createPublicClient, http, zeroAddress } from "viem";
37
+ * import { mainnet } from "viem/chains";
38
+ * import { getUnusedPermit2Nonce } from "@morpho-org/morpho-sdk";
39
+ *
40
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
41
+ * const permit2Nonce = await getUnusedPermit2Nonce(client, {
42
+ * owner: zeroAddress,
43
+ * chainId: mainnet.id,
44
+ * });
45
+ * // permit2Nonce satisfies bigint
46
+ * ```
47
+ */
48
+ export declare const getUnusedPermit2Nonce: (viemClient: Client, params: GetUnusedPermit2NonceParams) => Promise<bigint>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUnusedPermit2Nonce = 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 index_js_1 = require("../../../helpers/index.js");
9
+ const validate_js_1 = require("../../../helpers/validate.js");
10
+ const index_js_2 = require("../../../types/index.js");
11
+ /** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
12
+ const MAX_PERMIT2_NONCE_WORD = viem_1.maxUint256 >> 8n;
13
+ /**
14
+ * Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
15
+ * {@link getBlueBundlesV1TokenRequirements} or as `nonce` to {@link encodeErc20Permit2TransferFrom}.
16
+ *
17
+ * Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
18
+ * `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
19
+ * (one RPC read per 256 nonces) and returns the first free nonce, so integrators do not reimplement
20
+ * the scan. Concurrent flows for the same owner should advance `startNonce` (or read once, then
21
+ * partition locally) so two signatures never race on the same owner-global nonce.
22
+ *
23
+ * @param viemClient - Connected viem client used for the bitmap reads.
24
+ * @param params - Lookup parameters.
25
+ * @param params.owner - Account that will sign the SignatureTransfer.
26
+ * @param params.chainId - Target chain id; must match the client chain.
27
+ * @param params.startNonce - Lowest nonce to consider; defaults to 0.
28
+ * @returns The lowest unused Permit2 nonce at or after `startNonce`.
29
+ * @throws {ChainIdMismatchError} when the connected client targets another chain.
30
+ * @throws {NegativeInputError} when `startNonce` is negative.
31
+ * @throws {InputExceedsMaxError} when `startNonce` exceeds `uint256`.
32
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
33
+ * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
34
+ * @throws {viem.BaseError} when a Permit2 nonce-bitmap RPC read fails.
35
+ * @throws {NoUnusedPermit2NonceError} when every nonce at or after `startNonce` is consumed.
36
+ * @example
37
+ * ```ts
38
+ * import { createPublicClient, http, zeroAddress } from "viem";
39
+ * import { mainnet } from "viem/chains";
40
+ * import { getUnusedPermit2Nonce } from "@morpho-org/morpho-sdk";
41
+ *
42
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
43
+ * const permit2Nonce = await getUnusedPermit2Nonce(client, {
44
+ * owner: zeroAddress,
45
+ * chainId: mainnet.id,
46
+ * });
47
+ * // permit2Nonce satisfies bigint
48
+ * ```
49
+ */
50
+ const getUnusedPermit2Nonce = async (viemClient, params) => {
51
+ (0, index_js_1.validateChainId)(viemClient.chain?.id, params.chainId);
52
+ const startNonce = params.startNonce ?? 0n;
53
+ (0, validate_js_1.validateUint256Field)("startNonce", startNonce);
54
+ const permit2 = (0, morpho_ts_1.getChainAddress)(params.chainId, "permit2");
55
+ const startWord = startNonce >> 8n;
56
+ for (let word = startWord; word <= MAX_PERMIT2_NONCE_WORD; word++) {
57
+ const bitmap = await (0, actions_1.readContract)(viemClient, {
58
+ abi: blue_sdk_viem_1.permit2Abi,
59
+ address: permit2,
60
+ functionName: "nonceBitmap",
61
+ args: [params.owner, word],
62
+ });
63
+ const firstBit = word === startWord ? startNonce & 255n : 0n;
64
+ for (let bit = firstBit; bit <= 255n; bit++) {
65
+ if ((bitmap & (1n << bit)) === 0n) {
66
+ return (word << 8n) | bit;
67
+ }
68
+ }
69
+ }
70
+ throw new index_js_2.NoUnusedPermit2NonceError(params.owner, startNonce);
71
+ };
72
+ exports.getUnusedPermit2Nonce = getUnusedPermit2Nonce;
@@ -1 +1,3 @@
1
1
  export * from "./getBlueAuthorizationRequirement.js";
2
+ export * from "./getBlueBundlesV1TokenRequirements.js";
3
+ export * from "./getUnusedPermit2Nonce.js";
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
18
+ __exportStar(require("./getBlueBundlesV1TokenRequirements.js"), exports);
19
+ __exportStar(require("./getUnusedPermit2Nonce.js"), exports);
@@ -1,9 +1,9 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import type { Client } from "viem";
2
+ import { type Client } from "viem";
3
3
  import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeBlueSignatureAuthorization}. */
5
5
  interface EncodeBlueSignatureAuthorizationParams {
6
- /** Account to authorize on Morpho (GeneralAdapter1). */
6
+ /** Operator to authorize on Morpho, such as GeneralAdapter1 or BlueBundlesV1. */
7
7
  authorized: Address;
8
8
  /** Target chain id; must match `viemClient.chain.id`. */
9
9
  chainId: number;
@@ -16,23 +16,26 @@ interface EncodeBlueSignatureAuthorizationParams {
16
16
  }
17
17
  /**
18
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.
19
+ * Morpho on the signer's behalf. Bundler3 consumes the result through `setAuthorizationWithSig`;
20
+ * BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
21
21
  *
22
22
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
23
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()`.
24
+ * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
25
+ * from `Time.timestamp()`.
26
26
  *
27
27
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
28
28
  * @param params - Authorization encoding parameters.
29
- * @param params.authorized - Account to authorize (GeneralAdapter1).
29
+ * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
30
30
  * @param params.chainId - Target chain id.
31
31
  * @param params.nonce - The signer's current Morpho authorization nonce.
32
32
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
33
33
  * @param params.deadline - Optional signature deadline in seconds.
34
34
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
35
35
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
36
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
37
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
38
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
36
39
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
37
40
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
38
41
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -3,27 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeBlueSignatureAuthorization = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
6
7
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
8
  const index_js_1 = require("../../../types/index.js");
8
9
  /**
9
10
  * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
10
- * Morpho on the signer's behalf through `setAuthorizationWithSig` — the offchain-signature
11
- * alternative to a standalone `setAuthorization` transaction.
11
+ * Morpho on the signer's behalf. Bundler3 consumes the result through `setAuthorizationWithSig`;
12
+ * BlueBundlesV1 embeds the same signed authorization in its direct-call struct.
12
13
  *
13
14
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
14
15
  * typed data, verifies it against the connected account, and returns a deep-frozen
15
- * `RequirementSignature` the bundler action helpers consume. Deadline defaults to two hours from
16
- * `Time.timestamp()`.
16
+ * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
17
+ * from `Time.timestamp()`.
17
18
  *
18
19
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
19
20
  * @param params - Authorization encoding parameters.
20
- * @param params.authorized - Account to authorize (GeneralAdapter1).
21
+ * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
21
22
  * @param params.chainId - Target chain id.
22
23
  * @param params.nonce - The signer's current Morpho authorization nonce.
23
24
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
24
25
  * @param params.deadline - Optional signature deadline in seconds.
25
26
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
26
27
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
28
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
29
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
30
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
27
31
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
28
32
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
29
33
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -47,6 +51,27 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
47
51
  if (viemClient.chain?.id !== chainId) {
48
52
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
49
53
  }
54
+ // Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
55
+ // is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
56
+ // `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2TransferFrom` and the
57
+ // `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
58
+ // from now and is always valid.
59
+ if (params.deadline != null) {
60
+ if (params.deadline <= 0n) {
61
+ throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
62
+ }
63
+ if (params.deadline > viem_1.maxUint256) {
64
+ throw new index_js_1.InputExceedsMaxError({
65
+ field: "deadline",
66
+ value: params.deadline,
67
+ max: viem_1.maxUint256,
68
+ });
69
+ }
70
+ const timestamp = morpho_ts_1.Time.timestamp();
71
+ if (params.deadline <= timestamp) {
72
+ throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
73
+ }
74
+ }
50
75
  const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
51
76
  const action = {
52
77
  type: "authorization",
@@ -16,10 +16,11 @@ interface EncodeErc20ApprovalParams {
16
16
  * @param params - Encoding parameters.
17
17
  * @param params.token - ERC-20 token address to approve.
18
18
  * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
19
- * Midnight, MidnightBundles, or VaultExitBundlesV1 for the chain.
19
+ * Midnight, MidnightBundles, VaultExitBundlesV1, or BlueBundlesV1 for the chain.
20
20
  * @param params.amount - Allowance amount before per-token cap.
21
21
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
22
22
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
23
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
23
24
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
24
25
  * @example
25
26
  * ```ts
@@ -15,10 +15,11 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
15
15
  * @param params - Encoding parameters.
16
16
  * @param params.token - ERC-20 token address to approve.
17
17
  * @param params.spender - Address granted the allowance. Must be GeneralAdapter1, Permit2,
18
- * Midnight, MidnightBundles, or VaultExitBundlesV1 for the chain.
18
+ * Midnight, MidnightBundles, VaultExitBundlesV1, or BlueBundlesV1 for the chain.
19
19
  * @param params.amount - Allowance amount before per-token cap.
20
20
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
21
21
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
22
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
22
23
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a supported SDK spender for `chainId`.
23
24
  * @example
24
25
  * ```ts
@@ -45,9 +46,13 @@ const encodeErc20Approval = (params) => {
45
46
  "midnight",
46
47
  "midnightBundles",
47
48
  "vaultExitBundlesV1",
49
+ "blueBundlesV1",
48
50
  ],
49
51
  });
50
- const amountValue = blue_sdk_1.MathLib.min(amount, constant_js_1.MAX_TOKEN_APPROVALS[chainId]?.[token] ?? viem_1.maxUint256);
52
+ const amountValue = blue_sdk_1.MathLib.min(amount,
53
+ // Checksum the lookup key so a differently-cased token still resolves its per-token cap
54
+ // instead of falling back to `maxUint256`, which UNI/ONDO/COMP/FLUID reject above `uint96`.
55
+ constant_js_1.MAX_TOKEN_APPROVALS[chainId]?.[(0, viem_1.getAddress)(token)] ?? viem_1.maxUint256);
51
56
  return (0, morpho_ts_1.deepFreeze)({
52
57
  to: token,
53
58
  data: (0, viem_1.encodeFunctionData)({
@@ -1,6 +1,6 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
- import type { Client } from "viem";
3
- import { type PermitRequirementSignature, type Requirement } from "../../../types/index.js";
2
+ import { type Client } from "viem";
3
+ import { type Erc2612RequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeErc20Permit}. */
5
5
  interface EncodeErc20PermitParams {
6
6
  token: Address;
@@ -9,6 +9,7 @@ interface EncodeErc20PermitParams {
9
9
  chainId: number;
10
10
  nonce: bigint;
11
11
  supportDeployless?: boolean;
12
+ deadline?: bigint;
12
13
  }
13
14
  /**
14
15
  * Builds an EIP-2612 permit `Requirement` that, once signed, lets a supported SDK spender pull
@@ -16,20 +17,28 @@ interface EncodeErc20PermitParams {
16
17
  *
17
18
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
18
19
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
19
- * the bundler action helpers can consume. Deadline defaults to two hours from `Time.timestamp()`.
20
+ * the selected transaction route can consume. Deadline defaults to two hours from
21
+ * `Time.timestamp()`.
20
22
  *
21
23
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
22
24
  * @param params - Permit encoding parameters.
23
25
  * @param params.token - ERC-20 token address (must support EIP-2612).
24
- * @param params.spender - Permit spender. Must be GeneralAdapter1 or MidnightBundles for the chain.
26
+ * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles, or
27
+ * BlueBundlesV1 for the chain.
25
28
  * @param params.amount - Permit allowance amount.
26
29
  * @param params.chainId - Target chain id.
27
30
  * @param params.nonce - The user's current EIP-2612 nonce on `token`.
28
31
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
32
+ * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
29
33
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
30
34
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
31
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or
32
- * MidnightBundles for `chainId`.
35
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
36
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
37
+ * MidnightBundles, or BlueBundlesV1 for `chainId`.
38
+ * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
39
+ * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
40
+ * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
41
+ * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
33
42
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
34
43
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
35
44
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -50,5 +59,5 @@ interface EncodeErc20PermitParams {
50
59
  * // requirement satisfies Requirement
51
60
  * ```
52
61
  */
53
- export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<PermitRequirementSignature>>;
62
+ export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;
54
63
  export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeErc20Permit = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
6
7
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
8
  const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
8
9
  const index_js_1 = require("../../../types/index.js");
@@ -12,20 +13,28 @@ const index_js_1 = require("../../../types/index.js");
12
13
  *
13
14
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
14
15
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
15
- * the bundler action helpers can consume. Deadline defaults to two hours from `Time.timestamp()`.
16
+ * the selected transaction route can consume. Deadline defaults to two hours from
17
+ * `Time.timestamp()`.
16
18
  *
17
19
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
18
20
  * @param params - Permit encoding parameters.
19
21
  * @param params.token - ERC-20 token address (must support EIP-2612).
20
- * @param params.spender - Permit spender. Must be GeneralAdapter1 or MidnightBundles for the chain.
22
+ * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles, or
23
+ * BlueBundlesV1 for the chain.
21
24
  * @param params.amount - Permit allowance amount.
22
25
  * @param params.chainId - Target chain id.
23
26
  * @param params.nonce - The user's current EIP-2612 nonce on `token`.
24
27
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
28
+ * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
25
29
  * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
26
30
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
27
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1 or
28
- * MidnightBundles for `chainId`.
31
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
32
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
33
+ * MidnightBundles, or BlueBundlesV1 for `chainId`.
34
+ * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
35
+ * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
36
+ * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
37
+ * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
29
38
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
30
39
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
31
40
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
@@ -54,10 +63,28 @@ const encodeErc20Permit = async (viemClient, params) => {
54
63
  (0, validateRequirementSpender_js_1.validateRequirementSpender)({
55
64
  chainId,
56
65
  spender,
57
- allowed: ["generalAdapter1", "midnightBundles"],
66
+ allowed: ["generalAdapter1", "midnightBundles", "blueBundlesV1"],
58
67
  });
59
68
  const now = morpho_ts_1.Time.timestamp();
60
- const deadline = now + morpho_ts_1.Time.s.from.h(2n);
69
+ // Validate an explicit deadline before the token-metadata read: this exported encoder can be
70
+ // called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
71
+ // deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
72
+ if (params.deadline != null) {
73
+ if (params.deadline <= 0n) {
74
+ throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
75
+ }
76
+ if (params.deadline > viem_1.maxUint256) {
77
+ throw new index_js_1.InputExceedsMaxError({
78
+ field: "deadline",
79
+ value: params.deadline,
80
+ max: viem_1.maxUint256,
81
+ });
82
+ }
83
+ if (params.deadline <= now) {
84
+ throw new index_js_1.ExpiredDeadlineError(params.deadline, now);
85
+ }
86
+ }
87
+ const deadline = params.deadline ?? now + morpho_ts_1.Time.s.from.h(2n);
61
88
  const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
62
89
  deployless: supportDeployless,
63
90
  });
@@ -0,0 +1,61 @@
1
+ import type { Address } from "@morpho-org/blue-sdk";
2
+ import { type Permit2TransferFromRequirementSignature, type Requirement } from "../../../types/index.js";
3
+ /** Parameters for {@link encodeErc20Permit2TransferFrom}. */
4
+ export interface EncodeErc20Permit2TransferFromParams {
5
+ /** ERC-20 token pulled through Permit2. */
6
+ readonly token: Address;
7
+ /** BlueBundlesV1 deployment receiving permission to pull the token. */
8
+ readonly spender: Address;
9
+ /** Exact token amount authorized by the one-time transfer. */
10
+ readonly amount: bigint;
11
+ /** Target chain id. */
12
+ readonly chainId: number;
13
+ /** Unused Permit2 unordered nonce. */
14
+ readonly nonce: bigint;
15
+ /** Signature expiration timestamp in seconds. */
16
+ readonly deadline: bigint;
17
+ }
18
+ /**
19
+ * Builds a Permit2 SignatureTransfer requirement for a direct BlueBundlesV1 token pull.
20
+ *
21
+ * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
22
+ * it has no managed allowance expiration.
23
+ *
24
+ * @param params - SignatureTransfer parameters.
25
+ * @param params.token - ERC-20 token pulled through Permit2.
26
+ * @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
27
+ * @param params.amount - Exact `uint256` token amount authorized.
28
+ * @param params.chainId - Target chain id.
29
+ * @param params.nonce - Unused Permit2 unordered nonce.
30
+ * @param params.deadline - Signature expiration timestamp in seconds.
31
+ * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
32
+ * @throws {NegativeInputError} when `amount` or `nonce` is negative.
33
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
34
+ * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
35
+ * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
36
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
37
+ * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
38
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not BlueBundlesV1 for `chainId`.
39
+ * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
40
+ * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
41
+ * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
42
+ * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
43
+ * @example
44
+ * ```ts
45
+ * import { addressesRegistry } from "@morpho-org/blue-sdk";
46
+ * import { encodeErc20Permit2TransferFrom } from "@morpho-org/morpho-sdk";
47
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
48
+ * import { mainnet } from "viem/chains";
49
+ *
50
+ * const requirement = encodeErc20Permit2TransferFrom({
51
+ * token: addressesRegistry[mainnet.id].usdc,
52
+ * spender: getChainAddress(mainnet.id, "bundles.blueBundlesV1"),
53
+ * amount: 1_000_000n,
54
+ * chainId: mainnet.id,
55
+ * nonce: 0n,
56
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
57
+ * });
58
+ * // requirement satisfies Requirement<Permit2TransferFromRequirementSignature>
59
+ * ```
60
+ */
61
+ export declare const encodeErc20Permit2TransferFrom: (params: EncodeErc20Permit2TransferFromParams) => Requirement<Permit2TransferFromRequirementSignature>;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeErc20Permit2TransferFrom = 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 signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
8
+ const validate_js_1 = require("../../../helpers/validate.js");
9
+ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
10
+ const index_js_1 = require("../../../types/index.js");
11
+ /**
12
+ * Builds a Permit2 SignatureTransfer requirement for a direct BlueBundlesV1 token pull.
13
+ *
14
+ * Unlike Permit2 AllowanceTransfer, this signs a one-time `uint256` amount and unordered nonce;
15
+ * it has no managed allowance expiration.
16
+ *
17
+ * @param params - SignatureTransfer parameters.
18
+ * @param params.token - ERC-20 token pulled through Permit2.
19
+ * @param params.spender - Registered BlueBundlesV1 deployment that performs the pull.
20
+ * @param params.amount - Exact `uint256` token amount authorized.
21
+ * @param params.chainId - Target chain id.
22
+ * @param params.nonce - Unused Permit2 unordered nonce.
23
+ * @param params.deadline - Signature expiration timestamp in seconds.
24
+ * @returns A requirement whose `sign(client, userAddress)` returns a deep-frozen signature result.
25
+ * @throws {NegativeInputError} when `amount` or `nonce` is negative.
26
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
27
+ * @throws {InputExceedsMaxError} when `amount`, `nonce`, or `deadline` exceeds `uint256`.
28
+ * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
29
+ * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
30
+ * @throws {UnknownAddressError} when the chain has no registered canonical Permit2 deployment.
31
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not BlueBundlesV1 for `chainId`.
32
+ * @throws {MissingClientPropertyError} from `sign()` when the wallet client has no account.
33
+ * @throws {AddressMismatchError} from `sign()` when the wallet account differs from `userAddress`.
34
+ * @throws {ChainIdMismatchError} from `sign()` when the wallet chain differs from `chainId`.
35
+ * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
36
+ * @example
37
+ * ```ts
38
+ * import { addressesRegistry } from "@morpho-org/blue-sdk";
39
+ * import { encodeErc20Permit2TransferFrom } from "@morpho-org/morpho-sdk";
40
+ * import { getChainAddress } from "@morpho-org/morpho-ts";
41
+ * import { mainnet } from "viem/chains";
42
+ *
43
+ * const requirement = encodeErc20Permit2TransferFrom({
44
+ * token: addressesRegistry[mainnet.id].usdc,
45
+ * spender: getChainAddress(mainnet.id, "bundles.blueBundlesV1"),
46
+ * amount: 1_000_000n,
47
+ * chainId: mainnet.id,
48
+ * nonce: 0n,
49
+ * deadline: BigInt(Math.floor(Date.now() / 1_000) + 3_600),
50
+ * });
51
+ * // requirement satisfies Requirement<Permit2TransferFromRequirementSignature>
52
+ * ```
53
+ */
54
+ const encodeErc20Permit2TransferFrom = (params) => {
55
+ const { token, spender, amount, chainId, nonce, deadline } = params;
56
+ // Bound every uint256 field before signing: getPermit2TransferFromTypedData silently clamps an
57
+ // oversized allowance to maxUint256, which would desync the signed value from the requirement
58
+ // metadata that blueSupply verifies. Direct callers bypass the token-requirement resolver, so
59
+ // this public encoder must reject the same out-of-range inputs itself.
60
+ (0, validate_js_1.validateUint256Field)("amount", amount);
61
+ (0, validate_js_1.validateUint256Field)("nonce", nonce);
62
+ if (deadline <= 0n) {
63
+ throw new index_js_1.NonPositiveInputError("deadline", deadline);
64
+ }
65
+ if (deadline > viem_1.maxUint256) {
66
+ throw new index_js_1.InputExceedsMaxError({
67
+ field: "deadline",
68
+ value: deadline,
69
+ max: viem_1.maxUint256,
70
+ });
71
+ }
72
+ // Reject an already-expired deadline before signing so a direct caller is never walked through a
73
+ // wallet EIP-712 prompt for a SignatureTransfer that Permit2 would revert with `SignatureExpired`.
74
+ // The sibling encodeErc20Permit and the token-requirement resolver enforce the same guard.
75
+ const timestamp = morpho_ts_1.Time.timestamp();
76
+ if (deadline <= timestamp) {
77
+ throw new index_js_1.ExpiredDeadlineError(deadline, timestamp);
78
+ }
79
+ (0, validateRequirementSpender_js_1.validateRequirementSpender)({
80
+ chainId,
81
+ spender,
82
+ allowed: ["blueBundlesV1"],
83
+ });
84
+ // getPermit2TransferFromTypedData derives its EIP-712 domain's verifyingContract from
85
+ // getChainAddresses(chainId).permit2. A chain that registers BlueBundlesV1 but no canonical Permit2
86
+ // leaves that undefined, and viem drops the undefined field from the domain — the wallet would then
87
+ // sign a domain-less separator that Permit2 can never accept. The resolver gates on permit2 != null;
88
+ // this exported encoder is reachable directly, so it must reject the same unsupported chain itself.
89
+ (0, morpho_ts_1.getChainAddress)(chainId, "permit2"); // throws UnknownAddressError when Permit2 is unregistered
90
+ const action = {
91
+ type: "permit2TransferFrom",
92
+ args: { spender, amount, deadline },
93
+ };
94
+ return {
95
+ action,
96
+ async sign(client, userAddress) {
97
+ const typedData = (0, blue_sdk_viem_1.getPermit2TransferFromTypedData)({
98
+ erc20: token,
99
+ allowance: amount,
100
+ spender,
101
+ nonce,
102
+ deadline,
103
+ }, chainId);
104
+ const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
105
+ client,
106
+ userAddress,
107
+ typedData,
108
+ });
109
+ return (0, morpho_ts_1.deepFreeze)({
110
+ args: {
111
+ owner: userAddress,
112
+ asset: token,
113
+ amount,
114
+ nonce,
115
+ deadline,
116
+ signature,
117
+ },
118
+ action,
119
+ });
120
+ },
121
+ };
122
+ };
123
+ exports.encodeErc20Permit2TransferFrom = encodeErc20Permit2TransferFrom;
@@ -2,4 +2,5 @@ export * from "./encodeBlueSignatureAuthorization.js";
2
2
  export * from "./encodeErc20Approval.js";
3
3
  export * from "./encodeErc20Permit.js";
4
4
  export * from "./encodeErc20Permit2Approve.js";
5
+ export * from "./encodeErc20Permit2TransferFrom.js";
5
6
  export * from "./encodeVaultSharesPermit.js";
@@ -18,4 +18,5 @@ __exportStar(require("./encodeBlueSignatureAuthorization.js"), exports);
18
18
  __exportStar(require("./encodeErc20Approval.js"), exports);
19
19
  __exportStar(require("./encodeErc20Permit.js"), exports);
20
20
  __exportStar(require("./encodeErc20Permit2Approve.js"), exports);
21
+ __exportStar(require("./encodeErc20Permit2TransferFrom.js"), exports);
21
22
  __exportStar(require("./encodeVaultSharesPermit.js"), exports);
@@ -34,4 +34,4 @@ export declare const getGeneralAdapterRequirementsPermit: (viemClient: Client, p
34
34
  };
35
35
  nonce: bigint;
36
36
  supportDeployless?: boolean;
37
- }) => Promise<import("../../../index.js").Requirement<import("../../../index.js").PermitRequirementSignature, undefined>[]>;
37
+ }) => Promise<import("../../../index.js").Requirement<import("../../../index.js").Erc2612RequirementSignature, undefined>[]>;