@morpho-org/morpho-sdk 9.1.0 → 9.3.0-next.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 (112) hide show
  1. package/README.md +5 -1
  2. package/lib/cjs/abis.d.ts +2 -2
  3. package/lib/cjs/abis.js +7 -1
  4. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  5. package/lib/cjs/actions/midnight/index.js +1 -0
  6. package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +50 -0
  7. package/lib/cjs/actions/midnight/withdrawCollateral.js +105 -0
  8. package/lib/cjs/blue/abis.d.ts +1 -1
  9. package/lib/cjs/blue/abis.js +5 -1
  10. package/lib/cjs/blue/constants.d.ts +1 -1
  11. package/lib/cjs/blue/constants.js +2 -1
  12. package/lib/cjs/blue/entities.d.ts +4 -4
  13. package/lib/cjs/blue/entities.js +3 -1
  14. package/lib/cjs/blue/errors.d.ts +2 -2
  15. package/lib/cjs/blue/errors.js +5 -1
  16. package/lib/cjs/blue/fetch.d.ts +2 -2
  17. package/lib/cjs/blue/fetch.js +3 -1
  18. package/lib/cjs/blue/utils.d.ts +1 -1
  19. package/lib/cjs/blue/utils.js +2 -1
  20. package/lib/cjs/constants.d.ts +2 -2
  21. package/lib/cjs/constants.js +4 -1
  22. package/lib/cjs/entities/blue/blue.d.ts +71 -16
  23. package/lib/cjs/entities/blue/blue.js +32 -4
  24. package/lib/cjs/entities/index.d.ts +5 -5
  25. package/lib/cjs/entities/index.js +3 -1
  26. package/lib/cjs/entities/midnight/midnight.d.ts +58 -11
  27. package/lib/cjs/entities/midnight/midnight.js +103 -11
  28. package/lib/cjs/entities/midnight/publication.d.ts +2 -1
  29. package/lib/cjs/entities/midnight/publication.js +44 -64
  30. package/lib/cjs/entities/midnight/types.d.ts +8 -0
  31. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +8 -0
  32. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -0
  33. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +37 -9
  34. package/lib/cjs/entities/vaultV2/vaultV2.js +36 -1
  35. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +42 -7
  36. package/lib/cjs/entities/vaultV2BlueReallocationData.js +206 -35
  37. package/lib/cjs/errors.d.ts +4 -4
  38. package/lib/cjs/errors.js +10 -5
  39. package/lib/cjs/fetch.d.ts +2 -2
  40. package/lib/cjs/fetch.js +3 -1
  41. package/lib/cjs/helpers/constant.d.ts +7 -0
  42. package/lib/cjs/helpers/constant.js +8 -1
  43. package/lib/cjs/helpers/deadShares.d.ts +82 -0
  44. package/lib/cjs/helpers/deadShares.js +202 -0
  45. package/lib/cjs/helpers/index.d.ts +2 -1
  46. package/lib/cjs/helpers/index.js +7 -1
  47. package/lib/cjs/midnight/abis.d.ts +1 -1
  48. package/lib/cjs/midnight/abis.js +3 -1
  49. package/lib/cjs/midnight/errors.d.ts +2 -1
  50. package/lib/cjs/midnight/errors.js +5 -4
  51. package/lib/cjs/types/action.d.ts +10 -1
  52. package/lib/cjs/types/error.d.ts +54 -5
  53. package/lib/cjs/types/error.js +60 -6
  54. package/lib/cjs/types/sharedLiquidity.d.ts +10 -6
  55. package/lib/cjs/utils.d.ts +2 -2
  56. package/lib/cjs/utils.js +4 -2
  57. package/lib/esm/abis.d.ts +2 -2
  58. package/lib/esm/abis.js +2 -2
  59. package/lib/esm/actions/midnight/index.d.ts +1 -0
  60. package/lib/esm/actions/midnight/index.js +1 -0
  61. package/lib/esm/actions/midnight/withdrawCollateral.d.ts +50 -0
  62. package/lib/esm/actions/midnight/withdrawCollateral.js +101 -0
  63. package/lib/esm/blue/abis.d.ts +1 -1
  64. package/lib/esm/blue/abis.js +1 -1
  65. package/lib/esm/blue/constants.d.ts +1 -1
  66. package/lib/esm/blue/constants.js +1 -1
  67. package/lib/esm/blue/entities.d.ts +4 -4
  68. package/lib/esm/blue/entities.js +2 -2
  69. package/lib/esm/blue/errors.d.ts +2 -2
  70. package/lib/esm/blue/errors.js +2 -2
  71. package/lib/esm/blue/fetch.d.ts +2 -2
  72. package/lib/esm/blue/fetch.js +2 -2
  73. package/lib/esm/blue/utils.d.ts +1 -1
  74. package/lib/esm/blue/utils.js +1 -1
  75. package/lib/esm/constants.d.ts +2 -2
  76. package/lib/esm/constants.js +2 -2
  77. package/lib/esm/entities/blue/blue.d.ts +71 -16
  78. package/lib/esm/entities/blue/blue.js +34 -6
  79. package/lib/esm/entities/index.d.ts +5 -5
  80. package/lib/esm/entities/index.js +2 -2
  81. package/lib/esm/entities/midnight/midnight.d.ts +58 -11
  82. package/lib/esm/entities/midnight/midnight.js +105 -13
  83. package/lib/esm/entities/midnight/publication.d.ts +2 -1
  84. package/lib/esm/entities/midnight/publication.js +45 -65
  85. package/lib/esm/entities/midnight/types.d.ts +8 -0
  86. package/lib/esm/entities/vaultV1/vaultV1.d.ts +8 -0
  87. package/lib/esm/entities/vaultV1/vaultV1.js +5 -0
  88. package/lib/esm/entities/vaultV2/vaultV2.d.ts +37 -9
  89. package/lib/esm/entities/vaultV2/vaultV2.js +36 -1
  90. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +42 -7
  91. package/lib/esm/entities/vaultV2BlueReallocationData.js +206 -35
  92. package/lib/esm/errors.d.ts +4 -4
  93. package/lib/esm/errors.js +4 -4
  94. package/lib/esm/fetch.d.ts +2 -2
  95. package/lib/esm/fetch.js +2 -2
  96. package/lib/esm/helpers/constant.d.ts +7 -0
  97. package/lib/esm/helpers/constant.js +7 -0
  98. package/lib/esm/helpers/deadShares.d.ts +82 -0
  99. package/lib/esm/helpers/deadShares.js +197 -0
  100. package/lib/esm/helpers/index.d.ts +2 -1
  101. package/lib/esm/helpers/index.js +2 -1
  102. package/lib/esm/midnight/abis.d.ts +1 -1
  103. package/lib/esm/midnight/abis.js +1 -1
  104. package/lib/esm/midnight/errors.d.ts +2 -1
  105. package/lib/esm/midnight/errors.js +2 -1
  106. package/lib/esm/types/action.d.ts +10 -1
  107. package/lib/esm/types/error.d.ts +54 -5
  108. package/lib/esm/types/error.js +57 -5
  109. package/lib/esm/types/sharedLiquidity.d.ts +10 -6
  110. package/lib/esm/utils.d.ts +2 -2
  111. package/lib/esm/utils.js +2 -2
  112. package/package.json +9 -8
@@ -26,6 +26,16 @@ export interface InputVaultV2BlueReallocationData {
26
26
  * defaults to the latest market/vault `lastUpdate`.
27
27
  */
28
28
  readonly timestamp?: BigIntish;
29
+ /**
30
+ * Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
31
+ * Explicit balances increase with idle-sourced reallocations in returned
32
+ * post-states. Sizing has zero margin over the snapshot balance, so activity
33
+ * on other Blue markets with the same loan token can make a plan revert;
34
+ * refetch close to submission. A missing token uses summed non-negative
35
+ * snapshot-market supply-minus-borrow only to size plans; balance-based
36
+ * rejection requires an explicit balance.
37
+ */
38
+ readonly blueBalances?: Readonly<Record<Address, BigIntish | undefined>>;
29
39
  /** Markets indexed by market id. */
30
40
  readonly markets?: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
31
41
  /** Accrued Vault V2 entities indexed by vault address. */
@@ -46,8 +56,9 @@ export interface InputVaultV2BlueReallocationData {
46
56
  /**
47
57
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
48
58
  *
49
- * Constructor inputs are cloned. Every simulated reallocation returns a new
50
- * instance. Planning keeps the transaction-scoped `firstTotalAssets`
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`
51
62
  * denominator outside the durable snapshot while applying reallocations in
52
63
  * contract order. Penalty donations update simulated vault accounting but are
53
64
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -83,10 +94,22 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
83
94
  private readonly mutableVaults;
84
95
  /** Mutable allocation state used only by cloned simulation transitions. */
85
96
  private readonly mutableAllocations;
97
+ /** Mutable Blue token balances used only by cloned simulation transitions. */
98
+ private readonly mutableBlueBalances;
86
99
  /** Chain id associated with this snapshot. */
87
100
  readonly chainId: number;
88
101
  /** Timestamp of the block the state was fetched at. */
89
102
  readonly timestamp?: bigint;
103
+ /**
104
+ * Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
105
+ * Explicit balances increase with idle-sourced reallocations in returned
106
+ * post-states. Sizing has zero margin over the snapshot balance, so activity
107
+ * on other Blue markets with the same loan token can make a plan revert;
108
+ * refetch close to submission. A missing token uses summed non-negative
109
+ * snapshot-market supply-minus-borrow only to size plans; balance-based
110
+ * rejection requires an explicit balance.
111
+ */
112
+ readonly blueBalances: Readonly<Record<Address, bigint | undefined>>;
90
113
  /** Markets indexed by market id. */
91
114
  readonly markets: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
92
115
  /** Vault V2 entities indexed by address. */
@@ -109,7 +132,8 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
109
132
  /**
110
133
  * Clones the complete simulation snapshot.
111
134
  *
112
- * @returns A deep clone of this simulation state.
135
+ * @returns A deep clone of this simulation state. Midnight adapter snapshots are
136
+ * shared by reference and must be treated as read-only.
113
137
  * @example
114
138
  * ```ts
115
139
  * import { markets } from "@morpho-org/morpho-test";
@@ -367,8 +391,9 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
367
391
  * Without `options.operation`, discovers every friendly call. With an
368
392
  * operation, penalty tiers are considered ascending, starting with free
369
393
  * vaults. The free tier aims to bring the target market back to 90%
370
- * utilization; positive tiers cover only the remaining absolute shortfall
371
- * (borrows minus supply). Within each tier, source markets go to the
394
+ * utilization; positive tiers cover the remaining absolute shortfall or,
395
+ * when larger, Blue's loan-token balance deficit while the penalty is
396
+ * flash-loaned. Within each tier, source markets go to the
372
397
  * friendly source utilization (90% by default) before 100%. Free capacity
373
398
  * inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
374
399
  * it instead. Discovery and liquidity getters still count every vault up to
@@ -382,6 +407,16 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
382
407
  * The planner includes the referral fee and its allocator-leg penalties in
383
408
  * destination debt, so penalized legs also cover their own penalty.
384
409
  * Refinance never uses vaults with a 100% penalty.
410
+ * BlueBundlesV1 flash-loans the plan's penalty from Blue before executing
411
+ * reallocation legs. When an explicit `blueBalances` value is supplied, plans
412
+ * throw `InsufficientSharedLiquidityError` if Blue cannot fund that flash
413
+ * loan or a market-sourced leg's withdrawal before later idle legs arrive.
414
+ * Legs are not reordered. A missing balance falls back to summed snapshot-
415
+ * market liquidity only to size plans and may make them larger; it cannot
416
+ * cause rejection for Blue-balance constraints.
417
+ * Sizing has zero margin over the snapshot balance; activity on other Blue
418
+ * markets with the same loan token can make a plan revert. Refetch close to
419
+ * submission; there is no balance-buffer option.
385
420
  * Friendly source utilization defaults to 90% and is configurable through
386
421
  * `options.maxWithdrawalUtilization`. Market/vault state and the returned
387
422
  * post-state stay at `timestamp`. An enabled operation that needs no
@@ -429,7 +464,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
429
464
  * @returns Flat action-ready reallocations and their post-simulation state.
430
465
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
431
466
  * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
432
- * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
467
+ * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
433
468
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
434
469
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
435
470
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -438,7 +473,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
438
473
  * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
439
474
  * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
440
475
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
441
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall and, for refinance, its planned allocator penalties.
476
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund the penalty flash loan, an earlier market-sourced withdrawal, or the final operation transfer.
442
477
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
443
478
  * @example
444
479
  * ```ts
@@ -90,6 +90,10 @@ 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;
93
97
  const base = {
94
98
  address: adapter.address,
95
99
  parentVault: adapter.parentVault,
@@ -137,8 +141,9 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
137
141
  /**
138
142
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
139
143
  *
140
- * Constructor inputs are cloned. Every simulated reallocation returns a new
141
- * instance. Planning keeps the transaction-scoped `firstTotalAssets`
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`
142
147
  * denominator outside the durable snapshot while applying reallocations in
143
148
  * contract order. Penalty donations update simulated vault accounting but are
144
149
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -174,10 +179,22 @@ class VaultV2BlueReallocationData {
174
179
  mutableVaults;
175
180
  /** Mutable allocation state used only by cloned simulation transitions. */
176
181
  mutableAllocations;
182
+ /** Mutable Blue token balances used only by cloned simulation transitions. */
183
+ mutableBlueBalances;
177
184
  /** Chain id associated with this snapshot. */
178
185
  chainId;
179
186
  /** Timestamp of the block the state was fetched at. */
180
187
  timestamp;
188
+ /**
189
+ * Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
190
+ * Explicit balances increase with idle-sourced reallocations in returned
191
+ * post-states. Sizing has zero margin over the snapshot balance, so activity
192
+ * on other Blue markets with the same loan token can make a plan revert;
193
+ * refetch close to submission. A missing token uses summed non-negative
194
+ * snapshot-market supply-minus-borrow only to size plans; balance-based
195
+ * rejection requires an explicit balance.
196
+ */
197
+ blueBalances;
181
198
  /** Markets indexed by market id. */
182
199
  markets;
183
200
  /** Vault V2 entities indexed by address. */
@@ -204,9 +221,11 @@ class VaultV2BlueReallocationData {
204
221
  this.mutableMarkets = {};
205
222
  this.mutableVaults = {};
206
223
  this.mutableAllocations = {};
224
+ this.mutableBlueBalances = {};
207
225
  this.markets = this.mutableMarkets;
208
226
  this.vaults = this.mutableVaults;
209
227
  this.allocations = this.mutableAllocations;
228
+ this.blueBalances = this.mutableBlueBalances;
210
229
  if (isClone) {
211
230
  this.publicAllocatorConfigs = input.publicAllocatorConfigs;
212
231
  this.activeAdapters = input.activeAdapters;
@@ -243,6 +262,10 @@ class VaultV2BlueReallocationData {
243
262
  this.mutableMarkets[marketId] =
244
263
  market == null ? undefined : new blue_sdk_1.Market({ ...market });
245
264
  }
265
+ for (const [token, balance] of Object.entries(input.blueBalances ?? {})) {
266
+ this.mutableBlueBalances[token] =
267
+ balance == null ? undefined : BigInt(balance);
268
+ }
246
269
  for (const [address, vault] of Object.entries(input.vaults ?? {})) {
247
270
  const clonedVault = vault == null
248
271
  ? undefined
@@ -264,7 +287,8 @@ class VaultV2BlueReallocationData {
264
287
  /**
265
288
  * Clones the complete simulation snapshot.
266
289
  *
267
- * @returns A deep clone of this simulation state.
290
+ * @returns A deep clone of this simulation state. Midnight adapter snapshots are
291
+ * shared by reference and must be treated as read-only.
268
292
  * @example
269
293
  * ```ts
270
294
  * import { markets } from "@morpho-org/morpho-test";
@@ -575,8 +599,9 @@ class VaultV2BlueReallocationData {
575
599
  * Without `options.operation`, discovers every friendly call. With an
576
600
  * operation, penalty tiers are considered ascending, starting with free
577
601
  * vaults. The free tier aims to bring the target market back to 90%
578
- * utilization; positive tiers cover only the remaining absolute shortfall
579
- * (borrows minus supply). Within each tier, source markets go to the
602
+ * utilization; positive tiers cover the remaining absolute shortfall or,
603
+ * when larger, Blue's loan-token balance deficit while the penalty is
604
+ * flash-loaned. Within each tier, source markets go to the
580
605
  * friendly source utilization (90% by default) before 100%. Free capacity
581
606
  * inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
582
607
  * it instead. Discovery and liquidity getters still count every vault up to
@@ -590,6 +615,16 @@ class VaultV2BlueReallocationData {
590
615
  * The planner includes the referral fee and its allocator-leg penalties in
591
616
  * destination debt, so penalized legs also cover their own penalty.
592
617
  * Refinance never uses vaults with a 100% penalty.
618
+ * BlueBundlesV1 flash-loans the plan's penalty from Blue before executing
619
+ * reallocation legs. When an explicit `blueBalances` value is supplied, plans
620
+ * throw `InsufficientSharedLiquidityError` if Blue cannot fund that flash
621
+ * loan or a market-sourced leg's withdrawal before later idle legs arrive.
622
+ * Legs are not reordered. A missing balance falls back to summed snapshot-
623
+ * market liquidity only to size plans and may make them larger; it cannot
624
+ * cause rejection for Blue-balance constraints.
625
+ * Sizing has zero margin over the snapshot balance; activity on other Blue
626
+ * markets with the same loan token can make a plan revert. Refetch close to
627
+ * submission; there is no balance-buffer option.
593
628
  * Friendly source utilization defaults to 90% and is configurable through
594
629
  * `options.maxWithdrawalUtilization`. Market/vault state and the returned
595
630
  * post-state stay at `timestamp`. An enabled operation that needs no
@@ -637,7 +672,7 @@ class VaultV2BlueReallocationData {
637
672
  * @returns Flat action-ready reallocations and their post-simulation state.
638
673
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
639
674
  * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
640
- * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
675
+ * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
641
676
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
642
677
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
643
678
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -646,7 +681,7 @@ class VaultV2BlueReallocationData {
646
681
  * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
647
682
  * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
648
683
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
649
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall and, for refinance, its planned allocator penalties.
684
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund the penalty flash loan, an earlier market-sourced withdrawal, or the final operation transfer.
650
685
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
651
686
  * @example
652
687
  * ```ts
@@ -719,6 +754,31 @@ class VaultV2BlueReallocationData {
719
754
  : [...options.reallocatableVaults],
720
755
  };
721
756
  const market = this.getMarket(marketId).accrueInterest(timestamp);
757
+ const blueBalanceKey = findAddressKey(this.mutableBlueBalances, market.params.loanToken);
758
+ const explicitBlueBalance = blueBalanceKey == null
759
+ ? undefined
760
+ : this.mutableBlueBalances[blueBalanceKey];
761
+ const hasExplicitBlueBalance = explicitBlueBalance !== undefined;
762
+ const blueBalance = explicitBlueBalance ??
763
+ Object.values(this.mutableMarkets).reduce((total, snapshotMarket) => snapshotMarket != null &&
764
+ (0, viem_1.isAddressEqual)(snapshotMarket.params.loanToken, market.params.loanToken)
765
+ ? total +
766
+ blue_sdk_1.MathLib.zeroFloorSub(snapshotMarket.totalSupplyAssets, snapshotMarket.totalBorrowAssets)
767
+ : total, 0n);
768
+ const getTransferShortfall = (reallocations) => {
769
+ const penaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(reallocations);
770
+ if (penaltyAssets === 0n)
771
+ return 0n;
772
+ let shortfall = blue_sdk_1.MathLib.zeroFloorSub(penaltyAssets, blueBalance);
773
+ let balance = blue_sdk_1.MathLib.zeroFloorSub(blueBalance, penaltyAssets);
774
+ for (const { from, assets } of reallocations) {
775
+ if (from.type === "idle")
776
+ balance += assets;
777
+ else
778
+ shortfall = blue_sdk_1.MathLib.max(shortfall, blue_sdk_1.MathLib.zeroFloorSub(assets, balance));
779
+ }
780
+ return shortfall;
781
+ };
722
782
  if (type === "withdraw" && amount > market.totalSupplyAssets) {
723
783
  throw new index_js_1.ReallocationWithdrawExceedsMarketSupplyError({
724
784
  marketId,
@@ -760,25 +820,30 @@ class VaultV2BlueReallocationData {
760
820
  let data = this.clone();
761
821
  let context = createSimulationContext();
762
822
  let remainingShortfall = absoluteShortfall;
823
+ let accountingShortfall = absoluteShortfall;
763
824
  let allocatorCapBoundTargets = new Set();
764
825
  let idleBoundVaults = new Set();
765
826
  for (const penalty of penaltyTiers) {
766
827
  if (type === "refinance" && penalty === blue_sdk_1.MathLib.WAD)
767
828
  continue;
768
829
  let isFriendlyPass = true;
830
+ let triedFullCapacityAttempt = false;
769
831
  for (const utilization of [maxWithdrawalUtilization, blue_sdk_1.MathLib.WAD]) {
770
832
  const isFreeFriendlyPass = penalty === 0n && isFriendlyPass;
771
833
  isFriendlyPass = false;
772
834
  if (remainingShortfall === 0n && !isFreeFriendlyPass)
773
835
  continue;
774
- let passMaxAssets = isFreeFriendlyPass
775
- ? maxAssets
776
- : remainingShortfall;
777
- const retryPaidPass = type === "refinance" && penalty > 0n;
778
- if (retryPaidPass) {
779
- passMaxAssets = blue_sdk_1.MathLib.mulDivUp(remainingShortfall, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - penalty);
780
- }
836
+ let passMaxAssets = type === "refinance" && penalty > 0n
837
+ ? blue_sdk_1.MathLib.mulDivUp(remainingShortfall, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - penalty)
838
+ : isFreeFriendlyPass
839
+ ? maxAssets
840
+ : remainingShortfall;
841
+ const retryPaidPass = penalty > 0n;
781
842
  let lo = retryPaidPass ? passMaxAssets - 1n : 0n;
843
+ let tryFullCapacityAttempt = false;
844
+ let isFullCapacityRetryPath = false;
845
+ const beforePassRemainingShortfall = remainingShortfall;
846
+ const beforePassAccountingShortfall = accountingShortfall;
782
847
  // Grow by grossed-up gaps, bisect to the smallest found, and keep the best for non-monotonic shared-cap fitting.
783
848
  const passStart = retryPaidPass
784
849
  ? {
@@ -789,9 +854,12 @@ class VaultV2BlueReallocationData {
789
854
  }
790
855
  : undefined;
791
856
  let previousPassReallocatedAssets = 0n;
857
+ let previousPhysicalShortfall;
792
858
  let hi;
793
859
  let bestAttempt;
794
860
  while (true) {
861
+ const isFullCapacityAttempt = tryFullCapacityAttempt;
862
+ tryFullCapacityAttempt = false;
795
863
  if (passStart != null) {
796
864
  data = passStart.data.clone();
797
865
  context = passStart.context;
@@ -803,7 +871,7 @@ class VaultV2BlueReallocationData {
803
871
  reserves,
804
872
  marketId,
805
873
  maxWithdrawalUtilization: utilization,
806
- maxAssets: passMaxAssets,
874
+ maxAssets: isFullCapacityAttempt ? undefined : passMaxAssets,
807
875
  capAccrualBuffer,
808
876
  allocatorCapHeadroom: headroom,
809
877
  penalty,
@@ -831,23 +899,56 @@ class VaultV2BlueReallocationData {
831
899
  const supply = type === "withdraw"
832
900
  ? currentMarket.totalSupplyAssets - amount
833
901
  : currentMarket.totalSupplyAssets;
834
- remainingShortfall = borrow > supply ? borrow - supply : 0n;
902
+ accountingShortfall = borrow > supply ? borrow - supply : 0n;
903
+ const penaltyForPhysicalShortfall = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(reallocations);
904
+ const idleAssetsForPhysicalShortfall = reallocations.reduce((total, { from, assets }) => from.type === "idle" ? total + assets : total, 0n);
905
+ const physicalShortfall = penaltyForPhysicalShortfall === 0n
906
+ ? 0n
907
+ : blue_sdk_1.MathLib.zeroFloorSub((type === "refinance"
908
+ ? amount + feeAssets + penaltyForPhysicalShortfall
909
+ : amount) + penaltyForPhysicalShortfall, blueBalance + idleAssetsForPhysicalShortfall);
910
+ remainingShortfall = blue_sdk_1.MathLib.max(accountingShortfall, physicalShortfall);
911
+ const attemptTransferShortfall = hasExplicitBlueBalance && isFullCapacityRetryPath
912
+ ? getTransferShortfall(reallocations)
913
+ : 0n;
914
+ const attemptCoversShortfall = remainingShortfall === 0n;
835
915
  const passReallocatedAssets = pass.reallocations.reduce((total, { assets }) => total + assets, 0n);
836
916
  if (passStart == null)
837
917
  break;
838
- if (bestAttempt == null ||
839
- remainingShortfall < bestAttempt.remainingShortfall ||
840
- (remainingShortfall === bestAttempt.remainingShortfall &&
841
- passReallocatedAssets < bestAttempt.passReallocatedAssets))
918
+ if (isFullCapacityAttempt)
919
+ passMaxAssets = passReallocatedAssets;
920
+ const improvesAccounting = accountingShortfall < beforePassAccountingShortfall;
921
+ const attemptPriority = hasExplicitBlueBalance
922
+ ? [0n, remainingShortfall, 0n, passReallocatedAssets]
923
+ : [
924
+ improvesAccounting ? 0n : 1n,
925
+ improvesAccounting ? accountingShortfall : 0n,
926
+ remainingShortfall,
927
+ passReallocatedAssets,
928
+ ];
929
+ const previousBestAttempt = bestAttempt;
930
+ let isBetterAttempt = previousBestAttempt == null;
931
+ if (previousBestAttempt != null) {
932
+ const firstDifference = attemptPriority.findIndex((priority, index) => priority !== previousBestAttempt.priority[index]);
933
+ isBetterAttempt =
934
+ firstDifference !== -1 &&
935
+ attemptPriority[firstDifference] <
936
+ previousBestAttempt.priority[firstDifference];
937
+ }
938
+ if (isBetterAttempt &&
939
+ (!isFullCapacityRetryPath ||
940
+ (attemptCoversShortfall && attemptTransferShortfall === 0n)))
842
941
  bestAttempt = {
843
942
  data,
844
943
  context,
845
944
  reserves: cloneCapReserveState(reserves),
846
945
  reallocations: pass.reallocations,
847
946
  remainingShortfall,
947
+ accountingShortfall,
848
948
  passReallocatedAssets,
949
+ priority: attemptPriority,
849
950
  };
850
- if (remainingShortfall === 0n)
951
+ if (attemptCoversShortfall)
851
952
  hi = hi == null ? passMaxAssets : blue_sdk_1.MathLib.min(hi, passMaxAssets);
852
953
  else
853
954
  lo = blue_sdk_1.MathLib.max(lo, passMaxAssets);
@@ -857,18 +958,52 @@ class VaultV2BlueReallocationData {
857
958
  passMaxAssets = (lo + hi) / 2n;
858
959
  continue;
859
960
  }
860
- if (passReallocatedAssets <= previousPassReallocatedAssets)
961
+ if (isFullCapacityAttempt && !attemptCoversShortfall)
962
+ break;
963
+ if (accountingShortfall === 0n &&
964
+ previousPhysicalShortfall != null &&
965
+ physicalShortfall >= previousPhysicalShortfall) {
966
+ if (!triedFullCapacityAttempt &&
967
+ passReallocatedAssets === passMaxAssets) {
968
+ triedFullCapacityAttempt = true;
969
+ tryFullCapacityAttempt = true;
970
+ isFullCapacityRetryPath = true;
971
+ continue;
972
+ }
973
+ break;
974
+ }
975
+ previousPhysicalShortfall = physicalShortfall;
976
+ if (passReallocatedAssets <= previousPassReallocatedAssets ||
977
+ penalty === blue_sdk_1.MathLib.WAD)
861
978
  break;
862
979
  previousPassReallocatedAssets = passReallocatedAssets;
863
980
  passMaxAssets += blue_sdk_1.MathLib.mulDivUp(remainingShortfall, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - penalty);
864
981
  }
865
- if (passStart != null && bestAttempt != null) {
866
- data = bestAttempt.data;
867
- context = bestAttempt.context;
868
- reserves = cloneCapReserveState(bestAttempt.reserves);
869
- reallocations.length = passStart.reallocationCount;
870
- reallocations.push(...bestAttempt.reallocations);
871
- remainingShortfall = bestAttempt.remainingShortfall;
982
+ if (passStart != null) {
983
+ const improved = bestAttempt != null &&
984
+ (hasExplicitBlueBalance
985
+ ? bestAttempt.remainingShortfall < beforePassRemainingShortfall
986
+ : bestAttempt.accountingShortfall <
987
+ beforePassAccountingShortfall ||
988
+ bestAttempt.remainingShortfall <
989
+ beforePassRemainingShortfall);
990
+ if (improved && bestAttempt != null) {
991
+ data = bestAttempt.data;
992
+ context = bestAttempt.context;
993
+ reserves = cloneCapReserveState(bestAttempt.reserves);
994
+ reallocations.length = passStart.reallocationCount;
995
+ reallocations.push(...bestAttempt.reallocations);
996
+ remainingShortfall = bestAttempt.remainingShortfall;
997
+ accountingShortfall = bestAttempt.accountingShortfall;
998
+ }
999
+ else {
1000
+ data = passStart.data;
1001
+ context = passStart.context;
1002
+ reserves = cloneCapReserveState(passStart.reserves);
1003
+ reallocations.length = passStart.reallocationCount;
1004
+ remainingShortfall = beforePassRemainingShortfall;
1005
+ accountingShortfall = beforePassAccountingShortfall;
1006
+ }
872
1007
  }
873
1008
  }
874
1009
  }
@@ -881,16 +1016,28 @@ class VaultV2BlueReallocationData {
881
1016
  !(from.type === "idle" && idleBoundVaults.has(vault.toLowerCase())))
882
1017
  unboundAssets += assets;
883
1018
  }
1019
+ const penaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(reallocations);
1020
+ const idleAssets = reallocations.reduce((total, { from, assets }) => from.type === "idle" ? total + assets : total, 0n);
1021
+ const physicalShortfall = penaltyAssets === 0n
1022
+ ? 0n
1023
+ : blue_sdk_1.MathLib.zeroFloorSub((type === "refinance"
1024
+ ? amount + feeAssets + penaltyAssets
1025
+ : amount) + penaltyAssets, blueBalance + idleAssets);
1026
+ const transferShortfall = getTransferShortfall(reallocations);
1027
+ const coversAccountingShortfall = type === "refinance"
1028
+ ? reallocatedAssets >= absoluteShortfall + penaltyAssets
1029
+ : reallocatedAssets >= absoluteShortfall;
884
1030
  return {
885
1031
  reallocations,
886
1032
  data,
887
1033
  liquidityBound: allocatorCapBoundTargets.size > 0 || idleBoundVaults.size > 0,
888
1034
  reallocatedAssets,
889
1035
  unboundAssets,
890
- coversShortfall: type === "refinance"
891
- ? reallocatedAssets >=
892
- absoluteShortfall + (0, common_js_1.getBlueBundlesV1PenaltyAssets)(reallocations)
893
- : reallocatedAssets >= absoluteShortfall,
1036
+ physicalShortfall,
1037
+ coversShortfall: coversAccountingShortfall &&
1038
+ (type === "refinance" || penaltyAssets <= amount) &&
1039
+ (!hasExplicitBlueBalance ||
1040
+ (physicalShortfall === 0n && transferShortfall === 0n)),
894
1041
  };
895
1042
  };
896
1043
  // A leg that fills an allocator cap, or idle legs that together take
@@ -918,12 +1065,30 @@ class VaultV2BlueReallocationData {
918
1065
  available = selected.reallocatedAssets;
919
1066
  }
920
1067
  if (!selected.coversShortfall) {
1068
+ const selectedTransferShortfall = hasExplicitBlueBalance
1069
+ ? getTransferShortfall(selected.reallocations)
1070
+ : 0n;
1071
+ const selectedPenaltyAssets = (0, common_js_1.getBlueBundlesV1PenaltyAssets)(selected.reallocations);
1072
+ if (type !== "refinance" &&
1073
+ selectedPenaltyAssets > amount &&
1074
+ selected.reallocatedAssets >= absoluteShortfall &&
1075
+ (!hasExplicitBlueBalance ||
1076
+ (selected.physicalShortfall === 0n &&
1077
+ selectedTransferShortfall === 0n)))
1078
+ throw new index_js_1.InputExceedsMaxError({
1079
+ field: "reallocationPenaltyAssets",
1080
+ value: selectedPenaltyAssets,
1081
+ max: amount,
1082
+ });
921
1083
  throw new index_js_1.InsufficientSharedLiquidityError({
922
1084
  marketId,
923
- shortfall: absoluteShortfall +
1085
+ shortfall: blue_sdk_1.MathLib.max(absoluteShortfall +
924
1086
  (type === "refinance"
925
1087
  ? (0, common_js_1.getBlueBundlesV1PenaltyAssets)(selected.reallocations)
926
- : 0n),
1088
+ : 0n), selected.reallocatedAssets +
1089
+ (hasExplicitBlueBalance
1090
+ ? blue_sdk_1.MathLib.max(selected.physicalShortfall, selectedTransferShortfall)
1091
+ : 0n)),
927
1092
  available,
928
1093
  });
929
1094
  }
@@ -1572,6 +1737,12 @@ class VaultV2BlueReallocationData {
1572
1737
  }
1573
1738
  vault.assetBalance += reallocation.assets;
1574
1739
  }
1740
+ if (reallocation.from.type === "idle") {
1741
+ const blueBalanceKey = findAddressKey(data.mutableBlueBalances, targetMarket.params.loanToken);
1742
+ if (blueBalanceKey != null &&
1743
+ data.mutableBlueBalances[blueBalanceKey] != null)
1744
+ data.mutableBlueBalances[blueBalanceKey] += reallocation.assets;
1745
+ }
1575
1746
  if (firstTotalAssets == null) {
1576
1747
  // Vault V2's transient firstTotalAssets tracks the first allocation in a
1577
1748
  // transaction independently from elapsed time. Later allocations must not
@@ -1,7 +1,7 @@
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,
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,
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, 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";
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
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } 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";
package/lib/cjs/errors.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidnightMempoolValidationError = 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.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.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 = void 0;
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.BlueUnresolvedBlockNumberError = 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.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidPositionAccrualStateError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = 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; } });
9
10
  Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
10
11
  Object.defineProperty(exports, "UnknownBlueDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
11
12
  Object.defineProperty(exports, "UnknownBlueFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
@@ -34,6 +35,7 @@ Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, g
34
35
  Object.defineProperty(exports, "Permit2ExpirationOutOfRangeError", { enumerable: true, get: function () { return blue_sdk_viem_1.Permit2ExpirationOutOfRangeError; } });
35
36
  Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
36
37
  Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
38
+ Object.defineProperty(exports, "BlueUnresolvedBlockNumberError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnresolvedBlockNumberError; } });
37
39
  Object.defineProperty(exports, "UnsupportedPermitDomainExtensionsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError; } });
38
40
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
39
41
  Object.defineProperty(exports, "MidnightChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
@@ -43,9 +45,6 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
43
45
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
44
46
  Object.defineProperty(exports, "InvalidMidnightOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
45
47
  Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
46
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
47
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
48
- Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
49
48
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
50
49
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
51
50
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -68,5 +67,11 @@ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { re
68
67
  Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return morpho_ts_1.DivisionByZeroError; } });
69
68
  Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return morpho_ts_1.InvalidAddressError; } });
70
69
  Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
70
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
71
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
72
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
73
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
74
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
75
+ Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
71
76
  Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
72
77
  Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, 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, 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, fetchVaultV2MidnightAdapter, 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";