@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,145 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when an operation's account is the zero address.
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { ZeroAccountError } from "@morpho-org/morpho-sdk";
|
|
7
|
+
* import { zeroAddress } from "viem";
|
|
8
|
+
* const error = new ZeroAccountError(zeroAddress);
|
|
9
|
+
* ```
|
|
10
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ZeroAccountError extends Error {
|
|
13
|
+
readonly account: Address;
|
|
14
|
+
/** @param account - Rejected account address. */
|
|
15
|
+
constructor(account: Address);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A stored plan uses a format version this SDK cannot interpret.
|
|
19
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
20
|
+
*/
|
|
21
|
+
export declare class UnsupportedTransactionPlanVersionError extends Error {
|
|
22
|
+
readonly version: number;
|
|
23
|
+
/**
|
|
24
|
+
* @param version - Unsupported stored plan version.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { UnsupportedTransactionPlanVersionError } from "@morpho-org/morpho-sdk";
|
|
28
|
+
* const error = new UnsupportedTransactionPlanVersionError(2);
|
|
29
|
+
* console.error(error.version);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
constructor(version: number);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A selected plan step names an action this SDK cannot build.
|
|
36
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
37
|
+
*/
|
|
38
|
+
export declare class UnsupportedTransactionPlanActionError extends Error {
|
|
39
|
+
readonly actionType: string;
|
|
40
|
+
/**
|
|
41
|
+
* @param actionType - Unsupported stored action discriminator.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { UnsupportedTransactionPlanActionError } from "@morpho-org/morpho-sdk";
|
|
45
|
+
* const error = new UnsupportedTransactionPlanActionError("futureAction");
|
|
46
|
+
* console.error(error.actionType);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
constructor(actionType: string);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Restored plan data has an invalid shape or inconsistent references.
|
|
53
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
54
|
+
*/
|
|
55
|
+
export declare class InvalidTransactionPlanError extends Error {
|
|
56
|
+
/** JSON path of the first rejected value. */
|
|
57
|
+
readonly path: string;
|
|
58
|
+
/** Shape or consistency constraint that the value failed. */
|
|
59
|
+
readonly reason: string;
|
|
60
|
+
/**
|
|
61
|
+
* @param details - JSON path, validation failure and optional underlying error.
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { InvalidTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
65
|
+
* const error = new InvalidTransactionPlanError({ path: "$.chainId", reason: "expected a positive safe integer" });
|
|
66
|
+
* console.error(error.path);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
constructor({ path, reason, cause, }: {
|
|
70
|
+
readonly path: string;
|
|
71
|
+
readonly reason: string;
|
|
72
|
+
readonly cause?: unknown;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A step references a signature request that is absent or has no signature yet.
|
|
77
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
78
|
+
*/
|
|
79
|
+
export declare class IncompleteTransactionPlanError extends Error {
|
|
80
|
+
readonly id: string;
|
|
81
|
+
/**
|
|
82
|
+
* Identifies the signature request needed to build the transaction.
|
|
83
|
+
* @param id - Plan-local signature request ID.
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { IncompleteTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
87
|
+
* const error = new IncompleteTransactionPlanError("vaultV2Deposit:tokenPermit");
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
constructor(id: string);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
94
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
95
|
+
*/
|
|
96
|
+
export declare class TransactionPlanSignatureMismatchError extends Error {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly field: string;
|
|
99
|
+
/**
|
|
100
|
+
* @param id - Rejected signature request ID.
|
|
101
|
+
* @param field - Mismatched typed-data, argument or reference field.
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { TransactionPlanSignatureMismatchError } from "@morpho-org/morpho-sdk";
|
|
105
|
+
* const error = new TransactionPlanSignatureMismatchError("vaultV2Deposit:tokenPermit", "message.owner");
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
constructor(id: string, field: string);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
112
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
113
|
+
*/
|
|
114
|
+
export declare class InvalidCalldataOriginError extends Error {
|
|
115
|
+
readonly calldataOrigin: string;
|
|
116
|
+
/**
|
|
117
|
+
* Identifies the rejected origin.
|
|
118
|
+
* @param calldataOrigin - Value supplied by the caller.
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { InvalidCalldataOriginError } from "@morpho-org/morpho-sdk";
|
|
122
|
+
* const error = new InvalidCalldataOriginError("0xabc");
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
constructor(calldataOrigin: string);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A number input that must be an integer is fractional, infinite or not a number.
|
|
129
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
130
|
+
*/
|
|
131
|
+
export declare class NonIntegerInputError extends Error {
|
|
132
|
+
readonly field: string;
|
|
133
|
+
readonly value: number;
|
|
134
|
+
/**
|
|
135
|
+
* Identifies the invalid input.
|
|
136
|
+
* @param field - Public input field whose value is invalid.
|
|
137
|
+
* @param value - Non-integer number supplied for the field.
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { NonIntegerInputError } from "@morpho-org/morpho-sdk";
|
|
141
|
+
* const error = new NonIntegerInputError("expiresAt", 1.5);
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
constructor(field: string, value: number);
|
|
145
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NonIntegerInputError = exports.InvalidCalldataOriginError = exports.TransactionPlanSignatureMismatchError = exports.IncompleteTransactionPlanError = exports.InvalidTransactionPlanError = exports.UnsupportedTransactionPlanActionError = exports.UnsupportedTransactionPlanVersionError = exports.ZeroAccountError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when an operation's account is the zero address.
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { ZeroAccountError } from "@morpho-org/morpho-sdk";
|
|
9
|
+
* import { zeroAddress } from "viem";
|
|
10
|
+
* const error = new ZeroAccountError(zeroAddress);
|
|
11
|
+
* ```
|
|
12
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
13
|
+
*/
|
|
14
|
+
class ZeroAccountError extends Error {
|
|
15
|
+
account;
|
|
16
|
+
/** @param account - Rejected account address. */
|
|
17
|
+
constructor(account) {
|
|
18
|
+
super(`Account "${account}" cannot be the zero address. Pass the account that sends the transaction.`);
|
|
19
|
+
this.account = account;
|
|
20
|
+
this.name = "ZeroAccountError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ZeroAccountError = ZeroAccountError;
|
|
24
|
+
/**
|
|
25
|
+
* A stored plan uses a format version this SDK cannot interpret.
|
|
26
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
27
|
+
*/
|
|
28
|
+
class UnsupportedTransactionPlanVersionError extends Error {
|
|
29
|
+
version;
|
|
30
|
+
/**
|
|
31
|
+
* @param version - Unsupported stored plan version.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { UnsupportedTransactionPlanVersionError } from "@morpho-org/morpho-sdk";
|
|
35
|
+
* const error = new UnsupportedTransactionPlanVersionError(2);
|
|
36
|
+
* console.error(error.version);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
constructor(version) {
|
|
40
|
+
super(`Unsupported transaction plan version "${version}". Use an SDK that supports this plan version.`);
|
|
41
|
+
this.version = version;
|
|
42
|
+
this.name = "UnsupportedTransactionPlanVersionError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.UnsupportedTransactionPlanVersionError = UnsupportedTransactionPlanVersionError;
|
|
46
|
+
/**
|
|
47
|
+
* A selected plan step names an action this SDK cannot build.
|
|
48
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
49
|
+
*/
|
|
50
|
+
class UnsupportedTransactionPlanActionError extends Error {
|
|
51
|
+
actionType;
|
|
52
|
+
/**
|
|
53
|
+
* @param actionType - Unsupported stored action discriminator.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { UnsupportedTransactionPlanActionError } from "@morpho-org/morpho-sdk";
|
|
57
|
+
* const error = new UnsupportedTransactionPlanActionError("futureAction");
|
|
58
|
+
* console.error(error.actionType);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(actionType) {
|
|
62
|
+
super(`Unsupported transaction plan action "${actionType}". Use an SDK that supports this action.`);
|
|
63
|
+
this.actionType = actionType;
|
|
64
|
+
this.name = "UnsupportedTransactionPlanActionError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.UnsupportedTransactionPlanActionError = UnsupportedTransactionPlanActionError;
|
|
68
|
+
/**
|
|
69
|
+
* Restored plan data has an invalid shape or inconsistent references.
|
|
70
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
71
|
+
*/
|
|
72
|
+
class InvalidTransactionPlanError extends Error {
|
|
73
|
+
/** JSON path of the first rejected value. */
|
|
74
|
+
path;
|
|
75
|
+
/** Shape or consistency constraint that the value failed. */
|
|
76
|
+
reason;
|
|
77
|
+
/**
|
|
78
|
+
* @param details - JSON path, validation failure and optional underlying error.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { InvalidTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
82
|
+
* const error = new InvalidTransactionPlanError({ path: "$.chainId", reason: "expected a positive safe integer" });
|
|
83
|
+
* console.error(error.path);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
constructor({ path, reason, cause, }) {
|
|
87
|
+
super(`Invalid transaction plan at "${path}": ${reason}. Restore a valid saved plan or prepare a new plan.`, { cause });
|
|
88
|
+
this.name = "InvalidTransactionPlanError";
|
|
89
|
+
this.path = path;
|
|
90
|
+
this.reason = reason;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.InvalidTransactionPlanError = InvalidTransactionPlanError;
|
|
94
|
+
/**
|
|
95
|
+
* A step references a signature request that is absent or has no signature yet.
|
|
96
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
97
|
+
*/
|
|
98
|
+
class IncompleteTransactionPlanError extends Error {
|
|
99
|
+
id;
|
|
100
|
+
/**
|
|
101
|
+
* Identifies the signature request needed to build the transaction.
|
|
102
|
+
* @param id - Plan-local signature request ID.
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { IncompleteTransactionPlanError } from "@morpho-org/morpho-sdk";
|
|
106
|
+
* const error = new IncompleteTransactionPlanError("vaultV2Deposit:tokenPermit");
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
constructor(id) {
|
|
110
|
+
super(`Missing signature for request "${id}". Verify and attach it with applySignatures before building this step.`);
|
|
111
|
+
this.id = id;
|
|
112
|
+
this.name = "IncompleteTransactionPlanError";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.IncompleteTransactionPlanError = IncompleteTransactionPlanError;
|
|
116
|
+
/**
|
|
117
|
+
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
118
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
119
|
+
*/
|
|
120
|
+
class TransactionPlanSignatureMismatchError extends Error {
|
|
121
|
+
id;
|
|
122
|
+
field;
|
|
123
|
+
/**
|
|
124
|
+
* @param id - Rejected signature request ID.
|
|
125
|
+
* @param field - Mismatched typed-data, argument or reference field.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { TransactionPlanSignatureMismatchError } from "@morpho-org/morpho-sdk";
|
|
129
|
+
* const error = new TransactionPlanSignatureMismatchError("vaultV2Deposit:tokenPermit", "message.owner");
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
constructor(id, field) {
|
|
133
|
+
super(`Signature request "${id}" has a mismatched "${field}". Prepare a new plan before signing or building.`);
|
|
134
|
+
this.id = id;
|
|
135
|
+
this.field = field;
|
|
136
|
+
this.name = "TransactionPlanSignatureMismatchError";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.TransactionPlanSignatureMismatchError = TransactionPlanSignatureMismatchError;
|
|
140
|
+
/**
|
|
141
|
+
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
142
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
143
|
+
*/
|
|
144
|
+
class InvalidCalldataOriginError extends Error {
|
|
145
|
+
calldataOrigin;
|
|
146
|
+
/**
|
|
147
|
+
* Identifies the rejected origin.
|
|
148
|
+
* @param calldataOrigin - Value supplied by the caller.
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { InvalidCalldataOriginError } from "@morpho-org/morpho-sdk";
|
|
152
|
+
* const error = new InvalidCalldataOriginError("0xabc");
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
constructor(calldataOrigin) {
|
|
156
|
+
super(`Calldata origin "${calldataOrigin}" must be 0x-prefixed hex with an even number of hex characters, such as "0xdeadbeef". Fix the value or omit it.`);
|
|
157
|
+
this.calldataOrigin = calldataOrigin;
|
|
158
|
+
this.name = "InvalidCalldataOriginError";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.InvalidCalldataOriginError = InvalidCalldataOriginError;
|
|
162
|
+
/**
|
|
163
|
+
* A number input that must be an integer is fractional, infinite or not a number.
|
|
164
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
165
|
+
*/
|
|
166
|
+
class NonIntegerInputError extends Error {
|
|
167
|
+
field;
|
|
168
|
+
value;
|
|
169
|
+
/**
|
|
170
|
+
* Identifies the invalid input.
|
|
171
|
+
* @param field - Public input field whose value is invalid.
|
|
172
|
+
* @param value - Non-integer number supplied for the field.
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { NonIntegerInputError } from "@morpho-org/morpho-sdk";
|
|
176
|
+
* const error = new NonIntegerInputError("expiresAt", 1.5);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
constructor(field, value) {
|
|
180
|
+
super(`Input "${field}" must be a safe integer, got "${value}".`);
|
|
181
|
+
this.field = field;
|
|
182
|
+
this.value = value;
|
|
183
|
+
this.name = "NonIntegerInputError";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.NonIntegerInputError = NonIntegerInputError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Client } from "viem";
|
|
2
|
+
import type { GetBundlesTokenRequirementsParams } from "../entities/requirements/getBundlesTokenRequirements.js";
|
|
3
|
+
import type { Erc2612RequirementSignature, Requirement } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal Builds an ERC-2612 permit requirement, or returns undefined when the token has no
|
|
6
|
+
* usable permit: DAI's non-standard permit, a reverting or undecodable `nonces()`, or no known
|
|
7
|
+
* compatible permit domain and matching DOMAIN_SEPARATOR. Transport failures propagate.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTokenPermit(client: Client, params: Pick<GetBundlesTokenRequirementsParams, "token" | "spender" | "amount" | "owner" | "chainId" | "deadline" | "supportDeployless"> & {
|
|
10
|
+
readonly now: bigint;
|
|
11
|
+
}): Promise<Requirement<Erc2612RequirementSignature> | undefined>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenPermit = getTokenPermit;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const getErc2612Permit_js_1 = require("../entities/requirements/getErc2612Permit.js");
|
|
8
|
+
/**
|
|
9
|
+
* @internal Builds an ERC-2612 permit requirement, or returns undefined when the token has no
|
|
10
|
+
* usable permit: DAI's non-standard permit, a reverting or undecodable `nonces()`, or no known
|
|
11
|
+
* compatible permit domain and matching DOMAIN_SEPARATOR. Transport failures propagate.
|
|
12
|
+
*/
|
|
13
|
+
async function getTokenPermit(client, params) {
|
|
14
|
+
const { dai } = (0, blue_sdk_1.getChainAddresses)(params.chainId);
|
|
15
|
+
if ((0, morpho_ts_1.isDefined)(dai) && (0, viem_1.isAddressEqual)(params.token, dai))
|
|
16
|
+
return undefined;
|
|
17
|
+
return (0, getErc2612Permit_js_1.getErc2612Permit)(client, params);
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
2
|
+
export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
|
|
3
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
4
|
+
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
5
|
+
export type { Action, SignatureRequest, Step, TransactionPlan, } from "./types.js";
|
|
6
|
+
export type { VaultV2DepositPlanParams } from "./vaultv2/deposit.js";
|
|
7
|
+
export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
|
|
8
|
+
export type { VaultV2WithdrawPlanParams } from "./vaultv2/withdraw.js";
|
|
9
|
+
export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareVaultV2Withdraw = exports.prepareVaultV2Deposit = exports.serializeTransactionPlan = exports.parseTransactionPlan = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.NonIntegerInputError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = void 0;
|
|
4
|
+
var error_js_1 = require("./error.js");
|
|
5
|
+
Object.defineProperty(exports, "IncompleteTransactionPlanError", { enumerable: true, get: function () { return error_js_1.IncompleteTransactionPlanError; } });
|
|
6
|
+
Object.defineProperty(exports, "InvalidCalldataOriginError", { enumerable: true, get: function () { return error_js_1.InvalidCalldataOriginError; } });
|
|
7
|
+
Object.defineProperty(exports, "InvalidTransactionPlanError", { enumerable: true, get: function () { return error_js_1.InvalidTransactionPlanError; } });
|
|
8
|
+
Object.defineProperty(exports, "NonIntegerInputError", { enumerable: true, get: function () { return error_js_1.NonIntegerInputError; } });
|
|
9
|
+
Object.defineProperty(exports, "TransactionPlanSignatureMismatchError", { enumerable: true, get: function () { return error_js_1.TransactionPlanSignatureMismatchError; } });
|
|
10
|
+
Object.defineProperty(exports, "UnsupportedTransactionPlanActionError", { enumerable: true, get: function () { return error_js_1.UnsupportedTransactionPlanActionError; } });
|
|
11
|
+
Object.defineProperty(exports, "UnsupportedTransactionPlanVersionError", { enumerable: true, get: function () { return error_js_1.UnsupportedTransactionPlanVersionError; } });
|
|
12
|
+
Object.defineProperty(exports, "ZeroAccountError", { enumerable: true, get: function () { return error_js_1.ZeroAccountError; } });
|
|
13
|
+
var plan_js_1 = require("./plan.js");
|
|
14
|
+
Object.defineProperty(exports, "applySignatures", { enumerable: true, get: function () { return plan_js_1.applySignatures; } });
|
|
15
|
+
Object.defineProperty(exports, "buildTransaction", { enumerable: true, get: function () { return plan_js_1.buildTransaction; } });
|
|
16
|
+
Object.defineProperty(exports, "buildTransactions", { enumerable: true, get: function () { return plan_js_1.buildTransactions; } });
|
|
17
|
+
Object.defineProperty(exports, "getPendingSignatureRequests", { enumerable: true, get: function () { return plan_js_1.getPendingSignatureRequests; } });
|
|
18
|
+
var serde_js_1 = require("./serde.js");
|
|
19
|
+
Object.defineProperty(exports, "parseTransactionPlan", { enumerable: true, get: function () { return serde_js_1.parseTransactionPlan; } });
|
|
20
|
+
Object.defineProperty(exports, "serializeTransactionPlan", { enumerable: true, get: function () { return serde_js_1.serializeTransactionPlan; } });
|
|
21
|
+
var deposit_js_1 = require("./vaultv2/deposit.js");
|
|
22
|
+
Object.defineProperty(exports, "prepareVaultV2Deposit", { enumerable: true, get: function () { return deposit_js_1.prepareVaultV2Deposit; } });
|
|
23
|
+
var withdraw_js_1 = require("./vaultv2/withdraw.js");
|
|
24
|
+
Object.defineProperty(exports, "prepareVaultV2Withdraw", { enumerable: true, get: function () { return withdraw_js_1.prepareVaultV2Withdraw; } });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Which balance pays a deposit: the vault asset, or native currency the bundle wraps.
|
|
4
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
5
|
+
*/
|
|
6
|
+
export type Funding = {
|
|
7
|
+
readonly type: "erc20";
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: "native";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Referral fee in basis points of the gross amount, paid to `recipient`.
|
|
13
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
14
|
+
*/
|
|
15
|
+
export interface ReferralFee {
|
|
16
|
+
readonly bps: number;
|
|
17
|
+
readonly recipient: Address;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Intent fields shared by every prepare function, mirroring the Actions API intent inputs.
|
|
21
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
22
|
+
*/
|
|
23
|
+
export interface IntentParams {
|
|
24
|
+
readonly chainId: number;
|
|
25
|
+
/** Non-zero account that funds, signs and sends the operation. */
|
|
26
|
+
readonly account: Address;
|
|
27
|
+
readonly referralFee?: ReferralFee;
|
|
28
|
+
/** Prefer an ERC-2612 permit when available, otherwise approve directly. Defaults to `false`. */
|
|
29
|
+
readonly supportSignature?: boolean;
|
|
30
|
+
/** Unix seconds. Defaults to two hours from now. */
|
|
31
|
+
readonly expiresAt?: number;
|
|
32
|
+
/** Optional attribution bytes appended verbatim to every built transaction's calldata. */
|
|
33
|
+
readonly calldataOrigin?: Hex;
|
|
34
|
+
/** Whether token metadata reads for permits may use deployless aggregation. */
|
|
35
|
+
readonly deployless?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** @internal Validated intent in the bigint units the encoders and requirement helpers take. */
|
|
38
|
+
export interface Intent {
|
|
39
|
+
readonly expiresAt: number;
|
|
40
|
+
readonly deadline: bigint;
|
|
41
|
+
readonly referralFeePct: bigint;
|
|
42
|
+
readonly referralFeeRecipient: Address | undefined;
|
|
43
|
+
readonly supportSignature: boolean;
|
|
44
|
+
readonly calldataOrigin: Hex | undefined;
|
|
45
|
+
readonly deployless: boolean | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @internal Normalizes caller intent before any RPC read: account, expiry, referral fee,
|
|
49
|
+
* signature support and calldata origin. Throws on invalid values so a plan never carries them.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveIntent(params: IntentParams, now: bigint): Intent;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveIntent = resolveIntent;
|
|
4
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const index_js_1 = require("../types/index.js");
|
|
7
|
+
const error_js_1 = require("./error.js");
|
|
8
|
+
const BASIS_POINTS = 10000n;
|
|
9
|
+
const WAD_PER_BASIS_POINT = morpho_ts_1.MathLib.WAD / BASIS_POINTS;
|
|
10
|
+
function toSafeInteger(field, value) {
|
|
11
|
+
if (!Number.isSafeInteger(value))
|
|
12
|
+
throw new error_js_1.NonIntegerInputError(field, value);
|
|
13
|
+
return BigInt(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @internal Normalizes caller intent before any RPC read: account, expiry, referral fee,
|
|
17
|
+
* signature support and calldata origin. Throws on invalid values so a plan never carries them.
|
|
18
|
+
*/
|
|
19
|
+
function resolveIntent(params, now) {
|
|
20
|
+
if (params.account === viem_1.zeroAddress)
|
|
21
|
+
throw new error_js_1.ZeroAccountError(params.account);
|
|
22
|
+
const expiresAt = params.expiresAt ?? Number(now + morpho_ts_1.Time.s.from.h(2n));
|
|
23
|
+
const deadline = toSafeInteger("expiresAt", expiresAt);
|
|
24
|
+
if (deadline <= 0n)
|
|
25
|
+
throw new index_js_1.NonPositiveInputError("expiresAt", deadline);
|
|
26
|
+
if (deadline <= now)
|
|
27
|
+
throw new index_js_1.ExpiredDeadlineError(deadline, now);
|
|
28
|
+
const bps = params.referralFee === undefined
|
|
29
|
+
? 0n
|
|
30
|
+
: toSafeInteger("referralFee.bps", params.referralFee.bps);
|
|
31
|
+
if (bps < 0n)
|
|
32
|
+
throw new index_js_1.NegativeInputError("referralFee.bps", bps);
|
|
33
|
+
if (bps > BASIS_POINTS)
|
|
34
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
35
|
+
field: "referralFee.bps",
|
|
36
|
+
value: bps,
|
|
37
|
+
max: BASIS_POINTS,
|
|
38
|
+
});
|
|
39
|
+
const { calldataOrigin } = params;
|
|
40
|
+
if (calldataOrigin !== undefined &&
|
|
41
|
+
(!(0, viem_1.isHex)(calldataOrigin, { strict: true }) ||
|
|
42
|
+
calldataOrigin.length <= 2 ||
|
|
43
|
+
calldataOrigin.length % 2 !== 0))
|
|
44
|
+
throw new error_js_1.InvalidCalldataOriginError(calldataOrigin);
|
|
45
|
+
return {
|
|
46
|
+
expiresAt: Number(deadline),
|
|
47
|
+
deadline,
|
|
48
|
+
referralFeePct: bps * WAD_PER_BASIS_POINT,
|
|
49
|
+
referralFeeRecipient: params.referralFee?.recipient,
|
|
50
|
+
supportSignature: params.supportSignature ?? false,
|
|
51
|
+
calldataOrigin,
|
|
52
|
+
deployless: params.deployless,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { Erc2612RequirementSignature } from "../types/index.js";
|
|
3
|
+
import type { Action, SignatureRequest } from "./types.js";
|
|
4
|
+
/** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
|
|
5
|
+
export declare function validatePermitPlanRequest(request: Record<string, unknown>, path: string): void;
|
|
6
|
+
/** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
|
|
7
|
+
export declare function validateSignatureRequest(request: SignatureRequest, action: Action): void;
|
|
8
|
+
/** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
|
|
9
|
+
export declare function getVaultPermit(requests: readonly SignatureRequest[], { id, asset, owner, }: {
|
|
10
|
+
readonly id: string | undefined;
|
|
11
|
+
readonly asset: Address;
|
|
12
|
+
readonly owner: Address;
|
|
13
|
+
}): Erc2612RequirementSignature | undefined;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePermitPlanRequest = validatePermitPlanRequest;
|
|
4
|
+
exports.validateSignatureRequest = validateSignatureRequest;
|
|
5
|
+
exports.getVaultPermit = getVaultPermit;
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const error_js_1 = require("./error.js");
|
|
8
|
+
const validation_js_1 = require("./validation.js");
|
|
9
|
+
/** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
|
|
10
|
+
function validatePermitPlanRequest(request, path) {
|
|
11
|
+
const args = (0, validation_js_1.getPlanObject)(request.args, `${path}.args`);
|
|
12
|
+
(0, validation_js_1.validatePlanFields)(args, {
|
|
13
|
+
path: `${path}.args`,
|
|
14
|
+
fields: {
|
|
15
|
+
spender: "address",
|
|
16
|
+
amount: "uint256 bigint",
|
|
17
|
+
nonce: "uint256 bigint",
|
|
18
|
+
deadline: "uint256 bigint",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const typedData = (0, validation_js_1.getPlanObject)(request.typedData, `${path}.typedData`);
|
|
22
|
+
(0, validation_js_1.validatePlanField)(typedData.primaryType, {
|
|
23
|
+
path: `${path}.typedData.primaryType`,
|
|
24
|
+
type: "string",
|
|
25
|
+
});
|
|
26
|
+
const domain = (0, validation_js_1.getPlanObject)(typedData.domain, `${path}.typedData.domain`);
|
|
27
|
+
(0, validation_js_1.validatePlanFields)(domain, {
|
|
28
|
+
path: `${path}.typedData.domain`,
|
|
29
|
+
fields: { chainId: "positive safe integer", verifyingContract: "address" },
|
|
30
|
+
});
|
|
31
|
+
for (const field of ["name", "version"])
|
|
32
|
+
if (domain[field] !== undefined)
|
|
33
|
+
(0, validation_js_1.validatePlanField)(domain[field], {
|
|
34
|
+
path: `${path}.typedData.domain.${field}`,
|
|
35
|
+
type: "string",
|
|
36
|
+
});
|
|
37
|
+
if (domain.salt !== undefined)
|
|
38
|
+
(0, validation_js_1.validatePlanField)(domain.salt, {
|
|
39
|
+
path: `${path}.typedData.domain.salt`,
|
|
40
|
+
type: "hex",
|
|
41
|
+
});
|
|
42
|
+
const types = (0, validation_js_1.getPlanObject)(typedData.types, `${path}.typedData.types`);
|
|
43
|
+
(0, validation_js_1.validatePlanField)(types[typedData.primaryType], {
|
|
44
|
+
path: `${path}.typedData.types.${typedData.primaryType}`,
|
|
45
|
+
type: "array",
|
|
46
|
+
});
|
|
47
|
+
for (const [name, fields] of Object.entries(types)) {
|
|
48
|
+
const typePath = `${path}.typedData.types.${name}`;
|
|
49
|
+
(0, validation_js_1.validatePlanField)(fields, { path: typePath, type: "array" });
|
|
50
|
+
for (const [index, field] of fields.entries()) {
|
|
51
|
+
const entry = (0, validation_js_1.getPlanObject)(field, `${typePath}[${index}]`);
|
|
52
|
+
(0, validation_js_1.validatePlanFields)(entry, {
|
|
53
|
+
path: `${typePath}[${index}]`,
|
|
54
|
+
fields: { name: "string", type: "string" },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const message = (0, validation_js_1.getPlanObject)(typedData.message, `${path}.typedData.message`);
|
|
59
|
+
(0, validation_js_1.validatePlanFields)(message, {
|
|
60
|
+
path: `${path}.typedData.message`,
|
|
61
|
+
fields: {
|
|
62
|
+
owner: "address",
|
|
63
|
+
spender: "address",
|
|
64
|
+
value: "uint256 bigint",
|
|
65
|
+
nonce: "uint256 bigint",
|
|
66
|
+
deadline: "uint256 bigint",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
if (request.signature !== undefined)
|
|
70
|
+
(0, validation_js_1.validatePlanField)(request.signature, {
|
|
71
|
+
path: `${path}.signature`,
|
|
72
|
+
type: "hex",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** @internal Checks a permit's signing payload against its referencing action and encoding arguments. */
|
|
76
|
+
function validateSignatureRequest(request, action) {
|
|
77
|
+
if (action.type === "erc20Approval" ||
|
|
78
|
+
action.signatureRequestIds.tokenPermit !== request.id)
|
|
79
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, "reference");
|
|
80
|
+
const { chainId, account } = action.inputs;
|
|
81
|
+
const { domain, message, primaryType } = request.typedData;
|
|
82
|
+
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
83
|
+
const asset = action.type === "vaultV2Deposit"
|
|
84
|
+
? action.inputs.asset
|
|
85
|
+
: action.inputs.vault;
|
|
86
|
+
const checks = [
|
|
87
|
+
["domain.chainId", domain?.chainId === chainId],
|
|
88
|
+
[
|
|
89
|
+
"domain.verifyingContract",
|
|
90
|
+
typeof domain?.verifyingContract === "string" &&
|
|
91
|
+
domain.verifyingContract.toLowerCase() === asset.toLowerCase(),
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
"message.owner",
|
|
95
|
+
typeof message?.owner === "string" &&
|
|
96
|
+
message.owner.toLowerCase() === account.toLowerCase(),
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
"message.spender",
|
|
100
|
+
typeof message?.spender === "string" &&
|
|
101
|
+
message.spender.toLowerCase() === spender.toLowerCase(),
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"args.spender",
|
|
105
|
+
typeof request.args.spender === "string" &&
|
|
106
|
+
request.args.spender.toLowerCase() === spender.toLowerCase(),
|
|
107
|
+
],
|
|
108
|
+
["message.value", message?.value === request.args.amount],
|
|
109
|
+
[
|
|
110
|
+
"value",
|
|
111
|
+
action.type === "vaultV2Deposit"
|
|
112
|
+
? request.args.amount === action.inputs.amount
|
|
113
|
+
: request.args.amount >= action.inputs.requiredShareAllowance,
|
|
114
|
+
],
|
|
115
|
+
["message.nonce", message?.nonce === request.args.nonce],
|
|
116
|
+
["message.deadline", message?.deadline === request.args.deadline],
|
|
117
|
+
["primaryType", primaryType === "Permit"],
|
|
118
|
+
];
|
|
119
|
+
const mismatch = checks.find(([, matches]) => !matches);
|
|
120
|
+
if (mismatch)
|
|
121
|
+
throw new error_js_1.TransactionPlanSignatureMismatchError(request.id, mismatch[0]);
|
|
122
|
+
}
|
|
123
|
+
/** @internal Rebuilds a token permit from the action's account/asset and its resolved signature requests. */
|
|
124
|
+
function getVaultPermit(requests, { id, asset, owner, }) {
|
|
125
|
+
if (id === undefined)
|
|
126
|
+
return undefined;
|
|
127
|
+
const request = requests.find((candidate) => candidate.id === id);
|
|
128
|
+
if (request?.signature === undefined)
|
|
129
|
+
throw new error_js_1.IncompleteTransactionPlanError(id);
|
|
130
|
+
return {
|
|
131
|
+
action: {
|
|
132
|
+
type: request.kind,
|
|
133
|
+
args: request.args,
|
|
134
|
+
typedData: request.typedData,
|
|
135
|
+
},
|
|
136
|
+
args: {
|
|
137
|
+
owner,
|
|
138
|
+
asset,
|
|
139
|
+
amount: request.args.amount,
|
|
140
|
+
nonce: request.args.nonce,
|
|
141
|
+
deadline: request.args.deadline,
|
|
142
|
+
signature: request.signature,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|