@morpho-org/morpho-sdk 9.2.0 → 9.3.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 (44) hide show
  1. package/README.md +4 -4
  2. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  3. package/lib/cjs/actions/midnight/index.js +1 -0
  4. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +50 -0
  5. package/lib/cjs/actions/midnight/withdrawCollateral.js +105 -0
  6. package/lib/cjs/entities/blue/blue.d.ts +4 -7
  7. package/lib/cjs/entities/blue/blue.js +0 -3
  8. package/lib/cjs/entities/index.d.ts +1 -1
  9. package/lib/cjs/entities/midnight/midnight.d.ts +57 -12
  10. package/lib/cjs/entities/midnight/midnight.js +102 -12
  11. package/lib/cjs/entities/midnight/publication.d.ts +2 -1
  12. package/lib/cjs/entities/midnight/publication.js +44 -64
  13. package/lib/cjs/entities/midnight/types.d.ts +8 -0
  14. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +0 -8
  15. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -4
  16. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +0 -4
  17. package/lib/cjs/entities/vaultV2/vaultV2.js +0 -3
  18. package/lib/cjs/helpers/deadShares.d.ts +5 -4
  19. package/lib/cjs/helpers/deadShares.js +5 -4
  20. package/lib/cjs/types/action.d.ts +10 -1
  21. package/lib/cjs/types/error.d.ts +1 -6
  22. package/lib/cjs/types/error.js +1 -6
  23. package/lib/esm/actions/midnight/index.d.ts +1 -0
  24. package/lib/esm/actions/midnight/index.js +1 -0
  25. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +50 -0
  26. package/lib/esm/actions/midnight/withdrawCollateral.js +101 -0
  27. package/lib/esm/entities/blue/blue.d.ts +4 -7
  28. package/lib/esm/entities/blue/blue.js +0 -3
  29. package/lib/esm/entities/index.d.ts +1 -1
  30. package/lib/esm/entities/midnight/midnight.d.ts +57 -12
  31. package/lib/esm/entities/midnight/midnight.js +104 -14
  32. package/lib/esm/entities/midnight/publication.d.ts +2 -1
  33. package/lib/esm/entities/midnight/publication.js +45 -65
  34. package/lib/esm/entities/midnight/types.d.ts +8 -0
  35. package/lib/esm/entities/vaultV1/vaultV1.d.ts +0 -8
  36. package/lib/esm/entities/vaultV1/vaultV1.js +0 -4
  37. package/lib/esm/entities/vaultV2/vaultV2.d.ts +0 -4
  38. package/lib/esm/entities/vaultV2/vaultV2.js +0 -3
  39. package/lib/esm/helpers/deadShares.d.ts +5 -4
  40. package/lib/esm/helpers/deadShares.js +5 -4
  41. package/lib/esm/types/action.d.ts +10 -1
  42. package/lib/esm/types/error.d.ts +1 -6
  43. package/lib/esm/types/error.js +1 -6
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -24,9 +24,9 @@ General Vault V1 operations remain supported.
24
24
  pnpm add @morpho-org/morpho-sdk
25
25
  ```
26
26
 
27
- Read [Adopting dead-share protection](./DEAD-SHARE-PROTECTION.md) for the protected Blue `supply`
28
- overload and the dead-deposit checks on supply and deposit flows. Snapshot-free Blue `supply`
29
- is deprecated but remains unprotected during the deprecation minor.
27
+ Read [Dead-share validators](./DEAD-SHARE-PROTECTION.md) for the exported checks. Builders do not
28
+ enforce the dead-deposit rule; integrators should validate their snapshot before building.
29
+ Snapshot-free Blue `supply` remains deprecated.
30
30
 
31
31
  Upgrading from v8? Read the [v8 → v9 migration guide](./MIGRATION-v8-to-v9.md) for the approval
32
32
  API removals and the new unlimited-approval behavior.
@@ -55,7 +55,7 @@ BlueBundlesV1, and the remaining rows identify their destination.
55
55
  | | `inKindRedeem` | VaultExitBundlesV1 |
56
56
  | **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
57
57
  | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `takeRepayWithdrawCollateral`, `repayWithdrawCollateral`, `takeWithdraw` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood, Tempo) |
58
- | | `supplyCollateral`, `redeem` | Direct call |
58
+ | | `supplyCollateral`, `withdrawCollateral`, `redeem` | Direct call |
59
59
  | | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend`, `cancelOffers` | MidnightBundlesV2 (Ethereum, Base, Arc, Robinhood, Tempo) |
60
60
 
61
61
  `makeBorrow` publishes without collateral; `supplyCollateralMakeBorrow` requires collateral and
@@ -9,3 +9,4 @@ export * from "./takeLend.js";
9
9
  export * from "./takeRepayWithdrawCollateral.js";
10
10
  export * from "./takeWithdraw.js";
11
11
  export * from "./types.js";
12
+ export * from "./withdrawCollateral.js";
@@ -25,3 +25,4 @@ __exportStar(require("./takeLend.js"), exports);
25
25
  __exportStar(require("./takeRepayWithdrawCollateral.js"), exports);
26
26
  __exportStar(require("./takeWithdraw.js"), exports);
27
27
  __exportStar(require("./types.js"), exports);
28
+ __exportStar(require("./withdrawCollateral.js"), exports);
@@ -0,0 +1,50 @@
1
+ import { type MarketInput } from "@morpho-org/midnight-sdk";
2
+ import { type Address } from "viem";
3
+ import { type Metadata, type MidnightWithdrawCollateralAction, type Transaction } from "../../types/index.js";
4
+ /** Parameters for encoding a direct Midnight collateral withdrawal. */
5
+ export interface MidnightWithdrawCollateralParams {
6
+ readonly chainId: number;
7
+ readonly market: MarketInput;
8
+ readonly collateralIndex?: bigint;
9
+ readonly assets: bigint;
10
+ readonly onBehalf: Address;
11
+ readonly receiver: Address;
12
+ readonly metadata?: Metadata;
13
+ }
14
+ /**
15
+ * Encodes a direct Midnight collateral withdrawal.
16
+ *
17
+ * This builder reads no position state. Prefer the entity method for balance and health checks.
18
+ *
19
+ * @param params.chainId - Chain id used to resolve `Midnight`.
20
+ * @param params.market - Midnight market from which collateral is withdrawn.
21
+ * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
22
+ * @param params.assets - Collateral assets to withdraw.
23
+ * @param params.onBehalf - Collateral owner; the sender must be this account or its authorized operator.
24
+ * @param params.receiver - Account receiving withdrawn collateral.
25
+ * @param params.metadata - Optional analytics metadata appended to calldata.
26
+ * @returns A deep-frozen `Transaction<MidnightWithdrawCollateralAction>` targeting `Midnight`.
27
+ * @throws {MidnightZeroReceiverError} when receiver is zero.
28
+ * @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
29
+ * @throws {NonPositiveInputError} when `assets <= 0n`.
30
+ * @throws {InputExceedsMaxError} when `assets` exceeds `uint128`.
31
+ * @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
32
+ * @throws {ChainIdMismatchError} when the market targets another chain.
33
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
34
+ * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
35
+ * @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
36
+ * @example
37
+ * ```ts
38
+ * import { midnightWithdrawCollateral } from "@morpho-org/morpho-sdk";
39
+ *
40
+ * const tx = midnightWithdrawCollateral({
41
+ * chainId: 8453,
42
+ * market: marketData.params,
43
+ * collateralIndex: 0n,
44
+ * assets: 2_000_000n,
45
+ * onBehalf: user,
46
+ * receiver: user,
47
+ * });
48
+ * ```
49
+ */
50
+ export declare const midnightWithdrawCollateral: (params: MidnightWithdrawCollateralParams) => Readonly<Transaction<MidnightWithdrawCollateralAction>>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.midnightWithdrawCollateral = void 0;
4
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
+ const viem_1 = require("viem");
7
+ const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
8
+ const index_js_1 = require("../../helpers/index.js");
9
+ const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
10
+ const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
11
+ const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
12
+ const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightReceiver.js");
13
+ const index_js_2 = require("../../types/index.js");
14
+ /**
15
+ * Encodes a direct Midnight collateral withdrawal.
16
+ *
17
+ * This builder reads no position state. Prefer the entity method for balance and health checks.
18
+ *
19
+ * @param params.chainId - Chain id used to resolve `Midnight`.
20
+ * @param params.market - Midnight market from which collateral is withdrawn.
21
+ * @param params.collateralIndex - Optional collateral index; defaults to `0n`.
22
+ * @param params.assets - Collateral assets to withdraw.
23
+ * @param params.onBehalf - Collateral owner; the sender must be this account or its authorized operator.
24
+ * @param params.receiver - Account receiving withdrawn collateral.
25
+ * @param params.metadata - Optional analytics metadata appended to calldata.
26
+ * @returns A deep-frozen `Transaction<MidnightWithdrawCollateralAction>` targeting `Midnight`.
27
+ * @throws {MidnightZeroReceiverError} when receiver is zero.
28
+ * @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
29
+ * @throws {NonPositiveInputError} when `assets <= 0n`.
30
+ * @throws {InputExceedsMaxError} when `assets` exceeds `uint128`.
31
+ * @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
32
+ * @throws {ChainIdMismatchError} when the market targets another chain.
33
+ * @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
34
+ * @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
35
+ * @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as a malformed `bytes32`, an out-of-range integer or a malformed address.
36
+ * @example
37
+ * ```ts
38
+ * import { midnightWithdrawCollateral } from "@morpho-org/morpho-sdk";
39
+ *
40
+ * const tx = midnightWithdrawCollateral({
41
+ * chainId: 8453,
42
+ * market: marketData.params,
43
+ * collateralIndex: 0n,
44
+ * assets: 2_000_000n,
45
+ * onBehalf: user,
46
+ * receiver: user,
47
+ * });
48
+ * ```
49
+ */
50
+ const midnightWithdrawCollateral = (params) => {
51
+ // Reject a malformed account before comparing it with the zero address.
52
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("onBehalf", params.onBehalf);
53
+ if (params.assets <= 0n) {
54
+ throw new index_js_2.NonPositiveInputError("assets", params.assets);
55
+ }
56
+ (0, validateMidnightBounds_js_1.validateMidnightUint128Field)("assets", params.assets);
57
+ if ((0, viem_1.isAddressEqual)(params.onBehalf, viem_1.zeroAddress)) {
58
+ throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
59
+ }
60
+ // Reject markets from another chain deployment before encoding the call.
61
+ (0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
62
+ const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
63
+ const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
64
+ const collateralIndex = params.collateralIndex ?? 0n;
65
+ // Validate that the supplied collateral index is configured before encoding.
66
+ midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
67
+ (0, validateMidnightReceiver_js_1.validateMidnightReceiver)({
68
+ chainId: params.chainId,
69
+ market: params.market,
70
+ field: "receiver",
71
+ receiver: params.receiver,
72
+ });
73
+ let tx = {
74
+ to: midnight,
75
+ value: 0n,
76
+ data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
77
+ abi: midnight_sdk_1.midnightAbi,
78
+ functionName: "withdrawCollateral",
79
+ args: [
80
+ midnight_sdk_1.MarketUtils.toStruct(params.market),
81
+ collateralIndex,
82
+ params.assets,
83
+ params.onBehalf,
84
+ params.receiver,
85
+ ],
86
+ }),
87
+ };
88
+ if (params.metadata) {
89
+ tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
90
+ }
91
+ return (0, morpho_ts_1.deepFreeze)({
92
+ ...tx,
93
+ action: {
94
+ type: "midnightWithdrawCollateral",
95
+ args: {
96
+ market: marketId,
97
+ collateralIndex,
98
+ assets: params.assets,
99
+ onBehalf: params.onBehalf,
100
+ receiver: params.receiver,
101
+ },
102
+ },
103
+ });
104
+ };
105
+ exports.midnightWithdrawCollateral = midnightWithdrawCollateral;
@@ -151,7 +151,8 @@ export interface BlueActions {
151
151
  *
152
152
  * @param params.userAddress - User funding and receiving the supply position.
153
153
  * @param params.marketData - Snapshot of this market from `getMarketData()` (or `fetchMarket` in
154
- * `@morpho-org/blue-sdk-viem`), used to check its dead deposit before building.
154
+ * `@morpho-org/blue-sdk-viem`), checked only for `MarketIdMismatchError`. To check the dead-deposit
155
+ * rule, call `validateBlueMarketDeadShares` on the snapshot yourself before building.
155
156
  * @param params.assets - Gross loan-token assets funded before the referral fee.
156
157
  * @param params.nativeAmount - Optional full native funding; must equal `assets` and requires wNative.
157
158
  * @param params.deadline - Final call deadline in Unix seconds.
@@ -180,8 +181,6 @@ export interface BlueActions {
180
181
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
181
182
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
182
183
  * @throws {MarketIdMismatchError} when `marketData` belongs to another market.
183
- * @throws {MissingDeadSharesDataError} when `marketData` has no `deadSupplyShares`.
184
- * @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
185
184
  * @throws {UnknownTokenError} from `getRequirements()` when the funded token's `decimals()` is unusable.
186
185
  * @throws {MalformedTokenMetadataError} when the token's `eip712Domain()` or
187
186
  * `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
@@ -223,8 +222,7 @@ export interface BlueActions {
223
222
  readonly referralFeeRecipient?: Address;
224
223
  }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
225
224
  /**
226
- * @deprecated Pass `marketData` from `getMarketData()` to check the dead deposit.
227
- * Snapshot-free supply is unprotected and will be removed in the next major after one minor.
225
+ * @deprecated Pass `marketData` from `getMarketData()`; the snapshot-free overload is removed in the next major.
228
226
  */
229
227
  (params: {
230
228
  readonly userAddress: Address;
@@ -1002,8 +1000,7 @@ export declare class MorphoBlue implements BlueActions {
1002
1000
  readonly referralFeeRecipient?: Address;
1003
1001
  }): ActionOutput<BlueSupplyAction, readonly RequirementSignature[], BlueTokenRequirementsParams>;
1004
1002
  /**
1005
- * @deprecated Pass `marketData` from `getMarketData()` to check the dead deposit.
1006
- * Snapshot-free supply is unprotected and will be removed in the next major after one minor.
1003
+ * @deprecated Pass `marketData` from `getMarketData()`; the snapshot-free overload is removed in the next major.
1007
1004
  */
1008
1005
  supply(params: {
1009
1006
  readonly userAddress: Address;
@@ -9,7 +9,6 @@ const actions_1 = require("viem/actions");
9
9
  const common_js_1 = require("../../actions/blue/common.js");
10
10
  const index_js_1 = require("../../actions/index.js");
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
- const deadShares_js_1 = require("../../helpers/deadShares.js");
13
12
  const index_js_2 = require("../../helpers/index.js");
14
13
  const validate_js_1 = require("../../helpers/validate.js");
15
14
  const index_js_3 = require("../../types/index.js");
@@ -144,8 +143,6 @@ class MorphoBlue {
144
143
  if (params.marketData.id !== this.marketParams.id) {
145
144
  throw new index_js_3.MarketIdMismatchError(params.marketData.id, this.marketParams.id);
146
145
  }
147
- // Throws when the market lacks a sufficient dead deposit; nothing to return.
148
- (0, deadShares_js_1.validateBlueMarketDeadShares)(params.marketData);
149
146
  }
150
147
  return {
151
148
  getRequirements: (requirementsParams) => {
@@ -12,7 +12,7 @@ export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnap
12
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
13
13
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
14
14
  export { MorphoBlue } from "./blue/index.js";
15
- export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
15
+ export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, WithdrawCollateralParams as MidnightWithdrawCollateralParams, } from "./midnight/index.js";
16
16
  export { type MidnightActionOutput, type MidnightActions, type MidnightRequirementsParams, MorphoMidnight, } from "./midnight/index.js";
17
17
  export * from "./requirements/index.js";
18
18
  export { MorphoVaultV1 } from "./vaultV1/index.js";
@@ -1,8 +1,8 @@
1
1
  import { type AccrualPosition, type Market, type MidnightFetchParams } from "@morpho-org/midnight-sdk";
2
2
  import { type Address, type Hex } from "viem";
3
3
  import type { MorphoClientType } from "../../types/client.js";
4
- import { type MidnightCancelAndMakeAction, type MidnightGroupCancellation, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction, type MidnightTakeRepayWithdrawCollateralAction, type MidnightTakeWithdrawAction } from "../../types/index.js";
5
- import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams, TakeRepayWithdrawCollateralParams, TakeWithdrawParams } from "./types.js";
4
+ import { type MidnightCancelAndMakeAction, type MidnightGroupCancellation, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction, type MidnightTakeRepayWithdrawCollateralAction, type MidnightTakeWithdrawAction, type MidnightWithdrawCollateralAction } from "../../types/index.js";
5
+ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams, TakeRepayWithdrawCollateralParams, TakeWithdrawParams, WithdrawCollateralParams } from "./types.js";
6
6
  /**
7
7
  * Entity methods exposed by `client.morpho.midnight(chainId)`.
8
8
  *
@@ -30,7 +30,7 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
30
30
  * const tx = output.buildTx();
31
31
  * ```
32
32
  */
33
- export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "takeWithdraw" | "supplyCollateralTakeBorrow" | "takeRepayWithdrawCollateral" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyBlueMakeLend" | "makeWithdraw" | "makeRepay" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffers">;
33
+ export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "takeWithdraw" | "supplyCollateralTakeBorrow" | "takeRepayWithdrawCollateral" | "supplyCollateral" | "withdrawCollateral" | "makeLend" | "makeBorrow" | "supplyBlueMakeLend" | "makeWithdraw" | "makeRepay" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffers">;
34
34
  /**
35
35
  * Entity facade for Midnight fixed-rate action flows.
36
36
  *
@@ -126,7 +126,7 @@ export declare class MorphoMidnight {
126
126
  * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
127
127
  * @throws {MidnightZeroAccountError} when `accountAddress` is the zero address.
128
128
  * @throws {MidnightCalldataEncodingError} when an offer cannot be ABI-encoded, such as an out-of-range integer, or `accountAddress` is not a well-formed address.
129
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
129
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
130
130
  * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
131
131
  * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
132
132
  * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
@@ -591,6 +591,52 @@ export declare class MorphoMidnight {
591
591
  * ```
592
592
  */
593
593
  takeRepayWithdrawCollateral(params: TakeRepayWithdrawCollateralParams): MidnightActionOutput<MidnightTakeRepayWithdrawCollateralAction>;
594
+ /**
595
+ * Withdraws collateral directly from Midnight without bundle authorization or token pulls.
596
+ *
597
+ * Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
598
+ * No requirements or RPC reads are needed. The signing account must be accountAddress.
599
+ *
600
+ * @param params - Market, owner-bound position, collateral prices and withdrawal amount.
601
+ * @param params.accountAddress - Collateral owner. This account must send the transaction.
602
+ * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
603
+ * @param params.positionData - Owner-bound position snapshot returned by getPositionData.
604
+ * @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
605
+ * ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
606
+ * @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
607
+ * market's collateral parameters, which Midnight sorts by token address, not the order they were
608
+ * listed in when the market was built; check marketData.getCollateralByIndex(index).token.
609
+ * @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
610
+ * the selected collateral from positionData before building the transaction.
611
+ * @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
612
+ * @returns Lazy handles for a direct Midnight withdrawal.
613
+ * @throws {ChainIdMismatchError} when the client or market targets another chain.
614
+ * @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
615
+ * @throws {MidnightZeroAccountError} when accountAddress is zero.
616
+ * @throws {MidnightMarketAddressMismatchError} when marketData targets another Midnight deployment.
617
+ * @throws {MissingMarketPriceError} when debt is positive and held collateral has no supplied price.
618
+ * @throws {MarketIdMismatchError} when positionData belongs to another market.
619
+ * @throws {AccrualPositionUserMismatchError} when positionData belongs to another account.
620
+ * @throws {UnknownCollateralIndexError} when collateralIndex is not configured.
621
+ * @throws {NonPositiveInputError} when the resolved amount is not positive.
622
+ * @throws {InputExceedsMaxError} when assets exceeds uint128.
623
+ * @throws {WithdrawExceedsCollateralError} when assets exceeds the collateral balance.
624
+ * @throws {WithdrawMakesPositionUnhealthyError} when remaining collateral cannot safely cover debt.
625
+ * @throws {MidnightZeroReceiverError} when receiver is zero.
626
+ * @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
627
+ * @example
628
+ * ```ts
629
+ * const output = midnight.withdrawCollateral({
630
+ * accountAddress: user,
631
+ * marketData,
632
+ * positionData,
633
+ * collateralPrices,
634
+ * assets: 1_000n,
635
+ * });
636
+ * const tx = output.buildTx();
637
+ * ```
638
+ */
639
+ withdrawCollateral(params: WithdrawCollateralParams): MidnightActionOutput<MidnightWithdrawCollateralAction>;
594
640
  /**
595
641
  * Prepares a direct collateral supply using a caller-provided market snapshot.
596
642
  *
@@ -684,7 +730,7 @@ export declare class MorphoMidnight {
684
730
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
685
731
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
686
732
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
687
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
733
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
688
734
  * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
689
735
  * @example
690
736
  * ```ts
@@ -746,7 +792,7 @@ export declare class MorphoMidnight {
746
792
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
747
793
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
748
794
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
749
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
795
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
750
796
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
751
797
  * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
752
798
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
@@ -847,9 +893,8 @@ export declare class MorphoMidnight {
847
893
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
848
894
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
849
895
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
850
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
851
- * @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
852
- * @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
896
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
897
+ * @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
853
898
  * @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
854
899
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
855
900
  * @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
@@ -923,7 +968,7 @@ export declare class MorphoMidnight {
923
968
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
924
969
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
925
970
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
926
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
971
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
927
972
  * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
928
973
  * (not thrown when `validation` is `false`).
929
974
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
@@ -997,7 +1042,7 @@ export declare class MorphoMidnight {
997
1042
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
998
1043
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
999
1044
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1000
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1045
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1001
1046
  * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
1002
1047
  * (not thrown when `validation` is `false`).
1003
1048
  * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
@@ -1082,7 +1127,7 @@ export declare class MorphoMidnight {
1082
1127
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1083
1128
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1084
1129
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1085
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1130
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1086
1131
  * @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
1087
1132
  * @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
1088
1133
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
@@ -11,7 +11,6 @@ const index_js_2 = require("../../actions/requirements/index.js");
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
12
  const callback_js_1 = require("../../helpers/callback.js");
13
13
  const constant_js_1 = require("../../helpers/constant.js");
14
- const deadShares_js_1 = require("../../helpers/deadShares.js");
15
14
  const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
16
15
  const index_js_3 = require("../../helpers/index.js");
17
16
  const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
@@ -266,7 +265,7 @@ class MorphoMidnight {
266
265
  * @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
267
266
  * @throws {MidnightZeroAccountError} when `accountAddress` is the zero address.
268
267
  * @throws {MidnightCalldataEncodingError} when an offer cannot be ABI-encoded, such as an out-of-range integer, or `accountAddress` is not a well-formed address.
269
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
268
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
270
269
  * @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
271
270
  * @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
272
271
  * @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
@@ -1074,6 +1073,97 @@ class MorphoMidnight {
1074
1073
  buildTx: () => tx,
1075
1074
  };
1076
1075
  }
1076
+ /**
1077
+ * Withdraws collateral directly from Midnight without bundle authorization or token pulls.
1078
+ *
1079
+ * Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
1080
+ * No requirements or RPC reads are needed. The signing account must be accountAddress.
1081
+ *
1082
+ * @param params - Market, owner-bound position, collateral prices and withdrawal amount.
1083
+ * @param params.accountAddress - Collateral owner. This account must send the transaction.
1084
+ * @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
1085
+ * @param params.positionData - Owner-bound position snapshot returned by getPositionData.
1086
+ * @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
1087
+ * ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
1088
+ * @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
1089
+ * market's collateral parameters, which Midnight sorts by token address, not the order they were
1090
+ * listed in when the market was built; check marketData.getCollateralByIndex(index).token.
1091
+ * @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
1092
+ * the selected collateral from positionData before building the transaction.
1093
+ * @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
1094
+ * @returns Lazy handles for a direct Midnight withdrawal.
1095
+ * @throws {ChainIdMismatchError} when the client or market targets another chain.
1096
+ * @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
1097
+ * @throws {MidnightZeroAccountError} when accountAddress is zero.
1098
+ * @throws {MidnightMarketAddressMismatchError} when marketData targets another Midnight deployment.
1099
+ * @throws {MissingMarketPriceError} when debt is positive and held collateral has no supplied price.
1100
+ * @throws {MarketIdMismatchError} when positionData belongs to another market.
1101
+ * @throws {AccrualPositionUserMismatchError} when positionData belongs to another account.
1102
+ * @throws {UnknownCollateralIndexError} when collateralIndex is not configured.
1103
+ * @throws {NonPositiveInputError} when the resolved amount is not positive.
1104
+ * @throws {InputExceedsMaxError} when assets exceeds uint128.
1105
+ * @throws {WithdrawExceedsCollateralError} when assets exceeds the collateral balance.
1106
+ * @throws {WithdrawMakesPositionUnhealthyError} when remaining collateral cannot safely cover debt.
1107
+ * @throws {MidnightZeroReceiverError} when receiver is zero.
1108
+ * @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
1109
+ * @example
1110
+ * ```ts
1111
+ * const output = midnight.withdrawCollateral({
1112
+ * accountAddress: user,
1113
+ * marketData,
1114
+ * positionData,
1115
+ * collateralPrices,
1116
+ * assets: 1_000n,
1117
+ * });
1118
+ * const tx = output.buildTx();
1119
+ * ```
1120
+ */
1121
+ withdrawCollateral(params) {
1122
+ (0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
1123
+ // Reject invalid owners before preparing the direct call.
1124
+ (0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
1125
+ validateMarketData(params.marketData, this.chainId);
1126
+ validatePositionBinding(params);
1127
+ const collateralIndex = params.collateralIndex ?? 0n;
1128
+ // Reject unconfigured indexes before reading the position balance.
1129
+ midnight_sdk_1.MarketUtils.getCollateralByIndex(params.marketData.params, collateralIndex);
1130
+ const index = Number(collateralIndex);
1131
+ const available = params.positionData.collateral[index] ?? 0n;
1132
+ const assets = params.assets === viem_1.maxUint256 ? available : params.assets;
1133
+ const tx = (0, index_js_1.midnightWithdrawCollateral)({
1134
+ chainId: this.chainId,
1135
+ market: params.marketData.params,
1136
+ collateralIndex,
1137
+ assets,
1138
+ onBehalf: params.accountAddress,
1139
+ receiver: params.receiver ?? params.accountAddress,
1140
+ metadata: this.client.options.metadata,
1141
+ });
1142
+ if (assets > available) {
1143
+ throw new index_js_4.WithdrawExceedsCollateralError({
1144
+ withdrawAmount: assets,
1145
+ available,
1146
+ market: params.marketData.id,
1147
+ });
1148
+ }
1149
+ if (params.positionData.debt > 0n) {
1150
+ const collateral = Array.from({ length: params.marketData.params.collateralParams.length }, (_, i) => params.positionData.collateral[i] ?? 0n);
1151
+ collateral[index] = available - assets;
1152
+ const maxSafeDebt = (0, index_js_3.getMidnightMaxSafeDebt)({
1153
+ market: params.marketData,
1154
+ collateral,
1155
+ collateralPrices: params.collateralPrices,
1156
+ });
1157
+ if (params.positionData.debt > maxSafeDebt) {
1158
+ throw new index_js_4.WithdrawMakesPositionUnhealthyError({
1159
+ withdrawAmount: assets,
1160
+ borrowAssets: params.positionData.debt,
1161
+ maxSafeBorrow: maxSafeDebt,
1162
+ });
1163
+ }
1164
+ }
1165
+ return { getRequirements: async () => [], buildTx: () => tx };
1166
+ }
1077
1167
  /**
1078
1168
  * Prepares a direct collateral supply using a caller-provided market snapshot.
1079
1169
  *
@@ -1203,7 +1293,7 @@ class MorphoMidnight {
1203
1293
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1204
1294
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1205
1295
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1206
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1296
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1207
1297
  * @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
1208
1298
  * @example
1209
1299
  * ```ts
@@ -1274,7 +1364,7 @@ class MorphoMidnight {
1274
1364
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1275
1365
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1276
1366
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1277
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1367
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1278
1368
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1279
1369
  * @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
1280
1370
  * @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
@@ -1438,9 +1528,8 @@ class MorphoMidnight {
1438
1528
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1439
1529
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1440
1530
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1441
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1442
- * @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
1443
- * @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
1531
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1532
+ * @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
1444
1533
  * @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
1445
1534
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
1446
1535
  * @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
@@ -1496,8 +1585,9 @@ class MorphoMidnight {
1496
1585
  }),
1497
1586
  ]);
1498
1587
  const market = (0, morpho_ts_1._try)(() => fetched.accrueInterest(blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), fetched.lastUpdate)), blue_sdk_1.UnsupportedMarketIrmError) ?? fetched;
1499
- // Throws when the parking market lacks a sufficient dead deposit; nothing to return.
1500
- (0, deadShares_js_1.validateBlueMarketDeadShares)(fetched);
1588
+ if (market.totalSupplyShares === 0n) {
1589
+ throw new index_js_4.EmptyBlueParkingMarketError({ marketId: blueMarketId });
1590
+ }
1501
1591
  if (market.toSupplyShares(params.assetsToPark, "Down") === 0n) {
1502
1592
  throw new index_js_4.ZeroBlueParkingSharesError({
1503
1593
  marketId: blueMarketId,
@@ -1643,7 +1733,7 @@ class MorphoMidnight {
1643
1733
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1644
1734
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1645
1735
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1646
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1736
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1647
1737
  * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
1648
1738
  * (not thrown when `validation` is `false`).
1649
1739
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
@@ -1731,7 +1821,7 @@ class MorphoMidnight {
1731
1821
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1732
1822
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1733
1823
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1734
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1824
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1735
1825
  * @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
1736
1826
  * (not thrown when `validation` is `false`).
1737
1827
  * @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
@@ -1830,7 +1920,7 @@ class MorphoMidnight {
1830
1920
  * @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
1831
1921
  * @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
1832
1922
  * @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
1833
- * @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
1923
+ * @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
1834
1924
  * @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
1835
1925
  * @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
1836
1926
  * @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
@@ -87,6 +87,7 @@ export declare function validateMidnightMakerOfferStates(params: {
87
87
  *
88
88
  * The reader uses a single block for contract reads and returns that block's
89
89
  * timestamp as `now`; oracle code checks use the same block number.
90
+ * Contract reads do not require a Multicall3 deployment or viem chain metadata.
90
91
  *
91
92
  * @internal
92
93
  * @param params.client - Viem client used for state reads.
@@ -96,7 +97,7 @@ export declare function validateMidnightMakerOfferStates(params: {
96
97
  * @returns Per-offer states plus the timestamp of the pinned block.
97
98
  * @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
98
99
  * another chain than `params.chainId`.
99
- * @throws {viem.BaseError} when block, multicall, or oracle-code reads fail.
100
+ * @throws {viem.BaseError} when block, contract, or oracle-code reads fail.
100
101
  * @example
101
102
  * ```ts
102
103
  * const { states, now } = await fetchMidnightMakerOfferStates({