@morpho-org/morpho-sdk 9.4.0 → 9.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/MIGRATION-v5-to-v6.md +7 -0
  2. package/MIGRATION-v7-to-v8.md +7 -0
  3. package/MIGRATION-v8-to-v9.md +7 -0
  4. package/README.md +6 -4
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
  6. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
  7. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -1
  8. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
  9. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  10. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  11. package/lib/cjs/client/morphoViemExtension.js +1 -1
  12. package/lib/cjs/entities/blue/blue.d.ts +7 -21
  13. package/lib/cjs/entities/blue/blue.js +4 -22
  14. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +21 -26
  15. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +42 -80
  16. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
  17. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +2 -2
  18. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +5 -11
  19. package/lib/cjs/entities/vaultV1/vaultV1.js +3 -11
  20. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +5 -11
  21. package/lib/cjs/entities/vaultV2/vaultV2.js +3 -11
  22. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -0
  23. package/lib/cjs/entities/vaultV2BlueReallocationData.js +40 -4
  24. package/lib/cjs/types/action.d.ts +11 -4
  25. package/lib/cjs/types/action.js +1 -0
  26. package/lib/cjs/types/error.d.ts +8 -2
  27. package/lib/cjs/types/error.js +8 -2
  28. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
  29. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
  30. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +4 -1
  31. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
  32. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  33. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  34. package/lib/esm/client/morphoViemExtension.js +1 -1
  35. package/lib/esm/entities/blue/blue.d.ts +7 -21
  36. package/lib/esm/entities/blue/blue.js +4 -22
  37. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +21 -26
  38. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +44 -82
  39. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
  40. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +2 -2
  41. package/lib/esm/entities/vaultV1/vaultV1.d.ts +5 -11
  42. package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
  43. package/lib/esm/entities/vaultV2/vaultV2.d.ts +5 -11
  44. package/lib/esm/entities/vaultV2/vaultV2.js +4 -12
  45. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -0
  46. package/lib/esm/entities/vaultV2BlueReallocationData.js +40 -4
  47. package/lib/esm/types/action.d.ts +11 -4
  48. package/lib/esm/types/action.js +1 -0
  49. package/lib/esm/types/error.d.ts +8 -2
  50. package/lib/esm/types/error.js +8 -2
  51. package/package.json +3 -3
@@ -1,5 +1,12 @@
1
1
  # Migrating `@morpho-org/morpho-sdk` from v5 to v6
2
2
 
3
+ > Current funding behavior: the SDK no longer requests Permit2 funding. Use ERC-2612 permits
4
+ > (`supportSignature: true`, with `useSimplePermit` defaulting to true) or direct ERC-20 approvals.
5
+ > Pass `useSimplePermit: false` to force approvals. The legacy
6
+ > `permit2Nonce` option is deprecated and ignored; builders still accept previously collected
7
+ > signatures. Permit2 requirement descriptions below document historical behavior.
8
+
9
+
3
10
  Version 6 keeps the Blue entity at `client.morpho.blue(marketParams, chainId)` and preserves its
4
11
  write-method names while routing them through five direct BlueBundlesV1 entrypoints. Blue reads and
5
12
  the Vault V2 reallocation-data helper remain on the same entity. There is no parallel
@@ -1,5 +1,12 @@
1
1
  # Migrating `@morpho-org/morpho-sdk` from v7 to v8
2
2
 
3
+ > Current funding behavior: the SDK no longer requests Permit2 funding. Use ERC-2612 permits
4
+ > (`supportSignature: true`, with `useSimplePermit` defaulting to true) or direct ERC-20 approvals.
5
+ > Pass `useSimplePermit: false` to force approvals. The legacy
6
+ > `permit2Nonce` option is deprecated and ignored; builders still accept previously collected
7
+ > signatures. Permit2 requirement descriptions below document historical behavior.
8
+
9
+
3
10
  Version 8 makes token metadata and RPC-backed requirement reads fail closed.
4
11
  These calls now throw typed errors instead of returning partial or default values.
5
12
 
@@ -1,5 +1,12 @@
1
1
  # Migrating from morpho-sdk v8 to v9
2
2
 
3
+ > Current funding behavior: the SDK no longer requests Permit2 funding. Use ERC-2612 permits
4
+ > (`supportSignature: true`, with `useSimplePermit` defaulting to true) or direct ERC-20 approvals.
5
+ > Pass `useSimplePermit: false` to force approvals. The legacy
6
+ > `permit2Nonce` option is deprecated and ignored; builders still accept previously collected
7
+ > signatures. Permit2 requirement descriptions below document historical behavior.
8
+
9
+
3
10
  Version 9 removes exact-amount approval controls. Classic ERC-20 approvals and vault-share
4
11
  approvals or permits now use `maxUint256` when the existing allowance is below the required amount.
5
12
  An allowance at or above the required amount satisfies the requirement; larger leftovers are
package/README.md CHANGED
@@ -86,7 +86,7 @@ live Blue liquidity — before invoking `buildTx()`. Calling `buildTx()` directl
86
86
  RPC-backed pre-flight checks. `forceRedeem` remains a direct Vault V2 multicall without
87
87
  prerequisites.
88
88
 
89
- - **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, permit / Permit2 signatures, Morpho authorization, or (for Midnight) operator authorization.
89
+ - **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, ERC-2612 permit signatures, Morpho authorization, or (for Midnight) operator authorization.
90
90
  - **`buildTx(signatures?)`** — synchronous; the final, deep-frozen viem transaction. Pass any signatures collected from the requirements.
91
91
 
92
92
  Every transaction carries `tx.action` — typed metadata describing the encoded call (`type` plus
@@ -111,7 +111,10 @@ const requirements = await getRequirements();
111
111
  const tx = buildTx([permitSignature]);
112
112
  ```
113
113
 
114
- Enable off-chain approvals (permit / Permit2) with `morphoViemExtension({ supportSignature: true })`.
114
+ Enable off-chain approvals (ERC-2612 permits) with `morphoViemExtension({ supportSignature: true })`. Pass `getRequirements({ useSimplePermit: false })` to force direct ERC-20 approvals; unsupported tokens also fall back to direct approvals.
115
+
116
+ Token funding checks the bundles allowance first on every route. If it already covers the amount,
117
+ no token requirement is returned and ERC-2612 support is not probed.
115
118
 
116
119
  ### `userAddress` is the eventual submitter
117
120
 
@@ -152,8 +155,7 @@ Create an entity — every factory takes a chain ID as its last argument:
152
155
  ### Vault deposit / withdraw
153
156
 
154
157
  Deposit calls VaultBundlesV1 and may require an approval or permit. ERC-20 approvals and ERC-2612
155
- permits authorize VaultBundlesV1. Permit2 SignatureTransfer also names VaultBundlesV1 as spender,
156
- while the ERC-20 approval prerequisite targets canonical Permit2.
158
+ permits authorize VaultBundlesV1. The SDK no longer requests Permit2 funding.
157
159
 
158
160
  ```typescript
159
161
  const vault = client.morpho.vaultV2("0xVault...", 1);
@@ -6,6 +6,7 @@ export type BundlesTokenRequirementsState = {
6
6
  /** Current allowance of the funding token for `spender`. */
7
7
  readonly allowance: bigint;
8
8
  } | {
9
+ /** @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
9
10
  readonly type: "permit2SignatureTransfer";
10
11
  readonly permit2Allowance: bigint;
11
12
  readonly permit2Nonce: bigint;
@@ -51,6 +51,9 @@ interface EncodeErc20PermitParams {
51
51
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
52
52
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
53
53
  * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
54
+ * @throws {InvalidPermitDomainChainIdError} when the EIP-5267 domain names another chain.
55
+ * @throws {InvalidPermitDomainVerifyingContractError} when the EIP-5267 domain names another token.
56
+ * @throws {UnsupportedPermitDomainExtensionsError} when the EIP-5267 domain has extensions.
54
57
  * @throws {MissingPermitDomainNameError} when the token exposes neither `name()` nor
55
58
  * `eip712Domain()`, so its permit domain is unknown.
56
59
  * @throws {viem.BaseError} when the `eth_chainId` request or a token metadata read fails at the
@@ -67,7 +70,7 @@ interface EncodeErc20PermitParams {
67
70
  *
68
71
  * const client = createWalletClient({ chain: mainnet, transport: http() });
69
72
  * const requirement = await encodeErc20Permit(client, {
70
- * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
73
+ * token: USDC, // Must implement standard ERC-2612. DAI falls back to a direct ERC-20 approval in requirement helpers.
71
74
  * owner,
72
75
  * spender: blueBundlesV1,
73
76
  * amount: 1_000_000n,
@@ -44,6 +44,9 @@ const validateClientChainId_js_1 = require("../validateClientChainId.js");
44
44
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
45
45
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
46
46
  * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
47
+ * @throws {InvalidPermitDomainChainIdError} when the EIP-5267 domain names another chain.
48
+ * @throws {InvalidPermitDomainVerifyingContractError} when the EIP-5267 domain names another token.
49
+ * @throws {UnsupportedPermitDomainExtensionsError} when the EIP-5267 domain has extensions.
47
50
  * @throws {MissingPermitDomainNameError} when the token exposes neither `name()` nor
48
51
  * `eip712Domain()`, so its permit domain is unknown.
49
52
  * @throws {viem.BaseError} when the `eth_chainId` request or a token metadata read fails at the
@@ -60,7 +63,7 @@ const validateClientChainId_js_1 = require("../validateClientChainId.js");
60
63
  *
61
64
  * const client = createWalletClient({ chain: mainnet, transport: http() });
62
65
  * const requirement = await encodeErc20Permit(client, {
63
- * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
66
+ * token: USDC, // Must implement standard ERC-2612. DAI falls back to a direct ERC-20 approval in requirement helpers.
64
67
  * owner,
65
68
  * spender: blueBundlesV1,
66
69
  * amount: 1_000_000n,
@@ -1,6 +1,9 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
2
  import { type Permit2SignatureTransferRequirementSignature, type Requirement } from "../../../types/index.js";
3
- /** Parameters for {@link encodeErc20Permit2SignatureTransfer}. */
3
+ /**
4
+ * Parameters for {@link encodeErc20Permit2SignatureTransfer}.
5
+ * @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
6
+ */
4
7
  export interface EncodeErc20Permit2SignatureTransferParams {
5
8
  /** ERC-20 token pulled through Permit2. */
6
9
  readonly token: Address;
@@ -62,5 +65,6 @@ export interface EncodeErc20Permit2SignatureTransferParams {
62
65
  * });
63
66
  * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
64
67
  * ```
68
+ * @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
65
69
  */
66
70
  export declare const encodeErc20Permit2SignatureTransfer: (params: EncodeErc20Permit2SignatureTransferParams) => Requirement<Permit2SignatureTransferRequirementSignature>;
@@ -53,6 +53,7 @@ const index_js_1 = require("../../../types/index.js");
53
53
  * });
54
54
  * // requirement satisfies Requirement<Permit2SignatureTransferRequirementSignature>
55
55
  * ```
56
+ * @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
56
57
  */
57
58
  const encodeErc20Permit2SignatureTransfer = (params) => {
58
59
  const { token, spender, amount, chainId, nonce, deadline } = params;
@@ -12,7 +12,7 @@ import type { Metadata, MorphoClientType } from "../types/index.js";
12
12
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
13
13
  * `morpho` namespace builds.
14
14
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
15
- * ERC-2612, Permit2 SignatureTransfer, and Morpho authorization.
15
+ * ERC-2612 and Morpho authorization.
16
16
  * Defaults to `false` (standalone approvals and authorization calls only).
17
17
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
18
18
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
@@ -49,7 +49,7 @@ function createMorphoNamespace(viemClient, options) {
49
49
  * @param _options.metadata - Optional analytics metadata applied to every transaction the
50
50
  * `morpho` namespace builds.
51
51
  * @param _options.supportSignature - Whether the integrator can collect EIP-712 signatures for
52
- * ERC-2612, Permit2 SignatureTransfer, and Morpho authorization.
52
+ * ERC-2612 and Morpho authorization.
53
53
  * Defaults to `false` (standalone approvals and authorization calls only).
54
54
  * @param _options.supportDeployless - Whether entity fetchers may use deployless multicall.
55
55
  * @returns A viem extension function — `client.extend(morphoViemExtension(...))` adds
@@ -18,9 +18,9 @@ type VaultV2BlueReallocationsParams = {
18
18
  };
19
19
  /** Options for resolving token-backed BlueBundlesV1 approval or signature prerequisites. */
20
20
  export interface BlueTokenRequirementsParams {
21
- /** Prefer ERC-2612 when the funded token exposes a compatible nonce. */
21
+ /** Prefer ERC-2612 when the funded token exposes a compatible nonce; defaults to true when signatures are supported. */
22
22
  readonly useSimplePermit?: boolean;
23
- /** Explicit unused Permit2 SignatureTransfer unordered nonce; defaults to the lowest unused nonce. */
23
+ /** @deprecated Ignored. The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
24
24
  readonly permit2Nonce?: bigint;
25
25
  }
26
26
  /**
@@ -95,8 +95,6 @@ export interface BlueActions {
95
95
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
96
96
  * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
97
97
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
98
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
99
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
100
98
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
101
99
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
102
100
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -144,10 +142,9 @@ export interface BlueActions {
144
142
  /**
145
143
  * Prepares a direct BlueBundlesV1 loan-asset supply.
146
144
  *
147
- * `getRequirements()` first checks that BlueBundlesV1, Blue and, for ERC-20 funding with
148
- * signatures enabled, Permit2 hold code at their registered addresses, then reads the loan-token
149
- * allowance and selected ERC-2612 or Permit2 nonce state. Direct approvals and ERC-2612 name
150
- * BlueBundlesV1 as spender; Permit2 keeps its ERC-20 approval on canonical Permit2. Native
145
+ * `getRequirements()` first checks that BlueBundlesV1 and Blue hold code, then
146
+ * reads the loan-token allowance and selected ERC-2612 nonce state. Direct approvals and
147
+ * ERC-2612 name BlueBundlesV1 as spender. Native
151
148
  * funding is exclusive and skips token requirements (the code check still runs).
152
149
  * The referral fee is deducted from the gross `assets` supplied. This route exposes no
153
150
  * share-price bound or `slippageTolerance`.
@@ -166,14 +163,12 @@ export interface BlueActions {
166
163
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
167
164
  * @throws {ExpiredDeadlineError} when the deadline is not in the future at creation or requirement resolution.
168
165
  * @throws {NonPositiveInputError} when `assets` is not positive.
169
- * @throws {NegativeInputError} when native funding or the referral fee is negative, or from `getRequirements()` when an explicit `permit2Nonce` is negative.
166
+ * @throws {NegativeInputError} when native funding or the referral fee is negative.
170
167
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
171
168
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
172
169
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
173
- * @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD, or from `getRequirements()` when an explicit `permit2Nonce` exceeds `uint256`.
170
+ * @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD.
174
171
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
175
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
176
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
177
172
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
178
173
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when the route cannot consume a supplied signature.
179
174
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -500,8 +495,6 @@ export interface BlueActions {
500
495
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
501
496
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
502
497
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
503
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
504
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
505
498
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
506
499
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an authorization signature is supplied.
507
500
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -675,8 +668,6 @@ export interface BlueActions {
675
668
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
676
669
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
677
670
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
678
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
679
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
680
671
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
681
672
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
682
673
  * @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
@@ -782,8 +773,6 @@ export interface BlueActions {
782
773
  * @throws {InconsistentReallocationPenaltyError} when one vault uses different penalties.
783
774
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a source is the target market.
784
775
  * @throws {ReallocationLoanTokenMismatchError} when a source uses another loan token.
785
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the owner is consumed and none was passed explicitly.
786
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the explicit Permit2 nonce is consumed.
787
776
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple signatures of one kind are supplied.
788
777
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an inactive leg cannot consume a supplied signature.
789
778
  * @throws {DepositOwnerMismatchError} from `buildTx()` when a signed owner differs from `userAddress`.
@@ -1051,9 +1040,6 @@ export declare class MorphoBlue implements BlueActions {
1051
1040
  * spender/authorized operator holds code, with one `eth_getCode` per distinct address
1052
1041
  * before any other requirement read. Blue write flows probe `eth_chainId` only after a target
1053
1042
  * has no code and report a chain mismatch when the RPC serves another chain.
1054
- *
1055
- * @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
1056
- * may name canonical Permit2 when signatures are supported.
1057
1043
  */
1058
1044
  private assertWriteTargets;
1059
1045
  private getMaxLtv;
@@ -61,11 +61,8 @@ class MorphoBlue {
61
61
  * spender/authorized operator holds code, with one `eth_getCode` per distinct address
62
62
  * before any other requirement read. Blue write flows probe `eth_chainId` only after a target
63
63
  * has no code and report a chain mismatch when the RPC serves another chain.
64
- *
65
- * @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
66
- * may name canonical Permit2 when signatures are supported.
67
64
  */
68
- async assertWriteTargets(params) {
65
+ async assertWriteTargets() {
69
66
  const targets = [
70
67
  {
71
68
  role: "bundles.blueBundlesV1",
@@ -73,11 +70,6 @@ class MorphoBlue {
73
70
  },
74
71
  { role: "blue", address: (0, morpho_ts_1.getChainAddress)(this.chainId, "blue") },
75
72
  ];
76
- if (params?.erc20Funding && this.client.options.supportSignature) {
77
- const permit2 = (0, morpho_ts_1.getChainAddresses)(this.chainId).permit2;
78
- if (permit2 != null)
79
- targets.push({ role: "permit2", address: permit2 });
80
- }
81
73
  await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(this.client.viemClient, this.chainId, targets);
82
74
  }
83
75
  getMaxLtv(marketParams = this.marketParams) {
@@ -98,7 +90,6 @@ class MorphoBlue {
98
90
  supportSignature: this.client.options.supportSignature,
99
91
  supportDeployless: this.client.options.supportDeployless,
100
92
  useSimplePermit: params.useSimplePermit,
101
- permit2Nonce: params.permit2Nonce,
102
93
  now: params.now,
103
94
  });
104
95
  }
@@ -149,9 +140,7 @@ class MorphoBlue {
149
140
  getRequirements: (requirementsParams) => {
150
141
  const now = morpho_ts_1.Time.timestamp();
151
142
  this.validateDeadline(deadline, now);
152
- return this.assertWriteTargets({
153
- erc20Funding: nativeValue === 0n,
154
- }).then(() => {
143
+ return this.assertWriteTargets().then(() => {
155
144
  if (nativeValue > 0n)
156
145
  return [];
157
146
  return this.getTokenRequirements({
@@ -161,7 +150,6 @@ class MorphoBlue {
161
150
  deadline,
162
151
  now,
163
152
  useSimplePermit: requirementsParams?.useSimplePermit,
164
- permit2Nonce: requirementsParams?.permit2Nonce,
165
153
  });
166
154
  });
167
155
  },
@@ -575,9 +563,7 @@ class MorphoBlue {
575
563
  getRequirements: async (requirementsParams) => {
576
564
  const now = morpho_ts_1.Time.timestamp();
577
565
  this.validateDeadline(deadline, now);
578
- await this.assertWriteTargets({
579
- erc20Funding: hasRepay && nativeValue === 0n,
580
- });
566
+ await this.assertWriteTargets();
581
567
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
582
568
  hasRepay && nativeValue === 0n
583
569
  ? this.getTokenRequirements({
@@ -587,7 +573,6 @@ class MorphoBlue {
587
573
  deadline,
588
574
  now,
589
575
  useSimplePermit: requirementsParams?.useSimplePermit,
590
- permit2Nonce: requirementsParams?.permit2Nonce,
591
576
  })
592
577
  : Promise.resolve([]),
593
578
  collateralAssets > 0n
@@ -686,9 +671,7 @@ class MorphoBlue {
686
671
  getRequirements: async (requirementsParams) => {
687
672
  const now = morpho_ts_1.Time.timestamp();
688
673
  this.validateDeadline(deadline, now);
689
- await this.assertWriteTargets({
690
- erc20Funding: collateralAssets > 0n && nativeValue === 0n,
691
- });
674
+ await this.assertWriteTargets();
692
675
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
693
676
  collateralAssets > 0n && nativeValue === 0n
694
677
  ? this.getTokenRequirements({
@@ -698,7 +681,6 @@ class MorphoBlue {
698
681
  deadline,
699
682
  now,
700
683
  useSimplePermit: requirementsParams?.useSimplePermit,
701
- permit2Nonce: requirementsParams?.permit2Nonce,
702
684
  })
703
685
  : Promise.resolve([]),
704
686
  borrowAssets > 0n
@@ -18,22 +18,19 @@ export interface GetBundlesTokenRequirementsParams {
18
18
  readonly supportSignature: boolean;
19
19
  /** Whether token metadata reads may use deployless aggregation. */
20
20
  readonly supportDeployless?: boolean;
21
- /** Prefer ERC-2612 when the token exposes a compatible nonce. */
21
+ /** Prefer ERC-2612 when the token exposes a compatible nonce; defaults to true when signatures are supported. */
22
22
  readonly useSimplePermit?: boolean;
23
- /** Explicit unused uint256 nonce; defaults to the lowest unused nonce found via getUnusedPermit2Nonce. */
23
+ /** @deprecated Ignored. The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
24
24
  readonly permit2Nonce?: bigint;
25
25
  /** Timestamp the deadline is validated against; defaults to the current time. */
26
26
  readonly now?: bigint;
27
27
  }
28
28
  /**
29
- * Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
30
- * a registered fixed bundles contract.
29
+ * Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
31
30
  *
32
- * Returns no requirements when the direct bundles allowance covers the amount, even when
33
- * signatures are supported. Otherwise reads only the state required by the selected path.
34
- * Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
35
- * names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
36
- * by default; concurrent flows for the same owner should pass explicit nonces.
31
+ * Reads the direct allowance first for nonzero amounts. Only when it is insufficient does
32
+ * the selected signature path try ERC-2612 nonce and metadata reads. A permit is returned only
33
+ * when the token's DOMAIN_SEPARATOR matches the domain to be signed; otherwise use approval.
37
34
  *
38
35
  * @param viemClient - Connected viem client used for allowance and nonce reads.
39
36
  * @param params - Token requirement parameters.
@@ -44,37 +41,35 @@ export interface GetBundlesTokenRequirementsParams {
44
41
  * @param params.chainId - Target chain id; must match the client chain.
45
42
  * @param params.deadline - Final-call and signature deadline.
46
43
  * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
47
- * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
44
+ * @param params.supportSignature - Whether ERC-2612 signatures may be requested.
48
45
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
49
- * @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
50
- * domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
51
- * (no `name()` and no EIP-5267 domain), falls back to Permit2 or classic approval. A malformed
46
+ * @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
47
+ * DOMAIN_SEPARATOR matches the signing domain. Missing, mismatched, or unsupported domains,
48
+ * or recognized nonce/separator reverts or undecodable results, fall back to classic approval. A malformed
52
49
  * `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
53
- * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
54
- * found via {@link getUnusedPermit2Nonce}.
55
- * @returns Ordered deep-frozen approval transactions and/or signable token requirements.
50
+ * @param params.permit2Nonce - Deprecated and ignored.
51
+ * @returns Ordered deep-frozen approval transactions and/or signable token requirements;
52
+ * empty when the direct allowance already covers the amount, without probing permit support.
56
53
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
57
54
  * another chain than `params.chainId`.
58
- * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
55
+ * @throws {NegativeInputError} when `amount` is negative.
59
56
  * @throws {NonPositiveInputError} when `deadline` is not positive.
60
57
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
61
58
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
62
59
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
63
60
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
64
- * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
65
- * was passed explicitly.
66
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
67
- * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
61
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
68
62
  * @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
69
63
  * undecodable data, or is out of range.
70
64
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
71
65
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
72
66
  * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
73
- * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
74
- * or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
75
- * only when the token reverts or returns undecodable data; other read failures propagate. A
76
- * missing permit domain is handled internally and also falls back; this function does not
77
- * surface `MissingPermitDomainNameError`.
67
+ * @throws {viem.BaseError} when a required allowance, ERC-2612 metadata, DOMAIN_SEPARATOR,
68
+ * or `eth_chainId` read fails. Nonce and separator probes fall back to classic approval
69
+ * only when the token reverts or returns undecodable data; other read failures propagate.
70
+ * `MissingPermitDomainNameError`, `InvalidPermitDomainChainIdError`,
71
+ * `InvalidPermitDomainVerifyingContractError`, and `UnsupportedPermitDomainExtensionsError`
72
+ * are handled internally and fall back to approval.
78
73
  * @example
79
74
  * ```ts
80
75
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
@@ -11,16 +11,12 @@ const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encode
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
12
  const index_js_2 = require("../../helpers/index.js");
13
13
  const index_js_3 = require("../../types/index.js");
14
- const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
15
14
  /**
16
- * Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
17
- * a registered fixed bundles contract.
15
+ * Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
18
16
  *
19
- * Returns no requirements when the direct bundles allowance covers the amount, even when
20
- * signatures are supported. Otherwise reads only the state required by the selected path.
21
- * Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
22
- * names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
23
- * by default; concurrent flows for the same owner should pass explicit nonces.
17
+ * Reads the direct allowance first for nonzero amounts. Only when it is insufficient does
18
+ * the selected signature path try ERC-2612 nonce and metadata reads. A permit is returned only
19
+ * when the token's DOMAIN_SEPARATOR matches the domain to be signed; otherwise use approval.
24
20
  *
25
21
  * @param viemClient - Connected viem client used for allowance and nonce reads.
26
22
  * @param params - Token requirement parameters.
@@ -31,37 +27,35 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
31
27
  * @param params.chainId - Target chain id; must match the client chain.
32
28
  * @param params.deadline - Final-call and signature deadline.
33
29
  * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
34
- * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
30
+ * @param params.supportSignature - Whether ERC-2612 signatures may be requested.
35
31
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
36
- * @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
37
- * domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
38
- * (no `name()` and no EIP-5267 domain), falls back to Permit2 or classic approval. A malformed
32
+ * @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
33
+ * DOMAIN_SEPARATOR matches the signing domain. Missing, mismatched, or unsupported domains,
34
+ * or recognized nonce/separator reverts or undecodable results, fall back to classic approval. A malformed
39
35
  * `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
40
- * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
41
- * found via {@link getUnusedPermit2Nonce}.
42
- * @returns Ordered deep-frozen approval transactions and/or signable token requirements.
36
+ * @param params.permit2Nonce - Deprecated and ignored.
37
+ * @returns Ordered deep-frozen approval transactions and/or signable token requirements;
38
+ * empty when the direct allowance already covers the amount, without probing permit support.
43
39
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
44
40
  * another chain than `params.chainId`.
45
- * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
41
+ * @throws {NegativeInputError} when `amount` is negative.
46
42
  * @throws {NonPositiveInputError} when `deadline` is not positive.
47
43
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
48
44
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
49
45
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
50
46
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
51
- * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
52
- * was passed explicitly.
53
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
54
- * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
47
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
55
48
  * @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
56
49
  * undecodable data, or is out of range.
57
50
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
58
51
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
59
52
  * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
60
- * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
61
- * or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
62
- * only when the token reverts or returns undecodable data; other read failures propagate. A
63
- * missing permit domain is handled internally and also falls back; this function does not
64
- * surface `MissingPermitDomainNameError`.
53
+ * @throws {viem.BaseError} when a required allowance, ERC-2612 metadata, DOMAIN_SEPARATOR,
54
+ * or `eth_chainId` read fails. Nonce and separator probes fall back to classic approval
55
+ * only when the token reverts or returns undecodable data; other read failures propagate.
56
+ * `MissingPermitDomainNameError`, `InvalidPermitDomainChainIdError`,
57
+ * `InvalidPermitDomainVerifyingContractError`, and `UnsupportedPermitDomainExtensionsError`
58
+ * are handled internally and fall back to approval.
65
59
  * @example
66
60
  * ```ts
67
61
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
@@ -131,10 +125,10 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
131
125
  });
132
126
  if (allowance >= params.amount)
133
127
  return [];
134
- const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
128
+ const { dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
135
129
  if (params.supportSignature) {
136
130
  const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
137
- if (params.useSimplePermit && !isDai) {
131
+ if ((params.useSimplePermit ?? true) && !isDai) {
138
132
  const nonce = await (0, actions_1.readContract)(viemClient, {
139
133
  abi: blue_sdk_viem_1.erc2612Abi,
140
134
  address: params.token,
@@ -158,61 +152,29 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
158
152
  deadline: params.deadline,
159
153
  now: timestamp,
160
154
  supportDeployless: params.supportDeployless,
161
- }), blue_sdk_viem_1.MissingPermitDomainNameError);
162
- if ((0, morpho_ts_1.isDefined)(permit))
163
- return [permit];
164
- // A token that exposes nonces() but has neither name() nor
165
- // eip712Domain() cannot be permitted over a known domain: fall
166
- // through to the Permit2/classic-approval path.
155
+ }), blue_sdk_viem_1.MissingPermitDomainNameError, blue_sdk_viem_1.InvalidPermitDomainChainIdError, blue_sdk_viem_1.InvalidPermitDomainVerifyingContractError, blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError);
156
+ if ((0, morpho_ts_1.isDefined)(permit)) {
157
+ const separator = await (0, actions_1.readContract)(viemClient, {
158
+ abi: blue_sdk_viem_1.erc2612Abi,
159
+ address: params.token,
160
+ functionName: "DOMAIN_SEPARATOR",
161
+ }).catch((error) => {
162
+ if ((0, blue_sdk_viem_1.isTransportError)(error))
163
+ throw error;
164
+ if ((0, blue_sdk_viem_1.isContractRevertError)(error) || (0, blue_sdk_viem_1.isUndecodableResultError)(error))
165
+ return undefined;
166
+ throw error;
167
+ });
168
+ const domain = permit.action.typedData.domain ?? {};
169
+ if (separator?.toLowerCase() ===
170
+ (0, viem_1.hashDomain)({
171
+ domain,
172
+ types: { EIP712Domain: (0, viem_1.getTypesForEIP712Domain)({ domain }) },
173
+ }).toLowerCase())
174
+ return [permit];
175
+ }
167
176
  }
168
177
  }
169
- if (permit2 != null) {
170
- const permit2Nonce = params.permit2Nonce ??
171
- (await (0, getUnusedPermit2Nonce_js_1.getUnusedPermit2Nonce)(viemClient, {
172
- owner: params.owner,
173
- chainId: params.chainId,
174
- }));
175
- if (permit2Nonce < 0n) {
176
- throw new index_js_3.NegativeInputError("permit2Nonce", permit2Nonce);
177
- }
178
- if (permit2Nonce > viem_1.maxUint256) {
179
- throw new index_js_3.InputExceedsMaxError({
180
- field: "permit2Nonce",
181
- value: permit2Nonce,
182
- max: viem_1.maxUint256,
183
- });
184
- }
185
- const wordPosition = permit2Nonce >> 8n;
186
- const [permit2Allowance, nonceBitmap] = await Promise.all([
187
- (0, actions_1.readContract)(viemClient, {
188
- abi: viem_1.erc20Abi,
189
- address: params.token,
190
- functionName: "allowance",
191
- args: [params.owner, permit2],
192
- }),
193
- (0, actions_1.readContract)(viemClient, {
194
- abi: blue_sdk_viem_1.permit2Abi,
195
- address: permit2,
196
- functionName: "nonceBitmap",
197
- args: [params.owner, wordPosition],
198
- }),
199
- ]);
200
- return (0, index_js_1.resolveBundlesTokenRequirements)({
201
- token: params.token,
202
- spender: params.spender,
203
- owner: params.owner,
204
- chainId: params.chainId,
205
- amount: params.amount,
206
- deadline: params.deadline,
207
- now: timestamp,
208
- state: {
209
- type: "permit2SignatureTransfer",
210
- permit2Allowance,
211
- permit2Nonce,
212
- nonceBitmap,
213
- },
214
- });
215
- }
216
178
  }
217
179
  return (0, index_js_1.resolveBundlesTokenRequirements)({
218
180
  token: params.token,