@aztec/ethereum 0.0.0-test.0
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/chain.d.ts +25 -0
- package/dest/chain.d.ts.map +1 -0
- package/dest/chain.js +53 -0
- package/dest/client.d.ts +16 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +31 -0
- package/dest/config.d.ts +39 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +70 -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/empire_base.d.ts +13 -0
- package/dest/contracts/empire_base.d.ts.map +1 -0
- package/dest/contracts/empire_base.js +11 -0
- package/dest/contracts/fee_juice.d.ts +15 -0
- package/dest/contracts/fee_juice.d.ts.map +1 -0
- package/dest/contracts/fee_juice.js +52 -0
- package/dest/contracts/forwarder.d.ts +24 -0
- package/dest/contracts/forwarder.d.ts.map +1 -0
- package/dest/contracts/forwarder.js +101 -0
- package/dest/contracts/governance.d.ts +79 -0
- package/dest/contracts/governance.d.ts.map +1 -0
- package/dest/contracts/governance.js +247 -0
- package/dest/contracts/governance_proposer.d.ts +28 -0
- package/dest/contracts/governance_proposer.d.ts.map +1 -0
- package/dest/contracts/governance_proposer.js +82 -0
- package/dest/contracts/index.d.ts +9 -0
- package/dest/contracts/index.d.ts.map +1 -0
- package/dest/contracts/index.js +8 -0
- package/dest/contracts/registry.d.ts +24 -0
- package/dest/contracts/registry.d.ts.map +1 -0
- package/dest/contracts/registry.js +85 -0
- package/dest/contracts/rollup.d.ts +92 -0
- package/dest/contracts/rollup.d.ts.map +1 -0
- package/dest/contracts/rollup.js +234 -0
- package/dest/contracts/slashing_proposer.d.ts +21 -0
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/slashing_proposer.js +47 -0
- package/dest/deploy_l1_contracts.d.ts +21210 -0
- package/dest/deploy_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_l1_contracts.js +687 -0
- package/dest/eth_cheat_codes.d.ts +147 -0
- package/dest/eth_cheat_codes.d.ts.map +1 -0
- package/dest/eth_cheat_codes.js +303 -0
- package/dest/index.d.ts +14 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +13 -0
- package/dest/l1_contract_addresses.d.ts +57 -0
- package/dest/l1_contract_addresses.d.ts.map +1 -0
- package/dest/l1_contract_addresses.js +97 -0
- package/dest/l1_reader.d.ts +16 -0
- package/dest/l1_reader.d.ts.map +1 -0
- package/dest/l1_reader.js +27 -0
- package/dest/l1_tx_utils.d.ts +192 -0
- package/dest/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils.js +641 -0
- package/dest/l1_tx_utils_with_blobs.d.ts +12 -0
- package/dest/l1_tx_utils_with_blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils_with_blobs.js +64 -0
- package/dest/queries.d.ts +12 -0
- package/dest/queries.d.ts.map +1 -0
- package/dest/queries.js +35 -0
- package/dest/test/delayed_tx_utils.d.ts +8 -0
- package/dest/test/delayed_tx_utils.d.ts.map +1 -0
- package/dest/test/delayed_tx_utils.js +21 -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 +6 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +5 -0
- package/dest/test/start_anvil.d.ts +12 -0
- package/dest/test/start_anvil.d.ts.map +1 -0
- package/dest/test/start_anvil.js +46 -0
- package/dest/test/tx_delayer.d.ts +25 -0
- package/dest/test/tx_delayer.d.ts.map +1 -0
- package/dest/test/tx_delayer.js +116 -0
- package/dest/test/upgrade_utils.d.ts +11 -0
- package/dest/test/upgrade_utils.d.ts.map +1 -0
- package/dest/test/upgrade_utils.js +104 -0
- package/dest/types.d.ts +14 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +1 -0
- package/dest/utils.d.ts +24 -0
- package/dest/utils.d.ts.map +1 -0
- package/dest/utils.js +209 -0
- package/package.json +98 -0
- package/src/chain.ts +71 -0
- package/src/client.ts +58 -0
- package/src/config.ts +103 -0
- package/src/constants.ts +4 -0
- package/src/contracts/empire_base.ts +19 -0
- package/src/contracts/fee_juice.ts +43 -0
- package/src/contracts/forwarder.ts +132 -0
- package/src/contracts/governance.ts +285 -0
- package/src/contracts/governance_proposer.ts +82 -0
- package/src/contracts/index.ts +8 -0
- package/src/contracts/registry.ts +106 -0
- package/src/contracts/rollup.ts +274 -0
- package/src/contracts/slashing_proposer.ts +51 -0
- package/src/deploy_l1_contracts.ts +948 -0
- package/src/eth_cheat_codes.ts +314 -0
- package/src/index.ts +13 -0
- package/src/l1_contract_addresses.ts +109 -0
- package/src/l1_reader.ts +42 -0
- package/src/l1_tx_utils.ts +847 -0
- package/src/l1_tx_utils_with_blobs.ts +86 -0
- package/src/queries.ts +58 -0
- package/src/test/delayed_tx_utils.ts +24 -0
- package/src/test/eth_cheat_codes_with_state.ts +38 -0
- package/src/test/index.ts +5 -0
- package/src/test/start_anvil.ts +52 -0
- package/src/test/tx_delayer.ts +163 -0
- package/src/test/upgrade_utils.ts +100 -0
- package/src/types.ts +33 -0
- package/src/utils.ts +276 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
|
|
6
|
+
import { type Hex, createPublicClient, fallback, http } from 'viem';
|
|
7
|
+
|
|
8
|
+
import type { ViemPublicClient } from './types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A class that provides utility functions for interacting with ethereum (L1).
|
|
12
|
+
*/
|
|
13
|
+
export class EthCheatCodes {
|
|
14
|
+
private publicClient: ViemPublicClient;
|
|
15
|
+
constructor(
|
|
16
|
+
/**
|
|
17
|
+
* The RPC URL to use for interacting with the chain
|
|
18
|
+
*/
|
|
19
|
+
public rpcUrls: string[],
|
|
20
|
+
/**
|
|
21
|
+
* The logger to use for the eth cheatcodes
|
|
22
|
+
*/
|
|
23
|
+
public logger = createLogger('ethereum:cheat_codes'),
|
|
24
|
+
) {
|
|
25
|
+
this.publicClient = createPublicClient({
|
|
26
|
+
transport: fallback(this.rpcUrls.map(url => http(url))),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async rpcCall(method: string, params: any[]) {
|
|
31
|
+
const paramsString = JSON.stringify(params);
|
|
32
|
+
this.logger.info(`Calling ${method} with params: ${paramsString} on ${this.rpcUrls.join(', ')}`);
|
|
33
|
+
return (await this.publicClient.transport.request({
|
|
34
|
+
method,
|
|
35
|
+
params,
|
|
36
|
+
})) as any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the auto mine status of the underlying chain
|
|
41
|
+
* @returns True if automine is on, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
public async isAutoMining(): Promise<boolean> {
|
|
44
|
+
try {
|
|
45
|
+
const res = await this.rpcCall('anvil_getAutomine', []);
|
|
46
|
+
return res;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the current blocknumber
|
|
55
|
+
* @returns The current block number
|
|
56
|
+
*/
|
|
57
|
+
public async blockNumber(): Promise<number> {
|
|
58
|
+
const res = await this.rpcCall('eth_blockNumber', []);
|
|
59
|
+
return parseInt(res, 16);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get the current chainId
|
|
64
|
+
* @returns The current chainId
|
|
65
|
+
*/
|
|
66
|
+
public async chainId(): Promise<number> {
|
|
67
|
+
const res = await this.rpcCall('eth_chainId', []);
|
|
68
|
+
return parseInt(res, 16);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get the current timestamp
|
|
73
|
+
* @returns The current timestamp
|
|
74
|
+
*/
|
|
75
|
+
public async timestamp(): Promise<number> {
|
|
76
|
+
const res = await this.rpcCall('eth_getBlockByNumber', ['latest', true]);
|
|
77
|
+
return parseInt(res.timestamp, 16);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Advance the chain by a number of blocks
|
|
82
|
+
* @param numberOfBlocks - The number of blocks to mine
|
|
83
|
+
*/
|
|
84
|
+
public async mine(numberOfBlocks = 1): Promise<void> {
|
|
85
|
+
await this.doMine(numberOfBlocks);
|
|
86
|
+
this.logger.warn(`Mined ${numberOfBlocks} L1 blocks`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private async doMine(numberOfBlocks = 1): Promise<void> {
|
|
90
|
+
try {
|
|
91
|
+
await this.rpcCall('hardhat_mine', [numberOfBlocks]);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
throw new Error(`Error mining: ${err}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Mines a single block with evm_mine
|
|
99
|
+
*/
|
|
100
|
+
public async evmMine(): Promise<void> {
|
|
101
|
+
try {
|
|
102
|
+
await this.rpcCall('evm_mine', []);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
throw new Error(`Error mining: ${err}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set the balance of an account
|
|
110
|
+
* @param account - The account to set the balance for
|
|
111
|
+
* @param balance - The balance to set
|
|
112
|
+
*/
|
|
113
|
+
public async setBalance(account: EthAddress, balance: bigint): Promise<void> {
|
|
114
|
+
try {
|
|
115
|
+
await this.rpcCall('anvil_setBalance', [account.toString(), toHex(balance)]);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
throw new Error(`Error setting balance for ${account}: ${err}`);
|
|
118
|
+
}
|
|
119
|
+
this.logger.warn(`Set balance for ${account} to ${balance}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Set the interval between blocks (block time)
|
|
124
|
+
* @param interval - The interval to use between blocks
|
|
125
|
+
*/
|
|
126
|
+
public async setBlockInterval(interval: number): Promise<void> {
|
|
127
|
+
try {
|
|
128
|
+
await this.rpcCall('anvil_setBlockTimestampInterval', [interval]);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
throw new Error(`Error setting block interval: ${err}`);
|
|
131
|
+
}
|
|
132
|
+
this.logger.warn(`Set L1 block interval to ${interval}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set the next block base fee per gas
|
|
137
|
+
* @param baseFee - The base fee to set
|
|
138
|
+
*/
|
|
139
|
+
public async setNextBlockBaseFeePerGas(baseFee: bigint | number): Promise<void> {
|
|
140
|
+
try {
|
|
141
|
+
await this.rpcCall('anvil_setNextBlockBaseFeePerGas', [baseFee.toString()]);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
throw new Error(`Error setting next block base fee per gas: ${err}`);
|
|
144
|
+
}
|
|
145
|
+
this.logger.warn(`Set L1 next block base fee per gas to ${baseFee}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set the interval between blocks (block time)
|
|
150
|
+
* @param seconds - The interval to use between blocks
|
|
151
|
+
*/
|
|
152
|
+
public async setIntervalMining(seconds: number): Promise<void> {
|
|
153
|
+
try {
|
|
154
|
+
await this.rpcCall('anvil_setIntervalMining', [seconds]);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
throw new Error(`Error setting interval mining: ${err}`);
|
|
157
|
+
}
|
|
158
|
+
this.logger.warn(`Set L1 interval mining to ${seconds} seconds`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Set the automine status of the underlying anvil chain
|
|
163
|
+
* @param automine - The automine status to set
|
|
164
|
+
*/
|
|
165
|
+
public async setAutomine(automine: boolean): Promise<void> {
|
|
166
|
+
try {
|
|
167
|
+
await this.rpcCall('anvil_setAutomine', [automine]);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
throw new Error(`Error setting automine: ${err}`);
|
|
170
|
+
}
|
|
171
|
+
this.logger.warn(`Set L1 automine to ${automine}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Drop a transaction from the mempool
|
|
176
|
+
* @param txHash - The transaction hash
|
|
177
|
+
*/
|
|
178
|
+
public async dropTransaction(txHash: Hex): Promise<void> {
|
|
179
|
+
try {
|
|
180
|
+
await this.rpcCall('anvil_dropTransaction', [txHash]);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
throw new Error(`Error dropping transaction: ${err}`);
|
|
183
|
+
}
|
|
184
|
+
this.logger.warn(`Dropped transaction ${txHash}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Set the next block timestamp
|
|
189
|
+
* @param timestamp - The timestamp to set the next block to
|
|
190
|
+
*/
|
|
191
|
+
public async setNextBlockTimestamp(timestamp: number): Promise<void> {
|
|
192
|
+
try {
|
|
193
|
+
await this.rpcCall('evm_setNextBlockTimestamp', [timestamp]);
|
|
194
|
+
} catch (err: any) {
|
|
195
|
+
throw new Error(`Error setting next block timestamp: ${err.message}`);
|
|
196
|
+
}
|
|
197
|
+
this.logger.warn(`Set L1 next block timestamp to ${timestamp}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Set the next block timestamp and mines the block
|
|
202
|
+
* @param timestamp - The timestamp to set the next block to
|
|
203
|
+
*/
|
|
204
|
+
public async warp(timestamp: number | bigint, silent = false): Promise<void> {
|
|
205
|
+
try {
|
|
206
|
+
await this.rpcCall('evm_setNextBlockTimestamp', [Number(timestamp)]);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
throw new Error(`Error warping: ${err}`);
|
|
209
|
+
}
|
|
210
|
+
await this.doMine();
|
|
211
|
+
if (!silent) {
|
|
212
|
+
this.logger.warn(`Warped L1 timestamp to ${timestamp}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Load the value at a storage slot of a contract address on eth
|
|
218
|
+
* @param contract - The contract address
|
|
219
|
+
* @param slot - The storage slot
|
|
220
|
+
* @returns - The value at the storage slot
|
|
221
|
+
*/
|
|
222
|
+
public async load(contract: EthAddress, slot: bigint): Promise<bigint> {
|
|
223
|
+
const res = await this.rpcCall('eth_getStorageAt', [contract.toString(), toHex(slot), 'latest']);
|
|
224
|
+
return BigInt(res);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Set the value at a storage slot of a contract address on eth
|
|
229
|
+
* @param contract - The contract address
|
|
230
|
+
* @param slot - The storage slot
|
|
231
|
+
* @param value - The value to set the storage slot to
|
|
232
|
+
*/
|
|
233
|
+
public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<void> {
|
|
234
|
+
// for the rpc call, we need to change value to be a 32 byte hex string.
|
|
235
|
+
try {
|
|
236
|
+
await this.rpcCall('hardhat_setStorageAt', [contract.toString(), toHex(slot), toHex(value, true)]);
|
|
237
|
+
} catch (err) {
|
|
238
|
+
throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${err}`);
|
|
239
|
+
}
|
|
240
|
+
this.logger.warn(`Set L1 storage for contract ${contract} at ${slot} to ${value}`);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Computes the slot value for a given map and key.
|
|
245
|
+
* @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
|
|
246
|
+
* @param key - The key to lookup in the map
|
|
247
|
+
* @returns The storage slot of the value in the map
|
|
248
|
+
*/
|
|
249
|
+
public keccak256(baseSlot: bigint, key: bigint): bigint {
|
|
250
|
+
// abi encode (removing the 0x) - concat key and baseSlot (both padded to 32 bytes)
|
|
251
|
+
const abiEncoded = toHex(key, true).substring(2) + toHex(baseSlot, true).substring(2);
|
|
252
|
+
return toBigIntBE(keccak256(Buffer.from(abiEncoded, 'hex')));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Send transactions impersonating an externally owned account or contract.
|
|
257
|
+
* @param who - The address to impersonate
|
|
258
|
+
*/
|
|
259
|
+
public async startImpersonating(who: EthAddress | Hex): Promise<void> {
|
|
260
|
+
try {
|
|
261
|
+
await this.rpcCall('hardhat_impersonateAccount', [who.toString()]);
|
|
262
|
+
} catch (err) {
|
|
263
|
+
throw new Error(`Error impersonating ${who}: ${err}`);
|
|
264
|
+
}
|
|
265
|
+
this.logger.warn(`Impersonating ${who}`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Stop impersonating an account that you are currently impersonating.
|
|
270
|
+
* @param who - The address to stop impersonating
|
|
271
|
+
*/
|
|
272
|
+
public async stopImpersonating(who: EthAddress | Hex): Promise<void> {
|
|
273
|
+
try {
|
|
274
|
+
await this.rpcCall('hardhat_stopImpersonatingAccount', [who.toString()]);
|
|
275
|
+
} catch (err) {
|
|
276
|
+
throw new Error(`Error when stopping the impersonation of ${who}: ${err}`);
|
|
277
|
+
}
|
|
278
|
+
this.logger.warn(`Stopped impersonating ${who}`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Set the bytecode for a contract
|
|
283
|
+
* @param contract - The contract address
|
|
284
|
+
* @param bytecode - The bytecode to set
|
|
285
|
+
*/
|
|
286
|
+
public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void> {
|
|
287
|
+
try {
|
|
288
|
+
await this.rpcCall('hardhat_setCode', [contract.toString(), bytecode]);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
throw new Error(`Error setting bytecode for ${contract}: ${err}`);
|
|
291
|
+
}
|
|
292
|
+
this.logger.warn(`Set bytecode for ${contract} to ${bytecode}`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Get the bytecode for a contract
|
|
297
|
+
* @param contract - The contract address
|
|
298
|
+
* @returns The bytecode for the contract
|
|
299
|
+
*/
|
|
300
|
+
public async getBytecode(contract: EthAddress): Promise<`0x${string}`> {
|
|
301
|
+
const res = await this.rpcCall('eth_getCode', [contract.toString(), 'latest']);
|
|
302
|
+
return res;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Get the raw transaction object for a given transaction hash
|
|
307
|
+
* @param txHash - The transaction hash
|
|
308
|
+
* @returns The raw transaction
|
|
309
|
+
*/
|
|
310
|
+
public async getRawTransaction(txHash: Hex): Promise<`0x${string}`> {
|
|
311
|
+
const res = await this.rpcCall('debug_getRawTransaction', [txHash]);
|
|
312
|
+
return res;
|
|
313
|
+
}
|
|
314
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './deploy_l1_contracts.js';
|
|
3
|
+
export * from './chain.js';
|
|
4
|
+
export * from './eth_cheat_codes.js';
|
|
5
|
+
export * from './l1_tx_utils.js';
|
|
6
|
+
export * from './l1_contract_addresses.js';
|
|
7
|
+
export * from './l1_reader.js';
|
|
8
|
+
export * from './utils.js';
|
|
9
|
+
export * from './config.js';
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
export * from './contracts/index.js';
|
|
12
|
+
export * from './queries.js';
|
|
13
|
+
export * from './client.js';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ConfigMappingsType } from '@aztec/foundation/config';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { type ZodFor, schemas } from '@aztec/foundation/schemas';
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The names of the current L1 contract addresses.
|
|
9
|
+
* NOTE: When changing this list, make sure to update CLI & CI scripts accordingly.
|
|
10
|
+
* For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
|
|
11
|
+
*/
|
|
12
|
+
export const L1ContractsNames = [
|
|
13
|
+
'rollupAddress',
|
|
14
|
+
'registryAddress',
|
|
15
|
+
'inboxAddress',
|
|
16
|
+
'outboxAddress',
|
|
17
|
+
'feeJuiceAddress',
|
|
18
|
+
'feeJuicePortalAddress',
|
|
19
|
+
'coinIssuerAddress',
|
|
20
|
+
'rewardDistributorAddress',
|
|
21
|
+
'governanceProposerAddress',
|
|
22
|
+
'governanceAddress',
|
|
23
|
+
'stakingAssetAddress',
|
|
24
|
+
] as const;
|
|
25
|
+
|
|
26
|
+
/** Provides the directory of current L1 contract addresses */
|
|
27
|
+
export type L1ContractAddresses = {
|
|
28
|
+
[K in (typeof L1ContractsNames)[number]]: EthAddress;
|
|
29
|
+
} & { slashFactoryAddress?: EthAddress | undefined };
|
|
30
|
+
|
|
31
|
+
export const L1ContractAddressesSchema = z.object({
|
|
32
|
+
rollupAddress: schemas.EthAddress,
|
|
33
|
+
registryAddress: schemas.EthAddress,
|
|
34
|
+
inboxAddress: schemas.EthAddress,
|
|
35
|
+
outboxAddress: schemas.EthAddress,
|
|
36
|
+
feeJuiceAddress: schemas.EthAddress,
|
|
37
|
+
stakingAssetAddress: schemas.EthAddress,
|
|
38
|
+
feeJuicePortalAddress: schemas.EthAddress,
|
|
39
|
+
coinIssuerAddress: schemas.EthAddress,
|
|
40
|
+
rewardDistributorAddress: schemas.EthAddress,
|
|
41
|
+
governanceProposerAddress: schemas.EthAddress,
|
|
42
|
+
governanceAddress: schemas.EthAddress,
|
|
43
|
+
slashFactoryAddress: schemas.EthAddress.optional(),
|
|
44
|
+
}) satisfies ZodFor<L1ContractAddresses>;
|
|
45
|
+
|
|
46
|
+
const parseEnv = (val: string) => EthAddress.fromString(val);
|
|
47
|
+
|
|
48
|
+
export const l1ContractAddressesMapping: ConfigMappingsType<L1ContractAddresses> = {
|
|
49
|
+
rollupAddress: {
|
|
50
|
+
env: 'ROLLUP_CONTRACT_ADDRESS',
|
|
51
|
+
description: 'The deployed L1 rollup contract address.',
|
|
52
|
+
parseEnv,
|
|
53
|
+
},
|
|
54
|
+
registryAddress: {
|
|
55
|
+
env: 'REGISTRY_CONTRACT_ADDRESS',
|
|
56
|
+
description: 'The deployed L1 registry contract address.',
|
|
57
|
+
parseEnv,
|
|
58
|
+
},
|
|
59
|
+
inboxAddress: {
|
|
60
|
+
env: 'INBOX_CONTRACT_ADDRESS',
|
|
61
|
+
description: 'The deployed L1 inbox contract address.',
|
|
62
|
+
parseEnv,
|
|
63
|
+
},
|
|
64
|
+
outboxAddress: {
|
|
65
|
+
env: 'OUTBOX_CONTRACT_ADDRESS',
|
|
66
|
+
description: 'The deployed L1 outbox contract address.',
|
|
67
|
+
parseEnv,
|
|
68
|
+
},
|
|
69
|
+
feeJuiceAddress: {
|
|
70
|
+
env: 'FEE_JUICE_CONTRACT_ADDRESS',
|
|
71
|
+
description: 'The deployed L1 Fee Juice contract address.',
|
|
72
|
+
parseEnv,
|
|
73
|
+
},
|
|
74
|
+
stakingAssetAddress: {
|
|
75
|
+
env: 'STAKING_ASSET_CONTRACT_ADDRESS',
|
|
76
|
+
description: 'The deployed L1 staking asset contract address.',
|
|
77
|
+
parseEnv,
|
|
78
|
+
},
|
|
79
|
+
feeJuicePortalAddress: {
|
|
80
|
+
env: 'FEE_JUICE_PORTAL_CONTRACT_ADDRESS',
|
|
81
|
+
description: 'The deployed L1 Fee Juice portal contract address.',
|
|
82
|
+
parseEnv,
|
|
83
|
+
},
|
|
84
|
+
coinIssuerAddress: {
|
|
85
|
+
env: 'COIN_ISSUER_CONTRACT_ADDRESS',
|
|
86
|
+
description: 'The deployed L1 coinIssuer contract address',
|
|
87
|
+
parseEnv,
|
|
88
|
+
},
|
|
89
|
+
rewardDistributorAddress: {
|
|
90
|
+
env: 'REWARD_DISTRIBUTOR_CONTRACT_ADDRESS',
|
|
91
|
+
description: 'The deployed L1 rewardDistributor contract address',
|
|
92
|
+
parseEnv,
|
|
93
|
+
},
|
|
94
|
+
governanceProposerAddress: {
|
|
95
|
+
env: 'GOVERNANCE_PROPOSER_CONTRACT_ADDRESS',
|
|
96
|
+
description: 'The deployed L1 governanceProposer contract address',
|
|
97
|
+
parseEnv,
|
|
98
|
+
},
|
|
99
|
+
governanceAddress: {
|
|
100
|
+
env: 'GOVERNANCE_CONTRACT_ADDRESS',
|
|
101
|
+
description: 'The deployed L1 governance contract address',
|
|
102
|
+
parseEnv,
|
|
103
|
+
},
|
|
104
|
+
slashFactoryAddress: {
|
|
105
|
+
env: 'SLASH_FACTORY_CONTRACT_ADDRESS',
|
|
106
|
+
description: 'The deployed L1 slashFactory contract address',
|
|
107
|
+
parseEnv,
|
|
108
|
+
},
|
|
109
|
+
};
|
package/src/l1_reader.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
+
|
|
3
|
+
import { type L1ContractAddresses, l1ContractAddressesMapping } from './l1_contract_addresses.js';
|
|
4
|
+
|
|
5
|
+
/** Configuration of the L1GlobalReader. */
|
|
6
|
+
export interface L1ReaderConfig {
|
|
7
|
+
/** The RPC Url of the ethereum host. */
|
|
8
|
+
l1RpcUrls: string[];
|
|
9
|
+
/** The chain ID of the ethereum host. */
|
|
10
|
+
l1ChainId: number;
|
|
11
|
+
/** The deployed l1 contract addresses */
|
|
12
|
+
l1Contracts: L1ContractAddresses;
|
|
13
|
+
/** The polling interval viem uses in ms */
|
|
14
|
+
viemPollingIntervalMS: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
|
|
18
|
+
l1RpcUrls: {
|
|
19
|
+
env: 'ETHEREUM_HOSTS',
|
|
20
|
+
description: 'The RPC Url of the ethereum host.',
|
|
21
|
+
parseEnv: (val: string) => val.split(',').map(url => url.trim()),
|
|
22
|
+
},
|
|
23
|
+
l1ChainId: {
|
|
24
|
+
env: 'L1_CHAIN_ID',
|
|
25
|
+
parseEnv: (val: string) => +val,
|
|
26
|
+
defaultValue: 31337,
|
|
27
|
+
description: 'The chain ID of the ethereum host.',
|
|
28
|
+
},
|
|
29
|
+
l1Contracts: {
|
|
30
|
+
description: 'The deployed L1 contract addresses',
|
|
31
|
+
nested: l1ContractAddressesMapping,
|
|
32
|
+
},
|
|
33
|
+
viemPollingIntervalMS: {
|
|
34
|
+
env: 'L1_READER_VIEM_POLLING_INTERVAL_MS',
|
|
35
|
+
description: 'The polling interval viem uses in ms',
|
|
36
|
+
...numberConfigHelper(1_000),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function getL1ReaderConfigFromEnv(): L1ReaderConfig {
|
|
41
|
+
return getConfigFromMappings<L1ReaderConfig>(l1ReaderConfigMappings);
|
|
42
|
+
}
|