@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,99 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
import type { Transaction } from "../types/index.js";
|
|
3
|
+
import type { SignatureRequest, Step, TransactionPlan } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
|
|
6
|
+
* and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
|
|
7
|
+
* binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
|
|
8
|
+
* Contract wallets should use `supportSignature: false` for direct approvals: deployed bundles
|
|
9
|
+
* consume ECDSA `v/r/s`, not arbitrary ERC-1271 or ERC-6492 signatures.
|
|
10
|
+
* Stored inputs remain trusted; verification does not establish the integrator's intent or protect
|
|
11
|
+
* a plan changed afterwards. Builders do not reverify signatures in restored plans.
|
|
12
|
+
* @param plan - Plan to update without mutating its requests or steps.
|
|
13
|
+
* @param signatures - Compact or serialized ECDSA signatures, each naming a unique existing request ID.
|
|
14
|
+
* @returns A new plan sharing steps and unpatched requests; omitted IDs are preserved. Empty input validates all requests and returns the original plan.
|
|
15
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including when no signatures are supplied.
|
|
16
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests or updates.
|
|
17
|
+
* @throws {TransactionPlanSignatureMismatchError} If a request disagrees with its actions, an ID is unknown, or an input ID is duplicated (`field: "duplicate"`).
|
|
18
|
+
* @throws {BundlesPermitMismatchError} If a supplied signature cannot be parsed by the bundle permit builders.
|
|
19
|
+
* @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the permit owner and typed data.
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { applySignatures, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
23
|
+
* import type { Hex } from "viem";
|
|
24
|
+
* const complete = (plan: TransactionPlan, signature: Hex) =>
|
|
25
|
+
* applySignatures(plan, [{ id: "vaultV2Deposit:tokenPermit", signature }]);
|
|
26
|
+
* ```
|
|
27
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applySignatures(plan: TransactionPlan, signatures: readonly {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly signature: Hex;
|
|
32
|
+
}[]): TransactionPlan;
|
|
33
|
+
/**
|
|
34
|
+
* Lists pending signature requests once per request ID after checking each against every referencing action.
|
|
35
|
+
* Sign each request's typed data with your wallet stack, then verify and attach the results with
|
|
36
|
+
* {@link applySignatures}.
|
|
37
|
+
* @param plan - Plan to inspect without changing it.
|
|
38
|
+
* @returns Pending requests in first-reference order, each carrying its `id`, `kind` and validated `typedData`. Dangling IDs are omitted. The SDK never signs.
|
|
39
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
|
|
40
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
|
|
41
|
+
* @throws {TransactionPlanSignatureMismatchError} If a pending permit disagrees with its action or arguments, including the action deadline, or any request has no referencing step.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { getPendingSignatureRequests, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
45
|
+
* const prompts = (plan: TransactionPlan) =>
|
|
46
|
+
* getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
|
|
47
|
+
* ```
|
|
48
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getPendingSignatureRequests(plan: TransactionPlan): readonly SignatureRequest[];
|
|
51
|
+
/**
|
|
52
|
+
* Builds one transaction from a step, its fixed inputs and the signatures its action names.
|
|
53
|
+
* Plans are trusted as given, whether restored or supplied directly. Signature checks establish
|
|
54
|
+
* only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
|
|
55
|
+
* vaults or amounts against the intended operation. Integrators must protect stored plans from tampering.
|
|
56
|
+
* This builder does not verify signature ownership; use {@link applySignatures} to verify and attach signatures.
|
|
57
|
+
* @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
|
|
58
|
+
* @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
|
|
59
|
+
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
|
|
60
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
|
|
61
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
|
|
62
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
|
|
63
|
+
* @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
|
|
64
|
+
* @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
|
|
65
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
|
|
66
|
+
* @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
|
|
67
|
+
* @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
|
|
71
|
+
* const resume = (saved: string) => {
|
|
72
|
+
* const plan = parseTransactionPlan(saved);
|
|
73
|
+
* return plan.steps.map((step) => buildTransaction(plan, step));
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildTransaction(plan: TransactionPlan, step: Step): Readonly<Transaction>;
|
|
79
|
+
/**
|
|
80
|
+
* Builds every step of the plan in order.
|
|
81
|
+
* @param plan - Plan whose referenced signature requests all carry a signature.
|
|
82
|
+
* @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
|
|
83
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
|
|
84
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
|
|
85
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
|
|
86
|
+
* @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
|
|
87
|
+
* @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
|
|
88
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
|
|
89
|
+
* @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
|
|
90
|
+
* @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
94
|
+
* const submit = (plan: TransactionPlan) => buildTransactions(plan);
|
|
95
|
+
* // Simulate and send in order from plan.account on plan.chainId.
|
|
96
|
+
* ```
|
|
97
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
98
|
+
*/
|
|
99
|
+
export declare function buildTransactions(plan: TransactionPlan): readonly Readonly<Transaction>[];
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySignatures = applySignatures;
|
|
4
|
+
exports.getPendingSignatureRequests = getPendingSignatureRequests;
|
|
5
|
+
exports.buildTransaction = buildTransaction;
|
|
6
|
+
exports.buildTransactions = buildTransactions;
|
|
7
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
9
|
+
const viem_1 = require("viem");
|
|
10
|
+
const accounts_1 = require("viem/accounts");
|
|
11
|
+
const common_js_1 = require("../actions/bundles/common.js");
|
|
12
|
+
const index_js_1 = require("../actions/index.js");
|
|
13
|
+
const error_js_1 = require("../types/error.js");
|
|
14
|
+
const error_js_2 = require("./error.js");
|
|
15
|
+
const permit_js_1 = require("./permit.js");
|
|
16
|
+
const validateActions_js_1 = require("./validateActions.js");
|
|
17
|
+
const deposit_js_1 = require("./vaultv2/deposit.js");
|
|
18
|
+
const withdraw_js_1 = require("./vaultv2/withdraw.js");
|
|
19
|
+
const version_js_1 = require("./version.js");
|
|
20
|
+
/**
|
|
21
|
+
* Validates every request against its actions, verifies supplied ECDSA signatures synchronously,
|
|
22
|
+
* and attaches serialized signatures by request ID. No client or RPC is used; the EIP-712 domain
|
|
23
|
+
* binds the signature to its chain. Only low-s compact or serialized ECDSA permits are supported.
|
|
24
|
+
* Contract wallets should use `supportSignature: false` for direct approvals: deployed bundles
|
|
25
|
+
* consume ECDSA `v/r/s`, not arbitrary ERC-1271 or ERC-6492 signatures.
|
|
26
|
+
* Stored inputs remain trusted; verification does not establish the integrator's intent or protect
|
|
27
|
+
* a plan changed afterwards. Builders do not reverify signatures in restored plans.
|
|
28
|
+
* @param plan - Plan to update without mutating its requests or steps.
|
|
29
|
+
* @param signatures - Compact or serialized ECDSA signatures, each naming a unique existing request ID.
|
|
30
|
+
* @returns A new plan sharing steps and unpatched requests; omitted IDs are preserved. Empty input validates all requests and returns the original plan.
|
|
31
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including when no signatures are supplied.
|
|
32
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests or updates.
|
|
33
|
+
* @throws {TransactionPlanSignatureMismatchError} If a request disagrees with its actions, an ID is unknown, or an input ID is duplicated (`field: "duplicate"`).
|
|
34
|
+
* @throws {BundlesPermitMismatchError} If a supplied signature cannot be parsed by the bundle permit builders.
|
|
35
|
+
* @throws {InvalidSignatureError} If a signature has high s, cannot recover a public key, or does not match the permit owner and typed data.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { applySignatures, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
39
|
+
* import type { Hex } from "viem";
|
|
40
|
+
* const complete = (plan: TransactionPlan, signature: Hex) =>
|
|
41
|
+
* applySignatures(plan, [{ id: "vaultV2Deposit:tokenPermit", signature }]);
|
|
42
|
+
* ```
|
|
43
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
44
|
+
*/
|
|
45
|
+
function applySignatures(plan, signatures) {
|
|
46
|
+
// Reject unknown formats before interpreting stored fields or signature updates.
|
|
47
|
+
(0, version_js_1.validateTransactionPlanVersion)(plan.version);
|
|
48
|
+
// Reject unknown actions before reading signature requests or updates.
|
|
49
|
+
(0, validateActions_js_1.validateTransactionPlanActions)(plan.steps);
|
|
50
|
+
const requests = getPendingSignatureRequests({
|
|
51
|
+
...plan,
|
|
52
|
+
signatureRequests: plan.signatureRequests.map((request) => ({
|
|
53
|
+
...request,
|
|
54
|
+
signature: undefined,
|
|
55
|
+
})),
|
|
56
|
+
});
|
|
57
|
+
const updates = new Map();
|
|
58
|
+
for (const { id, signature } of signatures) {
|
|
59
|
+
if (!requests.some((request) => request.id === id))
|
|
60
|
+
throw new error_js_2.TransactionPlanSignatureMismatchError(id, "reference");
|
|
61
|
+
if (updates.has(id))
|
|
62
|
+
throw new error_js_2.TransactionPlanSignatureMismatchError(id, "duplicate");
|
|
63
|
+
updates.set(id, signature);
|
|
64
|
+
}
|
|
65
|
+
if (updates.size === 0)
|
|
66
|
+
return plan;
|
|
67
|
+
for (const [id, signature] of updates) {
|
|
68
|
+
const request = requests.find((candidate) => candidate.id === id);
|
|
69
|
+
const normalized = (0, common_js_1.normalizeBundlesSignature)(signature);
|
|
70
|
+
let recovered;
|
|
71
|
+
try {
|
|
72
|
+
const ecdsa = new secp256k1_1.secp256k1.Signature(BigInt(normalized.r), BigInt(normalized.s));
|
|
73
|
+
if (ecdsa.hasHighS())
|
|
74
|
+
throw new error_js_1.InvalidSignatureError();
|
|
75
|
+
const publicKey = ecdsa
|
|
76
|
+
.addRecoveryBit(normalized.v - 27)
|
|
77
|
+
.recoverPublicKey((0, viem_1.hashTypedData)(request.typedData).slice(2));
|
|
78
|
+
recovered = (0, accounts_1.publicKeyToAddress)((0, viem_1.toHex)(publicKey.toRawBytes(false)));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
throw new error_js_1.InvalidSignatureError();
|
|
82
|
+
}
|
|
83
|
+
if (!(0, viem_1.isAddressEqual)(recovered, request.typedData.message.owner))
|
|
84
|
+
throw new error_js_1.InvalidSignatureError();
|
|
85
|
+
updates.set(id, (0, viem_1.serializeSignature)({ ...normalized, v: BigInt(normalized.v) }));
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
...plan,
|
|
89
|
+
signatureRequests: plan.signatureRequests.map((request) => updates.has(request.id)
|
|
90
|
+
? { ...request, signature: updates.get(request.id) }
|
|
91
|
+
: request),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** @internal Lists the signature request IDs a step's action names, in role order. */
|
|
95
|
+
function getStepSignatureRequestIds(step) {
|
|
96
|
+
const { action } = step;
|
|
97
|
+
if (!("signatureRequestIds" in action))
|
|
98
|
+
return [];
|
|
99
|
+
return Object.values(action.signatureRequestIds).filter((id) => id !== undefined);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Lists pending signature requests once per request ID after checking each against every referencing action.
|
|
103
|
+
* Sign each request's typed data with your wallet stack, then verify and attach the results with
|
|
104
|
+
* {@link applySignatures}.
|
|
105
|
+
* @param plan - Plan to inspect without changing it.
|
|
106
|
+
* @returns Pending requests in first-reference order, each carrying its `id`, `kind` and validated `typedData`. Dangling IDs are omitted. The SDK never signs.
|
|
107
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
|
|
108
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
|
|
109
|
+
* @throws {TransactionPlanSignatureMismatchError} If a pending permit disagrees with its action or arguments, including the action deadline, or any request has no referencing step.
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { getPendingSignatureRequests, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
113
|
+
* const prompts = (plan: TransactionPlan) =>
|
|
114
|
+
* getPendingSignatureRequests(plan).map(({ id, kind, typedData }) => ({ id, kind, typedData }));
|
|
115
|
+
* ```
|
|
116
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
117
|
+
*/
|
|
118
|
+
function getPendingSignatureRequests(plan) {
|
|
119
|
+
// Reject unknown formats before interpreting stored fields.
|
|
120
|
+
(0, version_js_1.validateTransactionPlanVersion)(plan.version);
|
|
121
|
+
// Reject unknown actions before exposing signature requests.
|
|
122
|
+
(0, validateActions_js_1.validateTransactionPlanActions)(plan.steps);
|
|
123
|
+
const referenced = new Map();
|
|
124
|
+
for (const step of plan.steps) {
|
|
125
|
+
for (const id of getStepSignatureRequestIds(step)) {
|
|
126
|
+
referenced.set(id, [...(referenced.get(id) ?? []), step.action]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const request of plan.signatureRequests) {
|
|
130
|
+
const actions = referenced.get(request.id);
|
|
131
|
+
if (actions === undefined)
|
|
132
|
+
throw new error_js_2.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
133
|
+
if (request.signature === undefined) {
|
|
134
|
+
for (const action of actions) {
|
|
135
|
+
(0, permit_js_1.validateSignatureRequest)(request, action);
|
|
136
|
+
if (action.type !== "erc20Approval" &&
|
|
137
|
+
request.args.deadline !== action.inputs.deadline)
|
|
138
|
+
throw new error_js_2.TransactionPlanSignatureMismatchError(request.id, "args.deadline");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return [...referenced.keys()].flatMap((id) => {
|
|
143
|
+
const request = plan.signatureRequests.find((candidate) => candidate.id === id);
|
|
144
|
+
return request && request.signature === undefined ? [request] : [];
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function encodeStep(action, requests) {
|
|
148
|
+
switch (action.type) {
|
|
149
|
+
case "erc20Approval":
|
|
150
|
+
return (0, index_js_1.encodeErc20Approval)(action.inputs);
|
|
151
|
+
case "vaultV2Deposit":
|
|
152
|
+
return (0, deposit_js_1.buildVaultV2Deposit)(action, requests);
|
|
153
|
+
case "vaultV2Withdraw":
|
|
154
|
+
return (0, withdraw_js_1.buildVaultV2Withdraw)(action, requests);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Builds one transaction from a step, its fixed inputs and the signatures its action names.
|
|
159
|
+
* Plans are trusted as given, whether restored or supplied directly. Signature checks establish
|
|
160
|
+
* only request/action consistency; they do not validate stored fees, recipients, share-price bounds,
|
|
161
|
+
* vaults or amounts against the intended operation. Integrators must protect stored plans from tampering.
|
|
162
|
+
* This builder does not verify signature ownership; use {@link applySignatures} to verify and attach signatures.
|
|
163
|
+
* @param plan - Plan supplying referenced signature requests and the calldata origin; chain and account come from the action inputs.
|
|
164
|
+
* @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
|
|
165
|
+
* @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
|
|
166
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
|
|
167
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
|
|
168
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
|
|
169
|
+
* @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
|
|
170
|
+
* @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
|
|
171
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
|
|
172
|
+
* @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
|
|
173
|
+
* @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with the step's action or its encoding arguments.
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { buildTransaction, parseTransactionPlan } from "@morpho-org/morpho-sdk";
|
|
177
|
+
* const resume = (saved: string) => {
|
|
178
|
+
* const plan = parseTransactionPlan(saved);
|
|
179
|
+
* return plan.steps.map((step) => buildTransaction(plan, step));
|
|
180
|
+
* };
|
|
181
|
+
* ```
|
|
182
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
183
|
+
*/
|
|
184
|
+
function buildTransaction(plan, step) {
|
|
185
|
+
// Reject unknown formats before interpreting stored fields.
|
|
186
|
+
(0, version_js_1.validateTransactionPlanVersion)(plan.version);
|
|
187
|
+
// Check the whole plan and any separately selected step before reading requests.
|
|
188
|
+
(0, validateActions_js_1.validateTransactionPlanActions)([...plan.steps, step]);
|
|
189
|
+
const requests = getStepSignatureRequestIds(step).map((id) => {
|
|
190
|
+
const request = plan.signatureRequests.find((candidate) => candidate.id === id);
|
|
191
|
+
if (request === undefined)
|
|
192
|
+
throw new error_js_2.IncompleteTransactionPlanError(id);
|
|
193
|
+
(0, permit_js_1.validateSignatureRequest)(request, step.action);
|
|
194
|
+
return request;
|
|
195
|
+
});
|
|
196
|
+
const { to, value, data, action } = encodeStep(step.action, requests);
|
|
197
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
198
|
+
to,
|
|
199
|
+
value,
|
|
200
|
+
data: plan.calldataOrigin === undefined
|
|
201
|
+
? data
|
|
202
|
+
: (0, viem_1.concatHex)([data, plan.calldataOrigin]),
|
|
203
|
+
action,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Builds every step of the plan in order.
|
|
208
|
+
* @param plan - Plan whose referenced signature requests all carry a signature.
|
|
209
|
+
* @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
|
|
210
|
+
* @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
|
|
211
|
+
* @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
|
|
212
|
+
* @throws {UnsupportedErc20ApprovalSpenderError} If an approval names an unregistered spender.
|
|
213
|
+
* @throws {NonPositiveInputError} If a deposit or withdrawal amount, deposit share-price bound or deadline is not positive.
|
|
214
|
+
* @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
|
|
215
|
+
* @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
|
|
216
|
+
* @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
|
|
217
|
+
* @throws {TransactionPlanSignatureMismatchError} If a referenced permit disagrees with its action or encoding arguments.
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* import { buildTransactions, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
221
|
+
* const submit = (plan: TransactionPlan) => buildTransactions(plan);
|
|
222
|
+
* // Simulate and send in order from plan.account on plan.chainId.
|
|
223
|
+
* ```
|
|
224
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
225
|
+
*/
|
|
226
|
+
function buildTransactions(plan) {
|
|
227
|
+
// Reject unknown formats even when there are no steps to build.
|
|
228
|
+
(0, version_js_1.validateTransactionPlanVersion)(plan.version);
|
|
229
|
+
// Validate every action before the first step can interpret requests.
|
|
230
|
+
(0, validateActions_js_1.validateTransactionPlanActions)(plan.steps);
|
|
231
|
+
return plan.steps.map((step) => buildTransaction(plan, step));
|
|
232
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Address, type Client } from "viem";
|
|
2
|
+
import type { ERC20ApprovalAction, Erc2612RequirementSignature, Requirement, Transaction } from "../types/index.js";
|
|
3
|
+
import type { Action, SignatureRequest, Step } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal Converts an ERC-2612 requirement into a plan-local signature request.
|
|
6
|
+
* @param requirement - Permit requirement carrying its typed data and encoding arguments.
|
|
7
|
+
* @param id - Signature request ID selected by the preparer.
|
|
8
|
+
* @returns The unsigned request with a concrete nonce.
|
|
9
|
+
* @throws {UnexpectedRequirementSignatureError} If the permit requirement has no nonce.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildPermitSignatureRequest(requirement: Requirement<Erc2612RequirementSignature>, id: string): SignatureRequest;
|
|
12
|
+
/**
|
|
13
|
+
* @internal Converts an approval transaction into a step with prepared chain/account inputs.
|
|
14
|
+
* @param requirement - Direct token approval prerequisite.
|
|
15
|
+
* @param params - Step ID, chain and account selected by the preparer.
|
|
16
|
+
* @returns The approval recipe labeled for token spending.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildApprovalStep(requirement: Readonly<Transaction<ERC20ApprovalAction>>, { id, chainId, account, }: {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly chainId: number;
|
|
21
|
+
readonly account: Address;
|
|
22
|
+
}): Step<Extract<Action, {
|
|
23
|
+
type: "erc20Approval";
|
|
24
|
+
}>>;
|
|
25
|
+
/** @internal Token pull prerequisites: direct approvals or an ERC-2612 permit. */
|
|
26
|
+
type TokenRequirement = Readonly<Transaction<ERC20ApprovalAction>> | Requirement<Erc2612RequirementSignature>;
|
|
27
|
+
interface TokenRequirementsParams {
|
|
28
|
+
readonly token: Address;
|
|
29
|
+
readonly spender: Address;
|
|
30
|
+
readonly amount: bigint;
|
|
31
|
+
readonly owner: Address;
|
|
32
|
+
readonly chainId: number;
|
|
33
|
+
readonly deadline: bigint;
|
|
34
|
+
readonly now: bigint;
|
|
35
|
+
readonly supportSignature: boolean;
|
|
36
|
+
readonly deployless: boolean | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @internal Resolves the token prerequisite of a VaultBundlesV1 pull without Permit2. A sufficient
|
|
40
|
+
* direct allowance yields nothing. Otherwise signature support prefers an ERC-2612 permit when
|
|
41
|
+
* available and falls back to a direct unlimited approval. Without signature support, always approve.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getTokenRequirements(client: Client, params: TokenRequirementsParams): Promise<readonly TokenRequirement[]>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPermitSignatureRequest = buildPermitSignatureRequest;
|
|
4
|
+
exports.buildApprovalStep = buildApprovalStep;
|
|
5
|
+
exports.getTokenRequirements = getTokenRequirements;
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const actions_1 = require("viem/actions");
|
|
8
|
+
const getRequirementsApproval_js_1 = require("../actions/requirements/getRequirementsApproval.js");
|
|
9
|
+
const error_js_1 = require("../types/error.js");
|
|
10
|
+
const getTokenPermit_js_1 = require("./getTokenPermit.js");
|
|
11
|
+
/**
|
|
12
|
+
* @internal Converts an ERC-2612 requirement into a plan-local signature request.
|
|
13
|
+
* @param requirement - Permit requirement carrying its typed data and encoding arguments.
|
|
14
|
+
* @param id - Signature request ID selected by the preparer.
|
|
15
|
+
* @returns The unsigned request with a concrete nonce.
|
|
16
|
+
* @throws {UnexpectedRequirementSignatureError} If the permit requirement has no nonce.
|
|
17
|
+
*/
|
|
18
|
+
function buildPermitSignatureRequest(requirement, id) {
|
|
19
|
+
const { nonce, ...args } = requirement.action.args;
|
|
20
|
+
if (nonce === undefined)
|
|
21
|
+
throw new error_js_1.UnexpectedRequirementSignatureError(requirement.action.type);
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
kind: "permit",
|
|
25
|
+
typedData: requirement.action.typedData,
|
|
26
|
+
args: { ...args, nonce },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal Converts an approval transaction into a step with prepared chain/account inputs.
|
|
31
|
+
* @param requirement - Direct token approval prerequisite.
|
|
32
|
+
* @param params - Step ID, chain and account selected by the preparer.
|
|
33
|
+
* @returns The approval recipe labeled for token spending.
|
|
34
|
+
*/
|
|
35
|
+
function buildApprovalStep(requirement, { id, chainId, account, }) {
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
label: "Approve token spending",
|
|
39
|
+
action: {
|
|
40
|
+
type: "erc20Approval",
|
|
41
|
+
inputs: {
|
|
42
|
+
token: requirement.to,
|
|
43
|
+
...requirement.action.args,
|
|
44
|
+
chainId,
|
|
45
|
+
account,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @internal Resolves the token prerequisite of a VaultBundlesV1 pull without Permit2. A sufficient
|
|
52
|
+
* direct allowance yields nothing. Otherwise signature support prefers an ERC-2612 permit when
|
|
53
|
+
* available and falls back to a direct unlimited approval. Without signature support, always approve.
|
|
54
|
+
*/
|
|
55
|
+
async function getTokenRequirements(client, params) {
|
|
56
|
+
// The allowance is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
|
|
57
|
+
const allowance = await (0, actions_1.readContract)(client, {
|
|
58
|
+
abi: viem_1.erc20Abi,
|
|
59
|
+
address: params.token,
|
|
60
|
+
functionName: "allowance",
|
|
61
|
+
args: [params.owner, params.spender],
|
|
62
|
+
});
|
|
63
|
+
if (allowance >= params.amount)
|
|
64
|
+
return [];
|
|
65
|
+
if (params.supportSignature) {
|
|
66
|
+
const permit = await (0, getTokenPermit_js_1.getTokenPermit)(client, {
|
|
67
|
+
...params,
|
|
68
|
+
supportDeployless: params.deployless,
|
|
69
|
+
});
|
|
70
|
+
if (permit !== undefined)
|
|
71
|
+
return [permit];
|
|
72
|
+
}
|
|
73
|
+
return (0, getRequirementsApproval_js_1.getRequirementsApproval)({
|
|
74
|
+
address: params.token,
|
|
75
|
+
chainId: params.chainId,
|
|
76
|
+
args: { spendAmount: params.amount, spender: params.spender },
|
|
77
|
+
allowances: allowance,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -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;
|