@morpho-org/morpho-sdk 9.8.0 → 10.0.0-next.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 (181) hide show
  1. package/MIGRATION-v9-to-v10.md +114 -0
  2. package/README.md +5 -1
  3. package/lib/cjs/abis.d.ts +1 -1
  4. package/lib/cjs/abis.js +5 -1
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
  7. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
  8. package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
  9. package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
  10. package/lib/cjs/actions/midnight/cancelOffers.js +107 -0
  11. package/lib/cjs/actions/midnight/index.d.ts +1 -0
  12. package/lib/cjs/actions/midnight/index.js +1 -0
  13. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  14. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
  15. package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
  16. package/lib/cjs/actions/midnight/takeBorrow.js +1 -1
  17. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
  18. package/lib/cjs/actions/midnight/takeLend.js +1 -1
  19. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  20. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
  21. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
  22. package/lib/cjs/actions/midnight/takeWithdraw.js +1 -1
  23. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  25. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  26. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  27. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
  31. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  32. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  33. package/lib/cjs/blue/abis.d.ts +1 -1
  34. package/lib/cjs/blue/abis.js +5 -1
  35. package/lib/cjs/blue/entities.d.ts +4 -4
  36. package/lib/cjs/blue/entities.js +3 -1
  37. package/lib/cjs/blue/errors.d.ts +2 -2
  38. package/lib/cjs/blue/errors.js +5 -1
  39. package/lib/cjs/blue/fetch.d.ts +2 -2
  40. package/lib/cjs/blue/fetch.js +3 -1
  41. package/lib/cjs/blue/utils.d.ts +1 -1
  42. package/lib/cjs/blue/utils.js +2 -1
  43. package/lib/cjs/entities/blue/blue.d.ts +34 -28
  44. package/lib/cjs/entities/blue/blue.js +99 -73
  45. package/lib/cjs/entities/index.d.ts +4 -4
  46. package/lib/cjs/entities/index.js +3 -1
  47. package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
  48. package/lib/cjs/entities/midnight/deadline.js +2 -2
  49. package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
  50. package/lib/cjs/entities/midnight/midnight.js +144 -131
  51. package/lib/cjs/entities/midnight/publication.d.ts +2 -0
  52. package/lib/cjs/entities/midnight/publication.js +126 -100
  53. package/lib/cjs/entities/midnight/types.d.ts +4 -4
  54. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  55. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +17 -17
  56. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
  57. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
  58. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
  59. package/lib/cjs/entities/vaultV1/vaultV1.js +83 -57
  60. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +50 -24
  61. package/lib/cjs/entities/vaultV2/vaultV2.js +166 -90
  62. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +17 -2
  63. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1410 -806
  64. package/lib/cjs/errors.d.ts +4 -4
  65. package/lib/cjs/errors.js +7 -5
  66. package/lib/cjs/fetch.d.ts +2 -2
  67. package/lib/cjs/fetch.js +3 -1
  68. package/lib/cjs/helpers/deadShares.js +55 -34
  69. package/lib/cjs/helpers/metadata.d.ts +14 -2
  70. package/lib/cjs/helpers/metadata.js +39 -4
  71. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +34 -22
  72. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +7 -1
  73. package/lib/cjs/helpers/validate.js +76 -61
  74. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +154 -103
  75. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +31 -20
  76. package/lib/cjs/midnight/errors.d.ts +2 -1
  77. package/lib/cjs/midnight/errors.js +5 -4
  78. package/lib/cjs/transactionPlan/plan.js +6 -3
  79. package/lib/cjs/transactionPlan/serde.js +7 -7
  80. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +6 -4
  81. package/lib/cjs/transactionPlan/vaultv2/deposit.js +5 -3
  82. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +6 -4
  83. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +5 -3
  84. package/lib/cjs/types/action.d.ts +26 -2
  85. package/lib/cjs/types/action.js +1 -1
  86. package/lib/cjs/types/error.js +11 -5
  87. package/lib/cjs/types/metadata.d.ts +12 -2
  88. package/lib/cjs/utils.d.ts +2 -2
  89. package/lib/cjs/utils.js +4 -2
  90. package/lib/cjs/version.d.ts +1 -1
  91. package/lib/cjs/version.js +1 -1
  92. package/lib/esm/abis.d.ts +1 -1
  93. package/lib/esm/abis.js +1 -1
  94. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
  95. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
  96. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
  97. package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
  98. package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
  99. package/lib/esm/actions/midnight/cancelOffers.js +103 -0
  100. package/lib/esm/actions/midnight/index.d.ts +1 -0
  101. package/lib/esm/actions/midnight/index.js +1 -0
  102. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
  103. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
  104. package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
  105. package/lib/esm/actions/midnight/takeBorrow.js +1 -1
  106. package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
  107. package/lib/esm/actions/midnight/takeLend.js +1 -1
  108. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
  109. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
  110. package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
  111. package/lib/esm/actions/midnight/takeWithdraw.js +1 -1
  112. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
  113. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
  114. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
  115. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
  116. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
  117. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
  118. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
  119. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
  120. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
  121. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
  122. package/lib/esm/blue/abis.d.ts +1 -1
  123. package/lib/esm/blue/abis.js +1 -1
  124. package/lib/esm/blue/entities.d.ts +4 -4
  125. package/lib/esm/blue/entities.js +2 -2
  126. package/lib/esm/blue/errors.d.ts +2 -2
  127. package/lib/esm/blue/errors.js +2 -2
  128. package/lib/esm/blue/fetch.d.ts +2 -2
  129. package/lib/esm/blue/fetch.js +2 -2
  130. package/lib/esm/blue/utils.d.ts +1 -1
  131. package/lib/esm/blue/utils.js +1 -1
  132. package/lib/esm/entities/blue/blue.d.ts +34 -28
  133. package/lib/esm/entities/blue/blue.js +99 -73
  134. package/lib/esm/entities/index.d.ts +4 -4
  135. package/lib/esm/entities/index.js +2 -2
  136. package/lib/esm/entities/midnight/deadline.d.ts +2 -2
  137. package/lib/esm/entities/midnight/deadline.js +2 -2
  138. package/lib/esm/entities/midnight/midnight.d.ts +49 -51
  139. package/lib/esm/entities/midnight/midnight.js +145 -132
  140. package/lib/esm/entities/midnight/publication.d.ts +2 -0
  141. package/lib/esm/entities/midnight/publication.js +126 -100
  142. package/lib/esm/entities/midnight/types.d.ts +4 -4
  143. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
  144. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +17 -17
  145. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
  146. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
  147. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
  148. package/lib/esm/entities/vaultV1/vaultV1.js +83 -57
  149. package/lib/esm/entities/vaultV2/vaultV2.d.ts +50 -24
  150. package/lib/esm/entities/vaultV2/vaultV2.js +166 -90
  151. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +17 -2
  152. package/lib/esm/entities/vaultV2BlueReallocationData.js +1410 -806
  153. package/lib/esm/errors.d.ts +4 -4
  154. package/lib/esm/errors.js +4 -4
  155. package/lib/esm/fetch.d.ts +2 -2
  156. package/lib/esm/fetch.js +2 -2
  157. package/lib/esm/helpers/deadShares.js +56 -35
  158. package/lib/esm/helpers/metadata.d.ts +14 -2
  159. package/lib/esm/helpers/metadata.js +38 -4
  160. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +34 -22
  161. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +7 -1
  162. package/lib/esm/helpers/validate.js +76 -61
  163. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +153 -102
  164. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +31 -20
  165. package/lib/esm/midnight/errors.d.ts +2 -1
  166. package/lib/esm/midnight/errors.js +2 -1
  167. package/lib/esm/transactionPlan/plan.js +6 -3
  168. package/lib/esm/transactionPlan/serde.js +7 -7
  169. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +6 -4
  170. package/lib/esm/transactionPlan/vaultv2/deposit.js +5 -3
  171. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +6 -4
  172. package/lib/esm/transactionPlan/vaultv2/withdraw.js +5 -3
  173. package/lib/esm/types/action.d.ts +26 -2
  174. package/lib/esm/types/action.js +1 -1
  175. package/lib/esm/types/error.js +11 -5
  176. package/lib/esm/types/metadata.d.ts +12 -2
  177. package/lib/esm/utils.d.ts +2 -2
  178. package/lib/esm/utils.js +2 -2
  179. package/lib/esm/version.d.ts +1 -1
  180. package/lib/esm/version.js +1 -1
  181. package/package.json +8 -7
@@ -1,7 +1,7 @@
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,
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,
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, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
- export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, 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";
4
+ export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnresolvedBlockNumberError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
5
+ export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, 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";
6
6
  export type { ErrorClass } from "@morpho-org/morpho-ts";
7
- export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
7
+ export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
package/lib/cjs/errors.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.InvalidMidnightEcrecoverSignatureError = 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.RetryStoppedError = exports.RetriesExhaustedError = 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 = exports.MidnightMempoolValidationError = void 0;
3
+ 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.InvalidMidnightEcrecoverSignatureError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnresolvedBlockNumberError = 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.InvalidBlueVaultV2MidnightAdapterMarketsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
+ exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = 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; } });
9
10
  Object.defineProperty(exports, "UnknownAddressError", { enumerable: true, get: function () { return blue_sdk_1.UnknownAddressError; } });
10
11
  Object.defineProperty(exports, "UnknownBlueDataError", { enumerable: true, get: function () { return blue_sdk_1.UnknownDataError; } });
11
12
  Object.defineProperty(exports, "UnknownBlueFactory", { enumerable: true, get: function () { return blue_sdk_1.UnknownFactory; } });
@@ -34,6 +35,7 @@ Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, g
34
35
  Object.defineProperty(exports, "Permit2ExpirationOutOfRangeError", { enumerable: true, get: function () { return blue_sdk_viem_1.Permit2ExpirationOutOfRangeError; } });
35
36
  Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
36
37
  Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
38
+ Object.defineProperty(exports, "UnresolvedBlockNumberError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnresolvedBlockNumberError; } });
37
39
  Object.defineProperty(exports, "UnsupportedPermitDomainExtensionsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnsupportedPermitDomainExtensionsError; } });
38
40
  var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
39
41
  Object.defineProperty(exports, "MidnightChainIdMismatchError", { enumerable: true, get: function () { return midnight_sdk_1.ChainIdMismatchError; } });
@@ -44,9 +46,6 @@ Object.defineProperty(exports, "InvalidMidnightApiQuoteTargetError", { enumerabl
44
46
  Object.defineProperty(exports, "InvalidMidnightApiResponseError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidMidnightApiResponseError; } });
45
47
  Object.defineProperty(exports, "InvalidMidnightOfferGroupError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferGroupError; } });
46
48
  Object.defineProperty(exports, "InvalidMidnightOfferParameterError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidOfferParameterError; } });
47
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualStateError; } });
48
- Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionAccrualTimestampError; } });
49
- Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidPositionLossFactorError; } });
50
49
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1RateError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1RateError; } });
51
50
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TickError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TickError; } });
52
51
  Object.defineProperty(exports, "InvalidMidnightRateRatifierV1TimeError", { enumerable: true, get: function () { return midnight_sdk_1.InvalidRateRatifierV1TimeError; } });
@@ -69,6 +68,9 @@ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { re
69
68
  Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return morpho_ts_1.DivisionByZeroError; } });
70
69
  Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return morpho_ts_1.InvalidAddressError; } });
71
70
  Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
71
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualStateError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualStateError; } });
72
+ Object.defineProperty(exports, "InvalidMidnightPositionAccrualTimestampError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionAccrualTimestampError; } });
73
+ Object.defineProperty(exports, "InvalidMidnightPositionLossFactorError", { enumerable: true, get: function () { return morpho_ts_1.InvalidPositionLossFactorError; } });
72
74
  Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
73
75
  Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
74
76
  Object.defineProperty(exports, "RetriesExhaustedError", { enumerable: true, get: function () { return morpho_ts_1.RetriesExhaustedError; } });
@@ -1,6 +1,6 @@
1
- export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
1
+ export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, 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, 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, fetchVaultV2MidnightAdapter, 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,11 +1,12 @@
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.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;
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;
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; } });
9
10
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1Adapter; } });
10
11
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoMarketV1AdapterV2; } });
11
12
  Object.defineProperty(exports, "fetchAccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchAccrualVaultV2MorphoVaultV1Adapter; } });
@@ -29,6 +30,7 @@ Object.defineProperty(exports, "fetchVaultV2Adapter", { enumerable: true, get: f
29
30
  Object.defineProperty(exports, "fetchVaultV2BlueMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BlueMarketPublicAllocatorConfig; } });
30
31
  Object.defineProperty(exports, "fetchVaultV2BluePublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2BluePublicAllocatorConfig; } });
31
32
  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; } });
32
34
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1Adapter; } });
33
35
  Object.defineProperty(exports, "fetchVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoMarketV1AdapterV2; } });
34
36
  Object.defineProperty(exports, "fetchVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2MorphoVaultV1Adapter; } });
@@ -146,41 +146,9 @@ function validateVaultV2DeadShares(vault, path = []) {
146
146
  observed: priceNumerator,
147
147
  required: priceDenominator + 1n,
148
148
  });
149
- const capOf = (id, adapter) => {
150
- const cap = absoluteCaps[id];
151
- if (cap == null)
152
- throw new error_js_1.MissingDeadSharesDataError({
153
- entity: [...entity, adapter],
154
- field: "absoluteCaps",
155
- });
156
- return cap;
157
- };
158
149
  for (const adapter of vault.accrualAdapters) {
159
- if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
160
- const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
161
- if (capOf(id, adapter.address) > 0n)
162
- validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
163
- }
164
- else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter) {
165
- for (const { market } of adapter.positions) {
166
- const id = blue_sdk_1.VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
167
- if (capOf(id, adapter.address) > 0n)
168
- validateBlueMarketDeadShares(market, entity);
169
- }
170
- }
171
- else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2) {
172
- for (const market of adapter.markets) {
173
- const id = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
174
- if (capOf(id, adapter.address) > 0n)
175
- validateBlueMarketDeadShares(market, entity);
176
- }
177
- }
178
- else {
179
- throw new error_js_1.MissingDeadSharesDataError({
180
- entity: [...entity, adapter.address],
181
- field: "adapter",
182
- });
183
- }
150
+ // Reject incomplete or underfunded adapter snapshots before checking liquidity.
151
+ assertAdapterDeadShares(adapter, { absoluteCaps, entity });
184
152
  }
185
153
  // Deposits are allocated to the liquidity market, so the snapshot must hold it even when it
186
154
  // has no allocation yet (the adapters only list markets they currently supply to).
@@ -199,3 +167,56 @@ function validateVaultV2DeadShares(vault, path = []) {
199
167
  field: "liquidityMarket",
200
168
  });
201
169
  }
170
+ /** Reads a fetched adapter cap before applying the dead-share rule. @internal */
171
+ function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
172
+ const cap = absoluteCaps[id];
173
+ if (cap == null)
174
+ throw new error_js_1.MissingDeadSharesDataError({
175
+ entity: [...entity, adapter],
176
+ field: "absoluteCaps",
177
+ });
178
+ return cap;
179
+ }
180
+ /** Checks the currently allocated positions of one supported adapter. @internal */
181
+ function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
182
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MidnightAdapter)
183
+ return;
184
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
185
+ const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
186
+ if (getDeadSharesAbsoluteCap(id, {
187
+ absoluteCaps,
188
+ entity,
189
+ adapter: adapter.address,
190
+ }) > 0n)
191
+ validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
192
+ return;
193
+ }
194
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter) {
195
+ for (const { market } of adapter.positions) {
196
+ const id = blue_sdk_1.VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
197
+ if (getDeadSharesAbsoluteCap(id, {
198
+ absoluteCaps,
199
+ entity,
200
+ adapter: adapter.address,
201
+ }) > 0n)
202
+ validateBlueMarketDeadShares(market, entity);
203
+ }
204
+ return;
205
+ }
206
+ if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2) {
207
+ for (const market of adapter.markets) {
208
+ const id = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
209
+ if (getDeadSharesAbsoluteCap(id, {
210
+ absoluteCaps,
211
+ entity,
212
+ adapter: adapter.address,
213
+ }) > 0n)
214
+ validateBlueMarketDeadShares(market, entity);
215
+ }
216
+ return;
217
+ }
218
+ throw new error_js_1.MissingDeadSharesDataError({
219
+ entity: [...entity, adapter.address],
220
+ field: "adapter",
221
+ });
222
+ }
@@ -1,5 +1,13 @@
1
1
  import { type Address, type Hex } from "viem";
2
2
  import type { Metadata } from "../types/index.js";
3
+ /**
4
+ * Replaces a device-clock metadata timestamp with the flow's explicit reference time.
5
+ * Returns the input unchanged when no replacement is needed; never mutates it.
6
+ * @throws {NegativeInputError} when the resolved bigint timestamp is negative.
7
+ * @throws {InputExceedsMaxError} when the resolved bigint timestamp exceeds uint32 seconds.
8
+ * @internal
9
+ */
10
+ export declare function resolveTransactionMetadata(metadata: Metadata | undefined, now?: bigint): Metadata | undefined;
3
11
  /**
4
12
  * Adds metadata to a transaction object by concatenating additional
5
13
  * hex-encoded data to the transaction's `data` field. The additional
@@ -29,17 +37,21 @@ import type { Metadata } from "../types/index.js";
29
37
  * @returns The same `tx` object when `data` is missing, an empty string, or
30
38
  * canonical empty calldata (`"0x"`); otherwise, a new transaction object
31
39
  * with `data` containing any appended metadata. The input is never mutated.
40
+ * @throws {NegativeInputError} when an explicit bigint timestamp is negative.
41
+ * @throws {InputExceedsMaxError} when an explicit bigint timestamp exceeds uint32 seconds.
32
42
  * @example
33
43
  * ```ts
34
44
  * import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
35
45
  * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
36
- * import type { Address, Hex } from "viem";
46
+ * import { type Address, createPublicClient, type Hex, http } from "viem";
37
47
  * import { mainnet } from "viem/chains";
38
48
  *
49
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
39
50
  * const { blue } = getChainAddresses(mainnet.id);
40
51
  * const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
52
+ * const { timestamp } = await client.getBlock();
41
53
  * const result: { to: Address; value: bigint; data: Hex } =
42
- * addTransactionMetadata(tx, { origin: "deadbeef", timestamp: true });
54
+ * addTransactionMetadata(tx, { origin: "deadbeef", timestamp });
43
55
  * // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
44
56
  * ```
45
57
  */
@@ -1,8 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTransactionMetadata = resolveTransactionMetadata;
3
4
  exports.addTransactionMetadata = addTransactionMetadata;
4
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
6
  const viem_1 = require("viem");
7
+ const error_js_1 = require("../types/error.js");
8
+ const MAX_METADATA_TIMESTAMP = (1n << 32n) - 1n;
9
+ function validateMetadataTimestamp(timestamp) {
10
+ if (typeof timestamp !== "bigint")
11
+ return;
12
+ if (timestamp < 0n)
13
+ throw new error_js_1.NegativeInputError("metadata.timestamp", timestamp);
14
+ if (timestamp > MAX_METADATA_TIMESTAMP) {
15
+ throw new error_js_1.InputExceedsMaxError({
16
+ field: "metadata.timestamp",
17
+ value: timestamp,
18
+ max: MAX_METADATA_TIMESTAMP,
19
+ });
20
+ }
21
+ }
22
+ /**
23
+ * Replaces a device-clock metadata timestamp with the flow's explicit reference time.
24
+ * Returns the input unchanged when no replacement is needed; never mutates it.
25
+ * @throws {NegativeInputError} when the resolved bigint timestamp is negative.
26
+ * @throws {InputExceedsMaxError} when the resolved bigint timestamp exceeds uint32 seconds.
27
+ * @internal
28
+ */
29
+ function resolveTransactionMetadata(metadata, now) {
30
+ const resolved = metadata?.timestamp === true && now != null
31
+ ? { ...metadata, timestamp: now }
32
+ : metadata;
33
+ validateMetadataTimestamp(resolved?.timestamp);
34
+ return resolved;
35
+ }
6
36
  /**
7
37
  * Adds metadata to a transaction object by concatenating additional
8
38
  * hex-encoded data to the transaction's `data` field. The additional
@@ -32,27 +62,32 @@ const viem_1 = require("viem");
32
62
  * @returns The same `tx` object when `data` is missing, an empty string, or
33
63
  * canonical empty calldata (`"0x"`); otherwise, a new transaction object
34
64
  * with `data` containing any appended metadata. The input is never mutated.
65
+ * @throws {NegativeInputError} when an explicit bigint timestamp is negative.
66
+ * @throws {InputExceedsMaxError} when an explicit bigint timestamp exceeds uint32 seconds.
35
67
  * @example
36
68
  * ```ts
37
69
  * import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
38
70
  * import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
39
- * import type { Address, Hex } from "viem";
71
+ * import { type Address, createPublicClient, type Hex, http } from "viem";
40
72
  * import { mainnet } from "viem/chains";
41
73
  *
74
+ * const client = createPublicClient({ chain: mainnet, transport: http() });
42
75
  * const { blue } = getChainAddresses(mainnet.id);
43
76
  * const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
77
+ * const { timestamp } = await client.getBlock();
44
78
  * const result: { to: Address; value: bigint; data: Hex } =
45
- * addTransactionMetadata(tx, { origin: "deadbeef", timestamp: true });
79
+ * addTransactionMetadata(tx, { origin: "deadbeef", timestamp });
46
80
  * // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
47
81
  * ```
48
82
  */
49
83
  function addTransactionMetadata(tx, metadata) {
84
+ validateMetadataTimestamp(metadata.timestamp);
50
85
  const { data, ..._tx } = tx;
51
86
  if (!data || data === "0x")
52
87
  return tx;
53
88
  const concatItems = [data];
54
- if (metadata.timestamp) {
55
- concatItems.push((0, viem_1.numberToHex)(morpho_ts_1.Time.timestamp(), { size: 4 }));
89
+ if (metadata.timestamp === true || typeof metadata.timestamp === "bigint") {
90
+ concatItems.push((0, viem_1.numberToHex)(metadata.timestamp === true ? morpho_ts_1.Time.timestamp() : metadata.timestamp, { size: 4 }));
56
91
  }
57
92
  try {
58
93
  // Strip a leading "0x" / "0X" case-insensitively so callers can pass
@@ -97,6 +97,39 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
97
97
  });
98
98
  if (plan.withdrawnAssets <= 0n)
99
99
  return undefined;
100
+ const defaultMinSharePriceE27 = computePreviewMinSharePrice(vaultData, {
101
+ timestamp,
102
+ feeProjectionTimestamp,
103
+ userAddress,
104
+ plan,
105
+ });
106
+ if (defaultMinSharePriceE27 == null ||
107
+ defaultMinSharePriceE27 <= 0n ||
108
+ defaultMinSharePriceE27 > viem_1.maxUint256) {
109
+ return undefined;
110
+ }
111
+ const referralFeeAssets = blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, blue_sdk_1.MathLib.WAD);
112
+ const selfPaidReferralFee = userAddress != null &&
113
+ referralFeeRecipient != null &&
114
+ (0, viem_1.isAddressEqual)(userAddress, referralFeeRecipient);
115
+ return {
116
+ maxExitAssets: capacity.maxExitAssets,
117
+ exitAssets,
118
+ remainingExitAssets: requestedExitAssets - exitAssets,
119
+ assetsToWithdraw: plan.assetsToWithdraw,
120
+ assetsToDeallocate: plan.assetsToDeallocate,
121
+ // The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
122
+ // bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
123
+ // break reconciliation with `exitAssets` for a multi-market exit.
124
+ penaltyAssets: blue_sdk_1.MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
125
+ referralFeeAssets,
126
+ netAssets: selfPaidReferralFee
127
+ ? plan.withdrawnAssets
128
+ : plan.withdrawnAssets - referralFeeAssets,
129
+ };
130
+ }
131
+ /** Computes the preview's fee-adjusted floor, excluding fee mints that consume the burn. @internal */
132
+ function computePreviewMinSharePrice(vaultData, { timestamp, feeProjectionTimestamp, userAddress, plan, }) {
100
133
  // Mirror the entity's zero-floor guard. `forceWithdraw()` derives its slippage floor from
101
134
  // `withdrawnAssets / sharesBurnt` and rejects an exit whose realized share price rounds down to
102
135
  // zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
@@ -149,26 +182,5 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
149
182
  const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
150
183
  ? blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
151
184
  : 0n;
152
- if (defaultMinSharePriceE27 <= 0n || defaultMinSharePriceE27 > viem_1.maxUint256) {
153
- return undefined;
154
- }
155
- const referralFeeAssets = blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, blue_sdk_1.MathLib.WAD);
156
- const selfPaidReferralFee = userAddress != null &&
157
- referralFeeRecipient != null &&
158
- (0, viem_1.isAddressEqual)(userAddress, referralFeeRecipient);
159
- return {
160
- maxExitAssets: capacity.maxExitAssets,
161
- exitAssets,
162
- remainingExitAssets: requestedExitAssets - exitAssets,
163
- assetsToWithdraw: plan.assetsToWithdraw,
164
- assetsToDeallocate: plan.assetsToDeallocate,
165
- // The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
166
- // bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
167
- // break reconciliation with `exitAssets` for a multi-market exit.
168
- penaltyAssets: blue_sdk_1.MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
169
- referralFeeAssets,
170
- netAssets: selfPaidReferralFee
171
- ? plan.withdrawnAssets
172
- : plan.withdrawnAssets - referralFeeAssets,
173
- };
185
+ return defaultMinSharePriceE27;
174
186
  }
@@ -49,7 +49,13 @@ function previewVaultV2InKindRedeem(vaultData, params) {
49
49
  .toSupplyAssets(adapter.supplyShares[market.id] ?? 0n),
50
50
  }))
51
51
  .filter(({ allocationAssets }) => allocationAssets > 0n)
52
- .toSorted(({ allocationAssets: a }, { allocationAssets: b }) => a === b ? 0 : a > b ? -1 : 1);
52
+ .toSorted(({ allocationAssets: a }, { allocationAssets: b }) => {
53
+ if (a === b)
54
+ return 0;
55
+ if (a > b)
56
+ return -1;
57
+ return 1;
58
+ });
53
59
  return allocations.flatMap(({ market, allocationAssets }) => {
54
60
  const maxExitAssets = availableIdleAssets +
55
61
  blue_sdk_1.MathLib.wMulUp(allocationAssets + 1n, blue_sdk_1.MathLib.WAD + penalty) -
@@ -597,67 +597,11 @@ exports.validateRepayShares = validateRepayShares;
597
597
  const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
598
598
  const penaltyByVault = new Map();
599
599
  for (const reallocation of reallocations) {
600
- // Reject non-object entries and Vault V1-shaped entries (which carry
601
- // `withdrawals`/`fee`) with a typed, instructive error instead of a raw
602
- // TypeError or a misleading `to.adapter` address error.
603
- if (typeof reallocation !== "object" ||
604
- reallocation === null ||
605
- "withdrawals" in reallocation ||
606
- "fee" in reallocation) {
607
- throw new index_js_1.InvalidVaultV2BlueReallocationShapeError();
608
- }
609
- if (typeof reallocation.vault !== "string" ||
610
- !(0, viem_1.isAddress)(reallocation.vault)) {
611
- throw new index_js_1.InvalidReallocationAddressError("vault");
612
- }
613
- if (reallocation.to == null ||
614
- typeof reallocation.to.adapter !== "string" ||
615
- !(0, viem_1.isAddress)(reallocation.to.adapter)) {
616
- throw new index_js_1.InvalidReallocationAddressError("to.adapter");
617
- }
618
- const source = reallocation.from;
619
- if (source == null) {
620
- throw new index_js_1.InvalidReallocationSourceTypeError(undefined);
621
- }
622
- const sourceType = source.type;
623
- if (sourceType !== "market" && sourceType !== "idle") {
624
- throw new index_js_1.InvalidReallocationSourceTypeError(sourceType);
625
- }
626
- let sourceMarketId;
627
- if (source.type === "market") {
628
- if (typeof source.adapter !== "string" || !(0, viem_1.isAddress)(source.adapter)) {
629
- throw new index_js_1.InvalidReallocationAddressError("from.adapter");
630
- }
631
- if (source.marketParams == null ||
632
- !(0, viem_1.isAddress)(source.marketParams.loanToken) ||
633
- !(0, viem_1.isAddress)(source.marketParams.collateralToken) ||
634
- !(0, viem_1.isAddress)(source.marketParams.oracle) ||
635
- !(0, viem_1.isAddress)(source.marketParams.irm) ||
636
- typeof source.marketParams.lltv !== "bigint") {
637
- throw new index_js_1.InvalidReallocationSourceTypeError("market", "marketParams");
638
- }
639
- sourceMarketId = blue_sdk_1.MarketUtils.getMarketId(source.marketParams);
640
- }
641
- if (reallocation.penalty < 0n) {
642
- throw new index_js_1.NegativeInputError("reallocation.penalty", reallocation.penalty);
643
- }
644
- if (reallocation.penalty > constant_js_1.MAX_REALLOCATION_PENALTY) {
645
- throw new index_js_1.InputExceedsMaxError({
646
- field: "reallocation.penalty",
647
- value: reallocation.penalty,
648
- max: constant_js_1.MAX_REALLOCATION_PENALTY,
649
- });
650
- }
651
- if (reallocation.assets <= 0n) {
652
- throw new index_js_1.NonPositiveInputError("reallocation.assets", reallocation.assets);
653
- }
654
- if (reallocation.assets > viem_1.maxUint128) {
655
- throw new index_js_1.InputExceedsMaxError({
656
- field: "reallocation.assets",
657
- value: reallocation.assets,
658
- max: viem_1.maxUint128,
659
- });
660
- }
600
+ // Validate shape before source and amounts so malformed entries keep their original error.
601
+ assertReallocationShape(reallocation);
602
+ const sourceMarketId = resolveReallocationSourceMarketId(reallocation);
603
+ // Reject out-of-range amounts before comparing penalties across vault legs.
604
+ assertReallocationAmounts(reallocation);
661
605
  const penaltyKey = reallocation.vault.toLowerCase();
662
606
  const expectedPenalty = penaltyByVault.get(penaltyKey);
663
607
  if (expectedPenalty !== undefined &&
@@ -772,3 +716,74 @@ const validateWithdrawShares = (params) => {
772
716
  }
773
717
  };
774
718
  exports.validateWithdrawShares = validateWithdrawShares;
719
+ /** Rejects malformed reallocation entries before reading source or amount fields. @internal */
720
+ function assertReallocationShape(reallocation) {
721
+ // Reject non-object entries and Vault V1-shaped entries (which carry
722
+ // `withdrawals`/`fee`) with a typed, instructive error instead of a raw
723
+ // TypeError or a misleading `to.adapter` address error.
724
+ if (typeof reallocation !== "object" ||
725
+ reallocation === null ||
726
+ "withdrawals" in reallocation ||
727
+ "fee" in reallocation) {
728
+ throw new index_js_1.InvalidVaultV2BlueReallocationShapeError();
729
+ }
730
+ if (typeof reallocation.vault !== "string" ||
731
+ !(0, viem_1.isAddress)(reallocation.vault)) {
732
+ throw new index_js_1.InvalidReallocationAddressError("vault");
733
+ }
734
+ if (reallocation.to == null ||
735
+ typeof reallocation.to.adapter !== "string" ||
736
+ !(0, viem_1.isAddress)(reallocation.to.adapter)) {
737
+ throw new index_js_1.InvalidReallocationAddressError("to.adapter");
738
+ }
739
+ }
740
+ /** Validates the reallocation source and resolves its market identifier. @internal */
741
+ function resolveReallocationSourceMarketId(reallocation) {
742
+ const source = reallocation.from;
743
+ if (source == null) {
744
+ throw new index_js_1.InvalidReallocationSourceTypeError(undefined);
745
+ }
746
+ const sourceType = source.type;
747
+ if (sourceType !== "market" && sourceType !== "idle") {
748
+ throw new index_js_1.InvalidReallocationSourceTypeError(sourceType);
749
+ }
750
+ let sourceMarketId;
751
+ if (source.type === "market") {
752
+ if (typeof source.adapter !== "string" || !(0, viem_1.isAddress)(source.adapter)) {
753
+ throw new index_js_1.InvalidReallocationAddressError("from.adapter");
754
+ }
755
+ if (source.marketParams == null ||
756
+ !(0, viem_1.isAddress)(source.marketParams.loanToken) ||
757
+ !(0, viem_1.isAddress)(source.marketParams.collateralToken) ||
758
+ !(0, viem_1.isAddress)(source.marketParams.oracle) ||
759
+ !(0, viem_1.isAddress)(source.marketParams.irm) ||
760
+ typeof source.marketParams.lltv !== "bigint") {
761
+ throw new index_js_1.InvalidReallocationSourceTypeError("market", "marketParams");
762
+ }
763
+ sourceMarketId = blue_sdk_1.MarketUtils.getMarketId(source.marketParams);
764
+ }
765
+ return sourceMarketId;
766
+ }
767
+ /** Checks penalty and asset amounts against the allocator's ABI bounds. @internal */
768
+ function assertReallocationAmounts(reallocation) {
769
+ if (reallocation.penalty < 0n) {
770
+ throw new index_js_1.NegativeInputError("reallocation.penalty", reallocation.penalty);
771
+ }
772
+ if (reallocation.penalty > constant_js_1.MAX_REALLOCATION_PENALTY) {
773
+ throw new index_js_1.InputExceedsMaxError({
774
+ field: "reallocation.penalty",
775
+ value: reallocation.penalty,
776
+ max: constant_js_1.MAX_REALLOCATION_PENALTY,
777
+ });
778
+ }
779
+ if (reallocation.assets <= 0n) {
780
+ throw new index_js_1.NonPositiveInputError("reallocation.assets", reallocation.assets);
781
+ }
782
+ if (reallocation.assets > viem_1.maxUint128) {
783
+ throw new index_js_1.InputExceedsMaxError({
784
+ field: "reallocation.assets",
785
+ value: reallocation.assets,
786
+ max: viem_1.maxUint128,
787
+ });
788
+ }
789
+ }