@morpho-org/morpho-sdk 9.8.0 → 10.0.0
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-v9-to-v10.md +114 -0
- package/README.md +109 -13
- package/lib/cjs/actions/blue/common.js +4 -2
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/cjs/actions/bundles/common.js +20 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
- package/lib/cjs/actions/midnight/index.d.ts +1 -0
- package/lib/cjs/actions/midnight/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeLend.js +3 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/cjs/entities/blue/blue.d.ts +34 -28
- package/lib/cjs/entities/blue/blue.js +107 -77
- package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
- package/lib/cjs/entities/midnight/deadline.js +4 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
- package/lib/cjs/entities/midnight/midnight.js +158 -138
- package/lib/cjs/entities/midnight/publication.d.ts +2 -0
- package/lib/cjs/entities/midnight/publication.js +193 -138
- package/lib/cjs/entities/midnight/types.d.ts +4 -4
- package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
- package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
- package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +2 -1
- package/lib/cjs/helpers/deadShares.js +83 -47
- package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/cjs/helpers/metadata.d.ts +14 -2
- package/lib/cjs/helpers/metadata.js +49 -8
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
- package/lib/cjs/helpers/utilization.js +10 -5
- package/lib/cjs/helpers/validate.js +88 -67
- package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
- package/lib/cjs/helpers/validatePositiveInput.js +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +10 -1
- package/lib/cjs/transactionPlan/approval.js +12 -1
- package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
- package/lib/cjs/transactionPlan/deposit.js +139 -0
- package/lib/cjs/transactionPlan/error.d.ts +10 -8
- package/lib/cjs/transactionPlan/error.js +10 -8
- package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
- package/lib/cjs/transactionPlan/index.d.ts +18 -0
- package/lib/cjs/transactionPlan/index.js +23 -5
- package/lib/cjs/transactionPlan/intent.d.ts +3 -3
- package/lib/cjs/transactionPlan/intent.js +14 -7
- package/lib/cjs/transactionPlan/permit.d.ts +1 -1
- package/lib/cjs/transactionPlan/permit.js +86 -20
- package/lib/cjs/transactionPlan/plan.d.ts +16 -6
- package/lib/cjs/transactionPlan/plan.js +77 -24
- package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
- package/lib/cjs/transactionPlan/redeem.js +63 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
- package/lib/cjs/transactionPlan/requirements.js +12 -6
- package/lib/cjs/transactionPlan/serde.d.ts +2 -2
- package/lib/cjs/transactionPlan/serde.js +45 -19
- package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/cjs/transactionPlan/shareSpending.js +50 -0
- package/lib/cjs/transactionPlan/types.d.ts +117 -11
- package/lib/cjs/transactionPlan/validateActions.js +11 -1
- package/lib/cjs/transactionPlan/validation.js +6 -3
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
- package/lib/cjs/transactionPlan/version.js +2 -1
- package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
- package/lib/cjs/transactionPlan/withdraw.js +94 -0
- package/lib/cjs/types/action.d.ts +26 -2
- package/lib/cjs/types/action.js +17 -9
- package/lib/cjs/types/error.d.ts +8 -1
- package/lib/cjs/types/error.js +21 -6
- package/lib/cjs/types/metadata.d.ts +12 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/common.js +4 -2
- package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/esm/actions/bundles/common.js +20 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/esm/actions/midnight/cancelOffers.js +104 -0
- package/lib/esm/actions/midnight/index.d.ts +1 -0
- package/lib/esm/actions/midnight/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/takeBorrow.js +3 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
- package/lib/esm/actions/midnight/takeLend.js +3 -2
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/esm/entities/blue/blue.d.ts +34 -28
- package/lib/esm/entities/blue/blue.js +107 -77
- package/lib/esm/entities/midnight/deadline.d.ts +2 -2
- package/lib/esm/entities/midnight/deadline.js +4 -3
- package/lib/esm/entities/midnight/midnight.d.ts +49 -51
- package/lib/esm/entities/midnight/midnight.js +159 -139
- package/lib/esm/entities/midnight/publication.d.ts +2 -0
- package/lib/esm/entities/midnight/publication.js +193 -138
- package/lib/esm/entities/midnight/types.d.ts +4 -4
- package/lib/esm/entities/requirements/assertContractCode.js +4 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
- package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
- package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/deadShares.js +83 -47
- package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/esm/helpers/metadata.d.ts +14 -2
- package/lib/esm/helpers/metadata.js +48 -8
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
- package/lib/esm/helpers/utilization.js +10 -5
- package/lib/esm/helpers/validate.js +88 -67
- package/lib/esm/helpers/validateMidnightBounds.js +2 -1
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/esm/helpers/validateMidnightPublication.js +4 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
- package/lib/esm/helpers/validatePositiveInput.js +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +2 -1
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/transactionPlan/approval.js +13 -2
- package/lib/esm/transactionPlan/deposit.d.ts +22 -0
- package/lib/esm/transactionPlan/deposit.js +135 -0
- package/lib/esm/transactionPlan/error.d.ts +10 -8
- package/lib/esm/transactionPlan/error.js +10 -8
- package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
- package/lib/esm/transactionPlan/index.d.ts +18 -0
- package/lib/esm/transactionPlan/index.js +9 -0
- package/lib/esm/transactionPlan/intent.d.ts +3 -3
- package/lib/esm/transactionPlan/intent.js +14 -7
- package/lib/esm/transactionPlan/permit.d.ts +1 -1
- package/lib/esm/transactionPlan/permit.js +86 -20
- package/lib/esm/transactionPlan/plan.d.ts +16 -6
- package/lib/esm/transactionPlan/plan.js +73 -20
- package/lib/esm/transactionPlan/redeem.d.ts +18 -0
- package/lib/esm/transactionPlan/redeem.js +59 -0
- package/lib/esm/transactionPlan/requirements.d.ts +4 -3
- package/lib/esm/transactionPlan/requirements.js +12 -6
- package/lib/esm/transactionPlan/serde.d.ts +2 -2
- package/lib/esm/transactionPlan/serde.js +45 -19
- package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/esm/transactionPlan/shareSpending.js +47 -0
- package/lib/esm/transactionPlan/types.d.ts +117 -11
- package/lib/esm/transactionPlan/validateActions.js +11 -1
- package/lib/esm/transactionPlan/validation.js +6 -3
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
- package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
- package/lib/esm/transactionPlan/version.js +2 -1
- package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
- package/lib/esm/transactionPlan/withdraw.js +90 -0
- package/lib/esm/types/action.d.ts +26 -2
- package/lib/esm/types/action.js +17 -9
- package/lib/esm/types/error.d.ts +8 -1
- package/lib/esm/types/error.js +21 -6
- package/lib/esm/types/metadata.d.ts +12 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +15 -14
|
@@ -5,19 +5,20 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
|
5
5
|
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
|
-
const actions_1 = require("viem/actions");
|
|
9
8
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
9
|
const index_js_1 = require("../../actions/index.js");
|
|
11
10
|
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
12
11
|
const index_js_2 = require("../../helpers/index.js");
|
|
12
|
+
const metadata_js_1 = require("../../helpers/metadata.js");
|
|
13
13
|
const validate_js_1 = require("../../helpers/validate.js");
|
|
14
14
|
const index_js_3 = require("../../types/index.js");
|
|
15
15
|
const assertContractCode_js_1 = require("../requirements/assertContractCode.js");
|
|
16
16
|
const getVaultBundlesSharesRequirements_js_1 = require("../requirements/getVaultBundlesSharesRequirements.js");
|
|
17
|
+
const getVaultV2ForceWithdrawRequirements_js_1 = require("../requirements/getVaultV2ForceWithdrawRequirements.js");
|
|
18
|
+
const getVaultV2InKindRedeemRequirements_js_1 = require("../requirements/getVaultV2InKindRedeemRequirements.js");
|
|
17
19
|
const index_js_4 = require("../requirements/index.js");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const VAULT_V2_FEE_PROJECTION_HORIZON = morpho_ts_1.Time.s.from.y(1n);
|
|
20
|
+
const forceWithdrawQuote_js_1 = require("./forceWithdrawQuote.js");
|
|
21
|
+
const inKindRedeemQuote_js_1 = require("./inKindRedeemQuote.js");
|
|
21
22
|
/** Binds a viem client to a Vault V2 vault's action builders. */
|
|
22
23
|
class MorphoVaultV2 {
|
|
23
24
|
client;
|
|
@@ -54,16 +55,19 @@ class MorphoVaultV2 {
|
|
|
54
55
|
}
|
|
55
56
|
/** {@inheritDoc VaultV2Actions.deposit} */
|
|
56
57
|
deposit(params) {
|
|
58
|
+
const suppliedNow = params.now;
|
|
59
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
|
|
57
60
|
const { userAddress, vaultData } = params;
|
|
58
61
|
const { asset: vaultAsset } = vaultData;
|
|
59
62
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
60
63
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
61
64
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
62
65
|
}
|
|
63
|
-
const createdAt = morpho_ts_1.Time.timestamp();
|
|
66
|
+
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
64
67
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
65
|
-
if (deadline <= createdAt)
|
|
68
|
+
if (deadline <= createdAt) {
|
|
66
69
|
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
70
|
+
}
|
|
67
71
|
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
68
72
|
deadline,
|
|
69
73
|
referralFeePct: params.referralFeePct,
|
|
@@ -87,11 +91,13 @@ class MorphoVaultV2 {
|
|
|
87
91
|
let pendingRequirements;
|
|
88
92
|
return Object.freeze({
|
|
89
93
|
getRequirements: async (requirementOptions) => {
|
|
90
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
91
|
-
if (deadline <= now)
|
|
94
|
+
const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
95
|
+
if (deadline <= now) {
|
|
92
96
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
93
|
-
|
|
97
|
+
}
|
|
98
|
+
if (pendingRequirements != null) {
|
|
94
99
|
return await pendingRequirements;
|
|
100
|
+
}
|
|
95
101
|
// Memoize the in-flight promise so concurrent callers share one round of
|
|
96
102
|
// allowance/nonce reads.
|
|
97
103
|
const pending = (async () => {
|
|
@@ -117,8 +123,9 @@ class MorphoVaultV2 {
|
|
|
117
123
|
}
|
|
118
124
|
finally {
|
|
119
125
|
// Later calls must re-read live allowances/nonces and honor their own options.
|
|
120
|
-
if (pendingRequirements === pending)
|
|
126
|
+
if (pendingRequirements === pending) {
|
|
121
127
|
pendingRequirements = undefined;
|
|
128
|
+
}
|
|
122
129
|
}
|
|
123
130
|
},
|
|
124
131
|
buildTx: (signatures) => {
|
|
@@ -141,25 +148,29 @@ class MorphoVaultV2 {
|
|
|
141
148
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
142
149
|
deadline,
|
|
143
150
|
},
|
|
144
|
-
metadata
|
|
151
|
+
metadata,
|
|
145
152
|
});
|
|
146
153
|
},
|
|
147
154
|
});
|
|
148
155
|
}
|
|
149
156
|
withdraw(params) {
|
|
157
|
+
const suppliedNow = params.now;
|
|
158
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
|
|
150
159
|
const { amount, userAddress, vaultData } = params;
|
|
151
160
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
152
161
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
153
162
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
154
163
|
}
|
|
155
|
-
if (amount <= 0n)
|
|
164
|
+
if (amount <= 0n) {
|
|
156
165
|
throw new index_js_3.NonPositiveInputError("amount", amount);
|
|
166
|
+
}
|
|
157
167
|
// Reject values outside the ABI range before resolving any requirements.
|
|
158
168
|
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
159
|
-
const createdAt = morpho_ts_1.Time.timestamp();
|
|
169
|
+
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
160
170
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
161
|
-
if (deadline <= createdAt)
|
|
171
|
+
if (deadline <= createdAt) {
|
|
162
172
|
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
173
|
+
}
|
|
163
174
|
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
164
175
|
deadline,
|
|
165
176
|
referralFeePct: params.referralFeePct,
|
|
@@ -177,9 +188,10 @@ class MorphoVaultV2 {
|
|
|
177
188
|
});
|
|
178
189
|
return Object.freeze({
|
|
179
190
|
getRequirements: async () => {
|
|
180
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
181
|
-
if (deadline <= now)
|
|
191
|
+
const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
192
|
+
if (deadline <= now) {
|
|
182
193
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
194
|
+
}
|
|
183
195
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
184
196
|
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
185
197
|
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
@@ -209,21 +221,25 @@ class MorphoVaultV2 {
|
|
|
209
221
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
210
222
|
deadline,
|
|
211
223
|
},
|
|
212
|
-
metadata
|
|
224
|
+
metadata,
|
|
213
225
|
});
|
|
214
226
|
},
|
|
215
227
|
});
|
|
216
228
|
}
|
|
217
229
|
/** {@inheritDoc VaultV2Actions.redeem} */
|
|
218
230
|
redeem(params) {
|
|
231
|
+
const suppliedNow = params.now;
|
|
232
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
|
|
219
233
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
220
234
|
const { shares, userAddress } = params;
|
|
221
|
-
if (shares <= 0n)
|
|
235
|
+
if (shares <= 0n) {
|
|
222
236
|
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
223
|
-
|
|
237
|
+
}
|
|
238
|
+
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
224
239
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
225
|
-
if (deadline <= createdAt)
|
|
240
|
+
if (deadline <= createdAt) {
|
|
226
241
|
throw new index_js_3.ExpiredDeadlineError(deadline, createdAt);
|
|
242
|
+
}
|
|
227
243
|
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
228
244
|
deadline,
|
|
229
245
|
referralFeePct: params.referralFeePct,
|
|
@@ -232,9 +248,10 @@ class MorphoVaultV2 {
|
|
|
232
248
|
const spender = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultBundlesV1");
|
|
233
249
|
return Object.freeze({
|
|
234
250
|
getRequirements: async () => {
|
|
235
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
236
|
-
if (deadline <= now)
|
|
251
|
+
const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
252
|
+
if (deadline <= now) {
|
|
237
253
|
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
254
|
+
}
|
|
238
255
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
239
256
|
return (0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(this.client.viemClient, {
|
|
240
257
|
vaultData: await this.getData(),
|
|
@@ -263,172 +280,42 @@ class MorphoVaultV2 {
|
|
|
263
280
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
264
281
|
deadline,
|
|
265
282
|
},
|
|
266
|
-
metadata
|
|
283
|
+
metadata,
|
|
267
284
|
});
|
|
268
285
|
},
|
|
269
286
|
});
|
|
270
287
|
}
|
|
271
288
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
272
|
-
inKindRedeem(
|
|
289
|
+
inKindRedeem(params) {
|
|
290
|
+
const suppliedNow = params.now;
|
|
291
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
|
|
292
|
+
const { amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, } = params;
|
|
273
293
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
274
294
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
275
295
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
276
296
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
})
|
|
286
|
-
const marketIdListSnapshot = marketParamsListSnapshot.map((marketParams) => blue_sdk_1.MarketUtils.getMarketId(marketParams));
|
|
287
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
288
|
-
const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
|
|
289
|
-
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
290
|
-
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
291
|
-
(0, validate_js_1.validateDeadline)(deadline);
|
|
292
|
-
if (deadline <= now)
|
|
293
|
-
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
294
|
-
if (vaultData.accrualAdapters.length !== 1) {
|
|
295
|
-
throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, vaultData.accrualAdapters.length);
|
|
296
|
-
}
|
|
297
|
-
const soleAdapter = vaultData.accrualAdapters[0];
|
|
298
|
-
if (soleAdapter == null) {
|
|
299
|
-
throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, 0);
|
|
300
|
-
}
|
|
301
|
-
const adapter = adapterOverride ?? soleAdapter.address;
|
|
302
|
-
if (!(0, viem_1.isAddressEqual)(adapter, soleAdapter.address)) {
|
|
303
|
-
throw new index_js_3.AdapterNotPartOfVaultError(this.vault, adapter);
|
|
304
|
-
}
|
|
305
|
-
if (!(soleAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2)) {
|
|
306
|
-
throw new index_js_3.VaultV2UnsupportedExitAdapterError(adapter);
|
|
307
|
-
}
|
|
308
|
-
const penalty = vaultData.forceDeallocatePenalties[soleAdapter.address] ?? 0n;
|
|
309
|
-
const idleAssets = blue_sdk_1.MathLib.min(vaultData.assetBalance, amount);
|
|
310
|
-
const assetsToDeallocate = blue_sdk_1.MathLib.wDivDown(amount - idleAssets, blue_sdk_1.MathLib.WAD + penalty);
|
|
311
|
-
if (idleAssets === 0n && assetsToDeallocate === 0n) {
|
|
312
|
-
throw new index_js_3.InKindRedeemZeroDeallocationError({
|
|
313
|
-
vault: this.vault,
|
|
314
|
-
amount,
|
|
315
|
-
penalty,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
|
|
319
|
-
throw new index_js_3.EmptyMarketParamsListError();
|
|
320
|
-
}
|
|
321
|
-
const assetsByMarket = new Map(soleAdapter.markets
|
|
322
|
-
.filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
|
|
323
|
-
.map((market) => [
|
|
324
|
-
market.id,
|
|
325
|
-
market
|
|
326
|
-
.accrueInterest(now)
|
|
327
|
-
.toSupplyAssets(soleAdapter.supplyShares[market.id] ?? 0n),
|
|
328
|
-
]));
|
|
329
|
-
const uniqueMarketIds = new Set(marketIdListSnapshot);
|
|
330
|
-
let covered = 0n;
|
|
331
|
-
for (const id of uniqueMarketIds)
|
|
332
|
-
covered += assetsByMarket.get(id) ?? 0n;
|
|
333
|
-
if (covered < assetsToDeallocate) {
|
|
334
|
-
const maxExitAssets = covered === 0n
|
|
335
|
-
? idleAssets
|
|
336
|
-
: idleAssets +
|
|
337
|
-
blue_sdk_1.MathLib.wMulUp(covered + 1n, blue_sdk_1.MathLib.WAD + penalty) -
|
|
338
|
-
1n;
|
|
339
|
-
throw new index_js_3.InKindRedeemCoverageError({
|
|
340
|
-
required: assetsToDeallocate,
|
|
341
|
-
covered,
|
|
342
|
-
maxExitAssets,
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
let remaining = assetsToDeallocate;
|
|
346
|
-
let peak = 0n;
|
|
347
|
-
const consumedMarketIds = new Set();
|
|
348
|
-
const { vault: allowanceVault } = vaultData.accrueInterest(deadline);
|
|
349
|
-
// Interest can lower the burn, while management fees can raise it; bound both endpoints.
|
|
350
|
-
const previewAllowance = (assets) => blue_sdk_1.MathLib.max(vaultData.toShares(assets, "Up"), allowanceVault.toShares(assets, "Up"));
|
|
351
|
-
let requiredShareAllowance = previewAllowance(BigInt(marketParamsListSnapshot.length));
|
|
352
|
-
// Pre-burn previews upper-bound each separately rounded idle, penalty, and main burn.
|
|
353
|
-
requiredShareAllowance += previewAllowance(idleAssets);
|
|
354
|
-
for (const id of marketIdListSnapshot) {
|
|
355
|
-
const available = consumedMarketIds.has(id)
|
|
356
|
-
? 0n
|
|
357
|
-
: (assetsByMarket.get(id) ?? 0n);
|
|
358
|
-
consumedMarketIds.add(id);
|
|
359
|
-
const chunk = blue_sdk_1.MathLib.min(available, remaining);
|
|
360
|
-
peak = blue_sdk_1.MathLib.max(peak, chunk);
|
|
361
|
-
requiredShareAllowance += previewAllowance(blue_sdk_1.MathLib.wMulUp(chunk, penalty));
|
|
362
|
-
requiredShareAllowance += previewAllowance(chunk);
|
|
363
|
-
remaining -= chunk;
|
|
364
|
-
}
|
|
297
|
+
const { deadline, adapter, marketParamsListSnapshot, requiredShareAllowance, peak, } = (0, inKindRedeemQuote_js_1.computeVaultV2InKindRedeemQuote)({
|
|
298
|
+
amount,
|
|
299
|
+
marketParamsList,
|
|
300
|
+
vaultData,
|
|
301
|
+
deadline: deadlineOverride,
|
|
302
|
+
adapter: adapterOverride,
|
|
303
|
+
now: suppliedNow ?? morpho_ts_1.Time.timestamp(),
|
|
304
|
+
vault: this.vault,
|
|
305
|
+
});
|
|
365
306
|
const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
|
|
366
|
-
const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
|
|
367
307
|
return {
|
|
368
|
-
getRequirements:
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
// either. Simulate the finalized transaction after authorization when gate compatibility
|
|
380
|
-
// must be checked before submission.
|
|
381
|
-
const [allowance, nonce, blueBalance] = await Promise.all([
|
|
382
|
-
(0, actions_1.readContract)(this.client.viemClient, {
|
|
383
|
-
address: this.vault,
|
|
384
|
-
abi: viem_1.erc20Abi,
|
|
385
|
-
functionName: "allowance",
|
|
386
|
-
args: [userAddress, vaultExitBundlesV1],
|
|
387
|
-
}),
|
|
388
|
-
(0, actions_1.readContract)(this.client.viemClient, {
|
|
389
|
-
address: this.vault,
|
|
390
|
-
abi: blue_sdk_viem_1.erc2612Abi,
|
|
391
|
-
functionName: "nonces",
|
|
392
|
-
args: [userAddress],
|
|
393
|
-
}),
|
|
394
|
-
(0, actions_1.readContract)(this.client.viemClient, {
|
|
395
|
-
address: vaultData.asset,
|
|
396
|
-
abi: viem_1.erc20Abi,
|
|
397
|
-
functionName: "balanceOf",
|
|
398
|
-
args: [blue],
|
|
399
|
-
}),
|
|
400
|
-
]);
|
|
401
|
-
if (blueBalance < peak) {
|
|
402
|
-
throw new index_js_3.InsufficientBlueBalanceForInKindRedeemError({
|
|
403
|
-
asset: vaultData.asset,
|
|
404
|
-
available: blueBalance,
|
|
405
|
-
required: peak,
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
if (allowance >= requiredShareAllowance)
|
|
409
|
-
return [];
|
|
410
|
-
if (this.client.options.supportSignature) {
|
|
411
|
-
return [
|
|
412
|
-
(0, index_js_1.encodeVaultSharesPermit)({
|
|
413
|
-
vault: vaultData,
|
|
414
|
-
version: "vaultV2",
|
|
415
|
-
spender: vaultExitBundlesV1,
|
|
416
|
-
owner: userAddress,
|
|
417
|
-
chainId: this.chainId,
|
|
418
|
-
nonce,
|
|
419
|
-
deadline,
|
|
420
|
-
}),
|
|
421
|
-
];
|
|
422
|
-
}
|
|
423
|
-
return [
|
|
424
|
-
(0, index_js_1.encodeErc20Approval)({
|
|
425
|
-
token: this.vault,
|
|
426
|
-
spender: vaultExitBundlesV1,
|
|
427
|
-
amount: viem_1.maxUint256,
|
|
428
|
-
chainId: this.chainId,
|
|
429
|
-
}),
|
|
430
|
-
];
|
|
431
|
-
},
|
|
308
|
+
getRequirements: () => (0, getVaultV2InKindRedeemRequirements_js_1.getVaultV2InKindRedeemRequirements)(this.client.viemClient, {
|
|
309
|
+
vaultData,
|
|
310
|
+
vault: this.vault,
|
|
311
|
+
userAddress,
|
|
312
|
+
chainId: this.chainId,
|
|
313
|
+
deadline,
|
|
314
|
+
requiredShareAllowance,
|
|
315
|
+
supportSignature: this.client.options.supportSignature,
|
|
316
|
+
peak,
|
|
317
|
+
now: suppliedNow,
|
|
318
|
+
}),
|
|
432
319
|
buildTx: (signatures) => {
|
|
433
320
|
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
434
321
|
spender: vaultExitBundlesV1,
|
|
@@ -445,225 +332,45 @@ class MorphoVaultV2 {
|
|
|
445
332
|
deadline,
|
|
446
333
|
requirementSignature: permit,
|
|
447
334
|
},
|
|
448
|
-
metadata
|
|
335
|
+
metadata,
|
|
449
336
|
});
|
|
450
337
|
},
|
|
451
338
|
};
|
|
452
339
|
}
|
|
453
340
|
/** {@inheritDoc VaultV2Actions.forceWithdraw} */
|
|
454
|
-
forceWithdraw(
|
|
341
|
+
forceWithdraw(params) {
|
|
342
|
+
const suppliedNow = params.now;
|
|
343
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
|
|
344
|
+
const { exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, minSharePriceE27: minSharePriceE27Override, referralFeePct = 0n, referralFeeRecipient, } = params;
|
|
455
345
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
456
346
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
457
347
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
458
348
|
}
|
|
459
|
-
|
|
460
|
-
throw new index_js_3.NonPositiveInputError("exitAssets", exitAssets);
|
|
461
|
-
(0, validate_js_1.validateUint256Field)("exitAssets", exitAssets);
|
|
462
|
-
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
463
|
-
// Called for its throws only: the raw pair is forwarded to the action, which normalizes it
|
|
464
|
-
// again on the encode path so a direct action caller gets the same guarantees.
|
|
465
|
-
(0, validate_js_1.validateReferralFee)({ referralFeePct, referralFeeRecipient });
|
|
466
|
-
if (minSharePriceE27Override != null) {
|
|
467
|
-
// An unbounded override reopens the exact hole this path closes: the contract reads
|
|
468
|
-
// `minSharePriceE27 == 0` as "no bound".
|
|
469
|
-
if (minSharePriceE27Override <= 0n) {
|
|
470
|
-
throw new index_js_3.NonPositiveInputError("minSharePriceE27", minSharePriceE27Override);
|
|
471
|
-
}
|
|
472
|
-
// And an override the uint256 slot cannot hold must fail here rather than after
|
|
473
|
-
// `getRequirements()` has already asked for an approval or a permit signature.
|
|
474
|
-
(0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27Override);
|
|
475
|
-
}
|
|
476
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
477
|
-
const deadline = deadlineOverride ?? now + morpho_ts_1.Time.s.from.h(2n);
|
|
478
|
-
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
479
|
-
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
480
|
-
(0, validate_js_1.validateDeadline)(deadline);
|
|
481
|
-
if (deadline <= now)
|
|
482
|
-
throw new index_js_3.ExpiredDeadlineError(deadline, now);
|
|
483
|
-
const maxDeadline = now + VAULT_V2_FEE_PROJECTION_HORIZON;
|
|
484
|
-
if (deadline > maxDeadline) {
|
|
485
|
-
throw new index_js_3.InputExceedsMaxError({
|
|
486
|
-
field: "deadline",
|
|
487
|
-
value: deadline,
|
|
488
|
-
max: maxDeadline,
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
const eligibility = (0, index_js_2.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
|
|
492
|
-
switch (eligibility.type) {
|
|
493
|
-
case "eligible":
|
|
494
|
-
break;
|
|
495
|
-
case "adapterCount":
|
|
496
|
-
throw new index_js_3.VaultV2SingleAdapterRequiredError(this.vault, eligibility.adapters);
|
|
497
|
-
case "adapterMismatch":
|
|
498
|
-
throw new index_js_3.AdapterNotPartOfVaultError(this.vault, eligibility.adapter);
|
|
499
|
-
case "unsupportedAdapter":
|
|
500
|
-
throw new index_js_3.VaultV2UnsupportedExitAdapterError(eligibility.adapter);
|
|
501
|
-
case "unsupportedLiquidityAdapter":
|
|
502
|
-
throw new index_js_3.VaultV2UnsupportedLiquidityAdapterError({
|
|
503
|
-
vault: this.vault,
|
|
504
|
-
liquidityAdapter: eligibility.liquidityAdapter,
|
|
505
|
-
adapter: eligibility.adapter,
|
|
506
|
-
});
|
|
507
|
-
case "undecodableLiquidityData":
|
|
508
|
-
throw new index_js_3.VaultV2UndecodableLiquidityDataError({
|
|
509
|
-
vault: this.vault,
|
|
510
|
-
liquidityAdapter: eligibility.liquidityAdapter,
|
|
511
|
-
liquidityData: eligibility.liquidityData,
|
|
512
|
-
cause: eligibility.cause,
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
const { adapter: accrualAdapter, liquidityMarketId } = eligibility;
|
|
516
|
-
const adapter = accrualAdapter.address;
|
|
517
|
-
const plan = (0, index_js_2.computeVaultV2ForceWithdrawPlan)({
|
|
518
|
-
vaultData,
|
|
519
|
-
adapter: accrualAdapter,
|
|
520
|
-
liquidityMarketId,
|
|
349
|
+
const { deadline, adapter, minSharePriceE27, requiredShareAllowance } = (0, forceWithdrawQuote_js_1.computeVaultV2ForceWithdrawQuote)({
|
|
521
350
|
exitAssets,
|
|
522
|
-
timestamp: now,
|
|
523
|
-
});
|
|
524
|
-
if (plan.withdrawnAssets <= 0n) {
|
|
525
|
-
throw new index_js_3.VaultV2ForceWithdrawZeroWithdrawalError({
|
|
526
|
-
vault: this.vault,
|
|
527
|
-
exitAssets,
|
|
528
|
-
penalty: plan.penalty,
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
// The contract's force-deallocation loop is unbounded: under-coverage panics on-chain.
|
|
532
|
-
if (plan.coveredAssets < plan.assetsToDeallocate) {
|
|
533
|
-
throw new index_js_3.VaultV2ForceWithdrawCoverageError({
|
|
534
|
-
required: plan.assetsToDeallocate,
|
|
535
|
-
covered: plan.coveredAssets,
|
|
536
|
-
maxExitAssets: plan.maxExitAssets,
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
const projectionTimestamp = deadline;
|
|
540
|
-
// VaultExitBundlesV1 measures shares as `sharesBefore - balanceAfter`; its first withdrawal
|
|
541
|
-
// accrues the vault before burning. The realized price sits between the raw snapshot price
|
|
542
|
-
// (pending fee mints not yet diluting it) and the `now` projection (interest the chain may not
|
|
543
|
-
// have accrued yet, e.g. when the wall clock runs ahead of the chain). Price the floor off the
|
|
544
|
-
// larger *net* burn of the two endpoints — the raw snapshot mints no fee shares, the `now`
|
|
545
|
-
// accrual mints `feeSharesNow` — so it never exceeds either, and use the projected deadline
|
|
546
|
-
// accrual for the fee-mint guard.
|
|
547
|
-
const { vault: nowVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(now, vaultData.lastUpdate));
|
|
548
|
-
const { vault: projectedVaultData } = vaultData.accrueInterest(blue_sdk_1.MathLib.max(projectionTimestamp, vaultData.lastUpdate));
|
|
549
|
-
const sharesBurntRaw = (0, index_js_2.computeVaultV2ForceWithdrawSharesBurnt)({
|
|
550
351
|
vaultData,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
vaultData,
|
|
561
|
-
owner: userAddress,
|
|
562
|
-
timestamp: now,
|
|
563
|
-
});
|
|
564
|
-
const feeSharesProjected = (0, index_js_2.computeVaultV2ForceWithdrawFeeSharesMinted)({
|
|
565
|
-
vaultData,
|
|
566
|
-
owner: userAddress,
|
|
567
|
-
timestamp: projectionTimestamp,
|
|
568
|
-
});
|
|
569
|
-
const minSharesBurntProjected = (0, index_js_2.computeVaultV2ForceWithdrawMinSharesBurnt)({
|
|
570
|
-
vaultData: projectedVaultData,
|
|
571
|
-
plan,
|
|
352
|
+
userAddress,
|
|
353
|
+
adapter: adapterOverride,
|
|
354
|
+
deadline: deadlineOverride,
|
|
355
|
+
slippageTolerance,
|
|
356
|
+
minSharePriceE27: minSharePriceE27Override,
|
|
357
|
+
referralFeePct,
|
|
358
|
+
referralFeeRecipient,
|
|
359
|
+
now: suppliedNow ?? morpho_ts_1.Time.timestamp(),
|
|
360
|
+
vault: this.vault,
|
|
572
361
|
});
|
|
573
|
-
// When fee shares are minted, the projected pair bounds every execution time in the window.
|
|
574
|
-
if (feeSharesProjected > 0n &&
|
|
575
|
-
feeSharesProjected >= minSharesBurntProjected) {
|
|
576
|
-
throw new index_js_3.VaultV2ForceWithdrawFeeSharesExceedBurnError({
|
|
577
|
-
vault: this.vault,
|
|
578
|
-
userAddress,
|
|
579
|
-
sharesBurnt: minSharesBurntProjected,
|
|
580
|
-
feeShares: feeSharesProjected,
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
// sharesBurntNow ≥ minSharesBurntNow ≥ minSharesBurntProjected > feeSharesProjected ≥ feeSharesNow
|
|
584
|
-
const sharesBurntForFloor = blue_sdk_1.MathLib.max(sharesBurntRaw, sharesBurntNow - feeSharesNow);
|
|
585
|
-
if (minSharePriceE27Override != null) {
|
|
586
|
-
// The maximum-slippage threshold only bounds the override; unlike the transaction floor it
|
|
587
|
-
// may round to zero, in which case every positive override is acceptable.
|
|
588
|
-
const minAllowedSharePriceE27 = (0, morpho_ts_1._try)(() => (0, index_js_2.computeMinForceWithdrawSharePrice)({
|
|
589
|
-
withdrawnAssets: plan.withdrawnAssets,
|
|
590
|
-
sharesBurnt: sharesBurntForFloor,
|
|
591
|
-
slippageTolerance: index_js_2.MAX_SLIPPAGE_TOLERANCE,
|
|
592
|
-
}), index_js_3.VaultV2ForceWithdrawZeroSharePriceError) ?? 1n;
|
|
593
|
-
if (minSharePriceE27Override < minAllowedSharePriceE27) {
|
|
594
|
-
throw new index_js_3.VaultV2ForceWithdrawSharePriceBelowFloorError({
|
|
595
|
-
minSharePriceE27: minSharePriceE27Override,
|
|
596
|
-
floorE27: minAllowedSharePriceE27,
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
const minSharePriceE27 = minSharePriceE27Override ??
|
|
601
|
-
(0, index_js_2.computeMinForceWithdrawSharePrice)({
|
|
602
|
-
withdrawnAssets: plan.withdrawnAssets,
|
|
603
|
-
sharesBurnt: sharesBurntForFloor,
|
|
604
|
-
slippageTolerance,
|
|
605
|
-
});
|
|
606
|
-
// The floor is deliberately *not* capped at `MAX_ABSOLUTE_SHARE_PRICE` (100 assets/share):
|
|
607
|
-
// lowering a lower bound weakens it, so any vault whose share price grew past that would be left
|
|
608
|
-
// with no real protection. Its two sibling `computeMin*SharePrice` helpers cap nothing either —
|
|
609
|
-
// only the `computeMax*` ones do, where capping relaxes an upper bound and is safe.
|
|
610
|
-
(0, validate_js_1.validateUint256Field)("minSharePriceE27", minSharePriceE27);
|
|
611
|
-
// This is the minimum allowance needed for successful execution, not an exit cap: the bundle
|
|
612
|
-
// independently rejects a realized share price below `minSharePriceE27`. Include the fee
|
|
613
|
-
// shares minted by the first withdrawal and enough headroom for the configured tolerance.
|
|
614
|
-
const allowanceSharePriceE27 = blue_sdk_1.MathLib.max(blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivDown(minSharePriceE27, blue_sdk_1.MathLib.WAD - slippageTolerance, blue_sdk_1.MathLib.WAD), minSharePriceE27 - 1n), 1n);
|
|
615
|
-
const requiredShareAllowance = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.max(blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, allowanceSharePriceE27), blue_sdk_1.MathLib.mulDivUp(exitAssets, blue_sdk_1.MathLib.RAY, minSharePriceE27) + 1n) + feeSharesProjected, viem_1.maxUint256);
|
|
616
362
|
const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
|
|
617
363
|
return {
|
|
618
|
-
getRequirements:
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
// execution-equivalent from a standalone read. Unlike in-kind redemption, this exit never
|
|
629
|
-
// supplies into Morpho Blue, so no Blue token-balance check is needed.
|
|
630
|
-
const [allowance, nonce] = await Promise.all([
|
|
631
|
-
(0, actions_1.readContract)(this.client.viemClient, {
|
|
632
|
-
address: this.vault,
|
|
633
|
-
abi: viem_1.erc20Abi,
|
|
634
|
-
functionName: "allowance",
|
|
635
|
-
args: [userAddress, vaultExitBundlesV1],
|
|
636
|
-
}),
|
|
637
|
-
(0, actions_1.readContract)(this.client.viemClient, {
|
|
638
|
-
address: this.vault,
|
|
639
|
-
abi: blue_sdk_viem_1.erc2612Abi,
|
|
640
|
-
functionName: "nonces",
|
|
641
|
-
args: [userAddress],
|
|
642
|
-
}),
|
|
643
|
-
]);
|
|
644
|
-
if (allowance >= requiredShareAllowance)
|
|
645
|
-
return [];
|
|
646
|
-
if (this.client.options.supportSignature) {
|
|
647
|
-
const requirement = (0, index_js_1.encodeVaultSharesPermit)({
|
|
648
|
-
vault: vaultData,
|
|
649
|
-
version: "vaultV2",
|
|
650
|
-
spender: vaultExitBundlesV1,
|
|
651
|
-
owner: userAddress,
|
|
652
|
-
chainId: this.chainId,
|
|
653
|
-
nonce,
|
|
654
|
-
deadline,
|
|
655
|
-
});
|
|
656
|
-
return [requirement];
|
|
657
|
-
}
|
|
658
|
-
return [
|
|
659
|
-
(0, index_js_1.encodeErc20Approval)({
|
|
660
|
-
token: this.vault,
|
|
661
|
-
spender: vaultExitBundlesV1,
|
|
662
|
-
amount: viem_1.maxUint256,
|
|
663
|
-
chainId: this.chainId,
|
|
664
|
-
}),
|
|
665
|
-
];
|
|
666
|
-
},
|
|
364
|
+
getRequirements: () => (0, getVaultV2ForceWithdrawRequirements_js_1.getVaultV2ForceWithdrawRequirements)(this.client.viemClient, {
|
|
365
|
+
vaultData,
|
|
366
|
+
vault: this.vault,
|
|
367
|
+
userAddress,
|
|
368
|
+
chainId: this.chainId,
|
|
369
|
+
deadline,
|
|
370
|
+
requiredShareAllowance,
|
|
371
|
+
supportSignature: this.client.options.supportSignature,
|
|
372
|
+
now: suppliedNow,
|
|
373
|
+
}),
|
|
667
374
|
buildTx: (signatures) => {
|
|
668
375
|
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
|
|
669
376
|
spender: vaultExitBundlesV1,
|
|
@@ -682,12 +389,14 @@ class MorphoVaultV2 {
|
|
|
682
389
|
referralFeeRecipient,
|
|
683
390
|
requirementSignature: permit,
|
|
684
391
|
},
|
|
685
|
-
metadata
|
|
392
|
+
metadata,
|
|
686
393
|
});
|
|
687
394
|
},
|
|
688
395
|
};
|
|
689
396
|
}
|
|
690
|
-
forceRedeem(
|
|
397
|
+
forceRedeem(params) {
|
|
398
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
399
|
+
const { deallocations, redeem, userAddress } = params;
|
|
691
400
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
692
401
|
const shares = redeem.shares;
|
|
693
402
|
const deallocationsSnapshot = deallocations.map(({ adapter, marketParams, amount }) => ({
|
|
@@ -703,7 +412,7 @@ class MorphoVaultV2 {
|
|
|
703
412
|
redeem: { shares, recipient: userAddress },
|
|
704
413
|
onBehalf: userAddress,
|
|
705
414
|
},
|
|
706
|
-
metadata
|
|
415
|
+
metadata,
|
|
707
416
|
}),
|
|
708
417
|
};
|
|
709
418
|
}
|