@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
@@ -25,10 +25,10 @@ GeneralAdapter1.
25
25
  > application needs deposits or withdrawals on an affected chain until VaultBundlesV1 is deployed
26
26
  > and registered in the SDK.
27
27
 
28
- As checked on 2026-09-07, the [official deployment list](https://docs.morpho.org/developers/contracts/addresses/#bundles)
29
- and the [SDK registry](../morpho-ts/src/addresses.ts) list VaultBundlesV1 on 13 chains: Ethereum,
30
- Arbitrum, Base, HyperEVM, Katana, Monad, Optimism, Polygon, Robinhood, Stable, Tempo, Unichain, and
31
- World Chain. Bundler3 availability alone does not imply support for v6 vault deposits or withdrawals.
28
+ As checked on 2026-09-23, the [official deployment list](https://docs.morpho.org/developers/contracts/addresses/#bundles)
29
+ and the [SDK registry](../morpho-ts/src/addresses.ts) list VaultBundlesV1 on 14 chains: Ethereum,
30
+ Arbitrum, Arc, Base, HyperEVM, Katana, Monad, Optimism, Polygon, Robinhood, Stable, Tempo, Unichain,
31
+ and World Chain. Bundler3 availability alone does not imply support for v6 vault deposits or withdrawals.
32
32
 
33
33
  Update deposit inputs as follows:
34
34
 
@@ -41,8 +41,12 @@ Update deposit inputs as follows:
41
41
 
42
42
  For ERC-20 funding, approvals and ERC-2612 permits now name VaultBundlesV1 as spender. Permit2
43
43
  keeps its ERC-20 approval on canonical Permit2, while its one-time SignatureTransfer payload names
44
- VaultBundlesV1. Resolve requirements and build from the same prepared handle so its captured nonce,
45
- deadline, asset, owner, amount, and spender remain consistent:
44
+ VaultBundlesV1. `buildTx()` validates the supplied signature's deadline, asset, owner, amount,
45
+ and spender against the operation's values; the signed nonce is checked against the nonce carried
46
+ on the requirement's action when present and otherwise verified onchain by the spender (a
47
+ consumed-nonce ERC-2612 permit is skipped and the live allowance applies; a consumed Permit2
48
+ SignatureTransfer nonce reverts onchain). Finalize on any handle built
49
+ from identical params (or one resumed from serialized state):
46
50
 
47
51
  ```ts
48
52
  const deposit = vault.deposit({
@@ -89,7 +93,7 @@ Version 6 also preserves the Vault V1 and Vault V2 method and builder names whil
89
93
  | Stable method | v5 input/workflow | v6 input/workflow |
90
94
  | --- | --- | --- |
91
95
  | `deposit` | Additive `amount` and `nativeAmount`; Bundler3/GeneralAdapter1 requirements. | Supply exactly one of `amount` or `nativeAmount`; optionally set `deadline`, `referralFeePct`, and `referralFeeRecipient`. Token requirements authorize VaultBundlesV1 and may return Permit2 SignatureTransfer. |
92
- | `withdraw` | Direct vault withdrawal with no share requirement. | Exact-assets VaultBundlesV1 exit. Optionally set `slippageTolerance`, `deadline`, and referral fields; resolve a vault-share approval or ERC-2612 permit before building. |
96
+ | `withdraw` | Direct vault withdrawal with no share requirement. | Exact-assets VaultBundlesV1 exit. Pass required `vaultData` (from `await vault.getData()`); optionally set `slippageTolerance`, `deadline`, and referral fields; resolve a vault-share approval or ERC-2612 permit before building. |
93
97
  | `redeem` | Direct vault redemption with no share requirement. | Exact-shares VaultBundlesV1 exit. Optionally set `deadline` and referral fields; resolve a vault-share approval or ERC-2612 permit before building. |
94
98
  | `migrateToV2` (Vault V1 only) | Share-denominated Bundler3 migration with a source `minSharePriceVaultV1`. | Keep the existing `shares` mode or supply the new `assets` alternative; remove the source share-price bound; optionally set `slippageTolerance`, `deadline`, and referral fields. Resolve source-vault share authorization before building. The destination deposit retains its onchain maximum-share-price bound. |
95
99
 
@@ -152,7 +156,7 @@ stable, but now encode one direct VaultBundlesV1 call instead of a direct vault
152
156
 
153
157
  | Flow | v5 input | v6 input |
154
158
  | --- | --- | --- |
155
- | `withdraw` | `amount`, `userAddress` | Keep `amount` and `userAddress`; remove the implicit `recipient` / `onBehalf` (VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`); add optional `slippageTolerance`, `deadline`, and referral-fee fields. |
159
+ | `withdraw` | `amount`, `userAddress` | Keep `amount` and `userAddress`; add required `vaultData` (from `await vault.getData()`); remove the implicit `recipient` / `onBehalf` (VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`); add optional `slippageTolerance`, `deadline`, and referral-fee fields. |
156
160
 
157
161
  `withdraw` now returns `{ buildTx, getRequirements }` instead of `{ buildTx }`. VaultBundlesV1 spends
158
162
  the caller's vault shares, so the withdrawal needs a vault-share allowance for VaultBundlesV1 — a
@@ -166,9 +170,9 @@ prerequisite v5 withdrawals did not have. Await `getRequirements()` and satisfy
166
170
  transaction instead, because VaultBundlesV1 skips a permit whose nonce was already consumed.
167
171
 
168
172
  The allowance is the only cap on the burn, since asset-mode calldata carries no maximum-shares
169
- argument. `getRequirements()` therefore derives an exact cap from the vault snapshot, the deadline,
170
- and `slippageTolerance` (default 0.03%), and returns an approval or permit for exactly that amount
171
- whenever the current allowance differs.
173
+ argument. The exact cap is derived at handle creation from the supplied `vaultData`, the deadline,
174
+ and `slippageTolerance` (default 0.03%); `getRequirements()` re-reads the live allowance against
175
+ that fixed cap and returns an approval or permit for exactly that amount whenever it differs.
172
176
 
173
177
  `getRequirements()` re-validates the deadline on every call, so a prepared withdrawal reused after
174
178
  its deadline throws `ExpiredDeadlineError` rather than returning cached prerequisites.
@@ -192,8 +196,9 @@ their `args` objects as follows. `metadata` is unchanged.
192
196
 
193
197
  The transaction metadata exports and discriminator strings stay stable; their argument fields change
194
198
  as below. The table lists only the delta: unchanged fields are retained and omitted. In particular
195
- every Blue action keeps its `market` (`Hex` market id) field, so a strict decoder must keep matching
196
- it alongside the added fields.
199
+ every Blue action except `blueRefinance` keeps its `market` (`Hex` market id) field, so a strict
200
+ decoder must keep matching it alongside the added fields; `blueRefinance` uses
201
+ `sourceMarket`/`destinationMarket` instead.
197
202
 
198
203
  | Stable action type / discriminator | Removed v5 `action.args` fields | Changed / added v6 `action.args` fields |
199
204
  | --- | --- | --- |
@@ -486,7 +491,7 @@ Migration steps:
486
491
  - Replace `InKindRedeemRequiresSingleAdapterError` and `UnsupportedInKindAdapterError` with
487
492
  `VaultV2SingleAdapterRequiredError` and `VaultV2UnsupportedExitAdapterError`.
488
493
 
489
- See the [`TIB-2026-08-28-vault-exit-force-withdraw`](https://github.com/morpho-org/sdks/blob/main/docs/tibs/TIB-2026-08-28-vault-exit-force-withdraw.md)
494
+ See the [`ADR-2026-08-28-vault-exit-force-withdraw`](https://github.com/morpho-org/sdks/blob/main/docs/adrs/ADR-2026-08-28-vault-exit-force-withdraw.md)
490
495
  decision record for the full rationale.
491
496
 
492
497
  ## Update Vault V1 and Vault V2 writes
@@ -518,7 +523,8 @@ can inspect the bundle's transient initiator, validate them by simulating the fi
518
523
  after satisfying requirements rather than by pre-reading the gate.
519
524
 
520
525
  ```ts
521
- const withdrawal = vault.withdraw({ amount, userAddress });
526
+ const vaultData = await vault.getData();
527
+ const withdrawal = vault.withdraw({ amount, userAddress, vaultData });
522
528
  const signatures = [];
523
529
  for (const requirement of await withdrawal.getRequirements()) {
524
530
  if ("sign" in requirement) {
package/README.md CHANGED
@@ -42,12 +42,12 @@ BlueBundlesV1, and the remaining rows identify their destination.
42
42
  | | `inKindRedeem` | VaultExitBundlesV1 |
43
43
  | **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
44
44
  | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `repayWithdrawCollateral` | Midnight Bundles |
45
- | | `makeLend`, `makeBorrow` | Midnight mempool |
45
+ | | `makeLend`, `makeBorrow`, `supplyCollateralMakeBorrow` | Midnight mempool |
46
46
  | | `supplyCollateral`, `redeem`, `cancelOffer` | Direct call |
47
47
 
48
48
  `VaultExitBundlesV1`, `VaultBundlesV1`, and `BlueBundlesV1` are registered on Ethereum, Base,
49
- Arbitrum, Optimism, Polygon, World Chain, Unichain, HyperEVM, Katana, Monad, Stable, Tempo, and
50
- Robinhood Chain. Custom deployments can still be configured with `registerCustomAddresses`.
49
+ Arbitrum, Optimism, Polygon, World Chain, Unichain, HyperEVM, Katana, Monad, Stable, Tempo,
50
+ Robinhood Chain, and Arc. Custom deployments can still be configured with `registerCustomAddresses`.
51
51
 
52
52
  ## How it works
53
53
 
@@ -150,7 +150,8 @@ async function withdrawUsdc(provider: EIP1193Provider, supportSignature = false)
150
150
  const [userAddress] = await walletClient.requestAddresses();
151
151
  if (!userAddress) throw new Error("Connect a wallet account before withdrawing.");
152
152
  const vault = client.morpho.vaultV2("0x04422053aDDbc9bB2759b248B574e3FCA76Bc145", mainnet.id);
153
- const withdrawal = vault.withdraw({ amount: 500_000n, userAddress });
153
+ const vaultData = await vault.getData();
154
+ const withdrawal = vault.withdraw({ amount: 500_000n, userAddress, vaultData });
154
155
  const requirements = await withdrawal.getRequirements();
155
156
  const requirement = requirements[0];
156
157
 
@@ -351,7 +352,8 @@ Link this package to your app for local debugging:
351
352
 
352
353
  ```bash
353
354
  # In this morpho-sdk project
354
- pnpm run build:link
355
+ pnpm build
356
+ pnpm link
355
357
  ```
356
358
 
357
359
  ```bash
package/lib/cjs/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/cjs/abis.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.blueBundlesV1Abi = exports.vaultBundlesV1Abi = exports.vaultExitBundlesV1Abi = exports.midnightSetterRatifierAbi = exports.midnightBundlesAbi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.bluePreLiquidationFactoryAbi = exports.bluePreLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.blueAdaptiveCurveIrmAbi = exports.blueMarketParamsAbi = void 0;
3
+ exports.blueBundlesV1Abi = exports.vaultBundlesV1Abi = exports.vaultExitBundlesV1Abi = exports.midnightSetterRatifierAbi = exports.midnightRateRatifierV1Abi = exports.midnightPriceRatifierV1Abi = exports.midnightBundlesAbi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.bluePreLiquidationFactoryAbi = exports.bluePreLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.blueAdaptiveCurveIrmAbi = exports.blueMarketParamsAbi = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  Object.defineProperty(exports, "blueMarketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
6
6
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
@@ -33,6 +33,8 @@ var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
33
33
  Object.defineProperty(exports, "midnightEcrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
34
34
  Object.defineProperty(exports, "midnightAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightAbi; } });
35
35
  Object.defineProperty(exports, "midnightBundlesAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesAbi; } });
36
+ Object.defineProperty(exports, "midnightPriceRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.priceRatifierV1Abi; } });
37
+ Object.defineProperty(exports, "midnightRateRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.rateRatifierV1Abi; } });
36
38
  Object.defineProperty(exports, "midnightSetterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });
37
39
  /** ABI for the VaultExitBundlesV1 periphery contract. */
38
40
  exports.vaultExitBundlesV1Abi = [
@@ -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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets = exports.selectBundlesSharesPermitSignature = 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");
@@ -346,12 +346,17 @@ exports.getBundlesSharesPermit = getBundlesSharesPermit;
346
346
  * @internal
347
347
  *
348
348
  * @param signatures - Signatures passed to `buildTx`.
349
- * @param expectedRequirement - Signature requirement captured by this prepared operation.
349
+ * @param expected - Immutable spender, amount, and deadline required by the operation.
350
+ * @param expected.spender - Fixed bundles contract the signature must authorize.
351
+ * @param expected.amount - Exact pull amount the signature must cover.
352
+ * @param expected.deadline - Deadline the signature must carry.
350
353
  * @returns The selected ERC-2612 or Permit2 SignatureTransfer signature.
351
354
  * @throws {UnexpectedRequirementSignatureError} when a non-token signature is supplied.
352
355
  * @throws {AmbiguousRequirementSignaturesError} when both token signature kinds are supplied.
356
+ * @throws {BundlesPermitMismatchError} when the signature's spender, amount, or deadline differ
357
+ * from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
353
358
  */
354
- const selectBundlesTokenRequirementSignature = (signatures, expectedRequirement) => {
359
+ const selectBundlesTokenRequirementSignature = (signatures, expected) => {
355
360
  if (signatures == null || signatures.length === 0)
356
361
  return undefined;
357
362
  const selected = signatures.filter((signature) => signature.action.type === "permit" ||
@@ -371,100 +376,45 @@ const selectBundlesTokenRequirementSignature = (signatures, expectedRequirement)
371
376
  const selectedSignature = selected[0];
372
377
  if (selectedSignature == null)
373
378
  return undefined;
374
- validatePreparedBundlesRequirementSignature(selectedSignature, expectedRequirement);
375
- return selectedSignature;
376
- };
377
- exports.selectBundlesTokenRequirementSignature = selectBundlesTokenRequirementSignature;
378
- const validatePreparedBundlesRequirementSignature = (signature, expectedRequirement) => {
379
- if (expectedRequirement == null) {
380
- throw new index_js_2.BundlesPermitMismatchError({
381
- field: "nonce",
382
- expected: "the nonce from getRequirements()",
383
- actual: String(signature.args.nonce),
384
- });
385
- }
386
- if (signature.action.type !== expectedRequirement.type) {
387
- throw new index_js_2.BundlesPermitMismatchError({
388
- field: "type",
389
- expected: expectedRequirement.type,
390
- actual: signature.action.type,
391
- });
392
- }
393
- const expectedArgs = expectedRequirement.args;
394
- if (!(0, viem_1.isAddressEqual)(signature.action.args.spender, expectedArgs.spender)) {
379
+ const { action } = selectedSignature;
380
+ if (!(0, viem_1.isAddressEqual)(action.args.spender, expected.spender)) {
395
381
  throw new index_js_2.BundlesPermitMismatchError({
396
382
  field: "spender",
397
- expected: expectedArgs.spender,
398
- actual: signature.action.args.spender,
383
+ expected: expected.spender,
384
+ actual: action.args.spender,
399
385
  });
400
386
  }
401
- if (signature.args.amount !== expectedArgs.amount ||
402
- signature.action.args.amount !== expectedArgs.amount) {
387
+ if (selectedSignature.args.amount !== expected.amount ||
388
+ action.args.amount !== expected.amount) {
403
389
  throw new index_js_2.BundlesPermitMismatchError({
404
390
  field: "amount",
405
- expected: String(expectedArgs.amount),
406
- actual: String(signature.args.amount),
391
+ expected: String(expected.amount),
392
+ actual: String(selectedSignature.args.amount !== expected.amount
393
+ ? selectedSignature.args.amount
394
+ : action.args.amount),
407
395
  });
408
396
  }
409
- if (signature.args.deadline !== expectedArgs.deadline ||
410
- signature.action.args.deadline !== expectedArgs.deadline) {
397
+ if (selectedSignature.args.deadline !== expected.deadline ||
398
+ action.args.deadline !== expected.deadline) {
411
399
  throw new index_js_2.BundlesPermitMismatchError({
412
400
  field: "deadline",
413
- expected: String(expectedArgs.deadline),
414
- actual: String(signature.args.deadline),
401
+ expected: String(expected.deadline),
402
+ actual: String(selectedSignature.args.deadline !== expected.deadline
403
+ ? selectedSignature.args.deadline
404
+ : action.args.deadline),
415
405
  });
416
406
  }
417
- if (expectedArgs.nonce == null ||
418
- signature.args.nonce !== expectedArgs.nonce ||
419
- signature.action.args.nonce !== expectedArgs.nonce) {
407
+ if (action.args.nonce != null &&
408
+ action.args.nonce !== selectedSignature.args.nonce) {
420
409
  throw new index_js_2.BundlesPermitMismatchError({
421
410
  field: "nonce",
422
- expected: expectedArgs.nonce == null
423
- ? "the nonce from getRequirements()"
424
- : String(expectedArgs.nonce),
425
- actual: String(signature.args.nonce),
426
- });
427
- }
428
- };
429
- /**
430
- * Selects the exact ERC-2612 vault-share permit produced for one prepared exit.
431
- *
432
- * @internal
433
- *
434
- * @param signatures - Signatures passed to the prepared operation's `buildTx` function.
435
- * @param prepared - Exact share cap and permit requirement captured by this prepared operation.
436
- * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
437
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, was built for another
438
- * share cap, or is supplied before this operation resolves its share cap.
439
- */
440
- const selectBundlesSharesRequirementSignature = (signatures, prepared) => {
441
- const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
442
- if (permit == null)
443
- return undefined;
444
- const { action } = permit;
445
- if (action.type !== "permit") {
446
- throw new index_js_2.BundlesPermitMismatchError({
447
- field: "type",
448
- expected: "permit",
449
- actual: action.type,
411
+ expected: String(selectedSignature.args.nonce),
412
+ actual: String(action.args.nonce),
450
413
  });
451
414
  }
452
- if (prepared.requiredShareAllowance == null ||
453
- permit.args.amount !== prepared.requiredShareAllowance ||
454
- action.args.amount !== prepared.requiredShareAllowance) {
455
- throw new index_js_2.BundlesPermitMismatchError({
456
- field: "amount",
457
- expected: prepared.requiredShareAllowance == null
458
- ? "the current cap from getRequirements()"
459
- : String(prepared.requiredShareAllowance),
460
- actual: String(permit.args.amount),
461
- });
462
- }
463
- const selectedPermit = { args: permit.args, action };
464
- validatePreparedBundlesRequirementSignature(selectedPermit, prepared.expectedRequirement);
465
- return selectedPermit;
415
+ return selectedSignature;
466
416
  };
467
- exports.selectBundlesSharesRequirementSignature = selectBundlesSharesRequirementSignature;
417
+ exports.selectBundlesTokenRequirementSignature = selectBundlesTokenRequirementSignature;
468
418
  /**
469
419
  * Selects the ERC-2612 vault-share permit for one exit from its immutable operation fields alone.
470
420
  *
@@ -472,10 +422,13 @@ exports.selectBundlesSharesRequirementSignature = selectBundlesSharesRequirement
472
422
  *
473
423
  * @param signatures - Signatures passed to the operation's `buildTx` function.
474
424
  * @param expected - Immutable spender, amount, and deadline required by the operation.
425
+ * @param expected.spender - Fixed bundles contract the permit must authorize.
426
+ * @param expected.amount - Exact share allowance the permit must cover.
427
+ * @param expected.deadline - Deadline the permit must carry.
475
428
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
476
- * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount or
477
- * deadline differ from the operation's. The nonce is not checked here: it is onchain state the
478
- * vault's `permit` verifies at execution.
429
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612 or its spender, amount
430
+ * or deadline differ from the operation's. The nonce is not checked here: it is onchain state
431
+ * the vault's `permit` verifies at execution.
479
432
  */
480
433
  const selectBundlesSharesPermitSignature = (signatures, expected) => {
481
434
  const { permit } = (0, index_js_2.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";
@@ -25,7 +25,8 @@ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApp
25
25
  * @param params.owner - Account funding the operation and owning the Permit2 nonce bitmap.
26
26
  * @param params.chainId - Target chain id used to resolve supported approval spenders and canonical Permit2.
27
27
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
28
- * @param params.deadline - Signature expiration as a Unix timestamp in seconds.
28
+ * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
29
+ * SignatureTransfer branch it must be positive, within uint256, and in the future.
29
30
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
30
31
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
31
32
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -38,10 +39,13 @@ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApp
38
39
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
39
40
  * BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
40
41
  * @throws {NegativeInputError} when an amount or Permit2 nonce is negative.
41
- * @throws {InputExceedsMaxError} when `amount` or the Permit2 nonce exceeds uint256.
42
+ * @throws {InputExceedsMaxError} when `amount`, the Permit2 nonce, or the SignatureTransfer
43
+ * `deadline` exceeds uint256.
42
44
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} when the selected nonce bit is set.
43
45
  * @throws {ApprovalAmountLessThanSpendAmountError} when a classic approval cannot cover the pull.
44
46
  * @throws {UnknownAddressError} when the SignatureTransfer branch runs on a chain without canonical Permit2.
47
+ * @throws {NonPositiveInputError} when the SignatureTransfer `deadline` is not positive.
48
+ * @throws {ExpiredDeadlineError} when the SignatureTransfer `deadline` is positive but not in the future.
45
49
  * @example
46
50
  * ```ts
47
51
  * 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
@@ -37,6 +37,7 @@ const encodeBlueSignatureAuthorization_js_1 = require("../encode/encodeBlueSigna
37
37
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
38
38
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
39
39
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
40
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on the target chain.
40
41
  * @throws {viem.BaseError} when an authorization or nonce RPC read fails.
41
42
  * @example
42
43
  * ```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.
@@ -3,6 +3,7 @@ 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");
6
7
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
7
8
  const validate_js_1 = require("../../../helpers/validate.js");
8
9
  const index_js_1 = require("../../../types/index.js");
@@ -15,11 +16,15 @@ const index_js_1 = require("../../../types/index.js");
15
16
  * `RequirementSignature` the selected transaction route consumes. The requirement's
16
17
  * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
17
18
  * Deadline defaults to two hours from `Time.timestamp()`.
19
+ * The operator pin applies to grants and revocations alike: revoking a previously registered
20
+ * operator is outside this helper's scope.
18
21
  *
19
22
  * @param viemClient - Connected viem `Client` whose `chain.id` matches `params.chainId`.
20
23
  * @param params - Authorization encoding parameters.
21
24
  * @param params.owner - Account granting the authorization and signing it (the Morpho `authorizer`).
22
- * @param params.authorized - BlueBundlesV1 operator to authorize.
25
+ * @param params.authorized - BlueBundlesV1 operator to authorize; must be the chain's
26
+ * registered BlueBundlesV1 deployment, so a misconfigured `authorized` cannot grant an
27
+ * arbitrary address control over the signer's Morpho positions.
23
28
  * @param params.chainId - Target chain id.
24
29
  * @param params.nonce - The owner's current Morpho authorization nonce.
25
30
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
@@ -27,6 +32,10 @@ const index_js_1 = require("../../../types/index.js");
27
32
  * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
28
33
  * `sign(client, userAddress)` produces the deep-frozen signature.
29
34
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
35
+ * @throws {UnsupportedChainIdError} when `params.chainId` is absent from the address registry.
36
+ * @throws {UnknownAddressError} when BlueBundlesV1 is not registered on `params.chainId`.
37
+ * @throws {UnsupportedAuthorizationOperatorError} when `params.authorized` is not the chain's
38
+ * registered BlueBundlesV1 deployment.
30
39
  * @throws {NonPositiveInputError} when a provided `deadline` is not positive.
31
40
  * @throws {InputExceedsMaxError} when a provided `deadline` exceeds `uint256`.
32
41
  * @throws {ExpiredDeadlineError} when a provided `deadline` is positive but not in the future.
@@ -55,6 +64,15 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
55
64
  if (viemClient.chain?.id !== chainId) {
56
65
  throw new index_js_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
57
66
  }
67
+ // Pin the authorized operator to the chain's registered BlueBundlesV1 so a direct caller
68
+ // cannot sign an authorization granting an arbitrary address control over the signer's Morpho
69
+ // positions. Mirrors the `getBlueAuthorizationRequirement` resolver guard and applies to grant
70
+ // and revoke payloads alike: the registry is pinned per release, so revoking a rotated-out
71
+ // operator is outside this helper's scope.
72
+ const blueBundlesV1 = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.blueBundlesV1");
73
+ if (!(0, viem_1.isAddressEqual)(blueBundlesV1, authorized)) {
74
+ throw new index_js_1.UnsupportedAuthorizationOperatorError(authorized, chainId);
75
+ }
58
76
  // Reject an invalid or already-expired caller-supplied deadline before signing, so a direct caller
59
77
  // is never walked through a wallet EIP-712 prompt for an authorization Morpho would reject with
60
78
  // `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`.
@@ -8,6 +8,7 @@ const viem_1 = require("viem");
8
8
  const signAndVerifyTypedData_js_1 = require("../../../helpers/signAndVerifyTypedData.js");
9
9
  const validate_js_1 = require("../../../helpers/validate.js");
10
10
  const validateRequirementSpender_js_1 = require("../../../helpers/validateRequirementSpender.js");
11
+ const index_js_1 = require("../../../types/index.js");
11
12
  /**
12
13
  * Builds the bounded ERC-2612 shares-permit requirement used by an in-kind vault exit.
13
14
  *
@@ -27,6 +28,9 @@ const validateRequirementSpender_js_1 = require("../../../helpers/validateRequir
27
28
  * can be embedded in fixed vault-bundles calldata.
28
29
  * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
29
30
  * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not a registered fixed vault-bundles contract.
31
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
32
+ * @throws {InputExceedsMaxError} when `deadline` exceeds uint256.
33
+ * @throws {ExpiredDeadlineError} when `deadline` is not in the future.
30
34
  * @throws {MissingClientPropertyError} from `sign()` when the wallet has no account.
31
35
  * @throws {AddressMismatchError} from `sign()` when `userAddress` differs from `owner`, or when the
32
36
  * wallet account differs from `userAddress`.
@@ -88,6 +92,14 @@ const encodeVaultSharesPermit = (params) => {
88
92
  spender,
89
93
  allowed: ["vaultExitBundlesV1", "vaultBundlesV1"],
90
94
  });
95
+ const now = morpho_ts_1.Time.timestamp();
96
+ // Validate the explicit deadline: this exported encoder can be called independently of the
97
+ // guarded resolvers, and an out-of-range or already-expired deadline otherwise surfaces only as
98
+ // a downstream wallet typed-data error or an on-chain revert.
99
+ (0, validate_js_1.validateDeadline)(deadline);
100
+ if (deadline <= now) {
101
+ throw new index_js_1.ExpiredDeadlineError(deadline, now);
102
+ }
91
103
  const permitTypedData = (0, blue_sdk_viem_1.getPermitTypedData)({
92
104
  owner,
93
105
  spender,