@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareVaultV2Redeem = prepareVaultV2Redeem;
|
|
4
|
+
exports.buildVaultV2Redeem = buildVaultV2Redeem;
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
7
|
+
const redeem_js_1 = require("../../actions/vaultV2/redeem.js");
|
|
8
|
+
const permit_js_1 = require("../permit.js");
|
|
9
|
+
const redeem_js_2 = require("../redeem.js");
|
|
10
|
+
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
12
|
+
* Prepares an exact-share redemption through VaultBundlesV1. Reads share allowance and, when a
|
|
13
|
+
* permit is needed, the vault nonce. No quote or fetch request is needed for an exact share count.
|
|
14
|
+
* @param client - Viem client targeting `params.chainId`.
|
|
15
|
+
* @param params.shareToken - Vault share token; an address-only Token is sufficient, without an accrual snapshot.
|
|
16
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
17
|
+
* @param params.account - Non-zero share owner, permit signer and transaction sender; receives the net assets.
|
|
18
|
+
* @param params.shares - Positive exact shares to burn, in share base units; use the account's balance for full redemption.
|
|
19
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of gross redeemed assets; defaults to zero and must be below 10,000.
|
|
20
|
+
* @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
|
|
21
|
+
* @param params.supportSignature - Optional ERC-2612 share-permit preference; defaults to `false` for direct approval.
|
|
22
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
23
|
+
* @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).
|
|
24
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
25
|
+
* @returns A deep-frozen, serializable `TransactionPlan` with version, chain, account, expiry,
|
|
26
|
+
* ordered approval/redeem steps and signature requests. Any required share approval or permit is unlimited.
|
|
27
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
28
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
29
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
|
|
30
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
31
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
32
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
33
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
34
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
35
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
36
|
+
* @throws {ChainIdMismatchError} when the declared or RPC chain differs from `chainId`.
|
|
37
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
38
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
39
|
+
* @throws {MissingContractCodeError} when VaultBundlesV1 is absent on the target chain.
|
|
40
|
+
* @throws {viem.BaseError} when a chain, bytecode, allowance or permit nonce read fails.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { Token } from "@morpho-org/morpho-sdk/blue/entities";
|
|
44
|
+
* import { prepareVaultV2Redeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
45
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
46
|
+
* import { mainnet } from "viem/chains";
|
|
47
|
+
*
|
|
48
|
+
* // Supply a non-zero share owner and its desired redemption shares in share base units.
|
|
49
|
+
* export async function prepareRedeem(account: Address, shares: bigint): Promise<TransactionPlan> {
|
|
50
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
51
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
52
|
+
* const plan = await prepareVaultV2Redeem(client, {
|
|
53
|
+
* shareToken: new Token({ address: vault }), chainId: mainnet.id, account, shares, supportSignature: false,
|
|
54
|
+
* });
|
|
55
|
+
* // plan: TransactionPlan = { version: 2, chainId: 1, account, expiresAt,
|
|
56
|
+
* // steps: [optional unlimited approval, vaultV2Redeem], signatureRequests: [] }.
|
|
57
|
+
* return plan;
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async function prepareVaultV2Redeem(client, params) {
|
|
62
|
+
return (0, redeem_js_2.prepareVaultRedeem)(client, { ...params, type: "vaultV2Redeem" });
|
|
63
|
+
}
|
|
64
|
+
/** @internal Encodes a redemption from its fixed inputs and referenced share permit. */
|
|
65
|
+
function buildVaultV2Redeem(action, requests) {
|
|
66
|
+
const { chainId, account, vault, shares, ...common } = action.inputs;
|
|
67
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
68
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
69
|
+
asset: vault,
|
|
70
|
+
owner: account,
|
|
71
|
+
});
|
|
72
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
|
|
73
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
74
|
+
amount: shares,
|
|
75
|
+
deadline: action.inputs.deadline,
|
|
76
|
+
});
|
|
77
|
+
return (0, redeem_js_1.vaultV2Redeem)({
|
|
78
|
+
vault: { chainId, address: vault },
|
|
79
|
+
args: {
|
|
80
|
+
...common,
|
|
81
|
+
shares,
|
|
82
|
+
userAddress: account,
|
|
83
|
+
requirementSignature: permit,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { type IntentParams } from "../intent.js";
|
|
1
|
+
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import type { Transaction, VaultV2WithdrawAction } from "../../types/index.js";
|
|
5
4
|
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
|
-
|
|
7
|
-
export declare function validateWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
|
|
5
|
+
import { type WithdrawPlanParams } from "../withdraw.js";
|
|
8
6
|
/**
|
|
9
|
-
* Caller intent for a Vault V2 asset withdrawal, mirroring the Actions API withdraw inputs, plus the snapshot.
|
|
10
7
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Caller intent for a Vault V2 asset withdrawal, mirroring the Actions API withdraw inputs, plus the snapshot.
|
|
11
9
|
*/
|
|
12
|
-
export interface VaultV2WithdrawPlanParams extends
|
|
13
|
-
readonly vault: Address;
|
|
14
|
-
/** Gross assets withdrawn, before the referral fee. */
|
|
15
|
-
readonly amount: bigint;
|
|
16
|
-
/**
|
|
17
|
-
* Accrual snapshot of `vault`, fetched by the caller with `fetchAccrualVaultV2`. The required
|
|
18
|
-
* share allowance is derived from it at preparation; the snapshot itself is never stored.
|
|
19
|
-
*/
|
|
20
|
-
readonly vaultData: AccrualVaultV2;
|
|
10
|
+
export interface VaultV2WithdrawPlanParams extends WithdrawPlanParams<AccrualVaultV2> {
|
|
21
11
|
}
|
|
22
12
|
/**
|
|
13
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
23
14
|
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
24
15
|
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
25
16
|
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
@@ -28,28 +19,26 @@ export interface VaultV2WithdrawPlanParams extends IntentParams {
|
|
|
28
19
|
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
29
20
|
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
30
21
|
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
31
|
-
* @param params.vault -
|
|
32
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
22
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
33
23
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
34
24
|
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
35
|
-
* @param params.
|
|
36
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
25
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
26
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
37
27
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
38
28
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
39
|
-
* @param params.
|
|
29
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
30
|
+
* @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).
|
|
40
31
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
41
|
-
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
42
32
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
43
33
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
44
34
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
45
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
46
|
-
* @throws {ExpiredDeadlineError} when `expiresAt` is
|
|
35
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
36
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
47
37
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
48
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
38
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
49
39
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
50
40
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
51
41
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
52
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
53
42
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
54
43
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
55
44
|
* @see computeVaultMaxShareAllowance for quote errors.
|
|
@@ -63,12 +52,12 @@ export interface VaultV2WithdrawPlanParams extends IntentParams {
|
|
|
63
52
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
64
53
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
65
54
|
* const plan = await prepareVaultV2Withdraw(client, {
|
|
66
|
-
*
|
|
67
|
-
*
|
|
55
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
56
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
57
|
+
* now: (await client.getBlock()).timestamp,
|
|
68
58
|
* });
|
|
69
59
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
70
60
|
* ```
|
|
71
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
72
61
|
*/
|
|
73
62
|
export declare function prepareVaultV2Withdraw(client: Client, params: VaultV2WithdrawPlanParams): Promise<TransactionPlan>;
|
|
74
63
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
@@ -1,58 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawPlanAction = validateWithdrawPlanAction;
|
|
4
3
|
exports.prepareVaultV2Withdraw = prepareVaultV2Withdraw;
|
|
5
4
|
exports.buildVaultV2Withdraw = buildVaultV2Withdraw;
|
|
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 withdraw_js_1 = require("../../actions/vaultV2/withdraw.js");
|
|
12
|
-
const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
|
|
13
|
-
const getVaultBundlesSharesRequirements_js_1 = require("../../entities/requirements/getVaultBundlesSharesRequirements.js");
|
|
14
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
15
|
-
const validate_js_1 = require("../../helpers/validate.js");
|
|
16
|
-
const index_js_2 = require("../../types/index.js");
|
|
17
|
-
const intent_js_1 = require("../intent.js");
|
|
18
8
|
const permit_js_1 = require("../permit.js");
|
|
19
|
-
const
|
|
20
|
-
const validation_js_1 = require("../validation.js");
|
|
21
|
-
/** @internal Validates the stored Vault V2 withdrawal action's input shape. */
|
|
22
|
-
function validateWithdrawPlanAction(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: {
|
|
27
|
-
amount: "uint256 bigint",
|
|
28
|
-
requiredShareAllowance: "uint256 bigint",
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function resolveWithdrawInputs(params, now) {
|
|
33
|
-
const { vault, amount, vaultData } = params;
|
|
34
|
-
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
35
|
-
if (amount <= 0n)
|
|
36
|
-
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
37
|
-
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
38
|
-
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
39
|
-
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
40
|
-
deadline: intent.deadline,
|
|
41
|
-
referralFeePct: intent.referralFeePct,
|
|
42
|
-
referralFeeRecipient: intent.referralFeeRecipient,
|
|
43
|
-
});
|
|
44
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.address, vault))
|
|
45
|
-
throw new index_js_2.VaultAddressMismatchError(vaultData.address, vault);
|
|
46
|
-
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
47
|
-
const requiredShareAllowance = (0, index_js_1.computeVaultMaxShareAllowance)({
|
|
48
|
-
vaultData,
|
|
49
|
-
deadline: intent.deadline,
|
|
50
|
-
assets: amount,
|
|
51
|
-
slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
52
|
-
});
|
|
53
|
-
return { intent, common, requiredShareAllowance };
|
|
54
|
-
}
|
|
9
|
+
const withdraw_js_2 = require("../withdraw.js");
|
|
55
10
|
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
56
12
|
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
57
13
|
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
58
14
|
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
@@ -61,28 +17,26 @@ function resolveWithdrawInputs(params, now) {
|
|
|
61
17
|
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
62
18
|
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
63
19
|
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
64
|
-
* @param params.vault -
|
|
65
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
20
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
66
21
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
67
22
|
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
68
|
-
* @param params.
|
|
69
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
23
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
24
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
70
25
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
71
26
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
72
|
-
* @param params.
|
|
27
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
28
|
+
* @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).
|
|
73
29
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
74
|
-
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
75
30
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
76
31
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
77
32
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
78
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
79
|
-
* @throws {ExpiredDeadlineError} when `expiresAt` is
|
|
33
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
34
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
80
35
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
81
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
36
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
82
37
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
83
38
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
84
39
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
85
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
86
40
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
87
41
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
88
42
|
* @see computeVaultMaxShareAllowance for quote errors.
|
|
@@ -96,83 +50,19 @@ function resolveWithdrawInputs(params, now) {
|
|
|
96
50
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
97
51
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
98
52
|
* const plan = await prepareVaultV2Withdraw(client, {
|
|
99
|
-
*
|
|
100
|
-
*
|
|
53
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
54
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
55
|
+
* now: (await client.getBlock()).timestamp,
|
|
101
56
|
* });
|
|
102
57
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
103
58
|
* ```
|
|
104
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
105
59
|
*/
|
|
106
60
|
async function prepareVaultV2Withdraw(client, params) {
|
|
107
|
-
|
|
108
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
109
|
-
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
110
|
-
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
111
|
-
const [, , requirements] = await Promise.all([
|
|
112
|
-
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId),
|
|
113
|
-
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
114
|
-
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
115
|
-
]),
|
|
116
|
-
(0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(client, {
|
|
117
|
-
vaultData: new blue_sdk_1.Token({ address: vault }),
|
|
118
|
-
version: "vaultV2",
|
|
119
|
-
owner: account,
|
|
120
|
-
chainId,
|
|
121
|
-
requiredShareAllowance,
|
|
122
|
-
deadline: intent.deadline,
|
|
123
|
-
supportSignature: intent.supportSignature,
|
|
124
|
-
now,
|
|
125
|
-
}),
|
|
126
|
-
]);
|
|
127
|
-
const approvals = [];
|
|
128
|
-
const signatureRequests = [];
|
|
129
|
-
const tokenPermitRequestId = "vaultV2Withdraw:tokenPermit";
|
|
130
|
-
const requirement = requirements[0];
|
|
131
|
-
if (requirement !== undefined) {
|
|
132
|
-
if ("sign" in requirement) {
|
|
133
|
-
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
137
|
-
id: "vaultV2Withdraw:approval",
|
|
138
|
-
chainId,
|
|
139
|
-
account,
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
144
|
-
version: 1,
|
|
145
|
-
account,
|
|
146
|
-
chainId,
|
|
147
|
-
expiresAt: intent.expiresAt,
|
|
148
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
149
|
-
steps: [
|
|
150
|
-
...approvals,
|
|
151
|
-
{
|
|
152
|
-
id: "vaultV2Withdraw",
|
|
153
|
-
label: "Withdraw from vault",
|
|
154
|
-
action: {
|
|
155
|
-
type: "vaultV2Withdraw",
|
|
156
|
-
inputs: {
|
|
157
|
-
chainId,
|
|
158
|
-
account,
|
|
159
|
-
vault,
|
|
160
|
-
amount,
|
|
161
|
-
requiredShareAllowance,
|
|
162
|
-
...common,
|
|
163
|
-
},
|
|
164
|
-
signatureRequestIds: signatureRequests.length > 0
|
|
165
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
166
|
-
: {},
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
signatureRequests,
|
|
171
|
-
}));
|
|
61
|
+
return (0, withdraw_js_2.prepareVaultWithdraw)(client, { ...params, type: "vaultV2Withdraw" });
|
|
172
62
|
}
|
|
173
63
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
174
64
|
function buildVaultV2Withdraw(action, requests) {
|
|
175
|
-
const { requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
65
|
+
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
176
66
|
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
177
67
|
id: action.signatureRequestIds.tokenPermit,
|
|
178
68
|
asset: action.inputs.vault,
|
|
@@ -185,6 +75,11 @@ function buildVaultV2Withdraw(action, requests) {
|
|
|
185
75
|
});
|
|
186
76
|
return (0, withdraw_js_1.vaultV2Withdraw)({
|
|
187
77
|
vault: { chainId, address: action.inputs.vault },
|
|
188
|
-
args: {
|
|
78
|
+
args: {
|
|
79
|
+
...args,
|
|
80
|
+
amount: assets,
|
|
81
|
+
userAddress: account,
|
|
82
|
+
requirementSignature: permit,
|
|
83
|
+
},
|
|
189
84
|
});
|
|
190
85
|
}
|
|
@@ -4,6 +4,7 @@ exports.validateTransactionPlanVersion = validateTransactionPlanVersion;
|
|
|
4
4
|
const error_js_1 = require("./error.js");
|
|
5
5
|
/** @internal Rejects unsupported plan versions before interpreting stored fields. */
|
|
6
6
|
function validateTransactionPlanVersion(version) {
|
|
7
|
-
if (version !==
|
|
7
|
+
if (version !== 2) {
|
|
8
8
|
throw new error_js_1.UnsupportedTransactionPlanVersionError(version);
|
|
9
|
+
}
|
|
9
10
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type ReferenceTimestampParams } from "../types/index.js";
|
|
4
|
+
import { type IntentParams } from "./intent.js";
|
|
5
|
+
import type { TransactionPlan } from "./types.js";
|
|
6
|
+
/** @internal Validates the stored vault withdrawal action's input shape. */
|
|
7
|
+
export declare function validateWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
|
|
8
|
+
/** @internal Snapshot-based asset withdrawal intent shared by V1 and V2. */
|
|
9
|
+
export interface WithdrawPlanParams<TSnapshot extends AccrualVault | AccrualVaultV2> extends Omit<IntentParams, "deployless">, ReferenceTimestampParams {
|
|
10
|
+
/** Caller-fetched accrual snapshot used to quote the required share allowance. */
|
|
11
|
+
readonly vault: TSnapshot;
|
|
12
|
+
/** Gross assets withdrawn, before the referral fee. */
|
|
13
|
+
readonly assets: bigint;
|
|
14
|
+
}
|
|
15
|
+
/** @internal Fixes a withdrawal quote and resolves the vault-share prerequisites. */
|
|
16
|
+
export declare function prepareVaultWithdraw<TSnapshot extends AccrualVault | AccrualVaultV2>(client: Client, params: WithdrawPlanParams<TSnapshot> & {
|
|
17
|
+
readonly type: "vaultV1Withdraw" | "vaultV2Withdraw";
|
|
18
|
+
}): Promise<TransactionPlan>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateWithdrawPlanAction = validateWithdrawPlanAction;
|
|
4
|
+
exports.prepareVaultWithdraw = prepareVaultWithdraw;
|
|
5
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const common_js_1 = require("../actions/bundles/common.js");
|
|
8
|
+
const index_js_1 = require("../helpers/index.js");
|
|
9
|
+
const validate_js_1 = require("../helpers/validate.js");
|
|
10
|
+
const index_js_2 = require("../types/index.js");
|
|
11
|
+
const intent_js_1 = require("./intent.js");
|
|
12
|
+
const shareSpending_js_1 = require("./shareSpending.js");
|
|
13
|
+
const validation_js_1 = require("./validation.js");
|
|
14
|
+
/** @internal Validates the stored vault withdrawal action's input shape. */
|
|
15
|
+
function validateWithdrawPlanAction(action, path) {
|
|
16
|
+
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
17
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
18
|
+
path: `${path}.inputs`,
|
|
19
|
+
fields: {
|
|
20
|
+
assets: "uint256 bigint",
|
|
21
|
+
requiredShareAllowance: "uint256 bigint",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function resolveWithdrawInputs(params, now) {
|
|
26
|
+
const { vault, assets } = params;
|
|
27
|
+
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
28
|
+
if (assets <= 0n) {
|
|
29
|
+
throw new index_js_2.NonPositiveInputError("assets", assets);
|
|
30
|
+
}
|
|
31
|
+
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
32
|
+
(0, validate_js_1.validateUint256Field)("assets", assets);
|
|
33
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
34
|
+
deadline: intent.deadline,
|
|
35
|
+
referralFeePct: intent.referralFeePct,
|
|
36
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
37
|
+
});
|
|
38
|
+
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
39
|
+
const requiredShareAllowance = (0, index_js_1.computeVaultMaxShareAllowance)({
|
|
40
|
+
vaultData: vault,
|
|
41
|
+
deadline: intent.deadline,
|
|
42
|
+
assets,
|
|
43
|
+
slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
44
|
+
});
|
|
45
|
+
return { intent, common, requiredShareAllowance };
|
|
46
|
+
}
|
|
47
|
+
/** @internal Fixes a withdrawal quote and resolves the vault-share prerequisites. */
|
|
48
|
+
async function prepareVaultWithdraw(client, params) {
|
|
49
|
+
const { chainId, account, assets } = params;
|
|
50
|
+
const vault = params.vault.address;
|
|
51
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
52
|
+
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
53
|
+
const { approvals, signatureRequests, tokenPermitRequestId } = await (0, shareSpending_js_1.getVaultShareSpendingRequirements)(client, {
|
|
54
|
+
type: params.type,
|
|
55
|
+
shareToken: params.type === "vaultV1Withdraw"
|
|
56
|
+
? params.vault
|
|
57
|
+
: new blue_sdk_1.Token({ address: vault }),
|
|
58
|
+
chainId,
|
|
59
|
+
account,
|
|
60
|
+
requiredShareAllowance,
|
|
61
|
+
deadline: intent.deadline,
|
|
62
|
+
supportSignature: intent.supportSignature,
|
|
63
|
+
now,
|
|
64
|
+
});
|
|
65
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
66
|
+
version: 2,
|
|
67
|
+
account,
|
|
68
|
+
chainId,
|
|
69
|
+
expiresAt: intent.expiresAt,
|
|
70
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
71
|
+
steps: [
|
|
72
|
+
...approvals,
|
|
73
|
+
{
|
|
74
|
+
id: params.type,
|
|
75
|
+
label: "Withdraw from vault",
|
|
76
|
+
action: {
|
|
77
|
+
type: params.type,
|
|
78
|
+
inputs: {
|
|
79
|
+
chainId,
|
|
80
|
+
account,
|
|
81
|
+
vault,
|
|
82
|
+
assets,
|
|
83
|
+
requiredShareAllowance,
|
|
84
|
+
...common,
|
|
85
|
+
},
|
|
86
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
87
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
88
|
+
: {},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
signatureRequests,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
@@ -534,12 +534,23 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
534
534
|
readonly deadline: bigint;
|
|
535
535
|
}> {
|
|
536
536
|
}
|
|
537
|
+
/**
|
|
538
|
+
* Metadata for a direct Midnight cancellation of offer groups. One group is a bare
|
|
539
|
+
* `setConsumed` call; two or more are one Midnight `multicall` of `setConsumed` calls.
|
|
540
|
+
*/
|
|
541
|
+
export interface MidnightCancelOffersAction extends BaseAction<"midnightCancelOffers", {
|
|
542
|
+
/** Offer groups cancelled in full, in encoded order. */
|
|
543
|
+
readonly groups: readonly Hex[];
|
|
544
|
+
/** Maker whose groups are cancelled. */
|
|
545
|
+
readonly onBehalf: Address;
|
|
546
|
+
}> {
|
|
547
|
+
}
|
|
537
548
|
/**
|
|
538
549
|
* Enumerates every action a {@link Transaction} can describe across the VaultV1,
|
|
539
550
|
* VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
|
|
540
551
|
* consumers can `switch` exhaustively on it.
|
|
541
552
|
*/
|
|
542
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
553
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction | MidnightCancelOffersAction;
|
|
543
554
|
/**
|
|
544
555
|
* Describes a single, immutable, deep-frozen transaction to submit on-chain:
|
|
545
556
|
* the target `to`, native `value`, encoded call `data`, and the originating
|
|
@@ -731,6 +742,18 @@ export type CallRequirementAction = ERC20ApprovalAction | BlueAuthorizationActio
|
|
|
731
742
|
export type CallRequirement = Readonly<Transaction<CallRequirementAction>>;
|
|
732
743
|
/** Onchain call or signature prerequisite returned by an entity action output. */
|
|
733
744
|
export type ActionRequirement = CallRequirement | SignatureRequirement;
|
|
745
|
+
/** Optional reference time for preparing a transaction flow. */
|
|
746
|
+
export interface ReferenceTimestampParams {
|
|
747
|
+
/**
|
|
748
|
+
* Reference timestamp in seconds, normally the latest block's `timestamp`
|
|
749
|
+
* (e.g. `(await client.getBlock()).timestamp`). Omitting it falls back to the
|
|
750
|
+
* device clock; this fallback is deprecated and `now` becomes required in the
|
|
751
|
+
* next major. Entity `getRequirements()` calls reuse a supplied `now` rather
|
|
752
|
+
* than re-reading time. If collecting requirements later, create a new handle
|
|
753
|
+
* using a newer block's timestamp.
|
|
754
|
+
*/
|
|
755
|
+
readonly now?: bigint;
|
|
756
|
+
}
|
|
734
757
|
/** Optional controls used while resolving action prerequisites. */
|
|
735
758
|
interface ActionRequirementsParams {
|
|
736
759
|
/**
|
|
@@ -743,6 +766,7 @@ interface ActionRequirementsParams {
|
|
|
743
766
|
/** Lazy entity result exposing prerequisite resolution and synchronous transaction building. */
|
|
744
767
|
export interface ActionOutput<TAction extends BaseAction = TransactionAction, TSignatures = RequirementSignature, TRequirementsParams = ActionRequirementsParams> {
|
|
745
768
|
readonly buildTx: (signatures?: TSignatures) => Readonly<Transaction<TAction>>;
|
|
769
|
+
/** Resolves prerequisites using the flow's {@link ReferenceTimestampParams.now | reference timestamp}. */
|
|
746
770
|
readonly getRequirements: (params?: TRequirementsParams) => Promise<readonly ActionRequirement[]>;
|
|
747
771
|
}
|
|
748
772
|
/**
|
|
@@ -827,7 +851,7 @@ export declare function isRequirementApproval(requirement: unknown): requirement
|
|
|
827
851
|
* userAddress: zeroAddress,
|
|
828
852
|
* borrowAssets: 1_000_000n,
|
|
829
853
|
* positionData,
|
|
830
|
-
* deadline:
|
|
854
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
831
855
|
* });
|
|
832
856
|
*
|
|
833
857
|
* for (const requirement of await handle.getRequirements()) {
|
package/lib/cjs/types/action.js
CHANGED
|
@@ -101,7 +101,7 @@ function isRequirementApproval(requirement) {
|
|
|
101
101
|
* userAddress: zeroAddress,
|
|
102
102
|
* borrowAssets: 1_000_000n,
|
|
103
103
|
* positionData,
|
|
104
|
-
* deadline:
|
|
104
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
105
105
|
* });
|
|
106
106
|
*
|
|
107
107
|
* for (const requirement of await handle.getRequirements()) {
|
|
@@ -218,28 +218,36 @@ function isAuthorizationSignature(signature) {
|
|
|
218
218
|
* ```
|
|
219
219
|
*/
|
|
220
220
|
function selectRequirementSignatures(signatures, accepts) {
|
|
221
|
-
if (signatures == null)
|
|
221
|
+
if (signatures == null) {
|
|
222
222
|
return {};
|
|
223
|
+
}
|
|
223
224
|
const permits = signatures.filter(isPermitSignature);
|
|
224
225
|
const permit2Transfers = signatures.filter(isPermit2SignatureTransferSignature);
|
|
225
226
|
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
226
227
|
const unsupported = signatures.find((signature) => !isPermitSignature(signature) &&
|
|
227
228
|
!isPermit2SignatureTransferSignature(signature) &&
|
|
228
229
|
!isAuthorizationSignature(signature));
|
|
229
|
-
if (unsupported != null)
|
|
230
|
+
if (unsupported != null) {
|
|
230
231
|
throw new error_js_1.UnsupportedRequirementSignatureError(unsupported.action.type);
|
|
231
|
-
|
|
232
|
+
}
|
|
233
|
+
if (!accepts.permit && permits.length > 0) {
|
|
232
234
|
throw new error_js_1.UnexpectedRequirementSignatureError("permit");
|
|
233
|
-
|
|
235
|
+
}
|
|
236
|
+
if (!accepts.permit2SignatureTransfer && permit2Transfers.length > 0) {
|
|
234
237
|
throw new error_js_1.UnexpectedRequirementSignatureError("permit2SignatureTransfer");
|
|
235
|
-
|
|
238
|
+
}
|
|
239
|
+
if (!accepts.authorization && authorizations.length > 0) {
|
|
236
240
|
throw new error_js_1.UnexpectedRequirementSignatureError("authorization");
|
|
237
|
-
|
|
241
|
+
}
|
|
242
|
+
if (permits.length > 1) {
|
|
238
243
|
throw new error_js_1.AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
239
|
-
|
|
244
|
+
}
|
|
245
|
+
if (permit2Transfers.length > 1) {
|
|
240
246
|
throw new error_js_1.AmbiguousRequirementSignaturesError("permit2SignatureTransfer", permit2Transfers.length);
|
|
241
|
-
|
|
247
|
+
}
|
|
248
|
+
if (authorizations.length > 1) {
|
|
242
249
|
throw new error_js_1.AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
250
|
+
}
|
|
243
251
|
return {
|
|
244
252
|
permit: permits[0],
|
|
245
253
|
permit2SignatureTransfer: permit2Transfers[0],
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -711,7 +711,10 @@ export declare class AddressMismatchError extends Error {
|
|
|
711
711
|
export declare class ChainIdMismatchError extends Error {
|
|
712
712
|
constructor(clientChainId: number | undefined, argsChainId: number);
|
|
713
713
|
}
|
|
714
|
-
/**
|
|
714
|
+
/**
|
|
715
|
+
* Thrown when a runtime crypto API is required but unavailable.
|
|
716
|
+
* @deprecated This error is never thrown by the SDK and will be removed in the next major version.
|
|
717
|
+
*/
|
|
715
718
|
export declare class CryptoUnavailableError extends Error {
|
|
716
719
|
constructor(feature: string);
|
|
717
720
|
}
|
|
@@ -775,6 +778,10 @@ export declare class ChainWNativeMissingError extends Error {
|
|
|
775
778
|
}
|
|
776
779
|
/** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
|
|
777
780
|
export declare class VaultAddressMismatchError extends Error {
|
|
781
|
+
/** Vault targeted by the caller. */
|
|
782
|
+
readonly expected: Address;
|
|
783
|
+
/** Vault address found in the supplied snapshot. */
|
|
784
|
+
readonly actual: Address;
|
|
778
785
|
constructor(vaultAddress: Address, argsVaultAddress: Address);
|
|
779
786
|
}
|
|
780
787
|
/** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
|