@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351
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/account.d.ts +2 -0
- package/dest/account.d.ts.map +1 -0
- package/dest/account.js +4 -0
- package/dest/chain.d.ts +1 -1
- package/dest/client.d.ts +28 -4
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +73 -3
- package/dest/config.d.ts +70 -23
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +151 -34
- package/dest/constants.d.ts +1 -1
- 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/empire_base.d.ts +25 -8
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +75 -2
- 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 +6 -7
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/fee_juice.js +27 -20
- package/dest/contracts/governance.d.ts +131 -43
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +281 -87
- package/dest/contracts/governance_proposer.d.ts +49 -13
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +483 -26
- package/dest/contracts/gse.d.ts +32 -0
- package/dest/contracts/gse.d.ts.map +1 -0
- package/dest/contracts/gse.js +72 -0
- package/dest/contracts/inbox.d.ts +47 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +85 -0
- package/dest/contracts/index.d.ts +11 -2
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +10 -1
- 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 +136 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +264 -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 +12 -5
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +74 -17
- package/dest/contracts/rollup.d.ts +5526 -52
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1446 -118
- 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 +133 -15
- package/dest/contracts/slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/slashing_proposer.js +293 -22
- 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/deploy_aztec_l1_contracts.d.ts +256 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +411 -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/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +79270 -0
- package/dest/l1_artifacts.d.ts.map +1 -0
- package/dest/l1_artifacts.js +151 -0
- package/dest/l1_contract_addresses.d.ts +61 -45
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +99 -76
- package/dest/l1_reader.d.ts +8 -6
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +20 -12
- 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 +233 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +658 -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 +328 -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 +67 -0
- package/dest/l1_tx_utils/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/types.js +26 -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 +30 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +162 -0
- package/dest/queries.d.ts +17 -4
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +120 -12
- package/dest/test/chain_monitor.d.ts +95 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +249 -0
- package/dest/test/eth_cheat_codes.d.ts +237 -0
- package/dest/test/eth_cheat_codes.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes.js +573 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes_with_state.js +1 -1
- package/dest/test/index.d.ts +4 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +3 -2
- package/dest/test/rollup_cheat_codes.d.ts +118 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +344 -0
- package/dest/test/start_anvil.d.ts +30 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +147 -24
- package/dest/test/upgrade_utils.d.ts +6 -5
- package/dest/test/upgrade_utils.d.ts.map +1 -1
- package/dest/test/upgrade_utils.js +23 -16
- package/dest/types.d.ts +62 -8
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -1
- package/dest/utils.d.ts +25 -4
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +142 -91
- package/dest/zkPassportVerifierAddress.d.ts +15 -0
- package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
- package/dest/zkPassportVerifierAddress.js +11 -0
- package/package.json +52 -26
- package/src/account.ts +5 -0
- package/src/client.ts +107 -5
- package/src/config.ts +218 -43
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/empire_base.ts +77 -7
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +66 -0
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/fee_juice.ts +29 -15
- package/src/contracts/governance.ts +343 -74
- package/src/contracts/governance_proposer.ts +128 -25
- package/src/contracts/gse.ts +88 -0
- package/src/contracts/inbox.ts +123 -0
- package/src/contracts/index.ts +10 -1
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +296 -0
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +81 -26
- package/src/contracts/rollup.ts +1246 -90
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/slashing_proposer.ts +296 -27
- package/src/contracts/utils.ts +14 -0
- package/src/deploy_aztec_l1_contracts.ts +646 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/eth-signer/eth-signer.ts +25 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_artifacts.ts +231 -0
- package/src/l1_contract_addresses.ts +121 -80
- package/src/l1_reader.ts +31 -16
- 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 +163 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +15 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +789 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +424 -0
- package/src/l1_tx_utils/signer.ts +28 -0
- package/src/l1_tx_utils/tx_delayer.ts +303 -0
- package/src/l1_tx_utils/types.ts +85 -0
- package/src/l1_tx_utils/utils.ts +16 -0
- package/src/l1_types.ts +6 -0
- package/src/publisher_manager.ts +203 -0
- package/src/queries.ts +149 -17
- package/src/test/chain_monitor.ts +307 -0
- package/src/test/eth_cheat_codes.ts +600 -0
- package/src/test/eth_cheat_codes_with_state.ts +1 -1
- package/src/test/index.ts +3 -2
- package/src/test/rollup_cheat_codes.ts +388 -0
- package/src/test/start_anvil.ts +189 -22
- package/src/test/upgrade_utils.ts +30 -21
- package/src/types.ts +71 -7
- package/src/utils.ts +164 -96
- package/src/zkPassportVerifierAddress.ts +15 -0
- package/dest/contracts/forwarder.d.ts +0 -24
- package/dest/contracts/forwarder.d.ts.map +0 -1
- package/dest/contracts/forwarder.js +0 -101
- package/dest/deploy_l1_contracts.d.ts +0 -21210
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -687
- package/dest/eth_cheat_codes.d.ts +0 -147
- package/dest/eth_cheat_codes.d.ts.map +0 -1
- package/dest/eth_cheat_codes.js +0 -303
- package/dest/index.d.ts +0 -14
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -13
- package/dest/l1_tx_utils.d.ts +0 -192
- package/dest/l1_tx_utils.d.ts.map +0 -1
- package/dest/l1_tx_utils.js +0 -641
- package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
- package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils_with_blobs.js +0 -64
- package/dest/test/delayed_tx_utils.d.ts +0 -8
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -21
- package/dest/test/tx_delayer.d.ts +0 -25
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/dest/test/tx_delayer.js +0 -116
- package/src/contracts/forwarder.ts +0 -132
- package/src/deploy_l1_contracts.ts +0 -948
- package/src/eth_cheat_codes.ts +0 -314
- package/src/index.ts +0 -13
- package/src/l1_tx_utils.ts +0 -847
- package/src/l1_tx_utils_with_blobs.ts +0 -86
- package/src/test/delayed_tx_utils.ts +0 -24
- package/src/test/tx_delayer.ts +0 -163
package/dest/utils.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ErrorsAbi } from '@aztec/l1-artifacts';
|
|
1
|
+
import { ErrorsAbi } from '@aztec/l1-artifacts/ErrorsAbi';
|
|
2
2
|
import { BaseError, ContractFunctionRevertedError, decodeErrorResult, decodeEventLog } from 'viem';
|
|
3
|
+
import { formatAbiItem, formatAbiParams } from 'viem/utils';
|
|
3
4
|
export class FormattedViemError extends Error {
|
|
4
5
|
metaMessages;
|
|
5
|
-
constructor(message, metaMessages){
|
|
6
|
-
super(message);
|
|
6
|
+
constructor(message, metaMessages, options){
|
|
7
|
+
super(message, options);
|
|
7
8
|
this.name = 'FormattedViemError';
|
|
8
9
|
this.metaMessages = metaMessages;
|
|
9
10
|
}
|
|
@@ -15,7 +16,7 @@ export function extractEvent(logs, address, abi, eventName, filter, logger) {
|
|
|
15
16
|
}
|
|
16
17
|
return event;
|
|
17
18
|
}
|
|
18
|
-
function tryExtractEvent(logs, address, abi, eventName, filter, logger) {
|
|
19
|
+
export function tryExtractEvent(logs, address, abi, eventName, filter, logger) {
|
|
19
20
|
for (const log of logs){
|
|
20
21
|
if (log.address.toLowerCase() === address.toLowerCase()) {
|
|
21
22
|
try {
|
|
@@ -46,6 +47,51 @@ export function prettyLogViemErrorMsg(err) {
|
|
|
46
47
|
}
|
|
47
48
|
return err?.message ?? err;
|
|
48
49
|
}
|
|
50
|
+
export function mergeAbis(abis) {
|
|
51
|
+
let merged = [];
|
|
52
|
+
const seen = new Set();
|
|
53
|
+
for (const abi of abis){
|
|
54
|
+
for (const item of abi){
|
|
55
|
+
const key = getAbiItemKey(item);
|
|
56
|
+
if (!seen.has(key)) {
|
|
57
|
+
seen.add(key);
|
|
58
|
+
merged = [
|
|
59
|
+
...merged,
|
|
60
|
+
item
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return merged;
|
|
66
|
+
}
|
|
67
|
+
function getAbiItemKey(item) {
|
|
68
|
+
if (item.type === 'function') {
|
|
69
|
+
const signature = formatAbiItem(item);
|
|
70
|
+
const outputs = formatAbiParams(item.outputs);
|
|
71
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
72
|
+
return `function:${signature}:${outputs}:${stateMutability}`;
|
|
73
|
+
}
|
|
74
|
+
if (item.type === 'event') {
|
|
75
|
+
const signature = formatAbiItem(item);
|
|
76
|
+
const indexed = (item.inputs ?? []).map((input)=>input.indexed ? '1' : '0').join('');
|
|
77
|
+
const anonymous = item.anonymous ? 'anonymous' : 'not-anonymous';
|
|
78
|
+
return `event:${signature}:${indexed}:${anonymous}`;
|
|
79
|
+
}
|
|
80
|
+
if (item.type === 'error') {
|
|
81
|
+
const signature = formatAbiItem(item);
|
|
82
|
+
return `error:${signature}`;
|
|
83
|
+
}
|
|
84
|
+
if (item.type === 'constructor') {
|
|
85
|
+
const inputs = formatAbiParams(item.inputs);
|
|
86
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
87
|
+
return `constructor::${inputs}:${stateMutability}`;
|
|
88
|
+
}
|
|
89
|
+
if (item.type === 'fallback' || item.type === 'receive') {
|
|
90
|
+
const stateMutability = typeof item.stateMutability === 'string' ? item.stateMutability : '';
|
|
91
|
+
return `${item.type}:::${stateMutability}`;
|
|
92
|
+
}
|
|
93
|
+
return 'unknown';
|
|
94
|
+
}
|
|
49
95
|
function getNestedErrorData(error) {
|
|
50
96
|
// If nothing, bail
|
|
51
97
|
if (!error) {
|
|
@@ -66,6 +112,19 @@ function getNestedErrorData(error) {
|
|
|
66
112
|
// Not found
|
|
67
113
|
return undefined;
|
|
68
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Truncates an error message to a safe length for log renderers.
|
|
117
|
+
* LogExplorer can only render up to 2500 characters in its summary view.
|
|
118
|
+
* We cap at 2000 to leave room for decorating context added by callers.
|
|
119
|
+
*/ function truncateErrorMessage(message) {
|
|
120
|
+
const MAX = 2000;
|
|
121
|
+
const CHUNK = 950;
|
|
122
|
+
if (message.length <= MAX) {
|
|
123
|
+
return message;
|
|
124
|
+
}
|
|
125
|
+
const truncated = message.length - 2 * CHUNK;
|
|
126
|
+
return message.slice(0, CHUNK) + `...${truncated} characters truncated...` + message.slice(-CHUNK);
|
|
127
|
+
}
|
|
69
128
|
/**
|
|
70
129
|
* Formats a Viem error into a FormattedViemError instance.
|
|
71
130
|
* @param error - The error to format.
|
|
@@ -76,6 +135,7 @@ function getNestedErrorData(error) {
|
|
|
76
135
|
if (error instanceof FormattedViemError) {
|
|
77
136
|
return error;
|
|
78
137
|
}
|
|
138
|
+
const originalError = error;
|
|
79
139
|
// First try to decode as a custom error using the ABI
|
|
80
140
|
try {
|
|
81
141
|
const data = getNestedErrorData(error);
|
|
@@ -86,7 +146,9 @@ function getNestedErrorData(error) {
|
|
|
86
146
|
data: data
|
|
87
147
|
});
|
|
88
148
|
if (decoded) {
|
|
89
|
-
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages
|
|
149
|
+
return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages, {
|
|
150
|
+
cause: originalError
|
|
151
|
+
});
|
|
90
152
|
}
|
|
91
153
|
}
|
|
92
154
|
// If it's a BaseError, try to get the custom error through ContractFunctionRevertedError
|
|
@@ -98,100 +160,71 @@ function getNestedErrorData(error) {
|
|
|
98
160
|
errorName = revertError.signature ?? '';
|
|
99
161
|
}
|
|
100
162
|
const args = revertError.metaMessages && revertError.metaMessages?.length > 1 ? revertError.metaMessages[1].trimStart() : '';
|
|
101
|
-
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages
|
|
163
|
+
return new FormattedViemError(`${errorName}${args}`, error?.metaMessages, {
|
|
164
|
+
cause: originalError
|
|
165
|
+
});
|
|
102
166
|
}
|
|
103
167
|
}
|
|
104
|
-
} catch
|
|
168
|
+
} catch {
|
|
105
169
|
// If decoding fails, we fall back to the original formatting
|
|
106
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
|
+
}
|
|
107
181
|
// If it's a regular Error instance, return it with its message
|
|
108
182
|
if (error instanceof Error) {
|
|
109
|
-
return error
|
|
183
|
+
return new FormattedViemError(truncateErrorMessage(error.message), error?.metaMessages, {
|
|
184
|
+
cause: originalError
|
|
185
|
+
});
|
|
110
186
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
133
|
-
const result = {};
|
|
134
|
-
for (const [key, value] of Object.entries(obj)){
|
|
135
|
-
result[key] = processParams(value);
|
|
136
|
-
}
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
if (typeof obj === 'string') {
|
|
140
|
-
if (obj.startsWith('0x')) {
|
|
141
|
-
return truncateHex(obj);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return obj;
|
|
145
|
-
};
|
|
146
|
-
// Process the entire request body
|
|
147
|
-
const processed = processParams(parsed);
|
|
148
|
-
return JSON.stringify(processed, null, 2);
|
|
149
|
-
} catch {
|
|
150
|
-
return body;
|
|
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);
|
|
151
207
|
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const processedLines = lines.map((line)=>{
|
|
168
|
-
// Check if line contains a colon followed by content
|
|
169
|
-
const colonIndex = line.indexOf(':');
|
|
170
|
-
if (colonIndex !== -1) {
|
|
171
|
-
const [prefix, content] = [
|
|
172
|
-
line.slice(0, colonIndex + 1),
|
|
173
|
-
line.slice(colonIndex + 1).trim()
|
|
174
|
-
];
|
|
175
|
-
// If content contains a hex string, truncate it
|
|
176
|
-
if (content.includes('0x')) {
|
|
177
|
-
const hexMatches = content.match(/0x[a-fA-F0-9]+/g) || [];
|
|
178
|
-
let processedContent = content;
|
|
179
|
-
hexMatches.forEach((hex)=>{
|
|
180
|
-
processedContent = processedContent.replace(hex, truncateHex(hex));
|
|
181
|
-
});
|
|
182
|
-
return `${prefix} ${processedContent}`;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return line;
|
|
186
|
-
});
|
|
187
|
-
return processedLines.join('\n');
|
|
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
|
|
188
223
|
});
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
}
|
|
193
|
-
const formattedRes = extractAndFormatRequestBody(error?.message || String(error));
|
|
194
|
-
return new FormattedViemError(formattedRes.replace(/\\n/g, '\n'), error?.metaMessages);
|
|
224
|
+
return `${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`;
|
|
225
|
+
} catch {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
195
228
|
}
|
|
196
229
|
export function tryGetCustomErrorName(err) {
|
|
197
230
|
try {
|
|
@@ -203,7 +236,25 @@ export function tryGetCustomErrorName(err) {
|
|
|
203
236
|
return revertError.data?.errorName;
|
|
204
237
|
}
|
|
205
238
|
}
|
|
206
|
-
} catch
|
|
239
|
+
} catch {
|
|
207
240
|
return undefined;
|
|
208
241
|
}
|
|
209
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/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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiemtQYXNzcG9ydFZlcmlmaWVyQWRkcmVzcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3prUGFzc3BvcnRWZXJpZmllckFkZHJlc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBRTNEOzs7R0FHRztBQUNILGVBQU8sTUFBTSw0QkFBNEIsWUFBc0UsQ0FBQztBQUNoSDs7R0FFRztBQUNILGVBQU8sTUFBTSxrQkFBa0IsMEJBQTBCLENBQUM7QUFDMUQ7O0dBRUc7QUFDSCxlQUFPLE1BQU0saUJBQWlCLGVBQWUsQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zkPassportVerifierAddress.d.ts","sourceRoot":"","sources":["../src/zkPassportVerifierAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D;;;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/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
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/ethereum",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-commit.017a351",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
"
|
|
7
|
-
"./
|
|
8
|
-
"./
|
|
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",
|
|
9
11
|
"./contracts": "./dest/contracts/index.js",
|
|
10
|
-
"./deploy-l1-contracts": "./dest/
|
|
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",
|
|
11
19
|
"./l1-contract-addresses": "./dest/l1_contract_addresses.js",
|
|
12
|
-
"./l1-
|
|
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",
|
|
13
30
|
"./utils": "./dest/utils.js"
|
|
14
31
|
},
|
|
15
32
|
"typedocOptions": {
|
|
@@ -20,45 +37,50 @@
|
|
|
20
37
|
"tsconfig": "./tsconfig.json"
|
|
21
38
|
},
|
|
22
39
|
"scripts": {
|
|
23
|
-
"build": "yarn clean && tsc
|
|
24
|
-
"build:dev": "tsc
|
|
40
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
41
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
25
42
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"start:dev": "tsc-watch -p tsconfig.json --onSuccess 'yarn start'",
|
|
43
|
+
"generate": "./scripts/generate.sh",
|
|
44
|
+
"start:dev": "concurrently -k \"../scripts/tsc.sh --watch\" \"nodemon --watch dest --exec yarn start\"",
|
|
29
45
|
"start": "node ./dest/index.js",
|
|
30
|
-
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
46
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
47
|
+
"proposer-address": "node ./dest/cli/forwarder_address.js"
|
|
31
48
|
},
|
|
32
49
|
"inherits": [
|
|
33
50
|
"../package.common.json"
|
|
34
51
|
],
|
|
35
52
|
"dependencies": {
|
|
36
|
-
"@aztec/blob-lib": "0.0.
|
|
37
|
-
"@aztec/
|
|
38
|
-
"@aztec/
|
|
39
|
-
"@
|
|
53
|
+
"@aztec/blob-lib": "0.0.1-commit.017a351",
|
|
54
|
+
"@aztec/constants": "0.0.1-commit.017a351",
|
|
55
|
+
"@aztec/foundation": "0.0.1-commit.017a351",
|
|
56
|
+
"@aztec/l1-artifacts": "0.0.1-commit.017a351",
|
|
40
57
|
"dotenv": "^16.0.3",
|
|
58
|
+
"lodash.chunk": "^4.2.0",
|
|
59
|
+
"lodash.pickby": "^4.5.0",
|
|
41
60
|
"tslib": "^2.4.0",
|
|
42
|
-
"viem": "2.
|
|
43
|
-
"zod": "^
|
|
61
|
+
"viem": "npm:@aztec/viem@2.38.2",
|
|
62
|
+
"zod": "^4"
|
|
44
63
|
},
|
|
45
64
|
"devDependencies": {
|
|
46
|
-
"@jest/globals": "^
|
|
47
|
-
"@
|
|
48
|
-
"@types/
|
|
49
|
-
"@
|
|
65
|
+
"@jest/globals": "^30.0.0",
|
|
66
|
+
"@noble/curves": "=1.7.0",
|
|
67
|
+
"@types/jest": "^30.0.0",
|
|
68
|
+
"@types/lodash.pickby": "^4",
|
|
69
|
+
"@types/node": "^22.15.17",
|
|
70
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
50
71
|
"get-port": "^7.1.0",
|
|
51
|
-
"jest": "^
|
|
72
|
+
"jest": "^30.0.0",
|
|
73
|
+
"jest-mock-extended": "^4.0.0",
|
|
52
74
|
"lodash.omit": "^4.5.0",
|
|
53
75
|
"ts-node": "^10.9.1",
|
|
54
|
-
"typescript": "^5.
|
|
76
|
+
"typescript": "^5.3.3"
|
|
55
77
|
},
|
|
56
78
|
"files": [
|
|
57
79
|
"dest",
|
|
58
80
|
"src",
|
|
59
81
|
"!*.test.*"
|
|
60
82
|
],
|
|
61
|
-
"types": "./dest/
|
|
83
|
+
"types": "./dest/types.d.ts",
|
|
62
84
|
"jest": {
|
|
63
85
|
"moduleNameMapper": {
|
|
64
86
|
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
@@ -90,9 +112,13 @@
|
|
|
90
112
|
"testTimeout": 120000,
|
|
91
113
|
"setupFiles": [
|
|
92
114
|
"../../foundation/src/jest/setup.mjs"
|
|
115
|
+
],
|
|
116
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
117
|
+
"setupFilesAfterEnv": [
|
|
118
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
93
119
|
]
|
|
94
120
|
},
|
|
95
121
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
122
|
+
"node": ">=20.10"
|
|
97
123
|
}
|
|
98
124
|
}
|
package/src/account.ts
ADDED
package/src/client.ts
CHANGED
|
@@ -1,20 +1,97 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type Chain,
|
|
7
|
+
type FallbackTransport,
|
|
8
|
+
type HDAccount,
|
|
9
|
+
HttpRequestError,
|
|
10
|
+
type HttpTransport,
|
|
11
|
+
type LocalAccount,
|
|
12
|
+
type PrivateKeyAccount,
|
|
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';
|
|
5
21
|
|
|
6
22
|
import { createEthereumChain } from './chain.js';
|
|
7
|
-
import type { ViemPublicClient } from './types.js';
|
|
23
|
+
import type { ExtendedViemWalletClient, ViemPublicClient } from './types.js';
|
|
8
24
|
|
|
9
25
|
type Config = {
|
|
10
|
-
/**
|
|
26
|
+
/** List of URLs of Ethereum RPC nodes that services will connect to (comma separated). */
|
|
11
27
|
l1RpcUrls: string[];
|
|
12
28
|
/** The chain ID of the ethereum host. */
|
|
13
29
|
l1ChainId: number;
|
|
14
30
|
/** The polling interval viem uses in ms */
|
|
15
31
|
viemPollingIntervalMS?: number;
|
|
32
|
+
/** Timeout for HTTP requests to the L1 RPC node in ms. */
|
|
33
|
+
l1HttpTimeoutMS?: number;
|
|
16
34
|
};
|
|
17
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
|
+
function wrapL1RpcTransport(transport: FallbackTransport<HttpTransport[]>): FallbackTransport<HttpTransport[]> {
|
|
62
|
+
const wrappedTransport: FallbackTransport<HttpTransport[]> = parameters => {
|
|
63
|
+
const fallbackTransport = transport(parameters);
|
|
64
|
+
const request: typeof fallbackTransport.request = async args => {
|
|
65
|
+
try {
|
|
66
|
+
return await fallbackTransport.request(args);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
throw err instanceof L1RpcError ? err : new L1RpcError('L1 RPC request failed', { cause: err });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return { ...fallbackTransport, request };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return wrappedTransport;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Returns the individual RPC URLs underlying a viem public client that was constructed with a
|
|
79
|
+
* fallback HTTP transport (see {@link makeL1HttpTransport}). Returns an empty array if the
|
|
80
|
+
* transport shape is not recognized (e.g. mock clients in tests, or non-fallback transports).
|
|
81
|
+
*/
|
|
82
|
+
export function getRpcUrlsFromClient(client: ViemPublicClient): string[] {
|
|
83
|
+
const transport = client.transport as unknown as {
|
|
84
|
+
transports?: { value?: { url?: string } }[];
|
|
85
|
+
value?: { url?: string };
|
|
86
|
+
url?: string;
|
|
87
|
+
};
|
|
88
|
+
if (Array.isArray(transport?.transports)) {
|
|
89
|
+
return transport.transports.map(t => t?.value?.url).filter((url): url is string => typeof url === 'string');
|
|
90
|
+
}
|
|
91
|
+
const singleUrl = transport?.value?.url ?? transport?.url;
|
|
92
|
+
return typeof singleUrl === 'string' ? [singleUrl] : [];
|
|
93
|
+
}
|
|
94
|
+
|
|
18
95
|
// TODO: Use these methods to abstract the creation of viem clients.
|
|
19
96
|
|
|
20
97
|
/** Returns a viem public client given the L1 config. */
|
|
@@ -22,7 +99,7 @@ export function getPublicClient(config: Config): ViemPublicClient {
|
|
|
22
99
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
23
100
|
return createPublicClient({
|
|
24
101
|
chain: chain.chainInfo,
|
|
25
|
-
transport:
|
|
102
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
26
103
|
pollingInterval: config.viemPollingIntervalMS,
|
|
27
104
|
});
|
|
28
105
|
}
|
|
@@ -40,7 +117,7 @@ async function waitForRpc(client: ViemPublicClient, config: Config, logger?: Log
|
|
|
40
117
|
let chainId = 0;
|
|
41
118
|
try {
|
|
42
119
|
chainId = await client.getChainId();
|
|
43
|
-
} catch
|
|
120
|
+
} catch {
|
|
44
121
|
logger?.warn(`Failed to connect to Ethereum node at ${config.l1RpcUrls.join(', ')}. Retrying...`);
|
|
45
122
|
}
|
|
46
123
|
return chainId;
|
|
@@ -56,3 +133,28 @@ async function waitForRpc(client: ViemPublicClient, config: Config, logger?: Log
|
|
|
56
133
|
);
|
|
57
134
|
}
|
|
58
135
|
}
|
|
136
|
+
|
|
137
|
+
export function createExtendedL1Client(
|
|
138
|
+
rpcUrls: string[],
|
|
139
|
+
mnemonicOrPrivateKeyOrHdAccount: string | HDAccount | PrivateKeyAccount | LocalAccount,
|
|
140
|
+
chain: Chain = foundry,
|
|
141
|
+
pollingIntervalMS?: number,
|
|
142
|
+
addressIndex?: number,
|
|
143
|
+
opts?: { httpTimeoutMS?: number },
|
|
144
|
+
): ExtendedViemWalletClient {
|
|
145
|
+
const hdAccount =
|
|
146
|
+
typeof mnemonicOrPrivateKeyOrHdAccount === 'string'
|
|
147
|
+
? mnemonicOrPrivateKeyOrHdAccount.startsWith('0x')
|
|
148
|
+
? privateKeyToAccount(mnemonicOrPrivateKeyOrHdAccount as `0x${string}`)
|
|
149
|
+
: mnemonicToAccount(mnemonicOrPrivateKeyOrHdAccount, { addressIndex })
|
|
150
|
+
: mnemonicOrPrivateKeyOrHdAccount;
|
|
151
|
+
|
|
152
|
+
const extendedClient = createWalletClient({
|
|
153
|
+
account: hdAccount,
|
|
154
|
+
chain,
|
|
155
|
+
transport: makeL1HttpTransport(rpcUrls, { timeout: opts?.httpTimeoutMS }),
|
|
156
|
+
pollingInterval: pollingIntervalMS,
|
|
157
|
+
}).extend(publicActions);
|
|
158
|
+
|
|
159
|
+
return extendedClient;
|
|
160
|
+
}
|