@morpho-org/morpho-sdk 10.0.0-next.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/README.md +104 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- 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.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.js +2 -1
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -1
- package/lib/cjs/actions/midnight/takeLend.js +2 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +2 -1
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -11
- 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/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/blue/blue.js +8 -4
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/deadline.js +2 -1
- package/lib/cjs/entities/midnight/midnight.js +14 -7
- package/lib/cjs/entities/midnight/publication.js +73 -44
- package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +9 -13
- package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
- 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.js +51 -181
- 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 +8 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +62 -429
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +346 -234
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +6 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.js +34 -19
- package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/cjs/helpers/metadata.js +12 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -5
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +6 -3
- package/lib/cjs/helpers/utilization.js +10 -5
- package/lib/cjs/helpers/validate.js +12 -6
- 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 +44 -22
- package/lib/cjs/helpers/validatePositiveInput.js +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +14 -7
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +10 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- 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 +72 -22
- 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 +41 -15
- 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 +14 -31
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +15 -141
- 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 +14 -27
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +17 -124
- 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.js +16 -8
- package/lib/cjs/types/error.d.ts +8 -1
- package/lib/cjs/types/error.js +10 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.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.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.js +2 -1
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
- package/lib/esm/actions/midnight/takeBorrow.js +2 -1
- package/lib/esm/actions/midnight/takeLend.js +2 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +2 -1
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +4 -13
- 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/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.js +8 -4
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/deadline.js +2 -1
- package/lib/esm/entities/midnight/midnight.js +14 -7
- package/lib/esm/entities/midnight/publication.js +73 -44
- package/lib/esm/entities/requirements/assertContractCode.js +4 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +10 -14
- package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
- 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.js +57 -187
- 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 +8 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +70 -437
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +346 -234
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +35 -20
- package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/esm/helpers/metadata.js +12 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -5
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +6 -3
- package/lib/esm/helpers/utilization.js +10 -5
- package/lib/esm/helpers/validate.js +12 -6
- 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 +44 -22
- package/lib/esm/helpers/validatePositiveInput.js +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +2 -1
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +14 -7
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- 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 +68 -18
- 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 +41 -15
- 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 +14 -31
- package/lib/esm/transactionPlan/vaultv2/deposit.js +17 -142
- 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 +14 -27
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +19 -125
- 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.js +16 -8
- package/lib/esm/types/error.d.ts +8 -1
- package/lib/esm/types/error.js +10 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +15 -15
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, Token, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual } from "viem";
|
|
4
|
+
import { normalizeBundlesCommonParams, selectBundlesSharesPermitSignature, } from "../../actions/bundles/common.js";
|
|
5
|
+
import { vaultV1MigrateToV2 } from "../../actions/vaultV1/migrateToV2.js";
|
|
6
|
+
import { computeVaultV1MigrateToV2Quote } from "../../entities/vaultV1/migrateToV2Quote.js";
|
|
7
|
+
import { validateSlippageTolerance, validateUint256Field, } from "../../helpers/validate.js";
|
|
8
|
+
import { AmountAndSharesExclusiveError, NonPositiveInputError, SameVaultMigrationError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
9
|
+
import { InvalidTransactionPlanError } from "../error.js";
|
|
10
|
+
import { resolveIntent } from "../intent.js";
|
|
11
|
+
import { getVaultPermit } from "../permit.js";
|
|
12
|
+
import { getVaultShareSpendingRequirements } from "../shareSpending.js";
|
|
13
|
+
import { getPlanObject, validatePlanField, validatePlanFields, validateVaultPlanAction, } from "../validation.js";
|
|
14
|
+
/** @internal Validates the stored Vault V1 migration action's input shape. */
|
|
15
|
+
export function validateMigrateToV2PlanAction(action, path) {
|
|
16
|
+
const inputs = validateVaultPlanAction(action, path);
|
|
17
|
+
validatePlanFields(inputs, {
|
|
18
|
+
path: `${path}.inputs`,
|
|
19
|
+
fields: {
|
|
20
|
+
sourceVault: "address",
|
|
21
|
+
targetVault: "address",
|
|
22
|
+
asset: "address",
|
|
23
|
+
maxSharePrice: "uint256 bigint",
|
|
24
|
+
requiredShareAllowance: "uint256 bigint",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
if (!isAddressEqual(inputs.vault, inputs.sourceVault)) {
|
|
28
|
+
throw new InvalidTransactionPlanError({
|
|
29
|
+
path: `${path}.inputs.vault`,
|
|
30
|
+
reason: "expected sourceVault",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if ((inputs.assets === undefined) === (inputs.shares === undefined)) {
|
|
34
|
+
throw new InvalidTransactionPlanError({
|
|
35
|
+
path: `${path}.inputs`,
|
|
36
|
+
reason: "expected exactly one of assets or shares",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const field = inputs.assets === undefined ? "shares" : "assets";
|
|
40
|
+
validatePlanField(inputs[field], {
|
|
41
|
+
path: `${path}.inputs.${field}`,
|
|
42
|
+
type: "uint256 bigint",
|
|
43
|
+
});
|
|
44
|
+
// Migration actions require a role map even when no permit is needed.
|
|
45
|
+
getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
49
|
+
* Prepares a migration with fixed destination price and source share allowance quotes.
|
|
50
|
+
* @param client - Viem client for the intended chain, used for code, allowance and nonce reads.
|
|
51
|
+
* @param params.sourceVault - Caller-fetched AccrualVault source snapshot, including the source address and permit metadata.
|
|
52
|
+
* @param params.targetVault - Caller-fetched AccrualVaultV2 destination snapshot, including its address and quote data.
|
|
53
|
+
* @param params.chainId - Chain containing both vaults and the registered VaultBundlesV1 contract.
|
|
54
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the migration.
|
|
55
|
+
* @param params.assets - Positive gross migration in asset base units, before referral fees; mutually exclusive with `shares`.
|
|
56
|
+
* @param params.shares - Positive source share amount to migrate; mutually exclusive with `assets`.
|
|
57
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
58
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
59
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance for the destination price and source share allowance quotes; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
|
|
60
|
+
* @param params.supportSignature - Optional unlimited ERC-2612 share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient. Vault V1 shares support ERC-2612; no Permit2 is used.
|
|
61
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
62
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
63
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
64
|
+
* @returns A static migration plan with any required source share approval or permit.
|
|
65
|
+
* @throws {VaultAssetMismatchError} If the vault assets differ.
|
|
66
|
+
* @throws {SameVaultMigrationError} If source and target are identical.
|
|
67
|
+
* @throws {AmountAndSharesExclusiveError} If both or neither amount is supplied.
|
|
68
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
69
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
70
|
+
* @throws {NonPositiveInputError} when `expiresAt`, the selected amount, net migrated assets or previewed shares are not positive.
|
|
71
|
+
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
72
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
|
|
73
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
74
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
75
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
76
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
77
|
+
* @throws {ExpiredDeadlineError} If the expiry is not in the future.
|
|
78
|
+
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
79
|
+
* @throws {MissingContractCodeError} If VaultBundlesV1 is absent.
|
|
80
|
+
* @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
|
|
81
|
+
* @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
|
|
82
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
|
|
83
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
|
|
84
|
+
* @see computeVaultMaxSharePrice for quote errors.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { prepareVaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
88
|
+
* import { fetchAccrualVault, fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
89
|
+
* import { createPublicClient, http } from "viem";
|
|
90
|
+
* import { mainnet } from "viem/chains";
|
|
91
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
92
|
+
* const sourceVault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
93
|
+
* const targetVault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
94
|
+
* const plan = await prepareVaultV1MigrateToV2(client, {
|
|
95
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001",
|
|
96
|
+
* sourceVault: await fetchAccrualVault(sourceVault, client),
|
|
97
|
+
* targetVault: await fetchAccrualVaultV2(targetVault, client),
|
|
98
|
+
* assets: 1_000_000n, supportSignature: true,
|
|
99
|
+
* });
|
|
100
|
+
* // Sign pending requests, verify and attach with applySignatures, then buildTransactions.
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export async function prepareVaultV1MigrateToV2(client, params) {
|
|
104
|
+
const { sourceVault, targetVault, chainId, account } = params;
|
|
105
|
+
const now = params.now ?? Time.timestamp();
|
|
106
|
+
const intent = resolveIntent(params, now);
|
|
107
|
+
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
108
|
+
validateSlippageTolerance(slippageTolerance);
|
|
109
|
+
if (!isAddressEqual(sourceVault.asset, targetVault.asset)) {
|
|
110
|
+
throw new VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
|
|
111
|
+
}
|
|
112
|
+
if (isAddressEqual(sourceVault.address, targetVault.address)) {
|
|
113
|
+
throw new SameVaultMigrationError(sourceVault.address);
|
|
114
|
+
}
|
|
115
|
+
const { assets, shares } = params;
|
|
116
|
+
if ((assets == null) === (shares == null)) {
|
|
117
|
+
throw new AmountAndSharesExclusiveError();
|
|
118
|
+
}
|
|
119
|
+
const selectedAmount = assets ?? shares ?? 0n;
|
|
120
|
+
if (selectedAmount <= 0n) {
|
|
121
|
+
throw new NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
|
|
122
|
+
}
|
|
123
|
+
// Reject ABI overflow before any RPC request.
|
|
124
|
+
validateUint256Field(assets == null ? "shares" : "assets", selectedAmount);
|
|
125
|
+
const common = normalizeBundlesCommonParams(intent);
|
|
126
|
+
const { maxSharePriceVaultV2, requiredShareAllowance } = computeVaultV1MigrateToV2Quote({
|
|
127
|
+
sourceVault,
|
|
128
|
+
targetVault,
|
|
129
|
+
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
130
|
+
referralFeePct: common.referralFeePct,
|
|
131
|
+
deadline: intent.deadline,
|
|
132
|
+
slippageTolerance,
|
|
133
|
+
now,
|
|
134
|
+
});
|
|
135
|
+
const domain = sourceVault.eip5267Domain;
|
|
136
|
+
const { approvals, signatureRequests, tokenPermitRequestId } = await getVaultShareSpendingRequirements(client, {
|
|
137
|
+
type: "vaultV1MigrateToV2",
|
|
138
|
+
shareToken: new Token({
|
|
139
|
+
address: sourceVault.address,
|
|
140
|
+
name: sourceVault.name,
|
|
141
|
+
eip5267Domain: domain == null
|
|
142
|
+
? undefined
|
|
143
|
+
: new Eip5267Domain({
|
|
144
|
+
...domain,
|
|
145
|
+
extensions: [...domain.extensions],
|
|
146
|
+
}),
|
|
147
|
+
}),
|
|
148
|
+
account,
|
|
149
|
+
chainId,
|
|
150
|
+
requiredShareAllowance,
|
|
151
|
+
deadline: intent.deadline,
|
|
152
|
+
supportSignature: intent.supportSignature,
|
|
153
|
+
now,
|
|
154
|
+
});
|
|
155
|
+
return deepFreeze(structuredClone({
|
|
156
|
+
version: 2,
|
|
157
|
+
account,
|
|
158
|
+
chainId,
|
|
159
|
+
expiresAt: intent.expiresAt,
|
|
160
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
161
|
+
steps: [
|
|
162
|
+
...approvals,
|
|
163
|
+
{
|
|
164
|
+
id: "vaultV1MigrateToV2",
|
|
165
|
+
label: "Migrate to Vault V2",
|
|
166
|
+
action: {
|
|
167
|
+
type: "vaultV1MigrateToV2",
|
|
168
|
+
inputs: {
|
|
169
|
+
chainId,
|
|
170
|
+
account,
|
|
171
|
+
vault: sourceVault.address,
|
|
172
|
+
sourceVault: sourceVault.address,
|
|
173
|
+
targetVault: targetVault.address,
|
|
174
|
+
asset: sourceVault.asset,
|
|
175
|
+
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
176
|
+
maxSharePrice: maxSharePriceVaultV2,
|
|
177
|
+
requiredShareAllowance,
|
|
178
|
+
...common,
|
|
179
|
+
},
|
|
180
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
181
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
182
|
+
: {},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
signatureRequests,
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
/** @internal Maps stored maxSharePrice to the ABI maxSharePriceVaultV2 and encodes the source permit. */
|
|
190
|
+
export function buildVaultV1MigrateToV2(action, requests) {
|
|
191
|
+
const { vault: _vault, sourceVault, maxSharePrice, asset, requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
192
|
+
const signature = getVaultPermit(requests, {
|
|
193
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
194
|
+
asset: sourceVault,
|
|
195
|
+
owner: account,
|
|
196
|
+
});
|
|
197
|
+
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
198
|
+
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
199
|
+
amount: requiredShareAllowance,
|
|
200
|
+
deadline: args.deadline,
|
|
201
|
+
});
|
|
202
|
+
return vaultV1MigrateToV2({
|
|
203
|
+
vault: { chainId, address: sourceVault, asset },
|
|
204
|
+
args: {
|
|
205
|
+
...args,
|
|
206
|
+
targetAsset: asset,
|
|
207
|
+
maxSharePriceVaultV2: maxSharePrice,
|
|
208
|
+
userAddress: account,
|
|
209
|
+
requirementSignature: permit,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Client } from "viem";
|
|
2
|
+
import type { Transaction, VaultV1RedeemAction } from "../../types/index.js";
|
|
3
|
+
import { type RedeemPlanParams } from "../redeem.js";
|
|
4
|
+
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
7
|
+
* Caller intent for an exact-share Vault V1 redemption through VaultBundlesV1.
|
|
8
|
+
* Redemption sets no on-chain minimum assets received.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { VaultV1RedeemPlanParams } from "@morpho-org/morpho-sdk";
|
|
12
|
+
* import type { Token } from "@morpho-org/blue-sdk";
|
|
13
|
+
* import type { Address } from "viem";
|
|
14
|
+
* const intent = (shareToken: Token, account: Address): VaultV1RedeemPlanParams => ({
|
|
15
|
+
* shareToken, chainId: 1, account, shares: 1_000_000n,
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface VaultV1RedeemPlanParams extends RedeemPlanParams {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
23
|
+
* Prepares an exact-share Vault V1 redemption with a direct unlimited share approval or ERC-2612
|
|
24
|
+
* permit when needed. Reads the share allowance and, for permits, the account's nonce. The returned
|
|
25
|
+
* plan contains only fixed inputs and signature requests; it never uses Permit2 or fetch requests.
|
|
26
|
+
* Redemption sets no on-chain minimum assets received and accepts no slippage tolerance input.
|
|
27
|
+
* @param client - Viem client connected to the target chain.
|
|
28
|
+
* @param params - Vault share metadata and caller intent; inherited fields follow IntentParams.
|
|
29
|
+
* @param params.shareToken - Required share Token carrying the vault address and V1 permit-domain metadata; no accrual snapshot is required.
|
|
30
|
+
* @param params.shares - Positive exact share amount, not underlying assets.
|
|
31
|
+
* @param params.supportSignature - Defaults to false for direct approval; true selects an unlimited ERC-2612 share permit when allowance is insufficient.
|
|
32
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
33
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
34
|
+
* @returns A static plan containing any share approval followed by the redemption step.
|
|
35
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
36
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
37
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
|
|
38
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
39
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
40
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
41
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
42
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
43
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
44
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
45
|
+
* @throws {MissingContractCodeError} when VaultBundlesV1 is absent.
|
|
46
|
+
* @throws {viem.BaseError} when an allowance, nonce, chain or contract-code read fails.
|
|
47
|
+
* @see resolveIntent for shared expiry, fee and calldata origin validation.
|
|
48
|
+
* @see getVaultBundlesSharesRequirements for share-permit domain errors.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { prepareVaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
52
|
+
* import { fetchToken } from "@morpho-org/morpho-sdk/fetch";
|
|
53
|
+
* import { createPublicClient, http } from "viem";
|
|
54
|
+
* import { mainnet } from "viem/chains";
|
|
55
|
+
* import type { Address } from "viem";
|
|
56
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
57
|
+
* const prepare = async (vault: Address, account: Address, shares: bigint) =>
|
|
58
|
+
* prepareVaultV1Redeem(client, {
|
|
59
|
+
* account, chainId: mainnet.id, shares, supportSignature: true,
|
|
60
|
+
* shareToken: await fetchToken(vault, client),
|
|
61
|
+
* });
|
|
62
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function prepareVaultV1Redeem(client: Client, params: VaultV1RedeemPlanParams): Promise<TransactionPlan>;
|
|
66
|
+
/** @internal Encodes a redemption from fixed inputs and the referenced share permit. */
|
|
67
|
+
export declare function buildVaultV1Redeem(action: Extract<Action, {
|
|
68
|
+
type: "vaultV1Redeem";
|
|
69
|
+
}>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1RedeemAction>>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
|
+
import { vaultV1Redeem } from "../../actions/vaultV1/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 Vault V1 redemption with a direct unlimited share approval or ERC-2612
|
|
9
|
+
* permit when needed. Reads the share allowance and, for permits, the account's nonce. The returned
|
|
10
|
+
* plan contains only fixed inputs and signature requests; it never uses Permit2 or fetch requests.
|
|
11
|
+
* Redemption sets no on-chain minimum assets received and accepts no slippage tolerance input.
|
|
12
|
+
* @param client - Viem client connected to the target chain.
|
|
13
|
+
* @param params - Vault share metadata and caller intent; inherited fields follow IntentParams.
|
|
14
|
+
* @param params.shareToken - Required share Token carrying the vault address and V1 permit-domain metadata; no accrual snapshot is required.
|
|
15
|
+
* @param params.shares - Positive exact share amount, not underlying assets.
|
|
16
|
+
* @param params.supportSignature - Defaults to false for direct approval; true selects an unlimited ERC-2612 share permit when allowance is insufficient.
|
|
17
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
18
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
19
|
+
* @returns A static plan containing any share approval followed by the redemption step.
|
|
20
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
21
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
22
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
|
|
23
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
24
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
25
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
26
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
27
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
28
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
29
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
30
|
+
* @throws {MissingContractCodeError} when VaultBundlesV1 is absent.
|
|
31
|
+
* @throws {viem.BaseError} when an allowance, nonce, chain or contract-code read fails.
|
|
32
|
+
* @see resolveIntent for shared expiry, fee and calldata origin validation.
|
|
33
|
+
* @see getVaultBundlesSharesRequirements for share-permit domain errors.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { prepareVaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
37
|
+
* import { fetchToken } from "@morpho-org/morpho-sdk/fetch";
|
|
38
|
+
* import { createPublicClient, http } from "viem";
|
|
39
|
+
* import { mainnet } from "viem/chains";
|
|
40
|
+
* import type { Address } from "viem";
|
|
41
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
42
|
+
* const prepare = async (vault: Address, account: Address, shares: bigint) =>
|
|
43
|
+
* prepareVaultV1Redeem(client, {
|
|
44
|
+
* account, chainId: mainnet.id, shares, supportSignature: true,
|
|
45
|
+
* shareToken: await fetchToken(vault, client),
|
|
46
|
+
* });
|
|
47
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export async function prepareVaultV1Redeem(client, params) {
|
|
51
|
+
return prepareVaultRedeem(client, { ...params, type: "vaultV1Redeem" });
|
|
52
|
+
}
|
|
53
|
+
/** @internal Encodes a redemption from fixed inputs and the referenced share permit. */
|
|
54
|
+
export function buildVaultV1Redeem(action, requests) {
|
|
55
|
+
const { chainId, account, ...args } = action.inputs;
|
|
56
|
+
const signature = getVaultPermit(requests, {
|
|
57
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
58
|
+
asset: action.inputs.vault,
|
|
59
|
+
owner: account,
|
|
60
|
+
});
|
|
61
|
+
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
62
|
+
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
63
|
+
amount: action.inputs.shares,
|
|
64
|
+
deadline: action.inputs.deadline,
|
|
65
|
+
});
|
|
66
|
+
return vaultV1Redeem({
|
|
67
|
+
vault: { chainId, address: action.inputs.vault },
|
|
68
|
+
args: {
|
|
69
|
+
...args,
|
|
70
|
+
userAddress: account,
|
|
71
|
+
requirementSignature: permit,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { AccrualVault } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import type { Transaction, VaultV1WithdrawAction } from "../../types/index.js";
|
|
4
|
+
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
5
|
+
import { type WithdrawPlanParams } from "../withdraw.js";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Caller intent for a Vault V1 asset withdrawal plus its accrual snapshot.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { VaultV1WithdrawPlanParams } from "@morpho-org/morpho-sdk";
|
|
12
|
+
* const params: VaultV1WithdrawPlanParams = {
|
|
13
|
+
* vault, chainId: 1, account, assets: 1_000_000n,
|
|
14
|
+
* supportSignature: true,
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface VaultV1WithdrawPlanParams extends WithdrawPlanParams<AccrualVault> {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
22
|
+
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
23
|
+
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
24
|
+
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
25
|
+
* When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
|
|
26
|
+
* `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
|
|
27
|
+
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
28
|
+
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
29
|
+
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
30
|
+
* @param params.vault - Caller-fetched AccrualVault snapshot used for the share quote; its address identifies the vault.
|
|
31
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
32
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
33
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
34
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
35
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
36
|
+
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
37
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
38
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
39
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
40
|
+
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
41
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
42
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
43
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
44
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
45
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
46
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
47
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
48
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
49
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
50
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
51
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
52
|
+
* @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
|
|
53
|
+
* @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
|
|
54
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
|
|
55
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
|
|
56
|
+
* @see computeVaultMaxShareAllowance for quote errors.
|
|
57
|
+
* @see getVaultBundlesSharesRequirements for allowance and nonce reads.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { prepareVaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
61
|
+
* import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
|
|
62
|
+
* import { createPublicClient, http } from "viem";
|
|
63
|
+
* import { mainnet } from "viem/chains";
|
|
64
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
65
|
+
* const vault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
66
|
+
* const plan = await prepareVaultV1Withdraw(client, {
|
|
67
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
68
|
+
* vault: await fetchAccrualVault(vault, client),
|
|
69
|
+
* });
|
|
70
|
+
* // Sign the pending requests, applySignatures to verify and attach them, then build.
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function prepareVaultV1Withdraw(client: Client, params: VaultV1WithdrawPlanParams): Promise<TransactionPlan>;
|
|
74
|
+
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
75
|
+
export declare function buildVaultV1Withdraw(action: Extract<Action, {
|
|
76
|
+
type: "vaultV1Withdraw";
|
|
77
|
+
}>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1WithdrawAction>>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
|
+
import { vaultV1Withdraw } from "../../actions/vaultV1/withdraw.js";
|
|
4
|
+
import { getVaultPermit } from "../permit.js";
|
|
5
|
+
import { prepareVaultWithdraw } from "../withdraw.js";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
9
|
+
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
10
|
+
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
11
|
+
* When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
|
|
12
|
+
* `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
|
|
13
|
+
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
14
|
+
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
15
|
+
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
16
|
+
* @param params.vault - Caller-fetched AccrualVault snapshot used for the share quote; its address identifies the vault.
|
|
17
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
18
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
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 amount; defaults to zero and must be below 10,000.
|
|
21
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
22
|
+
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
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`.
|
|
25
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
26
|
+
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
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`, `assets` or the computed required shares are 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 `assets` 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 recipient or a zero recipient.
|
|
36
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
37
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
38
|
+
* @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
|
|
39
|
+
* @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
|
|
40
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
|
|
41
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
|
|
42
|
+
* @see computeVaultMaxShareAllowance for quote errors.
|
|
43
|
+
* @see getVaultBundlesSharesRequirements for allowance and nonce reads.
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { prepareVaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
47
|
+
* import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
|
|
48
|
+
* import { createPublicClient, http } from "viem";
|
|
49
|
+
* import { mainnet } from "viem/chains";
|
|
50
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
51
|
+
* const vault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
52
|
+
* const plan = await prepareVaultV1Withdraw(client, {
|
|
53
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
54
|
+
* vault: await fetchAccrualVault(vault, client),
|
|
55
|
+
* });
|
|
56
|
+
* // Sign the pending requests, applySignatures to verify and attach them, then build.
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export async function prepareVaultV1Withdraw(client, params) {
|
|
60
|
+
return prepareVaultWithdraw(client, { ...params, type: "vaultV1Withdraw" });
|
|
61
|
+
}
|
|
62
|
+
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
63
|
+
export function buildVaultV1Withdraw(action, requests) {
|
|
64
|
+
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
65
|
+
const signature = getVaultPermit(requests, {
|
|
66
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
67
|
+
asset: action.inputs.vault,
|
|
68
|
+
owner: account,
|
|
69
|
+
});
|
|
70
|
+
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
71
|
+
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
72
|
+
amount: requiredShareAllowance,
|
|
73
|
+
deadline: action.inputs.deadline,
|
|
74
|
+
});
|
|
75
|
+
return vaultV1Withdraw({
|
|
76
|
+
vault: { chainId, address: action.inputs.vault },
|
|
77
|
+
args: {
|
|
78
|
+
...args,
|
|
79
|
+
amount: assets,
|
|
80
|
+
userAddress: account,
|
|
81
|
+
requirementSignature: permit,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -1,41 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { type
|
|
1
|
+
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import type { Transaction, VaultV2DepositAction } from "../../types/index.js";
|
|
4
|
+
import { type DepositPlanParams } from "../deposit.js";
|
|
5
5
|
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
|
-
/** @internal Validates the stored Vault V2 deposit action's input shape. */
|
|
7
|
-
export declare function validateDepositPlanAction(action: Record<string, unknown>, path: string): void;
|
|
8
6
|
/**
|
|
9
|
-
* Caller intent for a Vault V2 deposit, mirroring the Actions API deposit 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 deposit, mirroring the Actions API deposit inputs, plus the snapshot.
|
|
11
9
|
*/
|
|
12
|
-
export interface VaultV2DepositPlanParams extends
|
|
13
|
-
/** WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE`. */
|
|
14
|
-
readonly slippageTolerance?: bigint;
|
|
15
|
-
readonly vault: Address;
|
|
16
|
-
/** Gross amount the account pays, before the referral fee. */
|
|
17
|
-
readonly amount: bigint;
|
|
18
|
-
/** Defaults to `{ type: "erc20" }`. */
|
|
19
|
-
readonly funding?: Funding;
|
|
20
|
-
/**
|
|
21
|
-
* Accrual snapshot of `vault`, fetched by the caller with `fetchAccrualVaultV2`. The asset and
|
|
22
|
-
* the deadline-accrued `maxSharePrice` are derived from it at preparation; the snapshot itself is
|
|
23
|
-
* never stored in the plan.
|
|
24
|
-
*/
|
|
25
|
-
readonly vaultData: AccrualVaultV2;
|
|
10
|
+
export interface VaultV2DepositPlanParams extends DepositPlanParams<AccrualVaultV2> {
|
|
26
11
|
}
|
|
27
12
|
/**
|
|
13
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
28
14
|
* Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
|
|
29
15
|
* directly. The quote is fixed on the deposit step at preparation, so the returned plan is static:
|
|
30
16
|
* only signatures are added before building.
|
|
31
17
|
* @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
|
|
32
|
-
* @param params.vault -
|
|
33
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the asset and deadline-accrued share-price bound.
|
|
18
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
34
19
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
35
20
|
* @param params.account - Non-zero account funding, signing and sending the deposit.
|
|
36
|
-
* @param params.
|
|
21
|
+
* @param params.assets - Positive gross deposit in asset base units, before referral fees.
|
|
37
22
|
* @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
|
|
38
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
23
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
39
24
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
40
25
|
* @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
|
|
41
26
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
@@ -46,15 +31,14 @@ export interface VaultV2DepositPlanParams extends IntentParams, ReferenceTimesta
|
|
|
46
31
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
47
32
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
48
33
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
49
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
34
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets`, net assets or previewed shares are not positive.
|
|
50
35
|
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
51
36
|
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
52
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
37
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
53
38
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
54
39
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
55
40
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
56
41
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
57
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
58
42
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
59
43
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
60
44
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
@@ -68,13 +52,12 @@ export interface VaultV2DepositPlanParams extends IntentParams, ReferenceTimesta
|
|
|
68
52
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
69
53
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
70
54
|
* const plan = await prepareVaultV2Deposit(client, {
|
|
71
|
-
*
|
|
72
|
-
*
|
|
55
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
56
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
73
57
|
* now: (await client.getBlock()).timestamp,
|
|
74
58
|
* });
|
|
75
59
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
76
60
|
* ```
|
|
77
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
78
61
|
*/
|
|
79
62
|
export declare function prepareVaultV2Deposit(client: Client, params: VaultV2DepositPlanParams): Promise<TransactionPlan>;
|
|
80
63
|
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|