@morpho-org/morpho-sdk 6.5.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 (167) 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 +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +10 -6
  42. package/lib/cjs/entities/blue/blue.js +5 -3
  43. package/lib/cjs/entities/index.d.ts +2 -2
  44. package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
  45. package/lib/cjs/entities/midnight/midnight.js +981 -509
  46. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  47. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
  48. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -3
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +119 -43
  53. package/lib/cjs/helpers/callback.d.ts +54 -0
  54. package/lib/cjs/helpers/callback.js +73 -0
  55. package/lib/cjs/helpers/constant.d.ts +10 -0
  56. package/lib/cjs/helpers/constant.js +11 -1
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +7 -1
  59. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  60. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  61. package/lib/cjs/helpers/utilization.d.ts +13 -0
  62. package/lib/cjs/helpers/utilization.js +26 -1
  63. package/lib/cjs/helpers/validate.d.ts +43 -2
  64. package/lib/cjs/helpers/validate.js +60 -3
  65. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  66. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  67. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  68. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -2
  71. package/lib/cjs/midnight/types.d.ts +1 -1
  72. package/lib/cjs/types/action.d.ts +117 -89
  73. package/lib/cjs/types/action.js +1 -19
  74. package/lib/cjs/types/error.d.ts +126 -40
  75. package/lib/cjs/types/error.js +154 -49
  76. package/lib/cjs/types/sharedLiquidity.d.ts +17 -0
  77. package/lib/esm/abis.d.ts +1 -1
  78. package/lib/esm/abis.js +1 -1
  79. package/lib/esm/actions/bundles/common.d.ts +9 -5
  80. package/lib/esm/actions/bundles/common.js +22 -13
  81. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  82. package/lib/esm/actions/midnight/authorization.js +3 -2
  83. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  84. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  85. package/lib/esm/actions/midnight/index.d.ts +3 -3
  86. package/lib/esm/actions/midnight/index.js +3 -3
  87. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  88. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  89. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  90. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  91. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  92. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  93. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  94. package/lib/esm/actions/midnight/takeLend.js +114 -57
  95. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  96. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  97. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  98. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  99. package/lib/esm/actions/midnight/types.d.ts +7 -26
  100. package/lib/esm/actions/midnight/types.js +1 -12
  101. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  102. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  103. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  104. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  105. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  106. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  107. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  108. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  109. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  110. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  111. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  112. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  113. package/lib/esm/constants.d.ts +1 -1
  114. package/lib/esm/constants.js +1 -1
  115. package/lib/esm/entities/blue/blue.d.ts +10 -6
  116. package/lib/esm/entities/blue/blue.js +5 -3
  117. package/lib/esm/entities/index.d.ts +2 -2
  118. package/lib/esm/entities/midnight/midnight.d.ts +582 -108
  119. package/lib/esm/entities/midnight/midnight.js +987 -515
  120. package/lib/esm/entities/midnight/types.d.ts +142 -60
  121. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
  122. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  123. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
  124. package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
  125. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -3
  126. package/lib/esm/entities/vaultV2BlueReallocationData.js +120 -44
  127. package/lib/esm/helpers/callback.d.ts +54 -0
  128. package/lib/esm/helpers/callback.js +68 -0
  129. package/lib/esm/helpers/constant.d.ts +10 -0
  130. package/lib/esm/helpers/constant.js +10 -0
  131. package/lib/esm/helpers/index.d.ts +3 -2
  132. package/lib/esm/helpers/index.js +3 -2
  133. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  134. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  135. package/lib/esm/helpers/utilization.d.ts +13 -0
  136. package/lib/esm/helpers/utilization.js +25 -1
  137. package/lib/esm/helpers/validate.d.ts +43 -2
  138. package/lib/esm/helpers/validate.js +58 -2
  139. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  140. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  141. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  142. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  143. package/lib/esm/midnight/abis.d.ts +1 -1
  144. package/lib/esm/midnight/abis.js +1 -1
  145. package/lib/esm/midnight/types.d.ts +1 -1
  146. package/lib/esm/types/action.d.ts +117 -89
  147. package/lib/esm/types/action.js +1 -18
  148. package/lib/esm/types/error.d.ts +126 -40
  149. package/lib/esm/types/error.js +135 -38
  150. package/lib/esm/types/sharedLiquidity.d.ts +17 -0
  151. package/package.json +9 -8
  152. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  153. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  154. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  155. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  156. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  157. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  158. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  159. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  160. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  161. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  162. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  163. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  164. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  165. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  166. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  167. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -0,0 +1,197 @@
1
+ import { MarketUtils, midnightBundlesV2Abi, } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData, maxUint256 } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateDeadline, validateMidnightNativeAmount, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
6
+ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
7
+ import { validateTakeableOffers } from "../../helpers/validateTakeableOffers.js";
8
+ import { InputExceedsMaxError, NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../types/index.js";
9
+ /**
10
+ * Encodes a `MidnightBundlesV2` reduce-only buy that repays `msg.sender`'s debt by taking
11
+ * borrow-side offers, optionally repays the remainder directly, then withdraws collateral.
12
+ *
13
+ * `reduceOnly` is always set, so the buy never opens a lender position. Prefer
14
+ * `client.morpho.midnight(chainId).takeRepayWithdrawCollateral(...)` in app flows so the
15
+ * loan-token approval and the `MidnightBundlesV2` authorization are resolved first.
16
+ *
17
+ * @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
18
+ * @param params.market - Midnight market traded by every takeable offer.
19
+ * @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`; `units: maxUint256` targets the sender's whole debt, capped by `maxBuyerAssets` (must be finite; `units: maxUint256` already selects the whole debt).
20
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
21
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of the
22
+ * maximum wNative amount this call can pull, but not more. Any wrapped native not pulled stays in
23
+ * the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still required
24
+ * for the full pulled amount.
25
+ * @param params.takeableOffers - ABI-ready borrow-side offers returned by the Midnight API; must not be empty.
26
+ * @param params.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
27
+ * @param params.collateralWithdrawals - Collateral index and assets per withdrawal; may be empty.
28
+ * @param params.collateralReceiver - Recipient of withdrawn collateral.
29
+ * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
30
+ * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
31
+ * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
32
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
33
+ * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
34
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
35
+ * @param params.metadata - Optional analytics metadata appended to calldata.
36
+ * @returns A deep-frozen `Transaction<MidnightTakeRepayWithdrawCollateralAction>` targeting `MidnightBundlesV2`.
37
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
38
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
39
+ * @throws {ChainIdMismatchError} when the market targets another chain.
40
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
41
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
42
+ * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
43
+ * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
44
+ * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
45
+ * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
46
+ * withdrawal amount or `deadline` is not positive.
47
+ * @throws {NegativeInputError} when `maxContinuousFee`, `referralFeePct` or `nativeAmount` is negative.
48
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
49
+ * @throws {NativeAmountOnNonWNativeAssetError} when `market.loanToken` is not wNative.
50
+ * @throws {InputExceedsMaxError} when `target.assets` or `target.maxBuyerAssets` is at
51
+ * least `maxUint256`, or a `collateralWithdrawals[].assets` amount, `target.units`,
52
+ * `minUnits`, `maxBuyerAssets`, `maxContinuousFee` or `deadline` exceeds `uint256`, or
53
+ * `nativeAmount` exceeds the maximum wNative amount this call can pull.
54
+ * @throws {UnboundedMidnightTakeInputError} when `deadline` is `maxUint256`.
55
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
56
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
57
+ * @example
58
+ * ```ts
59
+ * import { Time } from "@morpho-org/morpho-ts";
60
+ * import { maxUint256 } from "viem";
61
+ * import { midnightTakeRepayWithdrawCollateral } from "@morpho-org/morpho-sdk";
62
+ *
63
+ * const tx = midnightTakeRepayWithdrawCollateral({
64
+ * chainId: 8453,
65
+ * market: marketData.params,
66
+ * target: { type: "units", units: 1_000_000n, maxBuyerAssets: 990_000n },
67
+ * takeableOffers: quote.data.takeableOffers,
68
+ * repayEnabled: true,
69
+ * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
70
+ * collateralReceiver: borrower,
71
+ * maxContinuousFee: maxUint256,
72
+ * deadline: Time.timestamp() + 600n,
73
+ * });
74
+ * ```
75
+ */
76
+ export const midnightTakeRepayWithdrawCollateral = (params) => {
77
+ if (params.target.type === "assets" && params.target.assets <= 0n) {
78
+ throw new NonPositiveInputError("target.assets", params.target.assets);
79
+ }
80
+ // Reject markets from another chain deployment before checking offers against them.
81
+ validateMidnightMarket({ market: params.market, chainId: params.chainId });
82
+ for (const [index, { collateralIndex, assets },] of params.collateralWithdrawals.entries()) {
83
+ if (assets <= 0n) {
84
+ throw new NonPositiveInputError(`collateralWithdrawals[${index}].assets`, assets);
85
+ }
86
+ validateUint256Field(`collateralWithdrawals[${index}].assets`, assets);
87
+ // Throws UnknownCollateralIndexError when the index is not configured on the market.
88
+ MarketUtils.getCollateralByIndex(params.market, collateralIndex);
89
+ }
90
+ const marketId = validateTakeableOffers({
91
+ market: params.market,
92
+ takeableOffers: params.takeableOffers,
93
+ expectedBuy: false,
94
+ });
95
+ const { target } = params;
96
+ if (target.type === "assets") {
97
+ // `assets` bounds the loan assets pulled; it stays finite since there is no
98
+ // "whole debt" sentinel for an assets target.
99
+ if (target.assets >= maxUint256) {
100
+ throw new InputExceedsMaxError({
101
+ field: "target.assets",
102
+ value: target.assets,
103
+ max: maxUint256 - 1n,
104
+ });
105
+ }
106
+ if (target.minUnits <= 0n) {
107
+ throw new NonPositiveInputError("target.minUnits", target.minUnits);
108
+ }
109
+ validateUint256Field("target.minUnits", target.minUnits);
110
+ }
111
+ else {
112
+ if (target.units <= 0n) {
113
+ throw new NonPositiveInputError("target.units", target.units);
114
+ }
115
+ if (target.maxBuyerAssets <= 0n) {
116
+ throw new NonPositiveInputError("target.maxBuyerAssets", target.maxBuyerAssets);
117
+ }
118
+ // `maxBuyerAssets` bounds the loan assets pulled; it stays finite since
119
+ // `units: maxUint256` already selects the whole debt.
120
+ if (target.maxBuyerAssets >= maxUint256) {
121
+ throw new InputExceedsMaxError({
122
+ field: "target.maxBuyerAssets",
123
+ value: target.maxBuyerAssets,
124
+ max: maxUint256 - 1n,
125
+ });
126
+ }
127
+ validateUint256Field("target.units", target.units);
128
+ }
129
+ validateUint256Field("maxContinuousFee", params.maxContinuousFee);
130
+ if (params.deadline === maxUint256) {
131
+ throw new UnboundedMidnightTakeInputError("deadline");
132
+ }
133
+ validateDeadline(params.deadline);
134
+ const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
135
+ const market = MarketUtils.toStruct(params.market);
136
+ const nativeFunding = validateMidnightNativeAmount({
137
+ chainId: params.chainId,
138
+ nativeAmount: params.nativeAmount,
139
+ pulls: [
140
+ {
141
+ token: market.loanToken,
142
+ assets: target.type === "assets" ? target.assets : target.maxBuyerAssets,
143
+ },
144
+ ],
145
+ });
146
+ const args = [
147
+ true, // reduceOnly
148
+ params.repayEnabled, // repayEnabled
149
+ params.takeableOffers, // offerFills
150
+ params.collateralWithdrawals.map(({ collateralIndex, assets }) => ({
151
+ collateralIndex,
152
+ assets,
153
+ })), // collateralWithdrawals
154
+ params.collateralReceiver, // collateralReceiver
155
+ referralFeePct, // referralFeePct
156
+ referralFeeRecipient, // referralFeeRecipient
157
+ params.maxContinuousFee, // maxContinuousFee
158
+ params.deadline, // deadline
159
+ nativeFunding.wrappedNative, // wrappedNative
160
+ ];
161
+ let tx = {
162
+ to: getChainAddress(params.chainId, "midnightBundlesV2"),
163
+ value: nativeFunding.value,
164
+ data: target.type === "assets"
165
+ ? encodeFunctionData({
166
+ abi: midnightBundlesV2Abi,
167
+ functionName: "midnightBundlesV2BuyWithAssetsTargetAndWithdrawCollateral",
168
+ args: [market, target.assets, target.minUnits, ...args],
169
+ })
170
+ : encodeFunctionData({
171
+ abi: midnightBundlesV2Abi,
172
+ functionName: "midnightBundlesV2BuyWithUnitsTargetAndWithdrawCollateral",
173
+ args: [market, target.units, target.maxBuyerAssets, ...args],
174
+ }),
175
+ };
176
+ if (params.metadata) {
177
+ tx = addTransactionMetadata(tx, params.metadata);
178
+ }
179
+ return deepFreeze({
180
+ ...tx,
181
+ action: {
182
+ type: "midnightTakeRepayWithdrawCollateral",
183
+ args: {
184
+ market: marketId,
185
+ target: { ...params.target },
186
+ repayEnabled: params.repayEnabled,
187
+ collateralWithdrawals: params.collateralWithdrawals.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
188
+ collateralReceiver: params.collateralReceiver,
189
+ takeableOffers: params.takeableOffers.length,
190
+ maxContinuousFee: params.maxContinuousFee,
191
+ deadline: params.deadline,
192
+ referralFeePct,
193
+ referralFeeRecipient,
194
+ },
195
+ },
196
+ });
197
+ };
@@ -0,0 +1,69 @@
1
+ import { type MarketInput } from "@morpho-org/midnight-sdk";
2
+ import { type Address } from "viem";
3
+ import { type Metadata, type MidnightSellTarget, type MidnightTakeWithdrawAction, type Transaction } from "../../types/index.js";
4
+ import type { MidnightReferralFeeParams, MidnightTakeableOffer } from "./types.js";
5
+ /** Parameters for encoding a Midnight credit withdrawal that redeems first, then sells to offers. */
6
+ export interface MidnightTakeWithdrawParams extends MidnightReferralFeeParams {
7
+ readonly chainId: number;
8
+ readonly market: MarketInput;
9
+ /** Loan assets received with a credit-unit cap, or credit units sold with a loan-asset floor. */
10
+ readonly target: MidnightSellTarget;
11
+ /** Recipient of the withdrawn loan assets. */
12
+ readonly receiver: Address;
13
+ readonly takeableOffers: readonly MidnightTakeableOffer[];
14
+ /** Bounded bundle execution deadline timestamp. */
15
+ readonly deadline: bigint;
16
+ readonly metadata?: Metadata;
17
+ }
18
+ /**
19
+ * Encodes a reduce-only `MidnightBundlesV2` sell that withdraws `msg.sender`'s credit.
20
+ *
21
+ * `MidnightBundlesV2` first redeems as much credit as the target and market liquidity allow, then
22
+ * sells the rest of the target to lend-side offers. `reduceOnly` is always set, so the sell fails
23
+ * instead of opening debt when the sender's credit does not cover the target.
24
+ *
25
+ * Prefer `client.morpho.midnight(chainId).takeWithdraw(...)` in app flows so the
26
+ * `MidnightBundlesV2` authorization is resolved before building the bundle.
27
+ *
28
+ * @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
29
+ * @param params.market - Midnight market traded by every takeable offer.
30
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
31
+ * @param params.receiver - Recipient of the withdrawn loan assets.
32
+ * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
33
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
34
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
35
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
36
+ * @param params.metadata - Optional analytics metadata appended to calldata.
37
+ * @returns A deep-frozen `Transaction<MidnightTakeWithdrawAction>` targeting `MidnightBundlesV2`.
38
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
39
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
40
+ * @throws {ChainIdMismatchError} when the market targets another chain.
41
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
42
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
43
+ * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
44
+ * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
45
+ * @throws {NonPositiveInputError} when the target amount, `maxUnits`, `minSellerAssets` or
46
+ * `deadline` is not positive.
47
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
48
+ * @throws {InputExceedsMaxError} when `target.assets`, `target.maxUnits`, `target.units`,
49
+ * `target.minSellerAssets` or `deadline` exceeds `uint256`.
50
+ * @throws {UnboundedMidnightTakeInputError} when `target.units`, `target.maxUnits` or `deadline`
51
+ * is `maxUint256`.
52
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
53
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
54
+ * @example
55
+ * ```ts
56
+ * import { Time } from "@morpho-org/morpho-ts";
57
+ * import { midnightTakeWithdraw } from "@morpho-org/morpho-sdk";
58
+ *
59
+ * const tx = midnightTakeWithdraw({
60
+ * chainId: 8453,
61
+ * market: marketData.params,
62
+ * target: { type: "units", units: credit, minSellerAssets: 990_000n },
63
+ * receiver: lender,
64
+ * takeableOffers: quote.data.takeableOffers,
65
+ * deadline: Time.timestamp() + 600n,
66
+ * });
67
+ * ```
68
+ */
69
+ export declare const midnightTakeWithdraw: (params: MidnightTakeWithdrawParams) => Readonly<Transaction<MidnightTakeWithdrawAction>>;
@@ -0,0 +1,149 @@
1
+ import { MarketUtils, midnightBundlesV2Abi, } from "@morpho-org/midnight-sdk";
2
+ import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
3
+ import { encodeFunctionData, maxUint256, zeroAddress, } from "viem";
4
+ import { addTransactionMetadata } from "../../helpers/index.js";
5
+ import { validateDeadline, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
6
+ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
7
+ import { validateTakeableOffers } from "../../helpers/validateTakeableOffers.js";
8
+ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../types/index.js";
9
+ const validateParams = (params) => {
10
+ // Reject markets from another chain deployment before checking offers against them.
11
+ validateMidnightMarket({ market: params.market, chainId: params.chainId });
12
+ const marketId = validateTakeableOffers({
13
+ market: params.market,
14
+ takeableOffers: params.takeableOffers,
15
+ expectedBuy: true,
16
+ });
17
+ const { target } = params;
18
+ if (target.type === "assets") {
19
+ if (target.assets <= 0n) {
20
+ throw new NonPositiveInputError("target.assets", target.assets);
21
+ }
22
+ if (target.maxUnits === maxUint256) {
23
+ throw new UnboundedMidnightTakeInputError("target.maxUnits");
24
+ }
25
+ if (target.maxUnits <= 0n) {
26
+ throw new NonPositiveInputError("target.maxUnits", target.maxUnits);
27
+ }
28
+ validateUint256Field("target.assets", target.assets);
29
+ validateUint256Field("target.maxUnits", target.maxUnits);
30
+ }
31
+ else {
32
+ if (target.units === maxUint256) {
33
+ throw new UnboundedMidnightTakeInputError("target.units");
34
+ }
35
+ if (target.units <= 0n) {
36
+ throw new NonPositiveInputError("target.units", target.units);
37
+ }
38
+ if (target.minSellerAssets <= 0n) {
39
+ throw new NonPositiveInputError("target.minSellerAssets", target.minSellerAssets);
40
+ }
41
+ validateUint256Field("target.units", target.units);
42
+ validateUint256Field("target.minSellerAssets", target.minSellerAssets);
43
+ }
44
+ if (params.deadline === maxUint256) {
45
+ throw new UnboundedMidnightTakeInputError("deadline");
46
+ }
47
+ validateDeadline(params.deadline);
48
+ const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
49
+ return { marketId, referralFeePct, referralFeeRecipient };
50
+ };
51
+ /**
52
+ * Encodes a reduce-only `MidnightBundlesV2` sell that withdraws `msg.sender`'s credit.
53
+ *
54
+ * `MidnightBundlesV2` first redeems as much credit as the target and market liquidity allow, then
55
+ * sells the rest of the target to lend-side offers. `reduceOnly` is always set, so the sell fails
56
+ * instead of opening debt when the sender's credit does not cover the target.
57
+ *
58
+ * Prefer `client.morpho.midnight(chainId).takeWithdraw(...)` in app flows so the
59
+ * `MidnightBundlesV2` authorization is resolved before building the bundle.
60
+ *
61
+ * @param params.chainId - Chain id used to resolve `MidnightBundlesV2`.
62
+ * @param params.market - Midnight market traded by every takeable offer.
63
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
64
+ * @param params.receiver - Recipient of the withdrawn loan assets.
65
+ * @param params.takeableOffers - ABI-ready lend-side offers returned by the Midnight API.
66
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
67
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
68
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
69
+ * @param params.metadata - Optional analytics metadata appended to calldata.
70
+ * @returns A deep-frozen `Transaction<MidnightTakeWithdrawAction>` targeting `MidnightBundlesV2`.
71
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
72
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
73
+ * @throws {ChainIdMismatchError} when the market targets another chain.
74
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
75
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
76
+ * @throws {MidnightOfferSideMismatchError} when any offer is not lend-side.
77
+ * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
78
+ * @throws {NonPositiveInputError} when the target amount, `maxUnits`, `minSellerAssets` or
79
+ * `deadline` is not positive.
80
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
81
+ * @throws {InputExceedsMaxError} when `target.assets`, `target.maxUnits`, `target.units`,
82
+ * `target.minSellerAssets` or `deadline` exceeds `uint256`.
83
+ * @throws {UnboundedMidnightTakeInputError} when `target.units`, `target.maxUnits` or `deadline`
84
+ * is `maxUint256`.
85
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
86
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
87
+ * @example
88
+ * ```ts
89
+ * import { Time } from "@morpho-org/morpho-ts";
90
+ * import { midnightTakeWithdraw } from "@morpho-org/morpho-sdk";
91
+ *
92
+ * const tx = midnightTakeWithdraw({
93
+ * chainId: 8453,
94
+ * market: marketData.params,
95
+ * target: { type: "units", units: credit, minSellerAssets: 990_000n },
96
+ * receiver: lender,
97
+ * takeableOffers: quote.data.takeableOffers,
98
+ * deadline: Time.timestamp() + 600n,
99
+ * });
100
+ * ```
101
+ */
102
+ export const midnightTakeWithdraw = (params) => {
103
+ const { marketId, referralFeePct, referralFeeRecipient } = validateParams(params);
104
+ const { target } = params;
105
+ const market = MarketUtils.toStruct(params.market);
106
+ const args = [
107
+ true, // reduceOnly
108
+ params.receiver, // receiver
109
+ [], // collateralSupplies
110
+ params.takeableOffers, // offerFills
111
+ referralFeePct, // referralFeePct
112
+ referralFeeRecipient, // referralFeeRecipient
113
+ params.deadline, // deadline
114
+ zeroAddress, // wrappedNative
115
+ ];
116
+ let tx = {
117
+ to: getChainAddress(params.chainId, "midnightBundlesV2"),
118
+ value: 0n,
119
+ data: target.type === "assets"
120
+ ? encodeFunctionData({
121
+ abi: midnightBundlesV2Abi,
122
+ functionName: "midnightBundlesV2SupplyCollateralAndSellWithAssetsTarget",
123
+ args: [market, target.assets, target.maxUnits, ...args],
124
+ })
125
+ : encodeFunctionData({
126
+ abi: midnightBundlesV2Abi,
127
+ functionName: "midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget",
128
+ args: [market, target.units, target.minSellerAssets, ...args],
129
+ }),
130
+ };
131
+ if (params.metadata) {
132
+ tx = addTransactionMetadata(tx, params.metadata);
133
+ }
134
+ return deepFreeze({
135
+ ...tx,
136
+ action: {
137
+ type: "midnightTakeWithdraw",
138
+ args: {
139
+ market: marketId,
140
+ target: { ...params.target },
141
+ receiver: params.receiver,
142
+ takeableOffers: params.takeableOffers.length,
143
+ deadline: params.deadline,
144
+ referralFeePct,
145
+ referralFeeRecipient,
146
+ },
147
+ },
148
+ });
149
+ };
@@ -1,30 +1,5 @@
1
1
  import type { OfferStruct } from "@morpho-org/midnight-sdk";
2
- import type { Hex } from "viem";
3
- /**
4
- * MidnightBundles token permit selector.
5
- *
6
- * The first Midnight action implementation only emits `None`; `ERC2612` and
7
- * `Permit2` are reserved for future token-signature bundle support.
8
- */
9
- export declare enum PermitKind {
10
- None = 0,
11
- ERC2612 = 1,
12
- Permit2 = 2
13
- }
14
- /** ABI-ready token permit metadata consumed by MidnightBundles. */
15
- export type MidnightTokenPermit = {
16
- readonly kind: PermitKind.None;
17
- readonly data: "0x";
18
- } | {
19
- readonly kind: PermitKind.ERC2612 | PermitKind.Permit2;
20
- readonly data: Hex;
21
- };
22
- /** Protocol-shaped collateral supply used by Midnight bundle calls. */
23
- export interface MidnightCollateralSupply {
24
- readonly collateralIndex: bigint;
25
- readonly assets: bigint;
26
- readonly permit: MidnightTokenPermit;
27
- }
2
+ import type { Address, Hex } from "viem";
28
3
  /**
29
4
  * ABI-ready Midnight takeable offer returned by quote/takeable-offer APIs.
30
5
  *
@@ -37,3 +12,9 @@ export interface MidnightTakeableOffer {
37
12
  readonly offer: OfferStruct;
38
13
  readonly ratifierData: Hex;
39
14
  }
15
+ /** Optional referral fee shared by the Midnight taker builders. */
16
+ export interface MidnightReferralFeeParams {
17
+ /** WAD-scaled share of the filled loan assets paid to `referralFeeRecipient`. Defaults to `0n`. */
18
+ readonly referralFeePct?: bigint;
19
+ readonly referralFeeRecipient?: Address;
20
+ }
@@ -1,12 +1 @@
1
- /**
2
- * MidnightBundles token permit selector.
3
- *
4
- * The first Midnight action implementation only emits `None`; `ERC2612` and
5
- * `Permit2` are reserved for future token-signature bundle support.
6
- */
7
- export var PermitKind;
8
- (function (PermitKind) {
9
- PermitKind[PermitKind["None"] = 0] = "None";
10
- PermitKind[PermitKind["ERC2612"] = 1] = "ERC2612";
11
- PermitKind[PermitKind["Permit2"] = 2] = "Permit2";
12
- })(PermitKind || (PermitKind = {}));
1
+ export {};
@@ -16,7 +16,8 @@ interface EncodeErc20ApprovalParams {
16
16
  * @param params - Encoding parameters.
17
17
  * @param params.token - ERC-20 token address to approve.
18
18
  * @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
19
- * MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
19
+ * MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
20
+ * the chain.
20
21
  * @param params.amount - Allowance amount before per-token cap.
21
22
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
22
23
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -12,7 +12,8 @@ import { validateRequirementSpender } from "../../../helpers/validateRequirement
12
12
  * @param params - Encoding parameters.
13
13
  * @param params.token - ERC-20 token address to approve.
14
14
  * @param params.spender - Address granted the allowance. Must be Permit2, Midnight,
15
- * MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for the chain.
15
+ * MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for
16
+ * the chain.
16
17
  * @param params.amount - Allowance amount before per-token cap.
17
18
  * @param params.chainId - The chain the transaction targets (used to resolve supported spenders and the per-token cap).
18
19
  * @returns A deep-frozen `Transaction<ERC20ApprovalAction>` with the capped approval amount.
@@ -40,7 +41,7 @@ export const encodeErc20Approval = (params) => {
40
41
  allowed: [
41
42
  "permit2",
42
43
  "midnight",
43
- "midnightBundles",
44
+ "midnightBundlesV2",
44
45
  "vaultExitBundlesV1",
45
46
  "vaultBundlesV1",
46
47
  "blueBundlesV1",
@@ -27,8 +27,8 @@ interface EncodeErc20PermitParams {
27
27
  * @param params - Permit encoding parameters.
28
28
  * @param params.token - ERC-20 token address (must support EIP-2612).
29
29
  * @param params.owner - Account that owns the tokens and signs the permit.
30
- * @param params.spender - Permit spender. Must be MidnightBundles, VaultBundlesV1, or
31
- * BlueBundlesV1 for the chain.
30
+ * @param params.spender - Permit spender. Must be VaultBundlesV1 or BlueBundlesV1 for the
31
+ * chain.
32
32
  * @param params.amount - Permit allowance amount.
33
33
  * @param params.chainId - Target chain id.
34
34
  * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
@@ -38,8 +38,8 @@ interface EncodeErc20PermitParams {
38
38
  * `sign(client, userAddress)` produces the deep-frozen signature.
39
39
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
40
40
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
41
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not MidnightBundles,
42
- * VaultBundlesV1, or BlueBundlesV1 for `chainId`.
41
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not VaultBundlesV1 or
42
+ * BlueBundlesV1 for `chainId`.
43
43
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
44
44
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
45
45
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
@@ -18,8 +18,8 @@ import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/inde
18
18
  * @param params - Permit encoding parameters.
19
19
  * @param params.token - ERC-20 token address (must support EIP-2612).
20
20
  * @param params.owner - Account that owns the tokens and signs the permit.
21
- * @param params.spender - Permit spender. Must be MidnightBundles, VaultBundlesV1, or
22
- * BlueBundlesV1 for the chain.
21
+ * @param params.spender - Permit spender. Must be VaultBundlesV1 or BlueBundlesV1 for the
22
+ * chain.
23
23
  * @param params.amount - Permit allowance amount.
24
24
  * @param params.chainId - Target chain id.
25
25
  * @param params.nonce - The owner's current EIP-2612 nonce on `token`.
@@ -29,8 +29,8 @@ import { ChainIdMismatchError, ExpiredDeadlineError, } from "../../../types/inde
29
29
  * `sign(client, userAddress)` produces the deep-frozen signature.
30
30
  * @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
31
31
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
32
- * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not MidnightBundles,
33
- * VaultBundlesV1, or BlueBundlesV1 for `chainId`.
32
+ * @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not VaultBundlesV1 or
33
+ * BlueBundlesV1 for `chainId`.
34
34
  * @throws {NonPositiveInputError} when an explicit `deadline` is not positive.
35
35
  * @throws {InputExceedsMaxError} when an explicit `deadline` exceeds `uint256`.
36
36
  * @throws {ExpiredDeadlineError} when an explicit `deadline` is positive but not in the future.
@@ -67,7 +67,7 @@ export const encodeErc20Permit = async (viemClient, params) => {
67
67
  validateRequirementSpender({
68
68
  chainId,
69
69
  spender,
70
- allowed: ["midnightBundles", "vaultBundlesV1", "blueBundlesV1"],
70
+ allowed: ["vaultBundlesV1", "blueBundlesV1"],
71
71
  });
72
72
  const now = Time.timestamp();
73
73
  // Validate an explicit deadline before the token-metadata read: this exported encoder can be
@@ -5,7 +5,7 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
5
5
  * allowance.
6
6
  *
7
7
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
8
- * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
8
+ * Permit2, Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
9
9
  * addresses when configured.
10
10
  *
11
11
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
@@ -20,7 +20,7 @@ import { type ERC20ApprovalAction, type Transaction } from "../../types/index.js
20
20
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
21
21
  * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
22
22
  * @param params.args.spender - Address that will be granted the approval. Must be Permit2,
23
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
23
+ * Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
24
24
  * @param params.allowances - The user's current allowance of `address` for `spender`.
25
25
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
26
26
  * followed by the new approval. Empty when no approval is needed.
@@ -7,7 +7,7 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
7
7
  * allowance.
8
8
  *
9
9
  * The spender is validated by {@link encodeErc20Approval}. Supported spenders are the chain's
10
- * Permit2, Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
10
+ * Permit2, Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, and BlueBundlesV1
11
11
  * addresses when configured.
12
12
  *
13
13
  * Returns an empty array when the allowance already covers `spendAmount`. When the token is in
@@ -22,7 +22,7 @@ import { encodeErc20Approval } from "./encode/encodeErc20Approval.js";
22
22
  * @param params.args.approvalAmount - The amount to approve (often equal to `spendAmount`, but
23
23
  * may be `maxUint256` for reusable Permit2 or saturated-share-repay approvals).
24
24
  * @param params.args.spender - Address that will be granted the approval. Must be Permit2,
25
- * Midnight, MidnightBundles, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
25
+ * Midnight, MidnightBundlesV2, VaultExitBundlesV1, VaultBundlesV1, or BlueBundlesV1 for `chainId`.
26
26
  * @param params.allowances - The user's current allowance of `address` for `spender`.
27
27
  * @returns Up to two deep-frozen `Transaction<ERC20ApprovalAction>` entries: an optional reset
28
28
  * followed by the new approval. Empty when no approval is needed.