@morpho-org/morpho-sdk 9.6.0-next.0 → 9.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v6-to-v7.md +1 -1
- package/README.md +123 -3
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.js +39 -32
- package/lib/cjs/actions/midnight/cancelAndMake.js +20 -98
- package/lib/cjs/actions/midnight/index.d.ts +2 -0
- package/lib/cjs/actions/midnight/index.js +2 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +5 -6
- package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +39 -0
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +91 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +31 -32
- package/lib/cjs/actions/midnight/takeBorrow.js +24 -23
- package/lib/cjs/actions/midnight/takeLend.js +24 -23
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
- package/lib/cjs/actions/midnight/takeWithdraw.js +24 -23
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +104 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +7 -7
- 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/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +77 -3
- package/lib/cjs/entities/midnight/midnight.js +174 -0
- package/lib/cjs/entities/midnight/types.d.ts +16 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +12 -46
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -0
- package/lib/cjs/entities/requirements/getErc2612Permit.js +60 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +3 -3
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +10 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -33
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
- 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 +0 -2
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +1 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +12 -5
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +129 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +28 -0
- package/lib/cjs/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
- package/lib/cjs/helpers/validateMidnightCollateralSupplies.js +28 -0
- package/lib/cjs/helpers/validatePositiveInput.d.ts +10 -0
- package/lib/cjs/helpers/validatePositiveInput.js +18 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +18 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +5 -5
- package/lib/cjs/transactionPlan/approval.d.ts +2 -0
- package/lib/cjs/transactionPlan/approval.js +16 -0
- package/lib/cjs/transactionPlan/error.d.ts +145 -0
- package/lib/cjs/transactionPlan/error.js +186 -0
- package/lib/cjs/transactionPlan/getTokenPermit.d.ts +11 -0
- package/lib/cjs/transactionPlan/getTokenPermit.js +18 -0
- package/lib/cjs/transactionPlan/index.d.ts +9 -0
- package/lib/cjs/transactionPlan/index.js +24 -0
- package/lib/cjs/transactionPlan/intent.d.ts +51 -0
- package/lib/cjs/transactionPlan/intent.js +54 -0
- package/lib/cjs/transactionPlan/permit.d.ts +13 -0
- package/lib/cjs/transactionPlan/permit.js +145 -0
- package/lib/cjs/transactionPlan/plan.d.ts +99 -0
- package/lib/cjs/transactionPlan/plan.js +232 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +44 -0
- package/lib/cjs/transactionPlan/requirements.js +79 -0
- package/lib/cjs/transactionPlan/serde.d.ts +33 -0
- package/lib/cjs/transactionPlan/serde.js +205 -0
- package/lib/cjs/transactionPlan/types.d.ts +91 -0
- package/lib/cjs/transactionPlan/types.js +2 -0
- package/lib/cjs/transactionPlan/validateActions.d.ts +8 -0
- package/lib/cjs/transactionPlan/validateActions.js +19 -0
- package/lib/cjs/transactionPlan/validation.d.ts +17 -0
- package/lib/cjs/transactionPlan/validation.js +70 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +81 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +211 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +190 -0
- package/lib/cjs/transactionPlan/version.d.ts +2 -0
- package/lib/cjs/transactionPlan/version.js +9 -0
- package/lib/cjs/types/action.d.ts +18 -3
- package/lib/cjs/types/error.d.ts +23 -2
- package/lib/cjs/types/error.js +45 -5
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.js +39 -32
- package/lib/esm/actions/midnight/cancelAndMake.js +25 -103
- package/lib/esm/actions/midnight/index.d.ts +2 -0
- package/lib/esm/actions/midnight/index.js +2 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +5 -6
- package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +39 -0
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +87 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -34
- package/lib/esm/actions/midnight/takeBorrow.js +25 -24
- package/lib/esm/actions/midnight/takeLend.js +25 -24
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +20 -19
- package/lib/esm/actions/midnight/takeWithdraw.js +25 -24
- package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +44 -0
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +100 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +1 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +1 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +8 -8
- 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/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +77 -3
- package/lib/esm/entities/midnight/midnight.js +176 -2
- package/lib/esm/entities/midnight/types.d.ts +16 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +14 -48
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -0
- package/lib/esm/entities/requirements/getErc2612Permit.js +57 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +3 -3
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +10 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -33
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
- 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 +1 -3
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +1 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +13 -6
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +68 -0
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +124 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +25 -0
- package/lib/esm/helpers/validateMidnightCollateralSupplies.d.ts +17 -0
- package/lib/esm/helpers/validateMidnightCollateralSupplies.js +24 -0
- package/lib/esm/helpers/validatePositiveInput.d.ts +10 -0
- package/lib/esm/helpers/validatePositiveInput.js +14 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/transactionPlan/approval.d.ts +2 -0
- package/lib/esm/transactionPlan/approval.js +13 -0
- package/lib/esm/transactionPlan/error.d.ts +145 -0
- package/lib/esm/transactionPlan/error.js +175 -0
- package/lib/esm/transactionPlan/getTokenPermit.d.ts +11 -0
- package/lib/esm/transactionPlan/getTokenPermit.js +15 -0
- package/lib/esm/transactionPlan/index.d.ts +9 -0
- package/lib/esm/transactionPlan/index.js +5 -0
- package/lib/esm/transactionPlan/intent.d.ts +51 -0
- package/lib/esm/transactionPlan/intent.js +51 -0
- package/lib/esm/transactionPlan/permit.d.ts +13 -0
- package/lib/esm/transactionPlan/permit.js +140 -0
- package/lib/esm/transactionPlan/plan.d.ts +99 -0
- package/lib/esm/transactionPlan/plan.js +226 -0
- package/lib/esm/transactionPlan/requirements.d.ts +44 -0
- package/lib/esm/transactionPlan/requirements.js +74 -0
- package/lib/esm/transactionPlan/serde.d.ts +33 -0
- package/lib/esm/transactionPlan/serde.js +201 -0
- package/lib/esm/transactionPlan/types.d.ts +91 -0
- package/lib/esm/transactionPlan/types.js +1 -0
- package/lib/esm/transactionPlan/validateActions.d.ts +8 -0
- package/lib/esm/transactionPlan/validateActions.js +16 -0
- package/lib/esm/transactionPlan/validation.d.ts +17 -0
- package/lib/esm/transactionPlan/validation.js +64 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +81 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.js +206 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +185 -0
- package/lib/esm/transactionPlan/version.d.ts +2 -0
- package/lib/esm/transactionPlan/version.js +6 -0
- package/lib/esm/types/action.d.ts +18 -3
- package/lib/esm/types/error.d.ts +23 -2
- package/lib/esm/types/error.js +40 -3
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +8 -7
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateDepositPlanAction = validateDepositPlanAction;
|
|
4
|
+
exports.prepareVaultV2Deposit = prepareVaultV2Deposit;
|
|
5
|
+
exports.buildVaultV2Deposit = buildVaultV2Deposit;
|
|
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 validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
|
+
const deposit_js_1 = require("../../actions/vaultV2/deposit.js");
|
|
12
|
+
const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
|
|
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");
|
|
18
|
+
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
|
+
/**
|
|
70
|
+
* Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
|
|
71
|
+
* directly. The quote is fixed on the deposit step at preparation, so the returned plan is static:
|
|
72
|
+
* only signatures are added before building.
|
|
73
|
+
* @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
|
|
74
|
+
* @param params.vault - Vault V2 contract receiving the net deposit.
|
|
75
|
+
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the asset and deadline-accrued share-price bound.
|
|
76
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
77
|
+
* @param params.account - Non-zero account funding, signing and sending the deposit.
|
|
78
|
+
* @param params.amount - Positive gross deposit in asset base units, before referral fees.
|
|
79
|
+
* @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 amount; defaults to zero and must be below 10,000.
|
|
81
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
82
|
+
* @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
|
+
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
84
|
+
* @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
|
|
85
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
86
|
+
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
87
|
+
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
88
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
89
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
90
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `amount`, net assets or previewed shares are not positive.
|
|
91
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
92
|
+
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
93
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
|
|
94
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
95
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
96
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
97
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
98
|
+
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
99
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
100
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
101
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
102
|
+
* @see computeVaultMaxSharePrice for quote errors.
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { prepareVaultV2Deposit } from "@morpho-org/morpho-sdk";
|
|
106
|
+
* import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
107
|
+
* import { createPublicClient, http } from "viem";
|
|
108
|
+
* import { mainnet } from "viem/chains";
|
|
109
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
110
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
111
|
+
* const plan = await prepareVaultV2Deposit(client, {
|
|
112
|
+
* vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
|
|
113
|
+
* vaultData: await fetchAccrualVaultV2(vault, client),
|
|
114
|
+
* });
|
|
115
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
116
|
+
* ```
|
|
117
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
118
|
+
*/
|
|
119
|
+
async function prepareVaultV2Deposit(client, params) {
|
|
120
|
+
const { vault, chainId, account, amount } = params;
|
|
121
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
122
|
+
const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
|
|
123
|
+
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
124
|
+
const [requirements] = await Promise.all([
|
|
125
|
+
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId).then(() => native
|
|
126
|
+
? []
|
|
127
|
+
: (0, requirements_js_1.getTokenRequirements)(client, {
|
|
128
|
+
token: asset,
|
|
129
|
+
spender,
|
|
130
|
+
amount,
|
|
131
|
+
owner: account,
|
|
132
|
+
chainId,
|
|
133
|
+
deadline: intent.deadline,
|
|
134
|
+
now,
|
|
135
|
+
supportSignature: intent.supportSignature,
|
|
136
|
+
deployless: intent.deployless,
|
|
137
|
+
})),
|
|
138
|
+
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
139
|
+
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
140
|
+
]),
|
|
141
|
+
]);
|
|
142
|
+
const approvals = [];
|
|
143
|
+
const signatureRequests = [];
|
|
144
|
+
const tokenPermitRequestId = "vaultV2Deposit:tokenPermit";
|
|
145
|
+
for (const requirement of requirements) {
|
|
146
|
+
if ("sign" in requirement) {
|
|
147
|
+
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
151
|
+
id: approvals.length === 0
|
|
152
|
+
? "vaultV2Deposit:approval"
|
|
153
|
+
: `vaultV2Deposit:approval:${approvals.length + 1}`,
|
|
154
|
+
chainId,
|
|
155
|
+
account,
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
160
|
+
version: 1,
|
|
161
|
+
account,
|
|
162
|
+
chainId,
|
|
163
|
+
expiresAt: intent.expiresAt,
|
|
164
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
165
|
+
steps: [
|
|
166
|
+
...approvals,
|
|
167
|
+
{
|
|
168
|
+
id: "vaultV2Deposit",
|
|
169
|
+
label: "Deposit into vault",
|
|
170
|
+
action: {
|
|
171
|
+
type: "vaultV2Deposit",
|
|
172
|
+
inputs: {
|
|
173
|
+
chainId,
|
|
174
|
+
account,
|
|
175
|
+
vault,
|
|
176
|
+
asset,
|
|
177
|
+
maxSharePrice,
|
|
178
|
+
...(native ? { nativeAmount: amount } : { amount }),
|
|
179
|
+
...common,
|
|
180
|
+
},
|
|
181
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
182
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
183
|
+
: {},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
signatureRequests,
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|
|
191
|
+
function buildVaultV2Deposit(action, requests) {
|
|
192
|
+
const { asset, chainId, account, ...args } = action.inputs;
|
|
193
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
194
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
195
|
+
asset,
|
|
196
|
+
owner: account,
|
|
197
|
+
});
|
|
198
|
+
const requirementSignature = (0, common_js_1.selectBundlesTokenRequirementSignature)(signature ? [signature] : [], {
|
|
199
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
200
|
+
amount: action.inputs.amount ?? action.inputs.nativeAmount,
|
|
201
|
+
deadline: action.inputs.deadline,
|
|
202
|
+
});
|
|
203
|
+
return (0, deposit_js_1.vaultV2Deposit)({
|
|
204
|
+
vault: { chainId, address: action.inputs.vault, asset },
|
|
205
|
+
args: {
|
|
206
|
+
...args,
|
|
207
|
+
userAddress: account,
|
|
208
|
+
requirementSignature,
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address, type Client } from "viem";
|
|
3
|
+
import { type Transaction, type VaultV2WithdrawAction } 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 V2 withdrawal action's input shape. */
|
|
7
|
+
export declare function validateWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Caller intent for a Vault V2 asset withdrawal, mirroring the Actions API withdraw inputs, plus the snapshot.
|
|
10
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
11
|
+
*/
|
|
12
|
+
export interface VaultV2WithdrawPlanParams extends IntentParams {
|
|
13
|
+
readonly vault: Address;
|
|
14
|
+
/** Gross assets withdrawn, before the referral fee. */
|
|
15
|
+
readonly amount: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Accrual snapshot of `vault`, fetched by the caller with `fetchAccrualVaultV2`. The required
|
|
18
|
+
* share allowance is derived from it at preparation; the snapshot itself is never stored.
|
|
19
|
+
*/
|
|
20
|
+
readonly vaultData: AccrualVaultV2;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
24
|
+
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
25
|
+
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
26
|
+
* When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
|
|
27
|
+
* `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
|
|
28
|
+
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
29
|
+
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
30
|
+
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
31
|
+
* @param params.vault - Vault V2 contract whose shares are burned for the withdrawal.
|
|
32
|
+
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
33
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
34
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
35
|
+
* @param params.amount - Positive gross withdrawal in asset base units, before referral fees.
|
|
36
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
37
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
38
|
+
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
39
|
+
* @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
|
|
40
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
41
|
+
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
42
|
+
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
43
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
44
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
45
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `amount` or the computed required shares are not positive.
|
|
46
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
47
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
48
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
|
|
49
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
50
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
51
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
52
|
+
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
53
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
54
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
55
|
+
* @see computeVaultMaxShareAllowance for quote errors.
|
|
56
|
+
* @see getVaultBundlesSharesRequirements for allowance and nonce reads.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { prepareVaultV2Withdraw } from "@morpho-org/morpho-sdk";
|
|
60
|
+
* import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
61
|
+
* import { createPublicClient, http } from "viem";
|
|
62
|
+
* import { mainnet } from "viem/chains";
|
|
63
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
64
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
65
|
+
* const plan = await prepareVaultV2Withdraw(client, {
|
|
66
|
+
* vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
|
|
67
|
+
* vaultData: await fetchAccrualVaultV2(vault, client),
|
|
68
|
+
* });
|
|
69
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
70
|
+
* ```
|
|
71
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
72
|
+
*/
|
|
73
|
+
export declare function prepareVaultV2Withdraw(client: Client, params: VaultV2WithdrawPlanParams): Promise<TransactionPlan>;
|
|
74
|
+
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
75
|
+
export declare function buildVaultV2Withdraw(action: Extract<Action, {
|
|
76
|
+
type: "vaultV2Withdraw";
|
|
77
|
+
}>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2WithdrawAction>>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateWithdrawPlanAction = validateWithdrawPlanAction;
|
|
4
|
+
exports.prepareVaultV2Withdraw = prepareVaultV2Withdraw;
|
|
5
|
+
exports.buildVaultV2Withdraw = buildVaultV2Withdraw;
|
|
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 validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
|
+
const withdraw_js_1 = require("../../actions/vaultV2/withdraw.js");
|
|
12
|
+
const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
|
|
13
|
+
const getVaultBundlesSharesRequirements_js_1 = require("../../entities/requirements/getVaultBundlesSharesRequirements.js");
|
|
14
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
15
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
16
|
+
const index_js_2 = require("../../types/index.js");
|
|
17
|
+
const intent_js_1 = require("../intent.js");
|
|
18
|
+
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 withdrawal action's input shape. */
|
|
22
|
+
function validateWithdrawPlanAction(action, path) {
|
|
23
|
+
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
24
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
25
|
+
path: `${path}.inputs`,
|
|
26
|
+
fields: {
|
|
27
|
+
amount: "uint256 bigint",
|
|
28
|
+
requiredShareAllowance: "uint256 bigint",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function resolveWithdrawInputs(params, now) {
|
|
33
|
+
const { vault, amount, vaultData } = params;
|
|
34
|
+
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
35
|
+
if (amount <= 0n)
|
|
36
|
+
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
37
|
+
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
38
|
+
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
39
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
40
|
+
deadline: intent.deadline,
|
|
41
|
+
referralFeePct: intent.referralFeePct,
|
|
42
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
43
|
+
});
|
|
44
|
+
if (!(0, viem_1.isAddressEqual)(vaultData.address, vault))
|
|
45
|
+
throw new index_js_2.VaultAddressMismatchError(vaultData.address, vault);
|
|
46
|
+
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
47
|
+
const requiredShareAllowance = (0, index_js_1.computeVaultMaxShareAllowance)({
|
|
48
|
+
vaultData,
|
|
49
|
+
deadline: intent.deadline,
|
|
50
|
+
assets: amount,
|
|
51
|
+
slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
52
|
+
});
|
|
53
|
+
return { intent, common, requiredShareAllowance };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
57
|
+
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
58
|
+
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
59
|
+
* When allowance is insufficient, both direct share approvals and ERC-2612 share permits authorize
|
|
60
|
+
* `maxUint256`, not the quote. Later withdrawals reuse that allowance without another signature.
|
|
61
|
+
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
62
|
+
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
63
|
+
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
64
|
+
* @param params.vault - Vault V2 contract whose shares are burned for the withdrawal.
|
|
65
|
+
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
66
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
67
|
+
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
68
|
+
* @param params.amount - Positive gross withdrawal in asset base units, before referral fees.
|
|
69
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross amount; defaults to zero and must be below 10,000.
|
|
70
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
71
|
+
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
72
|
+
* @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
|
|
73
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
74
|
+
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
75
|
+
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
76
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
77
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
78
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `amount` or the computed required shares are not positive.
|
|
79
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
80
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
81
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
|
|
82
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
83
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
84
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
85
|
+
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
86
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
87
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
88
|
+
* @see computeVaultMaxShareAllowance for quote errors.
|
|
89
|
+
* @see getVaultBundlesSharesRequirements for allowance and nonce reads.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { prepareVaultV2Withdraw } from "@morpho-org/morpho-sdk";
|
|
93
|
+
* import { 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 vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
98
|
+
* const plan = await prepareVaultV2Withdraw(client, {
|
|
99
|
+
* vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
|
|
100
|
+
* vaultData: await fetchAccrualVaultV2(vault, client),
|
|
101
|
+
* });
|
|
102
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
103
|
+
* ```
|
|
104
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
105
|
+
*/
|
|
106
|
+
async function prepareVaultV2Withdraw(client, params) {
|
|
107
|
+
const { vault, chainId, account, amount } = params;
|
|
108
|
+
const now = morpho_ts_1.Time.timestamp();
|
|
109
|
+
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
110
|
+
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
111
|
+
const [, , requirements] = await Promise.all([
|
|
112
|
+
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId),
|
|
113
|
+
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
114
|
+
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
115
|
+
]),
|
|
116
|
+
(0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(client, {
|
|
117
|
+
vaultData: new blue_sdk_1.Token({ address: vault }),
|
|
118
|
+
version: "vaultV2",
|
|
119
|
+
owner: account,
|
|
120
|
+
chainId,
|
|
121
|
+
requiredShareAllowance,
|
|
122
|
+
deadline: intent.deadline,
|
|
123
|
+
supportSignature: intent.supportSignature,
|
|
124
|
+
now,
|
|
125
|
+
}),
|
|
126
|
+
]);
|
|
127
|
+
const approvals = [];
|
|
128
|
+
const signatureRequests = [];
|
|
129
|
+
const tokenPermitRequestId = "vaultV2Withdraw:tokenPermit";
|
|
130
|
+
const requirement = requirements[0];
|
|
131
|
+
if (requirement !== undefined) {
|
|
132
|
+
if ("sign" in requirement) {
|
|
133
|
+
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
137
|
+
id: "vaultV2Withdraw:approval",
|
|
138
|
+
chainId,
|
|
139
|
+
account,
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
144
|
+
version: 1,
|
|
145
|
+
account,
|
|
146
|
+
chainId,
|
|
147
|
+
expiresAt: intent.expiresAt,
|
|
148
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
149
|
+
steps: [
|
|
150
|
+
...approvals,
|
|
151
|
+
{
|
|
152
|
+
id: "vaultV2Withdraw",
|
|
153
|
+
label: "Withdraw from vault",
|
|
154
|
+
action: {
|
|
155
|
+
type: "vaultV2Withdraw",
|
|
156
|
+
inputs: {
|
|
157
|
+
chainId,
|
|
158
|
+
account,
|
|
159
|
+
vault,
|
|
160
|
+
amount,
|
|
161
|
+
requiredShareAllowance,
|
|
162
|
+
...common,
|
|
163
|
+
},
|
|
164
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
165
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
166
|
+
: {},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
signatureRequests,
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
174
|
+
function buildVaultV2Withdraw(action, requests) {
|
|
175
|
+
const { requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
176
|
+
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
177
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
178
|
+
asset: action.inputs.vault,
|
|
179
|
+
owner: account,
|
|
180
|
+
});
|
|
181
|
+
const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signature ? [signature] : [], {
|
|
182
|
+
spender: (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1"),
|
|
183
|
+
amount: requiredShareAllowance,
|
|
184
|
+
deadline: action.inputs.deadline,
|
|
185
|
+
});
|
|
186
|
+
return (0, withdraw_js_1.vaultV2Withdraw)({
|
|
187
|
+
vault: { chainId, address: action.inputs.vault },
|
|
188
|
+
args: { ...args, userAddress: account, requirementSignature: permit },
|
|
189
|
+
});
|
|
190
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTransactionPlanVersion = validateTransactionPlanVersion;
|
|
4
|
+
const error_js_1 = require("./error.js");
|
|
5
|
+
/** @internal Rejects unsupported plan versions before interpreting stored fields. */
|
|
6
|
+
function validateTransactionPlanVersion(version) {
|
|
7
|
+
if (version !== 1)
|
|
8
|
+
throw new error_js_1.UnsupportedTransactionPlanVersionError(version);
|
|
9
|
+
}
|
|
@@ -283,12 +283,12 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
|
|
|
283
283
|
}> {
|
|
284
284
|
}
|
|
285
285
|
/**
|
|
286
|
-
* Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's
|
|
286
|
+
* Metadata for a direct Morpho Blue withdrawal of a BlueBuyCallback's supply shares,
|
|
287
287
|
* sent by the callback's owner.
|
|
288
288
|
*/
|
|
289
289
|
export interface BlueWithdrawBuyCallbackAction extends BaseAction<"blueWithdrawBuyCallback", {
|
|
290
290
|
readonly market: Hex;
|
|
291
|
-
/**
|
|
291
|
+
/** Caller-supplied number of supply shares burned. */
|
|
292
292
|
readonly shares: bigint;
|
|
293
293
|
/** BlueBuyCallback whose supply position is withdrawn. */
|
|
294
294
|
readonly onBehalf: Address;
|
|
@@ -449,6 +449,13 @@ export interface MidnightSupplyCollateralAction extends BaseAction<"midnightSupp
|
|
|
449
449
|
readonly onBehalf: Address;
|
|
450
450
|
}> {
|
|
451
451
|
}
|
|
452
|
+
/** Metadata for an atomic direct Midnight collateral supply batch. */
|
|
453
|
+
export interface MidnightSupplyCollateralBatchAction extends BaseAction<"midnightSupplyCollateralBatch", {
|
|
454
|
+
readonly market: Hex;
|
|
455
|
+
readonly collateralSupplies: readonly MidnightCollateralTransfer[];
|
|
456
|
+
readonly onBehalf: Address;
|
|
457
|
+
}> {
|
|
458
|
+
}
|
|
452
459
|
/** Metadata for a direct Midnight collateral withdrawal transaction. */
|
|
453
460
|
export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWithdrawCollateral", {
|
|
454
461
|
readonly market: Hex;
|
|
@@ -458,6 +465,14 @@ export interface MidnightWithdrawCollateralAction extends BaseAction<"midnightWi
|
|
|
458
465
|
readonly receiver: Address;
|
|
459
466
|
}> {
|
|
460
467
|
}
|
|
468
|
+
/** Metadata for an atomic direct Midnight collateral withdrawal batch. */
|
|
469
|
+
export interface MidnightWithdrawCollateralBatchAction extends BaseAction<"midnightWithdrawCollateralBatch", {
|
|
470
|
+
readonly market: Hex;
|
|
471
|
+
readonly collateralWithdrawals: readonly MidnightCollateralTransfer[];
|
|
472
|
+
readonly onBehalf: Address;
|
|
473
|
+
readonly receiver: Address;
|
|
474
|
+
}> {
|
|
475
|
+
}
|
|
461
476
|
/** Metadata for a direct Midnight credit redemption transaction. */
|
|
462
477
|
export interface MidnightRedeemAction extends BaseAction<"midnightRedeem", {
|
|
463
478
|
readonly market: Hex;
|
|
@@ -524,7 +539,7 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
524
539
|
* VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
|
|
525
540
|
* consumers can `switch` exhaustively on it.
|
|
526
541
|
*/
|
|
527
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightWithdrawCollateralAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
542
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
528
543
|
/**
|
|
529
544
|
* Describes a single, immutable, deep-frozen transaction to submit on-chain:
|
|
530
545
|
* the target `to`, native `value`, encoded call `data`, and the originating
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -922,9 +922,22 @@ export declare class RepayExceedsDebtError extends Error {
|
|
|
922
922
|
market: string;
|
|
923
923
|
});
|
|
924
924
|
}
|
|
925
|
-
/** Thrown when EIP-712 signature verification fails
|
|
925
|
+
/** Thrown when EIP-712 signature verification fails to recover the expected signer. */
|
|
926
926
|
export declare class InvalidSignatureError extends Error {
|
|
927
|
-
constructor();
|
|
927
|
+
constructor(options?: ErrorOptions);
|
|
928
|
+
}
|
|
929
|
+
/** Thrown when signature recovery fails, with redacted diagnostics and the original error as `cause`. */
|
|
930
|
+
export declare class MalformedSignatureError extends InvalidSignatureError {
|
|
931
|
+
/** JavaScript type returned by the wallet, without the signature value. */
|
|
932
|
+
readonly signatureType: string;
|
|
933
|
+
/** Whether the returned value is an even-length hex string. */
|
|
934
|
+
readonly signatureIsHex: boolean;
|
|
935
|
+
/** Signature byte length, when it is an even-length hex string. */
|
|
936
|
+
readonly signatureByteLength: number | undefined;
|
|
937
|
+
constructor(params: {
|
|
938
|
+
readonly signature: unknown;
|
|
939
|
+
readonly cause: unknown;
|
|
940
|
+
});
|
|
928
941
|
}
|
|
929
942
|
/** Thrown when a repay in shares mode supplies more shares than the borrower owes. */
|
|
930
943
|
export declare class RepaySharesExceedDebtError extends Error {
|
|
@@ -1056,6 +1069,14 @@ export declare class EmptyMidnightGroupCancellationsError extends Error {
|
|
|
1056
1069
|
export declare class EmptyMidnightCollateralSuppliesError extends Error {
|
|
1057
1070
|
constructor();
|
|
1058
1071
|
}
|
|
1072
|
+
/** Thrown when a direct Midnight collateral withdrawal batch is empty. */
|
|
1073
|
+
export declare class EmptyMidnightCollateralWithdrawalsError extends Error {
|
|
1074
|
+
constructor();
|
|
1075
|
+
}
|
|
1076
|
+
/** Thrown when a direct Midnight collateral batch repeats an index. */
|
|
1077
|
+
export declare class DuplicateMidnightCollateralIndexError extends Error {
|
|
1078
|
+
constructor(collateralIndex: bigint);
|
|
1079
|
+
}
|
|
1059
1080
|
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1060
1081
|
export declare class DuplicateMidnightGroupCancellationError extends Error {
|
|
1061
1082
|
constructor(params: {
|