@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,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareVaultV1InKindRedeem = prepareVaultV1InKindRedeem;
|
|
4
|
+
exports.buildVaultV1InKindRedeem = buildVaultV1InKindRedeem;
|
|
5
|
+
exports.validateInKindRedeemPlanAction = validateInKindRedeemPlanAction;
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
9
|
+
const inKindRedeem_js_1 = require("../../actions/vaultV1/inKindRedeem.js");
|
|
10
|
+
const getVaultV1InKindRedeemRequirements_js_1 = require("../../entities/requirements/getVaultV1InKindRedeemRequirements.js");
|
|
11
|
+
const inKindRedeemQuote_js_1 = require("../../entities/vaultV1/inKindRedeemQuote.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
13
|
+
const index_js_1 = require("../../types/index.js");
|
|
14
|
+
const intent_js_1 = require("../intent.js");
|
|
15
|
+
const permit_js_1 = require("../permit.js");
|
|
16
|
+
const requirements_js_1 = require("../requirements.js");
|
|
17
|
+
const validation_js_1 = require("../validation.js");
|
|
18
|
+
/**
|
|
19
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
20
|
+
* Prepares the stable Vault V1 in-kind exit through VaultExitBundlesV1.
|
|
21
|
+
* All market inputs are copied during preparation; building requires no client or further reads.
|
|
22
|
+
* Insufficient share allowance produces an unlimited direct approval or ERC-2612 permit, never Permit2.
|
|
23
|
+
* The asset-denominated exit has no on-chain share-price or max-shares bound; a price drop before
|
|
24
|
+
* inclusion can burn more shares than quoted.
|
|
25
|
+
* @param params.vault - Caller-fetched AccrualVault snapshot; its address identifies the vault.
|
|
26
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
27
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
28
|
+
* @param client - Viem client used for chain, code and requirement reads.
|
|
29
|
+
* @param params - Account, asset amount, ordered markets and caller-fetched vault snapshot.
|
|
30
|
+
* @returns A data-only plan with the exit and any share approval or signature request.
|
|
31
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
32
|
+
* @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
|
|
33
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
34
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
35
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
36
|
+
* @throws {ChainIdMismatchError} when the client declares or its RPC serves another chain.
|
|
37
|
+
* @throws {EmptyMarketParamsListError} when no markets are supplied.
|
|
38
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
|
|
39
|
+
* @throws {UnknownAddressError} when VaultExitBundlesV1 or Morpho Blue is not registered on the chain.
|
|
40
|
+
* @throws {InKindRedeemCoverageError} when the ordered markets cannot cover `assets` without overusing an allocation.
|
|
41
|
+
* @throws {MissingContractCodeError} when VaultExitBundlesV1 or Morpho Blue has no deployed code.
|
|
42
|
+
* @throws {viem.BaseError} when a chain, code, allowance, nonce, balance or contract configuration read fails, or inputs cannot be ABI-encoded.
|
|
43
|
+
* @throws {VaultMorphoMismatchError} when the vault's `MORPHO` differs from the registered Morpho Blue contract.
|
|
44
|
+
* @throws {VaultIsBlueFeeRecipientError} when the vault is Morpho Blue's fee recipient, an unsupported configuration.
|
|
45
|
+
* @throws {InsufficientBlueBalanceForInKindRedeemError} when Morpho Blue's asset balance is below `assets`.
|
|
46
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when a required share permit advertises unsupported EIP-5267 extensions.
|
|
47
|
+
* @throws {InvalidPermitDomainChainIdError} when a required share permit domain targets another chain or omits `chainId`.
|
|
48
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when a required share permit domain targets another token or omits `verifyingContract`.
|
|
49
|
+
* @throws {MissingPermitDomainNameError} when a required share permit has neither an EIP-5267 domain nor a token name.
|
|
50
|
+
* @see computeVaultMaxShareAllowance for snapshot accrual and share-quote errors.
|
|
51
|
+
* @see MorphoVaultV1.inKindRedeem for snapshot and onchain preflight validation.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { prepareVaultV1InKindRedeem } from "@morpho-org/morpho-sdk";
|
|
55
|
+
* import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
|
|
56
|
+
* import { createPublicClient, http } from "viem";
|
|
57
|
+
* import { mainnet } from "viem/chains";
|
|
58
|
+
*
|
|
59
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
60
|
+
* const vaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"; // Mainnet steakUSDC Vault V1.
|
|
61
|
+
* const vault = await fetchAccrualVault(vaultAddress, client);
|
|
62
|
+
* const marketParamsList = [...vault.allocations.values()]
|
|
63
|
+
* .filter(({ config, position }) => config.enabled && position.supplyShares > 0n)
|
|
64
|
+
* .map(({ position }) => position.market.params);
|
|
65
|
+
* const plan = await prepareVaultV1InKindRedeem(client, {
|
|
66
|
+
* chainId: mainnet.id, account: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
67
|
+
* vault, assets: 1_000_000n, marketParamsList,
|
|
68
|
+
* });
|
|
69
|
+
* // plan satisfies TransactionPlan: { version, chainId, account, expiresAt, steps, signatureRequests }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
async function prepareVaultV1InKindRedeem(client, params) {
|
|
73
|
+
const { chainId, account, vault } = params;
|
|
74
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
75
|
+
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
76
|
+
(0, validate_js_1.validateChainId)(client.chain?.id, chainId);
|
|
77
|
+
const quote = (0, inKindRedeemQuote_js_1.computeVaultV1InKindRedeemQuote)({
|
|
78
|
+
vaultData: vault,
|
|
79
|
+
chainId,
|
|
80
|
+
deadline: intent.deadline,
|
|
81
|
+
now,
|
|
82
|
+
amount: params.assets,
|
|
83
|
+
marketParamsList: params.marketParamsList,
|
|
84
|
+
});
|
|
85
|
+
const inputs = (0, inKindRedeem_js_1.vaultV1InKindRedeem)({
|
|
86
|
+
vault: { chainId, address: vault.address },
|
|
87
|
+
args: {
|
|
88
|
+
amount: params.assets,
|
|
89
|
+
marketParamsList: quote.marketParamsListSnapshot,
|
|
90
|
+
userAddress: account,
|
|
91
|
+
deadline: quote.deadline,
|
|
92
|
+
},
|
|
93
|
+
}).action.args;
|
|
94
|
+
const requirements = await (0, getVaultV1InKindRedeemRequirements_js_1.getVaultV1InKindRedeemRequirements)(client, {
|
|
95
|
+
vaultData: vault,
|
|
96
|
+
vault: vault.address,
|
|
97
|
+
userAddress: account,
|
|
98
|
+
chainId,
|
|
99
|
+
deadline: quote.deadline,
|
|
100
|
+
requiredShareAllowance: quote.requiredShareAllowance,
|
|
101
|
+
supportSignature: intent.supportSignature,
|
|
102
|
+
now,
|
|
103
|
+
amount: params.assets,
|
|
104
|
+
});
|
|
105
|
+
const approvals = [];
|
|
106
|
+
const signatureRequests = [];
|
|
107
|
+
const id = "vaultV1InKindRedeem:tokenPermit";
|
|
108
|
+
for (const requirement of requirements) {
|
|
109
|
+
if ((0, index_js_1.isRequirementApproval)(requirement)) {
|
|
110
|
+
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
111
|
+
id: "vaultV1InKindRedeem:approval",
|
|
112
|
+
chainId,
|
|
113
|
+
account,
|
|
114
|
+
denomination: "shares",
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
else if (requirement.action.type === "permit") {
|
|
118
|
+
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)({ action: requirement.action }, id));
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
throw new index_js_1.UnsupportedRequirementSignatureError(requirement.action.type);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
125
|
+
version: 2,
|
|
126
|
+
chainId,
|
|
127
|
+
account,
|
|
128
|
+
expiresAt: intent.expiresAt,
|
|
129
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
130
|
+
steps: [
|
|
131
|
+
...approvals,
|
|
132
|
+
{
|
|
133
|
+
id: "vaultV1InKindRedeem",
|
|
134
|
+
label: "Redeem vault shares in kind",
|
|
135
|
+
action: {
|
|
136
|
+
type: "vaultV1InKindRedeem",
|
|
137
|
+
inputs: {
|
|
138
|
+
chainId,
|
|
139
|
+
account,
|
|
140
|
+
vault: vault.address,
|
|
141
|
+
assets: inputs.amount,
|
|
142
|
+
deadline: inputs.deadline,
|
|
143
|
+
marketParamsList: inputs.marketParamsList,
|
|
144
|
+
},
|
|
145
|
+
signatureRequestIds: signatureRequests.length
|
|
146
|
+
? { tokenPermit: id }
|
|
147
|
+
: {},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
signatureRequests,
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
/** @internal Encodes the fixed in-kind exit with its referenced permit. */
|
|
155
|
+
function buildVaultV1InKindRedeem(action, requests) {
|
|
156
|
+
const { chainId, account, vault, assets, ...args } = action.inputs;
|
|
157
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
158
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
159
|
+
asset: vault,
|
|
160
|
+
owner: account,
|
|
161
|
+
});
|
|
162
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
|
|
163
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultExitBundlesV1"),
|
|
164
|
+
amount: viem_1.maxUint256,
|
|
165
|
+
deadline: action.inputs.deadline,
|
|
166
|
+
});
|
|
167
|
+
return (0, inKindRedeem_js_1.vaultV1InKindRedeem)({
|
|
168
|
+
vault: { chainId, address: vault },
|
|
169
|
+
args: {
|
|
170
|
+
...args,
|
|
171
|
+
amount: assets,
|
|
172
|
+
userAddress: account,
|
|
173
|
+
requirementSignature: permit,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/** @internal Validates the stored in-kind action and ordered market structs. */
|
|
178
|
+
function validateInKindRedeemPlanAction(action, path) {
|
|
179
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
180
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
181
|
+
path: `${path}.inputs`,
|
|
182
|
+
fields: {
|
|
183
|
+
vault: "address",
|
|
184
|
+
assets: "uint256 bigint",
|
|
185
|
+
deadline: "uint256 bigint",
|
|
186
|
+
marketParamsList: "array",
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
(0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
190
|
+
for (const [index, value] of inputs.marketParamsList.entries()) {
|
|
191
|
+
const marketPath = `${path}.inputs.marketParamsList[${index}]`;
|
|
192
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(value, marketPath), {
|
|
193
|
+
path: marketPath,
|
|
194
|
+
fields: {
|
|
195
|
+
loanToken: "address",
|
|
196
|
+
collateralToken: "address",
|
|
197
|
+
oracle: "address",
|
|
198
|
+
irm: "address",
|
|
199
|
+
lltv: "uint256 bigint",
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Client } from "viem";
|
|
3
|
+
import { type ReferenceTimestampParams, type Transaction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
|
|
4
|
+
import { type IntentParams } from "../intent.js";
|
|
5
|
+
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
|
+
/** @internal Validates the stored Vault V1 migration action's input shape. */
|
|
7
|
+
export declare function validateMigrateToV2PlanAction(action: Record<string, unknown>, path: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
10
|
+
* Caller intent for a Vault V1-to-V2 migration with caller-fetched accrual snapshots.
|
|
11
|
+
* Snapshots are used only at preparation and are never stored in the plan.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import type { VaultV1MigrateToV2PlanParams } from "@morpho-org/morpho-sdk";
|
|
15
|
+
* import { fetchAccrualVault, fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
16
|
+
* import { createPublicClient, http } from "viem";
|
|
17
|
+
* import { mainnet } from "viem/chains";
|
|
18
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
19
|
+
* const sourceVault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
20
|
+
* const targetVault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
21
|
+
* const params: VaultV1MigrateToV2PlanParams = {
|
|
22
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001",
|
|
23
|
+
* sourceVault: await fetchAccrualVault(sourceVault, client),
|
|
24
|
+
* targetVault: await fetchAccrualVaultV2(targetVault, client),
|
|
25
|
+
* shares: 1_000_000n, supportSignature: true,
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type VaultV1MigrateToV2PlanParams = Omit<IntentParams, "deployless"> & ReferenceTimestampParams & VaultV1MigrateToV2AmountArgs & {
|
|
30
|
+
readonly sourceVault: AccrualVault;
|
|
31
|
+
readonly targetVault: AccrualVaultV2;
|
|
32
|
+
readonly slippageTolerance?: bigint;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
36
|
+
* Prepares a migration with fixed destination price and source share allowance quotes.
|
|
37
|
+
* @param client - Viem client for the intended chain, used for code, allowance and nonce reads.
|
|
38
|
+
* @param params.sourceVault - Caller-fetched AccrualVault source snapshot, including the source address and permit metadata.
|
|
39
|
+
* @param params.targetVault - Caller-fetched AccrualVaultV2 destination snapshot, including its address and quote data.
|
|
40
|
+
* @param params.chainId - Chain containing both vaults and the registered VaultBundlesV1 contract.
|
|
41
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the migration.
|
|
42
|
+
* @param params.assets - Positive gross migration in asset base units, before referral fees; mutually exclusive with `shares`.
|
|
43
|
+
* @param params.shares - Positive source share amount to migrate; mutually exclusive with `assets`.
|
|
44
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
45
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
46
|
+
* @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`.
|
|
47
|
+
* @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.
|
|
48
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
49
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
50
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
51
|
+
* @returns A static migration plan with any required source share approval or permit.
|
|
52
|
+
* @throws {VaultAssetMismatchError} If the vault assets differ.
|
|
53
|
+
* @throws {SameVaultMigrationError} If source and target are identical.
|
|
54
|
+
* @throws {AmountAndSharesExclusiveError} If both or neither amount is supplied.
|
|
55
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
56
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
57
|
+
* @throws {NonPositiveInputError} when `expiresAt`, the selected amount, net migrated assets or previewed shares are not positive.
|
|
58
|
+
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
59
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
|
|
60
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
61
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
62
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
63
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
64
|
+
* @throws {ExpiredDeadlineError} If the expiry is not in the future.
|
|
65
|
+
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
66
|
+
* @throws {MissingContractCodeError} If VaultBundlesV1 is absent.
|
|
67
|
+
* @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
|
|
68
|
+
* @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
|
|
69
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
|
|
70
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
|
|
71
|
+
* @see computeVaultMaxSharePrice for quote errors.
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { prepareVaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
75
|
+
* import { fetchAccrualVault, fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
76
|
+
* import { createPublicClient, http } from "viem";
|
|
77
|
+
* import { mainnet } from "viem/chains";
|
|
78
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
79
|
+
* const sourceVault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
80
|
+
* const targetVault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
81
|
+
* const plan = await prepareVaultV1MigrateToV2(client, {
|
|
82
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001",
|
|
83
|
+
* sourceVault: await fetchAccrualVault(sourceVault, client),
|
|
84
|
+
* targetVault: await fetchAccrualVaultV2(targetVault, client),
|
|
85
|
+
* assets: 1_000_000n, supportSignature: true,
|
|
86
|
+
* });
|
|
87
|
+
* // Sign pending requests, verify and attach with applySignatures, then buildTransactions.
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function prepareVaultV1MigrateToV2(client: Client, params: VaultV1MigrateToV2PlanParams): Promise<TransactionPlan>;
|
|
91
|
+
/** @internal Maps stored maxSharePrice to the ABI maxSharePriceVaultV2 and encodes the source permit. */
|
|
92
|
+
export declare function buildVaultV1MigrateToV2(action: Extract<Action, {
|
|
93
|
+
type: "vaultV1MigrateToV2";
|
|
94
|
+
}>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV1MigrateToV2Action>>;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMigrateToV2PlanAction = validateMigrateToV2PlanAction;
|
|
4
|
+
exports.prepareVaultV1MigrateToV2 = prepareVaultV1MigrateToV2;
|
|
5
|
+
exports.buildVaultV1MigrateToV2 = buildVaultV1MigrateToV2;
|
|
6
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
+
const viem_1 = require("viem");
|
|
9
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
|
+
const migrateToV2_js_1 = require("../../actions/vaultV1/migrateToV2.js");
|
|
11
|
+
const migrateToV2Quote_js_1 = require("../../entities/vaultV1/migrateToV2Quote.js");
|
|
12
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
13
|
+
const index_js_1 = require("../../types/index.js");
|
|
14
|
+
const error_js_1 = require("../error.js");
|
|
15
|
+
const intent_js_1 = require("../intent.js");
|
|
16
|
+
const permit_js_1 = require("../permit.js");
|
|
17
|
+
const shareSpending_js_1 = require("../shareSpending.js");
|
|
18
|
+
const validation_js_1 = require("../validation.js");
|
|
19
|
+
/** @internal Validates the stored Vault V1 migration action's input shape. */
|
|
20
|
+
function validateMigrateToV2PlanAction(action, path) {
|
|
21
|
+
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
22
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
23
|
+
path: `${path}.inputs`,
|
|
24
|
+
fields: {
|
|
25
|
+
sourceVault: "address",
|
|
26
|
+
targetVault: "address",
|
|
27
|
+
asset: "address",
|
|
28
|
+
maxSharePrice: "uint256 bigint",
|
|
29
|
+
requiredShareAllowance: "uint256 bigint",
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (!(0, viem_1.isAddressEqual)(inputs.vault, inputs.sourceVault)) {
|
|
33
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
34
|
+
path: `${path}.inputs.vault`,
|
|
35
|
+
reason: "expected sourceVault",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if ((inputs.assets === undefined) === (inputs.shares === undefined)) {
|
|
39
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
40
|
+
path: `${path}.inputs`,
|
|
41
|
+
reason: "expected exactly one of assets or shares",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const field = inputs.assets === undefined ? "shares" : "assets";
|
|
45
|
+
(0, validation_js_1.validatePlanField)(inputs[field], {
|
|
46
|
+
path: `${path}.inputs.${field}`,
|
|
47
|
+
type: "uint256 bigint",
|
|
48
|
+
});
|
|
49
|
+
// Migration actions require a role map even when no permit is needed.
|
|
50
|
+
(0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
54
|
+
* Prepares a migration with fixed destination price and source share allowance quotes.
|
|
55
|
+
* @param client - Viem client for the intended chain, used for code, allowance and nonce reads.
|
|
56
|
+
* @param params.sourceVault - Caller-fetched AccrualVault source snapshot, including the source address and permit metadata.
|
|
57
|
+
* @param params.targetVault - Caller-fetched AccrualVaultV2 destination snapshot, including its address and quote data.
|
|
58
|
+
* @param params.chainId - Chain containing both vaults and the registered VaultBundlesV1 contract.
|
|
59
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the migration.
|
|
60
|
+
* @param params.assets - Positive gross migration in asset base units, before referral fees; mutually exclusive with `shares`.
|
|
61
|
+
* @param params.shares - Positive source share amount to migrate; mutually exclusive with `assets`.
|
|
62
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
63
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
64
|
+
* @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`.
|
|
65
|
+
* @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.
|
|
66
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
67
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
68
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
69
|
+
* @returns A static migration plan with any required source share approval or permit.
|
|
70
|
+
* @throws {VaultAssetMismatchError} If the vault assets differ.
|
|
71
|
+
* @throws {SameVaultMigrationError} If source and target are identical.
|
|
72
|
+
* @throws {AmountAndSharesExclusiveError} If both or neither amount is supplied.
|
|
73
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
74
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
75
|
+
* @throws {NonPositiveInputError} when `expiresAt`, the selected amount, net migrated assets or previewed shares are not positive.
|
|
76
|
+
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
77
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or the selected amount exceeds uint256.
|
|
78
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
79
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
80
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
81
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
82
|
+
* @throws {ExpiredDeadlineError} If the expiry is not in the future.
|
|
83
|
+
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
84
|
+
* @throws {MissingContractCodeError} If VaultBundlesV1 is absent.
|
|
85
|
+
* @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
|
|
86
|
+
* @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
|
|
87
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
|
|
88
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
|
|
89
|
+
* @see computeVaultMaxSharePrice for quote errors.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { prepareVaultV1MigrateToV2 } from "@morpho-org/morpho-sdk";
|
|
93
|
+
* import { fetchAccrualVault, fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
94
|
+
* import { createPublicClient, http } from "viem";
|
|
95
|
+
* import { mainnet } from "viem/chains";
|
|
96
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
97
|
+
* const sourceVault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
98
|
+
* const targetVault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
99
|
+
* const plan = await prepareVaultV1MigrateToV2(client, {
|
|
100
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001",
|
|
101
|
+
* sourceVault: await fetchAccrualVault(sourceVault, client),
|
|
102
|
+
* targetVault: await fetchAccrualVaultV2(targetVault, client),
|
|
103
|
+
* assets: 1_000_000n, supportSignature: true,
|
|
104
|
+
* });
|
|
105
|
+
* // Sign pending requests, verify and attach with applySignatures, then buildTransactions.
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
async function prepareVaultV1MigrateToV2(client, params) {
|
|
109
|
+
const { sourceVault, targetVault, chainId, account } = params;
|
|
110
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
111
|
+
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
112
|
+
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
113
|
+
(0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
|
|
114
|
+
if (!(0, viem_1.isAddressEqual)(sourceVault.asset, targetVault.asset)) {
|
|
115
|
+
throw new index_js_1.VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
|
|
116
|
+
}
|
|
117
|
+
if ((0, viem_1.isAddressEqual)(sourceVault.address, targetVault.address)) {
|
|
118
|
+
throw new index_js_1.SameVaultMigrationError(sourceVault.address);
|
|
119
|
+
}
|
|
120
|
+
const { assets, shares } = params;
|
|
121
|
+
if ((assets == null) === (shares == null)) {
|
|
122
|
+
throw new index_js_1.AmountAndSharesExclusiveError();
|
|
123
|
+
}
|
|
124
|
+
const selectedAmount = assets ?? shares ?? 0n;
|
|
125
|
+
if (selectedAmount <= 0n) {
|
|
126
|
+
throw new index_js_1.NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
|
|
127
|
+
}
|
|
128
|
+
// Reject ABI overflow before any RPC request.
|
|
129
|
+
(0, validate_js_1.validateUint256Field)(assets == null ? "shares" : "assets", selectedAmount);
|
|
130
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)(intent);
|
|
131
|
+
const { maxSharePriceVaultV2, requiredShareAllowance } = (0, migrateToV2Quote_js_1.computeVaultV1MigrateToV2Quote)({
|
|
132
|
+
sourceVault,
|
|
133
|
+
targetVault,
|
|
134
|
+
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
135
|
+
referralFeePct: common.referralFeePct,
|
|
136
|
+
deadline: intent.deadline,
|
|
137
|
+
slippageTolerance,
|
|
138
|
+
now,
|
|
139
|
+
});
|
|
140
|
+
const domain = sourceVault.eip5267Domain;
|
|
141
|
+
const { approvals, signatureRequests, tokenPermitRequestId } = await (0, shareSpending_js_1.getVaultShareSpendingRequirements)(client, {
|
|
142
|
+
type: "vaultV1MigrateToV2",
|
|
143
|
+
shareToken: new blue_sdk_1.Token({
|
|
144
|
+
address: sourceVault.address,
|
|
145
|
+
name: sourceVault.name,
|
|
146
|
+
eip5267Domain: domain == null
|
|
147
|
+
? undefined
|
|
148
|
+
: new blue_sdk_1.Eip5267Domain({
|
|
149
|
+
...domain,
|
|
150
|
+
extensions: [...domain.extensions],
|
|
151
|
+
}),
|
|
152
|
+
}),
|
|
153
|
+
account,
|
|
154
|
+
chainId,
|
|
155
|
+
requiredShareAllowance,
|
|
156
|
+
deadline: intent.deadline,
|
|
157
|
+
supportSignature: intent.supportSignature,
|
|
158
|
+
now,
|
|
159
|
+
});
|
|
160
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
161
|
+
version: 2,
|
|
162
|
+
account,
|
|
163
|
+
chainId,
|
|
164
|
+
expiresAt: intent.expiresAt,
|
|
165
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
166
|
+
steps: [
|
|
167
|
+
...approvals,
|
|
168
|
+
{
|
|
169
|
+
id: "vaultV1MigrateToV2",
|
|
170
|
+
label: "Migrate to Vault V2",
|
|
171
|
+
action: {
|
|
172
|
+
type: "vaultV1MigrateToV2",
|
|
173
|
+
inputs: {
|
|
174
|
+
chainId,
|
|
175
|
+
account,
|
|
176
|
+
vault: sourceVault.address,
|
|
177
|
+
sourceVault: sourceVault.address,
|
|
178
|
+
targetVault: targetVault.address,
|
|
179
|
+
asset: sourceVault.asset,
|
|
180
|
+
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
181
|
+
maxSharePrice: maxSharePriceVaultV2,
|
|
182
|
+
requiredShareAllowance,
|
|
183
|
+
...common,
|
|
184
|
+
},
|
|
185
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
186
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
187
|
+
: {},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
signatureRequests,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
/** @internal Maps stored maxSharePrice to the ABI maxSharePriceVaultV2 and encodes the source permit. */
|
|
195
|
+
function buildVaultV1MigrateToV2(action, requests) {
|
|
196
|
+
const { vault: _vault, sourceVault, maxSharePrice, asset, requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
197
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
198
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
199
|
+
asset: sourceVault,
|
|
200
|
+
owner: account,
|
|
201
|
+
});
|
|
202
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
|
|
203
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
204
|
+
amount: requiredShareAllowance,
|
|
205
|
+
deadline: args.deadline,
|
|
206
|
+
});
|
|
207
|
+
return (0, migrateToV2_js_1.vaultV1MigrateToV2)({
|
|
208
|
+
vault: { chainId, address: sourceVault, asset },
|
|
209
|
+
args: {
|
|
210
|
+
...args,
|
|
211
|
+
targetAsset: asset,
|
|
212
|
+
maxSharePriceVaultV2: maxSharePrice,
|
|
213
|
+
userAddress: account,
|
|
214
|
+
requirementSignature: permit,
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
@@ -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>>;
|