@morpho-org/morpho-sdk 5.5.0 → 5.6.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 (90) hide show
  1. package/README.md +8 -6
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +3 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +21 -15
  5. package/lib/cjs/actions/blue/borrow.js +25 -18
  6. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
  7. package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
  8. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
  9. package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
  10. package/lib/cjs/actions/blue/refinance.d.ts +14 -7
  11. package/lib/cjs/actions/blue/refinance.js +18 -10
  12. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  13. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
  14. package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
  15. package/lib/cjs/actions/blue/withdraw.js +23 -18
  16. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -1
  17. package/lib/cjs/bundler/actions.d.ts +117 -0
  18. package/lib/cjs/bundler/actions.js +211 -4
  19. package/lib/cjs/bundler/types.d.ts +20 -0
  20. package/lib/cjs/constants.d.ts +1 -1
  21. package/lib/cjs/constants.js +3 -1
  22. package/lib/cjs/entities/blue/blue.d.ts +360 -71
  23. package/lib/cjs/entities/blue/blue.js +285 -52
  24. package/lib/cjs/entities/index.d.ts +2 -1
  25. package/lib/cjs/entities/index.js +6 -3
  26. package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
  27. package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +29 -16
  28. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +1 -1
  29. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
  30. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
  31. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1311 -0
  32. package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  33. package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
  34. package/lib/cjs/helpers/constant.d.ts +5 -3
  35. package/lib/cjs/helpers/constant.js +6 -4
  36. package/lib/cjs/helpers/index.d.ts +2 -2
  37. package/lib/cjs/helpers/index.js +6 -3
  38. package/lib/cjs/helpers/validate.d.ts +30 -14
  39. package/lib/cjs/helpers/validate.js +140 -27
  40. package/lib/cjs/types/action.d.ts +12 -0
  41. package/lib/cjs/types/error.d.ts +224 -5
  42. package/lib/cjs/types/error.js +269 -7
  43. package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
  44. package/lib/cjs/utils.d.ts +2 -2
  45. package/lib/cjs/utils.js +6 -4
  46. package/lib/esm/abis.d.ts +1 -1
  47. package/lib/esm/abis.js +1 -1
  48. package/lib/esm/actions/blue/borrow.d.ts +21 -15
  49. package/lib/esm/actions/blue/borrow.js +26 -19
  50. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
  51. package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
  52. package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
  53. package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
  54. package/lib/esm/actions/blue/refinance.d.ts +14 -7
  55. package/lib/esm/actions/blue/refinance.js +19 -11
  56. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  57. package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
  58. package/lib/esm/actions/blue/withdraw.d.ts +20 -13
  59. package/lib/esm/actions/blue/withdraw.js +24 -19
  60. package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -1
  61. package/lib/esm/bundler/actions.d.ts +117 -0
  62. package/lib/esm/bundler/actions.js +214 -7
  63. package/lib/esm/bundler/types.d.ts +20 -0
  64. package/lib/esm/constants.d.ts +1 -1
  65. package/lib/esm/constants.js +1 -1
  66. package/lib/esm/entities/blue/blue.d.ts +360 -71
  67. package/lib/esm/entities/blue/blue.js +288 -55
  68. package/lib/esm/entities/index.d.ts +2 -1
  69. package/lib/esm/entities/index.js +2 -1
  70. package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
  71. package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +32 -14
  72. package/lib/esm/entities/vaultV2/vaultV2.d.ts +1 -1
  73. package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
  74. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
  75. package/lib/esm/entities/vaultV2BlueReallocationData.js +1307 -0
  76. package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  77. package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
  78. package/lib/esm/helpers/constant.d.ts +5 -3
  79. package/lib/esm/helpers/constant.js +5 -3
  80. package/lib/esm/helpers/index.d.ts +2 -2
  81. package/lib/esm/helpers/index.js +2 -2
  82. package/lib/esm/helpers/validate.d.ts +30 -14
  83. package/lib/esm/helpers/validate.js +141 -30
  84. package/lib/esm/types/action.d.ts +12 -0
  85. package/lib/esm/types/error.d.ts +224 -5
  86. package/lib/esm/types/error.js +253 -4
  87. package/lib/esm/types/sharedLiquidity.d.ts +72 -8
  88. package/lib/esm/utils.d.ts +2 -2
  89. package/lib/esm/utils.js +2 -2
  90. package/package.json +5 -5
@@ -1,5 +1,5 @@
1
1
  import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
2
- import type { Address } from "viem";
2
+ import type { Address, Hash } from "viem";
3
3
  /**
4
4
  * Thrown when a morpho-sdk input that must be non-negative is negative.
5
5
  *
@@ -44,6 +44,26 @@ export declare class NonPositiveInputError extends Error {
44
44
  */
45
45
  constructor(field: string, value: bigint);
46
46
  }
47
+ /** Thrown when an integer input exceeds its protocol-defined maximum. */
48
+ export declare class InputExceedsMaxError extends Error {
49
+ /**
50
+ * @param params - Maximum-bound validation details.
51
+ * @param params.field - Public input field whose value is invalid.
52
+ * @param params.value - Supplied value.
53
+ * @param params.max - Largest accepted value.
54
+ */
55
+ constructor(params: {
56
+ readonly field: string;
57
+ readonly value: bigint;
58
+ readonly max: bigint;
59
+ });
60
+ /** Public input field whose value is invalid. */
61
+ readonly field: string;
62
+ /** Supplied value. */
63
+ readonly value: bigint;
64
+ /** Largest accepted value. */
65
+ readonly max: bigint;
66
+ }
47
67
  /** Thrown when an in-kind redemption does not include any Morpho Blue market parameters. */
48
68
  export declare class EmptyMarketParamsListError extends Error {
49
69
  constructor();
@@ -333,6 +353,26 @@ export declare namespace BundlerErrors {
333
353
  */
334
354
  constructor(authorized: Address);
335
355
  }
356
+ /**
357
+ * Thrown when a skippable Blue Public Allocator call would leave a usable
358
+ * token allowance behind after the allocator call reverts.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
363
+ *
364
+ * if (error instanceof BundlerErrors.SkippableAllocatorPenalty) {
365
+ * // Rebuild the allocator call with skipRevert set to false.
366
+ * }
367
+ * ```
368
+ */
369
+ class SkippableAllocatorPenalty extends Error {
370
+ readonly penaltyAssets: bigint;
371
+ /**
372
+ * @param penaltyAssets - Exact token amount approved to the allocator.
373
+ */
374
+ constructor(penaltyAssets: bigint);
375
+ }
336
376
  }
337
377
  /** Requirement signature kind accepted by action-output transaction builders. */
338
378
  export type RequirementSignatureKind = "permit" | "authorization" | "midnightOfferRootSignature";
@@ -488,10 +528,115 @@ export declare class AccrualPositionUserMismatchError extends Error {
488
528
  export declare class EmptyReallocationWithdrawalsError extends Error {
489
529
  constructor(vault: string);
490
530
  }
491
- /** Thrown when a reallocation withdrawal references the operation's target market (which would be a no-op or self-deal). */
531
+ /** Thrown when a Public Allocator source references the target Blue market. */
492
532
  export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
493
533
  constructor(vault: string, marketId: string);
494
534
  }
535
+ /**
536
+ * Thrown when a Public Allocator reallocation does not match exactly one V1 or
537
+ * V2 input shape.
538
+ *
539
+ * @example
540
+ * ```ts
541
+ * import { InvalidReallocationShapeError } from "@morpho-org/morpho-sdk";
542
+ *
543
+ * const error = new InvalidReallocationShapeError();
544
+ * ```
545
+ */
546
+ export declare class InvalidReallocationShapeError extends Error {
547
+ constructor();
548
+ }
549
+ /**
550
+ * Thrown when one reallocation plan contains both Vault V1 and Vault V2 entries.
551
+ *
552
+ * @example
553
+ * ```ts
554
+ * import { MixedReallocationVersionsError } from "@morpho-org/morpho-sdk";
555
+ *
556
+ * const error = new MixedReallocationVersionsError();
557
+ * ```
558
+ */
559
+ export declare class MixedReallocationVersionsError extends Error {
560
+ constructor();
561
+ }
562
+ /**
563
+ * Thrown when a Blue Public Allocator reallocation contains a malformed vault
564
+ * or adapter address.
565
+ *
566
+ * @example
567
+ * ```ts
568
+ * import { InvalidReallocationAddressError } from "@morpho-org/morpho-sdk";
569
+ *
570
+ * const error = new InvalidReallocationAddressError("to.adapter");
571
+ * if (error instanceof InvalidReallocationAddressError) {
572
+ * console.error(error.field);
573
+ * }
574
+ * ```
575
+ */
576
+ export declare class InvalidReallocationAddressError extends Error {
577
+ readonly field: "vault" | "from.adapter" | "to.adapter";
578
+ /**
579
+ * @param field - Reallocation address field that is absent or malformed.
580
+ */
581
+ constructor(field: "vault" | "from.adapter" | "to.adapter");
582
+ }
583
+ /**
584
+ * Thrown when a Blue Public Allocator source is absent, incomplete, or has an
585
+ * unknown discriminator.
586
+ *
587
+ * @example
588
+ * ```ts
589
+ * import { InvalidReallocationSourceTypeError } from "@morpho-org/morpho-sdk";
590
+ *
591
+ * const error = new InvalidReallocationSourceTypeError("marketTypo");
592
+ * ```
593
+ */
594
+ export declare class InvalidReallocationSourceTypeError extends Error {
595
+ readonly sourceType: string | undefined;
596
+ readonly missingField?: "adapter" | "marketParams" | undefined;
597
+ /**
598
+ * @param sourceType - Invalid runtime value received for `reallocation.from.type`,
599
+ * or `undefined` when the source or discriminator is absent.
600
+ * @param missingField - Required market-source field that is absent or malformed.
601
+ */
602
+ constructor(sourceType: string | undefined, missingField?: "adapter" | "marketParams" | undefined);
603
+ }
604
+ /**
605
+ * Thrown when one bundle assigns different penalty rates to the same Vault V2.
606
+ *
607
+ * @example
608
+ * ```ts
609
+ * import { InconsistentReallocationPenaltyError } from "@morpho-org/morpho-sdk";
610
+ * import type { Address } from "viem";
611
+ *
612
+ * const vaultFixture =
613
+ * "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
614
+ * const error = new InconsistentReallocationPenaltyError({
615
+ * vault: vaultFixture,
616
+ * expected: 5n,
617
+ * actual: 11n,
618
+ * });
619
+ * ```
620
+ */
621
+ export declare class InconsistentReallocationPenaltyError extends Error {
622
+ /** Vault whose configured penalty must be reused. */
623
+ readonly vault: Address;
624
+ /** Penalty rate established by the first matching bundle entry. */
625
+ readonly expected: bigint;
626
+ /** Conflicting penalty rate supplied by a later bundle entry. */
627
+ readonly actual: bigint;
628
+ /**
629
+ * @param params - Conflicting vault penalty details.
630
+ * @param params.vault - Vault whose configured penalty applies.
631
+ * @param params.expected - Penalty rate established by the first matching entry.
632
+ * @param params.actual - Conflicting penalty rate supplied by a later entry.
633
+ */
634
+ constructor(params: {
635
+ readonly vault: Address;
636
+ readonly expected: bigint;
637
+ readonly actual: bigint;
638
+ });
639
+ }
495
640
  /** Thrown when reallocation withdrawals within a vault are not strictly sorted by market id. */
496
641
  export declare class UnsortedReallocationWithdrawalsError extends Error {
497
642
  constructor(vault: string, marketId: string);
@@ -563,8 +708,8 @@ export declare class DisabledReallocationMarketError extends Error {
563
708
  constructor(vault: Address, marketId: MarketId);
564
709
  }
565
710
  /**
566
- * Thrown when shared liquidity selected by `computeReallocations` cannot cover
567
- * the operation's absolute shortfall on the target market — the resulting
711
+ * Thrown when shared liquidity selected by a Vault V1 or Vault V2 reallocation planner cannot
712
+ * cover the operation's absolute shortfall on the target market — the resulting
568
713
  * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
569
714
  *
570
715
  * Pattern-match on the class and inspect `params` to surface the gap to users.
@@ -617,6 +762,80 @@ export declare class UnknownReallocationPositionError extends UnknownDataError {
617
762
  */
618
763
  constructor(user: Address, marketId: MarketId);
619
764
  }
765
+ /** Thrown when Vault V2 reallocation state does not contain a requested allocation id. */
766
+ export declare class UnknownReallocationAllocationError extends UnknownDataError {
767
+ readonly vault: Address;
768
+ readonly id: Hash;
769
+ /**
770
+ * @param vault - Vault V2 address for the missing allocation.
771
+ * @param id - Missing Vault V2 allocation id.
772
+ */
773
+ constructor(vault: Address, id: Hash);
774
+ }
775
+ /** Thrown when Vault V2 reallocation state lacks the vault-wide allocator configuration. */
776
+ export declare class UnknownReallocationPublicAllocatorConfigError extends UnknownDataError {
777
+ readonly vault: Address;
778
+ /** @param vault - Vault V2 address with missing allocator configuration. */
779
+ constructor(vault: Address);
780
+ }
781
+ /** Thrown when Vault V2 reallocation state lacks the fetched active-adapter set. */
782
+ export declare class UnknownReallocationActiveAdaptersError extends UnknownDataError {
783
+ readonly vault: Address;
784
+ /** @param vault - Vault V2 address with missing active-adapter state. */
785
+ constructor(vault: Address);
786
+ }
787
+ /** Thrown when Vault V2 reallocation state lacks an adapter-market allocator configuration. */
788
+ export declare class UnknownReallocationMarketPublicAllocatorConfigError extends UnknownDataError {
789
+ readonly vault: Address;
790
+ readonly adapterMarketCapId: Hash;
791
+ /**
792
+ * @param vault - Vault V2 address for the missing configuration.
793
+ * @param adapterMarketCapId - Missing adapter-scoped market cap id.
794
+ */
795
+ constructor(vault: Address, adapterMarketCapId: Hash);
796
+ }
797
+ /** Thrown when Vault V2 reallocation state does not contain a requested adapter. */
798
+ export declare class UnknownReallocationAdapterError extends UnknownDataError {
799
+ readonly vault: Address;
800
+ readonly adapter: Address;
801
+ /**
802
+ * @param vault - Vault V2 address expected to own the adapter.
803
+ * @param adapter - Missing adapter address.
804
+ */
805
+ constructor(vault: Address, adapter: Address);
806
+ }
807
+ /** Thrown when a simulated Vault V2 allocation transition would underflow. */
808
+ export declare class ReallocationAllocationUnderflowError extends Error {
809
+ readonly params: {
810
+ readonly vault: Address;
811
+ readonly id: Hash;
812
+ readonly allocation: bigint;
813
+ readonly change: bigint;
814
+ };
815
+ constructor(params: {
816
+ readonly vault: Address;
817
+ readonly id: Hash;
818
+ readonly allocation: bigint;
819
+ readonly change: bigint;
820
+ });
821
+ }
822
+ /** Thrown when a simulated Vault V2 market withdrawal exceeds the adapter's supply shares. */
823
+ export declare class ReallocationAdapterSupplySharesUnderflowError extends Error {
824
+ readonly params: {
825
+ readonly vault: Address;
826
+ readonly adapter: Address;
827
+ readonly marketId: MarketId;
828
+ readonly supplyShares: bigint;
829
+ readonly withdrawnShares: bigint;
830
+ };
831
+ constructor(params: {
832
+ readonly vault: Address;
833
+ readonly adapter: Address;
834
+ readonly marketId: MarketId;
835
+ readonly supplyShares: bigint;
836
+ readonly withdrawnShares: bigint;
837
+ });
838
+ }
620
839
  /** Thrown when a Midnight amount exceeds the maximum offer-cap value accepted onchain. */
621
840
  export declare class MidnightAmountExceedsMaxOfferCapError extends Error {
622
841
  constructor(params: {
@@ -769,7 +988,7 @@ export declare class WithdrawSharesExceedSupplyError extends Error {
769
988
  });
770
989
  }
771
990
  /**
772
- * Thrown when `computeReallocations` is called with a withdraw `amount` greater
991
+ * Thrown when a Vault V1 or Vault V2 reallocation planner receives a withdraw `amount` greater
773
992
  * than the target market's current `totalSupplyAssets` — the post-withdraw
774
993
  * supply would be negative, making the on-chain `morphoWithdraw` revert
775
994
  * regardless of any reallocation. Caught here so callers do not pay
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.UnsupportedMidnightAuthorizationTargetError = exports.UnsupportedErc20ApprovalSpenderError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.CryptoUnavailableError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.BundlerErrors = exports.NegativeMaxRepaySharePriceError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.NegativeWithdrawMinSharePriceError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.NegativeReallocationFeeError = exports.NegativeNativeAmountError = exports.NegativeSlippageToleranceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.NonPositiveReallocationAmountError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.ZeroDepositAmountError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.VaultExitBundlesV1PermitMismatchError = exports.VaultIsBlueFeeRecipientError = exports.VaultMorphoMismatchError = exports.InsufficientBlueBalanceForInKindRedeemError = exports.InKindRedeemCoverageError = exports.InKindRedeemZeroDeallocationError = exports.UnsupportedInKindAdapterError = exports.AdapterNotPartOfVaultError = exports.InKindRedeemRequiresSingleAdapterError = exports.ExpiredDeadlineError = exports.EmptyMarketParamsListError = exports.NonPositiveInputError = exports.NegativeInputError = void 0;
4
- exports.MutuallyExclusiveWithdrawAmountsError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.UnpreparedMidnightOfferRootSignatureError = exports.MidnightOfferRootOfferCountMismatchError = exports.MidnightOfferRootRatifierMismatchError = exports.MidnightOfferRootOwnerMismatchError = exports.MidnightOfferRootMismatchError = exports.MissingMidnightOfferRootSignatureError = exports.UnknownMidnightRatifierError = exports.MidnightTakeableOfferMarketMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.MidnightAmountExceedsMaxOfferCapError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.DisabledReallocationMarketError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.EmptyReallocationWithdrawalsError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.NativeAmountOnNonWNativeAssetError = exports.VaultAddressMismatchError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositSpenderMismatchError = exports.DepositOwnerMismatchError = void 0;
5
- exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.BorrowAmountAndSharesExclusiveError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = void 0;
3
+ exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.UnsupportedMidnightAuthorizationTargetError = exports.UnsupportedErc20ApprovalSpenderError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.CryptoUnavailableError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.BundlerErrors = exports.NegativeMaxRepaySharePriceError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.NegativeWithdrawMinSharePriceError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.NegativeReallocationFeeError = exports.NegativeNativeAmountError = exports.NegativeSlippageToleranceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.NonPositiveReallocationAmountError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.ZeroDepositAmountError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.VaultExitBundlesV1PermitMismatchError = exports.VaultIsBlueFeeRecipientError = exports.VaultMorphoMismatchError = exports.InsufficientBlueBalanceForInKindRedeemError = exports.InKindRedeemCoverageError = exports.InKindRedeemZeroDeallocationError = exports.UnsupportedInKindAdapterError = exports.AdapterNotPartOfVaultError = exports.InKindRedeemRequiresSingleAdapterError = exports.ExpiredDeadlineError = exports.EmptyMarketParamsListError = exports.InputExceedsMaxError = exports.NonPositiveInputError = exports.NegativeInputError = void 0;
4
+ exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.MidnightAmountExceedsMaxOfferCapError = exports.ReallocationAdapterSupplySharesUnderflowError = exports.ReallocationAllocationUnderflowError = exports.UnknownReallocationAdapterError = exports.UnknownReallocationMarketPublicAllocatorConfigError = exports.UnknownReallocationActiveAdaptersError = exports.UnknownReallocationPublicAllocatorConfigError = exports.UnknownReallocationAllocationError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.DisabledReallocationMarketError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.UnsortedReallocationWithdrawalsError = exports.InconsistentReallocationPenaltyError = exports.InvalidReallocationSourceTypeError = exports.InvalidReallocationAddressError = exports.MixedReallocationVersionsError = exports.InvalidReallocationShapeError = exports.ReallocationWithdrawalOnTargetMarketError = exports.EmptyReallocationWithdrawalsError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.NativeAmountOnNonWNativeAssetError = exports.VaultAddressMismatchError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositSpenderMismatchError = exports.DepositOwnerMismatchError = exports.DepositAssetMismatchError = void 0;
5
+ exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.BorrowAmountAndSharesExclusiveError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.UnpreparedMidnightOfferRootSignatureError = exports.MidnightOfferRootOfferCountMismatchError = exports.MidnightOfferRootRatifierMismatchError = exports.MidnightOfferRootOwnerMismatchError = exports.MidnightOfferRootMismatchError = exports.MissingMidnightOfferRootSignatureError = exports.UnknownMidnightRatifierError = exports.MidnightTakeableOfferMarketMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = void 0;
6
6
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
7
  /**
8
8
  * Thrown when a morpho-sdk input that must be non-negative is negative.
@@ -60,6 +60,29 @@ class NonPositiveInputError extends Error {
60
60
  }
61
61
  }
62
62
  exports.NonPositiveInputError = NonPositiveInputError;
63
+ /** Thrown when an integer input exceeds its protocol-defined maximum. */
64
+ class InputExceedsMaxError extends Error {
65
+ /**
66
+ * @param params - Maximum-bound validation details.
67
+ * @param params.field - Public input field whose value is invalid.
68
+ * @param params.value - Supplied value.
69
+ * @param params.max - Largest accepted value.
70
+ */
71
+ constructor(params) {
72
+ super(`Input "${params.field}" must be at most "${params.max}", got "${params.value}".`);
73
+ this.field = params.field;
74
+ this.value = params.value;
75
+ this.max = params.max;
76
+ this.name = "InputExceedsMaxError";
77
+ }
78
+ /** Public input field whose value is invalid. */
79
+ field;
80
+ /** Supplied value. */
81
+ value;
82
+ /** Largest accepted value. */
83
+ max;
84
+ }
85
+ exports.InputExceedsMaxError = InputExceedsMaxError;
63
86
  /** Thrown when an in-kind redemption does not include any Morpho Blue market parameters. */
64
87
  class EmptyMarketParamsListError extends Error {
65
88
  constructor() {
@@ -362,6 +385,31 @@ var BundlerErrors;
362
385
  }
363
386
  }
364
387
  BundlerErrors.UnexpectedSignature = UnexpectedSignature;
388
+ /**
389
+ * Thrown when a skippable Blue Public Allocator call would leave a usable
390
+ * token allowance behind after the allocator call reverts.
391
+ *
392
+ * @example
393
+ * ```ts
394
+ * import { BundlerErrors } from "@morpho-org/morpho-sdk";
395
+ *
396
+ * if (error instanceof BundlerErrors.SkippableAllocatorPenalty) {
397
+ * // Rebuild the allocator call with skipRevert set to false.
398
+ * }
399
+ * ```
400
+ */
401
+ class SkippableAllocatorPenalty extends Error {
402
+ penaltyAssets;
403
+ /**
404
+ * @param penaltyAssets - Exact token amount approved to the allocator.
405
+ */
406
+ constructor(penaltyAssets) {
407
+ super(`Blue Public Allocator calls with penalty assets cannot skip reverts. Rebuild with skipRevert false for penalty amount "${penaltyAssets}".`);
408
+ this.penaltyAssets = penaltyAssets;
409
+ this.name = "SkippableAllocatorPenalty";
410
+ }
411
+ }
412
+ BundlerErrors.SkippableAllocatorPenalty = SkippableAllocatorPenalty;
365
413
  })(BundlerErrors || (exports.BundlerErrors = BundlerErrors = {}));
366
414
  /**
367
415
  * Thrown when `buildTx` receives more than one requirement signature of the same kind.
@@ -590,13 +638,144 @@ class EmptyReallocationWithdrawalsError extends Error {
590
638
  }
591
639
  }
592
640
  exports.EmptyReallocationWithdrawalsError = EmptyReallocationWithdrawalsError;
593
- /** Thrown when a reallocation withdrawal references the operation's target market (which would be a no-op or self-deal). */
641
+ /** Thrown when a Public Allocator source references the target Blue market. */
594
642
  class ReallocationWithdrawalOnTargetMarketError extends Error {
595
643
  constructor(vault, marketId) {
596
644
  super(`Reallocation withdrawal cannot include the target market ${marketId} for vault ${vault}.`);
597
645
  }
598
646
  }
599
647
  exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTargetMarketError;
648
+ /**
649
+ * Thrown when a Public Allocator reallocation does not match exactly one V1 or
650
+ * V2 input shape.
651
+ *
652
+ * @example
653
+ * ```ts
654
+ * import { InvalidReallocationShapeError } from "@morpho-org/morpho-sdk";
655
+ *
656
+ * const error = new InvalidReallocationShapeError();
657
+ * ```
658
+ */
659
+ class InvalidReallocationShapeError extends Error {
660
+ constructor() {
661
+ super('Reallocation must contain either V1 "withdrawals" or V2 "from", but not both.');
662
+ this.name = "InvalidReallocationShapeError";
663
+ }
664
+ }
665
+ exports.InvalidReallocationShapeError = InvalidReallocationShapeError;
666
+ /**
667
+ * Thrown when one reallocation plan contains both Vault V1 and Vault V2 entries.
668
+ *
669
+ * @example
670
+ * ```ts
671
+ * import { MixedReallocationVersionsError } from "@morpho-org/morpho-sdk";
672
+ *
673
+ * const error = new MixedReallocationVersionsError();
674
+ * ```
675
+ */
676
+ class MixedReallocationVersionsError extends Error {
677
+ constructor() {
678
+ super("Reallocation plans cannot mix Vault V1 and Vault V2 entries. Submit one version per transaction.");
679
+ this.name = "MixedReallocationVersionsError";
680
+ }
681
+ }
682
+ exports.MixedReallocationVersionsError = MixedReallocationVersionsError;
683
+ /**
684
+ * Thrown when a Blue Public Allocator reallocation contains a malformed vault
685
+ * or adapter address.
686
+ *
687
+ * @example
688
+ * ```ts
689
+ * import { InvalidReallocationAddressError } from "@morpho-org/morpho-sdk";
690
+ *
691
+ * const error = new InvalidReallocationAddressError("to.adapter");
692
+ * if (error instanceof InvalidReallocationAddressError) {
693
+ * console.error(error.field);
694
+ * }
695
+ * ```
696
+ */
697
+ class InvalidReallocationAddressError extends Error {
698
+ field;
699
+ /**
700
+ * @param field - Reallocation address field that is absent or malformed.
701
+ */
702
+ constructor(field) {
703
+ super(`Reallocation "${field}" must be a valid address.`);
704
+ this.field = field;
705
+ this.name = "InvalidReallocationAddressError";
706
+ }
707
+ }
708
+ exports.InvalidReallocationAddressError = InvalidReallocationAddressError;
709
+ /**
710
+ * Thrown when a Blue Public Allocator source is absent, incomplete, or has an
711
+ * unknown discriminator.
712
+ *
713
+ * @example
714
+ * ```ts
715
+ * import { InvalidReallocationSourceTypeError } from "@morpho-org/morpho-sdk";
716
+ *
717
+ * const error = new InvalidReallocationSourceTypeError("marketTypo");
718
+ * ```
719
+ */
720
+ class InvalidReallocationSourceTypeError extends Error {
721
+ sourceType;
722
+ missingField;
723
+ /**
724
+ * @param sourceType - Invalid runtime value received for `reallocation.from.type`,
725
+ * or `undefined` when the source or discriminator is absent.
726
+ * @param missingField - Required market-source field that is absent or malformed.
727
+ */
728
+ constructor(sourceType, missingField) {
729
+ super(missingField == null
730
+ ? sourceType === undefined
731
+ ? 'Reallocation source must specify type "market" or "idle".'
732
+ : `Reallocation source type must be "market" or "idle", got "${sourceType}".`
733
+ : `Reallocation market source must include a valid "${missingField}".`);
734
+ this.sourceType = sourceType;
735
+ this.missingField = missingField;
736
+ this.name = "InvalidReallocationSourceTypeError";
737
+ }
738
+ }
739
+ exports.InvalidReallocationSourceTypeError = InvalidReallocationSourceTypeError;
740
+ /**
741
+ * Thrown when one bundle assigns different penalty rates to the same Vault V2.
742
+ *
743
+ * @example
744
+ * ```ts
745
+ * import { InconsistentReallocationPenaltyError } from "@morpho-org/morpho-sdk";
746
+ * import type { Address } from "viem";
747
+ *
748
+ * const vaultFixture =
749
+ * "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
750
+ * const error = new InconsistentReallocationPenaltyError({
751
+ * vault: vaultFixture,
752
+ * expected: 5n,
753
+ * actual: 11n,
754
+ * });
755
+ * ```
756
+ */
757
+ class InconsistentReallocationPenaltyError extends Error {
758
+ /** Vault whose configured penalty must be reused. */
759
+ vault;
760
+ /** Penalty rate established by the first matching bundle entry. */
761
+ expected;
762
+ /** Conflicting penalty rate supplied by a later bundle entry. */
763
+ actual;
764
+ /**
765
+ * @param params - Conflicting vault penalty details.
766
+ * @param params.vault - Vault whose configured penalty applies.
767
+ * @param params.expected - Penalty rate established by the first matching entry.
768
+ * @param params.actual - Conflicting penalty rate supplied by a later entry.
769
+ */
770
+ constructor(params) {
771
+ super(`Penalty for vault "${params.vault}" must remain "${params.expected}" across the bundle, got "${params.actual}". Use the vault's configured penalty for every call.`);
772
+ this.vault = params.vault;
773
+ this.expected = params.expected;
774
+ this.actual = params.actual;
775
+ this.name = "InconsistentReallocationPenaltyError";
776
+ }
777
+ }
778
+ exports.InconsistentReallocationPenaltyError = InconsistentReallocationPenaltyError;
600
779
  /** Thrown when reallocation withdrawals within a vault are not strictly sorted by market id. */
601
780
  class UnsortedReallocationWithdrawalsError extends Error {
602
781
  constructor(vault, marketId) {
@@ -683,8 +862,8 @@ class DisabledReallocationMarketError extends Error {
683
862
  }
684
863
  exports.DisabledReallocationMarketError = DisabledReallocationMarketError;
685
864
  /**
686
- * Thrown when shared liquidity selected by `computeReallocations` cannot cover
687
- * the operation's absolute shortfall on the target market — the resulting
865
+ * Thrown when shared liquidity selected by a Vault V1 or Vault V2 reallocation planner cannot
866
+ * cover the operation's absolute shortfall on the target market — the resulting
688
867
  * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
689
868
  *
690
869
  * Pattern-match on the class and inspect `params` to surface the gap to users.
@@ -751,6 +930,89 @@ class UnknownReallocationPositionError extends blue_sdk_1.UnknownDataError {
751
930
  }
752
931
  }
753
932
  exports.UnknownReallocationPositionError = UnknownReallocationPositionError;
933
+ /** Thrown when Vault V2 reallocation state does not contain a requested allocation id. */
934
+ class UnknownReallocationAllocationError extends blue_sdk_1.UnknownDataError {
935
+ vault;
936
+ id;
937
+ /**
938
+ * @param vault - Vault V2 address for the missing allocation.
939
+ * @param id - Missing Vault V2 allocation id.
940
+ */
941
+ constructor(vault, id) {
942
+ super(`unknown reallocation allocation "${id}" for vault "${vault}"`);
943
+ this.vault = vault;
944
+ this.id = id;
945
+ }
946
+ }
947
+ exports.UnknownReallocationAllocationError = UnknownReallocationAllocationError;
948
+ /** Thrown when Vault V2 reallocation state lacks the vault-wide allocator configuration. */
949
+ class UnknownReallocationPublicAllocatorConfigError extends blue_sdk_1.UnknownDataError {
950
+ vault;
951
+ /** @param vault - Vault V2 address with missing allocator configuration. */
952
+ constructor(vault) {
953
+ super(`unknown public allocator configuration for vault "${vault}"`);
954
+ this.vault = vault;
955
+ }
956
+ }
957
+ exports.UnknownReallocationPublicAllocatorConfigError = UnknownReallocationPublicAllocatorConfigError;
958
+ /** Thrown when Vault V2 reallocation state lacks the fetched active-adapter set. */
959
+ class UnknownReallocationActiveAdaptersError extends blue_sdk_1.UnknownDataError {
960
+ vault;
961
+ /** @param vault - Vault V2 address with missing active-adapter state. */
962
+ constructor(vault) {
963
+ super(`unknown active adapters for reallocation vault "${vault}"`);
964
+ this.vault = vault;
965
+ }
966
+ }
967
+ exports.UnknownReallocationActiveAdaptersError = UnknownReallocationActiveAdaptersError;
968
+ /** Thrown when Vault V2 reallocation state lacks an adapter-market allocator configuration. */
969
+ class UnknownReallocationMarketPublicAllocatorConfigError extends blue_sdk_1.UnknownDataError {
970
+ vault;
971
+ adapterMarketCapId;
972
+ /**
973
+ * @param vault - Vault V2 address for the missing configuration.
974
+ * @param adapterMarketCapId - Missing adapter-scoped market cap id.
975
+ */
976
+ constructor(vault, adapterMarketCapId) {
977
+ super(`unknown public allocator configuration "${adapterMarketCapId}" for vault "${vault}"`);
978
+ this.vault = vault;
979
+ this.adapterMarketCapId = adapterMarketCapId;
980
+ }
981
+ }
982
+ exports.UnknownReallocationMarketPublicAllocatorConfigError = UnknownReallocationMarketPublicAllocatorConfigError;
983
+ /** Thrown when Vault V2 reallocation state does not contain a requested adapter. */
984
+ class UnknownReallocationAdapterError extends blue_sdk_1.UnknownDataError {
985
+ vault;
986
+ adapter;
987
+ /**
988
+ * @param vault - Vault V2 address expected to own the adapter.
989
+ * @param adapter - Missing adapter address.
990
+ */
991
+ constructor(vault, adapter) {
992
+ super(`unknown reallocation adapter "${adapter}" for vault "${vault}"`);
993
+ this.vault = vault;
994
+ this.adapter = adapter;
995
+ }
996
+ }
997
+ exports.UnknownReallocationAdapterError = UnknownReallocationAdapterError;
998
+ /** Thrown when a simulated Vault V2 allocation transition would underflow. */
999
+ class ReallocationAllocationUnderflowError extends Error {
1000
+ params;
1001
+ constructor(params) {
1002
+ super(`Reallocation change "${params.change}" exceeds allocation "${params.allocation}" for id "${params.id}" on vault "${params.vault}". Refresh the reallocation data and recompute the plan.`);
1003
+ this.params = params;
1004
+ }
1005
+ }
1006
+ exports.ReallocationAllocationUnderflowError = ReallocationAllocationUnderflowError;
1007
+ /** Thrown when a simulated Vault V2 market withdrawal exceeds the adapter's supply shares. */
1008
+ class ReallocationAdapterSupplySharesUnderflowError extends Error {
1009
+ params;
1010
+ constructor(params) {
1011
+ super(`Reallocation withdraw shares "${params.withdrawnShares}" exceed adapter supply shares "${params.supplyShares}" on market "${params.marketId}" for adapter "${params.adapter}". Refresh the reallocation data and recompute the plan.`);
1012
+ this.params = params;
1013
+ }
1014
+ }
1015
+ exports.ReallocationAdapterSupplySharesUnderflowError = ReallocationAdapterSupplySharesUnderflowError;
754
1016
  /** Thrown when a Midnight amount exceeds the maximum offer-cap value accepted onchain. */
755
1017
  class MidnightAmountExceedsMaxOfferCapError extends Error {
756
1018
  constructor(params) {
@@ -906,7 +1168,7 @@ class WithdrawSharesExceedSupplyError extends Error {
906
1168
  }
907
1169
  exports.WithdrawSharesExceedSupplyError = WithdrawSharesExceedSupplyError;
908
1170
  /**
909
- * Thrown when `computeReallocations` is called with a withdraw `amount` greater
1171
+ * Thrown when a Vault V1 or Vault V2 reallocation planner receives a withdraw `amount` greater
910
1172
  * than the target market's current `totalSupplyAssets` — the post-withdraw
911
1173
  * supply would be negative, making the on-chain `morphoWithdraw` revert
912
1174
  * regardless of any reallocation. Caught here so callers do not pay