@morpho-org/morpho-sdk 9.1.0-next.0 → 9.2.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 (154) hide show
  1. package/README.md +7 -1
  2. package/lib/cjs/abis.d.ts +2 -2
  3. package/lib/cjs/abis.js +3 -5
  4. package/lib/cjs/actions/blue/borrow.d.ts +1 -0
  5. package/lib/cjs/actions/blue/borrow.js +1 -0
  6. package/lib/cjs/actions/blue/refinance.d.ts +1 -0
  7. package/lib/cjs/actions/blue/refinance.js +3 -0
  8. package/lib/cjs/actions/blue/repay.d.ts +1 -0
  9. package/lib/cjs/actions/blue/repay.js +1 -0
  10. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  11. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
  12. package/lib/cjs/actions/blue/supply.d.ts +1 -0
  13. package/lib/cjs/actions/blue/supply.js +2 -0
  14. package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
  15. package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
  16. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  17. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
  18. package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
  19. package/lib/cjs/actions/blue/withdraw.js +2 -0
  20. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
  21. package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  23. package/lib/cjs/actions/midnight/takeLend.js +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  25. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  26. package/lib/cjs/blue/abis.d.ts +1 -1
  27. package/lib/cjs/blue/abis.js +1 -5
  28. package/lib/cjs/blue/constants.d.ts +1 -1
  29. package/lib/cjs/blue/constants.js +2 -1
  30. package/lib/cjs/blue/entities.d.ts +4 -4
  31. package/lib/cjs/blue/entities.js +1 -3
  32. package/lib/cjs/blue/errors.d.ts +2 -2
  33. package/lib/cjs/blue/errors.js +2 -5
  34. package/lib/cjs/blue/fetch.d.ts +2 -2
  35. package/lib/cjs/blue/fetch.js +1 -3
  36. package/lib/cjs/blue/utils.d.ts +1 -1
  37. package/lib/cjs/blue/utils.js +1 -2
  38. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  39. package/lib/cjs/client/morphoViemExtension.js +1 -7
  40. package/lib/cjs/constants.d.ts +2 -2
  41. package/lib/cjs/constants.js +4 -1
  42. package/lib/cjs/entities/blue/blue.d.ts +112 -21
  43. package/lib/cjs/entities/blue/blue.js +58 -6
  44. package/lib/cjs/entities/index.d.ts +4 -4
  45. package/lib/cjs/entities/index.js +1 -3
  46. package/lib/cjs/entities/midnight/midnight.d.ts +9 -6
  47. package/lib/cjs/entities/midnight/midnight.js +12 -9
  48. package/lib/cjs/entities/midnight/types.d.ts +8 -1
  49. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +8 -0
  50. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -0
  51. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -34
  52. package/lib/cjs/entities/vaultV2/vaultV2.js +12 -38
  53. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +77 -19
  54. package/lib/cjs/entities/vaultV2BlueReallocationData.js +376 -80
  55. package/lib/cjs/errors.d.ts +4 -4
  56. package/lib/cjs/errors.js +6 -10
  57. package/lib/cjs/fetch.d.ts +2 -2
  58. package/lib/cjs/fetch.js +1 -3
  59. package/lib/cjs/helpers/constant.d.ts +7 -0
  60. package/lib/cjs/helpers/constant.js +8 -1
  61. package/lib/cjs/helpers/deadShares.d.ts +82 -0
  62. package/lib/cjs/helpers/deadShares.js +200 -0
  63. package/lib/cjs/helpers/index.d.ts +2 -1
  64. package/lib/cjs/helpers/index.js +7 -1
  65. package/lib/cjs/helpers/validate.d.ts +11 -1
  66. package/lib/cjs/helpers/validate.js +17 -1
  67. package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
  68. package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
  69. package/lib/cjs/midnight/abis.d.ts +1 -1
  70. package/lib/cjs/midnight/abis.js +3 -1
  71. package/lib/cjs/midnight/errors.d.ts +1 -2
  72. package/lib/cjs/midnight/errors.js +4 -5
  73. package/lib/cjs/types/error.d.ts +60 -5
  74. package/lib/cjs/types/error.js +68 -6
  75. package/lib/cjs/types/sharedLiquidity.d.ts +31 -11
  76. package/lib/cjs/utils.d.ts +2 -2
  77. package/lib/cjs/utils.js +2 -4
  78. package/lib/esm/abis.d.ts +2 -2
  79. package/lib/esm/abis.js +2 -2
  80. package/lib/esm/actions/blue/borrow.d.ts +1 -0
  81. package/lib/esm/actions/blue/borrow.js +1 -0
  82. package/lib/esm/actions/blue/refinance.d.ts +1 -0
  83. package/lib/esm/actions/blue/refinance.js +4 -1
  84. package/lib/esm/actions/blue/repay.d.ts +1 -0
  85. package/lib/esm/actions/blue/repay.js +1 -0
  86. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
  87. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
  88. package/lib/esm/actions/blue/supply.d.ts +1 -0
  89. package/lib/esm/actions/blue/supply.js +3 -1
  90. package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
  91. package/lib/esm/actions/blue/supplyCollateral.js +1 -0
  92. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
  93. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
  94. package/lib/esm/actions/blue/withdraw.d.ts +1 -0
  95. package/lib/esm/actions/blue/withdraw.js +3 -1
  96. package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
  97. package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
  98. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  99. package/lib/esm/actions/midnight/takeLend.js +1 -0
  100. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  101. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
  102. package/lib/esm/blue/abis.d.ts +1 -1
  103. package/lib/esm/blue/abis.js +1 -1
  104. package/lib/esm/blue/constants.d.ts +1 -1
  105. package/lib/esm/blue/constants.js +1 -1
  106. package/lib/esm/blue/entities.d.ts +4 -4
  107. package/lib/esm/blue/entities.js +2 -2
  108. package/lib/esm/blue/errors.d.ts +2 -2
  109. package/lib/esm/blue/errors.js +2 -2
  110. package/lib/esm/blue/fetch.d.ts +2 -2
  111. package/lib/esm/blue/fetch.js +2 -2
  112. package/lib/esm/blue/utils.d.ts +1 -1
  113. package/lib/esm/blue/utils.js +1 -1
  114. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  115. package/lib/esm/client/morphoViemExtension.js +1 -7
  116. package/lib/esm/constants.d.ts +2 -2
  117. package/lib/esm/constants.js +2 -2
  118. package/lib/esm/entities/blue/blue.d.ts +112 -21
  119. package/lib/esm/entities/blue/blue.js +60 -8
  120. package/lib/esm/entities/index.d.ts +4 -4
  121. package/lib/esm/entities/index.js +2 -2
  122. package/lib/esm/entities/midnight/midnight.d.ts +9 -6
  123. package/lib/esm/entities/midnight/midnight.js +13 -10
  124. package/lib/esm/entities/midnight/types.d.ts +8 -1
  125. package/lib/esm/entities/vaultV1/vaultV1.d.ts +8 -0
  126. package/lib/esm/entities/vaultV1/vaultV1.js +5 -0
  127. package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -34
  128. package/lib/esm/entities/vaultV2/vaultV2.js +13 -39
  129. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +77 -19
  130. package/lib/esm/entities/vaultV2BlueReallocationData.js +377 -81
  131. package/lib/esm/errors.d.ts +4 -4
  132. package/lib/esm/errors.js +4 -4
  133. package/lib/esm/fetch.d.ts +2 -2
  134. package/lib/esm/fetch.js +2 -2
  135. package/lib/esm/helpers/constant.d.ts +7 -0
  136. package/lib/esm/helpers/constant.js +7 -0
  137. package/lib/esm/helpers/deadShares.d.ts +82 -0
  138. package/lib/esm/helpers/deadShares.js +195 -0
  139. package/lib/esm/helpers/index.d.ts +2 -1
  140. package/lib/esm/helpers/index.js +2 -1
  141. package/lib/esm/helpers/validate.d.ts +11 -1
  142. package/lib/esm/helpers/validate.js +15 -0
  143. package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
  144. package/lib/esm/helpers/validateTakeableOffers.js +13 -2
  145. package/lib/esm/midnight/abis.d.ts +1 -1
  146. package/lib/esm/midnight/abis.js +1 -1
  147. package/lib/esm/midnight/errors.d.ts +1 -2
  148. package/lib/esm/midnight/errors.js +1 -2
  149. package/lib/esm/types/error.d.ts +60 -5
  150. package/lib/esm/types/error.js +64 -5
  151. package/lib/esm/types/sharedLiquidity.d.ts +31 -11
  152. package/lib/esm/utils.d.ts +2 -2
  153. package/lib/esm/utils.js +2 -2
  154. package/package.json +9 -8
@@ -1,2 +1 @@
1
- export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
2
- export { InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, } from "@morpho-org/morpho-ts";
1
+ export { ChainIdMismatchError, InvalidEcrecoverSignatureVError, InvalidMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError, InvalidOfferParameterError, InvalidPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidRateRatifierV1RateError, InvalidRateRatifierV1TickError, InvalidRateRatifierV1TimeError, InvalidRatifierV1AddressError, InvalidTickSpacingError, InvalidTreeError, InvalidTreeHeightError, InvalidTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError, PriceGreaterThanOneError, RateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError, TickOutOfRangeError, UnknownCollateralIndexError, } from "@morpho-org/midnight-sdk";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
3
+ exports.UnknownCollateralIndexError = exports.TickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.RatifierV1TakerNotAllowedError = exports.RateRatifierV1BoundOverflowError = exports.PriceGreaterThanOneError = exports.PayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidTreeError = exports.InvalidTickSpacingError = exports.InvalidRatifierV1AddressError = exports.InvalidRateRatifierV1TimeError = exports.InvalidRateRatifierV1TickError = exports.InvalidRateRatifierV1RateError = exports.InvalidPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMarketParameterError = exports.InvalidEcrecoverSignatureVError = exports.ChainIdMismatchError = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "ChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
6
6
  Object.defineProperty(exports, "InvalidEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
@@ -9,6 +9,9 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
9
9
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
10
10
  Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
11
11
  Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
12
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
13
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
14
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
12
15
  Object.defineProperty(exports, "InvalidRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
13
16
  Object.defineProperty(exports, "InvalidRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
14
17
  Object.defineProperty(exports, "InvalidRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -26,7 +29,3 @@ Object.defineProperty(exports, "RatifierV1TakerNotAllowedError", { enumerable: t
26
29
  Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
27
30
  Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
28
31
  Object.defineProperty(exports, "UnknownCollateralIndexError", { enumerable: true, get: function () { return midnight_sdk_1.UnknownCollateralIndexError; } });
29
- var morpho_ts_1 = require("@morpho-org/morpho-ts");
30
- Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
31
- Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
32
- Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
@@ -929,11 +929,16 @@ export declare class RepaySharesExceedDebtError extends Error {
929
929
  });
930
930
  }
931
931
  /**
932
- * Thrown when shared liquidity selected by a Vault V2 reallocation planner cannot
933
- * cover the operation's absolute shortfall on the target market — the resulting
934
- * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
932
+ * Thrown when shared liquidity cannot cover the operation's required
933
+ * reallocated assets. When Blue's balance is explicit, it is also thrown if
934
+ * that balance cannot fund the penalty flash loan, an earlier market-sourced
935
+ * withdrawal, or the final operation transfer. A borrow or withdraw plan that
936
+ * otherwise covers its shortfall but whose planned penalty exceeds its amount
937
+ * instead throws `InputExceedsMaxError`.
935
938
  *
936
- * Pattern-match on the class and inspect `params` to surface the gap to users.
939
+ * `shortfall` is the reallocated assets required by the operation and is
940
+ * comparable to `available`. Pattern-match on the class and inspect `params`
941
+ * to surface the gap to users.
937
942
  */
938
943
  export declare class InsufficientSharedLiquidityError extends Error {
939
944
  readonly params: {
@@ -1316,7 +1321,12 @@ export declare class MidnightOfferCallbackDataMismatchError extends Error {
1316
1321
  readonly actualCallbackData: Hex;
1317
1322
  });
1318
1323
  }
1319
- /** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
1324
+ /**
1325
+ * Thrown when loan assets would be parked in a Morpho Blue market with no existing supply.
1326
+ *
1327
+ * @deprecated `supplyBlueMakeLend` now throws `InsufficientDeadSharesError` or
1328
+ * `MissingDeadSharesDataError` instead; kept exported so existing `instanceof` checks compile.
1329
+ */
1320
1330
  export declare class EmptyBlueParkingMarketError extends Error {
1321
1331
  constructor(params: {
1322
1332
  readonly marketId: MarketId;
@@ -1332,6 +1342,45 @@ export declare class ZeroBlueParkingSharesError extends Error {
1332
1342
  readonly assets: bigint;
1333
1343
  });
1334
1344
  }
1345
+ /** Which dead-deposit condition an entity failed. */
1346
+ export type DeadSharesFailureReason = "deadShares" | "deadAssets" | "sharePrice";
1347
+ /**
1348
+ * Thrown when a Morpho Blue market or vault, or a market or Vault V1 it can allocate to, fails the
1349
+ * dead-deposit rule that protects deposits against share-price inflation.
1350
+ */
1351
+ export declare class InsufficientDeadSharesError extends Error {
1352
+ /** Failing entity, outermost vault first; the last element is the market id or vault address. */
1353
+ readonly entity: readonly (Address | Hash)[];
1354
+ /** Failed condition. */
1355
+ readonly reason: DeadSharesFailureReason;
1356
+ /** Observed dead shares or assets; for `sharePrice`, `(totalAssets + 1) * 10 * virtualShares`. */
1357
+ readonly observed: bigint;
1358
+ /** Required minimum; for `sharePrice`, `totalSupply + virtualShares + 1`. */
1359
+ readonly required: bigint;
1360
+ constructor(params: {
1361
+ readonly entity: readonly (Address | Hash)[];
1362
+ readonly reason: DeadSharesFailureReason;
1363
+ readonly observed: bigint;
1364
+ readonly required: bigint;
1365
+ });
1366
+ }
1367
+ /** Snapshot field the dead-deposit check needs but the snapshot does not carry. */
1368
+ export type DeadSharesDataField = "deadSupplyShares" | "deadShares" | "deadAssets" | "absoluteCaps" | "allocation" | "adapter" | "liquidityMarket";
1369
+ /**
1370
+ * Thrown when a market or vault snapshot lacks the data the dead-deposit check needs, such as a
1371
+ * snapshot built by hand, from the Morpho API or by an older fetcher, or a Vault V2 adapter the
1372
+ * SDK cannot hydrate. The check fails closed rather than pass unverified data.
1373
+ */
1374
+ export declare class MissingDeadSharesDataError extends Error {
1375
+ /** Entity missing the data, outermost vault first. */
1376
+ readonly entity: readonly (Address | Hash)[];
1377
+ /** Missing field. */
1378
+ readonly field: DeadSharesDataField;
1379
+ constructor(params: {
1380
+ readonly entity: readonly (Address | Hash)[];
1381
+ readonly field: DeadSharesDataField;
1382
+ });
1383
+ }
1335
1384
  /** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
1336
1385
  export declare class MidnightTakeableOfferMarketMismatchError extends Error {
1337
1386
  constructor(params: {
@@ -1340,6 +1389,12 @@ export declare class MidnightTakeableOfferMarketMismatchError extends Error {
1340
1389
  actualMarket: string;
1341
1390
  });
1342
1391
  }
1392
+ /** Thrown when a quoted Midnight sell offer routes its seller proceeds to the zero address. */
1393
+ export declare class MidnightTakeableOfferZeroSellerReceiverError extends Error {
1394
+ constructor(params: {
1395
+ index: number;
1396
+ });
1397
+ }
1343
1398
  /** Thrown when a Midnight offer's ratifier does not match its tree's ratifier route. */
1344
1399
  export declare class MidnightOfferRatifierMismatchError extends Error {
1345
1400
  constructor(params: {
@@ -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.MissingDeadSharesDataError = exports.InsufficientDeadSharesError = 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");
@@ -1219,11 +1219,16 @@ class RepaySharesExceedDebtError extends Error {
1219
1219
  }
1220
1220
  exports.RepaySharesExceedDebtError = RepaySharesExceedDebtError;
1221
1221
  /**
1222
- * Thrown when shared liquidity selected by a Vault V2 reallocation planner cannot
1223
- * cover the operation's absolute shortfall on the target market — the resulting
1224
- * `morphoBorrow` or `morphoWithdraw` would still revert onchain.
1222
+ * Thrown when shared liquidity cannot cover the operation's required
1223
+ * reallocated assets. When Blue's balance is explicit, it is also thrown if
1224
+ * that balance cannot fund the penalty flash loan, an earlier market-sourced
1225
+ * withdrawal, or the final operation transfer. A borrow or withdraw plan that
1226
+ * otherwise covers its shortfall but whose planned penalty exceeds its amount
1227
+ * instead throws `InputExceedsMaxError`.
1225
1228
  *
1226
- * Pattern-match on the class and inspect `params` to surface the gap to users.
1229
+ * `shortfall` is the reallocated assets required by the operation and is
1230
+ * comparable to `available`. Pattern-match on the class and inspect `params`
1231
+ * to surface the gap to users.
1227
1232
  */
1228
1233
  class InsufficientSharedLiquidityError extends Error {
1229
1234
  params;
@@ -1689,7 +1694,12 @@ class MidnightOfferCallbackDataMismatchError extends Error {
1689
1694
  }
1690
1695
  }
1691
1696
  exports.MidnightOfferCallbackDataMismatchError = MidnightOfferCallbackDataMismatchError;
1692
- /** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
1697
+ /**
1698
+ * Thrown when loan assets would be parked in a Morpho Blue market with no existing supply.
1699
+ *
1700
+ * @deprecated `supplyBlueMakeLend` now throws `InsufficientDeadSharesError` or
1701
+ * `MissingDeadSharesDataError` instead; kept exported so existing `instanceof` checks compile.
1702
+ */
1693
1703
  class EmptyBlueParkingMarketError extends Error {
1694
1704
  constructor(params) {
1695
1705
  super(`Morpho Blue market "${params.marketId}" has no supply shares. Parking assets in an empty market is exposed to supply-share-price inflation; choose a market with existing supply.`);
@@ -1708,6 +1718,50 @@ class ZeroBlueParkingSharesError extends Error {
1708
1718
  }
1709
1719
  }
1710
1720
  exports.ZeroBlueParkingSharesError = ZeroBlueParkingSharesError;
1721
+ /**
1722
+ * Thrown when a Morpho Blue market or vault, or a market or Vault V1 it can allocate to, fails the
1723
+ * dead-deposit rule that protects deposits against share-price inflation.
1724
+ */
1725
+ class InsufficientDeadSharesError extends Error {
1726
+ /** Failing entity, outermost vault first; the last element is the market id or vault address. */
1727
+ entity;
1728
+ /** Failed condition. */
1729
+ reason;
1730
+ /** Observed dead shares or assets; for `sharePrice`, `(totalAssets + 1) * 10 * virtualShares`. */
1731
+ observed;
1732
+ /** Required minimum; for `sharePrice`, `totalSupply + virtualShares + 1`. */
1733
+ required;
1734
+ constructor(params) {
1735
+ const target = params.entity.join(" > ");
1736
+ super(params.reason === "sharePrice"
1737
+ ? `Vault V2 "${target}" share price is at or below 1 / (10 * virtualShares) ("${params.observed}" < "${params.required}"), so it may have been deflated before its dead deposit. Choose another vault.`
1738
+ : `"${target}" holds "${params.observed}" dead ${params.reason === "deadShares" ? "shares" : "assets"} at 0x000000000000000000000000000000000000dEaD, below the required "${params.required}". Choose a market or vault with a sufficient dead deposit.`);
1739
+ this.name = "InsufficientDeadSharesError";
1740
+ this.entity = params.entity;
1741
+ this.reason = params.reason;
1742
+ this.observed = params.observed;
1743
+ this.required = params.required;
1744
+ }
1745
+ }
1746
+ exports.InsufficientDeadSharesError = InsufficientDeadSharesError;
1747
+ /**
1748
+ * Thrown when a market or vault snapshot lacks the data the dead-deposit check needs, such as a
1749
+ * snapshot built by hand, from the Morpho API or by an older fetcher, or a Vault V2 adapter the
1750
+ * SDK cannot hydrate. The check fails closed rather than pass unverified data.
1751
+ */
1752
+ class MissingDeadSharesDataError extends Error {
1753
+ /** Entity missing the data, outermost vault first. */
1754
+ entity;
1755
+ /** Missing field. */
1756
+ field;
1757
+ constructor(params) {
1758
+ super(`"${params.entity.join(" > ")}" has no "${params.field}" data for the dead-deposit check. Fetch the snapshot with the @morpho-org/blue-sdk-viem fetchers before building the transaction.`);
1759
+ this.name = "MissingDeadSharesDataError";
1760
+ this.entity = params.entity;
1761
+ this.field = params.field;
1762
+ }
1763
+ }
1764
+ exports.MissingDeadSharesDataError = MissingDeadSharesDataError;
1711
1765
  /** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
1712
1766
  class MidnightTakeableOfferMarketMismatchError extends Error {
1713
1767
  constructor(params) {
@@ -1716,6 +1770,14 @@ class MidnightTakeableOfferMarketMismatchError extends Error {
1716
1770
  }
1717
1771
  }
1718
1772
  exports.MidnightTakeableOfferMarketMismatchError = MidnightTakeableOfferMarketMismatchError;
1773
+ /** Thrown when a quoted Midnight sell offer routes its seller proceeds to the zero address. */
1774
+ class MidnightTakeableOfferZeroSellerReceiverError extends Error {
1775
+ constructor(params) {
1776
+ super(`Midnight takeable offer "${params.index}" routes seller proceeds to the zero address. Drop the offer or refresh the quote.`);
1777
+ this.name = "MidnightTakeableOfferZeroSellerReceiverError";
1778
+ }
1779
+ }
1780
+ exports.MidnightTakeableOfferZeroSellerReceiverError = MidnightTakeableOfferZeroSellerReceiverError;
1719
1781
  /** Thrown when a Midnight offer's ratifier does not match its tree's ratifier route. */
1720
1782
  class MidnightOfferRatifierMismatchError extends Error {
1721
1783
  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,33 @@ 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 planner tries this friendly
60
+ * utilization before falling back to 100% when required coverage remains.
61
+ * Positive-penalty tiers cover the remaining absolute shortfall or, when
62
+ * larger, Blue's loan-token balance deficit while BlueBundlesV1 flash-loans
63
+ * the penalty.
58
64
  *
59
65
  * @default 90% (900000000000000000n)
60
66
  */
61
67
  readonly maxWithdrawalUtilization?: bigint;
62
68
  /**
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%).
69
+ * Maximum proportional vault-asset penalty accepted per call, scaled by
70
+ * WAD; higher-penalty vaults are ignored. Must not exceed WAD. Operation
71
+ * plans consider penalty tiers ascending, free first. Each tier tries
72
+ * friendly source utilization (90% by default) before falling back to 100%
73
+ * when required coverage remains. Positive-penalty tiers cover the remaining
74
+ * absolute shortfall or, when larger, Blue's loan-token balance deficit while
75
+ * BlueBundlesV1 flash-loans the penalty. Free capacity inside
76
+ * `allocatorCapHeadroom` stays unused, so a penalized leg can cover it.
77
+ * Getters count all vaults up to this limit. For `refinance`, compute the
78
+ * plan on the destination-market handle (for example,
79
+ * `client.morpho.blue(destination.marketParams, chainId)`), not the source
80
+ * handle. Pass the source position's `borrowAssets` accrued to
81
+ * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
82
+ * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
83
+ * The planner includes the referral fee and its own allocator-leg penalties
84
+ * in destination debt, so penalized legs also cover their own penalty.
85
+ * Refinance never uses vaults with a 100% penalty.
66
86
  *
67
87
  * @default 0n
68
88
  */
@@ -3,7 +3,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
- getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MidnightAdapterUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
6
+ getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
7
7
  export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
8
8
  export { EcrecoverRatifier as MidnightEcrecoverRatifier,
9
9
  /** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
@@ -17,7 +17,7 @@ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier
17
17
  /** @deprecated Use MidnightSetterRatifier with a tagged tree. */
18
18
  SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
19
19
  export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
20
- export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, MidnightPositionLib, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
20
+ export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
21
21
  export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
22
22
  export { addTransactionMetadata } from "./helpers/metadata.js";
23
23
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./helpers/previewVaultV2ForceWithdraw.js";
package/lib/cjs/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.VaultV2MidnightAdapterUtils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
4
- exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.MidnightPositionLib = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = void 0;
3
+ exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
4
+ exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueAdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
7
7
  Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "BlueSharesMath", { enumerable: true, get: functi
15
15
  Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultUtils; } });
16
16
  Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfigUtils; } });
17
17
  Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils; } });
18
- Object.defineProperty(exports, "VaultV2MidnightAdapterUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapterUtils; } });
19
18
  Object.defineProperty(exports, "VaultV2Utils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Utils; } });
20
19
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
21
20
  Object.defineProperty(exports, "catchRevertOnly", { enumerable: true, get: function () { return blue_sdk_viem_1.catchRevertOnly; } });
@@ -77,7 +76,6 @@ Object.defineProperty(exports, "isDefined", { enumerable: true, get: function ()
77
76
  Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return morpho_ts_1.isNotNull; } });
78
77
  Object.defineProperty(exports, "isNotUndefined", { enumerable: true, get: function () { return morpho_ts_1.isNotUndefined; } });
79
78
  Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return morpho_ts_1.keys; } });
80
- Object.defineProperty(exports, "MidnightPositionLib", { enumerable: true, get: function () { return morpho_ts_1.MidnightPositionLib; } });
81
79
  Object.defineProperty(exports, "mergeEntries", { enumerable: true, get: function () { return morpho_ts_1.mergeEntries; } });
82
80
  Object.defineProperty(exports, "retryPromiseLinearBackoff", { enumerable: true, get: function () { return morpho_ts_1.retryPromiseLinearBackoff; } });
83
81
  Object.defineProperty(exports, "Time", { enumerable: true, get: function () { return morpho_ts_1.Time; } });
package/lib/esm/abis.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  preLiquidationAbi as bluePreLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
6
  preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
7
- export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi as midnightEcrecoverAuthorizerAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
8
8
  /** ABI for the VaultExitBundlesV1 periphery contract. */
9
9
  export declare const vaultExitBundlesV1Abi: readonly [{
10
10
  readonly type: "constructor";
package/lib/esm/abis.js CHANGED
@@ -1,10 +1,10 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
3
3
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
4
4
  preLiquidationAbi as bluePreLiquidationAbi,
5
5
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
6
6
  preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
7
- export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
7
+ export { blueBuyCallbackFactoryAbi as midnightBlueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi as midnightEcrecoverAuthorizerAbi, ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi as midnightPriceRatifierV1Abi, rateRatifierV1Abi as midnightRateRatifierV1Abi, setterRatifierAbi as midnightSetterRatifierAbi, } from "@morpho-org/midnight-sdk";
8
8
  /** ABI for the VaultExitBundlesV1 periphery contract. */
9
9
  export const vaultExitBundlesV1Abi = [
10
10
  {
@@ -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],