@morpho-org/morpho-sdk 9.3.0 → 9.5.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 (75) 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 +9 -5
  5. package/lib/cjs/abis.d.ts +2 -2
  6. package/lib/cjs/abis.js +4 -1
  7. package/lib/cjs/actions/blue/index.d.ts +1 -0
  8. package/lib/cjs/actions/blue/index.js +1 -0
  9. package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +60 -0
  10. package/lib/cjs/actions/blue/withdrawBuyCallback.js +79 -0
  11. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
  12. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
  13. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +4 -1
  14. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  16. package/lib/cjs/blue/abis.d.ts +1 -1
  17. package/lib/cjs/blue/abis.js +3 -1
  18. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  19. package/lib/cjs/client/morphoViemExtension.js +1 -1
  20. package/lib/cjs/entities/blue/blue.d.ts +88 -23
  21. package/lib/cjs/entities/blue/blue.js +89 -22
  22. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +21 -25
  23. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +50 -85
  24. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
  25. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +2 -2
  26. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +5 -11
  27. package/lib/cjs/entities/vaultV1/vaultV1.js +3 -11
  28. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +5 -11
  29. package/lib/cjs/entities/vaultV2/vaultV2.js +3 -11
  30. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -0
  31. package/lib/cjs/entities/vaultV2BlueReallocationData.js +40 -4
  32. package/lib/cjs/errors.d.ts +1 -1
  33. package/lib/cjs/errors.js +3 -1
  34. package/lib/cjs/midnight/abis.d.ts +1 -1
  35. package/lib/cjs/midnight/abis.js +2 -1
  36. package/lib/cjs/types/action.d.ts +26 -5
  37. package/lib/cjs/types/action.js +1 -0
  38. package/lib/cjs/types/error.d.ts +42 -2
  39. package/lib/cjs/types/error.js +49 -3
  40. package/lib/esm/abis.d.ts +2 -2
  41. package/lib/esm/abis.js +2 -2
  42. package/lib/esm/actions/blue/index.d.ts +1 -0
  43. package/lib/esm/actions/blue/index.js +1 -0
  44. package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +60 -0
  45. package/lib/esm/actions/blue/withdrawBuyCallback.js +75 -0
  46. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -0
  47. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -1
  48. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +4 -1
  49. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -1
  50. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  51. package/lib/esm/blue/abis.d.ts +1 -1
  52. package/lib/esm/blue/abis.js +1 -1
  53. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  54. package/lib/esm/client/morphoViemExtension.js +1 -1
  55. package/lib/esm/entities/blue/blue.d.ts +88 -23
  56. package/lib/esm/entities/blue/blue.js +91 -24
  57. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +21 -25
  58. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +52 -87
  59. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +6 -3
  60. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +2 -2
  61. package/lib/esm/entities/vaultV1/vaultV1.d.ts +5 -11
  62. package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
  63. package/lib/esm/entities/vaultV2/vaultV2.d.ts +5 -11
  64. package/lib/esm/entities/vaultV2/vaultV2.js +4 -12
  65. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -0
  66. package/lib/esm/entities/vaultV2BlueReallocationData.js +40 -4
  67. package/lib/esm/errors.d.ts +1 -1
  68. package/lib/esm/errors.js +1 -1
  69. package/lib/esm/midnight/abis.d.ts +1 -1
  70. package/lib/esm/midnight/abis.js +1 -1
  71. package/lib/esm/types/action.d.ts +26 -5
  72. package/lib/esm/types/action.js +1 -0
  73. package/lib/esm/types/error.d.ts +42 -2
  74. package/lib/esm/types/error.js +43 -2
  75. package/package.json +5 -5
@@ -6,6 +6,7 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
8
  const actions_1 = require("viem/actions");
9
+ const abis_js_1 = require("../../abis.js");
9
10
  const common_js_1 = require("../../actions/blue/common.js");
10
11
  const index_js_1 = require("../../actions/index.js");
11
12
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
@@ -60,11 +61,8 @@ class MorphoBlue {
60
61
  * spender/authorized operator holds code, with one `eth_getCode` per distinct address
61
62
  * before any other requirement read. Blue write flows probe `eth_chainId` only after a target
62
63
  * has no code and report a chain mismatch when the RPC serves another chain.
63
- *
64
- * @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
65
- * may name canonical Permit2 when signatures are supported.
66
64
  */
67
- async assertWriteTargets(params) {
65
+ async assertWriteTargets() {
68
66
  const targets = [
69
67
  {
70
68
  role: "bundles.blueBundlesV1",
@@ -72,11 +70,6 @@ class MorphoBlue {
72
70
  },
73
71
  { role: "blue", address: (0, morpho_ts_1.getChainAddress)(this.chainId, "blue") },
74
72
  ];
75
- if (params?.erc20Funding && this.client.options.supportSignature) {
76
- const permit2 = (0, morpho_ts_1.getChainAddresses)(this.chainId).permit2;
77
- if (permit2 != null)
78
- targets.push({ role: "permit2", address: permit2 });
79
- }
80
73
  await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(this.client.viemClient, this.chainId, targets);
81
74
  }
82
75
  getMaxLtv(marketParams = this.marketParams) {
@@ -97,7 +90,6 @@ class MorphoBlue {
97
90
  supportSignature: this.client.options.supportSignature,
98
91
  supportDeployless: this.client.options.supportDeployless,
99
92
  useSimplePermit: params.useSimplePermit,
100
- permit2Nonce: params.permit2Nonce,
101
93
  now: params.now,
102
94
  });
103
95
  }
@@ -148,9 +140,7 @@ class MorphoBlue {
148
140
  getRequirements: (requirementsParams) => {
149
141
  const now = morpho_ts_1.Time.timestamp();
150
142
  this.validateDeadline(deadline, now);
151
- return this.assertWriteTargets({
152
- erc20Funding: nativeValue === 0n,
153
- }).then(() => {
143
+ return this.assertWriteTargets().then(() => {
154
144
  if (nativeValue > 0n)
155
145
  return [];
156
146
  return this.getTokenRequirements({
@@ -160,7 +150,6 @@ class MorphoBlue {
160
150
  deadline,
161
151
  now,
162
152
  useSimplePermit: requirementsParams?.useSimplePermit,
163
- permit2Nonce: requirementsParams?.permit2Nonce,
164
153
  });
165
154
  });
166
155
  },
@@ -266,6 +255,90 @@ class MorphoBlue {
266
255
  },
267
256
  };
268
257
  }
258
+ /** {@inheritDoc BlueActions.withdrawBuyCallback} */
259
+ withdrawBuyCallback(params) {
260
+ const { userAddress, callbackAddress, positionData } = params;
261
+ (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
262
+ if (positionData == null) {
263
+ throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
264
+ }
265
+ (0, index_js_2.validateAccrualPosition)({
266
+ positionData,
267
+ expectedMarketId: this.marketParams.id,
268
+ expectedUser: callbackAddress,
269
+ });
270
+ const shares = positionData.supplyShares;
271
+ if (shares === 0n) {
272
+ throw new index_js_3.EmptyBlueSupplyPositionError({
273
+ market: this.marketParams.id,
274
+ user: callbackAddress,
275
+ });
276
+ }
277
+ const assets = positionData.supplyAssets;
278
+ const liquidity = positionData.market.liquidity;
279
+ if (assets > liquidity) {
280
+ throw new index_js_3.InsufficientBlueLiquidityError({
281
+ market: this.marketParams.id,
282
+ assets,
283
+ liquidity,
284
+ });
285
+ }
286
+ const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
287
+ const factory = (0, morpho_ts_1.getChainAddress)(this.chainId, "midnightBlueBuyCallbackFactory");
288
+ const tx = (0, index_js_1.blueWithdrawBuyCallback)({
289
+ market: { chainId: this.chainId, marketParams: this.marketParams },
290
+ args: { callbackAddress, userAddress, shares },
291
+ metadata: this.client.options.metadata,
292
+ });
293
+ return {
294
+ getRequirements: async () => {
295
+ const viemClient = this.client.viemClient;
296
+ await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, this.chainId);
297
+ await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(viemClient, this.chainId, [
298
+ { role: "blue", address: blue },
299
+ { role: "midnightBlueBuyCallbackFactory", address: factory },
300
+ ]);
301
+ // Check the factory first: OWNER() on an arbitrary address can revert or lie.
302
+ const isBlueBuyCallback = await (0, actions_1.readContract)(viemClient, {
303
+ address: factory,
304
+ abi: abis_js_1.midnightBlueBuyCallbackFactoryAbi,
305
+ functionName: "isBlueBuyCallback",
306
+ args: [callbackAddress],
307
+ });
308
+ if (!isBlueBuyCallback) {
309
+ throw new index_js_3.NotBlueBuyCallbackError(callbackAddress);
310
+ }
311
+ const [owner, isAuthorized] = await Promise.all([
312
+ (0, actions_1.readContract)(viemClient, {
313
+ address: callbackAddress,
314
+ abi: abis_js_1.midnightBlueBuyCallbackAbi,
315
+ functionName: "OWNER",
316
+ }),
317
+ (0, actions_1.readContract)(viemClient, {
318
+ address: blue,
319
+ abi: abis_js_1.blueAbi,
320
+ functionName: "isAuthorized",
321
+ args: [callbackAddress, userAddress],
322
+ }),
323
+ ]);
324
+ if (!(0, viem_1.isAddressEqual)(owner, userAddress)) {
325
+ throw new index_js_3.BlueBuyCallbackOwnerMismatchError({
326
+ callback: callbackAddress,
327
+ owner,
328
+ userAddress,
329
+ });
330
+ }
331
+ if (!isAuthorized) {
332
+ throw new index_js_3.BlueBuyCallbackUnauthorizedError({
333
+ callback: callbackAddress,
334
+ userAddress,
335
+ });
336
+ }
337
+ return [];
338
+ },
339
+ buildTx: () => tx,
340
+ };
341
+ }
269
342
  /** {@inheritDoc BlueActions.supplyCollateral} */
270
343
  supplyCollateral(params) {
271
344
  const { userAddress, collateralAssets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
@@ -490,9 +563,7 @@ class MorphoBlue {
490
563
  getRequirements: async (requirementsParams) => {
491
564
  const now = morpho_ts_1.Time.timestamp();
492
565
  this.validateDeadline(deadline, now);
493
- await this.assertWriteTargets({
494
- erc20Funding: hasRepay && nativeValue === 0n,
495
- });
566
+ await this.assertWriteTargets();
496
567
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
497
568
  hasRepay && nativeValue === 0n
498
569
  ? this.getTokenRequirements({
@@ -502,7 +573,6 @@ class MorphoBlue {
502
573
  deadline,
503
574
  now,
504
575
  useSimplePermit: requirementsParams?.useSimplePermit,
505
- permit2Nonce: requirementsParams?.permit2Nonce,
506
576
  })
507
577
  : Promise.resolve([]),
508
578
  collateralAssets > 0n
@@ -601,9 +671,7 @@ class MorphoBlue {
601
671
  getRequirements: async (requirementsParams) => {
602
672
  const now = morpho_ts_1.Time.timestamp();
603
673
  this.validateDeadline(deadline, now);
604
- await this.assertWriteTargets({
605
- erc20Funding: collateralAssets > 0n && nativeValue === 0n,
606
- });
674
+ await this.assertWriteTargets();
607
675
  const [tokenRequirements, authorizationRequirements] = await Promise.all([
608
676
  collateralAssets > 0n && nativeValue === 0n
609
677
  ? this.getTokenRequirements({
@@ -613,7 +681,6 @@ class MorphoBlue {
613
681
  deadline,
614
682
  now,
615
683
  useSimplePermit: requirementsParams?.useSimplePermit,
616
- permit2Nonce: requirementsParams?.permit2Nonce,
617
684
  })
618
685
  : Promise.resolve([]),
619
686
  borrowAssets > 0n
@@ -18,21 +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
- * Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
33
- * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
34
- * as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
35
- * 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.
36
34
  *
37
35
  * @param viemClient - Connected viem client used for allowance and nonce reads.
38
36
  * @param params - Token requirement parameters.
@@ -43,37 +41,35 @@ export interface GetBundlesTokenRequirementsParams {
43
41
  * @param params.chainId - Target chain id; must match the client chain.
44
42
  * @param params.deadline - Final-call and signature deadline.
45
43
  * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
46
- * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
44
+ * @param params.supportSignature - Whether ERC-2612 signatures may be requested.
47
45
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
48
- * @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
49
- * domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
50
- * (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
51
49
  * `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
52
- * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
53
- * found via {@link getUnusedPermit2Nonce}.
54
- * @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.
55
53
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
56
54
  * another chain than `params.chainId`.
57
- * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
55
+ * @throws {NegativeInputError} when `amount` is negative.
58
56
  * @throws {NonPositiveInputError} when `deadline` is not positive.
59
57
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
60
58
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
61
59
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
62
60
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
63
- * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
64
- * was passed explicitly.
65
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
66
- * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
61
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
67
62
  * @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
68
63
  * undecodable data, or is out of range.
69
64
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
70
65
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
71
66
  * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
72
- * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
73
- * or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
74
- * only when the token reverts or returns undecodable data; other read failures propagate. A
75
- * missing permit domain is handled internally and also falls back; this function does not
76
- * 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.
77
73
  * @example
78
74
  * ```ts
79
75
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
@@ -11,15 +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
- * Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
20
- * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
21
- * as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
22
- * 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.
23
20
  *
24
21
  * @param viemClient - Connected viem client used for allowance and nonce reads.
25
22
  * @param params - Token requirement parameters.
@@ -30,37 +27,35 @@ const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
30
27
  * @param params.chainId - Target chain id; must match the client chain.
31
28
  * @param params.deadline - Final-call and signature deadline.
32
29
  * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
33
- * @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
30
+ * @param params.supportSignature - Whether ERC-2612 signatures may be requested.
34
31
  * @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
35
- * @param params.useSimplePermit - Prefer ERC-2612 when `nonces()` succeeds and the token's permit
36
- * domain is known; a recognized `nonces()` revert or undecodable result, or a missing domain
37
- * (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
38
35
  * `eip712Domain()` result rejects with `MalformedTokenMetadataError`.
39
- * @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
40
- * found via {@link getUnusedPermit2Nonce}.
41
- * @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.
42
39
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
43
40
  * another chain than `params.chainId`.
44
- * @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
41
+ * @throws {NegativeInputError} when `amount` is negative.
45
42
  * @throws {NonPositiveInputError} when `deadline` is not positive.
46
43
  * @throws {ExpiredDeadlineError} when `deadline` is positive but not in the future.
47
44
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
48
45
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
49
46
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
50
- * @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
51
- * was passed explicitly.
52
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
53
- * @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
47
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256.
54
48
  * @throws {UnknownTokenError} when the token's `decimals()` reverts, has no code, returns
55
49
  * undecodable data, or is out of range.
56
50
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
57
51
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
58
52
  * deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
59
- * @throws {viem.BaseError} when a required allowance, Permit2 nonce-bitmap, ERC-2612 metadata,
60
- * or `eth_chainId` read fails. An ERC-2612 nonce probe falls back to Permit2 or classic approval
61
- * only when the token reverts or returns undecodable data; other read failures propagate. A
62
- * missing permit domain is handled internally and also falls back; this function does not
63
- * 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.
64
59
  * @example
65
60
  * ```ts
66
61
  * import { addressesRegistry } from "@morpho-org/blue-sdk";
@@ -122,10 +117,18 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
122
117
  if (params.amount === 0n)
123
118
  return [];
124
119
  await (0, validateClientChainId_js_1.validateClientChainId)(viemClient, params.chainId);
125
- const { permit2, dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
120
+ const allowance = await (0, actions_1.readContract)(viemClient, {
121
+ abi: viem_1.erc20Abi,
122
+ address: params.token,
123
+ functionName: "allowance",
124
+ args: [params.owner, params.spender],
125
+ });
126
+ if (allowance >= params.amount)
127
+ return [];
128
+ const { dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
126
129
  if (params.supportSignature) {
127
130
  const isDai = (0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai);
128
- if (params.useSimplePermit && !isDai) {
131
+ if ((params.useSimplePermit ?? true) && !isDai) {
129
132
  const nonce = await (0, actions_1.readContract)(viemClient, {
130
133
  abi: blue_sdk_viem_1.erc2612Abi,
131
134
  address: params.token,
@@ -149,68 +152,30 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
149
152
  deadline: params.deadline,
150
153
  now: timestamp,
151
154
  supportDeployless: params.supportDeployless,
152
- }), blue_sdk_viem_1.MissingPermitDomainNameError);
153
- if ((0, morpho_ts_1.isDefined)(permit))
154
- return [permit];
155
- // A token that exposes nonces() but has neither name() nor
156
- // eip712Domain() cannot be permitted over a known domain: fall
157
- // 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
+ }
158
176
  }
159
177
  }
160
- if (permit2 != null) {
161
- const permit2Nonce = params.permit2Nonce ??
162
- (await (0, getUnusedPermit2Nonce_js_1.getUnusedPermit2Nonce)(viemClient, {
163
- owner: params.owner,
164
- chainId: params.chainId,
165
- }));
166
- if (permit2Nonce < 0n) {
167
- throw new index_js_3.NegativeInputError("permit2Nonce", permit2Nonce);
168
- }
169
- if (permit2Nonce > viem_1.maxUint256) {
170
- throw new index_js_3.InputExceedsMaxError({
171
- field: "permit2Nonce",
172
- value: permit2Nonce,
173
- max: viem_1.maxUint256,
174
- });
175
- }
176
- const wordPosition = permit2Nonce >> 8n;
177
- const [allowance, nonceBitmap] = await Promise.all([
178
- (0, actions_1.readContract)(viemClient, {
179
- abi: viem_1.erc20Abi,
180
- address: params.token,
181
- functionName: "allowance",
182
- args: [params.owner, permit2],
183
- }),
184
- (0, actions_1.readContract)(viemClient, {
185
- abi: blue_sdk_viem_1.permit2Abi,
186
- address: permit2,
187
- functionName: "nonceBitmap",
188
- args: [params.owner, wordPosition],
189
- }),
190
- ]);
191
- return (0, index_js_1.resolveBundlesTokenRequirements)({
192
- token: params.token,
193
- spender: params.spender,
194
- owner: params.owner,
195
- chainId: params.chainId,
196
- amount: params.amount,
197
- deadline: params.deadline,
198
- now: timestamp,
199
- state: {
200
- type: "permit2SignatureTransfer",
201
- permit2Allowance: allowance,
202
- permit2Nonce,
203
- nonceBitmap,
204
- },
205
- });
206
- }
207
178
  }
208
- const allowance = await (0, actions_1.readContract)(viemClient, {
209
- abi: viem_1.erc20Abi,
210
- address: params.token,
211
- functionName: "allowance",
212
- args: [params.owner, params.spender],
213
- });
214
179
  return (0, index_js_1.resolveBundlesTokenRequirements)({
215
180
  token: params.token,
216
181
  spender: params.spender,
@@ -1,5 +1,8 @@
1
1
  import { type Address, type Client } from "viem";
2
- /** Parameters for {@link getUnusedPermit2Nonce}. */
2
+ /**
3
+ * Parameters for {@link getUnusedPermit2Nonce}.
4
+ * @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
5
+ */
3
6
  export interface GetUnusedPermit2NonceParams {
4
7
  /** Account that will sign the Permit2 SignatureTransfer. */
5
8
  readonly owner: Address;
@@ -9,8 +12,7 @@ export interface GetUnusedPermit2NonceParams {
9
12
  readonly startNonce?: bigint;
10
13
  }
11
14
  /**
12
- * Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
13
- * {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
15
+ * Finds the lowest unused Permit2 unordered nonce for legacy SignatureTransfer integrations.
14
16
  *
15
17
  * Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
16
18
  * `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
@@ -45,5 +47,6 @@ export interface GetUnusedPermit2NonceParams {
45
47
  * });
46
48
  * // permit2Nonce satisfies bigint
47
49
  * ```
50
+ * @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
48
51
  */
49
52
  export declare const getUnusedPermit2Nonce: (viemClient: Client, params: GetUnusedPermit2NonceParams) => Promise<bigint>;
@@ -12,8 +12,7 @@ const index_js_2 = require("../../types/index.js");
12
12
  /** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
13
13
  const MAX_PERMIT2_NONCE_WORD = viem_1.maxUint256 >> 8n;
14
14
  /**
15
- * Finds the lowest unused Permit2 unordered nonce for `owner`, ready to pass as `permit2Nonce` to
16
- * {@link getBundlesTokenRequirements} or as `nonce` to {@link encodeErc20Permit2SignatureTransfer}.
15
+ * Finds the lowest unused Permit2 unordered nonce for legacy SignatureTransfer integrations.
17
16
  *
18
17
  * Permit2 SignatureTransfer consumes an unordered 256-bit nonce; a nonce is free when its bit in
19
18
  * `nonceBitmap(owner, word)` is unset. This scans consecutive bitmap words starting at `startNonce`
@@ -48,6 +47,7 @@ const MAX_PERMIT2_NONCE_WORD = viem_1.maxUint256 >> 8n;
48
47
  * });
49
48
  * // permit2Nonce satisfies bigint
50
49
  * ```
50
+ * @deprecated The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals.
51
51
  */
52
52
  const getUnusedPermit2Nonce = async (viemClient, params) => {
53
53
  (0, index_js_1.validateChainId)(viemClient.chain?.id, params.chainId);
@@ -27,8 +27,8 @@ export interface VaultV1Actions {
27
27
  * Prepares a Vault V1 deposit through the registered VaultBundlesV1 contract.
28
28
  *
29
29
  * Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
30
- * `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612 or
31
- * Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
30
+ * `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612
31
+ * nonce state. Native funding is exclusive and skips token requirements. Shares are
32
32
  * always minted to the transaction sender, which must be `userAddress`.
33
33
  * Concurrent requirement reads share the first caller's options; later calls refresh on-chain
34
34
  * state using their own options.
@@ -53,19 +53,14 @@ export interface VaultV1Actions {
53
53
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
54
54
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
55
55
  * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
56
- * @throws {NegativeInputError} when funding, slippage, the referral fee, or a Permit2 nonce is negative.
56
+ * @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
57
57
  * @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
58
58
  * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
59
59
  * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
60
60
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
61
61
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
62
62
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
63
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
64
- * owner is consumed and none was passed explicitly.
65
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
66
- * explicit Permit2 nonce is consumed.
67
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
68
- * `getRequirements()` when the Permit2 nonce exceeds uint256.
63
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
69
64
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
70
65
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
71
66
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -481,8 +476,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
481
476
  * before any other requirement read. This VaultV1 `inKindRedeem` path validates the client chain
482
477
  * before this code check.
483
478
  *
484
- * @param roles - Registry labels to resolve and check; `permit2` is skipped when the
485
- * chain registers none.
479
+ * @param roles - Registry labels to resolve and check.
486
480
  */
487
481
  private assertWriteTargets;
488
482
  /** {@inheritDoc VaultV1Actions.deposit} */
@@ -39,17 +39,12 @@ class MorphoVaultV1 {
39
39
  * before any other requirement read. This VaultV1 `inKindRedeem` path validates the client chain
40
40
  * before this code check.
41
41
  *
42
- * @param roles - Registry labels to resolve and check; `permit2` is skipped when the
43
- * chain registers none.
42
+ * @param roles - Registry labels to resolve and check.
44
43
  */
45
44
  async assertWriteTargets(roles) {
46
45
  const targets = [];
47
46
  for (const role of roles) {
48
- const address = role === "permit2"
49
- ? (0, morpho_ts_1.getChainAddresses)(this.chainId).permit2
50
- : (0, morpho_ts_1.getChainAddress)(this.chainId, role);
51
- if (address == null)
52
- continue;
47
+ const address = (0, morpho_ts_1.getChainAddress)(this.chainId, role);
53
48
  targets.push({ role, address });
54
49
  }
55
50
  await (0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(this.client.viemClient, this.chainId, targets);
@@ -97,9 +92,7 @@ class MorphoVaultV1 {
97
92
  // Memoize the in-flight promise so concurrent callers share one round of
98
93
  // allowance/nonce reads.
99
94
  const pending = (async () => {
100
- await this.assertWriteTargets(funding.value === 0n && this.client.options.supportSignature
101
- ? ["bundles.vaultBundlesV1", "permit2"]
102
- : ["bundles.vaultBundlesV1"]);
95
+ await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
103
96
  return funding.value > 0n
104
97
  ? []
105
98
  : (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
@@ -112,7 +105,6 @@ class MorphoVaultV1 {
112
105
  supportSignature: this.client.options.supportSignature,
113
106
  supportDeployless: this.client.options.supportDeployless,
114
107
  useSimplePermit: requirementOptions?.useSimplePermit,
115
- permit2Nonce: requirementOptions?.permit2Nonce,
116
108
  now,
117
109
  });
118
110
  })();
@@ -32,8 +32,8 @@ export interface VaultV2Actions {
32
32
  * Prepares a Vault V2 deposit through the registered VaultBundlesV1 contract.
33
33
  *
34
34
  * Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
35
- * `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612 or
36
- * Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
35
+ * `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612
36
+ * nonce state. Native funding is exclusive and skips token requirements. Shares are
37
37
  * always minted to the transaction sender, which must be `userAddress`.
38
38
  * Concurrent requirement reads share the first caller's options; later calls refresh on-chain
39
39
  * state using their own options.
@@ -58,19 +58,14 @@ export interface VaultV2Actions {
58
58
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
59
59
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
60
60
  * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
61
- * @throws {NegativeInputError} when funding, slippage, the referral fee, or a Permit2 nonce is negative.
61
+ * @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
62
62
  * @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
63
63
  * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
64
64
  * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
65
65
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
66
66
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
67
67
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
68
- * @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
69
- * owner is consumed and none was passed explicitly.
70
- * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
71
- * explicit Permit2 nonce is consumed.
72
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
73
- * `getRequirements()` when the Permit2 nonce exceeds uint256.
68
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
74
69
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
75
70
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
76
71
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -555,8 +550,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
555
550
  * before any other requirement read. The `inKindRedeem` and `forceWithdraw` paths validate the
556
551
  * client chain before this code check.
557
552
  *
558
- * @param roles - Registry labels to resolve and check; `permit2` is skipped when the
559
- * chain registers none.
553
+ * @param roles - Registry labels to resolve and check.
560
554
  */
561
555
  private assertWriteTargets;
562
556
  /** {@inheritDoc VaultV2Actions.deposit} */