@morpho-org/morpho-sdk 10.0.0-next.0 → 10.0.1
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,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareVaultV1Redeem = prepareVaultV1Redeem;
|
|
4
|
+
exports.buildVaultV1Redeem = buildVaultV1Redeem;
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
7
|
+
const redeem_js_1 = require("../../actions/vaultV1/redeem.js");
|
|
8
|
+
const permit_js_1 = require("../permit.js");
|
|
9
|
+
const redeem_js_2 = require("../redeem.js");
|
|
10
|
+
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
12
|
+
* Prepares an exact-share Vault V1 redemption with a direct unlimited share approval or ERC-2612
|
|
13
|
+
* permit when needed. Reads the share allowance and, for permits, the account's nonce. The returned
|
|
14
|
+
* plan contains only fixed inputs and signature requests; it never uses Permit2 or fetch requests.
|
|
15
|
+
* Redemption sets no on-chain minimum assets received and accepts no slippage tolerance input.
|
|
16
|
+
* @param client - Viem client connected to the target chain.
|
|
17
|
+
* @param params - Vault share metadata and caller intent; inherited fields follow IntentParams.
|
|
18
|
+
* @param params.shareToken - Required share Token carrying the vault address and V1 permit-domain metadata; no accrual snapshot is required.
|
|
19
|
+
* @param params.shares - Positive exact share amount, not underlying assets.
|
|
20
|
+
* @param params.supportSignature - Defaults to false for direct approval; true selects an unlimited ERC-2612 share permit when allowance is insufficient.
|
|
21
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
22
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
23
|
+
* @returns A static plan containing any share approval followed by the redemption step.
|
|
24
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
25
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
26
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
|
|
27
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
28
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
29
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
30
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
31
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
32
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
33
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
34
|
+
* @throws {MissingContractCodeError} when VaultBundlesV1 is absent.
|
|
35
|
+
* @throws {viem.BaseError} when an allowance, nonce, chain or contract-code read fails.
|
|
36
|
+
* @see resolveIntent for shared expiry, fee and calldata origin validation.
|
|
37
|
+
* @see getVaultBundlesSharesRequirements for share-permit domain errors.
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { prepareVaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
41
|
+
* import { fetchToken } from "@morpho-org/morpho-sdk/fetch";
|
|
42
|
+
* import { createPublicClient, http } from "viem";
|
|
43
|
+
* import { mainnet } from "viem/chains";
|
|
44
|
+
* import type { Address } from "viem";
|
|
45
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
46
|
+
* const prepare = async (vault: Address, account: Address, shares: bigint) =>
|
|
47
|
+
* prepareVaultV1Redeem(client, {
|
|
48
|
+
* account, chainId: mainnet.id, shares, supportSignature: true,
|
|
49
|
+
* shareToken: await fetchToken(vault, client),
|
|
50
|
+
* });
|
|
51
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
async function prepareVaultV1Redeem(client, params) {
|
|
55
|
+
return (0, redeem_js_2.prepareVaultRedeem)(client, { ...params, type: "vaultV1Redeem" });
|
|
56
|
+
}
|
|
57
|
+
/** @internal Encodes a redemption from fixed inputs and the referenced share permit. */
|
|
58
|
+
function buildVaultV1Redeem(action, requests) {
|
|
59
|
+
const { chainId, account, ...args } = action.inputs;
|
|
60
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
61
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
62
|
+
asset: action.inputs.vault,
|
|
63
|
+
owner: account,
|
|
64
|
+
});
|
|
65
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
|
|
66
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
67
|
+
amount: action.inputs.shares,
|
|
68
|
+
deadline: action.inputs.deadline,
|
|
69
|
+
});
|
|
70
|
+
return (0, redeem_js_1.vaultV1Redeem)({
|
|
71
|
+
vault: { chainId, address: action.inputs.vault },
|
|
72
|
+
args: {
|
|
73
|
+
...args,
|
|
74
|
+
userAddress: account,
|
|
75
|
+
requirementSignature: permit,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -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,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareVaultV1Withdraw = prepareVaultV1Withdraw;
|
|
4
|
+
exports.buildVaultV1Withdraw = buildVaultV1Withdraw;
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const common_js_1 = require("../../actions/bundles/common.js");
|
|
7
|
+
const withdraw_js_1 = require("../../actions/vaultV1/withdraw.js");
|
|
8
|
+
const permit_js_1 = require("../permit.js");
|
|
9
|
+
const withdraw_js_2 = require("../withdraw.js");
|
|
10
|
+
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
12
|
+
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
13
|
+
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
14
|
+
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
15
|
+
* When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
|
|
16
|
+
* `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
|
|
17
|
+
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
18
|
+
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
19
|
+
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
20
|
+
* @param params.vault - Caller-fetched AccrualVault snapshot used for the share quote; its address identifies the vault.
|
|
21
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
22
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
23
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
24
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
25
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
26
|
+
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
27
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
28
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h`.
|
|
29
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
30
|
+
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
31
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
32
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` 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 {NegativeInputError} when `referralFee.bps` is negative.
|
|
36
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
37
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
38
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
39
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
40
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
41
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
42
|
+
* @throws {MissingPermitDomainNameError} when share allowance is insufficient, signatures are enabled, and the snapshot has neither a permit domain nor a name.
|
|
43
|
+
* @throws {InvalidPermitDomainChainIdError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing chain ID.
|
|
44
|
+
* @throws {InvalidPermitDomainVerifyingContractError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain has a different or missing verifying contract.
|
|
45
|
+
* @throws {UnsupportedPermitDomainExtensionsError} when share allowance is insufficient, signatures are enabled, and the snapshot's permit domain advertises extensions.
|
|
46
|
+
* @see computeVaultMaxShareAllowance for quote errors.
|
|
47
|
+
* @see getVaultBundlesSharesRequirements for allowance and nonce reads.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { prepareVaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
51
|
+
* import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
|
|
52
|
+
* import { createPublicClient, http } from "viem";
|
|
53
|
+
* import { mainnet } from "viem/chains";
|
|
54
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
55
|
+
* const vault = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
56
|
+
* const plan = await prepareVaultV1Withdraw(client, {
|
|
57
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
58
|
+
* vault: await fetchAccrualVault(vault, client),
|
|
59
|
+
* });
|
|
60
|
+
* // Sign the pending requests, applySignatures to verify and attach them, then build.
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
async function prepareVaultV1Withdraw(client, params) {
|
|
64
|
+
return (0, withdraw_js_2.prepareVaultWithdraw)(client, { ...params, type: "vaultV1Withdraw" });
|
|
65
|
+
}
|
|
66
|
+
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
67
|
+
function buildVaultV1Withdraw(action, requests) {
|
|
68
|
+
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
69
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
70
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
71
|
+
asset: action.inputs.vault,
|
|
72
|
+
owner: account,
|
|
73
|
+
});
|
|
74
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
|
|
75
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
76
|
+
amount: requiredShareAllowance,
|
|
77
|
+
deadline: action.inputs.deadline,
|
|
78
|
+
});
|
|
79
|
+
return (0, withdraw_js_1.vaultV1Withdraw)({
|
|
80
|
+
vault: { chainId, address: action.inputs.vault },
|
|
81
|
+
args: {
|
|
82
|
+
...args,
|
|
83
|
+
amount: assets,
|
|
84
|
+
userAddress: account,
|
|
85
|
+
requirementSignature: permit,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -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. */
|
|
@@ -1,83 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateDepositPlanAction = validateDepositPlanAction;
|
|
4
3
|
exports.prepareVaultV2Deposit = prepareVaultV2Deposit;
|
|
5
4
|
exports.buildVaultV2Deposit = buildVaultV2Deposit;
|
|
6
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
-
const viem_1 = require("viem");
|
|
9
6
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
|
-
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
7
|
const deposit_js_1 = require("../../actions/vaultV2/deposit.js");
|
|
12
|
-
const
|
|
13
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
14
|
-
const validate_js_1 = require("../../helpers/validate.js");
|
|
15
|
-
const index_js_2 = require("../../types/index.js");
|
|
16
|
-
const error_js_1 = require("../error.js");
|
|
17
|
-
const intent_js_1 = require("../intent.js");
|
|
8
|
+
const deposit_js_2 = require("../deposit.js");
|
|
18
9
|
const permit_js_1 = require("../permit.js");
|
|
19
|
-
const requirements_js_1 = require("../requirements.js");
|
|
20
|
-
const validation_js_1 = require("../validation.js");
|
|
21
|
-
/** @internal Validates the stored Vault V2 deposit action's input shape. */
|
|
22
|
-
function validateDepositPlanAction(action, path) {
|
|
23
|
-
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
24
|
-
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
25
|
-
path: `${path}.inputs`,
|
|
26
|
-
fields: { asset: "address", maxSharePrice: "uint256 bigint" },
|
|
27
|
-
});
|
|
28
|
-
if ((inputs.amount === undefined) === (inputs.nativeAmount === undefined))
|
|
29
|
-
throw new error_js_1.InvalidTransactionPlanError({
|
|
30
|
-
path: `${path}.inputs`,
|
|
31
|
-
reason: "expected exactly one of amount or nativeAmount",
|
|
32
|
-
});
|
|
33
|
-
const field = inputs.amount === undefined ? "nativeAmount" : "amount";
|
|
34
|
-
(0, validation_js_1.validatePlanField)(inputs[field], {
|
|
35
|
-
path: `${path}.inputs.${field}`,
|
|
36
|
-
type: "uint256 bigint",
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function resolveDepositInputs(params, now) {
|
|
40
|
-
const { vault, chainId, amount, vaultData } = params;
|
|
41
|
-
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
42
|
-
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
43
|
-
(0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
|
|
44
|
-
const native = (params.funding ?? { type: "erc20" }).type === "native";
|
|
45
|
-
if (amount <= 0n)
|
|
46
|
-
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
47
|
-
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
48
|
-
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
49
|
-
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
50
|
-
deadline: intent.deadline,
|
|
51
|
-
referralFeePct: intent.referralFeePct,
|
|
52
|
-
referralFeeRecipient: intent.referralFeeRecipient,
|
|
53
|
-
});
|
|
54
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.address, vault))
|
|
55
|
-
throw new index_js_2.VaultAddressMismatchError(vaultData.address, vault);
|
|
56
|
-
const { asset } = vaultData;
|
|
57
|
-
// Native funding must target the chain's wrapped-native vault asset.
|
|
58
|
-
if (native)
|
|
59
|
-
(0, validate_js_1.validateNativeVaultAsset)(chainId, asset);
|
|
60
|
-
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
61
|
-
const maxSharePrice = (0, index_js_1.computeVaultMaxSharePrice)({
|
|
62
|
-
vaultData,
|
|
63
|
-
deadline: intent.deadline,
|
|
64
|
-
assets: amount - (0, common_js_1.getBundlesReferralFeeAssets)(amount, common.referralFeePct),
|
|
65
|
-
slippageTolerance,
|
|
66
|
-
});
|
|
67
|
-
return { intent, native, common, asset, maxSharePrice };
|
|
68
|
-
}
|
|
69
10
|
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
70
12
|
* Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
|
|
71
13
|
* directly. The quote is fixed on the deposit step at preparation, so the returned plan is static:
|
|
72
14
|
* only signatures are added before building.
|
|
73
15
|
* @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
|
|
74
|
-
* @param params.vault -
|
|
75
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the asset and deadline-accrued share-price bound.
|
|
16
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
76
17
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
77
18
|
* @param params.account - Non-zero account funding, signing and sending the deposit.
|
|
78
|
-
* @param params.
|
|
19
|
+
* @param params.assets - Positive gross deposit in asset base units, before referral fees.
|
|
79
20
|
* @param params.funding.type - Optional funding source: `"erc20"` (default) or `"native"`; native funding requires the vault asset to be wNative.
|
|
80
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
21
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
81
22
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
82
23
|
* @param params.slippageTolerance - Optional WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE` and must not exceed `MAX_SLIPPAGE_TOLERANCE`.
|
|
83
24
|
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
@@ -88,15 +29,14 @@ function resolveDepositInputs(params, now) {
|
|
|
88
29
|
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
89
30
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
90
31
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
91
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
32
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets`, net assets or previewed shares are not positive.
|
|
92
33
|
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
93
34
|
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
94
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
35
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
95
36
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
96
37
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
97
38
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
98
39
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
99
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
100
40
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
101
41
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
102
42
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
@@ -110,88 +50,19 @@ function resolveDepositInputs(params, now) {
|
|
|
110
50
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
111
51
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
112
52
|
* const plan = await prepareVaultV2Deposit(client, {
|
|
113
|
-
*
|
|
114
|
-
*
|
|
53
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
54
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
115
55
|
* now: (await client.getBlock()).timestamp,
|
|
116
56
|
* });
|
|
117
57
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
118
58
|
* ```
|
|
119
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
120
59
|
*/
|
|
121
60
|
async function prepareVaultV2Deposit(client, params) {
|
|
122
|
-
|
|
123
|
-
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
124
|
-
const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
|
|
125
|
-
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
126
|
-
const [requirements] = await Promise.all([
|
|
127
|
-
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId).then(() => native
|
|
128
|
-
? []
|
|
129
|
-
: (0, requirements_js_1.getTokenRequirements)(client, {
|
|
130
|
-
token: asset,
|
|
131
|
-
spender,
|
|
132
|
-
amount,
|
|
133
|
-
owner: account,
|
|
134
|
-
chainId,
|
|
135
|
-
deadline: intent.deadline,
|
|
136
|
-
now,
|
|
137
|
-
supportSignature: intent.supportSignature,
|
|
138
|
-
deployless: intent.deployless,
|
|
139
|
-
})),
|
|
140
|
-
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
141
|
-
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
142
|
-
]),
|
|
143
|
-
]);
|
|
144
|
-
const approvals = [];
|
|
145
|
-
const signatureRequests = [];
|
|
146
|
-
const tokenPermitRequestId = "vaultV2Deposit:tokenPermit";
|
|
147
|
-
for (const requirement of requirements) {
|
|
148
|
-
if ("sign" in requirement) {
|
|
149
|
-
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
153
|
-
id: approvals.length === 0
|
|
154
|
-
? "vaultV2Deposit:approval"
|
|
155
|
-
: `vaultV2Deposit:approval:${approvals.length + 1}`,
|
|
156
|
-
chainId,
|
|
157
|
-
account,
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
162
|
-
version: 1,
|
|
163
|
-
account,
|
|
164
|
-
chainId,
|
|
165
|
-
expiresAt: intent.expiresAt,
|
|
166
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
167
|
-
steps: [
|
|
168
|
-
...approvals,
|
|
169
|
-
{
|
|
170
|
-
id: "vaultV2Deposit",
|
|
171
|
-
label: "Deposit into vault",
|
|
172
|
-
action: {
|
|
173
|
-
type: "vaultV2Deposit",
|
|
174
|
-
inputs: {
|
|
175
|
-
chainId,
|
|
176
|
-
account,
|
|
177
|
-
vault,
|
|
178
|
-
asset,
|
|
179
|
-
maxSharePrice,
|
|
180
|
-
...(native ? { nativeAmount: amount } : { amount }),
|
|
181
|
-
...common,
|
|
182
|
-
},
|
|
183
|
-
signatureRequestIds: signatureRequests.length > 0
|
|
184
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
185
|
-
: {},
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
signatureRequests,
|
|
190
|
-
}));
|
|
61
|
+
return (0, deposit_js_2.prepareVaultDeposit)(client, { ...params, type: "vaultV2Deposit" });
|
|
191
62
|
}
|
|
192
63
|
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|
|
193
64
|
function buildVaultV2Deposit(action, requests) {
|
|
194
|
-
const { asset, chainId, account, ...args } = action.inputs;
|
|
65
|
+
const { asset, chainId, account, assets, nativeAssets, ...args } = action.inputs;
|
|
195
66
|
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
196
67
|
id: action.signatureRequestIds.tokenPermit,
|
|
197
68
|
asset,
|
|
@@ -199,13 +70,16 @@ function buildVaultV2Deposit(action, requests) {
|
|
|
199
70
|
});
|
|
200
71
|
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signature ? [signature] : [], {
|
|
201
72
|
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
202
|
-
amount:
|
|
73
|
+
amount: assets ?? nativeAssets,
|
|
203
74
|
deadline: action.inputs.deadline,
|
|
204
75
|
});
|
|
205
76
|
return (0, deposit_js_1.vaultV2Deposit)({
|
|
206
77
|
vault: { chainId, address: action.inputs.vault, asset },
|
|
207
78
|
args: {
|
|
208
79
|
...args,
|
|
80
|
+
...(nativeAssets === undefined
|
|
81
|
+
? { amount: assets }
|
|
82
|
+
: { nativeAmount: nativeAssets }),
|
|
209
83
|
userAddress: account,
|
|
210
84
|
requirementSignature,
|
|
211
85
|
},
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Address, Client } from "viem";
|
|
2
|
+
import type { ReferenceTimestampParams, Transaction, VaultV2ForceRedeemAction } from "../../types/index.js";
|
|
3
|
+
import { type IntentParams } from "../intent.js";
|
|
4
|
+
import type { Action, TransactionPlan } from "../types.js";
|
|
5
|
+
/** @internal Validates the stored force-redeem action's plain input shape. */
|
|
6
|
+
export declare function validateForceRedeemPlanAction(action: Record<string, unknown>, path: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
9
|
+
* Caller-supplied shares and deallocations for the vault's native force-redeem multicall.
|
|
10
|
+
* No approval or signature is needed.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const params: VaultV2ForceRedeemPlanParams = {
|
|
14
|
+
* vaultAddress, chainId: 1, account, shares: 100n,
|
|
15
|
+
* deallocations: [{ adapter, assets: 100n }],
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface VaultV2ForceRedeemPlanParams extends Pick<IntentParams, "chainId" | "account" | "expiresAt" | "calldataOrigin">, ReferenceTimestampParams {
|
|
20
|
+
readonly vaultAddress: Address;
|
|
21
|
+
readonly shares: bigint;
|
|
22
|
+
/** Fixed, ordered asset deallocations executed before redeeming. Include any required penalty buffer. */
|
|
23
|
+
readonly deallocations: Extract<Action, {
|
|
24
|
+
type: "vaultV2ForceRedeem";
|
|
25
|
+
}>["inputs"]["deallocations"];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
29
|
+
* Prepares one vault multicall, fixing the supplied deallocations and shares in the plan.
|
|
30
|
+
* Shares and deallocation penalties are burned from `account`; redeemed assets go to `account`.
|
|
31
|
+
* No permissions are requested, and expiry is plan metadata, not an onchain deadline.
|
|
32
|
+
* @param client - Client used to validate the chain, not retained by the plan.
|
|
33
|
+
* @param params.vaultAddress - Vault V2 whose shares are redeemed.
|
|
34
|
+
* @param params.chainId - Chain containing the vault.
|
|
35
|
+
* @param params.account - Share owner submitting the multicall and receiving the redeemed assets.
|
|
36
|
+
* @param params.shares - Positive shares to redeem, in vault share base units.
|
|
37
|
+
* @param params.deallocations - Non-empty, ordered deallocations with positive `assets` in asset base units, including any penalty buffer.
|
|
38
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
39
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` and is plan metadata only.
|
|
40
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
41
|
+
* @returns A deep-frozen `TransactionPlan` containing one `vaultV2ForceRedeem` step and no signature requests.
|
|
42
|
+
* @throws {ChainIdMismatchError} If the client targets another chain.
|
|
43
|
+
* @throws {EmptyDeallocationsError} If `deallocations` is empty.
|
|
44
|
+
* @throws {NonPositiveInputError} If expiry, shares or any deallocation assets are non-positive.
|
|
45
|
+
* @throws {ZeroAccountError} If `account` is the zero address.
|
|
46
|
+
* @throws {NonIntegerInputError} If `expiresAt` is not a safe integer.
|
|
47
|
+
* @throws {ExpiredDeadlineError} If `expiresAt` is not in the future.
|
|
48
|
+
* @throws {InvalidCalldataOriginError} If `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { prepareVaultV2ForceRedeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
52
|
+
* import { createPublicClient, http } from "viem";
|
|
53
|
+
* import { mainnet } from "viem/chains";
|
|
54
|
+
*
|
|
55
|
+
* // Fixture addresses for preparation only; use your vault, adapter and share owner before execution.
|
|
56
|
+
* const IN_KIND_VAULT = "0x0000000000000000000000000000000000001001";
|
|
57
|
+
* const IN_KIND_ADAPTER = "0x0000000000000000000000000000000000001002";
|
|
58
|
+
* const IN_KIND_USER = "0x0000000000000000000000000000000000001004";
|
|
59
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
60
|
+
* const plan: TransactionPlan = await prepareVaultV2ForceRedeem(client, {
|
|
61
|
+
* vaultAddress: IN_KIND_VAULT, chainId: mainnet.id, account: IN_KIND_USER,
|
|
62
|
+
* shares: 100n,
|
|
63
|
+
* now: (await client.getBlock()).timestamp,
|
|
64
|
+
* deallocations: [{ adapter: IN_KIND_ADAPTER, assets: 100n }],
|
|
65
|
+
* });
|
|
66
|
+
* // plan.steps contains one step with action.type === "vaultV2ForceRedeem".
|
|
67
|
+
* // plan.signatureRequests is []; the caller signs and submits the built transaction.
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function prepareVaultV2ForceRedeem(client: Client, params: VaultV2ForceRedeemPlanParams): Promise<TransactionPlan>;
|
|
71
|
+
/** @internal Encodes the fixed multicall through the same action as the forceRedeem handle. */
|
|
72
|
+
export declare function buildVaultV2ForceRedeem(action: Extract<Action, {
|
|
73
|
+
type: "vaultV2ForceRedeem";
|
|
74
|
+
}>): Readonly<Transaction<VaultV2ForceRedeemAction>>;
|