@aztec/ethereum 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea
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.js +6 -2
- package/dest/config.d.ts +21 -68
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +61 -380
- package/dest/contracts/empire_base.d.ts +4 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts +4 -1
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +31 -15
- package/dest/contracts/fee_asset_handler.d.ts +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +651 -0
- package/dest/contracts/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +14 -4
- package/dest/contracts/governance_proposer.d.ts +4 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +404 -9
- package/dest/contracts/inbox.d.ts +24 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +36 -1
- package/dest/contracts/index.d.ts +4 -1
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +3 -0
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +1 -1
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +2 -1
- package/dest/contracts/outbox.d.ts +41 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +86 -0
- 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 +177 -96
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +717 -144
- package/dest/contracts/tally_slashing_proposer.d.ts +3 -2
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +8 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +259 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +413 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +5975 -1575
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +1 -1
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +3 -3
- package/dest/l1_reader.d.ts +3 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +6 -0
- package/dest/l1_tx_utils/config.d.ts +9 -3
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +31 -4
- package/dest/l1_tx_utils/constants.d.ts +8 -2
- package/dest/l1_tx_utils/constants.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.js +27 -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/index.d.ts +10 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/index-blobs.js +2 -0
- package/dest/l1_tx_utils/index.d.ts +4 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +3 -0
- package/dest/l1_tx_utils/interfaces.d.ts +2 -2
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +18 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +75 -46
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +53 -160
- package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +65 -36
- package/dest/publisher_manager.d.ts +3 -2
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +2 -2
- package/dest/queries.d.ts +2 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +12 -4
- package/dest/test/chain_monitor.d.ts +15 -13
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +7 -9
- package/dest/test/eth_cheat_codes.d.ts +13 -1
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +4 -2
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- package/dest/test/rollup_cheat_codes.d.ts +9 -6
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +32 -6
- package/dest/test/start_anvil.d.ts +10 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +128 -29
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +16 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +80 -12
- package/package.json +33 -16
- package/src/client.ts +2 -2
- package/src/config.ts +77 -459
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +3 -1
- package/src/contracts/empire_slashing_proposer.ts +28 -28
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +280 -0
- package/src/contracts/governance.ts +13 -4
- package/src/contracts/governance_proposer.ts +16 -2
- package/src/contracts/inbox.ts +55 -3
- package/src/contracts/index.ts +3 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +5 -2
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +404 -118
- package/src/contracts/tally_slashing_proposer.ts +7 -1
- package/src/deploy_aztec_l1_contracts.ts +650 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_contract_addresses.ts +22 -20
- package/src/l1_reader.ts +8 -0
- package/src/l1_tx_utils/config.ts +44 -6
- package/src/l1_tx_utils/constants.ts +13 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +3 -0
- package/src/l1_tx_utils/interfaces.ts +1 -1
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +84 -36
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +67 -206
- package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +11 -3
- package/src/test/chain_monitor.ts +18 -16
- package/src/test/eth_cheat_codes.ts +2 -2
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +32 -9
- package/src/test/start_anvil.ts +147 -28
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +100 -15
- package/dest/deploy_l1_contracts.d.ts +0 -673
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1491
- package/dest/index.d.ts +0 -18
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -17
- 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/deploy_l1_contracts.ts +0 -1869
- package/src/index.ts +0 -17
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
package/src/test/start_anvil.ts
CHANGED
|
@@ -2,9 +2,17 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
3
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type ChildProcess, spawn } from 'child_process';
|
|
6
6
|
import { dirname, resolve } from 'path';
|
|
7
7
|
|
|
8
|
+
/** Minimal interface matching the @viem/anvil Anvil shape used by callers. */
|
|
9
|
+
export interface Anvil {
|
|
10
|
+
readonly port: number;
|
|
11
|
+
readonly host: string;
|
|
12
|
+
readonly status: 'listening' | 'idle';
|
|
13
|
+
stop(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
/**
|
|
9
17
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
10
18
|
*/
|
|
@@ -16,54 +24,165 @@ export async function startAnvil(
|
|
|
16
24
|
captureMethodCalls?: boolean;
|
|
17
25
|
accounts?: number;
|
|
18
26
|
chainId?: number;
|
|
27
|
+
/** The hardfork to use (e.g. 'cancun', 'latest'). */
|
|
28
|
+
hardfork?: string;
|
|
19
29
|
} = {},
|
|
20
30
|
): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
|
|
21
31
|
const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
|
|
22
32
|
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
23
33
|
const methodCalls = opts.captureMethodCalls ? ([] as string[]) : undefined;
|
|
24
34
|
|
|
25
|
-
let
|
|
35
|
+
let detectedPort: number | undefined;
|
|
26
36
|
|
|
27
|
-
// Start anvil.
|
|
28
|
-
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
29
37
|
const anvil = await retry(
|
|
30
38
|
async () => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
host
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
accounts
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
|
|
40
|
+
const args: string[] = [
|
|
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
|
+
|
|
59
|
+
const child = spawn(anvilBinary, args, {
|
|
60
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
61
|
+
env: { ...process.env, RAYON_NUM_THREADS: '1' },
|
|
40
62
|
});
|
|
41
63
|
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
64
|
+
// Wait for "Listening on" or an early exit.
|
|
65
|
+
await new Promise<void>((resolve, reject) => {
|
|
66
|
+
let stderr = '';
|
|
67
|
+
|
|
68
|
+
const onStdout = (data: Buffer) => {
|
|
69
|
+
const text = data.toString();
|
|
70
|
+
logger?.debug(text.trim());
|
|
71
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
45
72
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
if (detectedPort === undefined && text.includes('Listening on')) {
|
|
74
|
+
const match = text.match(/Listening on ([^:]+):(\d+)/);
|
|
75
|
+
if (match) {
|
|
76
|
+
detectedPort = parseInt(match[2]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (detectedPort !== undefined) {
|
|
80
|
+
child.stdout?.removeListener('data', onStdout);
|
|
81
|
+
child.stderr?.removeListener('data', onStderr);
|
|
82
|
+
child.removeListener('close', onClose);
|
|
83
|
+
resolve();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const onStderr = (data: Buffer) => {
|
|
88
|
+
stderr += data.toString();
|
|
89
|
+
logger?.debug(data.toString().trim());
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const onClose = (code: number | null) => {
|
|
93
|
+
child.stdout?.removeListener('data', onStdout);
|
|
94
|
+
child.stderr?.removeListener('data', onStderr);
|
|
95
|
+
reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
child.stdout?.on('data', onStdout);
|
|
99
|
+
child.stderr?.on('data', onStderr);
|
|
100
|
+
child.once('close', onClose);
|
|
50
101
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
102
|
+
|
|
103
|
+
// Continue piping for logging / method-call capture after startup.
|
|
104
|
+
if (logger || opts.captureMethodCalls) {
|
|
105
|
+
child.stdout?.on('data', (data: Buffer) => {
|
|
106
|
+
const text = data.toString();
|
|
107
|
+
logger?.debug(text.trim());
|
|
108
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
109
|
+
});
|
|
110
|
+
child.stderr?.on('data', (data: Buffer) => {
|
|
111
|
+
logger?.debug(data.toString().trim());
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
// Consume streams so the child process doesn't block on full pipe buffers.
|
|
115
|
+
child.stdout?.resume();
|
|
116
|
+
child.stderr?.resume();
|
|
54
117
|
}
|
|
55
118
|
|
|
56
|
-
return
|
|
119
|
+
return child;
|
|
57
120
|
},
|
|
58
121
|
'Start anvil',
|
|
59
122
|
makeBackoff([5, 5, 5]),
|
|
60
123
|
);
|
|
61
124
|
|
|
62
|
-
if (!
|
|
125
|
+
if (!detectedPort) {
|
|
63
126
|
throw new Error('Failed to start anvil');
|
|
64
127
|
}
|
|
65
128
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
129
|
+
const port = detectedPort;
|
|
130
|
+
let status: 'listening' | 'idle' = 'listening';
|
|
131
|
+
|
|
132
|
+
anvil.once('close', () => {
|
|
133
|
+
status = 'idle';
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const stop = async () => {
|
|
137
|
+
if (status === 'idle') {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
await killChild(anvil);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const anvilObj: Anvil = {
|
|
144
|
+
port,
|
|
145
|
+
host: '127.0.0.1',
|
|
146
|
+
get status() {
|
|
147
|
+
return status;
|
|
148
|
+
},
|
|
149
|
+
stop,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return { anvil: anvilObj, methodCalls, stop, rpcUrl: `http://127.0.0.1:${port}` };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Send SIGTERM, wait up to 5 s, then SIGKILL. All timers are always cleared. */
|
|
156
|
+
function killChild(child: ChildProcess): Promise<void> {
|
|
157
|
+
return new Promise<void>(resolve => {
|
|
158
|
+
if (child.exitCode !== null || child.killed) {
|
|
159
|
+
child.stdout?.destroy();
|
|
160
|
+
child.stderr?.destroy();
|
|
161
|
+
resolve();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let killTimer: NodeJS.Timeout | undefined;
|
|
166
|
+
|
|
167
|
+
const onClose = () => {
|
|
168
|
+
if (killTimer !== undefined) {
|
|
169
|
+
clearTimeout(killTimer);
|
|
170
|
+
}
|
|
171
|
+
// Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
|
|
172
|
+
child.stdout?.destroy();
|
|
173
|
+
child.stderr?.destroy();
|
|
174
|
+
resolve();
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
child.once('close', onClose);
|
|
178
|
+
child.kill('SIGTERM');
|
|
179
|
+
|
|
180
|
+
killTimer = setTimeout(() => {
|
|
181
|
+
killTimer = undefined;
|
|
182
|
+
child.kill('SIGKILL');
|
|
183
|
+
}, 5000);
|
|
184
|
+
|
|
185
|
+
// Ensure the timer does not prevent Node from exiting.
|
|
186
|
+
killTimer.unref();
|
|
187
|
+
});
|
|
69
188
|
}
|
|
@@ -7,7 +7,7 @@ import { type GetContractReturnType, type PrivateKeyAccount, getContract } from
|
|
|
7
7
|
|
|
8
8
|
import { extractProposalIdFromLogs } from '../contracts/governance.js';
|
|
9
9
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
10
|
-
import {
|
|
10
|
+
import { createL1TxUtils } from '../l1_tx_utils/index.js';
|
|
11
11
|
import type { ExtendedViemWalletClient, ViemPublicClient } from '../types.js';
|
|
12
12
|
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
13
13
|
|
|
@@ -22,7 +22,7 @@ export async function executeGovernanceProposal(
|
|
|
22
22
|
) {
|
|
23
23
|
const proposal = await governance.read.getProposal([proposalId]);
|
|
24
24
|
|
|
25
|
-
const l1TxUtils =
|
|
25
|
+
const l1TxUtils = createL1TxUtils(l1Client);
|
|
26
26
|
|
|
27
27
|
const waitL1Block = async () => {
|
|
28
28
|
await l1TxUtils.sendAndMonitorTransaction({
|
package/src/types.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
Client,
|
|
6
6
|
FallbackTransport,
|
|
7
7
|
GetContractReturnType,
|
|
8
|
+
Hex,
|
|
8
9
|
HttpTransport,
|
|
9
10
|
PublicActions,
|
|
10
11
|
PublicClient,
|
|
@@ -16,6 +17,67 @@ import type {
|
|
|
16
17
|
/** Type for a viem public client */
|
|
17
18
|
export type ViemPublicClient = PublicClient<FallbackTransport<HttpTransport[]>, Chain>;
|
|
18
19
|
|
|
20
|
+
export type PublicRpcDebugSchema = [
|
|
21
|
+
{
|
|
22
|
+
Method: 'debug_traceTransaction';
|
|
23
|
+
Parameters: [txHash: `0x${string}`, options: { tracer: 'callTracer' }];
|
|
24
|
+
ReturnType: DebugCallTrace;
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
Method: 'trace_transaction';
|
|
28
|
+
Parameters: [txHash: `0x${string}`];
|
|
29
|
+
ReturnType: TraceTransactionResponse[];
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/** Return type for a debug_traceTransaction call */
|
|
34
|
+
export type DebugCallTrace = {
|
|
35
|
+
from: Hex;
|
|
36
|
+
to?: Hex;
|
|
37
|
+
type: string;
|
|
38
|
+
input?: Hex;
|
|
39
|
+
output?: Hex;
|
|
40
|
+
gas?: Hex;
|
|
41
|
+
gasUsed?: Hex;
|
|
42
|
+
value?: Hex;
|
|
43
|
+
error?: string;
|
|
44
|
+
calls?: DebugCallTrace[];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Action object for a trace_transaction call */
|
|
48
|
+
export type TraceAction = {
|
|
49
|
+
from: Hex;
|
|
50
|
+
to?: Hex;
|
|
51
|
+
callType: string;
|
|
52
|
+
gas?: Hex;
|
|
53
|
+
input?: Hex;
|
|
54
|
+
value?: Hex;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Result object for a trace_transaction call */
|
|
58
|
+
export type TraceResult = {
|
|
59
|
+
gasUsed?: Hex;
|
|
60
|
+
output?: Hex;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Return type for a single trace in trace_transaction response */
|
|
64
|
+
export type TraceTransactionResponse = {
|
|
65
|
+
action: TraceAction;
|
|
66
|
+
result?: TraceResult;
|
|
67
|
+
error?: string;
|
|
68
|
+
subtraces: number;
|
|
69
|
+
traceAddress: number[];
|
|
70
|
+
type: string;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** Type for a viem public client with support for debug methods */
|
|
74
|
+
export type ViemPublicDebugClient = PublicClient<
|
|
75
|
+
FallbackTransport<HttpTransport[]>,
|
|
76
|
+
Chain,
|
|
77
|
+
undefined,
|
|
78
|
+
[...PublicRpcSchema, ...PublicRpcDebugSchema]
|
|
79
|
+
>;
|
|
80
|
+
|
|
19
81
|
export type ExtendedViemWalletClient = Client<
|
|
20
82
|
FallbackTransport<readonly HttpTransport[]>,
|
|
21
83
|
Chain,
|
package/src/utils.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
3
|
import { ErrorsAbi } from '@aztec/l1-artifacts/ErrorsAbi';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
type Abi,
|
|
7
|
+
type AbiItem,
|
|
7
8
|
BaseError,
|
|
8
9
|
type ContractEventName,
|
|
9
10
|
ContractFunctionRevertedError,
|
|
10
11
|
type DecodeEventLogReturnType,
|
|
12
|
+
type FormattedTransaction,
|
|
11
13
|
type Hex,
|
|
12
14
|
type Log,
|
|
13
15
|
decodeErrorResult,
|
|
14
16
|
decodeEventLog,
|
|
15
17
|
} from 'viem';
|
|
18
|
+
import { formatAbiItem, formatAbiParams } from 'viem/utils';
|
|
16
19
|
|
|
17
20
|
export interface L2Claim {
|
|
18
21
|
claimSecret: Fr;
|
|
@@ -92,6 +95,57 @@ export function prettyLogViemErrorMsg(err: any) {
|
|
|
92
95
|
return err?.message ?? err;
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
export function mergeAbis(abis: Abi[]): Abi {
|
|
99
|
+
let merged: Abi = [];
|
|
100
|
+
const seen = new Set<string>();
|
|
101
|
+
|
|
102
|
+
for (const abi of abis) {
|
|
103
|
+
for (const item of abi) {
|
|
104
|
+
const key = getAbiItemKey(item);
|
|
105
|
+
if (!seen.has(key)) {
|
|
106
|
+
seen.add(key);
|
|
107
|
+
merged = [...merged, item];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return merged;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getAbiItemKey(item: AbiItem): string {
|
|
116
|
+
if (item.type === 'function') {
|
|
117
|
+
const signature = formatAbiItem(item);
|
|
118
|
+
const outputs = formatAbiParams(item.outputs);
|
|
119
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
120
|
+
return `function:${signature}:${outputs}:${stateMutability}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (item.type === 'event') {
|
|
124
|
+
const signature = formatAbiItem(item);
|
|
125
|
+
const indexed = (item.inputs ?? []).map(input => ((input as { indexed?: boolean }).indexed ? '1' : '0')).join('');
|
|
126
|
+
const anonymous = item.anonymous ? 'anonymous' : 'not-anonymous';
|
|
127
|
+
return `event:${signature}:${indexed}:${anonymous}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (item.type === 'error') {
|
|
131
|
+
const signature = formatAbiItem(item);
|
|
132
|
+
return `error:${signature}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (item.type === 'constructor') {
|
|
136
|
+
const inputs = formatAbiParams(item.inputs);
|
|
137
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
138
|
+
return `constructor::${inputs}:${stateMutability}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (item.type === 'fallback' || item.type === 'receive') {
|
|
142
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
143
|
+
return `${item.type}:::${stateMutability}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return 'unknown';
|
|
147
|
+
}
|
|
148
|
+
|
|
95
149
|
function getNestedErrorData(error: unknown): string | undefined {
|
|
96
150
|
// If nothing, bail
|
|
97
151
|
if (!error) {
|
|
@@ -116,6 +170,21 @@ function getNestedErrorData(error: unknown): string | undefined {
|
|
|
116
170
|
return undefined;
|
|
117
171
|
}
|
|
118
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Truncates an error message to a safe length for log renderers.
|
|
175
|
+
* LogExplorer can only render up to 2500 characters in its summary view.
|
|
176
|
+
* We cap at 2000 to leave room for decorating context added by callers.
|
|
177
|
+
*/
|
|
178
|
+
function truncateErrorMessage(message: string): string {
|
|
179
|
+
const MAX = 2000;
|
|
180
|
+
const CHUNK = 950;
|
|
181
|
+
if (message.length <= MAX) {
|
|
182
|
+
return message;
|
|
183
|
+
}
|
|
184
|
+
const truncated = message.length - 2 * CHUNK;
|
|
185
|
+
return message.slice(0, CHUNK) + `...${truncated} characters truncated...` + message.slice(-CHUNK);
|
|
186
|
+
}
|
|
187
|
+
|
|
119
188
|
/**
|
|
120
189
|
* Formats a Viem error into a FormattedViemError instance.
|
|
121
190
|
* @param error - The error to format.
|
|
@@ -178,22 +247,10 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
178
247
|
|
|
179
248
|
// If it's a regular Error instance, return it with its message
|
|
180
249
|
if (error instanceof Error) {
|
|
181
|
-
return new FormattedViemError(error.message, (error as any)?.metaMessages);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const body = String(error);
|
|
185
|
-
const length = body.length;
|
|
186
|
-
// LogExplorer can only render up to 2500 characters in it's summary view. Try to keep the whole message below this number
|
|
187
|
-
// Limit the error to 2000 chacaters in order to allow code higher up to decorate this error with extra details (up to 500 characters)
|
|
188
|
-
if (length > 2000) {
|
|
189
|
-
const chunk = 950;
|
|
190
|
-
const truncated = length - 2 * chunk;
|
|
191
|
-
return new FormattedViemError(
|
|
192
|
-
body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk),
|
|
193
|
-
);
|
|
250
|
+
return new FormattedViemError(truncateErrorMessage(error.message), (error as any)?.metaMessages);
|
|
194
251
|
}
|
|
195
252
|
|
|
196
|
-
return new FormattedViemError(
|
|
253
|
+
return new FormattedViemError(truncateErrorMessage(String(error)));
|
|
197
254
|
}
|
|
198
255
|
|
|
199
256
|
function stripAbis(obj: any) {
|
|
@@ -233,3 +290,31 @@ export function tryGetCustomErrorName(err: any) {
|
|
|
233
290
|
return undefined;
|
|
234
291
|
}
|
|
235
292
|
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Type guard to check if a transaction is a blob transaction (EIP-4844).
|
|
296
|
+
* Blob transactions have maxFeePerBlobGas and blobVersionedHashes fields.
|
|
297
|
+
*/
|
|
298
|
+
export function isBlobTransaction(tx: FormattedTransaction): tx is FormattedTransaction & {
|
|
299
|
+
maxFeePerBlobGas: bigint;
|
|
300
|
+
blobVersionedHashes: readonly Hex[];
|
|
301
|
+
} {
|
|
302
|
+
return (
|
|
303
|
+
'maxFeePerBlobGas' in tx &&
|
|
304
|
+
tx.maxFeePerBlobGas !== undefined &&
|
|
305
|
+
'blobVersionedHashes' in tx &&
|
|
306
|
+
tx.blobVersionedHashes !== undefined
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Calculates a percentile from an array of bigints
|
|
312
|
+
*/
|
|
313
|
+
export function calculatePercentile(values: bigint[], percentile: number): bigint {
|
|
314
|
+
if (values.length === 0) {
|
|
315
|
+
return 0n;
|
|
316
|
+
}
|
|
317
|
+
const sorted = [...values].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
318
|
+
const index = Math.ceil((sorted.length - 1) * (percentile / 100));
|
|
319
|
+
return sorted[index];
|
|
320
|
+
}
|