@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.2

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 (174) hide show
  1. package/MIGRATION-v5-to-v6.md +127 -16
  2. package/README.md +17 -11
  3. package/lib/cjs/abis.d.ts +17 -2
  4. package/lib/cjs/abis.js +14 -1
  5. package/lib/cjs/actions/blue/common.js +5 -26
  6. package/lib/cjs/actions/blue/supply.js +2 -7
  7. package/lib/cjs/actions/bundles/common.d.ts +32 -2
  8. package/lib/cjs/actions/bundles/common.js +68 -30
  9. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  10. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
  11. package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
  12. package/lib/cjs/actions/requirements/blue/index.js +0 -1
  13. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  14. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +20 -20
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -27
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  18. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  19. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  20. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  21. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  22. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  23. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  24. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  25. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  26. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  27. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
  30. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
  31. package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
  34. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  35. package/lib/cjs/blue/abis.d.ts +5 -1
  36. package/lib/cjs/blue/abis.js +2 -0
  37. package/lib/cjs/blue/entities.d.ts +8 -2
  38. package/lib/cjs/blue/entities.js +1 -0
  39. package/lib/cjs/blue/errors.d.ts +1 -1
  40. package/lib/cjs/blue/errors.js +2 -1
  41. package/lib/cjs/blue/fetch.d.ts +3 -1
  42. package/lib/cjs/blue/fetch.js +1 -0
  43. package/lib/cjs/entities/blue/blue.d.ts +15 -6
  44. package/lib/cjs/entities/blue/blue.js +3 -0
  45. package/lib/cjs/entities/index.d.ts +8 -2
  46. package/lib/cjs/entities/index.js +1 -0
  47. package/lib/cjs/entities/midnight/midnight.js +20 -24
  48. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  49. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
  50. package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  51. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  52. package/lib/cjs/entities/requirements/index.js +1 -0
  53. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +10 -5
  54. package/lib/cjs/entities/vaultV1/vaultV1.js +13 -1
  55. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  56. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  57. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +140 -34
  58. package/lib/cjs/entities/vaultV2/vaultV2.js +229 -16
  59. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
  61. package/lib/cjs/errors.d.ts +1 -1
  62. package/lib/cjs/errors.js +3 -2
  63. package/lib/cjs/fetch.d.ts +3 -1
  64. package/lib/cjs/fetch.js +1 -0
  65. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  66. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  67. package/lib/cjs/helpers/index.d.ts +3 -1
  68. package/lib/cjs/helpers/index.js +10 -1
  69. package/lib/cjs/helpers/metadata.d.ts +3 -5
  70. package/lib/cjs/helpers/metadata.js +4 -6
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  72. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
  73. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  74. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  75. package/lib/cjs/helpers/slippage.d.ts +46 -0
  76. package/lib/cjs/helpers/slippage.js +65 -0
  77. package/lib/cjs/helpers/validate.d.ts +65 -8
  78. package/lib/cjs/helpers/validate.js +83 -9
  79. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  80. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
  81. package/lib/cjs/types/action.d.ts +95 -13
  82. package/lib/cjs/types/error.d.ts +290 -12
  83. package/lib/cjs/types/error.js +312 -24
  84. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  85. package/lib/cjs/utils.d.ts +3 -1
  86. package/lib/cjs/utils.js +10 -1
  87. package/lib/esm/abis.d.ts +17 -2
  88. package/lib/esm/abis.js +17 -2
  89. package/lib/esm/actions/blue/common.js +7 -28
  90. package/lib/esm/actions/blue/supply.js +4 -9
  91. package/lib/esm/actions/bundles/common.d.ts +32 -2
  92. package/lib/esm/actions/bundles/common.js +68 -31
  93. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
  94. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
  95. package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
  96. package/lib/esm/actions/requirements/blue/index.js +0 -1
  97. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
  98. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
  99. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  100. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -28
  101. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
  102. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
  105. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
  106. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
  107. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
  108. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
  109. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
  110. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +6 -0
  111. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +2 -0
  112. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
  113. package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
  114. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
  115. package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
  116. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -0
  117. package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
  118. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  119. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  120. package/lib/esm/blue/abis.d.ts +5 -1
  121. package/lib/esm/blue/abis.js +5 -1
  122. package/lib/esm/blue/entities.d.ts +8 -2
  123. package/lib/esm/blue/entities.js +3 -1
  124. package/lib/esm/blue/errors.d.ts +1 -1
  125. package/lib/esm/blue/errors.js +1 -1
  126. package/lib/esm/blue/fetch.d.ts +3 -1
  127. package/lib/esm/blue/fetch.js +3 -1
  128. package/lib/esm/entities/blue/blue.d.ts +15 -6
  129. package/lib/esm/entities/blue/blue.js +3 -0
  130. package/lib/esm/entities/index.d.ts +8 -2
  131. package/lib/esm/entities/index.js +3 -1
  132. package/lib/esm/entities/midnight/midnight.js +20 -24
  133. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
  134. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
  135. package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
  136. package/lib/esm/entities/requirements/index.d.ts +1 -0
  137. package/lib/esm/entities/requirements/index.js +1 -0
  138. package/lib/esm/entities/vaultV1/vaultV1.d.ts +10 -5
  139. package/lib/esm/entities/vaultV1/vaultV1.js +14 -2
  140. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  141. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  142. package/lib/esm/entities/vaultV2/vaultV2.d.ts +140 -34
  143. package/lib/esm/entities/vaultV2/vaultV2.js +234 -21
  144. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  145. package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
  146. package/lib/esm/errors.d.ts +1 -1
  147. package/lib/esm/errors.js +1 -1
  148. package/lib/esm/fetch.d.ts +3 -1
  149. package/lib/esm/fetch.js +3 -1
  150. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  151. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  152. package/lib/esm/helpers/index.d.ts +3 -1
  153. package/lib/esm/helpers/index.js +3 -1
  154. package/lib/esm/helpers/metadata.d.ts +3 -5
  155. package/lib/esm/helpers/metadata.js +4 -6
  156. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
  157. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
  158. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  159. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  160. package/lib/esm/helpers/slippage.d.ts +46 -0
  161. package/lib/esm/helpers/slippage.js +65 -1
  162. package/lib/esm/helpers/validate.d.ts +65 -8
  163. package/lib/esm/helpers/validate.js +82 -10
  164. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
  165. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
  166. package/lib/esm/types/action.d.ts +95 -13
  167. package/lib/esm/types/error.d.ts +290 -12
  168. package/lib/esm/types/error.js +301 -19
  169. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  170. package/lib/esm/utils.d.ts +3 -1
  171. package/lib/esm/utils.js +3 -1
  172. package/package.json +7 -7
  173. /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
  174. /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesRequirementSignature = exports.selectBundlesTokenRequirementSignature = exports.getBundlesSharesPermit = exports.normalizeBundlesSignature = exports.getBundlesTokenPermit = exports.resolveBundlesFunding = exports.normalizeBundlesCommonParams = exports.BundlesPermitKind = void 0;
3
+ exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesPermitSignature = exports.selectBundlesSharesRequirementSignature = exports.selectBundlesTokenRequirementSignature = exports.getBundlesSharesPermit = exports.normalizeBundlesSignature = exports.getBundlesTokenPermit = exports.resolveBundlesFunding = exports.normalizeBundlesCommonParams = exports.BundlesPermitKind = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
7
  const index_js_1 = require("../../helpers/index.js");
8
+ const validate_js_1 = require("../../helpers/validate.js");
8
9
  const index_js_2 = require("../../types/index.js");
9
10
  /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
10
11
  exports.BundlesPermitKind = {
@@ -30,32 +31,12 @@ const EMPTY_TOKEN_PERMIT = {
30
31
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
31
32
  */
32
33
  const normalizeBundlesCommonParams = (params) => {
33
- if (params.deadline <= 0n) {
34
- throw new index_js_2.NonPositiveInputError("deadline", params.deadline);
35
- }
36
- if (params.deadline > viem_1.maxUint256) {
37
- throw new index_js_2.InputExceedsMaxError({
38
- field: "deadline",
39
- value: params.deadline,
40
- max: viem_1.maxUint256,
41
- });
42
- }
43
- const referralFeePct = params.referralFeePct ?? 0n;
44
- if (referralFeePct < 0n) {
45
- throw new index_js_2.NegativeInputError("referralFeePct", referralFeePct);
46
- }
47
- if (referralFeePct >= blue_sdk_1.MathLib.WAD) {
48
- throw new index_js_2.ReferralFeePctExceededError(referralFeePct);
49
- }
50
- if (referralFeePct > 0n &&
51
- (params.referralFeeRecipient == null ||
52
- (0, viem_1.isAddressEqual)(params.referralFeeRecipient, viem_1.zeroAddress))) {
53
- throw new index_js_2.ReferralFeeRecipientMissingError();
54
- }
34
+ (0, validate_js_1.validateDeadline)(params.deadline);
35
+ const { referralFeePct, referralFeeRecipient } = (0, validate_js_1.validateReferralFee)(params);
55
36
  return {
56
37
  deadline: params.deadline,
57
38
  referralFeePct,
58
- referralFeeRecipient: params.referralFeeRecipient ?? viem_1.zeroAddress,
39
+ referralFeeRecipient,
59
40
  };
60
41
  };
61
42
  exports.normalizeBundlesCommonParams = normalizeBundlesCommonParams;
@@ -204,8 +185,17 @@ const getBundlesTokenPermit = (params) => {
204
185
  };
205
186
  };
206
187
  exports.getBundlesTokenPermit = getBundlesTokenPermit;
207
- /** @internal Normalizes a compact or serialized ECDSA signature for bundles permit tuples. */
208
- const normalizeBundlesSignature = (serializedSignature) => {
188
+ /**
189
+ * Normalizes a compact or serialized ECDSA signature for bundles permit tuples.
190
+ *
191
+ * @internal
192
+ *
193
+ * @param serializedSignature - Compact or serialized ECDSA signature.
194
+ * @param onInvalid - Error factory used when parsing or extracting the recovery identifier fails.
195
+ * @returns The normalized signature tuple.
196
+ * @throws {BundlesPermitMismatchError} when the signature is malformed.
197
+ */
198
+ const normalizeBundlesSignature = (serializedSignature, onInvalid = (details) => new index_js_2.BundlesPermitMismatchError({ field: "signature", ...details })) => {
209
199
  let parsed;
210
200
  try {
211
201
  parsed =
@@ -214,8 +204,7 @@ const normalizeBundlesSignature = (serializedSignature) => {
214
204
  : (0, viem_1.parseSignature)(serializedSignature);
215
205
  }
216
206
  catch (cause) {
217
- throw new index_js_2.BundlesPermitMismatchError({
218
- field: "signature",
207
+ throw onInvalid({
219
208
  expected: "a 64-byte compact or 65-byte serialized ECDSA signature",
220
209
  actual: serializedSignature,
221
210
  cause,
@@ -224,8 +213,7 @@ const normalizeBundlesSignature = (serializedSignature) => {
224
213
  const normalizedV = parsed.v ??
225
214
  (parsed.yParity == null ? undefined : BigInt(parsed.yParity + 27));
226
215
  if (normalizedV == null) {
227
- throw new index_js_2.BundlesPermitMismatchError({
228
- field: "signature",
216
+ throw onInvalid({
229
217
  expected: "a signature containing v or yParity",
230
218
  actual: serializedSignature,
231
219
  });
@@ -451,6 +439,56 @@ const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
451
439
  return selectedPermit;
452
440
  };
453
441
  exports.selectBundlesSharesRequirementSignature = selectBundlesSharesRequirementSignature;
442
+ /**
443
+ * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
444
+ *
445
+ * @internal
446
+ *
447
+ * @param signatures - Signatures passed to the operation's `buildTx` function.
448
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
449
+ * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
450
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
451
+ * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
452
+ * vault's `permit` verifies at execution.
453
+ */
454
+ const selectBundlesSharesPermitSignature = (signatures, expected) => {
455
+ const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
456
+ if (permit == null)
457
+ return undefined;
458
+ const { action } = permit;
459
+ if (action.type !== "permit") {
460
+ throw new index_js_2.BundlesPermitMismatchError({
461
+ field: "type",
462
+ expected: "permit",
463
+ actual: action.type,
464
+ });
465
+ }
466
+ if (!(0, viem_1.isAddressEqual)(action.args.spender, expected.spender)) {
467
+ throw new index_js_2.BundlesPermitMismatchError({
468
+ field: "spender",
469
+ expected: expected.spender,
470
+ actual: action.args.spender,
471
+ });
472
+ }
473
+ if (permit.args.amount !== expected.amount ||
474
+ action.args.amount !== expected.amount) {
475
+ throw new index_js_2.BundlesPermitMismatchError({
476
+ field: "amount",
477
+ expected: String(expected.amount),
478
+ actual: String(permit.args.amount),
479
+ });
480
+ }
481
+ if (permit.args.deadline !== expected.deadline ||
482
+ action.args.deadline !== expected.deadline) {
483
+ throw new index_js_2.BundlesPermitMismatchError({
484
+ field: "deadline",
485
+ expected: String(expected.deadline),
486
+ actual: String(permit.args.deadline),
487
+ });
488
+ }
489
+ return { args: permit.args, action };
490
+ };
491
+ exports.selectBundlesSharesPermitSignature = selectBundlesSharesPermitSignature;
454
492
  /** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
455
493
  const getBundlesReferralFeeAssets = (assets, referralFeePct) => blue_sdk_1.MathLib.mulDivDown(assets, referralFeePct, blue_sdk_1.MathLib.WAD);
456
494
  exports.getBundlesReferralFeeAssets = getBundlesReferralFeeAssets;
@@ -28,6 +28,9 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
28
28
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
29
29
  * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
30
30
  * GeneralAdapter1 nor its BlueBundlesV1 operator.
31
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
32
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
33
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
31
34
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
32
35
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
33
36
  * @example
@@ -5,6 +5,7 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
7
  const viem_1 = require("viem");
8
+ const validate_js_1 = require("../../../helpers/validate.js");
8
9
  const index_js_1 = require("../../../types/index.js");
9
10
  const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSignatureAuthorization.js");
10
11
  /**
@@ -34,6 +35,9 @@ const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSigna
34
35
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
36
  * @throws {UnsupportedAuthorizationOperatorError} when `authorized` is neither the chain's
36
37
  * GeneralAdapter1 nor its BlueBundlesV1 operator.
38
+ * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
39
+ * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
40
+ * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
37
41
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
42
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
39
43
  * @example
@@ -80,16 +84,7 @@ const getBlueAuthorizationRequirement = async (params) => {
80
84
  // one before the RPC reads so the caller never signs an authorization that cannot be encoded
81
85
  // or would revert on-chain. An omitted deadline defaults downstream to two hours from now.
82
86
  if (params.deadline != null) {
83
- if (params.deadline <= 0n) {
84
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
85
- }
86
- if (params.deadline > viem_1.maxUint256) {
87
- throw new index_js_1.InputExceedsMaxError({
88
- field: "deadline",
89
- value: params.deadline,
90
- max: viem_1.maxUint256,
91
- });
92
- }
87
+ (0, validate_js_1.validateDeadline)(params.deadline);
93
88
  const timestamp = morpho_ts_1.Time.timestamp();
94
89
  if (params.deadline <= timestamp) {
95
90
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
@@ -117,6 +112,7 @@ const getBlueAuthorizationRequirement = async (params) => {
117
112
  return null;
118
113
  }
119
114
  return (0, encodeBlueSignatureAuthorization_js_1.encodeBlueSignatureAuthorization)(viemClient, {
115
+ owner: userAddress,
120
116
  authorized,
121
117
  chainId,
122
118
  nonce,
@@ -1,2 +1 @@
1
1
  export * from "./getBlueAuthorizationRequirement.js";
2
- export * from "./getUnusedPermit2Nonce.js";
@@ -15,4 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./getBlueAuthorizationRequirement.js"), exports);
18
- __exportStar(require("./getUnusedPermit2Nonce.js"), exports);
@@ -1,13 +1,15 @@
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 granting the authorization and signing it (the Morpho `authorizer`). */
7
+ owner: Address;
6
8
  /** Operator to authorize on Morpho, such as GeneralAdapter1 or BlueBundlesV1. */
7
9
  authorized: Address;
8
10
  /** Target chain id; must match `viemClient.chain.id`. */
9
11
  chainId: number;
10
- /** The signer's current Morpho authorization nonce. */
12
+ /** The owner's current Morpho authorization nonce. */
11
13
  nonce: bigint;
12
14
  /** Whether to grant (`true`, default) or revoke (`false`) the authorization. */
13
15
  isAuthorized?: boolean;
@@ -21,23 +23,27 @@ interface EncodeBlueSignatureAuthorizationParams {
21
23
  *
22
24
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
23
25
  * typed data, verifies it against the connected account, and returns a deep-frozen
24
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
25
- * from `Time.timestamp()`.
26
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
27
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
28
+ * Deadline defaults to two hours from `Time.timestamp()`.
26
29
  *
27
30
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
28
31
  * @param params - Authorization encoding parameters.
32
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
29
33
  * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
30
34
  * @param params.chainId - Target chain id.
31
- * @param params.nonce - The signer's current Morpho authorization nonce.
35
+ * @param params.nonce - The owner's current Morpho authorization nonce.
32
36
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
33
37
  * @param params.deadline - Optional signature deadline in seconds.
34
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
38
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
39
+ * `sign(client, userAddress)` produces the deep-frozen signature.
35
40
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
36
41
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
37
42
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
38
43
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
39
44
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
40
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
45
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
46
+ * client account differs from `userAddress`.
41
47
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
42
48
  * @example
43
49
  * ```ts
@@ -47,11 +53,12 @@ interface EncodeBlueSignatureAuthorizationParams {
47
53
  *
48
54
  * const client = createWalletClient({ chain: mainnet, transport: http() });
49
55
  * const requirement = await encodeBlueSignatureAuthorization(client, {
56
+ * owner,
50
57
  * authorized: generalAdapter1,
51
58
  * chainId: 1,
52
59
  * nonce: 0n,
53
60
  * });
54
- * // requirement satisfies Requirement
61
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
55
62
  * ```
56
63
  */
57
64
  export declare const encodeBlueSignatureAuthorization: (viemClient: Client, params: EncodeBlueSignatureAuthorizationParams) => Promise<Requirement<AuthorizationRequirementSignature>>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeBlueSignatureAuthorization = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
6
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
+ const validate_js_1 = require("../../../helpers/validate.js");
8
8
  const index_js_1 = require("../../../types/index.js");
9
9
  /**
10
10
  * Builds a Morpho authorization `Requirement` that, once signed, lets `authorized` operate on
@@ -13,23 +13,27 @@ const index_js_1 = require("../../../types/index.js");
13
13
  *
14
14
  * The returned `Requirement.sign()` produces the EIP-712 signature over Morpho's `Authorization`
15
15
  * typed data, verifies it against the connected account, and returns a deep-frozen
16
- * `RequirementSignature` the selected transaction route consumes. Deadline defaults to two hours
17
- * from `Time.timestamp()`.
16
+ * `RequirementSignature` the selected transaction route consumes. The requirement's
17
+ * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
18
+ * Deadline defaults to two hours from `Time.timestamp()`.
18
19
  *
19
20
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
21
  * @param params - Authorization encoding parameters.
22
+ * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
21
23
  * @param params.authorized - Operator to authorize, such as GeneralAdapter1 or BlueBundlesV1.
22
24
  * @param params.chainId - Target chain id.
23
- * @param params.nonce - The signer's current Morpho authorization nonce.
25
+ * @param params.nonce - The owner's current Morpho authorization nonce.
24
26
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
25
27
  * @param params.deadline - Optional signature deadline in seconds.
26
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
28
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
29
+ * `sign(client, userAddress)` produces the deep-frozen signature.
27
30
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
28
31
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
29
32
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
30
33
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
31
34
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
32
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
35
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
36
+ * client account differs from `userAddress`.
33
37
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
34
38
  * @example
35
39
  * ```ts
@@ -39,15 +43,16 @@ const index_js_1 = require("../../../types/index.js");
39
43
  *
40
44
  * const client = createWalletClient({ chain: mainnet, transport: http() });
41
45
  * const requirement = await encodeBlueSignatureAuthorization(client, {
46
+ * owner,
42
47
  * authorized: generalAdapter1,
43
48
  * chainId: 1,
44
49
  * nonce: 0n,
45
50
  * });
46
- * // requirement satisfies Requirement
51
+ * // Inspect the EIP-712 payload (requirement.action.typedData) or sign via requirement.sign(...).
47
52
  * ```
48
53
  */
49
54
  const encodeBlueSignatureAuthorization = async (viemClient, params) => {
50
- const { authorized, chainId, nonce, isAuthorized = true } = params;
55
+ const { owner, authorized, chainId, nonce, isAuthorized = true } = params;
51
56
  if (viemClient.chain?.id !== chainId) {
52
57
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
53
58
  }
@@ -57,30 +62,25 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
57
62
  // `getBlueAuthorizationRequirement` resolver guards. An omitted deadline defaults to two hours
58
63
  // from now and is always valid.
59
64
  if (params.deadline != null) {
60
- if (params.deadline <= 0n) {
61
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
62
- }
63
- if (params.deadline > viem_1.maxUint256) {
64
- throw new index_js_1.InputExceedsMaxError({
65
- field: "deadline",
66
- value: params.deadline,
67
- max: viem_1.maxUint256,
68
- });
69
- }
65
+ (0, validate_js_1.validateDeadline)(params.deadline);
70
66
  const timestamp = morpho_ts_1.Time.timestamp();
71
67
  if (params.deadline <= timestamp) {
72
68
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
73
69
  }
74
70
  }
75
71
  const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
72
+ const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
76
73
  const action = {
77
74
  type: "authorization",
78
75
  args: { authorized, isAuthorized, deadline },
76
+ typedData,
79
77
  };
80
78
  return {
81
79
  action,
82
80
  async sign(client, userAddress) {
83
- const typedData = (0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: userAddress, authorized, isAuthorized, nonce, deadline }, chainId);
81
+ // The authorizer is fixed at build time (the fetched nonce is owner-specific), so a different
82
+ // signer cannot produce a valid authorization for it.
83
+ (0, validate_js_1.validateUserAddress)(userAddress, owner);
84
84
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
85
85
  client,
86
86
  userAddress,
@@ -88,7 +88,7 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
88
88
  });
89
89
  return (0, morpho_ts_1.deepFreeze)({
90
90
  args: {
91
- owner: userAddress,
91
+ owner,
92
92
  authorized,
93
93
  isAuthorized,
94
94
  nonce,
@@ -1,9 +1,11 @@
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 Erc2612RequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeErc20Permit}. */
5
5
  interface EncodeErc20PermitParams {
6
6
  token: Address;
7
+ /** Account that owns the tokens and signs the permit. */
8
+ owner: Address;
7
9
  spender: Address;
8
10
  amount: bigint;
9
11
  chainId: number;
@@ -17,20 +19,23 @@ interface EncodeErc20PermitParams {
17
19
  *
18
20
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
19
21
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
20
- * the selected transaction route can consume. Deadline defaults to two hours from
21
- * `Time.timestamp()`.
22
+ * the selected transaction route can consume. The requirement's `action.typedData` holds that
23
+ * EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
24
+ * hours from `Time.timestamp()`.
22
25
  *
23
26
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
24
27
  * @param params - Permit encoding parameters.
25
28
  * @param params.token - ERC-20 token address (must support EIP-2612).
29
+ * @param params.owner - Account that owns the tokens and signs the permit.
26
30
  * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
27
31
  * VaultBundlesV1, or BlueBundlesV1 for the chain.
28
32
  * @param params.amount - Permit allowance amount.
29
33
  * @param params.chainId - Target chain id.
30
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
34
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
31
35
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
32
36
  * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
33
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
37
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
38
+ * `sign(client, userAddress)` produces the deep-frozen signature.
34
39
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
40
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
36
41
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
@@ -40,7 +45,8 @@ interface EncodeErc20PermitParams {
40
45
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
41
46
  * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
42
47
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
43
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
48
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
49
+ * client account differs from `userAddress`.
44
50
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
45
51
  * @example
46
52
  * ```ts
@@ -51,12 +57,15 @@ interface EncodeErc20PermitParams {
51
57
  * const client = createWalletClient({ chain: mainnet, transport: http() });
52
58
  * const requirement = await encodeErc20Permit(client, {
53
59
  * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
60
+ * owner,
54
61
  * spender: generalAdapter1,
55
62
  * amount: 1_000_000n,
56
63
  * chainId: 1,
57
64
  * nonce: 0n,
58
65
  * });
59
- * // requirement satisfies Requirement
66
+ * // Inspect the EIP-712 payload, then sign via the requirement:
67
+ * const typedData = requirement.action.typedData;
68
+ * const signed = await requirement.sign(client, owner);
60
69
  * ```
61
70
  */
62
71
  export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement<Erc2612RequirementSignature>>;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeErc20Permit = void 0;
4
4
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- const viem_1 = require("viem");
7
6
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
+ const validate_js_1 = require("../../../helpers/validate.js");
8
8
  const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
9
9
  const index_js_1 = require("../../../types/index.js");
10
10
  /**
@@ -13,20 +13,23 @@ const index_js_1 = require("../../../types/index.js");
13
13
  *
14
14
  * Reads token metadata via `fetchToken`. The returned `Requirement.sign()` produces the EIP-712
15
15
  * signature, verifies it against the connected account, and returns a `RequirementSignature`
16
- * the selected transaction route can consume. Deadline defaults to two hours from
17
- * `Time.timestamp()`.
16
+ * the selected transaction route can consume. The requirement's `action.typedData` holds that
17
+ * EIP-712 payload so it can be inspected or displayed before signing. Deadline defaults to two
18
+ * hours from `Time.timestamp()`.
18
19
  *
19
20
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
21
  * @param params - Permit encoding parameters.
21
22
  * @param params.token - ERC-20 token address (must support EIP-2612).
23
+ * @param params.owner - Account that owns the tokens and signs the permit.
22
24
  * @param params.spender - Permit spender. Must be GeneralAdapter1, MidnightBundles,
23
25
  * VaultBundlesV1, or BlueBundlesV1 for the chain.
24
26
  * @param params.amount - Permit allowance amount.
25
27
  * @param params.chainId - Target chain id.
26
- * @param params.nonce - The user's current EIP-2612 nonce on `token`.
28
+ * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
27
29
  * @param params.supportDeployless - Whether `fetchToken` should use deployless multicall.
28
30
  * @param params.deadline - Signature expiration timestamp. Defaults to two hours from now.
29
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
31
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
32
+ * `sign(client, userAddress)` produces the deep-frozen signature.
30
33
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
31
34
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
32
35
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not GeneralAdapter1,
@@ -36,7 +39,8 @@ const index_js_1 = require("../../../types/index.js");
36
39
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
37
40
  * @throws {viem.BaseError} when the token metadata read fails with no fallback left.
38
41
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
39
- * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
42
+ * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
43
+ * client account differs from `userAddress`.
40
44
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.
41
45
  * @example
42
46
  * ```ts
@@ -47,16 +51,19 @@ const index_js_1 = require("../../../types/index.js");
47
51
  * const client = createWalletClient({ chain: mainnet, transport: http() });
48
52
  * const requirement = await encodeErc20Permit(client, {
49
53
  * token: USDC, // Must implement standard ERC-2612. DAI is routed through Permit2 by requirement helpers.
54
+ * owner,
50
55
  * spender: generalAdapter1,
51
56
  * amount: 1_000_000n,
52
57
  * chainId: 1,
53
58
  * nonce: 0n,
54
59
  * });
55
- * // requirement satisfies Requirement
60
+ * // Inspect the EIP-712 payload, then sign via the requirement:
61
+ * const typedData = requirement.action.typedData;
62
+ * const signed = await requirement.sign(client, owner);
56
63
  * ```
57
64
  */
58
65
  const encodeErc20Permit = async (viemClient, params) => {
59
- const { token, spender, amount, chainId, nonce, supportDeployless } = params;
66
+ const { token, owner, spender, amount, chainId, nonce, supportDeployless } = params;
60
67
  if (viemClient.chain?.id !== chainId) {
61
68
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
62
69
  }
@@ -75,16 +82,7 @@ const encodeErc20Permit = async (viemClient, params) => {
75
82
  // called independently of the BlueBundlesV1 resolver, and an out-of-range or already-expired
76
83
  // deadline otherwise surfaces only as a downstream wallet typed-data error or an on-chain revert.
77
84
  if (params.deadline != null) {
78
- if (params.deadline <= 0n) {
79
- throw new index_js_1.NonPositiveInputError("deadline", params.deadline);
80
- }
81
- if (params.deadline > viem_1.maxUint256) {
82
- throw new index_js_1.InputExceedsMaxError({
83
- field: "deadline",
84
- value: params.deadline,
85
- max: viem_1.maxUint256,
86
- });
87
- }
85
+ (0, validate_js_1.validateDeadline)(params.deadline);
88
86
  if (params.deadline <= now) {
89
87
  throw new index_js_1.ExpiredDeadlineError(params.deadline, now);
90
88
  }
@@ -93,6 +91,18 @@ const encodeErc20Permit = async (viemClient, params) => {
93
91
  const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
94
92
  deployless: supportDeployless,
95
93
  });
94
+ const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
95
+ erc20: tokenData,
96
+ owner,
97
+ spender,
98
+ allowance: amount,
99
+ nonce,
100
+ deadline,
101
+ }, chainId);
102
+ const typedData = (0, morpho_ts_1.deepFreeze)({
103
+ ...permitTypedData,
104
+ domain: { ...permitTypedData.domain },
105
+ });
96
106
  const action = {
97
107
  type: "permit",
98
108
  args: {
@@ -101,18 +111,14 @@ const encodeErc20Permit = async (viemClient, params) => {
101
111
  deadline,
102
112
  nonce,
103
113
  },
114
+ typedData,
104
115
  };
105
116
  return {
106
117
  action,
107
118
  async sign(client, userAddress) {
108
- const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
109
- erc20: tokenData,
110
- owner: userAddress,
111
- spender,
112
- allowance: amount,
113
- nonce,
114
- deadline,
115
- }, chainId);
119
+ // The permit's owner is fixed at build time (the fetched nonce is owner-specific), so a
120
+ // different signer cannot produce a valid signature for it.
121
+ (0, validate_js_1.validateUserAddress)(userAddress, owner);
116
122
  const signature = await (0, signAndVerifyTypedData_js_1.signAndVerifyTypedData)({
117
123
  client,
118
124
  userAddress,
@@ -120,7 +126,7 @@ const encodeErc20Permit = async (viemClient, params) => {
120
126
  });
121
127
  return (0, morpho_ts_1.deepFreeze)({
122
128
  args: {
123
- owner: userAddress,
129
+ owner,
124
130
  signature,
125
131
  deadline,
126
132
  amount,
@@ -12,7 +12,8 @@ interface EncodeErc20Permit2ApproveParams {
12
12
  * Builds a Permit2 `Requirement` that, once signed, lets GeneralAdapter1 pull `amount` of `token`
13
13
  * via the Permit2 contract.
14
14
  *
15
- * Deadline defaults to two hours from `Time.timestamp()`.
15
+ * The requirement's `action.typedData` holds the EIP-712 payload so it can be inspected or
16
+ * displayed before signing. Deadline defaults to two hours from `Time.timestamp()`.
16
17
  *
17
18
  * @param params - Permit2 encoding parameters.
18
19
  * @param params.token - ERC-20 token address.
@@ -20,7 +21,8 @@ interface EncodeErc20Permit2ApproveParams {
20
21
  * @param params.chainId - Target chain id.
21
22
  * @param params.nonce - The user's current Permit2 nonce for `(token, GeneralAdapter1)`.
22
23
  * @param params.expiration - Permit2-managed allowance expiration timestamp.
23
- * @returns A `Requirement` whose `sign(client, userAddress)` produces the deep-frozen signature.
24
+ * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
25
+ * `sign(client, userAddress)` produces the deep-frozen signature.
24
26
  * @throws {MissingClientPropertyError} from `sign()` when the client has no `account.address`.
25
27
  * @throws {AddressMismatchError} from `sign()` when the client account differs from `userAddress`.
26
28
  * @throws {InvalidSignatureError} from `sign()` when EIP-712 verification fails.