@morpho-org/morpho-sdk 6.6.0 → 7.0.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 (153) hide show
  1. package/MIGRATION-v6-to-v7.md +291 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +3 -2
  5. package/lib/cjs/actions/bundles/common.d.ts +9 -5
  6. package/lib/cjs/actions/bundles/common.js +22 -13
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
  8. package/lib/cjs/actions/midnight/authorization.js +3 -2
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +3 -3
  12. package/lib/cjs/actions/midnight/index.js +3 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  16. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
  17. package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
  18. package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
  19. package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
  20. package/lib/cjs/actions/midnight/takeLend.js +111 -54
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
  23. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
  24. package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
  25. package/lib/cjs/actions/midnight/types.d.ts +7 -26
  26. package/lib/cjs/actions/midnight/types.js +0 -13
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
  32. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  33. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
  35. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  37. package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
  38. package/lib/cjs/actions/requirements/midnight/index.js +0 -1
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +2 -1
  41. package/lib/cjs/entities/index.d.ts +2 -2
  42. package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
  43. package/lib/cjs/entities/midnight/midnight.js +981 -509
  44. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  45. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
  46. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  47. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
  48. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  49. package/lib/cjs/helpers/callback.d.ts +54 -0
  50. package/lib/cjs/helpers/callback.js +73 -0
  51. package/lib/cjs/helpers/constant.d.ts +2 -0
  52. package/lib/cjs/helpers/constant.js +3 -1
  53. package/lib/cjs/helpers/index.d.ts +3 -2
  54. package/lib/cjs/helpers/index.js +6 -1
  55. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  56. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  57. package/lib/cjs/helpers/validate.d.ts +43 -2
  58. package/lib/cjs/helpers/validate.js +60 -3
  59. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  60. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  61. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  62. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  63. package/lib/cjs/midnight/abis.d.ts +1 -1
  64. package/lib/cjs/midnight/abis.js +3 -2
  65. package/lib/cjs/midnight/types.d.ts +1 -1
  66. package/lib/cjs/types/action.d.ts +117 -89
  67. package/lib/cjs/types/action.js +1 -19
  68. package/lib/cjs/types/error.d.ts +126 -40
  69. package/lib/cjs/types/error.js +154 -49
  70. package/lib/esm/abis.d.ts +1 -1
  71. package/lib/esm/abis.js +1 -1
  72. package/lib/esm/actions/bundles/common.d.ts +9 -5
  73. package/lib/esm/actions/bundles/common.js +22 -13
  74. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  75. package/lib/esm/actions/midnight/authorization.js +3 -2
  76. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  77. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  78. package/lib/esm/actions/midnight/index.d.ts +3 -3
  79. package/lib/esm/actions/midnight/index.js +3 -3
  80. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  81. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  82. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  83. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  84. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  85. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  86. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  87. package/lib/esm/actions/midnight/takeLend.js +114 -57
  88. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  89. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  90. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  91. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  92. package/lib/esm/actions/midnight/types.d.ts +7 -26
  93. package/lib/esm/actions/midnight/types.js +1 -12
  94. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  95. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  96. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  97. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  98. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  99. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  100. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  101. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  102. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  103. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  104. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  105. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  106. package/lib/esm/constants.d.ts +1 -1
  107. package/lib/esm/constants.js +1 -1
  108. package/lib/esm/entities/index.d.ts +2 -2
  109. package/lib/esm/entities/midnight/midnight.d.ts +582 -108
  110. package/lib/esm/entities/midnight/midnight.js +987 -515
  111. package/lib/esm/entities/midnight/types.d.ts +142 -60
  112. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
  113. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  114. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
  115. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  116. package/lib/esm/helpers/callback.d.ts +54 -0
  117. package/lib/esm/helpers/callback.js +68 -0
  118. package/lib/esm/helpers/constant.d.ts +2 -0
  119. package/lib/esm/helpers/constant.js +2 -0
  120. package/lib/esm/helpers/index.d.ts +3 -2
  121. package/lib/esm/helpers/index.js +3 -2
  122. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  123. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  124. package/lib/esm/helpers/validate.d.ts +43 -2
  125. package/lib/esm/helpers/validate.js +58 -2
  126. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  127. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  128. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  129. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  130. package/lib/esm/midnight/abis.d.ts +1 -1
  131. package/lib/esm/midnight/abis.js +1 -1
  132. package/lib/esm/midnight/types.d.ts +1 -1
  133. package/lib/esm/types/action.d.ts +117 -89
  134. package/lib/esm/types/action.js +1 -18
  135. package/lib/esm/types/error.d.ts +126 -40
  136. package/lib/esm/types/error.js +135 -38
  137. package/package.json +8 -7
  138. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  139. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  140. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  141. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  142. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  143. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  144. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  145. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  146. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  147. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  148. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  149. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  150. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  151. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  152. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  153. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -0,0 +1,291 @@
1
+ # Migrating `@morpho-org/morpho-sdk` from v6 to v7
2
+
3
+ Version 7 publishes Midnight maker offers through MidnightBundlesV2 in one transaction. The v6
4
+ flow sent a separate root-ratification transaction or root signature, then posted the offers to
5
+ MidnightMempool. v7 removes that route instead of keeping it selectable; stay on v6 if you
6
+ still need it.
7
+
8
+ ## Maker methods
9
+
10
+ | v6 | v7 |
11
+ | --- | --- |
12
+ | `makeLend` | `makeLend` (retyped) |
13
+ | `makeBorrow` | `makeBorrow` (retyped) |
14
+ | `supplyCollateralMakeBorrow` | `supplyCollateralMakeBorrow` (retyped) |
15
+
16
+ Each MidnightBundlesV2 call cancels the groups you are replacing, authorizes the ratifier, activates
17
+ the new root, and publishes the payload. `supplyCollateralMakeBorrow` also supplies borrow
18
+ collateral in that call; `makeBorrow` does not. If any cancelled group was filled beyond its
19
+ `maxConsumed` before the transaction lands, the whole call reverts and nothing is published.
20
+
21
+ `makeBorrow` still takes `MidnightMakeOffersParams`, which now requires `deadline` and accepts
22
+ optional `cancellations` (see below), and does not accept collateral. Use
23
+ `supplyCollateralMakeBorrow` to supply collateral; it requires a non-empty
24
+ `supplies` list and throws `EmptyMidnightCollateralSuppliesError` for an empty list. Both methods
25
+ build the `midnightCancelAndMake` action directly.
26
+
27
+ ```ts
28
+ // v6
29
+ const output = await midnight.makeLend({ accountAddress, offers, loanToken, loanAssets });
30
+ const tx = output.buildTx(await signRequirements(await output.getRequirements()));
31
+
32
+ // v7: repost over previousGroup; pass `cancellations: []` for a fresh publication
33
+ const output = await midnight.makeLend({
34
+ accountAddress,
35
+ offers,
36
+ cancellations: [{ group: previousGroup, maxConsumed: 0n }],
37
+ deadline,
38
+ loanToken,
39
+ loanAssets,
40
+ });
41
+ const tx = output.buildTx();
42
+ ```
43
+
44
+ ```ts
45
+ // v6
46
+ await midnight.supplyCollateralMakeBorrow({ accountAddress, offers, market, collateralAssets });
47
+
48
+ // v7
49
+ await midnight.supplyCollateralMakeBorrow({
50
+ accountAddress,
51
+ offers,
52
+ collateral: { market, supplies: [{ collateralIndex: 0n, assets }] },
53
+ deadline,
54
+ });
55
+ ```
56
+
57
+ The method returns `MidnightMakeOffersOutput`, whose transaction action is
58
+ `midnightCancelAndMake`. Its required `collateral: { market, supplies }` replaces the v6
59
+ `market`, `collateralAssets`, and `collateralIndex` inputs; `reservedCollateralAssets` is removed.
60
+ An empty `supplies` list throws `EmptyMidnightCollateralSuppliesError`.
61
+
62
+ ## Taker methods
63
+
64
+ `takeLend`, `takeBorrow` and `supplyCollateralTakeBorrow` now call MidnightBundlesV2. Each takes a
65
+ `target` that picks the amount the trade is sized by, and acts for the sender: there is no `taker`
66
+ input, and `accountAddress` must send the transaction.
67
+
68
+ | v6 input | v7 input |
69
+ | --- | --- |
70
+ | `takeLend` `assets`, `minUnits` | `target: { type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }` |
71
+ | `takeBorrow` `loanAssets`, `maxUnits` | `target: { type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }` |
72
+ | `supplyCollateralTakeBorrow` `collateralAssets`, `collateralIndex` | `collateralSupplies: [{ collateralIndex, assets }]` (non-empty) |
73
+ | — | `takeLend` `maxContinuousFee` (required; `maxUint256` for no cap) |
74
+ | — | optional `referralFeePct`, `referralFeeRecipient` |
75
+ | — | `takeBorrow` and `supplyCollateralTakeBorrow` optional `receiver` (defaults to `accountAddress`) |
76
+
77
+ ```ts
78
+ // v6
79
+ midnight.takeLend({ accountAddress, marketData, assets, minUnits, takeableOffers, deadline });
80
+
81
+ // v7
82
+ midnight.takeLend({
83
+ accountAddress,
84
+ marketData,
85
+ target: { type: "assets", assets, minUnits },
86
+ takeableOffers,
87
+ maxContinuousFee: maxUint256,
88
+ deadline,
89
+ });
90
+ ```
91
+
92
+ - Low-level builders: `midnightTakeBorrow` and `midnightSupplyCollateralTakeBorrow` replace `taker`
93
+ with a required `receiver`; `midnightTakeLend` drops `taker` with no replacement.
94
+ - Deadlines on `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeWithdraw` and
95
+ `takeRepayWithdrawCollateral` must be greater than now and no more than
96
+ `MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS` (one hour) from now. Builders reject `maxUint256` deadlines
97
+ with `UnboundedMidnightTakeInputError` and `0n` with `NonPositiveInputError`; entity methods
98
+ reject expired deadlines with `ExpiredDeadlineError` and deadlines beyond the window with
99
+ `MidnightTakeDeadlineTooFarError`.
100
+ - Target amounts and bounds must be positive. `takeWithdraw` requires a positive `minSellerAssets`
101
+ on units targets and rejects `maxUint256` for `target.units` or `target.maxUnits`.
102
+ `takeRepayWithdrawCollateral` requires positive `minUnits` on assets targets. Its units target
103
+ still allows `units: maxUint256` to repay the whole debt, bounded by finite, positive
104
+ `maxBuyerAssets`; it rejects `maxUint256` for `maxBuyerAssets`. `takeLend`, `takeBorrow`, and
105
+ `supplyCollateralTakeBorrow` reject unbounded target fields with
106
+ `UnboundedMidnightTakeInputError`; `receiver` cannot be the zero address or throws
107
+ `MidnightZeroReceiverError`.
108
+ - Maker `continuousFeeCap` must be `0n` or throws `MidnightOfferContinuousFeeCapError`. A sell
109
+ offer's `receiverIfMakerIsSeller` must equal its maker or throws
110
+ `MidnightOfferSellerReceiverMismatchError`.
111
+ - Requirements approve the loan token (`takeLend`: `assets` or `maxBuyerAssets`) or each collateral
112
+ token (summed per token) to MidnightBundlesV2, and authorize MidnightBundlesV2 on Midnight.
113
+ Approvals are now unlimited: `getRequirements()`/`getMidnightApprovalRequirements` return a
114
+ `maxUint256` approval (capped per token by `MAX_TOKEN_APPROVALS`) instead of the exact pulled
115
+ amount, still only when the allowance is below the pulled amount. Callers can pass
116
+ `getRequirements({ approvalAmount })` (or `approvalAmount` on
117
+ `getMidnightApprovalRequirements`) to set a different allowance.
118
+ - `takeBorrow` and `supplyCollateralTakeBorrow` withdraw the sender's existing credit before
119
+ taking offers, so a lender who borrows nets the credit first.
120
+ - Action metadata exposes `target` instead of `assets`/`minUnits` or `loanAssets`/`maxUnits`, and
121
+ drops `taker`. `MidnightSupplyCollateralTakeBorrowAction.collateralSupplies` is the supply list
122
+ instead of a count, and `MidnightTakeBorrowAction.args` no longer has `collateralSupplies`.
123
+ - New types: `MidnightBuyTarget`, `MidnightSellTarget`, `MidnightReferralFeeParams`.
124
+ `MidnightCollateralSupply` is removed; use `MidnightCollateralTransfer`.
125
+ - New `takeRepayWithdrawCollateral` (and the `midnightTakeRepayWithdrawCollateral` builder) repays
126
+ debt by taking borrow-side offers with `reduceOnly` set, repays the rest directly when
127
+ `repayEnabled` is true, then withdraws `collateralWithdrawals` to `collateralReceiver`
128
+ (default `accountAddress`). It takes a `MidnightBuyTarget` and needs the same approval and
129
+ authorization as `takeLend`.
130
+ - New `takeWithdraw` (and the `midnightTakeWithdraw` builder) withdraws the sender's credit: it
131
+ redeems what market liquidity allows, then sells the rest of a `MidnightSellTarget` to lend-side
132
+ offers with `reduceOnly` set, so it never opens debt. It needs only MidnightBundlesV2
133
+ authorization. `redeem` stays the direct, offer-free path.
134
+
135
+ ## Removed MidnightBundles (V1) support
136
+
137
+ v7 no longer routes anything through the V1 `midnightBundles` contract:
138
+
139
+ - `midnightBundlesAbi` is no longer re-exported from `@morpho-org/morpho-sdk` or
140
+ `@morpho-org/morpho-sdk/midnight`, and `midnight-sdk` 2.0.0 removes it too. Integrations that
141
+ still call V1 stay on `morpho-sdk` 6.x with `midnight-sdk` 1.x and `morpho-ts` 3.x.
142
+ - `RequirementSpenderKey` drops `"midnightBundles"`. `encodeErc20Approval` and
143
+ `getMidnightApprovalRequirements` reject a `midnightBundles` spender, and `encodeErc20Permit` no
144
+ longer signs permits for it (V2 takes no inline permits).
145
+ - `midnightSetIsAuthorized` and `getMidnightAuthorizationRequirement` accept only
146
+ `midnightBundlesV2` as the operator to grant. Revocations through `midnightSetIsAuthorized`
147
+ (`isAuthorized: false`) still accept any operator.
148
+ - `UnsupportedErc20ApprovalSpenderError` no longer takes a `midnightBundles` constructor field.
149
+ - `PermitKind` and `MidnightTokenPermit` are removed with no replacement: V2 takes no inline token
150
+ permits.
151
+
152
+ ## repayWithdrawCollateral
153
+
154
+ `repayWithdrawCollateral` now calls MidnightBundlesV2 for the sender (no `onBehalf`). It repays
155
+ debt directly, without taking offers, and can withdraw several collaterals in the same call.
156
+
157
+ | v6 input | v7 input |
158
+ | --- | --- |
159
+ | `repayAssets` | `repay: { type: "assets", assets }` (repays exactly `assets`; `0n` for withdraw-only) or `repay: { type: "full", maxBuyerAssets }` (repays the whole debt at execution time, pulling the finite `maxBuyerAssets` upfront and refunding the rest, so the sender must hold the full cap; reverts with `Panic(0x11)` if the debt at execution exceeds it) |
160
+ | `withdrawCollateralAssets`, `collateralIndex` | `collateralWithdrawals: [{ collateralIndex, assets }]` (`assets: maxUint256` withdraws the whole balance) |
161
+ | — | optional `collateralReceiver` (defaults to `accountAddress`) |
162
+
163
+ ```ts
164
+ // v6
165
+ midnight.repayWithdrawCollateral({ accountAddress, marketData, repayAssets, withdrawCollateralAssets, deadline });
166
+
167
+ // v7: close the position
168
+ midnight.repayWithdrawCollateral({
169
+ accountAddress,
170
+ marketData,
171
+ repay: { type: "full", maxBuyerAssets },
172
+ collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
173
+ deadline,
174
+ });
175
+ ```
176
+
177
+ - Requirements approve the loan token to MidnightBundlesV2 when the allowance is below the pulled
178
+ assets (`assets`, or `maxBuyerAssets` on a full repay; skipped when `0n`) and authorize
179
+ MidnightBundlesV2 on Midnight. Unused assets
180
+ are refunded. A full repay rejects `maxBuyerAssets` of `0n` or `maxUint256`, and an `assets` repay
181
+ rejects `assets: maxUint256` (use `{ type: "full" }` to repay the whole debt).
182
+ - `deadline` must be positive: `0n` now throws `NonPositiveInputError` (v6 only rejected negative
183
+ values). Pass `maxUint256` for no expiry.
184
+ - `MidnightRepayWithdrawCollateralAction.args` exposes `repay` and the `collateralWithdrawals`
185
+ list, and drops `repayAssets` and `onBehalf`.
186
+ - The `midnightRepayWithdrawCollateral` builder takes the same `repay` and `collateralWithdrawals`
187
+ plus a required `collateralReceiver`; it drops `repayAssets`, `withdrawCollateralAssets`,
188
+ `collateralIndex` and `onBehalf`. Like the other V2 builders, it throws `UnknownAddressError`
189
+ on chains without a `midnightBundlesV2` deployment.
190
+
191
+ ## Ratifiers
192
+
193
+ Offers must use PriceRatifierV1 or RateRatifierV1. Pass a `Tree<"priceV1">`, a `Tree<"rateV1">`,
194
+ or the matching tree-create request; every offer's `ratifier` must be the tree's ratifier
195
+ (`MidnightOfferRatifierMismatchError`). Ecrecover and Setter trees are no longer accepted by
196
+ maker methods. `getOffersData` follows the same rule and now returns the V1 payload and ratifier
197
+ address.
198
+
199
+ ## Ownership and requirements
200
+
201
+ - MidnightBundlesV2 acts on `msg.sender`. `accountAddress` must be the sender and the maker of every
202
+ offer; there is no `onBehalf`.
203
+ - `getRequirements()` returns only onchain transactions: the MidnightBundlesV2 Midnight
204
+ authorization, the lend-side loan-token approval to Midnight for later fills, and borrow-side
205
+ collateral approvals to MidnightBundlesV2 for `supplyCollateralMakeBorrow`. `makeBorrow`
206
+ requires only MidnightBundlesV2 authorization. It no longer returns a root signature or a
207
+ SetterRatifier root transaction, so `buildTx()` takes no signatures.
208
+ - Replacement offers need fresh groups. A group cannot be both published and cancelled
209
+ (`MidnightReplacementGroupCancelledError`).
210
+ - `makeLend`, `makeBorrow`, and `supplyCollateralMakeBorrow` reject `reduceOnly` offers with
211
+ `MidnightOfferReduceOnlyError`.
212
+
213
+ ## Renamed and changed types
214
+
215
+ | v6 | v7 |
216
+ | --- | --- |
217
+ | `MidnightMakeOffersParams` | `MidnightMakeOffersParams` (retyped) |
218
+ | `MidnightMakeLendParams` | `MidnightMakeLendParams` (retyped) |
219
+ | `MidnightSupplyCollateralMakeBorrowParams` | `MidnightSupplyCollateralMakeBorrowParams` (required `collateral`) |
220
+ | `MidnightMakeOffersOutput` | `MidnightMakeOffersOutput` (retyped) |
221
+ | — | `MidnightMakeBorrowCollateral` |
222
+ | — | `MidnightOfferPublication`, `MidnightCancelAndMakeParams`, and `MidnightRootActivationSignature` |
223
+
224
+ - `MidnightMakeOffersParams`, and so `MidnightMakeLendParams` and
225
+ `MidnightSupplyCollateralMakeBorrowParams`, adds a required `deadline: bigint` bundle execution
226
+ deadline with no default; pass `maxUint256` for no expiry. It also adds optional
227
+ `cancellations: readonly MidnightGroupCancellation[]`; omit it or pass `[]` for a new publication.
228
+ - `MidnightMakeOffersParams` is used by `makeBorrow`, as in v6, and does not include collateral.
229
+ `MidnightSupplyCollateralMakeBorrowParams` extends it with required
230
+ `collateral: MidnightMakeBorrowCollateral`. Its nested supplies replace the v6 `market`,
231
+ `collateralAssets`, and `collateralIndex` inputs; `reservedCollateralAssets` is removed. The
232
+ collateral approval now goes to MidnightBundlesV2 instead of Midnight.
233
+ - `MidnightCancelAndMakeParams` takes ratifier, root, groups, payload, root signature, and optional
234
+ collateral together under `publication?: MidnightOfferPublication`. Omit `publication` for
235
+ cancel-only calls; this preserves `cancelOffers` behavior.
236
+ - `offers` accepts only `MidnightMakerTreeInput` (a PriceRatifierV1 or RateRatifierV1 tree or
237
+ `Tree.create` request) instead of any `TreeInput`.
238
+ - `MidnightOfferValidationParams` no longer accepts `ratification`; the ratifier comes from the tree.
239
+ - `MidnightOffersData.ratifierType` is `"priceV1" | "rateV1"` instead of `"ecrecover" | "setter"`.
240
+ - `MidnightOffersData.setterPayload` is replaced by `payload`, set for every tree.
241
+
242
+ ## Removed exports
243
+
244
+ - Actions and requirements: `mempoolSubmitOffers` (`MempoolSubmitOffersParams`),
245
+ `setterRatifierRatifyRoot` (`SetterRatifierRatifyRootParams`),
246
+ `getSetterRatifierRatifyRootRequirement` (`GetSetterRatifierRatifyRootRequirementParams`).
247
+ - Types: `MempoolSubmitOffersAction`, `SetterRatifierRatifyRootAction`,
248
+ `MidnightOfferRootSignatureAction`, `MidnightOfferRootSignatureArgs`,
249
+ `MidnightOfferRootSignature`, `MidnightOfferRootRequirement`, `MidnightActionSignatures`.
250
+ - Helpers and errors: `isMidnightOfferRootSignature`, the `midnightOfferRoot` slot of
251
+ `selectRequirementSignatures`, `MissingMidnightOfferRootSignatureError`,
252
+ `MidnightOfferRootMismatchError`, `MidnightOfferRootOwnerMismatchError`,
253
+ `MidnightOfferRootRatifierMismatchError`, `MidnightOfferRootOfferCountMismatchError`,
254
+ `UnpreparedMidnightOfferRootSignatureError`, `UnknownMidnightRatifierError`.
255
+
256
+ - `getMidnightAuthorizationRequirement` and `midnightSetIsAuthorized` no longer accept the
257
+ Ecrecover or Setter ratifier as a target; MidnightBundlesV2 authorizes the V1 ratifier itself.
258
+ - `RequirementSignatureKind` no longer includes `"midnightOfferRootSignature"`.
259
+
260
+ There is no replacement for `UnknownMidnightRatifierError`: the `MidnightMakerTreeInput` type
261
+ makes it unreachable. The pure `midnightCancelAndMake` builder accepts only the chain's registered
262
+ `priceRatifierV1` or `rateRatifierV1` and throws `UnsupportedMidnightAuthorizationTargetError`
263
+ otherwise; entity methods derive the registered ratifier from the tree type.
264
+
265
+ The Ecrecover and Setter protocol utilities in `@morpho-org/midnight-sdk` are unchanged.
266
+
267
+ ## Single-group cancellation
268
+
269
+ ```ts
270
+ // v6
271
+ midnight.cancelOffer({ group, accountAddress });
272
+
273
+ // v7
274
+ midnight.cancelOffers({
275
+ accountAddress,
276
+ cancellations: [{ group, maxConsumed: maxUint128 }],
277
+ deadline,
278
+ });
279
+ ```
280
+
281
+ v6 `cancelOffer` called `Midnight.setConsumed` directly and returned no requirements. v7 `cancelOffers`
282
+ goes through MidnightBundlesV2, so call `getRequirements()` first: it returns the maker's Midnight
283
+ authorization of `MidnightBundlesV2` when it is missing. The bundle also needs a `deadline`, and
284
+ `maxConsumed` only caps how much of the group may already be consumed when the cancellation runs.
285
+
286
+ Removed: `cancelOffer`, `midnightCancelOffer`, `MidnightCancelOfferParams`, `MidnightCancelOfferAction` and
287
+ `MidnightAmountExceedsMaxOfferCapError`.
288
+
289
+ ## Deployment
290
+
291
+ MidnightBundlesV2 is pinned on Ethereum, Base, Arc, and Robinhood.
package/README.md CHANGED
@@ -24,7 +24,8 @@ General Vault V1 operations remain supported.
24
24
  pnpm add @morpho-org/morpho-sdk
25
25
  ```
26
26
 
27
- Upgrading from v5? Read the [v5 → v6 migration guide](./MIGRATION-v5-to-v6.md) before updating vault
27
+ Upgrading from v6? Read the [v6 → v7 migration guide](./MIGRATION-v6-to-v7.md) before updating Midnight
28
+ maker integrations. Upgrading from v5? Read the [v5 → v6 migration guide](./MIGRATION-v5-to-v6.md) before updating vault
28
29
  deposit or Blue write integrations.
29
30
 
30
31
  ## Actions
@@ -41,9 +42,18 @@ BlueBundlesV1, and the remaining rows identify their destination.
41
42
  | | `forceRedeem` | Vault multicall |
42
43
  | | `inKindRedeem` | VaultExitBundlesV1 |
43
44
  | **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
44
- | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `repayWithdrawCollateral` | Midnight Bundles |
45
- | | `makeLend`, `makeBorrow`, `supplyCollateralMakeBorrow` | Midnight mempool |
46
- | | `supplyCollateral`, `redeem`, `cancelOffer` | Direct call |
45
+ | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeRepayWithdrawCollateral`, `repayWithdrawCollateral`, `takeWithdraw` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood) |
46
+ | | `supplyCollateral`, `redeem` | Direct call |
47
+ | | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`, `cancelOffers` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood) |
48
+
49
+ `makeBorrow` publishes without collateral; `supplyCollateralMakeBorrow` requires collateral and
50
+ supplies it in the same transaction.
51
+
52
+ `makeWithdraw` publishes reduce-only sell offers for lend limit exits. `makeRepay` publishes
53
+ reduce-only buy offers for borrow limit exits and uses the same loan reserve inputs as `makeLend`.
54
+ Both preserve the supplied offer tree and use `midnightCancelAndMake`; neither executes a fill
55
+ or withdraws collateral during publication. Send their approval/authorization requirements first,
56
+ then call `buildTx()` without a separate root signature.
47
57
 
48
58
  `VaultExitBundlesV1`, `VaultBundlesV1`, and `BlueBundlesV1` are registered on Ethereum, Base,
49
59
  Arbitrum, Optimism, Polygon, World Chain, Unichain, HyperEVM, Katana, Monad, Stable, Tempo,
@@ -60,7 +70,7 @@ live Blue liquidity — before invoking `buildTx()`. Calling `buildTx()` directl
60
70
  RPC-backed pre-flight checks. `forceRedeem` remains a direct Vault V2 multicall without
61
71
  prerequisites.
62
72
 
63
- - **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, permit / Permit2 signatures, Morpho authorization, or (for Midnight) operator authorization and offer-root signatures.
73
+ - **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, permit / Permit2 signatures, Morpho authorization, or (for Midnight) operator authorization.
64
74
  - **`buildTx(signatures?)`** — synchronous; the final, deep-frozen viem transaction. Pass any signatures collected from the requirements.
65
75
 
66
76
  ```typescript
@@ -230,6 +240,8 @@ instant liquidation. Blue writes do not accept `slippageTolerance`, `minSharePri
230
240
 
231
241
  Protocol-specific names are qualified in shared facades, for example `fetchBluePosition` and `fetchMidnightPosition` from `@morpho-org/morpho-sdk/fetch`. Canonical raw upstream names remain available under `/blue/{abis,addresses,constants,entities,errors,fetch,types,utils}` and `/midnight/{abis,constants,entities,errors,fetch,types,utils}`.
232
242
 
243
+ Morpho-ts registers MidnightBundlesV2 on Ethereum, Base, Arc, and Robinhood.
244
+
233
245
  ```typescript
234
246
  const midnight = client.morpho.midnight(8453);
235
247
  const marketData = await midnight.getMarketData(marketId);
@@ -237,9 +249,9 @@ const marketData = await midnight.getMarketData(marketId);
237
249
  const output = midnight.takeLend({
238
250
  accountAddress: lender,
239
251
  marketData,
240
- assets: 1_000_000n,
241
- minUnits: 900_000n,
252
+ target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
242
253
  takeableOffers: quote.data.takeableOffers,
254
+ maxContinuousFee: maxUint256,
243
255
  deadline,
244
256
  });
245
257
 
@@ -323,10 +335,12 @@ graph LR
323
335
  MN1[MorphoMidnight]
324
336
  MN1 --> MNT[fixed-rate taker actions]
325
337
  MN1 --> MNM[maker offer submission]
326
- MN1 --> MNP[position actions]
327
- MNT --> MNB[MidnightBundles]
328
- MNM --> MNMP[Midnight mempool]
329
- MNP --> MNC[Midnight / MidnightBundles]
338
+ MN1 --> MNR[repayWithdrawCollateral]
339
+ MN1 --> MNP[collateral supply / redeem]
340
+ MNT --> MNB2[MidnightBundlesV2]
341
+ MNM --> MNB2
342
+ MNR --> MNB2
343
+ MNP --> MNC[Midnight]
330
344
  end
331
345
 
332
346
 
@@ -337,7 +351,7 @@ graph LR
337
351
  MV1 -.->|approval / permit| REQ
338
352
  MV2 -.->|approval / permit| REQ
339
353
  MM1 -.->|approval / permit / authorization| REQ
340
- MN1 -.->|approval / authorization / root signature or ratification| REQ
354
+ MN1 -.->|approval / authorization| REQ
341
355
 
342
356
  style VBV1 fill:#e8f5e9,stroke:#4caf50
343
357
  style BBV1 fill:#e8f5e9,stroke:#4caf50
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, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, 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.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;
3
+ exports.blueBundlesV1Abi = exports.vaultBundlesV1Abi = exports.vaultExitBundlesV1Abi = exports.midnightSetterRatifierAbi = exports.midnightRateRatifierV1Abi = exports.midnightPriceRatifierV1Abi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.midnightEcrecoverRatifierAbi = exports.midnightBlueBuyCallbackFactoryAbi = 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");
@@ -30,9 +30,10 @@ Object.defineProperty(exports, "whitelistControllerAggregatorV2Abi", { enumerabl
30
30
  Object.defineProperty(exports, "wrappedBackedTokenAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wrappedBackedTokenAbi; } });
31
31
  Object.defineProperty(exports, "wstEthAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wstEthAbi; } });
32
32
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
33
+ Object.defineProperty(exports, "midnightBlueBuyCallbackFactoryAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackFactoryAbi; } });
33
34
  Object.defineProperty(exports, "midnightEcrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
34
35
  Object.defineProperty(exports, "midnightAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightAbi; } });
35
- Object.defineProperty(exports, "midnightBundlesAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesAbi; } });
36
+ Object.defineProperty(exports, "midnightBundlesV2Abi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesV2Abi; } });
36
37
  Object.defineProperty(exports, "midnightPriceRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.priceRatifierV1Abi; } });
37
38
  Object.defineProperty(exports, "midnightRateRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.rateRatifierV1Abi; } });
38
39
  Object.defineProperty(exports, "midnightSetterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });
@@ -203,18 +203,22 @@ export declare const selectBundlesTokenRequirementSignature: (signatures: readon
203
203
  * @internal
204
204
  *
205
205
  * @param signatures - Signatures passed to the operation's `buildTx` function.
206
- * @param expected - Immutable spender, amount, and deadline required by the operation.
206
+ * @param expected - Immutable spender, amount bounds, and deadline required by the operation.
207
207
  * @param expected.spender - Fixed bundles contract the permit must authorize.
208
- * @param expected.amount - Exact share allowance the permit must cover.
208
+ * @param expected.amount - Minimum share allowance the permit must cover.
209
+ * @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
210
+ * `expected.amount`, which accepts only an exact match.
209
211
  * @param expected.deadline - Deadline the permit must carry.
210
212
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
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.
213
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
214
+ * deadline differ from the operation's, its signed amount differs from its action's amount, or
215
+ * its amount is outside `[expected.amount, expected.maxAmount ?? expected.amount]`.
216
+ * The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
214
217
  */
215
218
  export declare const selectBundlesSharesPermitSignature: (signatures: readonly RequirementSignature[] | undefined, expected: {
216
219
  readonly spender: Address;
217
220
  readonly amount: bigint;
221
+ readonly maxAmount?: bigint;
218
222
  readonly deadline: bigint;
219
223
  }) => Erc2612RequirementSignature | undefined;
220
224
  /** @internal Returns the exact referral fee deducted from a fixed gross asset amount. */
@@ -364,11 +364,7 @@ const selectBundlesTokenRequirementSignature = (signatures, expected) => {
364
364
  if (selected.length !== signatures.length) {
365
365
  const unexpected = signatures.find((signature) => signature.action.type !== "permit" &&
366
366
  signature.action.type !== "permit2SignatureTransfer");
367
- throw new index_js_2.UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization"
368
- ? "authorization"
369
- : unexpected?.action.type === "midnightOfferRootSignature"
370
- ? "midnightOfferRootSignature"
371
- : "permit");
367
+ throw new index_js_2.UnexpectedRequirementSignatureError(unexpected?.action.type === "authorization" ? "authorization" : "permit");
372
368
  }
373
369
  if (selected.length > 1) {
374
370
  throw new index_js_2.AmbiguousRequirementSignaturesError("permit", selected.length);
@@ -421,14 +417,17 @@ exports.selectBundlesTokenRequirementSignature = selectBundlesTokenRequirementSi
421
417
  * @internal
422
418
  *
423
419
  * @param signatures - Signatures passed to the operation's `buildTx` function.
424
- * @param expected - Immutable spender, amount, and deadline required by the operation.
420
+ * @param expected - Immutable spender, amount bounds, and deadline required by the operation.
425
421
  * @param expected.spender - Fixed bundles contract the permit must authorize.
426
- * @param expected.amount - Exact share allowance the permit must cover.
422
+ * @param expected.amount - Minimum share allowance the permit must cover.
423
+ * @param expected.maxAmount - Optional inclusive share allowance ceiling; defaults to
424
+ * `expected.amount`, which accepts only an exact match.
427
425
  * @param expected.deadline - Deadline the permit must carry.
428
426
  * @returns The matching ERC-2612 signature, or `undefined` when no signature is supplied.
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.
427
+ * @throws {BundlesPermitMismatchError} when the signature is not ERC-2612, its spender or
428
+ * deadline differ from the operation's, its signed amount differs from its action's amount, or
429
+ * its amount is outside `[expected.amount, expected.maxAmount ?? expected.amount]`.
430
+ * The nonce is not checked here: it is onchain state the vault's `permit` verifies at execution.
432
431
  */
433
432
  const selectBundlesSharesPermitSignature = (signatures, expected) => {
434
433
  const { permit } = (0, index_js_2.selectRequirementSignatures)(signatures, { permit: true });
@@ -449,11 +448,21 @@ const selectBundlesSharesPermitSignature = (signatures, expected) => {
449
448
  actual: action.args.spender,
450
449
  });
451
450
  }
452
- if (permit.args.amount !== expected.amount ||
453
- action.args.amount !== expected.amount) {
451
+ const maxAmount = expected.maxAmount ?? expected.amount;
452
+ const expectedAmount = expected.maxAmount == null || expected.maxAmount === expected.amount
453
+ ? String(expected.amount)
454
+ : `[${expected.amount}, ${expected.maxAmount}]`;
455
+ if (permit.args.amount !== action.args.amount) {
454
456
  throw new index_js_2.BundlesPermitMismatchError({
455
457
  field: "amount",
456
- expected: String(expected.amount),
458
+ expected: String(action.args.amount),
459
+ actual: String(permit.args.amount),
460
+ });
461
+ }
462
+ if (permit.args.amount < expected.amount || permit.args.amount > maxAmount) {
463
+ throw new index_js_2.BundlesPermitMismatchError({
464
+ field: "amount",
465
+ expected: expectedAmount,
457
466
  actual: String(permit.args.amount),
458
467
  });
459
468
  }
@@ -9,7 +9,8 @@ export interface MidnightSetIsAuthorizedParams {
9
9
  readonly metadata?: Metadata;
10
10
  }
11
11
  /**
12
- * Encodes `Midnight.setIsAuthorized` for a bundle spender or ratifier.
12
+ * Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
13
+ * revocations accept any operator.
13
14
  *
14
15
  * Prefer requirement helpers or entity `getRequirements()` in app flows; they
15
16
  * read `isAuthorized` first and return this transaction only when needed. Use
@@ -29,7 +30,7 @@ export interface MidnightSetIsAuthorizedParams {
29
30
  *
30
31
  * const tx = midnightSetIsAuthorized({
31
32
  * chainId: 8453,
32
- * authorized: midnightBundles,
33
+ * authorized: midnightBundlesV2,
33
34
  * onBehalf: user,
34
35
  * });
35
36
  * ```
@@ -7,7 +7,8 @@ const viem_1 = require("viem");
7
7
  const index_js_1 = require("../../helpers/index.js");
8
8
  const validateMidnightAuthorizationTarget_js_1 = require("../../helpers/validateMidnightAuthorizationTarget.js");
9
9
  /**
10
- * Encodes `Midnight.setIsAuthorized` for a bundle spender or ratifier.
10
+ * Encodes `Midnight.setIsAuthorized`. Grants target MidnightBundlesV2;
11
+ * revocations accept any operator.
11
12
  *
12
13
  * Prefer requirement helpers or entity `getRequirements()` in app flows; they
13
14
  * read `isAuthorized` first and return this transaction only when needed. Use
@@ -27,7 +28,7 @@ const validateMidnightAuthorizationTarget_js_1 = require("../../helpers/validate
27
28
  *
28
29
  * const tx = midnightSetIsAuthorized({
29
30
  * chainId: 8453,
30
- * authorized: midnightBundles,
31
+ * authorized: midnightBundlesV2,
31
32
  * onBehalf: user,
32
33
  * });
33
34
  * ```