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