@aztec/ethereum 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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 +10 -2
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +13 -7
- package/dest/config.d.ts +22 -33
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +59 -64
- package/dest/contracts/chain_state_override.d.ts +38 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +100 -0
- package/dest/contracts/empire_base.d.ts +3 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- 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 +101 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +651 -0
- package/dest/contracts/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +14 -4
- package/dest/contracts/governance_proposer.d.ts +3 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +13 -1
- package/dest/contracts/inbox.d.ts +18 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +31 -1
- package/dest/contracts/index.d.ts +5 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +4 -2
- 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 +51 -2
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +87 -1
- 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 +117 -22
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +370 -60
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
- package/dest/deploy_aztec_l1_contracts.d.ts +9 -8
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +58 -32
- package/dest/deploy_l1_contract.js +3 -3
- 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 +10713 -16120
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +1 -5
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +0 -6
- package/dest/l1_reader.d.ts +3 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +6 -1
- 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 +14 -1
- 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_tx_utils.d.ts +20 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +81 -57
- 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 +11 -7
- package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +62 -34
- package/dest/publisher_manager.d.ts +21 -6
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +81 -7
- package/dest/queries.d.ts +2 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +7 -4
- package/dest/test/chain_monitor.d.ts +22 -3
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +33 -2
- package/dest/test/eth_cheat_codes.d.ts +18 -4
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +6 -4
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- package/dest/test/rollup_cheat_codes.d.ts +8 -2
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +19 -2
- package/dest/test/start_anvil.d.ts +23 -3
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +143 -29
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/utils.d.ts +2 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +62 -12
- package/package.json +8 -9
- package/src/client.ts +10 -2
- package/src/config.ts +75 -65
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +147 -0
- package/src/contracts/empire_base.ts +2 -0
- package/src/contracts/fee_asset_handler.ts +2 -0
- package/src/contracts/fee_asset_price_oracle.ts +280 -0
- package/src/contracts/governance.ts +13 -4
- package/src/contracts/governance_proposer.ts +10 -1
- package/src/contracts/inbox.ts +48 -1
- package/src/contracts/index.ts +4 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +70 -3
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +424 -56
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +16 -14
- package/src/deploy_aztec_l1_contracts.ts +81 -40
- package/src/deploy_l1_contract.ts +3 -3
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +0 -7
- package/src/l1_reader.ts +13 -1
- package/src/l1_tx_utils/config.ts +20 -0
- 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_tx_utils.ts +74 -36
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +11 -7
- package/src/{test → l1_tx_utils}/tx_delayer.ts +78 -50
- package/src/publisher_manager.ts +107 -10
- package/src/queries.ts +6 -4
- package/src/test/chain_monitor.ts +60 -3
- package/src/test/eth_cheat_codes.ts +6 -4
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +22 -3
- package/src/test/start_anvil.ts +177 -29
- package/src/test/upgrade_utils.ts +2 -2
- package/src/utils.ts +70 -14
- 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.map +0 -1
- 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/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
package/dest/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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
6
|
constructor(message, metaMessages){
|
|
@@ -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.
|
|
@@ -116,18 +175,9 @@ function getNestedErrorData(error) {
|
|
|
116
175
|
}
|
|
117
176
|
// If it's a regular Error instance, return it with its message
|
|
118
177
|
if (error instanceof Error) {
|
|
119
|
-
return new FormattedViemError(error.message, error?.metaMessages);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const length = body.length;
|
|
123
|
-
// LogExplorer can only render up to 2500 characters in it's summary view. Try to keep the whole message below this number
|
|
124
|
-
// Limit the error to 2000 chacaters in order to allow code higher up to decorate this error with extra details (up to 500 characters)
|
|
125
|
-
if (length > 2000) {
|
|
126
|
-
const chunk = 950;
|
|
127
|
-
const truncated = length - 2 * chunk;
|
|
128
|
-
return new FormattedViemError(body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk));
|
|
129
|
-
}
|
|
130
|
-
return new FormattedViemError(body);
|
|
178
|
+
return new FormattedViemError(truncateErrorMessage(error.message), error?.metaMessages);
|
|
179
|
+
}
|
|
180
|
+
return new FormattedViemError(truncateErrorMessage(String(error)));
|
|
131
181
|
}
|
|
132
182
|
function stripAbis(obj) {
|
|
133
183
|
if (!obj || typeof obj !== 'object') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/ethereum",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.11bf3dd6e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./account": "./dest/account.js",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"build": "yarn clean && ../scripts/tsc.sh",
|
|
41
41
|
"build:dev": "../scripts/tsc.sh --watch",
|
|
42
42
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
43
|
-
"
|
|
43
|
+
"generate": "./scripts/generate.sh",
|
|
44
|
+
"start:dev": "concurrently -k \"../scripts/tsc.sh --watch\" \"nodemon --watch dest --exec yarn start\"",
|
|
44
45
|
"start": "node ./dest/index.js",
|
|
45
46
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
46
47
|
"proposer-address": "node ./dest/cli/forwarder_address.js"
|
|
@@ -49,11 +50,10 @@
|
|
|
49
50
|
"../package.common.json"
|
|
50
51
|
],
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
53
|
-
"@aztec/constants": "0.0.1-commit.
|
|
54
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
55
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
56
|
-
"@viem/anvil": "^0.0.10",
|
|
53
|
+
"@aztec/blob-lib": "0.0.1-commit.11bf3dd6e",
|
|
54
|
+
"@aztec/constants": "0.0.1-commit.11bf3dd6e",
|
|
55
|
+
"@aztec/foundation": "0.0.1-commit.11bf3dd6e",
|
|
56
|
+
"@aztec/l1-artifacts": "0.0.1-commit.11bf3dd6e",
|
|
57
57
|
"dotenv": "^16.0.3",
|
|
58
58
|
"lodash.chunk": "^4.2.0",
|
|
59
59
|
"lodash.pickby": "^4.5.0",
|
|
@@ -67,8 +67,7 @@
|
|
|
67
67
|
"@types/jest": "^30.0.0",
|
|
68
68
|
"@types/lodash.pickby": "^4",
|
|
69
69
|
"@types/node": "^22.15.17",
|
|
70
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
71
|
-
"@viem/anvil": "^0.0.10",
|
|
70
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
72
71
|
"get-port": "^7.1.0",
|
|
73
72
|
"jest": "^30.0.0",
|
|
74
73
|
"jest-mock-extended": "^4.0.0",
|
package/src/client.ts
CHANGED
|
@@ -25,10 +25,17 @@ type Config = {
|
|
|
25
25
|
l1ChainId: number;
|
|
26
26
|
/** The polling interval viem uses in ms */
|
|
27
27
|
viemPollingIntervalMS?: number;
|
|
28
|
+
/** Timeout for HTTP requests to the L1 RPC node in ms. */
|
|
29
|
+
l1HttpTimeoutMS?: number;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
export type { Config as EthereumClientConfig };
|
|
31
33
|
|
|
34
|
+
/** Creates a viem fallback HTTP transport for the given L1 RPC URLs. */
|
|
35
|
+
export function makeL1HttpTransport(rpcUrls: string[], opts?: { timeout?: number }) {
|
|
36
|
+
return fallback(rpcUrls.map(url => http(url, { batch: false, timeout: opts?.timeout })));
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
// TODO: Use these methods to abstract the creation of viem clients.
|
|
33
40
|
|
|
34
41
|
/** Returns a viem public client given the L1 config. */
|
|
@@ -36,7 +43,7 @@ export function getPublicClient(config: Config): ViemPublicClient {
|
|
|
36
43
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
37
44
|
return createPublicClient({
|
|
38
45
|
chain: chain.chainInfo,
|
|
39
|
-
transport:
|
|
46
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
40
47
|
pollingInterval: config.viemPollingIntervalMS,
|
|
41
48
|
});
|
|
42
49
|
}
|
|
@@ -77,6 +84,7 @@ export function createExtendedL1Client(
|
|
|
77
84
|
chain: Chain = foundry,
|
|
78
85
|
pollingIntervalMS?: number,
|
|
79
86
|
addressIndex?: number,
|
|
87
|
+
opts?: { httpTimeoutMS?: number },
|
|
80
88
|
): ExtendedViemWalletClient {
|
|
81
89
|
const hdAccount =
|
|
82
90
|
typeof mnemonicOrPrivateKeyOrHdAccount === 'string'
|
|
@@ -88,7 +96,7 @@ export function createExtendedL1Client(
|
|
|
88
96
|
const extendedClient = createWalletClient({
|
|
89
97
|
account: hdAccount,
|
|
90
98
|
chain,
|
|
91
|
-
transport:
|
|
99
|
+
transport: makeL1HttpTransport(rpcUrls, { timeout: opts?.httpTimeoutMS }),
|
|
92
100
|
pollingInterval: pollingIntervalMS,
|
|
93
101
|
}).extend(publicActions);
|
|
94
102
|
|
package/src/config.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ConfigMappingsType,
|
|
3
|
-
// type NetworkNames,
|
|
4
3
|
bigintConfigHelper,
|
|
5
4
|
booleanConfigHelper,
|
|
6
|
-
enumConfigHelper,
|
|
7
5
|
getConfigFromMappings,
|
|
6
|
+
getDefaultConfig,
|
|
8
7
|
numberConfigHelper,
|
|
8
|
+
omitConfigMappings,
|
|
9
9
|
optionalNumberConfigHelper,
|
|
10
10
|
} from '@aztec/foundation/config';
|
|
11
11
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
12
12
|
|
|
13
|
+
import { l1ContractsDefaultEnv } from './generated/l1-contracts-defaults.js';
|
|
13
14
|
import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './l1_tx_utils/config.js';
|
|
14
15
|
|
|
15
16
|
export type GenesisStateConfig = {
|
|
@@ -17,6 +18,8 @@ export type GenesisStateConfig = {
|
|
|
17
18
|
testAccounts: boolean;
|
|
18
19
|
/** Whether to populate the genesis state with initial fee juice for the sponsored FPC */
|
|
19
20
|
sponsoredFPC: boolean;
|
|
21
|
+
/** Additional addresses to prefund with fee juice at genesis */
|
|
22
|
+
prefundAddresses: string[];
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
export type L1ContractsConfig = {
|
|
@@ -56,136 +59,117 @@ export type L1ContractsConfig = {
|
|
|
56
59
|
slashingOffsetInRounds: number;
|
|
57
60
|
/** How long slashing can be disabled for in seconds when vetoer disables it */
|
|
58
61
|
slashingDisableDuration: number;
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
/** Minimum amount that can be slashed
|
|
62
|
+
/** Whether to deploy a slasher proposer */
|
|
63
|
+
slasherEnabled: boolean;
|
|
64
|
+
/** Minimum amount that can be slashed */
|
|
62
65
|
slashAmountSmall: bigint;
|
|
63
|
-
/** Medium amount to slash
|
|
66
|
+
/** Medium amount to slash */
|
|
64
67
|
slashAmountMedium: bigint;
|
|
65
|
-
/** Largest amount that can be slashed per round
|
|
68
|
+
/** Largest amount that can be slashed per round */
|
|
66
69
|
slashAmountLarge: bigint;
|
|
67
70
|
/** Governance proposing quorum (defaults to roundSize/2 + 1) */
|
|
68
71
|
governanceProposerQuorum?: number;
|
|
69
72
|
/** Governance proposing round size */
|
|
70
73
|
governanceProposerRoundSize: number;
|
|
74
|
+
/** Governance voting duration in seconds (only for local/devnet/next-net, default 3600) */
|
|
75
|
+
governanceVotingDuration?: number;
|
|
71
76
|
/** The mana target for the rollup */
|
|
72
77
|
manaTarget: bigint;
|
|
73
78
|
/** The proving cost per mana */
|
|
74
79
|
provingCostPerMana: bigint;
|
|
80
|
+
/** The initial ETH per fee asset price (with 1e12 precision) */
|
|
81
|
+
initialEthPerFeeAsset: bigint;
|
|
75
82
|
/** The number of seconds to wait for an exit */
|
|
76
83
|
exitDelaySeconds: number;
|
|
77
84
|
} & L1TxUtilsConfig;
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
lagInEpochsForValidatorSet: 2,
|
|
85
|
-
lagInEpochsForRandao: 2, // For PROD, this value should be > lagInEpochsForValidatorSet
|
|
86
|
-
inboxLag: 1, // Default inbox lag to prevent sequencer DOS attacks
|
|
87
|
-
aztecProofSubmissionEpochs: 1, // you have a full epoch to submit a proof after the epoch to prove ends
|
|
88
|
-
activationThreshold: 100n * 10n ** 18n,
|
|
89
|
-
ejectionThreshold: 50n * 10n ** 18n,
|
|
90
|
-
localEjectionThreshold: 98n * 10n ** 18n,
|
|
91
|
-
slashAmountSmall: 10n * 10n ** 18n,
|
|
92
|
-
slashAmountMedium: 20n * 10n ** 18n,
|
|
93
|
-
slashAmountLarge: 50n * 10n ** 18n,
|
|
94
|
-
slashingRoundSizeInEpochs: 4,
|
|
95
|
-
slashingLifetimeInRounds: 5,
|
|
96
|
-
slashingExecutionDelayInRounds: 0, // round N may be submitted in round N + 1
|
|
97
|
-
slashingVetoer: EthAddress.ZERO,
|
|
98
|
-
governanceProposerRoundSize: 300,
|
|
99
|
-
manaTarget: BigInt(100e6),
|
|
100
|
-
provingCostPerMana: BigInt(100),
|
|
101
|
-
exitDelaySeconds: 2 * 24 * 60 * 60,
|
|
102
|
-
slasherFlavor: 'tally' as const,
|
|
103
|
-
slashingOffsetInRounds: 2,
|
|
104
|
-
slashingDisableDuration: 5 * 24 * 60 * 60, // 5 days in seconds
|
|
105
|
-
} satisfies L1ContractsConfig;
|
|
106
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Config mappings for L1ContractsConfig.
|
|
88
|
+
* Default values come from generated l1-contracts-defaults.json (source: defaults.yml).
|
|
89
|
+
* Real deployments use forge scripts which require explicit env vars (vm.envUint).
|
|
90
|
+
*/
|
|
107
91
|
export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> = {
|
|
108
92
|
ethereumSlotDuration: {
|
|
109
93
|
env: 'ETHEREUM_SLOT_DURATION',
|
|
110
94
|
description: 'How many seconds an L1 slot lasts.',
|
|
111
|
-
...numberConfigHelper(
|
|
95
|
+
...numberConfigHelper(l1ContractsDefaultEnv.ETHEREUM_SLOT_DURATION),
|
|
112
96
|
},
|
|
113
97
|
aztecSlotDuration: {
|
|
114
98
|
env: 'AZTEC_SLOT_DURATION',
|
|
115
99
|
description: 'How many seconds an L2 slots lasts (must be multiple of ethereum slot duration).',
|
|
116
|
-
...numberConfigHelper(
|
|
100
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLOT_DURATION),
|
|
117
101
|
},
|
|
118
102
|
aztecEpochDuration: {
|
|
119
103
|
env: 'AZTEC_EPOCH_DURATION',
|
|
120
|
-
description: `How many L2 slots an epoch lasts (maximum
|
|
121
|
-
...numberConfigHelper(
|
|
104
|
+
description: `How many L2 slots an epoch lasts (maximum MAX_CHECKPOINTS_PER_EPOCH).`,
|
|
105
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EPOCH_DURATION),
|
|
122
106
|
},
|
|
123
107
|
aztecTargetCommitteeSize: {
|
|
124
108
|
env: 'AZTEC_TARGET_COMMITTEE_SIZE',
|
|
125
109
|
description: 'The target validator committee size.',
|
|
126
|
-
...numberConfigHelper(
|
|
110
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_TARGET_COMMITTEE_SIZE),
|
|
127
111
|
},
|
|
128
112
|
lagInEpochsForValidatorSet: {
|
|
129
113
|
env: 'AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET',
|
|
130
114
|
description: 'The number of epochs to lag behind the current epoch for validator selection.',
|
|
131
|
-
...numberConfigHelper(
|
|
115
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET),
|
|
132
116
|
},
|
|
133
117
|
lagInEpochsForRandao: {
|
|
134
118
|
env: 'AZTEC_LAG_IN_EPOCHS_FOR_RANDAO',
|
|
135
119
|
description: 'The number of epochs to lag behind the current epoch for randao selection.',
|
|
136
|
-
...numberConfigHelper(
|
|
120
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_RANDAO),
|
|
137
121
|
},
|
|
138
122
|
inboxLag: {
|
|
139
123
|
env: 'AZTEC_INBOX_LAG',
|
|
140
124
|
description: 'The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks).',
|
|
141
|
-
...numberConfigHelper(
|
|
125
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_INBOX_LAG),
|
|
142
126
|
},
|
|
143
127
|
aztecProofSubmissionEpochs: {
|
|
144
128
|
env: 'AZTEC_PROOF_SUBMISSION_EPOCHS',
|
|
145
129
|
description: 'The number of epochs after an epoch ends that proofs are still accepted.',
|
|
146
|
-
...numberConfigHelper(
|
|
130
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_PROOF_SUBMISSION_EPOCHS),
|
|
147
131
|
},
|
|
148
132
|
activationThreshold: {
|
|
149
133
|
env: 'AZTEC_ACTIVATION_THRESHOLD',
|
|
150
134
|
description: 'The deposit amount for a validator',
|
|
151
|
-
...bigintConfigHelper(
|
|
135
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_ACTIVATION_THRESHOLD)),
|
|
152
136
|
},
|
|
153
137
|
ejectionThreshold: {
|
|
154
138
|
env: 'AZTEC_EJECTION_THRESHOLD',
|
|
155
139
|
description: 'The minimum stake for a validator.',
|
|
156
|
-
...bigintConfigHelper(
|
|
140
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_EJECTION_THRESHOLD)),
|
|
157
141
|
},
|
|
158
142
|
localEjectionThreshold: {
|
|
159
143
|
env: 'AZTEC_LOCAL_EJECTION_THRESHOLD',
|
|
160
144
|
description:
|
|
161
145
|
'The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup',
|
|
162
|
-
...bigintConfigHelper(
|
|
146
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_LOCAL_EJECTION_THRESHOLD)),
|
|
163
147
|
},
|
|
164
148
|
slashingOffsetInRounds: {
|
|
165
149
|
env: 'AZTEC_SLASHING_OFFSET_IN_ROUNDS',
|
|
166
150
|
description:
|
|
167
151
|
'How many slashing rounds back we slash (ie when slashing in round N, we slash for offenses committed during epochs of round N-offset)',
|
|
168
|
-
...numberConfigHelper(
|
|
152
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_OFFSET_IN_ROUNDS),
|
|
169
153
|
},
|
|
170
|
-
|
|
171
|
-
env: '
|
|
172
|
-
description: '
|
|
173
|
-
...
|
|
154
|
+
slasherEnabled: {
|
|
155
|
+
env: 'AZTEC_SLASHER_ENABLED',
|
|
156
|
+
description: 'Whether to deploy a slasher proposer',
|
|
157
|
+
...booleanConfigHelper(true),
|
|
174
158
|
},
|
|
175
159
|
slashAmountSmall: {
|
|
176
160
|
env: 'AZTEC_SLASH_AMOUNT_SMALL',
|
|
177
161
|
description: 'Small slashing amount for light offenses',
|
|
178
|
-
...bigintConfigHelper(
|
|
162
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_SMALL)),
|
|
179
163
|
},
|
|
180
164
|
slashAmountMedium: {
|
|
181
165
|
env: 'AZTEC_SLASH_AMOUNT_MEDIUM',
|
|
182
166
|
description: 'Medium slashing amount for moderate offenses',
|
|
183
|
-
...bigintConfigHelper(
|
|
167
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_MEDIUM)),
|
|
184
168
|
},
|
|
185
169
|
slashAmountLarge: {
|
|
186
170
|
env: 'AZTEC_SLASH_AMOUNT_LARGE',
|
|
187
171
|
description: 'Large slashing amount for severe offenses',
|
|
188
|
-
...bigintConfigHelper(
|
|
172
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_LARGE)),
|
|
189
173
|
},
|
|
190
174
|
slashingQuorum: {
|
|
191
175
|
env: 'AZTEC_SLASHING_QUORUM',
|
|
@@ -195,28 +179,28 @@ export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> =
|
|
|
195
179
|
slashingRoundSizeInEpochs: {
|
|
196
180
|
env: 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS',
|
|
197
181
|
description: 'The slashing round size',
|
|
198
|
-
...numberConfigHelper(
|
|
182
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS),
|
|
199
183
|
},
|
|
200
184
|
slashingLifetimeInRounds: {
|
|
201
185
|
env: 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS',
|
|
202
186
|
description: 'The slashing lifetime in rounds',
|
|
203
|
-
...numberConfigHelper(
|
|
187
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_LIFETIME_IN_ROUNDS),
|
|
204
188
|
},
|
|
205
189
|
slashingExecutionDelayInRounds: {
|
|
206
190
|
env: 'AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS',
|
|
207
191
|
description: 'The slashing execution delay in rounds',
|
|
208
|
-
...numberConfigHelper(
|
|
192
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS),
|
|
209
193
|
},
|
|
210
194
|
slashingVetoer: {
|
|
211
195
|
env: 'AZTEC_SLASHING_VETOER',
|
|
212
196
|
description: 'The slashing vetoer',
|
|
213
197
|
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
214
|
-
defaultValue:
|
|
198
|
+
defaultValue: EthAddress.fromString(l1ContractsDefaultEnv.AZTEC_SLASHING_VETOER),
|
|
215
199
|
},
|
|
216
200
|
slashingDisableDuration: {
|
|
217
201
|
env: 'AZTEC_SLASHING_DISABLE_DURATION',
|
|
218
202
|
description: 'How long slashing can be disabled for in seconds when vetoer disables it',
|
|
219
|
-
...numberConfigHelper(
|
|
203
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_DISABLE_DURATION),
|
|
220
204
|
},
|
|
221
205
|
governanceProposerQuorum: {
|
|
222
206
|
env: 'AZTEC_GOVERNANCE_PROPOSER_QUORUM',
|
|
@@ -226,26 +210,42 @@ export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> =
|
|
|
226
210
|
governanceProposerRoundSize: {
|
|
227
211
|
env: 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE',
|
|
228
212
|
description: 'The governance proposing round size',
|
|
229
|
-
...numberConfigHelper(
|
|
213
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE),
|
|
214
|
+
},
|
|
215
|
+
governanceVotingDuration: {
|
|
216
|
+
env: 'AZTEC_GOVERNANCE_VOTING_DURATION',
|
|
217
|
+
description: 'Governance voting duration in seconds (only for local/devnet/next-net)',
|
|
218
|
+
...numberConfigHelper(3600), // 1 hour default, not in generated defaults as it's deployment-time only
|
|
230
219
|
},
|
|
231
220
|
manaTarget: {
|
|
232
221
|
env: 'AZTEC_MANA_TARGET',
|
|
233
222
|
description: 'The mana target for the rollup',
|
|
234
|
-
...bigintConfigHelper(
|
|
223
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_MANA_TARGET)),
|
|
235
224
|
},
|
|
236
225
|
provingCostPerMana: {
|
|
237
226
|
env: 'AZTEC_PROVING_COST_PER_MANA',
|
|
238
227
|
description: 'The proving cost per mana',
|
|
239
|
-
...bigintConfigHelper(
|
|
228
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_PROVING_COST_PER_MANA)),
|
|
229
|
+
},
|
|
230
|
+
initialEthPerFeeAsset: {
|
|
231
|
+
env: 'AZTEC_INITIAL_ETH_PER_FEE_ASSET',
|
|
232
|
+
description: 'The initial ETH per fee asset price (with 1e12 precision)',
|
|
233
|
+
...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_INITIAL_ETH_PER_FEE_ASSET)),
|
|
240
234
|
},
|
|
241
235
|
exitDelaySeconds: {
|
|
242
236
|
env: 'AZTEC_EXIT_DELAY_SECONDS',
|
|
243
237
|
description: 'The delay before a validator can exit the set',
|
|
244
|
-
...numberConfigHelper(
|
|
238
|
+
...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EXIT_DELAY_SECONDS),
|
|
245
239
|
},
|
|
246
|
-
...l1TxUtilsConfigMappings,
|
|
240
|
+
...omitConfigMappings(l1TxUtilsConfigMappings, ['ethereumSlotDuration']),
|
|
247
241
|
};
|
|
248
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Default L1 contracts configuration derived from l1ContractsConfigMappings.
|
|
245
|
+
* Source of truth: spartan/environments/defaults.yml -> defaults.l1-contracts
|
|
246
|
+
*/
|
|
247
|
+
export const DefaultL1ContractsConfig = getDefaultConfig(l1ContractsConfigMappings);
|
|
248
|
+
|
|
249
249
|
export const genesisStateConfigMappings: ConfigMappingsType<GenesisStateConfig> = {
|
|
250
250
|
testAccounts: {
|
|
251
251
|
env: 'TEST_ACCOUNTS',
|
|
@@ -257,6 +257,16 @@ export const genesisStateConfigMappings: ConfigMappingsType<GenesisStateConfig>
|
|
|
257
257
|
description: 'Whether to populate the genesis state with initial fee juice for the sponsored FPC.',
|
|
258
258
|
...booleanConfigHelper(false),
|
|
259
259
|
},
|
|
260
|
+
prefundAddresses: {
|
|
261
|
+
env: 'PREFUND_ADDRESSES',
|
|
262
|
+
description: 'Comma-separated list of Aztec addresses to prefund with fee juice at genesis (local network only).',
|
|
263
|
+
parseEnv: (val: string) =>
|
|
264
|
+
val
|
|
265
|
+
.split(',')
|
|
266
|
+
.map(a => a.trim())
|
|
267
|
+
.filter(a => a.length > 0),
|
|
268
|
+
defaultValue: [],
|
|
269
|
+
},
|
|
260
270
|
};
|
|
261
271
|
|
|
262
272
|
export function getL1ContractsConfigEnvVars(): L1ContractsConfig {
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# L1 Contract Wrappers
|
|
2
|
+
|
|
3
|
+
This folder contains TypeScript wrappers for L1 contracts defined in `l1-contracts/`. These wrappers are used by the node client to interact with the rollup and related contracts on Ethereum.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
The goal of wrapping is to shield consumers from L1-specific and viem-specific details. Clients using these wrappers interact with domain types and branded types native to the Aztec codebase, without needing to understand viem's ABI type system or deal with raw types like `Hex` and `bigint`.
|
|
8
|
+
|
|
9
|
+
## Type Safety
|
|
10
|
+
|
|
11
|
+
### Explicit Return Types
|
|
12
|
+
|
|
13
|
+
Every function in the contract wrappers must declare its return type explicitly. This is critical because viem's type inference over ABI types is slow and significantly impacts IDE performance.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Good: Explicit return type
|
|
17
|
+
async getSlotNumber(): Promise<SlotNumber> {
|
|
18
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Bad: Inferred return type (slow)
|
|
22
|
+
async getSlotNumber() {
|
|
23
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Branded and Domain Types
|
|
28
|
+
|
|
29
|
+
Use branded types and domain-specific types instead of viem's autogenerated types for both arguments and return values:
|
|
30
|
+
|
|
31
|
+
- `CheckpointNumber`, `EpochNumber`, `SlotNumber` instead of `bigint`
|
|
32
|
+
- `EthAddress` instead of `` `0x${string}` `` or `Hex`
|
|
33
|
+
- `Fr`, `Buffer32` instead of `Hex` for hashes and field elements
|
|
34
|
+
- Custom domain types (e.g., `CheckpointLog`, `AttesterView`) instead of raw tuples
|
|
35
|
+
|
|
36
|
+
Type conversions happen inside wrapper methods, not at the call site:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
|
|
40
|
+
const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
|
|
41
|
+
return {
|
|
42
|
+
archive: Fr.fromString(result.archive),
|
|
43
|
+
headerHash: Buffer32.fromString(result.headerHash),
|
|
44
|
+
blockCount: result.blockCount,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Wrapper Pattern
|
|
50
|
+
|
|
51
|
+
### Basic Structure
|
|
52
|
+
|
|
53
|
+
Each wrapper follows a consistent structure:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
export class FooContract {
|
|
57
|
+
private readonly foo: GetContractReturnType<typeof FooAbi, ViemClient>;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
public readonly client: ViemClient,
|
|
61
|
+
address: Hex | EthAddress,
|
|
62
|
+
) {
|
|
63
|
+
if (address instanceof EthAddress) {
|
|
64
|
+
address = address.toString();
|
|
65
|
+
}
|
|
66
|
+
this.foo = getContract({ address, abi: FooAbi, client });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public get address(): Hex {
|
|
70
|
+
return this.foo.address;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getContract(): GetContractReturnType<typeof FooAbi, ViemClient> {
|
|
74
|
+
return this.foo;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The raw contract is exposed via `getContract()` for cases where direct access is needed, but most consumers should use the typed wrapper methods. Relying on `getContract()` is a code smell and should be avoided.
|
|
80
|
+
|
|
81
|
+
### Static Factory Methods
|
|
82
|
+
|
|
83
|
+
Wrappers may provide static factory methods for common initialization patterns:
|
|
84
|
+
|
|
85
|
+
- `getFromConfig(config)` - construct from configuration object
|
|
86
|
+
- `getFromL1ContractsValues(deployResult)` - construct from deployment result
|
|
87
|
+
|
|
88
|
+
### Wallet Assertions
|
|
89
|
+
|
|
90
|
+
For write operations that require a wallet, use an assertion helper:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
private assertWallet(): GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient> {
|
|
94
|
+
if (!isExtendedClient(this.client)) {
|
|
95
|
+
throw new Error('Wallet client is required for this operation');
|
|
96
|
+
}
|
|
97
|
+
return this.foo as GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient>;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Event Handling
|
|
102
|
+
|
|
103
|
+
### Event Log Types
|
|
104
|
+
|
|
105
|
+
Event logs are wrapped in `L1EventLog<T>` to include L1 block context:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
type L1EventLog<T> = {
|
|
109
|
+
l1BlockNumber: bigint;
|
|
110
|
+
l1BlockHash: Buffer32;
|
|
111
|
+
l1TransactionHash: Hex;
|
|
112
|
+
args: T;
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Event Fetching
|
|
117
|
+
|
|
118
|
+
Methods that fetch events convert viem's raw logs to domain types:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
|
|
122
|
+
const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
|
|
123
|
+
return logs.map(log => ({
|
|
124
|
+
l1BlockNumber: log.blockNumber!,
|
|
125
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
126
|
+
l1TransactionHash: log.transactionHash!,
|
|
127
|
+
args: {
|
|
128
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
129
|
+
// ... convert other fields
|
|
130
|
+
},
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Event Listeners
|
|
136
|
+
|
|
137
|
+
For reactive event handling, wrapper methods convert arguments before invoking callbacks:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
public listenToCheckpointInvalidated(
|
|
141
|
+
callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
|
|
142
|
+
): WatchContractEventReturnType {
|
|
143
|
+
return this.rollup.watchEvent.CheckpointInvalidated({}, {
|
|
144
|
+
onLogs: logs => {
|
|
145
|
+
for (const log of logs) {
|
|
146
|
+
if (log.args.checkpointNumber !== undefined) {
|
|
147
|
+
callback({ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber) });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Error Handling
|
|
156
|
+
|
|
157
|
+
Custom error classes in `errors.ts` extend `Error` and set `this.name` for proper error identification. Include relevant context as public readonly properties.
|