@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,7 +1,7 @@
1
- export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, InvalidVaultV2MidnightAdapterMarketsError as InvalidBlueVaultV2MidnightAdapterMarketsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
1
+ export { BlueErrors, IncompleteChainRegistryError, InvalidMarketParamsError as InvalidBlueMarketParamsError, UnknownAddressError, UnknownDataError as UnknownBlueDataError, UnknownFactory as UnknownBlueFactory, UnknownMarketAllocationError as UnknownBlueMarketAllocationError, UnknownMarketParamsError as UnknownBlueMarketParamsError, UnknownOfFactory as UnknownBlueOfFactory, UnknownTokenError as UnknownBlueTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError, VaultV2Errors, } from "@morpho-org/blue-sdk";
4
- export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError as BlueUnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, } from "@morpho-org/morpho-ts";
package/lib/cjs/errors.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.BlueUnresolvedBlockNumberError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueVaultV2MidnightAdapterMarketsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
- exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidPositionAccrualStateError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = void 0;
3
+ exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
+ exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
7
7
  Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
8
8
  Object.defineProperty(exports, "InvalidBlueMarketParamsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidMarketParamsError; } });
9
- Object.defineProperty(exports, "InvalidBlueVaultV2MidnightAdapterMarketsError", { enumerable: true, get: function () { return blue_sdk_1.InvalidVaultV2MidnightAdapterMarketsError; } });
10
9
  Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
11
10
  Object.defineProperty(exports, "UnknownBlueDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
12
11
  Object.defineProperty(exports, "UnknownBlueFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
@@ -32,9 +31,9 @@ Object.defineProperty(exports, "MalformedTokenMetadataError", { enumerable: true
32
31
  Object.defineProperty(exports, "BlueMarketParamsIdMismatchError", { enumerable: true, get: function () { return blue_sdk_viem_1.MarketParamsIdMismatchError; } });
33
32
  Object.defineProperty(exports, "MissingPermitDomainNameError", { enumerable: true, get: function () { return blue_sdk_viem_1.MissingPermitDomainNameError; } });
34
33
  Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, get: function () { return blue_sdk_viem_1.NonTupleReturnValueError; } });
34
+ Object.defineProperty(exports, "Permit2ExpirationOutOfRangeError", { enumerable: true, get: function () { return blue_sdk_viem_1.Permit2ExpirationOutOfRangeError; } });
35
35
  Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
36
36
  Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
37
- Object.defineProperty(exports, "BlueUnresolvedBlockNumberError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnresolvedBlockNumberError; } });
38
37
  Object.defineProperty(exports, "UnsupportedPermitDomainExtensionsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError; } });
39
38
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
40
39
  Object.defineProperty(exports, "MidnightChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
@@ -44,6 +43,9 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
44
43
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
45
44
  Object.defineProperty(exports, "InvalidMidnightOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
46
45
  Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
46
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
47
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
48
+ Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
47
49
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
48
50
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
49
51
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -66,11 +68,5 @@ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { re
66
68
  Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return morpho_ts_1.DivisionByZeroError; } });
67
69
  Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return morpho_ts_1.InvalidAddressError; } });
68
70
  Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
69
- Object.defineProperty(exports, "InvalidPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
70
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
71
- Object.defineProperty(exports, "InvalidPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
72
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
73
- Object.defineProperty(exports, "InvalidPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
74
- Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
75
71
  Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
76
72
  Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
2
2
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
3
  fetchPreLiquidationParams as fetchBluePreLiquidationParams,
4
4
  /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
- fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
5
+ fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
6
6
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/cjs/fetch.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2MidnightAdapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2MidnightAdapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
3
+ exports.fetchMidnightRatifierInfo = exports.fetchMidnightPosition = exports.fetchMidnightMarketParams = exports.fetchMidnightMarket = exports.fetchMidnightAccrualPosition = exports.fetchVaultV2MorphoVaultV1Adapter = exports.fetchVaultV2MorphoMarketV1AdapterV2 = exports.fetchVaultV2MorphoMarketV1Adapter = exports.fetchVaultV2BluePublicAllocatorData = exports.fetchVaultV2BluePublicAllocatorConfig = exports.fetchVaultV2BlueMarketPublicAllocatorConfig = exports.fetchVaultV2Adapter = exports.fetchVaultV2 = exports.fetchVaultUser = exports.fetchVaultMarketConfig = exports.fetchVaultMarketAllocation = exports.fetchVaultConfig = exports.fetchVault = exports.fetchBlueUser = exports.fetchToken = exports.fetchBluePreLiquidationPosition = exports.fetchBluePreLiquidationParams = exports.fetchBluePosition = exports.fetchBlueMarketParams = exports.fetchBlueMarket = exports.fetchHolding = exports.fetchAccrualVaultV2MorphoVaultV1Adapter = exports.fetchAccrualVaultV2MorphoMarketV1AdapterV2 = exports.fetchAccrualVaultV2MorphoMarketV1Adapter = exports.fetchAccrualVaultV2Adapter = exports.fetchAccrualVaultV2 = exports.fetchAccrualVault = exports.fetchBlueAccrualPosition = void 0;
4
4
  var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
5
5
  Object.defineProperty(exports, "fetchBlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualPosition; } });
6
6
  Object.defineProperty(exports, "fetchAccrualVault", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVault; } });
7
7
  Object.defineProperty(exports, "fetchAccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2; } });
8
8
  Object.defineProperty(exports, "fetchAccrualVaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2Adapter; } });
9
- Object.defineProperty(exports, "fetchAccrualVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MidnightAdapter; } });
10
9
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1Adapter; } });
11
10
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1AdapterV2; } });
12
11
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoVaultV1Adapter; } });
@@ -30,7 +29,6 @@ Object.defineProperty(exports, "fetchVaultV2Adapter", { enumerable: true, get: f
30
29
  Object.defineProperty(exports, "fetchVaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BlueMarketPublicAllocatorConfig; } });
31
30
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorConfig; } });
32
31
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorData", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorData; } });
33
- Object.defineProperty(exports, "fetchVaultV2MidnightAdapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MidnightAdapter; } });
34
32
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1Adapter; } });
35
33
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1AdapterV2; } });
36
34
  Object.defineProperty(exports, "fetchVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoVaultV1Adapter; } });
@@ -30,6 +30,13 @@ export declare const DEFAULT_CAP_ACCRUAL_BUFFER: bigint;
30
30
  * `VaultV2BluePublicAllocatorOptions.allocatorCapHeadroom`.
31
31
  */
32
32
  export declare const DEFAULT_ALLOCATOR_CAP_HEADROOM: bigint;
33
+ /**
34
+ * Minimum shares a Morpho Blue market, Vault V1 or Vault V2 must hold at `DEAD_ADDRESS` to count as
35
+ * protected against share-price inflation (1e9, Protocol team rule).
36
+ */
37
+ export declare const MIN_DEAD_SHARES = 1000000000n;
38
+ /** Minimum assets, in the vault asset's smallest unit, a Vault V2's dead shares must be worth (1e6). */
39
+ export declare const MIN_VAULT_V2_DEAD_ASSETS = 1000000n;
33
40
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
34
41
  export declare const MAX_ABSOLUTE_SHARE_PRICE: bigint;
35
42
  /**
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = void 0;
3
+ exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
@@ -35,6 +35,13 @@ exports.DEFAULT_CAP_ACCRUAL_BUFFER = morpho_ts_1.Time.s.from.h(2n);
35
35
  * `VaultV2BluePublicAllocatorOptions.allocatorCapHeadroom`.
36
36
  */
37
37
  exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = blue_sdk_1.MathLib.WAD / 100n;
38
+ /**
39
+ * Minimum shares a Morpho Blue market, Vault V1 or Vault V2 must hold at `DEAD_ADDRESS` to count as
40
+ * protected against share-price inflation (1e9, Protocol team rule).
41
+ */
42
+ exports.MIN_DEAD_SHARES = 1000000000n;
43
+ /** Minimum assets, in the vault asset's smallest unit, a Vault V2's dead shares must be worth (1e6). */
44
+ exports.MIN_VAULT_V2_DEAD_ASSETS = 1000000n;
38
45
  /** Maximum absolute share price cap (100 RAY). Prevents absurd maxSharePrice values in repay. */
39
46
  exports.MAX_ABSOLUTE_SHARE_PRICE = 100n * blue_sdk_1.MathLib.RAY;
40
47
  /**
@@ -0,0 +1,82 @@
1
+ import { type AccrualVault, type AccrualVaultV2, type IMarket } from "@morpho-org/blue-sdk";
2
+ import type { Address, Hash } from "viem";
3
+ type DeadSharesPath = readonly (Address | Hash)[];
4
+ /**
5
+ * Checks that a Morpho Blue market holds at least `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
6
+ *
7
+ * @param market - Fetched market snapshot.
8
+ * @param path - Vaults leading to this market, outermost first; empty for a direct market.
9
+ * @returns Nothing; returns normally when the market passes.
10
+ * @throws {MissingDeadSharesDataError} when `market.deadSupplyShares` was not fetched.
11
+ * @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` dead supply shares.
12
+ * @example
13
+ * ```ts
14
+ * import { validateBlueMarketDeadShares } from "@morpho-org/morpho-sdk";
15
+ * import { fetchBlueMarket } from "@morpho-org/morpho-sdk/fetch";
16
+ * import { markets } from "@morpho-org/morpho-test";
17
+ * import { createPublicClient, http } from "viem";
18
+ * import { mainnet } from "viem/chains";
19
+ *
20
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
21
+ * const market = await fetchBlueMarket(markets[mainnet.id].usdc_wbtc.id, client);
22
+ * validateBlueMarketDeadShares(market);
23
+ * // Returns void on success; throws if the snapshot fails the rule.
24
+ * ```
25
+ */
26
+ export declare function validateBlueMarketDeadShares(market: Pick<IMarket, "params" | "deadSupplyShares"> & {
27
+ readonly id: Hash;
28
+ }, path?: DeadSharesPath): void;
29
+ /**
30
+ * Checks that a Vault V1 holds at least `MIN_DEAD_SHARES` shares at `DEAD_ADDRESS` and that every
31
+ * market in its withdraw queue passes `validateBlueMarketDeadShares`.
32
+ *
33
+ * @param vault - Fetched vault snapshot with its withdraw-queue allocations.
34
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
35
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
36
+ * @throws {MissingDeadSharesDataError} when `vault.deadShares`, a withdraw-queue allocation or a
37
+ * market's `deadSupplyShares` was not fetched.
38
+ * @throws {InsufficientDeadSharesError} when the vault or one of its withdraw-queue markets holds
39
+ * too few dead shares.
40
+ * @example
41
+ * ```ts
42
+ * import { validateVaultV1DeadShares } from "@morpho-org/morpho-sdk";
43
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
44
+ * import { vaults } from "@morpho-org/morpho-test";
45
+ * import { createPublicClient, http } from "viem";
46
+ * import { mainnet } from "viem/chains";
47
+ *
48
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
49
+ * const vault = await fetchAccrualVault(vaults[mainnet.id].steakUsdc.address, client);
50
+ * validateVaultV1DeadShares(vault);
51
+ * // Returns void on success; throws if the snapshot fails the rule.
52
+ * ```
53
+ */
54
+ export declare function validateVaultV1DeadShares(vault: AccrualVault, path?: DeadSharesPath): void;
55
+ /**
56
+ * Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
57
+ * `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
58
+ * `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
59
+ * absolute cap) passing its own rule. Zero-cap entries are skipped.
60
+ *
61
+ * @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
62
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
63
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
64
+ * @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
65
+ * adapter the SDK cannot hydrate is missing.
66
+ * @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
67
+ * @example
68
+ * ```ts
69
+ * import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
70
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
71
+ * import { createPublicClient, http } from "viem";
72
+ * import { mainnet } from "viem/chains";
73
+ *
74
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
75
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
76
+ * const vault = await fetchAccrualVaultV2(keyrockUsdcVaultV2, client);
77
+ * validateVaultV2DeadShares(vault);
78
+ * // Returns void on success; throws if the snapshot fails the rule.
79
+ * ```
80
+ */
81
+ export declare function validateVaultV2DeadShares(vault: AccrualVaultV2, path?: DeadSharesPath): void;
82
+ export {};
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateBlueMarketDeadShares = validateBlueMarketDeadShares;
4
+ exports.validateVaultV1DeadShares = validateVaultV1DeadShares;
5
+ exports.validateVaultV2DeadShares = validateVaultV2DeadShares;
6
+ const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
+ const error_js_1 = require("../types/error.js");
8
+ const constant_js_1 = require("./constant.js");
9
+ /**
10
+ * Checks that a Morpho Blue market holds at least `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
11
+ *
12
+ * @param market - Fetched market snapshot.
13
+ * @param path - Vaults leading to this market, outermost first; empty for a direct market.
14
+ * @returns Nothing; returns normally when the market passes.
15
+ * @throws {MissingDeadSharesDataError} when `market.deadSupplyShares` was not fetched.
16
+ * @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` dead supply shares.
17
+ * @example
18
+ * ```ts
19
+ * import { validateBlueMarketDeadShares } from "@morpho-org/morpho-sdk";
20
+ * import { fetchBlueMarket } from "@morpho-org/morpho-sdk/fetch";
21
+ * import { markets } from "@morpho-org/morpho-test";
22
+ * import { createPublicClient, http } from "viem";
23
+ * import { mainnet } from "viem/chains";
24
+ *
25
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
26
+ * const market = await fetchBlueMarket(markets[mainnet.id].usdc_wbtc.id, client);
27
+ * validateBlueMarketDeadShares(market);
28
+ * // Returns void on success; throws if the snapshot fails the rule.
29
+ * ```
30
+ */
31
+ function validateBlueMarketDeadShares(market, path = []) {
32
+ const entity = [...path, market.id];
33
+ if (market.deadSupplyShares == null)
34
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadSupplyShares" });
35
+ if (market.deadSupplyShares < constant_js_1.MIN_DEAD_SHARES)
36
+ throw new error_js_1.InsufficientDeadSharesError({
37
+ entity,
38
+ reason: "deadShares",
39
+ observed: market.deadSupplyShares,
40
+ required: constant_js_1.MIN_DEAD_SHARES,
41
+ });
42
+ }
43
+ /**
44
+ * Checks that a Vault V1 holds at least `MIN_DEAD_SHARES` shares at `DEAD_ADDRESS` and that every
45
+ * market in its withdraw queue passes `validateBlueMarketDeadShares`.
46
+ *
47
+ * @param vault - Fetched vault snapshot with its withdraw-queue allocations.
48
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
49
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
50
+ * @throws {MissingDeadSharesDataError} when `vault.deadShares`, a withdraw-queue allocation or a
51
+ * market's `deadSupplyShares` was not fetched.
52
+ * @throws {InsufficientDeadSharesError} when the vault or one of its withdraw-queue markets holds
53
+ * too few dead shares.
54
+ * @example
55
+ * ```ts
56
+ * import { validateVaultV1DeadShares } from "@morpho-org/morpho-sdk";
57
+ * import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
58
+ * import { vaults } from "@morpho-org/morpho-test";
59
+ * import { createPublicClient, http } from "viem";
60
+ * import { mainnet } from "viem/chains";
61
+ *
62
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
63
+ * const vault = await fetchAccrualVault(vaults[mainnet.id].steakUsdc.address, client);
64
+ * validateVaultV1DeadShares(vault);
65
+ * // Returns void on success; throws if the snapshot fails the rule.
66
+ * ```
67
+ */
68
+ function validateVaultV1DeadShares(vault, path = []) {
69
+ const entity = [...path, vault.address];
70
+ if (vault.deadShares == null)
71
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadShares" });
72
+ if (vault.deadShares < constant_js_1.MIN_DEAD_SHARES)
73
+ throw new error_js_1.InsufficientDeadSharesError({
74
+ entity,
75
+ reason: "deadShares",
76
+ observed: vault.deadShares,
77
+ required: constant_js_1.MIN_DEAD_SHARES,
78
+ });
79
+ for (const marketId of vault.withdrawQueue) {
80
+ const allocation = vault.allocations.get(marketId);
81
+ if (allocation == null)
82
+ throw new error_js_1.MissingDeadSharesDataError({
83
+ entity: [...entity, marketId],
84
+ field: "allocation",
85
+ });
86
+ validateBlueMarketDeadShares(allocation.position.market, entity);
87
+ }
88
+ }
89
+ /**
90
+ * Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
91
+ * `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
92
+ * `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
93
+ * absolute cap) passing its own rule. Zero-cap entries are skipped.
94
+ *
95
+ * @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
96
+ * @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
97
+ * @returns Nothing; returns normally when the vault and everything it can allocate to pass.
98
+ * @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
99
+ * adapter the SDK cannot hydrate is missing.
100
+ * @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
101
+ * @example
102
+ * ```ts
103
+ * import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
104
+ * import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
105
+ * import { createPublicClient, http } from "viem";
106
+ * import { mainnet } from "viem/chains";
107
+ *
108
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
109
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
110
+ * const vault = await fetchAccrualVaultV2(keyrockUsdcVaultV2, client);
111
+ * validateVaultV2DeadShares(vault);
112
+ * // Returns void on success; throws if the snapshot fails the rule.
113
+ * ```
114
+ */
115
+ function validateVaultV2DeadShares(vault, path = []) {
116
+ const entity = [...path, vault.address];
117
+ const { deadShares, deadAssets, absoluteCaps } = vault;
118
+ if (deadShares == null)
119
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadShares" });
120
+ if (deadAssets == null)
121
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadAssets" });
122
+ if (absoluteCaps == null)
123
+ throw new error_js_1.MissingDeadSharesDataError({ entity, field: "absoluteCaps" });
124
+ if (deadShares < constant_js_1.MIN_DEAD_SHARES)
125
+ throw new error_js_1.InsufficientDeadSharesError({
126
+ entity,
127
+ reason: "deadShares",
128
+ observed: deadShares,
129
+ required: constant_js_1.MIN_DEAD_SHARES,
130
+ });
131
+ if (deadAssets < constant_js_1.MIN_VAULT_V2_DEAD_ASSETS)
132
+ throw new error_js_1.InsufficientDeadSharesError({
133
+ entity,
134
+ reason: "deadAssets",
135
+ observed: deadAssets,
136
+ required: constant_js_1.MIN_VAULT_V2_DEAD_ASSETS,
137
+ });
138
+ // Share price (totalAssets + 1) / (totalSupply + virtualShares) must exceed 1 / (10 * virtualShares).
139
+ const priceNumerator = (vault._totalAssets + 1n) * 10n * vault.virtualShares;
140
+ const priceDenominator = vault.totalSupply + vault.virtualShares;
141
+ if (priceNumerator <= priceDenominator)
142
+ throw new error_js_1.InsufficientDeadSharesError({
143
+ entity,
144
+ reason: "sharePrice",
145
+ observed: priceNumerator,
146
+ required: priceDenominator + 1n,
147
+ });
148
+ const capOf = (id, adapter) => {
149
+ const cap = absoluteCaps[id];
150
+ if (cap == null)
151
+ throw new error_js_1.MissingDeadSharesDataError({
152
+ entity: [...entity, adapter],
153
+ field: "absoluteCaps",
154
+ });
155
+ return cap;
156
+ };
157
+ for (const adapter of vault.accrualAdapters) {
158
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
159
+ const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
160
+ if (capOf(id, adapter.address) > 0n)
161
+ validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
162
+ }
163
+ else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter) {
164
+ for (const { market } of adapter.positions) {
165
+ const id = blue_sdk_1.VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
166
+ if (capOf(id, adapter.address) > 0n)
167
+ validateBlueMarketDeadShares(market, entity);
168
+ }
169
+ }
170
+ else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2) {
171
+ for (const market of adapter.markets) {
172
+ const id = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
173
+ if (capOf(id, adapter.address) > 0n)
174
+ validateBlueMarketDeadShares(market, entity);
175
+ }
176
+ }
177
+ else {
178
+ throw new error_js_1.MissingDeadSharesDataError({
179
+ entity: [...entity, adapter.address],
180
+ field: "adapter",
181
+ });
182
+ }
183
+ }
184
+ // Deposits are allocated to the liquidity market, so the snapshot must hold it even when it
185
+ // has no allocation yet (the adapters only list markets they currently supply to).
186
+ const liquidityAdapter = vault.accrualLiquidityAdapter;
187
+ if (vault.liquidityData === "0x" ||
188
+ !(liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter ||
189
+ liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2))
190
+ return;
191
+ const liquidityMarketId = blue_sdk_1.MarketParams.fromHex(vault.liquidityData).id;
192
+ const markets = liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter
193
+ ? liquidityAdapter.positions.map(({ market }) => market)
194
+ : liquidityAdapter.markets;
195
+ if (!markets.some(({ id }) => id === liquidityMarketId))
196
+ throw new error_js_1.MissingDeadSharesDataError({
197
+ entity: [...entity, liquidityAdapter.address, liquidityMarketId],
198
+ field: "liquidityMarket",
199
+ });
200
+ }
@@ -1,5 +1,6 @@
1
1
  export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
3
+ export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
3
4
  export { addTransactionMetadata } from "./metadata.js";
4
5
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
5
6
  export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
3
+ exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
4
4
  var callback_js_1 = require("./callback.js");
5
5
  Object.defineProperty(exports, "getMidnightBlueBuyCallbackAddress", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackAddress; } });
6
6
  Object.defineProperty(exports, "getMidnightBlueBuyCallbackData", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackData; } });
@@ -17,6 +17,12 @@ Object.defineProperty(exports, "MAX_REALLOCATION_PENALTY", { enumerable: true, g
17
17
  Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return constant_js_1.MAX_SLIPPAGE_TOLERANCE; } });
18
18
  Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
19
19
  Object.defineProperty(exports, "MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS", { enumerable: true, get: function () { return constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS; } });
20
+ Object.defineProperty(exports, "MIN_DEAD_SHARES", { enumerable: true, get: function () { return constant_js_1.MIN_DEAD_SHARES; } });
21
+ Object.defineProperty(exports, "MIN_VAULT_V2_DEAD_ASSETS", { enumerable: true, get: function () { return constant_js_1.MIN_VAULT_V2_DEAD_ASSETS; } });
22
+ var deadShares_js_1 = require("./deadShares.js");
23
+ Object.defineProperty(exports, "validateBlueMarketDeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateBlueMarketDeadShares; } });
24
+ Object.defineProperty(exports, "validateVaultV1DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV1DeadShares; } });
25
+ Object.defineProperty(exports, "validateVaultV2DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV2DeadShares; } });
20
26
  var metadata_js_1 = require("./metadata.js");
21
27
  Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
22
28
  var previewVaultV2ForceWithdraw_js_1 = require("./previewVaultV2ForceWithdraw.js");
@@ -1,4 +1,4 @@
1
- import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
1
+ import { type AccrualPosition, type MarketId, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import { type Market as MidnightMarket, type MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
3
3
  import { type Address } from "viem";
4
4
  import { type VaultV2BlueReallocation } from "../types/index.js";
@@ -15,6 +15,16 @@ import { type VaultV2BlueReallocation } from "../types/index.js";
15
15
  * @internal
16
16
  */
17
17
  export declare const validateUint256Field: (field: string, value: bigint) => void;
18
+ /**
19
+ * Rejects market params whose cached `id` does not hash from their five tuple fields, so a
20
+ * hand-built or mutated object cannot make the SDK describe one market while calldata targets another.
21
+ *
22
+ * @param marketParams - Market params whose `id` must equal the id derived from the tuple.
23
+ * @returns Nothing when `marketParams.id` matches the derived id.
24
+ * @throws {MarketIdMismatchError} when `marketParams.id` differs from the derived id.
25
+ * @internal
26
+ */
27
+ export declare const validateMarketParamsId: (marketParams: MarketParams) => void;
18
28
  /**
19
29
  * Rejects a deadline that no periphery can honour: the contracts read `0` as "unset" and the ABI
20
30
  * slot is a `uint256`. Callers that also need the deadline to be in the future layer their own
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateMidnightNativeAmount = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.getMidnightMaxSafeDebt = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = void 0;
3
+ exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateMidnightNativeAmount = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.getMidnightMaxSafeDebt = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateMarketParamsId = exports.validateUint256Field = void 0;
4
4
  exports.validateUserAddress = validateUserAddress;
5
5
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
@@ -39,6 +39,22 @@ const validateUint256Field = (field, value) => {
39
39
  }
40
40
  };
41
41
  exports.validateUint256Field = validateUint256Field;
42
+ /**
43
+ * Rejects market params whose cached `id` does not hash from their five tuple fields, so a
44
+ * hand-built or mutated object cannot make the SDK describe one market while calldata targets another.
45
+ *
46
+ * @param marketParams - Market params whose `id` must equal the id derived from the tuple.
47
+ * @returns Nothing when `marketParams.id` matches the derived id.
48
+ * @throws {MarketIdMismatchError} when `marketParams.id` differs from the derived id.
49
+ * @internal
50
+ */
51
+ const validateMarketParamsId = (marketParams) => {
52
+ const derivedId = blue_sdk_1.MarketUtils.getMarketId(marketParams);
53
+ if (marketParams.id !== derivedId) {
54
+ throw new index_js_1.MarketIdMismatchError(marketParams.id, derivedId);
55
+ }
56
+ };
57
+ exports.validateMarketParamsId = validateMarketParamsId;
42
58
  /**
43
59
  * Rejects a deadline that no periphery can honour: the contracts read `0` as "unset" and the ABI
44
60
  * slot is a `uint256`. Callers that also need the deadline to be in the future layer their own
@@ -7,13 +7,15 @@ import type { MarketInput, OfferStruct } from "@morpho-org/midnight-sdk";
7
7
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
8
8
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
9
9
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
10
- * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
10
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
11
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded or a sell offer's
12
+ * `receiverIfMakerIsSeller` is not an address.
11
13
  * @internal
12
14
  */
13
15
  export declare const validateTakeableOffers: (params: {
14
16
  readonly market: MarketInput;
15
17
  readonly takeableOffers: readonly {
16
- readonly offer: Pick<OfferStruct, "buy" | "market">;
18
+ readonly offer: Pick<OfferStruct, "buy" | "market" | "receiverIfMakerIsSeller">;
17
19
  }[];
18
20
  readonly expectedBuy: boolean;
19
21
  }) => `0x${string}`;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateTakeableOffers = void 0;
4
+ const viem_1 = require("viem");
4
5
  const index_js_1 = require("../types/index.js");
5
6
  const encodeMidnightCalldata_js_1 = require("./encodeMidnightCalldata.js");
7
+ const validateMidnightAccount_js_1 = require("./validateMidnightAccount.js");
6
8
  const validateOfferSides_js_1 = require("./validateOfferSides.js");
7
9
  /**
8
10
  * Validates the pure invariants shared by Midnight take entity and action layers.
@@ -12,7 +14,9 @@ const validateOfferSides_js_1 = require("./validateOfferSides.js");
12
14
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
13
15
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
14
16
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
15
- * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
17
+ * @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
18
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded or a sell offer's
19
+ * `receiverIfMakerIsSeller` is not an address.
16
20
  * @internal
17
21
  */
18
22
  const validateTakeableOffers = (params) => {
@@ -30,6 +34,13 @@ const validateTakeableOffers = (params) => {
30
34
  actualMarket: actualMarketId,
31
35
  });
32
36
  }
37
+ if (take.offer.buy)
38
+ continue;
39
+ // Reject a malformed address before viem compares it.
40
+ (0, validateMidnightAccount_js_1.validateMidnightAddress)(`takeableOffers[${index}].offer.receiverIfMakerIsSeller`, take.offer.receiverIfMakerIsSeller);
41
+ if ((0, viem_1.isAddressEqual)(take.offer.receiverIfMakerIsSeller, viem_1.zeroAddress)) {
42
+ throw new index_js_1.MidnightTakeableOfferZeroSellerReceiverError({ index });
43
+ }
33
44
  }
34
45
  return marketId;
35
46
  };
@@ -1 +1 @@
1
- export { blueBuyCallbackFactoryAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
1
+ export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setterRatifierAbi = exports.rateRatifierV1Abi = exports.priceRatifierV1Abi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.blueBuyCallbackFactoryAbi = void 0;
3
+ exports.setterRatifierAbi = exports.rateRatifierV1Abi = exports.priceRatifierV1Abi = exports.midnightEventsAbi = exports.midnightBundlesV2Abi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.ecrecoverAuthorizerAbi = exports.blueBuyCallbackFactoryAbi = void 0;
4
4
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
5
  Object.defineProperty(exports, "blueBuyCallbackFactoryAbi", { enumerable: true, get: function () { return midnight_sdk_1.blueBuyCallbackFactoryAbi; } });
6
+ Object.defineProperty(exports, "ecrecoverAuthorizerAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverAuthorizerAbi; } });
6
7
  Object.defineProperty(exports, "ecrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
7
8
  Object.defineProperty(exports, "midnightAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightAbi; } });
8
9
  Object.defineProperty(exports, "midnightBundlesV2Abi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesV2Abi; } });
10
+ Object.defineProperty(exports, "midnightEventsAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightEventsAbi; } });
9
11
  Object.defineProperty(exports, "priceRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.priceRatifierV1Abi; } });
10
12
  Object.defineProperty(exports, "rateRatifierV1Abi", { enumerable: true, get: function () { return midnight_sdk_1.rateRatifierV1Abi; } });
11
13
  Object.defineProperty(exports, "setterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });