@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
|
@@ -1,101 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateDepositPlanAction = validateDepositPlanAction;
|
|
4
3
|
exports.prepareVaultV2Deposit = prepareVaultV2Deposit;
|
|
5
4
|
exports.buildVaultV2Deposit = buildVaultV2Deposit;
|
|
6
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
-
const viem_1 = require("viem");
|
|
9
6
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
|
-
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
7
|
const deposit_js_1 = require("../../actions/vaultV2/deposit.js");
|
|
12
|
-
const
|
|
13
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
14
|
-
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
|
-
const index_js_2 = require("../../types/index.js");
|
|
16
|
-
const error_js_1 = require("../error.js");
|
|
17
|
-
const intent_js_1 = require("../intent.js");
|
|
8
|
+
const deposit_js_2 = require("../deposit.js");
|
|
18
9
|
const permit_js_1 = require("../permit.js");
|
|
19
|
-
const requirements_js_1 = require("../requirements.js");
|
|
20
|
-
const validation_js_1 = require("../validation.js");
|
|
21
|
-
/** @internal Validates the stored Vault V2 deposit action's input shape. */
|
|
22
|
-
function validateDepositPlanAction(action, path) {
|
|
23
|
-
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
24
|
-
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
25
|
-
path: `${path}.inputs`,
|
|
26
|
-
fields: { asset: "address", maxSharePrice: "uint256 bigint" },
|
|
27
|
-
});
|
|
28
|
-
if ((inputs.amount === undefined) === (inputs.nativeAmount === undefined))
|
|
29
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
30
|
-
path: `${path}.inputs`,
|
|
31
|
-
reason: "expected exactly one of amount or nativeAmount",
|
|
32
|
-
});
|
|
33
|
-
const field = inputs.amount === undefined ? "nativeAmount" : "amount";
|
|
34
|
-
(0, validation_js_1.validatePlanField)(inputs[field], {
|
|
35
|
-
path: `${path}.inputs.${field}`,
|
|
36
|
-
type: "uint256 bigint",
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function resolveDepositInputs(params, now) {
|
|
40
|
-
const { vault, chainId, amount, vaultData } = params;
|
|
41
|
-
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
42
|
-
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
43
|
-
(0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
|
|
44
|
-
const native = (params.funding ?? { type: "erc20" }).type === "native";
|
|
45
|
-
if (amount <= 0n)
|
|
46
|
-
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
47
|
-
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
48
|
-
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
49
|
-
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
50
|
-
deadline: intent.deadline,
|
|
51
|
-
referralFeePct: intent.referralFeePct,
|
|
52
|
-
referralFeeRecipient: intent.referralFeeRecipient,
|
|
53
|
-
});
|
|
54
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.address, vault))
|
|
55
|
-
throw new index_js_2.VaultAddressMismatchError(vaultData.address, vault);
|
|
56
|
-
const { asset } = vaultData;
|
|
57
|
-
// Native funding must target the chain's wrapped-native vault asset.
|
|
58
|
-
if (native)
|
|
59
|
-
(0, validate_js_1.validateNativeVaultAsset)(chainId, asset);
|
|
60
|
-
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
61
|
-
const maxSharePrice = (0, index_js_1.computeVaultMaxSharePrice)({
|
|
62
|
-
vaultData,
|
|
63
|
-
deadline: intent.deadline,
|
|
64
|
-
assets: amount - (0, common_js_1.getBundlesReferralFeeAssets)(amount, common.referralFeePct),
|
|
65
|
-
slippageTolerance,
|
|
66
|
-
});
|
|
67
|
-
return { intent, native, common, asset, maxSharePrice };
|
|
68
|
-
}
|
|
69
10
|
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
70
12
|
* Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
|
|
71
13
|
* directly. The quote is fixed on the deposit step at preparation, so the returned plan is static:
|
|
72
14
|
* only signatures are added before building.
|
|
73
15
|
* @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
|
|
74
|
-
* @param params.vault -
|
|
75
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the asset and deadline-accrued share-price bound.
|
|
16
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
76
17
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
77
18
|
* @param params.account - Non-zero account funding, signing and sending the deposit.
|
|
78
|
-
* @param params.
|
|
19
|
+
* @param params.assets - Positive gross deposit in asset base units, before referral fees.
|
|
79
20
|
* @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
|
|
80
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
21
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
81
22
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
82
23
|
* @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
|
|
83
24
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
84
|
-
* @param params.
|
|
25
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
26
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
85
27
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
86
28
|
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
87
29
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
88
30
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
89
31
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
90
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
91
|
-
* @throws {ExpiredDeadlineError} when `expiresAt` is
|
|
32
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets`, net assets or previewed shares are not positive.
|
|
33
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
92
34
|
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
93
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
35
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
94
36
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
95
37
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
96
38
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
97
39
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
98
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
99
40
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
100
41
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
101
42
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
@@ -109,87 +50,19 @@ function resolveDepositInputs(params, now) {
|
|
|
109
50
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
110
51
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
111
52
|
* const plan = await prepareVaultV2Deposit(client, {
|
|
112
|
-
*
|
|
113
|
-
*
|
|
53
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
54
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
55
|
+
* now: (await client.getBlock()).timestamp,
|
|
114
56
|
* });
|
|
115
57
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
116
58
|
* ```
|
|
117
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
118
59
|
*/
|
|
119
60
|
async function prepareVaultV2Deposit(client, params) {
|
|
120
|
-
|
|
121
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
122
|
-
const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
|
|
123
|
-
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
124
|
-
const [requirements] = await Promise.all([
|
|
125
|
-
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId).then(() => native
|
|
126
|
-
? []
|
|
127
|
-
: (0, requirements_js_1.getTokenRequirements)(client, {
|
|
128
|
-
token: asset,
|
|
129
|
-
spender,
|
|
130
|
-
amount,
|
|
131
|
-
owner: account,
|
|
132
|
-
chainId,
|
|
133
|
-
deadline: intent.deadline,
|
|
134
|
-
now,
|
|
135
|
-
supportSignature: intent.supportSignature,
|
|
136
|
-
deployless: intent.deployless,
|
|
137
|
-
})),
|
|
138
|
-
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
139
|
-
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
140
|
-
]),
|
|
141
|
-
]);
|
|
142
|
-
const approvals = [];
|
|
143
|
-
const signatureRequests = [];
|
|
144
|
-
const tokenPermitRequestId = "vaultV2Deposit:tokenPermit";
|
|
145
|
-
for (const requirement of requirements) {
|
|
146
|
-
if ("sign" in requirement) {
|
|
147
|
-
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
151
|
-
id: approvals.length === 0
|
|
152
|
-
? "vaultV2Deposit:approval"
|
|
153
|
-
: `vaultV2Deposit:approval:${approvals.length + 1}`,
|
|
154
|
-
chainId,
|
|
155
|
-
account,
|
|
156
|
-
}));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
160
|
-
version: 1,
|
|
161
|
-
account,
|
|
162
|
-
chainId,
|
|
163
|
-
expiresAt: intent.expiresAt,
|
|
164
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
165
|
-
steps: [
|
|
166
|
-
...approvals,
|
|
167
|
-
{
|
|
168
|
-
id: "vaultV2Deposit",
|
|
169
|
-
label: "Deposit into vault",
|
|
170
|
-
action: {
|
|
171
|
-
type: "vaultV2Deposit",
|
|
172
|
-
inputs: {
|
|
173
|
-
chainId,
|
|
174
|
-
account,
|
|
175
|
-
vault,
|
|
176
|
-
asset,
|
|
177
|
-
maxSharePrice,
|
|
178
|
-
...(native ? { nativeAmount: amount } : { amount }),
|
|
179
|
-
...common,
|
|
180
|
-
},
|
|
181
|
-
signatureRequestIds: signatureRequests.length > 0
|
|
182
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
183
|
-
: {},
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
signatureRequests,
|
|
188
|
-
}));
|
|
61
|
+
return (0, deposit_js_2.prepareVaultDeposit)(client, { ...params, type: "vaultV2Deposit" });
|
|
189
62
|
}
|
|
190
63
|
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|
|
191
64
|
function buildVaultV2Deposit(action, requests) {
|
|
192
|
-
const { asset, chainId, account, ...args } = action.inputs;
|
|
65
|
+
const { asset, chainId, account, assets, nativeAssets, ...args } = action.inputs;
|
|
193
66
|
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
194
67
|
id: action.signatureRequestIds.tokenPermit,
|
|
195
68
|
asset,
|
|
@@ -197,13 +70,16 @@ function buildVaultV2Deposit(action, requests) {
|
|
|
197
70
|
});
|
|
198
71
|
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signature ? [signature] : [], {
|
|
199
72
|
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
200
|
-
amount:
|
|
73
|
+
amount: assets ?? nativeAssets,
|
|
201
74
|
deadline: action.inputs.deadline,
|
|
202
75
|
});
|
|
203
76
|
return (0, deposit_js_1.vaultV2Deposit)({
|
|
204
77
|
vault: { chainId, address: action.inputs.vault, asset },
|
|
205
78
|
args: {
|
|
206
79
|
...args,
|
|
80
|
+
...(nativeAssets === undefined
|
|
81
|
+
? { amount: assets }
|
|
82
|
+
: { nativeAmount: nativeAssets }),
|
|
207
83
|
userAddress: account,
|
|
208
84
|
requirementSignature,
|
|
209
85
|
},
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Address, Client } from "viem";
|
|
2
|
+
import type { ReferenceTimestampParams, Transaction, VaultV2ForceRedeemAction } from "../../types/index.js";
|
|
3
|
+
import { type IntentParams } from "../intent.js";
|
|
4
|
+
import type { Action, TransactionPlan } from "../types.js";
|
|
5
|
+
/** @internal Validates the stored force-redeem action's plain input shape. */
|
|
6
|
+
export declare function validateForceRedeemPlanAction(action: Record<string, unknown>, path: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
9
|
+
* Caller-supplied shares and deallocations for the vault's native force-redeem multicall.
|
|
10
|
+
* No approval or signature is needed.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const params: VaultV2ForceRedeemPlanParams = {
|
|
14
|
+
* vaultAddress, chainId: 1, account, shares: 100n,
|
|
15
|
+
* deallocations: [{ adapter, assets: 100n }],
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface VaultV2ForceRedeemPlanParams extends Pick<IntentParams, "chainId" | "account" | "expiresAt" | "calldataOrigin">, ReferenceTimestampParams {
|
|
20
|
+
readonly vaultAddress: Address;
|
|
21
|
+
readonly shares: bigint;
|
|
22
|
+
/** Fixed, ordered asset deallocations executed before redeeming. Include any required penalty buffer. */
|
|
23
|
+
readonly deallocations: Extract<Action, {
|
|
24
|
+
type: "vaultV2ForceRedeem";
|
|
25
|
+
}>["inputs"]["deallocations"];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
29
|
+
* Prepares one vault multicall, fixing the supplied deallocations and shares in the plan.
|
|
30
|
+
* Shares and deallocation penalties are burned from `account`; redeemed assets go to `account`.
|
|
31
|
+
* No permissions are requested, and expiry is plan metadata, not an onchain deadline.
|
|
32
|
+
* @param client - Client used to validate the chain, not retained by the plan.
|
|
33
|
+
* @param params.vaultAddress - Vault V2 whose shares are redeemed.
|
|
34
|
+
* @param params.chainId - Chain containing the vault.
|
|
35
|
+
* @param params.account - Share owner submitting the multicall and receiving the redeemed assets.
|
|
36
|
+
* @param params.shares - Positive shares to redeem, in vault share base units.
|
|
37
|
+
* @param params.deallocations - Non-empty, ordered deallocations with positive `assets` in asset base units, including any penalty buffer.
|
|
38
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
39
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` and is plan metadata only.
|
|
40
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
41
|
+
* @returns A deep-frozen `TransactionPlan` containing one `vaultV2ForceRedeem` step and no signature requests.
|
|
42
|
+
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
43
|
+
* @throws {EmptyDeallocationsError} If `deallocations` is empty.
|
|
44
|
+
* @throws {NonPositiveInputError} If expiry, shares or any deallocation assets are non-positive.
|
|
45
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
46
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
47
|
+
* @throws {ExpiredDeadlineError} If `expiresAt` is not in the future.
|
|
48
|
+
* @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { prepareVaultV2ForceRedeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
52
|
+
* import { createPublicClient, http } from "viem";
|
|
53
|
+
* import { mainnet } from "viem/chains";
|
|
54
|
+
*
|
|
55
|
+
* // Fixture addresses for preparation only; use your vault, adapter and share owner before execution.
|
|
56
|
+
* const IN_KIND_VAULT = "0x0000000000000000000000000000000000001001";
|
|
57
|
+
* const IN_KIND_ADAPTER = "0x0000000000000000000000000000000000001002";
|
|
58
|
+
* const IN_KIND_USER = "0x0000000000000000000000000000000000001004";
|
|
59
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
60
|
+
* const plan: TransactionPlan = await prepareVaultV2ForceRedeem(client, {
|
|
61
|
+
* vaultAddress: IN_KIND_VAULT, chainId: mainnet.id, account: IN_KIND_USER,
|
|
62
|
+
* shares: 100n,
|
|
63
|
+
* now: (await client.getBlock()).timestamp,
|
|
64
|
+
* deallocations: [{ adapter: IN_KIND_ADAPTER, assets: 100n }],
|
|
65
|
+
* });
|
|
66
|
+
* // plan.steps contains one step with action.type === "vaultV2ForceRedeem".
|
|
67
|
+
* // plan.signatureRequests is []; the caller signs and submits the built transaction.
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function prepareVaultV2ForceRedeem(client: Client, params: VaultV2ForceRedeemPlanParams): Promise<TransactionPlan>;
|
|
71
|
+
/** @internal Encodes the fixed multicall through the same action as the forceRedeem handle. */
|
|
72
|
+
export declare function buildVaultV2ForceRedeem(action: Extract<Action, {
|
|
73
|
+
type: "vaultV2ForceRedeem";
|
|
74
|
+
}>): Readonly<Transaction<VaultV2ForceRedeemAction>>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateForceRedeemPlanAction = validateForceRedeemPlanAction;
|
|
4
|
+
exports.prepareVaultV2ForceRedeem = prepareVaultV2ForceRedeem;
|
|
5
|
+
exports.buildVaultV2ForceRedeem = buildVaultV2ForceRedeem;
|
|
6
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
9
|
+
const forceRedeem_js_1 = require("../../actions/vaultV2/forceRedeem.js");
|
|
10
|
+
const intent_js_1 = require("../intent.js");
|
|
11
|
+
const validation_js_1 = require("../validation.js");
|
|
12
|
+
/** @internal Validates the stored force-redeem action's plain input shape. */
|
|
13
|
+
function validateForceRedeemPlanAction(action, path) {
|
|
14
|
+
const inputPath = `${path}.inputs`;
|
|
15
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, inputPath);
|
|
16
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
17
|
+
path: inputPath,
|
|
18
|
+
fields: { vault: "address", deallocations: "array" },
|
|
19
|
+
});
|
|
20
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(inputs.redeem, `${inputPath}.redeem`), {
|
|
21
|
+
path: `${inputPath}.redeem`,
|
|
22
|
+
fields: { shares: "uint256 bigint" },
|
|
23
|
+
});
|
|
24
|
+
for (const [index, value] of inputs.deallocations.entries()) {
|
|
25
|
+
const entryPath = `${inputPath}.deallocations[${index}]`;
|
|
26
|
+
const entry = (0, validation_js_1.getPlanObject)(value, entryPath);
|
|
27
|
+
(0, validation_js_1.validatePlanFields)(entry, {
|
|
28
|
+
path: entryPath,
|
|
29
|
+
fields: { adapter: "address", assets: "uint256 bigint" },
|
|
30
|
+
});
|
|
31
|
+
if (entry.marketParams !== undefined) {
|
|
32
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(entry.marketParams, `${entryPath}.marketParams`), {
|
|
33
|
+
path: `${entryPath}.marketParams`,
|
|
34
|
+
fields: {
|
|
35
|
+
loanToken: "address",
|
|
36
|
+
collateralToken: "address",
|
|
37
|
+
oracle: "address",
|
|
38
|
+
irm: "address",
|
|
39
|
+
lltv: "uint256 bigint",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
47
|
+
* Prepares one vault multicall, fixing the supplied deallocations and shares in the plan.
|
|
48
|
+
* Shares and deallocation penalties are burned from `account`; redeemed assets go to `account`.
|
|
49
|
+
* No permissions are requested, and expiry is plan metadata, not an onchain deadline.
|
|
50
|
+
* @param client - Client used to validate the chain, not retained by the plan.
|
|
51
|
+
* @param params.vaultAddress - Vault V2 whose shares are redeemed.
|
|
52
|
+
* @param params.chainId - Chain containing the vault.
|
|
53
|
+
* @param params.account - Share owner submitting the multicall and receiving the redeemed assets.
|
|
54
|
+
* @param params.shares - Positive shares to redeem, in vault share base units.
|
|
55
|
+
* @param params.deallocations - Non-empty, ordered deallocations with positive `assets` in asset base units, including any penalty buffer.
|
|
56
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
57
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` and is plan metadata only.
|
|
58
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
59
|
+
* @returns A deep-frozen `TransactionPlan` containing one `vaultV2ForceRedeem` step and no signature requests.
|
|
60
|
+
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
61
|
+
* @throws {EmptyDeallocationsError} If `deallocations` is empty.
|
|
62
|
+
* @throws {NonPositiveInputError} If expiry, shares or any deallocation assets are non-positive.
|
|
63
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
64
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
65
|
+
* @throws {ExpiredDeadlineError} If `expiresAt` is not in the future.
|
|
66
|
+
* @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { prepareVaultV2ForceRedeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
70
|
+
* import { createPublicClient, http } from "viem";
|
|
71
|
+
* import { mainnet } from "viem/chains";
|
|
72
|
+
*
|
|
73
|
+
* // Fixture addresses for preparation only; use your vault, adapter and share owner before execution.
|
|
74
|
+
* const IN_KIND_VAULT = "0x0000000000000000000000000000000000001001";
|
|
75
|
+
* const IN_KIND_ADAPTER = "0x0000000000000000000000000000000000001002";
|
|
76
|
+
* const IN_KIND_USER = "0x0000000000000000000000000000000000001004";
|
|
77
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
78
|
+
* const plan: TransactionPlan = await prepareVaultV2ForceRedeem(client, {
|
|
79
|
+
* vaultAddress: IN_KIND_VAULT, chainId: mainnet.id, account: IN_KIND_USER,
|
|
80
|
+
* shares: 100n,
|
|
81
|
+
* now: (await client.getBlock()).timestamp,
|
|
82
|
+
* deallocations: [{ adapter: IN_KIND_ADAPTER, assets: 100n }],
|
|
83
|
+
* });
|
|
84
|
+
* // plan.steps contains one step with action.type === "vaultV2ForceRedeem".
|
|
85
|
+
* // plan.signatureRequests is []; the caller signs and submits the built transaction.
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
async function prepareVaultV2ForceRedeem(client, params) {
|
|
89
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
90
|
+
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
91
|
+
const plan = structuredClone({
|
|
92
|
+
version: 2,
|
|
93
|
+
account: params.account,
|
|
94
|
+
chainId: params.chainId,
|
|
95
|
+
expiresAt: intent.expiresAt,
|
|
96
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
97
|
+
steps: [
|
|
98
|
+
{
|
|
99
|
+
id: "vaultV2ForceRedeem",
|
|
100
|
+
label: "Force redeem from vault",
|
|
101
|
+
action: {
|
|
102
|
+
type: "vaultV2ForceRedeem",
|
|
103
|
+
inputs: {
|
|
104
|
+
chainId: params.chainId,
|
|
105
|
+
account: params.account,
|
|
106
|
+
vault: params.vaultAddress,
|
|
107
|
+
redeem: { shares: params.shares },
|
|
108
|
+
deallocations: params.deallocations.map(({ adapter, assets, marketParams }) => ({
|
|
109
|
+
adapter,
|
|
110
|
+
assets,
|
|
111
|
+
...(marketParams && {
|
|
112
|
+
marketParams: {
|
|
113
|
+
loanToken: marketParams.loanToken,
|
|
114
|
+
collateralToken: marketParams.collateralToken,
|
|
115
|
+
oracle: marketParams.oracle,
|
|
116
|
+
irm: marketParams.irm,
|
|
117
|
+
lltv: marketParams.lltv,
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
})),
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
signatureRequests: [],
|
|
126
|
+
});
|
|
127
|
+
// Validate the cloned inputs with the action encoder before returning a plan.
|
|
128
|
+
buildVaultV2ForceRedeem(plan.steps[0].action);
|
|
129
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
|
|
130
|
+
return (0, morpho_ts_1.deepFreeze)(plan);
|
|
131
|
+
}
|
|
132
|
+
/** @internal Encodes the fixed multicall through the same action as the forceRedeem handle. */
|
|
133
|
+
function buildVaultV2ForceRedeem(action) {
|
|
134
|
+
return (0, forceRedeem_js_1.vaultV2ForceRedeem)({
|
|
135
|
+
vault: { address: action.inputs.vault },
|
|
136
|
+
args: {
|
|
137
|
+
deallocations: action.inputs.deallocations.map(({ adapter, assets, marketParams }) => ({
|
|
138
|
+
adapter,
|
|
139
|
+
amount: assets,
|
|
140
|
+
...(marketParams && {
|
|
141
|
+
marketParams: {
|
|
142
|
+
...marketParams,
|
|
143
|
+
id: blue_sdk_1.MarketUtils.getMarketId(marketParams),
|
|
144
|
+
liquidationIncentiveFactor: blue_sdk_1.MarketUtils.getLiquidationIncentiveFactor(marketParams),
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
})),
|
|
148
|
+
redeem: {
|
|
149
|
+
shares: action.inputs.redeem.shares,
|
|
150
|
+
recipient: action.inputs.account,
|
|
151
|
+
},
|
|
152
|
+
onBehalf: action.inputs.account,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address, type Client } from "viem";
|
|
3
|
+
import { type ReferenceTimestampParams, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
|
|
4
|
+
import { type IntentParams } from "../intent.js";
|
|
5
|
+
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Caller intent for a Vault V2 forced exit through VaultExitBundlesV1.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
12
|
+
* import type { VaultV2ForceWithdrawPlanParams } from "@morpho-org/morpho-sdk";
|
|
13
|
+
* import type { Address } from "viem";
|
|
14
|
+
* const intent = (vault: AccrualVaultV2, account: Address): VaultV2ForceWithdrawPlanParams => ({
|
|
15
|
+
* vault, account, chainId: 1, assets: 1_000_000n,
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface VaultV2ForceWithdrawPlanParams extends Omit<IntentParams, "deployless">, ReferenceTimestampParams {
|
|
20
|
+
/** Snapshot fetched by the caller; never stored in the plan. */
|
|
21
|
+
readonly vault: AccrualVaultV2;
|
|
22
|
+
/** Penalty-inclusive assets debited; received assets exclude penalties and referral fees. */
|
|
23
|
+
readonly assets: bigint;
|
|
24
|
+
/** Optional assertion that this is the vault's sole supported adapter. */
|
|
25
|
+
readonly adapter?: Address;
|
|
26
|
+
/** WAD-scaled tolerance for the derived floor; omitted values use the entity default. */
|
|
27
|
+
readonly slippageTolerance?: bigint;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
31
|
+
* Prepares a static forced-exit plan using shared snapshot quoting and requirement helpers.
|
|
32
|
+
* The adapter and realized share-price floor are fixed at preparation. VaultExitBundlesV1
|
|
33
|
+
* withdraws penalty-free liquidity first, then force-deallocates the remaining assets onchain.
|
|
34
|
+
* No fetch requests or Permit2 prerequisites are needed.
|
|
35
|
+
* @param client - Plain viem client for `params.chainId`, used for allowance, nonce and code reads.
|
|
36
|
+
* @param params.vault - Caller-fetched accrual snapshot used for the exit quote; its address identifies the vault.
|
|
37
|
+
* @param params.chainId - Chain containing the vault and registered VaultExitBundlesV1 contract.
|
|
38
|
+
* @param params.account - Non-zero account signing and sending the exit and receiving its assets.
|
|
39
|
+
* @param params.assets - Positive penalty-inclusive exit assets in asset base units; received assets exclude penalties and referral fees.
|
|
40
|
+
* @param params.adapter - Optional assertion that this address is the vault's sole supported adapter.
|
|
41
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance used to derive the realized share-price floor; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
|
|
42
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of withdrawn assets, after penalties; defaults to zero and must be below 10,000. The fee is deducted after the share-price check.
|
|
43
|
+
* @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
|
|
44
|
+
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; insufficient allowance produces an unlimited direct share approval, or an unlimited share permit when `true`.
|
|
45
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
46
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now` and within the fee-projection horizon; defaults to `now + 2h`.
|
|
47
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
48
|
+
* @returns A deep-frozen plan containing ordered share approvals, if needed, followed by the forced exit and its concrete permit request, if needed.
|
|
49
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
50
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
51
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `assets` is not positive.
|
|
52
|
+
* @throws {ExpiredDeadlineError} when the expiry has elapsed, including during requirement resolution.
|
|
53
|
+
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
54
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
55
|
+
* @throws {InputExceedsMaxError} when the fee exceeds 10,000 bps, an input exceeds uint256 or the expiry exceeds the fee-projection horizon.
|
|
56
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
57
|
+
* @throws {ChainIdMismatchError} when the client declares or serves another chain.
|
|
58
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
|
|
59
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
60
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the snapshot does not have exactly one adapter.
|
|
61
|
+
* @throws {AdapterNotPartOfVaultError} when the adapter assertion does not match the vault's adapter.
|
|
62
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the sole adapter is not a MorphoMarketV1AdapterV2.
|
|
63
|
+
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the liquidity adapter is neither unset nor the sole supported adapter.
|
|
64
|
+
* @throws {VaultV2UndecodableLiquidityDataError} when the configured liquidity data cannot be decoded as market parameters.
|
|
65
|
+
* @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit produces no assets after penalties.
|
|
66
|
+
* @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the required deallocation.
|
|
67
|
+
* @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when projected fee mints erase the net share burn.
|
|
68
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds to zero.
|
|
69
|
+
* @throws {UnsupportedChainIdError} when the chain has no address registry.
|
|
70
|
+
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the chain.
|
|
71
|
+
* @throws {MissingContractCodeError} when the registered exit bundle has no code.
|
|
72
|
+
* @throws {viem.BaseError} when a chain, code, allowance or nonce read fails.
|
|
73
|
+
* @throws {UnexpectedRequirementSignatureError} when a permit requirement omits its nonce.
|
|
74
|
+
* @throws {UnsupportedRequirementSignatureError} when a requirement is neither an approval nor an ERC-2612 permit.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { prepareVaultV2ForceWithdraw, buildTransactions } from "@morpho-org/morpho-sdk";
|
|
78
|
+
* import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
79
|
+
* import { createPublicClient, http, type Address } from "viem";
|
|
80
|
+
* import { mainnet } from "viem/chains";
|
|
81
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
82
|
+
* export async function forceWithdraw(vault: Address, account: Address) {
|
|
83
|
+
* const plan = await prepareVaultV2ForceWithdraw(client, {
|
|
84
|
+
* account, chainId: 1, assets: 1_000_000n,
|
|
85
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
86
|
+
* now: (await client.getBlock()).timestamp,
|
|
87
|
+
* });
|
|
88
|
+
* return buildTransactions(plan); // Submit approvals before the exit, from account.
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function prepareVaultV2ForceWithdraw(client: Client, params: VaultV2ForceWithdrawPlanParams): Promise<TransactionPlan>;
|
|
93
|
+
/** @internal Encodes the forced exit from fixed inputs and its referenced vault-share permit. */
|
|
94
|
+
export declare function buildVaultV2ForceWithdraw(action: Extract<Action, {
|
|
95
|
+
type: "vaultV2ForceWithdraw";
|
|
96
|
+
}>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2ForceWithdrawAction>>;
|
|
97
|
+
/** @internal Validates the stored forced withdrawal inputs. */
|
|
98
|
+
export declare function validateForceWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
|