@aztec/ethereum 0.0.1-commit.c31f2472 → 0.0.1-commit.c52d6e7
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_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 +135 -35
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +231 -18
- package/dest/contracts/governance_proposer.d.ts +33 -2
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +58 -7
- package/dest/contracts/gse.d.ts +8 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +11 -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 +5428 -31
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +414 -75
- package/dest/contracts/slashing_proposer.d.ts +170 -0
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/slashing_proposer.js +748 -0
- 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 +65 -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 +15526 -15844
- 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 -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 +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 +97 -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 +315 -13
- package/src/contracts/governance_proposer.ts +62 -10
- package/src/contracts/gse.ts +19 -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 +467 -78
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +93 -28
- package/src/deploy_aztec_l1_contracts.ts +92 -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 +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 +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 +0 -140
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/tally_slashing_proposer.js +0 -313
- 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 -270
- 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
|
@@ -4,6 +4,7 @@ import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
|
4
4
|
import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
8
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
8
9
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
9
10
|
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
getContract,
|
|
16
17
|
hexToBigInt,
|
|
17
18
|
http,
|
|
19
|
+
keccak256,
|
|
18
20
|
} from 'viem';
|
|
19
21
|
|
|
20
22
|
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
@@ -53,7 +55,17 @@ export class RollupCheatCodes {
|
|
|
53
55
|
/** Returns the current slot */
|
|
54
56
|
public async getSlot(): Promise<SlotNumber> {
|
|
55
57
|
const ts = BigInt((await this.client.getBlock()).timestamp);
|
|
56
|
-
return
|
|
58
|
+
return this.getSlotAt(ts);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Returns the slot number at a given timestamp. */
|
|
62
|
+
public async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
|
|
63
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Returns the timestamp for the start of a given slot. */
|
|
67
|
+
public async getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
|
|
68
|
+
return await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
/** Returns the number of seconds until the start of the given slot based on L1 block timestamp. */
|
|
@@ -168,6 +180,21 @@ export class RollupCheatCodes {
|
|
|
168
180
|
return [timestamp, nextSlot];
|
|
169
181
|
}
|
|
170
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Warps L1 time to the start of an explicit absolute slot. Unlike `advanceSlots(N)` which is
|
|
185
|
+
* relative to the current L1 timestamp at call time and therefore races with real-time
|
|
186
|
+
* progression between query and warp, this lands at the slot regardless of latency.
|
|
187
|
+
*
|
|
188
|
+
* Throws if the requested slot is in the past relative to current L1 time (anvil cannot
|
|
189
|
+
* rewind).
|
|
190
|
+
*/
|
|
191
|
+
public async advanceToSlot(slot: SlotNumber) {
|
|
192
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
193
|
+
await this.ethCheatCodes.warp(Number(timestamp), { silent: true, resetBlockInterval: true });
|
|
194
|
+
this.logger.warn(`Advanced to slot ${slot}`, { timestamp });
|
|
195
|
+
return timestamp;
|
|
196
|
+
}
|
|
197
|
+
|
|
171
198
|
/**
|
|
172
199
|
* Warps time in L1 equivalent to however many slots.
|
|
173
200
|
* @param howMany - The number of slots to advance.
|
|
@@ -218,6 +245,56 @@ export class RollupCheatCodes {
|
|
|
218
245
|
});
|
|
219
246
|
}
|
|
220
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Polls the rollup until its current epoch reaches `epoch`. Unlike {@link advanceToEpoch} this does
|
|
250
|
+
* not warp the L1 clock; it only waits for the chain to reach `epoch` through external activity.
|
|
251
|
+
*/
|
|
252
|
+
public async waitForEpoch(epoch: EpochNumber, opts: { timeout?: number; interval?: number } = {}): Promise<void> {
|
|
253
|
+
await retryUntil(
|
|
254
|
+
async () => (await this.getEpoch()) >= epoch || undefined,
|
|
255
|
+
`rollup epoch >= ${epoch}`,
|
|
256
|
+
opts.timeout ?? 60,
|
|
257
|
+
opts.interval ?? 1,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Polls the rollup until its current slot reaches `slot`. Unlike {@link advanceToSlot} this does not
|
|
263
|
+
* warp the L1 clock; it only waits for the chain to reach `slot` through external activity.
|
|
264
|
+
*/
|
|
265
|
+
public async waitForSlot(slot: SlotNumber, opts: { timeout?: number; interval?: number } = {}): Promise<void> {
|
|
266
|
+
await retryUntil(
|
|
267
|
+
async () => (await this.getSlot()) >= slot || undefined,
|
|
268
|
+
`rollup slot >= ${slot}`,
|
|
269
|
+
opts.timeout ?? 60,
|
|
270
|
+
opts.interval ?? 1,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Polls the rollup until its pending checkpoint settles below `checkpoint` on a freshly mined, non-zero
|
|
276
|
+
* checkpoint, and returns that new pending checkpoint number. Reads the L1 rollup contract directly
|
|
277
|
+
* rather than a node, since a rollback lands on L1 first.
|
|
278
|
+
*
|
|
279
|
+
* A prune can momentarily drop the pending checkpoint to 0 before the post-deadline propose mines its
|
|
280
|
+
* replacement, so a caller detecting a rollback wants the new lower checkpoint, not that transient
|
|
281
|
+
* empty state — hence the non-zero guard.
|
|
282
|
+
*/
|
|
283
|
+
public async waitForCheckpointBelow(
|
|
284
|
+
checkpoint: CheckpointNumber,
|
|
285
|
+
opts: { timeout?: number; interval?: number } = {},
|
|
286
|
+
): Promise<CheckpointNumber> {
|
|
287
|
+
return await retryUntil(
|
|
288
|
+
async () => {
|
|
289
|
+
const { pending } = await this.getTips();
|
|
290
|
+
return pending > 0 && pending < checkpoint ? pending : undefined;
|
|
291
|
+
},
|
|
292
|
+
`rollup checkpoint in (0, ${checkpoint})`,
|
|
293
|
+
opts.timeout ?? 60,
|
|
294
|
+
opts.interval ?? 1,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
221
298
|
/**
|
|
222
299
|
* Overrides the inProgress field of the Inbox contract state
|
|
223
300
|
* @param howMuch - How many checkpoints to move it forward
|
|
@@ -259,12 +336,14 @@ export class RollupCheatCodes {
|
|
|
259
336
|
});
|
|
260
337
|
}
|
|
261
338
|
|
|
262
|
-
public insertOutbox(epoch: EpochNumber, outHash: bigint) {
|
|
339
|
+
public insertOutbox(epoch: EpochNumber, numCheckpointsInEpoch: number, outHash: bigint) {
|
|
263
340
|
return this.ethCheatCodes.execWithPausedAnvil(async () => {
|
|
264
341
|
const outboxAddress = await this.rollup.read.getOutbox();
|
|
265
|
-
const epochRootSlot = OutboxContract.getEpochRootStorageSlot(epoch);
|
|
342
|
+
const epochRootSlot = OutboxContract.getEpochRootStorageSlot(epoch, numCheckpointsInEpoch);
|
|
266
343
|
await this.ethCheatCodes.store(EthAddress.fromString(outboxAddress), epochRootSlot, outHash);
|
|
267
|
-
this.logger.warn(
|
|
344
|
+
this.logger.warn(
|
|
345
|
+
`Advanced outbox to epoch ${epoch} numCheckpointsInEpoch ${numCheckpointsInEpoch} with out hash ${outHash}`,
|
|
346
|
+
);
|
|
268
347
|
});
|
|
269
348
|
}
|
|
270
349
|
|
|
@@ -313,7 +392,8 @@ export class RollupCheatCodes {
|
|
|
313
392
|
}
|
|
314
393
|
|
|
315
394
|
/**
|
|
316
|
-
* Directly updates proving cost per mana.
|
|
395
|
+
* Directly updates proving cost per mana. Throws if the on-chain tx reverts
|
|
396
|
+
* (e.g. rate-limit cooldown, step cap, or floor) instead of silently succeeding.
|
|
317
397
|
* @param ethValue - The new proving cost per mana in ETH
|
|
318
398
|
*/
|
|
319
399
|
public async setProvingCostPerMana(ethValue: bigint) {
|
|
@@ -323,8 +403,37 @@ export class RollupCheatCodes {
|
|
|
323
403
|
chain: this.client.chain,
|
|
324
404
|
gasLimit: 1000000n,
|
|
325
405
|
});
|
|
326
|
-
await this.client.waitForTransactionReceipt({ hash });
|
|
406
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash });
|
|
407
|
+
if (receipt.status !== 'success') {
|
|
408
|
+
throw new Error(
|
|
409
|
+
`setProvingCostPerMana(${ethValue}) reverted on L1 (tx ${hash}). ` +
|
|
410
|
+
`Likely FeeLib rate-limit (30-day cooldown or 1.5x step cap); ` +
|
|
411
|
+
`use clearProvingCostCooldown() between successive updates.`,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
327
414
|
this.logger.warn(`Updated proving cost per mana to ${ethValue}`);
|
|
328
415
|
});
|
|
329
416
|
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Resets the 30-day proving-cost update cooldown enforced by FeeLib.updateProvingCostPerMana
|
|
420
|
+
* by zeroing `FeeStore.provingCostLastUpdate` directly in contract storage. Use between
|
|
421
|
+
* successive setProvingCostPerMana / bumpProvingCostPerMana calls so the later update can
|
|
422
|
+
* land instead of reverting. Does not touch L1 time, so PXE/tx-expiration state stays intact.
|
|
423
|
+
*
|
|
424
|
+
* @note This is tightly coupled to the `FeeStore` layout in
|
|
425
|
+
* l1-contracts/src/core/libraries/rollup/FeeLib.sol:
|
|
426
|
+
* slot + 0: CompressedFeeConfig config (uint256)
|
|
427
|
+
* slot + 1: L1GasOracleValues l1GasOracleValues (14+14+4 bytes, packed)
|
|
428
|
+
* slot + 2: uint64 provingCostLastUpdate (only member — zeroing the slot is safe)
|
|
429
|
+
* If the struct layout changes, update the offset below.
|
|
430
|
+
*/
|
|
431
|
+
public async clearProvingCostCooldown() {
|
|
432
|
+
const feeStoreBaseSlot = hexToBigInt(keccak256(Buffer.from('aztec.fee.storage', 'utf-8')));
|
|
433
|
+
const provingCostLastUpdateSlot = feeStoreBaseSlot + 2n;
|
|
434
|
+
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provingCostLastUpdateSlot, 0n, {
|
|
435
|
+
silent: true,
|
|
436
|
+
});
|
|
437
|
+
this.logger.warn(`Cleared proving-cost update cooldown`);
|
|
438
|
+
}
|
|
330
439
|
}
|
package/src/test/start_anvil.ts
CHANGED
|
@@ -1,9 +1,42 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
|
-
import {
|
|
3
|
+
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
4
4
|
|
|
5
|
-
import { type
|
|
6
|
-
|
|
5
|
+
import { type ChildProcess, spawn } from 'child_process';
|
|
6
|
+
|
|
7
|
+
import { resolveFoundryBinary } from '../foundry_binary.js';
|
|
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
|
+
|
|
17
|
+
// Watchdog wrapper: instead of spawning anvil directly, we spawn a small bash supervisor that runs
|
|
18
|
+
// anvil as a background child and polls its own parent (this node process). If the parent dies for
|
|
19
|
+
// ANY reason — including SIGKILL / crash / OOM, where node's own exit handlers never run — the poll
|
|
20
|
+
// loop ends and the EXIT trap reaps anvil. The script is inlined (rather than shipped as a `.sh`) so
|
|
21
|
+
// it works from the published npm tarball too, and the resolved anvil binary is passed via
|
|
22
|
+
// `$ANVIL_BIN` so it works without `anvil` on PATH.
|
|
23
|
+
//
|
|
24
|
+
// `$@` is the anvil argv; `bash -c <script> bash <...args>` puts the args in `$@` and `$0` = 'bash'.
|
|
25
|
+
//
|
|
26
|
+
// The EXIT trap reaps anvil; INT/TERM just `exit` (which fires the EXIT trap) so a signal terminates
|
|
27
|
+
// the supervisor promptly instead of being swallowed — a trapped TERM does NOT terminate the shell,
|
|
28
|
+
// so trapping the kill directly on TERM would leave the poll loop running and the caller's teardown
|
|
29
|
+
// hanging until its SIGKILL escalation. `sleep & wait` makes the poll interruptible, so INT/TERM are
|
|
30
|
+
// handled immediately rather than after the current `sleep` returns.
|
|
31
|
+
const ANVIL_WATCHDOG = `
|
|
32
|
+
set -u
|
|
33
|
+
parent=$PPID
|
|
34
|
+
"$ANVIL_BIN" "$@" &
|
|
35
|
+
anvil_pid=$!
|
|
36
|
+
trap 'kill "$anvil_pid" 2>/dev/null' EXIT
|
|
37
|
+
trap 'exit 0' INT TERM
|
|
38
|
+
while kill -0 "$parent" 2>/dev/null; do sleep 1 & wait $!; done
|
|
39
|
+
`;
|
|
7
40
|
|
|
8
41
|
/**
|
|
9
42
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
@@ -16,56 +49,203 @@ export async function startAnvil(
|
|
|
16
49
|
captureMethodCalls?: boolean;
|
|
17
50
|
accounts?: number;
|
|
18
51
|
chainId?: number;
|
|
19
|
-
/** The hardfork to use
|
|
52
|
+
/** The hardfork to use (e.g. 'cancun', 'latest'). */
|
|
20
53
|
hardfork?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Number of slots per epoch used by anvil to compute the 'finalized' and 'safe' block tags.
|
|
56
|
+
* Anvil reports `finalized = latest - slotsInAnEpoch * 2`.
|
|
57
|
+
* Defaults to 1 so the finalized block advances immediately, making tests that check
|
|
58
|
+
* L1-finality-based logic work without needing hundreds of mined blocks.
|
|
59
|
+
*/
|
|
60
|
+
slotsInAnEpoch?: number;
|
|
61
|
+
/**
|
|
62
|
+
* If provided, the date provider will be synced to anvil's block time on every mined block.
|
|
63
|
+
* This keeps the dateProvider in lockstep with anvil's chain time, avoiding drift between
|
|
64
|
+
* the wall clock and the L1 chain when computing L1 slot timestamps.
|
|
65
|
+
*/
|
|
66
|
+
dateProvider?: TestDateProvider;
|
|
21
67
|
} = {},
|
|
22
68
|
): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
|
|
23
|
-
const anvilBinary =
|
|
69
|
+
const anvilBinary = resolveFoundryBinary('anvil');
|
|
24
70
|
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
25
71
|
const methodCalls = opts.captureMethodCalls ? ([] as string[]) : undefined;
|
|
26
72
|
|
|
27
|
-
let
|
|
73
|
+
let detectedPort: number | undefined;
|
|
28
74
|
|
|
29
|
-
// Start anvil.
|
|
30
|
-
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
31
75
|
const anvil = await retry(
|
|
32
76
|
async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
77
|
+
// `--port 0` lets anvil bind an OS-assigned ephemeral port; the actual port is read back from
|
|
78
|
+
// its "Listening on host:port" stdout below, so independent suites can spawn their own anvil
|
|
79
|
+
// in parallel without fighting over a fixed port.
|
|
80
|
+
const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
|
|
81
|
+
const args: string[] = [
|
|
82
|
+
'--host',
|
|
83
|
+
'127.0.0.1',
|
|
84
|
+
'--port',
|
|
85
|
+
String(port),
|
|
86
|
+
'--accounts',
|
|
87
|
+
String(opts.accounts ?? 20),
|
|
88
|
+
'--gas-limit',
|
|
89
|
+
String(45_000_000),
|
|
90
|
+
'--chain-id',
|
|
91
|
+
String(opts.chainId ?? 31337),
|
|
92
|
+
];
|
|
93
|
+
if (opts.l1BlockTime !== undefined) {
|
|
94
|
+
args.push('--block-time', String(opts.l1BlockTime));
|
|
95
|
+
}
|
|
96
|
+
if (opts.hardfork !== undefined) {
|
|
97
|
+
args.push('--hardfork', opts.hardfork);
|
|
98
|
+
}
|
|
99
|
+
args.push('--slots-in-an-epoch', String(opts.slotsInAnEpoch ?? 1));
|
|
100
|
+
|
|
101
|
+
// Spawn the watchdog (see ANVIL_WATCHDOG). It launches anvil with these args and reaps it if we
|
|
102
|
+
// die; `$0` is 'bash' and `$@` is the anvil argv.
|
|
103
|
+
const child = spawn('bash', ['-c', ANVIL_WATCHDOG, 'bash', ...args], {
|
|
104
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
105
|
+
env: { ...process.env, ANVIL_BIN: anvilBinary, RAYON_NUM_THREADS: '1' },
|
|
42
106
|
});
|
|
43
107
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
108
|
+
// Wait for "Listening on" or an early exit.
|
|
109
|
+
await new Promise<void>((resolve, reject) => {
|
|
110
|
+
let stderr = '';
|
|
111
|
+
|
|
112
|
+
const onStdout = (data: Buffer) => {
|
|
113
|
+
const text = data.toString();
|
|
114
|
+
logger?.debug(text.trim());
|
|
115
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
47
116
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
117
|
+
if (detectedPort === undefined && text.includes('Listening on')) {
|
|
118
|
+
const match = text.match(/Listening on ([^:]+):(\d+)/);
|
|
119
|
+
if (match) {
|
|
120
|
+
detectedPort = parseInt(match[2]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (detectedPort !== undefined) {
|
|
124
|
+
child.stdout?.removeListener('data', onStdout);
|
|
125
|
+
child.stderr?.removeListener('data', onStderr);
|
|
126
|
+
child.removeListener('close', onClose);
|
|
127
|
+
resolve();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const onStderr = (data: Buffer) => {
|
|
132
|
+
stderr += data.toString();
|
|
133
|
+
logger?.debug(data.toString().trim());
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const onClose = (code: number | null) => {
|
|
137
|
+
child.stdout?.removeListener('data', onStdout);
|
|
138
|
+
child.stderr?.removeListener('data', onStderr);
|
|
139
|
+
reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
child.stdout?.on('data', onStdout);
|
|
143
|
+
child.stderr?.on('data', onStderr);
|
|
144
|
+
child.once('close', onClose);
|
|
52
145
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
146
|
+
|
|
147
|
+
// Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
|
|
148
|
+
if (logger || opts.captureMethodCalls || opts.dateProvider) {
|
|
149
|
+
child.stdout?.on('data', (data: Buffer) => {
|
|
150
|
+
const text = data.toString();
|
|
151
|
+
logger?.debug(text.trim());
|
|
152
|
+
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
153
|
+
if (opts.dateProvider) {
|
|
154
|
+
syncDateProviderFromAnvilOutput(text, opts.dateProvider);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
child.stderr?.on('data', (data: Buffer) => {
|
|
158
|
+
logger?.debug(data.toString().trim());
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
// Consume streams so the child process doesn't block on full pipe buffers.
|
|
162
|
+
child.stdout?.resume();
|
|
163
|
+
child.stderr?.resume();
|
|
56
164
|
}
|
|
57
165
|
|
|
58
|
-
return
|
|
166
|
+
return child;
|
|
59
167
|
},
|
|
60
168
|
'Start anvil',
|
|
61
169
|
makeBackoff([5, 5, 5]),
|
|
62
170
|
);
|
|
63
171
|
|
|
64
|
-
if (!
|
|
172
|
+
if (!detectedPort) {
|
|
65
173
|
throw new Error('Failed to start anvil');
|
|
66
174
|
}
|
|
67
175
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
176
|
+
const port = detectedPort;
|
|
177
|
+
let status: 'listening' | 'idle' = 'listening';
|
|
178
|
+
|
|
179
|
+
anvil.once('close', () => {
|
|
180
|
+
status = 'idle';
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const stop = async () => {
|
|
184
|
+
if (status === 'idle') {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
await killChild(anvil);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const anvilObj: Anvil = {
|
|
191
|
+
port,
|
|
192
|
+
host: '127.0.0.1',
|
|
193
|
+
get status() {
|
|
194
|
+
return status;
|
|
195
|
+
},
|
|
196
|
+
stop,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return { anvil: anvilObj, methodCalls, stop, rpcUrl: `http://127.0.0.1:${port}` };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Extracts block time from anvil stdout and syncs the dateProvider. */
|
|
203
|
+
function syncDateProviderFromAnvilOutput(text: string, dateProvider: TestDateProvider): void {
|
|
204
|
+
// Anvil logs mined blocks as:
|
|
205
|
+
// Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
|
|
206
|
+
const match = text.match(/Block Time:\s*"([^"]+)"/);
|
|
207
|
+
if (match) {
|
|
208
|
+
const blockTimeMs = new Date(match[1]).getTime();
|
|
209
|
+
if (!isNaN(blockTimeMs)) {
|
|
210
|
+
dateProvider.setTime(blockTimeMs);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Send SIGTERM to the watchdog, wait up to 5 s, then SIGKILL. The watchdog's trap forwards the
|
|
217
|
+
* signal to anvil, so terminating it tears down anvil too. All timers are always cleared.
|
|
218
|
+
*/
|
|
219
|
+
function killChild(child: ChildProcess): Promise<void> {
|
|
220
|
+
return new Promise<void>(resolve => {
|
|
221
|
+
if (child.exitCode !== null || child.killed) {
|
|
222
|
+
child.stdout?.destroy();
|
|
223
|
+
child.stderr?.destroy();
|
|
224
|
+
resolve();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let killTimer: NodeJS.Timeout | undefined;
|
|
229
|
+
|
|
230
|
+
const onClose = () => {
|
|
231
|
+
if (killTimer !== undefined) {
|
|
232
|
+
clearTimeout(killTimer);
|
|
233
|
+
}
|
|
234
|
+
// Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
|
|
235
|
+
child.stdout?.destroy();
|
|
236
|
+
child.stderr?.destroy();
|
|
237
|
+
resolve();
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
child.once('close', onClose);
|
|
241
|
+
child.kill('SIGTERM');
|
|
242
|
+
|
|
243
|
+
killTimer = setTimeout(() => {
|
|
244
|
+
killTimer = undefined;
|
|
245
|
+
child.kill('SIGKILL');
|
|
246
|
+
}, 5000);
|
|
247
|
+
|
|
248
|
+
// Ensure the timer does not prevent Node from exiting.
|
|
249
|
+
killTimer.unref();
|
|
250
|
+
});
|
|
71
251
|
}
|
|
@@ -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
|
@@ -4,6 +4,7 @@ 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,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
decodeErrorResult,
|
|
15
16
|
decodeEventLog,
|
|
16
17
|
} from 'viem';
|
|
18
|
+
import { formatAbiItem, formatAbiParams } from 'viem/utils';
|
|
17
19
|
|
|
18
20
|
export interface L2Claim {
|
|
19
21
|
claimSecret: Fr;
|
|
@@ -25,8 +27,8 @@ export interface L2Claim {
|
|
|
25
27
|
export class FormattedViemError extends Error {
|
|
26
28
|
metaMessages?: any[];
|
|
27
29
|
|
|
28
|
-
constructor(message: string, metaMessages?: any[]) {
|
|
29
|
-
super(message);
|
|
30
|
+
constructor(message: string, metaMessages?: any[], options?: ErrorOptions) {
|
|
31
|
+
super(message, options);
|
|
30
32
|
this.name = 'FormattedViemError';
|
|
31
33
|
this.metaMessages = metaMessages;
|
|
32
34
|
}
|
|
@@ -93,6 +95,57 @@ export function prettyLogViemErrorMsg(err: any) {
|
|
|
93
95
|
return err?.message ?? err;
|
|
94
96
|
}
|
|
95
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
|
+
|
|
96
149
|
function getNestedErrorData(error: unknown): string | undefined {
|
|
97
150
|
// If nothing, bail
|
|
98
151
|
if (!error) {
|
|
@@ -117,6 +170,21 @@ function getNestedErrorData(error: unknown): string | undefined {
|
|
|
117
170
|
return undefined;
|
|
118
171
|
}
|
|
119
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
|
+
|
|
120
188
|
/**
|
|
121
189
|
* Formats a Viem error into a FormattedViemError instance.
|
|
122
190
|
* @param error - The error to format.
|
|
@@ -129,6 +197,8 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
129
197
|
return error;
|
|
130
198
|
}
|
|
131
199
|
|
|
200
|
+
const originalError = error;
|
|
201
|
+
|
|
132
202
|
// First try to decode as a custom error using the ABI
|
|
133
203
|
try {
|
|
134
204
|
const data = getNestedErrorData(error);
|
|
@@ -139,7 +209,9 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
139
209
|
data: data as Hex,
|
|
140
210
|
});
|
|
141
211
|
if (decoded) {
|
|
142
|
-
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
|
+
});
|
|
143
215
|
}
|
|
144
216
|
}
|
|
145
217
|
|
|
@@ -156,7 +228,7 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
156
228
|
revertError.metaMessages && revertError.metaMessages?.length > 1
|
|
157
229
|
? revertError.metaMessages[1].trimStart()
|
|
158
230
|
: '';
|
|
159
|
-
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages);
|
|
231
|
+
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages, { cause: originalError });
|
|
160
232
|
}
|
|
161
233
|
}
|
|
162
234
|
} catch {
|
|
@@ -179,22 +251,12 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
|
|
|
179
251
|
|
|
180
252
|
// If it's a regular Error instance, return it with its message
|
|
181
253
|
if (error instanceof Error) {
|
|
182
|
-
return new FormattedViemError(error.message, (error as any)?.metaMessages
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const body = String(error);
|
|
186
|
-
const length = body.length;
|
|
187
|
-
// LogExplorer can only render up to 2500 characters in it's summary view. Try to keep the whole message below this number
|
|
188
|
-
// Limit the error to 2000 chacaters in order to allow code higher up to decorate this error with extra details (up to 500 characters)
|
|
189
|
-
if (length > 2000) {
|
|
190
|
-
const chunk = 950;
|
|
191
|
-
const truncated = length - 2 * chunk;
|
|
192
|
-
return new FormattedViemError(
|
|
193
|
-
body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk),
|
|
194
|
-
);
|
|
254
|
+
return new FormattedViemError(truncateErrorMessage(error.message), (error as any)?.metaMessages, {
|
|
255
|
+
cause: originalError,
|
|
256
|
+
});
|
|
195
257
|
}
|
|
196
258
|
|
|
197
|
-
return new FormattedViemError(
|
|
259
|
+
return new FormattedViemError(truncateErrorMessage(String(error)), undefined, { cause: originalError });
|
|
198
260
|
}
|
|
199
261
|
|
|
200
262
|
function stripAbis(obj: any) {
|
|
@@ -220,6 +282,24 @@ function stripAbis(obj: any) {
|
|
|
220
282
|
});
|
|
221
283
|
}
|
|
222
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
|
+
|
|
223
303
|
export function tryGetCustomErrorName(err: any) {
|
|
224
304
|
try {
|
|
225
305
|
// See https://viem.sh/docs/contract/simulateContract#handling-custom-errors
|