@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,74 @@
|
|
|
1
|
+
import { erc20Abi } from "viem";
|
|
2
|
+
import { readContract } from "viem/actions";
|
|
3
|
+
import { getRequirementsApproval } from "../actions/requirements/getRequirementsApproval.js";
|
|
4
|
+
import { UnexpectedRequirementSignatureError } from "../types/error.js";
|
|
5
|
+
import { getTokenPermit } from "./getTokenPermit.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal Converts an ERC-2612 requirement into a plan-local signature request.
|
|
8
|
+
* @param requirement - Permit requirement carrying its typed data and encoding arguments.
|
|
9
|
+
* @param id - Signature request ID selected by the preparer.
|
|
10
|
+
* @returns The unsigned request with a concrete nonce.
|
|
11
|
+
* @throws {UnexpectedRequirementSignatureError} If the permit requirement has no nonce.
|
|
12
|
+
*/
|
|
13
|
+
export function buildPermitSignatureRequest(requirement, id) {
|
|
14
|
+
const { nonce, ...args } = requirement.action.args;
|
|
15
|
+
if (nonce === undefined)
|
|
16
|
+
throw new UnexpectedRequirementSignatureError(requirement.action.type);
|
|
17
|
+
return {
|
|
18
|
+
id,
|
|
19
|
+
kind: "permit",
|
|
20
|
+
typedData: requirement.action.typedData,
|
|
21
|
+
args: { ...args, nonce },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @internal Converts an approval transaction into a step with prepared chain/account inputs.
|
|
26
|
+
* @param requirement - Direct token approval prerequisite.
|
|
27
|
+
* @param params - Step ID, chain and account selected by the preparer.
|
|
28
|
+
* @returns The approval recipe labeled for token spending.
|
|
29
|
+
*/
|
|
30
|
+
export function buildApprovalStep(requirement, { id, chainId, account, }) {
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
label: "Approve token spending",
|
|
34
|
+
action: {
|
|
35
|
+
type: "erc20Approval",
|
|
36
|
+
inputs: {
|
|
37
|
+
token: requirement.to,
|
|
38
|
+
...requirement.action.args,
|
|
39
|
+
chainId,
|
|
40
|
+
account,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @internal Resolves the token prerequisite of a VaultBundlesV1 pull without Permit2. A sufficient
|
|
47
|
+
* direct allowance yields nothing. Otherwise signature support prefers an ERC-2612 permit when
|
|
48
|
+
* available and falls back to a direct unlimited approval. Without signature support, always approve.
|
|
49
|
+
*/
|
|
50
|
+
export async function getTokenRequirements(client, params) {
|
|
51
|
+
// The allowance is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
|
|
52
|
+
const allowance = await readContract(client, {
|
|
53
|
+
abi: erc20Abi,
|
|
54
|
+
address: params.token,
|
|
55
|
+
functionName: "allowance",
|
|
56
|
+
args: [params.owner, params.spender],
|
|
57
|
+
});
|
|
58
|
+
if (allowance >= params.amount)
|
|
59
|
+
return [];
|
|
60
|
+
if (params.supportSignature) {
|
|
61
|
+
const permit = await getTokenPermit(client, {
|
|
62
|
+
...params,
|
|
63
|
+
supportDeployless: params.deployless,
|
|
64
|
+
});
|
|
65
|
+
if (permit !== undefined)
|
|
66
|
+
return [permit];
|
|
67
|
+
}
|
|
68
|
+
return getRequirementsApproval({
|
|
69
|
+
address: params.token,
|
|
70
|
+
chainId: params.chainId,
|
|
71
|
+
args: { spendAmount: params.amount, spender: params.spender },
|
|
72
|
+
allowances: allowance,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TransactionPlan } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Serializes plan data with a bigint replacer. No validation is performed.
|
|
4
|
+
* @param plan - Plan to save.
|
|
5
|
+
* @returns JSON with `$bigint` tags for bigint quantities.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { serializeTransactionPlan, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
9
|
+
* const save = (plan: TransactionPlan) => serializeTransactionPlan(plan);
|
|
10
|
+
* ```
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
12
|
+
*/
|
|
13
|
+
export declare function serializeTransactionPlan(plan: TransactionPlan): string;
|
|
14
|
+
/**
|
|
15
|
+
* Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
|
|
16
|
+
* references, per-action chain/account and permit/action consistency, including signed requests.
|
|
17
|
+
* Extra keys are allowed. No clock or RPC is used: expiry, live state, signature ownership and
|
|
18
|
+
* action-layer business constraints are not checked. Parsing does not prove authenticity or intent;
|
|
19
|
+
* tampered but well-formed, internally consistent plans pass. Integrators must protect stored plans.
|
|
20
|
+
* Use `applySignatures` to verify new signatures; existing restored signatures remain trusted.
|
|
21
|
+
* @param json - JSON previously returned by `serializeTransactionPlan`.
|
|
22
|
+
* @returns The restored plan.
|
|
23
|
+
* @throws {InvalidTransactionPlanError} At the first malformed JSON, field shape or consistency failure, exposing its JSON `path` and `reason`.
|
|
24
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the stored integer version is unsupported.
|
|
25
|
+
* @throws {UnsupportedTransactionPlanActionError} If a step names an unsupported action type.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { parseTransactionPlan } from "@morpho-org/morpho-sdk";
|
|
29
|
+
* const restore = (saved: string) => parseTransactionPlan(saved);
|
|
30
|
+
* ```
|
|
31
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseTransactionPlan(json: string): TransactionPlan;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { isAddressEqual } from "viem";
|
|
2
|
+
import { validateApprovalPlanAction } from "./approval.js";
|
|
3
|
+
import { InvalidTransactionPlanError, TransactionPlanSignatureMismatchError, } from "./error.js";
|
|
4
|
+
import { validatePermitPlanRequest } from "./permit.js";
|
|
5
|
+
import { getPendingSignatureRequests } from "./plan.js";
|
|
6
|
+
import { validateTransactionPlanActions } from "./validateActions.js";
|
|
7
|
+
import { getPlanObject, validatePlanField, validatePlanFields, } from "./validation.js";
|
|
8
|
+
import { validateDepositPlanAction } from "./vaultv2/deposit.js";
|
|
9
|
+
import { validateWithdrawPlanAction } from "./vaultv2/withdraw.js";
|
|
10
|
+
import { validateTransactionPlanVersion } from "./version.js";
|
|
11
|
+
const actionValidators = {
|
|
12
|
+
erc20Approval: validateApprovalPlanAction,
|
|
13
|
+
vaultV2Deposit: validateDepositPlanAction,
|
|
14
|
+
vaultV2Withdraw: validateWithdrawPlanAction,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Serializes plan data with a bigint replacer. No validation is performed.
|
|
18
|
+
* @param plan - Plan to save.
|
|
19
|
+
* @returns JSON with `$bigint` tags for bigint quantities.
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { serializeTransactionPlan, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
23
|
+
* const save = (plan: TransactionPlan) => serializeTransactionPlan(plan);
|
|
24
|
+
* ```
|
|
25
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
26
|
+
*/
|
|
27
|
+
export function serializeTransactionPlan(plan) {
|
|
28
|
+
return JSON.stringify(plan, function (key) {
|
|
29
|
+
// Read the original value even when the host has installed BigInt.prototype.toJSON.
|
|
30
|
+
const value = this[key];
|
|
31
|
+
return typeof value === "bigint" ? { $bigint: value.toString() } : value;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Restores bigint fields and validates version, action/request shapes, uint256 ranges, unique IDs,
|
|
36
|
+
* references, per-action chain/account and permit/action consistency, including signed requests.
|
|
37
|
+
* Extra keys are allowed. No clock or RPC is used: expiry, live state, signature ownership and
|
|
38
|
+
* action-layer business constraints are not checked. Parsing does not prove authenticity or intent;
|
|
39
|
+
* tampered but well-formed, internally consistent plans pass. Integrators must protect stored plans.
|
|
40
|
+
* Use `applySignatures` to verify new signatures; existing restored signatures remain trusted.
|
|
41
|
+
* @param json - JSON previously returned by `serializeTransactionPlan`.
|
|
42
|
+
* @returns The restored plan.
|
|
43
|
+
* @throws {InvalidTransactionPlanError} At the first malformed JSON, field shape or consistency failure, exposing its JSON `path` and `reason`.
|
|
44
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the stored integer version is unsupported.
|
|
45
|
+
* @throws {UnsupportedTransactionPlanActionError} If a step names an unsupported action type.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { parseTransactionPlan } from "@morpho-org/morpho-sdk";
|
|
49
|
+
* const restore = (saved: string) => parseTransactionPlan(saved);
|
|
50
|
+
* ```
|
|
51
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
52
|
+
*/
|
|
53
|
+
export function parseTransactionPlan(json) {
|
|
54
|
+
let restored;
|
|
55
|
+
try {
|
|
56
|
+
restored = JSON.parse(json, (_key, field) => typeof field === "object" &&
|
|
57
|
+
field !== null &&
|
|
58
|
+
"$bigint" in field &&
|
|
59
|
+
typeof field.$bigint === "string"
|
|
60
|
+
? BigInt(field.$bigint)
|
|
61
|
+
: field);
|
|
62
|
+
}
|
|
63
|
+
catch (cause) {
|
|
64
|
+
throw new InvalidTransactionPlanError({
|
|
65
|
+
path: "$",
|
|
66
|
+
reason: "expected JSON with valid bigint tags",
|
|
67
|
+
cause,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const plan = getPlanObject(restored, "$");
|
|
71
|
+
validatePlanField(plan.version, { path: "$.version", type: "safe integer" });
|
|
72
|
+
validateTransactionPlanVersion(plan.version);
|
|
73
|
+
validatePlanFields(plan, {
|
|
74
|
+
path: "$",
|
|
75
|
+
fields: {
|
|
76
|
+
chainId: "positive safe integer",
|
|
77
|
+
account: "address",
|
|
78
|
+
expiresAt: "safe integer",
|
|
79
|
+
steps: "array",
|
|
80
|
+
signatureRequests: "array",
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
if (plan.calldataOrigin !== undefined)
|
|
84
|
+
validatePlanField(plan.calldataOrigin, {
|
|
85
|
+
path: "$.calldataOrigin",
|
|
86
|
+
type: "hex",
|
|
87
|
+
});
|
|
88
|
+
const steps = plan.steps;
|
|
89
|
+
const requests = plan.signatureRequests;
|
|
90
|
+
const stepIds = new Set();
|
|
91
|
+
for (const [index, value] of steps.entries()) {
|
|
92
|
+
const path = `$.steps[${index}]`;
|
|
93
|
+
const step = getPlanObject(value, path);
|
|
94
|
+
validatePlanFields(step, {
|
|
95
|
+
path,
|
|
96
|
+
fields: { id: "string", label: "string" },
|
|
97
|
+
});
|
|
98
|
+
if (stepIds.has(step.id))
|
|
99
|
+
throw new InvalidTransactionPlanError({
|
|
100
|
+
path: `${path}.id`,
|
|
101
|
+
reason: "expected a unique step ID",
|
|
102
|
+
});
|
|
103
|
+
stepIds.add(step.id);
|
|
104
|
+
const action = getPlanObject(step.action, `${path}.action`);
|
|
105
|
+
validatePlanField(action.type, {
|
|
106
|
+
path: `${path}.action.type`,
|
|
107
|
+
type: "string",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Preserve the existing action-type guard before dispatching action schemas.
|
|
111
|
+
validateTransactionPlanActions(steps);
|
|
112
|
+
for (const [index, step] of steps.entries()) {
|
|
113
|
+
const path = `$.steps[${index}].action`;
|
|
114
|
+
const action = getPlanObject(step.action, path);
|
|
115
|
+
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
116
|
+
validatePlanFields(inputs, {
|
|
117
|
+
path: `${path}.inputs`,
|
|
118
|
+
fields: { chainId: "positive safe integer", account: "address" },
|
|
119
|
+
});
|
|
120
|
+
actionValidators[step.action.type](action, path);
|
|
121
|
+
if (inputs.chainId !== plan.chainId)
|
|
122
|
+
throw new InvalidTransactionPlanError({
|
|
123
|
+
path: `${path}.inputs.chainId`,
|
|
124
|
+
reason: "expected the plan chainId",
|
|
125
|
+
});
|
|
126
|
+
if (!isAddressEqual(inputs.account, plan.account))
|
|
127
|
+
throw new InvalidTransactionPlanError({
|
|
128
|
+
path: `${path}.inputs.account`,
|
|
129
|
+
reason: "expected the plan account",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const requestIds = new Set();
|
|
133
|
+
for (const [index, value] of requests.entries()) {
|
|
134
|
+
const path = `$.signatureRequests[${index}]`;
|
|
135
|
+
const request = getPlanObject(value, path);
|
|
136
|
+
validatePlanFields(request, {
|
|
137
|
+
path,
|
|
138
|
+
fields: { id: "string", kind: "string" },
|
|
139
|
+
});
|
|
140
|
+
if (requestIds.has(request.id))
|
|
141
|
+
throw new InvalidTransactionPlanError({
|
|
142
|
+
path: `${path}.id`,
|
|
143
|
+
reason: "expected a unique signature request ID",
|
|
144
|
+
});
|
|
145
|
+
requestIds.add(request.id);
|
|
146
|
+
if (request.kind !== "permit")
|
|
147
|
+
throw new InvalidTransactionPlanError({
|
|
148
|
+
path: `${path}.kind`,
|
|
149
|
+
reason: "expected a supported signature request kind (permit)",
|
|
150
|
+
});
|
|
151
|
+
validatePermitPlanRequest(request, path);
|
|
152
|
+
}
|
|
153
|
+
for (const [index, step] of steps.entries()) {
|
|
154
|
+
if (!("signatureRequestIds" in step.action))
|
|
155
|
+
continue;
|
|
156
|
+
const path = `$.steps[${index}].action.signatureRequestIds`;
|
|
157
|
+
const ids = getPlanObject(step.action.signatureRequestIds, path);
|
|
158
|
+
for (const [role, id] of Object.entries(ids)) {
|
|
159
|
+
validatePlanField(id, { path: `${path}.${role}`, type: "string" });
|
|
160
|
+
if (!requestIds.has(id))
|
|
161
|
+
throw new InvalidTransactionPlanError({
|
|
162
|
+
path: `${path}.${role}`,
|
|
163
|
+
reason: "expected an existing signature request ID",
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const result = restored;
|
|
168
|
+
try {
|
|
169
|
+
// Clear signatures so the existing pure consistency check validates every request.
|
|
170
|
+
getPendingSignatureRequests({
|
|
171
|
+
...result,
|
|
172
|
+
signatureRequests: result.signatureRequests.map((request) => ({
|
|
173
|
+
...request,
|
|
174
|
+
signature: undefined,
|
|
175
|
+
})),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (cause) {
|
|
179
|
+
if (cause instanceof TransactionPlanSignatureMismatchError) {
|
|
180
|
+
const index = result.signatureRequests.findIndex((request) => request.id === cause.id);
|
|
181
|
+
const field = cause.field === "reference"
|
|
182
|
+
? "id"
|
|
183
|
+
: cause.field === "value"
|
|
184
|
+
? "args.amount"
|
|
185
|
+
: cause.field.startsWith("args.")
|
|
186
|
+
? cause.field
|
|
187
|
+
: `typedData.${cause.field}`;
|
|
188
|
+
throw new InvalidTransactionPlanError({
|
|
189
|
+
path: `$.signatureRequests[${index}].${field}`,
|
|
190
|
+
reason: "expected agreement with every referencing action",
|
|
191
|
+
cause,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
throw new InvalidTransactionPlanError({
|
|
195
|
+
path: "$.signatureRequests",
|
|
196
|
+
reason: "expected requests consistent with supported action chains",
|
|
197
|
+
cause,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { BundlesFundingArgs, PermitAction, RequirementTypedData } from "../types/index.js";
|
|
3
|
+
interface ActionInputs {
|
|
4
|
+
readonly chainId: number;
|
|
5
|
+
readonly account: Address;
|
|
6
|
+
}
|
|
7
|
+
interface VaultInputs extends ActionInputs {
|
|
8
|
+
readonly vault: Address;
|
|
9
|
+
readonly deadline: bigint;
|
|
10
|
+
readonly referralFeePct: bigint;
|
|
11
|
+
readonly referralFeeRecipient: Address;
|
|
12
|
+
}
|
|
13
|
+
/** Signature request roles a vault action selects by plan-local ID. */
|
|
14
|
+
type VaultSignatureRequestIds = {
|
|
15
|
+
/** Token permit consumed by the action; omitted when no permit is needed. */
|
|
16
|
+
readonly tokenPermit?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Recipes supported by Vault V2 plans. Each `type` equals the `action.type` of the
|
|
20
|
+
* {@link TransactionAction} it builds.
|
|
21
|
+
* Snapshot-derived values such as the asset and the quote are fixed on `inputs` at preparation;
|
|
22
|
+
* each action also carries its own chain and account on `inputs`.
|
|
23
|
+
* the role map `signatureRequestIds` is a step's only request reference.
|
|
24
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
25
|
+
*/
|
|
26
|
+
export type Action = {
|
|
27
|
+
readonly type: "erc20Approval";
|
|
28
|
+
readonly inputs: ActionInputs & {
|
|
29
|
+
readonly token: Address;
|
|
30
|
+
readonly spender: Address;
|
|
31
|
+
readonly amount: bigint;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
readonly type: "vaultV2Deposit";
|
|
35
|
+
readonly inputs: VaultInputs & BundlesFundingArgs & {
|
|
36
|
+
/** Vault asset read from the snapshot. */
|
|
37
|
+
readonly asset: Address;
|
|
38
|
+
/** Deadline-accrued RAY-scaled bound quoted from the snapshot for the net deposit. */
|
|
39
|
+
readonly maxSharePrice: bigint;
|
|
40
|
+
};
|
|
41
|
+
readonly signatureRequestIds: VaultSignatureRequestIds;
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "vaultV2Withdraw";
|
|
44
|
+
readonly inputs: VaultInputs & {
|
|
45
|
+
readonly amount: bigint;
|
|
46
|
+
/** Minimum share allowance quoted from the snapshot for the gross withdrawal. */
|
|
47
|
+
readonly requiredShareAllowance: bigint;
|
|
48
|
+
};
|
|
49
|
+
readonly signatureRequestIds: VaultSignatureRequestIds;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A recipe with a plan-unique `id`; its request dependencies are the roles its action names.
|
|
53
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
54
|
+
*/
|
|
55
|
+
export interface Step<TAction extends Action = Action> {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly label: string;
|
|
58
|
+
readonly action: TAction;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* ERC-2612 permit request exposed as `{ id, kind, typedData }`. `signature` is undefined until the
|
|
62
|
+
* account signs `typedData`. Protocol milestones add further `kind`s such as Blue authorization.
|
|
63
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
64
|
+
*/
|
|
65
|
+
export interface SignatureRequest {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly kind: "permit";
|
|
68
|
+
readonly typedData: RequirementTypedData;
|
|
69
|
+
readonly args: PermitAction["args"] & {
|
|
70
|
+
readonly nonce: bigint;
|
|
71
|
+
};
|
|
72
|
+
readonly signature?: Hex;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Data-only operation prepared for one chain and account from the caller's intent and a vault
|
|
76
|
+
* snapshot. Every step and signature request carries its own `id`, unique within the plan. Once
|
|
77
|
+
* prepared, a plan is static: only signatures are added before building.
|
|
78
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
79
|
+
*/
|
|
80
|
+
export interface TransactionPlan {
|
|
81
|
+
readonly version: 1;
|
|
82
|
+
readonly chainId: number;
|
|
83
|
+
readonly account: Address;
|
|
84
|
+
/** Unix seconds. One expiry governs every step deadline and signature deadline. */
|
|
85
|
+
readonly expiresAt: number;
|
|
86
|
+
/** Appended verbatim to every built transaction's calldata. */
|
|
87
|
+
readonly calldataOrigin?: Hex;
|
|
88
|
+
readonly steps: readonly Step[];
|
|
89
|
+
readonly signatureRequests: readonly SignatureRequest[];
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Step } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal Rejects unknown action types before interpreting requests or updates.
|
|
4
|
+
* @param steps - Steps whose action discriminators must be supported.
|
|
5
|
+
* @returns Nothing when every action type is supported.
|
|
6
|
+
* @throws {UnsupportedTransactionPlanActionError} when any step names an unsupported action type.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateTransactionPlanActions(steps: readonly Step[]): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UnsupportedTransactionPlanActionError } from "./error.js";
|
|
2
|
+
/**
|
|
3
|
+
* @internal Rejects unknown action types before interpreting requests or updates.
|
|
4
|
+
* @param steps - Steps whose action discriminators must be supported.
|
|
5
|
+
* @returns Nothing when every action type is supported.
|
|
6
|
+
* @throws {UnsupportedTransactionPlanActionError} when any step names an unsupported action type.
|
|
7
|
+
*/
|
|
8
|
+
export function validateTransactionPlanActions(steps) {
|
|
9
|
+
for (const step of steps) {
|
|
10
|
+
const actionType = step.action.type;
|
|
11
|
+
if (actionType !== "erc20Approval" &&
|
|
12
|
+
actionType !== "vaultV2Deposit" &&
|
|
13
|
+
actionType !== "vaultV2Withdraw")
|
|
14
|
+
throw new UnsupportedTransactionPlanActionError(actionType);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @internal Scalar and collection shapes used by stored plan fields. */
|
|
2
|
+
type PlanFieldType = "string" | "address" | "hex" | "safe integer" | "positive safe integer" | "uint256 bigint" | "array";
|
|
3
|
+
/** @internal Validates one restored field without coercing it. */
|
|
4
|
+
export declare function validatePlanField(value: unknown, options: {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly type: PlanFieldType;
|
|
7
|
+
}): void;
|
|
8
|
+
/** @internal Requires a non-null, non-array JSON object. */
|
|
9
|
+
export declare function getPlanObject(value: unknown, path: string): Record<string, unknown>;
|
|
10
|
+
/** @internal Validates required fields while permitting additional keys. */
|
|
11
|
+
export declare function validatePlanFields(value: Record<string, unknown>, options: {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly fields: Readonly<Record<string, PlanFieldType>>;
|
|
14
|
+
}): void;
|
|
15
|
+
/** @internal Validates the shared stored vault-action fields and role map. */
|
|
16
|
+
export declare function validateVaultPlanAction(action: Record<string, unknown>, path: string): Record<string, unknown>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isAddress, maxUint256 } from "viem";
|
|
2
|
+
import { InvalidTransactionPlanError } from "./error.js";
|
|
3
|
+
/** @internal Validates one restored field without coercing it. */
|
|
4
|
+
export function validatePlanField(value, options) {
|
|
5
|
+
const { path, type } = options;
|
|
6
|
+
let valid;
|
|
7
|
+
switch (type) {
|
|
8
|
+
case "string":
|
|
9
|
+
valid = typeof value === "string";
|
|
10
|
+
break;
|
|
11
|
+
case "address":
|
|
12
|
+
valid = typeof value === "string" && isAddress(value);
|
|
13
|
+
break;
|
|
14
|
+
case "hex":
|
|
15
|
+
valid =
|
|
16
|
+
typeof value === "string" && /^0x(?:[0-9a-fA-F]{2})*$/.test(value);
|
|
17
|
+
break;
|
|
18
|
+
case "safe integer":
|
|
19
|
+
valid = typeof value === "number" && Number.isSafeInteger(value);
|
|
20
|
+
break;
|
|
21
|
+
case "positive safe integer":
|
|
22
|
+
valid =
|
|
23
|
+
typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
24
|
+
break;
|
|
25
|
+
case "uint256 bigint":
|
|
26
|
+
valid = typeof value === "bigint" && value >= 0n && value <= maxUint256;
|
|
27
|
+
break;
|
|
28
|
+
case "array":
|
|
29
|
+
valid = Array.isArray(value);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
if (!valid)
|
|
33
|
+
throw new InvalidTransactionPlanError({ path, reason: `expected ${type}` });
|
|
34
|
+
}
|
|
35
|
+
/** @internal Requires a non-null, non-array JSON object. */
|
|
36
|
+
export function getPlanObject(value, path) {
|
|
37
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
38
|
+
throw new InvalidTransactionPlanError({
|
|
39
|
+
path,
|
|
40
|
+
reason: "expected an object",
|
|
41
|
+
});
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
/** @internal Validates required fields while permitting additional keys. */
|
|
45
|
+
export function validatePlanFields(value, options) {
|
|
46
|
+
for (const [key, type] of Object.entries(options.fields))
|
|
47
|
+
validatePlanField(value[key], { path: `${options.path}.${key}`, type });
|
|
48
|
+
}
|
|
49
|
+
/** @internal Validates the shared stored vault-action fields and role map. */
|
|
50
|
+
export function validateVaultPlanAction(action, path) {
|
|
51
|
+
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
52
|
+
validatePlanFields(inputs, {
|
|
53
|
+
path: `${path}.inputs`,
|
|
54
|
+
fields: {
|
|
55
|
+
vault: "address",
|
|
56
|
+
deadline: "uint256 bigint",
|
|
57
|
+
referralFeePct: "uint256 bigint",
|
|
58
|
+
referralFeeRecipient: "address",
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
// Vault actions require a role map even when no permit is needed.
|
|
62
|
+
getPlanObject(action.signatureRequestIds, `${path}.signatureRequestIds`);
|
|
63
|
+
return inputs;
|
|
64
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address, type Client } from "viem";
|
|
3
|
+
import { type Transaction, type VaultV2DepositAction } from "../../types/index.js";
|
|
4
|
+
import { type Funding, type IntentParams } from "../intent.js";
|
|
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
|
+
/**
|
|
9
|
+
* Caller intent for a Vault V2 deposit, mirroring the Actions API deposit inputs, plus the snapshot.
|
|
10
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
11
|
+
*/
|
|
12
|
+
export interface VaultV2DepositPlanParams extends IntentParams {
|
|
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;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Prepares a deposit plan from caller intent and a vault snapshot, reading the token prerequisites
|
|
29
|
+
* directly. The quote is fixed on the deposit step at preparation, so the returned plan is static:
|
|
30
|
+
* only signatures are added before building.
|
|
31
|
+
* @param client - Viem client for `params.chainId`, used for allowance and permit metadata reads only.
|
|
32
|
+
* @param params.vault - Vault V2 contract receiving the net deposit.
|
|
33
|
+
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the asset and deadline-accrued share-price bound.
|
|
34
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
35
|
+
* @param params.account - Non-zero account funding, signing and sending the deposit.
|
|
36
|
+
* @param params.amount - Positive gross deposit in asset base units, before referral fees.
|
|
37
|
+
* @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 amount; defaults to zero and must be below 10,000.
|
|
39
|
+
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
40
|
+
* @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
|
+
* @param params.supportSignature - Optional ERC-2612 preference, defaulting to `false`; when enabled, falls back to direct approval if no permit is available.
|
|
42
|
+
* @param params.expiresAt - Optional future Unix timestamp in seconds as a safe integer; defaults to two hours from preparation.
|
|
43
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
44
|
+
* @param params.deployless - Optional permission to use deployless aggregation for token permit metadata reads.
|
|
45
|
+
* @returns A plan with approvals, concrete signature requests and the deposit step.
|
|
46
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
47
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
48
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `amount`, net assets or previewed shares are not positive.
|
|
49
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
50
|
+
* @throws {NegativeInputError} when `referralFee.bps` or `slippageTolerance` is negative.
|
|
51
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `amount` exceeds uint256.
|
|
52
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds `MAX_SLIPPAGE_TOLERANCE`.
|
|
53
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
54
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
55
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
56
|
+
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
57
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a vault whose asset is not wNative.
|
|
58
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
59
|
+
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
60
|
+
* @see computeVaultMaxSharePrice for quote errors.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { prepareVaultV2Deposit } from "@morpho-org/morpho-sdk";
|
|
64
|
+
* import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
65
|
+
* import { createPublicClient, http } from "viem";
|
|
66
|
+
* import { mainnet } from "viem/chains";
|
|
67
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
68
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
69
|
+
* const plan = await prepareVaultV2Deposit(client, {
|
|
70
|
+
* vault, chainId: 1, account: "0x0000000000000000000000000000000000000001", amount: 1_000_000n, supportSignature: true,
|
|
71
|
+
* vaultData: await fetchAccrualVaultV2(vault, client),
|
|
72
|
+
* });
|
|
73
|
+
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
74
|
+
* ```
|
|
75
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
76
|
+
*/
|
|
77
|
+
export declare function prepareVaultV2Deposit(client: Client, params: VaultV2DepositPlanParams): Promise<TransactionPlan>;
|
|
78
|
+
/** @internal Encodes the deposit from its self-contained inputs and resolved signature requests. */
|
|
79
|
+
export declare function buildVaultV2Deposit(action: Extract<Action, {
|
|
80
|
+
type: "vaultV2Deposit";
|
|
81
|
+
}>, requests: readonly SignatureRequest[]): Readonly<Transaction<VaultV2DepositAction>>;
|