@morpho-org/morpho-sdk 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +3 -1
  2. package/lib/cjs/actions/blue/borrow.d.ts +1 -0
  3. package/lib/cjs/actions/blue/borrow.js +1 -0
  4. package/lib/cjs/actions/blue/refinance.d.ts +1 -0
  5. package/lib/cjs/actions/blue/refinance.js +3 -0
  6. package/lib/cjs/actions/blue/repay.d.ts +1 -0
  7. package/lib/cjs/actions/blue/repay.js +1 -0
  8. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  9. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
  10. package/lib/cjs/actions/blue/supply.d.ts +1 -0
  11. package/lib/cjs/actions/blue/supply.js +2 -0
  12. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
  13. package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
  14. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  15. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
  16. package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
  17. package/lib/cjs/actions/blue/withdraw.js +2 -0
  18. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
  19. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
  20. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  21. package/lib/cjs/actions/midnight/takeLend.js +1 -0
  22. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  23. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  24. package/lib/cjs/blue/errors.d.ts +1 -1
  25. package/lib/cjs/blue/errors.js +2 -1
  26. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  27. package/lib/cjs/client/morphoViemExtension.js +1 -7
  28. package/lib/cjs/entities/blue/blue.d.ts +43 -7
  29. package/lib/cjs/entities/blue/blue.js +27 -3
  30. package/lib/cjs/entities/midnight/midnight.d.ts +14 -6
  31. package/lib/cjs/entities/midnight/midnight.js +14 -6
  32. package/lib/cjs/entities/midnight/types.d.ts +9 -2
  33. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +3 -1
  34. package/lib/cjs/entities/vaultV2/vaultV2.js +8 -5
  35. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +40 -13
  36. package/lib/cjs/entities/vaultV2BlueReallocationData.js +207 -70
  37. package/lib/cjs/errors.d.ts +1 -1
  38. package/lib/cjs/errors.js +3 -2
  39. package/lib/cjs/helpers/validate.d.ts +11 -1
  40. package/lib/cjs/helpers/validate.js +17 -1
  41. package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
  42. package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
  43. package/lib/cjs/types/error.d.ts +10 -1
  44. package/lib/cjs/types/error.js +13 -2
  45. package/lib/cjs/types/sharedLiquidity.d.ts +27 -11
  46. package/lib/esm/actions/blue/borrow.d.ts +1 -0
  47. package/lib/esm/actions/blue/borrow.js +1 -0
  48. package/lib/esm/actions/blue/refinance.d.ts +1 -0
  49. package/lib/esm/actions/blue/refinance.js +4 -1
  50. package/lib/esm/actions/blue/repay.d.ts +1 -0
  51. package/lib/esm/actions/blue/repay.js +1 -0
  52. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  53. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
  54. package/lib/esm/actions/blue/supply.d.ts +1 -0
  55. package/lib/esm/actions/blue/supply.js +3 -1
  56. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
  57. package/lib/esm/actions/blue/supplyCollateral.js +1 -0
  58. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  59. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
  60. package/lib/esm/actions/blue/withdraw.d.ts +1 -0
  61. package/lib/esm/actions/blue/withdraw.js +3 -1
  62. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
  63. package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
  64. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  65. package/lib/esm/actions/midnight/takeLend.js +1 -0
  66. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  67. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  68. package/lib/esm/blue/errors.d.ts +1 -1
  69. package/lib/esm/blue/errors.js +1 -1
  70. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  71. package/lib/esm/client/morphoViemExtension.js +1 -7
  72. package/lib/esm/entities/blue/blue.d.ts +43 -7
  73. package/lib/esm/entities/blue/blue.js +27 -3
  74. package/lib/esm/entities/midnight/midnight.d.ts +14 -6
  75. package/lib/esm/entities/midnight/midnight.js +14 -6
  76. package/lib/esm/entities/midnight/types.d.ts +9 -2
  77. package/lib/esm/entities/vaultV2/vaultV2.d.ts +3 -1
  78. package/lib/esm/entities/vaultV2/vaultV2.js +9 -6
  79. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +40 -13
  80. package/lib/esm/entities/vaultV2BlueReallocationData.js +208 -71
  81. package/lib/esm/errors.d.ts +1 -1
  82. package/lib/esm/errors.js +1 -1
  83. package/lib/esm/helpers/validate.d.ts +11 -1
  84. package/lib/esm/helpers/validate.js +15 -0
  85. package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
  86. package/lib/esm/helpers/validateTakeableOffers.js +13 -2
  87. package/lib/esm/types/error.d.ts +10 -1
  88. package/lib/esm/types/error.js +11 -1
  89. package/lib/esm/types/sharedLiquidity.d.ts +27 -11
  90. package/package.json +4 -4
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DepositOwnerMismatchError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.UnsupportedMidnightAuthorizationTargetError = exports.UnsupportedErc20ApprovalSpenderError = exports.MissingClientPropertyError = exports.CryptoUnavailableError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.UnsupportedRequirementSignatureError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.MaxRepayAssetsBelowRepayAssetsError = exports.ReallocationsRequireBorrowError = exports.UnsupportedAuthorizationOperatorError = exports.ReallocationLoanTokenMismatchError = exports.SameVaultMigrationError = exports.AmountAndSharesExclusiveError = exports.MixedBundlesFundingError = exports.MidnightReferralFeePctExceededError = exports.ReferralFeePctExceededError = exports.ReferralFeeRecipientMissingError = exports.NativeFundingAmountMismatchError = exports.NoUnusedPermit2NonceError = exports.Permit2SignatureTransferNonceAlreadyUsedError = exports.BundlesRequirementSignatureMismatchError = exports.BundlesPermitMismatchError = exports.VaultIsBlueFeeRecipientError = exports.VaultMorphoMismatchError = exports.InsufficientBlueBalanceForInKindRedeemError = exports.InKindRedeemCoverageError = exports.InKindRedeemZeroDeallocationError = exports.VaultV2ForceWithdrawFeeSharesExceedBurnError = exports.VaultV2ForceWithdrawSharePriceBelowFloorError = exports.VaultV2ForceWithdrawZeroSharePriceError = exports.VaultV2ForceWithdrawZeroWithdrawalError = exports.VaultV2ForceWithdrawCoverageError = exports.VaultV2UndecodableLiquidityDataError = exports.VaultV2UnsupportedLiquidityAdapterError = exports.VaultV2UnsupportedExitAdapterError = exports.AdapterNotPartOfVaultError = exports.VaultV2SingleAdapterRequiredError = exports.ExpiredDeadlineError = exports.EmptyMarketParamsListError = exports.InputExceedsMaxError = exports.NonPositiveInputError = exports.NegativeInputError = void 0;
4
4
  exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightTakeDeadlineTooFarError = exports.MidnightContractReceiverError = exports.MidnightZeroOnBehalfError = exports.MidnightZeroReceiverError = exports.MidnightRepayExceedsDebtError = exports.MidnightContinuousFeeAboveMaxError = exports.MidnightTakeTargetUnreachableError = exports.MidnightTakeableOffersNotFillableError = exports.UnboundedMidnightTakeInputError = exports.MidnightOfferSellerReceiverMismatchError = exports.MidnightOfferContinuousFeeCapError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferReduceOnlyError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.DuplicateMidnightGroupCancellationError = exports.EmptyMidnightCollateralSuppliesError = exports.EmptyMidnightGroupCancellationsError = exports.ReallocationAdapterSupplySharesUnderflowError = exports.ReallocationAllocationUnderflowError = exports.UnknownReallocationAdapterError = exports.UnknownReallocationMarketPublicAllocatorConfigError = exports.UnknownReallocationActiveAdaptersError = exports.UnknownReallocationPublicAllocatorConfigError = exports.UnknownReallocationAllocationError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.MutuallyExclusiveRepayAmountsError = exports.InconsistentReallocationPenaltyError = exports.InvalidReallocationSourceTypeError = exports.InvalidReallocationAddressError = exports.InvalidVaultV2BlueReallocationShapeError = exports.ReallocationWithdrawalOnTargetMarketError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeAssetError = exports.VaultAddressMismatchError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositSpenderMismatchError = void 0;
5
- exports.MidnightCalldataEncodingError = exports.MidnightZeroAccountError = exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferMarketMismatchError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = void 0;
5
+ exports.MidnightCalldataEncodingError = exports.MidnightZeroAccountError = exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferZeroSellerReceiverError = exports.MidnightTakeableOfferMarketMismatchError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = void 0;
6
6
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
7
  const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
8
8
  const constant_js_1 = require("../helpers/constant.js");
@@ -1697,7 +1697,10 @@ class EmptyBlueParkingMarketError extends Error {
1697
1697
  }
1698
1698
  }
1699
1699
  exports.EmptyBlueParkingMarketError = EmptyBlueParkingMarketError;
1700
- /** Thrown when parked assets would mint no Morpho Blue supply shares. */
1700
+ /**
1701
+ * Thrown when parked assets would mint no Morpho Blue supply shares at preparation time; see
1702
+ * `MorphoMidnight.supplyBlueMakeLend` for why this is not an execution-time guarantee.
1703
+ */
1701
1704
  class ZeroBlueParkingSharesError extends Error {
1702
1705
  constructor(params) {
1703
1706
  super(`Supplying "${params.assets}" assets to Morpho Blue market "${params.marketId}" mints zero supply shares at its current share price; park more assets or choose another market.`);
@@ -1713,6 +1716,14 @@ class MidnightTakeableOfferMarketMismatchError extends Error {
1713
1716
  }
1714
1717
  }
1715
1718
  exports.MidnightTakeableOfferMarketMismatchError = MidnightTakeableOfferMarketMismatchError;
1719
+ /** Thrown when a quoted Midnight sell offer routes its seller proceeds to the zero address. */
1720
+ class MidnightTakeableOfferZeroSellerReceiverError extends Error {
1721
+ constructor(params) {
1722
+ super(`Midnight takeable offer "${params.index}" routes seller proceeds to the zero address. Drop the offer or refresh the quote.`);
1723
+ this.name = "MidnightTakeableOfferZeroSellerReceiverError";
1724
+ }
1725
+ }
1726
+ exports.MidnightTakeableOfferZeroSellerReceiverError = MidnightTakeableOfferZeroSellerReceiverError;
1716
1727
  /** Thrown when a Midnight offer's ratifier does not match its tree's ratifier route. */
1717
1728
  class MidnightOfferRatifierMismatchError extends Error {
1718
1729
  constructor(params) {
@@ -5,12 +5,15 @@ export interface VaultV2BluePublicAllocatorOptions {
5
5
  /** Whether Vault V2 public allocator discovery is enabled. */
6
6
  readonly enabled?: boolean;
7
7
  /**
8
- * Timestamp at which market and Vault V2 state is evaluated. Canonical state
9
- * and the returned post-state stay at this timestamp; only target-market cap
10
- * checks reserve interest on the vault's existing allocation through this
11
- * timestamp plus `capAccrualBuffer`. For market-source reallocations the
12
- * source position's interest is also reserved on cap ids shared with the
13
- * target, and reserves persist across every leg of a plan.
8
+ * Timestamp at which market and Vault V2 state is evaluated. Defaults to the
9
+ * snapshot's timestamp (the fetched block's timestamp), never earlier than
10
+ * the latest market/vault `lastUpdate`; when the snapshot has no timestamp,
11
+ * defaults to the latest market/vault `lastUpdate`. Canonical state and the
12
+ * returned post-state stay at this timestamp; only target-market cap checks
13
+ * reserve interest on the vault's existing allocation through this timestamp
14
+ * plus `capAccrualBuffer`. For market-source reallocations the source
15
+ * position's interest is also reserved on cap ids shared with the target, and
16
+ * reserves persist across every leg of a plan.
14
17
  */
15
18
  readonly timestamp?: BigIntish;
16
19
  /**
@@ -53,16 +56,29 @@ export interface VaultV2BluePublicAllocatorOptions {
53
56
  readonly reallocatableVaults?: Iterable<Address>;
54
57
  /**
55
58
  * Maximum utilization source markets may reach during friendly discovery,
56
- * scaled by WAD. The amount-aware planner falls back to 100% only when the
57
- * friendly phase cannot cover the operation's absolute shortfall.
59
+ * scaled by WAD. Within each penalty tier, the amount-aware planner falls
60
+ * back to 100% only when that tier's friendly pass leaves an absolute
61
+ * shortfall.
58
62
  *
59
63
  * @default 90% (900000000000000000n)
60
64
  */
61
65
  readonly maxWithdrawalUtilization?: bigint;
62
66
  /**
63
- * Maximum proportional vault-asset penalty accepted for each
64
- * BluePublicAllocator call, scaled by WAD. Vaults with a higher configured
65
- * penalty are ignored. Must not exceed WAD (100%).
67
+ * Maximum proportional vault-asset penalty accepted per call, scaled by
68
+ * WAD; higher-penalty vaults are ignored. Must not exceed WAD. Operation
69
+ * plans consider penalty tiers ascending, free first. Each tier uses friendly
70
+ * source utilization (90% by default) before 100%; positive tiers cover only
71
+ * the remaining absolute shortfall. Free capacity inside
72
+ * `allocatorCapHeadroom` stays unused, so a penalized leg can cover it.
73
+ * Getters count all vaults up to this limit. For `refinance`, compute the
74
+ * plan on the destination-market handle (for example,
75
+ * `client.morpho.blue(destination.marketParams, chainId)`), not the source
76
+ * handle. Pass the source position's `borrowAssets` accrued to
77
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
78
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
79
+ * The planner includes the referral fee and its own allocator-leg penalties
80
+ * in destination debt, so penalized legs also cover their own penalty.
81
+ * Refinance never uses vaults with a 100% penalty.
66
82
  *
67
83
  * @default 0n
68
84
  */
@@ -50,6 +50,7 @@ export interface BlueBorrowParams {
50
50
  * @param params.metadata - Optional transaction metadata.
51
51
  * @returns A deep-frozen `Readonly<Transaction<BlueBorrowAction>>` whose calldata invokes the
52
52
  * combined BlueBundlesV1 entrypoint with a zero collateral leg.
53
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
53
54
  * @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
54
55
  * @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
55
56
  * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
@@ -20,6 +20,7 @@ import { blueSupplyCollateralBorrow } from "./supplyCollateralBorrow.js";
20
20
  * @param params.metadata - Optional transaction metadata.
21
21
  * @returns A deep-frozen `Readonly<Transaction<BlueBorrowAction>>` whose calldata invokes the
22
22
  * combined BlueBundlesV1 entrypoint with a zero collateral leg.
23
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
23
24
  * @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
24
25
  * @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
25
26
  * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
@@ -56,6 +56,7 @@ export interface BlueRefinanceParams {
56
56
  * @param params.metadata - Optional transaction metadata.
57
57
  * @returns A deep-frozen `Readonly<Transaction<BlueRefinanceAction>>` whose
58
58
  * `to` address is BlueBundlesV1 and whose `action` records the normalized migration inputs.
59
+ * @throws {MarketIdMismatchError} when either market's `id` does not hash from its tuple fields.
59
60
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
60
61
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
61
62
  * @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData, isAddressEqual } from "viem";
2
2
  import { blueBundlesV1Abi } from "../../abis.js";
3
- import { validateUint256Field } from "../../helpers/validate.js";
3
+ import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
4
4
  import { RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
5
5
  import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1SignedAuthorization, normalizeBlueBundlesV1CommonParams, } from "./common.js";
6
6
  /**
@@ -26,6 +26,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
26
26
  * @param params.metadata - Optional transaction metadata.
27
27
  * @returns A deep-frozen `Readonly<Transaction<BlueRefinanceAction>>` whose
28
28
  * `to` address is BlueBundlesV1 and whose `action` records the normalized migration inputs.
29
+ * @throws {MarketIdMismatchError} when either market's `id` does not hash from its tuple fields.
29
30
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
30
31
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
31
32
  * @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
@@ -64,6 +65,8 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
64
65
  */
65
66
  export const blueRefinance = (params) => {
66
67
  const { chainId, sourceMarketParams, destinationMarketParams } = params.market;
68
+ validateMarketParamsId(sourceMarketParams);
69
+ validateMarketParamsId(destinationMarketParams);
67
70
  const { userAddress, maxLtv, authorizationSignature } = params.args;
68
71
  if (sourceMarketParams.id === destinationMarketParams.id) {
69
72
  throw new RefinanceSameMarketError(sourceMarketParams.id);
@@ -53,6 +53,7 @@ export interface BlueRepayParams {
53
53
  * @param params.metadata - Optional transaction metadata.
54
54
  * @returns A deep-frozen `Readonly<Transaction<BlueRepayAction>>` whose calldata invokes the
55
55
  * combined BlueBundlesV1 entrypoint with a zero collateral-withdrawal leg.
56
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
56
57
  * @throws {NegativeInputError} when an amount or fee is negative.
57
58
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
58
59
  * @throws {NonPositiveInputError} when repayment, funding, or deadline is not positive.
@@ -22,6 +22,7 @@ import { blueRepayWithdrawCollateral } from "./repayWithdrawCollateral.js";
22
22
  * @param params.metadata - Optional transaction metadata.
23
23
  * @returns A deep-frozen `Readonly<Transaction<BlueRepayAction>>` whose calldata invokes the
24
24
  * combined BlueBundlesV1 entrypoint with a zero collateral-withdrawal leg.
25
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
25
26
  * @throws {NegativeInputError} when an amount or fee is negative.
26
27
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
27
28
  * @throws {NonPositiveInputError} when repayment, funding, or deadline is not positive.
@@ -63,6 +63,7 @@ export interface BlueRepayWithdrawCollateralParams {
63
63
  * @param params.metadata - Optional transaction metadata.
64
64
  * @returns A deep-frozen `Readonly<Transaction<BlueRepayWithdrawCollateralAction>>`
65
65
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
66
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
66
67
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
67
68
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
68
69
  * @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData } from "viem";
2
2
  import { blueBundlesV1Abi } from "../../abis.js";
3
- import { validateUint256Field } from "../../helpers/validate.js";
3
+ import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
4
4
  import { InputExceedsMaxError, MaxRepayAssetsBelowRepayAssetsError, MutuallyExclusiveRepayAmountsError, NonPositiveInputError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
5
5
  import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1ReferralFeeAssets, getBlueBundlesV1SignedAuthorization, getBlueBundlesV1TokenPermit, normalizeBlueBundlesV1CommonParams, validateBlueBundlesV1NativeFunding, } from "./common.js";
6
6
  /**
@@ -28,6 +28,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1ReferralFeeAssets, ge
28
28
  * @param params.metadata - Optional transaction metadata.
29
29
  * @returns A deep-frozen `Readonly<Transaction<BlueRepayWithdrawCollateralAction>>`
30
30
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
31
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
31
32
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
32
33
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
33
34
  * @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
@@ -70,6 +71,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1ReferralFeeAssets, ge
70
71
  */
71
72
  export const blueRepayWithdrawCollateral = (params) => {
72
73
  const { chainId, marketParams } = params.market;
74
+ validateMarketParamsId(marketParams);
73
75
  const { userAddress, repayAssets, repayShares, maxRepayAssets, collateralAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
74
76
  for (const [field, value] of [
75
77
  ["repayAssets", repayAssets],
@@ -47,6 +47,7 @@ export interface BlueSupplyParams {
47
47
  * @param params.metadata - Optional transaction metadata.
48
48
  * @returns A deep-frozen `Readonly<Transaction<BlueSupplyAction>>` whose `to` address is
49
49
  * BlueBundlesV1 and whose `action` records the normalized supply inputs.
50
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
50
51
  * @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
51
52
  * @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
52
53
  * @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData } from "viem";
2
2
  import { blueBundlesV1Abi } from "../../abis.js";
3
- import { validateUint256Field } from "../../helpers/validate.js";
3
+ import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
4
4
  import { NonPositiveInputError } from "../../types/index.js";
5
5
  import { getBundlesReferralFeeAssets } from "../bundles/common.js";
6
6
  import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1TokenPermit, normalizeBlueBundlesV1CommonParams, validateBlueBundlesV1NativeFunding, } from "./common.js";
@@ -23,6 +23,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1TokenPermit, normaliz
23
23
  * @param params.metadata - Optional transaction metadata.
24
24
  * @returns A deep-frozen `Readonly<Transaction<BlueSupplyAction>>` whose `to` address is
25
25
  * BlueBundlesV1 and whose `action` records the normalized supply inputs.
26
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
26
27
  * @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
27
28
  * @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
28
29
  * @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
@@ -59,6 +60,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1TokenPermit, normaliz
59
60
  */
60
61
  export const blueSupply = (params) => {
61
62
  const { chainId, marketParams } = params.market;
63
+ validateMarketParamsId(marketParams);
62
64
  const { assets, userAddress, requirementSignature } = params.args;
63
65
  if (assets <= 0n) {
64
66
  throw new NonPositiveInputError("assets", assets);
@@ -47,6 +47,7 @@ export interface BlueSupplyCollateralParams {
47
47
  * @param params.metadata - Optional transaction metadata.
48
48
  * @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
49
49
  * invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
50
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
50
51
  * @throws {NegativeInputError} when an amount or fee is negative.
51
52
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
52
53
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
@@ -20,6 +20,7 @@ import { blueSupplyCollateralBorrow } from "./supplyCollateralBorrow.js";
20
20
  * @param params.metadata - Optional transaction metadata.
21
21
  * @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralAction>>` whose calldata
22
22
  * invokes the combined BlueBundlesV1 entrypoint with a zero borrow leg.
23
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
23
24
  * @throws {NegativeInputError} when an amount or fee is negative.
24
25
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
25
26
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
@@ -59,6 +59,7 @@ export interface BlueSupplyCollateralBorrowParams {
59
59
  * @param params.metadata - Optional transaction metadata.
60
60
  * @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
61
61
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
62
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
62
63
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
63
64
  * @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
64
65
  * or a reallocation amount is not positive.
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData } from "viem";
2
2
  import { blueBundlesV1Abi } from "../../abis.js";
3
- import { validateUint256Field } from "../../helpers/validate.js";
3
+ import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
4
4
  import { InputExceedsMaxError, NonPositiveInputError, ReallocationsRequireBorrowError, UnexpectedRequirementSignatureError, } from "../../types/index.js";
5
5
  import { getBundlesReferralFeeAssets } from "../bundles/common.js";
6
6
  import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1SignedAuthorization, getBlueBundlesV1TokenPermit, normalizeBlueBundlesV1CommonParams, validateBlueBundlesV1NativeFunding, } from "./common.js";
@@ -27,6 +27,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
27
27
  * @param params.metadata - Optional transaction metadata.
28
28
  * @returns A deep-frozen `Readonly<Transaction<BlueSupplyCollateralBorrowAction>>`
29
29
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
30
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
30
31
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
31
32
  * @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
32
33
  * or a reallocation amount is not positive.
@@ -73,6 +74,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
73
74
  */
74
75
  export const blueSupplyCollateralBorrow = (params) => {
75
76
  const { chainId, marketParams } = params.market;
77
+ validateMarketParamsId(marketParams);
76
78
  const { userAddress, collateralAssets, borrowAssets, maxLtv, requirementSignature, authorizationSignature, } = params.args;
77
79
  for (const [field, value] of [
78
80
  ["collateralAssets", collateralAssets],
@@ -51,6 +51,7 @@ export interface BlueWithdrawParams {
51
51
  * @param params.metadata - Optional transaction metadata.
52
52
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
53
53
  * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
54
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
54
55
  * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
55
56
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
56
57
  * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData } from "viem";
2
2
  import { blueBundlesV1Abi } from "../../abis.js";
3
- import { validateUint256Field } from "../../helpers/validate.js";
3
+ import { validateMarketParamsId, validateUint256Field, } from "../../helpers/validate.js";
4
4
  import { InputExceedsMaxError, MutuallyExclusiveWithdrawAmountsError, NonPositiveInputError, } from "../../types/index.js";
5
5
  import { getBundlesReferralFeeAssets } from "../bundles/common.js";
6
6
  import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1SignedAuthorization, normalizeBlueBundlesV1CommonParams, } from "./common.js";
@@ -25,6 +25,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
25
25
  * @param params.metadata - Optional transaction metadata.
26
26
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawAction>>` whose `to` address is
27
27
  * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
28
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
28
29
  * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
29
30
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
30
31
  * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
@@ -63,6 +64,7 @@ import { finalizeBlueBundlesV1Transaction, getBlueBundlesV1PenaltyAssets, getBlu
63
64
  */
64
65
  export const blueWithdraw = (params) => {
65
66
  const { chainId, marketParams } = params.market;
67
+ validateMarketParamsId(marketParams);
66
68
  const { userAddress, withdrawAssets, withdrawShares, authorizationSignature, } = params.args;
67
69
  validateUint256Field("withdrawAssets", withdrawAssets);
68
70
  validateUint256Field("withdrawShares", withdrawShares);
@@ -47,6 +47,7 @@ export interface BlueWithdrawCollateralParams {
47
47
  * @param params.metadata - Optional transaction metadata.
48
48
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
49
49
  * invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
50
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
50
51
  * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
51
52
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
52
53
  * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
@@ -19,6 +19,7 @@ import { blueRepayWithdrawCollateral } from "./repayWithdrawCollateral.js";
19
19
  * @param params.metadata - Optional transaction metadata.
20
20
  * @returns A deep-frozen `Readonly<Transaction<BlueWithdrawCollateralAction>>` whose calldata
21
21
  * invokes the combined BlueBundlesV1 entrypoint with a zero repay leg.
22
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
22
23
  * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
23
24
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
24
25
  * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
@@ -51,6 +51,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
51
51
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
52
52
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
53
53
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
54
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
54
55
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
55
56
  * @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
56
57
  * `referralFeePct` or `nativeAmount` is negative.
@@ -40,6 +40,7 @@ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../t
40
40
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
41
41
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
42
42
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
43
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
43
44
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
44
45
  * @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
45
46
  * `referralFeePct` or `nativeAmount` is negative.
@@ -70,6 +70,7 @@ export interface MidnightTakeRepayWithdrawCollateralParams extends MidnightRefer
70
70
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
71
71
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
72
72
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
73
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
73
74
  * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
74
75
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
75
76
  * withdrawal amount or `deadline` is not positive.
@@ -52,6 +52,7 @@ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../t
52
52
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
53
53
  * @throws {MidnightOfferSideMismatchError} when any offer is not borrow-side.
54
54
  * @throws {MidnightTakeableOfferMarketMismatchError} when any offer belongs to another market.
55
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when any offer routes seller proceeds to the zero address.
55
56
  * @throws {UnknownCollateralIndexError} when a withdrawal targets a collateral index not configured on the market.
56
57
  * @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets`, a
57
58
  * withdrawal amount or `deadline` is not positive.
@@ -1,4 +1,4 @@
1
1
  export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
4
+ export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
@@ -1,4 +1,4 @@
1
1
  export { BlueErrors, DivisionByZeroError, IncompleteChainRegistryError, InvalidAddressError, InvalidBitLengthError, InvalidMarketParamsError, RegistryValueAlreadyRegisteredError, UnknownAddressError, UnknownDataError, UnknownFactory, UnknownMarketAllocationError, UnknownMarketParamsError, UnknownOfFactory, UnknownTokenError, UnknownTokenPriceError, UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
4
+ export { getUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
@@ -1,5 +1,5 @@
1
1
  import type { Client } from "viem";
2
- import { type Metadata, type MorphoClientType } from "../types/index.js";
2
+ import type { Metadata, MorphoClientType } from "../types/index.js";
3
3
  /**
4
4
  * Returns a viem `extend(...)` function that adds a stateless `morpho` namespace to a viem client.
5
5
  * The namespace rides on top of the same client (one transport / chain / account) and exposes the
@@ -1,7 +1,5 @@
1
- import { MarketUtils } from "@morpho-org/blue-sdk";
2
1
  import { deepFreeze } from "@morpho-org/morpho-ts";
3
2
  import { MorphoBlue, MorphoMidnight, MorphoVaultV1, MorphoVaultV2, } from "../entities/index.js";
4
- import { MarketIdMismatchError, } from "../types/index.js";
5
3
  /**
6
4
  * Builds the stateless `morpho` namespace exposed on an extended viem client. Wraps the supplied
7
5
  * viem `Client` plus a frozen options bag and exposes factory methods for the protocol entities.
@@ -27,11 +25,7 @@ function createMorphoNamespace(viemClient, options) {
27
25
  return new MorphoVaultV2(namespace, vault, chainId);
28
26
  },
29
27
  blue(marketParams, chainId) {
30
- const derivedId = MarketUtils.getMarketId(marketParams);
31
- // Can happen with one-time/hardcoded/agent-written possibly inconsistent input market params.
32
- if (marketParams.id !== derivedId) {
33
- throw new MarketIdMismatchError(marketParams.id, derivedId);
34
- }
28
+ // The constructor rejects one-time/hardcoded/agent-written market params whose id does not hash from the tuple.
35
29
  return new MorphoBlue(namespace, marketParams, chainId);
36
30
  },
37
31
  midnight(chainId) {
@@ -9,6 +9,10 @@ type VaultV2BlueReallocationsParams = {
9
9
  readonly operation?: {
10
10
  readonly type: "borrow" | "withdraw";
11
11
  readonly amount: bigint;
12
+ } | {
13
+ readonly type: "refinance";
14
+ readonly amount: bigint;
15
+ readonly referralFeePct?: bigint;
12
16
  };
13
17
  };
14
18
  };
@@ -764,7 +768,7 @@ export interface BlueActions {
764
768
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
765
769
  * @throws {UnsupportedBlueMarketIrmError} when positive source or destination debt requires an unsupported IRM projection.
766
770
  * @throws {MissingAccrualPositionError} when either position snapshot is absent at runtime.
767
- * @throws {MarketIdMismatchError} when a position snapshot belongs to another market.
771
+ * @throws {MarketIdMismatchError} when `destination.marketParams.id` does not hash from its tuple fields, or a position snapshot belongs to another market.
768
772
  * @throws {AccrualPositionUserMismatchError} when a position snapshot belongs to another user.
769
773
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
770
774
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
@@ -842,10 +846,13 @@ export interface BlueActions {
842
846
  *
843
847
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
844
848
  * vault's BluePublicAllocator permissions and allocation caps at one block.
849
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
845
850
  *
846
851
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
847
852
  * @param params.block.number - Block number used for every RPC read.
848
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
853
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
854
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
855
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
849
856
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
850
857
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
851
858
  * chain via `eth_chainId`.
@@ -878,14 +885,23 @@ export interface BlueActions {
878
885
  * persist across every leg of a plan. Operation plans keep
879
886
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
880
887
  * BluePublicAllocator cap unless the operation shortfall needs it.
888
+ * For `refinance`, compute the plan on the destination-market handle (for
889
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
890
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
891
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
892
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
893
+ * The planner includes the referral fee and its own planned allocator-leg
894
+ * penalties in destination debt. Refinance never uses vaults with a 100%
895
+ * penalty.
881
896
  *
882
897
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
883
898
  * @param params.options - Optional allocator discovery controls and operation to support.
884
899
  * @returns Action-ready reallocations and their post-simulation state.
885
900
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
886
901
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
887
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
902
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
888
903
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
904
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
889
905
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
890
906
  * @throws {UnknownReallocationMarketError} when a required market is absent.
891
907
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -895,7 +911,7 @@ export interface BlueActions {
895
911
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
896
912
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
897
913
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
898
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
914
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
899
915
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
900
916
  * @example
901
917
  * ```ts
@@ -915,6 +931,14 @@ export declare class MorphoBlue implements BlueActions {
915
931
  private readonly client;
916
932
  readonly marketParams: MarketParams;
917
933
  private readonly chainId;
934
+ /**
935
+ * Binds `client` to the market described by `marketParams` on `chainId`.
936
+ *
937
+ * @param client - Morpho client used for reads and requirement lookups.
938
+ * @param marketParams - Market params whose `id` must hash from their five tuple fields.
939
+ * @param chainId - Chain the market lives on.
940
+ * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
941
+ */
918
942
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
919
943
  private validateDeadline;
920
944
  private validateWriteCommon;
@@ -1059,10 +1083,13 @@ export declare class MorphoBlue implements BlueActions {
1059
1083
  *
1060
1084
  * Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
1061
1085
  * vault's BluePublicAllocator permissions and allocation caps at one block.
1086
+ * The snapshot keeps the fetched block's timestamp as its default planning time.
1062
1087
  *
1063
1088
  * @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
1064
1089
  * @param params.block.number - Block number used for every RPC read.
1065
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
1090
+ * @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
1091
+ * planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
1092
+ * `lastUpdate`. An explicit `options.timestamp` is used as given.
1066
1093
  * @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
1067
1094
  * @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
1068
1095
  * chain via `eth_chainId`.
@@ -1114,14 +1141,23 @@ export declare class MorphoBlue implements BlueActions {
1114
1141
  * persist across every leg of a plan. Operation plans keep
1115
1142
  * `allocatorCapHeadroom` (1% of the cap by default) free under each target
1116
1143
  * BluePublicAllocator cap unless the operation shortfall needs it.
1144
+ * For `refinance`, compute the plan on the destination-market handle (for
1145
+ * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
1146
+ * source-market handle. Pass the source position's `borrowAssets` accrued to
1147
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
1148
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
1149
+ * The planner includes the referral fee and its own planned allocator-leg
1150
+ * penalties in destination debt. Refinance never uses vaults with a 100%
1151
+ * penalty.
1117
1152
  *
1118
1153
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
1119
1154
  * @param params.options - Optional allocator discovery controls and operation to support.
1120
1155
  * @returns Action-ready reallocations and their post-simulation state.
1121
1156
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1122
1157
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1123
- * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, or penalty limit is negative.
1158
+ * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
1124
1159
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
1160
+ * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
1125
1161
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
1126
1162
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1127
1163
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1131,7 +1167,7 @@ export declare class MorphoBlue implements BlueActions {
1131
1167
  * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
1132
1168
  * @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
1133
1169
  * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
1134
- * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
1170
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall and, for refinance, its planned allocator penalties.
1135
1171
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
1136
1172
  * @example
1137
1173
  * ```ts