@morpho-org/morpho-sdk 6.1.0 → 6.3.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 (57) hide show
  1. package/lib/cjs/blue/errors.d.ts +1 -1
  2. package/lib/cjs/blue/errors.js +2 -1
  3. package/lib/cjs/constants.d.ts +1 -1
  4. package/lib/cjs/constants.js +2 -1
  5. package/lib/cjs/entities/blue/blue.d.ts +14 -2
  6. package/lib/cjs/entities/blue/blue.js +7 -1
  7. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -0
  8. package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
  9. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +34 -9
  10. package/lib/cjs/entities/vaultV2BlueReallocationData.js +167 -47
  11. package/lib/cjs/errors.d.ts +1 -1
  12. package/lib/cjs/errors.js +3 -2
  13. package/lib/cjs/helpers/constant.d.ts +8 -0
  14. package/lib/cjs/helpers/constant.js +10 -1
  15. package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
  16. package/lib/cjs/helpers/encodeDeallocation.js +1 -0
  17. package/lib/cjs/helpers/index.d.ts +1 -1
  18. package/lib/cjs/helpers/index.js +2 -1
  19. package/lib/cjs/helpers/metadata.d.ts +13 -0
  20. package/lib/cjs/helpers/metadata.js +13 -0
  21. package/lib/cjs/helpers/utilization.d.ts +13 -0
  22. package/lib/cjs/helpers/utilization.js +19 -1
  23. package/lib/cjs/helpers/validate.d.ts +0 -2
  24. package/lib/cjs/helpers/validate.js +2 -3
  25. package/lib/cjs/types/data.d.ts +3 -0
  26. package/lib/cjs/types/entity.d.ts +3 -0
  27. package/lib/cjs/types/metadata.d.ts +6 -0
  28. package/lib/cjs/types/sharedLiquidity.d.ts +19 -1
  29. package/lib/esm/blue/errors.d.ts +1 -1
  30. package/lib/esm/blue/errors.js +1 -1
  31. package/lib/esm/constants.d.ts +1 -1
  32. package/lib/esm/constants.js +1 -1
  33. package/lib/esm/entities/blue/blue.d.ts +14 -2
  34. package/lib/esm/entities/blue/blue.js +7 -1
  35. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -0
  36. package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
  37. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +34 -9
  38. package/lib/esm/entities/vaultV2BlueReallocationData.js +168 -48
  39. package/lib/esm/errors.d.ts +1 -1
  40. package/lib/esm/errors.js +1 -1
  41. package/lib/esm/helpers/constant.d.ts +8 -0
  42. package/lib/esm/helpers/constant.js +9 -0
  43. package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
  44. package/lib/esm/helpers/encodeDeallocation.js +1 -0
  45. package/lib/esm/helpers/index.d.ts +1 -1
  46. package/lib/esm/helpers/index.js +1 -1
  47. package/lib/esm/helpers/metadata.d.ts +13 -0
  48. package/lib/esm/helpers/metadata.js +13 -0
  49. package/lib/esm/helpers/utilization.d.ts +13 -0
  50. package/lib/esm/helpers/utilization.js +18 -1
  51. package/lib/esm/helpers/validate.d.ts +0 -2
  52. package/lib/esm/helpers/validate.js +1 -1
  53. package/lib/esm/types/data.d.ts +3 -0
  54. package/lib/esm/types/entity.d.ts +3 -0
  55. package/lib/esm/types/metadata.d.ts +6 -0
  56. package/lib/esm/types/sharedLiquidity.d.ts +19 -1
  57. package/package.json +4 -4
@@ -2,9 +2,15 @@ import { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMark
2
2
  import { _try, bigIntComparator } from "@morpho-org/morpho-ts";
3
3
  import { isAddressEqual } from "viem";
4
4
  import { DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, MAX_REALLOCATION_PENALTY, } from "../helpers/constant.js";
5
- import { resolveMaxWithdrawalUtilization } from "../helpers/utilization.js";
5
+ import { resolveCapAccrualBuffer, resolveMaxWithdrawalUtilization, } from "../helpers/utilization.js";
6
6
  import { InputExceedsMaxError, InsufficientSharedLiquidityError, NegativeInputError, NonPositiveInputError, ReallocationAdapterSupplySharesUnderflowError, ReallocationAllocationUnderflowError, ReallocationWithdrawExceedsMarketSupplyError, UnknownReallocationActiveAdaptersError, UnknownReallocationAdapterError, UnknownReallocationAllocationError, UnknownReallocationMarketError, UnknownReallocationMarketPublicAllocatorConfigError, UnknownReallocationPublicAllocatorConfigError, UnknownReallocationVaultError, } from "../types/index.js";
7
7
  const MAX_SHARED_CAP_SEARCH_STEPS = 1024n;
8
+ const createCapReserveState = (markets) => ({
9
+ initialMarkets: { ...markets },
10
+ marketAccruals: new Map(),
11
+ touchedPairs: new Map(),
12
+ reserveByPairKey: new Map(),
13
+ });
8
14
  /** Creates isolated transaction-scoped state for one simulation. @internal */
9
15
  const createSimulationContext = () => ({
10
16
  donatedPenaltyAssets: {},
@@ -555,9 +561,15 @@ export class VaultV2BlueReallocationData {
555
561
  * utilization defaults to 90% and is configurable through
556
562
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
557
563
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
558
- * considered. Targets with no remaining supply or allocator capacity are skipped before
559
- * projecting source interest. The adapter's minimum share minting requirement, supply-share
560
- * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
564
+ * considered. Market/vault state and the returned post-state stay at
565
+ * `timestamp`; only target-market cap checks reserve interest the vault's
566
+ * existing allocation would accrue through `timestamp + capAccrualBuffer`
567
+ * (two hours by default; `0n` disables it). For market-source reallocations
568
+ * the source position's interest is also reserved on cap ids shared with the
569
+ * target, and reserves persist across every leg of a plan. Targets with no remaining supply
570
+ * or allocator capacity are skipped before projecting source interest. The
571
+ * adapter's minimum share minting requirement, supply-share limits, and target
572
+ * absolute or zero relative caps are checked against a one-asset deposit.
561
573
  * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
562
574
  * allocation does not increase after rounding.
563
575
  *
@@ -569,9 +581,15 @@ export class VaultV2BlueReallocationData {
569
581
  *
570
582
  * @param marketId - Target Blue market id.
571
583
  * @param options - Optional discovery controls and operation to support.
584
+ * Market/vault state and returned post-state stay at `timestamp`; only
585
+ * target-market cap checks reserve interest on the vault's existing allocation
586
+ * through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
587
+ * For market-source reallocations the source position's interest is also
588
+ * reserved on cap ids shared with the target, and reserves persist across
589
+ * every leg of a plan.
572
590
  * @returns Flat action-ready reallocations and their post-simulation state.
573
591
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
574
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
592
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
575
593
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
576
594
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
577
595
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -616,13 +634,16 @@ export class VaultV2BlueReallocationData {
616
634
  return { reallocations: [], data: this };
617
635
  const maxWithdrawalUtilization = resolveMaxWithdrawalUtilization(options.maxWithdrawalUtilization);
618
636
  const maxPenalty = resolveMaxPenalty(options.maxPenalty);
637
+ const capAccrualBuffer = resolveCapAccrualBuffer(options.capAccrualBuffer);
619
638
  const resolvedOptions = { ...options, maxPenalty };
620
639
  const operation = options.operation;
621
640
  if (operation == null) {
622
641
  const { reallocations, data } = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
623
642
  context: createSimulationContext(),
643
+ reserves: createCapReserveState(this.mutableMarkets),
624
644
  marketId,
625
645
  maxWithdrawalUtilization,
646
+ capAccrualBuffer,
626
647
  options: resolvedOptions,
627
648
  });
628
649
  return { reallocations, data };
@@ -663,11 +684,14 @@ export class VaultV2BlueReallocationData {
663
684
  newTotalSupplyAssets;
664
685
  if (requiredAssets <= 0n)
665
686
  return { reallocations: [], data: this };
687
+ const reserves = createCapReserveState(this.mutableMarkets);
666
688
  const friendly = this.clone().computeVaultV2BlueReallocationsAtUtilizationInPlace({
667
689
  context: createSimulationContext(),
690
+ reserves,
668
691
  marketId,
669
692
  maxWithdrawalUtilization,
670
693
  maxAssets: requiredAssets,
694
+ capAccrualBuffer,
671
695
  options: normalizedOptions,
672
696
  });
673
697
  const reallocations = [...friendly.reallocations];
@@ -682,9 +706,11 @@ export class VaultV2BlueReallocationData {
682
706
  if (friendlyBorrow > friendlySupply) {
683
707
  const fallback = data.computeVaultV2BlueReallocationsAtUtilizationInPlace({
684
708
  context: friendly.context,
709
+ reserves,
685
710
  marketId,
686
711
  maxWithdrawalUtilization: MathLib.WAD,
687
712
  maxAssets: friendlyBorrow - friendlySupply,
713
+ capAccrualBuffer,
688
714
  options: normalizedOptions,
689
715
  });
690
716
  reallocations.push(...fallback.reallocations);
@@ -702,7 +728,7 @@ export class VaultV2BlueReallocationData {
702
728
  }
703
729
  return { reallocations, data };
704
730
  }
705
- computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, marketId, maxWithdrawalUtilization, maxAssets, options = {}, }) {
731
+ computeVaultV2BlueReallocationsAtUtilizationInPlace({ context, reserves, marketId, maxWithdrawalUtilization, maxAssets, capAccrualBuffer, options = {}, }) {
706
732
  if (options.enabled === false)
707
733
  return { reallocations: [], data: this, context };
708
734
  this.getMarket(marketId);
@@ -722,6 +748,56 @@ export class VaultV2BlueReallocationData {
722
748
  const adapterIdsCache = new Map();
723
749
  const activeAdaptersCache = new Map();
724
750
  let remainingAssets = maxAssets;
751
+ // Onchain, market interest is booked once at transaction start, on pre-plan
752
+ // positions at pre-plan rates, and stays on touched positions' cap ids.
753
+ // This reserve state is shared across every planner pass and leg of the plan.
754
+ // biome-ignore lint/complexity/useMaxParams: a pair is identified by its vault, adapter, and market.
755
+ const getPair = (vault, adapter, market) => {
756
+ const key = `${vault}:${adapter.address}:${market.id}`.toLowerCase();
757
+ const touched = reserves.touchedPairs.get(vault.toLowerCase())?.get(key);
758
+ if (touched != null)
759
+ return touched;
760
+ const shares = adapter.supplyShares[market.id] ?? 0n;
761
+ return {
762
+ key,
763
+ ids: getAdapterIds(adapterIdsCache, adapter, market),
764
+ reserve: () => {
765
+ let reserve = reserves.reserveByPairKey.get(key);
766
+ if (reserve == null) {
767
+ let accruals = reserves.marketAccruals.get(market.id);
768
+ if (accruals == null) {
769
+ const initialMarket = reserves.initialMarkets[market.id];
770
+ if (initialMarket == null)
771
+ throw new UnknownReallocationMarketError(market.id);
772
+ accruals = [
773
+ initialMarket.accrueInterest(timestamp),
774
+ initialMarket.accrueInterest(timestamp + capAccrualBuffer),
775
+ ];
776
+ reserves.marketAccruals.set(market.id, accruals);
777
+ }
778
+ const [atTimestamp, projected] = accruals;
779
+ reserve = MathLib.zeroFloorSub(projected.toSupplyAssets(shares), atTimestamp.toSupplyAssets(shares));
780
+ reserves.reserveByPairKey.set(key, reserve);
781
+ }
782
+ return reserve;
783
+ },
784
+ };
785
+ };
786
+ // biome-ignore lint/complexity/useMaxParams: the reserve is scoped to one vault, cap id, and candidate set.
787
+ const capReserve = (vault, id, candidatePairs) => {
788
+ let reserve = 0n;
789
+ const seen = new Set();
790
+ for (const pair of [
791
+ ...(reserves.touchedPairs.get(vault.toLowerCase())?.values() ?? []),
792
+ ...candidatePairs,
793
+ ]) {
794
+ if (seen.has(pair.key) || !pair.ids.includes(id))
795
+ continue;
796
+ seen.add(pair.key);
797
+ reserve += pair.reserve();
798
+ }
799
+ return reserve;
800
+ };
725
801
  while (remainingAssets == null || remainingAssets > 0n) {
726
802
  const candidates = vaults
727
803
  .map((vaultAddress) => {
@@ -759,6 +835,7 @@ export class VaultV2BlueReallocationData {
759
835
  if (!isAddressEqual(targetMarket.params.loanToken, vault.asset) ||
760
836
  !isAddressEqual(targetMarket.params.irm, adapter.adaptiveCurveIrm))
761
837
  continue;
838
+ const targetPair = getPair(vaultAddress, adapter, targetMarket);
762
839
  const [adapterCapId, collateralCapId, adapterMarketCapId] = getAdapterIds(adapterIdsCache, adapter, targetMarket);
763
840
  const marketPublicAllocatorConfig = data.getMarketPublicAllocatorConfig(vaultAddress, adapterMarketCapId);
764
841
  if (!isAddressEqual(marketPublicAllocatorConfig.vault, vaultAddress) ||
@@ -775,14 +852,19 @@ export class VaultV2BlueReallocationData {
775
852
  ];
776
853
  if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
777
854
  continue;
778
- const expectedSupplyAssets = targetMarket.toSupplyAssets(adapter.supplyShares[marketId] ?? 0n);
855
+ const adapterShares = adapter.supplyShares[marketId] ?? 0n;
856
+ const expectedSupplyAssets = targetMarket.toSupplyAssets(adapterShares);
779
857
  const untracked = MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
780
- const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation + untracked);
781
- const minimumAllocation = minimumSupply.market.toSupplyAssets((adapter.supplyShares[marketId] ?? 0n) + minimumSupply.shares);
858
+ const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation +
859
+ untracked +
860
+ targetPair.reserve());
861
+ const minimumAllocation = minimumSupply.market.toSupplyAssets(adapterShares + minimumSupply.shares);
782
862
  const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
783
863
  const blockedTargetIds = targetAllocations
784
- .filter(({ allocation, absoluteCap, relativeCap }) => {
785
- const nextAllocation = allocation + minimumAllocationChange;
864
+ .filter(({ allocation, absoluteCap, relativeCap, id }) => {
865
+ const nextAllocation = allocation +
866
+ capReserve(vaultAddress, id, [targetPair]) +
867
+ minimumAllocationChange;
786
868
  return (nextAllocation > absoluteCap ||
787
869
  (relativeCap === 0n && nextAllocation > 0n));
788
870
  })
@@ -800,11 +882,14 @@ export class VaultV2BlueReallocationData {
800
882
  const assets = MathLib.min(MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
801
883
  if (assets > 0n) {
802
884
  rawCandidates.push({
803
- vault: vaultAddress,
804
- from: { type: "idle" },
805
- to: { adapter: adapter.address },
806
- assets,
807
- penalty: publicAllocatorConfig.penalty,
885
+ reallocation: {
886
+ vault: vaultAddress,
887
+ from: { type: "idle" },
888
+ to: { adapter: adapter.address },
889
+ assets,
890
+ penalty: publicAllocatorConfig.penalty,
891
+ },
892
+ targetPair,
808
893
  });
809
894
  }
810
895
  }
@@ -838,6 +923,7 @@ export class VaultV2BlueReallocationData {
838
923
  // A withdrawal can create target headroom only for shared cap IDs.
839
924
  if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
840
925
  continue;
926
+ const sourcePair = getPair(vaultAddress, sourceAdapter, sourceMarket);
841
927
  const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
842
928
  data.setMarkets([accruedSourceMarket]);
843
929
  const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
@@ -845,32 +931,32 @@ export class VaultV2BlueReallocationData {
845
931
  if (assets <= 0n)
846
932
  continue;
847
933
  rawCandidates.push({
848
- vault: vaultAddress,
849
- from: {
850
- type: "market",
851
- adapter: sourceAdapter.address,
852
- marketParams: sourceMarket.params,
934
+ reallocation: {
935
+ vault: vaultAddress,
936
+ from: {
937
+ type: "market",
938
+ adapter: sourceAdapter.address,
939
+ marketParams: sourceMarket.params,
940
+ },
941
+ to: { adapter: adapter.address },
942
+ assets,
943
+ penalty: publicAllocatorConfig.penalty,
853
944
  },
854
- to: { adapter: adapter.address },
855
- assets,
856
- penalty: publicAllocatorConfig.penalty,
945
+ targetPair,
946
+ sourcePair,
857
947
  });
858
948
  }
859
949
  }
860
950
  }
861
951
  const capCompatibleCandidates = [];
862
- for (const reallocation of rawCandidates) {
952
+ for (const { reallocation, targetPair, sourcePair, } of rawCandidates) {
863
953
  let lower = 0n;
864
954
  let upper = reallocation.assets;
865
- const reallocationAdapter = data.getAdapter(reallocation.vault, reallocation.to.adapter);
866
- const targetIds = getAdapterIds(adapterIdsCache, reallocationAdapter, targetMarket);
867
- const sourceIds = new Set();
868
- if (reallocation.from.type === "market") {
869
- const sourceAdapter = data.getAdapter(reallocation.vault, reallocation.from.adapter);
870
- const sourceMarket = data.getMarket(reallocation.from.marketParams.id);
871
- for (const id of getAdapterIds(adapterIdsCache, sourceAdapter, sourceMarket))
872
- sourceIds.add(id);
873
- }
955
+ const targetIds = targetPair.ids;
956
+ const sourceIds = new Set(sourcePair?.ids ?? []);
957
+ const reserveById = new Map();
958
+ for (const id of targetIds)
959
+ reserveById.set(id, capReserve(reallocation.vault, id, sourcePair == null ? [targetPair] : [targetPair, sourcePair]));
874
960
  const probeReallocation = (assets) => {
875
961
  if (targetMarket.totalSupplyShares +
876
962
  targetMarket.toSupplyShares(assets, "Down") >
@@ -894,8 +980,11 @@ export class VaultV2BlueReallocationData {
894
980
  for (const id of targetIds) {
895
981
  const allocation = postTransition.data.getAllocation(reallocation.vault, id);
896
982
  const capacity = VaultV2Utils.allocationHeadroom({ ...allocation, allocation: 0n }, firstTotalAssets).value;
983
+ // The reserve covers interest accrued before inclusion by every
984
+ // position the plan touched on this cap id, as booked onchain.
897
985
  const withinCap = allocation.absoluteCap > 0n &&
898
- allocation.allocation <= capacity;
986
+ allocation.allocation + (reserveById.get(id) ?? 0n) <=
987
+ capacity;
899
988
  if (!withinCap) {
900
989
  withinAllCaps = false;
901
990
  if (!sourceIds.has(id))
@@ -932,22 +1021,34 @@ export class VaultV2BlueReallocationData {
932
1021
  }
933
1022
  if (selectedAssets > 0n && probe?.withinAllCaps === true)
934
1023
  capCompatibleCandidates.push({
935
- ...reallocation,
936
- assets: selectedAssets,
1024
+ reallocation: { ...reallocation, assets: selectedAssets },
1025
+ targetPair,
1026
+ sourcePair,
937
1027
  });
938
1028
  }
939
- return capCompatibleCandidates.sort(bigIntComparator(({ assets }) => assets, "desc"))[0];
1029
+ return capCompatibleCandidates.sort(bigIntComparator(({ reallocation }) => reallocation.assets, "desc"))[0];
940
1030
  })
941
1031
  .filter((candidate) => candidate != null)
942
- .sort(bigIntComparator(({ assets }) => assets, "desc"));
1032
+ .sort(bigIntComparator(({ reallocation }) => reallocation.assets, "desc"));
943
1033
  const largest = candidates[0];
944
1034
  if (largest == null)
945
1035
  return { reallocations, data, context: simulationContext };
946
- const reallocation = largest;
947
- reallocations.push(reallocation);
1036
+ const { reallocation: acceptedReallocation, targetPair: acceptedTargetPair, sourcePair: acceptedSourcePair, } = largest;
1037
+ const touchedVaultKey = acceptedReallocation.vault.toLowerCase();
1038
+ let touchedVaultPairs = reserves.touchedPairs.get(touchedVaultKey);
1039
+ if (touchedVaultPairs == null) {
1040
+ touchedVaultPairs = new Map();
1041
+ reserves.touchedPairs.set(touchedVaultKey, touchedVaultPairs);
1042
+ }
1043
+ if (!touchedVaultPairs.has(acceptedTargetPair.key))
1044
+ touchedVaultPairs.set(acceptedTargetPair.key, acceptedTargetPair);
1045
+ if (acceptedSourcePair != null &&
1046
+ !touchedVaultPairs.has(acceptedSourcePair.key))
1047
+ touchedVaultPairs.set(acceptedSourcePair.key, acceptedSourcePair);
1048
+ reallocations.push(acceptedReallocation);
948
1049
  const transition = data.applyPublicReallocation({
949
1050
  context: simulationContext,
950
- reallocation,
1051
+ reallocation: acceptedReallocation,
951
1052
  targetMarketId: marketId,
952
1053
  timestamp,
953
1054
  adapterIdsCache,
@@ -955,18 +1056,25 @@ export class VaultV2BlueReallocationData {
955
1056
  data = transition.data;
956
1057
  simulationContext = transition.context;
957
1058
  if (remainingAssets != null)
958
- remainingAssets -= reallocation.assets;
1059
+ remainingAssets -= acceptedReallocation.assets;
959
1060
  }
960
1061
  return { reallocations, data, context: simulationContext };
961
1062
  }
962
1063
  /**
963
1064
  * Sums friendly Vault V2 shared liquidity available to a target market.
1065
+ * Market/vault state and returned post-state stay at `timestamp`; only
1066
+ * target-market cap checks reserve interest on the vault's existing allocation
1067
+ * through `timestamp + capAccrualBuffer` (two hours by default; `0n` disables).
1068
+ * For market-source reallocations the source position's interest is also
1069
+ * reserved on cap ids shared with the target, and reserves persist across
1070
+ * every leg of a plan.
964
1071
  *
965
1072
  * @param marketId - Target Blue market id.
966
- * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
1073
+ * @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
1074
+ * allowlist, source utilization ceiling, and maximum penalty.
967
1075
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
968
1076
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
969
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
1077
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
970
1078
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
971
1079
  * @throws {UnknownReallocationMarketError} when a required market is absent.
972
1080
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1000,26 +1108,35 @@ export class VaultV2BlueReallocationData {
1000
1108
  getPublicReallocationLiquidity(marketId, options) {
1001
1109
  if (options?.enabled === false)
1002
1110
  return 0n;
1111
+ const capAccrualBuffer = resolveCapAccrualBuffer(options?.capAccrualBuffer);
1003
1112
  const maxPenalty = resolveMaxPenalty(options?.maxPenalty);
1004
1113
  return this.clone()
1005
1114
  .computeVaultV2BlueReallocationsAtUtilizationInPlace({
1006
1115
  context: createSimulationContext(),
1116
+ reserves: createCapReserveState(this.mutableMarkets),
1007
1117
  marketId,
1008
1118
  maxWithdrawalUtilization: resolveMaxWithdrawalUtilization(options?.maxWithdrawalUtilization),
1119
+ capAccrualBuffer,
1009
1120
  options: { ...options, maxPenalty },
1010
1121
  })
1011
1122
  .reallocations.reduce((total, { assets }) => total + assets, 0n);
1012
1123
  }
1013
1124
  /**
1014
1125
  * Computes borrow liquidity to a target utilization, including friendly
1015
- * Vault V2 public reallocations.
1126
+ * Vault V2 public reallocations. Market/vault state and returned post-state
1127
+ * stay at `timestamp`; only target-market cap checks reserve interest on the
1128
+ * vault's existing allocation through `timestamp + capAccrualBuffer` (two
1129
+ * hours by default; `0n` disables). For market-source reallocations the
1130
+ * source position's interest is also reserved on cap ids shared with the
1131
+ * target, and reserves persist across every leg of a plan.
1016
1132
  *
1017
1133
  * @param marketId - Target Blue market id.
1018
1134
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
1019
- * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
1135
+ * @param options - Optional timestamp, cap-accrual buffer, enable flag, vault
1136
+ * allowlist, source utilization ceiling, and maximum penalty.
1020
1137
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
1021
1138
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1022
- * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
1139
+ * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
1023
1140
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
1024
1141
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1025
1142
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1053,6 +1170,7 @@ export class VaultV2BlueReallocationData {
1053
1170
  */
1054
1171
  // biome-ignore lint/complexity/useMaxParams: mirrors the existing V1 metric API
1055
1172
  getAvailableLiquidityToUtilization(marketId, utilization = DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
1173
+ const capAccrualBuffer = resolveCapAccrualBuffer(options?.capAccrualBuffer);
1056
1174
  const timestamp = options?.timestamp == null
1057
1175
  ? this.getLatestSnapshotTimestamp()
1058
1176
  : BigInt(options.timestamp);
@@ -1063,8 +1181,10 @@ export class VaultV2BlueReallocationData {
1063
1181
  const availableLiquidity = this.clone()
1064
1182
  .computeVaultV2BlueReallocationsAtUtilizationInPlace({
1065
1183
  context: createSimulationContext(),
1184
+ reserves: createCapReserveState(this.mutableMarkets),
1066
1185
  marketId,
1067
1186
  maxWithdrawalUtilization: resolveMaxWithdrawalUtilization(options?.maxWithdrawalUtilization),
1187
+ capAccrualBuffer,
1068
1188
  options: {
1069
1189
  ...options,
1070
1190
  timestamp,
@@ -1,7 +1,7 @@
1
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, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
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
7
  export { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
package/lib/esm/errors.js CHANGED
@@ -1,6 +1,6 @@
1
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, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
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 { _try, DivisionByZeroError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
@@ -7,6 +7,14 @@ export declare const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
7
7
  export declare const MAX_REALLOCATION_PENALTY = 1000000000000000000n;
8
8
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
9
9
  export declare const DEFAULT_LLTV_BUFFER: bigint;
10
+ /**
11
+ * Forward interest-accrual window, in seconds (2 hours), reserved in target-market
12
+ * cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
13
+ * planning reallocations, so a transaction included after the quote block does not
14
+ * revert on a cap check. Override with
15
+ * `VaultV2BluePublicAllocatorOptions.capAccrualBuffer`.
16
+ */
17
+ export declare const DEFAULT_CAP_ACCRUAL_BUFFER: bigint;
10
18
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
11
19
  export declare const MAX_ABSOLUTE_SHARE_PRICE: bigint;
12
20
  /**
@@ -1,4 +1,5 @@
1
1
  import { ChainId, MathLib } from "@morpho-org/blue-sdk";
2
+ import { Time } from "@morpho-org/morpho-ts";
2
3
  import { maxUint96 } from "viem";
3
4
  /** Maximum slippage tolerance: 10% */
4
5
  export const MAX_SLIPPAGE_TOLERANCE = MathLib.WAD / 10n;
@@ -8,6 +9,14 @@ export const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
8
9
  export const MAX_REALLOCATION_PENALTY = MathLib.WAD;
9
10
  /** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
10
11
  export const DEFAULT_LLTV_BUFFER = MathLib.WAD / 200n;
12
+ /**
13
+ * Forward interest-accrual window, in seconds (2 hours), reserved in target-market
14
+ * cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
15
+ * planning reallocations, so a transaction included after the quote block does not
16
+ * revert on a cap check. Override with
17
+ * `VaultV2BluePublicAllocatorOptions.capAccrualBuffer`.
18
+ */
19
+ export const DEFAULT_CAP_ACCRUAL_BUFFER = Time.s.from.h(2n);
11
20
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
12
21
  export const MAX_ABSOLUTE_SHARE_PRICE = 100n * MathLib.RAY;
13
22
  /**
@@ -7,5 +7,6 @@ import { type Deallocation } from "../types/index.js";
7
7
  * @param onBehalf - The address from which the penalty is taken (share owner).
8
8
  * @returns The ABI-encoded calldata for `VaultV2.forceDeallocate`.
9
9
  * @throws {NonPositiveInputError} when `deallocation.amount <= 0n`.
10
+ * @internal
10
11
  */
11
12
  export declare function encodeForceDeallocateCall(deallocation: Deallocation, onBehalf: Address): Hex;
@@ -21,6 +21,7 @@ function encodeDeallocateData(deallocation) {
21
21
  * @param onBehalf - The address from which the penalty is taken (share owner).
22
22
  * @returns The ABI-encoded calldata for `VaultV2.forceDeallocate`.
23
23
  * @throws {NonPositiveInputError} when `deallocation.amount <= 0n`.
24
+ * @internal
24
25
  */
25
26
  export function encodeForceDeallocateCall(deallocation, onBehalf) {
26
27
  if (deallocation.amount <= 0n) {
@@ -1,4 +1,4 @@
1
- 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 "./constant.js";
1
+ 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 "./constant.js";
2
2
  export { addTransactionMetadata } from "./metadata.js";
3
3
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
4
4
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
@@ -1,4 +1,4 @@
1
- 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 "./constant.js";
1
+ 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 "./constant.js";
2
2
  export { addTransactionMetadata } from "./metadata.js";
3
3
  export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
4
4
  export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
@@ -29,6 +29,19 @@ import type { Metadata } from "../types/index.js";
29
29
  * @returns The same `tx` object when `data` is missing, an empty string, or
30
30
  * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
31
  * with `data` containing any appended metadata. The input is never mutated.
32
+ * @example
33
+ * ```ts
34
+ * import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
35
+ * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
36
+ * import type { Address, Hex } from "viem";
37
+ * import { mainnet } from "viem/chains";
38
+ *
39
+ * const { blue } = getChainAddresses(mainnet.id);
40
+ * const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
41
+ * const result: { to: Address; value: bigint; data: Hex } =
42
+ * addTransactionMetadata(tx, { origin: "deadbeef", timestamp: true });
43
+ * // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
44
+ * ```
32
45
  */
33
46
  export declare function addTransactionMetadata(tx: {
34
47
  data: Hex;
@@ -29,6 +29,19 @@ import { concatHex, isHex, numberToHex } from "viem";
29
29
  * @returns The same `tx` object when `data` is missing, an empty string, or
30
30
  * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
31
  * with `data` containing any appended metadata. The input is never mutated.
32
+ * @example
33
+ * ```ts
34
+ * import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
35
+ * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
36
+ * import type { Address, Hex } from "viem";
37
+ * import { mainnet } from "viem/chains";
38
+ *
39
+ * const { blue } = getChainAddresses(mainnet.id);
40
+ * const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
41
+ * const result: { to: Address; value: bigint; data: Hex } =
42
+ * addTransactionMetadata(tx, { origin: "deadbeef", timestamp: true });
43
+ * // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
44
+ * ```
32
45
  */
33
46
  export function addTransactionMetadata(tx, metadata) {
34
47
  const { data, ..._tx } = tx;
@@ -1,3 +1,16 @@
1
+ import { type BigIntish } from "@morpho-org/blue-sdk";
2
+ /**
3
+ * Resolves and validates the target-market cap-accrual buffer.
4
+ * @internal
5
+ * @param value - Optional buffer duration in seconds.
6
+ * @returns The non-negative buffer duration, defaulting to two hours.
7
+ * @throws {NegativeInputError} when the buffer is negative.
8
+ * @example
9
+ * ```ts
10
+ * const buffer = resolveCapAccrualBuffer(undefined);
11
+ * ```
12
+ */
13
+ export declare const resolveCapAccrualBuffer: (value?: BigIntish) => bigint;
1
14
  /**
2
15
  * Resolves and validates a source withdrawal utilization ceiling.
3
16
  * @internal
@@ -1,6 +1,23 @@
1
1
  import { MathLib } from "@morpho-org/blue-sdk";
2
2
  import { InputExceedsMaxError, NegativeInputError } from "../types/index.js";
3
- import { DEFAULT_WITHDRAWAL_TARGET_UTILIZATION } from "./constant.js";
3
+ import { DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, } from "./constant.js";
4
+ /**
5
+ * Resolves and validates the target-market cap-accrual buffer.
6
+ * @internal
7
+ * @param value - Optional buffer duration in seconds.
8
+ * @returns The non-negative buffer duration, defaulting to two hours.
9
+ * @throws {NegativeInputError} when the buffer is negative.
10
+ * @example
11
+ * ```ts
12
+ * const buffer = resolveCapAccrualBuffer(undefined);
13
+ * ```
14
+ */
15
+ export const resolveCapAccrualBuffer = (value) => {
16
+ const buffer = value == null ? DEFAULT_CAP_ACCRUAL_BUFFER : BigInt(value);
17
+ if (buffer < 0n)
18
+ throw new NegativeInputError("capAccrualBuffer", buffer);
19
+ return buffer;
20
+ };
4
21
  /**
5
22
  * Resolves and validates a source withdrawal utilization ceiling.
6
23
  * @internal
@@ -2,8 +2,6 @@ import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
2
  import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
3
3
  import { type Address } from "viem";
4
4
  import { type VaultV2BlueReallocation } from "../types/index.js";
5
- /** @internal */
6
- export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1;
7
5
  /**
8
6
  * Rejects a `bigint` field that falls outside the unsigned 256-bit ABI range so a direct caller
9
7
  * gets the SDK's typed error instead of viem's `IntegerOutOfRangeError` at encode time. `maxUint256`
@@ -4,7 +4,7 @@ import { isAddress, isAddressEqual, maxUint128, maxUint256, zeroAddress, } from
4
4
  import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidReallocationAddressError, InvalidReallocationSourceTypeError, InvalidVaultV2BlueReallocationShapeError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
5
5
  import { DEFAULT_LLTV_BUFFER, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, } from "./constant.js";
6
6
  /** @internal */
7
- export const compareMarketIds = (idA, idB) => {
7
+ const compareMarketIds = (idA, idB) => {
8
8
  const normalizedIdA = idA.toLowerCase();
9
9
  const normalizedIdB = idB.toLowerCase();
10
10
  if (normalizedIdA > normalizedIdB)
@@ -1,2 +1,5 @@
1
1
  import type { CallParameters, UnionPick } from "viem";
2
+ /**
3
+ * Viem call options forwarded to SDK data-fetching helpers.
4
+ */
2
5
  export type FetchParameters = UnionPick<CallParameters, "account" | "blockNumber" | "blockTag" | "stateOverride">;