@morpho-org/morpho-sdk 9.1.0-next.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +3 -1
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/borrow.d.ts +1 -0
  5. package/lib/cjs/actions/blue/borrow.js +1 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +1 -0
  7. package/lib/cjs/actions/blue/refinance.js +3 -0
  8. package/lib/cjs/actions/blue/repay.d.ts +1 -0
  9. package/lib/cjs/actions/blue/repay.js +1 -0
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
  12. package/lib/cjs/actions/blue/supply.d.ts +1 -0
  13. package/lib/cjs/actions/blue/supply.js +2 -0
  14. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
  15. package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
  16. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  17. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
  18. package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
  19. package/lib/cjs/actions/blue/withdraw.js +2 -0
  20. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
  21. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  23. package/lib/cjs/actions/midnight/takeLend.js +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  25. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  26. package/lib/cjs/blue/abis.d.ts +1 -1
  27. package/lib/cjs/blue/abis.js +1 -5
  28. package/lib/cjs/blue/entities.d.ts +4 -4
  29. package/lib/cjs/blue/entities.js +1 -3
  30. package/lib/cjs/blue/errors.d.ts +2 -2
  31. package/lib/cjs/blue/errors.js +2 -5
  32. package/lib/cjs/blue/fetch.d.ts +2 -2
  33. package/lib/cjs/blue/fetch.js +1 -3
  34. package/lib/cjs/blue/utils.d.ts +1 -1
  35. package/lib/cjs/blue/utils.js +1 -2
  36. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  37. package/lib/cjs/client/morphoViemExtension.js +1 -7
  38. package/lib/cjs/entities/blue/blue.d.ts +43 -7
  39. package/lib/cjs/entities/blue/blue.js +27 -3
  40. package/lib/cjs/entities/index.d.ts +4 -4
  41. package/lib/cjs/entities/index.js +1 -3
  42. package/lib/cjs/entities/midnight/midnight.d.ts +7 -5
  43. package/lib/cjs/entities/midnight/midnight.js +7 -5
  44. package/lib/cjs/entities/midnight/types.d.ts +8 -1
  45. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -34
  46. package/lib/cjs/entities/vaultV2/vaultV2.js +9 -38
  47. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +43 -18
  48. package/lib/cjs/entities/vaultV2BlueReallocationData.js +210 -79
  49. package/lib/cjs/errors.d.ts +4 -4
  50. package/lib/cjs/errors.js +6 -10
  51. package/lib/cjs/fetch.d.ts +2 -2
  52. package/lib/cjs/fetch.js +1 -3
  53. package/lib/cjs/helpers/validate.d.ts +11 -1
  54. package/lib/cjs/helpers/validate.js +17 -1
  55. package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
  56. package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
  57. package/lib/cjs/midnight/errors.d.ts +1 -2
  58. package/lib/cjs/midnight/errors.js +4 -5
  59. package/lib/cjs/types/error.d.ts +6 -0
  60. package/lib/cjs/types/error.js +9 -1
  61. package/lib/cjs/types/sharedLiquidity.d.ts +27 -11
  62. package/lib/cjs/utils.d.ts +2 -2
  63. package/lib/cjs/utils.js +2 -4
  64. package/lib/esm/abis.d.ts +1 -1
  65. package/lib/esm/abis.js +1 -1
  66. package/lib/esm/actions/blue/borrow.d.ts +1 -0
  67. package/lib/esm/actions/blue/borrow.js +1 -0
  68. package/lib/esm/actions/blue/refinance.d.ts +1 -0
  69. package/lib/esm/actions/blue/refinance.js +4 -1
  70. package/lib/esm/actions/blue/repay.d.ts +1 -0
  71. package/lib/esm/actions/blue/repay.js +1 -0
  72. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  73. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
  74. package/lib/esm/actions/blue/supply.d.ts +1 -0
  75. package/lib/esm/actions/blue/supply.js +3 -1
  76. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
  77. package/lib/esm/actions/blue/supplyCollateral.js +1 -0
  78. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  79. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
  80. package/lib/esm/actions/blue/withdraw.d.ts +1 -0
  81. package/lib/esm/actions/blue/withdraw.js +3 -1
  82. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
  83. package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
  84. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  85. package/lib/esm/actions/midnight/takeLend.js +1 -0
  86. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  87. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  88. package/lib/esm/blue/abis.d.ts +1 -1
  89. package/lib/esm/blue/abis.js +1 -1
  90. package/lib/esm/blue/entities.d.ts +4 -4
  91. package/lib/esm/blue/entities.js +2 -2
  92. package/lib/esm/blue/errors.d.ts +2 -2
  93. package/lib/esm/blue/errors.js +2 -2
  94. package/lib/esm/blue/fetch.d.ts +2 -2
  95. package/lib/esm/blue/fetch.js +2 -2
  96. package/lib/esm/blue/utils.d.ts +1 -1
  97. package/lib/esm/blue/utils.js +1 -1
  98. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  99. package/lib/esm/client/morphoViemExtension.js +1 -7
  100. package/lib/esm/entities/blue/blue.d.ts +43 -7
  101. package/lib/esm/entities/blue/blue.js +27 -3
  102. package/lib/esm/entities/index.d.ts +4 -4
  103. package/lib/esm/entities/index.js +2 -2
  104. package/lib/esm/entities/midnight/midnight.d.ts +7 -5
  105. package/lib/esm/entities/midnight/midnight.js +7 -5
  106. package/lib/esm/entities/midnight/types.d.ts +8 -1
  107. package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -34
  108. package/lib/esm/entities/vaultV2/vaultV2.js +10 -39
  109. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +43 -18
  110. package/lib/esm/entities/vaultV2BlueReallocationData.js +211 -80
  111. package/lib/esm/errors.d.ts +4 -4
  112. package/lib/esm/errors.js +4 -4
  113. package/lib/esm/fetch.d.ts +2 -2
  114. package/lib/esm/fetch.js +2 -2
  115. package/lib/esm/helpers/validate.d.ts +11 -1
  116. package/lib/esm/helpers/validate.js +15 -0
  117. package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
  118. package/lib/esm/helpers/validateTakeableOffers.js +13 -2
  119. package/lib/esm/midnight/errors.d.ts +1 -2
  120. package/lib/esm/midnight/errors.js +1 -2
  121. package/lib/esm/types/error.d.ts +6 -0
  122. package/lib/esm/types/error.js +7 -0
  123. package/lib/esm/types/sharedLiquidity.d.ts +27 -11
  124. package/lib/esm/utils.d.ts +2 -2
  125. package/lib/esm/utils.js +2 -2
  126. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
1
+ import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type BigIntish, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
2
2
  import { type Address, type Hash } from "viem";
3
3
  import type { VaultV2BluePublicAllocatorOptions, VaultV2BlueReallocation } from "../types/index.js";
4
4
  type ReadonlyMarketSnapshot = Readonly<Market>;
@@ -19,6 +19,13 @@ type ReadonlyVaultSnapshot = Readonly<Omit<AccrualVaultV2, "adapters" | "liquidi
19
19
  export interface InputVaultV2BlueReallocationData {
20
20
  /** Chain id associated with the fetched state. */
21
21
  readonly chainId: number;
22
+ /**
23
+ * Timestamp of the block the state was fetched at. When present, this is the
24
+ * default planning timestamp when `options.timestamp` is omitted, never
25
+ * earlier than the latest market/vault `lastUpdate`; when absent, planning
26
+ * defaults to the latest market/vault `lastUpdate`.
27
+ */
28
+ readonly timestamp?: BigIntish;
22
29
  /** Markets indexed by market id. */
23
30
  readonly markets?: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
24
31
  /** Accrued Vault V2 entities indexed by vault address. */
@@ -39,9 +46,8 @@ export interface InputVaultV2BlueReallocationData {
39
46
  /**
40
47
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
41
48
  *
42
- * Constructor inputs are cloned, except Midnight adapter snapshots: those are
43
- * shared by reference and must be treated as read-only. Every simulated
44
- * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
49
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
50
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
45
51
  * denominator outside the durable snapshot while applying reallocations in
46
52
  * contract order. Penalty donations update simulated vault accounting but are
47
53
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -79,6 +85,8 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
79
85
  private readonly mutableAllocations;
80
86
  /** Chain id associated with this snapshot. */
81
87
  readonly chainId: number;
88
+ /** Timestamp of the block the state was fetched at. */
89
+ readonly timestamp?: bigint;
82
90
  /** Markets indexed by market id. */
83
91
  readonly markets: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
84
92
  /** Vault V2 entities indexed by address. */
@@ -101,8 +109,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
101
109
  /**
102
110
  * Clones the complete simulation snapshot.
103
111
  *
104
- * @returns A deep clone of this simulation state. Midnight adapter snapshots are
105
- * shared by reference and must be treated as read-only.
112
+ * @returns A deep clone of this simulation state.
106
113
  * @example
107
114
  * ```ts
108
115
  * import { markets } from "@morpho-org/morpho-test";
@@ -358,16 +365,29 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
358
365
  * Computes Vault V2 BluePublicAllocator calls available for a target market.
359
366
  *
360
367
  * Without `options.operation`, discovers every friendly call. With an
361
- * operation, targets the amount required by that borrow or loan-asset
362
- * withdrawal and falls back to 100% source utilization only when friendly
363
- * liquidity cannot cover the absolute shortfall. A shared relative-cap lower
364
- * bound may require one call to exceed the targeted amount. Friendly source
365
- * utilization defaults to 90% and is configurable through
366
- * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
367
- * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
368
- * considered. Market/vault state and the returned post-state stay at
369
- * `timestamp`; only target-market cap checks reserve interest the vault's
370
- * existing allocation would accrue through `timestamp + capAccrualBuffer`
368
+ * operation, penalty tiers are considered ascending, starting with free
369
+ * 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
372
+ * friendly source utilization (90% by default) before 100%. Free capacity
373
+ * inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
374
+ * it instead. Discovery and liquidity getters still count every vault up to
375
+ * `options.maxPenalty`. A shared relative-cap lower bound may require one call
376
+ * to exceed the targeted amount. For `refinance`, compute the plan on the
377
+ * destination-market handle (for example,
378
+ * `client.morpho.blue(destination.marketParams, chainId)`), not the source
379
+ * handle. Pass the source position's `borrowAssets` accrued to
380
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
381
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
382
+ * The planner includes the referral fee and its allocator-leg penalties in
383
+ * destination debt, so penalized legs also cover their own penalty.
384
+ * Refinance never uses vaults with a 100% penalty.
385
+ * Friendly source utilization defaults to 90% and is configurable through
386
+ * `options.maxWithdrawalUtilization`. Market/vault state and the returned
387
+ * post-state stay at `timestamp`. An enabled operation that needs no
388
+ * reallocation still returns a clone accrued to `timestamp`. Only
389
+ * target-market cap checks reserve interest the vault's existing allocation
390
+ * would accrue through `timestamp + capAccrualBuffer`
371
391
  * (two hours by default; `0n` disables it). When an operation's plan would
372
392
  * come within `allocatorCapHeadroom` (1% of the cap by default) of a target
373
393
  * BluePublicAllocator cap, the plan is reduced to the larger of the
@@ -408,8 +428,9 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
408
428
  * every leg of a plan.
409
429
  * @returns Flat action-ready reallocations and their post-simulation state.
410
430
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
411
- * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
431
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
412
432
  * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
433
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
413
434
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
414
435
  * @throws {UnknownReallocationMarketError} when a required market is absent.
415
436
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -417,7 +438,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
417
438
  * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
418
439
  * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
419
440
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
420
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall.
441
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall and, for refinance, its planned allocator penalties.
421
442
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
422
443
  * @example
423
444
  * ```ts
@@ -452,6 +473,10 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
452
473
  readonly operation?: {
453
474
  readonly type: "borrow" | "withdraw";
454
475
  readonly amount: bigint;
476
+ } | {
477
+ readonly type: "refinance";
478
+ readonly amount: bigint;
479
+ readonly referralFeePct?: bigint;
455
480
  };
456
481
  }): {
457
482
  readonly reallocations: readonly VaultV2BlueReallocation[];
@@ -4,6 +4,7 @@ exports.VaultV2BlueReallocationData = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
+ const common_js_1 = require("../actions/blue/common.js");
7
8
  const constant_js_1 = require("../helpers/constant.js");
8
9
  const utilization_js_1 = require("../helpers/utilization.js");
9
10
  const index_js_1 = require("../types/index.js");
@@ -14,6 +15,17 @@ const createCapReserveState = (markets) => ({
14
15
  touchedPairs: new Map(),
15
16
  reserveByPairKey: new Map(),
16
17
  });
18
+ const cloneCapReserveState = (state) => {
19
+ const touchedPairs = new Map();
20
+ for (const [vault, pairs] of state.touchedPairs)
21
+ touchedPairs.set(vault, new Map(pairs));
22
+ return {
23
+ initialMarkets: { ...state.initialMarkets },
24
+ marketAccruals: new Map(state.marketAccruals),
25
+ touchedPairs,
26
+ reserveByPairKey: new Map(state.reserveByPairKey),
27
+ };
28
+ };
17
29
  /** Creates isolated transaction-scoped state for one simulation. @internal */
18
30
  const createSimulationContext = () => ({
19
31
  donatedPenaltyAssets: {},
@@ -78,10 +90,6 @@ const cloneAccrualVault = (vault, markets) => new blue_sdk_1.AccrualVault({
78
90
  position: clonePosition(position, markets),
79
91
  })));
80
92
  const cloneAdapter = (adapter, markets) => {
81
- // BluePublicAllocator never moves Midnight liquidity, and reallocation never mutates a Midnight
82
- // adapter, so its read-only snapshot is shared as-is.
83
- if (adapter.type === "VaultV2MidnightAdapter")
84
- return adapter;
85
93
  const base = {
86
94
  address: adapter.address,
87
95
  parentVault: adapter.parentVault,
@@ -129,9 +137,8 @@ const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
129
137
  /**
130
138
  * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
131
139
  *
132
- * Constructor inputs are cloned, except Midnight adapter snapshots: those are
133
- * shared by reference and must be treated as read-only. Every simulated
134
- * reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
140
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
141
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
135
142
  * denominator outside the durable snapshot while applying reallocations in
136
143
  * contract order. Penalty donations update simulated vault accounting but are
137
144
  * excluded from same-plan idle liquidity so round-up dust cannot create
@@ -169,6 +176,8 @@ class VaultV2BlueReallocationData {
169
176
  mutableAllocations;
170
177
  /** Chain id associated with this snapshot. */
171
178
  chainId;
179
+ /** Timestamp of the block the state was fetched at. */
180
+ timestamp;
172
181
  /** Markets indexed by market id. */
173
182
  markets;
174
183
  /** Vault V2 entities indexed by address. */
@@ -190,6 +199,8 @@ class VaultV2BlueReallocationData {
190
199
  constructor(input) {
191
200
  const isClone = input instanceof VaultV2BlueReallocationData;
192
201
  this.chainId = input.chainId;
202
+ this.timestamp =
203
+ input.timestamp == null ? undefined : BigInt(input.timestamp);
193
204
  this.mutableMarkets = {};
194
205
  this.mutableVaults = {};
195
206
  this.mutableAllocations = {};
@@ -253,8 +264,7 @@ class VaultV2BlueReallocationData {
253
264
  /**
254
265
  * Clones the complete simulation snapshot.
255
266
  *
256
- * @returns A deep clone of this simulation state. Midnight adapter snapshots are
257
- * shared by reference and must be treated as read-only.
267
+ * @returns A deep clone of this simulation state.
258
268
  * @example
259
269
  * ```ts
260
270
  * import { markets } from "@morpho-org/morpho-test";
@@ -563,16 +573,29 @@ class VaultV2BlueReallocationData {
563
573
  * Computes Vault V2 BluePublicAllocator calls available for a target market.
564
574
  *
565
575
  * Without `options.operation`, discovers every friendly call. With an
566
- * operation, targets the amount required by that borrow or loan-asset
567
- * withdrawal and falls back to 100% source utilization only when friendly
568
- * liquidity cannot cover the absolute shortfall. A shared relative-cap lower
569
- * bound may require one call to exceed the targeted amount. Friendly source
570
- * utilization defaults to 90% and is configurable through
571
- * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
572
- * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
573
- * considered. Market/vault state and the returned post-state stay at
574
- * `timestamp`; only target-market cap checks reserve interest the vault's
575
- * existing allocation would accrue through `timestamp + capAccrualBuffer`
576
+ * operation, penalty tiers are considered ascending, starting with free
577
+ * 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
580
+ * friendly source utilization (90% by default) before 100%. Free capacity
581
+ * inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
582
+ * it instead. Discovery and liquidity getters still count every vault up to
583
+ * `options.maxPenalty`. A shared relative-cap lower bound may require one call
584
+ * to exceed the targeted amount. For `refinance`, compute the plan on the
585
+ * destination-market handle (for example,
586
+ * `client.morpho.blue(destination.marketParams, chainId)`), not the source
587
+ * handle. Pass the source position's `borrowAssets` accrued to
588
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
589
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
590
+ * The planner includes the referral fee and its allocator-leg penalties in
591
+ * destination debt, so penalized legs also cover their own penalty.
592
+ * Refinance never uses vaults with a 100% penalty.
593
+ * Friendly source utilization defaults to 90% and is configurable through
594
+ * `options.maxWithdrawalUtilization`. Market/vault state and the returned
595
+ * post-state stay at `timestamp`. An enabled operation that needs no
596
+ * reallocation still returns a clone accrued to `timestamp`. Only
597
+ * target-market cap checks reserve interest the vault's existing allocation
598
+ * would accrue through `timestamp + capAccrualBuffer`
576
599
  * (two hours by default; `0n` disables it). When an operation's plan would
577
600
  * come within `allocatorCapHeadroom` (1% of the cap by default) of a target
578
601
  * BluePublicAllocator cap, the plan is reduced to the larger of the
@@ -613,8 +636,9 @@ class VaultV2BlueReallocationData {
613
636
  * every leg of a plan.
614
637
  * @returns Flat action-ready reallocations and their post-simulation state.
615
638
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
616
- * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
639
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
617
640
  * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
641
+ * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
618
642
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
619
643
  * @throws {UnknownReallocationMarketError} when a required market is absent.
620
644
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -622,7 +646,7 @@ class VaultV2BlueReallocationData {
622
646
  * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
623
647
  * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
624
648
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
625
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall.
649
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall and, for refinance, its planned allocator penalties.
626
650
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
627
651
  * @example
628
652
  * ```ts
@@ -676,6 +700,14 @@ class VaultV2BlueReallocationData {
676
700
  const { amount, type } = operation;
677
701
  if (amount <= 0n)
678
702
  throw new index_js_1.NonPositiveInputError("amount", amount);
703
+ const referralFeePct = type === "refinance" ? (operation.referralFeePct ?? 0n) : 0n;
704
+ if (referralFeePct < 0n)
705
+ throw new index_js_1.NegativeInputError("referralFeePct", referralFeePct);
706
+ if (referralFeePct >= blue_sdk_1.MathLib.WAD)
707
+ throw new index_js_1.ReferralFeePctExceededError(referralFeePct);
708
+ const feeAssets = type === "refinance"
709
+ ? (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(amount, referralFeePct)
710
+ : 0n;
679
711
  const timestamp = options.timestamp == null
680
712
  ? this.getLatestSnapshotTimestamp()
681
713
  : BigInt(options.timestamp);
@@ -696,60 +728,150 @@ class VaultV2BlueReallocationData {
696
728
  }
697
729
  const newTotalBorrowAssets = type === "borrow"
698
730
  ? market.totalBorrowAssets + amount
699
- : market.totalBorrowAssets;
731
+ : type === "refinance"
732
+ ? market.totalBorrowAssets + amount + feeAssets
733
+ : market.totalBorrowAssets;
700
734
  const newTotalSupplyAssets = type === "withdraw"
701
735
  ? market.totalSupplyAssets - amount
702
736
  : market.totalSupplyAssets;
737
+ const requiredAssets = blue_sdk_1.MathLib.wDivUp(newTotalBorrowAssets, constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION) -
738
+ newTotalSupplyAssets;
703
739
  if (blue_sdk_1.MarketUtils.getUtilization({
704
740
  totalSupplyAssets: newTotalSupplyAssets,
705
741
  totalBorrowAssets: newTotalBorrowAssets,
706
- }) <= constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION)
707
- return { reallocations: [], data: this };
708
- const requiredAssets = blue_sdk_1.MathLib.wDivUp(newTotalBorrowAssets, constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION) -
709
- newTotalSupplyAssets;
710
- if (requiredAssets <= 0n)
711
- return { reallocations: [], data: this };
742
+ }) <= constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION ||
743
+ requiredAssets <= 0n) {
744
+ const data = this.clone();
745
+ data.setMarkets([market]);
746
+ return { reallocations: [], data };
747
+ }
712
748
  const absoluteShortfall = newTotalBorrowAssets > newTotalSupplyAssets
713
749
  ? newTotalBorrowAssets - newTotalSupplyAssets
714
750
  : 0n;
751
+ const penaltyTiers = [
752
+ 0n,
753
+ ...new Set(Object.values(this.publicAllocatorConfigs).flatMap((config) => config != null && config.penalty > 0n && config.penalty <= maxPenalty
754
+ ? [config.penalty]
755
+ : [])),
756
+ ].sort((0, morpho_ts_1.bigIntComparator)((tier) => tier));
715
757
  const plan = (maxAssets, headroom) => {
716
- const reserves = createCapReserveState(this.mutableMarkets);
717
- const friendly = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
718
- context: createSimulationContext(),
719
- reserves,
720
- marketId,
721
- maxWithdrawalUtilization,
722
- maxAssets,
723
- capAccrualBuffer,
724
- allocatorCapHeadroom: headroom,
725
- options: normalizedOptions,
726
- });
727
- const reallocations = [...friendly.reallocations];
728
- const data = friendly.data;
729
- const friendlyMarket = data.getMarket(marketId);
730
- const friendlyBorrow = type === "borrow"
731
- ? friendlyMarket.totalBorrowAssets + amount
732
- : friendlyMarket.totalBorrowAssets;
733
- const friendlySupply = type === "withdraw"
734
- ? friendlyMarket.totalSupplyAssets - amount
735
- : friendlyMarket.totalSupplyAssets;
736
- if (friendlyBorrow > friendlySupply) {
737
- const fallback = data.computeVaultV2BlueReallocationsAtUtilizationInPlace({
738
- context: friendly.context,
739
- reserves,
740
- marketId,
741
- maxWithdrawalUtilization: blue_sdk_1.MathLib.WAD,
742
- maxAssets: friendlyBorrow - friendlySupply,
743
- capAccrualBuffer,
744
- allocatorCapHeadroom: headroom,
745
- options: normalizedOptions,
746
- });
747
- reallocations.push(...fallback.reallocations);
758
+ let reserves = createCapReserveState(this.mutableMarkets);
759
+ const reallocations = [];
760
+ let data = this.clone();
761
+ let context = createSimulationContext();
762
+ let remainingShortfall = absoluteShortfall;
763
+ let allocatorCapBoundTargets = new Set();
764
+ let idleBoundVaults = new Set();
765
+ for (const penalty of penaltyTiers) {
766
+ if (type === "refinance" && penalty === blue_sdk_1.MathLib.WAD)
767
+ continue;
768
+ let isFriendlyPass = true;
769
+ for (const utilization of [maxWithdrawalUtilization, blue_sdk_1.MathLib.WAD]) {
770
+ const isFreeFriendlyPass = penalty === 0n && isFriendlyPass;
771
+ isFriendlyPass = false;
772
+ if (remainingShortfall === 0n && !isFreeFriendlyPass)
773
+ 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
+ }
781
+ let lo = retryPaidPass ? passMaxAssets - 1n : 0n;
782
+ // Grow by grossed-up gaps, bisect to the smallest found, and keep the best for non-monotonic shared-cap fitting.
783
+ const passStart = retryPaidPass
784
+ ? {
785
+ data: data.clone(),
786
+ context,
787
+ reserves: cloneCapReserveState(reserves),
788
+ reallocationCount: reallocations.length,
789
+ }
790
+ : undefined;
791
+ let previousPassReallocatedAssets = 0n;
792
+ let hi;
793
+ let bestAttempt;
794
+ while (true) {
795
+ if (passStart != null) {
796
+ data = passStart.data.clone();
797
+ context = passStart.context;
798
+ reserves = cloneCapReserveState(passStart.reserves);
799
+ reallocations.length = passStart.reallocationCount;
800
+ }
801
+ const pass = data.computeVaultV2BlueReallocationsAtUtilizationInPlace({
802
+ context,
803
+ reserves,
804
+ marketId,
805
+ maxWithdrawalUtilization: utilization,
806
+ maxAssets: passMaxAssets,
807
+ capAccrualBuffer,
808
+ allocatorCapHeadroom: headroom,
809
+ penalty,
810
+ options: normalizedOptions,
811
+ });
812
+ reallocations.push(...pass.reallocations);
813
+ data = pass.data;
814
+ context = pass.context;
815
+ if (isFreeFriendlyPass) {
816
+ allocatorCapBoundTargets = pass.allocatorCapBoundTargets;
817
+ idleBoundVaults = pass.idleBoundVaults;
818
+ }
819
+ const currentMarket = data.getMarket(marketId);
820
+ const penaltyAssets = type === "refinance"
821
+ ? (0, common_js_1.getBlueBundlesV1PenaltyAssets)(reallocations)
822
+ : 0n;
823
+ const borrow = type === "borrow"
824
+ ? currentMarket.totalBorrowAssets + amount
825
+ : type === "refinance"
826
+ ? currentMarket.totalBorrowAssets +
827
+ amount +
828
+ feeAssets +
829
+ penaltyAssets
830
+ : currentMarket.totalBorrowAssets;
831
+ const supply = type === "withdraw"
832
+ ? currentMarket.totalSupplyAssets - amount
833
+ : currentMarket.totalSupplyAssets;
834
+ remainingShortfall = borrow > supply ? borrow - supply : 0n;
835
+ const passReallocatedAssets = pass.reallocations.reduce((total, { assets }) => total + assets, 0n);
836
+ if (passStart == null)
837
+ break;
838
+ if (bestAttempt == null ||
839
+ remainingShortfall < bestAttempt.remainingShortfall ||
840
+ (remainingShortfall === bestAttempt.remainingShortfall &&
841
+ passReallocatedAssets < bestAttempt.passReallocatedAssets))
842
+ bestAttempt = {
843
+ data,
844
+ context,
845
+ reserves: cloneCapReserveState(reserves),
846
+ reallocations: pass.reallocations,
847
+ remainingShortfall,
848
+ passReallocatedAssets,
849
+ };
850
+ if (remainingShortfall === 0n)
851
+ hi = hi == null ? passMaxAssets : blue_sdk_1.MathLib.min(hi, passMaxAssets);
852
+ else
853
+ lo = blue_sdk_1.MathLib.max(lo, passMaxAssets);
854
+ if (hi != null) {
855
+ if (hi - lo <= 1n)
856
+ break;
857
+ passMaxAssets = (lo + hi) / 2n;
858
+ continue;
859
+ }
860
+ if (passReallocatedAssets <= previousPassReallocatedAssets)
861
+ break;
862
+ previousPassReallocatedAssets = passReallocatedAssets;
863
+ passMaxAssets += blue_sdk_1.MathLib.mulDivUp(remainingShortfall, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - penalty);
864
+ }
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;
872
+ }
873
+ }
748
874
  }
749
- // The fallback pass only runs when the plan moves exactly the absolute
750
- // shortfall, which a reduced plan would move anyway.
751
- const allocatorCapBoundTargets = friendly.allocatorCapBoundTargets;
752
- const idleBoundVaults = friendly.idleBoundVaults;
753
875
  let reallocatedAssets = 0n;
754
876
  let unboundAssets = 0n;
755
877
  for (const { vault, from, to, assets } of reallocations) {
@@ -765,6 +887,10 @@ class VaultV2BlueReallocationData {
765
887
  liquidityBound: allocatorCapBoundTargets.size > 0 || idleBoundVaults.size > 0,
766
888
  reallocatedAssets,
767
889
  unboundAssets,
890
+ coversShortfall: type === "refinance"
891
+ ? reallocatedAssets >=
892
+ absoluteShortfall + (0, common_js_1.getBlueBundlesV1PenaltyAssets)(reallocations)
893
+ : reallocatedAssets >= absoluteShortfall,
768
894
  };
769
895
  };
770
896
  // A leg that fills an allocator cap, or idle legs that together take
@@ -778,30 +904,32 @@ class VaultV2BlueReallocationData {
778
904
  ? absoluteShortfall
779
905
  : target.unboundAssets, allocatorCapHeadroom);
780
906
  // Shared-cap fitting is not monotonic in the budget.
781
- if (selected.reallocatedAssets < absoluteShortfall &&
782
- target.reallocatedAssets >= absoluteShortfall)
907
+ if (!selected.coversShortfall && target.coversShortfall)
783
908
  selected = target;
784
909
  }
785
910
  let available = blue_sdk_1.MathLib.max(target.reallocatedAssets, selected.reallocatedAssets);
786
911
  // Without headroom, `target` already is the full-cap plan toward the target.
787
912
  const fullCapBudgets = allocatorCapHeadroom > 0n ? [absoluteShortfall, requiredAssets] : [];
788
913
  for (const maxAssets of fullCapBudgets) {
789
- if (selected.reallocatedAssets >= absoluteShortfall)
914
+ if (selected.coversShortfall)
790
915
  break;
791
916
  selected = plan(maxAssets, 0n);
792
917
  if (selected.reallocatedAssets > available)
793
918
  available = selected.reallocatedAssets;
794
919
  }
795
- if (selected.reallocatedAssets < absoluteShortfall) {
920
+ if (!selected.coversShortfall) {
796
921
  throw new index_js_1.InsufficientSharedLiquidityError({
797
922
  marketId,
798
- shortfall: absoluteShortfall,
923
+ shortfall: absoluteShortfall +
924
+ (type === "refinance"
925
+ ? (0, common_js_1.getBlueBundlesV1PenaltyAssets)(selected.reallocations)
926
+ : 0n),
799
927
  available,
800
928
  });
801
929
  }
802
930
  return { reallocations: selected.reallocations, data: selected.data };
803
931
  }
804
- computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, reserves, marketId, maxWithdrawalUtilization, maxAssets, capAccrualBuffer, allocatorCapHeadroom = 0n, options = {}, }) {
932
+ computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, reserves, marketId, maxWithdrawalUtilization, maxAssets, capAccrualBuffer, allocatorCapHeadroom = 0n, penalty, options = {}, }) {
805
933
  if (options.enabled === false)
806
934
  return {
807
935
  reallocations: [],
@@ -844,23 +972,23 @@ class VaultV2BlueReallocationData {
844
972
  return {
845
973
  key,
846
974
  ids: getAdapterIds(adapterIdsCache, adapter, market),
847
- reserve: () => {
848
- let reserve = reserves.reserveByPairKey.get(key);
975
+ reserve: (reserveState) => {
976
+ let reserve = reserveState.reserveByPairKey.get(key);
849
977
  if (reserve == null) {
850
- let accruals = reserves.marketAccruals.get(market.id);
978
+ let accruals = reserveState.marketAccruals.get(market.id);
851
979
  if (accruals == null) {
852
- const initialMarket = reserves.initialMarkets[market.id];
980
+ const initialMarket = reserveState.initialMarkets[market.id];
853
981
  if (initialMarket == null)
854
982
  throw new index_js_1.UnknownReallocationMarketError(market.id);
855
983
  accruals = [
856
984
  initialMarket.accrueInterest(timestamp),
857
985
  initialMarket.accrueInterest(timestamp + capAccrualBuffer),
858
986
  ];
859
- reserves.marketAccruals.set(market.id, accruals);
987
+ reserveState.marketAccruals.set(market.id, accruals);
860
988
  }
861
989
  const [atTimestamp, projected] = accruals;
862
990
  reserve = blue_sdk_1.MathLib.zeroFloorSub(projected.toSupplyAssets(shares), atTimestamp.toSupplyAssets(shares));
863
- reserves.reserveByPairKey.set(key, reserve);
991
+ reserveState.reserveByPairKey.set(key, reserve);
864
992
  }
865
993
  return reserve;
866
994
  },
@@ -877,7 +1005,7 @@ class VaultV2BlueReallocationData {
877
1005
  if (seen.has(pair.key) || !pair.ids.includes(id))
878
1006
  continue;
879
1007
  seen.add(pair.key);
880
- reserve += pair.reserve();
1008
+ reserve += pair.reserve(reserves);
881
1009
  }
882
1010
  return reserve;
883
1011
  };
@@ -893,6 +1021,8 @@ class VaultV2BlueReallocationData {
893
1021
  publicAllocatorConfig.penalty >
894
1022
  (options.maxPenalty ?? constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY))
895
1023
  return;
1024
+ if (penalty != null && publicAllocatorConfig.penalty !== penalty)
1025
+ return;
896
1026
  const donatedPenaltyAssetsKey = findAddressKey(simulationContext.donatedPenaltyAssets, vaultAddress);
897
1027
  // Exclude rounded penalty dust from idle candidates so one donation
898
1028
  // cannot replenish liquidity for another same-plan reallocation.
@@ -943,7 +1073,7 @@ class VaultV2BlueReallocationData {
943
1073
  const untracked = blue_sdk_1.MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
944
1074
  const allocatorHeadroom = blue_sdk_1.MathLib.zeroFloorSub(marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation +
945
1075
  untracked +
946
- targetPair.reserve()), blue_sdk_1.MathLib.wMulUp(marketPublicAllocatorConfig.absoluteCap, allocatorCapHeadroom));
1076
+ targetPair.reserve(reserves)), blue_sdk_1.MathLib.wMulUp(marketPublicAllocatorConfig.absoluteCap, allocatorCapHeadroom));
947
1077
  const minimumAllocation = minimumSupply.market.toSupplyAssets(adapterShares + minimumSupply.shares);
948
1078
  const minimumAllocationChange = blue_sdk_1.MathLib.max(minimumAllocation - adapterMarketCapAllocation.allocation, minimumSupply.assets);
949
1079
  const blockedTargetIds = targetAllocations
@@ -1312,7 +1442,7 @@ class VaultV2BlueReallocationData {
1312
1442
  }, utilization);
1313
1443
  }
1314
1444
  getLatestSnapshotTimestamp() {
1315
- let timestamp = 0n;
1445
+ let timestamp = this.timestamp ?? 0n;
1316
1446
  for (const market of Object.values(this.markets)) {
1317
1447
  if (market != null)
1318
1448
  timestamp = blue_sdk_1.MathLib.max(timestamp, market.lastUpdate);
@@ -1357,6 +1487,7 @@ class VaultV2BlueReallocationData {
1357
1487
  }
1358
1488
  data = new VaultV2BlueReallocationData({
1359
1489
  chainId: this.chainId,
1490
+ timestamp: this.timestamp,
1360
1491
  markets: probeMarkets,
1361
1492
  });
1362
1493
  if (sourceVaultKey != null) {
@@ -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, 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, } from "@morpho-org/morpho-ts";