@morpho-org/morpho-sdk 7.0.0 → 8.1.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-v6-to-v7.md +6 -0
- package/MIGRATION-v7-to-v8.md +290 -0
- package/README.md +11 -6
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +17 -71
- package/lib/cjs/actions/midnight/cancelAndMake.js +41 -29
- package/lib/cjs/actions/midnight/redeem.d.ts +8 -1
- package/lib/cjs/actions/midnight/redeem.js +18 -1
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +24 -2
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +3 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +49 -14
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +18 -5
- package/lib/cjs/actions/midnight/takeBorrow.js +44 -12
- package/lib/cjs/actions/midnight/takeLend.d.ts +10 -5
- package/lib/cjs/actions/midnight/takeLend.js +27 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +51 -27
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +14 -5
- package/lib/cjs/actions/midnight/takeWithdraw.js +40 -9
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +17 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
- package/lib/cjs/actions/requirements/validateClientChainId.d.ts +26 -0
- package/lib/cjs/actions/requirements/validateClientChainId.js +34 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +3 -1
- package/lib/cjs/blue/types.d.ts +1 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +5 -1
- package/lib/cjs/entities/blue/blue.d.ts +109 -27
- package/lib/cjs/entities/blue/blue.js +103 -28
- package/lib/cjs/entities/index.d.ts +1 -1
- package/lib/cjs/entities/midnight/deadline.d.ts +15 -0
- package/lib/cjs/entities/midnight/deadline.js +24 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +432 -74
- package/lib/cjs/entities/midnight/midnight.js +869 -188
- package/lib/cjs/entities/midnight/publication.d.ts +134 -0
- package/lib/cjs/entities/midnight/publication.js +404 -0
- package/lib/cjs/entities/midnight/types.d.ts +26 -5
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +49 -0
- package/lib/cjs/entities/requirements/assertContractCode.js +79 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +45 -18
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +5 -2
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +63 -11
- package/lib/cjs/entities/vaultV1/vaultV1.js +83 -49
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +54 -12
- package/lib/cjs/entities/vaultV2/vaultV2.js +86 -55
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +4 -2
- package/lib/cjs/helpers/constant.d.ts +5 -0
- package/lib/cjs/helpers/constant.js +6 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/validate.d.ts +163 -8
- package/lib/cjs/helpers/validate.js +179 -8
- package/lib/cjs/helpers/validateMidnightBounds.d.ts +47 -0
- package/lib/cjs/helpers/validateMidnightBounds.js +79 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +12 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +144 -0
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +29 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +84 -0
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +231 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/types/action.d.ts +102 -1
- package/lib/cjs/types/action.js +102 -1
- package/lib/cjs/types/error.d.ts +197 -4
- package/lib/cjs/types/error.js +265 -5
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/midnightCancelAndMake.d.ts +70 -0
- package/lib/cjs/types/midnightCancelAndMake.js +2 -0
- package/lib/cjs/types/midnightPublicationError.d.ts +332 -0
- package/lib/cjs/types/midnightPublicationError.js +376 -0
- package/lib/cjs/types.d.ts +1 -1
- package/lib/cjs/utils.d.ts +2 -1
- package/lib/cjs/utils.js +8 -2
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +17 -71
- package/lib/esm/actions/midnight/cancelAndMake.js +42 -30
- package/lib/esm/actions/midnight/redeem.d.ts +8 -1
- package/lib/esm/actions/midnight/redeem.js +18 -1
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +24 -2
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +3 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +52 -17
- package/lib/esm/actions/midnight/takeBorrow.d.ts +18 -5
- package/lib/esm/actions/midnight/takeBorrow.js +47 -15
- package/lib/esm/actions/midnight/takeLend.d.ts +10 -5
- package/lib/esm/actions/midnight/takeLend.js +27 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +52 -28
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +14 -5
- package/lib/esm/actions/midnight/takeWithdraw.js +41 -10
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +13 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +17 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
- package/lib/esm/actions/requirements/validateClientChainId.d.ts +26 -0
- package/lib/esm/actions/requirements/validateClientChainId.js +30 -0
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/types.d.ts +1 -1
- 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 +109 -27
- package/lib/esm/entities/blue/blue.js +104 -29
- package/lib/esm/entities/index.d.ts +1 -1
- package/lib/esm/entities/midnight/deadline.d.ts +15 -0
- package/lib/esm/entities/midnight/deadline.js +20 -0
- package/lib/esm/entities/midnight/midnight.d.ts +432 -74
- package/lib/esm/entities/midnight/midnight.js +870 -189
- package/lib/esm/entities/midnight/publication.d.ts +134 -0
- package/lib/esm/entities/midnight/publication.js +397 -0
- package/lib/esm/entities/midnight/types.d.ts +26 -5
- package/lib/esm/entities/requirements/assertContractCode.d.ts +49 -0
- package/lib/esm/entities/requirements/assertContractCode.js +74 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +47 -20
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +5 -2
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +63 -11
- package/lib/esm/entities/vaultV1/vaultV1.js +85 -51
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +54 -12
- package/lib/esm/entities/vaultV2/vaultV2.js +88 -57
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/constant.d.ts +5 -0
- package/lib/esm/helpers/constant.js +5 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +163 -8
- package/lib/esm/helpers/validate.js +177 -7
- package/lib/esm/helpers/validateMidnightBounds.d.ts +47 -0
- package/lib/esm/helpers/validateMidnightBounds.js +72 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +12 -0
- package/lib/esm/helpers/validateMidnightPublication.js +139 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +29 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +80 -0
- package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +226 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +102 -1
- package/lib/esm/types/action.js +102 -1
- package/lib/esm/types/error.d.ts +197 -4
- package/lib/esm/types/error.js +253 -2
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/midnightCancelAndMake.d.ts +70 -0
- package/lib/esm/types/midnightCancelAndMake.js +1 -0
- package/lib/esm/types/midnightPublicationError.d.ts +332 -0
- package/lib/esm/types/midnightPublicationError.js +359 -0
- package/lib/esm/types.d.ts +1 -1
- package/lib/esm/utils.d.ts +2 -1
- package/lib/esm/utils.js +2 -1
- package/package.json +10 -10
package/lib/cjs/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = void 0;
|
|
3
|
+
exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
|
+
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = 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; } });
|
|
@@ -27,7 +27,9 @@ Object.defineProperty(exports, "InvalidNumberError", { enumerable: true, get: fu
|
|
|
27
27
|
Object.defineProperty(exports, "InvalidPermitDomainChainIdError", { enumerable: true, get: function () { return blue_sdk_viem_1.InvalidPermitDomainChainIdError; } });
|
|
28
28
|
Object.defineProperty(exports, "InvalidPermitDomainVerifyingContractError", { enumerable: true, get: function () { return blue_sdk_viem_1.InvalidPermitDomainVerifyingContractError; } });
|
|
29
29
|
Object.defineProperty(exports, "isBlueUnknownOfFactoryError", { enumerable: true, get: function () { return blue_sdk_viem_1.isUnknownOfFactoryError; } });
|
|
30
|
+
Object.defineProperty(exports, "MalformedTokenMetadataError", { enumerable: true, get: function () { return blue_sdk_viem_1.MalformedTokenMetadataError; } });
|
|
30
31
|
Object.defineProperty(exports, "BlueMarketParamsIdMismatchError", { enumerable: true, get: function () { return blue_sdk_viem_1.MarketParamsIdMismatchError; } });
|
|
32
|
+
Object.defineProperty(exports, "MissingPermitDomainNameError", { enumerable: true, get: function () { return blue_sdk_viem_1.MissingPermitDomainNameError; } });
|
|
31
33
|
Object.defineProperty(exports, "NonTupleReturnValueError", { enumerable: true, get: function () { return blue_sdk_viem_1.NonTupleReturnValueError; } });
|
|
32
34
|
Object.defineProperty(exports, "UnknownAbiFunctionError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnknownAbiFunctionError; } });
|
|
33
35
|
Object.defineProperty(exports, "UnnamedAbiOutputsError", { enumerable: true, get: function () { return blue_sdk_viem_1.UnnamedAbiOutputsError; } });
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
2
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
3
3
|
export declare const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
4
|
+
/**
|
|
5
|
+
* Matches MAX_SLIPPAGE_TOLERANCE, the SDK's other ceiling on a WAD share of user funds; higher fees are rejected as likely unit mistakes.
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const MIDNIGHT_MAX_REFERRAL_FEE_PCT: bigint;
|
|
4
9
|
/** Maximum slippage tolerance: 10% */
|
|
5
10
|
export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
|
|
6
11
|
/** Default maximum Vault V2 reallocation penalty: zero. */
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = void 0;
|
|
3
|
+
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
8
8
|
exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
9
|
+
/**
|
|
10
|
+
* Matches MAX_SLIPPAGE_TOLERANCE, the SDK's other ceiling on a WAD share of user funds; higher fees are rejected as likely unit mistakes.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = blue_sdk_1.MathLib.WAD / 10n;
|
|
9
14
|
/** Maximum slippage tolerance: 10% */
|
|
10
15
|
exports.MAX_SLIPPAGE_TOLERANCE = blue_sdk_1.MathLib.WAD / 10n;
|
|
11
16
|
/** Default maximum Vault V2 reallocation penalty: zero. */
|
|
@@ -6,7 +6,7 @@ export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type
|
|
|
6
6
|
export { grossFromNetAssets } from "./referralFee.js";
|
|
7
7
|
export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
|
|
8
8
|
export { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
|
|
9
|
-
export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateMidnightNativeAmount, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
|
9
|
+
export { getMidnightMaxSafeDebt, validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateMidnightNativeAmount, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
|
10
10
|
export { validateOfferSides } from "./validateOfferSides.js";
|
|
11
11
|
export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
|
|
12
12
|
export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
|
package/lib/cjs/helpers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
3
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
4
4
|
var callback_js_1 = require("./callback.js");
|
|
5
5
|
Object.defineProperty(exports, "getMidnightBlueBuyCallbackAddress", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackAddress; } });
|
|
6
6
|
Object.defineProperty(exports, "getMidnightBlueBuyCallbackData", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackData; } });
|
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "computeMinForceWithdrawSharePrice", { enumerable
|
|
|
32
32
|
Object.defineProperty(exports, "computeVaultMaxShareAllowance", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxShareAllowance; } });
|
|
33
33
|
Object.defineProperty(exports, "computeVaultMaxSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxSharePrice; } });
|
|
34
34
|
var validate_js_1 = require("./validate.js");
|
|
35
|
+
Object.defineProperty(exports, "getMidnightMaxSafeDebt", { enumerable: true, get: function () { return validate_js_1.getMidnightMaxSafeDebt; } });
|
|
35
36
|
Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return validate_js_1.validateAccrualPosition; } });
|
|
36
37
|
Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return validate_js_1.validateChainId; } });
|
|
37
38
|
Object.defineProperty(exports, "validateMidnightMarketChainId", { enumerable: true, get: function () { return validate_js_1.validateMidnightMarketChainId; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type
|
|
2
|
+
import { type Market as MidnightMarket, type MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import { type VaultV2BlueReallocation } from "../types/index.js";
|
|
5
5
|
/**
|
|
@@ -110,21 +110,85 @@ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput
|
|
|
110
110
|
export declare function validateUserAddress(clientAccountAddress: Address | undefined, userAddress: Address): asserts clientAccountAddress is Address;
|
|
111
111
|
/**
|
|
112
112
|
* Validates that the accrual position belongs to the expected market and user.
|
|
113
|
-
* Throws {@link MarketIdMismatchError} if the position's market ID
|
|
114
|
-
* does not match the expected market.
|
|
115
|
-
* Throws {@link AccrualPositionUserMismatchError} if the position's user
|
|
116
|
-
* does not match the expected user.
|
|
117
113
|
*
|
|
118
114
|
* @param params - Validation parameters.
|
|
119
115
|
* @param params.positionData - The accrual position to validate.
|
|
120
116
|
* @param params.expectedMarketId - The market ID the position must belong to.
|
|
121
117
|
* @param params.expectedUser - The user address the position must belong to.
|
|
118
|
+
* @returns Nothing when `positionData` belongs to the expected market and user.
|
|
119
|
+
* @throws {MarketIdMismatchError} when the position's market ID differs from `expectedMarketId`.
|
|
120
|
+
* @throws {AccrualPositionUserMismatchError} when the position's user address differs from
|
|
121
|
+
* `expectedUser`.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
125
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
126
|
+
* import { validateAccrualPosition } from "@morpho-org/morpho-sdk";
|
|
127
|
+
* import type { Address } from "viem";
|
|
128
|
+
*
|
|
129
|
+
* export function assertPositionOwner(
|
|
130
|
+
* positionData: AccrualPosition,
|
|
131
|
+
* expectedMarketId: MarketId,
|
|
132
|
+
* expectedUser: Address,
|
|
133
|
+
* ): void {
|
|
134
|
+
* validateAccrualPosition({
|
|
135
|
+
* positionData,
|
|
136
|
+
* expectedMarketId,
|
|
137
|
+
* expectedUser,
|
|
138
|
+
* });
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
122
141
|
*/
|
|
123
142
|
export declare const validateAccrualPosition: (params: {
|
|
124
143
|
positionData: AccrualPosition;
|
|
125
144
|
expectedMarketId: MarketId;
|
|
126
145
|
expectedUser: Address;
|
|
127
146
|
}) => void;
|
|
147
|
+
/**
|
|
148
|
+
* Computes the total debt supported by post-operation Midnight collateral at LLTV minus
|
|
149
|
+
* `DEFAULT_LLTV_BUFFER`.
|
|
150
|
+
* Mirrors Midnight's `isHealthy` formula in `Midnight.sol`, summing
|
|
151
|
+
* `collateral.mulDivDown(price, ORACLE_PRICE_SCALE).mulDivDown(lltv, WAD)` across indexes with the
|
|
152
|
+
* default buffer subtracted from each LLTV.
|
|
153
|
+
*
|
|
154
|
+
* @param params - Market, collateral amounts, and oracle prices.
|
|
155
|
+
* @param params.market - Hydrated Midnight market containing each collateral's LLTV.
|
|
156
|
+
* @param params.collateral - Post-operation collateral balances by market index.
|
|
157
|
+
* @param params.collateralPrices - Oracle prices by index, scaled by `ORACLE_PRICE_SCALE`.
|
|
158
|
+
* @returns Maximum safe debt in Midnight units.
|
|
159
|
+
* @throws {UnknownCollateralIndexError} when a held collateral index is not configured.
|
|
160
|
+
* @throws {MissingMarketPriceError} when a held collateral index has no supplied price.
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
164
|
+
* import {
|
|
165
|
+
* getMidnightMaxSafeDebt,
|
|
166
|
+
* morphoViemExtension,
|
|
167
|
+
* } from "@morpho-org/morpho-sdk";
|
|
168
|
+
* import { createPublicClient, http, type Hex } from "viem";
|
|
169
|
+
* import { base } from "viem/chains";
|
|
170
|
+
*
|
|
171
|
+
* const client = createPublicClient({ chain: base, transport: http() })
|
|
172
|
+
* .extend(morphoViemExtension());
|
|
173
|
+
* const midnight = client.morpho.midnight(base.id);
|
|
174
|
+
*
|
|
175
|
+
* const getMarketMaxSafeDebt = async (marketId: Hex) => {
|
|
176
|
+
* const market = await midnight.getMarketData(marketId);
|
|
177
|
+
* const maxSafeDebt = getMidnightMaxSafeDebt({
|
|
178
|
+
* market,
|
|
179
|
+
* collateral: [1_000_000n],
|
|
180
|
+
* collateralPrices: [ORACLE_PRICE_SCALE],
|
|
181
|
+
* });
|
|
182
|
+
* // maxSafeDebt: debt units supported at LLTV minus DEFAULT_LLTV_BUFFER
|
|
183
|
+
* return maxSafeDebt;
|
|
184
|
+
* };
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare const getMidnightMaxSafeDebt: (params: {
|
|
188
|
+
readonly market: MidnightMarket;
|
|
189
|
+
readonly collateral: readonly bigint[];
|
|
190
|
+
readonly collateralPrices: readonly bigint[];
|
|
191
|
+
}) => bigint;
|
|
128
192
|
/**
|
|
129
193
|
* Validates that the resulting position stays within the safe LTV threshold
|
|
130
194
|
* (LLTV minus buffer) after supplying additional collateral and borrowing.
|
|
@@ -135,6 +199,33 @@ export declare const validateAccrualPosition: (params: {
|
|
|
135
199
|
* @param params.borrowAmount - Amount being borrowed.
|
|
136
200
|
* @param params.marketId - The market identifier (for error messages).
|
|
137
201
|
* @param params.lltv - The market's liquidation LTV.
|
|
202
|
+
* @returns Nothing when the debt after borrowing, including the rounding allowance, is within the
|
|
203
|
+
* safe limit after adding collateral.
|
|
204
|
+
* @throws {MissingMarketPriceError} when `positionData.market.price` is unset or zero.
|
|
205
|
+
* @throws {BorrowExceedsSafeLtvError} when `positionData.borrowAssets + borrowAmount + 1n` exceeds
|
|
206
|
+
* the safe limit after adding collateral at LLTV minus `DEFAULT_LLTV_BUFFER`.
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
210
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
211
|
+
* import { validatePositionHealth } from "@morpho-org/morpho-sdk";
|
|
212
|
+
*
|
|
213
|
+
* export function assertSafeBorrow(
|
|
214
|
+
* positionData: AccrualPosition,
|
|
215
|
+
* additionalCollateral: bigint,
|
|
216
|
+
* borrowAmount: bigint,
|
|
217
|
+
* marketId: MarketId,
|
|
218
|
+
* lltv: bigint,
|
|
219
|
+
* ): void {
|
|
220
|
+
* validatePositionHealth({
|
|
221
|
+
* positionData,
|
|
222
|
+
* additionalCollateral,
|
|
223
|
+
* borrowAmount,
|
|
224
|
+
* marketId,
|
|
225
|
+
* lltv,
|
|
226
|
+
* });
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
138
229
|
*/
|
|
139
230
|
export declare const validatePositionHealth: (params: {
|
|
140
231
|
positionData: AccrualPosition;
|
|
@@ -145,10 +236,18 @@ export declare const validatePositionHealth: (params: {
|
|
|
145
236
|
}) => void;
|
|
146
237
|
/**
|
|
147
238
|
* Validates that the viem client chain ID matches the expected chain ID.
|
|
148
|
-
* Throws {@link ChainIdMismatchError} if they differ.
|
|
149
239
|
*
|
|
150
240
|
* @param clientChainId - Chain ID reported by the viem client (may be undefined).
|
|
151
241
|
* @param expectedChainId - Chain ID expected by the entity or action.
|
|
242
|
+
* @returns Nothing when `clientChainId` matches `expectedChainId`.
|
|
243
|
+
* @throws {ChainIdMismatchError} when `clientChainId` is undefined or differs from
|
|
244
|
+
* `expectedChainId`.
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* import { validateChainId } from "@morpho-org/morpho-sdk";
|
|
248
|
+
*
|
|
249
|
+
* validateChainId(8453, 8453);
|
|
250
|
+
* ```
|
|
152
251
|
*/
|
|
153
252
|
export declare const validateChainId: (clientChainId: number | undefined, expectedChainId: number) => void;
|
|
154
253
|
/**
|
|
@@ -158,8 +257,18 @@ export declare const validateChainId: (clientChainId: number | undefined, expect
|
|
|
158
257
|
*
|
|
159
258
|
* @param chainId - The chain to look up wNative on.
|
|
160
259
|
* @param asset - The asset address to check (collateral, loan, vault asset…).
|
|
161
|
-
* @
|
|
162
|
-
* @throws {
|
|
260
|
+
* @returns Nothing when `asset` is the chain's configured wrapped native token.
|
|
261
|
+
* @throws {UnsupportedChainIdError} when `chainId` has no address registry.
|
|
262
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
263
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when the asset is not wNative.
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
|
|
267
|
+
* import { validateNativeAsset } from "@morpho-org/morpho-sdk";
|
|
268
|
+
*
|
|
269
|
+
* const wNative = getChainAddress(8453, "wNative");
|
|
270
|
+
* validateNativeAsset(8453, wNative);
|
|
271
|
+
* ```
|
|
163
272
|
*/
|
|
164
273
|
export declare const validateNativeAsset: (chainId: number, asset: Address) => void;
|
|
165
274
|
/**
|
|
@@ -254,6 +363,22 @@ export declare const validatePositionHealthAfterWithdraw: (params: {
|
|
|
254
363
|
* @param params.positionData - The current accrual position.
|
|
255
364
|
* @param params.repayAssets - The amount of assets to repay.
|
|
256
365
|
* @param params.marketId - The market identifier (for error messages).
|
|
366
|
+
* @returns Nothing when `repayAssets` does not exceed the outstanding debt.
|
|
367
|
+
* @throws {RepayExceedsDebtError} when `repayAssets` exceeds the position's borrow assets.
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
371
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
372
|
+
* import { validateRepayAmount } from "@morpho-org/morpho-sdk";
|
|
373
|
+
*
|
|
374
|
+
* export function assertRepayWithinDebt(
|
|
375
|
+
* positionData: AccrualPosition,
|
|
376
|
+
* repayAssets: bigint,
|
|
377
|
+
* marketId: MarketId,
|
|
378
|
+
* ): void {
|
|
379
|
+
* validateRepayAmount({ positionData, repayAssets, marketId });
|
|
380
|
+
* }
|
|
381
|
+
* ```
|
|
257
382
|
*/
|
|
258
383
|
export declare const validateRepayAmount: (params: {
|
|
259
384
|
positionData: AccrualPosition;
|
|
@@ -315,7 +440,22 @@ export declare const validateSlippageTolerance: (slippageTolerance: bigint) => v
|
|
|
315
440
|
* @param params.positionData - The current accrual position.
|
|
316
441
|
* @param params.withdrawAssets - The amount of assets to withdraw.
|
|
317
442
|
* @param params.marketId - The market identifier (for error messages).
|
|
443
|
+
* @returns Nothing when `withdrawAssets` does not exceed the position's supplied assets.
|
|
318
444
|
* @throws {WithdrawExceedsSupplyError} when `withdrawAssets > positionData.supplyAssets`.
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
448
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
449
|
+
* import { validateWithdrawAmount } from "@morpho-org/morpho-sdk";
|
|
450
|
+
*
|
|
451
|
+
* export function assertWithdrawWithinSupply(
|
|
452
|
+
* positionData: AccrualPosition,
|
|
453
|
+
* withdrawAssets: bigint,
|
|
454
|
+
* marketId: MarketId,
|
|
455
|
+
* ): void {
|
|
456
|
+
* validateWithdrawAmount({ positionData, withdrawAssets, marketId });
|
|
457
|
+
* }
|
|
458
|
+
* ```
|
|
319
459
|
*/
|
|
320
460
|
export declare const validateWithdrawAmount: (params: {
|
|
321
461
|
positionData: AccrualPosition;
|
|
@@ -329,7 +469,22 @@ export declare const validateWithdrawAmount: (params: {
|
|
|
329
469
|
* @param params.positionData - The current accrual position.
|
|
330
470
|
* @param params.withdrawShares - The amount of shares to withdraw.
|
|
331
471
|
* @param params.marketId - The market identifier (for error messages).
|
|
472
|
+
* @returns Nothing when `withdrawShares` does not exceed the position's supply shares.
|
|
332
473
|
* @throws {WithdrawSharesExceedSupplyError} when `withdrawShares > positionData.supplyShares`.
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
477
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
478
|
+
* import { validateWithdrawShares } from "@morpho-org/morpho-sdk";
|
|
479
|
+
*
|
|
480
|
+
* export function assertWithdrawSharesWithinSupply(
|
|
481
|
+
* positionData: AccrualPosition,
|
|
482
|
+
* withdrawShares: bigint,
|
|
483
|
+
* marketId: MarketId,
|
|
484
|
+
* ): void {
|
|
485
|
+
* validateWithdrawShares({ positionData, withdrawShares, marketId });
|
|
486
|
+
* }
|
|
487
|
+
* ```
|
|
333
488
|
*/
|
|
334
489
|
export declare const validateWithdrawShares: (params: {
|
|
335
490
|
positionData: AccrualPosition;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateMidnightNativeAmount = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = void 0;
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateMidnightNativeAmount = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.getMidnightMaxSafeDebt = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
6
7
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
8
|
const viem_1 = require("viem");
|
|
8
9
|
const index_js_1 = require("../types/index.js");
|
|
@@ -160,15 +161,34 @@ function validateUserAddress(clientAccountAddress, userAddress) {
|
|
|
160
161
|
}
|
|
161
162
|
/**
|
|
162
163
|
* Validates that the accrual position belongs to the expected market and user.
|
|
163
|
-
* Throws {@link MarketIdMismatchError} if the position's market ID
|
|
164
|
-
* does not match the expected market.
|
|
165
|
-
* Throws {@link AccrualPositionUserMismatchError} if the position's user
|
|
166
|
-
* does not match the expected user.
|
|
167
164
|
*
|
|
168
165
|
* @param params - Validation parameters.
|
|
169
166
|
* @param params.positionData - The accrual position to validate.
|
|
170
167
|
* @param params.expectedMarketId - The market ID the position must belong to.
|
|
171
168
|
* @param params.expectedUser - The user address the position must belong to.
|
|
169
|
+
* @returns Nothing when `positionData` belongs to the expected market and user.
|
|
170
|
+
* @throws {MarketIdMismatchError} when the position's market ID differs from `expectedMarketId`.
|
|
171
|
+
* @throws {AccrualPositionUserMismatchError} when the position's user address differs from
|
|
172
|
+
* `expectedUser`.
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
176
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
177
|
+
* import { validateAccrualPosition } from "@morpho-org/morpho-sdk";
|
|
178
|
+
* import type { Address } from "viem";
|
|
179
|
+
*
|
|
180
|
+
* export function assertPositionOwner(
|
|
181
|
+
* positionData: AccrualPosition,
|
|
182
|
+
* expectedMarketId: MarketId,
|
|
183
|
+
* expectedUser: Address,
|
|
184
|
+
* ): void {
|
|
185
|
+
* validateAccrualPosition({
|
|
186
|
+
* positionData,
|
|
187
|
+
* expectedMarketId,
|
|
188
|
+
* expectedUser,
|
|
189
|
+
* });
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
172
192
|
*/
|
|
173
193
|
const validateAccrualPosition = (params) => {
|
|
174
194
|
const { positionData, expectedMarketId, expectedUser } = params;
|
|
@@ -180,6 +200,66 @@ const validateAccrualPosition = (params) => {
|
|
|
180
200
|
}
|
|
181
201
|
};
|
|
182
202
|
exports.validateAccrualPosition = validateAccrualPosition;
|
|
203
|
+
/**
|
|
204
|
+
* Computes the total debt supported by post-operation Midnight collateral at LLTV minus
|
|
205
|
+
* `DEFAULT_LLTV_BUFFER`.
|
|
206
|
+
* Mirrors Midnight's `isHealthy` formula in `Midnight.sol`, summing
|
|
207
|
+
* `collateral.mulDivDown(price, ORACLE_PRICE_SCALE).mulDivDown(lltv, WAD)` across indexes with the
|
|
208
|
+
* default buffer subtracted from each LLTV.
|
|
209
|
+
*
|
|
210
|
+
* @param params - Market, collateral amounts, and oracle prices.
|
|
211
|
+
* @param params.market - Hydrated Midnight market containing each collateral's LLTV.
|
|
212
|
+
* @param params.collateral - Post-operation collateral balances by market index.
|
|
213
|
+
* @param params.collateralPrices - Oracle prices by index, scaled by `ORACLE_PRICE_SCALE`.
|
|
214
|
+
* @returns Maximum safe debt in Midnight units.
|
|
215
|
+
* @throws {UnknownCollateralIndexError} when a held collateral index is not configured.
|
|
216
|
+
* @throws {MissingMarketPriceError} when a held collateral index has no supplied price.
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
220
|
+
* import {
|
|
221
|
+
* getMidnightMaxSafeDebt,
|
|
222
|
+
* morphoViemExtension,
|
|
223
|
+
* } from "@morpho-org/morpho-sdk";
|
|
224
|
+
* import { createPublicClient, http, type Hex } from "viem";
|
|
225
|
+
* import { base } from "viem/chains";
|
|
226
|
+
*
|
|
227
|
+
* const client = createPublicClient({ chain: base, transport: http() })
|
|
228
|
+
* .extend(morphoViemExtension());
|
|
229
|
+
* const midnight = client.morpho.midnight(base.id);
|
|
230
|
+
*
|
|
231
|
+
* const getMarketMaxSafeDebt = async (marketId: Hex) => {
|
|
232
|
+
* const market = await midnight.getMarketData(marketId);
|
|
233
|
+
* const maxSafeDebt = getMidnightMaxSafeDebt({
|
|
234
|
+
* market,
|
|
235
|
+
* collateral: [1_000_000n],
|
|
236
|
+
* collateralPrices: [ORACLE_PRICE_SCALE],
|
|
237
|
+
* });
|
|
238
|
+
* // maxSafeDebt: debt units supported at LLTV minus DEFAULT_LLTV_BUFFER
|
|
239
|
+
* return maxSafeDebt;
|
|
240
|
+
* };
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
const getMidnightMaxSafeDebt = (params) => {
|
|
244
|
+
let maxSafeDebt = 0n;
|
|
245
|
+
for (let index = 0; index < params.collateral.length; index += 1) {
|
|
246
|
+
const amount = params.collateral[index] ?? 0n;
|
|
247
|
+
if (amount === 0n)
|
|
248
|
+
continue;
|
|
249
|
+
const collateral = midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market.params, BigInt(index));
|
|
250
|
+
const price = params.collateralPrices[index];
|
|
251
|
+
if (price === undefined) {
|
|
252
|
+
throw new index_js_1.MissingMarketPriceError(params.market.id);
|
|
253
|
+
}
|
|
254
|
+
const collateralValue = blue_sdk_1.MathLib.mulDivDown(amount, price, blue_sdk_1.ORACLE_PRICE_SCALE);
|
|
255
|
+
const effectiveLltv = collateral.lltv > constant_js_1.DEFAULT_LLTV_BUFFER
|
|
256
|
+
? collateral.lltv - constant_js_1.DEFAULT_LLTV_BUFFER
|
|
257
|
+
: 0n;
|
|
258
|
+
maxSafeDebt += blue_sdk_1.MathLib.mulDivDown(collateralValue, effectiveLltv, blue_sdk_1.MathLib.WAD);
|
|
259
|
+
}
|
|
260
|
+
return maxSafeDebt;
|
|
261
|
+
};
|
|
262
|
+
exports.getMidnightMaxSafeDebt = getMidnightMaxSafeDebt;
|
|
183
263
|
/**
|
|
184
264
|
* Validates that the resulting position stays within the safe LTV threshold
|
|
185
265
|
* (LLTV minus buffer) after supplying additional collateral and borrowing.
|
|
@@ -190,6 +270,33 @@ exports.validateAccrualPosition = validateAccrualPosition;
|
|
|
190
270
|
* @param params.borrowAmount - Amount being borrowed.
|
|
191
271
|
* @param params.marketId - The market identifier (for error messages).
|
|
192
272
|
* @param params.lltv - The market's liquidation LTV.
|
|
273
|
+
* @returns Nothing when the debt after borrowing, including the rounding allowance, is within the
|
|
274
|
+
* safe limit after adding collateral.
|
|
275
|
+
* @throws {MissingMarketPriceError} when `positionData.market.price` is unset or zero.
|
|
276
|
+
* @throws {BorrowExceedsSafeLtvError} when `positionData.borrowAssets + borrowAmount + 1n` exceeds
|
|
277
|
+
* the safe limit after adding collateral at LLTV minus `DEFAULT_LLTV_BUFFER`.
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
281
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
282
|
+
* import { validatePositionHealth } from "@morpho-org/morpho-sdk";
|
|
283
|
+
*
|
|
284
|
+
* export function assertSafeBorrow(
|
|
285
|
+
* positionData: AccrualPosition,
|
|
286
|
+
* additionalCollateral: bigint,
|
|
287
|
+
* borrowAmount: bigint,
|
|
288
|
+
* marketId: MarketId,
|
|
289
|
+
* lltv: bigint,
|
|
290
|
+
* ): void {
|
|
291
|
+
* validatePositionHealth({
|
|
292
|
+
* positionData,
|
|
293
|
+
* additionalCollateral,
|
|
294
|
+
* borrowAmount,
|
|
295
|
+
* marketId,
|
|
296
|
+
* lltv,
|
|
297
|
+
* });
|
|
298
|
+
* }
|
|
299
|
+
* ```
|
|
193
300
|
*/
|
|
194
301
|
const validatePositionHealth = (params) => {
|
|
195
302
|
const { positionData, additionalCollateral, borrowAmount, marketId, lltv } = params;
|
|
@@ -210,10 +317,18 @@ const validatePositionHealth = (params) => {
|
|
|
210
317
|
exports.validatePositionHealth = validatePositionHealth;
|
|
211
318
|
/**
|
|
212
319
|
* Validates that the viem client chain ID matches the expected chain ID.
|
|
213
|
-
* Throws {@link ChainIdMismatchError} if they differ.
|
|
214
320
|
*
|
|
215
321
|
* @param clientChainId - Chain ID reported by the viem client (may be undefined).
|
|
216
322
|
* @param expectedChainId - Chain ID expected by the entity or action.
|
|
323
|
+
* @returns Nothing when `clientChainId` matches `expectedChainId`.
|
|
324
|
+
* @throws {ChainIdMismatchError} when `clientChainId` is undefined or differs from
|
|
325
|
+
* `expectedChainId`.
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* import { validateChainId } from "@morpho-org/morpho-sdk";
|
|
329
|
+
*
|
|
330
|
+
* validateChainId(8453, 8453);
|
|
331
|
+
* ```
|
|
217
332
|
*/
|
|
218
333
|
const validateChainId = (clientChainId, expectedChainId) => {
|
|
219
334
|
if (clientChainId !== expectedChainId) {
|
|
@@ -228,8 +343,18 @@ exports.validateChainId = validateChainId;
|
|
|
228
343
|
*
|
|
229
344
|
* @param chainId - The chain to look up wNative on.
|
|
230
345
|
* @param asset - The asset address to check (collateral, loan, vault asset…).
|
|
231
|
-
* @
|
|
232
|
-
* @throws {
|
|
346
|
+
* @returns Nothing when `asset` is the chain's configured wrapped native token.
|
|
347
|
+
* @throws {UnsupportedChainIdError} when `chainId` has no address registry.
|
|
348
|
+
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
349
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when the asset is not wNative.
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { getChainAddress } from "@morpho-org/morpho-sdk/addresses";
|
|
353
|
+
* import { validateNativeAsset } from "@morpho-org/morpho-sdk";
|
|
354
|
+
*
|
|
355
|
+
* const wNative = getChainAddress(8453, "wNative");
|
|
356
|
+
* validateNativeAsset(8453, wNative);
|
|
357
|
+
* ```
|
|
233
358
|
*/
|
|
234
359
|
const validateNativeAsset = (chainId, asset) => {
|
|
235
360
|
const { wNative } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
@@ -385,6 +510,22 @@ exports.validatePositionHealthAfterWithdraw = validatePositionHealthAfterWithdra
|
|
|
385
510
|
* @param params.positionData - The current accrual position.
|
|
386
511
|
* @param params.repayAssets - The amount of assets to repay.
|
|
387
512
|
* @param params.marketId - The market identifier (for error messages).
|
|
513
|
+
* @returns Nothing when `repayAssets` does not exceed the outstanding debt.
|
|
514
|
+
* @throws {RepayExceedsDebtError} when `repayAssets` exceeds the position's borrow assets.
|
|
515
|
+
* @example
|
|
516
|
+
* ```ts
|
|
517
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
518
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
519
|
+
* import { validateRepayAmount } from "@morpho-org/morpho-sdk";
|
|
520
|
+
*
|
|
521
|
+
* export function assertRepayWithinDebt(
|
|
522
|
+
* positionData: AccrualPosition,
|
|
523
|
+
* repayAssets: bigint,
|
|
524
|
+
* marketId: MarketId,
|
|
525
|
+
* ): void {
|
|
526
|
+
* validateRepayAmount({ positionData, repayAssets, marketId });
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
388
529
|
*/
|
|
389
530
|
const validateRepayAmount = (params) => {
|
|
390
531
|
const { positionData, repayAssets, marketId } = params;
|
|
@@ -547,7 +688,22 @@ exports.validateSlippageTolerance = validateSlippageTolerance;
|
|
|
547
688
|
* @param params.positionData - The current accrual position.
|
|
548
689
|
* @param params.withdrawAssets - The amount of assets to withdraw.
|
|
549
690
|
* @param params.marketId - The market identifier (for error messages).
|
|
691
|
+
* @returns Nothing when `withdrawAssets` does not exceed the position's supplied assets.
|
|
550
692
|
* @throws {WithdrawExceedsSupplyError} when `withdrawAssets > positionData.supplyAssets`.
|
|
693
|
+
* @example
|
|
694
|
+
* ```ts
|
|
695
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
696
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
697
|
+
* import { validateWithdrawAmount } from "@morpho-org/morpho-sdk";
|
|
698
|
+
*
|
|
699
|
+
* export function assertWithdrawWithinSupply(
|
|
700
|
+
* positionData: AccrualPosition,
|
|
701
|
+
* withdrawAssets: bigint,
|
|
702
|
+
* marketId: MarketId,
|
|
703
|
+
* ): void {
|
|
704
|
+
* validateWithdrawAmount({ positionData, withdrawAssets, marketId });
|
|
705
|
+
* }
|
|
706
|
+
* ```
|
|
551
707
|
*/
|
|
552
708
|
const validateWithdrawAmount = (params) => {
|
|
553
709
|
const { positionData, withdrawAssets, marketId } = params;
|
|
@@ -567,7 +723,22 @@ exports.validateWithdrawAmount = validateWithdrawAmount;
|
|
|
567
723
|
* @param params.positionData - The current accrual position.
|
|
568
724
|
* @param params.withdrawShares - The amount of shares to withdraw.
|
|
569
725
|
* @param params.marketId - The market identifier (for error messages).
|
|
726
|
+
* @returns Nothing when `withdrawShares` does not exceed the position's supply shares.
|
|
570
727
|
* @throws {WithdrawSharesExceedSupplyError} when `withdrawShares > positionData.supplyShares`.
|
|
728
|
+
* @example
|
|
729
|
+
* ```ts
|
|
730
|
+
* import type { AccrualPosition } from "@morpho-org/morpho-sdk/blue/entities";
|
|
731
|
+
* import type { MarketId } from "@morpho-org/morpho-sdk/blue/types";
|
|
732
|
+
* import { validateWithdrawShares } from "@morpho-org/morpho-sdk";
|
|
733
|
+
*
|
|
734
|
+
* export function assertWithdrawSharesWithinSupply(
|
|
735
|
+
* positionData: AccrualPosition,
|
|
736
|
+
* withdrawShares: bigint,
|
|
737
|
+
* marketId: MarketId,
|
|
738
|
+
* ): void {
|
|
739
|
+
* validateWithdrawShares({ positionData, withdrawShares, marketId });
|
|
740
|
+
* }
|
|
741
|
+
* ```
|
|
571
742
|
*/
|
|
572
743
|
const validateWithdrawShares = (params) => {
|
|
573
744
|
const { positionData, withdrawShares, marketId } = params;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { OfferStruct } from "@morpho-org/midnight-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Validates an integer stored by Midnight as `uint128`.
|
|
4
|
+
*
|
|
5
|
+
* @param field - Input field name used in validation errors.
|
|
6
|
+
* @param value - Candidate bigint.
|
|
7
|
+
* @returns Nothing when `value` is within the unsigned 128-bit range.
|
|
8
|
+
* @throws {NegativeInputError} when `value` is negative.
|
|
9
|
+
* @throws {InputExceedsMaxError} when `value` exceeds `maxUint128`.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare const validateMidnightUint128Field: (field: string, value: bigint) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Enforces the SDK's 10% (`WAD / 10n`) Midnight referral-fee cap. The contract
|
|
15
|
+
* itself only requires `referralFeePct < WAD`.
|
|
16
|
+
*
|
|
17
|
+
* @param referralFeePct - Candidate referral fee percentage.
|
|
18
|
+
* @returns Nothing when the fee is within the SDK cap.
|
|
19
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee exceeds the SDK cap.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare const validateMidnightReferralFeeCap: (referralFeePct: bigint) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Enforces the uint128 collateral-supply total for each collateral index.
|
|
25
|
+
*
|
|
26
|
+
* @param field - Input array name used in validation errors.
|
|
27
|
+
* @param supplies - Transfers grouped by collateral index.
|
|
28
|
+
* @returns Nothing when every per-key sum is at most `maxUint128`.
|
|
29
|
+
* @throws {InputExceedsMaxError} when a per-key sum exceeds `maxUint128`.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export declare const validateMidnightCollateralSupplySums: (field: string, supplies: readonly {
|
|
33
|
+
readonly collateralIndex: bigint;
|
|
34
|
+
readonly assets: bigint;
|
|
35
|
+
}[]) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Enforces uint128 limits on each offer's `maxUnits` and `maxAssets`.
|
|
38
|
+
*
|
|
39
|
+
* @param takeableOffers - Offers selected for a Midnight take.
|
|
40
|
+
* @returns Nothing when every offer cap is in the unsigned 128-bit range.
|
|
41
|
+
* @throws {NegativeInputError} when an offer cap is negative.
|
|
42
|
+
* @throws {InputExceedsMaxError} when an offer cap exceeds `maxUint128`.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare const validateMidnightTakeableOfferBounds: (takeableOffers: readonly {
|
|
46
|
+
readonly offer: Pick<OfferStruct, "maxUnits" | "maxAssets">;
|
|
47
|
+
}[]) => void;
|