@morpho-org/morpho-sdk 6.6.0 → 7.1.0-next.1

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 (195) hide show
  1. package/MIGRATION-v6-to-v7.md +297 -0
  2. package/README.md +26 -12
  3. package/lib/cjs/abis.d.ts +2 -2
  4. package/lib/cjs/abis.js +7 -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/blue/abis.d.ts +1 -1
  40. package/lib/cjs/blue/abis.js +5 -1
  41. package/lib/cjs/blue/entities.d.ts +4 -4
  42. package/lib/cjs/blue/entities.js +3 -1
  43. package/lib/cjs/blue/errors.d.ts +2 -2
  44. package/lib/cjs/blue/errors.js +5 -1
  45. package/lib/cjs/blue/fetch.d.ts +2 -2
  46. package/lib/cjs/blue/fetch.js +3 -1
  47. package/lib/cjs/blue/utils.d.ts +1 -1
  48. package/lib/cjs/blue/utils.js +2 -1
  49. package/lib/cjs/constants.d.ts +1 -1
  50. package/lib/cjs/constants.js +2 -1
  51. package/lib/cjs/entities/index.d.ts +6 -6
  52. package/lib/cjs/entities/index.js +3 -1
  53. package/lib/cjs/entities/midnight/midnight.d.ts +585 -108
  54. package/lib/cjs/entities/midnight/midnight.js +984 -509
  55. package/lib/cjs/entities/midnight/types.d.ts +142 -60
  56. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -2
  57. package/lib/cjs/entities/vaultV1/vaultV1.js +32 -34
  58. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +37 -12
  59. package/lib/cjs/entities/vaultV2/vaultV2.js +68 -41
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +5 -3
  61. package/lib/cjs/entities/vaultV2BlueReallocationData.js +9 -3
  62. package/lib/cjs/errors.d.ts +4 -4
  63. package/lib/cjs/errors.js +10 -5
  64. package/lib/cjs/fetch.d.ts +2 -2
  65. package/lib/cjs/fetch.js +3 -1
  66. package/lib/cjs/helpers/callback.d.ts +54 -0
  67. package/lib/cjs/helpers/callback.js +73 -0
  68. package/lib/cjs/helpers/constant.d.ts +2 -0
  69. package/lib/cjs/helpers/constant.js +3 -1
  70. package/lib/cjs/helpers/index.d.ts +3 -2
  71. package/lib/cjs/helpers/index.js +6 -1
  72. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
  73. package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
  74. package/lib/cjs/helpers/validate.d.ts +43 -2
  75. package/lib/cjs/helpers/validate.js +60 -3
  76. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  77. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
  78. package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
  79. package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
  80. package/lib/cjs/midnight/abis.d.ts +1 -1
  81. package/lib/cjs/midnight/abis.js +3 -2
  82. package/lib/cjs/midnight/errors.d.ts +2 -1
  83. package/lib/cjs/midnight/errors.js +5 -4
  84. package/lib/cjs/midnight/types.d.ts +1 -1
  85. package/lib/cjs/types/action.d.ts +219 -90
  86. package/lib/cjs/types/action.js +103 -20
  87. package/lib/cjs/types/error.d.ts +126 -40
  88. package/lib/cjs/types/error.js +154 -49
  89. package/lib/cjs/utils.d.ts +2 -2
  90. package/lib/cjs/utils.js +4 -2
  91. package/lib/esm/abis.d.ts +2 -2
  92. package/lib/esm/abis.js +2 -2
  93. package/lib/esm/actions/bundles/common.d.ts +9 -5
  94. package/lib/esm/actions/bundles/common.js +22 -13
  95. package/lib/esm/actions/midnight/authorization.d.ts +3 -2
  96. package/lib/esm/actions/midnight/authorization.js +3 -2
  97. package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
  98. package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
  99. package/lib/esm/actions/midnight/index.d.ts +3 -3
  100. package/lib/esm/actions/midnight/index.js +3 -3
  101. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
  102. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
  103. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
  104. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
  105. package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
  106. package/lib/esm/actions/midnight/takeBorrow.js +98 -57
  107. package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
  108. package/lib/esm/actions/midnight/takeLend.js +114 -57
  109. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
  110. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
  111. package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
  112. package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
  113. package/lib/esm/actions/midnight/types.d.ts +7 -26
  114. package/lib/esm/actions/midnight/types.js +1 -12
  115. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  116. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  117. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
  118. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
  119. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
  120. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
  121. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
  122. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
  123. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
  124. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
  125. package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
  126. package/lib/esm/actions/requirements/midnight/index.js +0 -1
  127. package/lib/esm/blue/abis.d.ts +1 -1
  128. package/lib/esm/blue/abis.js +1 -1
  129. package/lib/esm/blue/entities.d.ts +4 -4
  130. package/lib/esm/blue/entities.js +2 -2
  131. package/lib/esm/blue/errors.d.ts +2 -2
  132. package/lib/esm/blue/errors.js +2 -2
  133. package/lib/esm/blue/fetch.d.ts +2 -2
  134. package/lib/esm/blue/fetch.js +2 -2
  135. package/lib/esm/blue/utils.d.ts +1 -1
  136. package/lib/esm/blue/utils.js +1 -1
  137. package/lib/esm/constants.d.ts +1 -1
  138. package/lib/esm/constants.js +1 -1
  139. package/lib/esm/entities/index.d.ts +6 -6
  140. package/lib/esm/entities/index.js +2 -2
  141. package/lib/esm/entities/midnight/midnight.d.ts +585 -108
  142. package/lib/esm/entities/midnight/midnight.js +990 -515
  143. package/lib/esm/entities/midnight/types.d.ts +142 -60
  144. package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -2
  145. package/lib/esm/entities/vaultV1/vaultV1.js +33 -35
  146. package/lib/esm/entities/vaultV2/vaultV2.d.ts +37 -12
  147. package/lib/esm/entities/vaultV2/vaultV2.js +69 -42
  148. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +5 -3
  149. package/lib/esm/entities/vaultV2BlueReallocationData.js +9 -3
  150. package/lib/esm/errors.d.ts +4 -4
  151. package/lib/esm/errors.js +4 -4
  152. package/lib/esm/fetch.d.ts +2 -2
  153. package/lib/esm/fetch.js +2 -2
  154. package/lib/esm/helpers/callback.d.ts +54 -0
  155. package/lib/esm/helpers/callback.js +68 -0
  156. package/lib/esm/helpers/constant.d.ts +2 -0
  157. package/lib/esm/helpers/constant.js +2 -0
  158. package/lib/esm/helpers/index.d.ts +3 -2
  159. package/lib/esm/helpers/index.js +3 -2
  160. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
  161. package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
  162. package/lib/esm/helpers/validate.d.ts +43 -2
  163. package/lib/esm/helpers/validate.js +58 -2
  164. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
  165. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
  166. package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
  167. package/lib/esm/helpers/validateRequirementSpender.js +4 -5
  168. package/lib/esm/midnight/abis.d.ts +1 -1
  169. package/lib/esm/midnight/abis.js +1 -1
  170. package/lib/esm/midnight/errors.d.ts +2 -1
  171. package/lib/esm/midnight/errors.js +2 -1
  172. package/lib/esm/midnight/types.d.ts +1 -1
  173. package/lib/esm/types/action.d.ts +219 -90
  174. package/lib/esm/types/action.js +103 -19
  175. package/lib/esm/types/error.d.ts +126 -40
  176. package/lib/esm/types/error.js +135 -38
  177. package/lib/esm/utils.d.ts +2 -2
  178. package/lib/esm/utils.js +2 -2
  179. package/package.json +10 -10
  180. package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
  181. package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
  182. package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  183. package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
  184. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  185. package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
  186. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  187. package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
  188. package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
  189. package/lib/esm/actions/midnight/cancelOffer.js +0 -69
  190. package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
  191. package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
  192. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
  193. package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
  194. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
  195. package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
@@ -1,8 +1,8 @@
1
1
  import { type AccrualPosition, type Market, type MidnightFetchParams } from "@morpho-org/midnight-sdk";
2
2
  import { type Address, type Hex } from "viem";
3
3
  import type { MorphoClientType } from "../../types/client.js";
4
- import { type MidnightCancelOfferAction, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction } from "../../types/index.js";
5
- import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams } from "./types.js";
4
+ import { type MidnightCancelAndMakeAction, type MidnightGroupCancellation, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction, type MidnightTakeRepayWithdrawCollateralAction, type MidnightTakeWithdrawAction } from "../../types/index.js";
5
+ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams, TakeRepayWithdrawCollateralParams, TakeWithdrawParams } from "./types.js";
6
6
  /**
7
7
  * Entity methods exposed by `client.morpho.midnight(chainId)`.
8
8
  *
@@ -13,6 +13,7 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
13
13
  *
14
14
  * @example
15
15
  * ```ts
16
+ * import { Time } from "@morpho-org/morpho-ts";
16
17
  * import { maxUint256 } from "viem";
17
18
  *
18
19
  * const midnight = client.morpho.midnight(8453);
@@ -20,16 +21,16 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
20
21
  * const output = midnight.takeLend({
21
22
  * accountAddress: lender,
22
23
  * marketData,
23
- * assets: 1_000_000n,
24
- * minUnits: 900_000n,
24
+ * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
25
25
  * takeableOffers: quote.data.takeableOffers,
26
- * deadline: maxUint256,
26
+ * maxContinuousFee: maxUint256,
27
+ * deadline: Time.timestamp() + 600n,
27
28
  * });
28
29
  * const requirements = await output.getRequirements();
29
30
  * const tx = output.buildTx();
30
31
  * ```
31
32
  */
32
- export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "supplyCollateralTakeBorrow" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffer">;
33
+ export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "takeWithdraw" | "supplyCollateralTakeBorrow" | "takeRepayWithdrawCollateral" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyBlueMakeLend" | "makeWithdraw" | "makeRepay" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffers">;
33
34
  /**
34
35
  * Entity facade for Midnight fixed-rate action flows.
35
36
  *
@@ -100,123 +101,299 @@ export declare class MorphoMidnight {
100
101
  /**
101
102
  * Builds and validates a maker offer tree against the Midnight mempool API.
102
103
  *
103
- * @param params - Maker account, raw offer or group inputs, and optional API validation controls.
104
+ * @param params - Maker account, PriceRatifierV1 or RateRatifierV1 tree input, and optional API validation controls.
104
105
  * @param params.accountAddress - Maker expected on every offer.
105
- * @param params.offers - Offer, group, tree, or list accepted by `Tree.create`.
106
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
106
107
  * @param params.validation - Optional Midnight mempool API request controls.
107
- * @returns Prepared tree data used by maker flows.
108
+ * @returns Prepared tree, groups, ratifier, and encoded payload used by maker flows.
108
109
  * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
109
110
  * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
111
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
110
112
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
113
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
114
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
111
115
  * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
112
116
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
113
- * @throws {UnknownMidnightRatifierError} when the tree uses an unsupported ratifier.
117
+ * @throws {UnknownAddressError} when the chain has no deployment for the tree's V1 ratifier.
118
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
114
119
  * @example
115
120
  * ```ts
116
121
  * const offersData = await midnight.getOffersData({
117
122
  * accountAddress: maker,
118
- * offers: [offer],
123
+ * offers: { type: "rateV1", entries: [{ offer, rate }] },
119
124
  * });
120
125
  * ```
121
126
  */
122
127
  getOffersData(params: GetOffersDataParams): Promise<OffersData>;
123
128
  /**
124
- * Prepares a lend-side take using caller-provided market data and API offers.
129
+ * Prepares a `MidnightBundlesV2` buy that lends into borrow-side offers for `accountAddress`.
125
130
  *
126
- * @param params - Lender, market snapshot, target assets, units, offers, and deadline.
127
- * @param params.accountAddress - Lender executing the take.
131
+ * @param params - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
132
+ * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
128
133
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
129
- * @param params.assets - Loan assets spent by the lender.
130
- * @param params.minUnits - Minimum credit units accepted.
134
+ * @param params.target - `{ type: "assets", assets, minUnits }` or `{ type: "units", units, maxBuyerAssets }`.
135
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
136
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
137
+ * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
138
+ * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
139
+ * required for the full pulled amount.
131
140
  * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
141
+ * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
142
+ * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
143
+ * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
132
144
  * @param params.deadline - Bundle execution deadline timestamp.
133
- * @returns Lazy approval/authorization requirements and a synchronous transaction builder.
145
+ * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
146
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
147
+ * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
134
148
  * @throws {ChainIdMismatchError} when client or market data targets another chain.
149
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
150
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
151
+ * @throws {InputExceedsMaxError} when `target.assets`, `target.units`, `minUnits`, `maxBuyerAssets`
152
+ * or `maxContinuousFee` exceeds `uint256`, or `nativeAmount` exceeds the maximum
153
+ * wNative amount this call can pull.
135
154
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
136
- * @throws {NonPositiveInputError} when `assets` is non-positive.
137
- * @throws {NegativeInputError} when `minUnits` or `deadline` is negative.
155
+ * @throws {NonPositiveInputError} when the target amount, `minUnits` or `maxBuyerAssets` is not positive.
156
+ * @throws {NegativeInputError} when `maxContinuousFee`, `referralFeePct` or `nativeAmount` is negative.
157
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
158
+ * @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
159
+ * @throws {UnboundedMidnightTakeInputError} when `target.units` or
160
+ * `target.maxBuyerAssets` is `maxUint256`.
161
+ * @throws {ExpiredDeadlineError} when `deadline` has expired.
162
+ * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
138
163
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
139
164
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
140
165
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
166
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
167
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
168
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
141
169
  * @example
142
170
  * ```ts
143
171
  * const output = midnight.takeLend({
144
172
  * accountAddress: lender,
145
173
  * marketData,
146
- * assets: 1_000_000n,
147
- * minUnits: 900_000n,
174
+ * target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
148
175
  * takeableOffers: quote.data.takeableOffers,
149
- * deadline: maxUint256,
176
+ * maxContinuousFee: maxUint256,
177
+ * deadline: Time.timestamp() + 600n,
150
178
  * });
151
179
  * ```
152
180
  */
153
181
  takeLend(params: TakeLendParams): MidnightActionOutput<MidnightTakeLendAction>;
154
182
  /**
155
- * Prepares a borrow-side take using caller-provided market data and API offers.
183
+ * Prepares a `MidnightBundlesV2` sell that borrows from lend-side offers for `accountAddress`.
184
+ *
185
+ * The bundle first withdraws as much of the sender's existing credit as the target and market
186
+ * liquidity allow, then fills the rest from offers.
156
187
  *
157
- * @param params - Borrower, market snapshot, target assets, unit cap, offers, and deadline.
158
- * @param params.accountAddress - Borrower executing the take.
188
+ * @param params - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
189
+ * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
159
190
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
160
- * @param params.loanAssets - Loan assets received by the borrower.
161
- * @param params.maxUnits - Maximum debt units accepted.
191
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
192
+ * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
162
193
  * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
163
- * @param params.deadline - Bundle execution deadline timestamp.
164
- * @returns Lazy authorization requirements and a synchronous transaction builder.
194
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
195
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
196
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
197
+ * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
165
198
  * @throws {ChainIdMismatchError} when client or market data targets another chain.
199
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
200
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
201
+ * @throws {InputExceedsMaxError} when `target.assets`, `target.maxUnits`, `target.units`
202
+ * or `target.minSellerAssets` exceeds `uint256`.
166
203
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
167
- * @throws {NonPositiveInputError} when `loanAssets` or `maxUnits` is non-positive.
168
- * @throws {NegativeInputError} when `deadline` is negative.
204
+ * @throws {NonPositiveInputError} when the target amount, `maxUnits` or `minSellerAssets` is not positive.
205
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
206
+ * @throws {UnboundedMidnightTakeInputError} when `target.units` or
207
+ * `target.maxUnits` is `maxUint256`.
208
+ * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
209
+ * @throws {ExpiredDeadlineError} when `deadline` has expired.
210
+ * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
169
211
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
170
212
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
171
213
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
214
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
215
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
172
216
  * @example
173
217
  * ```ts
174
218
  * const output = midnight.takeBorrow({
175
219
  * accountAddress: borrower,
176
220
  * marketData,
177
- * loanAssets: 1_000_000n,
178
- * maxUnits: 1_100_000n,
221
+ * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
179
222
  * takeableOffers: quote.data.takeableOffers,
180
- * deadline: maxUint256,
223
+ * deadline: Time.timestamp() + 600n,
181
224
  * });
182
225
  * ```
183
226
  */
184
227
  takeBorrow(params: TakeBorrowParams): MidnightActionOutput<MidnightTakeBorrowAction>;
185
228
  /**
186
- * Prepares one bundle that supplies collateral and takes borrow-side offers.
229
+ * Prepares a reduce-only `MidnightBundlesV2` sell that withdraws `accountAddress`'s credit.
187
230
  *
188
- * @param params - Borrower, market snapshot, collateral and loan amounts, unit cap, offers, and deadline.
189
- * @param params.accountAddress - Borrower executing the bundle.
231
+ * The bundle first redeems as much credit as the target and market liquidity allow, then sells
232
+ * the rest to lend-side offers. `reduceOnly` is always set, so it never opens debt. Use `redeem`
233
+ * for a direct redemption without offers.
234
+ *
235
+ * @param params - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
236
+ * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
190
237
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
191
- * @param params.collateralAssets - Collateral assets supplied before borrowing.
192
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
193
- * @param params.loanAssets - Loan assets received by the borrower.
194
- * @param params.maxUnits - Maximum debt units accepted.
238
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
239
+ * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
195
240
  * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
196
241
  * @param params.deadline - Bundle execution deadline timestamp.
197
- * @returns Lazy collateral approval/authorization requirements and a synchronous transaction builder.
242
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
243
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
244
+ * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
198
245
  * @throws {ChainIdMismatchError} when client or market data targets another chain.
246
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
247
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
248
+ * @throws {InputExceedsMaxError} when `target.assets`, `target.maxUnits`, `target.units`
249
+ * or `target.minSellerAssets` exceeds `uint256`.
199
250
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
200
- * @throws {NonPositiveInputError} when collateral, loan assets, or `maxUnits` is non-positive.
201
- * @throws {NegativeInputError} when `deadline` is negative.
202
- * @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
251
+ * @throws {NonPositiveInputError} when the target amount, `maxUnits` or `minSellerAssets` is
252
+ * not positive.
253
+ * @throws {NegativeInputError} when `referralFeePct` is negative.
254
+ * @throws {UnboundedMidnightTakeInputError} when `target.units` or `target.maxUnits` is `maxUint256`.
255
+ * @throws {ExpiredDeadlineError} when `deadline` has expired.
256
+ * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
203
257
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
204
258
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
205
259
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
260
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
261
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
262
+ * @example
263
+ * ```ts
264
+ * const output = midnight.takeWithdraw({
265
+ * accountAddress: lender,
266
+ * marketData,
267
+ * target: { type: "units", units: credit, minSellerAssets: 990_000n },
268
+ * takeableOffers: quote.data.takeableOffers,
269
+ * deadline: Time.timestamp() + 600n,
270
+ * });
271
+ * ```
272
+ */
273
+ takeWithdraw(params: TakeWithdrawParams): MidnightActionOutput<MidnightTakeWithdrawAction>;
274
+ /**
275
+ * Prepares one `MidnightBundlesV2` sell that supplies collateral and borrows from lend-side
276
+ * offers for `accountAddress`.
277
+ *
278
+ * Like `takeBorrow`, the sender's existing credit is withdrawn before offers are taken.
279
+ *
280
+ * @param params - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
281
+ * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
282
+ * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
283
+ * @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
284
+ * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
285
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
286
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
287
+ * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
288
+ * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
289
+ * required for the full pulled amount.
290
+ * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
291
+ * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
292
+ * @param params.deadline - Bounded bundle execution deadline timestamp.
293
+ * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
294
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
295
+ * @returns Lazy collateral approvals and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
296
+ * @throws {ChainIdMismatchError} when client or market data targets another chain.
297
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
298
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
299
+ * @throws {InputExceedsMaxError} when a `collateralSupplies[].assets` amount, `target.assets`,
300
+ * `target.maxUnits`, `target.units` or `target.minSellerAssets` exceeds `uint256`, or
301
+ * `nativeAmount` exceeds the maximum wNative collateral amount this call can pull.
302
+ * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
303
+ * @throws {EmptyMidnightCollateralSuppliesError} when no collateral supply is provided.
304
+ * @throws {UnknownCollateralIndexError} when a collateral index is not configured.
305
+ * @throws {NonPositiveInputError} when a supply amount, the target amount, `maxUnits` or `minSellerAssets` is not positive.
306
+ * @throws {NegativeInputError} when `referralFeePct` or `nativeAmount` is negative.
307
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
308
+ * @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
309
+ * @throws {UnboundedMidnightTakeInputError} when `target.units` or
310
+ * `target.maxUnits` is `maxUint256`.
311
+ * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
312
+ * @throws {ExpiredDeadlineError} when `deadline` has expired.
313
+ * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
314
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
315
+ * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
316
+ * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
317
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
318
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
319
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below a collateral token's pulled assets.
206
320
  * @example
207
321
  * ```ts
208
322
  * const output = midnight.supplyCollateralTakeBorrow({
209
323
  * accountAddress: borrower,
210
324
  * marketData,
211
- * collateralAssets: 2_000_000n,
212
- * loanAssets: 1_000_000n,
213
- * maxUnits: 1_100_000n,
325
+ * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
326
+ * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
214
327
  * takeableOffers: quote.data.takeableOffers,
215
- * deadline: maxUint256,
328
+ * deadline: Time.timestamp() + 600n,
216
329
  * });
217
330
  * ```
218
331
  */
219
332
  supplyCollateralTakeBorrow(params: SupplyCollateralTakeBorrowParams): MidnightActionOutput<MidnightSupplyCollateralTakeBorrowAction>;
333
+ /**
334
+ * Prepares a `MidnightBundlesV2` reduce-only buy that repays `accountAddress`'s debt by taking
335
+ * borrow-side offers, optionally repays the remainder directly, then withdraws collateral.
336
+ *
337
+ * `reduceOnly` is always set, so the buy never opens a lender position.
338
+ *
339
+ * @param params - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
340
+ * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
341
+ * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
342
+ * @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).
343
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
344
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
345
+ * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
346
+ * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
347
+ * required for the full pulled amount.
348
+ * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
349
+ * @param params.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
350
+ * @param params.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
351
+ * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`.
352
+ * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
353
+ * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
354
+ * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
355
+ * @param params.deadline - Bundle execution deadline timestamp.
356
+ * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
357
+ * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
358
+ * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
359
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
360
+ * @throws {ChainIdMismatchError} when client or market data targets another chain.
361
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
362
+ * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
363
+ * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or a
364
+ * withdrawal amount is not positive.
365
+ * @throws {NegativeInputError} when `maxContinuousFee`, `referralFeePct` or `nativeAmount` is negative.
366
+ * @throws {InputExceedsMaxError} when `target.assets` or `target.maxBuyerAssets` is at
367
+ * least `maxUint256`, or a `collateralWithdrawals[].assets` amount, `target.units`,
368
+ * `minUnits`, `maxBuyerAssets` or `maxContinuousFee` exceeds `uint256`, or
369
+ * `nativeAmount` exceeds the maximum wNative amount this call can pull, including zero for a
370
+ * withdraw-only call.
371
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
372
+ * @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
373
+ * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
374
+ * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
375
+ * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
376
+ * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
377
+ * @throws {ExpiredDeadlineError} when `deadline` has expired.
378
+ * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
379
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
380
+ * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
381
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
382
+ * @example
383
+ * ```ts
384
+ * const output = midnight.takeRepayWithdrawCollateral({
385
+ * accountAddress: borrower,
386
+ * marketData,
387
+ * target: { type: "units", units: 1_000_000n, maxBuyerAssets: 990_000n },
388
+ * takeableOffers: quote.data.takeableOffers,
389
+ * repayEnabled: true,
390
+ * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
391
+ * maxContinuousFee: maxUint256,
392
+ * deadline: Time.timestamp() + 600n,
393
+ * });
394
+ * ```
395
+ */
396
+ takeRepayWithdrawCollateral(params: TakeRepayWithdrawCollateralParams): MidnightActionOutput<MidnightTakeRepayWithdrawCollateralAction>;
220
397
  /**
221
398
  * Prepares a direct collateral supply using a caller-provided market snapshot.
222
399
  *
@@ -232,6 +409,7 @@ export declare class MorphoMidnight {
232
409
  * @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
233
410
  * @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
234
411
  * @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
412
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
235
413
  * @example
236
414
  * ```ts
237
415
  * const output = midnight.supplyCollateral({
@@ -243,30 +421,49 @@ export declare class MorphoMidnight {
243
421
  */
244
422
  supplyCollateral(params: SupplyCollateralParams): MidnightActionOutput<MidnightSupplyCollateralAction>;
245
423
  /**
246
- * Validates lend-side maker offers and prepares their reserve and ratifier requirements.
424
+ * Prepares an atomic lend-offer publication or repost through `MidnightBundlesV2`.
247
425
  *
248
- * Calls the Midnight mempool validation API while preparing the offer tree;
249
- * allowance and ratifier state are read lazily by `getRequirements()`.
426
+ * One transaction cancels `cancellations` under their consumption ceilings, activates the
427
+ * PriceRatifierV1 or RateRatifierV1 root, and publishes its payload. Pass no cancellations
428
+ * for a new publication. Calls the Midnight mempool validation API while preparing the tree.
250
429
  *
251
- * @param params - Maker, raw offers, loan token, reserve amounts, and validation controls.
252
- * @param params.accountAddress - Maker expected on every offer.
253
- * @param params.offers - Raw lend-side offers or groups.
430
+ * @param params - Maker, lend-side offers, loan reserve, cancellations, and deadline.
431
+ * @param params.accountAddress - Maker expected on every offer; must send the transaction.
432
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
433
+ * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
434
+ * @param params.deadline - Bundle execution deadline timestamp.
254
435
  * @param params.validation - Optional Midnight mempool API request controls.
255
436
  * @param params.loanToken - Loan token shared by every offer market.
256
- * @param params.loanAssets - New loan reserve assigned to the submitted groups.
257
- * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
258
- * @returns Prepared group metadata, lazy requirements, and a synchronous mempool transaction builder.
437
+ * @param params.loanAssets - New loan reserve assigned to the published groups.
438
+ * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
439
+ * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
259
440
  * @throws {ChainIdMismatchError} when the client targets another chain.
260
- * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
441
+ * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
442
+ * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
443
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
261
444
  * @throws {NonPositiveInputError} when `loanAssets` is non-positive.
262
- * @throws {NegativeInputError} when `reservedLoanAssets` is negative.
445
+ * @throws {NegativeInputError} when `reservedLoanAssets` or a `maxConsumed` ceiling is negative.
446
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
447
+ * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128` or `deadline` exceeds `uint256`.
448
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
449
+ * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
450
+ * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
451
+ * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
452
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
453
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
454
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
263
455
  * @throws {MidnightOfferSideMismatchError} when an offer is not lend-side.
264
456
  * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
457
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
458
+ * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
459
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `loanAssets + reservedLoanAssets`.
265
460
  * @example
266
461
  * ```ts
267
462
  * const output = await midnight.makeLend({
268
463
  * accountAddress: maker,
269
- * offers: [offer],
464
+ * offers: { type: "rateV1", entries: [{ offer, rate }] },
465
+ * cancellations: [{ group: previousGroup, maxConsumed: 0n }],
466
+ * deadline: maxUint256,
270
467
  * loanToken,
271
468
  * loanAssets: 1_000_000n,
272
469
  * });
@@ -274,51 +471,290 @@ export declare class MorphoMidnight {
274
471
  */
275
472
  makeLend(params: MakeLendParams): Promise<MakeOffersOutput>;
276
473
  /**
277
- * Validates borrow-side maker offers and prepares their ratifier requirements.
474
+ * Prepares an atomic borrow-offer publication or repost through `MidnightBundlesV2`.
278
475
  *
279
- * @param params - Maker, raw borrow-side offers, and optional mempool validation controls.
280
- * @param params.accountAddress - Maker expected on every offer.
281
- * @param params.offers - Raw borrow-side offers or groups.
476
+ * One transaction cancels `cancellations` under their consumption ceilings, activates the
477
+ * PriceRatifierV1 or RateRatifierV1 root, and publishes its payload. Pass no cancellations for
478
+ * a new publication. Calls the Midnight mempool validation API while preparing the tree.
479
+ *
480
+ * @param params - Maker, borrow-side offers, cancellations, and deadline.
481
+ * @param params.accountAddress - Maker expected on every offer; must send the transaction.
482
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
483
+ * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
484
+ * @param params.deadline - Bundle execution deadline timestamp.
282
485
  * @param params.validation - Optional Midnight mempool API request controls.
283
- * @returns Prepared group metadata, lazy ratifier requirements, and a synchronous mempool transaction builder.
284
- * @throws {ChainIdMismatchError} when the client targets another chain.
486
+ * @returns Prepared group metadata, lazy authorization requirements, and a synchronous transaction builder.
487
+ * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
488
+ * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
489
+ * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
490
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
491
+ * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
492
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
493
+ * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128` or `deadline` exceeds `uint256`.
494
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
495
+ * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
285
496
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
497
+ * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
498
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
499
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
500
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
286
501
  * @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
502
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
503
+ * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
287
504
  * @example
288
505
  * ```ts
289
506
  * const output = await midnight.makeBorrow({
290
507
  * accountAddress: maker,
291
- * offers: [offer],
508
+ * offers: { type: "rateV1", entries: [{ offer, rate }] },
509
+ * deadline: maxUint256,
292
510
  * });
293
511
  * ```
294
512
  */
295
513
  makeBorrow(params: MakeOffersParams): Promise<MakeOffersOutput>;
296
514
  /**
297
- * Prepares collateral supply followed by borrow-side maker-offer submission.
515
+ * Prepares lend-side offers for publication.
516
+ */
517
+ private prepareLendOffers;
518
+ /**
519
+ * Prepares an atomic Blue-funded lend-offer publication or repost through `MidnightBundlesV2`.
298
520
  *
299
- * @param params - Maker, market, collateral reserve, raw offers, and validation controls.
300
- * @param params.accountAddress - Maker expected on every offer.
301
- * @param params.offers - Raw borrow-side offers or groups.
521
+ * One transaction cancels `cancellations` under their consumption ceilings, pulls `assetsToPark`
522
+ * from the maker and supplies them to `blueMarket` on Morpho Blue for the maker's
523
+ * `BlueBuyCallback` (created if missing), activates the PriceRatifierV1 or RateRatifierV1 root,
524
+ * and publishes its payload. When an offer is taken, the callback withdraws the bought assets
525
+ * from Blue and pays Midnight, so the maker needs no loan-token approval to Midnight.
526
+ *
527
+ * Every offer must set `callback` to the maker's derived `BlueBuyCallback` and `callbackData`
528
+ * to `abi.encode(blueMarket)`. The contract does not check supply share-price slippage, so
529
+ * `blueMarket` must be protected against supply-share-price inflation; this method rejects
530
+ * Blue markets with no supply shares and parked amounts that would mint zero shares. Calls the
531
+ * Midnight mempool validation API while preparing the tree. Computes the callback's CREATE2 address from the chain's
532
+ * `midnightBlueBuyCallbackFactory`, `accountAddress` and `callbackSalt`, and fetches the Morpho Blue market,
533
+ * accruing interest to the current time before previewing parked shares (markets whose
534
+ * IRM the SDK cannot accrue are previewed on their last-updated state).
535
+ *
536
+ * @param params - Maker, lend-side offers, Blue market, parked assets, cancellations, and deadline.
537
+ * @param params.accountAddress - Maker expected on every offer; must send the transaction.
538
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
539
+ * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
540
+ * @param params.deadline - Bundle execution deadline timestamp.
302
541
  * @param params.validation - Optional Midnight mempool API request controls.
303
- * @param params.market - Market shared by every submitted offer.
304
- * @param params.collateralAssets - Collateral supplied before offer submission.
305
- * @param params.reservedCollateralAssets - Existing collateral reserved by other open groups.
306
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
307
- * @returns Prepared group metadata, lazy supply/ratifier requirements, and a synchronous mempool transaction builder.
542
+ * @param params.blueMarket - Morpho Blue market the parked assets are supplied to.
543
+ * @param params.assetsToPark - Loan assets supplied to `blueMarket` for the maker's callback.
544
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
545
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
546
+ * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
547
+ * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
548
+ * required for the full pulled amount.
549
+ * @param params.callbackSalt - Salt selecting the maker's callback; the same salt reuses the same callback.
550
+ * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
308
551
  * @throws {ChainIdMismatchError} when the client targets another chain.
309
- * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
310
- * @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
311
- * @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
312
- * @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
552
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2`, `midnightBlueBuyCallbackFactory`, `midnight`, `blue` or V1 ratifier deployment.
553
+ * @throws {NonPositiveInputError} when `assetsToPark` is non-positive.
554
+ * @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
555
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
556
+ * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, `deadline` exceeds
557
+ * `uint256`, or `nativeAmount` exceeds `assetsToPark` when `blueMarket.loanToken` is wNative.
558
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
559
+ * @throws {NativeAmountOnNonWNativeAssetError} when `blueMarket.loanToken` is not wNative.
560
+ * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
561
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
562
+ * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
563
+ * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
564
+ * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
565
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
566
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
567
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
568
+ * @throws {MidnightOfferSideMismatchError} when an offer is not lend-side.
569
+ * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
570
+ * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer's loan token differs from `blueMarket`'s.
571
+ * @throws {MidnightOfferCallbackMismatchError} when an offer does not use the maker's derived callback.
572
+ * @throws {MidnightOfferCallbackDataMismatchError} when an offer's callback data is not `abi.encode(blueMarket)`.
573
+ * @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
574
+ * @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price.
575
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
576
+ * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
577
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `assetsToPark`.
578
+ * @example
579
+ * ```ts
580
+ * const callback = getMidnightBlueBuyCallbackAddress({ chainId, owner: maker, salt: callbackSalt });
581
+ * const callbackData = getMidnightBlueBuyCallbackData(blueMarket);
582
+ * const output = await midnight.supplyBlueMakeLend({
583
+ * accountAddress: maker,
584
+ * offers: {
585
+ * type: "rateV1",
586
+ * entries: [{ offer: { ...offer, callback, callbackData }, rate }],
587
+ * },
588
+ * deadline: maxUint256,
589
+ * blueMarket,
590
+ * assetsToPark: 1_000_000n,
591
+ * callbackSalt,
592
+ * });
593
+ * ```
594
+ */
595
+ supplyBlueMakeLend(params: SupplyBlueMakeLendParams): Promise<MakeOffersOutput>;
596
+ /**
597
+ * Prepares borrow-side offers for publication.
598
+ */
599
+ private prepareBorrowOffers;
600
+ /**
601
+ * Publishes reduce-only sell offers for a lend limit exit through MidnightBundlesV2.
602
+ *
603
+ * Shares the borrow-side publication and requirement handling of {@link MorphoMidnight.makeBorrow}.
604
+ * No tokens are pulled during publication and no token approval is required.
605
+ * Execution waits for a taker; publication does not close the position or withdraw collateral.
606
+ * Every offer must already have `buy = false` and `reduceOnly = true`.
607
+ * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
608
+ *
609
+ * @param params - Maker, reduce-only offers, optional cancellations, and deadline.
610
+ * @param params.accountAddress - Maker expected on every offer; must send the transaction.
611
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
612
+ * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
613
+ * @param params.deadline - Bundle execution deadline timestamp.
614
+ * @param params.validation - Optional Midnight mempool API request controls.
615
+ * @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
616
+ * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
617
+ * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
618
+ * @throws {MidnightOfferSideMismatchError} when an offer is not a sell offer (`buy = false`).
619
+ * @throws {MidnightOfferNotReduceOnlyError} when any offer can increase a position.
620
+ * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
621
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
622
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
623
+ * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
624
+ * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
625
+ * @throws {UnknownAddressError} when the chain has no V1 ratifier or `midnightBundlesV2` deployment.
626
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
627
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
628
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
629
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
630
+ * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
631
+ * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
632
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
633
+ * @example
634
+ * ```ts
635
+ * const output = await midnight.makeWithdraw({
636
+ * accountAddress: maker,
637
+ * offers: { type: "priceV1", entries: [{ offer: reduceOnlySellOffer }] },
638
+ * deadline: maxUint256,
639
+ * });
640
+ * const requirements = await output.getRequirements();
641
+ * const tx = output.buildTx();
642
+ * ```
643
+ */
644
+ makeWithdraw(params: MakeOffersParams): Promise<MakeOffersOutput>;
645
+ /**
646
+ * Publishes reduce-only buy offers for a borrow limit exit through MidnightBundlesV2.
647
+ *
648
+ * Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
649
+ * Loan assets are pulled by Midnight when the offers fill, not during publication.
650
+ * The loan reserve uses the same approval sizing as `makeLend`.
651
+ * Execution waits for a taker; publication does not close the position or withdraw collateral.
652
+ * Every offer must already have `buy = true` and `reduceOnly = true`.
653
+ * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
654
+ *
655
+ * @param params - Maker, reduce-only offers, optional cancellations, loan reserve, and deadline.
656
+ * @param params.accountAddress - Maker expected on every offer; must send the transaction.
657
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
658
+ * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
659
+ * @param params.deadline - Bundle execution deadline timestamp.
660
+ * @param params.validation - Optional Midnight mempool API request controls.
661
+ * @param params.loanToken - Loan token shared by every offer market.
662
+ * @param params.loanAssets - New loan reserve assigned to the published groups.
663
+ * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
664
+ * @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
665
+ * @throws {ChainIdMismatchError} when the client targets another chain.
666
+ * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
667
+ * @throws {MidnightOfferSideMismatchError} when an offer is not a buy offer (`buy = true`).
668
+ * @throws {MidnightOfferNotReduceOnlyError} when any offer can increase a position.
669
+ * @throws {NonPositiveInputError} when `loanAssets` or `deadline` is not positive.
670
+ * @throws {NegativeInputError} when `reservedLoanAssets` or a `maxConsumed` ceiling is negative.
671
+ * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
672
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
673
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
674
+ * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
675
+ * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
676
+ * @throws {UnknownAddressError} when the chain has no V1 ratifier or `midnightBundlesV2` deployment.
677
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
678
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
679
+ * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
680
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
681
+ * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
682
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
683
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `loanAssets + reservedLoanAssets`.
684
+ * @example
685
+ * ```ts
686
+ * const output = await midnight.makeRepay({
687
+ * accountAddress: maker,
688
+ * offers: { type: "priceV1", entries: [{ offer: reduceOnlyBuyOffer }] },
689
+ * loanToken,
690
+ * loanAssets: 1_000_000n,
691
+ * deadline: maxUint256,
692
+ * });
693
+ * const requirements = await output.getRequirements();
694
+ * const tx = output.buildTx();
695
+ * ```
696
+ */
697
+ makeRepay(params: MakeLendParams): Promise<MakeOffersOutput>;
698
+ /**
699
+ * Prepares an atomic borrow-offer publication or repost through `MidnightBundlesV2`,
700
+ * requiring collateral before activation.
701
+ *
702
+ * One transaction cancels `cancellations` under their consumption ceilings, pulls and supplies
703
+ * required `collateral`, activates the PriceRatifierV1 or RateRatifierV1 root, and publishes its
704
+ * payload. Pass no cancellations for a new publication. Calls the Midnight mempool validation
705
+ * API while preparing the tree.
706
+ *
707
+ * @param params - Maker, borrow-side offers, required collateral, cancellations, and deadline.
708
+ * @param params.accountAddress - Maker expected on every offer; must send the transaction.
709
+ * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
710
+ * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
711
+ * @param params.deadline - Bundle execution deadline timestamp.
712
+ * @param params.validation - Optional Midnight mempool API request controls.
713
+ * @param params.collateral - Required market and collateral supplies; every offer must target that market.
714
+ * @param params.collateral.market - Midnight market receiving the collateral; every offer must target it.
715
+ * @param params.collateral.supplies - Collateral index and assets per supply; must not be empty.
716
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
717
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
718
+ * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
719
+ * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
720
+ * required for the full pulled amount.
721
+ * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
722
+ * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
723
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
724
+ * @throws {UnknownCollateralIndexError} when a collateral index is not configured.
725
+ * @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
726
+ * @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
727
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
728
+ * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, `deadline` or a
729
+ * collateral supply amount exceeds `uint256`, or `nativeAmount` exceeds the maximum wNative
730
+ * collateral amount this call can pull.
731
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
732
+ * @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
733
+ * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
734
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
735
+ * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
736
+ * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
737
+ * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
738
+ * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
739
+ * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
740
+ * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
313
741
  * @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
314
- * @throws {MarketIdMismatchError} when an offer targets another market.
742
+ * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
743
+ * @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
744
+ * @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
745
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
746
+ * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
747
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below a collateral token's pulled assets.
315
748
  * @example
316
749
  * ```ts
317
750
  * const output = await midnight.supplyCollateralMakeBorrow({
318
751
  * accountAddress: maker,
319
- * market: marketData.params,
320
- * collateralAssets: 2_000_000n,
321
- * offers: [offer],
752
+ * offers: { type: "rateV1", entries: [{ offer, rate }] },
753
+ * collateral: {
754
+ * market: marketData.params,
755
+ * supplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
756
+ * },
757
+ * deadline: maxUint256,
322
758
  * });
323
759
  * ```
324
760
  */
@@ -350,53 +786,94 @@ export declare class MorphoMidnight {
350
786
  */
351
787
  redeem(params: RedeemParams): MidnightActionOutput<MidnightRedeemAction>;
352
788
  /**
353
- * Prepares a bundle that repays debt, withdraws collateral, or performs both.
789
+ * Prepares a direct `MidnightBundlesV2` repayment, collateral withdrawal, or both, for `accountAddress`.
354
790
  *
355
- * @param params - Account, market snapshot, repay and withdrawal amounts, collateral index, and deadline.
356
- * @param params.accountAddress - Position owner whose debt or collateral is updated.
791
+ * @param params - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
792
+ * @param params.accountAddress - Position owner and transaction sender.
357
793
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
358
- * @param params.repayAssets - Loan assets repaid; may be zero for withdrawal-only flows.
359
- * @param params.withdrawCollateralAssets - Collateral assets withdrawn; may be zero for repay-only flows.
360
- * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
794
+ * @param params.repay - `{ type: "assets", assets }` (`0n` to only withdraw) or `{ type: "full", maxBuyerAssets }`; a loan-token approval to `MidnightBundlesV2` is required when the allowance is below the pulled amount — unlimited (`maxUint256`) by default, or `approvalAmount` when passed to `getRequirements()` — and any unused part is refunded.
795
+ * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
796
+ * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
797
+ * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
798
+ * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
799
+ * required for the full pulled amount.
800
+ * @param params.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
801
+ * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`.
361
802
  * @param params.deadline - Bundle execution deadline timestamp.
362
803
  * @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
363
804
  * @throws {ChainIdMismatchError} when client or market data targets another chain.
364
805
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
365
- * @throws {NegativeInputError} when an amount, index, or deadline is negative.
366
- * @throws {NonPositiveInputError} when both repay and withdrawal amounts are zero.
367
- * @throws {UnknownCollateralIndexError} when a positive withdrawal selects an unconfigured collateral.
806
+ * @throws {NegativeInputError} when `repay.assets` or `nativeAmount` is negative.
807
+ * @throws {NonPositiveInputError} when nothing is repaid or withdrawn, a withdrawal amount is zero, `repay.maxBuyerAssets` is zero, or `deadline` is not positive.
808
+ * @throws {InputExceedsMaxError} when `repay.assets` or `repay.maxBuyerAssets` is at least
809
+ * `maxUint256`, a withdrawal amount or `deadline` exceeds uint256, or `nativeAmount` exceeds
810
+ * the maximum wNative amount this call can pull, including zero for a withdraw-only call.
811
+ * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
812
+ * @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
813
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
814
+ * @throws {UnknownCollateralIndexError} when a withdrawal selects an unconfigured collateral.
815
+ * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
368
816
  * @example
369
817
  * ```ts
818
+ * // Close the position: repay all debt, withdraw all collateral.
370
819
  * const output = midnight.repayWithdrawCollateral({
371
820
  * accountAddress: borrower,
372
821
  * marketData,
373
- * repayAssets: 1_000_000n,
374
- * withdrawCollateralAssets: 2_000_000n,
822
+ * repay: { type: "full", maxBuyerAssets: 1_010_000n },
823
+ * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
375
824
  * deadline: maxUint256,
376
825
  * });
377
826
  * ```
378
827
  */
379
828
  repayWithdrawCollateral(params: RepayWithdrawCollateralParams): MidnightActionOutput<MidnightRepayWithdrawCollateralAction>;
380
829
  /**
381
- * Prepares full cancellation of a maker offer group.
830
+ * Prepares guarded cancellation of several maker offer groups through `MidnightBundlesV2`.
382
831
  *
383
- * @param params - Group id and maker account whose consumption is updated.
384
- * @param params.group - Offer group id to fully consume.
385
- * @param params.accountAddress - Maker whose group consumption is updated.
386
- * @returns No requirements and a synchronous cancellation transaction builder.
832
+ * The transaction reverts as a whole when any group's consumption exceeds its
833
+ * `maxConsumed` ceiling, so fills landing before execution never leave a partial cancel.
834
+ *
835
+ * @param params - Maker account, groups with consumption ceilings, and deadline.
836
+ * @param params.accountAddress - Maker that must send the transaction. It is used only to check
837
+ * the maker's Midnight authorization of `MidnightBundlesV2`; the bundle cancels the groups of
838
+ * `msg.sender`. A transaction sent from another account that has also authorized
839
+ * `MidnightBundlesV2` does not revert: it cancels that account's groups and leaves the maker's
840
+ * offers fillable.
841
+ * @param params.cancellations - Offer groups and the largest consumption accepted for each.
842
+ * To cancel unconditionally, set `maxConsumed` to `maxUint128`; the contract treats
843
+ * `type(uint128).max` as no limit.
844
+ * @param params.deadline - Bundle execution deadline timestamp.
845
+ * @returns Lazy Midnight authorization requirement for `MidnightBundlesV2` and a synchronous transaction builder.
387
846
  * @throws {ChainIdMismatchError} when the client targets another chain.
847
+ * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
848
+ * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
849
+ * @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
850
+ * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
851
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
852
+ * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
853
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
388
854
  * @example
389
855
  * ```ts
390
- * const output = midnight.cancelOffer({
391
- * group,
856
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
857
+ * import { createPublicClient, http, maxUint256, type Address, type Hex } from "viem";
858
+ * import { base } from "viem/chains";
859
+ *
860
+ * declare const maker: Address;
861
+ * declare const group: Hex;
862
+ * const client = createPublicClient({ chain: base, transport: http() }).extend(
863
+ * morphoViemExtension(),
864
+ * );
865
+ * const midnight = client.morpho.midnight(base.id);
866
+ * const output = midnight.cancelOffers({
392
867
  * accountAddress: maker,
868
+ * cancellations: [{ group, maxConsumed: 0n }],
869
+ * deadline: maxUint256,
393
870
  * });
394
871
  * ```
395
872
  */
396
- cancelOffer(params: {
397
- readonly group: Hex;
873
+ cancelOffers(params: {
398
874
  readonly accountAddress: Address;
399
- }): MidnightActionOutput<MidnightCancelOfferAction>;
400
- private getRatifierRequirements;
401
- private buildSubmitOffersTx;
875
+ readonly cancellations: readonly MidnightGroupCancellation[];
876
+ readonly deadline: bigint;
877
+ }): MidnightActionOutput<MidnightCancelAndMakeAction>;
878
+ private getBundlesV2AuthorizationRequirements;
402
879
  }