@morpho-org/morpho-sdk 6.0.0-next.4 → 6.1.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 (121) hide show
  1. package/MIGRATION-v5-to-v6.md +21 -15
  2. package/README.md +7 -5
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -1
  5. package/lib/cjs/actions/bundles/common.d.ts +18 -23
  6. package/lib/cjs/actions/bundles/common.js +36 -83
  7. package/lib/cjs/actions/bundles/index.d.ts +1 -1
  8. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
  9. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
  10. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
  11. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
  12. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
  13. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +19 -1
  14. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
  15. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +12 -0
  16. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +62 -17
  17. package/lib/cjs/actions/vaultV1/migrateToV2.js +48 -17
  18. package/lib/cjs/actions/vaultV1/redeem.d.ts +28 -1
  19. package/lib/cjs/actions/vaultV1/redeem.js +17 -1
  20. package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
  21. package/lib/cjs/actions/vaultV1/withdraw.js +1 -1
  22. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +19 -7
  23. package/lib/cjs/actions/vaultV2/forceWithdraw.js +19 -7
  24. package/lib/cjs/actions/vaultV2/redeem.d.ts +28 -1
  25. package/lib/cjs/actions/vaultV2/redeem.js +17 -1
  26. package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
  27. package/lib/cjs/actions/vaultV2/withdraw.js +1 -1
  28. package/lib/cjs/constants.d.ts +1 -1
  29. package/lib/cjs/constants.js +4 -1
  30. package/lib/cjs/entities/blue/blue.d.ts +28 -0
  31. package/lib/cjs/entities/blue/blue.js +1 -0
  32. package/lib/cjs/entities/index.d.ts +1 -1
  33. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +38 -22
  34. package/lib/cjs/entities/vaultV1/vaultV1.js +51 -84
  35. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +68 -35
  36. package/lib/cjs/entities/vaultV2/vaultV2.js +45 -72
  37. package/lib/cjs/errors.d.ts +1 -1
  38. package/lib/cjs/errors.js +8 -1
  39. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
  40. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -6
  41. package/lib/cjs/helpers/slippage.d.ts +3 -2
  42. package/lib/cjs/helpers/slippage.js +3 -2
  43. package/lib/cjs/helpers/validate.d.ts +40 -0
  44. package/lib/cjs/helpers/validate.js +40 -0
  45. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
  46. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +94 -59
  47. package/lib/cjs/midnight/abis.d.ts +1 -1
  48. package/lib/cjs/midnight/abis.js +3 -1
  49. package/lib/cjs/midnight/constants.d.ts +1 -1
  50. package/lib/cjs/midnight/constants.js +4 -1
  51. package/lib/cjs/midnight/entities.d.ts +1 -1
  52. package/lib/cjs/midnight/errors.d.ts +1 -1
  53. package/lib/cjs/midnight/errors.js +7 -1
  54. package/lib/cjs/midnight/types.d.ts +1 -1
  55. package/lib/cjs/midnight/utils.d.ts +11 -1
  56. package/lib/cjs/midnight/utils.js +13 -1
  57. package/lib/cjs/types/action.d.ts +35 -0
  58. package/lib/cjs/types/action.js +10 -0
  59. package/lib/cjs/types.d.ts +1 -1
  60. package/lib/cjs/utils.d.ts +11 -1
  61. package/lib/cjs/utils.js +14 -2
  62. package/lib/esm/abis.d.ts +1 -1
  63. package/lib/esm/abis.js +1 -1
  64. package/lib/esm/actions/bundles/common.d.ts +18 -23
  65. package/lib/esm/actions/bundles/common.js +34 -80
  66. package/lib/esm/actions/bundles/index.d.ts +1 -1
  67. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +6 -2
  68. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +6 -2
  69. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +1 -0
  70. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -0
  71. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +11 -3
  72. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -3
  73. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -1
  74. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +14 -2
  75. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +62 -17
  76. package/lib/esm/actions/vaultV1/migrateToV2.js +48 -17
  77. package/lib/esm/actions/vaultV1/redeem.d.ts +28 -1
  78. package/lib/esm/actions/vaultV1/redeem.js +17 -1
  79. package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
  80. package/lib/esm/actions/vaultV1/withdraw.js +1 -1
  81. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +19 -7
  82. package/lib/esm/actions/vaultV2/forceWithdraw.js +19 -7
  83. package/lib/esm/actions/vaultV2/redeem.d.ts +28 -1
  84. package/lib/esm/actions/vaultV2/redeem.js +17 -1
  85. package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
  86. package/lib/esm/actions/vaultV2/withdraw.js +1 -1
  87. package/lib/esm/constants.d.ts +1 -1
  88. package/lib/esm/constants.js +1 -1
  89. package/lib/esm/entities/blue/blue.d.ts +28 -0
  90. package/lib/esm/entities/blue/blue.js +1 -0
  91. package/lib/esm/entities/index.d.ts +1 -1
  92. package/lib/esm/entities/vaultV1/vaultV1.d.ts +38 -22
  93. package/lib/esm/entities/vaultV1/vaultV1.js +53 -86
  94. package/lib/esm/entities/vaultV2/vaultV2.d.ts +68 -35
  95. package/lib/esm/entities/vaultV2/vaultV2.js +47 -74
  96. package/lib/esm/errors.d.ts +1 -1
  97. package/lib/esm/errors.js +1 -1
  98. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +10 -6
  99. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -6
  100. package/lib/esm/helpers/slippage.d.ts +3 -2
  101. package/lib/esm/helpers/slippage.js +3 -2
  102. package/lib/esm/helpers/validate.d.ts +40 -0
  103. package/lib/esm/helpers/validate.js +40 -0
  104. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +94 -59
  105. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +94 -59
  106. package/lib/esm/midnight/abis.d.ts +1 -1
  107. package/lib/esm/midnight/abis.js +1 -1
  108. package/lib/esm/midnight/constants.d.ts +1 -1
  109. package/lib/esm/midnight/constants.js +1 -1
  110. package/lib/esm/midnight/entities.d.ts +1 -1
  111. package/lib/esm/midnight/errors.d.ts +1 -1
  112. package/lib/esm/midnight/errors.js +1 -1
  113. package/lib/esm/midnight/types.d.ts +1 -1
  114. package/lib/esm/midnight/utils.d.ts +11 -1
  115. package/lib/esm/midnight/utils.js +11 -1
  116. package/lib/esm/types/action.d.ts +35 -0
  117. package/lib/esm/types/action.js +10 -0
  118. package/lib/esm/types.d.ts +1 -1
  119. package/lib/esm/utils.d.ts +11 -1
  120. package/lib/esm/utils.js +11 -1
  121. package/package.json +5 -5
@@ -16,11 +16,13 @@ export interface BaseAction<TType extends string = string, TArgs extends Record<
16
16
  readonly type: TType;
17
17
  readonly args: TArgs;
18
18
  }
19
+ /** Metadata for an ERC-20 `approve` call granting `spender` an `amount` allowance. */
19
20
  export interface ERC20ApprovalAction extends BaseAction<"erc20Approval", {
20
21
  spender: Address;
21
22
  amount: bigint;
22
23
  }> {
23
24
  }
25
+ /** Metadata for an ERC-2612 permit signature requirement, exposing only the `sign` callback. */
24
26
  export interface ERC20PermitAction {
25
27
  sign: (client: WalletClient, userAddress: Address) => Promise<Hex>;
26
28
  }
@@ -106,6 +108,7 @@ export interface VaultV2ForceWithdrawAction extends BaseAction<"vaultV2ForceWith
106
108
  readonly deadline: bigint;
107
109
  }> {
108
110
  }
111
+ /** Metadata for a Vault V2 force redeem executed through the vault's native multicall. */
109
112
  export interface VaultV2ForceRedeemAction extends BaseAction<"vaultV2ForceRedeem", {
110
113
  vault: Address;
111
114
  deallocations: readonly Deallocation[];
@@ -482,6 +485,7 @@ export interface MidnightOfferRootSignatureArgs {
482
485
  }
483
486
  /** EIP-712 payload carried by a signable requirement action. */
484
487
  export type RequirementTypedData = TypedDataDefinition<Record<string, unknown>, string>;
488
+ /** Signable ERC-2612 permit requirement for a fixed-bundles token pull. */
485
489
  export interface PermitAction extends BaseAction<"permit", {
486
490
  readonly spender: Address;
487
491
  readonly amount: bigint;
@@ -636,6 +640,27 @@ export interface ActionOutput<TAction extends BaseAction = TransactionAction, TS
636
640
  export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
637
641
  /** Checks whether an action requirement is a Blue authorization call. */
638
642
  export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
643
+ /**
644
+ * Narrows an action requirement to a signature requirement.
645
+ *
646
+ * A signature requirement exposes a `sign` callback; call requirements are plain transactions.
647
+ *
648
+ * @param requirement - The requirement returned by `getRequirements()` to test.
649
+ * @returns `true` when `requirement` carries a `sign` function.
650
+ * @example
651
+ * ```ts
652
+ * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
653
+ *
654
+ * for (const requirement of await handle.getRequirements()) {
655
+ * if (isRequirementSignature(requirement)) {
656
+ * signatures.push(await requirement.sign(walletClient, userAddress));
657
+ * } else {
658
+ * const hash = await walletClient.sendTransaction(requirement);
659
+ * await client.waitForTransactionReceipt({ hash });
660
+ * }
661
+ * }
662
+ * ```
663
+ */
639
664
  export declare function isRequirementSignature<T extends RequirementSignature = RequirementSignature>(requirement: CallRequirement | Requirement<T> | undefined): requirement is Requirement<T>;
640
665
  export declare function isRequirementSignature(requirement: CallRequirement | Requirement | undefined): requirement is Requirement;
641
666
  export declare function isRequirementSignature(requirement: ActionRequirement | undefined): requirement is SignatureRequirement;
@@ -644,6 +669,16 @@ export declare function isRequirementSignature(requirement: ActionRequirement |
644
669
  *
645
670
  * @param signature - The signed requirement to test.
646
671
  * @returns `true` when `signature.action.type` is `"permit"`.
672
+ * @example
673
+ * ```ts
674
+ * import {
675
+ * isPermitSignature,
676
+ * type RequirementSignature,
677
+ * } from "@morpho-org/morpho-sdk";
678
+ *
679
+ * const getPermitDeadline = (signature: RequirementSignature): bigint | undefined =>
680
+ * isPermitSignature(signature) ? signature.args.deadline : undefined;
681
+ * ```
647
682
  */
648
683
  export declare function isPermitSignature(signature: RequirementSignature): signature is PermitRequirementSignature;
649
684
  /**
@@ -46,6 +46,16 @@ function isRequirementSignature(requirement) {
46
46
  *
47
47
  * @param signature - The signed requirement to test.
48
48
  * @returns `true` when `signature.action.type` is `"permit"`.
49
+ * @example
50
+ * ```ts
51
+ * import {
52
+ * isPermitSignature,
53
+ * type RequirementSignature,
54
+ * } from "@morpho-org/morpho-sdk";
55
+ *
56
+ * const getPermitDeadline = (signature: RequirementSignature): bigint | undefined =>
57
+ * isPermitSignature(signature) ? signature.args.deadline : undefined;
58
+ * ```
49
59
  */
50
60
  function isPermitSignature(signature) {
51
61
  return signature.action.type === "permit";
@@ -1,5 +1,5 @@
1
1
  export type { BigIntish, CollateralAllocation, Eip712Field, Erc20AllowanceRecipient, Failable, Fetchable, InputMarketParams as BlueInputMarketParams, Loadable, MarketId as BlueMarketId, MaxBorrowOptions as BlueMaxBorrowOptions, MaxPositionCapacities as BlueMaxPositionCapacities, MaxWithdrawCollateralOptions as BlueMaxWithdrawCollateralOptions, Pending, } from "@morpho-org/blue-sdk";
2
2
  export type { AuthorizationArgs as BlueAuthorizationTypedDataArgs, DeploylessFetchParameters as BlueDeploylessFetchParameters, FetchParameters as BlueFetchParameters, InputAllocation as BlueInputAllocation, MetaMorphoCall as BlueMetaMorphoCall, Permit2PermitArgs, Permit2TransferFromArgs, PermitArgs as PermitTypedDataArgs, } from "@morpho-org/blue-sdk-viem";
3
- export type { BuildFixedRateOfferChainParams as MidnightBuildFixedRateOfferChainParams, DecodedEcrecoverRatifierData as MidnightDecodedEcrecoverRatifierData, DecodedSetterRatifierData as MidnightDecodedSetterRatifierData, DeploylessFetchParameters as MidnightDeploylessFetchParameters, EcrecoverRatificationTypedData as MidnightEcrecoverRatificationTypedData, EcrecoverRatifierDataDigestParams as MidnightEcrecoverRatifierDataDigestParams, EcrecoverRatifierDataParams as MidnightEcrecoverRatifierDataParams, EcrecoverRatifierDataVerificationParams as MidnightEcrecoverRatifierDataVerificationParams, EcrecoverRatifierRatifyParams as MidnightEcrecoverRatifierRatifyParams, EcrecoverRatifierRootDigestParams as MidnightEcrecoverRatifierRootDigestParams, EcrecoverRatifierTypedDataParams as MidnightEcrecoverRatifierTypedDataParams, EcrecoverSignatureInput as MidnightEcrecoverSignatureInput, FixedRateOfferChainLeg as MidnightFixedRateOfferChainLeg, GetRatifierInfoParams as MidnightGetRatifierInfoParams, MidnightCallParameters, MidnightFetchParams, RatifierInfo as MidnightRatifierInfo, SetterRatifierDataParams as MidnightSetterRatifierDataParams, SetterRatifierDataVerificationParams as MidnightSetterRatifierDataVerificationParams, VerifiedEcrecoverRatifierData as MidnightVerifiedEcrecoverRatifierData, } from "@morpho-org/midnight-sdk";
3
+ export type { BuildFixedRateOfferChainParams as MidnightBuildFixedRateOfferChainParams, DecodedEcrecoverRatifierData as MidnightDecodedEcrecoverRatifierData, DecodedPriceRatifierV1Data as MidnightDecodedPriceRatifierV1Data, DecodedRateRatifierV1Data as MidnightDecodedRateRatifierV1Data, DecodedSetterRatifierData as MidnightDecodedSetterRatifierData, DeploylessFetchParameters as MidnightDeploylessFetchParameters, EcrecoverRatificationTypedData as MidnightEcrecoverRatificationTypedData, EcrecoverRatifierDataDigestParams as MidnightEcrecoverRatifierDataDigestParams, EcrecoverRatifierDataParams as MidnightEcrecoverRatifierDataParams, EcrecoverRatifierDataRequest as MidnightEcrecoverRatifierDataRequest, EcrecoverRatifierDataVerificationParams as MidnightEcrecoverRatifierDataVerificationParams, EcrecoverRatifierRatifyParams as MidnightEcrecoverRatifierRatifyParams, EcrecoverRatifierRatifyRequest as MidnightEcrecoverRatifierRatifyRequest, EcrecoverRatifierRootDigestParams as MidnightEcrecoverRatifierRootDigestParams, EcrecoverRatifierSignRequest as MidnightEcrecoverRatifierSignRequest, EcrecoverRatifierTypedDataParams as MidnightEcrecoverRatifierTypedDataParams, EcrecoverRatifierTypedDataRequest as MidnightEcrecoverRatifierTypedDataRequest, EcrecoverSignatureInput as MidnightEcrecoverSignatureInput, FixedRateOfferChainLeg as MidnightFixedRateOfferChainLeg, GetRatifierInfoParams as MidnightGetRatifierInfoParams, MidnightCallParameters, MidnightFetchParams, PriceRatifierV1Leaf as MidnightPriceRatifierV1Leaf, PriceRatifierV1LeafStruct as MidnightPriceRatifierV1LeafStruct, PriceRatifierV1TreeDescriptor as MidnightPriceRatifierV1TreeDescriptor, PriceRatifierV1TreeInput as MidnightPriceRatifierV1TreeInput, RateRatifierV1Leaf as MidnightRateRatifierV1Leaf, RateRatifierV1LeafStruct as MidnightRateRatifierV1LeafStruct, RateRatifierV1TreeDescriptor as MidnightRateRatifierV1TreeDescriptor, RateRatifierV1TreeInput as MidnightRateRatifierV1TreeInput, RatifierInfo as MidnightRatifierInfo, SetterRatifierDataParams as MidnightSetterRatifierDataParams, SetterRatifierDataRequest as MidnightSetterRatifierDataRequest, SetterRatifierDataVerificationParams as MidnightSetterRatifierDataVerificationParams, SetterRatifierRatifyRequest as MidnightSetterRatifierRatifyRequest, VerifiedEcrecoverRatifierData as MidnightVerifiedEcrecoverRatifierData, } from "@morpho-org/midnight-sdk";
4
4
  export type { ChainMetadata } from "@morpho-org/morpho-ts";
5
5
  export * from "./types/index.js";
@@ -5,7 +5,17 @@ defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
6
  getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
7
7
  export { decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
8
- export { EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, RatifierUtils as MidnightRatifierUtils, SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
8
+ export { EcrecoverRatifier as MidnightEcrecoverRatifier,
9
+ /** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
10
+ EcrecoverRatifierUtils as MidnightEcrecoverRatifierUtils, eip712Digest, GroupUtils as MidnightGroupUtils, MarketUtils as MidnightMarketUtils, OfferChainUtils as MidnightOfferChainUtils, OfferUtils as MidnightOfferUtils, Payload as MidnightPayload, PositionUtils as MidnightPositionUtils, PriceRatifierV1 as MidnightPriceRatifierV1,
11
+ /** @deprecated Use MidnightPriceRatifierV1. */
12
+ PriceRatifierV1Utils as MidnightPriceRatifierV1Utils, RateRatifierV1 as MidnightRateRatifierV1,
13
+ /** @deprecated Use MidnightRateRatifierV1. */
14
+ RateRatifierV1Utils as MidnightRateRatifierV1Utils, Ratifier as MidnightRatifier,
15
+ /** @deprecated Use MidnightRatifier. */
16
+ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier,
17
+ /** @deprecated Use MidnightSetterRatifier with a tagged tree. */
18
+ SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
9
19
  export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
10
20
  export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
11
21
  export { addTransactionMetadata } from "./helpers/metadata.js";
package/lib/cjs/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightRatifierUtils = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.VaultV2Utils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
4
- exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = void 0;
3
+ exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.VaultV2Utils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
4
+ exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueAdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
7
7
  Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
@@ -30,6 +30,8 @@ Object.defineProperty(exports, "safeGetAddress", { enumerable: true, get: functi
30
30
  Object.defineProperty(exports, "safeParseNumber", { enumerable: true, get: function () { return blue_sdk_viem_1.safeParseNumber; } });
31
31
  Object.defineProperty(exports, "safeParseUnits", { enumerable: true, get: function () { return blue_sdk_viem_1.safeParseUnits; } });
32
32
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
33
+ Object.defineProperty(exports, "MidnightEcrecoverRatifier", { enumerable: true, get: function () { return midnight_sdk_1.EcrecoverRatifier; } });
34
+ /** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
33
35
  Object.defineProperty(exports, "MidnightEcrecoverRatifierUtils", { enumerable: true, get: function () { return midnight_sdk_1.EcrecoverRatifierUtils; } });
34
36
  Object.defineProperty(exports, "eip712Digest", { enumerable: true, get: function () { return midnight_sdk_1.eip712Digest; } });
35
37
  Object.defineProperty(exports, "MidnightGroupUtils", { enumerable: true, get: function () { return midnight_sdk_1.GroupUtils; } });
@@ -38,7 +40,17 @@ Object.defineProperty(exports, "MidnightOfferChainUtils", { enumerable: true, ge
38
40
  Object.defineProperty(exports, "MidnightOfferUtils", { enumerable: true, get: function () { return midnight_sdk_1.OfferUtils; } });
39
41
  Object.defineProperty(exports, "MidnightPayload", { enumerable: true, get: function () { return midnight_sdk_1.Payload; } });
40
42
  Object.defineProperty(exports, "MidnightPositionUtils", { enumerable: true, get: function () { return midnight_sdk_1.PositionUtils; } });
43
+ Object.defineProperty(exports, "MidnightPriceRatifierV1", { enumerable: true, get: function () { return midnight_sdk_1.PriceRatifierV1; } });
44
+ /** @deprecated Use MidnightPriceRatifierV1. */
45
+ Object.defineProperty(exports, "MidnightPriceRatifierV1Utils", { enumerable: true, get: function () { return midnight_sdk_1.PriceRatifierV1Utils; } });
46
+ Object.defineProperty(exports, "MidnightRateRatifierV1", { enumerable: true, get: function () { return midnight_sdk_1.RateRatifierV1; } });
47
+ /** @deprecated Use MidnightRateRatifierV1. */
48
+ Object.defineProperty(exports, "MidnightRateRatifierV1Utils", { enumerable: true, get: function () { return midnight_sdk_1.RateRatifierV1Utils; } });
49
+ Object.defineProperty(exports, "MidnightRatifier", { enumerable: true, get: function () { return midnight_sdk_1.Ratifier; } });
50
+ /** @deprecated Use MidnightRatifier. */
41
51
  Object.defineProperty(exports, "MidnightRatifierUtils", { enumerable: true, get: function () { return midnight_sdk_1.RatifierUtils; } });
52
+ Object.defineProperty(exports, "MidnightSetterRatifier", { enumerable: true, get: function () { return midnight_sdk_1.SetterRatifier; } });
53
+ /** @deprecated Use MidnightSetterRatifier with a tagged tree. */
42
54
  Object.defineProperty(exports, "MidnightSetterRatifierUtils", { enumerable: true, get: function () { return midnight_sdk_1.SetterRatifierUtils; } });
43
55
  Object.defineProperty(exports, "MidnightTakeAmountsLib", { enumerable: true, get: function () { return midnight_sdk_1.TakeAmountsLib; } });
44
56
  Object.defineProperty(exports, "MidnightTickLib", { enumerable: true, get: function () { return midnight_sdk_1.TickLib; } });
package/lib/esm/abis.d.ts CHANGED
@@ -4,7 +4,7 @@ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi,
4
4
  preLiquidationAbi as bluePreLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
6
  preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
7
- export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
8
8
  /** ABI for the VaultExitBundlesV1 periphery contract. */
9
9
  export declare const vaultExitBundlesV1Abi: readonly [{
10
10
  readonly type: "constructor";
package/lib/esm/abis.js CHANGED
@@ -4,7 +4,7 @@ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi,
4
4
  preLiquidationAbi as bluePreLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
6
  preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
7
- export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
8
8
  /** ABI for the VaultExitBundlesV1 periphery contract. */
9
9
  export const vaultExitBundlesV1Abi = [
10
10
  {
@@ -1,5 +1,5 @@
1
1
  import { type Address, type Hex } from "viem";
2
- import { type BaseAction, type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Erc2612RequirementSignature, type Metadata, type Permit2SignatureTransferAction, type PermitAction, type PermitRequirementSignature, type RequirementSignature, type TokenRequirementSignature, type Transaction } from "../../types/index.js";
2
+ import { type BaseAction, type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Erc2612RequirementSignature, type Metadata, type PermitRequirementSignature, type RequirementSignature, type TokenRequirementSignature, type Transaction } from "../../types/index.js";
3
3
  /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
4
4
  export declare const BundlesPermitKind: {
5
5
  readonly None: 0;
@@ -30,8 +30,6 @@ export interface BundleSharesPermit {
30
30
  /** ECDSA signature `s`, or zero for the empty sentinel. */
31
31
  readonly s: Hex;
32
32
  }
33
- /** Compatibility alias for the canonical {@link BundleSharesPermit} tuple. */
34
- export type BundlesSharesPermit = BundleSharesPermit;
35
33
  /** Common deadline and referral fields shared by fixed bundles calls. */
36
34
  export interface BundlesCommonParams {
37
35
  /** Contract execution deadline. */
@@ -184,27 +182,21 @@ export declare const getBundlesSharesPermit: (params: {
184
182
  * @internal
185
183
  *
186
184
  * @param signatures - Signatures passed to `buildTx`.
187
- * @param expectedRequirement - Signature requirement captured by this prepared operation.
185
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
186
+ * @param expected.spender - Fixed bundles contract the signature must authorize.
187
+ * @param expected.amount - Exact pull amount the signature must cover.
188
+ * @param expected.deadline - Deadline the signature must carry.
188
189
  * @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
189
190
  * @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
190
191
  * @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
192
+ * @throws {BundlesPermitMismatchError} when the signature's spender, amount, or deadline differ
193
+ * from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
191
194
  */
192
- export declare const selectBundlesTokenRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, expectedRequirement?: PermitAction | Permit2SignatureTransferAction) => BundlesTokenRequirementSignature | undefined;
193
- /**
194
- * Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
195
- *
196
- * @internal
197
- *
198
- * @param signatures - Signatures passed to the prepared operation's `buildTx` function.
199
- * @param prepared - Exact share cap and permit requirement captured by this prepared operation.
200
- * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
201
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
202
- * share cap, or is supplied before this operation resolves its share cap.
203
- */
204
- export declare const selectBundlesSharesRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, prepared: {
205
- readonly requiredShareAllowance: bigint | undefined;
206
- readonly expectedRequirement?: PermitAction;
207
- }) => Erc2612RequirementSignature | undefined;
195
+ export declare const selectBundlesTokenRequirementSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
196
+ readonly spender: Address;
197
+ readonly amount: bigint;
198
+ readonly deadline: bigint;
199
+ }) => BundlesTokenRequirementSignature | undefined;
208
200
  /**
209
201
  * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
210
202
  *
@@ -212,10 +204,13 @@ export declare const selectBundlesSharesRequirementSignature: (signatures: reado
212
204
  *
213
205
  * @param signatures - Signatures passed to the operation's `buildTx` function.
214
206
  * @param expected - Immutable spender, amount, and deadline required by the operation.
207
+ * @param expected.spender - Fixed bundles contract the permit must authorize.
208
+ * @param expected.amount - Exact share allowance the permit must cover.
209
+ * @param expected.deadline - Deadline the permit must carry.
215
210
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
216
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
217
- * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
218
- * vault's `permit` verifies at execution.
211
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount
212
+ * or deadline differ from the operation's. The nonce is not checked here: it is onchain state
213
+ * the vault's `permit` verifies at execution.
219
214
  */
220
215
  export declare const selectBundlesSharesPermitSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
221
216
  readonly spender: Address;
@@ -338,12 +338,17 @@ export const getBundlesSharesPermit = (params) => {
338
338
  * @internal
339
339
  *
340
340
  * @param signatures - Signatures passed to `buildTx`.
341
- * @param expectedRequirement - Signature requirement captured by this prepared operation.
341
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
342
+ * @param expected.spender - Fixed bundles contract the signature must authorize.
343
+ * @param expected.amount - Exact pull amount the signature must cover.
344
+ * @param expected.deadline - Deadline the signature must carry.
342
345
  * @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
343
346
  * @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
344
347
  * @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
348
+ * @throws {BundlesPermitMismatchError} when the signature's spender, amount, or deadline differ
349
+ * from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
345
350
  */
346
- export const selectBundlesTokenRequirementSignature = (signatures, expectedRequirement) => {
351
+ export const selectBundlesTokenRequirementSignature = (signatures, expected) => {
347
352
  if (signatures == null || signatures.length === 0)
348
353
  return undefined;
349
354
  const selected = signatures.filter((signature) => signature.action.type === "permit" ||
@@ -363,97 +368,43 @@ export const selectBundlesTokenRequirementSignature = (signatures, expectedRequi
363
368
  const selectedSignature = selected[0];
364
369
  if (selectedSignature == null)
365
370
  return undefined;
366
- validatePreparedBundlesRequirementSignature(selectedSignature, expectedRequirement);
367
- return selectedSignature;
368
- };
369
- const validatePreparedBundlesRequirementSignature = (signature, expectedRequirement) => {
370
- if (expectedRequirement == null) {
371
- throw new BundlesPermitMismatchError({
372
- field: "nonce",
373
- expected: "the nonce from getRequirements()",
374
- actual: String(signature.args.nonce),
375
- });
376
- }
377
- if (signature.action.type !== expectedRequirement.type) {
378
- throw new BundlesPermitMismatchError({
379
- field: "type",
380
- expected: expectedRequirement.type,
381
- actual: signature.action.type,
382
- });
383
- }
384
- const expectedArgs = expectedRequirement.args;
385
- if (!isAddressEqual(signature.action.args.spender, expectedArgs.spender)) {
371
+ const { action } = selectedSignature;
372
+ if (!isAddressEqual(action.args.spender, expected.spender)) {
386
373
  throw new BundlesPermitMismatchError({
387
374
  field: "spender",
388
- expected: expectedArgs.spender,
389
- actual: signature.action.args.spender,
375
+ expected: expected.spender,
376
+ actual: action.args.spender,
390
377
  });
391
378
  }
392
- if (signature.args.amount !== expectedArgs.amount ||
393
- signature.action.args.amount !== expectedArgs.amount) {
379
+ if (selectedSignature.args.amount !== expected.amount ||
380
+ action.args.amount !== expected.amount) {
394
381
  throw new BundlesPermitMismatchError({
395
382
  field: "amount",
396
- expected: String(expectedArgs.amount),
397
- actual: String(signature.args.amount),
383
+ expected: String(expected.amount),
384
+ actual: String(selectedSignature.args.amount !== expected.amount
385
+ ? selectedSignature.args.amount
386
+ : action.args.amount),
398
387
  });
399
388
  }
400
- if (signature.args.deadline !== expectedArgs.deadline ||
401
- signature.action.args.deadline !== expectedArgs.deadline) {
389
+ if (selectedSignature.args.deadline !== expected.deadline ||
390
+ action.args.deadline !== expected.deadline) {
402
391
  throw new BundlesPermitMismatchError({
403
392
  field: "deadline",
404
- expected: String(expectedArgs.deadline),
405
- actual: String(signature.args.deadline),
393
+ expected: String(expected.deadline),
394
+ actual: String(selectedSignature.args.deadline !== expected.deadline
395
+ ? selectedSignature.args.deadline
396
+ : action.args.deadline),
406
397
  });
407
398
  }
408
- if (expectedArgs.nonce == null ||
409
- signature.args.nonce !== expectedArgs.nonce ||
410
- signature.action.args.nonce !== expectedArgs.nonce) {
399
+ if (action.args.nonce != null &&
400
+ action.args.nonce !== selectedSignature.args.nonce) {
411
401
  throw new BundlesPermitMismatchError({
412
402
  field: "nonce",
413
- expected: expectedArgs.nonce == null
414
- ? "the nonce from getRequirements()"
415
- : String(expectedArgs.nonce),
416
- actual: String(signature.args.nonce),
417
- });
418
- }
419
- };
420
- /**
421
- * Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
422
- *
423
- * @internal
424
- *
425
- * @param signatures - Signatures passed to the prepared operation's `buildTx` function.
426
- * @param prepared - Exact share cap and permit requirement captured by this prepared operation.
427
- * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
428
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
429
- * share cap, or is supplied before this operation resolves its share cap.
430
- */
431
- export const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
432
- const { permit } = selectRequirementSignatures(signatures, { permit: true });
433
- if (permit == null)
434
- return undefined;
435
- const { action } = permit;
436
- if (action.type !== "permit") {
437
- throw new BundlesPermitMismatchError({
438
- field: "type",
439
- expected: "permit",
440
- actual: action.type,
441
- });
442
- }
443
- if (prepared.requiredShareAllowance == null ||
444
- permit.args.amount !== prepared.requiredShareAllowance ||
445
- action.args.amount !== prepared.requiredShareAllowance) {
446
- throw new BundlesPermitMismatchError({
447
- field: "amount",
448
- expected: prepared.requiredShareAllowance == null
449
- ? "the current cap from getRequirements()"
450
- : String(prepared.requiredShareAllowance),
451
- actual: String(permit.args.amount),
403
+ expected: String(selectedSignature.args.nonce),
404
+ actual: String(action.args.nonce),
452
405
  });
453
406
  }
454
- const selectedPermit = { args: permit.args, action };
455
- validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
456
- return selectedPermit;
407
+ return selectedSignature;
457
408
  };
458
409
  /**
459
410
  * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
@@ -462,10 +413,13 @@ export const selectBundlesSharesRequirementSignature = (signatures, prepared) =>
462
413
  *
463
414
  * @param signatures - Signatures passed to the operation's `buildTx` function.
464
415
  * @param expected - Immutable spender, amount, and deadline required by the operation.
416
+ * @param expected.spender - Fixed bundles contract the permit must authorize.
417
+ * @param expected.amount - Exact share allowance the permit must cover.
418
+ * @param expected.deadline - Deadline the permit must carry.
465
419
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
466
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
467
- * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
468
- * vault's `permit` verifies at execution.
420
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount
421
+ * or deadline differ from the operation's. The nonce is not checked here: it is onchain state
422
+ * the vault's `permit` verifies at execution.
469
423
  */
470
424
  export const selectBundlesSharesPermitSignature = (signatures, expected) => {
471
425
  const { permit } = selectRequirementSignatures(signatures, { permit: true });
@@ -1,3 +1,3 @@
1
- export type { BundleSharesPermit, BundlesCommonParams, BundlesSharesPermit, BundlesTokenPermit, NormalizedBundlesCommonParams, } from "./common.js";
1
+ export type { BundleSharesPermit, BundlesCommonParams, BundlesTokenPermit, NormalizedBundlesCommonParams, } from "./common.js";
2
2
  export { BundlesPermitKind, getBundlesSharesPermit, getBundlesTokenPermit, resolveBundlesFunding, } from "./common.js";
3
3
  export * from "./resolveBundlesTokenRequirements.js";
@@ -30,7 +30,8 @@ export type BundlesTokenRequirementsState = {
30
30
  * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
31
31
  * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
32
32
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
33
- * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
33
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
34
+ * SignatureTransfer branch it must be positive, within uint256, and in the future.
34
35
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
35
36
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
36
37
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -43,10 +44,13 @@ export type BundlesTokenRequirementsState = {
43
44
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
44
45
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
45
46
  * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
46
- * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
47
+ * @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
48
+ * `deadline` exceeds uint256.
47
49
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
48
50
  * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
49
51
  * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
52
+ * @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
53
+ * @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
50
54
  * @example
51
55
  * ```ts
52
56
  * import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
@@ -22,7 +22,8 @@ import { getRequirementsApproval } from "../requirements/getRequirementsApproval
22
22
  * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
23
23
  * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
24
24
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
25
- * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
25
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
26
+ * SignatureTransfer branch it must be positive, within uint256, and in the future.
26
27
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
27
28
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
28
29
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -35,10 +36,13 @@ import { getRequirementsApproval } from "../requirements/getRequirementsApproval
35
36
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
36
37
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
37
38
  * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
38
- * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
39
+ * @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
40
+ * `deadline` exceeds uint256.
39
41
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
40
42
  * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
41
43
  * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
44
+ * @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
45
+ * @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
42
46
  * @example
43
47
  * ```ts
44
48
  * import { resolveBundlesTokenRequirements } from "@morpho-org/morpho-sdk";
@@ -30,6 +30,7 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
30
30
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
31
31
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
32
32
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
33
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on the target chain.
33
34
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
34
35
  * @example
35
36
  * ```ts
@@ -34,6 +34,7 @@ import { encodeBlueSignatureAuthorization } from "../encode/encodeBlueSignatureA
34
34
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
35
35
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
36
36
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
37
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on the target chain.
37
38
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
38
39
  * @example
39
40
  * ```ts
@@ -1,11 +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 AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeBlueSignatureAuthorization}. */
5
5
  interface EncodeBlueSignatureAuthorizationParams {
6
6
  /** Account granting the authorization and signing it (the Morpho `authorizer`). */
7
7
  owner: Address;
8
- /** BlueBundlesV1 operator to authorize on Morpho. */
8
+ /** BlueBundlesV1 operator to authorize on Morpho; must be the chain's registered deployment. */
9
9
  authorized: Address;
10
10
  /** Target chain id; must match `viemClient.chain.id`. */
11
11
  chainId: number;
@@ -25,11 +25,15 @@ interface EncodeBlueSignatureAuthorizationParams {
25
25
  * `RequirementSignature` the selected transaction route consumes. The requirement's
26
26
  * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
27
27
  * Deadline defaults to two hours from `Time.timestamp()`.
28
+ * The operator pin applies to grants and revocations alike: revoking a previously registered
29
+ * operator is outside this helper's scope.
28
30
  *
29
31
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
30
32
  * @param params - Authorization encoding parameters.
31
33
  * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
32
- * @param params.authorized - BlueBundlesV1 operator to authorize.
34
+ * @param params.authorized - BlueBundlesV1 operator to authorize; must be the chain's
35
+ * registered BlueBundlesV1 deployment, so a misconfigured `authorized` cannot grant an
36
+ * arbitrary address control over the signer's Morpho positions.
33
37
  * @param params.chainId - Target chain id.
34
38
  * @param params.nonce - The owner's current Morpho authorization nonce.
35
39
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
@@ -37,6 +41,10 @@ interface EncodeBlueSignatureAuthorizationParams {
37
41
  * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
38
42
  * `sign(client, userAddress)` produces the deep-frozen signature.
39
43
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
44
+ * @throws {UnsupportedChainIdError} when `params.chainId` is absent from the address registry.
45
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on `params.chainId`.
46
+ * @throws {UnsupportedAuthorizationOperatorError} when `params.authorized` is not the chain's
47
+ * registered BlueBundlesV1 deployment.
40
48
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
41
49
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
42
50
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
@@ -1,8 +1,9 @@
1
1
  import { getAuthorizationTypedData } from "@morpho-org/blue-sdk-viem";
2
- import { deepFreeze, Time } from "@morpho-org/morpho-ts";
2
+ import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
3
+ import { isAddressEqual } from "viem";
3
4
  import { signAndVerifyTypedData } from "../../../helpers/signAndVerifyTypedData.js";
4
5
  import { validateDeadline, validateUserAddress, } from "../../../helpers/validate.js";
5
- import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/index.js";
6
+ import { ChainIdMismatchError, ExpiredDeadlineError, UnsupportedAuthorizationOperatorError, } from "../../../types/index.js";
6
7
  /**
7
8
  * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
8
9
  * Morpho on the signer's behalf.
@@ -12,11 +13,15 @@ import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/inde
12
13
  * `RequirementSignature` the selected transaction route consumes. The requirement's
13
14
  * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
14
15
  * Deadline defaults to two hours from `Time.timestamp()`.
16
+ * The operator pin applies to grants and revocations alike: revoking a previously registered
17
+ * operator is outside this helper's scope.
15
18
  *
16
19
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
17
20
  * @param params - Authorization encoding parameters.
18
21
  * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
19
- * @param params.authorized - BlueBundlesV1 operator to authorize.
22
+ * @param params.authorized - BlueBundlesV1 operator to authorize; must be the chain's
23
+ * registered BlueBundlesV1 deployment, so a misconfigured `authorized` cannot grant an
24
+ * arbitrary address control over the signer's Morpho positions.
20
25
  * @param params.chainId - Target chain id.
21
26
  * @param params.nonce - The owner's current Morpho authorization nonce.
22
27
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
@@ -24,6 +29,10 @@ import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/inde
24
29
  * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
25
30
  * `sign(client, userAddress)` produces the deep-frozen signature.
26
31
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
32
+ * @throws {UnsupportedChainIdError} when `params.chainId` is absent from the address registry.
33
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on `params.chainId`.
34
+ * @throws {UnsupportedAuthorizationOperatorError} when `params.authorized` is not the chain's
35
+ * registered BlueBundlesV1 deployment.
27
36
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
28
37
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
29
38
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
@@ -52,6 +61,15 @@ export const encodeBlueSignatureAuthorization = async (viemClient, params) => {
52
61
  if (viemClient.chain?.id !== chainId) {
53
62
  throw new ChainIdMismatchError(viemClient.chain?.id, chainId);
54
63
  }
64
+ // Pin the authorized operator to the chain's registered BlueBundlesV1 so a direct caller
65
+ // cannot sign an authorization granting an arbitrary address control over the signer's Morpho
66
+ // positions. Mirrors the `getBlueAuthorizationRequirement` resolver guard and applies to grant
67
+ // and revoke payloads alike: the registry is pinned per release, so revoking a rotated-out
68
+ // operator is outside this helper's scope.
69
+ const blueBundlesV1 = getChainAddress(chainId, "bundles.blueBundlesV1");
70
+ if (!isAddressEqual(blueBundlesV1, authorized)) {
71
+ throw new UnsupportedAuthorizationOperatorError(authorized, chainId);
72
+ }
55
73
  // Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
56
74
  // is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
57
75
  // `SIGNATURE_EXPIRED`. Mirrors the sibling `encodeErc20Permit2SignatureTransfer` and the
@@ -1,5 +1,5 @@
1
1
  import { type Address, Token } from "@morpho-org/blue-sdk";
2
- import type { PermitRequirementSignature, Requirement } from "../../../types/index.js";
2
+ import { type PermitRequirementSignature, type Requirement } from "../../../types/index.js";
3
3
  /** Parameters for {@link encodeVaultSharesPermit}. */
4
4
  export interface EncodeVaultSharesPermitParams {
5
5
  /** Vault share token, including V1 permit-domain metadata when available. */
@@ -38,6 +38,9 @@ export interface EncodeVaultSharesPermitParams {
38
38
  * can be embedded in fixed vault-bundles calldata.
39
39
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
40
40
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
41
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
42
+ * @throws {InputExceedsMaxError} when `deadline` exceeds uint256.
43
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future.
41
44
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
42
45
  * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
43
46
  * wallet account differs from `userAddress`.