@morpho-org/morpho-sdk 9.6.0-next.0 → 9.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +59 -0
  2. package/lib/cjs/abis.d.ts +1 -1
  3. package/lib/cjs/abis.js +1 -5
  4. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  5. package/lib/cjs/actions/bundles/common.js +39 -32
  6. package/lib/cjs/actions/midnight/cancelAndMake.js +20 -98
  7. package/lib/cjs/actions/midnight/index.d.ts +2 -0
  8. package/lib/cjs/actions/midnight/index.js +2 -0
  9. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +5 -6
  10. package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +39 -0
  11. package/lib/cjs/actions/midnight/supplyCollateralBatch.js +91 -0
  12. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +31 -32
  13. package/lib/cjs/actions/midnight/takeBorrow.js +24 -23
  14. package/lib/cjs/actions/midnight/takeLend.js +24 -23
  15. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
  16. package/lib/cjs/actions/midnight/takeWithdraw.js +24 -23
  17. package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
  18. package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +104 -0
  19. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
  20. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
  21. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
  22. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +1 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  25. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
  26. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
  27. package/lib/cjs/actions/vaultV1/migrateToV2.js +7 -7
  28. package/lib/cjs/blue/abis.d.ts +1 -1
  29. package/lib/cjs/blue/abis.js +1 -5
  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 +1 -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/entities/index.d.ts +5 -5
  39. package/lib/cjs/entities/index.js +1 -3
  40. package/lib/cjs/entities/midnight/midnight.d.ts +77 -3
  41. package/lib/cjs/entities/midnight/midnight.js +174 -0
  42. package/lib/cjs/entities/midnight/types.d.ts +16 -0
  43. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +8 -33
  44. package/lib/cjs/entities/vaultV2/vaultV2.js +1 -33
  45. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
  46. package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
  47. package/lib/cjs/errors.d.ts +4 -4
  48. package/lib/cjs/errors.js +6 -7
  49. package/lib/cjs/fetch.d.ts +2 -2
  50. package/lib/cjs/fetch.js +1 -3
  51. package/lib/cjs/helpers/deadShares.js +0 -2
  52. package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +1 -0
  53. package/lib/cjs/helpers/signAndVerifyTypedData.js +12 -5
  54. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
  55. package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +129 -0
  56. package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +14 -0
  57. package/lib/cjs/helpers/validateMidnightCollateralBatch.js +27 -0
  58. package/lib/cjs/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
  59. package/lib/cjs/helpers/validateMidnightCollateralSupplies.js +28 -0
  60. package/lib/cjs/helpers/validatePositiveInput.d.ts +10 -0
  61. package/lib/cjs/helpers/validatePositiveInput.js +18 -0
  62. package/lib/cjs/midnight/errors.d.ts +1 -2
  63. package/lib/cjs/midnight/errors.js +5 -5
  64. package/lib/cjs/types/action.d.ts +18 -3
  65. package/lib/cjs/types/error.d.ts +23 -2
  66. package/lib/cjs/types/error.js +45 -5
  67. package/lib/cjs/utils.d.ts +2 -2
  68. package/lib/cjs/utils.js +2 -4
  69. package/lib/esm/abis.d.ts +1 -1
  70. package/lib/esm/abis.js +1 -1
  71. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  72. package/lib/esm/actions/bundles/common.js +39 -32
  73. package/lib/esm/actions/midnight/cancelAndMake.js +25 -103
  74. package/lib/esm/actions/midnight/index.d.ts +2 -0
  75. package/lib/esm/actions/midnight/index.js +2 -0
  76. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +5 -6
  77. package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +39 -0
  78. package/lib/esm/actions/midnight/supplyCollateralBatch.js +87 -0
  79. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -34
  80. package/lib/esm/actions/midnight/takeBorrow.js +25 -24
  81. package/lib/esm/actions/midnight/takeLend.js +25 -24
  82. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
  83. package/lib/esm/actions/midnight/takeWithdraw.js +25 -24
  84. package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
  85. package/lib/esm/actions/midnight/withdrawCollateralBatch.js +100 -0
  86. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
  87. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
  88. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
  89. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +1 -0
  90. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
  91. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
  92. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
  93. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
  94. package/lib/esm/actions/vaultV1/migrateToV2.js +8 -8
  95. package/lib/esm/blue/abis.d.ts +1 -1
  96. package/lib/esm/blue/abis.js +1 -1
  97. package/lib/esm/blue/entities.d.ts +4 -4
  98. package/lib/esm/blue/entities.js +2 -2
  99. package/lib/esm/blue/errors.d.ts +2 -2
  100. package/lib/esm/blue/errors.js +2 -2
  101. package/lib/esm/blue/fetch.d.ts +2 -2
  102. package/lib/esm/blue/fetch.js +2 -2
  103. package/lib/esm/blue/utils.d.ts +1 -1
  104. package/lib/esm/blue/utils.js +1 -1
  105. package/lib/esm/entities/index.d.ts +5 -5
  106. package/lib/esm/entities/index.js +2 -2
  107. package/lib/esm/entities/midnight/midnight.d.ts +77 -3
  108. package/lib/esm/entities/midnight/midnight.js +176 -2
  109. package/lib/esm/entities/midnight/types.d.ts +16 -0
  110. package/lib/esm/entities/vaultV2/vaultV2.d.ts +8 -33
  111. package/lib/esm/entities/vaultV2/vaultV2.js +1 -33
  112. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
  113. package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
  114. package/lib/esm/errors.d.ts +4 -4
  115. package/lib/esm/errors.js +4 -4
  116. package/lib/esm/fetch.d.ts +2 -2
  117. package/lib/esm/fetch.js +2 -2
  118. package/lib/esm/helpers/deadShares.js +1 -3
  119. package/lib/esm/helpers/signAndVerifyTypedData.d.ts +1 -0
  120. package/lib/esm/helpers/signAndVerifyTypedData.js +13 -6
  121. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
  122. package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +124 -0
  123. package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +14 -0
  124. package/lib/esm/helpers/validateMidnightCollateralBatch.js +24 -0
  125. package/lib/esm/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
  126. package/lib/esm/helpers/validateMidnightCollateralSupplies.js +24 -0
  127. package/lib/esm/helpers/validatePositiveInput.d.ts +10 -0
  128. package/lib/esm/helpers/validatePositiveInput.js +14 -0
  129. package/lib/esm/midnight/errors.d.ts +1 -2
  130. package/lib/esm/midnight/errors.js +1 -2
  131. package/lib/esm/types/action.d.ts +18 -3
  132. package/lib/esm/types/error.d.ts +23 -2
  133. package/lib/esm/types/error.js +40 -3
  134. package/lib/esm/utils.d.ts +2 -2
  135. package/lib/esm/utils.js +2 -2
  136. package/package.json +6 -6
@@ -0,0 +1,17 @@
1
+ import { type MarketInput } from "@morpho-org/midnight-sdk";
2
+ import type { MidnightCollateralTransfer } from "../types/index.js";
3
+ /**
4
+ * Validates collateral supply entries and their per-index totals.
5
+ *
6
+ * @param params - Market, error-field prefix, and collateral supplies.
7
+ * @returns Nothing when every entry and total is valid; accepts an empty list.
8
+ * @throws {NonPositiveInputError} when an entry is not positive.
9
+ * @throws {InputExceedsMaxError} when an entry or per-index sum exceeds uint128.
10
+ * @throws {UnknownCollateralIndexError} when an index is not configured on the market.
11
+ * @internal
12
+ */
13
+ export declare const validateMidnightCollateralSupplies: (params: {
14
+ readonly market: MarketInput;
15
+ readonly field: string;
16
+ readonly supplies: readonly MidnightCollateralTransfer[];
17
+ }) => void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMidnightCollateralSupplies = void 0;
4
+ const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
+ const validateMidnightBounds_js_1 = require("./validateMidnightBounds.js");
6
+ const validatePositiveInput_js_1 = require("./validatePositiveInput.js");
7
+ /**
8
+ * Validates collateral supply entries and their per-index totals.
9
+ *
10
+ * @param params - Market, error-field prefix, and collateral supplies.
11
+ * @returns Nothing when every entry and total is valid; accepts an empty list.
12
+ * @throws {NonPositiveInputError} when an entry is not positive.
13
+ * @throws {InputExceedsMaxError} when an entry or per-index sum exceeds uint128.
14
+ * @throws {UnknownCollateralIndexError} when an index is not configured on the market.
15
+ * @internal
16
+ */
17
+ const validateMidnightCollateralSupplies = (params) => {
18
+ for (const [index, { collateralIndex, assets },] of params.supplies.entries()) {
19
+ const field = `${params.field}[${index}].assets`;
20
+ // Validation only; rejects non-positive supply amounts.
21
+ (0, validatePositiveInput_js_1.validatePositiveInput)(field, assets);
22
+ (0, validateMidnightBounds_js_1.validateMidnightUint128Field)(field, assets);
23
+ // Validation only; rejects indices not configured on the market.
24
+ midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex);
25
+ }
26
+ (0, validateMidnightBounds_js_1.validateMidnightCollateralSupplySums)(params.field, params.supplies);
27
+ };
28
+ exports.validateMidnightCollateralSupplies = validateMidnightCollateralSupplies;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Requires a strictly positive input amount.
3
+ *
4
+ * @param field - Input field name used in the error.
5
+ * @param value - Candidate amount.
6
+ * @returns Nothing when the amount is positive.
7
+ * @throws {NonPositiveInputError} when the amount is zero or negative.
8
+ * @internal
9
+ */
10
+ export declare const validatePositiveInput: (field: string, value: bigint) => void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validatePositiveInput = void 0;
4
+ const error_js_1 = require("../types/error.js");
5
+ /**
6
+ * Requires a strictly positive input amount.
7
+ *
8
+ * @param field - Input field name used in the error.
9
+ * @param value - Candidate amount.
10
+ * @returns Nothing when the amount is positive.
11
+ * @throws {NonPositiveInputError} when the amount is zero or negative.
12
+ * @internal
13
+ */
14
+ const validatePositiveInput = (field, value) => {
15
+ if (value <= 0n)
16
+ throw new error_js_1.NonPositiveInputError(field, value);
17
+ };
18
+ exports.validatePositiveInput = validatePositiveInput;
@@ -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, InvalidEcrecoverSignatureError, 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,14 +1,18 @@
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.InvalidEcrecoverSignatureError = 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
+ Object.defineProperty(exports, "InvalidEcrecoverSignatureError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureError; } });
6
7
  Object.defineProperty(exports, "InvalidEcrecoverSignatureVError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidEcrecoverSignatureVError; } });
7
8
  Object.defineProperty(exports, "InvalidMarketParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMarketParameterError; } });
8
9
  Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiQuoteTargetError; } });
9
10
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
10
11
  Object.defineProperty(exports, "InvalidOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
11
12
  Object.defineProperty(exports, "InvalidOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
13
+ Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
14
+ Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
15
+ Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
12
16
  Object.defineProperty(exports, "InvalidRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
13
17
  Object.defineProperty(exports, "InvalidRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
14
18
  Object.defineProperty(exports, "InvalidRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -26,7 +30,3 @@ Object.defineProperty(exports, "RatifierV1TakerNotAllowedError", { enumerable: t
26
30
  Object.defineProperty(exports, "SettlementFeeExceedsPriceError", { enumerable: true, get: function () { return midnight_sdk_1.SettlementFeeExceedsPriceError; } });
27
31
  Object.defineProperty(exports, "TickOutOfRangeError", { enumerable: true, get: function () { return midnight_sdk_1.TickOutOfRangeError; } });
28
32
  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; } });
@@ -283,12 +283,12 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
283
283
  }> {
284
284
  }
285
285
  /**
286
- * Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position,
286
+ * Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's supply shares,
287
287
  * sent by the callback's owner.
288
288
  */
289
289
  export interface BlueWithdrawBuyCallbackAction extends BaseAction<"blueWithdrawBuyCallback", {
290
290
  readonly market: Hex;
291
- /** Supply shares burned: the callback's whole position. */
291
+ /** Caller-supplied number of supply shares burned. */
292
292
  readonly shares: bigint;
293
293
  /** BlueBuyCallback whose supply position is withdrawn. */
294
294
  readonly onBehalf: Address;
@@ -449,6 +449,13 @@ export interface MidnightSupplyCollateralAction extends BaseAction<"midnightSupp
449
449
  readonly onBehalf: Address;
450
450
  }> {
451
451
  }
452
+ /** Metadata for an atomic direct Midnight collateral supply batch. */
453
+ export interface MidnightSupplyCollateralBatchAction extends BaseAction<"midnightSupplyCollateralBatch", {
454
+ readonly market: Hex;
455
+ readonly collateralSupplies: readonly MidnightCollateralTransfer[];
456
+ readonly onBehalf: Address;
457
+ }> {
458
+ }
452
459
  /** Metadata for a direct Midnight collateral withdrawal transaction. */
453
460
  export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWithdrawCollateral", {
454
461
  readonly market: Hex;
@@ -458,6 +465,14 @@ export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWi
458
465
  readonly receiver: Address;
459
466
  }> {
460
467
  }
468
+ /** Metadata for an atomic direct Midnight collateral withdrawal batch. */
469
+ export interface MidnightWithdrawCollateralBatchAction extends BaseAction<"midnightWithdrawCollateralBatch", {
470
+ readonly market: Hex;
471
+ readonly collateralWithdrawals: readonly MidnightCollateralTransfer[];
472
+ readonly onBehalf: Address;
473
+ readonly receiver: Address;
474
+ }> {
475
+ }
461
476
  /** Metadata for a direct Midnight credit redemption transaction. */
462
477
  export interface MidnightRedeemAction extends BaseAction<"midnightRedeem", {
463
478
  readonly market: Hex;
@@ -524,7 +539,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
524
539
  * VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
525
540
  * consumers can `switch` exhaustively on it.
526
541
  */
527
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
542
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
528
543
  /**
529
544
  * Describes a single, immutable, deep-frozen transaction to submit on-chain:
530
545
  * the target `to`, native `value`, encoded call `data`, and the originating
@@ -922,9 +922,22 @@ export declare class RepayExceedsDebtError extends Error {
922
922
  market: string;
923
923
  });
924
924
  }
925
- /** Thrown when EIP-712 signature verification fails (the signed data does not match the expected signer). */
925
+ /** Thrown when EIP-712 signature verification fails to recover the expected signer. */
926
926
  export declare class InvalidSignatureError extends Error {
927
- constructor();
927
+ constructor(options?: ErrorOptions);
928
+ }
929
+ /** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
930
+ export declare class MalformedSignatureError extends InvalidSignatureError {
931
+ /** JavaScript type returned by the wallet, without the signature value. */
932
+ readonly signatureType: string;
933
+ /** Whether the returned value is an even-length hex string. */
934
+ readonly signatureIsHex: boolean;
935
+ /** Signature byte length, when it is an even-length hex string. */
936
+ readonly signatureByteLength: number | undefined;
937
+ constructor(params: {
938
+ readonly signature: unknown;
939
+ readonly cause: unknown;
940
+ });
928
941
  }
929
942
  /** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
930
943
  export declare class RepaySharesExceedDebtError extends Error {
@@ -1056,6 +1069,14 @@ export declare class EmptyMidnightGroupCancellationsError extends Error {
1056
1069
  export declare class EmptyMidnightCollateralSuppliesError extends Error {
1057
1070
  constructor();
1058
1071
  }
1072
+ /** Thrown when a direct Midnight collateral withdrawal batch is empty. */
1073
+ export declare class EmptyMidnightCollateralWithdrawalsError extends Error {
1074
+ constructor();
1075
+ }
1076
+ /** Thrown when a direct Midnight collateral batch repeats an index. */
1077
+ export declare class DuplicateMidnightCollateralIndexError extends Error {
1078
+ constructor(collateralIndex: bigint);
1079
+ }
1059
1080
  /** Thrown when a Midnight batch cancellation lists the same offer group twice. */
1060
1081
  export declare class DuplicateMidnightGroupCancellationError extends Error {
1061
1082
  constructor(params: {
@@ -1,8 +1,8 @@
1
1
  "use strict";
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
- 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.BlueBuyCallbackUnauthorizedError = exports.BlueBuyCallbackOwnerMismatchError = exports.NotBlueBuyCallbackError = exports.InsufficientBlueLiquidityError = exports.EmptyBlueSupplyPositionError = 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;
4
+ 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.DuplicateMidnightCollateralIndexError = exports.EmptyMidnightCollateralWithdrawalsError = 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.MalformedSignatureError = 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.BlueBuyCallbackUnauthorizedError = exports.BlueBuyCallbackOwnerMismatchError = exports.NotBlueBuyCallbackError = exports.InsufficientBlueLiquidityError = exports.EmptyBlueSupplyPositionError = 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 = exports.MidnightOfferMarketAddressMismatchError = exports.MidnightOfferMarketChainMismatchError = exports.MidnightTakeDeadlineTooFarError = 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");
@@ -1208,14 +1208,38 @@ class RepayExceedsDebtError extends Error {
1208
1208
  }
1209
1209
  }
1210
1210
  exports.RepayExceedsDebtError = RepayExceedsDebtError;
1211
- /** Thrown when EIP-712 signature verification fails (the signed data does not match the expected signer). */
1211
+ /** Thrown when EIP-712 signature verification fails to recover the expected signer. */
1212
1212
  class InvalidSignatureError extends Error {
1213
- constructor() {
1214
- super("Signature verification failed: the signed data does not match the expected signer address");
1213
+ constructor(options) {
1214
+ super("Signature verification failed: the signed data does not match the expected signer address", options);
1215
1215
  this.name = "InvalidSignatureError";
1216
1216
  }
1217
1217
  }
1218
1218
  exports.InvalidSignatureError = InvalidSignatureError;
1219
+ /** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
1220
+ class MalformedSignatureError extends InvalidSignatureError {
1221
+ /** JavaScript type returned by the wallet, without the signature value. */
1222
+ signatureType;
1223
+ /** Whether the returned value is an even-length hex string. */
1224
+ signatureIsHex;
1225
+ /** Signature byte length, when it is an even-length hex string. */
1226
+ signatureByteLength;
1227
+ constructor(params) {
1228
+ super({ cause: params.cause });
1229
+ this.name = "MalformedSignatureError";
1230
+ this.message =
1231
+ "Signature verification failed: the wallet returned a malformed signature. Check the wallet signing transport and sign the typed data again.";
1232
+ this.signatureType = typeof params.signature;
1233
+ this.signatureIsHex =
1234
+ typeof params.signature === "string" &&
1235
+ /^0x(?:[0-9a-fA-F]{2})*$/.test(params.signature);
1236
+ this.signatureByteLength =
1237
+ this.signatureIsHex && typeof params.signature === "string"
1238
+ ? (params.signature.length - 2) / 2
1239
+ : undefined;
1240
+ }
1241
+ }
1242
+ exports.MalformedSignatureError = MalformedSignatureError;
1219
1243
  /** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
1220
1244
  class RepaySharesExceedDebtError extends Error {
1221
1245
  constructor(params) {
@@ -1377,6 +1401,22 @@ class EmptyMidnightCollateralSuppliesError extends Error {
1377
1401
  }
1378
1402
  }
1379
1403
  exports.EmptyMidnightCollateralSuppliesError = EmptyMidnightCollateralSuppliesError;
1404
+ /** Thrown when a direct Midnight collateral withdrawal batch is empty. */
1405
+ class EmptyMidnightCollateralWithdrawalsError extends Error {
1406
+ constructor() {
1407
+ super("Midnight collateral withdrawals cannot be empty. Pass at least one collateral withdrawal.");
1408
+ this.name = "EmptyMidnightCollateralWithdrawalsError";
1409
+ }
1410
+ }
1411
+ exports.EmptyMidnightCollateralWithdrawalsError = EmptyMidnightCollateralWithdrawalsError;
1412
+ /** Thrown when a direct Midnight collateral batch repeats an index. */
1413
+ class DuplicateMidnightCollateralIndexError extends Error {
1414
+ constructor(collateralIndex) {
1415
+ super(`Midnight collateral batch repeats index "${collateralIndex}". Pass each collateral index once.`);
1416
+ this.name = "DuplicateMidnightCollateralIndexError";
1417
+ }
1418
+ }
1419
+ exports.DuplicateMidnightCollateralIndexError = DuplicateMidnightCollateralIndexError;
1380
1420
  /** Thrown when a Midnight batch cancellation lists the same offer group twice. */
1381
1421
  class DuplicateMidnightGroupCancellationError extends Error {
1382
1422
  constructor(params) {
@@ -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,5 +1,5 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, 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. */
package/lib/esm/abis.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
2
- export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
2
+ export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, 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. */
@@ -85,8 +85,8 @@ export const blueRepayWithdrawCollateral = (params) => {
85
85
  if (repayAssets > 0n && repayShares > 0n) {
86
86
  throw new MutuallyExclusiveRepayAmountsError(marketParams.id);
87
87
  }
88
- const hasRepay = repayAssets > 0n || repayShares > 0n;
89
- if (!hasRepay && collateralAssets === 0n) {
88
+ const hasRepay = repayAssets + repayShares > 0n;
89
+ if (repayAssets + repayShares + collateralAssets === 0n) {
90
90
  throw new NonPositiveInputError("repayAssets, repayShares, or collateralAssets", 0n);
91
91
  }
92
92
  if (hasRepay && maxRepayAssets === 0n) {
@@ -215,6 +215,15 @@ export const normalizeBundlesSignature = (serializedSignature, onInvalid = (deta
215
215
  }
216
216
  return { v: Number(normalizedV), r: parsed.r, s: parsed.s };
217
217
  };
218
+ const validateBundlesPermitValue = (params) => {
219
+ if (params.actual !== params.expected) {
220
+ throw new BundlesPermitMismatchError({
221
+ field: params.field,
222
+ expected: String(params.expected),
223
+ actual: String(params.actual),
224
+ });
225
+ }
226
+ };
218
227
  /**
219
228
  * Converts an optional vault-share ERC-2612 requirement into the ABI-ready Permit tuple.
220
229
  *
@@ -246,10 +255,6 @@ export const getBundlesSharesPermit = (params) => {
246
255
  const { requirementSignature } = params;
247
256
  // Require a positive uint256 for the fallback permit deadline.
248
257
  validateDeadline(params.deadline);
249
- if (requirementSignature != null) {
250
- // Require a positive uint256 for the signed permit deadline too.
251
- validateDeadline(requirementSignature.args.deadline);
252
- }
253
258
  if (requirementSignature == null) {
254
259
  return {
255
260
  value: 0n,
@@ -260,6 +265,9 @@ export const getBundlesSharesPermit = (params) => {
260
265
  s: zeroHash,
261
266
  };
262
267
  }
268
+ // Require a positive uint256 for the signed permit deadline too.
269
+ validateDeadline(requirementSignature.args.deadline);
270
+ const validatesOperation = params.owner != null || params.spender != null || params.amount != null;
263
271
  if (requirementSignature.action.type !== "permit") {
264
272
  throw new BundlesPermitMismatchError({
265
273
  field: "type",
@@ -299,29 +307,26 @@ export const getBundlesSharesPermit = (params) => {
299
307
  actual: String(requirementSignature.args.amount),
300
308
  });
301
309
  }
302
- if ((params.owner != null || params.spender != null || params.amount != null) &&
303
- requirementSignature.action.args.amount !== requirementSignature.args.amount) {
304
- throw new BundlesPermitMismatchError({
310
+ if (validatesOperation) {
311
+ // Validation only; checks signed values against their operation descriptors.
312
+ validateBundlesPermitValue({
305
313
  field: "amount",
306
- expected: String(requirementSignature.args.amount),
307
- actual: String(requirementSignature.action.args.amount),
314
+ expected: requirementSignature.args.amount,
315
+ actual: requirementSignature.action.args.amount,
308
316
  });
309
- }
310
- if ((params.owner != null || params.spender != null || params.amount != null) &&
311
- requirementSignature.action.args.deadline !==
312
- requirementSignature.args.deadline) {
313
- throw new BundlesPermitMismatchError({
317
+ // Validation only; checks the signed deadline against its operation descriptor.
318
+ validateBundlesPermitValue({
314
319
  field: "deadline",
315
- expected: String(requirementSignature.args.deadline),
316
- actual: String(requirementSignature.action.args.deadline),
320
+ expected: requirementSignature.args.deadline,
321
+ actual: requirementSignature.action.args.deadline,
317
322
  });
318
323
  }
319
- if (requirementSignature.action.args.nonce != null &&
320
- requirementSignature.action.args.nonce !== requirementSignature.args.nonce) {
321
- throw new BundlesPermitMismatchError({
324
+ if (requirementSignature.action.args.nonce != null) {
325
+ // Validation only; checks the optional operation nonce against the signed nonce.
326
+ validateBundlesPermitValue({
322
327
  field: "nonce",
323
- expected: String(requirementSignature.args.nonce),
324
- actual: String(requirementSignature.action.args.nonce),
328
+ expected: requirementSignature.args.nonce,
329
+ actual: requirementSignature.action.args.nonce,
325
330
  });
326
331
  }
327
332
  const signature = normalizeBundlesSignature(requirementSignature.args.signature);
@@ -349,7 +354,9 @@ export const getBundlesSharesPermit = (params) => {
349
354
  * from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
350
355
  */
351
356
  export const selectBundlesTokenRequirementSignature = (signatures, expected) => {
352
- if (signatures == null || signatures.length === 0)
357
+ if (signatures == null)
358
+ return undefined;
359
+ if (signatures.length === 0)
353
360
  return undefined;
354
361
  const selected = signatures.filter((signature) => signature.action.type === "permit" ||
355
362
  signature.action.type === "permit2SignatureTransfer");
@@ -372,24 +379,24 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
372
379
  actual: action.args.spender,
373
380
  });
374
381
  }
375
- if (selectedSignature.args.amount !== expected.amount ||
376
- action.args.amount !== expected.amount) {
382
+ const actualAmount = selectedSignature.args.amount !== expected.amount
383
+ ? selectedSignature.args.amount
384
+ : action.args.amount;
385
+ if (actualAmount !== expected.amount) {
377
386
  throw new BundlesPermitMismatchError({
378
387
  field: "amount",
379
388
  expected: String(expected.amount),
380
- actual: String(selectedSignature.args.amount !== expected.amount
381
- ? selectedSignature.args.amount
382
- : action.args.amount),
389
+ actual: String(actualAmount),
383
390
  });
384
391
  }
385
- if (selectedSignature.args.deadline !== expected.deadline ||
386
- action.args.deadline !== expected.deadline) {
392
+ const actualDeadline = selectedSignature.args.deadline !== expected.deadline
393
+ ? selectedSignature.args.deadline
394
+ : action.args.deadline;
395
+ if (actualDeadline !== expected.deadline) {
387
396
  throw new BundlesPermitMismatchError({
388
397
  field: "deadline",
389
398
  expected: String(expected.deadline),
390
- actual: String(selectedSignature.args.deadline !== expected.deadline
391
- ? selectedSignature.args.deadline
392
- : action.args.deadline),
399
+ actual: String(actualDeadline),
393
400
  });
394
401
  }
395
402
  if (action.args.nonce != null &&