@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,82 @@
|
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
|
+
import { vaultV2Redeem } from "../../actions/vaultV2/redeem.js";
|
|
4
|
+
import { getVaultPermit } from "../permit.js";
|
|
5
|
+
import { prepareVaultRedeem } from "../redeem.js";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Prepares an exact-share redemption through VaultBundlesV1. Reads share allowance and, when a
|
|
9
|
+
* permit is needed, the vault nonce. No quote or fetch request is needed for an exact share count.
|
|
10
|
+
* @param client - Viem client targeting `params.chainId`.
|
|
11
|
+
* @param params.shareToken - Vault share token; an address-only Token is sufficient, without an accrual snapshot.
|
|
12
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
13
|
+
* @param params.account - Non-zero share owner, permit signer and transaction sender; receives the net assets.
|
|
14
|
+
* @param params.shares - Positive exact shares to burn, in share base units; use the account's balance for full redemption.
|
|
15
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of gross redeemed assets; defaults to zero and must be below 10,000.
|
|
16
|
+
* @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
|
|
17
|
+
* @param params.supportSignature - Optional ERC-2612 share-permit preference; defaults to `false` for direct approval.
|
|
18
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
19
|
+
* @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).
|
|
20
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
21
|
+
* @returns A deep-frozen, serializable `TransactionPlan` with version, chain, account, expiry,
|
|
22
|
+
* ordered approval/redeem steps and signature requests. Any required share approval or permit is unlimited.
|
|
23
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
24
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
25
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
|
|
26
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
27
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
28
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
29
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
30
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
31
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
32
|
+
* @throws {ChainIdMismatchError} when the declared or RPC chain differs from `chainId`.
|
|
33
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
34
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
35
|
+
* @throws {MissingContractCodeError} when VaultBundlesV1 is absent on the target chain.
|
|
36
|
+
* @throws {viem.BaseError} when a chain, bytecode, allowance or permit nonce read fails.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { Token } from "@morpho-org/morpho-sdk/blue/entities";
|
|
40
|
+
* import { prepareVaultV2Redeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
41
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
42
|
+
* import { mainnet } from "viem/chains";
|
|
43
|
+
*
|
|
44
|
+
* // Supply a non-zero share owner and its desired redemption shares in share base units.
|
|
45
|
+
* export async function prepareRedeem(account: Address, shares: bigint): Promise<TransactionPlan> {
|
|
46
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
47
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
48
|
+
* const plan = await prepareVaultV2Redeem(client, {
|
|
49
|
+
* shareToken: new Token({ address: vault }), chainId: mainnet.id, account, shares, supportSignature: false,
|
|
50
|
+
* });
|
|
51
|
+
* // plan: TransactionPlan = { version: 2, chainId: 1, account, expiresAt,
|
|
52
|
+
* // steps: [optional unlimited approval, vaultV2Redeem], signatureRequests: [] }.
|
|
53
|
+
* return plan;
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export async function prepareVaultV2Redeem(client, params) {
|
|
58
|
+
return prepareVaultRedeem(client, { ...params, type: "vaultV2Redeem" });
|
|
59
|
+
}
|
|
60
|
+
/** @internal Encodes a redemption from its fixed inputs and referenced share permit. */
|
|
61
|
+
export function buildVaultV2Redeem(action, requests) {
|
|
62
|
+
const { chainId, account, vault, shares, ...common } = action.inputs;
|
|
63
|
+
const signature = getVaultPermit(requests, {
|
|
64
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
65
|
+
asset: vault,
|
|
66
|
+
owner: account,
|
|
67
|
+
});
|
|
68
|
+
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
69
|
+
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
70
|
+
amount: shares,
|
|
71
|
+
deadline: action.inputs.deadline,
|
|
72
|
+
});
|
|
73
|
+
return vaultV2Redeem({
|
|
74
|
+
vault: { chainId, address: vault },
|
|
75
|
+
args: {
|
|
76
|
+
...common,
|
|
77
|
+
shares,
|
|
78
|
+
userAddress: account,
|
|
79
|
+
requirementSignature: permit,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -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,53 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isAddressEqual } from "viem";
|
|
4
|
-
import { normalizeBundlesCommonParams, selectBundlesSharesPermitSignature, } from "../../actions/bundles/common.js";
|
|
5
|
-
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
6
3
|
import { vaultV2Withdraw } from "../../actions/vaultV2/withdraw.js";
|
|
7
|
-
import { assertRegistryTargetsHaveCode } from "../../entities/requirements/assertContractCode.js";
|
|
8
|
-
import { getVaultBundlesSharesRequirements } from "../../entities/requirements/getVaultBundlesSharesRequirements.js";
|
|
9
|
-
import { computeVaultMaxShareAllowance } from "../../helpers/index.js";
|
|
10
|
-
import { validateUint256Field } from "../../helpers/validate.js";
|
|
11
|
-
import { NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
|
|
12
|
-
import { resolveIntent } from "../intent.js";
|
|
13
4
|
import { getVaultPermit } from "../permit.js";
|
|
14
|
-
import {
|
|
15
|
-
import { validatePlanFields, validateVaultPlanAction } from "../validation.js";
|
|
16
|
-
/** @internal Validates the stored Vault V2 withdrawal action's input shape. */
|
|
17
|
-
export function validateWithdrawPlanAction(action, path) {
|
|
18
|
-
const inputs = validateVaultPlanAction(action, path);
|
|
19
|
-
validatePlanFields(inputs, {
|
|
20
|
-
path: `${path}.inputs`,
|
|
21
|
-
fields: {
|
|
22
|
-
amount: "uint256 bigint",
|
|
23
|
-
requiredShareAllowance: "uint256 bigint",
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function resolveWithdrawInputs(params, now) {
|
|
28
|
-
const { vault, amount, vaultData } = params;
|
|
29
|
-
const intent = resolveIntent(params, now);
|
|
30
|
-
if (amount <= 0n)
|
|
31
|
-
throw new NonPositiveInputError("amount", amount);
|
|
32
|
-
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
33
|
-
validateUint256Field("amount", amount);
|
|
34
|
-
const common = normalizeBundlesCommonParams({
|
|
35
|
-
deadline: intent.deadline,
|
|
36
|
-
referralFeePct: intent.referralFeePct,
|
|
37
|
-
referralFeeRecipient: intent.referralFeeRecipient,
|
|
38
|
-
});
|
|
39
|
-
if (!isAddressEqual(vaultData.address, vault))
|
|
40
|
-
throw new VaultAddressMismatchError(vaultData.address, vault);
|
|
41
|
-
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
42
|
-
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
43
|
-
vaultData,
|
|
44
|
-
deadline: intent.deadline,
|
|
45
|
-
assets: amount,
|
|
46
|
-
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
47
|
-
});
|
|
48
|
-
return { intent, common, requiredShareAllowance };
|
|
49
|
-
}
|
|
5
|
+
import { prepareVaultWithdraw } from "../withdraw.js";
|
|
50
6
|
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
51
8
|
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
52
9
|
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
53
10
|
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
@@ -56,28 +13,26 @@ function resolveWithdrawInputs(params, now) {
|
|
|
56
13
|
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
57
14
|
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
58
15
|
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
59
|
-
* @param params.vault -
|
|
60
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
16
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
61
17
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
62
18
|
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
63
|
-
* @param params.
|
|
64
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
19
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
20
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
65
21
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
66
22
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
67
|
-
* @param params.
|
|
23
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
24
|
+
* @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).
|
|
68
25
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
69
|
-
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
70
26
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
71
27
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
72
28
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
73
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
74
|
-
* @throws {ExpiredDeadlineError} when `expiresAt` is
|
|
29
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
30
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
75
31
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
76
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
32
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
77
33
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
78
34
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
79
35
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
80
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
81
36
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
82
37
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
83
38
|
* @see computeVaultMaxShareAllowance for quote errors.
|
|
@@ -91,83 +46,19 @@ function resolveWithdrawInputs(params, now) {
|
|
|
91
46
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
92
47
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
93
48
|
* const plan = await prepareVaultV2Withdraw(client, {
|
|
94
|
-
*
|
|
95
|
-
*
|
|
49
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
50
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
51
|
+
* now: (await client.getBlock()).timestamp,
|
|
96
52
|
* });
|
|
97
53
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
98
54
|
* ```
|
|
99
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
100
55
|
*/
|
|
101
56
|
export async function prepareVaultV2Withdraw(client, params) {
|
|
102
|
-
|
|
103
|
-
const now = Time.timestamp();
|
|
104
|
-
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
105
|
-
const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
|
|
106
|
-
const [, , requirements] = await Promise.all([
|
|
107
|
-
validateClientChainId(client, chainId),
|
|
108
|
-
assertRegistryTargetsHaveCode(client, chainId, [
|
|
109
|
-
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
110
|
-
]),
|
|
111
|
-
getVaultBundlesSharesRequirements(client, {
|
|
112
|
-
vaultData: new Token({ address: vault }),
|
|
113
|
-
version: "vaultV2",
|
|
114
|
-
owner: account,
|
|
115
|
-
chainId,
|
|
116
|
-
requiredShareAllowance,
|
|
117
|
-
deadline: intent.deadline,
|
|
118
|
-
supportSignature: intent.supportSignature,
|
|
119
|
-
now,
|
|
120
|
-
}),
|
|
121
|
-
]);
|
|
122
|
-
const approvals = [];
|
|
123
|
-
const signatureRequests = [];
|
|
124
|
-
const tokenPermitRequestId = "vaultV2Withdraw:tokenPermit";
|
|
125
|
-
const requirement = requirements[0];
|
|
126
|
-
if (requirement !== undefined) {
|
|
127
|
-
if ("sign" in requirement) {
|
|
128
|
-
signatureRequests.push(buildPermitSignatureRequest(requirement, tokenPermitRequestId));
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
approvals.push(buildApprovalStep(requirement, {
|
|
132
|
-
id: "vaultV2Withdraw:approval",
|
|
133
|
-
chainId,
|
|
134
|
-
account,
|
|
135
|
-
}));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return deepFreeze(structuredClone({
|
|
139
|
-
version: 1,
|
|
140
|
-
account,
|
|
141
|
-
chainId,
|
|
142
|
-
expiresAt: intent.expiresAt,
|
|
143
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
144
|
-
steps: [
|
|
145
|
-
...approvals,
|
|
146
|
-
{
|
|
147
|
-
id: "vaultV2Withdraw",
|
|
148
|
-
label: "Withdraw from vault",
|
|
149
|
-
action: {
|
|
150
|
-
type: "vaultV2Withdraw",
|
|
151
|
-
inputs: {
|
|
152
|
-
chainId,
|
|
153
|
-
account,
|
|
154
|
-
vault,
|
|
155
|
-
amount,
|
|
156
|
-
requiredShareAllowance,
|
|
157
|
-
...common,
|
|
158
|
-
},
|
|
159
|
-
signatureRequestIds: signatureRequests.length > 0
|
|
160
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
161
|
-
: {},
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
signatureRequests,
|
|
166
|
-
}));
|
|
57
|
+
return prepareVaultWithdraw(client, { ...params, type: "vaultV2Withdraw" });
|
|
167
58
|
}
|
|
168
59
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
169
60
|
export function buildVaultV2Withdraw(action, requests) {
|
|
170
|
-
const { requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
61
|
+
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
171
62
|
const signature = getVaultPermit(requests, {
|
|
172
63
|
id: action.signatureRequestIds.tokenPermit,
|
|
173
64
|
asset: action.inputs.vault,
|
|
@@ -180,6 +71,11 @@ export function buildVaultV2Withdraw(action, requests) {
|
|
|
180
71
|
});
|
|
181
72
|
return vaultV2Withdraw({
|
|
182
73
|
vault: { chainId, address: action.inputs.vault },
|
|
183
|
-
args: {
|
|
74
|
+
args: {
|
|
75
|
+
...args,
|
|
76
|
+
amount: assets,
|
|
77
|
+
userAddress: account,
|
|
78
|
+
requirementSignature: permit,
|
|
79
|
+
},
|
|
184
80
|
});
|
|
185
81
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UnsupportedTransactionPlanVersionError } from "./error.js";
|
|
2
2
|
/** @internal Rejects unsupported plan versions before interpreting stored fields. */
|
|
3
3
|
export function validateTransactionPlanVersion(version) {
|
|
4
|
-
if (version !==
|
|
4
|
+
if (version !== 2) {
|
|
5
5
|
throw new UnsupportedTransactionPlanVersionError(version);
|
|
6
|
+
}
|
|
6
7
|
}
|
|
@@ -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,90 @@
|
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Token, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { deepFreeze, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { normalizeBundlesCommonParams } from "../actions/bundles/common.js";
|
|
4
|
+
import { computeVaultMaxShareAllowance } from "../helpers/index.js";
|
|
5
|
+
import { validateUint256Field } from "../helpers/validate.js";
|
|
6
|
+
import { NonPositiveInputError, } from "../types/index.js";
|
|
7
|
+
import { resolveIntent } from "./intent.js";
|
|
8
|
+
import { getVaultShareSpendingRequirements } from "./shareSpending.js";
|
|
9
|
+
import { validatePlanFields, validateVaultPlanAction } from "./validation.js";
|
|
10
|
+
/** @internal Validates the stored vault withdrawal action's input shape. */
|
|
11
|
+
export function validateWithdrawPlanAction(action, path) {
|
|
12
|
+
const inputs = validateVaultPlanAction(action, path);
|
|
13
|
+
validatePlanFields(inputs, {
|
|
14
|
+
path: `${path}.inputs`,
|
|
15
|
+
fields: {
|
|
16
|
+
assets: "uint256 bigint",
|
|
17
|
+
requiredShareAllowance: "uint256 bigint",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function resolveWithdrawInputs(params, now) {
|
|
22
|
+
const { vault, assets } = params;
|
|
23
|
+
const intent = resolveIntent(params, now);
|
|
24
|
+
if (assets <= 0n) {
|
|
25
|
+
throw new NonPositiveInputError("assets", assets);
|
|
26
|
+
}
|
|
27
|
+
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
28
|
+
validateUint256Field("assets", assets);
|
|
29
|
+
const common = normalizeBundlesCommonParams({
|
|
30
|
+
deadline: intent.deadline,
|
|
31
|
+
referralFeePct: intent.referralFeePct,
|
|
32
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
33
|
+
});
|
|
34
|
+
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
35
|
+
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
36
|
+
vaultData: vault,
|
|
37
|
+
deadline: intent.deadline,
|
|
38
|
+
assets,
|
|
39
|
+
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
40
|
+
});
|
|
41
|
+
return { intent, common, requiredShareAllowance };
|
|
42
|
+
}
|
|
43
|
+
/** @internal Fixes a withdrawal quote and resolves the vault-share prerequisites. */
|
|
44
|
+
export async function prepareVaultWithdraw(client, params) {
|
|
45
|
+
const { chainId, account, assets } = params;
|
|
46
|
+
const vault = params.vault.address;
|
|
47
|
+
const now = params.now ?? Time.timestamp();
|
|
48
|
+
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
49
|
+
const { approvals, signatureRequests, tokenPermitRequestId } = await getVaultShareSpendingRequirements(client, {
|
|
50
|
+
type: params.type,
|
|
51
|
+
shareToken: params.type === "vaultV1Withdraw"
|
|
52
|
+
? params.vault
|
|
53
|
+
: new Token({ address: vault }),
|
|
54
|
+
chainId,
|
|
55
|
+
account,
|
|
56
|
+
requiredShareAllowance,
|
|
57
|
+
deadline: intent.deadline,
|
|
58
|
+
supportSignature: intent.supportSignature,
|
|
59
|
+
now,
|
|
60
|
+
});
|
|
61
|
+
return deepFreeze(structuredClone({
|
|
62
|
+
version: 2,
|
|
63
|
+
account,
|
|
64
|
+
chainId,
|
|
65
|
+
expiresAt: intent.expiresAt,
|
|
66
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
67
|
+
steps: [
|
|
68
|
+
...approvals,
|
|
69
|
+
{
|
|
70
|
+
id: params.type,
|
|
71
|
+
label: "Withdraw from vault",
|
|
72
|
+
action: {
|
|
73
|
+
type: params.type,
|
|
74
|
+
inputs: {
|
|
75
|
+
chainId,
|
|
76
|
+
account,
|
|
77
|
+
vault,
|
|
78
|
+
assets,
|
|
79
|
+
requiredShareAllowance,
|
|
80
|
+
...common,
|
|
81
|
+
},
|
|
82
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
83
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
84
|
+
: {},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
signatureRequests,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
@@ -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/esm/types/action.js
CHANGED
|
@@ -92,7 +92,7 @@ export function isRequirementApproval(requirement) {
|
|
|
92
92
|
* userAddress: zeroAddress,
|
|
93
93
|
* borrowAssets: 1_000_000n,
|
|
94
94
|
* positionData,
|
|
95
|
-
* deadline:
|
|
95
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
96
96
|
* });
|
|
97
97
|
*
|
|
98
98
|
* for (const requirement of await handle.getRequirements()) {
|
|
@@ -209,28 +209,36 @@ export function isAuthorizationSignature(signature) {
|
|
|
209
209
|
* ```
|
|
210
210
|
*/
|
|
211
211
|
export function selectRequirementSignatures(signatures, accepts) {
|
|
212
|
-
if (signatures == null)
|
|
212
|
+
if (signatures == null) {
|
|
213
213
|
return {};
|
|
214
|
+
}
|
|
214
215
|
const permits = signatures.filter(isPermitSignature);
|
|
215
216
|
const permit2Transfers = signatures.filter(isPermit2SignatureTransferSignature);
|
|
216
217
|
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
217
218
|
const unsupported = signatures.find((signature) => !isPermitSignature(signature) &&
|
|
218
219
|
!isPermit2SignatureTransferSignature(signature) &&
|
|
219
220
|
!isAuthorizationSignature(signature));
|
|
220
|
-
if (unsupported != null)
|
|
221
|
+
if (unsupported != null) {
|
|
221
222
|
throw new UnsupportedRequirementSignatureError(unsupported.action.type);
|
|
222
|
-
|
|
223
|
+
}
|
|
224
|
+
if (!accepts.permit && permits.length > 0) {
|
|
223
225
|
throw new UnexpectedRequirementSignatureError("permit");
|
|
224
|
-
|
|
226
|
+
}
|
|
227
|
+
if (!accepts.permit2SignatureTransfer && permit2Transfers.length > 0) {
|
|
225
228
|
throw new UnexpectedRequirementSignatureError("permit2SignatureTransfer");
|
|
226
|
-
|
|
229
|
+
}
|
|
230
|
+
if (!accepts.authorization && authorizations.length > 0) {
|
|
227
231
|
throw new UnexpectedRequirementSignatureError("authorization");
|
|
228
|
-
|
|
232
|
+
}
|
|
233
|
+
if (permits.length > 1) {
|
|
229
234
|
throw new AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
230
|
-
|
|
235
|
+
}
|
|
236
|
+
if (permit2Transfers.length > 1) {
|
|
231
237
|
throw new AmbiguousRequirementSignaturesError("permit2SignatureTransfer", permit2Transfers.length);
|
|
232
|
-
|
|
238
|
+
}
|
|
239
|
+
if (authorizations.length > 1) {
|
|
233
240
|
throw new AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
241
|
+
}
|
|
234
242
|
return {
|
|
235
243
|
permit: permits[0],
|
|
236
244
|
permit2SignatureTransfer: permit2Transfers[0],
|
package/lib/esm/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. */
|