@aztec-labs/ethereum 6.0.0-nightly.20260829
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dest/account.d.ts +2 -0
- package/dest/account.d.ts.map +1 -0
- package/dest/account.js +4 -0
- package/dest/chain.d.ts +25 -0
- package/dest/chain.d.ts.map +1 -0
- package/dest/chain.js +53 -0
- package/dest/client.d.ts +42 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +104 -0
- package/dest/config.d.ts +103 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +233 -0
- package/dest/constants.d.ts +4 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/contracts/chain_state_override.d.ts +81 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +139 -0
- package/dest/contracts/empire_base.d.ts +30 -0
- package/dest/contracts/empire_base.d.ts.map +1 -0
- package/dest/contracts/empire_base.js +84 -0
- package/dest/contracts/errors.d.ts +7 -0
- package/dest/contracts/errors.d.ts.map +1 -0
- package/dest/contracts/errors.js +12 -0
- package/dest/contracts/fee_asset_handler.d.ts +20 -0
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
- package/dest/contracts/fee_asset_handler.js +59 -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/fee_juice.d.ts +14 -0
- package/dest/contracts/fee_juice.d.ts.map +1 -0
- package/dest/contracts/fee_juice.js +59 -0
- package/dest/contracts/governance.d.ts +192 -0
- package/dest/contracts/governance.d.ts.map +1 -0
- package/dest/contracts/governance.js +471 -0
- package/dest/contracts/governance_proposer.d.ts +63 -0
- package/dest/contracts/governance_proposer.d.ts.map +1 -0
- package/dest/contracts/governance_proposer.js +536 -0
- package/dest/contracts/gse.d.ts +38 -0
- package/dest/contracts/gse.d.ts.map +1 -0
- package/dest/contracts/gse.js +81 -0
- package/dest/contracts/inbox.d.ts +94 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +141 -0
- package/dest/contracts/index.d.ts +18 -0
- package/dest/contracts/index.d.ts.map +1 -0
- package/dest/contracts/index.js +17 -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 +138 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +266 -0
- package/dest/contracts/outbox.d.ts +64 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +113 -0
- package/dest/contracts/registry.d.ts +31 -0
- package/dest/contracts/registry.d.ts.map +1 -0
- package/dest/contracts/registry.js +142 -0
- package/dest/contracts/rollup.d.ts +5836 -0
- package/dest/contracts/rollup.d.ts.map +1 -0
- package/dest/contracts/rollup.js +1612 -0
- package/dest/contracts/slasher_contract.d.ts +44 -0
- package/dest/contracts/slasher_contract.d.ts.map +1 -0
- package/dest/contracts/slasher_contract.js +75 -0
- package/dest/contracts/slashing_proposer.d.ts +174 -0
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/slashing_proposer.js +755 -0
- package/dest/contracts/utils.d.ts +3 -0
- package/dest/contracts/utils.d.ts.map +1 -0
- package/dest/contracts/utils.js +11 -0
- package/dest/contracts/watch_event.d.ts +36 -0
- package/dest/contracts/watch_event.d.ts.map +1 -0
- package/dest/contracts/watch_event.js +66 -0
- package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +424 -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/eth-signer/eth-signer.d.ts +21 -0
- package/dest/eth-signer/eth-signer.d.ts.map +1 -0
- package/dest/eth-signer/eth-signer.js +5 -0
- package/dest/eth-signer/index.d.ts +2 -0
- package/dest/eth-signer/index.d.ts.map +1 -0
- package/dest/eth-signer/index.js +1 -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/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 +81896 -0
- package/dest/l1_artifacts.d.ts.map +1 -0
- package/dest/l1_artifacts.js +151 -0
- package/dest/l1_contract_addresses.d.ts +73 -0
- package/dest/l1_contract_addresses.d.ts.map +1 -0
- package/dest/l1_contract_addresses.js +120 -0
- package/dest/l1_reader.d.ts +18 -0
- package/dest/l1_reader.d.ts.map +1 -0
- package/dest/l1_reader.js +35 -0
- package/dest/l1_tx_utils/config.d.ts +65 -0
- package/dest/l1_tx_utils/config.d.ts.map +1 -0
- package/dest/l1_tx_utils/config.js +109 -0
- package/dest/l1_tx_utils/constants.d.ts +12 -0
- package/dest/l1_tx_utils/constants.d.ts.map +1 -0
- package/dest/l1_tx_utils/constants.js +39 -0
- package/dest/l1_tx_utils/factory.d.ts +32 -0
- package/dest/l1_tx_utils/factory.d.ts.map +1 -0
- package/dest/l1_tx_utils/factory.js +22 -0
- 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 +13 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +13 -0
- package/dest/l1_tx_utils/interfaces.d.ts +76 -0
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
- package/dest/l1_tx_utils/interfaces.js +4 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +252 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +720 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +357 -0
- package/dest/l1_tx_utils/signer.d.ts +4 -0
- package/dest/l1_tx_utils/signer.d.ts.map +1 -0
- package/dest/l1_tx_utils/signer.js +16 -0
- 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/l1_tx_utils/tx_delayer.js +223 -0
- package/dest/l1_tx_utils/types.d.ts +93 -0
- package/dest/l1_tx_utils/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/types.js +36 -0
- package/dest/l1_tx_utils/utils.d.ts +4 -0
- package/dest/l1_tx_utils/utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/utils.js +14 -0
- package/dest/l1_types.d.ts +6 -0
- package/dest/l1_types.d.ts.map +1 -0
- package/dest/l1_types.js +1 -0
- package/dest/publisher_manager.d.ts +42 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +199 -0
- package/dest/queries.d.ts +25 -0
- package/dest/queries.d.ts.map +1 -0
- package/dest/queries.js +144 -0
- 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 +126 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +314 -0
- package/dest/test/eth_cheat_codes.d.ts +260 -0
- package/dest/test/eth_cheat_codes.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes.js +608 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes_with_state.js +34 -0
- package/dest/test/index.d.ts +8 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +7 -0
- package/dest/test/recording_rpc_server.d.ts +18 -0
- package/dest/test/recording_rpc_server.d.ts.map +1 -0
- package/dest/test/recording_rpc_server.js +68 -0
- package/dest/test/rollup_cheat_codes.d.ts +142 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +338 -0
- package/dest/test/start_anvil.d.ts +40 -0
- package/dest/test/start_anvil.d.ts.map +1 -0
- package/dest/test/start_anvil.js +210 -0
- package/dest/test/upgrade_utils.d.ts +12 -0
- package/dest/test/upgrade_utils.d.ts.map +1 -0
- package/dest/test/upgrade_utils.js +111 -0
- package/dest/types.d.ts +68 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +3 -0
- package/dest/utils.d.ts +45 -0
- package/dest/utils.d.ts.map +1 -0
- package/dest/utils.js +260 -0
- package/dest/zkPassportVerifierAddress.d.ts +15 -0
- package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
- package/dest/zkPassportVerifierAddress.js +11 -0
- package/package.json +122 -0
- package/src/account.ts +5 -0
- package/src/chain.ts +71 -0
- package/src/client.ts +165 -0
- package/src/config.ts +342 -0
- package/src/constants.ts +4 -0
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +203 -0
- package/src/contracts/empire_base.ts +89 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +66 -0
- package/src/contracts/fee_asset_price_oracle.ts +284 -0
- package/src/contracts/fee_juice.ts +57 -0
- package/src/contracts/governance.ts +597 -0
- package/src/contracts/governance_proposer.ts +181 -0
- package/src/contracts/gse.ts +105 -0
- package/src/contracts/inbox.ts +223 -0
- package/src/contracts/index.ts +17 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +298 -0
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +161 -0
- package/src/contracts/rollup.ts +1502 -0
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/slashing_proposer.ts +397 -0
- package/src/contracts/utils.ts +14 -0
- package/src/contracts/watch_event.ts +109 -0
- package/src/deploy_aztec_l1_contracts.ts +663 -0
- package/src/deploy_l1_contract.ts +361 -0
- package/src/eth-signer/eth-signer.ts +24 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/forwarder_proxy.ts +107 -0
- package/src/foundry_binary.ts +57 -0
- package/src/l1_artifacts.ts +231 -0
- package/src/l1_contract_addresses.ts +149 -0
- package/src/l1_reader.ts +57 -0
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +181 -0
- package/src/l1_tx_utils/constants.ts +29 -0
- package/src/l1_tx_utils/factory.ts +64 -0
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +162 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +244 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +55 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +107 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +15 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +874 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +840 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +459 -0
- package/src/l1_tx_utils/signer.ts +27 -0
- package/src/l1_tx_utils/tx_delayer.ts +302 -0
- package/src/l1_tx_utils/types.ts +116 -0
- package/src/l1_tx_utils/utils.ts +15 -0
- package/src/l1_types.ts +6 -0
- package/src/publisher_manager.ts +239 -0
- package/src/queries.ts +189 -0
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +389 -0
- package/src/test/eth_cheat_codes.ts +624 -0
- package/src/test/eth_cheat_codes_with_state.ts +38 -0
- package/src/test/index.ts +7 -0
- package/src/test/recording_rpc_server.ts +69 -0
- package/src/test/rollup_cheat_codes.ts +398 -0
- package/src/test/start_anvil.ts +255 -0
- package/src/test/upgrade_utils.ts +109 -0
- package/src/types.ts +97 -0
- package/src/utils.ts +344 -0
- package/src/zkPassportVerifierAddress.ts +15 -0
package/dest/utils.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { ErrorsAbi } from '@aztec/l1-artifacts/ErrorsAbi';
|
|
2
|
+
import { BaseError, ContractFunctionRevertedError, decodeErrorResult, decodeEventLog } from 'viem';
|
|
3
|
+
import { formatAbiItem, formatAbiParams } from 'viem/utils';
|
|
4
|
+
export class FormattedViemError extends Error {
|
|
5
|
+
metaMessages;
|
|
6
|
+
constructor(message, metaMessages, options){
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = 'FormattedViemError';
|
|
9
|
+
this.metaMessages = metaMessages;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function extractEvent(logs, address, abi, eventName, filter, logger) {
|
|
13
|
+
const event = tryExtractEvent(logs, address, abi, eventName, filter, logger);
|
|
14
|
+
if (!event) {
|
|
15
|
+
throw new Error(`Failed to find matching event ${eventName} for contract ${address}`);
|
|
16
|
+
}
|
|
17
|
+
return event;
|
|
18
|
+
}
|
|
19
|
+
export function tryExtractEvent(logs, address, abi, eventName, filter, logger) {
|
|
20
|
+
for (const log of logs){
|
|
21
|
+
if (log.address.toLowerCase() === address.toLowerCase()) {
|
|
22
|
+
try {
|
|
23
|
+
const decodedEvent = decodeEventLog({
|
|
24
|
+
abi,
|
|
25
|
+
...log
|
|
26
|
+
});
|
|
27
|
+
if (decodedEvent.eventName === eventName) {
|
|
28
|
+
const matchingEvent = decodedEvent;
|
|
29
|
+
if (!filter || filter(matchingEvent)) {
|
|
30
|
+
return matchingEvent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
logger?.warn(`Failed to decode event log for contract ${address}: ${err}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function prettyLogViemErrorMsg(err) {
|
|
40
|
+
if (err instanceof BaseError) {
|
|
41
|
+
const revertError = err.walk((err)=>err instanceof ContractFunctionRevertedError);
|
|
42
|
+
if (revertError instanceof ContractFunctionRevertedError) {
|
|
43
|
+
const errorName = revertError.data?.errorName ?? '';
|
|
44
|
+
const args = revertError.metaMessages && revertError.metaMessages?.length > 1 ? revertError.metaMessages[1].trimStart() : '';
|
|
45
|
+
return `${errorName}${args}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return err?.message ?? err;
|
|
49
|
+
}
|
|
50
|
+
export function mergeAbis(abis) {
|
|
51
|
+
let merged = [];
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
for (const abi of abis){
|
|
54
|
+
for (const item of abi){
|
|
55
|
+
const key = getAbiItemKey(item);
|
|
56
|
+
if (!seen.has(key)) {
|
|
57
|
+
seen.add(key);
|
|
58
|
+
merged = [
|
|
59
|
+
...merged,
|
|
60
|
+
item
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return merged;
|
|
66
|
+
}
|
|
67
|
+
function getAbiItemKey(item) {
|
|
68
|
+
if (item.type === 'function') {
|
|
69
|
+
const signature = formatAbiItem(item);
|
|
70
|
+
const outputs = formatAbiParams(item.outputs);
|
|
71
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
72
|
+
return `function:${signature}:${outputs}:${stateMutability}`;
|
|
73
|
+
}
|
|
74
|
+
if (item.type === 'event') {
|
|
75
|
+
const signature = formatAbiItem(item);
|
|
76
|
+
const indexed = (item.inputs ?? []).map((input)=>input.indexed ? '1' : '0').join('');
|
|
77
|
+
const anonymous = item.anonymous ? 'anonymous' : 'not-anonymous';
|
|
78
|
+
return `event:${signature}:${indexed}:${anonymous}`;
|
|
79
|
+
}
|
|
80
|
+
if (item.type === 'error') {
|
|
81
|
+
const signature = formatAbiItem(item);
|
|
82
|
+
return `error:${signature}`;
|
|
83
|
+
}
|
|
84
|
+
if (item.type === 'constructor') {
|
|
85
|
+
const inputs = formatAbiParams(item.inputs);
|
|
86
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
87
|
+
return `constructor::${inputs}:${stateMutability}`;
|
|
88
|
+
}
|
|
89
|
+
if (item.type === 'fallback' || item.type === 'receive') {
|
|
90
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
91
|
+
return `${item.type}:::${stateMutability}`;
|
|
92
|
+
}
|
|
93
|
+
return 'unknown';
|
|
94
|
+
}
|
|
95
|
+
function getNestedErrorData(error) {
|
|
96
|
+
// If nothing, bail
|
|
97
|
+
if (!error) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
// If it's an object with a `data` property, return it
|
|
101
|
+
// (Remember to check TS type-safely or cast as needed)
|
|
102
|
+
if (typeof error === 'object' && error !== null && 'data' in error) {
|
|
103
|
+
const possibleData = error.data;
|
|
104
|
+
if (typeof possibleData === 'string' && possibleData.startsWith('0x')) {
|
|
105
|
+
return possibleData;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// If it has a `cause`, recurse
|
|
109
|
+
if (typeof error === 'object' && error !== null && 'cause' in error) {
|
|
110
|
+
return getNestedErrorData(error.cause);
|
|
111
|
+
}
|
|
112
|
+
// Not found
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Truncates an error message to a safe length for log renderers.
|
|
117
|
+
* LogExplorer can only render up to 2500 characters in its summary view.
|
|
118
|
+
* We cap at 2000 to leave room for decorating context added by callers.
|
|
119
|
+
*/ function truncateErrorMessage(message) {
|
|
120
|
+
const MAX = 2000;
|
|
121
|
+
const CHUNK = 950;
|
|
122
|
+
if (message.length <= MAX) {
|
|
123
|
+
return message;
|
|
124
|
+
}
|
|
125
|
+
const truncated = message.length - 2 * CHUNK;
|
|
126
|
+
return message.slice(0, CHUNK) + `...${truncated} characters truncated...` + message.slice(-CHUNK);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Formats a Viem error into a FormattedViemError instance.
|
|
130
|
+
* @param error - The error to format.
|
|
131
|
+
* @param abi - The ABI to use for decoding.
|
|
132
|
+
* @returns A FormattedViemError instance.
|
|
133
|
+
*/ export function formatViemError(error, abi = ErrorsAbi) {
|
|
134
|
+
// If error is already a FormattedViemError, return it as is
|
|
135
|
+
if (error instanceof FormattedViemError) {
|
|
136
|
+
return error;
|
|
137
|
+
}
|
|
138
|
+
const originalError = error;
|
|
139
|
+
// First try to decode as a custom error using the ABI
|
|
140
|
+
try {
|
|
141
|
+
const data = getNestedErrorData(error);
|
|
142
|
+
if (data) {
|
|
143
|
+
// Try to decode the error data using the ABI
|
|
144
|
+
const decoded = decodeErrorResult({
|
|
145
|
+
abi,
|
|
146
|
+
data: data
|
|
147
|
+
});
|
|
148
|
+
if (decoded) {
|
|
149
|
+
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages, {
|
|
150
|
+
cause: originalError
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// If it's a BaseError, try to get the custom error through ContractFunctionRevertedError
|
|
155
|
+
if (error instanceof BaseError) {
|
|
156
|
+
const revertError = error.walk((err)=>err instanceof ContractFunctionRevertedError);
|
|
157
|
+
if (revertError instanceof ContractFunctionRevertedError) {
|
|
158
|
+
let errorName = revertError.data?.errorName;
|
|
159
|
+
if (!errorName) {
|
|
160
|
+
errorName = revertError.signature ?? '';
|
|
161
|
+
}
|
|
162
|
+
const args = revertError.metaMessages && revertError.metaMessages?.length > 1 ? revertError.metaMessages[1].trimStart() : '';
|
|
163
|
+
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages, {
|
|
164
|
+
cause: originalError
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
// If decoding fails, we fall back to the original formatting
|
|
170
|
+
}
|
|
171
|
+
// Strip ABI from the error object before formatting
|
|
172
|
+
if (error && typeof error === 'object') {
|
|
173
|
+
// Create a clone to avoid modifying the original
|
|
174
|
+
const errorClone = structuredClone(error);
|
|
175
|
+
// Helper function to recursively remove ABI properties
|
|
176
|
+
// Strip ABIs from the clone
|
|
177
|
+
stripAbis(errorClone);
|
|
178
|
+
// Use the cleaned clone for further processing
|
|
179
|
+
error = errorClone;
|
|
180
|
+
}
|
|
181
|
+
// If it's a regular Error instance, return it with its message
|
|
182
|
+
if (error instanceof Error) {
|
|
183
|
+
return new FormattedViemError(truncateErrorMessage(error.message), error?.metaMessages, {
|
|
184
|
+
cause: originalError
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return new FormattedViemError(truncateErrorMessage(String(error)), undefined, {
|
|
188
|
+
cause: originalError
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function stripAbis(obj) {
|
|
192
|
+
if (!obj || typeof obj !== 'object') {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// Delete ABI property at current level
|
|
196
|
+
if ('abi' in obj) {
|
|
197
|
+
delete obj.abi;
|
|
198
|
+
}
|
|
199
|
+
// Process cause property
|
|
200
|
+
if (obj.cause) {
|
|
201
|
+
stripAbis(obj.cause);
|
|
202
|
+
}
|
|
203
|
+
// Process arrays and objects
|
|
204
|
+
Object.values(obj).forEach((value)=>{
|
|
205
|
+
if (value && typeof value === 'object') {
|
|
206
|
+
stripAbis(value);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Best-effort decode of a raw revert payload (`0x...`) against an ABI.
|
|
212
|
+
* Returns a human-readable `ErrorName(arg1, arg2, ...)` string, or `undefined` if the selector
|
|
213
|
+
* is unknown or the payload is empty. Use to surface decoded error names alongside the raw
|
|
214
|
+
* payload in log lines for operators.
|
|
215
|
+
*/ export function tryDecodeRevertReason(data, abi) {
|
|
216
|
+
if (!data || data === '0x') {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const decoded = decodeErrorResult({
|
|
221
|
+
abi,
|
|
222
|
+
data
|
|
223
|
+
});
|
|
224
|
+
return `${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`;
|
|
225
|
+
} catch {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
export function tryGetCustomErrorName(err) {
|
|
230
|
+
try {
|
|
231
|
+
// See https://viem.sh/docs/contract/simulateContract#handling-custom-errors
|
|
232
|
+
if (err.name === 'ViemError' || err.name === 'ContractFunctionExecutionError') {
|
|
233
|
+
const baseError = err;
|
|
234
|
+
const revertError = baseError.walk((err)=>err.name === 'ContractFunctionRevertedError');
|
|
235
|
+
if (revertError) {
|
|
236
|
+
return revertError.data?.errorName;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} catch {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Type guard to check if a transaction is a blob transaction (EIP-4844).
|
|
245
|
+
* Blob transactions have maxFeePerBlobGas and blobVersionedHashes fields.
|
|
246
|
+
*/ export function isBlobTransaction(tx) {
|
|
247
|
+
return 'maxFeePerBlobGas' in tx && tx.maxFeePerBlobGas !== undefined && 'blobVersionedHashes' in tx && tx.blobVersionedHashes !== undefined;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Calculates a percentile from an array of bigints
|
|
251
|
+
*/ export function calculatePercentile(values, percentile) {
|
|
252
|
+
if (values.length === 0) {
|
|
253
|
+
return 0n;
|
|
254
|
+
}
|
|
255
|
+
const sorted = [
|
|
256
|
+
...values
|
|
257
|
+
].sort((a, b)=>a < b ? -1 : a > b ? 1 : 0);
|
|
258
|
+
const index = Math.ceil((sorted.length - 1) * (percentile / 100));
|
|
259
|
+
return sorted[index];
|
|
260
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
2
|
+
/**
|
|
3
|
+
* The address of the zk passport verifier on sepolia
|
|
4
|
+
* get address from: ROOT/l1-contracts/lib/circuits/src/solidity/deployments/deployment-11155111.json
|
|
5
|
+
*/
|
|
6
|
+
export declare const ZK_PASSPORT_VERIFIER_ADDRESS: EthAddress;
|
|
7
|
+
/**
|
|
8
|
+
* The default domain of the zk passport site
|
|
9
|
+
*/
|
|
10
|
+
export declare const ZK_PASSPORT_DOMAIN = "testnet.aztec.network";
|
|
11
|
+
/**
|
|
12
|
+
* The default scope of the zk passport proofs
|
|
13
|
+
*/
|
|
14
|
+
export declare const ZK_PASSPORT_SCOPE = "personhood";
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiemtQYXNzcG9ydFZlcmlmaWVyQWRkcmVzcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3prUGFzc3BvcnRWZXJpZmllckFkZHJlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLG9DQUFvQyxDQUFDO0FBRWhFOzs7R0FHRztBQUNILGVBQU8sTUFBTSw0QkFBNEIsWUFBc0UsQ0FBQztBQUNoSDs7R0FFRztBQUNILGVBQU8sTUFBTSxrQkFBa0IsMEJBQTBCLENBQUM7QUFDMUQ7O0dBRUc7QUFDSCxlQUFPLE1BQU0saUJBQWlCLGVBQWUsQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkPassportVerifierAddress.d.ts","sourceRoot":"","sources":["../src/zkPassportVerifierAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,4BAA4B,YAAsE,CAAC;AAChH;;GAEG;AACH,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAAe,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
2
|
+
/**
|
|
3
|
+
* The address of the zk passport verifier on sepolia
|
|
4
|
+
* get address from: ROOT/l1-contracts/lib/circuits/src/solidity/deployments/deployment-11155111.json
|
|
5
|
+
*/ export const ZK_PASSPORT_VERIFIER_ADDRESS = EthAddress.fromString('0x3101Bad9eA5fACadA5554844a1a88F7Fe48D4DE0');
|
|
6
|
+
/**
|
|
7
|
+
* The default domain of the zk passport site
|
|
8
|
+
*/ export const ZK_PASSPORT_DOMAIN = 'testnet.aztec.network';
|
|
9
|
+
/**
|
|
10
|
+
* The default scope of the zk passport proofs
|
|
11
|
+
*/ export const ZK_PASSPORT_SCOPE = 'personhood';
|
package/package.json
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec-labs/ethereum",
|
|
3
|
+
"version": "6.0.0-nightly.20260829",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./account": "./dest/account.js",
|
|
7
|
+
"./chain": "./dest/chain.js",
|
|
8
|
+
"./client": "./dest/client.js",
|
|
9
|
+
"./config": "./dest/config.js",
|
|
10
|
+
"./constants": "./dest/constants.js",
|
|
11
|
+
"./contracts": "./dest/contracts/index.js",
|
|
12
|
+
"./deploy-aztec-l1-contracts": "./dest/deploy_aztec_l1_contracts.js",
|
|
13
|
+
"./deploy-l1-contract": "./dest/deploy_l1_contract.js",
|
|
14
|
+
"./contracts/registry": "./dest/contracts/registry.js",
|
|
15
|
+
"./contracts/rollup": "./dest/contracts/rollup.js",
|
|
16
|
+
"./eth-signer": "./dest/eth-signer/index.js",
|
|
17
|
+
"./forwarder-proxy": "./dest/forwarder_proxy.js",
|
|
18
|
+
"./l1-artifacts": "./dest/l1_artifacts.js",
|
|
19
|
+
"./l1-contract-addresses": "./dest/l1_contract_addresses.js",
|
|
20
|
+
"./l1-fee-analysis": "./dest/l1_tx_utils/l1_fee_analyzer.js",
|
|
21
|
+
"./l1-reader": "./dest/l1_reader.js",
|
|
22
|
+
"./l1-tx-utils": "./dest/l1_tx_utils/index.js",
|
|
23
|
+
"./l1-tx-utils-with-blobs": "./dest/l1_tx_utils/index-blobs.js",
|
|
24
|
+
"./l1-tx-utils/config": "./dest/l1_tx_utils/config.js",
|
|
25
|
+
"./l1-types": "./dest/l1_types.js",
|
|
26
|
+
"./publisher-manager": "./dest/publisher_manager.js",
|
|
27
|
+
"./queries": "./dest/queries.js",
|
|
28
|
+
"./test": "./dest/test/index.js",
|
|
29
|
+
"./types": "./dest/types.js",
|
|
30
|
+
"./utils": "./dest/utils.js"
|
|
31
|
+
},
|
|
32
|
+
"typedocOptions": {
|
|
33
|
+
"entryPoints": [
|
|
34
|
+
"./src/index.ts"
|
|
35
|
+
],
|
|
36
|
+
"name": "Ethereum",
|
|
37
|
+
"tsconfig": "./tsconfig.json"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
41
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
42
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
43
|
+
"start:dev": "concurrently -k \"../scripts/tsc.sh --watch\" \"nodemon --watch dest --exec yarn start\"",
|
|
44
|
+
"start": "node ./dest/index.js",
|
|
45
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
46
|
+
"proposer-address": "node ./dest/cli/forwarder_address.js"
|
|
47
|
+
},
|
|
48
|
+
"inherits": [
|
|
49
|
+
"../package.common.json"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@aztec-labs/blob-lib": "6.0.0-nightly.20260829",
|
|
53
|
+
"@aztec-labs/foundation": "6.0.0-nightly.20260829",
|
|
54
|
+
"@aztec/l1-artifacts": "6.0.0-nightly.20260826",
|
|
55
|
+
"dotenv": "^16.0.3",
|
|
56
|
+
"lodash.chunk": "^4.2.0",
|
|
57
|
+
"lodash.pickby": "^4.5.0",
|
|
58
|
+
"tslib": "^2.4.0",
|
|
59
|
+
"viem": "npm:@aztec/viem@2.38.2",
|
|
60
|
+
"zod": "^4"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@jest/globals": "^30.0.0",
|
|
64
|
+
"@noble/curves": "=1.7.0",
|
|
65
|
+
"@types/jest": "^30.0.0",
|
|
66
|
+
"@types/lodash.pickby": "^4",
|
|
67
|
+
"@types/node": "^22.15.17",
|
|
68
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
69
|
+
"get-port": "^7.1.0",
|
|
70
|
+
"jest": "^30.0.0",
|
|
71
|
+
"jest-mock-extended": "^4.0.0",
|
|
72
|
+
"lodash.omit": "^4.5.0",
|
|
73
|
+
"ts-node": "^10.9.1",
|
|
74
|
+
"typescript": "^5.3.3"
|
|
75
|
+
},
|
|
76
|
+
"files": [
|
|
77
|
+
"dest",
|
|
78
|
+
"src",
|
|
79
|
+
"!*.test.*"
|
|
80
|
+
],
|
|
81
|
+
"types": "./dest/types.d.ts",
|
|
82
|
+
"jest": {
|
|
83
|
+
"moduleNameMapper": {
|
|
84
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
85
|
+
},
|
|
86
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
87
|
+
"rootDir": "./src",
|
|
88
|
+
"transform": {
|
|
89
|
+
"^.+\\.tsx?$": [
|
|
90
|
+
"@swc/jest",
|
|
91
|
+
{
|
|
92
|
+
"jsc": {
|
|
93
|
+
"parser": {
|
|
94
|
+
"syntax": "typescript",
|
|
95
|
+
"decorators": true
|
|
96
|
+
},
|
|
97
|
+
"transform": {
|
|
98
|
+
"decoratorVersion": "2022-03"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"extensionsToTreatAsEsm": [
|
|
105
|
+
".ts"
|
|
106
|
+
],
|
|
107
|
+
"reporters": [
|
|
108
|
+
"default"
|
|
109
|
+
],
|
|
110
|
+
"testTimeout": 120000,
|
|
111
|
+
"setupFiles": [
|
|
112
|
+
"../../foundation/src/jest/setup.mjs"
|
|
113
|
+
],
|
|
114
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
115
|
+
"setupFilesAfterEnv": [
|
|
116
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"engines": {
|
|
120
|
+
"node": ">=20.10"
|
|
121
|
+
}
|
|
122
|
+
}
|
package/src/account.ts
ADDED
package/src/chain.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Chain } from 'viem';
|
|
2
|
+
import { foundry } from 'viem/chains';
|
|
3
|
+
|
|
4
|
+
import { AZTEC_TEST_CHAIN_ID } from './constants.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interface containing the connection and chain properties to interact with a blockchain.
|
|
8
|
+
*/
|
|
9
|
+
export interface EthereumChain {
|
|
10
|
+
/**
|
|
11
|
+
* An instance of the viem chain data.
|
|
12
|
+
*/
|
|
13
|
+
chainInfo: Chain;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The list of actual urls to be used.
|
|
17
|
+
*/
|
|
18
|
+
rpcUrls: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Helper function to create an instance of Aztec Chain from an rpc url and chain id.
|
|
23
|
+
* @param rpcUrls - The rpc url of the chain or a chain identifier (e.g. 'http://localhost:8545')
|
|
24
|
+
* @param chainId - The chain id of the chain or a chain identifier (e.g. 1337)
|
|
25
|
+
*/
|
|
26
|
+
export function createEthereumChain(rpcUrls: string[], _chainId: number | string): EthereumChain {
|
|
27
|
+
let chainId: number;
|
|
28
|
+
if (typeof _chainId === 'string') {
|
|
29
|
+
chainId = +_chainId;
|
|
30
|
+
} else {
|
|
31
|
+
chainId = _chainId;
|
|
32
|
+
}
|
|
33
|
+
if (chainId) {
|
|
34
|
+
return {
|
|
35
|
+
chainInfo: {
|
|
36
|
+
id: chainId,
|
|
37
|
+
name: 'Ethereum',
|
|
38
|
+
rpcUrls: {
|
|
39
|
+
default: {
|
|
40
|
+
http: rpcUrls,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
nativeCurrency: {
|
|
44
|
+
decimals: 18,
|
|
45
|
+
name: 'Ether',
|
|
46
|
+
symbol: 'ETH',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
rpcUrls,
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
return {
|
|
53
|
+
chainInfo: foundry,
|
|
54
|
+
rpcUrls,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Helper function to determine if a chain id is an instance of Anvil
|
|
61
|
+
*/
|
|
62
|
+
export function isAnvilTestChain(_chainId: number | string): boolean {
|
|
63
|
+
let chainId: number;
|
|
64
|
+
if (typeof _chainId === 'string') {
|
|
65
|
+
chainId = +_chainId;
|
|
66
|
+
} else {
|
|
67
|
+
chainId = _chainId;
|
|
68
|
+
}
|
|
69
|
+
const testChains = [foundry.id, AZTEC_TEST_CHAIN_ID];
|
|
70
|
+
return testChains.includes(chainId);
|
|
71
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Logger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import { retryUntil } from '@aztec-labs/foundation/retry';
|
|
3
|
+
import { getErrorCause } from '@aztec-labs/foundation/types';
|
|
4
|
+
import {
|
|
5
|
+
type Chain,
|
|
6
|
+
type FallbackTransport,
|
|
7
|
+
type HDAccount,
|
|
8
|
+
HttpRequestError,
|
|
9
|
+
type HttpTransport,
|
|
10
|
+
type LocalAccount,
|
|
11
|
+
type PrivateKeyAccount,
|
|
12
|
+
RpcRequestError,
|
|
13
|
+
createPublicClient,
|
|
14
|
+
createWalletClient,
|
|
15
|
+
fallback,
|
|
16
|
+
http,
|
|
17
|
+
publicActions,
|
|
18
|
+
} from 'viem';
|
|
19
|
+
import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
20
|
+
import { foundry } from 'viem/chains';
|
|
21
|
+
|
|
22
|
+
import { createEthereumChain } from './chain.js';
|
|
23
|
+
import type { ExtendedViemWalletClient, ViemPublicClient } from './types.js';
|
|
24
|
+
|
|
25
|
+
type Config = {
|
|
26
|
+
/** List of URLs of Ethereum RPC nodes that services will connect to (comma separated). */
|
|
27
|
+
l1RpcUrls: string[];
|
|
28
|
+
/** The chain ID of the ethereum host. */
|
|
29
|
+
l1ChainId: number;
|
|
30
|
+
/** The polling interval viem uses in ms */
|
|
31
|
+
viemPollingIntervalMS?: number;
|
|
32
|
+
/** Timeout for HTTP requests to the L1 RPC node in ms. */
|
|
33
|
+
l1HttpTimeoutMS?: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type { Config as EthereumClientConfig };
|
|
37
|
+
|
|
38
|
+
/** Error exposed by L1 RPC transports without including provider URLs in its message. */
|
|
39
|
+
export class L1RpcError extends Error {
|
|
40
|
+
constructor(message: string, options?: ErrorOptions) {
|
|
41
|
+
super(message, options);
|
|
42
|
+
this.name = 'L1RpcError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Creates a viem fallback HTTP transport for the given L1 RPC URLs. */
|
|
47
|
+
export function makeL1HttpTransport(rpcUrls: string[], opts?: { timeout?: number }) {
|
|
48
|
+
return wrapL1RpcTransport(fallback(rpcUrls.map(url => http(url, { batch: false, timeout: opts?.timeout }))));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Returns the HTTP status from an L1 RPC error's cause chain, if one is available. */
|
|
52
|
+
export function getL1RpcHttpStatus(err: unknown): number | undefined {
|
|
53
|
+
return getErrorCause(err, HttpRequestError)?.status;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Returns true when an L1 RPC error's cause chain contains the given HTTP status. */
|
|
57
|
+
export function isL1RpcHttpStatus(err: unknown, status: number): boolean {
|
|
58
|
+
return getL1RpcHttpStatus(err) === status;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Returns the JSON-RPC error code reported by the L1 node, if the error's cause chain carries one. */
|
|
62
|
+
export function getL1RpcErrorCode(err: unknown): number | undefined {
|
|
63
|
+
return getErrorCause(err, RpcRequestError)?.code;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function wrapL1RpcTransport(transport: FallbackTransport<HttpTransport[]>): FallbackTransport<HttpTransport[]> {
|
|
67
|
+
const wrappedTransport: FallbackTransport<HttpTransport[]> = parameters => {
|
|
68
|
+
const fallbackTransport = transport(parameters);
|
|
69
|
+
const request: typeof fallbackTransport.request = async args => {
|
|
70
|
+
try {
|
|
71
|
+
return await fallbackTransport.request(args);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
throw err instanceof L1RpcError ? err : new L1RpcError('L1 RPC request failed', { cause: err });
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return { ...fallbackTransport, request };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return wrappedTransport;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns the individual RPC URLs underlying a viem public client that was constructed with a
|
|
84
|
+
* fallback HTTP transport (see {@link makeL1HttpTransport}). Returns an empty array if the
|
|
85
|
+
* transport shape is not recognized (e.g. mock clients in tests, or non-fallback transports).
|
|
86
|
+
*/
|
|
87
|
+
export function getRpcUrlsFromClient(client: ViemPublicClient): string[] {
|
|
88
|
+
const transport = client.transport as unknown as {
|
|
89
|
+
transports?: { value?: { url?: string } }[];
|
|
90
|
+
value?: { url?: string };
|
|
91
|
+
url?: string;
|
|
92
|
+
};
|
|
93
|
+
if (Array.isArray(transport?.transports)) {
|
|
94
|
+
return transport.transports.map(t => t?.value?.url).filter((url): url is string => typeof url === 'string');
|
|
95
|
+
}
|
|
96
|
+
const singleUrl = transport?.value?.url ?? transport?.url;
|
|
97
|
+
return typeof singleUrl === 'string' ? [singleUrl] : [];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// TODO: Use these methods to abstract the creation of viem clients.
|
|
101
|
+
|
|
102
|
+
/** Returns a viem public client given the L1 config. */
|
|
103
|
+
export function getPublicClient(config: Config): ViemPublicClient {
|
|
104
|
+
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
105
|
+
return createPublicClient({
|
|
106
|
+
chain: chain.chainInfo,
|
|
107
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
108
|
+
pollingInterval: config.viemPollingIntervalMS,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Returns a viem public client after waiting for the L1 RPC node to become available. */
|
|
113
|
+
export async function waitForPublicClient(config: Config, logger?: Logger): Promise<ViemPublicClient> {
|
|
114
|
+
const client = getPublicClient(config);
|
|
115
|
+
await waitForRpc(client, config, logger);
|
|
116
|
+
return client;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function waitForRpc(client: ViemPublicClient, config: Config, logger?: Logger) {
|
|
120
|
+
const l1ChainId = await retryUntil(
|
|
121
|
+
async () => {
|
|
122
|
+
let chainId = 0;
|
|
123
|
+
try {
|
|
124
|
+
chainId = await client.getChainId();
|
|
125
|
+
} catch {
|
|
126
|
+
logger?.warn(`Failed to connect to Ethereum node at ${config.l1RpcUrls.join(', ')}. Retrying...`);
|
|
127
|
+
}
|
|
128
|
+
return chainId;
|
|
129
|
+
},
|
|
130
|
+
`L1 RPC url at ${config.l1RpcUrls.join(', ')}`,
|
|
131
|
+
600,
|
|
132
|
+
1,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (l1ChainId !== config.l1ChainId) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Ethereum node at ${config.l1RpcUrls.join(', ')} has chain ID ${l1ChainId} but expected ${config.l1ChainId}`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function createExtendedL1Client(
|
|
143
|
+
rpcUrls: string[],
|
|
144
|
+
mnemonicOrPrivateKeyOrHdAccount: string | HDAccount | PrivateKeyAccount | LocalAccount,
|
|
145
|
+
chain: Chain = foundry,
|
|
146
|
+
pollingIntervalMS?: number,
|
|
147
|
+
addressIndex?: number,
|
|
148
|
+
opts?: { httpTimeoutMS?: number },
|
|
149
|
+
): ExtendedViemWalletClient {
|
|
150
|
+
const hdAccount =
|
|
151
|
+
typeof mnemonicOrPrivateKeyOrHdAccount === 'string'
|
|
152
|
+
? mnemonicOrPrivateKeyOrHdAccount.startsWith('0x')
|
|
153
|
+
? privateKeyToAccount(mnemonicOrPrivateKeyOrHdAccount as `0x${string}`)
|
|
154
|
+
: mnemonicToAccount(mnemonicOrPrivateKeyOrHdAccount, { addressIndex })
|
|
155
|
+
: mnemonicOrPrivateKeyOrHdAccount;
|
|
156
|
+
|
|
157
|
+
const extendedClient = createWalletClient({
|
|
158
|
+
account: hdAccount,
|
|
159
|
+
chain,
|
|
160
|
+
transport: makeL1HttpTransport(rpcUrls, { timeout: opts?.httpTimeoutMS }),
|
|
161
|
+
pollingInterval: pollingIntervalMS,
|
|
162
|
+
}).extend(publicActions);
|
|
163
|
+
|
|
164
|
+
return extendedClient;
|
|
165
|
+
}
|