@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
package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js
RENAMED
|
@@ -2,9 +2,9 @@ import { permit2Abi } from "@morpho-org/blue-sdk-viem";
|
|
|
2
2
|
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { readContract } from "viem/actions";
|
|
5
|
-
import { validateChainId } from "
|
|
6
|
-
import { validateUint256Field } from "
|
|
7
|
-
import { NoUnusedPermit2NonceError } from "
|
|
5
|
+
import { validateChainId } from "../../helpers/index.js";
|
|
6
|
+
import { validateUint256Field } from "../../helpers/validate.js";
|
|
7
|
+
import { NoUnusedPermit2NonceError } from "../../types/index.js";
|
|
8
8
|
/** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
|
|
9
9
|
const MAX_PERMIT2_NONCE_WORD = maxUint256 >> 8n;
|
|
10
10
|
/**
|
|
@@ -5,10 +5,10 @@ import type { FetchParameters } from "../../types/data.js";
|
|
|
5
5
|
import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
|
-
* Fetches
|
|
8
|
+
* Fetches direct onchain vault and allocation state without applying virtual interest.
|
|
9
9
|
*
|
|
10
10
|
* @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
|
|
11
|
-
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The
|
|
11
|
+
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
|
|
12
12
|
*/
|
|
13
13
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
14
14
|
/**
|
|
@@ -36,6 +36,7 @@ export interface VaultV1Actions {
|
|
|
36
36
|
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
37
37
|
* transaction builder.
|
|
38
38
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
39
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
39
40
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
40
41
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
41
42
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
@@ -46,8 +47,8 @@ export interface VaultV1Actions {
|
|
|
46
47
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
47
48
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
48
49
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
49
|
-
* @throws {
|
|
50
|
-
*
|
|
50
|
+
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
|
|
51
|
+
* owner is consumed and none was passed explicitly.
|
|
51
52
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
52
53
|
* explicit Permit2 nonce is consumed.
|
|
53
54
|
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
@@ -240,6 +241,10 @@ export interface VaultV1Actions {
|
|
|
240
241
|
* Snapshot state can drift before inclusion, so a later reallocation may still make the on-chain
|
|
241
242
|
* loop under-cover even after pre-flight succeeds.
|
|
242
243
|
*
|
|
244
|
+
* In-kind exits require an exact vault-share allowance for the computed cap. An ERC-2612 permit
|
|
245
|
+
* is emitted only to raise an insufficient allowance; an oversized allowance is always reset
|
|
246
|
+
* with an onchain approval before the exit.
|
|
247
|
+
*
|
|
243
248
|
* @param params - In-kind redemption parameters.
|
|
244
249
|
* @param params.amount - Asset-denominated amount to exit.
|
|
245
250
|
* @param params.marketParamsList - Ordered vault markets consumed greedily by the contract;
|
|
@@ -249,9 +254,11 @@ export interface VaultV1Actions {
|
|
|
249
254
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
250
255
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
251
256
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
257
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
252
258
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
253
|
-
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
259
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
254
260
|
* @throws {EmptyMarketParamsListError} when the market list is empty.
|
|
261
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
255
262
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
256
263
|
* requirement resolution.
|
|
257
264
|
* @throws {InKindRedeemCoverageError} when the ordered list cannot cover `amount` without
|
|
@@ -264,7 +271,9 @@ export interface VaultV1Actions {
|
|
|
264
271
|
* @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the flash loan.
|
|
265
272
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
266
273
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
267
|
-
* @throws {
|
|
274
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
|
|
275
|
+
* the wrong asset, owner, or signature encoding, or names another spender, amount, or deadline
|
|
276
|
+
* than the prepared cap.
|
|
268
277
|
* @example
|
|
269
278
|
* ```ts
|
|
270
279
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -326,7 +335,9 @@ export interface VaultV1Actions {
|
|
|
326
335
|
* `getRequirements()` re-reads the live share allowance on every call, so a requirement
|
|
327
336
|
* satisfied between calls stops being reported, while the derived source share cap stays
|
|
328
337
|
* pinned to the supplied snapshot.
|
|
338
|
+
* @throws {UnknownBlueMarketAllocationError} when a source withdraw-queue market has no allocation snapshot.
|
|
329
339
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
340
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated source or target market with positive debt uses an unsupported IRM.
|
|
330
341
|
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
331
342
|
* @throws {VaultAssetMismatchError} when the source and destination vault assets differ.
|
|
332
343
|
* @throws {SameVaultMigrationError} when the source and destination vault addresses are equal.
|
|
@@ -442,6 +453,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
442
453
|
readonly userAddress: Address;
|
|
443
454
|
readonly deadline?: bigint;
|
|
444
455
|
}): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
456
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
445
457
|
migrateToV2(params: {
|
|
446
458
|
readonly userAddress: Address;
|
|
447
459
|
readonly sourceVault: AccrualVault;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain,
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
|
-
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
6
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
|
-
import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
-
import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError,
|
|
9
|
+
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
+
import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
11
11
|
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
12
12
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
13
13
|
export class MorphoVaultV1 {
|
|
@@ -27,7 +27,6 @@ export class MorphoVaultV1 {
|
|
|
27
27
|
}
|
|
28
28
|
return fetchAccrualVault(this.vault, this.client.viemClient, {
|
|
29
29
|
...parameters,
|
|
30
|
-
chainId: this.chainId,
|
|
31
30
|
deployless: this.client.options.supportDeployless,
|
|
32
31
|
});
|
|
33
32
|
}
|
|
@@ -287,11 +286,13 @@ export class MorphoVaultV1 {
|
|
|
287
286
|
}));
|
|
288
287
|
const now = Time.timestamp();
|
|
289
288
|
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
289
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
290
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
291
|
+
validateDeadline(deadline);
|
|
290
292
|
if (deadline <= now)
|
|
291
293
|
throw new ExpiredDeadlineError(deadline, now);
|
|
292
294
|
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
293
|
-
const
|
|
294
|
-
const blue = addresses.blue ?? addresses.morpho;
|
|
295
|
+
const blue = getChainAddress(this.chainId, "blue");
|
|
295
296
|
let covered = 0n;
|
|
296
297
|
const assignedByMarket = new Map();
|
|
297
298
|
for (const marketParams of marketParamsListSnapshot) {
|
|
@@ -301,6 +302,8 @@ export class MorphoVaultV1 {
|
|
|
301
302
|
const allocation = vaultData.allocations.get(marketId);
|
|
302
303
|
if (allocation?.config.enabled !== true)
|
|
303
304
|
continue;
|
|
305
|
+
if (allocation.position.supplyShares === 0n)
|
|
306
|
+
continue;
|
|
304
307
|
const market = allocation.position.market.accrueInterest(now);
|
|
305
308
|
const available = market.toSupplyAssets(allocation.position.supplyShares);
|
|
306
309
|
const assigned = assignedByMarket.get(marketId) ?? 0n;
|
|
@@ -387,9 +390,14 @@ export class MorphoVaultV1 {
|
|
|
387
390
|
required: amount,
|
|
388
391
|
});
|
|
389
392
|
}
|
|
390
|
-
|
|
393
|
+
// In-kind withdrawals carry no onchain share cap, so the allowance itself is the cap. A
|
|
394
|
+
// larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`.
|
|
395
|
+
if (allowance === requiredShareAllowance)
|
|
391
396
|
return [];
|
|
392
|
-
|
|
397
|
+
// A lowering permit can be skipped after its nonce is consumed, so oversized allowances
|
|
398
|
+
// must be reset with an onchain approval.
|
|
399
|
+
if (allowance < requiredShareAllowance &&
|
|
400
|
+
this.client.options.supportSignature) {
|
|
393
401
|
return [
|
|
394
402
|
encodeVaultSharesPermit({
|
|
395
403
|
vault: vaultData,
|
|
@@ -413,8 +421,10 @@ export class MorphoVaultV1 {
|
|
|
413
421
|
];
|
|
414
422
|
},
|
|
415
423
|
buildTx: (signatures) => {
|
|
416
|
-
const
|
|
417
|
-
|
|
424
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
425
|
+
spender: vaultExitBundlesV1,
|
|
426
|
+
amount: requiredShareAllowance,
|
|
427
|
+
deadline,
|
|
418
428
|
});
|
|
419
429
|
return vaultV1InKindRedeem({
|
|
420
430
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -430,6 +440,7 @@ export class MorphoVaultV1 {
|
|
|
430
440
|
},
|
|
431
441
|
};
|
|
432
442
|
}
|
|
443
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
433
444
|
migrateToV2(params) {
|
|
434
445
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
435
446
|
if (!isAddressEqual(params.sourceVault.address, this.vault)) {
|
|
@@ -461,7 +472,13 @@ export class MorphoVaultV1 {
|
|
|
461
472
|
referralFeePct: params.referralFeePct,
|
|
462
473
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
463
474
|
});
|
|
464
|
-
|
|
475
|
+
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
476
|
+
const grossAssets = assets ??
|
|
477
|
+
params.sourceVault
|
|
478
|
+
.accrueInterest(params.sourceVault.allocations
|
|
479
|
+
.values()
|
|
480
|
+
.reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), createdAt))
|
|
481
|
+
.toAssets(shares ?? 0n, "Down");
|
|
465
482
|
const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, common.referralFeePct);
|
|
466
483
|
const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
|
|
467
484
|
vaultData: params.targetVault,
|
|
@@ -38,6 +38,7 @@ export interface VaultV2Actions {
|
|
|
38
38
|
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
39
39
|
* transaction builder.
|
|
40
40
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
41
|
+
* @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
|
|
41
42
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
42
43
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
43
44
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
@@ -48,8 +49,8 @@ export interface VaultV2Actions {
|
|
|
48
49
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
49
50
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
50
51
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
51
|
-
* @throws {
|
|
52
|
-
*
|
|
52
|
+
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
|
|
53
|
+
* owner is consumed and none was passed explicitly.
|
|
53
54
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
54
55
|
* explicit Permit2 nonce is consumed.
|
|
55
56
|
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
@@ -232,6 +233,10 @@ export interface VaultV2Actions {
|
|
|
232
233
|
* Idle balance, penalty, and adapter positions can drift after the snapshot, so an on-chain
|
|
233
234
|
* under-coverage panic remains possible if vault state changes between preparation and inclusion.
|
|
234
235
|
*
|
|
236
|
+
* In-kind exits require an exact vault-share allowance for the computed cap. An ERC-2612 permit
|
|
237
|
+
* is emitted only to raise an insufficient allowance; an oversized allowance is always reset
|
|
238
|
+
* with an onchain approval before the exit.
|
|
239
|
+
*
|
|
235
240
|
* @param params - In-kind redemption parameters.
|
|
236
241
|
* @param params.amount - Penalty-inclusive, asset-denominated amount to exit.
|
|
237
242
|
* @param params.marketParamsList - Ordered adapter markets consumed greedily after idle assets;
|
|
@@ -242,16 +247,18 @@ export interface VaultV2Actions {
|
|
|
242
247
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
243
248
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
244
249
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
250
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
245
251
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
246
|
-
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
252
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
247
253
|
* @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
|
|
248
254
|
* penalty-adjusted amount rounds to zero deallocated assets.
|
|
249
255
|
* @throws {EmptyMarketParamsListError} when assets must be deallocated and the market list is empty.
|
|
256
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
250
257
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
251
258
|
* requirement resolution.
|
|
252
|
-
* @throws {
|
|
259
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
|
|
253
260
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
254
|
-
* @throws {
|
|
261
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
255
262
|
* @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
|
|
256
263
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
257
264
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -259,7 +266,9 @@ export interface VaultV2Actions {
|
|
|
259
266
|
* @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the largest callback.
|
|
260
267
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
261
268
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
262
|
-
* @throws {
|
|
269
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
|
|
270
|
+
* the wrong asset, owner, or signature encoding, or names another spender, amount, or deadline
|
|
271
|
+
* than the prepared cap.
|
|
263
272
|
* @example
|
|
264
273
|
* ```ts
|
|
265
274
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -294,29 +303,136 @@ export interface VaultV2Actions {
|
|
|
294
303
|
readonly deadline?: bigint;
|
|
295
304
|
}) => ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
296
305
|
/**
|
|
297
|
-
* Prepares a
|
|
306
|
+
* Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
|
|
298
307
|
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
308
|
+
* The contract withdraws everything the vault can pay without a penalty — its idle assets plus
|
|
309
|
+
* the liquidity available through its liquidity adapter — then force-deallocates the remainder by
|
|
310
|
+
* looping over the adapter's markets. It computes the deallocations itself: the caller supplies
|
|
311
|
+
* neither a market list nor an order.
|
|
302
312
|
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
313
|
+
* `exitAssets` is **penalty-inclusive**, matching `inKindRedeem`. The contract debits it from the
|
|
314
|
+
* user's position but pays out only
|
|
315
|
+
* `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))`, minus the
|
|
316
|
+
* referral fee. Quote the split with `previewVaultV2ForceWithdraw`.
|
|
317
|
+
*
|
|
318
|
+
* The vault must have exactly one `MorphoMarketV1AdapterV2` and route liquidity through that same
|
|
319
|
+
* adapter or none at all. Call `getRequirements()` before `buildTx()` so the vault-share allowance
|
|
320
|
+
* and permit nonce are read on-chain.
|
|
321
|
+
*
|
|
322
|
+
* The SDK derives a conservative lower bound on the realized exit share price from the snapshot
|
|
323
|
+
* and `slippageTolerance`. A supplied `minSharePriceE27` replaces the tolerance-derived bound
|
|
324
|
+
* (it may be tighter or looser) but must be at least the floor derived at
|
|
325
|
+
* `MAX_SLIPPAGE_TOLERANCE`, so an override can never disable meaningful protection.
|
|
326
|
+
* The bound rejects a share price drop, a penalty increase, and liquidity shifting from the
|
|
327
|
+
* penalty-free leg to the penalised leg. It does **not** cover the referral fee, which the
|
|
328
|
+
* contract deducts afterwards.
|
|
329
|
+
*
|
|
330
|
+
* Vault gates are enforced by the final transaction and are not preflighted: the receive-assets
|
|
331
|
+
* gate must allow VaultExitBundlesV1 and may depend on its transient initiator, while a
|
|
332
|
+
* send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
|
|
333
|
+
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
334
|
+
* share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
|
|
335
|
+
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` — the approved
|
|
336
|
+
* share allowance this handle returns is the exact upper bound on the burn — so a full-balance
|
|
337
|
+
* exit does not revert for insufficient shares.
|
|
338
|
+
*
|
|
339
|
+
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
340
|
+
* an on-chain revert remains possible if vault state changes between preparation and inclusion.
|
|
341
|
+
* A fee-recipient `userAddress` gets a floor from the net share burn after fee mints at `now`,
|
|
342
|
+
* and a guard against fee mints reaching the lower burn bound by the deadline. Its allowance
|
|
343
|
+
* includes the projected fee shares through that same deadline. Deadlines beyond one year after
|
|
344
|
+
* handle creation are rejected, so the guard and allowance cover the whole accepted window.
|
|
345
|
+
*
|
|
346
|
+
* @param params - Force withdrawal parameters.
|
|
347
|
+
* @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
|
|
348
|
+
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
349
|
+
* @param params.userAddress - Account that signs and submits the exit, and receives the assets.
|
|
350
|
+
* @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
|
|
351
|
+
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
352
|
+
* Deadlines more than one year after handle creation are rejected.
|
|
353
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance applied to the derived share
|
|
354
|
+
* price bound. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`, capped at `MAX_SLIPPAGE_TOLERANCE`.
|
|
355
|
+
* @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound. It replaces
|
|
356
|
+
* the tolerance-derived bound and may be tighter or looser, but must be at least the floor
|
|
357
|
+
* derived at `MAX_SLIPPAGE_TOLERANCE`. When that floor rounds down to zero (dust exits) it is
|
|
358
|
+
* clamped to `1`, so any positive override is accepted.
|
|
359
|
+
* @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
|
|
360
|
+
* `referralFeeRecipient`. Defaults to `0n`.
|
|
361
|
+
* @param params.referralFeeRecipient - Optional referral fee recipient, required when
|
|
362
|
+
* `referralFeePct` is positive.
|
|
363
|
+
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
364
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
365
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
366
|
+
* @throws {NonPositiveInputError} when `exitAssets`, `deadline`, or a supplied
|
|
367
|
+
* `minSharePriceE27` is not positive.
|
|
368
|
+
* @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
|
|
369
|
+
* @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
|
|
370
|
+
* `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `referralFeePct` is not
|
|
371
|
+
* below WAD, or when `deadline` is more than one year after handle creation.
|
|
372
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
373
|
+
* requirement resolution.
|
|
374
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
375
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
|
|
376
|
+
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
377
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
378
|
+
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
|
|
379
|
+
* another adapter.
|
|
380
|
+
* @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
|
|
381
|
+
* as `MarketParams`.
|
|
382
|
+
* @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit would withdraw nothing.
|
|
383
|
+
* @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the exit,
|
|
384
|
+
* which would overrun the contract's unbounded loop.
|
|
385
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds down
|
|
386
|
+
* to zero, which the contract would read as no bound at all.
|
|
387
|
+
* @throws {VaultV2ForceWithdrawSharePriceBelowFloorError} when a supplied `minSharePriceE27`
|
|
388
|
+
* is below the floor derived at `MAX_SLIPPAGE_TOLERANCE`.
|
|
389
|
+
* @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when fee shares are minted to a
|
|
390
|
+
* fee-recipient `userAddress` and reach the lower-bound share burn at the deadline.
|
|
391
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
392
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
393
|
+
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
394
|
+
* @throws {viem.BaseError} from `getRequirements()` when an RPC or multicall contract read fails.
|
|
395
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
396
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
397
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
398
|
+
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
399
|
+
* permit; the nonce is verified onchain by the vault's `permit`.
|
|
400
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
401
|
+
* @example
|
|
402
|
+
* ```ts
|
|
403
|
+
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
404
|
+
*
|
|
405
|
+
* const vault = client.morpho.vaultV2(vaultAddress, 1);
|
|
406
|
+
* const vaultData = await vault.getData();
|
|
407
|
+
* const exit = vault.forceWithdraw({
|
|
408
|
+
* exitAssets: 1_000_000n,
|
|
409
|
+
* vaultData,
|
|
410
|
+
* userAddress,
|
|
411
|
+
* });
|
|
412
|
+
* const signatures = [];
|
|
413
|
+
* for (const requirement of await exit.getRequirements()) {
|
|
414
|
+
* if (isRequirementSignature(requirement)) {
|
|
415
|
+
* signatures.push(await requirement.sign(walletClient, userAddress));
|
|
416
|
+
* } else {
|
|
417
|
+
* const hash = await walletClient.sendTransaction(requirement);
|
|
418
|
+
* await client.waitForTransactionReceipt({ hash });
|
|
419
|
+
* }
|
|
420
|
+
* }
|
|
421
|
+
* const tx = exit.buildTx(signatures);
|
|
422
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
|
|
423
|
+
* ```
|
|
310
424
|
*/
|
|
311
|
-
forceWithdraw: (params: {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
425
|
+
readonly forceWithdraw: (params: {
|
|
426
|
+
readonly exitAssets: bigint;
|
|
427
|
+
readonly vaultData: AccrualVaultV2;
|
|
428
|
+
readonly userAddress: Address;
|
|
429
|
+
readonly adapter?: Address;
|
|
430
|
+
readonly deadline?: bigint;
|
|
431
|
+
readonly slippageTolerance?: bigint;
|
|
432
|
+
readonly minSharePriceE27?: bigint;
|
|
433
|
+
readonly referralFeePct?: bigint;
|
|
434
|
+
readonly referralFeeRecipient?: Address;
|
|
435
|
+
}) => ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
320
436
|
/**
|
|
321
437
|
* Prepares a force redeem transaction for the VaultV2 contract using the vault's native multicall.
|
|
322
438
|
*
|
|
@@ -398,15 +514,18 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
398
514
|
readonly adapter?: Address;
|
|
399
515
|
readonly deadline?: bigint;
|
|
400
516
|
}): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
517
|
+
/** {@inheritDoc VaultV2Actions.forceWithdraw} */
|
|
518
|
+
forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, }: {
|
|
519
|
+
readonly exitAssets: bigint;
|
|
520
|
+
readonly vaultData: AccrualVaultV2;
|
|
521
|
+
readonly userAddress: Address;
|
|
522
|
+
readonly adapter?: Address;
|
|
523
|
+
readonly deadline?: bigint;
|
|
524
|
+
readonly slippageTolerance?: bigint;
|
|
525
|
+
readonly minSharePriceE27?: bigint;
|
|
526
|
+
readonly referralFeePct?: bigint;
|
|
527
|
+
readonly referralFeeRecipient?: Address;
|
|
528
|
+
}): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
410
529
|
forceRedeem({ deallocations, redeem, userAddress, }: {
|
|
411
530
|
deallocations: readonly Deallocation[];
|
|
412
531
|
redeem: {
|