@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
|
@@ -10,14 +10,15 @@ const index_js_1 = require("../../actions/bundles/index.js");
|
|
|
10
10
|
const encodeErc20Permit_js_1 = require("../../actions/requirements/encode/encodeErc20Permit.js");
|
|
11
11
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
12
|
const index_js_3 = require("../../types/index.js");
|
|
13
|
+
const getUnusedPermit2Nonce_js_1 = require("./getUnusedPermit2Nonce.js");
|
|
13
14
|
/**
|
|
14
15
|
* Resolves direct approval, ERC-2612, or Permit2 SignatureTransfer prerequisites for
|
|
15
16
|
* a registered fixed bundles contract.
|
|
16
17
|
*
|
|
17
18
|
* Reads only the allowance and nonce state required by the selected path. Permit2 keeps the
|
|
18
19
|
* ERC-20 allowance on canonical Permit2 while the one-time signed transfer names the bundles contract
|
|
19
|
-
* as spender.
|
|
20
|
-
*
|
|
20
|
+
* as spender. The resolver picks the lowest unused unordered nonce by default; concurrent flows for
|
|
21
|
+
* the same owner should pass explicit nonces.
|
|
21
22
|
*
|
|
22
23
|
* @param viemClient - Connected viem client used for allowance and nonce reads.
|
|
23
24
|
* @param params - Token requirement parameters.
|
|
@@ -31,7 +32,8 @@ const index_js_3 = require("../../types/index.js");
|
|
|
31
32
|
* @param params.supportSignature - Whether ERC-2612 or Permit2 signatures may be requested.
|
|
32
33
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
33
34
|
* @param params.useSimplePermit - Prefer ERC-2612 when its nonce probe succeeds.
|
|
34
|
-
* @param params.permit2Nonce - Explicit unused uint256 nonce
|
|
35
|
+
* @param params.permit2Nonce - Explicit unused uint256 nonce; defaults to the lowest unused nonce
|
|
36
|
+
* found via {@link getUnusedPermit2Nonce}.
|
|
35
37
|
* @returns Ordered deep-frozen approval transactions and/or signable token requirements.
|
|
36
38
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
37
39
|
* @throws {NegativeInputError} when `amount` or `permit2Nonce` is negative.
|
|
@@ -40,7 +42,8 @@ const index_js_3 = require("../../types/index.js");
|
|
|
40
42
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
41
43
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` is not the chain's registered
|
|
42
44
|
* BlueBundlesV1 or VaultBundlesV1 deployment, including for a zero-amount request.
|
|
43
|
-
* @throws {
|
|
45
|
+
* @throws {NoUnusedPermit2NonceError} when every Permit2 nonce for the owner is consumed and none
|
|
46
|
+
* was passed explicitly.
|
|
44
47
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} when `permit2Nonce` is already consumed.
|
|
45
48
|
* @throws {InputExceedsMaxError} when `amount`, `deadline`, or `permit2Nonce` exceeds uint256.
|
|
46
49
|
* @throws {ApprovalAmountLessThanSpendAmountError} when `approvalAmount` is below `amount`.
|
|
@@ -64,7 +67,6 @@ const index_js_3 = require("../../types/index.js");
|
|
|
64
67
|
* chainId: mainnet.id,
|
|
65
68
|
* deadline: 1_900_000_000n,
|
|
66
69
|
* supportSignature: true,
|
|
67
|
-
* permit2Nonce: 42n,
|
|
68
70
|
* });
|
|
69
71
|
* // requirements contains approvals and/or signable bundles token requirements.
|
|
70
72
|
* ```
|
|
@@ -121,6 +123,7 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
121
123
|
return [
|
|
122
124
|
await (0, encodeErc20Permit_js_1.encodeErc20Permit)(viemClient, {
|
|
123
125
|
token: params.token,
|
|
126
|
+
owner: params.owner,
|
|
124
127
|
spender: params.spender,
|
|
125
128
|
amount: params.amount,
|
|
126
129
|
chainId: params.chainId,
|
|
@@ -132,20 +135,22 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
if (permit2 != null) {
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
const permit2Nonce = params.permit2Nonce ??
|
|
139
|
+
(await (0, getUnusedPermit2Nonce_js_1.getUnusedPermit2Nonce)(viemClient, {
|
|
140
|
+
owner: params.owner,
|
|
141
|
+
chainId: params.chainId,
|
|
142
|
+
}));
|
|
143
|
+
if (permit2Nonce < 0n) {
|
|
144
|
+
throw new index_js_3.NegativeInputError("permit2Nonce", permit2Nonce);
|
|
137
145
|
}
|
|
138
|
-
if (
|
|
139
|
-
throw new index_js_3.NegativeInputError("permit2Nonce", params.permit2Nonce);
|
|
140
|
-
}
|
|
141
|
-
if (params.permit2Nonce > viem_1.maxUint256) {
|
|
146
|
+
if (permit2Nonce > viem_1.maxUint256) {
|
|
142
147
|
throw new index_js_3.InputExceedsMaxError({
|
|
143
148
|
field: "permit2Nonce",
|
|
144
|
-
value:
|
|
149
|
+
value: permit2Nonce,
|
|
145
150
|
max: viem_1.maxUint256,
|
|
146
151
|
});
|
|
147
152
|
}
|
|
148
|
-
const wordPosition =
|
|
153
|
+
const wordPosition = permit2Nonce >> 8n;
|
|
149
154
|
const [allowance, nonceBitmap] = await Promise.all([
|
|
150
155
|
(0, actions_1.readContract)(viemClient, {
|
|
151
156
|
abi: viem_1.erc20Abi,
|
|
@@ -170,7 +175,7 @@ const getBundlesTokenRequirements = async (viemClient, params) => {
|
|
|
170
175
|
state: {
|
|
171
176
|
type: "permit2SignatureTransfer",
|
|
172
177
|
permit2Allowance: allowance,
|
|
173
|
-
permit2Nonce
|
|
178
|
+
permit2Nonce,
|
|
174
179
|
nonceBitmap,
|
|
175
180
|
},
|
|
176
181
|
});
|
package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js
RENAMED
|
@@ -5,9 +5,9 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const actions_1 = require("viem/actions");
|
|
8
|
-
const index_js_1 = require("
|
|
9
|
-
const validate_js_1 = require("
|
|
10
|
-
const index_js_2 = require("
|
|
8
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
10
|
+
const index_js_2 = require("../../types/index.js");
|
|
11
11
|
/** Highest Permit2 nonce-bitmap word index; each word covers 256 unordered nonces. */
|
|
12
12
|
const MAX_PERMIT2_NONCE_WORD = viem_1.maxUint256 >> 8n;
|
|
13
13
|
/**
|
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./getBundlesTokenRequirements.js"), exports);
|
|
18
|
+
__exportStar(require("./getUnusedPermit2Nonce.js"), exports);
|
|
@@ -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;
|
|
@@ -30,7 +30,6 @@ class MorphoVaultV1 {
|
|
|
30
30
|
}
|
|
31
31
|
return (0, blue_sdk_viem_1.fetchAccrualVault)(this.vault, this.client.viemClient, {
|
|
32
32
|
...parameters,
|
|
33
|
-
chainId: this.chainId,
|
|
34
33
|
deployless: this.client.options.supportDeployless,
|
|
35
34
|
});
|
|
36
35
|
}
|
|
@@ -290,11 +289,13 @@ class MorphoVaultV1 {
|
|
|
290
289
|
}));
|
|
291
290
|
const now = morpho_ts_1.Time.timestamp();
|
|
292
291
|
const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
|
|
292
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
293
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
294
|
+
(0, validate_js_1.validateDeadline)(deadline);
|
|
293
295
|
if (deadline <= now)
|
|
294
296
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
295
297
|
const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
|
|
296
|
-
const
|
|
297
|
-
const blue = addresses.blue ?? addresses.morpho;
|
|
298
|
+
const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
|
|
298
299
|
let covered = 0n;
|
|
299
300
|
const assignedByMarket = new Map();
|
|
300
301
|
for (const marketParams of marketParamsListSnapshot) {
|
|
@@ -304,6 +305,8 @@ class MorphoVaultV1 {
|
|
|
304
305
|
const allocation = vaultData.allocations.get(marketId);
|
|
305
306
|
if (allocation?.config.enabled !== true)
|
|
306
307
|
continue;
|
|
308
|
+
if (allocation.position.supplyShares === 0n)
|
|
309
|
+
continue;
|
|
307
310
|
const market = allocation.position.market.accrueInterest(now);
|
|
308
311
|
const available = market.toSupplyAssets(allocation.position.supplyShares);
|
|
309
312
|
const assigned = assignedByMarket.get(marketId) ?? 0n;
|
|
@@ -390,9 +393,14 @@ class MorphoVaultV1 {
|
|
|
390
393
|
required: amount,
|
|
391
394
|
});
|
|
392
395
|
}
|
|
393
|
-
|
|
396
|
+
// In-kind withdrawals carry no onchain share cap, so the allowance itself is the cap. A
|
|
397
|
+
// larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`.
|
|
398
|
+
if (allowance === requiredShareAllowance)
|
|
394
399
|
return [];
|
|
395
|
-
|
|
400
|
+
// A lowering permit can be skipped after its nonce is consumed, so oversized allowances
|
|
401
|
+
// must be reset with an onchain approval.
|
|
402
|
+
if (allowance < requiredShareAllowance &&
|
|
403
|
+
this.client.options.supportSignature) {
|
|
396
404
|
return [
|
|
397
405
|
(0, index_js_1.encodeVaultSharesPermit)({
|
|
398
406
|
vault: vaultData,
|
|
@@ -416,8 +424,10 @@ class MorphoVaultV1 {
|
|
|
416
424
|
];
|
|
417
425
|
},
|
|
418
426
|
buildTx: (signatures) => {
|
|
419
|
-
const
|
|
420
|
-
|
|
427
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
428
|
+
spender: vaultExitBundlesV1,
|
|
429
|
+
amount: requiredShareAllowance,
|
|
430
|
+
deadline,
|
|
421
431
|
});
|
|
422
432
|
return (0, index_js_1.vaultV1InKindRedeem)({
|
|
423
433
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -433,6 +443,7 @@ class MorphoVaultV1 {
|
|
|
433
443
|
},
|
|
434
444
|
};
|
|
435
445
|
}
|
|
446
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
436
447
|
migrateToV2(params) {
|
|
437
448
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
438
449
|
if (!(0, viem_1.isAddressEqual)(params.sourceVault.address, this.vault)) {
|
|
@@ -464,7 +475,13 @@ class MorphoVaultV1 {
|
|
|
464
475
|
referralFeePct: params.referralFeePct,
|
|
465
476
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
466
477
|
});
|
|
467
|
-
|
|
478
|
+
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
479
|
+
const grossAssets = assets ??
|
|
480
|
+
params.sourceVault
|
|
481
|
+
.accrueInterest(params.sourceVault.allocations
|
|
482
|
+
.values()
|
|
483
|
+
.reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), createdAt))
|
|
484
|
+
.toAssets(shares ?? 0n, "Down");
|
|
468
485
|
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(grossAssets, common.referralFeePct);
|
|
469
486
|
const maxSharePriceVaultV2 = (0, index_js_2.computeVaultMaxSharePrice)({
|
|
470
487
|
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: {
|