@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.2
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 +329 -15
- package/README.md +93 -47
- package/lib/cjs/abis.d.ts +227 -2
- package/lib/cjs/abis.js +156 -3
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +28 -162
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +3 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +230 -0
- package/lib/cjs/actions/bundles/common.js +507 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
- package/lib/cjs/actions/requirements/blue/index.js +0 -2
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- 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 +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +8 -2
- package/lib/cjs/blue/entities.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +3 -1
- package/lib/cjs/blue/fetch.js +1 -0
- package/lib/cjs/entities/blue/blue.d.ts +29 -20
- package/lib/cjs/entities/blue/blue.js +6 -1
- package/lib/cjs/entities/index.d.ts +9 -2
- package/lib/cjs/entities/index.js +16 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
- package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +2 -0
- package/lib/cjs/entities/requirements/index.js +18 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/fetch.d.ts +3 -1
- package/lib/cjs/fetch.js +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +14 -1
- 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/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +136 -1
- package/lib/cjs/helpers/slippage.js +188 -0
- package/lib/cjs/helpers/validate.d.ts +67 -8
- package/lib/cjs/helpers/validate.js +94 -9
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +273 -82
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +349 -23
- package/lib/cjs/types/error.js +393 -39
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +10 -1
- package/lib/esm/abis.d.ts +227 -2
- package/lib/esm/abis.js +157 -2
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +30 -164
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +5 -10
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +230 -0
- package/lib/esm/actions/bundles/common.js +494 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
- package/lib/esm/actions/requirements/blue/index.js +0 -2
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- 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 +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +8 -2
- package/lib/esm/blue/entities.js +3 -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 +3 -1
- package/lib/esm/blue/fetch.js +3 -1
- package/lib/esm/entities/blue/blue.d.ts +29 -20
- package/lib/esm/entities/blue/blue.js +7 -2
- package/lib/esm/entities/index.d.ts +9 -2
- package/lib/esm/entities/index.js +4 -1
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
- package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +2 -0
- package/lib/esm/entities/requirements/index.js +2 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/fetch.d.ts +3 -1
- package/lib/esm/fetch.js +3 -1
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- 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/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +136 -1
- package/lib/esm/helpers/slippage.js +186 -2
- package/lib/esm/helpers/validate.d.ts +67 -8
- package/lib/esm/helpers/validate.js +92 -10
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +273 -82
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +349 -23
- package/lib/esm/types/error.js +377 -31
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -7
|
@@ -6,9 +6,16 @@ const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
7
|
const viem_1 = require("viem");
|
|
8
8
|
const actions_1 = require("viem/actions");
|
|
9
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
9
10
|
const index_js_1 = require("../../actions/index.js");
|
|
10
11
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
11
13
|
const index_js_3 = require("../../types/index.js");
|
|
14
|
+
const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
|
|
15
|
+
const index_js_4 = require("../requirements/index.js");
|
|
16
|
+
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
17
|
+
// accrual model stays well-defined inside it.
|
|
18
|
+
const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
|
|
12
19
|
class MorphoVaultV2 {
|
|
13
20
|
client;
|
|
14
21
|
vault;
|
|
@@ -30,104 +37,242 @@ class MorphoVaultV2 {
|
|
|
30
37
|
deployless: this.client.options.supportDeployless,
|
|
31
38
|
});
|
|
32
39
|
}
|
|
33
|
-
|
|
40
|
+
/** {@inheritDoc VaultV2Actions.deposit} */
|
|
41
|
+
deposit(params) {
|
|
42
|
+
const { userAddress, vaultData } = params;
|
|
43
|
+
const { asset: vaultAsset } = vaultData;
|
|
34
44
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
35
45
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
36
46
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.asset, wNative)) {
|
|
54
|
-
throw new index_js_3.NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
58
|
-
if (totalAssets === 0n) {
|
|
59
|
-
throw new index_js_3.NonPositiveInputError("totalAssets", totalAssets);
|
|
60
|
-
}
|
|
61
|
-
// Accrue interest forward to bound the on-chain share price at execution.
|
|
62
|
-
// Mirrors blue repay's 2h forward-accrual buffer.
|
|
63
|
-
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), vaultData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
|
|
64
|
-
const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
|
|
65
|
-
const shares = accruedVault.toShares(totalAssets);
|
|
66
|
-
if (shares <= 0n) {
|
|
67
|
-
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
48
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
49
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
50
|
+
if (deadline <= createdAt)
|
|
51
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
52
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
53
|
+
deadline,
|
|
54
|
+
referralFeePct: params.referralFeePct,
|
|
55
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
56
|
+
});
|
|
57
|
+
const funding = (0, common_js_1.resolveBundlesFunding)(params);
|
|
58
|
+
// Reject overflow before share-price math or native-only prerequisite resolution.
|
|
59
|
+
(0, validate_js_1.validateUint256Field)(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
|
|
60
|
+
if (funding.value > 0n) {
|
|
61
|
+
// The native path must target the chain's registered wrapped-native asset.
|
|
62
|
+
(0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
|
|
68
63
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
64
|
+
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
|
|
65
|
+
const maxSharePrice = (0, index_js_2.computeVaultMaxSharePrice)({
|
|
66
|
+
vaultData,
|
|
67
|
+
deadline,
|
|
68
|
+
assets: funding.assets - referralFeeAssets,
|
|
69
|
+
slippageTolerance: params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
70
|
+
});
|
|
71
|
+
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
72
|
+
let pendingRequirements;
|
|
73
|
+
let expectedRequirement;
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
getRequirements: async (requirementOptions) => {
|
|
76
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
77
|
+
if (deadline <= now)
|
|
78
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
79
|
+
if (pendingRequirements != null)
|
|
80
|
+
return await pendingRequirements;
|
|
81
|
+
// Memoize the in-flight promise, not just its result: concurrent callers
|
|
82
|
+
// requesting different routes would otherwise both resolve requirements and
|
|
83
|
+
// the slower one would overwrite `expectedRequirement`, making `buildTx()`
|
|
84
|
+
// reject the signature returned by the other call.
|
|
85
|
+
const pending = (async () => {
|
|
86
|
+
const requirements = funding.value > 0n
|
|
87
|
+
? []
|
|
88
|
+
: await (0, index_js_4.getBundlesTokenRequirements)(this.client.viemClient, {
|
|
89
|
+
token: vaultAsset,
|
|
90
|
+
spender,
|
|
91
|
+
amount: funding.assets,
|
|
92
|
+
owner: userAddress,
|
|
93
|
+
chainId: this.chainId,
|
|
94
|
+
deadline,
|
|
95
|
+
supportSignature: this.client.options.supportSignature,
|
|
96
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
97
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
98
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
99
|
+
});
|
|
100
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
101
|
+
expectedRequirement =
|
|
102
|
+
signatureRequirement?.action.type === "permit" ||
|
|
103
|
+
signatureRequirement?.action.type === "permit2SignatureTransfer"
|
|
104
|
+
? signatureRequirement.action
|
|
105
|
+
: undefined;
|
|
106
|
+
return requirements;
|
|
107
|
+
})();
|
|
108
|
+
pendingRequirements = pending;
|
|
109
|
+
try {
|
|
110
|
+
return await pending;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
// Later calls must re-read live allowances/nonces and honor their own options.
|
|
114
|
+
if (pendingRequirements === pending)
|
|
115
|
+
pendingRequirements = undefined;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
82
118
|
buildTx: (signatures) => {
|
|
83
|
-
const
|
|
84
|
-
permit: true,
|
|
85
|
-
});
|
|
119
|
+
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signatures, expectedRequirement);
|
|
86
120
|
return (0, index_js_1.vaultV2Deposit)({
|
|
87
121
|
vault: {
|
|
88
122
|
chainId: this.chainId,
|
|
89
123
|
address: this.vault,
|
|
90
|
-
asset:
|
|
124
|
+
asset: vaultAsset,
|
|
91
125
|
},
|
|
92
126
|
args: {
|
|
93
|
-
|
|
127
|
+
...(funding.value > 0n
|
|
128
|
+
? { nativeAmount: funding.assets }
|
|
129
|
+
: { amount: funding.assets }),
|
|
94
130
|
maxSharePrice,
|
|
95
|
-
|
|
96
|
-
requirementSignature
|
|
97
|
-
|
|
131
|
+
userAddress,
|
|
132
|
+
requirementSignature,
|
|
133
|
+
referralFeePct: common.referralFeePct,
|
|
134
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
135
|
+
deadline,
|
|
98
136
|
},
|
|
99
137
|
metadata: this.client.options.metadata,
|
|
100
138
|
});
|
|
101
139
|
},
|
|
102
|
-
};
|
|
140
|
+
});
|
|
103
141
|
}
|
|
104
|
-
withdraw(
|
|
142
|
+
withdraw(params) {
|
|
143
|
+
const { amount, userAddress } = params;
|
|
105
144
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
145
|
+
if (amount <= 0n)
|
|
146
|
+
throw new index_js_3.NonPositiveInputError("amount", amount);
|
|
147
|
+
// Reject values outside the ABI range before resolving any requirements.
|
|
148
|
+
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
149
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
150
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
151
|
+
if (deadline <= createdAt)
|
|
152
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
153
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
154
|
+
deadline,
|
|
155
|
+
referralFeePct: params.referralFeePct,
|
|
156
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
157
|
+
});
|
|
158
|
+
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
159
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
160
|
+
// Fail eagerly if VaultBundlesV1 is unavailable; only validation is needed here.
|
|
161
|
+
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
162
|
+
let requiredShareAllowance;
|
|
163
|
+
let vaultSnapshot;
|
|
164
|
+
let expectedRequirement;
|
|
165
|
+
return Object.freeze({
|
|
166
|
+
getRequirements: async () => {
|
|
167
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
168
|
+
if (deadline <= now)
|
|
169
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
170
|
+
// Re-read the live share allowance on every call instead of caching the resolved
|
|
171
|
+
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
172
|
+
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
173
|
+
// raised afterwards must resurface as an outstanding requirement. Only the vault snapshot
|
|
174
|
+
// and the cap derived from it are pinned, so re-reading cannot move the cap this handle
|
|
175
|
+
// already committed to; the snapshot is used for immutable identity and permit-domain
|
|
176
|
+
// fields only.
|
|
177
|
+
const vaultData = (vaultSnapshot ??= await this.getData());
|
|
178
|
+
requiredShareAllowance ??= (0, index_js_2.computeVaultMaxShareAllowance)({
|
|
179
|
+
vaultData,
|
|
180
|
+
deadline,
|
|
181
|
+
assets: amount,
|
|
182
|
+
slippageTolerance,
|
|
183
|
+
});
|
|
184
|
+
const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
185
|
+
vaultData,
|
|
186
|
+
version: "vaultV2",
|
|
187
|
+
owner: userAddress,
|
|
188
|
+
chainId: this.chainId,
|
|
189
|
+
requiredShareAllowance,
|
|
190
|
+
deadline,
|
|
191
|
+
supportSignature: this.client.options.supportSignature,
|
|
192
|
+
});
|
|
193
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
194
|
+
if (signatureRequirement?.action.type === "permit") {
|
|
195
|
+
expectedRequirement = signatureRequirement.action;
|
|
196
|
+
}
|
|
197
|
+
return requirements;
|
|
198
|
+
},
|
|
199
|
+
buildTx: (signatures) => {
|
|
200
|
+
const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
|
|
201
|
+
requiredShareAllowance,
|
|
202
|
+
expectedRequirement,
|
|
203
|
+
});
|
|
204
|
+
return (0, index_js_1.vaultV2Withdraw)({
|
|
205
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
206
|
+
args: {
|
|
207
|
+
amount,
|
|
208
|
+
userAddress,
|
|
209
|
+
requirementSignature: permit,
|
|
210
|
+
referralFeePct: common.referralFeePct,
|
|
211
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
212
|
+
deadline,
|
|
213
|
+
},
|
|
214
|
+
metadata: this.client.options.metadata,
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
});
|
|
117
218
|
}
|
|
118
|
-
|
|
219
|
+
/** {@inheritDoc VaultV2Actions.redeem} */
|
|
220
|
+
redeem(params) {
|
|
119
221
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
222
|
+
const { shares, userAddress } = params;
|
|
223
|
+
if (shares <= 0n)
|
|
224
|
+
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
225
|
+
const createdAt = morpho_ts_1.Time.timestamp();
|
|
226
|
+
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
227
|
+
if (deadline <= createdAt)
|
|
228
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
229
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
230
|
+
deadline,
|
|
231
|
+
referralFeePct: params.referralFeePct,
|
|
232
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
233
|
+
});
|
|
234
|
+
(0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
235
|
+
let expectedRequirement;
|
|
236
|
+
return Object.freeze({
|
|
237
|
+
getRequirements: async () => {
|
|
238
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
239
|
+
if (deadline <= now)
|
|
240
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
241
|
+
const requirements = await (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
242
|
+
vaultData: await this.getData(),
|
|
243
|
+
version: "vaultV2",
|
|
244
|
+
owner: userAddress,
|
|
245
|
+
chainId: this.chainId,
|
|
246
|
+
requiredShareAllowance: shares,
|
|
247
|
+
deadline,
|
|
248
|
+
supportSignature: this.client.options.supportSignature,
|
|
249
|
+
});
|
|
250
|
+
const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
|
|
251
|
+
expectedRequirement =
|
|
252
|
+
signatureRequirement?.action.type === "permit"
|
|
253
|
+
? signatureRequirement.action
|
|
254
|
+
: undefined;
|
|
255
|
+
return requirements;
|
|
256
|
+
},
|
|
257
|
+
buildTx: (signatures) => {
|
|
258
|
+
const permit = (0, common_js_1.selectBundlesSharesRequirementSignature)(signatures, {
|
|
259
|
+
requiredShareAllowance: shares,
|
|
260
|
+
expectedRequirement,
|
|
261
|
+
});
|
|
262
|
+
return (0, index_js_1.vaultV2Redeem)({
|
|
263
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
264
|
+
args: {
|
|
265
|
+
shares,
|
|
266
|
+
userAddress,
|
|
267
|
+
requirementSignature: permit,
|
|
268
|
+
referralFeePct: common.referralFeePct,
|
|
269
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
270
|
+
deadline,
|
|
271
|
+
},
|
|
272
|
+
metadata: this.client.options.metadata,
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
});
|
|
131
276
|
}
|
|
132
277
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
133
278
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }) {
|
|
@@ -147,21 +292,24 @@ class MorphoVaultV2 {
|
|
|
147
292
|
const marketIdListSnapshot = marketParamsListSnapshot.map((marketParams) => blue_sdk_1.MarketUtils.getMarketId(marketParams));
|
|
148
293
|
const now = morpho_ts_1.Time.timestamp();
|
|
149
294
|
const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
|
|
295
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
296
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
297
|
+
(0, validate_js_1.validateDeadline)(deadline);
|
|
150
298
|
if (deadline <= now)
|
|
151
299
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
152
300
|
if (vaultData.accrualAdapters.length !== 1) {
|
|
153
|
-
throw new index_js_3.
|
|
301
|
+
throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, vaultData.accrualAdapters.length);
|
|
154
302
|
}
|
|
155
303
|
const soleAdapter = vaultData.accrualAdapters[0];
|
|
156
304
|
if (soleAdapter == null) {
|
|
157
|
-
throw new index_js_3.
|
|
305
|
+
throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, 0);
|
|
158
306
|
}
|
|
159
307
|
const adapter = adapterOverride ?? soleAdapter.address;
|
|
160
308
|
if (!(0, viem_1.isAddressEqual)(adapter, soleAdapter.address)) {
|
|
161
309
|
throw new index_js_3.AdapterNotPartOfVaultError(this.vault, adapter);
|
|
162
310
|
}
|
|
163
311
|
if (!(soleAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2)) {
|
|
164
|
-
throw new index_js_3.
|
|
312
|
+
throw new index_js_3.VaultV2UnsupportedExitAdapterError(adapter);
|
|
165
313
|
}
|
|
166
314
|
const penalty = vaultData.forceDeallocatePenalties[soleAdapter.address] ?? 0n;
|
|
167
315
|
const idleAssets = blue_sdk_1.MathLib.min(vaultData.assetBalance, amount);
|
|
@@ -176,7 +324,9 @@ class MorphoVaultV2 {
|
|
|
176
324
|
if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
|
|
177
325
|
throw new index_js_3.EmptyMarketParamsListError();
|
|
178
326
|
}
|
|
179
|
-
const assetsByMarket = new Map(soleAdapter.markets
|
|
327
|
+
const assetsByMarket = new Map(soleAdapter.markets
|
|
328
|
+
.filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
|
|
329
|
+
.map((market) => [
|
|
180
330
|
market.id,
|
|
181
331
|
market
|
|
182
332
|
.accrueInterest(now)
|
|
@@ -307,21 +457,226 @@ class MorphoVaultV2 {
|
|
|
307
457
|
},
|
|
308
458
|
};
|
|
309
459
|
}
|
|
310
|
-
|
|
460
|
+
/** {@inheritDoc VaultV2Actions.forceWithdraw} */
|
|
461
|
+
forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, }) {
|
|
311
462
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
463
|
+
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
464
|
+
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
465
|
+
}
|
|
466
|
+
if (exitAssets <= 0n)
|
|
467
|
+
throw new index_js_3.NonPositiveInputError("exitAssets", exitAssets);
|
|
468
|
+
(0, validate_js_1.validateUint256Field)("exitAssets", exitAssets);
|
|
469
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
470
|
+
// Called for its throws only: the raw pair is forwarded to the action, which normalizes it
|
|
471
|
+
// again on the encode path so a direct action caller gets the same guarantees.
|
|
472
|
+
(0, validate_js_1.validateReferralFee)({ referralFeePct, referralFeeRecipient });
|
|
473
|
+
if (minSharePriceE27Override != null) {
|
|
474
|
+
// An unbounded override reopens the exact hole this path closes: the contract reads
|
|
475
|
+
// `minSharePriceE27 == 0` as "no bound".
|
|
476
|
+
if (minSharePriceE27Override <= 0n) {
|
|
477
|
+
throw new index_js_3.NonPositiveInputError("minSharePriceE27", minSharePriceE27Override);
|
|
478
|
+
}
|
|
479
|
+
// And an override the uint256 slot cannot hold must fail here rather than after
|
|
480
|
+
// `getRequirements()` has already asked for an approval or a permit signature.
|
|
481
|
+
(0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27Override);
|
|
482
|
+
}
|
|
483
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
484
|
+
const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
|
|
485
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
486
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
487
|
+
(0, validate_js_1.validateDeadline)(deadline);
|
|
488
|
+
if (deadline <= now)
|
|
489
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
490
|
+
const maxDeadline = now + VAULT_V2_FEE_PROJECTION_HORIZON;
|
|
491
|
+
if (deadline > maxDeadline) {
|
|
492
|
+
throw new index_js_3.InputExceedsMaxError({
|
|
493
|
+
field: "deadline",
|
|
494
|
+
value: deadline,
|
|
495
|
+
max: maxDeadline,
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
const eligibility = (0, index_js_2.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
|
|
499
|
+
switch (eligibility.type) {
|
|
500
|
+
case "eligible":
|
|
501
|
+
break;
|
|
502
|
+
case "adapterCount":
|
|
503
|
+
throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, eligibility.adapters);
|
|
504
|
+
case "adapterMismatch":
|
|
505
|
+
throw new index_js_3.AdapterNotPartOfVaultError(this.vault, eligibility.adapter);
|
|
506
|
+
case "unsupportedAdapter":
|
|
507
|
+
throw new index_js_3.VaultV2UnsupportedExitAdapterError(eligibility.adapter);
|
|
508
|
+
case "unsupportedLiquidityAdapter":
|
|
509
|
+
throw new index_js_3.VaultV2UnsupportedLiquidityAdapterError({
|
|
510
|
+
vault: this.vault,
|
|
511
|
+
liquidityAdapter: eligibility.liquidityAdapter,
|
|
512
|
+
adapter: eligibility.adapter,
|
|
513
|
+
});
|
|
514
|
+
case "undecodableLiquidityData":
|
|
515
|
+
throw new index_js_3.VaultV2UndecodableLiquidityDataError({
|
|
516
|
+
vault: this.vault,
|
|
517
|
+
liquidityAdapter: eligibility.liquidityAdapter,
|
|
518
|
+
liquidityData: eligibility.liquidityData,
|
|
519
|
+
cause: eligibility.cause,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
const { adapter: accrualAdapter, liquidityMarketId } = eligibility;
|
|
523
|
+
const adapter = accrualAdapter.address;
|
|
524
|
+
const plan = (0, index_js_2.computeVaultV2ForceWithdrawPlan)({
|
|
525
|
+
vaultData,
|
|
526
|
+
adapter: accrualAdapter,
|
|
527
|
+
liquidityMarketId,
|
|
528
|
+
exitAssets,
|
|
529
|
+
timestamp: now,
|
|
530
|
+
});
|
|
531
|
+
if (plan.withdrawnAssets <= 0n) {
|
|
532
|
+
throw new index_js_3.VaultV2ForceWithdrawZeroWithdrawalError({
|
|
533
|
+
vault: this.vault,
|
|
534
|
+
exitAssets,
|
|
535
|
+
penalty: plan.penalty,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
// The contract's force-deallocation loop is unbounded: under-coverage panics on-chain.
|
|
539
|
+
if (plan.coveredAssets < plan.assetsToDeallocate) {
|
|
540
|
+
throw new index_js_3.VaultV2ForceWithdrawCoverageError({
|
|
541
|
+
required: plan.assetsToDeallocate,
|
|
542
|
+
covered: plan.coveredAssets,
|
|
543
|
+
maxExitAssets: plan.maxExitAssets,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
const projectionTimestamp = deadline;
|
|
547
|
+
// VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
|
|
548
|
+
// accrues the vault before burning. Use the `now` accrual for the floor and the projected
|
|
549
|
+
// deadline accrual for the fee-mint guard.
|
|
550
|
+
const { vault: nowVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(now, vaultData.lastUpdate));
|
|
551
|
+
const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(projectionTimestamp, vaultData.lastUpdate));
|
|
552
|
+
const sharesBurntNow = (0, index_js_2.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
553
|
+
vaultData: nowVaultData,
|
|
554
|
+
deadlineVaultData: nowVaultData,
|
|
555
|
+
plan,
|
|
556
|
+
});
|
|
557
|
+
const feeSharesNow = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
|
|
558
|
+
vaultData,
|
|
559
|
+
owner: userAddress,
|
|
560
|
+
timestamp: now,
|
|
561
|
+
});
|
|
562
|
+
const feeSharesProjected = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
|
|
563
|
+
vaultData,
|
|
564
|
+
owner: userAddress,
|
|
565
|
+
timestamp: projectionTimestamp,
|
|
566
|
+
});
|
|
567
|
+
const minSharesBurntProjected = (0, index_js_2.computeVaultV2ForceWithdrawMinSharesBurnt)({
|
|
568
|
+
vaultData: projectedVaultData,
|
|
569
|
+
plan,
|
|
570
|
+
});
|
|
571
|
+
// When fee shares are minted, the projected pair bounds every execution time in the window.
|
|
572
|
+
if (feeSharesProjected > 0n &&
|
|
573
|
+
feeSharesProjected >= minSharesBurntProjected) {
|
|
574
|
+
throw new index_js_3.VaultV2ForceWithdrawFeeSharesExceedBurnError({
|
|
575
|
+
vault: this.vault,
|
|
576
|
+
userAddress,
|
|
577
|
+
sharesBurnt: minSharesBurntProjected,
|
|
578
|
+
feeShares: feeSharesProjected,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
// sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
|
|
582
|
+
const netSharesBurntNow = sharesBurntNow - feeSharesNow;
|
|
583
|
+
const minSharePriceE27 = minSharePriceE27Override ??
|
|
584
|
+
(0, index_js_2.computeMinForceWithdrawSharePrice)({
|
|
585
|
+
withdrawnAssets: plan.withdrawnAssets,
|
|
586
|
+
sharesBurnt: netSharesBurntNow,
|
|
587
|
+
slippageTolerance,
|
|
588
|
+
});
|
|
589
|
+
// The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
|
|
590
|
+
// lowering a lower bound weakens it, so any vault whose share price grew past that would be left
|
|
591
|
+
// with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
|
|
592
|
+
// only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
|
|
593
|
+
//
|
|
594
|
+
// It still has to fit the ABI slot though. Defense-in-depth rather than a reachable input error:
|
|
595
|
+
// with `exitAssets` bounded above, the derived floor only exceeds `uint256` on a vault whose
|
|
596
|
+
// share price passed ~1e50 assets/share, which no fixture here can construct.
|
|
597
|
+
(0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27);
|
|
598
|
+
// VaultExitBundlesV1's burn bound includes fee shares minted by the first withdrawal. Add the
|
|
599
|
+
// projected fee shares to the price-floor ceiling so the approval covers that mint.
|
|
600
|
+
// Saturated at `maxUint256`: a tiny accepted floor scales this above the ABI slot, and the
|
|
601
|
+
// approval encoder clamps what it emits — so an uncapped requirement would sit permanently above
|
|
602
|
+
// any allowance the user can actually grant and `getRequirements()` would return the same
|
|
603
|
+
// approval forever. No account can hold or burn more shares than that anyway.
|
|
604
|
+
const requiredShareAllowance = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, minSharePriceE27) +
|
|
605
|
+
feeSharesProjected, viem_1.maxUint256);
|
|
606
|
+
const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
|
|
312
607
|
return {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
608
|
+
getRequirements: async () => {
|
|
609
|
+
const requirementsTimestamp = morpho_ts_1.Time.timestamp();
|
|
610
|
+
if (deadline <= requirementsTimestamp) {
|
|
611
|
+
throw new index_js_3.ExpiredDeadlineError(deadline, requirementsTimestamp);
|
|
612
|
+
}
|
|
613
|
+
// Vault gates are intentionally left to the final transaction: the receive-assets gate may
|
|
614
|
+
// inspect VaultExitBundlesV1's transient `initiator`, and a send-shares gate is arbitrary
|
|
615
|
+
// external code re-evaluated after each intermediate penalty burn, so neither is
|
|
616
|
+
// execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
|
|
617
|
+
// supplies into Morpho Blue, so no Blue token-balance check is needed.
|
|
618
|
+
const [allowance, nonce] = await (0, actions_1.multicall)(this.client.viemClient, {
|
|
619
|
+
allowFailure: false,
|
|
620
|
+
contracts: [
|
|
621
|
+
{
|
|
622
|
+
address: this.vault,
|
|
623
|
+
abi: viem_1.erc20Abi,
|
|
624
|
+
functionName: "allowance",
|
|
625
|
+
args: [userAddress, vaultExitBundlesV1],
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
address: this.vault,
|
|
629
|
+
abi: blue_sdk_viem_1.erc2612Abi,
|
|
630
|
+
functionName: "nonces",
|
|
631
|
+
args: [userAddress],
|
|
632
|
+
},
|
|
633
|
+
],
|
|
634
|
+
});
|
|
635
|
+
if (allowance >= requiredShareAllowance)
|
|
636
|
+
return [];
|
|
637
|
+
if (this.client.options.supportSignature) {
|
|
638
|
+
const requirement = (0, index_js_1.encodeVaultSharesPermit)({
|
|
639
|
+
vault: vaultData,
|
|
640
|
+
version: "vaultV2",
|
|
641
|
+
spender: vaultExitBundlesV1,
|
|
642
|
+
owner: userAddress,
|
|
643
|
+
chainId: this.chainId,
|
|
644
|
+
nonce,
|
|
645
|
+
amount: requiredShareAllowance,
|
|
646
|
+
deadline,
|
|
647
|
+
});
|
|
648
|
+
return [requirement];
|
|
649
|
+
}
|
|
650
|
+
return [
|
|
651
|
+
(0, index_js_1.encodeErc20Approval)({
|
|
652
|
+
token: this.vault,
|
|
653
|
+
spender: vaultExitBundlesV1,
|
|
654
|
+
amount: requiredShareAllowance,
|
|
655
|
+
chainId: this.chainId,
|
|
656
|
+
}),
|
|
657
|
+
];
|
|
658
|
+
},
|
|
659
|
+
buildTx: (signatures) => {
|
|
660
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
661
|
+
spender: vaultExitBundlesV1,
|
|
662
|
+
amount: requiredShareAllowance,
|
|
663
|
+
deadline,
|
|
664
|
+
});
|
|
665
|
+
return (0, index_js_1.vaultV2ForceWithdraw)({
|
|
666
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
667
|
+
args: {
|
|
668
|
+
adapter,
|
|
669
|
+
exitAssets,
|
|
670
|
+
minSharePriceE27,
|
|
671
|
+
userAddress,
|
|
672
|
+
deadline,
|
|
673
|
+
referralFeePct,
|
|
674
|
+
referralFeeRecipient,
|
|
675
|
+
requirementSignature: permit,
|
|
320
676
|
},
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
}),
|
|
677
|
+
metadata: this.client.options.metadata,
|
|
678
|
+
});
|
|
679
|
+
},
|
|
325
680
|
};
|
|
326
681
|
}
|
|
327
682
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
@@ -363,7 +363,11 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
363
363
|
* utilization defaults to 90% and is configurable through
|
|
364
364
|
* `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
|
|
365
365
|
* `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
|
|
366
|
-
* considered.
|
|
366
|
+
* considered. Targets with no remaining supply or allocator capacity are skipped before
|
|
367
|
+
* projecting source interest. The adapter's minimum share minting requirement, supply-share
|
|
368
|
+
* limits, and target absolute or zero relative caps are checked against a one-asset deposit.
|
|
369
|
+
* Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
|
|
370
|
+
* allocation does not increase after rounding.
|
|
367
371
|
*
|
|
368
372
|
* Shared-cap discovery is conservative. Operation planning searches at most
|
|
369
373
|
* 1,024 base units above its targeted amount for the nearest executable fit.
|
|
@@ -374,6 +378,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
374
378
|
* @param marketId - Target Blue market id.
|
|
375
379
|
* @param options - Optional discovery controls and operation to support.
|
|
376
380
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
381
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
377
382
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
378
383
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
379
384
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
@@ -430,6 +435,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
430
435
|
* @param marketId - Target Blue market id.
|
|
431
436
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
432
437
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
438
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
433
439
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
434
440
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
435
441
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -470,6 +476,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
470
476
|
* @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
|
|
471
477
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
472
478
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
479
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
473
480
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
474
481
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
475
482
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|