@morpho-org/morpho-sdk 9.8.0 → 10.0.0-next.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 (181) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +5 -1
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +5 -1
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
  7. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  8. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  9. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  10. package/lib/cjs/actions/midnight/cancelOffers.js +107 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  12. package/lib/cjs/actions/midnight/index.js +1 -0
  13. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  14. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
  15. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/takeBorrow.js +1 -1
  17. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeLend.js +1 -1
  19. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
  21. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeWithdraw.js +1 -1
  23. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  25. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  26. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
  31. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  32. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  33. package/lib/cjs/blue/abis.d.ts +1 -1
  34. package/lib/cjs/blue/abis.js +5 -1
  35. package/lib/cjs/blue/entities.d.ts +4 -4
  36. package/lib/cjs/blue/entities.js +3 -1
  37. package/lib/cjs/blue/errors.d.ts +2 -2
  38. package/lib/cjs/blue/errors.js +5 -1
  39. package/lib/cjs/blue/fetch.d.ts +2 -2
  40. package/lib/cjs/blue/fetch.js +3 -1
  41. package/lib/cjs/blue/utils.d.ts +1 -1
  42. package/lib/cjs/blue/utils.js +2 -1
  43. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  44. package/lib/cjs/entities/blue/blue.js +99 -73
  45. package/lib/cjs/entities/index.d.ts +4 -4
  46. package/lib/cjs/entities/index.js +3 -1
  47. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  48. package/lib/cjs/entities/midnight/deadline.js +2 -2
  49. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  50. package/lib/cjs/entities/midnight/midnight.js +144 -131
  51. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  52. package/lib/cjs/entities/midnight/publication.js +126 -100
  53. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  54. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  55. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +17 -17
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
  57. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
  58. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  59. package/lib/cjs/entities/vaultV1/vaultV1.js +83 -57
  60. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +50 -24
  61. package/lib/cjs/entities/vaultV2/vaultV2.js +166 -90
  62. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +17 -2
  63. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1410 -806
  64. package/lib/cjs/errors.d.ts +4 -4
  65. package/lib/cjs/errors.js +7 -5
  66. package/lib/cjs/fetch.d.ts +2 -2
  67. package/lib/cjs/fetch.js +3 -1
  68. package/lib/cjs/helpers/deadShares.js +55 -34
  69. package/lib/cjs/helpers/metadata.d.ts +14 -2
  70. package/lib/cjs/helpers/metadata.js +39 -4
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +34 -22
  72. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +7 -1
  73. package/lib/cjs/helpers/validate.js +76 -61
  74. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +154 -103
  75. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +31 -20
  76. package/lib/cjs/midnight/errors.d.ts +2 -1
  77. package/lib/cjs/midnight/errors.js +5 -4
  78. package/lib/cjs/transactionPlan/plan.js +6 -3
  79. package/lib/cjs/transactionPlan/serde.js +7 -7
  80. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +6 -4
  81. package/lib/cjs/transactionPlan/vaultv2/deposit.js +5 -3
  82. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +6 -4
  83. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +5 -3
  84. package/lib/cjs/types/action.d.ts +26 -2
  85. package/lib/cjs/types/action.js +1 -1
  86. package/lib/cjs/types/error.js +11 -5
  87. package/lib/cjs/types/metadata.d.ts +12 -2
  88. package/lib/cjs/utils.d.ts +2 -2
  89. package/lib/cjs/utils.js +4 -2
  90. package/lib/cjs/version.d.ts +1 -1
  91. package/lib/cjs/version.js +1 -1
  92. package/lib/esm/abis.d.ts +1 -1
  93. package/lib/esm/abis.js +1 -1
  94. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  95. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
  96. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  97. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  98. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  99. package/lib/esm/actions/midnight/cancelOffers.js +103 -0
  100. package/lib/esm/actions/midnight/index.d.ts +1 -0
  101. package/lib/esm/actions/midnight/index.js +1 -0
  102. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  103. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
  104. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  105. package/lib/esm/actions/midnight/takeBorrow.js +1 -1
  106. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  107. package/lib/esm/actions/midnight/takeLend.js +1 -1
  108. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  109. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
  110. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  111. package/lib/esm/actions/midnight/takeWithdraw.js +1 -1
  112. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  113. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  114. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  115. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  116. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  117. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  118. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  119. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
  120. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  121. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  122. package/lib/esm/blue/abis.d.ts +1 -1
  123. package/lib/esm/blue/abis.js +1 -1
  124. package/lib/esm/blue/entities.d.ts +4 -4
  125. package/lib/esm/blue/entities.js +2 -2
  126. package/lib/esm/blue/errors.d.ts +2 -2
  127. package/lib/esm/blue/errors.js +2 -2
  128. package/lib/esm/blue/fetch.d.ts +2 -2
  129. package/lib/esm/blue/fetch.js +2 -2
  130. package/lib/esm/blue/utils.d.ts +1 -1
  131. package/lib/esm/blue/utils.js +1 -1
  132. package/lib/esm/entities/blue/blue.d.ts +34 -28
  133. package/lib/esm/entities/blue/blue.js +99 -73
  134. package/lib/esm/entities/index.d.ts +4 -4
  135. package/lib/esm/entities/index.js +2 -2
  136. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  137. package/lib/esm/entities/midnight/deadline.js +2 -2
  138. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  139. package/lib/esm/entities/midnight/midnight.js +145 -132
  140. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  141. package/lib/esm/entities/midnight/publication.js +126 -100
  142. package/lib/esm/entities/midnight/types.d.ts +4 -4
  143. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  144. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +17 -17
  145. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
  146. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
  147. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  148. package/lib/esm/entities/vaultV1/vaultV1.js +83 -57
  149. package/lib/esm/entities/vaultV2/vaultV2.d.ts +50 -24
  150. package/lib/esm/entities/vaultV2/vaultV2.js +166 -90
  151. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +17 -2
  152. package/lib/esm/entities/vaultV2BlueReallocationData.js +1410 -806
  153. package/lib/esm/errors.d.ts +4 -4
  154. package/lib/esm/errors.js +4 -4
  155. package/lib/esm/fetch.d.ts +2 -2
  156. package/lib/esm/fetch.js +2 -2
  157. package/lib/esm/helpers/deadShares.js +56 -35
  158. package/lib/esm/helpers/metadata.d.ts +14 -2
  159. package/lib/esm/helpers/metadata.js +38 -4
  160. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +34 -22
  161. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +7 -1
  162. package/lib/esm/helpers/validate.js +76 -61
  163. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +153 -102
  164. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +31 -20
  165. package/lib/esm/midnight/errors.d.ts +2 -1
  166. package/lib/esm/midnight/errors.js +2 -1
  167. package/lib/esm/transactionPlan/plan.js +6 -3
  168. package/lib/esm/transactionPlan/serde.js +7 -7
  169. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +6 -4
  170. package/lib/esm/transactionPlan/vaultv2/deposit.js +5 -3
  171. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +6 -4
  172. package/lib/esm/transactionPlan/vaultv2/withdraw.js +5 -3
  173. package/lib/esm/types/action.d.ts +26 -2
  174. package/lib/esm/types/action.js +1 -1
  175. package/lib/esm/types/error.js +11 -5
  176. package/lib/esm/types/metadata.d.ts +12 -2
  177. package/lib/esm/utils.d.ts +2 -2
  178. package/lib/esm/utils.js +2 -2
  179. package/lib/esm/version.d.ts +1 -1
  180. package/lib/esm/version.js +1 -1
  181. package/package.json +8 -7
@@ -0,0 +1,114 @@
1
+ # Migrating from morpho-sdk v9 to v10
2
+
3
+ Version 10 changes how `client.morpho.midnight(chainId).cancelOffers` cancels Midnight offer groups.
4
+ It now calls Midnight directly instead of going through MidnightBundlesV2. Nothing else changes:
5
+ the maker flows (`makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`,
6
+ `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`) and the pure `midnightCancelAndMake` builder
7
+ keep their inputs and calldata.
8
+
9
+ ## Why
10
+
11
+ A cancellation through MidnightBundlesV2 is a call to `midnightBundlesV2CancelAndMake`, the function
12
+ that also publishes offers, with about 17 arguments, most of them zero. Wallets that approve
13
+ transactions by policy (MPC wallets such as Utila, Fireblocks and Fordefi) need an argument-level
14
+ calldata policy to allow it. `Midnight.setConsumed(group, amount, onBehalf)` has three flat fields
15
+ and can only raise a group's consumed amount, so a policy can allow it by method name.
16
+
17
+ ## `cancelOffers` before and after
18
+
19
+ ```ts
20
+ // v9
21
+ const output = midnight.cancelOffers({
22
+ accountAddress: maker,
23
+ cancellations: [{ group, maxConsumed: maxUint128 }],
24
+ deadline,
25
+ });
26
+ // Returned the Midnight authorization of MidnightBundlesV2 when it was missing.
27
+ for (const requirement of await output.getRequirements()) {
28
+ await walletClient.sendTransaction(requirement);
29
+ }
30
+ await walletClient.sendTransaction(output.buildTx()); // to: MidnightBundlesV2
31
+
32
+ // v10
33
+ const output = midnight.cancelOffers({
34
+ accountAddress: maker,
35
+ groups: [group],
36
+ });
37
+ await output.getRequirements(); // always []
38
+ await walletClient.sendTransaction(output.buildTx()); // to: Midnight
39
+ ```
40
+
41
+ | | v9 | v10 |
42
+ | --- | --- | --- |
43
+ | Parameters | `{ accountAddress, cancellations, deadline }` | `{ accountAddress, groups }` |
44
+ | Target | MidnightBundlesV2 | Midnight |
45
+ | Calldata, one group | `midnightBundlesV2CancelAndMake(...)` | `setConsumed(group, maxUint128, accountAddress)` |
46
+ | Calldata, two or more groups | `midnightBundlesV2CancelAndMake(...)` | `multicall([setConsumed(...), ...])`, in list order |
47
+ | Requirements | Midnight authorization of MidnightBundlesV2 when missing | none |
48
+ | Action type | `midnightCancelAndMake` | `midnightCancelOffers`, args `{ groups, onBehalf }` |
49
+ | Chains | the six chains with a pinned MidnightBundlesV2 | every chain with a Midnight deployment |
50
+
51
+ ## What is gone
52
+
53
+ - **`cancellations`.** Pass the offer groups as `groups: readonly Hex[]`. Map
54
+ `cancellations.map(({ group }) => group)`.
55
+ - **`maxConsumed`.** There is no consumption guard on a plain cancellation. v9 reverted the
56
+ whole call when a group's consumption was above its ceiling; v10 cancels whatever has been filled
57
+ so far. Reading `Midnight.consumed(maker, group)` before sending is advisory only, because a taker
58
+ can fill the offer after the read and before the cancel is included. For a guard that holds, use
59
+ cancel-only `midnightCancelAndMake` with `maxConsumed` set to the ceiling (for example `0n`); it
60
+ targets MidnightBundlesV2, so the maker must have authorized MidnightBundlesV2 on Midnight.
61
+ - **`deadline`.** The call has no deadline and `cancelOffers` no longer throws
62
+ `ExpiredDeadlineError`. A cancellation can only make an offer less fillable, so a late inclusion
63
+ is harmless.
64
+ - **The MidnightBundlesV2 authorization requirement.** `getRequirements()` always resolves to an
65
+ empty list and performs no RPC read. A maker that only cancels never needs to authorize
66
+ MidnightBundlesV2. The authorization is still required by the maker and taker flows.
67
+ - **`NegativeInputError` and `InputExceedsMaxError`** from `cancelOffers`: there is no ceiling or
68
+ deadline left to validate. `EmptyMidnightGroupCancellationsError`,
69
+ `DuplicateMidnightGroupCancellationError`, `InvalidMidnightHexInputError`,
70
+ `MidnightInvalidAccountAddressError` and `ChainIdMismatchError` are thrown as before.
71
+
72
+ ## What changed
73
+
74
+ - **Full cancellation only.** Every group is set to `maxUint128`, which Midnight treats as fully
75
+ consumed. There is no partial amount.
76
+ - **An operator may send.** `accountAddress` is encoded as `onBehalf`. The maker can send the
77
+ transaction, and so can an operator the maker authorized on Midnight.
78
+ - **A wrong sender now reverts.** In v9 the bundle cancelled the groups of whichever account sent
79
+ the transaction, so a send from another account that had authorized MidnightBundlesV2 succeeded
80
+ and left the maker's offers fillable. In v10 a sender that is neither `accountAddress` nor its
81
+ operator reverts with `Unauthorized()` and no group changes.
82
+ - **A retry succeeds.** Cancelling a group that is already cancelled does not revert.
83
+ - **A batch is atomic.** Two or more groups are one `Midnight.multicall`: every group is cancelled
84
+ or none.
85
+ - **The action type changed.** Code that switches on `tx.action.type` for a cancellation must handle
86
+ `"midnightCancelOffers"`; `"midnightCancelAndMake"` now only describes maker bundles built by the
87
+ maker flows or the pure builder.
88
+ - **Simulation.** `toSimulationLimits` from `@morpho-org/evm-simulation` throws
89
+ `UnsupportedLimitActionError` for a `midnightCancelOffers` action, as it did for a cancel-only
90
+ bundle. A cancellation moves no value: simulate it with `limits: "none"`.
91
+
92
+ ## MPC wallets: cancel one group per transaction
93
+
94
+ Only the single-group transaction is a bare `setConsumed` call. A policy that allows `setConsumed`
95
+ on the chain's Midnight contract by method name approves it, and an approver reads three fields:
96
+ the group, the amount (`maxUint128`) and the maker.
97
+
98
+ A transaction that cancels two or more groups calls `multicall`, so a `setConsumed` method-name
99
+ policy does not match it, and allowing `multicall` by name would allow any Midnight call. In MPC
100
+ flows, send one `cancelOffers` transaction per group:
101
+
102
+ ```ts
103
+ for (const group of groups) {
104
+ const tx = midnight.cancelOffers({ accountAddress: maker, groups: [group] }).buildTx();
105
+ await walletClient.sendTransaction(tx);
106
+ }
107
+ ```
108
+
109
+ ## Lower-level builders
110
+
111
+ - `midnightCancelOffers({ chainId, groups, onBehalf, metadata? })` is the new pure action behind
112
+ `cancelOffers`, exported with `MidnightCancelOffersParams` and `MidnightCancelOffersAction`.
113
+ - `midnightCancelAndMake` is unchanged, including its cancel-only mode. Keep using it, or a maker
114
+ flow, to cancel and replace offers in one transaction under `maxConsumed` guards.
package/README.md CHANGED
@@ -28,6 +28,9 @@ Read [Dead-share validators](./DEAD-SHARE-PROTECTION.md) for the exported checks
28
28
  enforce the dead-deposit rule; integrators should validate their snapshot before building.
29
29
  Snapshot-free Blue `supply` remains deprecated.
30
30
 
31
+ Upgrading from v9? Read the [v9 → v10 migration guide](./MIGRATION-v9-to-v10.md) for the direct
32
+ Midnight `cancelOffers` route.
33
+
31
34
  Upgrading from v8? Read the [v8 → v9 migration guide](./MIGRATION-v8-to-v9.md) for the approval
32
35
  API removals and the new unlimited-approval behavior.
33
36
 
@@ -58,7 +61,8 @@ BlueBundlesV1, and the remaining rows identify their destination.
58
61
  | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeRepayWithdrawCollateral`, `repayWithdrawCollateral`, `takeWithdraw` | MidnightBundlesV2 (Ethereum, Base, Arbitrum, Arc, Robinhood, Tempo) |
59
62
  | | `supplyCollateral`, `withdrawCollateral`, `redeem` | Direct call |
60
63
  | | `supplyCollateralBatch`, `withdrawCollateralBatch` | Midnight multicall |
61
- | | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`, `cancelOffers` | MidnightBundlesV2 (Ethereum, Base, Arbitrum, Arc, Robinhood, Tempo) |
64
+ | | `cancelOffers` | Direct call for one group (`setConsumed`), Midnight multicall for several; every Midnight chain |
65
+ | | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend` | MidnightBundlesV2 (Ethereum, Base, Arbitrum, Arc, Robinhood, Tempo) |
62
66
 
63
67
  `makeBorrow` publishes without collateral; `supplyCollateralMakeBorrow` requires collateral and
64
68
  supplies it in the same transaction.
package/lib/cjs/abis.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  preLiquidationAbi as bluePreLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
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.midnightRateRatifierV1Abi = exports.midnightPriceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.midnightEcrecoverAuthorizerAbi = exports.midnightBlueBuyCallbackFactoryAbi = exports.midnightBlueBuyCallbackAbi = 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.erc3643IdentityRegistryAbi = exports.erc3643Abi = 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.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.midnightEcrecoverAuthorizerAbi = exports.midnightBlueBuyCallbackFactoryAbi = exports.midnightBlueBuyCallbackAbi = 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.midnightAdapterRateRatifierV1Abi = exports.midnightAdapterPriceRatifierV1Abi = exports.midnightAdapterFactoryAbi = exports.midnightAdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc3643IdentityRegistryAbi = exports.erc3643Abi = 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");
@@ -13,6 +13,10 @@ Object.defineProperty(exports, "erc3643IdentityRegistryAbi", { enumerable: true,
13
13
  Object.defineProperty(exports, "erc5267Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.erc5267Abi; } });
14
14
  Object.defineProperty(exports, "metaMorphoAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoAbi; } });
15
15
  Object.defineProperty(exports, "metaMorphoFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.metaMorphoFactoryAbi; } });
16
+ Object.defineProperty(exports, "midnightAdapterAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.midnightAdapterAbi; } });
17
+ Object.defineProperty(exports, "midnightAdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.midnightAdapterFactoryAbi; } });
18
+ Object.defineProperty(exports, "midnightAdapterPriceRatifierV1Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.midnightAdapterPriceRatifierV1Abi; } });
19
+ Object.defineProperty(exports, "midnightAdapterRateRatifierV1Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.midnightAdapterRateRatifierV1Abi; } });
16
20
  Object.defineProperty(exports, "morphoMarketV1AdapterAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterAbi; } });
17
21
  Object.defineProperty(exports, "morphoMarketV1AdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterFactoryAbi; } });
18
22
  Object.defineProperty(exports, "morphoMarketV1AdapterV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoMarketV1AdapterV2Abi; } });
@@ -1,5 +1,5 @@
1
1
  import type { Address } from "viem";
2
- import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
2
+ import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type ReferenceTimestampParams, type Transaction } from "../../types/index.js";
3
3
  /** Plain onchain state used by {@link resolveBundlesTokenRequirements}. */
4
4
  export type BundlesTokenRequirementsState = {
5
5
  readonly type: "approval";
@@ -31,7 +31,7 @@ export type BundlesTokenRequirementsState = {
31
31
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
32
32
  * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
33
33
  * SignatureTransfer branch it must be positive, within uint256, and in the future.
34
- * @param params.now - Timestamp the SignatureTransfer deadline is validated against; defaults to the current time.
34
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
35
35
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
36
36
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
37
37
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -74,6 +74,5 @@ export declare const resolveBundlesTokenRequirements: (params: {
74
74
  readonly chainId: number;
75
75
  readonly amount: bigint;
76
76
  readonly deadline: bigint;
77
- readonly now?: bigint;
78
77
  readonly state: BundlesTokenRequirementsState;
79
- }) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
78
+ } & ReferenceTimestampParams) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
@@ -27,7 +27,7 @@ const getRequirementsApproval_js_1 = require("../requirements/getRequirementsApp
27
27
  * @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
28
28
  * @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
29
29
  * SignatureTransfer branch it must be positive, within uint256, and in the future.
30
- * @param params.now - Timestamp the SignatureTransfer deadline is validated against; defaults to the current time.
30
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
31
31
  * @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
32
32
  * @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
33
33
  * @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
@@ -5,7 +5,8 @@ export type { MidnightCancelAndMakeParams, MidnightMakeBorrowCollateral, Midnigh
5
5
  * Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
6
6
  * groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
7
7
  * `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
8
- * Without `publication`, it only cancels groups (`cancelOffers` uses this).
8
+ * Without `publication`, it only cancels groups; `client.morpho.midnight(chainId).cancelOffers(...)`
9
+ * does not use this builder and calls Midnight directly through `midnightCancelOffers`.
9
10
  * Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
10
11
  * The builder snapshots every input field once before validation and encoding. It checks root,
11
12
  * groups, cancellation groups, Blue callback salt, and root-signature `r`/`s` as 32-byte hex and
@@ -26,7 +26,8 @@ const emptyMidnightMarket = {
26
26
  * Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
27
27
  * groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
28
28
  * `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
29
- * Without `publication`, it only cancels groups (`cancelOffers` uses this).
29
+ * Without `publication`, it only cancels groups; `client.morpho.midnight(chainId).cancelOffers(...)`
30
+ * does not use this builder and calls Midnight directly through `midnightCancelOffers`.
30
31
  * Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
31
32
  * The builder snapshots every input field once before validation and encoding. It checks root,
32
33
  * groups, cancellation groups, Blue callback salt, and root-signature `r`/`s` as 32-byte hex and
@@ -0,0 +1,54 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import { type Metadata, type MidnightCancelOffersAction, type Transaction } from "../../types/index.js";
3
+ /** Parameters for a direct Midnight cancellation of one or more offer groups. */
4
+ export interface MidnightCancelOffersParams {
5
+ readonly chainId: number;
6
+ readonly groups: readonly Hex[];
7
+ readonly onBehalf: Address;
8
+ readonly metadata?: Metadata;
9
+ }
10
+ /**
11
+ * Encodes a full cancellation of one or more offer groups as a direct call to Midnight.
12
+ *
13
+ * One group encodes a bare `setConsumed(group, maxUint128, onBehalf)`. Two or more groups encode
14
+ * one Midnight `multicall` holding one such `setConsumed` call per group, in list order; the batch
15
+ * cancels every group or none. Only the single-group encoding is matchable by a wallet policy that
16
+ * allows `setConsumed` by method name: a batch is a `multicall` call, so cancel one group per
17
+ * transaction when the signer's policy names `setConsumed`.
18
+ *
19
+ * The amount is always `maxUint128`, which Midnight never rejects, so cancelling a group again
20
+ * succeeds. Cancellation is per group: it does not unratify roots or revoke authorizations. The
21
+ * transaction never targets `MidnightBundlesV2` and needs no prior authorization or approval.
22
+ *
23
+ * @param params.chainId - Chain id used to resolve `Midnight`.
24
+ * @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
25
+ * @param params.onBehalf - Maker whose groups are cancelled. `onBehalf`, or an operator it
26
+ * authorized on Midnight, must send the transaction; otherwise Midnight reverts
27
+ * `Unauthorized()` and no group changes.
28
+ * @param params.metadata - Optional analytics metadata appended to calldata.
29
+ * @returns A deep-frozen `Transaction<MidnightCancelOffersAction>` targeting `Midnight`.
30
+ * @throws {MidnightCalldataEncodingError} when `onBehalf` is not a valid address.
31
+ * @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
32
+ * @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
33
+ * @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
34
+ * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
35
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
36
+ * @throws {UnknownAddressError} when the chain has no `midnight` deployment.
37
+ * @example
38
+ * ```ts
39
+ * import { midnightCancelOffers } from "@morpho-org/morpho-sdk";
40
+ * import type { Address, Hex } from "viem";
41
+ *
42
+ * declare const maker: Address;
43
+ * declare const group: Hex;
44
+ *
45
+ * // One group: calldata is `setConsumed(group, maxUint128, maker)`.
46
+ * const tx = midnightCancelOffers({
47
+ * chainId: 8453,
48
+ * groups: [group],
49
+ * onBehalf: maker,
50
+ * });
51
+ * // tx.action => { type: "midnightCancelOffers", args: { groups: [group], onBehalf: maker } }
52
+ * ```
53
+ */
54
+ export declare const midnightCancelOffers: (params: MidnightCancelOffersParams) => Readonly<Transaction<MidnightCancelOffersAction>>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.midnightCancelOffers = void 0;
4
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
8
+ const index_js_1 = require("../../helpers/index.js");
9
+ const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
10
+ const validateMidnightPublication_js_1 = require("../../helpers/validateMidnightPublication.js");
11
+ const index_js_2 = require("../../types/index.js");
12
+ /**
13
+ * Encodes a full cancellation of one or more offer groups as a direct call to Midnight.
14
+ *
15
+ * One group encodes a bare `setConsumed(group, maxUint128, onBehalf)`. Two or more groups encode
16
+ * one Midnight `multicall` holding one such `setConsumed` call per group, in list order; the batch
17
+ * cancels every group or none. Only the single-group encoding is matchable by a wallet policy that
18
+ * allows `setConsumed` by method name: a batch is a `multicall` call, so cancel one group per
19
+ * transaction when the signer's policy names `setConsumed`.
20
+ *
21
+ * The amount is always `maxUint128`, which Midnight never rejects, so cancelling a group again
22
+ * succeeds. Cancellation is per group: it does not unratify roots or revoke authorizations. The
23
+ * transaction never targets `MidnightBundlesV2` and needs no prior authorization or approval.
24
+ *
25
+ * @param params.chainId - Chain id used to resolve `Midnight`.
26
+ * @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
27
+ * @param params.onBehalf - Maker whose groups are cancelled. `onBehalf`, or an operator it
28
+ * authorized on Midnight, must send the transaction; otherwise Midnight reverts
29
+ * `Unauthorized()` and no group changes.
30
+ * @param params.metadata - Optional analytics metadata appended to calldata.
31
+ * @returns A deep-frozen `Transaction<MidnightCancelOffersAction>` targeting `Midnight`.
32
+ * @throws {MidnightCalldataEncodingError} when `onBehalf` is not a valid address.
33
+ * @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
34
+ * @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
35
+ * @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
36
+ * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
37
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
+ * @throws {UnknownAddressError} when the chain has no `midnight` deployment.
39
+ * @example
40
+ * ```ts
41
+ * import { midnightCancelOffers } from "@morpho-org/morpho-sdk";
42
+ * import type { Address, Hex } from "viem";
43
+ *
44
+ * declare const maker: Address;
45
+ * declare const group: Hex;
46
+ *
47
+ * // One group: calldata is `setConsumed(group, maxUint128, maker)`.
48
+ * const tx = midnightCancelOffers({
49
+ * chainId: 8453,
50
+ * groups: [group],
51
+ * onBehalf: maker,
52
+ * });
53
+ * // tx.action => { type: "midnightCancelOffers", args: { groups: [group], onBehalf: maker } }
54
+ * ```
55
+ */
56
+ const midnightCancelOffers = (params) => {
57
+ const { chainId, onBehalf, metadata } = params;
58
+ // Copy the list so validation and encoding read one snapshot and the caller's array stays unfrozen.
59
+ const groups = [...params.groups];
60
+ // Reject a malformed account before comparing it with the zero address.
61
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", onBehalf);
62
+ if ((0, viem_1.isAddressEqual)(onBehalf, viem_1.zeroAddress)) {
63
+ throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
64
+ }
65
+ if (groups.length === 0)
66
+ throw new index_js_2.EmptyMidnightGroupCancellationsError();
67
+ const seen = new Set();
68
+ for (const [index, group] of groups.entries()) {
69
+ // Validation only; rejects groups that are not 32-byte hex.
70
+ (0, validateMidnightPublication_js_1.validateMidnightBytes32)(`groups[${index}]`, group);
71
+ const key = group.toLowerCase();
72
+ if (seen.has(key)) {
73
+ throw new index_js_2.DuplicateMidnightGroupCancellationError({ index, group });
74
+ }
75
+ seen.add(key);
76
+ }
77
+ const midnight = (0, morpho_ts_1.getChainAddress)(chainId, "midnight");
78
+ const calls = groups.map((group) => (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
79
+ abi: midnight_sdk_1.midnightAbi,
80
+ functionName: "setConsumed",
81
+ args: [group, viem_1.maxUint128, onBehalf],
82
+ }));
83
+ const [single] = calls;
84
+ let tx = {
85
+ to: midnight,
86
+ value: 0n,
87
+ // A single cancellation stays a bare `setConsumed` so a method-name policy can match it.
88
+ data: calls.length === 1 && single !== undefined
89
+ ? single
90
+ : (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
91
+ abi: midnight_sdk_1.midnightAbi,
92
+ functionName: "multicall",
93
+ args: [calls],
94
+ }),
95
+ };
96
+ if (metadata) {
97
+ tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
98
+ }
99
+ return (0, morpho_ts_1.deepFreeze)({
100
+ ...tx,
101
+ action: {
102
+ type: "midnightCancelOffers",
103
+ args: { groups, onBehalf },
104
+ },
105
+ });
106
+ };
107
+ exports.midnightCancelOffers = midnightCancelOffers;
@@ -1,5 +1,6 @@
1
1
  export * from "./authorization.js";
2
2
  export * from "./cancelAndMake.js";
3
+ export * from "./cancelOffers.js";
3
4
  export * from "./redeem.js";
4
5
  export * from "./repayWithdrawCollateral.js";
5
6
  export * from "./supplyCollateral.js";
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./authorization.js"), exports);
18
18
  __exportStar(require("./cancelAndMake.js"), exports);
19
+ __exportStar(require("./cancelOffers.js"), exports);
19
20
  __exportStar(require("./redeem.js"), exports);
20
21
  __exportStar(require("./repayWithdrawCollateral.js"), exports);
21
22
  __exportStar(require("./supplyCollateral.js"), exports);
@@ -86,7 +86,7 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
86
86
  * receiver: borrower,
87
87
  * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
88
88
  * takeableOffers: quote.data.takeableOffers,
89
- * deadline: Time.timestamp() + 600n,
89
+ * deadline: (await client.getBlock()).timestamp + 600n,
90
90
  * });
91
91
  * ```
92
92
  */
@@ -90,7 +90,7 @@ const index_js_2 = require("../../types/index.js");
90
90
  * receiver: borrower,
91
91
  * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
92
92
  * takeableOffers: quote.data.takeableOffers,
93
- * deadline: Time.timestamp() + 600n,
93
+ * deadline: (await client.getBlock()).timestamp + 600n,
94
94
  * });
95
95
  * ```
96
96
  */
@@ -77,7 +77,7 @@ export interface MidnightTakeBorrowParams extends MidnightReferralFeeParams {
77
77
  * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
78
78
  * receiver: borrower,
79
79
  * takeableOffers: quote.data.takeableOffers,
80
- * deadline: Time.timestamp() + 600n,
80
+ * deadline: (await client.getBlock()).timestamp + 600n,
81
81
  * });
82
82
  * ```
83
83
  */
@@ -77,7 +77,7 @@ const index_js_2 = require("../../types/index.js");
77
77
  * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
78
78
  * receiver: borrower,
79
79
  * takeableOffers: quote.data.takeableOffers,
80
- * deadline: Time.timestamp() + 600n,
80
+ * deadline: (await client.getBlock()).timestamp + 600n,
81
81
  * });
82
82
  * ```
83
83
  */
@@ -81,7 +81,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
81
81
  * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
82
82
  * takeableOffers: quote.data.takeableOffers,
83
83
  * maxContinuousFee: maxUint256,
84
- * deadline: Time.timestamp() + 600n,
84
+ * deadline: (await client.getBlock()).timestamp + 600n,
85
85
  * });
86
86
  * ```
87
87
  */
@@ -74,7 +74,7 @@ const index_js_2 = require("../../types/index.js");
74
74
  * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
75
75
  * takeableOffers: quote.data.takeableOffers,
76
76
  * maxContinuousFee: maxUint256,
77
- * deadline: Time.timestamp() + 600n,
77
+ * deadline: (await client.getBlock()).timestamp + 600n,
78
78
  * });
79
79
  * ```
80
80
  */
@@ -107,7 +107,7 @@ export interface MidnightTakeRepayWithdrawCollateralParams extends MidnightRefer
107
107
  * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
108
108
  * collateralReceiver: borrower,
109
109
  * maxContinuousFee: maxUint256,
110
- * deadline: Time.timestamp() + 600n,
110
+ * deadline: (await client.getBlock()).timestamp + 600n,
111
111
  * });
112
112
  * ```
113
113
  */
@@ -93,7 +93,7 @@ const index_js_2 = require("../../types/index.js");
93
93
  * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
94
94
  * collateralReceiver: borrower,
95
95
  * maxContinuousFee: maxUint256,
96
- * deadline: Time.timestamp() + 600n,
96
+ * deadline: (await client.getBlock()).timestamp + 600n,
97
97
  * });
98
98
  * ```
99
99
  */
@@ -73,7 +73,7 @@ export interface MidnightTakeWithdrawParams extends MidnightReferralFeeParams {
73
73
  * target: { type: "units", units: credit, minSellerAssets: 990_000n },
74
74
  * receiver: lender,
75
75
  * takeableOffers: quote.data.takeableOffers,
76
- * deadline: Time.timestamp() + 600n,
76
+ * deadline: (await client.getBlock()).timestamp + 600n,
77
77
  * });
78
78
  * ```
79
79
  */
@@ -137,7 +137,7 @@ const validateParams = (params) => {
137
137
  * target: { type: "units", units: credit, minSellerAssets: 990_000n },
138
138
  * receiver: lender,
139
139
  * takeableOffers: quote.data.takeableOffers,
140
- * deadline: Time.timestamp() + 600n,
140
+ * deadline: (await client.getBlock()).timestamp + 600n,
141
141
  * });
142
142
  * ```
143
143
  */
@@ -1,6 +1,6 @@
1
1
  import type { Client } from "viem";
2
2
  import { type Address } from "viem";
3
- import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type Requirement, type Transaction } from "../../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type ReferenceTimestampParams, type Requirement, type Transaction } from "../../../types/index.js";
4
4
  /**
5
5
  * Resolves whether a supported operator needs Blue authorization for the given user, and returns
6
6
  * the requirement to satisfy it when it does.
@@ -18,7 +18,7 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
18
18
  * @param params.authorized - Operator to authorize. Defaults to the chain's registered
19
19
  * BlueBundlesV1 deployment and must match it.
20
20
  * @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
21
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
21
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
22
22
  * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
23
23
  * transaction so the destination route can consume the signed authorization.
24
24
  * @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
@@ -63,5 +63,4 @@ export declare const getBlueAuthorizationRequirement: (params: {
63
63
  readonly supportSignature?: boolean;
64
64
  readonly authorized?: Address;
65
65
  readonly deadline?: bigint;
66
- readonly now?: bigint;
67
- }) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
66
+ } & ReferenceTimestampParams) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
@@ -26,7 +26,7 @@ const validateClientChainId_js_1 = require("../validateClientChainId.js");
26
26
  * @param params.authorized - Operator to authorize. Defaults to the chain's registered
27
27
  * BlueBundlesV1 deployment and must match it.
28
28
  * @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
29
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
29
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
30
30
  * @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
31
31
  * transaction so the destination route can consume the signed authorization.
32
32
  * @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
@@ -1,8 +1,8 @@
1
1
  import type { Address } from "@morpho-org/blue-sdk";
2
2
  import { type Client } from "viem";
3
- import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
3
+ import { type AuthorizationRequirementSignature, type ReferenceTimestampParams, type Requirement } from "../../../types/index.js";
4
4
  /** Parameters for {@link encodeBlueSignatureAuthorization}. */
5
- interface EncodeBlueSignatureAuthorizationParams {
5
+ interface EncodeBlueSignatureAuthorizationParams extends ReferenceTimestampParams {
6
6
  /** Account granting the authorization and signing it (the Morpho `authorizer`). */
7
7
  owner: Address;
8
8
  /** BlueBundlesV1 operator to authorize on Morpho; must be the chain's registered deployment. */
@@ -15,8 +15,6 @@ interface EncodeBlueSignatureAuthorizationParams {
15
15
  isAuthorized?: boolean;
16
16
  /** Signature deadline in seconds. Defaults to two hours from now. */
17
17
  deadline?: bigint;
18
- /** Timestamp the deadline is validated against; defaults to the current time. */
19
- now?: bigint;
20
18
  }
21
19
  /**
22
20
  * Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
@@ -26,7 +24,7 @@ interface EncodeBlueSignatureAuthorizationParams {
26
24
  * typed data, verifies it against the connected account, and returns a deep-frozen
27
25
  * `RequirementSignature` the selected transaction route consumes. The requirement's
28
26
  * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
29
- * Deadline defaults to two hours from `Time.timestamp()`.
27
+ * Deadline defaults to two hours from `params.now` (the deprecated fallback uses the device clock).
30
28
  * The operator pin applies to grants and revocations alike: revoking a previously registered
31
29
  * operator is outside this helper's scope.
32
30
  *
@@ -40,7 +38,7 @@ interface EncodeBlueSignatureAuthorizationParams {
40
38
  * @param params.nonce - The owner's current Morpho authorization nonce.
41
39
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
42
40
  * @param params.deadline - Optional signature deadline in seconds.
43
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
41
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
44
42
  * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
45
43
  * `sign(client, userAddress)` produces the deep-frozen signature.
46
44
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
@@ -15,7 +15,7 @@ const index_js_1 = require("../../../types/index.js");
15
15
  * typed data, verifies it against the connected account, and returns a deep-frozen
16
16
  * `RequirementSignature` the selected transaction route consumes. The requirement's
17
17
  * `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
18
- * Deadline defaults to two hours from `Time.timestamp()`.
18
+ * Deadline defaults to two hours from `params.now` (the deprecated fallback uses the device clock).
19
19
  * The operator pin applies to grants and revocations alike: revoking a previously registered
20
20
  * operator is outside this helper's scope.
21
21
  *
@@ -29,7 +29,7 @@ const index_js_1 = require("../../../types/index.js");
29
29
  * @param params.nonce - The owner's current Morpho authorization nonce.
30
30
  * @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
31
31
  * @param params.deadline - Optional signature deadline in seconds.
32
- * @param params.now - Timestamp the deadline is validated against; defaults to the current time.
32
+ * @param params.now - See {@link ReferenceTimestampParams.now}.
33
33
  * @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
34
34
  * `sign(client, userAddress)` produces the deep-frozen signature.
35
35
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
@@ -87,7 +87,7 @@ const encodeBlueSignatureAuthorization = async (viemClient, params) => {
87
87
  throw new index_js_1.ExpiredDeadlineError(params.deadline, timestamp);
88
88
  }
89
89
  }
90
- const deadline = params.deadline ?? morpho_ts_1.Time.timestamp() + morpho_ts_1.Time.s.from.h(2n);
90
+ const deadline = params.deadline ?? (params.now ?? morpho_ts_1.Time.timestamp()) + morpho_ts_1.Time.s.from.h(2n);
91
91
  const typedData = (0, morpho_ts_1.deepFreeze)((0, blue_sdk_viem_1.getAuthorizationTypedData)({ authorizer: owner, authorized, isAuthorized, nonce, deadline }, chainId));
92
92
  const action = {
93
93
  type: "authorization",