@morpho-org/morpho-sdk 6.0.0-next.1 → 6.0.0-next.3
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-v5-to-v6.md +199 -34
- package/README.md +23 -15
- package/lib/cjs/abis.d.ts +3 -2829
- package/lib/cjs/abis.js +1 -1938
- package/lib/cjs/actions/blue/borrow.d.ts +3 -2
- package/lib/cjs/actions/blue/borrow.js +3 -2
- package/lib/cjs/actions/blue/common.js +6 -35
- package/lib/cjs/actions/blue/refinance.d.ts +2 -2
- package/lib/cjs/actions/blue/refinance.js +2 -2
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/blue/supply.d.ts +2 -2
- package/lib/cjs/actions/blue/supply.js +4 -9
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
- package/lib/cjs/actions/blue/withdraw.js +3 -3
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.d.ts +38 -4
- package/lib/cjs/actions/bundles/common.js +91 -35
- package/lib/cjs/actions/index.d.ts +0 -1
- package/lib/cjs/actions/index.js +0 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/encode/index.js +0 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/cjs/actions/requirements/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/index.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV1/deposit.js +1 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -4
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
- package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV2/deposit.js +1 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +2 -2
- package/lib/cjs/blue/entities.js +1 -2
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +1 -1
- package/lib/cjs/blue/fetch.js +1 -2
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +1 -3
- package/lib/cjs/blue/utils.js +1 -3
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/constants.d.ts +3 -37
- package/lib/cjs/constants.js +1 -39
- package/lib/cjs/entities/blue/blue.d.ts +38 -264
- package/lib/cjs/entities/blue/blue.js +2 -203
- package/lib/cjs/entities/index.d.ts +3 -60
- package/lib/cjs/entities/index.js +1 -20
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +2 -46
- package/lib/cjs/fetch.d.ts +1 -15
- package/lib/cjs/fetch.js +1 -16
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +4 -3
- package/lib/cjs/helpers/index.js +10 -9
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/slippage.d.ts +34 -90
- package/lib/cjs/helpers/slippage.js +52 -137
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +66 -32
- package/lib/cjs/helpers/validate.js +84 -57
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +102 -68
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +332 -385
- package/lib/cjs/types/error.js +369 -412
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +8 -35
- package/lib/cjs/utils.js +11 -36
- package/lib/esm/abis.d.ts +3 -2829
- package/lib/esm/abis.js +3 -1935
- package/lib/esm/actions/blue/borrow.d.ts +3 -2
- package/lib/esm/actions/blue/borrow.js +3 -2
- package/lib/esm/actions/blue/common.js +8 -37
- package/lib/esm/actions/blue/refinance.d.ts +2 -2
- package/lib/esm/actions/blue/refinance.js +2 -2
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/blue/supply.d.ts +2 -2
- package/lib/esm/actions/blue/supply.js +6 -11
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/supplyCollateral.js +2 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/esm/actions/blue/withdraw.d.ts +3 -3
- package/lib/esm/actions/blue/withdraw.js +3 -3
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +38 -4
- package/lib/esm/actions/bundles/common.js +91 -36
- package/lib/esm/actions/index.d.ts +0 -1
- package/lib/esm/actions/index.js +0 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +9 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +21 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
- package/lib/esm/actions/requirements/encode/index.js +0 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/esm/actions/requirements/index.d.ts +0 -1
- package/lib/esm/actions/requirements/index.js +0 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV1/deposit.js +1 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -4
- package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
- package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV2/deposit.js +1 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
- package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +2 -2
- package/lib/esm/blue/entities.js +1 -1
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/fetch.d.ts +1 -1
- package/lib/esm/blue/fetch.js +1 -1
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +1 -3
- package/lib/esm/blue/utils.js +1 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/constants.d.ts +3 -37
- package/lib/esm/constants.js +3 -37
- package/lib/esm/entities/blue/blue.d.ts +38 -264
- package/lib/esm/entities/blue/blue.js +5 -206
- package/lib/esm/entities/index.d.ts +3 -60
- package/lib/esm/entities/index.js +1 -16
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -15
- package/lib/esm/fetch.js +1 -15
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +4 -3
- package/lib/esm/helpers/index.js +4 -3
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/slippage.d.ts +34 -90
- package/lib/esm/helpers/slippage.js +52 -134
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +66 -32
- package/lib/esm/helpers/validate.js +83 -57
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +102 -68
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +332 -385
- package/lib/esm/types/error.js +355 -392
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +8 -35
- package/lib/esm/utils.js +7 -34
- package/package.json +7 -15
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
- package/lib/cjs/actions/signatures/index.d.ts +0 -3
- package/lib/cjs/actions/signatures/index.js +0 -19
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
- package/lib/cjs/bundler/actions.d.ts +0 -797
- package/lib/cjs/bundler/actions.js +0 -1371
- package/lib/cjs/bundler/index.d.ts +0 -2
- package/lib/cjs/bundler/index.js +0 -18
- package/lib/cjs/bundler/types.d.ts +0 -235
- package/lib/cjs/bundler/types.js +0 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -326
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -44
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
- package/lib/esm/actions/signatures/index.d.ts +0 -3
- package/lib/esm/actions/signatures/index.js +0 -3
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -8
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
- package/lib/esm/bundler/actions.d.ts +0 -797
- package/lib/esm/bundler/actions.js +0 -1368
- package/lib/esm/bundler/index.d.ts +0 -2
- package/lib/esm/bundler/index.js +0 -2
- package/lib/esm/bundler/types.d.ts +0 -235
- package/lib/esm/bundler/types.js +0 -1
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -326
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
- /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
- /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeVaultAsset = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateReferralFee = exports.validateDeadline = exports.validateUint256Field = exports.compareMarketIds = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
@@ -38,6 +38,58 @@ const validateUint256Field = (field, value) => {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
exports.validateUint256Field = validateUint256Field;
|
|
41
|
+
/**
|
|
42
|
+
* Rejects a deadline that no periphery can honour: the contracts read `0` as "unset" and the ABI
|
|
43
|
+
* slot is a `uint256`. Callers that also need the deadline to be in the future layer their own
|
|
44
|
+
* `ExpiredDeadlineError` on top — this check stays clock-free so transaction builders can use it.
|
|
45
|
+
*
|
|
46
|
+
* @param deadline - Candidate deadline, in seconds.
|
|
47
|
+
* @returns Nothing when `deadline` is a positive `uint256`.
|
|
48
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
49
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `maxUint256`.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const validateDeadline = (deadline) => {
|
|
53
|
+
if (deadline <= 0n)
|
|
54
|
+
throw new index_js_1.NonPositiveInputError("deadline", deadline);
|
|
55
|
+
(0, exports.validateUint256Field)("deadline", deadline);
|
|
56
|
+
};
|
|
57
|
+
exports.validateDeadline = validateDeadline;
|
|
58
|
+
/**
|
|
59
|
+
* Validates an optional referral fee and returns the pair every referral-fee-bearing periphery
|
|
60
|
+
* encodes. Shared by the direct BlueBundlesV1 writes and the VaultExitBundlesV1 force withdrawal,
|
|
61
|
+
* whose contracts apply the same `[0, WAD)` bound and both transfer the fee unconditionally.
|
|
62
|
+
*
|
|
63
|
+
* @param params - Referral fee inputs.
|
|
64
|
+
* @param params.referralFeePct - Optional WAD-scaled fee share. Defaults to `0n`.
|
|
65
|
+
* @param params.referralFeeRecipient - Optional fee recipient. Defaults to the zero address, which
|
|
66
|
+
* is only valid alongside a zero `referralFeePct`.
|
|
67
|
+
* @returns The normalized `{ referralFeePct, referralFeeRecipient }` pair.
|
|
68
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
69
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contracts reject
|
|
70
|
+
* it with `PctExceeded`); it extends `InputExceedsMaxError`, preserving that pattern-match.
|
|
71
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
const validateReferralFee = (params) => {
|
|
75
|
+
const referralFeePct = params.referralFeePct ?? 0n;
|
|
76
|
+
if (referralFeePct < 0n) {
|
|
77
|
+
throw new index_js_1.NegativeInputError("referralFeePct", referralFeePct);
|
|
78
|
+
}
|
|
79
|
+
if (referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
80
|
+
throw new index_js_1.ReferralFeePctExceededError(referralFeePct);
|
|
81
|
+
}
|
|
82
|
+
if (referralFeePct > 0n &&
|
|
83
|
+
(params.referralFeeRecipient == null ||
|
|
84
|
+
(0, viem_1.isAddressEqual)(params.referralFeeRecipient, viem_1.zeroAddress))) {
|
|
85
|
+
throw new index_js_1.ReferralFeeRecipientMissingError();
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
referralFeePct,
|
|
89
|
+
referralFeeRecipient: params.referralFeeRecipient ?? viem_1.zeroAddress,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
exports.validateReferralFee = validateReferralFee;
|
|
41
93
|
/**
|
|
42
94
|
* Validates that a raw or hydrated Midnight market belongs to the expected chain.
|
|
43
95
|
*
|
|
@@ -61,22 +113,44 @@ exports.validateMidnightMarketChainId = validateMidnightMarketChainId;
|
|
|
61
113
|
* Asserts that the client has a connected account AND that it matches
|
|
62
114
|
* the provided user address.
|
|
63
115
|
*
|
|
64
|
-
* Used
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
116
|
+
* Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
|
|
117
|
+
* backs the permit, Permit2, Blue authorization, and Midnight offer-root
|
|
118
|
+
* signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
|
|
119
|
+
* signer: the signing flow is
|
|
120
|
+
* the only path where an account/address mismatch is a real security concern
|
|
121
|
+
* (rather than just an integrator footgun).
|
|
68
122
|
*
|
|
69
123
|
* Transaction builders no longer call this helper — callers are
|
|
70
124
|
* responsible for keeping `userAddress` aligned with the signing account
|
|
71
125
|
* at the builder layer.
|
|
72
126
|
*
|
|
73
|
-
* Throws {@link MissingClientPropertyError} if the client has no account.
|
|
74
|
-
* Throws {@link AddressMismatchError} if the client account differs from
|
|
75
|
-
* `userAddress`.
|
|
76
|
-
*
|
|
77
127
|
* @param clientAccountAddress - The client's account address; if undefined,
|
|
78
128
|
* `MissingClientPropertyError` is thrown.
|
|
79
129
|
* @param userAddress - The user address provided by the caller.
|
|
130
|
+
* @returns Nothing; narrows `clientAccountAddress` to a defined `Address` when
|
|
131
|
+
* it is present and equal to `userAddress`.
|
|
132
|
+
* @throws {MissingClientPropertyError} when the client has no connected account.
|
|
133
|
+
* @throws {AddressMismatchError} when the client account differs from
|
|
134
|
+
* `userAddress`.
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { createWalletClient, http } from "viem";
|
|
138
|
+
* import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
139
|
+
* import { mainnet } from "viem/chains";
|
|
140
|
+
* import { validateUserAddress } from "@morpho-org/morpho-sdk";
|
|
141
|
+
*
|
|
142
|
+
* const account = privateKeyToAccount(generatePrivateKey());
|
|
143
|
+
* const walletClient = createWalletClient({
|
|
144
|
+
* account,
|
|
145
|
+
* chain: mainnet,
|
|
146
|
+
* transport: http(),
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* // Inside a `sign()` flow, before producing a typed-data signature:
|
|
150
|
+
* validateUserAddress(walletClient.account?.address, account.address);
|
|
151
|
+
* // Passes when the connected account equals the expected signer;
|
|
152
|
+
* // throws if the wallet has no account or signs for a different address.
|
|
153
|
+
* ```
|
|
80
154
|
*/
|
|
81
155
|
function validateUserAddress(clientAccountAddress, userAddress) {
|
|
82
156
|
if (clientAccountAddress === undefined) {
|
|
@@ -261,53 +335,6 @@ const validateRepayShares = (params) => {
|
|
|
261
335
|
}
|
|
262
336
|
};
|
|
263
337
|
exports.validateRepayShares = validateRepayShares;
|
|
264
|
-
/**
|
|
265
|
-
* Validates that Vault V1 PublicAllocator reallocations are well-formed.
|
|
266
|
-
*
|
|
267
|
-
* @param reallocations - Vault V1 reallocations to validate.
|
|
268
|
-
* @param targetMarketId - The operation's target market ID.
|
|
269
|
-
* @returns Nothing when every reallocation is valid.
|
|
270
|
-
* @throws {NegativeInputError} when a reallocation fee is negative.
|
|
271
|
-
* @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
|
|
272
|
-
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
273
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
274
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
275
|
-
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
276
|
-
* reallocations for new integrations.
|
|
277
|
-
* @example
|
|
278
|
-
* ```ts
|
|
279
|
-
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
280
|
-
* import { validateReallocations } from "@morpho-org/morpho-sdk";
|
|
281
|
-
* import { zeroHash } from "viem";
|
|
282
|
-
*
|
|
283
|
-
* const result: void = validateReallocations([], zeroHash as BlueMarketId);
|
|
284
|
-
* ```
|
|
285
|
-
*/
|
|
286
|
-
const validateReallocations = (reallocations, targetMarketId) => {
|
|
287
|
-
for (const reallocation of reallocations) {
|
|
288
|
-
if (reallocation.fee < 0n) {
|
|
289
|
-
throw new index_js_1.NegativeInputError("reallocation.fee", reallocation.fee);
|
|
290
|
-
}
|
|
291
|
-
if (reallocation.withdrawals.length === 0) {
|
|
292
|
-
throw new index_js_1.EmptyReallocationWithdrawalsError(reallocation.vault);
|
|
293
|
-
}
|
|
294
|
-
let previousMarketId;
|
|
295
|
-
for (const withdrawal of reallocation.withdrawals) {
|
|
296
|
-
if (withdrawal.amount <= 0n) {
|
|
297
|
-
throw new index_js_1.NonPositiveInputError(`reallocation.withdrawals[${withdrawal.marketParams.id}].amount`, withdrawal.amount);
|
|
298
|
-
}
|
|
299
|
-
if (withdrawal.marketParams.id === targetMarketId) {
|
|
300
|
-
throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(reallocation.vault, withdrawal.marketParams.id);
|
|
301
|
-
}
|
|
302
|
-
if (previousMarketId !== undefined &&
|
|
303
|
-
(0, exports.compareMarketIds)(withdrawal.marketParams.id, previousMarketId) <= 0) {
|
|
304
|
-
throw new index_js_1.UnsortedReallocationWithdrawalsError(reallocation.vault, withdrawal.marketParams.id);
|
|
305
|
-
}
|
|
306
|
-
previousMarketId = withdrawal.marketParams.id;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
exports.validateReallocations = validateReallocations;
|
|
311
338
|
/** @internal */
|
|
312
339
|
const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
313
340
|
const penaltyByVault = new Map();
|
|
@@ -319,7 +346,7 @@ const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
|
319
346
|
reallocation === null ||
|
|
320
347
|
"withdrawals" in reallocation ||
|
|
321
348
|
"fee" in reallocation) {
|
|
322
|
-
throw new index_js_1.
|
|
349
|
+
throw new index_js_1.InvalidVaultV2BlueReallocationShapeError();
|
|
323
350
|
}
|
|
324
351
|
if (typeof reallocation.vault !== "string" ||
|
|
325
352
|
!(0, viem_1.isAddress)(reallocation.vault)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Address } from "@morpho-org/blue-sdk";
|
|
2
2
|
/** Supported spender slots that can be validated against the chain address registry. */
|
|
3
|
-
export type RequirementSpenderKey = "
|
|
3
|
+
export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
|
|
4
4
|
/**
|
|
5
5
|
* Validates that a requirement encoder spender matches one of the allowed chain addresses.
|
|
6
6
|
*
|
|
@@ -27,9 +27,8 @@ const index_js_1 = require("../types/index.js");
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
const validateRequirementSpender = (params) => {
|
|
30
|
-
const { permit2, midnight, midnightBundles,
|
|
30
|
+
const { permit2, midnight, midnightBundles, bundles } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
31
31
|
const addresses = {
|
|
32
|
-
generalAdapter1,
|
|
33
32
|
permit2,
|
|
34
33
|
midnight,
|
|
35
34
|
midnightBundles,
|
|
@@ -42,7 +41,6 @@ const validateRequirementSpender = (params) => {
|
|
|
42
41
|
throw new index_js_1.UnsupportedErc20ApprovalSpenderError({
|
|
43
42
|
spender: params.spender,
|
|
44
43
|
chainId: params.chainId,
|
|
45
|
-
generalAdapter1,
|
|
46
44
|
permit2,
|
|
47
45
|
midnight,
|
|
48
46
|
midnightBundles,
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { type AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type Address, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Hex } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* Outcome of resolving a Vault V2 snapshot against VaultExitBundlesV1's force-withdraw
|
|
5
|
+
* preconditions.
|
|
6
|
+
*
|
|
7
|
+
* Discriminated on `type`. Callers that must fail loudly map each non-`"eligible"` tag to a typed
|
|
8
|
+
* error; callers that only frame a UI treat every non-`"eligible"` tag as "no exit available".
|
|
9
|
+
*/
|
|
10
|
+
export type VaultV2ForceWithdrawEligibility = {
|
|
11
|
+
readonly type: "eligible";
|
|
12
|
+
/** The vault's sole MorphoMarketV1AdapterV2. */
|
|
13
|
+
readonly adapter: AccrualVaultV2MorphoMarketV1AdapterV2;
|
|
14
|
+
/** Market the vault routes penalty-free liquidity through, or `undefined` when unset. */
|
|
15
|
+
readonly liquidityMarketId: MarketId | undefined;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "adapterCount";
|
|
18
|
+
readonly adapters: number;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "adapterMismatch";
|
|
21
|
+
readonly adapter: Address;
|
|
22
|
+
} | {
|
|
23
|
+
readonly type: "unsupportedAdapter";
|
|
24
|
+
readonly adapter: Address;
|
|
25
|
+
} | {
|
|
26
|
+
readonly type: "unsupportedLiquidityAdapter";
|
|
27
|
+
readonly liquidityAdapter: Address;
|
|
28
|
+
readonly adapter: Address;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "undecodableLiquidityData";
|
|
31
|
+
readonly liquidityAdapter: Address;
|
|
32
|
+
/** Raw `liquidityData` that failed to decode as `MarketParams`. */
|
|
33
|
+
readonly liquidityData: Hex;
|
|
34
|
+
/** The underlying decode failure, preserved for the caller to wrap as `cause`. */
|
|
35
|
+
readonly cause: unknown;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Resolves whether a Vault V2 snapshot can be force-withdrawn through VaultExitBundlesV1.
|
|
39
|
+
*
|
|
40
|
+
* Mirrors the contract's four preconditions: `adaptersLength() == 1`, `isAdapter(adapter)`,
|
|
41
|
+
* `adapter.morpho() == BLUE` (implied by the adapter type, whose factory pins Blue), and a
|
|
42
|
+
* `liquidityAdapter` the contract can cast to `IMorphoMarketV1AdapterV2` and whose `liquidityData`
|
|
43
|
+
* decodes as `MarketParams`. Because the exit already requires a single adapter, the only
|
|
44
|
+
* resolvable liquidity configurations are unset or that same adapter.
|
|
45
|
+
*
|
|
46
|
+
* Pure: reads only the supplied snapshot and never throws.
|
|
47
|
+
*
|
|
48
|
+
* @param vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
49
|
+
* @param adapterOverride - Optional adapter the caller expects; defaults to the vault's sole adapter.
|
|
50
|
+
* @returns The `"eligible"` variant with the resolved adapter and liquidity market, or the tag
|
|
51
|
+
* describing which precondition failed.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { resolveVaultV2ForceWithdrawEligibility } from "@morpho-org/morpho-sdk";
|
|
55
|
+
*
|
|
56
|
+
* const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
|
|
57
|
+
* if (eligibility.type === "eligible") {
|
|
58
|
+
* console.log(eligibility.adapter.address, eligibility.liquidityMarketId);
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveVaultV2ForceWithdrawEligibility(vaultData: AccrualVaultV2, adapterOverride?: Address): VaultV2ForceWithdrawEligibility;
|
|
63
|
+
/**
|
|
64
|
+
* Computes the Vault V2 shares that accruing a vault snapshot mints to its owner as management
|
|
65
|
+
* and/or performance fees.
|
|
66
|
+
*
|
|
67
|
+
* Fee shares are minted to the matching recipient during the first withdrawal after accrual.
|
|
68
|
+
* When the owner is both recipients, both fee-share amounts are included. Timestamps before the
|
|
69
|
+
* snapshot's last update are clamped because Vault V2 cannot accrue backwards.
|
|
70
|
+
*
|
|
71
|
+
* @param params - Vault fee-share accrual inputs.
|
|
72
|
+
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
73
|
+
* @param params.owner - Account whose fee-recipient share mints are measured.
|
|
74
|
+
* @param params.timestamp - Target accrual timestamp, clamped to `vaultData.lastUpdate`.
|
|
75
|
+
* @returns Shares minted to `owner` by the management and/or performance fees, or `0n` when the
|
|
76
|
+
* owner is not a fee recipient.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { computeVaultV2ForceWithdrawFeeSharesMinted } from "@morpho-org/morpho-sdk";
|
|
80
|
+
*
|
|
81
|
+
* const feeShares = computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
82
|
+
* vaultData,
|
|
83
|
+
* owner,
|
|
84
|
+
* timestamp,
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function computeVaultV2ForceWithdrawFeeSharesMinted(params: {
|
|
89
|
+
readonly vaultData: AccrualVaultV2;
|
|
90
|
+
readonly owner: Address;
|
|
91
|
+
readonly timestamp: bigint;
|
|
92
|
+
}): bigint;
|
|
93
|
+
/** Vault V2 force-withdraw amounts derived from a vault snapshot. */
|
|
94
|
+
export interface VaultV2ForceWithdrawPlan {
|
|
95
|
+
/** WAD-scaled force-deallocation penalty the vault charges on this adapter. */
|
|
96
|
+
readonly penalty: bigint;
|
|
97
|
+
/** Penalty-inclusive amount requested from the vault. */
|
|
98
|
+
readonly exitAssets: bigint;
|
|
99
|
+
/** Penalty-free leg, withdrawn before any force deallocation. */
|
|
100
|
+
readonly assetsToWithdraw: bigint;
|
|
101
|
+
/** Penalised leg, force-deallocated from the adapter's markets. */
|
|
102
|
+
readonly assetsToDeallocate: bigint;
|
|
103
|
+
/** Upper bound of the assets burned as force-deallocation penalty. */
|
|
104
|
+
readonly penaltyAssets: bigint;
|
|
105
|
+
/** Assets the contract withdraws in total, before the referral fee. */
|
|
106
|
+
readonly withdrawnAssets: bigint;
|
|
107
|
+
/** Assets the adapter's markets can release for *this* `exitAssets`, summed across markets. */
|
|
108
|
+
readonly coveredAssets: bigint;
|
|
109
|
+
/**
|
|
110
|
+
* Largest penalty-inclusive `exitAssets` the snapshot supports.
|
|
111
|
+
*
|
|
112
|
+
* Independent of the requested `exitAssets`, so it is safe to use as an input ceiling. Always an
|
|
113
|
+
* amount the exit actually accepts: `0n` when nothing is exitable, and saturated at `maxUint256`
|
|
114
|
+
* rather than grossing up past the ABI slot.
|
|
115
|
+
*/
|
|
116
|
+
readonly maxExitAssets: bigint;
|
|
117
|
+
/** Upper bound of the `forceDeallocate` calls the contract's loop performs. */
|
|
118
|
+
readonly penaltyLegs: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Computes every Vault V2 force-withdraw amount from a vault snapshot, without any RPC.
|
|
122
|
+
*
|
|
123
|
+
* Reproduces `vaultExitBundlesV1ForceWithdrawVaultV2` arithmetic:
|
|
124
|
+
*
|
|
125
|
+
* ```solidity
|
|
126
|
+
* withdrawableAssets = idle + min(liquidityAdapterAssets, liquidityMarketLiquidity);
|
|
127
|
+
* assetsToWithdraw = min(exitAssets, withdrawableAssets);
|
|
128
|
+
* assetsToDeallocate = mulDivDown(exitAssets - assetsToWithdraw, WAD, WAD + penalty);
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* `coveredAssets` sums `min(adapterPosition, marketLiquidity)` over the adapter's markets, minus
|
|
132
|
+
* whatever the penalty-free leg already drained from the liquidity market. The sum is deliberately
|
|
133
|
+
* order-independent: the contract's loop visits every market taking `min(available, remaining)`, so
|
|
134
|
+
* total capacity does not depend on the adapter's storage order — which matters because a drained
|
|
135
|
+
* market is removed from that list mid-loop.
|
|
136
|
+
*
|
|
137
|
+
* That order-independence assumes `VaultExitBundlesV1` copies `adapter.marketIds` into memory
|
|
138
|
+
* *before* the loop. If it instead re-read adapter storage each iteration,
|
|
139
|
+
* `MorphoMarketV1AdapterV2.deallocate`'s swap-and-pop removal of a drained market would make the
|
|
140
|
+
* loop skip markets, and this sum would overstate real capacity — letting an exit through that
|
|
141
|
+
* panics on-chain. The claim is load-bearing for the coverage guard and is verified only by the
|
|
142
|
+
* fork suite, not by any in-repo contract source.
|
|
143
|
+
*
|
|
144
|
+
* @param params - Plan inputs.
|
|
145
|
+
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
146
|
+
* @param params.adapter - The vault's sole MorphoMarketV1AdapterV2, from
|
|
147
|
+
* {@link resolveVaultV2ForceWithdrawEligibility}.
|
|
148
|
+
* @param params.liquidityMarketId - Market the vault routes penalty-free liquidity through, or
|
|
149
|
+
* `undefined` when the vault has no liquidity adapter.
|
|
150
|
+
* @param params.exitAssets - Penalty-inclusive amount to exit.
|
|
151
|
+
* @param params.timestamp - Timestamp used to accrue every Morpho Blue market before converting
|
|
152
|
+
* adapter shares.
|
|
153
|
+
* @returns The resolved plan. `coveredAssets < assetsToDeallocate` means the exit would overrun the
|
|
154
|
+
* contract's unbounded loop; the caller decides how to report that.
|
|
155
|
+
* @throws {NonPositiveInputError} when `exitAssets` is not positive.
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import {
|
|
159
|
+
* computeVaultV2ForceWithdrawPlan,
|
|
160
|
+
* resolveVaultV2ForceWithdrawEligibility,
|
|
161
|
+
* } from "@morpho-org/morpho-sdk";
|
|
162
|
+
*
|
|
163
|
+
* const eligibility = resolveVaultV2ForceWithdrawEligibility(vaultData);
|
|
164
|
+
* if (eligibility.type === "eligible") {
|
|
165
|
+
* const plan = computeVaultV2ForceWithdrawPlan({
|
|
166
|
+
* vaultData,
|
|
167
|
+
* adapter: eligibility.adapter,
|
|
168
|
+
* liquidityMarketId: eligibility.liquidityMarketId,
|
|
169
|
+
* exitAssets: 1_000_000n,
|
|
170
|
+
* timestamp: 1_800_000_000n,
|
|
171
|
+
* });
|
|
172
|
+
* // plan.withdrawnAssets is what the user receives before the referral fee
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
177
|
+
readonly vaultData: AccrualVaultV2;
|
|
178
|
+
readonly adapter: AccrualVaultV2MorphoMarketV1AdapterV2;
|
|
179
|
+
readonly liquidityMarketId: MarketId | undefined;
|
|
180
|
+
readonly exitAssets: bigint;
|
|
181
|
+
readonly timestamp: bigint;
|
|
182
|
+
}): VaultV2ForceWithdrawPlan;
|
|
183
|
+
/**
|
|
184
|
+
* Upper-bounds the vault shares a Vault V2 force withdrawal burns.
|
|
185
|
+
*
|
|
186
|
+
* The contract splits the burn across up to `penaltyLegs + 2` separate `VaultV2.withdraw` calls (the
|
|
187
|
+
* penalty-free leg, one per `forceDeallocate`, and the final deallocated leg), each rounding its own
|
|
188
|
+
* share burn up. Converting the aggregate already spends one ceiling, so the bound adds one share
|
|
189
|
+
* per *additional* leg that moves a positive amount — a zero-amount leg burns `toShares(0, "Up")`
|
|
190
|
+
* and rounds nothing.
|
|
191
|
+
*
|
|
192
|
+
* The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
|
|
193
|
+
* burn the realized exit price is measured against. It takes the max over the two supplied snapshots
|
|
194
|
+
* because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
|
|
195
|
+
* execution. The entity passes both accrued to `now` (execution time): the raw `lastUpdate` snapshot
|
|
196
|
+
* underestimates the burn a stale fee-bearing vault realizes — the first withdrawal accrues pending
|
|
197
|
+
* management fees before burning shares — which lifts the floor above the faithful price and trips
|
|
198
|
+
* `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`, tracks execution without
|
|
199
|
+
* letting a long deadline silently weaken the guard; `slippageTolerance` absorbs the residual drift
|
|
200
|
+
* until inclusion. Pass distinct snapshots to bound the burn across an accrual window.
|
|
201
|
+
*
|
|
202
|
+
* This is **not** the share allowance to authorize. The price floor's denominator is this bound
|
|
203
|
+
* minus `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`: the
|
|
204
|
+
* contract measures the *net* burn, which fee mints to `owner` shrink. The allowance is
|
|
205
|
+
* `min(mulDivUp(exitAssets, RAY, minSharePriceE27) + computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
206
|
+
* vaultData, owner, timestamp: deadline }), maxUint256)`: the permit pays for the *gross* burn.
|
|
207
|
+
*
|
|
208
|
+
* @param params - Share-bound inputs.
|
|
209
|
+
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
210
|
+
* @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
|
|
211
|
+
* share burns is returned. The entity passes the `now`-accrued snapshot for both.
|
|
212
|
+
* @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
|
|
213
|
+
* @returns An upper bound, in vault shares, of what the exit burns.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { MathLib } from "@morpho-org/blue-sdk";
|
|
217
|
+
* import {
|
|
218
|
+
* computeVaultV2ForceWithdrawFeeSharesMinted,
|
|
219
|
+
* computeVaultV2ForceWithdrawSharesBurnt,
|
|
220
|
+
* } from "@morpho-org/morpho-sdk";
|
|
221
|
+
*
|
|
222
|
+
* const { vault: nowVaultData } = vaultData.accrueInterest(now);
|
|
223
|
+
* const sharesBurnt = computeVaultV2ForceWithdrawSharesBurnt({
|
|
224
|
+
* vaultData: nowVaultData,
|
|
225
|
+
* deadlineVaultData: nowVaultData,
|
|
226
|
+
* plan,
|
|
227
|
+
* });
|
|
228
|
+
* const feeSharesNow = computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
229
|
+
* vaultData,
|
|
230
|
+
* owner,
|
|
231
|
+
* timestamp: now,
|
|
232
|
+
* });
|
|
233
|
+
* const sharesBurntForFloor = sharesBurnt - feeSharesNow;
|
|
234
|
+
* const requiredShareAllowance = MathLib.min(
|
|
235
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) +
|
|
236
|
+
* computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
237
|
+
* vaultData,
|
|
238
|
+
* owner,
|
|
239
|
+
* timestamp: deadline,
|
|
240
|
+
* }),
|
|
241
|
+
* maxUint256,
|
|
242
|
+
* );
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export declare function computeVaultV2ForceWithdrawSharesBurnt(params: {
|
|
246
|
+
readonly vaultData: AccrualVaultV2;
|
|
247
|
+
readonly deadlineVaultData: AccrualVaultV2;
|
|
248
|
+
readonly plan: VaultV2ForceWithdrawPlan;
|
|
249
|
+
}): bigint;
|
|
250
|
+
/**
|
|
251
|
+
* Computes a lower bound of the Vault V2 shares that a force withdrawal burns.
|
|
252
|
+
*
|
|
253
|
+
* The penalty-free/penalised split can move as liquidity accrues between planning and inclusion.
|
|
254
|
+
* This lower bound is used to reject fee-recipient exits whose fee mints could reach the burn
|
|
255
|
+
* measured by VaultExitBundlesV1, independently of that split.
|
|
256
|
+
*
|
|
257
|
+
* @param params - Lower-bound inputs.
|
|
258
|
+
* @param params.vaultData - Vault V2 snapshot already accrued to the execution timestamp.
|
|
259
|
+
* @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
|
|
260
|
+
* @returns A lower bound, in vault shares, of the burn measured by the contract.
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* import { computeVaultV2ForceWithdrawMinSharesBurnt } from "@morpho-org/morpho-sdk";
|
|
264
|
+
*
|
|
265
|
+
* const minSharesBurnt = computeVaultV2ForceWithdrawMinSharesBurnt({
|
|
266
|
+
* vaultData,
|
|
267
|
+
* plan,
|
|
268
|
+
* });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export declare function computeVaultV2ForceWithdrawMinSharesBurnt(params: {
|
|
272
|
+
readonly vaultData: AccrualVaultV2;
|
|
273
|
+
readonly plan: VaultV2ForceWithdrawPlan;
|
|
274
|
+
}): bigint;
|