@morpho-org/morpho-sdk 9.6.0-next.0 → 9.6.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 (136) hide show
  1. package/README.md +59 -0
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  5. package/lib/cjs/actions/bundles/common.js +39 -32
  6. package/lib/cjs/actions/midnight/cancelAndMake.js +20 -98
  7. package/lib/cjs/actions/midnight/index.d.ts +2 -0
  8. package/lib/cjs/actions/midnight/index.js +2 -0
  9. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +5 -6
  10. package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +39 -0
  11. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +91 -0
  12. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +31 -32
  13. package/lib/cjs/actions/midnight/takeBorrow.js +24 -23
  14. package/lib/cjs/actions/midnight/takeLend.js +24 -23
  15. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
  16. package/lib/cjs/actions/midnight/takeWithdraw.js +24 -23
  17. package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
  18. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +104 -0
  19. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
  20. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
  21. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
  22. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +1 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  25. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
  26. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
  27. package/lib/cjs/actions/vaultV1/migrateToV2.js +7 -7
  28. package/lib/cjs/blue/abis.d.ts +1 -1
  29. package/lib/cjs/blue/abis.js +1 -5
  30. package/lib/cjs/blue/entities.d.ts +4 -4
  31. package/lib/cjs/blue/entities.js +1 -3
  32. package/lib/cjs/blue/errors.d.ts +2 -2
  33. package/lib/cjs/blue/errors.js +1 -5
  34. package/lib/cjs/blue/fetch.d.ts +2 -2
  35. package/lib/cjs/blue/fetch.js +1 -3
  36. package/lib/cjs/blue/utils.d.ts +1 -1
  37. package/lib/cjs/blue/utils.js +1 -2
  38. package/lib/cjs/entities/index.d.ts +5 -5
  39. package/lib/cjs/entities/index.js +1 -3
  40. package/lib/cjs/entities/midnight/midnight.d.ts +77 -3
  41. package/lib/cjs/entities/midnight/midnight.js +174 -0
  42. package/lib/cjs/entities/midnight/types.d.ts +16 -0
  43. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +8 -33
  44. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -33
  45. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
  46. package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
  47. package/lib/cjs/errors.d.ts +4 -4
  48. package/lib/cjs/errors.js +6 -7
  49. package/lib/cjs/fetch.d.ts +2 -2
  50. package/lib/cjs/fetch.js +1 -3
  51. package/lib/cjs/helpers/deadShares.js +0 -2
  52. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +1 -0
  53. package/lib/cjs/helpers/signAndVerifyTypedData.js +12 -5
  54. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
  55. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +129 -0
  56. package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +14 -0
  57. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +27 -0
  58. package/lib/cjs/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
  59. package/lib/cjs/helpers/validateMidnightCollateralSupplies.js +28 -0
  60. package/lib/cjs/helpers/validatePositiveInput.d.ts +10 -0
  61. package/lib/cjs/helpers/validatePositiveInput.js +18 -0
  62. package/lib/cjs/midnight/errors.d.ts +1 -2
  63. package/lib/cjs/midnight/errors.js +5 -5
  64. package/lib/cjs/types/action.d.ts +18 -3
  65. package/lib/cjs/types/error.d.ts +23 -2
  66. package/lib/cjs/types/error.js +45 -5
  67. package/lib/cjs/utils.d.ts +2 -2
  68. package/lib/cjs/utils.js +2 -4
  69. package/lib/esm/abis.d.ts +1 -1
  70. package/lib/esm/abis.js +1 -1
  71. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  72. package/lib/esm/actions/bundles/common.js +39 -32
  73. package/lib/esm/actions/midnight/cancelAndMake.js +25 -103
  74. package/lib/esm/actions/midnight/index.d.ts +2 -0
  75. package/lib/esm/actions/midnight/index.js +2 -0
  76. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +5 -6
  77. package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +39 -0
  78. package/lib/esm/actions/midnight/supplyCollateralBatch.js +87 -0
  79. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -34
  80. package/lib/esm/actions/midnight/takeBorrow.js +25 -24
  81. package/lib/esm/actions/midnight/takeLend.js +25 -24
  82. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
  83. package/lib/esm/actions/midnight/takeWithdraw.js +25 -24
  84. package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
  85. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +100 -0
  86. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
  87. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
  88. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
  89. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +1 -0
  90. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
  91. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  92. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
  93. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
  94. package/lib/esm/actions/vaultV1/migrateToV2.js +8 -8
  95. package/lib/esm/blue/abis.d.ts +1 -1
  96. package/lib/esm/blue/abis.js +1 -1
  97. package/lib/esm/blue/entities.d.ts +4 -4
  98. package/lib/esm/blue/entities.js +2 -2
  99. package/lib/esm/blue/errors.d.ts +2 -2
  100. package/lib/esm/blue/errors.js +2 -2
  101. package/lib/esm/blue/fetch.d.ts +2 -2
  102. package/lib/esm/blue/fetch.js +2 -2
  103. package/lib/esm/blue/utils.d.ts +1 -1
  104. package/lib/esm/blue/utils.js +1 -1
  105. package/lib/esm/entities/index.d.ts +5 -5
  106. package/lib/esm/entities/index.js +2 -2
  107. package/lib/esm/entities/midnight/midnight.d.ts +77 -3
  108. package/lib/esm/entities/midnight/midnight.js +176 -2
  109. package/lib/esm/entities/midnight/types.d.ts +16 -0
  110. package/lib/esm/entities/vaultV2/vaultV2.d.ts +8 -33
  111. package/lib/esm/entities/vaultV2/vaultV2.js +1 -33
  112. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
  113. package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
  114. package/lib/esm/errors.d.ts +4 -4
  115. package/lib/esm/errors.js +4 -4
  116. package/lib/esm/fetch.d.ts +2 -2
  117. package/lib/esm/fetch.js +2 -2
  118. package/lib/esm/helpers/deadShares.js +1 -3
  119. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +1 -0
  120. package/lib/esm/helpers/signAndVerifyTypedData.js +13 -6
  121. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
  122. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +124 -0
  123. package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +14 -0
  124. package/lib/esm/helpers/validateMidnightCollateralBatch.js +24 -0
  125. package/lib/esm/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
  126. package/lib/esm/helpers/validateMidnightCollateralSupplies.js +24 -0
  127. package/lib/esm/helpers/validatePositiveInput.d.ts +10 -0
  128. package/lib/esm/helpers/validatePositiveInput.js +14 -0
  129. package/lib/esm/midnight/errors.d.ts +1 -2
  130. package/lib/esm/midnight/errors.js +1 -2
  131. package/lib/esm/types/action.d.ts +18 -3
  132. package/lib/esm/types/error.d.ts +23 -2
  133. package/lib/esm/types/error.js +40 -3
  134. package/lib/esm/utils.d.ts +2 -2
  135. package/lib/esm/utils.js +2 -2
  136. package/package.json +6 -6
@@ -65,9 +65,7 @@ export interface VaultV2Actions {
65
65
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
66
66
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
67
67
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
68
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or when the vault's
69
- * liquidity adapter is a Midnight adapter (it cannot receive vault allocations, so no deposit
70
- * fits and `max` is `0n`).
68
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
71
69
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
72
70
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
73
71
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -149,9 +147,7 @@ export interface VaultV2Actions {
149
147
  * @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
150
148
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
151
149
  * at any `getRequirements()` call.
152
- * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation,
153
- * or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
154
- * idle assets.
150
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
155
151
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
156
152
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
157
153
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
@@ -217,24 +213,7 @@ export interface VaultV2Actions {
217
213
  * @throws {NonPositiveInputError} when `shares` is not positive.
218
214
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
219
215
  * requirement resolution.
220
- * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256, or from
221
- * `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
222
- * are worth more than the vault's idle assets.
223
- * @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
224
- * @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
225
- * configured factory.
226
- * @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
227
- * adapters uses an unsupported adapter class.
228
- * @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
229
- * is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
230
- * unsupported IRM.
231
- * @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
232
- * adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
233
- * allocation data.
234
- * @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
235
- * adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
236
- * @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
237
- * liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
216
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
238
217
  * @throws {NegativeInputError} when `referralFeePct` is negative.
239
218
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
240
219
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
@@ -242,7 +221,7 @@ export interface VaultV2Actions {
242
221
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
243
222
  * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
244
223
  * contract has no code at its registered address.
245
- * @throws {viem.BaseError} from `getRequirements()` when a vault-state, allowance, nonce, `eth_chainId`, or
224
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
246
225
  * `eth_getCode` read fails.
247
226
  * @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
248
227
  * `getData()` has unusable decimals.
@@ -320,11 +299,9 @@ export interface VaultV2Actions {
320
299
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
321
300
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
322
301
  * requirement resolution.
323
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter, including
324
- * a vault that mixes Blue and Midnight adapters.
302
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
325
303
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
326
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
327
- * including a Midnight adapter.
304
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
328
305
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
329
306
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
330
307
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -449,11 +426,9 @@ export interface VaultV2Actions {
449
426
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
450
427
  * requirement resolution.
451
428
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
452
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter,
453
- * including a vault that mixes Blue and Midnight adapters.
429
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
454
430
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
455
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
456
- * including a Midnight adapter.
431
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
457
432
  * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
458
433
  * another adapter.
459
434
  * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
@@ -18,11 +18,6 @@ const index_js_4 = require("../requirements/index.js");
18
18
  // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
19
19
  // accrual model stays well-defined inside it.
20
20
  const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
21
- /**
22
- * Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
23
- * vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
24
- */
25
- const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
26
21
  /** Binds a viem client to a Vault V2 vault's action builders. */
27
22
  class MorphoVaultV2 {
28
23
  client;
@@ -81,13 +76,6 @@ class MorphoVaultV2 {
81
76
  // The native path must target the chain's registered wrapped-native asset.
82
77
  (0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
83
78
  }
84
- if (isMidnightLiquidityAdapter(vaultData)) {
85
- throw new index_js_3.InputExceedsMaxError({
86
- field: funding.value > 0n ? "nativeAmount" : "amount",
87
- value: funding.assets,
88
- max: 0n,
89
- });
90
- }
91
79
  const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
92
80
  const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
93
81
  vaultData,
@@ -168,14 +156,6 @@ class MorphoVaultV2 {
168
156
  throw new index_js_3.NonPositiveInputError("amount", amount);
169
157
  // Reject values outside the ABI range before resolving any requirements.
170
158
  (0, validate_js_1.validateUint256Field)("amount", amount);
171
- if (isMidnightLiquidityAdapter(vaultData) &&
172
- amount > vaultData.assetBalance) {
173
- throw new index_js_3.InputExceedsMaxError({
174
- field: "amount",
175
- value: amount,
176
- max: vaultData.assetBalance,
177
- });
178
- }
179
159
  const createdAt = morpho_ts_1.Time.timestamp();
180
160
  const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
181
161
  if (deadline <= createdAt)
@@ -256,20 +236,8 @@ class MorphoVaultV2 {
256
236
  if (deadline <= now)
257
237
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
258
238
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
259
- const vaultData = await this.getData();
260
- if (isMidnightLiquidityAdapter(vaultData)) {
261
- // Onchain redeem accrues interest before converting shares to assets.
262
- const { vault: accrued } = vaultData.accrueInterest(now);
263
- if (accrued.toAssets(shares) > accrued.assetBalance) {
264
- throw new index_js_3.InputExceedsMaxError({
265
- field: "shares",
266
- value: shares,
267
- max: accrued.toShares(accrued.assetBalance),
268
- });
269
- }
270
- }
271
239
  return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
272
- vaultData,
240
+ vaultData: await this.getData(),
273
241
  version: "vaultV2",
274
242
  owner: userAddress,
275
243
  chainId: this.chainId,
@@ -56,9 +56,8 @@ export interface InputVaultV2BlueReallocationData {
56
56
  /**
57
57
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
58
58
  *
59
- * Constructor inputs are cloned, except Midnight adapter snapshots: those are
60
- * shared by reference and must be treated as read-only. Every simulated
61
- * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
59
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
60
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
62
61
  * denominator outside the durable snapshot while applying reallocations in
63
62
  * contract order. Penalty donations update simulated vault accounting but are
64
63
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -132,8 +131,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
132
131
  /**
133
132
  * Clones the complete simulation snapshot.
134
133
  *
135
- * @returns A deep clone of this simulation state. Midnight adapter snapshots are
136
- * shared by reference and must be treated as read-only.
134
+ * @returns A deep clone of this simulation state.
137
135
  * @example
138
136
  * ```ts
139
137
  * import { markets } from "@morpho-org/morpho-test";
@@ -90,10 +90,6 @@ const cloneAccrualVault = (vault, markets) => new blue_sdk_1.AccrualVault({
90
90
  position: clonePosition(position, markets),
91
91
  })));
92
92
  const cloneAdapter = (adapter, markets) => {
93
- // BluePublicAllocator never moves Midnight liquidity, and reallocation never mutates a Midnight
94
- // adapter, so its read-only snapshot is shared as-is.
95
- if (adapter.type === "VaultV2MidnightAdapter")
96
- return adapter;
97
93
  const base = {
98
94
  address: adapter.address,
99
95
  parentVault: adapter.parentVault,
@@ -141,9 +137,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
141
137
  /**
142
138
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
143
139
  *
144
- * Constructor inputs are cloned, except Midnight adapter snapshots: those are
145
- * shared by reference and must be treated as read-only. Every simulated
146
- * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
140
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
141
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
147
142
  * denominator outside the durable snapshot while applying reallocations in
148
143
  * contract order. Penalty donations update simulated vault accounting but are
149
144
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -287,8 +282,7 @@ class VaultV2BlueReallocationData {
287
282
  /**
288
283
  * Clones the complete simulation snapshot.
289
284
  *
290
- * @returns A deep clone of this simulation state. Midnight adapter snapshots are
291
- * shared by reference and must be treated as read-only.
285
+ * @returns A deep clone of this simulation state.
292
286
  * @example
293
287
  * ```ts
294
288
  * import { markets } from "@morpho-org/morpho-test";
@@ -1,7 +1,7 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, InvalidVaultV2MidnightAdapterMarketsError as InvalidBlueVaultV2MidnightAdapterMarketsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
package/lib/cjs/errors.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnresolvedBlockNumberError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueVaultV2MidnightAdapterMarketsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
- exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = void 0;
3
+ exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.InvalidMidnightEcrecoverSignatureError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
+ exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
7
7
  Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
8
8
  Object.defineProperty(exports, "InvalidBlueMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidMarketParamsError; } });
9
- Object.defineProperty(exports, "InvalidBlueVaultV2MidnightAdapterMarketsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidVaultV2MidnightAdapterMarketsError; } });
10
9
  Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
11
10
  Object.defineProperty(exports, "UnknownBlueDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
12
11
  Object.defineProperty(exports, "UnknownBlueFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
@@ -35,16 +34,19 @@ Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, g
35
34
  Object.defineProperty(exports, "Permit2ExpirationOutOfRangeError", { enumerable: true, get: function () { return blue_sdk_viem_1.Permit2ExpirationOutOfRangeError; } });
36
35
  Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
37
36
  Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
38
- Object.defineProperty(exports, "UnresolvedBlockNumberError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnresolvedBlockNumberError; } });
39
37
  Object.defineProperty(exports, "UnsupportedPermitDomainExtensionsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError; } });
40
38
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
41
39
  Object.defineProperty(exports, "MidnightChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
40
+ Object.defineProperty(exports, "InvalidMidnightEcrecoverSignatureError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureError; } });
42
41
  Object.defineProperty(exports, "InvalidMidnightEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
43
42
  Object.defineProperty(exports, "InvalidMidnightMarketParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMarketParameterError; } });
44
43
  Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiQuoteTargetError; } });
45
44
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
46
45
  Object.defineProperty(exports, "InvalidMidnightOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
47
46
  Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
47
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
48
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
49
+ Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
48
50
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
49
51
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
50
52
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -67,9 +69,6 @@ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { re
67
69
  Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return morpho_ts_1.DivisionByZeroError; } });
68
70
  Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return morpho_ts_1.InvalidAddressError; } });
69
71
  Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
70
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
71
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
72
- Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
73
72
  Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
74
73
  Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
75
74
  Object.defineProperty(exports, "RetriesExhaustedError", { enumerable: true, get: function () { return morpho_ts_1.RetriesExhaustedError; } });
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/cjs/fetch.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2MidnightAdapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2MidnightAdapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
3
+ exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
4
4
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  Object.defineProperty(exports, "fetchBlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualPosition; } });
6
6
  Object.defineProperty(exports, "fetchAccrualVault", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVault; } });
7
7
  Object.defineProperty(exports, "fetchAccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2; } });
8
8
  Object.defineProperty(exports, "fetchAccrualVaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2Adapter; } });
9
- Object.defineProperty(exports, "fetchAccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MidnightAdapter; } });
10
9
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1Adapter; } });
11
10
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1AdapterV2; } });
12
11
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoVaultV1Adapter; } });
@@ -30,7 +29,6 @@ Object.defineProperty(exports, "fetchVaultV2Adapter", { enumerable: true, get: f
30
29
  Object.defineProperty(exports, "fetchVaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BlueMarketPublicAllocatorConfig; } });
31
30
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorConfig; } });
32
31
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorData", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorData; } });
33
- Object.defineProperty(exports, "fetchVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MidnightAdapter; } });
34
32
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1Adapter; } });
35
33
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1AdapterV2; } });
36
34
  Object.defineProperty(exports, "fetchVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoVaultV1Adapter; } });
@@ -156,8 +156,6 @@ function validateVaultV2DeadShares(vault, path = []) {
156
156
  return cap;
157
157
  };
158
158
  for (const adapter of vault.accrualAdapters) {
159
- if (adapter instanceof blue_sdk_1.AccrualVaultV2MidnightAdapter)
160
- continue;
161
159
  if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
162
160
  const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
163
161
  if (capOf(id, adapter.address) > 0n)
@@ -16,6 +16,7 @@ import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
16
16
  * @throws {AddressMismatchError} when the wallet client account differs from `userAddress`.
17
17
  * @throws {ChainIdMismatchError} when the wallet client targets a different chain than the typed-data domain.
18
18
  * @throws {InvalidSignatureError} when the signature does not recover to `userAddress`.
19
+ * @throws {MalformedSignatureError} when verification throws; preserves the original error as `cause` with redacted signature diagnostics. Extends `InvalidSignatureError`.
19
20
  * @example
20
21
  * ```ts
21
22
  * import { signAndVerifyTypedData } from "@morpho-org/morpho-sdk";
@@ -22,6 +22,7 @@ const validate_js_1 = require("./validate.js");
22
22
  * @throws {AddressMismatchError} when the wallet client account differs from `userAddress`.
23
23
  * @throws {ChainIdMismatchError} when the wallet client targets a different chain than the typed-data domain.
24
24
  * @throws {InvalidSignatureError} when the signature does not recover to `userAddress`.
25
+ * @throws {MalformedSignatureError} when verification throws; preserves the original error as `cause` with redacted signature diagnostics. Extends `InvalidSignatureError`.
25
26
  * @example
26
27
  * ```ts
27
28
  * import { signAndVerifyTypedData } from "@morpho-org/morpho-sdk";
@@ -45,11 +46,17 @@ const signAndVerifyTypedData = async (params) => {
45
46
  ...typedData,
46
47
  account,
47
48
  });
48
- const isValid = await (0, viem_1.verifyTypedData)({
49
- ...typedData,
50
- address: userAddress,
51
- signature,
52
- });
49
+ let isValid;
50
+ try {
51
+ isValid = await (0, viem_1.verifyTypedData)({
52
+ ...typedData,
53
+ address: userAddress,
54
+ signature,
55
+ });
56
+ }
57
+ catch (cause) {
58
+ throw new index_js_1.MalformedSignatureError({ signature, cause });
59
+ }
53
60
  if (!isValid) {
54
61
  throw new index_js_1.InvalidSignatureError();
55
62
  }
@@ -0,0 +1,68 @@
1
+ import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
2
+ /**
3
+ * Validates publication content after snapshot and hex-shape validation.
4
+ *
5
+ * @param params - Publication, chain deployment, and groups cancelled by this bundle.
6
+ * @returns Nothing when publication content and funding inputs are valid.
7
+ * @throws {InvalidTreeError} when the root is zero, payload empty, or groups empty.
8
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
9
+ * @throws {MidnightCalldataEncodingError} when the ratifier or collateral market address is malformed.
10
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not supported.
11
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is cancelled.
12
+ * @throws {NonPositiveInputError} when Blue funding or a collateral supply is not positive.
13
+ * @throws {InputExceedsMaxError} when funding or collateral supply totals exceed uint128.
14
+ * @throws {EmptyMidnightCollateralSuppliesError} when collateral supplies are empty.
15
+ * @throws {ChainIdMismatchError} when the collateral market targets another chain.
16
+ * @throws {MidnightMarketAddressMismatchError} when its Midnight deployment differs.
17
+ * @throws {UnknownCollateralIndexError} when a supply index is not configured.
18
+ * @internal
19
+ */
20
+ export declare const validateMidnightCancelAndMakePublication: ({ publication, chainId, cancelledGroups, }: {
21
+ readonly publication: NonNullable<MidnightCancelAndMakeParams["publication"]>;
22
+ readonly chainId: number;
23
+ readonly cancelledGroups: ReadonlySet<string>;
24
+ }) => void;
25
+ /**
26
+ * Copies validated publication fields and supplies zero ABI defaults for omitted steps.
27
+ *
28
+ * @param publication - Snapshotted publication, or undefined for cancellation only.
29
+ * @returns ABI defaults and copied publication fields, without mutating the input.
30
+ * @internal
31
+ */
32
+ export declare const normalizeMidnightCancelAndMakePublication: (publication: MidnightCancelAndMakeParams["publication"]) => {
33
+ supplies: {
34
+ collateralIndex: bigint;
35
+ assets: bigint;
36
+ }[];
37
+ blueSupply: {
38
+ market: {
39
+ loanToken: `0x${string}`;
40
+ collateralToken: `0x${string}`;
41
+ oracle: `0x${string}`;
42
+ irm: `0x${string}`;
43
+ lltv: bigint;
44
+ };
45
+ assets: bigint;
46
+ callbackSalt: `0x${string}`;
47
+ } | undefined;
48
+ signature: import("../index.js").MidnightRootActivationSignature;
49
+ blueMarket: {
50
+ readonly loanToken: "0x0000000000000000000000000000000000000000";
51
+ readonly collateralToken: "0x0000000000000000000000000000000000000000";
52
+ readonly oracle: "0x0000000000000000000000000000000000000000";
53
+ readonly irm: "0x0000000000000000000000000000000000000000";
54
+ readonly lltv: 0n;
55
+ } | {
56
+ loanToken: `0x${string}`;
57
+ collateralToken: `0x${string}`;
58
+ oracle: `0x${string}`;
59
+ irm: `0x${string}`;
60
+ lltv: bigint;
61
+ };
62
+ assetsToPark: bigint;
63
+ callbackSalt: `0x${string}`;
64
+ ratifier: `0x${string}`;
65
+ root: `0x${string}`;
66
+ groups: `0x${string}`[];
67
+ payload: `0x${string}`;
68
+ };
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMidnightCancelAndMakePublication = exports.validateMidnightCancelAndMakePublication = 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 index_js_1 = require("../types/index.js");
8
+ const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
9
+ const validateMidnightBounds_js_1 = require("./validateMidnightBounds.js");
10
+ const validateMidnightCollateralSupplies_js_1 = require("./validateMidnightCollateralSupplies.js");
11
+ const validateMidnightMarket_js_1 = require("./validateMidnightMarket.js");
12
+ const validatePositiveInput_js_1 = require("./validatePositiveInput.js");
13
+ /** Blue market argument for `MidnightBundlesV2` calls that park no loan assets. */
14
+ const emptyBlueMarket = {
15
+ loanToken: viem_1.zeroAddress,
16
+ collateralToken: viem_1.zeroAddress,
17
+ oracle: viem_1.zeroAddress,
18
+ irm: viem_1.zeroAddress,
19
+ lltv: 0n,
20
+ };
21
+ /**
22
+ * Validates publication content after snapshot and hex-shape validation.
23
+ *
24
+ * @param params - Publication, chain deployment, and groups cancelled by this bundle.
25
+ * @returns Nothing when publication content and funding inputs are valid.
26
+ * @throws {InvalidTreeError} when the root is zero, payload empty, or groups empty.
27
+ * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
28
+ * @throws {MidnightCalldataEncodingError} when the ratifier or collateral market address is malformed.
29
+ * @throws {UnsupportedMidnightAuthorizationTargetError} when the ratifier is not supported.
30
+ * @throws {MidnightReplacementGroupCancelledError} when a published group is cancelled.
31
+ * @throws {NonPositiveInputError} when Blue funding or a collateral supply is not positive.
32
+ * @throws {InputExceedsMaxError} when funding or collateral supply totals exceed uint128.
33
+ * @throws {EmptyMidnightCollateralSuppliesError} when collateral supplies are empty.
34
+ * @throws {ChainIdMismatchError} when the collateral market targets another chain.
35
+ * @throws {MidnightMarketAddressMismatchError} when its Midnight deployment differs.
36
+ * @throws {UnknownCollateralIndexError} when a supply index is not configured.
37
+ * @internal
38
+ */
39
+ const validateMidnightCancelAndMakePublication = ({ publication, chainId, cancelledGroups, }) => {
40
+ if (publication.root === viem_1.zeroHash) {
41
+ throw new midnight_sdk_1.InvalidTreeError("Offer root cannot be zero.");
42
+ }
43
+ if (publication.payload === "0x") {
44
+ throw new midnight_sdk_1.InvalidTreeError("Offer payload cannot be empty.");
45
+ }
46
+ if (publication.groups.length === 0) {
47
+ throw new midnight_sdk_1.InvalidTreeError("Offer groups cannot be empty.");
48
+ }
49
+ const { priceRatifierV1, rateRatifierV1 } = (0, morpho_ts_1.getChainAddresses)(chainId);
50
+ const supportedTargets = [priceRatifierV1, rateRatifierV1].filter((target) => target != null);
51
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)("publication.ratifier", publication.ratifier);
52
+ if (!supportedTargets.some((target) => (0, viem_1.isAddressEqual)(publication.ratifier, target))) {
53
+ throw new index_js_1.UnsupportedMidnightAuthorizationTargetError({
54
+ authorized: publication.ratifier,
55
+ chainId,
56
+ supportedTargets,
57
+ });
58
+ }
59
+ for (const group of publication.groups) {
60
+ if (cancelledGroups.has(group.toLowerCase())) {
61
+ throw new index_js_1.MidnightReplacementGroupCancelledError({ group });
62
+ }
63
+ }
64
+ if (publication.blueSupply != null) {
65
+ // Validation only; rejects non-positive Blue supply amounts.
66
+ (0, validatePositiveInput_js_1.validatePositiveInput)("blueSupply.assets", publication.blueSupply.assets);
67
+ (0, validateMidnightBounds_js_1.validateMidnightUint128Field)("blueSupply.assets", publication.blueSupply.assets);
68
+ }
69
+ if (publication.collateral != null) {
70
+ if (publication.collateral.supplies.length === 0) {
71
+ throw new index_js_1.EmptyMidnightCollateralSuppliesError();
72
+ }
73
+ (0, validateMidnightMarket_js_1.validateMidnightMarket)({
74
+ market: publication.collateral.market,
75
+ chainId,
76
+ });
77
+ // Validation only; checks supply entries and their per-index totals.
78
+ (0, validateMidnightCollateralSupplies_js_1.validateMidnightCollateralSupplies)({
79
+ market: publication.collateral.market,
80
+ field: "collateral.supplies",
81
+ supplies: publication.collateral.supplies,
82
+ });
83
+ }
84
+ };
85
+ exports.validateMidnightCancelAndMakePublication = validateMidnightCancelAndMakePublication;
86
+ /**
87
+ * Copies validated publication fields and supplies zero ABI defaults for omitted steps.
88
+ *
89
+ * @param publication - Snapshotted publication, or undefined for cancellation only.
90
+ * @returns ABI defaults and copied publication fields, without mutating the input.
91
+ * @internal
92
+ */
93
+ const normalizeMidnightCancelAndMakePublication = (publication) => {
94
+ const supplies = (publication?.collateral?.supplies ?? []).map(({ collateralIndex, assets }) => ({ collateralIndex, assets }));
95
+ const blueSupply = publication?.blueSupply == null
96
+ ? undefined
97
+ : {
98
+ market: {
99
+ loanToken: publication.blueSupply.market.loanToken,
100
+ collateralToken: publication.blueSupply.market.collateralToken,
101
+ oracle: publication.blueSupply.market.oracle,
102
+ irm: publication.blueSupply.market.irm,
103
+ lltv: publication.blueSupply.market.lltv,
104
+ },
105
+ assets: publication.blueSupply.assets,
106
+ callbackSalt: publication.blueSupply.callbackSalt,
107
+ };
108
+ const signature = publication?.rootSignature ?? {
109
+ height: 0n,
110
+ nonce: 0n,
111
+ deadline: 0n,
112
+ v: 0,
113
+ r: viem_1.zeroHash,
114
+ s: viem_1.zeroHash,
115
+ };
116
+ return {
117
+ supplies,
118
+ blueSupply,
119
+ signature,
120
+ blueMarket: blueSupply?.market ?? emptyBlueMarket,
121
+ assetsToPark: blueSupply?.assets ?? 0n,
122
+ callbackSalt: blueSupply?.callbackSalt ?? viem_1.zeroHash,
123
+ ratifier: publication?.ratifier ?? viem_1.zeroAddress,
124
+ root: publication?.root ?? viem_1.zeroHash,
125
+ groups: [...(publication?.groups ?? [])],
126
+ payload: publication?.payload ?? "0x",
127
+ };
128
+ };
129
+ exports.normalizeMidnightCancelAndMakePublication = normalizeMidnightCancelAndMakePublication;
@@ -0,0 +1,14 @@
1
+ import type { MidnightCollateralTransfer } from "../types/action.js";
2
+ /**
3
+ * Rejects empty batches and repeated collateral indexes.
4
+ * @internal
5
+ * @param transfers - Ordered collateral transfers.
6
+ * @param emptyError - Operation-specific error thrown for an empty batch.
7
+ * @returns Nothing.
8
+ * @throws {DuplicateMidnightCollateralIndexError} when an index appears twice.
9
+ * @example
10
+ * ```ts
11
+ * validateMidnightCollateralBatch(supplies, new EmptyMidnightCollateralSuppliesError());
12
+ * ```
13
+ */
14
+ export declare function validateMidnightCollateralBatch(transfers: readonly MidnightCollateralTransfer[], emptyError: Error): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMidnightCollateralBatch = validateMidnightCollateralBatch;
4
+ const error_js_1 = require("../types/error.js");
5
+ /**
6
+ * Rejects empty batches and repeated collateral indexes.
7
+ * @internal
8
+ * @param transfers - Ordered collateral transfers.
9
+ * @param emptyError - Operation-specific error thrown for an empty batch.
10
+ * @returns Nothing.
11
+ * @throws {DuplicateMidnightCollateralIndexError} when an index appears twice.
12
+ * @example
13
+ * ```ts
14
+ * validateMidnightCollateralBatch(supplies, new EmptyMidnightCollateralSuppliesError());
15
+ * ```
16
+ */
17
+ function validateMidnightCollateralBatch(transfers, emptyError) {
18
+ if (transfers.length === 0)
19
+ throw emptyError;
20
+ const indexes = new Set();
21
+ for (const { collateralIndex } of transfers) {
22
+ if (indexes.has(collateralIndex)) {
23
+ throw new error_js_1.DuplicateMidnightCollateralIndexError(collateralIndex);
24
+ }
25
+ indexes.add(collateralIndex);
26
+ }
27
+ }