@morpho-org/morpho-sdk 9.3.0-next.0 → 9.4.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 (92) hide show
  1. package/README.md +6 -4
  2. package/lib/cjs/abis.d.ts +2 -2
  3. package/lib/cjs/abis.js +4 -5
  4. package/lib/cjs/actions/blue/index.d.ts +1 -0
  5. package/lib/cjs/actions/blue/index.js +1 -0
  6. package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +60 -0
  7. package/lib/cjs/actions/blue/withdrawBuyCallback.js +79 -0
  8. package/lib/cjs/blue/abis.d.ts +1 -1
  9. package/lib/cjs/blue/abis.js +3 -5
  10. package/lib/cjs/blue/entities.d.ts +4 -4
  11. package/lib/cjs/blue/entities.js +1 -3
  12. package/lib/cjs/blue/errors.d.ts +2 -2
  13. package/lib/cjs/blue/errors.js +1 -5
  14. package/lib/cjs/blue/fetch.d.ts +2 -2
  15. package/lib/cjs/blue/fetch.js +1 -3
  16. package/lib/cjs/blue/utils.d.ts +1 -1
  17. package/lib/cjs/blue/utils.js +1 -2
  18. package/lib/cjs/entities/blue/blue.d.ts +85 -9
  19. package/lib/cjs/entities/blue/blue.js +85 -3
  20. package/lib/cjs/entities/index.d.ts +4 -4
  21. package/lib/cjs/entities/index.js +1 -3
  22. package/lib/cjs/entities/midnight/midnight.d.ts +1 -2
  23. package/lib/cjs/entities/midnight/midnight.js +4 -5
  24. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
  25. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +15 -12
  26. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +0 -8
  27. package/lib/cjs/entities/vaultV1/vaultV1.js +0 -4
  28. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +9 -37
  29. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -36
  30. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
  31. package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
  32. package/lib/cjs/errors.d.ts +4 -4
  33. package/lib/cjs/errors.js +7 -10
  34. package/lib/cjs/fetch.d.ts +2 -2
  35. package/lib/cjs/fetch.js +1 -3
  36. package/lib/cjs/helpers/deadShares.d.ts +5 -4
  37. package/lib/cjs/helpers/deadShares.js +5 -6
  38. package/lib/cjs/midnight/abis.d.ts +1 -1
  39. package/lib/cjs/midnight/abis.js +2 -1
  40. package/lib/cjs/midnight/errors.d.ts +1 -2
  41. package/lib/cjs/midnight/errors.js +4 -5
  42. package/lib/cjs/types/action.d.ts +15 -1
  43. package/lib/cjs/types/error.d.ts +35 -6
  44. package/lib/cjs/types/error.js +42 -7
  45. package/lib/cjs/utils.d.ts +2 -2
  46. package/lib/cjs/utils.js +2 -4
  47. package/lib/esm/abis.d.ts +2 -2
  48. package/lib/esm/abis.js +2 -2
  49. package/lib/esm/actions/blue/index.d.ts +1 -0
  50. package/lib/esm/actions/blue/index.js +1 -0
  51. package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +60 -0
  52. package/lib/esm/actions/blue/withdrawBuyCallback.js +75 -0
  53. package/lib/esm/blue/abis.d.ts +1 -1
  54. package/lib/esm/blue/abis.js +1 -1
  55. package/lib/esm/blue/entities.d.ts +4 -4
  56. package/lib/esm/blue/entities.js +2 -2
  57. package/lib/esm/blue/errors.d.ts +2 -2
  58. package/lib/esm/blue/errors.js +2 -2
  59. package/lib/esm/blue/fetch.d.ts +2 -2
  60. package/lib/esm/blue/fetch.js +2 -2
  61. package/lib/esm/blue/utils.d.ts +1 -1
  62. package/lib/esm/blue/utils.js +1 -1
  63. package/lib/esm/entities/blue/blue.d.ts +85 -9
  64. package/lib/esm/entities/blue/blue.js +87 -5
  65. package/lib/esm/entities/index.d.ts +4 -4
  66. package/lib/esm/entities/index.js +2 -2
  67. package/lib/esm/entities/midnight/midnight.d.ts +1 -2
  68. package/lib/esm/entities/midnight/midnight.js +5 -6
  69. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +5 -4
  70. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +15 -12
  71. package/lib/esm/entities/vaultV1/vaultV1.d.ts +0 -8
  72. package/lib/esm/entities/vaultV1/vaultV1.js +0 -4
  73. package/lib/esm/entities/vaultV2/vaultV2.d.ts +9 -37
  74. package/lib/esm/entities/vaultV2/vaultV2.js +1 -36
  75. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
  76. package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
  77. package/lib/esm/errors.d.ts +4 -4
  78. package/lib/esm/errors.js +4 -4
  79. package/lib/esm/fetch.d.ts +2 -2
  80. package/lib/esm/fetch.js +2 -2
  81. package/lib/esm/helpers/deadShares.d.ts +5 -4
  82. package/lib/esm/helpers/deadShares.js +6 -7
  83. package/lib/esm/midnight/abis.d.ts +1 -1
  84. package/lib/esm/midnight/abis.js +1 -1
  85. package/lib/esm/midnight/errors.d.ts +1 -2
  86. package/lib/esm/midnight/errors.js +1 -2
  87. package/lib/esm/types/action.d.ts +15 -1
  88. package/lib/esm/types/error.d.ts +35 -6
  89. package/lib/esm/types/error.js +36 -6
  90. package/lib/esm/utils.d.ts +2 -2
  91. package/lib/esm/utils.js +2 -2
  92. package/package.json +6 -6
@@ -13,10 +13,11 @@ import { getUnusedPermit2Nonce } from "./getUnusedPermit2Nonce.js";
13
13
  * Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
14
14
  * a registered fixed bundles contract.
15
15
  *
16
- * Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
17
- * ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
18
- * as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
19
- * the same owner should pass explicit nonces.
16
+ * Returns no requirements when the direct bundles allowance covers the amount, even when
17
+ * signatures are supported. Otherwise reads only the state required by the selected path.
18
+ * Permit2 keeps the ERC-20 allowance on canonical Permit2 while the one-time signed transfer
19
+ * names the bundles contract as spender. The resolver picks the lowest unused unordered nonce
20
+ * by default; concurrent flows for the same owner should pass explicit nonces.
20
21
  *
21
22
  * @param viemClient - Connected viem client used for allowance and nonce reads.
22
23
  * @param params - Token requirement parameters.
@@ -119,6 +120,14 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
119
120
  if (params.amount === 0n)
120
121
  return [];
121
122
  await validateClientChainId(viemClient, params.chainId);
123
+ const allowance = await readContract(viemClient, {
124
+ abi: erc20Abi,
125
+ address: params.token,
126
+ functionName: "allowance",
127
+ args: [params.owner, params.spender],
128
+ });
129
+ if (allowance >= params.amount)
130
+ return [];
122
131
  const { permit2, dai } = getChainAddresses(params.chainId);
123
132
  if (params.supportSignature) {
124
133
  const isDai = isDefined(dai) && isAddressEqual(params.token, dai);
@@ -171,7 +180,7 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
171
180
  });
172
181
  }
173
182
  const wordPosition = permit2Nonce >> 8n;
174
- const [allowance, nonceBitmap] = await Promise.all([
183
+ const [permit2Allowance, nonceBitmap] = await Promise.all([
175
184
  readContract(viemClient, {
176
185
  abi: erc20Abi,
177
186
  address: params.token,
@@ -195,19 +204,13 @@ export const getBundlesTokenRequirements = async (viemClient, params) => {
195
204
  now: timestamp,
196
205
  state: {
197
206
  type: "permit2SignatureTransfer",
198
- permit2Allowance: allowance,
207
+ permit2Allowance,
199
208
  permit2Nonce,
200
209
  nonceBitmap,
201
210
  },
202
211
  });
203
212
  }
204
213
  }
205
- const allowance = await readContract(viemClient, {
206
- abi: erc20Abi,
207
- address: params.token,
208
- functionName: "allowance",
209
- args: [params.owner, params.spender],
210
- });
211
214
  return resolveBundlesTokenRequirements({
212
215
  token: params.token,
213
216
  spender: params.spender,
@@ -104,10 +104,6 @@ export interface VaultV1Actions {
104
104
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
105
105
  * // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
106
106
  * ```
107
- * @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
108
- * the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
109
- * @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
110
- * holds less than the required dead deposit.
111
107
  */
112
108
  deposit: (params: {
113
109
  readonly userAddress: Address;
@@ -461,10 +457,6 @@ export interface VaultV1Actions {
461
457
  * const tx = migration.buildTx(signatures);
462
458
  * // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
463
459
  * ```
464
- * @throws {MissingDeadSharesDataError} when `targetVault` lacks the dead-share, cap or adapter data
465
- * the dead-deposit check needs. The source Vault V1 is not checked.
466
- * @throws {InsufficientDeadSharesError} when `targetVault`, or a market or vault it can allocate
467
- * to, holds less than the required dead deposit.
468
460
  */
469
461
  migrateToV2: (params: {
470
462
  readonly userAddress: Address;
@@ -6,7 +6,6 @@ import { readContract } from "viem/actions";
6
6
  import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
7
7
  import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
8
8
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
9
- import { validateVaultV1DeadShares, validateVaultV2DeadShares, } from "../../helpers/deadShares.js";
10
9
  import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
11
10
  import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
12
11
  import { AmountAndSharesExclusiveError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
@@ -76,8 +75,6 @@ export class MorphoVaultV1 {
76
75
  // The native path must target the chain's registered wrapped-native asset.
77
76
  validateNativeVaultAsset(this.chainId, vaultAsset);
78
77
  }
79
- // Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
80
- validateVaultV1DeadShares(vaultData);
81
78
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
82
79
  const maxSharePrice = computeVaultMaxSharePrice({
83
80
  vaultData,
@@ -473,7 +470,6 @@ export class MorphoVaultV1 {
473
470
  referralFeeRecipient: params.referralFeeRecipient,
474
471
  });
475
472
  // Only the destination receives a deposit; the source vault is an exit.
476
- validateVaultV2DeadShares(params.targetVault);
477
473
  // V1 redeem accrues market interest and performance fees before converting shares.
478
474
  const grossAssets = assets ??
479
475
  params.sourceVault
@@ -69,9 +69,8 @@ export interface VaultV2Actions {
69
69
  * owner is consumed and none was passed explicitly.
70
70
  * @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
71
71
  * explicit Permit2 nonce is consumed.
72
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, when the vault's
73
- * liquidity adapter is a Midnight adapter (it cannot receive vault allocations, so no deposit
74
- * fits and `max` is `0n`), or from `getRequirements()` when the Permit2 nonce exceeds uint256.
72
+ * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
73
+ * `getRequirements()` when the Permit2 nonce exceeds uint256.
75
74
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
76
75
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
77
76
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -111,10 +110,6 @@ export interface VaultV2Actions {
111
110
  * const tx = action.buildTx(); // For a client configured with supportSignature: false.
112
111
  * // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
113
112
  * ```
114
- * @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
115
- * the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
116
- * @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
117
- * holds less than the required dead deposit.
118
113
  */
119
114
  deposit: (params: {
120
115
  readonly userAddress: Address;
@@ -157,9 +152,7 @@ export interface VaultV2Actions {
157
152
  * @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
158
153
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
159
154
  * at any `getRequirements()` call.
160
- * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation,
161
- * or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
162
- * idle assets.
155
+ * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
163
156
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
164
157
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
165
158
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
@@ -225,24 +218,7 @@ export interface VaultV2Actions {
225
218
  * @throws {NonPositiveInputError} when `shares` is not positive.
226
219
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
227
220
  * requirement resolution.
228
- * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256, or from
229
- * `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
230
- * are worth more than the vault's idle assets.
231
- * @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
232
- * @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
233
- * configured factory.
234
- * @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
235
- * adapters uses an unsupported adapter class.
236
- * @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
237
- * is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
238
- * unsupported IRM.
239
- * @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
240
- * adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
241
- * allocation data.
242
- * @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
243
- * adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
244
- * @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
245
- * liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
221
+ * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
246
222
  * @throws {NegativeInputError} when `referralFeePct` is negative.
247
223
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
248
224
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
@@ -250,7 +226,7 @@ export interface VaultV2Actions {
250
226
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
251
227
  * @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
252
228
  * contract has no code at its registered address.
253
- * @throws {viem.BaseError} from `getRequirements()` when a vault-state, allowance, nonce, `eth_chainId`, or
229
+ * @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
254
230
  * `eth_getCode` read fails.
255
231
  * @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
256
232
  * `getData()` has unusable decimals.
@@ -328,11 +304,9 @@ export interface VaultV2Actions {
328
304
  * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
329
305
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
330
306
  * requirement resolution.
331
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter, including
332
- * a vault that mixes Blue and Midnight adapters.
307
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
333
308
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
334
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
335
- * including a Midnight adapter.
309
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
336
310
  * @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
337
311
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
338
312
  * @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
@@ -457,11 +431,9 @@ export interface VaultV2Actions {
457
431
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
458
432
  * requirement resolution.
459
433
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
460
- * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter,
461
- * including a vault that mixes Blue and Midnight adapters.
434
+ * @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
462
435
  * @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
463
- * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2,
464
- * including a Midnight adapter.
436
+ * @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
465
437
  * @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
466
438
  * another adapter.
467
439
  * @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
@@ -6,7 +6,6 @@ import { readContract } from "viem/actions";
6
6
  import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
7
7
  import { encodeErc20Approval, encodeVaultSharesPermit, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
8
8
  import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
9
- import { validateVaultV2DeadShares } from "../../helpers/deadShares.js";
10
9
  import { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, MAX_SLIPPAGE_TOLERANCE, resolveVaultV2ForceWithdrawEligibility, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
11
10
  import { validateDeadline, validateNativeVaultAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
12
11
  import { AdapterNotPartOfVaultError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InKindRedeemZeroDeallocationError, InputExceedsMaxError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, VaultAddressMismatchError, VaultV2ForceWithdrawCoverageError, VaultV2ForceWithdrawFeeSharesExceedBurnError, VaultV2ForceWithdrawSharePriceBelowFloorError, VaultV2ForceWithdrawZeroSharePriceError, VaultV2ForceWithdrawZeroWithdrawalError, VaultV2SingleAdapterRequiredError, VaultV2UndecodableLiquidityDataError, VaultV2UnsupportedExitAdapterError, VaultV2UnsupportedLiquidityAdapterError, } from "../../types/index.js";
@@ -16,11 +15,6 @@ import { getBundlesTokenRequirements } from "../requirements/index.js";
16
15
  // Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
17
16
  // accrual model stays well-defined inside it.
18
17
  const VAULT_V2_FEE_PROJECTION_HORIZON = Time.s.from.y(1n);
19
- /**
20
- * Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
21
- * vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
22
- */
23
- const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
24
18
  /** Binds a viem client to a Vault V2 vault's action builders. */
25
19
  export class MorphoVaultV2 {
26
20
  client;
@@ -84,15 +78,6 @@ export class MorphoVaultV2 {
84
78
  // The native path must target the chain's registered wrapped-native asset.
85
79
  validateNativeVaultAsset(this.chainId, vaultAsset);
86
80
  }
87
- if (isMidnightLiquidityAdapter(vaultData)) {
88
- throw new InputExceedsMaxError({
89
- field: funding.value > 0n ? "nativeAmount" : "amount",
90
- value: funding.assets,
91
- max: 0n,
92
- });
93
- }
94
- // Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
95
- validateVaultV2DeadShares(vaultData);
96
81
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
97
82
  const maxSharePrice = computeVaultMaxSharePrice({
98
83
  vaultData,
@@ -176,14 +161,6 @@ export class MorphoVaultV2 {
176
161
  throw new NonPositiveInputError("amount", amount);
177
162
  // Reject values outside the ABI range before resolving any requirements.
178
163
  validateUint256Field("amount", amount);
179
- if (isMidnightLiquidityAdapter(vaultData) &&
180
- amount > vaultData.assetBalance) {
181
- throw new InputExceedsMaxError({
182
- field: "amount",
183
- value: amount,
184
- max: vaultData.assetBalance,
185
- });
186
- }
187
164
  const createdAt = Time.timestamp();
188
165
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
189
166
  if (deadline <= createdAt)
@@ -264,20 +241,8 @@ export class MorphoVaultV2 {
264
241
  if (deadline <= now)
265
242
  throw new ExpiredDeadlineError(deadline, now);
266
243
  await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
267
- const vaultData = await this.getData();
268
- if (isMidnightLiquidityAdapter(vaultData)) {
269
- // Onchain redeem accrues interest before converting shares to assets.
270
- const { vault: accrued } = vaultData.accrueInterest(now);
271
- if (accrued.toAssets(shares) > accrued.assetBalance) {
272
- throw new InputExceedsMaxError({
273
- field: "shares",
274
- value: shares,
275
- max: accrued.toShares(accrued.assetBalance),
276
- });
277
- }
278
- }
279
244
  return getVaultBundlesSharesRequirements(this.client.viemClient, {
280
- vaultData,
245
+ vaultData: await this.getData(),
281
246
  version: "vaultV2",
282
247
  owner: userAddress,
283
248
  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";
@@ -87,10 +87,6 @@ const cloneAccrualVault = (vault, markets) => new AccrualVault({
87
87
  position: clonePosition(position, markets),
88
88
  })));
89
89
  const cloneAdapter = (adapter, markets) => {
90
- // BluePublicAllocator never moves Midnight liquidity, and reallocation never mutates a Midnight
91
- // adapter, so its read-only snapshot is shared as-is.
92
- if (adapter.type === "VaultV2MidnightAdapter")
93
- return adapter;
94
90
  const base = {
95
91
  address: adapter.address,
96
92
  parentVault: adapter.parentVault,
@@ -138,9 +134,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
138
134
  /**
139
135
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
140
136
  *
141
- * Constructor inputs are cloned, except Midnight adapter snapshots: those are
142
- * shared by reference and must be treated as read-only. Every simulated
143
- * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
137
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
138
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
144
139
  * denominator outside the durable snapshot while applying reallocations in
145
140
  * contract order. Penalty donations update simulated vault accounting but are
146
141
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -284,8 +279,7 @@ export class VaultV2BlueReallocationData {
284
279
  /**
285
280
  * Clones the complete simulation snapshot.
286
281
  *
287
- * @returns A deep clone of this simulation state. Midnight adapter snapshots are
288
- * shared by reference and must be treated as read-only.
282
+ * @returns A deep clone of this simulation state.
289
283
  * @example
290
284
  * ```ts
291
285
  * 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 as BlueUnresolvedBlockNumberError, 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, 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, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
package/lib/esm/errors.js CHANGED
@@ -1,6 +1,6 @@
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 as BlueUnresolvedBlockNumberError, 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";
6
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
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, 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
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
@@ -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/esm/fetch.js CHANGED
@@ -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";
@@ -55,15 +55,16 @@ export declare function validateVaultV1DeadShares(vault: AccrualVault, path?: De
55
55
  /**
56
56
  * Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
57
57
  * `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
58
- * `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
59
- * absolute cap) passing its own rule. Zero-cap entries are skipped.
58
+ * `1 / (10 * virtualShares)`, and each currently allocated Blue market or Vault V1 with a non-zero
59
+ * absolute cap passing its own rule. A market with a positive cap but no current allocation is not
60
+ * checked; a later reallocation can reach it.
60
61
  *
61
62
  * @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
62
63
  * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
63
- * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
64
+ * @returns Nothing; returns normally when the vault and its checked allocations pass.
64
65
  * @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
65
66
  * adapter the SDK cannot hydrate is missing.
66
- * @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
67
+ * @throws {InsufficientDeadSharesError} when the vault or a checked market or Vault V1 fails the rule.
67
68
  * @example
68
69
  * ```ts
69
70
  * import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
@@ -1,4 +1,4 @@
1
- import { AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
1
+ import { AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
2
2
  import { InsufficientDeadSharesError, MissingDeadSharesDataError, } from "../types/error.js";
3
3
  import { MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS } from "./constant.js";
4
4
  /**
@@ -84,15 +84,16 @@ export function validateVaultV1DeadShares(vault, path = []) {
84
84
  /**
85
85
  * Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
86
86
  * `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
87
- * `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
88
- * absolute cap) passing its own rule. Zero-cap entries are skipped.
87
+ * `1 / (10 * virtualShares)`, and each currently allocated Blue market or Vault V1 with a non-zero
88
+ * absolute cap passing its own rule. A market with a positive cap but no current allocation is not
89
+ * checked; a later reallocation can reach it.
89
90
  *
90
91
  * @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
91
92
  * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
92
- * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
93
+ * @returns Nothing; returns normally when the vault and its checked allocations pass.
93
94
  * @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
94
95
  * adapter the SDK cannot hydrate is missing.
95
- * @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
96
+ * @throws {InsufficientDeadSharesError} when the vault or a checked market or Vault V1 fails the rule.
96
97
  * @example
97
98
  * ```ts
98
99
  * import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
@@ -150,8 +151,6 @@ export function validateVaultV2DeadShares(vault, path = []) {
150
151
  return cap;
151
152
  };
152
153
  for (const adapter of vault.accrualAdapters) {
153
- if (adapter instanceof AccrualVaultV2MidnightAdapter)
154
- continue;
155
154
  if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter) {
156
155
  const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
157
156
  if (capOf(id, adapter.address) > 0n)
@@ -1 +1 @@
1
- export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
1
+ export { blueBuyCallbackAbi, blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
@@ -1 +1 @@
1
- export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
1
+ export { blueBuyCallbackAbi, blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
@@ -1,2 +1 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
- export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
@@ -1,2 +1 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
- export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
@@ -282,6 +282,20 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
282
282
  readonly deadline: bigint;
283
283
  }> {
284
284
  }
285
+ /**
286
+ * Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position,
287
+ * sent by the callback's owner.
288
+ */
289
+ export interface BlueWithdrawBuyCallbackAction extends BaseAction<"blueWithdrawBuyCallback", {
290
+ readonly market: Hex;
291
+ /** Supply shares burned: the callback's whole position. */
292
+ readonly shares: bigint;
293
+ /** BlueBuyCallback whose supply position is withdrawn. */
294
+ readonly onBehalf: Address;
295
+ /** Account receiving the withdrawn loan assets: the callback's owner. */
296
+ readonly receiver: Address;
297
+ }> {
298
+ }
285
299
  type BlueSupplyCollateralBorrowActionArgs = {
286
300
  readonly market: Hex;
287
301
  readonly collateralAssets: bigint;
@@ -510,7 +524,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
510
524
  * VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
511
525
  * consumers can `switch` exhaustively on it.
512
526
  */
513
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
527
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
514
528
  /**
515
529
  * Describes a single, immutable, deep-frozen transaction to submit on-chain:
516
530
  * the target `to`, native `value`, encoded call `data`, and the originating
@@ -1321,12 +1321,7 @@ export declare class MidnightOfferCallbackDataMismatchError extends Error {
1321
1321
  readonly actualCallbackData: Hex;
1322
1322
  });
1323
1323
  }
1324
- /**
1325
- * Thrown when loan assets would be parked in a Morpho Blue market with no existing supply.
1326
- *
1327
- * @deprecated `supplyBlueMakeLend` now throws `InsufficientDeadSharesError` or
1328
- * `MissingDeadSharesDataError` instead; kept exported so existing `instanceof` checks compile.
1329
- */
1324
+ /** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
1330
1325
  export declare class EmptyBlueParkingMarketError extends Error {
1331
1326
  constructor(params: {
1332
1327
  readonly marketId: MarketId;
@@ -1480,6 +1475,40 @@ export declare class WithdrawSharesExceedSupplyError extends Error {
1480
1475
  market: string;
1481
1476
  });
1482
1477
  }
1478
+ /** Thrown when a Blue withdrawal finds no supply shares to withdraw for the position owner. */
1479
+ export declare class EmptyBlueSupplyPositionError extends Error {
1480
+ constructor(params: {
1481
+ market: string;
1482
+ user: string;
1483
+ });
1484
+ }
1485
+ /** Thrown when a Blue withdrawal needs more assets than the market's available liquidity. */
1486
+ export declare class InsufficientBlueLiquidityError extends Error {
1487
+ constructor(params: {
1488
+ market: string;
1489
+ assets: bigint;
1490
+ liquidity: bigint;
1491
+ });
1492
+ }
1493
+ /** Thrown when an address is not a BlueBuyCallback created by the chain's registered factory. */
1494
+ export declare class NotBlueBuyCallbackError extends Error {
1495
+ constructor(callback: string);
1496
+ }
1497
+ /** Thrown when a BlueBuyCallback's `OWNER()` is not the account withdrawing its Blue position. */
1498
+ export declare class BlueBuyCallbackOwnerMismatchError extends Error {
1499
+ constructor(params: {
1500
+ callback: string;
1501
+ owner: string;
1502
+ userAddress: string;
1503
+ });
1504
+ }
1505
+ /** Thrown when Morpho Blue does not authorize an account to withdraw a BlueBuyCallback's position. */
1506
+ export declare class BlueBuyCallbackUnauthorizedError extends Error {
1507
+ constructor(params: {
1508
+ callback: string;
1509
+ userAddress: string;
1510
+ });
1511
+ }
1483
1512
  /**
1484
1513
  * Thrown when a Vault V2 reallocation planner receives a withdraw `amount` greater
1485
1514
  * than the target market's current `totalSupplyAssets` — the post-withdraw