@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
|
@@ -107,7 +107,11 @@ const cloneAdapter = (adapter, markets) => {
|
|
|
107
107
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter)
|
|
108
108
|
return new blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter({ ...base, marketParamsList: [...adapter.marketParamsList] }, adapter.positions.map((position) => clonePosition(position, markets)));
|
|
109
109
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter)
|
|
110
|
-
return new blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter({
|
|
110
|
+
return new blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter({
|
|
111
|
+
...base,
|
|
112
|
+
morphoVaultV1: adapter.morphoVaultV1,
|
|
113
|
+
parentAllocation: adapter.parentAllocation,
|
|
114
|
+
}, cloneAccrualVault(adapter.accrualVaultV1, markets), adapter.shares);
|
|
111
115
|
throw new blue_sdk_1.UnsupportedVaultV2AdapterError(adapter.address);
|
|
112
116
|
};
|
|
113
117
|
const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
|
|
@@ -571,7 +575,11 @@ class VaultV2BlueReallocationData {
|
|
|
571
575
|
* utilization defaults to 90% and is configurable through
|
|
572
576
|
* `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
|
|
573
577
|
* `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
|
|
574
|
-
* considered.
|
|
578
|
+
* considered. Targets with no remaining supply or allocator capacity are skipped before
|
|
579
|
+
* projecting source interest. The adapter's minimum share minting requirement, supply-share
|
|
580
|
+
* limits, and target absolute or zero relative caps are checked against a one-asset deposit.
|
|
581
|
+
* Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
|
|
582
|
+
* allocation does not increase after rounding.
|
|
575
583
|
*
|
|
576
584
|
* Shared-cap discovery is conservative. Operation planning searches at most
|
|
577
585
|
* 1,024 base units above its targeted amount for the nearest executable fit.
|
|
@@ -582,6 +590,7 @@ class VaultV2BlueReallocationData {
|
|
|
582
590
|
* @param marketId - Target Blue market id.
|
|
583
591
|
* @param options - Optional discovery controls and operation to support.
|
|
584
592
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
593
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
585
594
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
586
595
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
587
596
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
@@ -722,9 +731,7 @@ class VaultV2BlueReallocationData {
|
|
|
722
731
|
: BigInt(options.timestamp);
|
|
723
732
|
let data = this;
|
|
724
733
|
let simulationContext = context;
|
|
725
|
-
data.setMarkets(
|
|
726
|
-
.filter((market) => market != null)
|
|
727
|
-
.map((market) => market.accrueInterest(timestamp)));
|
|
734
|
+
data.setMarkets([data.getMarket(marketId).accrueInterest(timestamp)]);
|
|
728
735
|
const reallocations = [];
|
|
729
736
|
const configuredVaults = Object.keys(data.vaults);
|
|
730
737
|
const vaultKeyByLower = new Map(configuredVaults.map((vault) => [vault.toLowerCase(), vault]));
|
|
@@ -759,6 +766,7 @@ class VaultV2BlueReallocationData {
|
|
|
759
766
|
activeAdaptersCache.set(vaultAddress, activeAdapters);
|
|
760
767
|
}
|
|
761
768
|
const targetSupplyHeadroom = blue_sdk_1.MathLib.zeroFloorSub(blue_sdk_1.MathLib.MAX_UINT_128, targetMarket.totalSupplyAssets);
|
|
769
|
+
const minimumSupply = targetMarket.supply(1n, 0n);
|
|
762
770
|
const rawCandidates = [];
|
|
763
771
|
// Missing nested allocator state means the snapshot is incomplete, so
|
|
764
772
|
// typed getter errors below must propagate. Only explicit zero caps or
|
|
@@ -780,17 +788,35 @@ class VaultV2BlueReallocationData {
|
|
|
780
788
|
const adapterCapAllocation = data.getAllocation(vaultAddress, adapterCapId);
|
|
781
789
|
const collateralCapAllocation = data.getAllocation(vaultAddress, collateralCapId);
|
|
782
790
|
const adapterMarketCapAllocation = data.getAllocation(vaultAddress, adapterMarketCapId);
|
|
783
|
-
|
|
791
|
+
const targetAllocations = [
|
|
784
792
|
adapterCapAllocation,
|
|
785
793
|
collateralCapAllocation,
|
|
786
794
|
adapterMarketCapAllocation,
|
|
787
|
-
]
|
|
795
|
+
];
|
|
796
|
+
if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
|
|
788
797
|
continue;
|
|
789
798
|
const expectedSupplyAssets = targetMarket.toSupplyAssets(adapter.supplyShares[marketId] ?? 0n);
|
|
790
799
|
const untracked = blue_sdk_1.MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
|
|
791
800
|
const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation + untracked);
|
|
801
|
+
const minimumAllocation = minimumSupply.market.toSupplyAssets((adapter.supplyShares[marketId] ?? 0n) + minimumSupply.shares);
|
|
802
|
+
const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
|
|
803
|
+
const blockedTargetIds = targetAllocations
|
|
804
|
+
.filter(({ allocation, absoluteCap, relativeCap }) => {
|
|
805
|
+
const nextAllocation = allocation + minimumAllocationChange;
|
|
806
|
+
return (nextAllocation > absoluteCap ||
|
|
807
|
+
(relativeCap === 0n && nextAllocation > 0n));
|
|
808
|
+
})
|
|
809
|
+
.map(({ id }) => id);
|
|
810
|
+
// MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
|
|
811
|
+
if (targetSupplyHeadroom === 0n ||
|
|
812
|
+
allocatorHeadroom === 0n ||
|
|
813
|
+
minimumSupply.shares < minimumSupply.assets ||
|
|
814
|
+
minimumSupply.market.totalSupplyShares > blue_sdk_1.MathLib.MAX_UINT_128 ||
|
|
815
|
+
blockedTargetIds.includes(adapterMarketCapId))
|
|
816
|
+
continue;
|
|
792
817
|
if (publicAllocatorConfig.canPullFromIdle &&
|
|
793
|
-
availableIdleAssets > 0n
|
|
818
|
+
availableIdleAssets > 0n &&
|
|
819
|
+
blockedTargetIds.length === 0) {
|
|
794
820
|
const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
|
|
795
821
|
if (assets > 0n) {
|
|
796
822
|
rawCandidates.push({
|
|
@@ -826,8 +852,16 @@ class VaultV2BlueReallocationData {
|
|
|
826
852
|
const sourceAllocations = sourceIds.map((id) => data.getAllocation(vaultAddress, id));
|
|
827
853
|
if (sourceAllocations.some(({ allocation }) => allocation === 0n))
|
|
828
854
|
continue;
|
|
829
|
-
const
|
|
830
|
-
|
|
855
|
+
const sourceSupplyShares = sourceAdapter.supplyShares[sourceMarket.id] ?? 0n;
|
|
856
|
+
if (sourceSupplyShares === 0n)
|
|
857
|
+
continue;
|
|
858
|
+
// A withdrawal can create target headroom only for shared cap IDs.
|
|
859
|
+
if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
|
|
860
|
+
continue;
|
|
861
|
+
const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
|
|
862
|
+
data.setMarkets([accruedSourceMarket]);
|
|
863
|
+
const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
|
|
864
|
+
const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, expectedSourceSupplyAssets, accruedSourceMarket.getWithdrawToUtilization(maxWithdrawalUtilization));
|
|
831
865
|
if (assets <= 0n)
|
|
832
866
|
continue;
|
|
833
867
|
rawCandidates.push({
|
|
@@ -848,9 +882,6 @@ class VaultV2BlueReallocationData {
|
|
|
848
882
|
for (const reallocation of rawCandidates) {
|
|
849
883
|
let lower = 0n;
|
|
850
884
|
let upper = reallocation.assets;
|
|
851
|
-
// MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
|
|
852
|
-
if (targetMarket.toSupplyShares(upper, "Down") < upper)
|
|
853
|
-
continue;
|
|
854
885
|
const reallocationAdapter = data.getAdapter(reallocation.vault, reallocation.to.adapter);
|
|
855
886
|
const targetIds = getAdapterIds(adapterIdsCache, reallocationAdapter, targetMarket);
|
|
856
887
|
const sourceIds = new Set();
|
|
@@ -954,6 +985,7 @@ class VaultV2BlueReallocationData {
|
|
|
954
985
|
* @param marketId - Target Blue market id.
|
|
955
986
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
956
987
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
988
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
957
989
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
958
990
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
959
991
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
@@ -1006,6 +1038,7 @@ class VaultV2BlueReallocationData {
|
|
|
1006
1038
|
* @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
|
|
1007
1039
|
* @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
|
|
1008
1040
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
1041
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1009
1042
|
* @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
|
|
1010
1043
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
1011
1044
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
package/lib/cjs/errors.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ UnknownTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError,
|
|
|
14
14
|
/** @deprecated Use UnknownBlueTokenPriceError or the raw protocol subpath. */
|
|
15
15
|
UnknownTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError,
|
|
16
16
|
/** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
|
|
17
|
-
UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
|
|
17
|
+
UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
|
|
18
18
|
/** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
|
|
19
19
|
UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError,
|
|
20
20
|
/** @deprecated Use UnsupportedBlueVaultV2AdapterError or the raw protocol subpath. */
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownCollateralIndexError = exports.UnknownMidnightCollateralIndexError = exports.TickOutOfRangeError = exports.MidnightTickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.MidnightSettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidTreeHeightError = void 0;
|
|
3
|
+
exports.InvalidTreeError = exports.InvalidMidnightTreeError = exports.InvalidTickSpacingError = exports.InvalidMidnightTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidMidnightOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownBlueVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownBlueTokenPriceError = exports.UnknownTokenError = exports.UnknownBlueTokenError = exports.UnknownOfFactory = exports.UnknownBlueOfFactory = exports.UnknownMarketParamsError = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownFactory = exports.UnknownBlueFactory = exports.UnknownDataError = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
|
+
exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownCollateralIndexError = exports.UnknownMidnightCollateralIndexError = exports.TickOutOfRangeError = exports.MidnightTickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.MidnightSettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidMidnightTreeHeightError = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
7
7
|
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "UnknownBlueVaultConfigError", { enumerable: true
|
|
|
32
32
|
/** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
|
|
33
33
|
Object.defineProperty(exports, "UnknownVaultConfigError", { enumerable: true, get: function () { return blue_sdk_1.UnknownVaultConfigError; } });
|
|
34
34
|
Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedChainIdError; } });
|
|
35
|
+
Object.defineProperty(exports, "UnsupportedBlueMarketIrmError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedMarketIrmError; } });
|
|
35
36
|
Object.defineProperty(exports, "UnsupportedBluePreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
|
|
36
37
|
/** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
|
|
37
38
|
Object.defineProperty(exports, "UnsupportedPreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
|
package/lib/cjs/fetch.d.ts
CHANGED
|
@@ -12,5 +12,7 @@ fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidatio
|
|
|
12
12
|
/** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
|
|
13
13
|
fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
|
|
14
14
|
/** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
|
|
15
|
-
fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
|
|
15
|
+
fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
|
|
16
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
|
|
17
|
+
fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
16
18
|
export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
|
package/lib/cjs/fetch.js
CHANGED
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "fetchVault", { enumerable: true, get: function (
|
|
|
35
35
|
Object.defineProperty(exports, "fetchVaultConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultConfig; } });
|
|
36
36
|
Object.defineProperty(exports, "fetchVaultMarketAllocation", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketAllocation; } });
|
|
37
37
|
Object.defineProperty(exports, "fetchVaultMarketConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketConfig; } });
|
|
38
|
+
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
|
|
38
39
|
Object.defineProperty(exports, "fetchVaultMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketPublicAllocatorConfig; } });
|
|
39
40
|
Object.defineProperty(exports, "fetchVaultUser", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultUser; } });
|
|
40
41
|
Object.defineProperty(exports, "fetchVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2; } });
|
|
@@ -22,6 +22,7 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
22
22
|
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
23
23
|
* @param params.options - Optional reallocation computation options.
|
|
24
24
|
* @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
|
|
25
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
25
26
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
|
|
26
27
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
27
28
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
@@ -72,6 +73,7 @@ export declare const computeVaultV1Reallocations: ({ reallocationData: data, mar
|
|
|
72
73
|
/**
|
|
73
74
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
74
75
|
*
|
|
76
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
75
77
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
76
78
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
77
79
|
*/
|
|
@@ -78,6 +78,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
78
78
|
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
79
79
|
* @param params.options - Optional reallocation computation options.
|
|
80
80
|
* @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
|
|
81
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
81
82
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
|
|
82
83
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
83
84
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
@@ -237,6 +238,7 @@ exports.computeVaultV1Reallocations = computeVaultV1Reallocations;
|
|
|
237
238
|
/**
|
|
238
239
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
239
240
|
*
|
|
241
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
240
242
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
241
243
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
242
244
|
*/
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export { computeReallocations, computeVaultV1Reallocations, } from "./computeVaultV1Reallocations.js";
|
|
2
2
|
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./constant.js";
|
|
3
3
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
|
+
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
|
|
4
5
|
export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
|
|
6
|
+
export { grossFromNetAssets } from "./referralFee.js";
|
|
5
7
|
export { signAndVerifyTypedData } from "./signAndVerifyTypedData.js";
|
|
6
|
-
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinWithdrawSharePrice, } from "./slippage.js";
|
|
8
|
+
export { computeMaxRepaySharePrice, computeMaxSupplySharePrice, computeMinBorrowSharePrice, computeMinForceWithdrawSharePrice, computeMinWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "./slippage.js";
|
|
7
9
|
export { validateAccrualPosition, validateChainId, validateMidnightMarketChainId, validateNativeAsset, validatePositionHealth, validatePositionHealthAfterWithdraw, validateReallocations, validateRepayAmount, validateRepayShares, validateSlippageTolerance, validateUserAddress, validateWithdrawAmount, validateWithdrawShares, } from "./validate.js";
|
|
8
10
|
export { validateOfferSides } from "./validateOfferSides.js";
|
|
9
11
|
export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
|
|
12
|
+
export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
|
package/lib/cjs/helpers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.signAndVerifyTypedData = exports.previewVaultV2InKindRedeem = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeVaultV1Reallocations = exports.computeReallocations = void 0;
|
|
3
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validateReallocations = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinWithdrawSharePrice = exports.computeMinForceWithdrawSharePrice = exports.computeMinBorrowSharePrice = exports.computeMaxSupplySharePrice = exports.computeMaxRepaySharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.computeVaultV1Reallocations = exports.computeReallocations = void 0;
|
|
4
4
|
var computeVaultV1Reallocations_js_1 = require("./computeVaultV1Reallocations.js");
|
|
5
5
|
Object.defineProperty(exports, "computeReallocations", { enumerable: true, get: function () { return computeVaultV1Reallocations_js_1.computeReallocations; } });
|
|
6
6
|
Object.defineProperty(exports, "computeVaultV1Reallocations", { enumerable: true, get: function () { return computeVaultV1Reallocations_js_1.computeVaultV1Reallocations; } });
|
|
@@ -16,15 +16,22 @@ Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get
|
|
|
16
16
|
Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
|
|
17
17
|
var metadata_js_1 = require("./metadata.js");
|
|
18
18
|
Object.defineProperty(exports, "addTransactionMetadata", { enumerable: true, get: function () { return metadata_js_1.addTransactionMetadata; } });
|
|
19
|
+
var previewVaultV2ForceWithdraw_js_1 = require("./previewVaultV2ForceWithdraw.js");
|
|
20
|
+
Object.defineProperty(exports, "previewVaultV2ForceWithdraw", { enumerable: true, get: function () { return previewVaultV2ForceWithdraw_js_1.previewVaultV2ForceWithdraw; } });
|
|
19
21
|
var previewVaultV2InKindRedeem_js_1 = require("./previewVaultV2InKindRedeem.js");
|
|
20
22
|
Object.defineProperty(exports, "previewVaultV2InKindRedeem", { enumerable: true, get: function () { return previewVaultV2InKindRedeem_js_1.previewVaultV2InKindRedeem; } });
|
|
23
|
+
var referralFee_js_1 = require("./referralFee.js");
|
|
24
|
+
Object.defineProperty(exports, "grossFromNetAssets", { enumerable: true, get: function () { return referralFee_js_1.grossFromNetAssets; } });
|
|
21
25
|
var signAndVerifyTypedData_js_1 = require("./signAndVerifyTypedData.js");
|
|
22
26
|
Object.defineProperty(exports, "signAndVerifyTypedData", { enumerable: true, get: function () { return signAndVerifyTypedData_js_1.signAndVerifyTypedData; } });
|
|
23
27
|
var slippage_js_1 = require("./slippage.js");
|
|
24
28
|
Object.defineProperty(exports, "computeMaxRepaySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxRepaySharePrice; } });
|
|
25
29
|
Object.defineProperty(exports, "computeMaxSupplySharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMaxSupplySharePrice; } });
|
|
26
30
|
Object.defineProperty(exports, "computeMinBorrowSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinBorrowSharePrice; } });
|
|
31
|
+
Object.defineProperty(exports, "computeMinForceWithdrawSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinForceWithdrawSharePrice; } });
|
|
27
32
|
Object.defineProperty(exports, "computeMinWithdrawSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeMinWithdrawSharePrice; } });
|
|
33
|
+
Object.defineProperty(exports, "computeVaultMaxShareAllowance", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxShareAllowance; } });
|
|
34
|
+
Object.defineProperty(exports, "computeVaultMaxSharePrice", { enumerable: true, get: function () { return slippage_js_1.computeVaultMaxSharePrice; } });
|
|
28
35
|
var validate_js_1 = require("./validate.js");
|
|
29
36
|
Object.defineProperty(exports, "validateAccrualPosition", { enumerable: true, get: function () { return validate_js_1.validateAccrualPosition; } });
|
|
30
37
|
Object.defineProperty(exports, "validateChainId", { enumerable: true, get: function () { return validate_js_1.validateChainId; } });
|
|
@@ -43,3 +50,9 @@ var validateOfferSides_js_1 = require("./validateOfferSides.js");
|
|
|
43
50
|
Object.defineProperty(exports, "validateOfferSides", { enumerable: true, get: function () { return validateOfferSides_js_1.validateOfferSides; } });
|
|
44
51
|
var validateRequirementSpender_js_1 = require("./validateRequirementSpender.js");
|
|
45
52
|
Object.defineProperty(exports, "validateRequirementSpender", { enumerable: true, get: function () { return validateRequirementSpender_js_1.validateRequirementSpender; } });
|
|
53
|
+
var vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
54
|
+
Object.defineProperty(exports, "computeVaultV2ForceWithdrawFeeSharesMinted", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawFeeSharesMinted; } });
|
|
55
|
+
Object.defineProperty(exports, "computeVaultV2ForceWithdrawMinSharesBurnt", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawMinSharesBurnt; } });
|
|
56
|
+
Object.defineProperty(exports, "computeVaultV2ForceWithdrawPlan", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawPlan; } });
|
|
57
|
+
Object.defineProperty(exports, "computeVaultV2ForceWithdrawSharesBurnt", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt; } });
|
|
58
|
+
Object.defineProperty(exports, "resolveVaultV2ForceWithdrawEligibility", { enumerable: true, get: function () { return vaultV2ForceWithdrawPlan_js_1.resolveVaultV2ForceWithdrawEligibility; } });
|
|
@@ -26,11 +26,9 @@ import type { Metadata } from "../types/index.js";
|
|
|
26
26
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
27
27
|
* such as `timestamp` and `origin`.
|
|
28
28
|
*
|
|
29
|
-
* @returns
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* If no `data` is present in the original transaction, the function returns
|
|
33
|
-
* the transaction unmodified.
|
|
29
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
34
32
|
*/
|
|
35
33
|
export declare function addTransactionMetadata(tx: {
|
|
36
34
|
data: Hex;
|
|
@@ -29,15 +29,13 @@ const viem_1 = require("viem");
|
|
|
29
29
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
30
30
|
* such as `timestamp` and `origin`.
|
|
31
31
|
*
|
|
32
|
-
* @returns
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* If no `data` is present in the original transaction, the function returns
|
|
36
|
-
* the transaction unmodified.
|
|
32
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
33
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
34
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
37
35
|
*/
|
|
38
36
|
function addTransactionMetadata(tx, metadata) {
|
|
39
37
|
const { data, ..._tx } = tx;
|
|
40
|
-
if (!data)
|
|
38
|
+
if (!data || data === "0x")
|
|
41
39
|
return tx;
|
|
42
40
|
const concatItems = [data];
|
|
43
41
|
if (metadata.timestamp) {
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type AccrualVaultV2, type Address } from "@morpho-org/blue-sdk";
|
|
2
|
+
/** Inputs used to preview a Vault V2 force withdrawal. */
|
|
3
|
+
export interface PreviewVaultV2ForceWithdrawParams {
|
|
4
|
+
/** Penalty-inclusive amount the user wants to exit. */
|
|
5
|
+
readonly requestedExitAssets: bigint;
|
|
6
|
+
/** Timestamp used to accrue every Morpho Blue market before converting adapter shares. */
|
|
7
|
+
readonly timestamp: bigint;
|
|
8
|
+
/** Optional adapter override; defaults to the vault's sole adapter. */
|
|
9
|
+
readonly adapter?: Address;
|
|
10
|
+
/**
|
|
11
|
+
* Account that will call `forceWithdraw`; fee-recipient mints are mirrored when provided. The
|
|
12
|
+
* entity projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it.
|
|
13
|
+
*/
|
|
14
|
+
readonly userAddress?: Address;
|
|
15
|
+
/**
|
|
16
|
+
* Timestamp the fee-recipient mint guard is projected to; defaults to `timestamp`. Pass the
|
|
17
|
+
* `forceWithdraw` deadline you will submit to mirror the entity's guard exactly. The entity
|
|
18
|
+
* rejects deadlines more than one year after handle creation (`InputExceedsMaxError`) rather
|
|
19
|
+
* than clamping them, so a quote projected past that horizon cannot be submitted. Ignored
|
|
20
|
+
* without `userAddress`.
|
|
21
|
+
*/
|
|
22
|
+
readonly feeProjectionTimestamp?: bigint;
|
|
23
|
+
/** Optional WAD-scaled referral fee percentage. Defaults to `0n`. */
|
|
24
|
+
readonly referralFeePct?: bigint;
|
|
25
|
+
/** Optional referral fee recipient. Required when `referralFeePct` is positive, as the entity
|
|
26
|
+
* enforces (`ReferralFeeRecipientMissingError`). When it equals `userAddress`, the fee is paid
|
|
27
|
+
* back to the exiting account and `netAssets` includes it. */
|
|
28
|
+
readonly referralFeeRecipient?: Address;
|
|
29
|
+
}
|
|
30
|
+
/** Frontend-ready preview of a Vault V2 force withdrawal through VaultExitBundlesV1. */
|
|
31
|
+
export interface VaultV2ForceWithdrawPreview {
|
|
32
|
+
/** Largest penalty-inclusive exit the current vault state supports. */
|
|
33
|
+
readonly maxExitAssets: bigint;
|
|
34
|
+
/** Penalty-inclusive exit amount this preview is computed for, capped at `maxExitAssets`. */
|
|
35
|
+
readonly exitAssets: bigint;
|
|
36
|
+
/** Requested penalty-inclusive amount left uncovered by `exitAssets`. */
|
|
37
|
+
readonly remainingExitAssets: bigint;
|
|
38
|
+
/** Portion withdrawn without a force-deallocation penalty (vault idle plus liquidity adapter). */
|
|
39
|
+
readonly assetsToWithdraw: bigint;
|
|
40
|
+
/** Portion force-deallocated from the adapter's markets, net of the penalty. */
|
|
41
|
+
readonly assetsToDeallocate: bigint;
|
|
42
|
+
/**
|
|
43
|
+
* Lower-bound estimate of the assets charged as the force-deallocation penalty,
|
|
44
|
+
* `ceil(assetsToDeallocate × penalty)`. Exact for a single-market exit. Across multiple markets
|
|
45
|
+
* the contract charges `Σ ceil(chunkᵢ × penalty)`, which this order-independent plan cannot
|
|
46
|
+
* reproduce without committing to the adapter's execution order (reordered mid-loop by
|
|
47
|
+
* swap-and-pop); the true charge is at most `penaltyLegs − 1` wei higher. It is never the inflated
|
|
48
|
+
* allowance bound. `netAssets` is exact and does not depend on this field, so the residual never
|
|
49
|
+
* affects the quoted payout.
|
|
50
|
+
*/
|
|
51
|
+
readonly penaltyAssets: bigint;
|
|
52
|
+
/** Assets routed to the referral fee recipient. */
|
|
53
|
+
readonly referralFeeAssets: bigint;
|
|
54
|
+
/** Assets the exiting account actually receives: `withdrawnAssets` minus the referral fee, unless
|
|
55
|
+
* the fee is paid back to `userAddress` itself. */
|
|
56
|
+
readonly netAssets: bigint;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Previews what a Vault V2 force withdrawal delivers, without any RPC.
|
|
60
|
+
*
|
|
61
|
+
* `exitAssets` is **penalty-inclusive**: the contract debits it from the user's position but pays
|
|
62
|
+
* out only `assetsToWithdraw + assetsToDeallocate`. Use `netAssets` to quote what the user
|
|
63
|
+
* receives and `maxExitAssets` to cap an input field.
|
|
64
|
+
*
|
|
65
|
+
* @param vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
66
|
+
* @param params - Preview parameters.
|
|
67
|
+
* @param params.requestedExitAssets - Penalty-inclusive amount the user wants to exit.
|
|
68
|
+
* @param params.timestamp - Timestamp used to accrue Morpho Blue markets before computing capacity.
|
|
69
|
+
* Must not run ahead of the wall clock at the subsequent `forceWithdraw()` call: market accrual
|
|
70
|
+
* grows the adapter's position, so a forward timestamp reports a `maxExitAssets` the entity will
|
|
71
|
+
* reject.
|
|
72
|
+
* @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
|
|
73
|
+
* @param params.userAddress - Optional account that will call `forceWithdraw`; when provided,
|
|
74
|
+
* fee shares minted to it by the accrual are mirrored exactly as the entity does. The entity
|
|
75
|
+
* projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it. Omit
|
|
76
|
+
* only for non-fee-recipient users.
|
|
77
|
+
* @param params.feeProjectionTimestamp - Timestamp for the fee-recipient mint guard; defaults to
|
|
78
|
+
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
79
|
+
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
80
|
+
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
81
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
82
|
+
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
83
|
+
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
84
|
+
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
85
|
+
* includes it.
|
|
86
|
+
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
87
|
+
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
88
|
+
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
89
|
+
* `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
|
|
90
|
+
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
91
|
+
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
92
|
+
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
93
|
+
* the entity rejects with `VaultV2ForceWithdrawZeroSharePriceError`), or whose derived default
|
|
94
|
+
* floor cannot fit `uint256`.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
|
|
98
|
+
*
|
|
99
|
+
* const preview = previewVaultV2ForceWithdraw(vaultData, {
|
|
100
|
+
* requestedExitAssets: 1_000_000n,
|
|
101
|
+
* timestamp: block.timestamp,
|
|
102
|
+
* });
|
|
103
|
+
* // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
|
|
104
|
+
* // preview?.netAssets is what the user receives
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function previewVaultV2ForceWithdraw(vaultData: AccrualVaultV2, params: PreviewVaultV2ForceWithdrawParams): VaultV2ForceWithdrawPreview | undefined;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.previewVaultV2ForceWithdraw = previewVaultV2ForceWithdraw;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
7
|
+
/**
|
|
8
|
+
* Previews what a Vault V2 force withdrawal delivers, without any RPC.
|
|
9
|
+
*
|
|
10
|
+
* `exitAssets` is **penalty-inclusive**: the contract debits it from the user's position but pays
|
|
11
|
+
* out only `assetsToWithdraw + assetsToDeallocate`. Use `netAssets` to quote what the user
|
|
12
|
+
* receives and `maxExitAssets` to cap an input field.
|
|
13
|
+
*
|
|
14
|
+
* @param vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
15
|
+
* @param params - Preview parameters.
|
|
16
|
+
* @param params.requestedExitAssets - Penalty-inclusive amount the user wants to exit.
|
|
17
|
+
* @param params.timestamp - Timestamp used to accrue Morpho Blue markets before computing capacity.
|
|
18
|
+
* Must not run ahead of the wall clock at the subsequent `forceWithdraw()` call: market accrual
|
|
19
|
+
* grows the adapter's position, so a forward timestamp reports a `maxExitAssets` the entity will
|
|
20
|
+
* reject.
|
|
21
|
+
* @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
|
|
22
|
+
* @param params.userAddress - Optional account that will call `forceWithdraw`; when provided,
|
|
23
|
+
* fee shares minted to it by the accrual are mirrored exactly as the entity does. The entity
|
|
24
|
+
* projects the mints to its deadline; pass that as `feeProjectionTimestamp` to mirror it. Omit
|
|
25
|
+
* only for non-fee-recipient users.
|
|
26
|
+
* @param params.feeProjectionTimestamp - Timestamp for the fee-recipient mint guard; defaults to
|
|
27
|
+
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
28
|
+
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
29
|
+
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
30
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
31
|
+
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
32
|
+
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
33
|
+
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
34
|
+
* includes it.
|
|
35
|
+
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
36
|
+
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
37
|
+
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
38
|
+
* `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
|
|
39
|
+
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
40
|
+
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
41
|
+
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
42
|
+
* the entity rejects with `VaultV2ForceWithdrawZeroSharePriceError`), or whose derived default
|
|
43
|
+
* floor cannot fit `uint256`.
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { previewVaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
|
|
47
|
+
*
|
|
48
|
+
* const preview = previewVaultV2ForceWithdraw(vaultData, {
|
|
49
|
+
* requestedExitAssets: 1_000_000n,
|
|
50
|
+
* timestamp: block.timestamp,
|
|
51
|
+
* });
|
|
52
|
+
* // preview?.exitAssets is ready to pass to vault.forceWithdraw(...)
|
|
53
|
+
* // preview?.netAssets is what the user receives
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
57
|
+
const { requestedExitAssets, timestamp, adapter: adapterOverride, userAddress, feeProjectionTimestamp = timestamp, referralFeePct = 0n, referralFeeRecipient, } = params;
|
|
58
|
+
if (requestedExitAssets <= 0n)
|
|
59
|
+
return undefined;
|
|
60
|
+
// Out of the range the action accepts, `netAssets` would quote a payout the contract can never
|
|
61
|
+
// deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
|
|
62
|
+
if (referralFeePct < 0n || referralFeePct >= blue_sdk_1.MathLib.WAD)
|
|
63
|
+
return undefined;
|
|
64
|
+
if (referralFeePct > 0n &&
|
|
65
|
+
(referralFeeRecipient == null ||
|
|
66
|
+
(0, viem_1.isAddressEqual)(referralFeeRecipient, viem_1.zeroAddress))) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const eligibility = (0, vaultV2ForceWithdrawPlan_js_1.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
|
|
70
|
+
if (eligibility.type !== "eligible")
|
|
71
|
+
return undefined;
|
|
72
|
+
const capacity = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawPlan)({
|
|
73
|
+
vaultData,
|
|
74
|
+
adapter: eligibility.adapter,
|
|
75
|
+
liquidityMarketId: eligibility.liquidityMarketId,
|
|
76
|
+
exitAssets: requestedExitAssets,
|
|
77
|
+
timestamp,
|
|
78
|
+
});
|
|
79
|
+
const exitAssets = blue_sdk_1.MathLib.min(requestedExitAssets, capacity.maxExitAssets);
|
|
80
|
+
// A vault with no exitable capacity caps `maxExitAssets` to `0`; the planner rejects a
|
|
81
|
+
// non-positive amount, so short-circuit to the "not previewable" verdict before re-planning.
|
|
82
|
+
if (exitAssets <= 0n)
|
|
83
|
+
return undefined;
|
|
84
|
+
// Re-plan at the capped amount so every returned leg describes the same exit.
|
|
85
|
+
const plan = exitAssets === requestedExitAssets
|
|
86
|
+
? capacity
|
|
87
|
+
: (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawPlan)({
|
|
88
|
+
vaultData,
|
|
89
|
+
adapter: eligibility.adapter,
|
|
90
|
+
liquidityMarketId: eligibility.liquidityMarketId,
|
|
91
|
+
exitAssets,
|
|
92
|
+
timestamp,
|
|
93
|
+
});
|
|
94
|
+
if (plan.withdrawnAssets <= 0n)
|
|
95
|
+
return undefined;
|
|
96
|
+
// Mirror the entity's zero-floor guard. `forceWithdraw()` derives its slippage floor from
|
|
97
|
+
// `withdrawnAssets / sharesBurnt` and rejects an exit whose realized share price rounds down to
|
|
98
|
+
// zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
|
|
99
|
+
// dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
|
|
100
|
+
// `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
|
|
101
|
+
// divides by (accrued to `timestamp` like the plan): a tolerance-free screen clears an exit whose
|
|
102
|
+
// realized price is a single RAY-unit, yet the default tolerance scales that below 1 and rounds it
|
|
103
|
+
// to zero — so the entity would reject with `VaultV2ForceWithdrawZeroSharePriceError` the very
|
|
104
|
+
// `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
|
|
105
|
+
// entity's own guard. The entity validates this derived value with
|
|
106
|
+
// `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
|
|
107
|
+
// cannot fit uint256.
|
|
108
|
+
const { vault: accruedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(timestamp, vaultData.lastUpdate));
|
|
109
|
+
const sharesBurnt = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
110
|
+
vaultData: accruedVaultData,
|
|
111
|
+
deadlineVaultData: accruedVaultData,
|
|
112
|
+
plan,
|
|
113
|
+
});
|
|
114
|
+
const feeShares = userAddress
|
|
115
|
+
? (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawFeeSharesMinted)({
|
|
116
|
+
vaultData,
|
|
117
|
+
owner: userAddress,
|
|
118
|
+
timestamp,
|
|
119
|
+
})
|
|
120
|
+
: 0n;
|
|
121
|
+
const effectiveFeeProjectionTimestamp = blue_sdk_1.MathLib.max(timestamp, feeProjectionTimestamp);
|
|
122
|
+
if (userAddress) {
|
|
123
|
+
const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(effectiveFeeProjectionTimestamp, vaultData.lastUpdate));
|
|
124
|
+
const feeSharesProjected = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawFeeSharesMinted)({
|
|
125
|
+
vaultData,
|
|
126
|
+
owner: userAddress,
|
|
127
|
+
timestamp: effectiveFeeProjectionTimestamp,
|
|
128
|
+
});
|
|
129
|
+
const minSharesBurntProjected = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawMinSharesBurnt)({
|
|
130
|
+
vaultData: projectedVaultData,
|
|
131
|
+
plan,
|
|
132
|
+
});
|
|
133
|
+
if (feeSharesProjected > 0n &&
|
|
134
|
+
feeSharesProjected >= minSharesBurntProjected) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const sharesBurntForFloor = sharesBurnt - feeShares;
|
|
139
|
+
const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
|
|
140
|
+
? blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
|
|
141
|
+
: 0n;
|
|
142
|
+
if (defaultMinSharePriceE27 <= 0n || defaultMinSharePriceE27 > viem_1.maxUint256) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const referralFeeAssets = blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, blue_sdk_1.MathLib.WAD);
|
|
146
|
+
const selfPaidReferralFee = userAddress != null &&
|
|
147
|
+
referralFeeRecipient != null &&
|
|
148
|
+
(0, viem_1.isAddressEqual)(userAddress, referralFeeRecipient);
|
|
149
|
+
return {
|
|
150
|
+
maxExitAssets: capacity.maxExitAssets,
|
|
151
|
+
exitAssets,
|
|
152
|
+
remainingExitAssets: requestedExitAssets - exitAssets,
|
|
153
|
+
assetsToWithdraw: plan.assetsToWithdraw,
|
|
154
|
+
assetsToDeallocate: plan.assetsToDeallocate,
|
|
155
|
+
// The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
|
|
156
|
+
// bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
|
|
157
|
+
// break reconciliation with `exitAssets` for a multi-market exit.
|
|
158
|
+
penaltyAssets: blue_sdk_1.MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
|
|
159
|
+
referralFeeAssets,
|
|
160
|
+
netAssets: selfPaidReferralFee
|
|
161
|
+
? plan.withdrawnAssets
|
|
162
|
+
: plan.withdrawnAssets - referralFeeAssets,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -35,6 +35,7 @@ export interface VaultV2InKindRedeemMarketPreview {
|
|
|
35
35
|
* @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
|
|
36
36
|
* @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
|
|
37
37
|
* @returns Frontend-ready market choices, or an empty list when no choices are available.
|
|
38
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
38
39
|
* @example
|
|
39
40
|
* ```ts
|
|
40
41
|
* import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
|