@morpho-org/morpho-sdk 7.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/MIGRATION-v6-to-v7.md +6 -0
  2. package/MIGRATION-v7-to-v8.md +290 -0
  3. package/README.md +11 -6
  4. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
  6. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +17 -71
  7. package/lib/cjs/actions/midnight/cancelAndMake.js +41 -29
  8. package/lib/cjs/actions/midnight/redeem.d.ts +8 -1
  9. package/lib/cjs/actions/midnight/redeem.js +18 -1
  10. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
  11. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +24 -2
  12. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
  13. package/lib/cjs/actions/midnight/supplyCollateral.js +3 -0
  14. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +49 -14
  16. package/lib/cjs/actions/midnight/takeBorrow.d.ts +18 -5
  17. package/lib/cjs/actions/midnight/takeBorrow.js +44 -12
  18. package/lib/cjs/actions/midnight/takeLend.d.ts +10 -5
  19. package/lib/cjs/actions/midnight/takeLend.js +27 -9
  20. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +51 -27
  22. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +14 -5
  23. package/lib/cjs/actions/midnight/takeWithdraw.js +40 -9
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
  25. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -6
  26. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
  27. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +17 -6
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
  32. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
  33. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
  35. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
  37. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
  38. package/lib/cjs/actions/requirements/validateClientChainId.d.ts +26 -0
  39. package/lib/cjs/actions/requirements/validateClientChainId.js +34 -0
  40. package/lib/cjs/blue/errors.d.ts +1 -1
  41. package/lib/cjs/blue/errors.js +3 -1
  42. package/lib/cjs/blue/types.d.ts +1 -1
  43. package/lib/cjs/blue/utils.d.ts +1 -1
  44. package/lib/cjs/blue/utils.js +5 -1
  45. package/lib/cjs/entities/blue/blue.d.ts +109 -27
  46. package/lib/cjs/entities/blue/blue.js +103 -28
  47. package/lib/cjs/entities/index.d.ts +1 -1
  48. package/lib/cjs/entities/midnight/deadline.d.ts +15 -0
  49. package/lib/cjs/entities/midnight/deadline.js +24 -0
  50. package/lib/cjs/entities/midnight/midnight.d.ts +432 -74
  51. package/lib/cjs/entities/midnight/midnight.js +869 -188
  52. package/lib/cjs/entities/midnight/publication.d.ts +134 -0
  53. package/lib/cjs/entities/midnight/publication.js +404 -0
  54. package/lib/cjs/entities/midnight/types.d.ts +26 -5
  55. package/lib/cjs/entities/requirements/assertContractCode.d.ts +49 -0
  56. package/lib/cjs/entities/requirements/assertContractCode.js +79 -0
  57. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
  58. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +45 -18
  59. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
  60. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +5 -2
  61. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
  62. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  63. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +63 -11
  64. package/lib/cjs/entities/vaultV1/vaultV1.js +83 -49
  65. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +54 -12
  66. package/lib/cjs/entities/vaultV2/vaultV2.js +86 -55
  67. package/lib/cjs/errors.d.ts +1 -1
  68. package/lib/cjs/errors.js +4 -2
  69. package/lib/cjs/helpers/constant.d.ts +5 -0
  70. package/lib/cjs/helpers/constant.js +6 -1
  71. package/lib/cjs/helpers/index.d.ts +1 -1
  72. package/lib/cjs/helpers/index.js +2 -1
  73. package/lib/cjs/helpers/validate.d.ts +163 -8
  74. package/lib/cjs/helpers/validate.js +179 -8
  75. package/lib/cjs/helpers/validateMidnightBounds.d.ts +47 -0
  76. package/lib/cjs/helpers/validateMidnightBounds.js +79 -0
  77. package/lib/cjs/helpers/validateMidnightPublication.d.ts +12 -0
  78. package/lib/cjs/helpers/validateMidnightPublication.js +144 -0
  79. package/lib/cjs/helpers/validateMidnightReceiver.d.ts +29 -0
  80. package/lib/cjs/helpers/validateMidnightReceiver.js +84 -0
  81. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
  82. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +231 -0
  83. package/lib/cjs/index.d.ts +1 -0
  84. package/lib/cjs/index.js +3 -0
  85. package/lib/cjs/types/action.d.ts +102 -1
  86. package/lib/cjs/types/action.js +102 -1
  87. package/lib/cjs/types/error.d.ts +197 -4
  88. package/lib/cjs/types/error.js +265 -5
  89. package/lib/cjs/types/index.d.ts +1 -0
  90. package/lib/cjs/types/index.js +1 -0
  91. package/lib/cjs/types/midnightCancelAndMake.d.ts +70 -0
  92. package/lib/cjs/types/midnightCancelAndMake.js +2 -0
  93. package/lib/cjs/types/midnightPublicationError.d.ts +332 -0
  94. package/lib/cjs/types/midnightPublicationError.js +376 -0
  95. package/lib/cjs/types.d.ts +1 -1
  96. package/lib/cjs/utils.d.ts +2 -1
  97. package/lib/cjs/utils.js +8 -2
  98. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
  99. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
  100. package/lib/esm/actions/midnight/cancelAndMake.d.ts +17 -71
  101. package/lib/esm/actions/midnight/cancelAndMake.js +42 -30
  102. package/lib/esm/actions/midnight/redeem.d.ts +8 -1
  103. package/lib/esm/actions/midnight/redeem.js +18 -1
  104. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
  105. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +24 -2
  106. package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
  107. package/lib/esm/actions/midnight/supplyCollateral.js +3 -0
  108. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
  109. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +52 -17
  110. package/lib/esm/actions/midnight/takeBorrow.d.ts +18 -5
  111. package/lib/esm/actions/midnight/takeBorrow.js +47 -15
  112. package/lib/esm/actions/midnight/takeLend.d.ts +10 -5
  113. package/lib/esm/actions/midnight/takeLend.js +27 -9
  114. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
  115. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +52 -28
  116. package/lib/esm/actions/midnight/takeWithdraw.d.ts +14 -5
  117. package/lib/esm/actions/midnight/takeWithdraw.js +41 -10
  118. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
  119. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +13 -8
  120. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
  121. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
  122. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
  123. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +17 -6
  124. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
  125. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
  126. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
  127. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
  128. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
  129. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
  130. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
  131. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
  132. package/lib/esm/actions/requirements/validateClientChainId.d.ts +26 -0
  133. package/lib/esm/actions/requirements/validateClientChainId.js +30 -0
  134. package/lib/esm/blue/errors.d.ts +1 -1
  135. package/lib/esm/blue/errors.js +1 -1
  136. package/lib/esm/blue/types.d.ts +1 -1
  137. package/lib/esm/blue/utils.d.ts +1 -1
  138. package/lib/esm/blue/utils.js +1 -1
  139. package/lib/esm/entities/blue/blue.d.ts +109 -27
  140. package/lib/esm/entities/blue/blue.js +104 -29
  141. package/lib/esm/entities/index.d.ts +1 -1
  142. package/lib/esm/entities/midnight/deadline.d.ts +15 -0
  143. package/lib/esm/entities/midnight/deadline.js +20 -0
  144. package/lib/esm/entities/midnight/midnight.d.ts +432 -74
  145. package/lib/esm/entities/midnight/midnight.js +870 -189
  146. package/lib/esm/entities/midnight/publication.d.ts +134 -0
  147. package/lib/esm/entities/midnight/publication.js +397 -0
  148. package/lib/esm/entities/midnight/types.d.ts +26 -5
  149. package/lib/esm/entities/requirements/assertContractCode.d.ts +49 -0
  150. package/lib/esm/entities/requirements/assertContractCode.js +74 -0
  151. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
  152. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +47 -20
  153. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
  154. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +5 -2
  155. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
  156. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  157. package/lib/esm/entities/vaultV1/vaultV1.d.ts +63 -11
  158. package/lib/esm/entities/vaultV1/vaultV1.js +85 -51
  159. package/lib/esm/entities/vaultV2/vaultV2.d.ts +54 -12
  160. package/lib/esm/entities/vaultV2/vaultV2.js +88 -57
  161. package/lib/esm/errors.d.ts +1 -1
  162. package/lib/esm/errors.js +1 -1
  163. package/lib/esm/helpers/constant.d.ts +5 -0
  164. package/lib/esm/helpers/constant.js +5 -0
  165. package/lib/esm/helpers/index.d.ts +1 -1
  166. package/lib/esm/helpers/index.js +1 -1
  167. package/lib/esm/helpers/validate.d.ts +163 -8
  168. package/lib/esm/helpers/validate.js +177 -7
  169. package/lib/esm/helpers/validateMidnightBounds.d.ts +47 -0
  170. package/lib/esm/helpers/validateMidnightBounds.js +72 -0
  171. package/lib/esm/helpers/validateMidnightPublication.d.ts +12 -0
  172. package/lib/esm/helpers/validateMidnightPublication.js +139 -0
  173. package/lib/esm/helpers/validateMidnightReceiver.d.ts +29 -0
  174. package/lib/esm/helpers/validateMidnightReceiver.js +80 -0
  175. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
  176. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +226 -0
  177. package/lib/esm/index.d.ts +1 -0
  178. package/lib/esm/index.js +1 -0
  179. package/lib/esm/types/action.d.ts +102 -1
  180. package/lib/esm/types/action.js +102 -1
  181. package/lib/esm/types/error.d.ts +197 -4
  182. package/lib/esm/types/error.js +253 -2
  183. package/lib/esm/types/index.d.ts +1 -0
  184. package/lib/esm/types/index.js +1 -0
  185. package/lib/esm/types/midnightCancelAndMake.d.ts +70 -0
  186. package/lib/esm/types/midnightCancelAndMake.js +1 -0
  187. package/lib/esm/types/midnightPublicationError.d.ts +332 -0
  188. package/lib/esm/types/midnightPublicationError.js +359 -0
  189. package/lib/esm/types.d.ts +1 -1
  190. package/lib/esm/utils.d.ts +2 -1
  191. package/lib/esm/utils.js +2 -1
  192. package/package.json +10 -10
@@ -66,7 +66,8 @@ export declare class MorphoMidnight {
66
66
  * @param marketId - Market id to fetch.
67
67
  * @param parameters - Optional block, account, and state-override parameters forwarded to every read.
68
68
  * @returns The market parameters and current onchain market state.
69
- * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
69
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`, another chain than this entity's.
70
+ * @throws {viem.BaseError} when the `eth_chainId` request or a state read fails.
70
71
  * @example
71
72
  * ```ts
72
73
  * const midnight = client.morpho.midnight(8453);
@@ -87,7 +88,8 @@ export declare class MorphoMidnight {
87
88
  * @param params.accountAddress - Position owner address.
88
89
  * @param params.parameters - Optional block, account, and state-override parameters forwarded to every read.
89
90
  * @returns The account's position paired with the fetched market.
90
- * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
91
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`, another chain than this entity's.
92
+ * @throws {viem.BaseError} when the `eth_chainId` request or a state read fails.
91
93
  * @example
92
94
  * ```ts
93
95
  * const positionData = await midnight.getPositionData({
@@ -99,16 +101,21 @@ export declare class MorphoMidnight {
99
101
  */
100
102
  getPositionData(params: GetPositionDataParams): Promise<AccrualPosition>;
101
103
  /**
102
- * Builds and validates a maker offer tree against the Midnight mempool API.
104
+ * Checks the RPC chain and reads Midnight state at one pinned block, then rejects unfillable offers
105
+ * before calling the mempool API unless `validation: false` skips that call. Reads market state,
106
+ * group consumption, maker credit and debt,
107
+ * plus the default continuous fee, LLTV and liquidation-cursor enablement, and oracle code for
108
+ * uncreated markets.
103
109
  *
104
110
  * @param params - Maker account, PriceRatifierV1 or RateRatifierV1 tree input, and optional API validation controls.
105
111
  * @param params.accountAddress - Maker expected on every offer.
106
112
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
107
- * @param params.validation - Optional Midnight mempool API request controls.
113
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
108
114
  * @returns Prepared tree, groups, ratifier, and encoded payload used by maker flows.
109
- * @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
115
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`, another chain than this entity's.
110
116
  * @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.
117
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
118
+ * (not thrown when `validation` is `false`).
112
119
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
113
120
  * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
114
121
  * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
@@ -116,6 +123,20 @@ export declare class MorphoMidnight {
116
123
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
117
124
  * @throws {UnknownAddressError} when the chain has no deployment for the tree's V1 ratifier.
118
125
  * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
126
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
127
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
128
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
129
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
130
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
131
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
132
+ * @throws {MidnightOfferZeroPriceSellError} when a sell offer has a zero tick.
133
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
134
+ * @throws {MidnightOfferNoDebtError} when a reduce-only buy is submitted without maker debt.
135
+ * @throws {MidnightOfferNoCreditError} when a reduce-only sell is submitted without maker credit.
136
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the offer's expiry.
137
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
138
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
139
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
119
140
  * @example
120
141
  * ```ts
121
142
  * const offersData = await midnight.getOffersData({
@@ -128,6 +149,9 @@ export declare class MorphoMidnight {
128
149
  /**
129
150
  * Prepares a `MidnightBundlesV2` buy that lends into borrow-side offers for `accountAddress`.
130
151
  *
152
+ * On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
153
+ * above one are dropped from the transaction because one of them would revert the whole bundle.
154
+ *
131
155
  * @param params - Lender, market snapshot, buy target, offers, fee cap, deadline, and optional referral fee.
132
156
  * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
133
157
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
@@ -145,15 +169,20 @@ export declare class MorphoMidnight {
145
169
  * @param params.referralFeePct - Optional WAD-scaled referral fee paid out of the pulled assets.
146
170
  * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
147
171
  * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
148
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
172
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
173
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
174
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
175
+ * RPC read fails.
149
176
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
150
177
  * @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.
178
+ * @throws {InputExceedsMaxError} when a target amount or offer cap exceeds `uint128`, when
179
+ * `target.maxBuyerAssets` exceeds `uint128` (an SDK cap: the bundle accepts `uint256`, but a
180
+ * higher ceiling gives no slippage protection), when `maxContinuousFee` exceeds `uint256`, or
181
+ * when `nativeAmount` exceeds the maximum wNative amount this call can pull.
154
182
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
155
183
  * @throws {NonPositiveInputError} when the target amount, `minUnits` or `maxBuyerAssets` is not positive.
156
- * @throws {NegativeInputError} when `maxContinuousFee`, `referralFeePct` or `nativeAmount` is negative.
184
+ * @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
185
+ * `referralFeePct` or `nativeAmount` is negative.
157
186
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
158
187
  * @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
159
188
  * @throws {UnboundedMidnightTakeInputError} when `target.units` or
@@ -164,7 +193,17 @@ export declare class MorphoMidnight {
164
193
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
165
194
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
166
195
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
196
+ * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
167
197
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
198
+ * @throws {MidnightContinuousFeeAboveMaxError} when `maxContinuousFee` is below the market's
199
+ * current continuous fee.
200
+ * @throws {MidnightTakeableOffersNotFillableError} when every takeable offer is expired, not yet
201
+ * started, self-made, capped below the market fee or otherwise dead.
202
+ * @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
203
+ * its bounds cannot hold at any fill, or a buy assets target's `minUnits` exceeds the live
204
+ * offers plus the fallback.
205
+ * @throws {MidnightContractReceiverError} when `referralFeeRecipient` is a Midnight protocol
206
+ * contract or a market token contract with a positive referral fee.
168
207
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
169
208
  * @example
170
209
  * ```ts
@@ -185,39 +224,85 @@ export declare class MorphoMidnight {
185
224
  * The bundle first withdraws as much of the sender's existing credit as the target and market
186
225
  * liquidity allow, then fills the rest from offers.
187
226
  *
227
+ * Buy offers whose tick is out of range, whose price is zero, or whose price stays below the
228
+ * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
229
+ * revert the whole bundle.
230
+ *
188
231
  * @param params - Borrower, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
189
232
  * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
190
233
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
234
+ * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
235
+ * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
236
+ * does not see transactions mined or prices moved since, so two transactions built from one
237
+ * snapshot can together end inside the buffer. Midnight still rejects any position above
238
+ * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
239
+ * @param params.collateralPrices - Values from `price()` on each
240
+ * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
241
+ * scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
242
+ * index, because debt after a borrow is always positive.
191
243
  * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
192
244
  * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
245
+ * Midnight protocol and market token contracts are rejected.
193
246
  * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
194
247
  * @param params.deadline - Bounded bundle execution deadline timestamp.
195
248
  * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
196
249
  * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
197
250
  * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
198
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
251
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
252
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
253
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
254
+ * RPC read fails.
199
255
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
200
256
  * @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`.
257
+ * @throws {InputExceedsMaxError} when a target amount or offer cap exceeds `uint128`, or when
258
+ * `target.maxUnits` exceeds `uint128` (an SDK cap: the bundle accepts `uint256`, but a higher
259
+ * ceiling gives no slippage protection).
203
260
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
204
261
  * @throws {NonPositiveInputError} when the target amount, `maxUnits` or `minSellerAssets` is not positive.
205
- * @throws {NegativeInputError} when `referralFeePct` is negative.
262
+ * @throws {NegativeInputError} when a takeable offer cap or `referralFeePct` is negative.
206
263
  * @throws {UnboundedMidnightTakeInputError} when `target.units` or
207
264
  * `target.maxUnits` is `maxUint256`.
208
265
  * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
266
+ * @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
267
+ * market token contract, or when `referralFeeRecipient` is either with a positive referral fee.
209
268
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
210
269
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
211
270
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
212
271
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
213
272
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
273
+ * @throws {AccrualPositionUserMismatchError} when `positionData.user` differs from `accountAddress`.
274
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketData.id`.
275
+ * @throws {UnknownCollateralIndexError} when held collateral uses an unconfigured index.
276
+ * @throws {MissingMarketPriceError} when a held collateral index has no supplied price.
277
+ * @throws {BorrowExceedsSafeLtvError} when the post-borrow debt exceeds buffered collateral capacity.
214
278
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
279
+ * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
215
280
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
281
+ * @throws {MidnightTakeableOffersNotFillableError} when every takeable offer is expired, not yet
282
+ * started, self-made, capped below the market fee or otherwise dead, and no credit withdrawal can fill instead,
283
+ * or when every offer is dropped for an out-of-range tick, a zero price, or a price below the
284
+ * settlement fee until `deadline` (at or below it on an assets target), even with a credit
285
+ * withdrawal.
286
+ * @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
287
+ * its bounds cannot hold at any fill.
216
288
  * @example
217
289
  * ```ts
290
+ * import { blueOracleAbi } from "@morpho-org/morpho-sdk/abis";
291
+ *
292
+ * const collateralPrices = await Promise.all(
293
+ * marketData.params.collateralParams.map(({ oracle }) =>
294
+ * client.readContract({
295
+ * address: oracle,
296
+ * abi: blueOracleAbi,
297
+ * functionName: "price",
298
+ * }),
299
+ * ),
300
+ * );
218
301
  * const output = midnight.takeBorrow({
219
302
  * accountAddress: borrower,
220
303
  * marketData,
304
+ * positionData,
305
+ * collateralPrices,
221
306
  * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
222
307
  * takeableOffers: quote.data.takeableOffers,
223
308
  * deadline: Time.timestamp() + 600n,
@@ -232,33 +317,53 @@ export declare class MorphoMidnight {
232
317
  * the rest to lend-side offers. `reduceOnly` is always set, so it never opens debt. Use `redeem`
233
318
  * for a direct redemption without offers.
234
319
  *
320
+ * Buy offers whose tick is out of range, whose price is zero, or whose price stays below the
321
+ * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
322
+ * revert the whole bundle.
323
+ *
235
324
  * @param params - Lender, market snapshot, sell target, offers, deadline, receiver, and optional referral fee.
236
325
  * @param params.accountAddress - Lender; must send the transaction, since V2 acts for `msg.sender`.
237
326
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
238
327
  * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
239
328
  * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
329
+ * Midnight protocol and market token contracts are rejected.
240
330
  * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
241
331
  * @param params.deadline - Bundle execution deadline timestamp.
242
332
  * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
243
333
  * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
244
334
  * @returns Lazy `MidnightBundlesV2` authorization requirement and a synchronous transaction builder.
245
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
335
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
336
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
337
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
338
+ * RPC read fails.
246
339
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
247
340
  * @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`.
341
+ * @throws {InputExceedsMaxError} when a target amount or offer cap exceeds `uint128`, or when
342
+ * `target.maxUnits` exceeds `uint128` (an SDK cap: the bundle accepts `uint256`, but a higher
343
+ * ceiling gives no slippage protection).
250
344
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
251
345
  * @throws {NonPositiveInputError} when the target amount, `maxUnits` or `minSellerAssets` is
252
346
  * not positive.
253
- * @throws {NegativeInputError} when `referralFeePct` is negative.
347
+ * @throws {NegativeInputError} when a takeable offer cap or `referralFeePct` is negative.
254
348
  * @throws {UnboundedMidnightTakeInputError} when `target.units` or `target.maxUnits` is `maxUint256`.
349
+ * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
350
+ * @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
351
+ * market token contract, or when `referralFeeRecipient` is either with a positive referral fee.
255
352
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
256
353
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
257
354
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
258
355
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
259
356
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
260
357
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
358
+ * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
261
359
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
360
+ * @throws {MidnightTakeableOffersNotFillableError} when every takeable offer is expired, not yet
361
+ * started, self-made, capped below the market fee or otherwise dead, and no credit withdrawal can fill instead,
362
+ * or when every offer is dropped for an out-of-range tick, a zero price, or a price below the
363
+ * settlement fee until `deadline` (at or below it on an assets target), even with a credit
364
+ * withdrawal.
365
+ * @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
366
+ * its bounds cannot hold at any fill.
262
367
  * @example
263
368
  * ```ts
264
369
  * const output = midnight.takeWithdraw({
@@ -277,9 +382,22 @@ export declare class MorphoMidnight {
277
382
  *
278
383
  * Like `takeBorrow`, the sender's existing credit is withdrawn before offers are taken.
279
384
  *
385
+ * Buy offers whose tick is out of range, whose price is zero, or whose price stays below the
386
+ * settlement fee until `deadline` (at or below it on an assets target) are dropped from the transaction because one of them would
387
+ * revert the whole bundle.
388
+ *
280
389
  * @param params - Borrower, market snapshot, collateral supplies, sell target, offers, deadline, receiver, and optional referral fee.
281
390
  * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
282
391
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
392
+ * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
393
+ * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
394
+ * does not see transactions mined or prices moved since, so two transactions built from one
395
+ * snapshot can together end inside the buffer. Midnight still rejects any position above
396
+ * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
397
+ * @param params.collateralPrices - Values from `price()` on each
398
+ * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
399
+ * scaled by `ORACLE_PRICE_SCALE`. A price is required for every held or supplied collateral
400
+ * index, because debt after a borrow is always positive.
283
401
  * @param params.collateralSupplies - Collateral index and assets per supply; must not be empty.
284
402
  * @param params.target - `{ type: "assets", assets, maxUnits }` or `{ type: "units", units, minSellerAssets }`.
285
403
  * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
@@ -288,40 +406,62 @@ export declare class MorphoMidnight {
288
406
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
289
407
  * required for the full pulled amount.
290
408
  * @param params.receiver - Optional loan-asset recipient; defaults to `accountAddress`.
409
+ * Midnight protocol and market token contracts are rejected.
291
410
  * @param params.takeableOffers - Lend-side offers returned by the Midnight API.
292
411
  * @param params.deadline - Bounded bundle execution deadline timestamp.
293
412
  * @param params.referralFeePct - Optional WAD-scaled referral fee taken from the received assets.
294
413
  * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
295
414
  * @returns Lazy collateral approvals and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
296
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
415
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
416
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
417
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
418
+ * RPC read fails.
297
419
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
298
420
  * @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
421
+ * @throws {InputExceedsMaxError} when a collateral supply amount, per-index sum, target amount,
422
+ * or offer cap exceeds `uint128`, or when `target.maxUnits` exceeds `uint128` (an SDK cap: the
423
+ * bundle accepts `uint256`, but a higher ceiling gives no slippage protection), or when
301
424
  * `nativeAmount` exceeds the maximum wNative collateral amount this call can pull.
302
425
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
303
426
  * @throws {EmptyMidnightCollateralSuppliesError} when no collateral supply is provided.
304
427
  * @throws {UnknownCollateralIndexError} when a collateral index is not configured.
428
+ * @throws {AccrualPositionUserMismatchError} when `positionData.user` differs from `accountAddress`.
429
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketData.id`.
430
+ * @throws {MissingMarketPriceError} when a held collateral index has no supplied price.
431
+ * @throws {BorrowExceedsSafeLtvError} when the post-borrow debt exceeds buffered collateral capacity.
305
432
  * @throws {NonPositiveInputError} when a supply amount, the target amount, `maxUnits` or `minSellerAssets` is not positive.
306
- * @throws {NegativeInputError} when `referralFeePct` or `nativeAmount` is negative.
433
+ * @throws {NegativeInputError} when a takeable offer cap, `referralFeePct` or `nativeAmount`
434
+ * is negative.
307
435
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
308
436
  * @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
309
437
  * @throws {UnboundedMidnightTakeInputError} when `target.units` or
310
438
  * `target.maxUnits` is `maxUint256`.
311
439
  * @throws {MidnightZeroReceiverError} when `receiver` is the zero address.
440
+ * @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
441
+ * market token contract, or when `referralFeeRecipient` is either with a positive referral fee.
312
442
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
313
443
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
314
444
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
315
445
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
316
446
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
317
447
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
448
+ * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
318
449
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
450
+ * @throws {MidnightTakeableOffersNotFillableError} when every takeable offer is expired, not yet
451
+ * started, self-made, capped below the market fee or otherwise dead, and no credit withdrawal can fill instead,
452
+ * or when every offer is dropped for an out-of-range tick, a zero price, or a price below the
453
+ * settlement fee until `deadline` (at or below it on an assets target), even with a credit
454
+ * withdrawal.
455
+ * @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
456
+ * its bounds cannot hold at any fill.
319
457
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below a collateral token's pulled assets.
320
458
  * @example
321
459
  * ```ts
322
460
  * const output = midnight.supplyCollateralTakeBorrow({
323
461
  * accountAddress: borrower,
324
462
  * marketData,
463
+ * positionData,
464
+ * collateralPrices,
325
465
  * collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
326
466
  * target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
327
467
  * takeableOffers: quote.data.takeableOffers,
@@ -336,9 +476,22 @@ export declare class MorphoMidnight {
336
476
  *
337
477
  * `reduceOnly` is always set, so the buy never opens a lender position.
338
478
  *
479
+ * On an assets target, sell offers whose tick is out of range or whose buyer price is zero or
480
+ * above one are dropped from the transaction because one of them would revert the whole bundle.
481
+ *
339
482
  * @param params - Borrower, market snapshot, buy target, offers, repay fallback, withdrawals, fee cap, deadline and optional referral fee.
340
483
  * @param params.accountAddress - Borrower; must send the transaction, since V2 acts for `msg.sender`.
341
484
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
485
+ * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
486
+ * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
487
+ * does not see transactions mined or prices moved since, so two transactions built from one
488
+ * snapshot can together end inside the buffer. Midnight still rejects any position above
489
+ * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
490
+ * @param params.collateralPrices - Values from `price()` on each
491
+ * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
492
+ * scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
493
+ * `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a units
494
+ * `target` covering `positionData.debt`, or an assets target whose `minUnits` covers it.
342
495
  * @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
496
  * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
344
497
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
@@ -348,7 +501,9 @@ export declare class MorphoMidnight {
348
501
  * @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
349
502
  * @param params.repayEnabled - Whether the unfilled remainder is repaid directly to Midnight.
350
503
  * @param params.collateralWithdrawals - Optional collateral withdrawals; `maxUint256` assets withdraws the whole balance.
351
- * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`.
504
+ * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
505
+ * must be non-zero and not a Midnight protocol or market token contract when
506
+ * `collateralWithdrawals` is non-empty, and is unused otherwise.
352
507
  * @param params.maxContinuousFee - Largest market continuous fee accepted, in the unit of the market's
353
508
  * onchain `continuousFee` (`Market.continuousFee`): a WAD-scaled per-second rate, so `317097919n`
354
509
  * is about 1% per year. The take reverts if the market fee is higher. Pass `maxUint256` for no cap.
@@ -357,33 +512,60 @@ export declare class MorphoMidnight {
357
512
  * @param params.referralFeeRecipient - Referral fee recipient; required with a positive fee.
358
513
  * @returns Lazy loan-token approval and `MidnightBundlesV2` authorization requirements, and a synchronous transaction builder.
359
514
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
360
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
515
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
516
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
517
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
518
+ * RPC read fails.
361
519
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
362
520
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
363
521
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or a
364
522
  * 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.
523
+ * @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`, `referralFeePct`
524
+ * or `nativeAmount` is negative.
525
+ * @throws {InputExceedsMaxError} when a finite target amount, collateral withdrawal amount, or
526
+ * offer cap exceeds `uint128`; when `target.maxBuyerAssets` exceeds `uint128` (an SDK cap: the
527
+ * bundle accepts `uint256`, but a higher ceiling gives no slippage protection); when
528
+ * `maxContinuousFee` exceeds `uint256`; or when `nativeAmount` exceeds the maximum wNative
529
+ * amount this call can pull, including zero for a withdraw-only call.
371
530
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
372
531
  * @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
373
532
  * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
533
+ * @throws {AccrualPositionUserMismatchError} when `positionData.user` differs from `accountAddress`.
534
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketData.id`.
535
+ * @throws {WithdrawExceedsCollateralError} when a withdrawal exceeds the position's collateral.
536
+ * @throws {MissingMarketPriceError} when a held collateral index has no supplied price.
537
+ * @throws {WithdrawMakesPositionUnhealthyError} when the withdrawal exceeds buffered collateral capacity.
374
538
  * @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
375
539
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
376
540
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
377
541
  * @throws {ExpiredDeadlineError} when `deadline` has expired.
378
542
  * @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
379
543
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
544
+ * @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
380
545
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
546
+ * @throws {MidnightContinuousFeeAboveMaxError} when `maxContinuousFee` is below the market's
547
+ * current continuous fee.
548
+ * @throws {MidnightRepayExceedsDebtError} when a reduce-only repay target exceeds the position's debt.
549
+ * @throws {MidnightTakeableOffersNotFillableError} when every takeable offer is expired, not yet
550
+ * started, self-made, capped below the market fee or otherwise dead, and `repayEnabled` is false,
551
+ * or when every offer on an assets target has an out-of-range tick or a zero or above-par buyer
552
+ * price, even with `repayEnabled`.
553
+ * @throws {MidnightTakeTargetUnreachableError} when the live offers cannot hold the target, or
554
+ * its bounds cannot hold at any fill, or a buy assets target's `minUnits` exceeds the live
555
+ * offers plus the fallback.
556
+ * @throws {MidnightZeroReceiverError} when collateral is withdrawn to the zero address. Thrown
557
+ * during this method call, before the lazy output is returned.
558
+ * @throws {MidnightContractReceiverError} when `collateralReceiver` is a Midnight protocol
559
+ * contract or a market token contract, or when `referralFeeRecipient` is either with a
560
+ * positive referral fee.
381
561
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
382
562
  * @example
383
563
  * ```ts
384
564
  * const output = midnight.takeRepayWithdrawCollateral({
385
565
  * accountAddress: borrower,
386
566
  * marketData,
567
+ * positionData,
568
+ * collateralPrices,
387
569
  * target: { type: "units", units: 1_000_000n, maxBuyerAssets: 990_000n },
388
570
  * takeableOffers: quote.data.takeableOffers,
389
571
  * repayEnabled: true,
@@ -404,9 +586,13 @@ export declare class MorphoMidnight {
404
586
  * @param params.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
405
587
  * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
406
588
  * @returns Lazy token-approval requirements and a synchronous transaction builder.
407
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
589
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
590
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
591
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
592
+ * RPC read fails.
408
593
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
409
594
  * @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
595
+ * @throws {InputExceedsMaxError} when `collateralAssets` exceeds `uint128`.
410
596
  * @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
411
597
  * @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
412
598
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
@@ -423,29 +609,33 @@ export declare class MorphoMidnight {
423
609
  /**
424
610
  * Prepares an atomic lend-offer publication or repost through `MidnightBundlesV2`.
425
611
  *
612
+ * A partially consumed offer group remains publishable with its shared remaining cap reduced.
426
613
  * One transaction cancels `cancellations` under their consumption ceilings, activates the
427
614
  * 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.
615
+ * for a new publication. Calls the Midnight mempool validation API while preparing the tree;
616
+ * `validation: false` skips that call.
429
617
  *
430
618
  * @param params - Maker, lend-side offers, loan reserve, cancellations, and deadline.
431
619
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
432
620
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
433
621
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
434
622
  * @param params.deadline - Bundle execution deadline timestamp.
435
- * @param params.validation - Optional Midnight mempool API request controls.
623
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
436
624
  * @param params.loanToken - Loan token shared by every offer market.
437
625
  * @param params.loanAssets - New loan reserve assigned to the published groups.
438
626
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
439
627
  * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
440
- * @throws {ChainIdMismatchError} when the client targets another chain.
628
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
629
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
630
+ * RPC read fails.
441
631
  * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
442
632
  * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
443
633
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
444
634
  * @throws {NonPositiveInputError} when `loanAssets` is non-positive.
445
635
  * @throws {NegativeInputError} when `reservedLoanAssets` or a `maxConsumed` ceiling is negative.
446
- * @throws {NonPositiveInputError} when `deadline` is not positive.
447
636
  * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128` or `deadline` exceeds `uint256`.
448
- * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
637
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
638
+ * (not thrown when `validation` is `false`).
449
639
  * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
450
640
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
451
641
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
@@ -453,10 +643,24 @@ export declare class MorphoMidnight {
453
643
  * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
454
644
  * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
455
645
  * @throws {MidnightOfferSideMismatchError} when an offer is not lend-side.
646
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer has a nonzero callback.
456
647
  * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
457
648
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
649
+ * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
458
650
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
651
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
652
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
653
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
654
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
655
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
656
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
657
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the offer's expiry.
658
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
659
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
660
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
661
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
459
662
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `loanAssets + reservedLoanAssets`.
663
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
460
664
  * @example
461
665
  * ```ts
462
666
  * const output = await midnight.makeLend({
@@ -475,23 +679,26 @@ export declare class MorphoMidnight {
475
679
  *
476
680
  * One transaction cancels `cancellations` under their consumption ceilings, activates the
477
681
  * 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.
682
+ * a new publication. Calls the Midnight mempool validation API while preparing the tree;
683
+ * `validation: false` skips that call.
479
684
  *
480
685
  * @param params - Maker, borrow-side offers, cancellations, and deadline.
481
686
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
482
687
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
483
688
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
484
689
  * @param params.deadline - Bundle execution deadline timestamp.
485
- * @param params.validation - Optional Midnight mempool API request controls.
690
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
486
691
  * @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.
692
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
693
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
694
+ * RPC read fails.
488
695
  * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
489
696
  * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
490
697
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
491
698
  * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
492
- * @throws {NonPositiveInputError} when `deadline` is not positive.
493
699
  * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128` or `deadline` exceeds `uint256`.
494
- * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
700
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
701
+ * (not thrown when `validation` is `false`).
495
702
  * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
496
703
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
497
704
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
@@ -499,8 +706,23 @@ export declare class MorphoMidnight {
499
706
  * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
500
707
  * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
501
708
  * @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
709
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer has a nonzero callback.
710
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
711
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
712
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
713
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
714
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
715
+ * @throws {MidnightOfferZeroPriceSellError} when a sell offer has a zero tick.
716
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
717
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the offer's expiry.
718
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
719
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
720
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
721
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
502
722
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
723
+ * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
503
724
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
725
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
504
726
  * @example
505
727
  * ```ts
506
728
  * const output = await midnight.makeBorrow({
@@ -528,17 +750,21 @@ export declare class MorphoMidnight {
528
750
  * to `abi.encode(blueMarket)`. The contract does not check supply share-price slippage, so
529
751
  * `blueMarket` must be protected against supply-share-price inflation; this method rejects
530
752
  * 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
753
+ * Midnight mempool validation API while preparing the tree; `validation: false` skips that call.
754
+ * Computes the callback's CREATE2 address from the chain's
532
755
  * `midnightBlueBuyCallbackFactory`, `accountAddress` and `callbackSalt`, and fetches the Morpho Blue market,
533
756
  * accruing interest to the current time before previewing parked shares (markets whose
534
757
  * IRM the SDK cannot accrue are previewed on their last-updated state).
758
+ * The caller is responsible for trusting the Blue market's oracle and IRM. If Blue liquidity is
759
+ * drained, callback offers cannot fill until liquidity returns. `assetsToPark` may underfund the
760
+ * offers; top-ups are allowed.
535
761
  *
536
762
  * @param params - Maker, lend-side offers, Blue market, parked assets, cancellations, and deadline.
537
763
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
538
764
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
539
765
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
540
766
  * @param params.deadline - Bundle execution deadline timestamp.
541
- * @param params.validation - Optional Midnight mempool API request controls.
767
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
542
768
  * @param params.blueMarket - Morpho Blue market the parked assets are supplied to.
543
769
  * @param params.assetsToPark - Loan assets supplied to `blueMarket` for the maker's callback.
544
770
  * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
@@ -546,19 +772,23 @@ export declare class MorphoMidnight {
546
772
  * the maximum wNative amount this call can pull, but not more. Any wrapped native not pulled
547
773
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
548
774
  * required for the full pulled amount.
549
- * @param params.callbackSalt - Salt selecting the maker's callback; the same salt reuses the same callback.
775
+ * @param params.callbackSalt - Salt selecting the maker's callback; must be exactly 32 bytes of hex.
550
776
  * @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
551
- * @throws {ChainIdMismatchError} when the client targets another chain.
777
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
778
+ * another chain than `this.chainId`.
779
+ * @throws {viem.BaseError} when the `eth_chainId` request, a Blue market RPC read, or a
780
+ * requirement RPC read fails.
552
781
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2`, `midnightBlueBuyCallbackFactory`, `midnight`, `blue` or V1 ratifier deployment.
553
782
  * @throws {NonPositiveInputError} when `assetsToPark` is non-positive.
783
+ * @throws {InputExceedsMaxError} when `assetsToPark` exceeds `uint128`.
554
784
  * @throws {NegativeInputError} when a `maxConsumed` ceiling or `nativeAmount` is negative.
555
- * @throws {NonPositiveInputError} when `deadline` is not positive.
556
785
  * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling exceeds `uint128`, `deadline` exceeds
557
786
  * `uint256`, or `nativeAmount` exceeds `assetsToPark` when `blueMarket.loanToken` is wNative.
558
787
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
559
788
  * @throws {NativeAmountOnNonWNativeAssetError} when `blueMarket.loanToken` is not wNative.
560
789
  * @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.
790
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
791
+ * (not thrown when `validation` is `false`).
562
792
  * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
563
793
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
564
794
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
@@ -570,11 +800,24 @@ export declare class MorphoMidnight {
570
800
  * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer's loan token differs from `blueMarket`'s.
571
801
  * @throws {MidnightOfferCallbackMismatchError} when an offer does not use the maker's derived callback.
572
802
  * @throws {MidnightOfferCallbackDataMismatchError} when an offer's callback data is not `abi.encode(blueMarket)`.
803
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
804
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
805
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
806
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
807
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
808
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
809
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the offer's expiry.
810
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
811
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
812
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
813
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
573
814
  * @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
574
815
  * @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price.
575
816
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
817
+ * @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
576
818
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
577
819
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `assetsToPark`.
820
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
578
821
  * @example
579
822
  * ```ts
580
823
  * const callback = getMidnightBlueBuyCallbackAddress({ chainId, owner: maker, salt: callbackSalt });
@@ -603,6 +846,7 @@ export declare class MorphoMidnight {
603
846
  * Shares the borrow-side publication and requirement handling of {@link MorphoMidnight.makeBorrow}.
604
847
  * No tokens are pulled during publication and no token approval is required.
605
848
  * Execution waits for a taker; publication does not close the position or withdraw collateral.
849
+ * A partially consumed offer group remains publishable with its shared remaining cap reduced.
606
850
  * Every offer must already have `buy = false` and `reduceOnly = true`.
607
851
  * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
608
852
  *
@@ -611,12 +855,15 @@ export declare class MorphoMidnight {
611
855
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
612
856
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
613
857
  * @param params.deadline - Bundle execution deadline timestamp.
614
- * @param params.validation - Optional Midnight mempool API request controls.
858
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
615
859
  * @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.
860
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
861
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
862
+ * RPC read fails.
617
863
  * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
618
864
  * @throws {MidnightOfferSideMismatchError} when an offer is not a sell offer (`buy = false`).
619
865
  * @throws {MidnightOfferNotReduceOnlyError} when any offer can increase a position.
866
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer has a nonzero callback.
620
867
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
621
868
  * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
622
869
  * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
@@ -624,12 +871,27 @@ export declare class MorphoMidnight {
624
871
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
625
872
  * @throws {UnknownAddressError} when the chain has no V1 ratifier or `midnightBundlesV2` deployment.
626
873
  * @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.
874
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
875
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
876
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
877
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
878
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
879
+ * @throws {MidnightOfferZeroPriceSellError} when a sell offer has a zero tick.
880
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
881
+ * @throws {MidnightOfferNoCreditError} when a reduce-only sell is submitted without maker credit.
882
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the offer's expiry.
883
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
884
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
885
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
886
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
887
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
888
+ * (not thrown when `validation` is `false`).
629
889
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
630
890
  * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
891
+ * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
631
892
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
632
893
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
894
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
633
895
  * @example
634
896
  * ```ts
635
897
  * const output = await midnight.makeWithdraw({
@@ -648,6 +910,9 @@ export declare class MorphoMidnight {
648
910
  * Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
649
911
  * Loan assets are pulled by Midnight when the offers fill, not during publication.
650
912
  * The loan reserve uses the same approval sizing as `makeLend`.
913
+ * A partially consumed offer group remains publishable with its shared remaining cap reduced.
914
+ * No repay offer can be live after market maturity; late borrowers should repay directly with
915
+ * {@link MorphoMidnight.repayWithdrawCollateral}.
651
916
  * Execution waits for a taker; publication does not close the position or withdraw collateral.
652
917
  * Every offer must already have `buy = true` and `reduceOnly = true`.
653
918
  * The supplied tree, group caps and prices are preserved; no separate root signature is needed.
@@ -657,16 +922,19 @@ export declare class MorphoMidnight {
657
922
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
658
923
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
659
924
  * @param params.deadline - Bundle execution deadline timestamp.
660
- * @param params.validation - Optional Midnight mempool API request controls.
925
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
661
926
  * @param params.loanToken - Loan token shared by every offer market.
662
927
  * @param params.loanAssets - New loan reserve assigned to the published groups.
663
928
  * @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
664
929
  * @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
665
- * @throws {ChainIdMismatchError} when the client targets another chain.
930
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
931
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
932
+ * RPC read fails.
666
933
  * @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
667
934
  * @throws {MidnightOfferSideMismatchError} when an offer is not a buy offer (`buy = true`).
668
935
  * @throws {MidnightOfferNotReduceOnlyError} when any offer can increase a position.
669
- * @throws {NonPositiveInputError} when `loanAssets` or `deadline` is not positive.
936
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer has a nonzero callback.
937
+ * @throws {NonPositiveInputError} when `loanAssets` is not positive.
670
938
  * @throws {NegativeInputError} when `reservedLoanAssets` or a `maxConsumed` ceiling is negative.
671
939
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
672
940
  * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
@@ -675,12 +943,27 @@ export declare class MorphoMidnight {
675
943
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
676
944
  * @throws {UnknownAddressError} when the chain has no V1 ratifier or `midnightBundlesV2` deployment.
677
945
  * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
678
- * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree.
946
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
947
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
948
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
949
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
950
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
951
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
952
+ * @throws {MidnightOfferNoDebtError} when a reduce-only buy is submitted without maker debt.
953
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the offer's expiry.
954
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
955
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
956
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
957
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
958
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
959
+ * (not thrown when `validation` is `false`).
679
960
  * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
680
961
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
962
+ * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
681
963
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
682
964
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
683
965
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below `loanAssets + reservedLoanAssets`.
966
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
684
967
  * @example
685
968
  * ```ts
686
969
  * const output = await midnight.makeRepay({
@@ -702,14 +985,14 @@ export declare class MorphoMidnight {
702
985
  * One transaction cancels `cancellations` under their consumption ceilings, pulls and supplies
703
986
  * required `collateral`, activates the PriceRatifierV1 or RateRatifierV1 root, and publishes its
704
987
  * payload. Pass no cancellations for a new publication. Calls the Midnight mempool validation
705
- * API while preparing the tree.
988
+ * API while preparing the tree; `validation: false` skips that call.
706
989
  *
707
990
  * @param params - Maker, borrow-side offers, required collateral, cancellations, and deadline.
708
991
  * @param params.accountAddress - Maker expected on every offer; must send the transaction.
709
992
  * @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
710
993
  * @param params.cancellations - Previous groups to cancel with their consumption ceilings.
711
994
  * @param params.deadline - Bundle execution deadline timestamp.
712
- * @param params.validation - Optional Midnight mempool API request controls.
995
+ * @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
713
996
  * @param params.collateral - Required market and collateral supplies; every offer must target that market.
714
997
  * @param params.collateral.market - Midnight market receiving the collateral; every offer must target it.
715
998
  * @param params.collateral.supplies - Collateral index and assets per supply; must not be empty.
@@ -719,19 +1002,21 @@ export declare class MorphoMidnight {
719
1002
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
720
1003
  * required for the full pulled amount.
721
1004
  * @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.
1005
+ * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
1006
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
1007
+ * RPC read fails.
723
1008
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` or V1 ratifier deployment.
724
1009
  * @throws {UnknownCollateralIndexError} when a collateral index is not configured.
725
1010
  * @throws {NonPositiveInputError} when a collateral supply amount is non-positive.
726
1011
  * @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.
1012
+ * @throws {InputExceedsMaxError} when a `maxConsumed` ceiling, a collateral supply amount or a
1013
+ * per-index sum exceeds `uint128`, `deadline` exceeds `uint256`, or `nativeAmount` exceeds the
1014
+ * maximum wNative collateral amount this call can pull.
731
1015
  * @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
732
1016
  * @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
733
1017
  * @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.
1018
+ * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
1019
+ * (not thrown when `validation` is `false`).
735
1020
  * @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
736
1021
  * @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
737
1022
  * @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
@@ -739,12 +1024,27 @@ export declare class MorphoMidnight {
739
1024
  * @throws {MidnightOfferContinuousFeeCapError} when an offer has a nonzero continuous fee cap.
740
1025
  * @throws {MidnightOfferSellerReceiverMismatchError} when a sell offer routes proceeds to another address.
741
1026
  * @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
1027
+ * @throws {MidnightOfferCallbackNotSupportedError} when an offer has a nonzero callback.
742
1028
  * @throws {MidnightOfferReduceOnlyError} when an offer is reduce-only.
1029
+ * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
1030
+ * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
1031
+ * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
1032
+ * @throws {MidnightOfferTickSpacingError} when an offer tick is not accessible in its market.
1033
+ * @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds an offer's cap.
1034
+ * @throws {MidnightOfferZeroPriceSellError} when a sell offer has a zero tick.
1035
+ * @throws {MidnightOfferRateBoundUnreachableError} when a Rate V1 offer cannot satisfy its bound.
1036
+ * @throws {MidnightMarketMaturityTooFarError} when an uncreated market's maturity is more than 100 years after the pinned block timestamp.
1037
+ * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1038
+ * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1039
+ * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1040
+ * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
743
1041
  * @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
744
1042
  * @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
745
1043
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1044
+ * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
746
1045
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
747
1046
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below a collateral token's pulled assets.
1047
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
748
1048
  * @example
749
1049
  * ```ts
750
1050
  * const output = await midnight.supplyCollateralMakeBorrow({
@@ -764,17 +1064,33 @@ export declare class MorphoMidnight {
764
1064
  *
765
1065
  * @param params - Position owner, accrued position, optional unit amount, and receiver.
766
1066
  * @param params.accountAddress - Position owner whose credit is redeemed.
767
- * @param params.positionData - Accrued position and hydrated market snapshot.
1067
+ * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`.
768
1068
  * @param params.receiver - Optional credit receiver; defaults to the position owner.
1069
+ * Midnight protocol and market token contracts are rejected.
769
1070
  * @param params.units - Optional credit units to redeem; defaults to the position face value.
1071
+ * Credit is checked after applying the realized losses and continuous fees that Midnight
1072
+ * charges before a withdrawal, accrued up to now. Fees keep accruing until maturity, so `units` close to the accrued
1073
+ * credit can still revert when the transaction lands later. The default face value does not
1074
+ * shrink with time, but before maturity on a market with a continuous fee it is not a full
1075
+ * exit: `withdraw` cuts the pending fee in proportion to the units withdrawn, so some credit
1076
+ * is left. Redeem again after maturity to empty the position.
770
1077
  * @returns No requirements and a synchronous redemption transaction builder.
771
1078
  * @throws {ChainIdMismatchError} when the position market targets another chain.
772
1079
  * @throws {MidnightMarketAddressMismatchError} when the position market targets another Midnight deployment.
773
1080
  * @throws {MissingAccrualPositionError} when no position snapshot is supplied.
774
1081
  * @throws {AccrualPositionUserMismatchError} when the position snapshot belongs to another account.
775
1082
  * @throws {NoMidnightCreditToRedeemError} when the selected unit amount is non-positive.
776
- * @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds position credit.
1083
+ * @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds the accrued
1084
+ * position credit.
1085
+ * @throws {InvalidMidnightPositionLossFactorError} when the market loss factor is below the
1086
+ * position's `lastLossFactor`, which `getPositionData` snapshots never are.
1087
+ * @throws {InvalidMidnightPositionAccrualStateError} when the snapshot's credit, pending fee or
1088
+ * loss factor are inconsistent, which `getPositionData` snapshots never are.
1089
+ * @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
777
1090
  * @throws {InsufficientMidnightWithdrawableLiquidityError} when market liquidity cannot cover the redemption.
1091
+ * @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
1092
+ * @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
1093
+ * market token contract.
778
1094
  * @example
779
1095
  * ```ts
780
1096
  * const output = midnight.redeem({
@@ -791,6 +1107,16 @@ export declare class MorphoMidnight {
791
1107
  * @param params - Account, market snapshot, `repay` mode, collateral withdrawals, optional collateral receiver, and deadline.
792
1108
  * @param params.accountAddress - Position owner and transaction sender.
793
1109
  * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
1110
+ * @param params.positionData - Owner-bound position snapshot returned by `getPositionData`. The
1111
+ * `DEFAULT_LLTV_BUFFER` check is only as current as this snapshot and `collateralPrices`: it
1112
+ * does not see transactions mined or prices moved since, so two transactions built from one
1113
+ * snapshot can together end inside the buffer. Midnight still rejects any position above
1114
+ * LLTV onchain. Midnight debt and collateral do not accrue, so the check needs no accrual.
1115
+ * @param params.collateralPrices - Values from `price()` on each
1116
+ * `marketData.params.collateralParams[i].oracle`, indexed like `positionData.collateral` and
1117
+ * scaled by `ORACLE_PRICE_SCALE`. An empty array is safe only when
1118
+ * `collateralWithdrawals` is empty or the conservative post-operation debt is zero: a `full`
1119
+ * repay, or `repay.assets` covering `positionData.debt`.
794
1120
  * @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
1121
  * @param params.nativeAmount - Optional native ETH sent as `value`; the bundle wraps it into the
796
1122
  * chain's wNative and transfers it to `msg.sender` before pulling. It may cover part or all of
@@ -798,13 +1124,25 @@ export declare class MorphoMidnight {
798
1124
  * stays in the sender's wallet as wNative. The wNative approval to `MidnightBundlesV2` is still
799
1125
  * required for the full pulled amount.
800
1126
  * @param params.collateralWithdrawals - Optional withdrawals; `assets: maxUint256` withdraws the full balance.
801
- * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`.
802
- * @param params.deadline - Bundle execution deadline timestamp.
1127
+ * @param params.collateralReceiver - Optional collateral recipient; defaults to `accountAddress`,
1128
+ * must be non-zero and not a Midnight protocol or market token contract when
1129
+ * `collateralWithdrawals` is non-empty, and is unused otherwise.
1130
+ * @param params.deadline - Bundle execution deadline timestamp. Unlike taker builders,
1131
+ * `maxUint256` is accepted because no offers are filled; the pull remains bounded by
1132
+ * `repay.assets` or `repay.maxBuyerAssets`.
803
1133
  * @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
804
- * @throws {ChainIdMismatchError} when client or market data targets another chain.
1134
+ * @throws {ChainIdMismatchError} when client or market data targets another chain, or from
1135
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
1136
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
1137
+ * RPC read fails.
805
1138
  * @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
1139
+ * @throws {AccrualPositionUserMismatchError} when `positionData.user` differs from `accountAddress`.
1140
+ * @throws {MarketIdMismatchError} when `positionData.marketId` differs from `marketData.id`.
1141
+ * @throws {WithdrawExceedsCollateralError} when a withdrawal exceeds the position's collateral.
1142
+ * @throws {MissingMarketPriceError} when a held collateral index has no supplied price.
1143
+ * @throws {WithdrawMakesPositionUnhealthyError} when the withdrawal exceeds buffered collateral capacity.
806
1144
  * @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.
1145
+ * @throws {NonPositiveInputError} when nothing is repaid or withdrawn, a withdrawal amount is zero, or `repay.maxBuyerAssets` is zero.
808
1146
  * @throws {InputExceedsMaxError} when `repay.assets` or `repay.maxBuyerAssets` is at least
809
1147
  * `maxUint256`, a withdrawal amount or `deadline` exceeds uint256, or `nativeAmount` exceeds
810
1148
  * the maximum wNative amount this call can pull, including zero for a withdraw-only call.
@@ -812,13 +1150,23 @@ export declare class MorphoMidnight {
812
1150
  * @throws {NativeAmountOnNonWNativeAssetError} when `marketData.params.loanToken` is not wNative.
813
1151
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
814
1152
  * @throws {UnknownCollateralIndexError} when a withdrawal selects an unconfigured collateral.
1153
+ * @throws {MidnightRepayExceedsDebtError} when `repay.assets` exceeds the position's debt.
1154
+ * @throws {MidnightTakeTargetUnreachableError} when a full repay's `repay.maxBuyerAssets` is below
1155
+ * the position's debt.
1156
+ * @throws {MidnightZeroReceiverError} when collateral is withdrawn to the zero address. Thrown
1157
+ * during this method call, before the lazy output is returned.
1158
+ * @throws {MidnightContractReceiverError} when `collateralReceiver` is a Midnight protocol
1159
+ * contract or a market token contract.
815
1160
  * @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled loan assets.
1161
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
816
1162
  * @example
817
1163
  * ```ts
818
1164
  * // Close the position: repay all debt, withdraw all collateral.
819
1165
  * const output = midnight.repayWithdrawCollateral({
820
1166
  * accountAddress: borrower,
821
1167
  * marketData,
1168
+ * positionData,
1169
+ * collateralPrices,
822
1170
  * repay: { type: "full", maxBuyerAssets: 1_010_000n },
823
1171
  * collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
824
1172
  * deadline: maxUint256,
@@ -833,21 +1181,31 @@ export declare class MorphoMidnight {
833
1181
  * `maxConsumed` ceiling, so fills landing before execution never leave a partial cancel.
834
1182
  *
835
1183
  * @param params - Maker account, groups with consumption ceilings, and deadline.
836
- * @param params.accountAddress - Maker that must send the transaction; V2 cancels for `msg.sender`,
837
- * so sending from another account cancels that account's groups instead.
1184
+ * @param params.accountAddress - Maker that must send the transaction. It is used only to check
1185
+ * the maker's Midnight authorization of `MidnightBundlesV2`; the bundle cancels the groups of
1186
+ * `msg.sender`. A transaction sent from another account that has also authorized
1187
+ * `MidnightBundlesV2` does not revert: it cancels that account's groups and leaves the maker's
1188
+ * offers fillable.
838
1189
  * @param params.cancellations - Offer groups and the largest consumption accepted for each.
839
1190
  * To cancel unconditionally, set `maxConsumed` to `maxUint128`; the contract treats
840
1191
  * `type(uint128).max` as no limit.
1192
+ * Cancellation is per group: it does not unratify roots or revoke
1193
+ * `MidnightBundlesV2` or ratifier authorization.
841
1194
  * @param params.deadline - Bundle execution deadline timestamp.
842
1195
  * @returns Lazy Midnight authorization requirement for `MidnightBundlesV2` and a synchronous transaction builder.
843
- * @throws {ChainIdMismatchError} when the client targets another chain.
1196
+ * @throws {ChainIdMismatchError} when the client targets another chain, or from
1197
+ * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
1198
+ * @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
1199
+ * RPC read fails.
844
1200
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
845
1201
  * @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
846
1202
  * @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
1203
+ * @throws {MidnightInvalidAccountAddressError} when `accountAddress` is malformed or zero.
1204
+ * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
847
1205
  * @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
848
- * @throws {NonPositiveInputError} when `deadline` is not positive.
849
1206
  * @throws {NegativeInputError} when a `maxConsumed` ceiling is negative.
850
1207
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
1208
+ * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
851
1209
  * @example
852
1210
  * ```ts
853
1211
  * import { morphoViemExtension } from "@morpho-org/morpho-sdk";