@aztec/ethereum 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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/dest/client.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -8
- package/dest/config.d.ts +31 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +74 -14
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/fee_asset_handler.d.ts +1 -1
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +2 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -0
- package/dest/contracts/governance.d.ts +110 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +207 -16
- package/dest/contracts/governance_proposer.d.ts +33 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +57 -3
- package/dest/contracts/gse.d.ts +4 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +2 -2
- package/dest/contracts/inbox.d.ts +3 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +12 -7
- package/dest/contracts/index.d.ts +4 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +3 -2
- package/dest/contracts/multicall.d.ts +130 -13
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +203 -93
- package/dest/contracts/outbox.d.ts +27 -4
- package/dest/contracts/outbox.d.ts.map +1 -1
- package/dest/contracts/outbox.js +34 -7
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +5422 -33
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +409 -78
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
- package/dest/deploy_aztec_l1_contracts.d.ts +21 -12
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +66 -39
- package/dest/deploy_l1_contract.js +3 -3
- package/dest/foundry_binary.d.ts +13 -0
- package/dest/foundry_binary.d.ts.map +1 -0
- package/dest/foundry_binary.js +52 -0
- package/dest/l1_artifacts.d.ts +16231 -15758
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +101 -82
- package/dest/l1_reader.d.ts +5 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +9 -7
- package/dest/l1_tx_utils/config.d.ts +7 -1
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +17 -4
- package/dest/l1_tx_utils/constants.d.ts +1 -1
- package/dest/l1_tx_utils/constants.js +2 -2
- package/dest/l1_tx_utils/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
- package/dest/l1_tx_utils/index-blobs.js +2 -2
- package/dest/l1_tx_utils/index.d.ts +2 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +23 -4
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.js +65 -3
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +185 -88
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +13 -8
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +67 -37
- package/dest/l1_tx_utils/types.d.ts +27 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/types.js +10 -0
- package/dest/publisher_manager.d.ts +34 -7
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +119 -8
- package/dest/queries.d.ts +13 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +70 -4
- package/dest/test/blob_kzg_warmup.d.ts +19 -0
- package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
- package/dest/test/blob_kzg_warmup.js +64 -0
- package/dest/test/chain_monitor.d.ts +55 -4
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +104 -3
- package/dest/test/eth_cheat_codes.d.ts +37 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +89 -41
- package/dest/test/index.d.ts +2 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -2
- package/dest/test/rollup_cheat_codes.d.ts +63 -4
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +96 -8
- package/dest/test/start_anvil.d.ts +23 -3
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +182 -32
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/utils.d.ts +10 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +94 -16
- package/package.json +6 -9
- package/src/client.ts +66 -2
- package/src/config.ts +104 -18
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/fee_asset_handler.ts +2 -0
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +279 -13
- package/src/contracts/governance_proposer.ts +58 -2
- package/src/contracts/gse.ts +7 -2
- package/src/contracts/inbox.ts +13 -5
- package/src/contracts/index.ts +3 -2
- package/src/contracts/multicall.ts +247 -103
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +461 -82
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +16 -14
- package/src/deploy_aztec_l1_contracts.ts +93 -47
- package/src/deploy_l1_contract.ts +3 -3
- package/src/foundry_binary.ts +57 -0
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -94
- package/src/l1_reader.ts +17 -10
- package/src/l1_tx_utils/config.ts +23 -3
- package/src/l1_tx_utils/constants.ts +2 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +1 -1
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +1 -1
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
- package/src/l1_tx_utils/index-blobs.ts +2 -2
- package/src/l1_tx_utils/index.ts +1 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +75 -3
- package/src/l1_tx_utils/l1_tx_utils.ts +170 -68
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +13 -8
- package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
- package/src/l1_tx_utils/types.ts +32 -0
- package/src/publisher_manager.ts +145 -12
- package/src/queries.ts +77 -4
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +148 -3
- package/src/test/eth_cheat_codes.ts +82 -45
- package/src/test/index.ts +1 -2
- package/src/test/rollup_cheat_codes.ts +126 -8
- package/src/test/start_anvil.ts +212 -32
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +98 -18
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -209
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/generated/l1-contracts-defaults.d.ts +0 -29
- package/dest/generated/l1-contracts-defaults.d.ts.map +0 -1
- package/dest/generated/l1-contracts-defaults.js +0 -29
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
- package/dest/test/delayed_tx_utils.d.ts +0 -13
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -28
- package/dest/test/tx_delayer.d.ts +0 -36
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/src/contracts/empire_slashing_proposer.ts +0 -270
- package/src/generated/l1-contracts-defaults.ts +0 -31
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
package/dest/test/start_anvil.js
CHANGED
|
@@ -1,55 +1,205 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { resolveFoundryBinary } from '../foundry_binary.js';
|
|
5
|
+
// Watchdog wrapper: instead of spawning anvil directly, we spawn a small bash supervisor that runs
|
|
6
|
+
// anvil as a background child and polls its own parent (this node process). If the parent dies for
|
|
7
|
+
// ANY reason — including SIGKILL / crash / OOM, where node's own exit handlers never run — the poll
|
|
8
|
+
// loop ends and the EXIT trap reaps anvil. The script is inlined (rather than shipped as a `.sh`) so
|
|
9
|
+
// it works from the published npm tarball too, and the resolved anvil binary is passed via
|
|
10
|
+
// `$ANVIL_BIN` so it works without `anvil` on PATH.
|
|
11
|
+
//
|
|
12
|
+
// `$@` is the anvil argv; `bash -c <script> bash <...args>` puts the args in `$@` and `$0` = 'bash'.
|
|
13
|
+
//
|
|
14
|
+
// The EXIT trap reaps anvil; INT/TERM just `exit` (which fires the EXIT trap) so a signal terminates
|
|
15
|
+
// the supervisor promptly instead of being swallowed — a trapped TERM does NOT terminate the shell,
|
|
16
|
+
// so trapping the kill directly on TERM would leave the poll loop running and the caller's teardown
|
|
17
|
+
// hanging until its SIGKILL escalation. `sleep & wait` makes the poll interruptible, so INT/TERM are
|
|
18
|
+
// handled immediately rather than after the current `sleep` returns.
|
|
19
|
+
const ANVIL_WATCHDOG = `
|
|
20
|
+
set -u
|
|
21
|
+
parent=$PPID
|
|
22
|
+
"$ANVIL_BIN" "$@" &
|
|
23
|
+
anvil_pid=$!
|
|
24
|
+
trap 'kill "$anvil_pid" 2>/dev/null' EXIT
|
|
25
|
+
trap 'exit 0' INT TERM
|
|
26
|
+
while kill -0 "$parent" 2>/dev/null; do sleep 1 & wait $!; done
|
|
27
|
+
`;
|
|
6
28
|
/**
|
|
7
29
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
8
30
|
*/ export async function startAnvil(opts = {}) {
|
|
9
|
-
const anvilBinary =
|
|
31
|
+
const anvilBinary = resolveFoundryBinary('anvil');
|
|
10
32
|
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
11
33
|
const methodCalls = opts.captureMethodCalls ? [] : undefined;
|
|
12
|
-
let
|
|
13
|
-
// Start anvil.
|
|
14
|
-
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
34
|
+
let detectedPort;
|
|
15
35
|
const anvil = await retry(async ()=>{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
// `--port 0` lets anvil bind an OS-assigned ephemeral port; the actual port is read back from
|
|
37
|
+
// its "Listening on host:port" stdout below, so independent suites can spawn their own anvil
|
|
38
|
+
// in parallel without fighting over a fixed port.
|
|
39
|
+
const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
|
|
40
|
+
const args = [
|
|
41
|
+
'--host',
|
|
42
|
+
'127.0.0.1',
|
|
43
|
+
'--port',
|
|
44
|
+
String(port),
|
|
45
|
+
'--accounts',
|
|
46
|
+
String(opts.accounts ?? 20),
|
|
47
|
+
'--gas-limit',
|
|
48
|
+
String(45_000_000),
|
|
49
|
+
'--chain-id',
|
|
50
|
+
String(opts.chainId ?? 31337)
|
|
51
|
+
];
|
|
52
|
+
if (opts.l1BlockTime !== undefined) {
|
|
53
|
+
args.push('--block-time', String(opts.l1BlockTime));
|
|
54
|
+
}
|
|
55
|
+
if (opts.hardfork !== undefined) {
|
|
56
|
+
args.push('--hardfork', opts.hardfork);
|
|
57
|
+
}
|
|
58
|
+
args.push('--slots-in-an-epoch', String(opts.slotsInAnEpoch ?? 1));
|
|
59
|
+
// Spawn the watchdog (see ANVIL_WATCHDOG). It launches anvil with these args and reaps it if we
|
|
60
|
+
// die; `$0` is 'bash' and `$@` is the anvil argv.
|
|
61
|
+
const child = spawn('bash', [
|
|
62
|
+
'-c',
|
|
63
|
+
ANVIL_WATCHDOG,
|
|
64
|
+
'bash',
|
|
65
|
+
...args
|
|
66
|
+
], {
|
|
67
|
+
stdio: [
|
|
68
|
+
'ignore',
|
|
69
|
+
'pipe',
|
|
70
|
+
'pipe'
|
|
71
|
+
],
|
|
72
|
+
env: {
|
|
73
|
+
...process.env,
|
|
74
|
+
ANVIL_BIN: anvilBinary,
|
|
75
|
+
RAYON_NUM_THREADS: '1'
|
|
32
76
|
}
|
|
33
77
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
78
|
+
// Wait for "Listening on" or an early exit.
|
|
79
|
+
await new Promise((resolve, reject)=>{
|
|
80
|
+
let stderr = '';
|
|
81
|
+
const onStdout = (data)=>{
|
|
82
|
+
const text = data.toString();
|
|
83
|
+
logger?.debug(text.trim());
|
|
84
|
+
methodCalls?.push(...text.match(/eth_[^\s]+/g) || []);
|
|
85
|
+
if (detectedPort === undefined && text.includes('Listening on')) {
|
|
86
|
+
const match = text.match(/Listening on ([^:]+):(\d+)/);
|
|
87
|
+
if (match) {
|
|
88
|
+
detectedPort = parseInt(match[2]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (detectedPort !== undefined) {
|
|
92
|
+
child.stdout?.removeListener('data', onStdout);
|
|
93
|
+
child.stderr?.removeListener('data', onStderr);
|
|
94
|
+
child.removeListener('close', onClose);
|
|
95
|
+
resolve();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const onStderr = (data)=>{
|
|
99
|
+
stderr += data.toString();
|
|
100
|
+
logger?.debug(data.toString().trim());
|
|
101
|
+
};
|
|
102
|
+
const onClose = (code)=>{
|
|
103
|
+
child.stdout?.removeListener('data', onStdout);
|
|
104
|
+
child.stderr?.removeListener('data', onStderr);
|
|
105
|
+
reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
|
|
106
|
+
};
|
|
107
|
+
child.stdout?.on('data', onStdout);
|
|
108
|
+
child.stderr?.on('data', onStderr);
|
|
109
|
+
child.once('close', onClose);
|
|
110
|
+
});
|
|
111
|
+
// Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
|
|
112
|
+
if (logger || opts.captureMethodCalls || opts.dateProvider) {
|
|
113
|
+
child.stdout?.on('data', (data)=>{
|
|
114
|
+
const text = data.toString();
|
|
115
|
+
logger?.debug(text.trim());
|
|
116
|
+
methodCalls?.push(...text.match(/eth_[^\s]+/g) || []);
|
|
117
|
+
if (opts.dateProvider) {
|
|
118
|
+
syncDateProviderFromAnvilOutput(text, opts.dateProvider);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
child.stderr?.on('data', (data)=>{
|
|
122
|
+
logger?.debug(data.toString().trim());
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
// Consume streams so the child process doesn't block on full pipe buffers.
|
|
126
|
+
child.stdout?.resume();
|
|
127
|
+
child.stderr?.resume();
|
|
37
128
|
}
|
|
38
|
-
return
|
|
129
|
+
return child;
|
|
39
130
|
}, 'Start anvil', makeBackoff([
|
|
40
131
|
5,
|
|
41
132
|
5,
|
|
42
133
|
5
|
|
43
134
|
]));
|
|
44
|
-
if (!
|
|
135
|
+
if (!detectedPort) {
|
|
45
136
|
throw new Error('Failed to start anvil');
|
|
46
137
|
}
|
|
47
|
-
|
|
48
|
-
|
|
138
|
+
const port = detectedPort;
|
|
139
|
+
let status = 'listening';
|
|
140
|
+
anvil.once('close', ()=>{
|
|
141
|
+
status = 'idle';
|
|
142
|
+
});
|
|
143
|
+
const stop = async ()=>{
|
|
144
|
+
if (status === 'idle') {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
await killChild(anvil);
|
|
148
|
+
};
|
|
149
|
+
const anvilObj = {
|
|
150
|
+
port,
|
|
151
|
+
host: '127.0.0.1',
|
|
152
|
+
get status () {
|
|
153
|
+
return status;
|
|
154
|
+
},
|
|
155
|
+
stop
|
|
156
|
+
};
|
|
49
157
|
return {
|
|
50
|
-
anvil,
|
|
158
|
+
anvil: anvilObj,
|
|
51
159
|
methodCalls,
|
|
52
|
-
stop
|
|
160
|
+
stop,
|
|
53
161
|
rpcUrl: `http://127.0.0.1:${port}`
|
|
54
162
|
};
|
|
55
163
|
}
|
|
164
|
+
/** Extracts block time from anvil stdout and syncs the dateProvider. */ function syncDateProviderFromAnvilOutput(text, dateProvider) {
|
|
165
|
+
// Anvil logs mined blocks as:
|
|
166
|
+
// Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
|
|
167
|
+
const match = text.match(/Block Time:\s*"([^"]+)"/);
|
|
168
|
+
if (match) {
|
|
169
|
+
const blockTimeMs = new Date(match[1]).getTime();
|
|
170
|
+
if (!isNaN(blockTimeMs)) {
|
|
171
|
+
dateProvider.setTime(blockTimeMs);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Send SIGTERM to the watchdog, wait up to 5 s, then SIGKILL. The watchdog's trap forwards the
|
|
177
|
+
* signal to anvil, so terminating it tears down anvil too. All timers are always cleared.
|
|
178
|
+
*/ function killChild(child) {
|
|
179
|
+
return new Promise((resolve)=>{
|
|
180
|
+
if (child.exitCode !== null || child.killed) {
|
|
181
|
+
child.stdout?.destroy();
|
|
182
|
+
child.stderr?.destroy();
|
|
183
|
+
resolve();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
let killTimer;
|
|
187
|
+
const onClose = ()=>{
|
|
188
|
+
if (killTimer !== undefined) {
|
|
189
|
+
clearTimeout(killTimer);
|
|
190
|
+
}
|
|
191
|
+
// Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
|
|
192
|
+
child.stdout?.destroy();
|
|
193
|
+
child.stderr?.destroy();
|
|
194
|
+
resolve();
|
|
195
|
+
};
|
|
196
|
+
child.once('close', onClose);
|
|
197
|
+
child.kill('SIGTERM');
|
|
198
|
+
killTimer = setTimeout(()=>{
|
|
199
|
+
killTimer = undefined;
|
|
200
|
+
child.kill('SIGKILL');
|
|
201
|
+
}, 5000);
|
|
202
|
+
// Ensure the timer does not prevent Node from exiting.
|
|
203
|
+
killTimer.unref();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
@@ -3,13 +3,13 @@ import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi';
|
|
|
3
3
|
import { TestERC20Abi as StakingAssetAbi } from '@aztec/l1-artifacts/TestERC20Abi';
|
|
4
4
|
import { getContract } from 'viem';
|
|
5
5
|
import { extractProposalIdFromLogs } from '../contracts/governance.js';
|
|
6
|
-
import {
|
|
6
|
+
import { createL1TxUtils } from '../l1_tx_utils/index.js';
|
|
7
7
|
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
8
8
|
export async function executeGovernanceProposal(proposalId, governance, voteAmount, privateKey, l1Client, rpcUrls, logger) {
|
|
9
9
|
const proposal = await governance.read.getProposal([
|
|
10
10
|
proposalId
|
|
11
11
|
]);
|
|
12
|
-
const l1TxUtils =
|
|
12
|
+
const l1TxUtils = createL1TxUtils(l1Client);
|
|
13
13
|
const waitL1Block = async ()=>{
|
|
14
14
|
await l1TxUtils.sendAndMonitorTransaction({
|
|
15
15
|
to: l1Client.account.address,
|
package/dest/utils.d.ts
CHANGED
|
@@ -9,11 +9,12 @@ export interface L2Claim {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class FormattedViemError extends Error {
|
|
11
11
|
metaMessages?: any[];
|
|
12
|
-
constructor(message: string, metaMessages?: any[]);
|
|
12
|
+
constructor(message: string, metaMessages?: any[], options?: ErrorOptions);
|
|
13
13
|
}
|
|
14
14
|
export declare function extractEvent<const TAbi extends Abi | readonly unknown[], TEventName extends ContractEventName<TAbi>, TEventType = DecodeEventLogReturnType<TAbi, TEventName, Hex[], undefined, true>>(logs: Log[], address: Hex, abi: TAbi, eventName: TEventName, filter?: (log: TEventType) => boolean, logger?: Logger): TEventType;
|
|
15
15
|
export declare function tryExtractEvent<const TAbi extends Abi | readonly unknown[], TEventName extends ContractEventName<TAbi>, TEventType = DecodeEventLogReturnType<TAbi, TEventName, Hex[], undefined, true>>(logs: Log[], address: Hex, abi: TAbi, eventName: TEventName, filter?: (log: TEventType) => boolean, logger?: Logger): TEventType | undefined;
|
|
16
16
|
export declare function prettyLogViemErrorMsg(err: any): any;
|
|
17
|
+
export declare function mergeAbis(abis: Abi[]): Abi;
|
|
17
18
|
/**
|
|
18
19
|
* Formats a Viem error into a FormattedViemError instance.
|
|
19
20
|
* @param error - The error to format.
|
|
@@ -21,6 +22,13 @@ export declare function prettyLogViemErrorMsg(err: any): any;
|
|
|
21
22
|
* @returns A FormattedViemError instance.
|
|
22
23
|
*/
|
|
23
24
|
export declare function formatViemError(error: any, abi?: Abi): FormattedViemError;
|
|
25
|
+
/**
|
|
26
|
+
* Best-effort decode of a raw revert payload (`0x...`) against an ABI.
|
|
27
|
+
* Returns a human-readable `ErrorName(arg1, arg2, ...)` string, or `undefined` if the selector
|
|
28
|
+
* is unknown or the payload is empty. Use to surface decoded error names alongside the raw
|
|
29
|
+
* payload in log lines for operators.
|
|
30
|
+
*/
|
|
31
|
+
export declare function tryDecodeRevertReason(data: Hex | undefined, abi: Abi): string | undefined;
|
|
24
32
|
export declare function tryGetCustomErrorName(err: any): string | undefined;
|
|
25
33
|
/**
|
|
26
34
|
* Type guard to check if a transaction is a blob transaction (EIP-4844).
|
|
@@ -34,4 +42,4 @@ export declare function isBlobTransaction(tx: FormattedTransaction): tx is Forma
|
|
|
34
42
|
* Calculates a percentile from an array of bigints
|
|
35
43
|
*/
|
|
36
44
|
export declare function calculatePercentile(values: bigint[], percentile: number): bigint;
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
45
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3Vy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LEdBQUcsU0FBUyxFQUFFLEdBQUcsRUFBRSxHQUFHLEdBQUcsTUFBTSxHQUFHLFNBQVMsQ0FVekY7QUFFRCx3QkFBZ0IscUJBQXFCLENBQUMsR0FBRyxFQUFFLEdBQUcsc0JBYTdDO0FBRUQ7OztHQUdHO0FBQ0gsd0JBQWdCLGlCQUFpQixDQUFDLEVBQUUsRUFBRSxvQkFBb0IsR0FBRyxFQUFFLElBQUksb0JBQW9CLEdBQUc7SUFDeEYsZ0JBQWdCLEVBQUUsTUFBTSxDQUFDO0lBQ3pCLG1CQUFtQixFQUFFLFNBQVMsR0FBRyxFQUFFLENBQUM7Q0FDckMsQ0FPQTtBQUVEOztHQUVHO0FBQ0gsd0JBQWdCLG1CQUFtQixDQUFDLE1BQU0sRUFBRSxNQUFNLEVBQUUsRUFBRSxVQUFVLEVBQUUsTUFBTSxHQUFHLE1BQU0sQ0FPaEYifQ==
|
package/dest/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EACL,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EACL,KAAK,GAAG,EAGR,KAAK,iBAAiB,EAEtB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,GAAG,EACR,KAAK,GAAG,EAGT,MAAM,MAAM,CAAC;AAGd,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,EAAE,CAAC;IAChB,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AS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAe1C;AA2ED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,GAAE,GAAe,GAAG,kBAAkB,CAkEpF;AAyBD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,SAAS,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAUzF;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,sBAa7C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,oBAAoB,GAAG,EAAE,IAAI,oBAAoB,GAAG;IACxF,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,SAAS,GAAG,EAAE,CAAC;CACrC,CAOA;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAOhF"}
|
package/dest/utils.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ErrorsAbi } from '@aztec/l1-artifacts/ErrorsAbi';
|
|
2
2
|
import { BaseError, ContractFunctionRevertedError, decodeErrorResult, decodeEventLog } from 'viem';
|
|
3
|
+
import { formatAbiItem, formatAbiParams } from 'viem/utils';
|
|
3
4
|
export class FormattedViemError extends Error {
|
|
4
5
|
metaMessages;
|
|
5
|
-
constructor(message, metaMessages){
|
|
6
|
-
super(message);
|
|
6
|
+
constructor(message, metaMessages, options){
|
|
7
|
+
super(message, options);
|
|
7
8
|
this.name = 'FormattedViemError';
|
|
8
9
|
this.metaMessages = metaMessages;
|
|
9
10
|
}
|
|
@@ -46,6 +47,51 @@ export function prettyLogViemErrorMsg(err) {
|
|
|
46
47
|
}
|
|
47
48
|
return err?.message ?? err;
|
|
48
49
|
}
|
|
50
|
+
export function mergeAbis(abis) {
|
|
51
|
+
let merged = [];
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
for (const abi of abis){
|
|
54
|
+
for (const item of abi){
|
|
55
|
+
const key = getAbiItemKey(item);
|
|
56
|
+
if (!seen.has(key)) {
|
|
57
|
+
seen.add(key);
|
|
58
|
+
merged = [
|
|
59
|
+
...merged,
|
|
60
|
+
item
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return merged;
|
|
66
|
+
}
|
|
67
|
+
function getAbiItemKey(item) {
|
|
68
|
+
if (item.type === 'function') {
|
|
69
|
+
const signature = formatAbiItem(item);
|
|
70
|
+
const outputs = formatAbiParams(item.outputs);
|
|
71
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
72
|
+
return `function:${signature}:${outputs}:${stateMutability}`;
|
|
73
|
+
}
|
|
74
|
+
if (item.type === 'event') {
|
|
75
|
+
const signature = formatAbiItem(item);
|
|
76
|
+
const indexed = (item.inputs ?? []).map((input)=>input.indexed ? '1' : '0').join('');
|
|
77
|
+
const anonymous = item.anonymous ? 'anonymous' : 'not-anonymous';
|
|
78
|
+
return `event:${signature}:${indexed}:${anonymous}`;
|
|
79
|
+
}
|
|
80
|
+
if (item.type === 'error') {
|
|
81
|
+
const signature = formatAbiItem(item);
|
|
82
|
+
return `error:${signature}`;
|
|
83
|
+
}
|
|
84
|
+
if (item.type === 'constructor') {
|
|
85
|
+
const inputs = formatAbiParams(item.inputs);
|
|
86
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
87
|
+
return `constructor::${inputs}:${stateMutability}`;
|
|
88
|
+
}
|
|
89
|
+
if (item.type === 'fallback' || item.type === 'receive') {
|
|
90
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
91
|
+
return `${item.type}:::${stateMutability}`;
|
|
92
|
+
}
|
|
93
|
+
return 'unknown';
|
|
94
|
+
}
|
|
49
95
|
function getNestedErrorData(error) {
|
|
50
96
|
// If nothing, bail
|
|
51
97
|
if (!error) {
|
|
@@ -66,6 +112,19 @@ function getNestedErrorData(error) {
|
|
|
66
112
|
// Not found
|
|
67
113
|
return undefined;
|
|
68
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Truncates an error message to a safe length for log renderers.
|
|
117
|
+
* LogExplorer can only render up to 2500 characters in its summary view.
|
|
118
|
+
* We cap at 2000 to leave room for decorating context added by callers.
|
|
119
|
+
*/ function truncateErrorMessage(message) {
|
|
120
|
+
const MAX = 2000;
|
|
121
|
+
const CHUNK = 950;
|
|
122
|
+
if (message.length <= MAX) {
|
|
123
|
+
return message;
|
|
124
|
+
}
|
|
125
|
+
const truncated = message.length - 2 * CHUNK;
|
|
126
|
+
return message.slice(0, CHUNK) + `...${truncated} characters truncated...` + message.slice(-CHUNK);
|
|
127
|
+
}
|
|
69
128
|
/**
|
|
70
129
|
* Formats a Viem error into a FormattedViemError instance.
|
|
71
130
|
* @param error - The error to format.
|
|
@@ -76,6 +135,7 @@ function getNestedErrorData(error) {
|
|
|
76
135
|
if (error instanceof FormattedViemError) {
|
|
77
136
|
return error;
|
|
78
137
|
}
|
|
138
|
+
const originalError = error;
|
|
79
139
|
// First try to decode as a custom error using the ABI
|
|
80
140
|
try {
|
|
81
141
|
const data = getNestedErrorData(error);
|
|
@@ -86,7 +146,9 @@ function getNestedErrorData(error) {
|
|
|
86
146
|
data: data
|
|
87
147
|
});
|
|
88
148
|
if (decoded) {
|
|
89
|
-
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages
|
|
149
|
+
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages, {
|
|
150
|
+
cause: originalError
|
|
151
|
+
});
|
|
90
152
|
}
|
|
91
153
|
}
|
|
92
154
|
// If it's a BaseError, try to get the custom error through ContractFunctionRevertedError
|
|
@@ -98,7 +160,9 @@ function getNestedErrorData(error) {
|
|
|
98
160
|
errorName = revertError.signature ?? '';
|
|
99
161
|
}
|
|
100
162
|
const args = revertError.metaMessages && revertError.metaMessages?.length > 1 ? revertError.metaMessages[1].trimStart() : '';
|
|
101
|
-
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages
|
|
163
|
+
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages, {
|
|
164
|
+
cause: originalError
|
|
165
|
+
});
|
|
102
166
|
}
|
|
103
167
|
}
|
|
104
168
|
} catch {
|
|
@@ -116,18 +180,13 @@ function getNestedErrorData(error) {
|
|
|
116
180
|
}
|
|
117
181
|
// If it's a regular Error instance, return it with its message
|
|
118
182
|
if (error instanceof Error) {
|
|
119
|
-
return new FormattedViemError(error.message, error?.metaMessages
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const chunk = 950;
|
|
127
|
-
const truncated = length - 2 * chunk;
|
|
128
|
-
return new FormattedViemError(body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk));
|
|
129
|
-
}
|
|
130
|
-
return new FormattedViemError(body);
|
|
183
|
+
return new FormattedViemError(truncateErrorMessage(error.message), error?.metaMessages, {
|
|
184
|
+
cause: originalError
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return new FormattedViemError(truncateErrorMessage(String(error)), undefined, {
|
|
188
|
+
cause: originalError
|
|
189
|
+
});
|
|
131
190
|
}
|
|
132
191
|
function stripAbis(obj) {
|
|
133
192
|
if (!obj || typeof obj !== 'object') {
|
|
@@ -148,6 +207,25 @@ function stripAbis(obj) {
|
|
|
148
207
|
}
|
|
149
208
|
});
|
|
150
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Best-effort decode of a raw revert payload (`0x...`) against an ABI.
|
|
212
|
+
* Returns a human-readable `ErrorName(arg1, arg2, ...)` string, or `undefined` if the selector
|
|
213
|
+
* is unknown or the payload is empty. Use to surface decoded error names alongside the raw
|
|
214
|
+
* payload in log lines for operators.
|
|
215
|
+
*/ export function tryDecodeRevertReason(data, abi) {
|
|
216
|
+
if (!data || data === '0x') {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const decoded = decodeErrorResult({
|
|
221
|
+
abi,
|
|
222
|
+
data
|
|
223
|
+
});
|
|
224
|
+
return `${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`;
|
|
225
|
+
} catch {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
151
229
|
export function tryGetCustomErrorName(err) {
|
|
152
230
|
try {
|
|
153
231
|
// See https://viem.sh/docs/contract/simulateContract#handling-custom-errors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/ethereum",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.d58ff9d0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./account": "./dest/account.js",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"build": "yarn clean && ../scripts/tsc.sh",
|
|
41
41
|
"build:dev": "../scripts/tsc.sh --watch",
|
|
42
42
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
43
|
-
"generate": "./scripts/generate.sh",
|
|
44
43
|
"start:dev": "concurrently -k \"../scripts/tsc.sh --watch\" \"nodemon --watch dest --exec yarn start\"",
|
|
45
44
|
"start": "node ./dest/index.js",
|
|
46
45
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
@@ -50,17 +49,16 @@
|
|
|
50
49
|
"../package.common.json"
|
|
51
50
|
],
|
|
52
51
|
"dependencies": {
|
|
53
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
54
|
-
"@aztec/constants": "0.0.1-commit.
|
|
55
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
56
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
57
|
-
"@viem/anvil": "^0.0.10",
|
|
52
|
+
"@aztec/blob-lib": "0.0.1-commit.d58ff9d0",
|
|
53
|
+
"@aztec/constants": "0.0.1-commit.d58ff9d0",
|
|
54
|
+
"@aztec/foundation": "0.0.1-commit.d58ff9d0",
|
|
55
|
+
"@aztec/l1-artifacts": "0.0.1-commit.d58ff9d0",
|
|
58
56
|
"dotenv": "^16.0.3",
|
|
59
57
|
"lodash.chunk": "^4.2.0",
|
|
60
58
|
"lodash.pickby": "^4.5.0",
|
|
61
59
|
"tslib": "^2.4.0",
|
|
62
60
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
63
|
-
"zod": "^
|
|
61
|
+
"zod": "^4"
|
|
64
62
|
},
|
|
65
63
|
"devDependencies": {
|
|
66
64
|
"@jest/globals": "^30.0.0",
|
|
@@ -69,7 +67,6 @@
|
|
|
69
67
|
"@types/lodash.pickby": "^4",
|
|
70
68
|
"@types/node": "^22.15.17",
|
|
71
69
|
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
72
|
-
"@viem/anvil": "^0.0.10",
|
|
73
70
|
"get-port": "^7.1.0",
|
|
74
71
|
"jest": "^30.0.0",
|
|
75
72
|
"jest-mock-extended": "^4.0.0",
|
package/src/client.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
type Chain,
|
|
7
|
+
type FallbackTransport,
|
|
6
8
|
type HDAccount,
|
|
9
|
+
HttpRequestError,
|
|
10
|
+
type HttpTransport,
|
|
7
11
|
type LocalAccount,
|
|
8
12
|
type PrivateKeyAccount,
|
|
9
13
|
createPublicClient,
|
|
@@ -25,10 +29,69 @@ type Config = {
|
|
|
25
29
|
l1ChainId: number;
|
|
26
30
|
/** The polling interval viem uses in ms */
|
|
27
31
|
viemPollingIntervalMS?: number;
|
|
32
|
+
/** Timeout for HTTP requests to the L1 RPC node in ms. */
|
|
33
|
+
l1HttpTimeoutMS?: number;
|
|
28
34
|
};
|
|
29
35
|
|
|
30
36
|
export type { Config as EthereumClientConfig };
|
|
31
37
|
|
|
38
|
+
/** Error exposed by L1 RPC transports without including provider URLs in its message. */
|
|
39
|
+
export class L1RpcError extends Error {
|
|
40
|
+
constructor(message: string, options?: ErrorOptions) {
|
|
41
|
+
super(message, options);
|
|
42
|
+
this.name = 'L1RpcError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Creates a viem fallback HTTP transport for the given L1 RPC URLs. */
|
|
47
|
+
export function makeL1HttpTransport(rpcUrls: string[], opts?: { timeout?: number }) {
|
|
48
|
+
return wrapL1RpcTransport(fallback(rpcUrls.map(url => http(url, { batch: false, timeout: opts?.timeout }))));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Returns the HTTP status from an L1 RPC error's cause chain, if one is available. */
|
|
52
|
+
export function getL1RpcHttpStatus(err: unknown): number | undefined {
|
|
53
|
+
return getErrorCause(err, HttpRequestError)?.status;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Returns true when an L1 RPC error's cause chain contains the given HTTP status. */
|
|
57
|
+
export function isL1RpcHttpStatus(err: unknown, status: number): boolean {
|
|
58
|
+
return getL1RpcHttpStatus(err) === status;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function wrapL1RpcTransport(transport: FallbackTransport<HttpTransport[]>): FallbackTransport<HttpTransport[]> {
|
|
62
|
+
const wrappedTransport: FallbackTransport<HttpTransport[]> = parameters => {
|
|
63
|
+
const fallbackTransport = transport(parameters);
|
|
64
|
+
const request: typeof fallbackTransport.request = async args => {
|
|
65
|
+
try {
|
|
66
|
+
return await fallbackTransport.request(args);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
throw err instanceof L1RpcError ? err : new L1RpcError('L1 RPC request failed', { cause: err });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return { ...fallbackTransport, request };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return wrappedTransport;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns the individual RPC URLs underlying a viem public client that was constructed with a
|
|
79
|
+
* fallback HTTP transport (see {@link makeL1HttpTransport}). Returns an empty array if the
|
|
80
|
+
* transport shape is not recognized (e.g. mock clients in tests, or non-fallback transports).
|
|
81
|
+
*/
|
|
82
|
+
export function getRpcUrlsFromClient(client: ViemPublicClient): string[] {
|
|
83
|
+
const transport = client.transport as unknown as {
|
|
84
|
+
transports?: { value?: { url?: string } }[];
|
|
85
|
+
value?: { url?: string };
|
|
86
|
+
url?: string;
|
|
87
|
+
};
|
|
88
|
+
if (Array.isArray(transport?.transports)) {
|
|
89
|
+
return transport.transports.map(t => t?.value?.url).filter((url): url is string => typeof url === 'string');
|
|
90
|
+
}
|
|
91
|
+
const singleUrl = transport?.value?.url ?? transport?.url;
|
|
92
|
+
return typeof singleUrl === 'string' ? [singleUrl] : [];
|
|
93
|
+
}
|
|
94
|
+
|
|
32
95
|
// TODO: Use these methods to abstract the creation of viem clients.
|
|
33
96
|
|
|
34
97
|
/** Returns a viem public client given the L1 config. */
|
|
@@ -36,7 +99,7 @@ export function getPublicClient(config: Config): ViemPublicClient {
|
|
|
36
99
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
37
100
|
return createPublicClient({
|
|
38
101
|
chain: chain.chainInfo,
|
|
39
|
-
transport:
|
|
102
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
40
103
|
pollingInterval: config.viemPollingIntervalMS,
|
|
41
104
|
});
|
|
42
105
|
}
|
|
@@ -77,6 +140,7 @@ export function createExtendedL1Client(
|
|
|
77
140
|
chain: Chain = foundry,
|
|
78
141
|
pollingIntervalMS?: number,
|
|
79
142
|
addressIndex?: number,
|
|
143
|
+
opts?: { httpTimeoutMS?: number },
|
|
80
144
|
): ExtendedViemWalletClient {
|
|
81
145
|
const hdAccount =
|
|
82
146
|
typeof mnemonicOrPrivateKeyOrHdAccount === 'string'
|
|
@@ -88,7 +152,7 @@ export function createExtendedL1Client(
|
|
|
88
152
|
const extendedClient = createWalletClient({
|
|
89
153
|
account: hdAccount,
|
|
90
154
|
chain,
|
|
91
|
-
transport:
|
|
155
|
+
transport: makeL1HttpTransport(rpcUrls, { timeout: opts?.httpTimeoutMS }),
|
|
92
156
|
pollingInterval: pollingIntervalMS,
|
|
93
157
|
}).extend(publicActions);
|
|
94
158
|
|