viem-tx-sim 0.1.1 → 0.2.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/README.md +103 -34
- package/contracts/TxSimulator.sol +83 -20
- package/dist/generated/txSimulatorBytecode.d.ts +1 -1
- package/dist/generated/txSimulatorBytecode.d.ts.map +1 -1
- package/dist/generated/txSimulatorBytecode.js +1 -1
- package/dist/generated/txSimulatorBytecode.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/queryDiscovery.d.ts +8 -0
- package/dist/internal/queryDiscovery.d.ts.map +1 -0
- package/dist/internal/queryDiscovery.js +38 -0
- package/dist/internal/queryDiscovery.js.map +1 -0
- package/dist/internal/requirements.d.ts +2 -1
- package/dist/internal/requirements.d.ts.map +1 -1
- package/dist/internal/requirements.js +2 -1
- package/dist/internal/requirements.js.map +1 -1
- package/dist/internal/simulator.d.ts +19 -3
- package/dist/internal/simulator.d.ts.map +1 -1
- package/dist/internal/simulator.js +12 -16
- package/dist/internal/simulator.js.map +1 -1
- package/dist/internal/slots.d.ts +4 -2
- package/dist/internal/slots.d.ts.map +1 -1
- package/dist/internal/slots.js +4 -2
- package/dist/internal/slots.js.map +1 -1
- package/dist/txSimulator.d.ts +64 -40
- package/dist/txSimulator.d.ts.map +1 -1
- package/dist/txSimulator.js +64 -16
- package/dist/txSimulator.js.map +1 -1
- package/dist/types.d.ts +47 -16
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/generated/txSimulatorBytecode.ts +1 -1
- package/src/index.ts +3 -1
- package/src/internal/queryDiscovery.ts +49 -0
- package/src/internal/requirements.ts +3 -1
- package/src/internal/simulator.ts +28 -24
- package/src/internal/slots.ts +5 -2
- package/src/txSimulator.ts +160 -63
- package/src/types.ts +50 -17
package/src/txSimulator.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
|
|
1
3
|
import { DEFAULT_SIMULATION_GAS_LIMIT } from "./constants.js";
|
|
2
4
|
import { InvalidSimulationInputError } from "./errors.js";
|
|
3
|
-
import {
|
|
5
|
+
import { discoverErc20s, forUserBalanceQueries } from "./internal/queryDiscovery.js";
|
|
6
|
+
import { estimateTokenOverrideRequirements } from "./internal/requirements.js";
|
|
4
7
|
import { blockOptionsSpread, type ClientArgs } from "./internal/rpc.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
8
|
+
import { runSimulator } from "./internal/simulator.js";
|
|
9
|
+
import { prepareAllowanceTokenOverrides, prepareBalanceTokenOverrides } from "./internal/slots.js";
|
|
7
10
|
import type {
|
|
11
|
+
BalanceDelta,
|
|
12
|
+
BalanceQuery,
|
|
13
|
+
ForUserBalanceQueriesArgs,
|
|
8
14
|
PreparedAllowanceOverrides,
|
|
9
15
|
PreparedBalanceOverrides,
|
|
10
16
|
PrepareAllowanceOverridesArgs,
|
|
@@ -32,15 +38,13 @@ type BoundCallDefaults = {
|
|
|
32
38
|
*/
|
|
33
39
|
export interface TxSimulator {
|
|
34
40
|
/**
|
|
35
|
-
* Simulates one call or sequential batch and returns
|
|
41
|
+
* Simulates one call or sequential batch and returns requested balance deltas.
|
|
36
42
|
*
|
|
37
|
-
* This
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* unfunded accounts. Transaction reverts return `status: "reverted"` instead of throwing.
|
|
43
|
+
* This performs one `eth_call` with state overrides that inject the simulator at `from`.
|
|
44
|
+
* Balances are observed only for `balanceQueries`; query the tokens you forge if you want to
|
|
45
|
+
* observe them. Transaction reverts return `status: "reverted"` instead of throwing.
|
|
41
46
|
*
|
|
42
47
|
* @throws InvalidSimulationInputError when `calls` is empty.
|
|
43
|
-
* @throws AccessListUnsupportedError when the RPC endpoint cannot provide access lists.
|
|
44
48
|
* @throws StateOverrideUnsupportedError when the RPC endpoint cannot execute state overrides or
|
|
45
49
|
* returns undecodable simulator output.
|
|
46
50
|
*
|
|
@@ -50,50 +54,75 @@ export interface TxSimulator {
|
|
|
50
54
|
* const result = await sim.simulate({
|
|
51
55
|
* from,
|
|
52
56
|
* calls: [{ to, data, value: 0n }],
|
|
57
|
+
* balanceQueries: [{ asset: "native", account: from }],
|
|
53
58
|
* });
|
|
54
59
|
* ```
|
|
55
60
|
*/
|
|
56
61
|
simulate: (args: SimulateArgs) => Promise<SimulationResult>;
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
readonly balanceQueries: {
|
|
64
|
+
/**
|
|
65
|
+
* Discovers wallet-style balance queries for `from`.
|
|
66
|
+
*
|
|
67
|
+
* This runs access-list candidate discovery, then one token-filter `eth_call`, and returns
|
|
68
|
+
* native plus token balance queries for `from`. Pass the result to `simulate`.
|
|
69
|
+
*
|
|
70
|
+
* @throws AccessListUnsupportedError when the RPC endpoint cannot provide access lists.
|
|
71
|
+
* @throws StateOverrideUnsupportedError when the RPC endpoint cannot execute state overrides.
|
|
72
|
+
*/
|
|
73
|
+
forUser: (args: ForUserBalanceQueriesArgs) => Promise<BalanceQuery[]>;
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
) => Promise<PreparedAllowanceOverrides>;
|
|
75
|
+
/**
|
|
76
|
+
* Discovers ERC-20 contracts touched by the calls that answer `balanceOf(from)`.
|
|
77
|
+
*
|
|
78
|
+
* This is the discovery half of `forUser`; map the returned addresses yourself when observing a
|
|
79
|
+
* different account.
|
|
80
|
+
*
|
|
81
|
+
* @throws AccessListUnsupportedError when the RPC endpoint cannot provide access lists.
|
|
82
|
+
* @throws StateOverrideUnsupportedError when the RPC endpoint cannot execute state overrides.
|
|
83
|
+
*/
|
|
84
|
+
discoverErc20s: (args: ForUserBalanceQueriesArgs) => Promise<Address[]>;
|
|
85
|
+
};
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
readonly tokenOverrides: {
|
|
88
|
+
/**
|
|
89
|
+
* Prepares ERC-20 balance overrides for `from`.
|
|
90
|
+
*
|
|
91
|
+
* Each token is probed with RPC-only access lists and sentinel state overrides. Tokens the
|
|
92
|
+
* simulator cannot `deal` by verified storage write are returned in `unresolved` rather than
|
|
93
|
+
* thrown.
|
|
94
|
+
*
|
|
95
|
+
* @throws StateOverrideUnsupportedError when the RPC endpoint cannot execute state overrides.
|
|
96
|
+
*/
|
|
97
|
+
forBalances: (args: PrepareBalanceOverridesArgs) => Promise<PreparedBalanceOverrides>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Prepares ERC-20 allowance overrides for `from` and the requested token/spender pairs.
|
|
101
|
+
*
|
|
102
|
+
* Standard Solidity allowance layouts are inferred after one verified probe per token where
|
|
103
|
+
* possible; non-standard layouts fall back to per-pair probing. Pairs the simulator cannot
|
|
104
|
+
* `deal` via verified storage write are returned in `unresolved` rather than thrown.
|
|
105
|
+
*
|
|
106
|
+
* @throws StateOverrideUnsupportedError when the RPC endpoint cannot execute state overrides.
|
|
107
|
+
*/
|
|
108
|
+
forAllowances: (args: PrepareAllowanceOverridesArgs) => Promise<PreparedAllowanceOverrides>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Estimates the balances and approvals needed to execute the observed path.
|
|
112
|
+
*
|
|
113
|
+
* Use this when the tokens or spenders are not known ahead of time. Returned amounts are
|
|
114
|
+
* estimated under forged balances/allowances and should be padded before display or transaction
|
|
115
|
+
* assembly; unreliable measurements are reported under `unresolved`.
|
|
116
|
+
*
|
|
117
|
+
* @throws InvalidSimulationInputError when `calls` is empty.
|
|
118
|
+
* @throws AccessListUnsupportedError when the RPC endpoint cannot provide access lists.
|
|
119
|
+
* @throws StateOverrideUnsupportedError when the RPC endpoint cannot execute state overrides or
|
|
120
|
+
* returns undecodable simulator output.
|
|
121
|
+
*/
|
|
122
|
+
estimateRequirements: (
|
|
123
|
+
args: EstimateAssetRequirementsArgs,
|
|
124
|
+
) => Promise<EstimatedAssetRequirements>;
|
|
125
|
+
};
|
|
97
126
|
}
|
|
98
127
|
|
|
99
128
|
/** Factory for {@link TxSimulator} instances bound to one viem public client. */
|
|
@@ -131,12 +160,24 @@ export const TxSimulator = {
|
|
|
131
160
|
|
|
132
161
|
return {
|
|
133
162
|
simulate: (args) => runSimulate({ ...args, ...revertDefaults(args), client: bound.client }),
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
163
|
+
balanceQueries: {
|
|
164
|
+
forUser: (args) =>
|
|
165
|
+
forUserBalanceQueries({ ...args, ...defaults(args), client: bound.client }),
|
|
166
|
+
discoverErc20s: (args) =>
|
|
167
|
+
discoverErc20s({ ...args, ...defaults(args), client: bound.client }),
|
|
168
|
+
},
|
|
169
|
+
tokenOverrides: {
|
|
170
|
+
forBalances: (args) =>
|
|
171
|
+
prepareBalanceTokenOverrides({ ...args, ...defaults(args), client: bound.client }),
|
|
172
|
+
forAllowances: (args) =>
|
|
173
|
+
prepareAllowanceTokenOverrides({ ...args, ...defaults(args), client: bound.client }),
|
|
174
|
+
estimateRequirements: (args) =>
|
|
175
|
+
estimateTokenOverrideRequirements({
|
|
176
|
+
...args,
|
|
177
|
+
...revertDefaults(args),
|
|
178
|
+
client: bound.client,
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
140
181
|
};
|
|
141
182
|
},
|
|
142
183
|
};
|
|
@@ -151,26 +192,82 @@ async function runSimulate(args: SimulateArgs & ClientArgs): Promise<SimulationR
|
|
|
151
192
|
data: call.data,
|
|
152
193
|
value: call.value ?? 0n,
|
|
153
194
|
})) satisfies SimulatedCall[];
|
|
154
|
-
const candidateAddresses = await discoverCandidateAddresses({
|
|
155
|
-
client: args.client,
|
|
156
|
-
from: args.from,
|
|
157
|
-
calls,
|
|
158
|
-
...blockOptionsSpread(args),
|
|
159
|
-
gas: args.gas,
|
|
160
|
-
...(args.debug !== undefined ? { debug: args.debug } : {}),
|
|
161
|
-
});
|
|
162
|
-
|
|
163
195
|
const tokenSlotOverrides = args.tokenSlotOverrides ?? [];
|
|
164
196
|
|
|
165
|
-
|
|
197
|
+
const result = await runSimulator({
|
|
166
198
|
client: args.client,
|
|
167
199
|
from: args.from,
|
|
168
200
|
calls,
|
|
169
|
-
candidates: [
|
|
201
|
+
candidates: [],
|
|
170
202
|
tokenSlotOverrides,
|
|
203
|
+
balanceProbes: args.balanceQueries.map((query) => ({
|
|
204
|
+
token: query.asset,
|
|
205
|
+
account: query.account,
|
|
206
|
+
})),
|
|
171
207
|
debug: args.debug,
|
|
172
208
|
...blockOptionsSpread(args),
|
|
173
209
|
gas: args.gas,
|
|
174
210
|
...(args.errorAbi !== undefined ? { errorAbi: args.errorAbi } : {}),
|
|
175
211
|
});
|
|
212
|
+
const balances = buildBalanceResults(args.balanceQueries, result.probeData, calls.length);
|
|
213
|
+
|
|
214
|
+
if (result.status === "reverted") {
|
|
215
|
+
return {
|
|
216
|
+
status: "reverted",
|
|
217
|
+
...balances,
|
|
218
|
+
revertData: result.revertData,
|
|
219
|
+
...(result.revertReason !== undefined ? { revertReason: result.revertReason } : {}),
|
|
220
|
+
...(result.revertError !== undefined ? { revertError: result.revertError } : {}),
|
|
221
|
+
...(result.revertSelector !== undefined ? { revertSelector: result.revertSelector } : {}),
|
|
222
|
+
failingCallIndex: result.failingCallIndex,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return { status: "success", ...balances };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
type BalanceResultFields = {
|
|
230
|
+
balanceDeltas: BalanceDelta[];
|
|
231
|
+
unresolved: BalanceQuery[];
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
function buildBalanceResults(
|
|
235
|
+
queries: readonly BalanceQuery[],
|
|
236
|
+
probeData: {
|
|
237
|
+
balanceCheckpoints: readonly bigint[];
|
|
238
|
+
balanceProbeOk: readonly boolean[];
|
|
239
|
+
},
|
|
240
|
+
callsLength: number,
|
|
241
|
+
): BalanceResultFields {
|
|
242
|
+
const balanceDeltas: BalanceDelta[] = [];
|
|
243
|
+
const unresolved: BalanceQuery[] = [];
|
|
244
|
+
const stride = callsLength + 1;
|
|
245
|
+
|
|
246
|
+
for (let i = 0; i < queries.length; ++i) {
|
|
247
|
+
const query = queries[i];
|
|
248
|
+
if (query === undefined) continue;
|
|
249
|
+
if (probeData.balanceProbeOk[i] !== true) {
|
|
250
|
+
unresolved.push(query);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const base = i * stride;
|
|
254
|
+
const before = probeData.balanceCheckpoints[base] ?? 0n;
|
|
255
|
+
const after = probeData.balanceCheckpoints[base + callsLength] ?? 0n;
|
|
256
|
+
const byCall = Array.from(
|
|
257
|
+
{ length: callsLength },
|
|
258
|
+
(_, callIndex) =>
|
|
259
|
+
(probeData.balanceCheckpoints[base + callIndex + 1] ?? 0n) -
|
|
260
|
+
(probeData.balanceCheckpoints[base + callIndex] ?? 0n),
|
|
261
|
+
);
|
|
262
|
+
balanceDeltas.push({
|
|
263
|
+
asset: query.asset,
|
|
264
|
+
account: query.account,
|
|
265
|
+
before,
|
|
266
|
+
after,
|
|
267
|
+
delta: after - before,
|
|
268
|
+
byCall,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return { balanceDeltas, unresolved };
|
|
176
273
|
}
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,30 @@ export type SimulatedCall = {
|
|
|
10
10
|
value?: bigint;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
/** One balance to observe during simulation. `asset` is `"native"` or an ERC-20 address. */
|
|
14
|
+
export type BalanceQuery = {
|
|
15
|
+
asset: "native" | Address;
|
|
16
|
+
/** Account whose balance is observed; this can be any address, not just `from`. */
|
|
17
|
+
account: Address;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Balance observation for one query. `before` is after `tokenSlotOverrides` are applied, so deltas
|
|
22
|
+
* describe simulated changes under the supplied state assumptions.
|
|
23
|
+
*/
|
|
24
|
+
export type BalanceDelta = {
|
|
25
|
+
asset: "native" | Address;
|
|
26
|
+
account: Address;
|
|
27
|
+
before: bigint;
|
|
28
|
+
after: bigint;
|
|
29
|
+
delta: bigint;
|
|
30
|
+
/**
|
|
31
|
+
* Signed change per call, index-aligned with `calls`. Sums to `delta`; on a
|
|
32
|
+
* revert, entries from the failing call onward are 0n.
|
|
33
|
+
*/
|
|
34
|
+
byCall: readonly bigint[];
|
|
35
|
+
};
|
|
36
|
+
|
|
13
37
|
/** Structured event emitted before and after each RPC call when debug logging is enabled. */
|
|
14
38
|
export type SimulationDebugEvent = {
|
|
15
39
|
/** Lifecycle phase for the RPC operation. */
|
|
@@ -51,7 +75,7 @@ type SimulationOptions = {
|
|
|
51
75
|
export type TokenSlotOverride = {
|
|
52
76
|
/** Token contract whose storage should be overridden. */
|
|
53
77
|
token: Address;
|
|
54
|
-
/** Storage slot to write. Usually prepared by `
|
|
78
|
+
/** Storage slot to write. Usually prepared by `tokenOverrides.forBalances` or `tokenOverrides.forAllowances`. */
|
|
55
79
|
slot: Hex;
|
|
56
80
|
/** Value written to the slot. Must be below uint256 max. */
|
|
57
81
|
amount: bigint;
|
|
@@ -100,13 +124,26 @@ export type SimulateArgs = SimulationOptions & {
|
|
|
100
124
|
from: Address;
|
|
101
125
|
/** One call or an ERC-5792-style sequential batch. Must contain at least one call. */
|
|
102
126
|
calls: readonly SimulatedCall[];
|
|
103
|
-
/**
|
|
127
|
+
/** Balances to observe. Use `[]` to execute without balance observations. */
|
|
128
|
+
balanceQueries: readonly BalanceQuery[];
|
|
129
|
+
/**
|
|
130
|
+
* Storage-slot overrides applied before simulating. Query the tokens you forge if you want to
|
|
131
|
+
* observe them.
|
|
132
|
+
*/
|
|
104
133
|
tokenSlotOverrides?: readonly TokenSlotOverride[];
|
|
105
134
|
/** Additional error definitions for decoding this call's reverts; merged after the bound errorAbi. */
|
|
106
135
|
errorAbi?: Abi;
|
|
107
136
|
};
|
|
108
137
|
|
|
109
|
-
/** Arguments for `TxSimulator.
|
|
138
|
+
/** Arguments for `TxSimulator.balanceQueries.forUser`. */
|
|
139
|
+
export type ForUserBalanceQueriesArgs = SimulationOptions & {
|
|
140
|
+
/** Account whose wallet-style balance queries should be discovered. */
|
|
141
|
+
from: Address;
|
|
142
|
+
/** Calls whose access lists should be searched for token candidates. */
|
|
143
|
+
calls: readonly SimulatedCall[];
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** Arguments for `TxSimulator.tokenOverrides.forBalances`. */
|
|
110
147
|
export type PrepareBalanceOverridesArgs = SimulationOptions & {
|
|
111
148
|
/** Account whose token balance overrides should be prepared. */
|
|
112
149
|
from: Address;
|
|
@@ -114,7 +151,7 @@ export type PrepareBalanceOverridesArgs = SimulationOptions & {
|
|
|
114
151
|
tokens: readonly Address[];
|
|
115
152
|
};
|
|
116
153
|
|
|
117
|
-
/** Arguments for `TxSimulator.
|
|
154
|
+
/** Arguments for `TxSimulator.tokenOverrides.forAllowances`. */
|
|
118
155
|
export type PrepareAllowanceOverridesArgs = SimulationOptions & {
|
|
119
156
|
/** Account whose allowance overrides should be prepared. */
|
|
120
157
|
from: Address;
|
|
@@ -122,7 +159,7 @@ export type PrepareAllowanceOverridesArgs = SimulationOptions & {
|
|
|
122
159
|
pairs: readonly AllowanceSlotPair[];
|
|
123
160
|
};
|
|
124
161
|
|
|
125
|
-
/** Arguments for `TxSimulator.
|
|
162
|
+
/** Arguments for `TxSimulator.tokenOverrides.estimateRequirements`. */
|
|
126
163
|
export type EstimateAssetRequirementsArgs = SimulationOptions & {
|
|
127
164
|
/** Account whose balance and approval needs should be estimated. */
|
|
128
165
|
from: Address;
|
|
@@ -204,26 +241,22 @@ export type EstimatedAssetRequirements =
|
|
|
204
241
|
| EstimatedAssetRequirementsSuccess
|
|
205
242
|
| EstimatedAssetRequirementsReverted;
|
|
206
243
|
|
|
207
|
-
/** Raw balance delta for native ETH or an ERC-20-style `balanceOf(address)` asset. */
|
|
208
|
-
export type AssetBalanceDelta = {
|
|
209
|
-
/** `"native"` for ETH, otherwise the token contract address. */
|
|
210
|
-
asset: "native" | Address;
|
|
211
|
-
/** Signed raw-unit balance change for `from`; negative means the account lost assets. */
|
|
212
|
-
delta: bigint;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
244
|
/** Successful simulation result. */
|
|
216
245
|
export type SimulationSuccess = {
|
|
217
246
|
status: "success";
|
|
218
|
-
/**
|
|
219
|
-
|
|
247
|
+
/** Balance observations mirrored 1:1 from successful queries, including zero deltas. */
|
|
248
|
+
balanceDeltas: BalanceDelta[];
|
|
249
|
+
/** Queries that could not be read, usually because an ERC-20 `balanceOf` staticcall failed. */
|
|
250
|
+
unresolved: BalanceQuery[];
|
|
220
251
|
};
|
|
221
252
|
|
|
222
253
|
/** Simulation result for a transaction revert; infrastructure failures throw typed errors instead. */
|
|
223
254
|
export type SimulationReverted = {
|
|
224
255
|
status: "reverted";
|
|
225
|
-
/**
|
|
226
|
-
|
|
256
|
+
/** Balance observations mirrored 1:1 from successful queries, including zero deltas. */
|
|
257
|
+
balanceDeltas: BalanceDelta[];
|
|
258
|
+
/** Queries that could not be read, usually because an ERC-20 `balanceOf` staticcall failed. */
|
|
259
|
+
unresolved: BalanceQuery[];
|
|
227
260
|
/** Raw EVM revert data from the failing simulated call. */
|
|
228
261
|
revertData: Hex;
|
|
229
262
|
/** Human-readable decoded revert; present when revertData decodes via supplied error definitions or as built-in Error/Panic. */
|