@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.
- package/MIGRATION-v9-to-v10.md +114 -0
- package/README.md +5 -1
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +107 -0
- package/lib/cjs/actions/midnight/index.d.ts +1 -0
- package/lib/cjs/actions/midnight/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +1 -1
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeLend.js +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +1 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +34 -28
- package/lib/cjs/entities/blue/blue.js +99 -73
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
- package/lib/cjs/entities/midnight/deadline.js +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
- package/lib/cjs/entities/midnight/midnight.js +144 -131
- package/lib/cjs/entities/midnight/publication.d.ts +2 -0
- package/lib/cjs/entities/midnight/publication.js +126 -100
- package/lib/cjs/entities/midnight/types.d.ts +4 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +17 -17
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +83 -57
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +50 -24
- package/lib/cjs/entities/vaultV2/vaultV2.js +166 -90
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +17 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1410 -806
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/deadShares.js +55 -34
- package/lib/cjs/helpers/metadata.d.ts +14 -2
- package/lib/cjs/helpers/metadata.js +39 -4
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +34 -22
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +7 -1
- package/lib/cjs/helpers/validate.js +76 -61
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +154 -103
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +31 -20
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/transactionPlan/plan.js +6 -3
- package/lib/cjs/transactionPlan/serde.js +7 -7
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +6 -4
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +5 -3
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +6 -4
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +5 -3
- package/lib/cjs/types/action.d.ts +26 -2
- package/lib/cjs/types/action.js +1 -1
- package/lib/cjs/types/error.js +11 -5
- package/lib/cjs/types/metadata.d.ts +12 -2
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/esm/actions/midnight/cancelOffers.js +103 -0
- package/lib/esm/actions/midnight/index.d.ts +1 -0
- package/lib/esm/actions/midnight/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
- package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/takeBorrow.js +1 -1
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
- package/lib/esm/actions/midnight/takeLend.js +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +1 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +34 -28
- package/lib/esm/entities/blue/blue.js +99 -73
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/deadline.d.ts +2 -2
- package/lib/esm/entities/midnight/deadline.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +49 -51
- package/lib/esm/entities/midnight/midnight.js +145 -132
- package/lib/esm/entities/midnight/publication.d.ts +2 -0
- package/lib/esm/entities/midnight/publication.js +126 -100
- package/lib/esm/entities/midnight/types.d.ts +4 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +17 -17
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +83 -57
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +50 -24
- package/lib/esm/entities/vaultV2/vaultV2.js +166 -90
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +17 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1410 -806
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +56 -35
- package/lib/esm/helpers/metadata.d.ts +14 -2
- package/lib/esm/helpers/metadata.js +38 -4
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +34 -22
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +7 -1
- package/lib/esm/helpers/validate.js +76 -61
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +153 -102
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +31 -20
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/transactionPlan/plan.js +6 -3
- package/lib/esm/transactionPlan/serde.js +7 -7
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +6 -4
- package/lib/esm/transactionPlan/vaultv2/deposit.js +5 -3
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +6 -4
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +5 -3
- package/lib/esm/types/action.d.ts +26 -2
- package/lib/esm/types/action.js +1 -1
- package/lib/esm/types/error.js +11 -5
- package/lib/esm/types/metadata.d.ts +12 -2
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +8 -7
package/lib/esm/errors.d.ts
CHANGED
|
@@ -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,
|
|
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/esm/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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,
|
|
6
|
-
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
|
|
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
|
+
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/esm/fetch.d.ts
CHANGED
|
@@ -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/esm/fetch.js
CHANGED
|
@@ -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";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { InsufficientDeadSharesError, MissingDeadSharesDataError, } from "../types/error.js";
|
|
3
3
|
import { MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS } from "./constant.js";
|
|
4
4
|
/**
|
|
@@ -141,41 +141,9 @@ export function validateVaultV2DeadShares(vault, path = []) {
|
|
|
141
141
|
observed: priceNumerator,
|
|
142
142
|
required: priceDenominator + 1n,
|
|
143
143
|
});
|
|
144
|
-
const capOf = (id, adapter) => {
|
|
145
|
-
const cap = absoluteCaps[id];
|
|
146
|
-
if (cap == null)
|
|
147
|
-
throw new MissingDeadSharesDataError({
|
|
148
|
-
entity: [...entity, adapter],
|
|
149
|
-
field: "absoluteCaps",
|
|
150
|
-
});
|
|
151
|
-
return cap;
|
|
152
|
-
};
|
|
153
144
|
for (const adapter of vault.accrualAdapters) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (capOf(id, adapter.address) > 0n)
|
|
157
|
-
validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
|
|
158
|
-
}
|
|
159
|
-
else if (adapter instanceof AccrualVaultV2MorphoMarketV1Adapter) {
|
|
160
|
-
for (const { market } of adapter.positions) {
|
|
161
|
-
const id = VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
|
|
162
|
-
if (capOf(id, adapter.address) > 0n)
|
|
163
|
-
validateBlueMarketDeadShares(market, entity);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else if (adapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2) {
|
|
167
|
-
for (const market of adapter.markets) {
|
|
168
|
-
const id = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
|
|
169
|
-
if (capOf(id, adapter.address) > 0n)
|
|
170
|
-
validateBlueMarketDeadShares(market, entity);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
throw new MissingDeadSharesDataError({
|
|
175
|
-
entity: [...entity, adapter.address],
|
|
176
|
-
field: "adapter",
|
|
177
|
-
});
|
|
178
|
-
}
|
|
145
|
+
// Reject incomplete or underfunded adapter snapshots before checking liquidity.
|
|
146
|
+
assertAdapterDeadShares(adapter, { absoluteCaps, entity });
|
|
179
147
|
}
|
|
180
148
|
// Deposits are allocated to the liquidity market, so the snapshot must hold it even when it
|
|
181
149
|
// has no allocation yet (the adapters only list markets they currently supply to).
|
|
@@ -194,3 +162,56 @@ export function validateVaultV2DeadShares(vault, path = []) {
|
|
|
194
162
|
field: "liquidityMarket",
|
|
195
163
|
});
|
|
196
164
|
}
|
|
165
|
+
/** Reads a fetched adapter cap before applying the dead-share rule. @internal */
|
|
166
|
+
function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
|
|
167
|
+
const cap = absoluteCaps[id];
|
|
168
|
+
if (cap == null)
|
|
169
|
+
throw new MissingDeadSharesDataError({
|
|
170
|
+
entity: [...entity, adapter],
|
|
171
|
+
field: "absoluteCaps",
|
|
172
|
+
});
|
|
173
|
+
return cap;
|
|
174
|
+
}
|
|
175
|
+
/** Checks the currently allocated positions of one supported adapter. @internal */
|
|
176
|
+
function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
|
|
177
|
+
if (adapter instanceof AccrualVaultV2MidnightAdapter)
|
|
178
|
+
return;
|
|
179
|
+
if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter) {
|
|
180
|
+
const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
|
|
181
|
+
if (getDeadSharesAbsoluteCap(id, {
|
|
182
|
+
absoluteCaps,
|
|
183
|
+
entity,
|
|
184
|
+
adapter: adapter.address,
|
|
185
|
+
}) > 0n)
|
|
186
|
+
validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (adapter instanceof AccrualVaultV2MorphoMarketV1Adapter) {
|
|
190
|
+
for (const { market } of adapter.positions) {
|
|
191
|
+
const id = VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
|
|
192
|
+
if (getDeadSharesAbsoluteCap(id, {
|
|
193
|
+
absoluteCaps,
|
|
194
|
+
entity,
|
|
195
|
+
adapter: adapter.address,
|
|
196
|
+
}) > 0n)
|
|
197
|
+
validateBlueMarketDeadShares(market, entity);
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (adapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2) {
|
|
202
|
+
for (const market of adapter.markets) {
|
|
203
|
+
const id = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
|
|
204
|
+
if (getDeadSharesAbsoluteCap(id, {
|
|
205
|
+
absoluteCaps,
|
|
206
|
+
entity,
|
|
207
|
+
adapter: adapter.address,
|
|
208
|
+
}) > 0n)
|
|
209
|
+
validateBlueMarketDeadShares(market, entity);
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
throw new MissingDeadSharesDataError({
|
|
214
|
+
entity: [...entity, adapter.address],
|
|
215
|
+
field: "adapter",
|
|
216
|
+
});
|
|
217
|
+
}
|
|
@@ -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
|
|
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
|
|
54
|
+
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp });
|
|
43
55
|
* // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
|
|
44
56
|
* ```
|
|
45
57
|
*/
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import { Time } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { concatHex, isHex, numberToHex } from "viem";
|
|
3
|
+
import { InputExceedsMaxError, NegativeInputError } from "../types/error.js";
|
|
4
|
+
const MAX_METADATA_TIMESTAMP = (1n << 32n) - 1n;
|
|
5
|
+
function validateMetadataTimestamp(timestamp) {
|
|
6
|
+
if (typeof timestamp !== "bigint")
|
|
7
|
+
return;
|
|
8
|
+
if (timestamp < 0n)
|
|
9
|
+
throw new NegativeInputError("metadata.timestamp", timestamp);
|
|
10
|
+
if (timestamp > MAX_METADATA_TIMESTAMP) {
|
|
11
|
+
throw new InputExceedsMaxError({
|
|
12
|
+
field: "metadata.timestamp",
|
|
13
|
+
value: timestamp,
|
|
14
|
+
max: MAX_METADATA_TIMESTAMP,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Replaces a device-clock metadata timestamp with the flow's explicit reference time.
|
|
20
|
+
* Returns the input unchanged when no replacement is needed; never mutates it.
|
|
21
|
+
* @throws {NegativeInputError} when the resolved bigint timestamp is negative.
|
|
22
|
+
* @throws {InputExceedsMaxError} when the resolved bigint timestamp exceeds uint32 seconds.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function resolveTransactionMetadata(metadata, now) {
|
|
26
|
+
const resolved = metadata?.timestamp === true && now != null
|
|
27
|
+
? { ...metadata, timestamp: now }
|
|
28
|
+
: metadata;
|
|
29
|
+
validateMetadataTimestamp(resolved?.timestamp);
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
3
32
|
/**
|
|
4
33
|
* Adds metadata to a transaction object by concatenating additional
|
|
5
34
|
* hex-encoded data to the transaction's `data` field. The additional
|
|
@@ -29,27 +58,32 @@ import { concatHex, isHex, numberToHex } from "viem";
|
|
|
29
58
|
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
59
|
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
60
|
* with `data` containing any appended metadata. The input is never mutated.
|
|
61
|
+
* @throws {NegativeInputError} when an explicit bigint timestamp is negative.
|
|
62
|
+
* @throws {InputExceedsMaxError} when an explicit bigint timestamp exceeds uint32 seconds.
|
|
32
63
|
* @example
|
|
33
64
|
* ```ts
|
|
34
65
|
* import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
|
|
35
66
|
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
36
|
-
* import type
|
|
67
|
+
* import { type Address, createPublicClient, type Hex, http } from "viem";
|
|
37
68
|
* import { mainnet } from "viem/chains";
|
|
38
69
|
*
|
|
70
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
39
71
|
* const { blue } = getChainAddresses(mainnet.id);
|
|
40
72
|
* const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
|
|
73
|
+
* const { timestamp } = await client.getBlock();
|
|
41
74
|
* const result: { to: Address; value: bigint; data: Hex } =
|
|
42
|
-
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp
|
|
75
|
+
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp });
|
|
43
76
|
* // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
|
|
44
77
|
* ```
|
|
45
78
|
*/
|
|
46
79
|
export function addTransactionMetadata(tx, metadata) {
|
|
80
|
+
validateMetadataTimestamp(metadata.timestamp);
|
|
47
81
|
const { data, ..._tx } = tx;
|
|
48
82
|
if (!data || data === "0x")
|
|
49
83
|
return tx;
|
|
50
84
|
const concatItems = [data];
|
|
51
|
-
if (metadata.timestamp) {
|
|
52
|
-
concatItems.push(numberToHex(Time.timestamp(), { size: 4 }));
|
|
85
|
+
if (metadata.timestamp === true || typeof metadata.timestamp === "bigint") {
|
|
86
|
+
concatItems.push(numberToHex(metadata.timestamp === true ? Time.timestamp() : metadata.timestamp, { size: 4 }));
|
|
53
87
|
}
|
|
54
88
|
try {
|
|
55
89
|
// Strip a leading "0x" / "0X" case-insensitively so callers can pass
|
|
@@ -94,6 +94,39 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
94
94
|
});
|
|
95
95
|
if (plan.withdrawnAssets <= 0n)
|
|
96
96
|
return undefined;
|
|
97
|
+
const defaultMinSharePriceE27 = computePreviewMinSharePrice(vaultData, {
|
|
98
|
+
timestamp,
|
|
99
|
+
feeProjectionTimestamp,
|
|
100
|
+
userAddress,
|
|
101
|
+
plan,
|
|
102
|
+
});
|
|
103
|
+
if (defaultMinSharePriceE27 == null ||
|
|
104
|
+
defaultMinSharePriceE27 <= 0n ||
|
|
105
|
+
defaultMinSharePriceE27 > maxUint256) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const referralFeeAssets = MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, MathLib.WAD);
|
|
109
|
+
const selfPaidReferralFee = userAddress != null &&
|
|
110
|
+
referralFeeRecipient != null &&
|
|
111
|
+
isAddressEqual(userAddress, referralFeeRecipient);
|
|
112
|
+
return {
|
|
113
|
+
maxExitAssets: capacity.maxExitAssets,
|
|
114
|
+
exitAssets,
|
|
115
|
+
remainingExitAssets: requestedExitAssets - exitAssets,
|
|
116
|
+
assetsToWithdraw: plan.assetsToWithdraw,
|
|
117
|
+
assetsToDeallocate: plan.assetsToDeallocate,
|
|
118
|
+
// The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
|
|
119
|
+
// bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
|
|
120
|
+
// break reconciliation with `exitAssets` for a multi-market exit.
|
|
121
|
+
penaltyAssets: MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
|
|
122
|
+
referralFeeAssets,
|
|
123
|
+
netAssets: selfPaidReferralFee
|
|
124
|
+
? plan.withdrawnAssets
|
|
125
|
+
: plan.withdrawnAssets - referralFeeAssets,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** Computes the preview's fee-adjusted floor, excluding fee mints that consume the burn. @internal */
|
|
129
|
+
function computePreviewMinSharePrice(vaultData, { timestamp, feeProjectionTimestamp, userAddress, plan, }) {
|
|
97
130
|
// Mirror the entity's zero-floor guard. `forceWithdraw()` derives its slippage floor from
|
|
98
131
|
// `withdrawnAssets / sharesBurnt` and rejects an exit whose realized share price rounds down to
|
|
99
132
|
// zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
|
|
@@ -146,26 +179,5 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
146
179
|
const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
|
|
147
180
|
? MathLib.mulDivDown(plan.withdrawnAssets, MathLib.wToRay(MathLib.WAD - DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
|
|
148
181
|
: 0n;
|
|
149
|
-
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
const referralFeeAssets = MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, MathLib.WAD);
|
|
153
|
-
const selfPaidReferralFee = userAddress != null &&
|
|
154
|
-
referralFeeRecipient != null &&
|
|
155
|
-
isAddressEqual(userAddress, referralFeeRecipient);
|
|
156
|
-
return {
|
|
157
|
-
maxExitAssets: capacity.maxExitAssets,
|
|
158
|
-
exitAssets,
|
|
159
|
-
remainingExitAssets: requestedExitAssets - exitAssets,
|
|
160
|
-
assetsToWithdraw: plan.assetsToWithdraw,
|
|
161
|
-
assetsToDeallocate: plan.assetsToDeallocate,
|
|
162
|
-
// The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
|
|
163
|
-
// bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
|
|
164
|
-
// break reconciliation with `exitAssets` for a multi-market exit.
|
|
165
|
-
penaltyAssets: MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
|
|
166
|
-
referralFeeAssets,
|
|
167
|
-
netAssets: selfPaidReferralFee
|
|
168
|
-
? plan.withdrawnAssets
|
|
169
|
-
: plan.withdrawnAssets - referralFeeAssets,
|
|
170
|
-
};
|
|
182
|
+
return defaultMinSharePriceE27;
|
|
171
183
|
}
|
|
@@ -46,7 +46,13 @@ export function previewVaultV2InKindRedeem(vaultData, params) {
|
|
|
46
46
|
.toSupplyAssets(adapter.supplyShares[market.id] ?? 0n),
|
|
47
47
|
}))
|
|
48
48
|
.filter(({ allocationAssets }) => allocationAssets > 0n)
|
|
49
|
-
.toSorted(({ allocationAssets: a }, { allocationAssets: b }) =>
|
|
49
|
+
.toSorted(({ allocationAssets: a }, { allocationAssets: b }) => {
|
|
50
|
+
if (a === b)
|
|
51
|
+
return 0;
|
|
52
|
+
if (a > b)
|
|
53
|
+
return -1;
|
|
54
|
+
return 1;
|
|
55
|
+
});
|
|
50
56
|
return allocations.flatMap(({ market, allocationAssets }) => {
|
|
51
57
|
const maxExitAssets = availableIdleAssets +
|
|
52
58
|
MathLib.wMulUp(allocationAssets + 1n, MathLib.WAD + penalty) -
|
|
@@ -578,67 +578,11 @@ export const validateRepayShares = (params) => {
|
|
|
578
578
|
export const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
579
579
|
const penaltyByVault = new Map();
|
|
580
580
|
for (const reallocation of reallocations) {
|
|
581
|
-
//
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
"withdrawals" in reallocation ||
|
|
587
|
-
"fee" in reallocation) {
|
|
588
|
-
throw new InvalidVaultV2BlueReallocationShapeError();
|
|
589
|
-
}
|
|
590
|
-
if (typeof reallocation.vault !== "string" ||
|
|
591
|
-
!isAddress(reallocation.vault)) {
|
|
592
|
-
throw new InvalidReallocationAddressError("vault");
|
|
593
|
-
}
|
|
594
|
-
if (reallocation.to == null ||
|
|
595
|
-
typeof reallocation.to.adapter !== "string" ||
|
|
596
|
-
!isAddress(reallocation.to.adapter)) {
|
|
597
|
-
throw new InvalidReallocationAddressError("to.adapter");
|
|
598
|
-
}
|
|
599
|
-
const source = reallocation.from;
|
|
600
|
-
if (source == null) {
|
|
601
|
-
throw new InvalidReallocationSourceTypeError(undefined);
|
|
602
|
-
}
|
|
603
|
-
const sourceType = source.type;
|
|
604
|
-
if (sourceType !== "market" && sourceType !== "idle") {
|
|
605
|
-
throw new InvalidReallocationSourceTypeError(sourceType);
|
|
606
|
-
}
|
|
607
|
-
let sourceMarketId;
|
|
608
|
-
if (source.type === "market") {
|
|
609
|
-
if (typeof source.adapter !== "string" || !isAddress(source.adapter)) {
|
|
610
|
-
throw new InvalidReallocationAddressError("from.adapter");
|
|
611
|
-
}
|
|
612
|
-
if (source.marketParams == null ||
|
|
613
|
-
!isAddress(source.marketParams.loanToken) ||
|
|
614
|
-
!isAddress(source.marketParams.collateralToken) ||
|
|
615
|
-
!isAddress(source.marketParams.oracle) ||
|
|
616
|
-
!isAddress(source.marketParams.irm) ||
|
|
617
|
-
typeof source.marketParams.lltv !== "bigint") {
|
|
618
|
-
throw new InvalidReallocationSourceTypeError("market", "marketParams");
|
|
619
|
-
}
|
|
620
|
-
sourceMarketId = MarketUtils.getMarketId(source.marketParams);
|
|
621
|
-
}
|
|
622
|
-
if (reallocation.penalty < 0n) {
|
|
623
|
-
throw new NegativeInputError("reallocation.penalty", reallocation.penalty);
|
|
624
|
-
}
|
|
625
|
-
if (reallocation.penalty > MAX_REALLOCATION_PENALTY) {
|
|
626
|
-
throw new InputExceedsMaxError({
|
|
627
|
-
field: "reallocation.penalty",
|
|
628
|
-
value: reallocation.penalty,
|
|
629
|
-
max: MAX_REALLOCATION_PENALTY,
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
if (reallocation.assets <= 0n) {
|
|
633
|
-
throw new NonPositiveInputError("reallocation.assets", reallocation.assets);
|
|
634
|
-
}
|
|
635
|
-
if (reallocation.assets > maxUint128) {
|
|
636
|
-
throw new InputExceedsMaxError({
|
|
637
|
-
field: "reallocation.assets",
|
|
638
|
-
value: reallocation.assets,
|
|
639
|
-
max: maxUint128,
|
|
640
|
-
});
|
|
641
|
-
}
|
|
581
|
+
// Validate shape before source and amounts so malformed entries keep their original error.
|
|
582
|
+
assertReallocationShape(reallocation);
|
|
583
|
+
const sourceMarketId = resolveReallocationSourceMarketId(reallocation);
|
|
584
|
+
// Reject out-of-range amounts before comparing penalties across vault legs.
|
|
585
|
+
assertReallocationAmounts(reallocation);
|
|
642
586
|
const penaltyKey = reallocation.vault.toLowerCase();
|
|
643
587
|
const expectedPenalty = penaltyByVault.get(penaltyKey);
|
|
644
588
|
if (expectedPenalty !== undefined &&
|
|
@@ -749,3 +693,74 @@ export const validateWithdrawShares = (params) => {
|
|
|
749
693
|
});
|
|
750
694
|
}
|
|
751
695
|
};
|
|
696
|
+
/** Rejects malformed reallocation entries before reading source or amount fields. @internal */
|
|
697
|
+
function assertReallocationShape(reallocation) {
|
|
698
|
+
// Reject non-object entries and Vault V1-shaped entries (which carry
|
|
699
|
+
// `withdrawals`/`fee`) with a typed, instructive error instead of a raw
|
|
700
|
+
// TypeError or a misleading `to.adapter` address error.
|
|
701
|
+
if (typeof reallocation !== "object" ||
|
|
702
|
+
reallocation === null ||
|
|
703
|
+
"withdrawals" in reallocation ||
|
|
704
|
+
"fee" in reallocation) {
|
|
705
|
+
throw new InvalidVaultV2BlueReallocationShapeError();
|
|
706
|
+
}
|
|
707
|
+
if (typeof reallocation.vault !== "string" ||
|
|
708
|
+
!isAddress(reallocation.vault)) {
|
|
709
|
+
throw new InvalidReallocationAddressError("vault");
|
|
710
|
+
}
|
|
711
|
+
if (reallocation.to == null ||
|
|
712
|
+
typeof reallocation.to.adapter !== "string" ||
|
|
713
|
+
!isAddress(reallocation.to.adapter)) {
|
|
714
|
+
throw new InvalidReallocationAddressError("to.adapter");
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
/** Validates the reallocation source and resolves its market identifier. @internal */
|
|
718
|
+
function resolveReallocationSourceMarketId(reallocation) {
|
|
719
|
+
const source = reallocation.from;
|
|
720
|
+
if (source == null) {
|
|
721
|
+
throw new InvalidReallocationSourceTypeError(undefined);
|
|
722
|
+
}
|
|
723
|
+
const sourceType = source.type;
|
|
724
|
+
if (sourceType !== "market" && sourceType !== "idle") {
|
|
725
|
+
throw new InvalidReallocationSourceTypeError(sourceType);
|
|
726
|
+
}
|
|
727
|
+
let sourceMarketId;
|
|
728
|
+
if (source.type === "market") {
|
|
729
|
+
if (typeof source.adapter !== "string" || !isAddress(source.adapter)) {
|
|
730
|
+
throw new InvalidReallocationAddressError("from.adapter");
|
|
731
|
+
}
|
|
732
|
+
if (source.marketParams == null ||
|
|
733
|
+
!isAddress(source.marketParams.loanToken) ||
|
|
734
|
+
!isAddress(source.marketParams.collateralToken) ||
|
|
735
|
+
!isAddress(source.marketParams.oracle) ||
|
|
736
|
+
!isAddress(source.marketParams.irm) ||
|
|
737
|
+
typeof source.marketParams.lltv !== "bigint") {
|
|
738
|
+
throw new InvalidReallocationSourceTypeError("market", "marketParams");
|
|
739
|
+
}
|
|
740
|
+
sourceMarketId = MarketUtils.getMarketId(source.marketParams);
|
|
741
|
+
}
|
|
742
|
+
return sourceMarketId;
|
|
743
|
+
}
|
|
744
|
+
/** Checks penalty and asset amounts against the allocator's ABI bounds. @internal */
|
|
745
|
+
function assertReallocationAmounts(reallocation) {
|
|
746
|
+
if (reallocation.penalty < 0n) {
|
|
747
|
+
throw new NegativeInputError("reallocation.penalty", reallocation.penalty);
|
|
748
|
+
}
|
|
749
|
+
if (reallocation.penalty > MAX_REALLOCATION_PENALTY) {
|
|
750
|
+
throw new InputExceedsMaxError({
|
|
751
|
+
field: "reallocation.penalty",
|
|
752
|
+
value: reallocation.penalty,
|
|
753
|
+
max: MAX_REALLOCATION_PENALTY,
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
if (reallocation.assets <= 0n) {
|
|
757
|
+
throw new NonPositiveInputError("reallocation.assets", reallocation.assets);
|
|
758
|
+
}
|
|
759
|
+
if (reallocation.assets > maxUint128) {
|
|
760
|
+
throw new InputExceedsMaxError({
|
|
761
|
+
field: "reallocation.assets",
|
|
762
|
+
value: reallocation.assets,
|
|
763
|
+
max: maxUint128,
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}
|