@aztec/ethereum 0.0.1-commit.a072138 → 0.0.1-commit.a4600f49
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 +29 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +69 -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_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 +108 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +196 -15
- 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 +53 -2
- 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 -94
- 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 +5420 -31
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +402 -75
- 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} +13 -15
- package/dest/deploy_aztec_l1_contracts.d.ts +19 -12
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +54 -35
- package/dest/deploy_l1_contract.js +3 -3
- package/dest/l1_artifacts.d.ts +15524 -15847
- 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/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 +179 -82
- 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 +10 -5
- 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 -8
- 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 +69 -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 +60 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +86 -7
- 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 +143 -29
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/utils.d.ts +9 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +48 -16
- package/package.json +6 -9
- package/src/client.ts +66 -2
- package/src/config.ts +97 -18
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +269 -12
- package/src/contracts/governance_proposer.ts +54 -1
- 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 -106
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +453 -78
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
- package/src/deploy_aztec_l1_contracts.ts +76 -43
- package/src/deploy_l1_contract.ts +3 -3
- 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/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 +164 -62
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +10 -5
- 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 +143 -12
- package/src/queries.ts +76 -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 +115 -6
- package/src/test/start_anvil.ts +177 -29
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +45 -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 -207
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/generated/l1-contracts-defaults.d.ts +0 -30
- package/dest/generated/l1-contracts-defaults.d.ts.map +0 -1
- package/dest/generated/l1-contracts-defaults.js +0 -30
- 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 -259
- package/src/generated/l1-contracts-defaults.ts +0 -32
- 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
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
|
+
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
3
4
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
4
5
|
|
|
5
|
-
import { type
|
|
6
|
+
import { type ChildProcess, spawn } from 'child_process';
|
|
6
7
|
import { dirname, resolve } from 'path';
|
|
7
8
|
|
|
9
|
+
/** Minimal interface matching the @viem/anvil Anvil shape used by callers. */
|
|
10
|
+
export interface Anvil {
|
|
11
|
+
readonly port: number;
|
|
12
|
+
readonly host: string;
|
|
13
|
+
readonly status: 'listening' | 'idle';
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
/**
|
|
9
18
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
10
19
|
*/
|
|
@@ -16,56 +25,195 @@ export async function startAnvil(
|
|
|
16
25
|
captureMethodCalls?: boolean;
|
|
17
26
|
accounts?: number;
|
|
18
27
|
chainId?: number;
|
|
19
|
-
/** The hardfork to use
|
|
28
|
+
/** The hardfork to use (e.g. 'cancun', 'latest'). */
|
|
20
29
|
hardfork?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Number of slots per epoch used by anvil to compute the 'finalized' and 'safe' block tags.
|
|
32
|
+
* Anvil reports `finalized = latest - slotsInAnEpoch * 2`.
|
|
33
|
+
* Defaults to 1 so the finalized block advances immediately, making tests that check
|
|
34
|
+
* L1-finality-based logic work without needing hundreds of mined blocks.
|
|
35
|
+
*/
|
|
36
|
+
slotsInAnEpoch?: number;
|
|
37
|
+
/**
|
|
38
|
+
* If provided, the date provider will be synced to anvil's block time on every mined block.
|
|
39
|
+
* This keeps the dateProvider in lockstep with anvil's chain time, avoiding drift between
|
|
40
|
+
* the wall clock and the L1 chain when computing L1 slot timestamps.
|
|
41
|
+
*/
|
|
42
|
+
dateProvider?: TestDateProvider;
|
|
21
43
|
} = {},
|
|
22
44
|
): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
|
|
23
45
|
const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
|
|
24
46
|
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
25
47
|
const methodCalls = opts.captureMethodCalls ? ([] as string[]) : undefined;
|
|
26
48
|
|
|
27
|
-
let
|
|
49
|
+
let detectedPort: number | undefined;
|
|
28
50
|
|
|
29
|
-
// Start anvil.
|
|
30
|
-
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
31
51
|
const anvil = await retry(
|
|
32
52
|
async () => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
host
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
accounts
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
|
|
54
|
+
const args: string[] = [
|
|
55
|
+
'--host',
|
|
56
|
+
'127.0.0.1',
|
|
57
|
+
'--port',
|
|
58
|
+
String(port),
|
|
59
|
+
'--accounts',
|
|
60
|
+
String(opts.accounts ?? 20),
|
|
61
|
+
'--gas-limit',
|
|
62
|
+
String(45_000_000),
|
|
63
|
+
'--chain-id',
|
|
64
|
+
String(opts.chainId ?? 31337),
|
|
65
|
+
];
|
|
66
|
+
if (opts.l1BlockTime !== undefined) {
|
|
67
|
+
args.push('--block-time', String(opts.l1BlockTime));
|
|
68
|
+
}
|
|
69
|
+
if (opts.hardfork !== undefined) {
|
|
70
|
+
args.push('--hardfork', opts.hardfork);
|
|
71
|
+
}
|
|
72
|
+
args.push('--slots-in-an-epoch', String(opts.slotsInAnEpoch ?? 1));
|
|
73
|
+
|
|
74
|
+
const child = spawn(anvilBinary, args, {
|
|
75
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
76
|
+
env: { ...process.env, RAYON_NUM_THREADS: '1' },
|
|
42
77
|
});
|
|
43
78
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
79
|
+
// Wait for "Listening on" or an early exit.
|
|
80
|
+
await new Promise<void>((resolve, reject) => {
|
|
81
|
+
let stderr = '';
|
|
82
|
+
|
|
83
|
+
const onStdout = (data: Buffer) => {
|
|
84
|
+
const text = data.toString();
|
|
85
|
+
logger?.debug(text.trim());
|
|
86
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
87
|
+
|
|
88
|
+
if (detectedPort === undefined && text.includes('Listening on')) {
|
|
89
|
+
const match = text.match(/Listening on ([^:]+):(\d+)/);
|
|
90
|
+
if (match) {
|
|
91
|
+
detectedPort = parseInt(match[2]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (detectedPort !== undefined) {
|
|
95
|
+
child.stdout?.removeListener('data', onStdout);
|
|
96
|
+
child.stderr?.removeListener('data', onStderr);
|
|
97
|
+
child.removeListener('close', onClose);
|
|
98
|
+
resolve();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
47
101
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
102
|
+
const onStderr = (data: Buffer) => {
|
|
103
|
+
stderr += data.toString();
|
|
104
|
+
logger?.debug(data.toString().trim());
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const onClose = (code: number | null) => {
|
|
108
|
+
child.stdout?.removeListener('data', onStdout);
|
|
109
|
+
child.stderr?.removeListener('data', onStderr);
|
|
110
|
+
reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
child.stdout?.on('data', onStdout);
|
|
114
|
+
child.stderr?.on('data', onStderr);
|
|
115
|
+
child.once('close', onClose);
|
|
52
116
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
117
|
+
|
|
118
|
+
// Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
|
|
119
|
+
if (logger || opts.captureMethodCalls || opts.dateProvider) {
|
|
120
|
+
child.stdout?.on('data', (data: Buffer) => {
|
|
121
|
+
const text = data.toString();
|
|
122
|
+
logger?.debug(text.trim());
|
|
123
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
124
|
+
if (opts.dateProvider) {
|
|
125
|
+
syncDateProviderFromAnvilOutput(text, opts.dateProvider);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
child.stderr?.on('data', (data: Buffer) => {
|
|
129
|
+
logger?.debug(data.toString().trim());
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
// Consume streams so the child process doesn't block on full pipe buffers.
|
|
133
|
+
child.stdout?.resume();
|
|
134
|
+
child.stderr?.resume();
|
|
56
135
|
}
|
|
57
136
|
|
|
58
|
-
return
|
|
137
|
+
return child;
|
|
59
138
|
},
|
|
60
139
|
'Start anvil',
|
|
61
140
|
makeBackoff([5, 5, 5]),
|
|
62
141
|
);
|
|
63
142
|
|
|
64
|
-
if (!
|
|
143
|
+
if (!detectedPort) {
|
|
65
144
|
throw new Error('Failed to start anvil');
|
|
66
145
|
}
|
|
67
146
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
147
|
+
const port = detectedPort;
|
|
148
|
+
let status: 'listening' | 'idle' = 'listening';
|
|
149
|
+
|
|
150
|
+
anvil.once('close', () => {
|
|
151
|
+
status = 'idle';
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const stop = async () => {
|
|
155
|
+
if (status === 'idle') {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
await killChild(anvil);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const anvilObj: Anvil = {
|
|
162
|
+
port,
|
|
163
|
+
host: '127.0.0.1',
|
|
164
|
+
get status() {
|
|
165
|
+
return status;
|
|
166
|
+
},
|
|
167
|
+
stop,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return { anvil: anvilObj, methodCalls, stop, rpcUrl: `http://127.0.0.1:${port}` };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Extracts block time from anvil stdout and syncs the dateProvider. */
|
|
174
|
+
function syncDateProviderFromAnvilOutput(text: string, dateProvider: TestDateProvider): void {
|
|
175
|
+
// Anvil logs mined blocks as:
|
|
176
|
+
// Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
|
|
177
|
+
const match = text.match(/Block Time:\s*"([^"]+)"/);
|
|
178
|
+
if (match) {
|
|
179
|
+
const blockTimeMs = new Date(match[1]).getTime();
|
|
180
|
+
if (!isNaN(blockTimeMs)) {
|
|
181
|
+
dateProvider.setTime(blockTimeMs);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Send SIGTERM, wait up to 5 s, then SIGKILL. All timers are always cleared. */
|
|
187
|
+
function killChild(child: ChildProcess): Promise<void> {
|
|
188
|
+
return new Promise<void>(resolve => {
|
|
189
|
+
if (child.exitCode !== null || child.killed) {
|
|
190
|
+
child.stdout?.destroy();
|
|
191
|
+
child.stderr?.destroy();
|
|
192
|
+
resolve();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let killTimer: NodeJS.Timeout | undefined;
|
|
197
|
+
|
|
198
|
+
const onClose = () => {
|
|
199
|
+
if (killTimer !== undefined) {
|
|
200
|
+
clearTimeout(killTimer);
|
|
201
|
+
}
|
|
202
|
+
// Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
|
|
203
|
+
child.stdout?.destroy();
|
|
204
|
+
child.stderr?.destroy();
|
|
205
|
+
resolve();
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
child.once('close', onClose);
|
|
209
|
+
child.kill('SIGTERM');
|
|
210
|
+
|
|
211
|
+
killTimer = setTimeout(() => {
|
|
212
|
+
killTimer = undefined;
|
|
213
|
+
child.kill('SIGKILL');
|
|
214
|
+
}, 5000);
|
|
215
|
+
|
|
216
|
+
// Ensure the timer does not prevent Node from exiting.
|
|
217
|
+
killTimer.unref();
|
|
218
|
+
});
|
|
71
219
|
}
|
|
@@ -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/utils.ts
CHANGED
|
@@ -27,8 +27,8 @@ export interface L2Claim {
|
|
|
27
27
|
export class FormattedViemError extends Error {
|
|
28
28
|
metaMessages?: any[];
|
|
29
29
|
|
|
30
|
-
constructor(message: string, metaMessages?: any[]) {
|
|
31
|
-
super(message);
|
|
30
|
+
constructor(message: string, metaMessages?: any[], options?: ErrorOptions) {
|
|
31
|
+
super(message, options);
|
|
32
32
|
this.name = 'FormattedViemError';
|
|
33
33
|
this.metaMessages = metaMessages;
|
|
34
34
|
}
|
|
@@ -170,6 +170,21 @@ function getNestedErrorData(error: unknown): string | undefined {
|
|
|
170
170
|
return undefined;
|
|
171
171
|
}
|
|
172
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
|
+
|
|
173
188
|
/**
|
|
174
189
|
* Formats a Viem error into a FormattedViemError instance.
|
|
175
190
|
* @param error - The error to format.
|
|
@@ -182,6 +197,8 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
182
197
|
return error;
|
|
183
198
|
}
|
|
184
199
|
|
|
200
|
+
const originalError = error;
|
|
201
|
+
|
|
185
202
|
// First try to decode as a custom error using the ABI
|
|
186
203
|
try {
|
|
187
204
|
const data = getNestedErrorData(error);
|
|
@@ -192,7 +209,9 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
192
209
|
data: data as Hex,
|
|
193
210
|
});
|
|
194
211
|
if (decoded) {
|
|
195
|
-
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages
|
|
212
|
+
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages, {
|
|
213
|
+
cause: originalError,
|
|
214
|
+
});
|
|
196
215
|
}
|
|
197
216
|
}
|
|
198
217
|
|
|
@@ -209,7 +228,7 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
209
228
|
revertError.metaMessages && revertError.metaMessages?.length > 1
|
|
210
229
|
? revertError.metaMessages[1].trimStart()
|
|
211
230
|
: '';
|
|
212
|
-
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages);
|
|
231
|
+
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages, { cause: originalError });
|
|
213
232
|
}
|
|
214
233
|
}
|
|
215
234
|
} catch {
|
|
@@ -232,22 +251,12 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
232
251
|
|
|
233
252
|
// If it's a regular Error instance, return it with its message
|
|
234
253
|
if (error instanceof Error) {
|
|
235
|
-
return new FormattedViemError(error.message, (error as any)?.metaMessages
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const body = String(error);
|
|
239
|
-
const length = body.length;
|
|
240
|
-
// LogExplorer can only render up to 2500 characters in it's summary view. Try to keep the whole message below this number
|
|
241
|
-
// Limit the error to 2000 chacaters in order to allow code higher up to decorate this error with extra details (up to 500 characters)
|
|
242
|
-
if (length > 2000) {
|
|
243
|
-
const chunk = 950;
|
|
244
|
-
const truncated = length - 2 * chunk;
|
|
245
|
-
return new FormattedViemError(
|
|
246
|
-
body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk),
|
|
247
|
-
);
|
|
254
|
+
return new FormattedViemError(truncateErrorMessage(error.message), (error as any)?.metaMessages, {
|
|
255
|
+
cause: originalError,
|
|
256
|
+
});
|
|
248
257
|
}
|
|
249
258
|
|
|
250
|
-
return new FormattedViemError(
|
|
259
|
+
return new FormattedViemError(truncateErrorMessage(String(error)), undefined, { cause: originalError });
|
|
251
260
|
}
|
|
252
261
|
|
|
253
262
|
function stripAbis(obj: any) {
|
|
@@ -273,6 +282,24 @@ function stripAbis(obj: any) {
|
|
|
273
282
|
});
|
|
274
283
|
}
|
|
275
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Best-effort decode of a raw revert payload (`0x...`) against an ABI.
|
|
287
|
+
* Returns a human-readable `ErrorName(arg1, arg2, ...)` string, or `undefined` if the selector
|
|
288
|
+
* is unknown or the payload is empty. Use to surface decoded error names alongside the raw
|
|
289
|
+
* payload in log lines for operators.
|
|
290
|
+
*/
|
|
291
|
+
export function tryDecodeRevertReason(data: Hex | undefined, abi: Abi): string | undefined {
|
|
292
|
+
if (!data || data === '0x') {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
const decoded = decodeErrorResult({ abi, data });
|
|
297
|
+
return `${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`;
|
|
298
|
+
} catch {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
276
303
|
export function tryGetCustomErrorName(err: any) {
|
|
277
304
|
try {
|
|
278
305
|
// See https://viem.sh/docs/contract/simulateContract#handling-custom-errors
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import EventEmitter from 'events';
|
|
4
|
-
import { type Hex, type Log, type TypedDataDefinition } from 'viem';
|
|
5
|
-
import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
|
|
6
|
-
import type { ViemClient } from '../types.js';
|
|
7
|
-
import { type IEmpireBase } from './empire_base.js';
|
|
8
|
-
export declare class ProposalAlreadyExecutedError extends Error {
|
|
9
|
-
constructor(round: bigint);
|
|
10
|
-
}
|
|
11
|
-
export declare class EmpireSlashingProposerContract extends EventEmitter implements IEmpireBase {
|
|
12
|
-
readonly client: ViemClient;
|
|
13
|
-
private readonly logger;
|
|
14
|
-
private readonly proposer;
|
|
15
|
-
readonly type: "empire";
|
|
16
|
-
constructor(client: ViemClient, address: Hex | EthAddress);
|
|
17
|
-
get address(): EthAddress;
|
|
18
|
-
getQuorumSize(): Promise<bigint>;
|
|
19
|
-
getRoundSize(): Promise<bigint>;
|
|
20
|
-
getLifetimeInRounds(): Promise<bigint>;
|
|
21
|
-
getExecutionDelayInRounds(): Promise<bigint>;
|
|
22
|
-
getCurrentRound(): Promise<bigint>;
|
|
23
|
-
computeRound(slot: SlotNumber): Promise<bigint>;
|
|
24
|
-
getInstance(): Promise<`0x${string}`>;
|
|
25
|
-
getRoundInfo(rollupAddress: Hex, round: bigint): Promise<{
|
|
26
|
-
lastSignalSlot: SlotNumber;
|
|
27
|
-
payloadWithMostSignals: Hex;
|
|
28
|
-
quorumReached: boolean;
|
|
29
|
-
executed: boolean;
|
|
30
|
-
}>;
|
|
31
|
-
getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint>;
|
|
32
|
-
createSignalRequest(payload: Hex): L1TxRequest;
|
|
33
|
-
createSignalRequestWithSignature(payload: Hex, slot: SlotNumber, chainId: number, signerAddress: Hex, signer: (msg: TypedDataDefinition) => Promise<Hex>): Promise<L1TxRequest>;
|
|
34
|
-
listenToSubmittablePayloads(callback: (args: {
|
|
35
|
-
payload: `0x${string}`;
|
|
36
|
-
round: bigint;
|
|
37
|
-
}) => unknown): import("viem").WatchContractEventReturnType;
|
|
38
|
-
listenToPayloadSubmitted(callback: (args: {
|
|
39
|
-
round: bigint;
|
|
40
|
-
payload: `0x${string}`;
|
|
41
|
-
}) => unknown): import("viem").WatchContractEventReturnType;
|
|
42
|
-
listenToSignalCasted(callback: (args: {
|
|
43
|
-
round: bigint;
|
|
44
|
-
payload: `0x${string}`;
|
|
45
|
-
signaler: `0x${string}`;
|
|
46
|
-
}) => unknown): import("viem").WatchContractEventReturnType;
|
|
47
|
-
/** Creates an L1TxRequest to submit the round winner for the given round. */
|
|
48
|
-
buildExecuteRoundRequest(round: bigint): L1TxRequest;
|
|
49
|
-
/** Tries to extract a PayloadSubmitted event from the given logs. */
|
|
50
|
-
tryExtractPayloadSubmittedEvent(logs: Log[]): {
|
|
51
|
-
eventName: "PayloadSubmitted";
|
|
52
|
-
args: {
|
|
53
|
-
payload: `0x${string}`;
|
|
54
|
-
round: bigint;
|
|
55
|
-
};
|
|
56
|
-
} | undefined;
|
|
57
|
-
/**
|
|
58
|
-
* Wait for a round to be reached.
|
|
59
|
-
*
|
|
60
|
-
* @param round - The round to wait for.
|
|
61
|
-
* @param pollingIntervalSeconds - The interval in seconds to poll for the round.
|
|
62
|
-
* @returns True if the round was reached, false otherwise.
|
|
63
|
-
*/
|
|
64
|
-
waitForRound(round: bigint, pollingIntervalSeconds?: number): Promise<boolean>;
|
|
65
|
-
executeRound(txUtils: L1TxUtils, round: bigint | number): ReturnType<typeof txUtils.sendAndMonitorTransaction>;
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1waXJlX3NsYXNoaW5nX3Byb3Bvc2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3Rz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AE,GAAG,EACZ,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,GAAG,EAClB,MAAM,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,GAAG,CAAC,GACjD,OAAO,CAAC,WAAW,CAAC,CActB;IAEM,2BAA2B,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,+CAexG;IAEM,wBAAwB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,KAAK,OAAO,+CAcrG;IAEM,oBAAoB,CACzB,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,KAAK,OAAO,+CAehG;IAED,6EAA6E;IACtE,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAU1D;IAED,qEAAqE;IAC9D,+BAA+B,CAAC,IAAI,EAAE,GAAG,EAAE;;;;;;kBAEjD;IAED;;;;;;OAMG;IACI,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,sBAAsB,GAAE,MAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAavF;IAEY,YAAY,CACvB,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,MAAM,GAAG,MAAM,GACrB,UAAU,CAAC,OAAO,OAAO,CAAC,yBAAyB,CAAC,CAmCtD;CACF"}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
5
|
-
import { EmpireSlashingProposerAbi } from '@aztec/l1-artifacts/EmpireSlashingProposerAbi';
|
|
6
|
-
import EventEmitter from 'events';
|
|
7
|
-
import { encodeFunctionData, getContract } from 'viem';
|
|
8
|
-
import { FormattedViemError, tryExtractEvent } from '../utils.js';
|
|
9
|
-
import { encodeSignal, encodeSignalWithSignature, signSignalWithSig } from './empire_base.js';
|
|
10
|
-
export class ProposalAlreadyExecutedError extends Error {
|
|
11
|
-
constructor(round){
|
|
12
|
-
super(`Proposal already executed: ${round}`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export class EmpireSlashingProposerContract extends EventEmitter {
|
|
16
|
-
client;
|
|
17
|
-
logger;
|
|
18
|
-
proposer;
|
|
19
|
-
type;
|
|
20
|
-
constructor(client, address){
|
|
21
|
-
super(), this.client = client, this.logger = createLogger('ethereum:contracts:empire_slashing_proposer'), this.type = 'empire';
|
|
22
|
-
this.proposer = getContract({
|
|
23
|
-
address: typeof address === 'string' ? address : address.toString(),
|
|
24
|
-
abi: EmpireSlashingProposerAbi,
|
|
25
|
-
client
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
get address() {
|
|
29
|
-
return EthAddress.fromString(this.proposer.address);
|
|
30
|
-
}
|
|
31
|
-
getQuorumSize() {
|
|
32
|
-
return this.proposer.read.QUORUM_SIZE();
|
|
33
|
-
}
|
|
34
|
-
getRoundSize() {
|
|
35
|
-
return this.proposer.read.ROUND_SIZE();
|
|
36
|
-
}
|
|
37
|
-
getLifetimeInRounds() {
|
|
38
|
-
return this.proposer.read.LIFETIME_IN_ROUNDS();
|
|
39
|
-
}
|
|
40
|
-
getExecutionDelayInRounds() {
|
|
41
|
-
return this.proposer.read.EXECUTION_DELAY_IN_ROUNDS();
|
|
42
|
-
}
|
|
43
|
-
getCurrentRound() {
|
|
44
|
-
return this.proposer.read.getCurrentRound();
|
|
45
|
-
}
|
|
46
|
-
computeRound(slot) {
|
|
47
|
-
return this.proposer.read.computeRound([
|
|
48
|
-
BigInt(slot)
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
51
|
-
getInstance() {
|
|
52
|
-
return this.proposer.read.getInstance();
|
|
53
|
-
}
|
|
54
|
-
async getRoundInfo(rollupAddress, round) {
|
|
55
|
-
const result = await this.proposer.read.getRoundData([
|
|
56
|
-
rollupAddress,
|
|
57
|
-
round
|
|
58
|
-
]);
|
|
59
|
-
const [signalCount, quorum] = await Promise.all([
|
|
60
|
-
this.proposer.read.signalCount([
|
|
61
|
-
rollupAddress,
|
|
62
|
-
round,
|
|
63
|
-
result.payloadWithMostSignals
|
|
64
|
-
]),
|
|
65
|
-
this.getQuorumSize()
|
|
66
|
-
]);
|
|
67
|
-
return {
|
|
68
|
-
lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
|
|
69
|
-
payloadWithMostSignals: result.payloadWithMostSignals,
|
|
70
|
-
quorumReached: signalCount >= quorum,
|
|
71
|
-
executed: result.executed
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
getPayloadSignals(rollupAddress, round, payload) {
|
|
75
|
-
return this.proposer.read.signalCount([
|
|
76
|
-
rollupAddress,
|
|
77
|
-
round,
|
|
78
|
-
payload
|
|
79
|
-
]);
|
|
80
|
-
}
|
|
81
|
-
createSignalRequest(payload) {
|
|
82
|
-
return {
|
|
83
|
-
to: this.address.toString(),
|
|
84
|
-
abi: EmpireSlashingProposerAbi,
|
|
85
|
-
data: encodeSignal(payload)
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
async createSignalRequestWithSignature(payload, slot, chainId, signerAddress, signer) {
|
|
89
|
-
const signature = await signSignalWithSig(signer, payload, slot, await this.getInstance(), this.address.toString(), chainId);
|
|
90
|
-
return {
|
|
91
|
-
to: this.address.toString(),
|
|
92
|
-
abi: EmpireSlashingProposerAbi,
|
|
93
|
-
data: encodeSignalWithSignature(payload, signature)
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
listenToSubmittablePayloads(callback) {
|
|
97
|
-
return this.proposer.watchEvent.PayloadSubmittable({}, {
|
|
98
|
-
strict: true,
|
|
99
|
-
onLogs: (logs)=>{
|
|
100
|
-
for (const log of logs){
|
|
101
|
-
const { payload, round } = log.args;
|
|
102
|
-
if (payload && round) {
|
|
103
|
-
callback({
|
|
104
|
-
payload,
|
|
105
|
-
round
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
listenToPayloadSubmitted(callback) {
|
|
113
|
-
return this.proposer.watchEvent.PayloadSubmitted({}, {
|
|
114
|
-
onLogs: (logs)=>{
|
|
115
|
-
for (const log of logs){
|
|
116
|
-
const { payload, round } = log.args;
|
|
117
|
-
if (round && payload) {
|
|
118
|
-
callback({
|
|
119
|
-
round,
|
|
120
|
-
payload
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
listenToSignalCasted(callback) {
|
|
128
|
-
return this.proposer.watchEvent.SignalCast({}, {
|
|
129
|
-
onLogs: (logs)=>{
|
|
130
|
-
for (const log of logs){
|
|
131
|
-
const { round, payload, signaler } = log.args;
|
|
132
|
-
if (round && payload && signaler) {
|
|
133
|
-
callback({
|
|
134
|
-
round,
|
|
135
|
-
payload,
|
|
136
|
-
signaler
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/** Creates an L1TxRequest to submit the round winner for the given round. */ buildExecuteRoundRequest(round) {
|
|
144
|
-
return {
|
|
145
|
-
to: this.address.toString(),
|
|
146
|
-
abi: EmpireSlashingProposerAbi,
|
|
147
|
-
data: encodeFunctionData({
|
|
148
|
-
abi: EmpireSlashingProposerAbi,
|
|
149
|
-
functionName: 'submitRoundWinner',
|
|
150
|
-
args: [
|
|
151
|
-
round
|
|
152
|
-
]
|
|
153
|
-
})
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
/** Tries to extract a PayloadSubmitted event from the given logs. */ tryExtractPayloadSubmittedEvent(logs) {
|
|
157
|
-
return tryExtractEvent(logs, this.address.toString(), EmpireSlashingProposerAbi, 'PayloadSubmitted');
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Wait for a round to be reached.
|
|
161
|
-
*
|
|
162
|
-
* @param round - The round to wait for.
|
|
163
|
-
* @param pollingIntervalSeconds - The interval in seconds to poll for the round.
|
|
164
|
-
* @returns True if the round was reached, false otherwise.
|
|
165
|
-
*/ waitForRound(round, pollingIntervalSeconds = 1) {
|
|
166
|
-
return retryUntil(async ()=>{
|
|
167
|
-
const currentRound = await this.proposer.read.getCurrentRound().catch((e)=>{
|
|
168
|
-
this.logger.error('Error getting current round', e);
|
|
169
|
-
return undefined;
|
|
170
|
-
});
|
|
171
|
-
return currentRound !== undefined && currentRound >= round;
|
|
172
|
-
}, `Waiting for round ${round} to be reached`, 0, pollingIntervalSeconds).catch(()=>false);
|
|
173
|
-
}
|
|
174
|
-
async executeRound(txUtils, round) {
|
|
175
|
-
if (typeof round === 'number') {
|
|
176
|
-
round = BigInt(round);
|
|
177
|
-
}
|
|
178
|
-
const request = this.buildExecuteRoundRequest(round);
|
|
179
|
-
const response = await txUtils.sendAndMonitorTransaction(request, {
|
|
180
|
-
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
181
|
-
// for the actual slashing dynamically.
|
|
182
|
-
gasLimitBufferPercentage: 50
|
|
183
|
-
}).catch((err)=>{
|
|
184
|
-
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
185
|
-
throw new ProposalAlreadyExecutedError(round);
|
|
186
|
-
}
|
|
187
|
-
throw err;
|
|
188
|
-
});
|
|
189
|
-
if (response.receipt.status === 'reverted') {
|
|
190
|
-
const args = {
|
|
191
|
-
abi: EmpireSlashingProposerAbi,
|
|
192
|
-
functionName: 'submitRoundWinner',
|
|
193
|
-
args: [
|
|
194
|
-
round
|
|
195
|
-
],
|
|
196
|
-
address: this.address.toString()
|
|
197
|
-
};
|
|
198
|
-
const error = await txUtils.tryGetErrorFromRevertedTx(request.data, args, undefined, []);
|
|
199
|
-
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
200
|
-
throw new ProposalAlreadyExecutedError(round);
|
|
201
|
-
}
|
|
202
|
-
const errorMessage = `Failed to execute round ${round}, TxHash: ${response.receipt.transactionHash}, Error: ${error ?? 'Unknown error'}`;
|
|
203
|
-
throw new Error(errorMessage);
|
|
204
|
-
}
|
|
205
|
-
return response;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tally_slashing_proposer.d.ts","sourceRoot":"","sources":["../../src/contracts/tally_slashing_proposer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAM3D,OAAO,EAEL,KAAK,GAAG,EACR,KAAK,GAAG,EACR,KAAK,mBAAmB,EAGzB,MAAM,MAAM,CAAC;AAEd;;;GAGG;AACH,qBAAa,6BAA6B;aAMtB,MAAM,EAAE,UAAU;IALpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqE;IAE9F,SAAgB,IAAI,UAAoB;IAExC,YACkB,MAAM,EAAE,UAAU,EAClC,OAAO,EAAE,GAAG,GAAG,UAAU,EAO1B;IAED,IAAW,OAAO,eAEjB;IAEM,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAEtC;IAEM,YAAY,I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