@morpho-org/evm-simulation 4.2.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -17
- package/lib/cjs/authorizations.d.ts +95 -0
- package/lib/cjs/authorizations.js +2 -0
- package/lib/cjs/errors.d.ts +199 -12
- package/lib/cjs/errors.js +190 -12
- package/lib/cjs/index.d.ts +10 -2
- package/lib/cjs/index.js +19 -3
- package/lib/cjs/limits.d.ts +112 -0
- package/lib/cjs/limits.js +50 -0
- package/lib/cjs/params.d.ts +26 -0
- package/lib/cjs/params.js +5 -0
- package/lib/cjs/requirements/index.d.ts +1 -0
- package/lib/cjs/requirements/index.js +5 -0
- package/lib/cjs/requirements/requirements.d.ts +64 -0
- package/lib/cjs/requirements/requirements.js +149 -0
- package/lib/cjs/result.d.ts +49 -0
- package/lib/cjs/result.js +2 -0
- package/lib/cjs/simulate/asset-changes.d.ts +7 -5
- package/lib/cjs/simulate/asset-changes.js +6 -5
- package/lib/cjs/simulate/backends/client.d.ts +16 -0
- package/lib/cjs/simulate/backends/client.js +27 -0
- package/lib/cjs/simulate/backends/eth-simulate-v1.d.ts +69 -20
- package/lib/cjs/simulate/backends/eth-simulate-v1.js +174 -98
- package/lib/cjs/simulate/backends/index.d.ts +1 -2
- package/lib/cjs/simulate/backends/index.js +3 -4
- package/lib/cjs/simulate/backends/parse-response.d.ts +69 -0
- package/lib/cjs/simulate/backends/parse-response.js +168 -0
- package/lib/cjs/simulate/backends/resolve-assets.d.ts +26 -0
- package/lib/cjs/simulate/backends/resolve-assets.js +111 -0
- package/lib/cjs/simulate/backends/resolve-pinned-block.d.ts +33 -0
- package/lib/cjs/simulate/backends/resolve-pinned-block.js +46 -0
- package/lib/cjs/simulate/context.d.ts +14 -0
- package/lib/cjs/simulate/context.js +2 -0
- package/lib/cjs/simulate/measurement-plan.d.ts +29 -0
- package/lib/cjs/simulate/measurement-plan.js +115 -0
- package/lib/cjs/simulate/parsing/transfers.d.ts +4 -3
- package/lib/cjs/simulate/parsing/transfers.js +4 -6
- package/lib/cjs/simulate/pipeline/bundles-retention.d.ts +7 -10
- package/lib/cjs/simulate/pipeline/bundles-retention.js +11 -14
- package/lib/cjs/simulate/pipeline/resolve-chain.d.ts +5 -11
- package/lib/cjs/simulate/pipeline/resolve-chain.js +5 -10
- package/lib/cjs/simulate/plan/plan-execution.d.ts +58 -0
- package/lib/cjs/simulate/plan/plan-execution.js +75 -0
- package/lib/cjs/simulate/prepare.d.ts +30 -0
- package/lib/cjs/simulate/prepare.js +80 -0
- package/lib/cjs/simulate/request/index.d.ts +1 -0
- package/lib/cjs/simulate/request/index.js +5 -0
- package/lib/cjs/simulate/request/parse-request.d.ts +44 -0
- package/lib/cjs/simulate/request/parse-request.js +759 -0
- package/lib/cjs/simulate/result.d.ts +19 -0
- package/lib/cjs/simulate/result.js +29 -0
- package/lib/cjs/simulate/run-simulation.d.ts +18 -0
- package/lib/cjs/simulate/run-simulation.js +156 -0
- package/lib/cjs/simulate/simulate.d.ts +102 -51
- package/lib/cjs/simulate/simulate.js +101 -82
- package/lib/cjs/simulate/slippage.d.ts +18 -0
- package/lib/cjs/simulate/slippage.js +41 -0
- package/lib/cjs/simulate/state/contract.d.ts +19 -0
- package/lib/cjs/simulate/state/contract.js +2 -0
- package/lib/cjs/simulate/state/read-state.d.ts +60 -0
- package/lib/cjs/simulate/state/read-state.js +148 -0
- package/lib/cjs/simulate/verify-slippage.d.ts +24 -0
- package/lib/cjs/simulate/verify-slippage.js +85 -0
- package/lib/cjs/types.d.ts +37 -96
- package/lib/esm/authorizations.d.ts +95 -0
- package/lib/esm/authorizations.js +1 -0
- package/lib/esm/errors.d.ts +199 -12
- package/lib/esm/errors.js +182 -11
- package/lib/esm/index.d.ts +10 -2
- package/lib/esm/index.js +4 -1
- package/lib/esm/limits.d.ts +112 -0
- package/lib/esm/limits.js +47 -0
- package/lib/esm/params.d.ts +26 -0
- package/lib/esm/params.js +2 -0
- package/lib/esm/requirements/index.d.ts +1 -0
- package/lib/esm/requirements/index.js +1 -0
- package/lib/esm/requirements/requirements.d.ts +64 -0
- package/lib/esm/requirements/requirements.js +146 -0
- package/lib/esm/result.d.ts +49 -0
- package/lib/esm/result.js +1 -0
- package/lib/esm/simulate/asset-changes.d.ts +7 -5
- package/lib/esm/simulate/asset-changes.js +6 -5
- package/lib/esm/simulate/backends/client.d.ts +16 -0
- package/lib/esm/simulate/backends/client.js +24 -0
- package/lib/esm/simulate/backends/eth-simulate-v1.d.ts +69 -20
- package/lib/esm/simulate/backends/eth-simulate-v1.js +172 -99
- package/lib/esm/simulate/backends/index.d.ts +1 -2
- package/lib/esm/simulate/backends/index.js +1 -2
- package/lib/esm/simulate/backends/parse-response.d.ts +69 -0
- package/lib/esm/simulate/backends/parse-response.js +165 -0
- package/lib/esm/simulate/backends/resolve-assets.d.ts +26 -0
- package/lib/esm/simulate/backends/resolve-assets.js +108 -0
- package/lib/esm/simulate/backends/resolve-pinned-block.d.ts +33 -0
- package/lib/esm/simulate/backends/resolve-pinned-block.js +43 -0
- package/lib/esm/simulate/context.d.ts +14 -0
- package/lib/esm/simulate/context.js +1 -0
- package/lib/esm/simulate/measurement-plan.d.ts +29 -0
- package/lib/esm/simulate/measurement-plan.js +112 -0
- package/lib/esm/simulate/parsing/transfers.d.ts +4 -3
- package/lib/esm/simulate/parsing/transfers.js +4 -6
- package/lib/esm/simulate/pipeline/bundles-retention.d.ts +7 -10
- package/lib/esm/simulate/pipeline/bundles-retention.js +11 -14
- package/lib/esm/simulate/pipeline/resolve-chain.d.ts +5 -11
- package/lib/esm/simulate/pipeline/resolve-chain.js +5 -10
- package/lib/esm/simulate/plan/plan-execution.d.ts +58 -0
- package/lib/esm/simulate/plan/plan-execution.js +72 -0
- package/lib/esm/simulate/prepare.d.ts +30 -0
- package/lib/esm/simulate/prepare.js +77 -0
- package/lib/esm/simulate/request/index.d.ts +1 -0
- package/lib/esm/simulate/request/index.js +1 -0
- package/lib/esm/simulate/request/parse-request.d.ts +44 -0
- package/lib/esm/simulate/request/parse-request.js +756 -0
- package/lib/esm/simulate/result.d.ts +19 -0
- package/lib/esm/simulate/result.js +26 -0
- package/lib/esm/simulate/run-simulation.d.ts +18 -0
- package/lib/esm/simulate/run-simulation.js +153 -0
- package/lib/esm/simulate/simulate.d.ts +102 -51
- package/lib/esm/simulate/simulate.js +101 -82
- package/lib/esm/simulate/slippage.d.ts +18 -0
- package/lib/esm/simulate/slippage.js +38 -0
- package/lib/esm/simulate/state/contract.d.ts +19 -0
- package/lib/esm/simulate/state/contract.js +1 -0
- package/lib/esm/simulate/state/read-state.d.ts +60 -0
- package/lib/esm/simulate/state/read-state.js +144 -0
- package/lib/esm/simulate/verify-slippage.d.ts +24 -0
- package/lib/esm/simulate/verify-slippage.js +82 -0
- package/lib/esm/types.d.ts +37 -96
- package/package.json +7 -6
- package/lib/cjs/simulate/authorizations/index.d.ts +0 -2
- package/lib/cjs/simulate/authorizations/index.js +0 -7
- package/lib/cjs/simulate/authorizations/resolve.d.ts +0 -9
- package/lib/cjs/simulate/authorizations/resolve.js +0 -29
- package/lib/cjs/simulate/authorizations/validate.d.ts +0 -6
- package/lib/cjs/simulate/authorizations/validate.js +0 -23
- package/lib/cjs/simulate/backends/tenderly-rpc.d.ts +0 -23
- package/lib/cjs/simulate/backends/tenderly-rpc.js +0 -234
- package/lib/cjs/simulate/pipeline/build-simulation-txs.d.ts +0 -17
- package/lib/cjs/simulate/pipeline/build-simulation-txs.js +0 -50
- package/lib/cjs/simulate/pipeline/execute-simulation.d.ts +0 -22
- package/lib/cjs/simulate/pipeline/execute-simulation.js +0 -82
- package/lib/cjs/simulate/pipeline/index.d.ts +0 -4
- package/lib/cjs/simulate/pipeline/index.js +0 -11
- package/lib/cjs/simulate/pipeline/validate-input.d.ts +0 -10
- package/lib/cjs/simulate/pipeline/validate-input.js +0 -55
- package/lib/esm/simulate/authorizations/index.d.ts +0 -2
- package/lib/esm/simulate/authorizations/index.js +0 -2
- package/lib/esm/simulate/authorizations/resolve.d.ts +0 -9
- package/lib/esm/simulate/authorizations/resolve.js +0 -26
- package/lib/esm/simulate/authorizations/validate.d.ts +0 -6
- package/lib/esm/simulate/authorizations/validate.js +0 -20
- package/lib/esm/simulate/backends/tenderly-rpc.d.ts +0 -23
- package/lib/esm/simulate/backends/tenderly-rpc.js +0 -231
- package/lib/esm/simulate/pipeline/build-simulation-txs.d.ts +0 -17
- package/lib/esm/simulate/pipeline/build-simulation-txs.js +0 -47
- package/lib/esm/simulate/pipeline/execute-simulation.d.ts +0 -22
- package/lib/esm/simulate/pipeline/execute-simulation.js +0 -79
- package/lib/esm/simulate/pipeline/index.d.ts +0 -4
- package/lib/esm/simulate/pipeline/index.js +0 -4
- package/lib/esm/simulate/pipeline/validate-input.d.ts +0 -10
- package/lib/esm/simulate/pipeline/validate-input.js +0 -52
package/lib/cjs/errors.js
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnsupportedChainError = exports.SimulationValidationError = exports.ExternalServiceError = exports.BlacklistViolationError = exports.SimulationRevertedError = exports.SimulationPackageError = void 0;
|
|
3
|
+
exports.UnexpectedSimulationError = exports.ConsumerLimitViolationError = exports.AuthorizationRequestMismatchError = exports.MissingVerificationEvidenceError = exports.InvalidSimulationResponseError = exports.UnsupportedOperationError = exports.UnsupportedChainError = exports.SimulationValidationError = exports.ExternalServiceError = exports.BlacklistViolationError = exports.SimulationRevertedError = exports.SimulationPackageError = exports.SIMULATION_ERROR_CODES = void 0;
|
|
4
|
+
exports.isSimulationPackageError = isSimulationPackageError;
|
|
5
|
+
const limits_js_1 = require("./limits.js");
|
|
6
|
+
const params_js_1 = require("./params.js");
|
|
7
|
+
/** Stable error codes thrown by this package, part of the public API. */
|
|
8
|
+
exports.SIMULATION_ERROR_CODES = [
|
|
9
|
+
"VALIDATION_ERROR",
|
|
10
|
+
"UNSUPPORTED_CHAIN",
|
|
11
|
+
"EXTERNAL_SERVICE_ERROR",
|
|
12
|
+
"SIMULATION_REVERTED",
|
|
13
|
+
"BLACKLIST_ERROR",
|
|
14
|
+
"UNSUPPORTED_OPERATION",
|
|
15
|
+
"INVALID_SIMULATION_RESPONSE",
|
|
16
|
+
"MISSING_VERIFICATION_EVIDENCE",
|
|
17
|
+
"AUTHORIZATION_REQUEST_MISMATCH",
|
|
18
|
+
"CONSUMER_LIMIT_VIOLATION",
|
|
19
|
+
"UNEXPECTED_SIMULATION_ERROR",
|
|
20
|
+
];
|
|
21
|
+
const SIMULATION_STAGES = [
|
|
22
|
+
"validation",
|
|
23
|
+
"preparation",
|
|
24
|
+
"execution",
|
|
25
|
+
"verification",
|
|
26
|
+
"transport",
|
|
27
|
+
];
|
|
4
28
|
/**
|
|
5
29
|
* Base class for every error this package throws. Transport-agnostic — no HTTP status codes.
|
|
6
30
|
* Consumers pattern-match with `instanceof` on the concrete subclass.
|
|
7
31
|
*/
|
|
8
32
|
class SimulationPackageError extends Error {
|
|
33
|
+
/** Frozen copy of the failure context, when one was supplied. */
|
|
34
|
+
context;
|
|
9
35
|
constructor(message, options) {
|
|
10
|
-
|
|
11
|
-
|
|
36
|
+
const { context, ...errorOptions } = options ?? {};
|
|
37
|
+
super(message, errorOptions);
|
|
38
|
+
this.name = new.target.name;
|
|
39
|
+
if (context !== undefined) {
|
|
40
|
+
this.context = Object.freeze({ ...context });
|
|
41
|
+
}
|
|
12
42
|
}
|
|
13
43
|
}
|
|
14
44
|
exports.SimulationPackageError = SimulationPackageError;
|
|
@@ -16,11 +46,21 @@ exports.SimulationPackageError = SimulationPackageError;
|
|
|
16
46
|
class SimulationRevertedError extends SimulationPackageError {
|
|
17
47
|
reason;
|
|
18
48
|
details;
|
|
49
|
+
reasonCode;
|
|
50
|
+
name = "SimulationRevertedError";
|
|
19
51
|
code = "SIMULATION_REVERTED";
|
|
20
|
-
constructor
|
|
21
|
-
|
|
52
|
+
// biome-ignore lint/complexity/useMaxParams: public error constructor signature
|
|
53
|
+
constructor(
|
|
54
|
+
/** Raw revert string as reported by the backend, when any. */
|
|
55
|
+
reason, details,
|
|
56
|
+
/** Machine-readable cause; `UNKNOWN_REVERT` when the revert maps to no known Morpho condition. */
|
|
57
|
+
reasonCode = "UNKNOWN_REVERT",
|
|
58
|
+
/** Which transaction/authorization reverted and the operation it belonged to. */
|
|
59
|
+
context) {
|
|
60
|
+
super(reason ?? "Transaction simulation reverted", details instanceof Error ? { cause: details, context } : { context });
|
|
22
61
|
this.reason = reason;
|
|
23
62
|
this.details = details;
|
|
63
|
+
this.reasonCode = reasonCode;
|
|
24
64
|
}
|
|
25
65
|
}
|
|
26
66
|
exports.SimulationRevertedError = SimulationRevertedError;
|
|
@@ -31,26 +71,31 @@ exports.SimulationRevertedError = SimulationRevertedError;
|
|
|
31
71
|
*/
|
|
32
72
|
class BlacklistViolationError extends SimulationPackageError {
|
|
33
73
|
assetChanges;
|
|
74
|
+
name = "BlacklistViolationError";
|
|
34
75
|
code = "BLACKLIST_ERROR";
|
|
76
|
+
// biome-ignore lint/complexity/useMaxParams: public error constructor signature
|
|
35
77
|
constructor(message,
|
|
36
78
|
/** Per-asset net retained amounts keyed by restricted contract and token. */
|
|
37
|
-
assetChanges) {
|
|
38
|
-
super(message);
|
|
79
|
+
assetChanges, context) {
|
|
80
|
+
super(message, { context });
|
|
39
81
|
this.assetChanges = assetChanges;
|
|
40
82
|
}
|
|
41
83
|
}
|
|
42
84
|
exports.BlacklistViolationError = BlacklistViolationError;
|
|
43
|
-
/**
|
|
85
|
+
/** RPC service is down or unreachable. Bypassable — user can proceed. */
|
|
44
86
|
class ExternalServiceError extends SimulationPackageError {
|
|
87
|
+
name = "ExternalServiceError";
|
|
45
88
|
code = "EXTERNAL_SERVICE_ERROR";
|
|
46
89
|
}
|
|
47
90
|
exports.ExternalServiceError = ExternalServiceError;
|
|
48
91
|
/** Bad input to the simulation functions. Not bypassable. */
|
|
49
92
|
class SimulationValidationError extends SimulationPackageError {
|
|
50
93
|
fieldErrors;
|
|
94
|
+
name = "SimulationValidationError";
|
|
51
95
|
code = "VALIDATION_ERROR";
|
|
52
|
-
constructor
|
|
53
|
-
|
|
96
|
+
// biome-ignore lint/complexity/useMaxParams: public error constructor signature
|
|
97
|
+
constructor(message, fieldErrors, context) {
|
|
98
|
+
super(message, { context });
|
|
54
99
|
this.fieldErrors = fieldErrors;
|
|
55
100
|
}
|
|
56
101
|
}
|
|
@@ -58,10 +103,143 @@ exports.SimulationValidationError = SimulationValidationError;
|
|
|
58
103
|
/** Chain ID not configured for any simulation method. Not bypassable. */
|
|
59
104
|
class UnsupportedChainError extends SimulationPackageError {
|
|
60
105
|
chainId;
|
|
106
|
+
name = "UnsupportedChainError";
|
|
61
107
|
code = "UNSUPPORTED_CHAIN";
|
|
62
|
-
constructor(chainId) {
|
|
63
|
-
super(`Chain ${chainId} is not configured for simulation
|
|
108
|
+
constructor(chainId, context) {
|
|
109
|
+
super(`Chain ${chainId} is not configured for simulation`, { context });
|
|
64
110
|
this.chainId = chainId;
|
|
65
111
|
}
|
|
66
112
|
}
|
|
67
113
|
exports.UnsupportedChainError = UnsupportedChainError;
|
|
114
|
+
/**
|
|
115
|
+
* An SDK requirement passed to `toSimulationAuthorizations` cannot be
|
|
116
|
+
* converted into a simulation authorization.
|
|
117
|
+
*/
|
|
118
|
+
class UnsupportedOperationError extends SimulationPackageError {
|
|
119
|
+
name = "UnsupportedOperationError";
|
|
120
|
+
code = "UNSUPPORTED_OPERATION";
|
|
121
|
+
}
|
|
122
|
+
exports.UnsupportedOperationError = UnsupportedOperationError;
|
|
123
|
+
/** The simulation backend returned a response that cannot be parsed. */
|
|
124
|
+
class InvalidSimulationResponseError extends SimulationPackageError {
|
|
125
|
+
name = "InvalidSimulationResponseError";
|
|
126
|
+
code = "INVALID_SIMULATION_RESPONSE";
|
|
127
|
+
}
|
|
128
|
+
exports.InvalidSimulationResponseError = InvalidSimulationResponseError;
|
|
129
|
+
/** State needed to verify an operation could not be fetched or derived. */
|
|
130
|
+
class MissingVerificationEvidenceError extends SimulationPackageError {
|
|
131
|
+
name = "MissingVerificationEvidenceError";
|
|
132
|
+
code = "MISSING_VERIFICATION_EVIDENCE";
|
|
133
|
+
}
|
|
134
|
+
exports.MissingVerificationEvidenceError = MissingVerificationEvidenceError;
|
|
135
|
+
/** A pending authorization does not match the request it was prepared for. */
|
|
136
|
+
class AuthorizationRequestMismatchError extends SimulationPackageError {
|
|
137
|
+
name = "AuthorizationRequestMismatchError";
|
|
138
|
+
code = "AUTHORIZATION_REQUEST_MISMATCH";
|
|
139
|
+
}
|
|
140
|
+
exports.AuthorizationRequestMismatchError = AuthorizationRequestMismatchError;
|
|
141
|
+
/** A consumer-supplied limit was violated. */
|
|
142
|
+
class ConsumerLimitViolationError extends SimulationPackageError {
|
|
143
|
+
name = "ConsumerLimitViolationError";
|
|
144
|
+
code = "CONSUMER_LIMIT_VIOLATION";
|
|
145
|
+
}
|
|
146
|
+
exports.ConsumerLimitViolationError = ConsumerLimitViolationError;
|
|
147
|
+
/** The simulation failed for a reason that fits no other code. */
|
|
148
|
+
class UnexpectedSimulationError extends SimulationPackageError {
|
|
149
|
+
name = "UnexpectedSimulationError";
|
|
150
|
+
code = "UNEXPECTED_SIMULATION_ERROR";
|
|
151
|
+
}
|
|
152
|
+
exports.UnexpectedSimulationError = UnexpectedSimulationError;
|
|
153
|
+
const ERROR_NAME_BY_CODE = Object.freeze({
|
|
154
|
+
VALIDATION_ERROR: "SimulationValidationError",
|
|
155
|
+
UNSUPPORTED_CHAIN: "UnsupportedChainError",
|
|
156
|
+
EXTERNAL_SERVICE_ERROR: "ExternalServiceError",
|
|
157
|
+
SIMULATION_REVERTED: "SimulationRevertedError",
|
|
158
|
+
BLACKLIST_ERROR: "BlacklistViolationError",
|
|
159
|
+
UNSUPPORTED_OPERATION: "UnsupportedOperationError",
|
|
160
|
+
INVALID_SIMULATION_RESPONSE: "InvalidSimulationResponseError",
|
|
161
|
+
MISSING_VERIFICATION_EVIDENCE: "MissingVerificationEvidenceError",
|
|
162
|
+
AUTHORIZATION_REQUEST_MISMATCH: "AuthorizationRequestMismatchError",
|
|
163
|
+
CONSUMER_LIMIT_VIOLATION: "ConsumerLimitViolationError",
|
|
164
|
+
UNEXPECTED_SIMULATION_ERROR: "UnexpectedSimulationError",
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* Structural guard for consumers where `instanceof` fails across bundles.
|
|
168
|
+
*
|
|
169
|
+
* @param value - Anything caught.
|
|
170
|
+
* @returns `true` for `SimulationPackageError` instances and for objects
|
|
171
|
+
* carrying a `message` string, a known `code`, the `name` of the class
|
|
172
|
+
* owning that `code`, and an absent or
|
|
173
|
+
* well-formed `context` (known `stage`, `mode`, numeric `chainId`,
|
|
174
|
+
* `bigint` `blockNumber`, `authorizationIndex` for `preparation`, and a
|
|
175
|
+
* known `operation` with its subject fields for `execution`/`verification`,
|
|
176
|
+
* or a verification `field` string with no `operation`).
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { isSimulationPackageError, simulate } from "@morpho-org/evm-simulation";
|
|
180
|
+
* import type { Address, Hex } from "viem";
|
|
181
|
+
*
|
|
182
|
+
* declare const user: Address;
|
|
183
|
+
* declare const vault: Address;
|
|
184
|
+
* declare const encodedDeposit: Hex;
|
|
185
|
+
* const config = {
|
|
186
|
+
* chains: new Map([[1, { simulateV1Url: "https://rpc.example" }]]),
|
|
187
|
+
* };
|
|
188
|
+
* try {
|
|
189
|
+
* await simulate(config, {
|
|
190
|
+
* chainId: 1,
|
|
191
|
+
* transactions: [{ from: user, to: vault, data: encodedDeposit }],
|
|
192
|
+
* });
|
|
193
|
+
* } catch (e) {
|
|
194
|
+
* if (!isSimulationPackageError(e)) throw e;
|
|
195
|
+
* if (e.code !== "SIMULATION_REVERTED") throw e;
|
|
196
|
+
* console.log(e.context?.stage, e.message);
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
function isSimulationPackageError(value) {
|
|
201
|
+
if (value instanceof SimulationPackageError)
|
|
202
|
+
return true;
|
|
203
|
+
if (typeof value !== "object" || value === null)
|
|
204
|
+
return false;
|
|
205
|
+
const { name, message, code, context } = value;
|
|
206
|
+
if (typeof message !== "string")
|
|
207
|
+
return false;
|
|
208
|
+
if (typeof code !== "string" ||
|
|
209
|
+
!exports.SIMULATION_ERROR_CODES.includes(code) ||
|
|
210
|
+
name !== ERROR_NAME_BY_CODE[code])
|
|
211
|
+
return false;
|
|
212
|
+
if (context === undefined)
|
|
213
|
+
return true;
|
|
214
|
+
if (typeof context !== "object" || context === null || Array.isArray(context))
|
|
215
|
+
return false;
|
|
216
|
+
const { stage, mode, chainId, blockNumber, authorizationIndex } = context;
|
|
217
|
+
if (typeof stage !== "string" ||
|
|
218
|
+
!SIMULATION_STAGES.includes(stage) ||
|
|
219
|
+
typeof mode !== "string" ||
|
|
220
|
+
!params_js_1.SIMULATION_MODES.includes(mode) ||
|
|
221
|
+
typeof chainId !== "number" ||
|
|
222
|
+
typeof blockNumber !== "bigint")
|
|
223
|
+
return false;
|
|
224
|
+
const c = context;
|
|
225
|
+
if (stage === "preparation")
|
|
226
|
+
return typeof authorizationIndex === "number";
|
|
227
|
+
if (stage === "verification" && c.operation === undefined)
|
|
228
|
+
return typeof c.field === "string";
|
|
229
|
+
if (stage !== "execution" && stage !== "verification")
|
|
230
|
+
return true;
|
|
231
|
+
const operation = c.operation;
|
|
232
|
+
if (typeof operation !== "string" ||
|
|
233
|
+
!limits_js_1.OPERATION_TYPES.includes(operation))
|
|
234
|
+
return false;
|
|
235
|
+
const isString = (key) => typeof c[key] === "string";
|
|
236
|
+
if (operation === "blueRefinance")
|
|
237
|
+
return isString("sourceMarketId") && isString("targetMarketId");
|
|
238
|
+
if (operation === "vaultV1MigrateToV2")
|
|
239
|
+
return isString("sourceVault") && isString("targetVault");
|
|
240
|
+
if (limits_js_1.BLUE_MARKET_OPERATION_TYPES.includes(operation))
|
|
241
|
+
return isString("marketId");
|
|
242
|
+
if (limits_js_1.VAULT_OPERATION_TYPES.includes(operation))
|
|
243
|
+
return isString("vault");
|
|
244
|
+
return false;
|
|
245
|
+
}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { BlueAuthorization, BlueAuthorizationSignature, BlueAuthorizationTypedData, Eip712Domain, Eip712Field, Erc20ApprovalAuthorization, Erc2612PermitAuthorization, Erc2612PermitTypedData, Permit2TransferAuthorization, Permit2TransferTypedData, SimulationAuthorization, } from "./authorizations.js";
|
|
2
|
+
export type { RetainedAsset, SimulationErrorCode, SimulationErrorContext, SimulationExecutionContext, SimulationExecutionReason, SimulationPreparationContext, SimulationStage, SimulationTransportContext, SimulationValidationContext, SimulationVerificationContext, } from "./errors.js";
|
|
3
|
+
export { AuthorizationRequestMismatchError, BlacklistViolationError, ConsumerLimitViolationError, ExternalServiceError, InvalidSimulationResponseError, isSimulationPackageError, MissingVerificationEvidenceError, SIMULATION_ERROR_CODES, SimulationPackageError, SimulationRevertedError, SimulationValidationError, UnexpectedSimulationError, UnsupportedChainError, UnsupportedOperationError, } from "./errors.js";
|
|
4
|
+
export type { BlueMarketOperationSubject, BlueMarketOperationType, BlueRefinanceSubject, OperationLimit, OperationType, SimulationLimits, SimulationOperationSubject, SlippageLimits, SlippageQuote, VaultOperationSubject, VaultOperationType, VaultV1MigrateToV2Subject, } from "./limits.js";
|
|
5
|
+
export { BLUE_MARKET_OPERATION_TYPES, OPERATION_TYPES, VAULT_OPERATION_TYPES, } from "./limits.js";
|
|
6
|
+
export type { SimulateParams, SimulationMode, } from "./params.js";
|
|
7
|
+
export { SIMULATION_MODES } from "./params.js";
|
|
8
|
+
export { toSimulationAuthorizations } from "./requirements/index.js";
|
|
9
|
+
export type { AuthorizationPreparation, SimulatedOperation, SimulationVerification, VerifiedSimulationResult, } from "./result.js";
|
|
2
10
|
export { simulate } from "./simulate/index.js";
|
|
3
|
-
export type { AccountAssetChanges, AssetChange, ChainSimulationConfig, RawLog,
|
|
11
|
+
export type { AccountAssetChanges, AssetChange, ChainSimulationConfig, RawLog, SimulationCall, SimulationConfig, SimulationLogger, SimulationResult, SimulationTransaction, Transfer, } from "./types.js";
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Public fns (via feature-folder barrels)
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.simulate = exports.UnsupportedChainError = exports.SimulationValidationError = exports.SimulationRevertedError = exports.SimulationPackageError = exports.ExternalServiceError = exports.BlacklistViolationError = void 0;
|
|
4
|
+
exports.simulate = exports.toSimulationAuthorizations = exports.SIMULATION_MODES = exports.VAULT_OPERATION_TYPES = exports.OPERATION_TYPES = exports.BLUE_MARKET_OPERATION_TYPES = exports.UnsupportedOperationError = exports.UnsupportedChainError = exports.UnexpectedSimulationError = exports.SimulationValidationError = exports.SimulationRevertedError = exports.SimulationPackageError = exports.SIMULATION_ERROR_CODES = exports.MissingVerificationEvidenceError = exports.isSimulationPackageError = exports.InvalidSimulationResponseError = exports.ExternalServiceError = exports.ConsumerLimitViolationError = exports.BlacklistViolationError = exports.AuthorizationRequestMismatchError = void 0;
|
|
5
5
|
// Errors (for instanceof checks by consumers)
|
|
6
6
|
var errors_js_1 = require("./errors.js");
|
|
7
|
+
Object.defineProperty(exports, "AuthorizationRequestMismatchError", { enumerable: true, get: function () { return errors_js_1.AuthorizationRequestMismatchError; } });
|
|
7
8
|
Object.defineProperty(exports, "BlacklistViolationError", { enumerable: true, get: function () { return errors_js_1.BlacklistViolationError; } });
|
|
9
|
+
Object.defineProperty(exports, "ConsumerLimitViolationError", { enumerable: true, get: function () { return errors_js_1.ConsumerLimitViolationError; } });
|
|
8
10
|
Object.defineProperty(exports, "ExternalServiceError", { enumerable: true, get: function () { return errors_js_1.ExternalServiceError; } });
|
|
11
|
+
Object.defineProperty(exports, "InvalidSimulationResponseError", { enumerable: true, get: function () { return errors_js_1.InvalidSimulationResponseError; } });
|
|
12
|
+
Object.defineProperty(exports, "isSimulationPackageError", { enumerable: true, get: function () { return errors_js_1.isSimulationPackageError; } });
|
|
13
|
+
Object.defineProperty(exports, "MissingVerificationEvidenceError", { enumerable: true, get: function () { return errors_js_1.MissingVerificationEvidenceError; } });
|
|
14
|
+
Object.defineProperty(exports, "SIMULATION_ERROR_CODES", { enumerable: true, get: function () { return errors_js_1.SIMULATION_ERROR_CODES; } });
|
|
9
15
|
Object.defineProperty(exports, "SimulationPackageError", { enumerable: true, get: function () { return errors_js_1.SimulationPackageError; } });
|
|
10
16
|
Object.defineProperty(exports, "SimulationRevertedError", { enumerable: true, get: function () { return errors_js_1.SimulationRevertedError; } });
|
|
11
17
|
Object.defineProperty(exports, "SimulationValidationError", { enumerable: true, get: function () { return errors_js_1.SimulationValidationError; } });
|
|
18
|
+
Object.defineProperty(exports, "UnexpectedSimulationError", { enumerable: true, get: function () { return errors_js_1.UnexpectedSimulationError; } });
|
|
12
19
|
Object.defineProperty(exports, "UnsupportedChainError", { enumerable: true, get: function () { return errors_js_1.UnsupportedChainError; } });
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
Object.defineProperty(exports, "UnsupportedOperationError", { enumerable: true, get: function () { return errors_js_1.UnsupportedOperationError; } });
|
|
21
|
+
var limits_js_1 = require("./limits.js");
|
|
22
|
+
Object.defineProperty(exports, "BLUE_MARKET_OPERATION_TYPES", { enumerable: true, get: function () { return limits_js_1.BLUE_MARKET_OPERATION_TYPES; } });
|
|
23
|
+
Object.defineProperty(exports, "OPERATION_TYPES", { enumerable: true, get: function () { return limits_js_1.OPERATION_TYPES; } });
|
|
24
|
+
Object.defineProperty(exports, "VAULT_OPERATION_TYPES", { enumerable: true, get: function () { return limits_js_1.VAULT_OPERATION_TYPES; } });
|
|
25
|
+
var params_js_1 = require("./params.js");
|
|
26
|
+
Object.defineProperty(exports, "SIMULATION_MODES", { enumerable: true, get: function () { return params_js_1.SIMULATION_MODES; } });
|
|
27
|
+
var index_js_1 = require("./requirements/index.js");
|
|
28
|
+
Object.defineProperty(exports, "toSimulationAuthorizations", { enumerable: true, get: function () { return index_js_1.toSimulationAuthorizations; } });
|
|
29
|
+
var index_js_2 = require("./simulate/index.js");
|
|
30
|
+
Object.defineProperty(exports, "simulate", { enumerable: true, get: function () { return index_js_2.simulate; } });
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
/** Every operation type; source of `OperationType`. */
|
|
4
|
+
export declare const OPERATION_TYPES: readonly ["blueSupply", "blueWithdraw", "blueSupplyCollateral", "blueBorrow", "blueSupplyCollateralBorrow", "blueRepay", "blueWithdrawCollateral", "blueRepayWithdrawCollateral", "blueRefinance", "vaultV1Deposit", "vaultV2Deposit", "vaultV1Withdraw", "vaultV2Withdraw", "vaultV1Redeem", "vaultV2Redeem", "vaultV2ForceWithdraw", "vaultV2ForceRedeem", "vaultV1InKindRedeem", "vaultV2InKindRedeem", "vaultV1MigrateToV2"];
|
|
5
|
+
/** Discriminator for operations and their limits. */
|
|
6
|
+
export type OperationType = (typeof OPERATION_TYPES)[number];
|
|
7
|
+
/** Operations acting on one Blue market; source of `BlueMarketOperationType`. */
|
|
8
|
+
export declare const BLUE_MARKET_OPERATION_TYPES: readonly ["blueSupply", "blueWithdraw", "blueSupplyCollateral", "blueBorrow", "blueSupplyCollateralBorrow", "blueRepay", "blueWithdrawCollateral", "blueRepayWithdrawCollateral"];
|
|
9
|
+
/** Operations acting on one Blue market. */
|
|
10
|
+
export type BlueMarketOperationType = (typeof BLUE_MARKET_OPERATION_TYPES)[number];
|
|
11
|
+
/** Operations acting on one vault (V1 or V2); source of `VaultOperationType`. */
|
|
12
|
+
export declare const VAULT_OPERATION_TYPES: readonly ["vaultV1Deposit", "vaultV2Deposit", "vaultV1Withdraw", "vaultV2Withdraw", "vaultV1Redeem", "vaultV2Redeem", "vaultV2ForceWithdraw", "vaultV2ForceRedeem", "vaultV1InKindRedeem", "vaultV2InKindRedeem"];
|
|
13
|
+
/** Operations acting on one vault (V1 or V2). */
|
|
14
|
+
export type VaultOperationType = (typeof VAULT_OPERATION_TYPES)[number];
|
|
15
|
+
/** Subject of an operation acting on one Blue market. */
|
|
16
|
+
export interface BlueMarketOperationSubject {
|
|
17
|
+
readonly operation: BlueMarketOperationType;
|
|
18
|
+
/** Blue market the operation acts on. */
|
|
19
|
+
readonly marketId: MarketId;
|
|
20
|
+
}
|
|
21
|
+
/** Subject of a Blue refinance between two markets. */
|
|
22
|
+
export interface BlueRefinanceSubject {
|
|
23
|
+
readonly operation: "blueRefinance";
|
|
24
|
+
/** Market the refinance closes. */
|
|
25
|
+
readonly sourceMarketId: MarketId;
|
|
26
|
+
/** Market the refinance opens. */
|
|
27
|
+
readonly targetMarketId: MarketId;
|
|
28
|
+
}
|
|
29
|
+
/** Subject of an operation acting on one vault (V1 or V2). */
|
|
30
|
+
export interface VaultOperationSubject {
|
|
31
|
+
readonly operation: VaultOperationType;
|
|
32
|
+
/** Vault the operation acts on. */
|
|
33
|
+
readonly vault: Address;
|
|
34
|
+
}
|
|
35
|
+
/** Subject of a Vault V1 → V2 migration. */
|
|
36
|
+
export interface VaultV1MigrateToV2Subject {
|
|
37
|
+
readonly operation: "vaultV1MigrateToV2";
|
|
38
|
+
/** Vault the migration exits. */
|
|
39
|
+
readonly sourceVault: Address;
|
|
40
|
+
/** Vault the migration enters. */
|
|
41
|
+
readonly targetVault: Address;
|
|
42
|
+
}
|
|
43
|
+
/** Protocol entity a limit's operation acts on, keyed by `operation`; shared by `SimulatedOperation` and the verification error context. */
|
|
44
|
+
export type SimulationOperationSubject = BlueMarketOperationSubject | BlueRefinanceSubject | VaultOperationSubject | VaultV1MigrateToV2Subject;
|
|
45
|
+
/** Caller-quoted net amounts in raw units over the whole bundle.
|
|
46
|
+
* Supply at least one amount. Unquoted amounts are not checked.
|
|
47
|
+
*/
|
|
48
|
+
export interface SlippageQuote {
|
|
49
|
+
/**
|
|
50
|
+
* Expected net assets credited to the receiver. For in-kind vault redemptions,
|
|
51
|
+
* this measures only the wallet balance of the vault asset, not Morpho positions.
|
|
52
|
+
*/
|
|
53
|
+
readonly assetsReceived?: bigint;
|
|
54
|
+
/**
|
|
55
|
+
* Expected net shares added to the position. For debt shares, this is a
|
|
56
|
+
* maximum: minting more debt shares than quoted is adverse.
|
|
57
|
+
*/
|
|
58
|
+
readonly sharesMinted?: bigint;
|
|
59
|
+
/** Expected net assets debited from the sender. */
|
|
60
|
+
readonly assetsPaid?: bigint;
|
|
61
|
+
/**
|
|
62
|
+
* Expected net shares removed from the position. For debt shares, this is a
|
|
63
|
+
* minimum: burning fewer debt shares than quoted is adverse.
|
|
64
|
+
*/
|
|
65
|
+
readonly sharesBurned?: bigint;
|
|
66
|
+
}
|
|
67
|
+
/** Caller quote and permitted adverse percentage deviation. */
|
|
68
|
+
export interface SlippageLimits {
|
|
69
|
+
readonly quote: SlippageQuote;
|
|
70
|
+
/** WAD-scaled fraction from 0 to 1e18 inclusive; 1e16 means 1%. No default. */
|
|
71
|
+
readonly slippageTolerance: bigint;
|
|
72
|
+
}
|
|
73
|
+
/** Caller-selected action and subject with the same quote/tolerance shape for every action.
|
|
74
|
+
* Measurements cover the entire bundle for the named subject, never an inferred
|
|
75
|
+
* individual transaction. Use separate simulations for per-transaction bounds.
|
|
76
|
+
*/
|
|
77
|
+
export type OperationLimit = SlippageLimits & {
|
|
78
|
+
/** Position/share owner; defaults to the transaction sender. */
|
|
79
|
+
readonly account?: Address;
|
|
80
|
+
/**
|
|
81
|
+
* Explicit asset paid; defaults to the action underlying. Use viem's
|
|
82
|
+
* `ethAddress` (`0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) for native ETH;
|
|
83
|
+
* sentinels such as `zeroAddress` are read as ERC-20 tokens.
|
|
84
|
+
*/
|
|
85
|
+
readonly assetPaid?: Address;
|
|
86
|
+
/**
|
|
87
|
+
* Explicit asset received; defaults to the action underlying. Use viem's
|
|
88
|
+
* `ethAddress` (`0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`) for native ETH;
|
|
89
|
+
* sentinels such as `zeroAddress` are read as ERC-20 tokens.
|
|
90
|
+
*/
|
|
91
|
+
readonly assetReceived?: Address;
|
|
92
|
+
/** Asset receiver; defaults to the transaction sender. */
|
|
93
|
+
readonly receiver?: Address;
|
|
94
|
+
} & ({
|
|
95
|
+
readonly type: BlueMarketOperationType;
|
|
96
|
+
readonly marketId: MarketId;
|
|
97
|
+
} | {
|
|
98
|
+
readonly type: "blueRefinance";
|
|
99
|
+
readonly sourceMarketId: MarketId;
|
|
100
|
+
readonly targetMarketId: MarketId;
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: VaultOperationType;
|
|
103
|
+
readonly vault: Address;
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "vaultV1MigrateToV2";
|
|
106
|
+
readonly sourceVault: Address;
|
|
107
|
+
readonly targetVault: Address;
|
|
108
|
+
});
|
|
109
|
+
/** Optional caller-selected checks. No action discovery or default bounds. */
|
|
110
|
+
export interface SimulationLimits {
|
|
111
|
+
readonly operations?: readonly OperationLimit[];
|
|
112
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VAULT_OPERATION_TYPES = exports.BLUE_MARKET_OPERATION_TYPES = exports.OPERATION_TYPES = void 0;
|
|
4
|
+
/** Every operation type; source of `OperationType`. */
|
|
5
|
+
exports.OPERATION_TYPES = [
|
|
6
|
+
"blueSupply",
|
|
7
|
+
"blueWithdraw",
|
|
8
|
+
"blueSupplyCollateral",
|
|
9
|
+
"blueBorrow",
|
|
10
|
+
"blueSupplyCollateralBorrow",
|
|
11
|
+
"blueRepay",
|
|
12
|
+
"blueWithdrawCollateral",
|
|
13
|
+
"blueRepayWithdrawCollateral",
|
|
14
|
+
"blueRefinance",
|
|
15
|
+
"vaultV1Deposit",
|
|
16
|
+
"vaultV2Deposit",
|
|
17
|
+
"vaultV1Withdraw",
|
|
18
|
+
"vaultV2Withdraw",
|
|
19
|
+
"vaultV1Redeem",
|
|
20
|
+
"vaultV2Redeem",
|
|
21
|
+
"vaultV2ForceWithdraw",
|
|
22
|
+
"vaultV2ForceRedeem",
|
|
23
|
+
"vaultV1InKindRedeem",
|
|
24
|
+
"vaultV2InKindRedeem",
|
|
25
|
+
"vaultV1MigrateToV2",
|
|
26
|
+
];
|
|
27
|
+
/** Operations acting on one Blue market; source of `BlueMarketOperationType`. */
|
|
28
|
+
exports.BLUE_MARKET_OPERATION_TYPES = [
|
|
29
|
+
"blueSupply",
|
|
30
|
+
"blueWithdraw",
|
|
31
|
+
"blueSupplyCollateral",
|
|
32
|
+
"blueBorrow",
|
|
33
|
+
"blueSupplyCollateralBorrow",
|
|
34
|
+
"blueRepay",
|
|
35
|
+
"blueWithdrawCollateral",
|
|
36
|
+
"blueRepayWithdrawCollateral",
|
|
37
|
+
];
|
|
38
|
+
/** Operations acting on one vault (V1 or V2); source of `VaultOperationType`. */
|
|
39
|
+
exports.VAULT_OPERATION_TYPES = [
|
|
40
|
+
"vaultV1Deposit",
|
|
41
|
+
"vaultV2Deposit",
|
|
42
|
+
"vaultV1Withdraw",
|
|
43
|
+
"vaultV2Withdraw",
|
|
44
|
+
"vaultV1Redeem",
|
|
45
|
+
"vaultV2Redeem",
|
|
46
|
+
"vaultV2ForceWithdraw",
|
|
47
|
+
"vaultV2ForceRedeem",
|
|
48
|
+
"vaultV1InKindRedeem",
|
|
49
|
+
"vaultV2InKindRedeem",
|
|
50
|
+
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BlockTag } from "viem";
|
|
2
|
+
import type { SimulationAuthorization } from "./authorizations.js";
|
|
3
|
+
import type { SimulationLimits } from "./limits.js";
|
|
4
|
+
import type { SimulationTransaction } from "./types.js";
|
|
5
|
+
/** Every simulation mode; source of `SimulationMode`. */
|
|
6
|
+
export declare const SIMULATION_MODES: readonly ["preview", "final"];
|
|
7
|
+
/** Simulation mode: `"preview"` accepts pending authorizations, `"final"` does not. */
|
|
8
|
+
export type SimulationMode = (typeof SIMULATION_MODES)[number];
|
|
9
|
+
/**
|
|
10
|
+
* Input to `simulate()`. `authorizations` is accepted only in "preview";
|
|
11
|
+
* `mode` defaults to "final".
|
|
12
|
+
*/
|
|
13
|
+
export interface SimulateParams {
|
|
14
|
+
readonly chainId: number;
|
|
15
|
+
readonly transactions: readonly SimulationTransaction[];
|
|
16
|
+
/** Defaults to "final". */
|
|
17
|
+
readonly mode?: SimulationMode;
|
|
18
|
+
/** Pending wallet requests, in order. Preview only; rejected in final. */
|
|
19
|
+
readonly authorizations?: readonly SimulationAuthorization[];
|
|
20
|
+
/** Resolved once; defaults to "latest" ("finalized" on Monad, whose
|
|
21
|
+
* "latest" block is not final). Only canonical (mined) blocks can be
|
|
22
|
+
* pinned; `pending` has no stable hash and is rejected at runtime. */
|
|
23
|
+
readonly blockNumber?: bigint | Exclude<BlockTag, "pending">;
|
|
24
|
+
/** Caller-selected quotes and percentage tolerances. Omitted limits are unchecked. */
|
|
25
|
+
readonly limits?: SimulationLimits;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { toSimulationAuthorizations } from "./requirements.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSimulationAuthorizations = void 0;
|
|
4
|
+
var requirements_js_1 = require("./requirements.js");
|
|
5
|
+
Object.defineProperty(exports, "toSimulationAuthorizations", { enumerable: true, get: function () { return requirements_js_1.toSimulationAuthorizations; } });
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ActionRequirement } from "@morpho-org/morpho-sdk";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import type { SimulationAuthorization } from "../authorizations.js";
|
|
4
|
+
import type { SimulationMode } from "../params.js";
|
|
5
|
+
/**
|
|
6
|
+
* Maps morpho-sdk action requirements, in order, onto simulation authorization descriptors.
|
|
7
|
+
*
|
|
8
|
+
* The adapter is a pure mapper — nothing is decoded or validated; `simulate()`'s request parser
|
|
9
|
+
* validates each authorization's shape and semantics when the request is parsed. Call requirements
|
|
10
|
+
* (`erc20Approval`, `blueAuthorization`) are mapped straight from `action.args` (the approval
|
|
11
|
+
* token is the requirement's `to`). Signature requirements (`permit`,
|
|
12
|
+
* `permit2SignatureTransfer`, `authorization`) carry their EIP-712 payload through unchanged; a
|
|
13
|
+
* missing payload throws {@link AuthorizationRequestMismatchError}. Any other requirement type
|
|
14
|
+
* throws {@link UnsupportedOperationError}.
|
|
15
|
+
*
|
|
16
|
+
* The function is pure and synchronous: no RPC reads, no clock, no signing.
|
|
17
|
+
*
|
|
18
|
+
* @param params - Mapping parameters.
|
|
19
|
+
* @param params.chainId - The chain the requirements were resolved on; carried into error contexts.
|
|
20
|
+
* @param params.mode - Simulation mode carried into error contexts (`"preview"` or `"final"`).
|
|
21
|
+
* @param params.blockNumber - Pinned block the simulation is verified against; carried into error contexts.
|
|
22
|
+
* @param params.owner - The account the requirements were resolved for (transaction sender).
|
|
23
|
+
* @param params.requirements - Requirements returned by `ActionOutput.getRequirements()`.
|
|
24
|
+
* @returns One {@link SimulationAuthorization} per input requirement, in the same order.
|
|
25
|
+
* @throws {AuthorizationRequestMismatchError} when a signature requirement carries no `typedData`.
|
|
26
|
+
* @throws {UnsupportedOperationError} when a requirement's action type is not a supported
|
|
27
|
+
* authorization.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { toSimulationAuthorizations } from "@morpho-org/evm-simulation";
|
|
31
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
32
|
+
* import { vaults } from "@morpho-org/morpho-test";
|
|
33
|
+
* import { createPublicClient, http, type Address } from "viem";
|
|
34
|
+
* import { mainnet } from "viem/chains";
|
|
35
|
+
*
|
|
36
|
+
* async function prepare(userAddress: Address, blockNumber: bigint) {
|
|
37
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
38
|
+
* .extend(morphoViemExtension());
|
|
39
|
+
* const vault = client.morpho.vaultV1(
|
|
40
|
+
* vaults[mainnet.id].steakUsdc.address,
|
|
41
|
+
* mainnet.id,
|
|
42
|
+
* );
|
|
43
|
+
* const vaultData = await vault.getData();
|
|
44
|
+
* const requirements = await vault
|
|
45
|
+
* .deposit({ amount: 1_000_000n, userAddress, vaultData })
|
|
46
|
+
* .getRequirements();
|
|
47
|
+
* const authorizations = toSimulationAuthorizations({
|
|
48
|
+
* chainId: mainnet.id,
|
|
49
|
+
* mode: "final",
|
|
50
|
+
* blockNumber,
|
|
51
|
+
* owner: userAddress,
|
|
52
|
+
* requirements,
|
|
53
|
+
* });
|
|
54
|
+
* return authorizations; // readonly SimulationAuthorization[], one entry per requirement
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function toSimulationAuthorizations(params: {
|
|
59
|
+
readonly chainId: number;
|
|
60
|
+
readonly mode: SimulationMode;
|
|
61
|
+
readonly blockNumber: bigint;
|
|
62
|
+
readonly owner: Address;
|
|
63
|
+
readonly requirements: readonly ActionRequirement[];
|
|
64
|
+
}): readonly SimulationAuthorization[];
|