@morpho-org/morpho-sdk 6.2.0 → 6.3.1

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.
@@ -1,4 +1,4 @@
1
1
  export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType, } from "@morpho-org/blue-sdk";
2
2
  export { CBP as MIDNIGHT_CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK, MAX_TREE_HEIGHT as MIDNIGHT_MAX_TREE_HEIGHT, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH, PRICE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP, RATE_RATIFIER_V1_OFFER_TYPEHASH as MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
3
3
  export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
4
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
4
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.ChainUtils = exports.ChainId = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.MIDNIGHT_TIME_TO_MAX_LIF = exports.MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS = exports.MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_PRICE_ROUNDING_STEP = exports.MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_OFFER_TYPEHASH = exports.MIDNIGHT_MAX_TREE_HEIGHT = exports.MIDNIGHT_MAX_TICK = exports.MIDNIGHT_MAX_SETTLEMENT_FEES = exports.MIDNIGHT_MAX_OFFER_CAP = exports.MIDNIGHT_MAX_CONTINUOUS_FEE = exports.MIDNIGHT_MAX_COLLATERALS_PER_BORROWER = exports.MIDNIGHT_MAX_COLLATERALS = exports.MIDNIGHT_MARKET_TYPEHASH = exports.MIDNIGHT_EIP712_DOMAIN_TYPEHASH = exports.MIDNIGHT_DEFAULT_TICK_SPACING = exports.MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH = exports.MIDNIGHT_CBP = exports.BlueTransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.BLUE_LIQUIDATION_CURSOR = exports.isBlueMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
3
+ exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.ChainUtils = exports.ChainId = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.MIDNIGHT_TIME_TO_MAX_LIF = exports.MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS = exports.MIDNIGHT_RATE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_PRICE_ROUNDING_STEP = exports.MIDNIGHT_PRICE_RATIFIER_V1_OFFER_TYPEHASH = exports.MIDNIGHT_OFFER_TYPEHASH = exports.MIDNIGHT_MAX_TREE_HEIGHT = exports.MIDNIGHT_MAX_TICK = exports.MIDNIGHT_MAX_SETTLEMENT_FEES = exports.MIDNIGHT_MAX_OFFER_CAP = exports.MIDNIGHT_MAX_CONTINUOUS_FEE = exports.MIDNIGHT_MAX_COLLATERALS_PER_BORROWER = exports.MIDNIGHT_MAX_COLLATERALS = exports.MIDNIGHT_MARKET_TYPEHASH = exports.MIDNIGHT_EIP712_DOMAIN_TYPEHASH = exports.MIDNIGHT_DEFAULT_TICK_SPACING = exports.MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH = exports.MIDNIGHT_CBP = exports.BlueTransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.BLUE_LIQUIDATION_CURSOR = exports.isBlueMarketId = exports.ERC20_ALLOWANCE_RECIPIENTS = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = void 0;
4
4
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  Object.defineProperty(exports, "DEFAULT_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE; } });
6
6
  Object.defineProperty(exports, "EIP_712_FIELDS", { enumerable: true, get: function () { return blue_sdk_1.EIP_712_FIELDS; } });
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "REWARDS_BASE_URL", { enumerable: true, get: func
41
41
  Object.defineProperty(exports, "ZERO_ADDRESS", { enumerable: true, get: function () { return morpho_ts_1.ZERO_ADDRESS; } });
42
42
  var constant_js_1 = require("./helpers/constant.js");
43
43
  Object.defineProperty(exports, "APPROVE_ONLY_ONCE_TOKENS", { enumerable: true, get: function () { return constant_js_1.APPROVE_ONLY_ONCE_TOKENS; } });
44
+ Object.defineProperty(exports, "DEFAULT_CAP_ACCRUAL_BUFFER", { enumerable: true, get: function () { return constant_js_1.DEFAULT_CAP_ACCRUAL_BUFFER; } });
44
45
  Object.defineProperty(exports, "DEFAULT_LLTV_BUFFER", { enumerable: true, get: function () { return constant_js_1.DEFAULT_LLTV_BUFFER; } });
45
46
  Object.defineProperty(exports, "DEFAULT_MAX_REALLOCATION_PENALTY", { enumerable: true, get: function () { return constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY; } });
46
47
  Object.defineProperty(exports, "DEFAULT_SUPPLY_TARGET_UTILIZATION", { enumerable: true, get: function () { return constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION; } });
@@ -814,13 +814,19 @@ export interface BlueActions {
814
814
  }) => Promise<VaultV2BlueReallocationData>;
815
815
  /**
816
816
  * Computes Vault V2 BluePublicAllocator reallocations for this market.
817
+ * Market/vault state and returned post-state stay at `options.timestamp`;
818
+ * only target-market cap checks reserve interest on the vault's existing
819
+ * allocation through `timestamp + capAccrualBuffer` (two hours by default;
820
+ * `0n` disables it). For market-source reallocations the source position's
821
+ * interest is also reserved on cap ids shared with the target, and reserves
822
+ * persist across every leg of a plan.
817
823
  *
818
824
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
819
825
  * @param params.options - Optional allocator discovery controls and operation to support.
820
826
  * @returns Action-ready reallocations and their post-simulation state.
821
827
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
822
828
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
823
- * @throws {NegativeInputError} when a utilization or penalty limit is negative.
829
+ * @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
824
830
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
825
831
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
826
832
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -1026,13 +1032,19 @@ export declare class MorphoBlue implements BlueActions {
1026
1032
  }): Promise<VaultV2BlueReallocationData>;
1027
1033
  /**
1028
1034
  * Computes Vault V2 BluePublicAllocator reallocations for this market.
1035
+ * Market/vault state and returned post-state stay at `options.timestamp`;
1036
+ * only target-market cap checks reserve interest on the vault's existing
1037
+ * allocation through `timestamp + capAccrualBuffer` (two hours by default;
1038
+ * `0n` disables it). For market-source reallocations the source position's
1039
+ * interest is also reserved on cap ids shared with the target, and reserves
1040
+ * persist across every leg of a plan.
1029
1041
  *
1030
1042
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
1031
1043
  * @param params.options - Optional allocator discovery controls and operation to support.
1032
1044
  * @returns Action-ready reallocations and their post-simulation state.
1033
1045
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1034
1046
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1035
- * @throws {NegativeInputError} when a utilization or penalty limit is negative.
1047
+ * @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
1036
1048
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
1037
1049
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
1038
1050
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -733,13 +733,19 @@ class MorphoBlue {
733
733
  }
734
734
  /**
735
735
  * Computes Vault V2 BluePublicAllocator reallocations for this market.
736
+ * Market/vault state and returned post-state stay at `options.timestamp`;
737
+ * only target-market cap checks reserve interest on the vault's existing
738
+ * allocation through `timestamp + capAccrualBuffer` (two hours by default;
739
+ * `0n` disables it). For market-source reallocations the source position's
740
+ * interest is also reserved on cap ids shared with the target, and reserves
741
+ * persist across every leg of a plan.
736
742
  *
737
743
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
738
744
  * @param params.options - Optional allocator discovery controls and operation to support.
739
745
  * @returns Action-ready reallocations and their post-simulation state.
740
746
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
741
747
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
742
- * @throws {NegativeInputError} when a utilization or penalty limit is negative.
748
+ * @throws {NegativeInputError} when the cap-accrual buffer, utilization, or penalty limit is negative.
743
749
  * @throws {InputExceedsMaxError} when a utilization or penalty limit exceeds WAD.
744
750
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
745
751
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -363,11 +363,18 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
363
363
  * utilization defaults to 90% and is configurable through
364
364
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
365
365
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
366
- * considered. Targets with no remaining supply or allocator capacity are skipped before
367
- * projecting source interest. The adapter's minimum share minting requirement, supply-share
368
- * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
369
- * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
370
- * allocation does not increase after rounding.
366
+ * considered. Market/vault state and the returned post-state stay at
367
+ * `timestamp`; only target-market cap checks reserve interest the vault's
368
+ * existing allocation would accrue through `timestamp + capAccrualBuffer`
369
+ * (two hours by default; `0n` disables it). For market-source reallocations
370
+ * the source position's interest is also reserved on cap ids shared with the
371
+ * target, and reserves persist across every leg of a plan. Targets with no remaining supply
372
+ * or allocator capacity are skipped before projecting source interest. The
373
+ * adapter's minimum share minting requirement, supply-share limits, and target
374
+ * absolute or zero relative caps are checked against a one-asset deposit.
375
+ * Shared cap IDs that a source withdrawal can reduce remain eligible. Each
376
+ * accepted leg counts at least its requested `assets` against the target cap
377
+ * IDs, so a leg sized to a cap leaves no rounding headroom.
371
378
  *
372
379
  * Shared-cap discovery is conservative. Operation planning searches at most
373
380
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -377,9 +384,15 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
377
384
  *
378
385
  * @param marketId - Target Blue market id.
379
386
  * @param options - Optional discovery controls and operation to support.
387
+ * Market/vault state and returned post-state stay at `timestamp`; only
388
+ * target-market cap checks reserve interest on the vault's existing allocation
389
+ * through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
390
+ * For market-source reallocations the source position's interest is also
391
+ * reserved on cap ids shared with the target, and reserves persist across
392
+ * every leg of a plan.
380
393
  * @returns Flat action-ready reallocations and their post-simulation state.
381
394
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
382
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
395
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
383
396
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
384
397
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
385
398
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -431,12 +444,19 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
431
444
  private computeVaultV2BlueReallocationsAtUtilizationInPlace;
432
445
  /**
433
446
  * Sums friendly Vault V2 shared liquidity available to a target market.
447
+ * Market/vault state and returned post-state stay at `timestamp`; only
448
+ * target-market cap checks reserve interest on the vault's existing allocation
449
+ * through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
450
+ * For market-source reallocations the source position's interest is also
451
+ * reserved on cap ids shared with the target, and reserves persist across
452
+ * every leg of a plan.
434
453
  *
435
454
  * @param marketId - Target Blue market id.
436
- * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
455
+ * @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
456
+ * allowlist, source utilization ceiling, and maximum penalty.
437
457
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
438
458
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
439
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
459
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
440
460
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
441
461
  * @throws {UnknownReallocationMarketError} when a required market is absent.
442
462
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -470,14 +490,20 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
470
490
  getPublicReallocationLiquidity(marketId: MarketId, options?: VaultV2BluePublicAllocatorOptions): bigint;
471
491
  /**
472
492
  * Computes borrow liquidity to a target utilization, including friendly
473
- * Vault V2 public reallocations.
493
+ * Vault V2 public reallocations. Market/vault state and returned post-state
494
+ * stay at `timestamp`; only target-market cap checks reserve interest on the
495
+ * vault's existing allocation through `timestamp + capAccrualBuffer` (two
496
+ * hours by default; `0n` disables). For market-source reallocations the
497
+ * source position's interest is also reserved on cap ids shared with the
498
+ * target, and reserves persist across every leg of a plan.
474
499
  *
475
500
  * @param marketId - Target Blue market id.
476
501
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
477
- * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
502
+ * @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
503
+ * allowlist, source utilization ceiling, and maximum penalty.
478
504
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
479
505
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
480
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
506
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
481
507
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
482
508
  * @throws {UnknownReallocationMarketError} when a required market is absent.
483
509
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -8,6 +8,12 @@ const constant_js_1 = require("../helpers/constant.js");
8
8
  const utilization_js_1 = require("../helpers/utilization.js");
9
9
  const index_js_1 = require("../types/index.js");
10
10
  const MAX_SHARED_CAP_SEARCH_STEPS = 1024n;
11
+ const createCapReserveState = (markets) => ({
12
+ initialMarkets: { ...markets },
13
+ marketAccruals: new Map(),
14
+ touchedPairs: new Map(),
15
+ reserveByPairKey: new Map(),
16
+ });
11
17
  /** Creates isolated transaction-scoped state for one simulation. @internal */
12
18
  const createSimulationContext = () => ({
13
19
  donatedPenaltyAssets: {},
@@ -558,11 +564,18 @@ class VaultV2BlueReallocationData {
558
564
  * utilization defaults to 90% and is configurable through
559
565
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
560
566
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
561
- * considered. Targets with no remaining supply or allocator capacity are skipped before
562
- * projecting source interest. The adapter's minimum share minting requirement, supply-share
563
- * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
564
- * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
565
- * allocation does not increase after rounding.
567
+ * considered. Market/vault state and the returned post-state stay at
568
+ * `timestamp`; only target-market cap checks reserve interest the vault's
569
+ * existing allocation would accrue through `timestamp + capAccrualBuffer`
570
+ * (two hours by default; `0n` disables it). For market-source reallocations
571
+ * the source position's interest is also reserved on cap ids shared with the
572
+ * target, and reserves persist across every leg of a plan. Targets with no remaining supply
573
+ * or allocator capacity are skipped before projecting source interest. The
574
+ * adapter's minimum share minting requirement, supply-share limits, and target
575
+ * absolute or zero relative caps are checked against a one-asset deposit.
576
+ * Shared cap IDs that a source withdrawal can reduce remain eligible. Each
577
+ * accepted leg counts at least its requested `assets` against the target cap
578
+ * IDs, so a leg sized to a cap leaves no rounding headroom.
566
579
  *
567
580
  * Shared-cap discovery is conservative. Operation planning searches at most
568
581
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -572,9 +585,15 @@ class VaultV2BlueReallocationData {
572
585
  *
573
586
  * @param marketId - Target Blue market id.
574
587
  * @param options - Optional discovery controls and operation to support.
588
+ * Market/vault state and returned post-state stay at `timestamp`; only
589
+ * target-market cap checks reserve interest on the vault's existing allocation
590
+ * through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
591
+ * For market-source reallocations the source position's interest is also
592
+ * reserved on cap ids shared with the target, and reserves persist across
593
+ * every leg of a plan.
575
594
  * @returns Flat action-ready reallocations and their post-simulation state.
576
595
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
577
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
596
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
578
597
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
579
598
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
580
599
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -619,13 +638,16 @@ class VaultV2BlueReallocationData {
619
638
  return { reallocations: [], data: this };
620
639
  const maxWithdrawalUtilization = (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options.maxWithdrawalUtilization);
621
640
  const maxPenalty = resolveMaxPenalty(options.maxPenalty);
641
+ const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options.capAccrualBuffer);
622
642
  const resolvedOptions = { ...options, maxPenalty };
623
643
  const operation = options.operation;
624
644
  if (operation == null) {
625
645
  const { reallocations, data } = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
626
646
  context: createSimulationContext(),
647
+ reserves: createCapReserveState(this.mutableMarkets),
627
648
  marketId,
628
649
  maxWithdrawalUtilization,
650
+ capAccrualBuffer,
629
651
  options: resolvedOptions,
630
652
  });
631
653
  return { reallocations, data };
@@ -666,11 +688,14 @@ class VaultV2BlueReallocationData {
666
688
  newTotalSupplyAssets;
667
689
  if (requiredAssets <= 0n)
668
690
  return { reallocations: [], data: this };
691
+ const reserves = createCapReserveState(this.mutableMarkets);
669
692
  const friendly = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
670
693
  context: createSimulationContext(),
694
+ reserves,
671
695
  marketId,
672
696
  maxWithdrawalUtilization,
673
697
  maxAssets: requiredAssets,
698
+ capAccrualBuffer,
674
699
  options: normalizedOptions,
675
700
  });
676
701
  const reallocations = [...friendly.reallocations];
@@ -685,9 +710,11 @@ class VaultV2BlueReallocationData {
685
710
  if (friendlyBorrow > friendlySupply) {
686
711
  const fallback = data.computeVaultV2BlueReallocationsAtUtilizationInPlace({
687
712
  context: friendly.context,
713
+ reserves,
688
714
  marketId,
689
715
  maxWithdrawalUtilization: blue_sdk_1.MathLib.WAD,
690
716
  maxAssets: friendlyBorrow - friendlySupply,
717
+ capAccrualBuffer,
691
718
  options: normalizedOptions,
692
719
  });
693
720
  reallocations.push(...fallback.reallocations);
@@ -705,7 +732,7 @@ class VaultV2BlueReallocationData {
705
732
  }
706
733
  return { reallocations, data };
707
734
  }
708
- computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, marketId, maxWithdrawalUtilization, maxAssets, options = {}, }) {
735
+ computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, reserves, marketId, maxWithdrawalUtilization, maxAssets, capAccrualBuffer, options = {}, }) {
709
736
  if (options.enabled === false)
710
737
  return { reallocations: [], data: this, context };
711
738
  this.getMarket(marketId);
@@ -725,6 +752,56 @@ class VaultV2BlueReallocationData {
725
752
  const adapterIdsCache = new Map();
726
753
  const activeAdaptersCache = new Map();
727
754
  let remainingAssets = maxAssets;
755
+ // Onchain, market interest is booked once at transaction start, on pre-plan
756
+ // positions at pre-plan rates, and stays on touched positions' cap ids.
757
+ // This reserve state is shared across every planner pass and leg of the plan.
758
+ // biome-ignore lint/complexity/useMaxParams: a pair is identified by its vault, adapter, and market.
759
+ const getPair = (vault, adapter, market) => {
760
+ const key = `${vault}:${adapter.address}:${market.id}`.toLowerCase();
761
+ const touched = reserves.touchedPairs.get(vault.toLowerCase())?.get(key);
762
+ if (touched != null)
763
+ return touched;
764
+ const shares = adapter.supplyShares[market.id] ?? 0n;
765
+ return {
766
+ key,
767
+ ids: getAdapterIds(adapterIdsCache, adapter, market),
768
+ reserve: () => {
769
+ let reserve = reserves.reserveByPairKey.get(key);
770
+ if (reserve == null) {
771
+ let accruals = reserves.marketAccruals.get(market.id);
772
+ if (accruals == null) {
773
+ const initialMarket = reserves.initialMarkets[market.id];
774
+ if (initialMarket == null)
775
+ throw new index_js_1.UnknownReallocationMarketError(market.id);
776
+ accruals = [
777
+ initialMarket.accrueInterest(timestamp),
778
+ initialMarket.accrueInterest(timestamp + capAccrualBuffer),
779
+ ];
780
+ reserves.marketAccruals.set(market.id, accruals);
781
+ }
782
+ const [atTimestamp, projected] = accruals;
783
+ reserve = blue_sdk_1.MathLib.zeroFloorSub(projected.toSupplyAssets(shares), atTimestamp.toSupplyAssets(shares));
784
+ reserves.reserveByPairKey.set(key, reserve);
785
+ }
786
+ return reserve;
787
+ },
788
+ };
789
+ };
790
+ // biome-ignore lint/complexity/useMaxParams: the reserve is scoped to one vault, cap id, and candidate set.
791
+ const capReserve = (vault, id, candidatePairs) => {
792
+ let reserve = 0n;
793
+ const seen = new Set();
794
+ for (const pair of [
795
+ ...(reserves.touchedPairs.get(vault.toLowerCase())?.values() ?? []),
796
+ ...candidatePairs,
797
+ ]) {
798
+ if (seen.has(pair.key) || !pair.ids.includes(id))
799
+ continue;
800
+ seen.add(pair.key);
801
+ reserve += pair.reserve();
802
+ }
803
+ return reserve;
804
+ };
728
805
  while (remainingAssets == null || remainingAssets > 0n) {
729
806
  const candidates = vaults
730
807
  .map((vaultAddress) => {
@@ -762,6 +839,7 @@ class VaultV2BlueReallocationData {
762
839
  if (!(0, viem_1.isAddressEqual)(targetMarket.params.loanToken, vault.asset) ||
763
840
  !(0, viem_1.isAddressEqual)(targetMarket.params.irm, adapter.adaptiveCurveIrm))
764
841
  continue;
842
+ const targetPair = getPair(vaultAddress, adapter, targetMarket);
765
843
  const [adapterCapId, collateralCapId, adapterMarketCapId] = getAdapterIds(adapterIdsCache, adapter, targetMarket);
766
844
  const marketPublicAllocatorConfig = data.getMarketPublicAllocatorConfig(vaultAddress, adapterMarketCapId);
767
845
  if (!(0, viem_1.isAddressEqual)(marketPublicAllocatorConfig.vault, vaultAddress) ||
@@ -778,14 +856,19 @@ class VaultV2BlueReallocationData {
778
856
  ];
779
857
  if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
780
858
  continue;
781
- const expectedSupplyAssets = targetMarket.toSupplyAssets(adapter.supplyShares[marketId] ?? 0n);
859
+ const adapterShares = adapter.supplyShares[marketId] ?? 0n;
860
+ const expectedSupplyAssets = targetMarket.toSupplyAssets(adapterShares);
782
861
  const untracked = blue_sdk_1.MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
783
- const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation + untracked);
784
- const minimumAllocation = minimumSupply.market.toSupplyAssets((adapter.supplyShares[marketId] ?? 0n) + minimumSupply.shares);
785
- const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
862
+ const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation +
863
+ untracked +
864
+ targetPair.reserve());
865
+ const minimumAllocation = minimumSupply.market.toSupplyAssets(adapterShares + minimumSupply.shares);
866
+ const minimumAllocationChange = blue_sdk_1.MathLib.max(minimumAllocation - adapterMarketCapAllocation.allocation, minimumSupply.assets);
786
867
  const blockedTargetIds = targetAllocations
787
- .filter(({ allocation, absoluteCap, relativeCap }) => {
788
- const nextAllocation = allocation + minimumAllocationChange;
868
+ .filter(({ allocation, absoluteCap, relativeCap, id }) => {
869
+ const nextAllocation = allocation +
870
+ capReserve(vaultAddress, id, [targetPair]) +
871
+ minimumAllocationChange;
789
872
  return (nextAllocation > absoluteCap ||
790
873
  (relativeCap === 0n && nextAllocation > 0n));
791
874
  })
@@ -803,11 +886,14 @@ class VaultV2BlueReallocationData {
803
886
  const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
804
887
  if (assets > 0n) {
805
888
  rawCandidates.push({
806
- vault: vaultAddress,
807
- from: { type: "idle" },
808
- to: { adapter: adapter.address },
809
- assets,
810
- penalty: publicAllocatorConfig.penalty,
889
+ reallocation: {
890
+ vault: vaultAddress,
891
+ from: { type: "idle" },
892
+ to: { adapter: adapter.address },
893
+ assets,
894
+ penalty: publicAllocatorConfig.penalty,
895
+ },
896
+ targetPair,
811
897
  });
812
898
  }
813
899
  }
@@ -841,6 +927,7 @@ class VaultV2BlueReallocationData {
841
927
  // A withdrawal can create target headroom only for shared cap IDs.
842
928
  if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
843
929
  continue;
930
+ const sourcePair = getPair(vaultAddress, sourceAdapter, sourceMarket);
844
931
  const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
845
932
  data.setMarkets([accruedSourceMarket]);
846
933
  const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
@@ -848,32 +935,32 @@ class VaultV2BlueReallocationData {
848
935
  if (assets <= 0n)
849
936
  continue;
850
937
  rawCandidates.push({
851
- vault: vaultAddress,
852
- from: {
853
- type: "market",
854
- adapter: sourceAdapter.address,
855
- marketParams: sourceMarket.params,
938
+ reallocation: {
939
+ vault: vaultAddress,
940
+ from: {
941
+ type: "market",
942
+ adapter: sourceAdapter.address,
943
+ marketParams: sourceMarket.params,
944
+ },
945
+ to: { adapter: adapter.address },
946
+ assets,
947
+ penalty: publicAllocatorConfig.penalty,
856
948
  },
857
- to: { adapter: adapter.address },
858
- assets,
859
- penalty: publicAllocatorConfig.penalty,
949
+ targetPair,
950
+ sourcePair,
860
951
  });
861
952
  }
862
953
  }
863
954
  }
864
955
  const capCompatibleCandidates = [];
865
- for (const reallocation of rawCandidates) {
956
+ for (const { reallocation, targetPair, sourcePair, } of rawCandidates) {
866
957
  let lower = 0n;
867
958
  let upper = reallocation.assets;
868
- const reallocationAdapter = data.getAdapter(reallocation.vault, reallocation.to.adapter);
869
- const targetIds = getAdapterIds(adapterIdsCache, reallocationAdapter, targetMarket);
870
- const sourceIds = new Set();
871
- if (reallocation.from.type === "market") {
872
- const sourceAdapter = data.getAdapter(reallocation.vault, reallocation.from.adapter);
873
- const sourceMarket = data.getMarket(reallocation.from.marketParams.id);
874
- for (const id of getAdapterIds(adapterIdsCache, sourceAdapter, sourceMarket))
875
- sourceIds.add(id);
876
- }
959
+ const targetIds = targetPair.ids;
960
+ const sourceIds = new Set(sourcePair?.ids ?? []);
961
+ const reserveById = new Map();
962
+ for (const id of targetIds)
963
+ reserveById.set(id, capReserve(reallocation.vault, id, sourcePair == null ? [targetPair] : [targetPair, sourcePair]));
877
964
  const probeReallocation = (assets) => {
878
965
  if (targetMarket.totalSupplyShares +
879
966
  targetMarket.toSupplyShares(assets, "Down") >
@@ -897,8 +984,11 @@ class VaultV2BlueReallocationData {
897
984
  for (const id of targetIds) {
898
985
  const allocation = postTransition.data.getAllocation(reallocation.vault, id);
899
986
  const capacity = blue_sdk_1.VaultV2Utils.allocationHeadroom({ ...allocation, allocation: 0n }, firstTotalAssets).value;
987
+ // The reserve covers interest accrued before inclusion by every
988
+ // position the plan touched on this cap id, as booked onchain.
900
989
  const withinCap = allocation.absoluteCap > 0n &&
901
- allocation.allocation <= capacity;
990
+ allocation.allocation + (reserveById.get(id) ?? 0n) <=
991
+ capacity;
902
992
  if (!withinCap) {
903
993
  withinAllCaps = false;
904
994
  if (!sourceIds.has(id))
@@ -935,22 +1025,34 @@ class VaultV2BlueReallocationData {
935
1025
  }
936
1026
  if (selectedAssets > 0n && probe?.withinAllCaps === true)
937
1027
  capCompatibleCandidates.push({
938
- ...reallocation,
939
- assets: selectedAssets,
1028
+ reallocation: { ...reallocation, assets: selectedAssets },
1029
+ targetPair,
1030
+ sourcePair,
940
1031
  });
941
1032
  }
942
- return capCompatibleCandidates.sort((0, morpho_ts_1.bigIntComparator)(({ assets }) => assets, "desc"))[0];
1033
+ return capCompatibleCandidates.sort((0, morpho_ts_1.bigIntComparator)(({ reallocation }) => reallocation.assets, "desc"))[0];
943
1034
  })
944
1035
  .filter((candidate) => candidate != null)
945
- .sort((0, morpho_ts_1.bigIntComparator)(({ assets }) => assets, "desc"));
1036
+ .sort((0, morpho_ts_1.bigIntComparator)(({ reallocation }) => reallocation.assets, "desc"));
946
1037
  const largest = candidates[0];
947
1038
  if (largest == null)
948
1039
  return { reallocations, data, context: simulationContext };
949
- const reallocation = largest;
950
- reallocations.push(reallocation);
1040
+ const { reallocation: acceptedReallocation, targetPair: acceptedTargetPair, sourcePair: acceptedSourcePair, } = largest;
1041
+ const touchedVaultKey = acceptedReallocation.vault.toLowerCase();
1042
+ let touchedVaultPairs = reserves.touchedPairs.get(touchedVaultKey);
1043
+ if (touchedVaultPairs == null) {
1044
+ touchedVaultPairs = new Map();
1045
+ reserves.touchedPairs.set(touchedVaultKey, touchedVaultPairs);
1046
+ }
1047
+ if (!touchedVaultPairs.has(acceptedTargetPair.key))
1048
+ touchedVaultPairs.set(acceptedTargetPair.key, acceptedTargetPair);
1049
+ if (acceptedSourcePair != null &&
1050
+ !touchedVaultPairs.has(acceptedSourcePair.key))
1051
+ touchedVaultPairs.set(acceptedSourcePair.key, acceptedSourcePair);
1052
+ reallocations.push(acceptedReallocation);
951
1053
  const transition = data.applyPublicReallocation({
952
1054
  context: simulationContext,
953
- reallocation,
1055
+ reallocation: acceptedReallocation,
954
1056
  targetMarketId: marketId,
955
1057
  timestamp,
956
1058
  adapterIdsCache,
@@ -958,18 +1060,25 @@ class VaultV2BlueReallocationData {
958
1060
  data = transition.data;
959
1061
  simulationContext = transition.context;
960
1062
  if (remainingAssets != null)
961
- remainingAssets -= reallocation.assets;
1063
+ remainingAssets -= acceptedReallocation.assets;
962
1064
  }
963
1065
  return { reallocations, data, context: simulationContext };
964
1066
  }
965
1067
  /**
966
1068
  * Sums friendly Vault V2 shared liquidity available to a target market.
1069
+ * Market/vault state and returned post-state stay at `timestamp`; only
1070
+ * target-market cap checks reserve interest on the vault's existing allocation
1071
+ * through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
1072
+ * For market-source reallocations the source position's interest is also
1073
+ * reserved on cap ids shared with the target, and reserves persist across
1074
+ * every leg of a plan.
967
1075
  *
968
1076
  * @param marketId - Target Blue market id.
969
- * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
1077
+ * @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
1078
+ * allowlist, source utilization ceiling, and maximum penalty.
970
1079
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
971
1080
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
972
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
1081
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
973
1082
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
974
1083
  * @throws {UnknownReallocationMarketError} when a required market is absent.
975
1084
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1003,26 +1112,35 @@ class VaultV2BlueReallocationData {
1003
1112
  getPublicReallocationLiquidity(marketId, options) {
1004
1113
  if (options?.enabled === false)
1005
1114
  return 0n;
1115
+ const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options?.capAccrualBuffer);
1006
1116
  const maxPenalty = resolveMaxPenalty(options?.maxPenalty);
1007
1117
  return this.clone()
1008
1118
  .computeVaultV2BlueReallocationsAtUtilizationInPlace({
1009
1119
  context: createSimulationContext(),
1120
+ reserves: createCapReserveState(this.mutableMarkets),
1010
1121
  marketId,
1011
1122
  maxWithdrawalUtilization: (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options?.maxWithdrawalUtilization),
1123
+ capAccrualBuffer,
1012
1124
  options: { ...options, maxPenalty },
1013
1125
  })
1014
1126
  .reallocations.reduce((total, { assets }) => total + assets, 0n);
1015
1127
  }
1016
1128
  /**
1017
1129
  * Computes borrow liquidity to a target utilization, including friendly
1018
- * Vault V2 public reallocations.
1130
+ * Vault V2 public reallocations. Market/vault state and returned post-state
1131
+ * stay at `timestamp`; only target-market cap checks reserve interest on the
1132
+ * vault's existing allocation through `timestamp + capAccrualBuffer` (two
1133
+ * hours by default; `0n` disables). For market-source reallocations the
1134
+ * source position's interest is also reserved on cap ids shared with the
1135
+ * target, and reserves persist across every leg of a plan.
1019
1136
  *
1020
1137
  * @param marketId - Target Blue market id.
1021
1138
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
1022
- * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
1139
+ * @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
1140
+ * allowlist, source utilization ceiling, and maximum penalty.
1023
1141
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
1024
1142
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1025
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
1143
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
1026
1144
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
1027
1145
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1028
1146
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1056,6 +1174,7 @@ class VaultV2BlueReallocationData {
1056
1174
  */
1057
1175
  // biome-ignore lint/complexity/useMaxParams: mirrors the existing V1 metric API
1058
1176
  getAvailableLiquidityToUtilization(marketId, utilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
1177
+ const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options?.capAccrualBuffer);
1059
1178
  const timestamp = options?.timestamp == null
1060
1179
  ? this.getLatestSnapshotTimestamp()
1061
1180
  : BigInt(options.timestamp);
@@ -1066,8 +1185,10 @@ class VaultV2BlueReallocationData {
1066
1185
  const availableLiquidity = this.clone()
1067
1186
  .computeVaultV2BlueReallocationsAtUtilizationInPlace({
1068
1187
  context: createSimulationContext(),
1188
+ reserves: createCapReserveState(this.mutableMarkets),
1069
1189
  marketId,
1070
1190
  maxWithdrawalUtilization: (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options?.maxWithdrawalUtilization),
1191
+ capAccrualBuffer,
1071
1192
  options: {
1072
1193
  ...options,
1073
1194
  timestamp,
@@ -1247,21 +1368,15 @@ class VaultV2BlueReallocationData {
1247
1368
  if (!targetAdapter.markets.some(({ id }) => id === targetMarket.id))
1248
1369
  targetAdapter.markets.push(supply.market);
1249
1370
  data.setMarkets([supply.market], probe ? [targetAdapter] : undefined);
1250
- const targetChange = supply.market.toSupplyAssets(targetSupplyShares) - oldTargetAllocation;
1371
+ const simulatedChange = supply.market.toSupplyAssets(targetSupplyShares) - oldTargetAllocation;
1372
+ // The adapter's rounded expected-assets delta can differ by one wei at inclusion,
1373
+ // so cap tracking assumes each accepted leg adds at least its requested assets.
1374
+ const targetChange = blue_sdk_1.MathLib.max(simulatedChange, reallocation.assets);
1251
1375
  for (const id of targetIds) {
1252
1376
  const allocation = data.getAllocation(reallocation.vault, id);
1253
- const nextAllocation = allocation.allocation + targetChange;
1254
- if (nextAllocation < 0n) {
1255
- throw new index_js_1.ReallocationAllocationUnderflowError({
1256
- vault: reallocation.vault,
1257
- id,
1258
- allocation: allocation.allocation,
1259
- change: targetChange,
1260
- });
1261
- }
1262
1377
  data.mutableAllocations[allocationsKey][id] = {
1263
1378
  ...allocation,
1264
- allocation: nextAllocation,
1379
+ allocation: allocation.allocation + targetChange,
1265
1380
  };
1266
1381
  }
1267
1382
  vault.assetBalance -= reallocation.assets;