@aztec/ethereum 0.0.0-test.0 → 0.0.1-commit.21caa21

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.
Files changed (232) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/chain.d.ts +1 -1
  5. package/dest/client.d.ts +6 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +16 -2
  8. package/dest/config.d.ts +111 -17
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +462 -22
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +24 -8
  13. package/dest/contracts/empire_base.d.ts.map +1 -1
  14. package/dest/contracts/empire_base.js +75 -2
  15. package/dest/contracts/empire_slashing_proposer.d.ts +66 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +200 -0
  18. package/dest/contracts/errors.d.ts +7 -0
  19. package/dest/contracts/errors.d.ts.map +1 -0
  20. package/dest/contracts/errors.js +12 -0
  21. package/dest/contracts/fee_asset_handler.d.ts +19 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +57 -0
  24. package/dest/contracts/fee_juice.d.ts +6 -7
  25. package/dest/contracts/fee_juice.d.ts.map +1 -1
  26. package/dest/contracts/fee_juice.js +27 -20
  27. package/dest/contracts/governance.d.ts +43 -32
  28. package/dest/contracts/governance.d.ts.map +1 -1
  29. package/dest/contracts/governance.js +87 -84
  30. package/dest/contracts/governance_proposer.d.ts +16 -13
  31. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  32. package/dest/contracts/governance_proposer.js +37 -17
  33. package/dest/contracts/gse.d.ts +32 -0
  34. package/dest/contracts/gse.d.ts.map +1 -0
  35. package/dest/contracts/gse.js +72 -0
  36. package/dest/contracts/inbox.d.ts +26 -0
  37. package/dest/contracts/inbox.d.ts.map +1 -0
  38. package/dest/contracts/inbox.js +45 -0
  39. package/dest/contracts/index.d.ts +9 -3
  40. package/dest/contracts/index.d.ts.map +1 -1
  41. package/dest/contracts/index.js +8 -2
  42. package/dest/contracts/multicall.d.ts +21 -0
  43. package/dest/contracts/multicall.d.ts.map +1 -0
  44. package/dest/contracts/multicall.js +156 -0
  45. package/dest/contracts/registry.d.ts +10 -5
  46. package/dest/contracts/registry.d.ts.map +1 -1
  47. package/dest/contracts/registry.js +44 -16
  48. package/dest/contracts/rollup.d.ts +204 -40
  49. package/dest/contracts/rollup.d.ts.map +1 -1
  50. package/dest/contracts/rollup.js +529 -79
  51. package/dest/contracts/slasher_contract.d.ts +44 -0
  52. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  53. package/dest/contracts/slasher_contract.js +75 -0
  54. package/dest/contracts/tally_slashing_proposer.d.ts +139 -0
  55. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  56. package/dest/contracts/tally_slashing_proposer.js +313 -0
  57. package/dest/contracts/utils.d.ts +3 -0
  58. package/dest/contracts/utils.d.ts.map +1 -0
  59. package/dest/contracts/utils.js +11 -0
  60. package/dest/deploy_l1_contracts.d.ts +577 -21114
  61. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  62. package/dest/deploy_l1_contracts.js +1225 -421
  63. package/dest/eth-signer/eth-signer.d.ts +21 -0
  64. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  65. package/dest/eth-signer/eth-signer.js +5 -0
  66. package/dest/eth-signer/index.d.ts +2 -0
  67. package/dest/eth-signer/index.d.ts.map +1 -0
  68. package/dest/eth-signer/index.js +1 -0
  69. package/dest/index.d.ts +7 -3
  70. package/dest/index.d.ts.map +1 -1
  71. package/dest/index.js +6 -2
  72. package/dest/l1_artifacts.d.ts +77344 -0
  73. package/dest/l1_artifacts.d.ts.map +1 -0
  74. package/dest/l1_artifacts.js +166 -0
  75. package/dest/l1_contract_addresses.d.ts +24 -4
  76. package/dest/l1_contract_addresses.d.ts.map +1 -1
  77. package/dest/l1_contract_addresses.js +22 -18
  78. package/dest/l1_reader.d.ts +2 -2
  79. package/dest/l1_reader.d.ts.map +1 -1
  80. package/dest/l1_reader.js +8 -8
  81. package/dest/l1_tx_utils/config.d.ts +59 -0
  82. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/config.js +82 -0
  84. package/dest/l1_tx_utils/constants.d.ts +6 -0
  85. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/constants.js +14 -0
  87. package/dest/l1_tx_utils/factory.d.ts +24 -0
  88. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/factory.js +12 -0
  90. package/dest/l1_tx_utils/index.d.ts +10 -0
  91. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/index.js +10 -0
  93. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  94. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/interfaces.js +4 -0
  96. package/dest/l1_tx_utils/l1_tx_utils.d.ts +94 -0
  97. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/l1_tx_utils.js +610 -0
  99. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  100. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  102. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +94 -0
  103. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +430 -0
  105. package/dest/l1_tx_utils/signer.d.ts +4 -0
  106. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/signer.js +16 -0
  108. package/dest/l1_tx_utils/types.d.ts +67 -0
  109. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/types.js +26 -0
  111. package/dest/l1_tx_utils/utils.d.ts +4 -0
  112. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/utils.js +14 -0
  114. package/dest/l1_types.d.ts +6 -0
  115. package/dest/l1_types.d.ts.map +1 -0
  116. package/dest/l1_types.js +1 -0
  117. package/dest/publisher_manager.d.ts +15 -0
  118. package/dest/publisher_manager.d.ts.map +1 -0
  119. package/dest/publisher_manager.js +88 -0
  120. package/dest/queries.d.ts +4 -2
  121. package/dest/queries.d.ts.map +1 -1
  122. package/dest/queries.js +53 -12
  123. package/dest/test/chain_monitor.d.ts +73 -0
  124. package/dest/test/chain_monitor.d.ts.map +1 -0
  125. package/dest/test/chain_monitor.js +215 -0
  126. package/dest/test/delayed_tx_utils.d.ts +8 -3
  127. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  128. package/dest/test/delayed_tx_utils.js +13 -6
  129. package/dest/test/eth_cheat_codes.d.ts +217 -0
  130. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  131. package/dest/test/eth_cheat_codes.js +558 -0
  132. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  133. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  134. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  135. package/dest/test/index.d.ts +4 -1
  136. package/dest/test/index.d.ts.map +1 -1
  137. package/dest/test/index.js +3 -0
  138. package/dest/test/rollup_cheat_codes.d.ts +87 -0
  139. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  140. package/dest/test/rollup_cheat_codes.js +266 -0
  141. package/dest/test/start_anvil.d.ts +7 -1
  142. package/dest/test/start_anvil.d.ts.map +1 -1
  143. package/dest/test/start_anvil.js +16 -7
  144. package/dest/test/tx_delayer.d.ts +18 -7
  145. package/dest/test/tx_delayer.d.ts.map +1 -1
  146. package/dest/test/tx_delayer.js +95 -19
  147. package/dest/test/upgrade_utils.d.ts +6 -5
  148. package/dest/test/upgrade_utils.d.ts.map +1 -1
  149. package/dest/test/upgrade_utils.js +23 -16
  150. package/dest/types.d.ts +7 -8
  151. package/dest/types.d.ts.map +1 -1
  152. package/dest/types.js +3 -1
  153. package/dest/utils.d.ts +2 -1
  154. package/dest/utils.d.ts.map +1 -1
  155. package/dest/utils.js +43 -88
  156. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  157. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  158. package/dest/zkPassportVerifierAddress.js +11 -0
  159. package/package.json +28 -19
  160. package/src/account.ts +5 -0
  161. package/src/client.ts +42 -4
  162. package/src/config.ts +592 -31
  163. package/src/contracts/empire_base.ts +77 -7
  164. package/src/contracts/empire_slashing_proposer.ts +265 -0
  165. package/src/contracts/errors.ts +13 -0
  166. package/src/contracts/fee_asset_handler.ts +63 -0
  167. package/src/contracts/fee_juice.ts +29 -15
  168. package/src/contracts/governance.ts +80 -77
  169. package/src/contracts/governance_proposer.ts +66 -24
  170. package/src/contracts/gse.ts +88 -0
  171. package/src/contracts/inbox.ts +63 -0
  172. package/src/contracts/index.ts +8 -2
  173. package/src/contracts/multicall.ts +155 -0
  174. package/src/contracts/registry.ts +51 -26
  175. package/src/contracts/rollup.ts +596 -74
  176. package/src/contracts/slasher_contract.ts +89 -0
  177. package/src/contracts/tally_slashing_proposer.ts +316 -0
  178. package/src/contracts/utils.ts +14 -0
  179. package/src/deploy_l1_contracts.ts +1459 -538
  180. package/src/eth-signer/eth-signer.ts +25 -0
  181. package/src/eth-signer/index.ts +1 -0
  182. package/src/index.ts +6 -2
  183. package/src/l1_artifacts.ts +254 -0
  184. package/src/l1_contract_addresses.ts +32 -19
  185. package/src/l1_reader.ts +9 -9
  186. package/src/l1_tx_utils/README.md +177 -0
  187. package/src/l1_tx_utils/config.ts +143 -0
  188. package/src/l1_tx_utils/constants.ts +18 -0
  189. package/src/l1_tx_utils/factory.ts +64 -0
  190. package/src/l1_tx_utils/index.ts +12 -0
  191. package/src/l1_tx_utils/interfaces.ts +86 -0
  192. package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
  193. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  194. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +558 -0
  195. package/src/l1_tx_utils/signer.ts +28 -0
  196. package/src/l1_tx_utils/types.ts +85 -0
  197. package/src/l1_tx_utils/utils.ts +16 -0
  198. package/src/l1_types.ts +6 -0
  199. package/src/publisher_manager.ts +106 -0
  200. package/src/queries.ts +73 -15
  201. package/src/test/chain_monitor.ts +243 -0
  202. package/src/test/delayed_tx_utils.ts +34 -6
  203. package/src/test/eth_cheat_codes.ts +588 -0
  204. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  205. package/src/test/index.ts +3 -0
  206. package/src/test/rollup_cheat_codes.ts +307 -0
  207. package/src/test/start_anvil.ts +22 -5
  208. package/src/test/tx_delayer.ts +127 -26
  209. package/src/test/upgrade_utils.ts +30 -21
  210. package/src/types.ts +10 -8
  211. package/src/utils.ts +49 -90
  212. package/src/zkPassportVerifierAddress.ts +15 -0
  213. package/dest/contracts/forwarder.d.ts +0 -24
  214. package/dest/contracts/forwarder.d.ts.map +0 -1
  215. package/dest/contracts/forwarder.js +0 -101
  216. package/dest/contracts/slashing_proposer.d.ts +0 -21
  217. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  218. package/dest/contracts/slashing_proposer.js +0 -47
  219. package/dest/eth_cheat_codes.d.ts +0 -147
  220. package/dest/eth_cheat_codes.d.ts.map +0 -1
  221. package/dest/eth_cheat_codes.js +0 -303
  222. package/dest/l1_tx_utils.d.ts +0 -192
  223. package/dest/l1_tx_utils.d.ts.map +0 -1
  224. package/dest/l1_tx_utils.js +0 -641
  225. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  226. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  227. package/dest/l1_tx_utils_with_blobs.js +0 -64
  228. package/src/contracts/forwarder.ts +0 -132
  229. package/src/contracts/slashing_proposer.ts +0 -51
  230. package/src/eth_cheat_codes.ts +0 -314
  231. package/src/l1_tx_utils.ts +0 -847
  232. package/src/l1_tx_utils_with_blobs.ts +0 -86
@@ -0,0 +1,558 @@
1
+ import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
2
+ import { keccak256 } from '@aztec/foundation/crypto';
3
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import { pluralize } from '@aztec/foundation/string';
6
+ import { createPublicClient, fallback, hexToNumber, http } from 'viem';
7
+ import { foundry } from 'viem/chains';
8
+ /**
9
+ * A class that provides utility functions for interacting with ethereum (L1).
10
+ */ export class EthCheatCodes {
11
+ rpcUrls;
12
+ dateProvider;
13
+ logger;
14
+ chain;
15
+ publicClient;
16
+ constructor(/**
17
+ * The RPC URL to use for interacting with the chain
18
+ */ rpcUrls, /**
19
+ * The date provider to use for time operations
20
+ */ dateProvider, /**
21
+ * The logger to use for the eth cheatcodes
22
+ */ logger = createLogger('ethereum:cheat_codes'), /**
23
+ * The chain configuration provided to Anvil
24
+ */ chain = foundry){
25
+ this.rpcUrls = rpcUrls;
26
+ this.dateProvider = dateProvider;
27
+ this.logger = logger;
28
+ this.chain = chain;
29
+ this.publicClient = createPublicClient({
30
+ transport: fallback(this.rpcUrls.map((url)=>http(url))),
31
+ chain: chain
32
+ });
33
+ }
34
+ rpcCall(method, params) {
35
+ this.logger.debug(`Calling ${method} with params: ${jsonStringify(params)} on ${this.rpcUrls.join(', ')}`);
36
+ return this.doRpcCall(method, params);
37
+ }
38
+ async doRpcCall(method, params) {
39
+ return await this.publicClient.transport.request({
40
+ method,
41
+ params
42
+ });
43
+ }
44
+ /**
45
+ * Get the auto mine status of the underlying chain
46
+ * @returns True if automine is on, false otherwise
47
+ */ async isAutoMining() {
48
+ try {
49
+ const res = await this.doRpcCall('anvil_getAutomine', []);
50
+ return res;
51
+ } catch (err) {
52
+ this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
53
+ }
54
+ return false;
55
+ }
56
+ /**
57
+ * Get the current blocknumber
58
+ * @returns The current block number
59
+ */ async blockNumber() {
60
+ const res = await this.doRpcCall('eth_blockNumber', []);
61
+ return parseInt(res, 16);
62
+ }
63
+ /**
64
+ * Get the current chainId
65
+ * @returns The current chainId
66
+ */ async chainId() {
67
+ const res = await this.doRpcCall('eth_chainId', []);
68
+ return parseInt(res, 16);
69
+ }
70
+ /**
71
+ * Get the current timestamp
72
+ * @returns The current timestamp
73
+ */ async timestamp() {
74
+ const res = await this.doRpcCall('eth_getBlockByNumber', [
75
+ 'latest',
76
+ true
77
+ ]);
78
+ return parseInt(res.timestamp, 16);
79
+ }
80
+ /**
81
+ * Advance the chain by a number of blocks
82
+ * @param numberOfBlocks - The number of blocks to mine
83
+ */ async mine(numberOfBlocks = 1) {
84
+ await this.doMine(Number(numberOfBlocks));
85
+ this.logger.warn(`Mined ${numberOfBlocks} L1 blocks`);
86
+ }
87
+ async doMine(numberOfBlocks = 1) {
88
+ try {
89
+ await this.doRpcCall('hardhat_mine', [
90
+ numberOfBlocks
91
+ ]);
92
+ } catch (err) {
93
+ throw new Error(`Error mining: ${err}`);
94
+ }
95
+ }
96
+ /**
97
+ * Mines a single block with evm_mine
98
+ */ async evmMine() {
99
+ try {
100
+ await this.doRpcCall('evm_mine', []);
101
+ this.logger.warn(`Mined 1 L1 block with evm_mine`);
102
+ } catch (err) {
103
+ throw new Error(`Error mining: ${err}`);
104
+ }
105
+ }
106
+ /**
107
+ * Set the balance of an account
108
+ * @param account - The account to set the balance for
109
+ * @param balance - The balance to set
110
+ */ async setBalance(account, balance) {
111
+ try {
112
+ await this.rpcCall('anvil_setBalance', [
113
+ account.toString(),
114
+ toHex(balance)
115
+ ]);
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
+ async getBalance(account) {
122
+ const res = await this.doRpcCall('eth_getBalance', [
123
+ account.toString(),
124
+ 'latest'
125
+ ]);
126
+ return BigInt(res);
127
+ }
128
+ /**
129
+ * Set the interval between successive blocks (block time). This does NOT enable interval mining.
130
+ * @param interval - The interval to use between blocks
131
+ */ async setBlockInterval(interval) {
132
+ try {
133
+ await this.rpcCall('anvil_setBlockTimestampInterval', [
134
+ interval
135
+ ]);
136
+ } catch (err) {
137
+ throw new Error(`Error setting block interval: ${err}`);
138
+ }
139
+ this.logger.warn(`Set L1 block interval to ${interval}`);
140
+ }
141
+ /**
142
+ * Set the next block base fee per gas
143
+ * @param baseFee - The base fee to set
144
+ */ async setNextBlockBaseFeePerGas(baseFee) {
145
+ try {
146
+ await this.rpcCall('anvil_setNextBlockBaseFeePerGas', [
147
+ baseFee.toString()
148
+ ]);
149
+ } catch (err) {
150
+ throw new Error(`Error setting next block base fee per gas: ${err}`);
151
+ }
152
+ this.logger.warn(`Set L1 next block base fee per gas to ${baseFee}`);
153
+ }
154
+ /**
155
+ * Get interval mining if set.
156
+ * @param seconds - The interval to use between blocks
157
+ */ getIntervalMining() {
158
+ try {
159
+ return this.doRpcCall('anvil_getIntervalMining', []);
160
+ } catch (err) {
161
+ throw new Error(`Error getting interval mining: ${err}`);
162
+ }
163
+ }
164
+ /**
165
+ * Enable interval mining at the given interval (block time)
166
+ * @param seconds - The interval to use between blocks
167
+ */ async setIntervalMining(seconds, opts = {}) {
168
+ try {
169
+ await this.rpcCall('anvil_setIntervalMining', [
170
+ seconds
171
+ ]);
172
+ } catch (err) {
173
+ throw new Error(`Error setting interval mining: ${err}`);
174
+ }
175
+ if (!opts.silent) {
176
+ this.logger.warn(`Set L1 interval mining to ${seconds} seconds`);
177
+ }
178
+ }
179
+ /**
180
+ * Set the automine status of the underlying anvil chain
181
+ * @param automine - The automine status to set
182
+ */ async setAutomine(automine, opts = {}) {
183
+ try {
184
+ await this.rpcCall('anvil_setAutomine', [
185
+ automine
186
+ ]);
187
+ } catch (err) {
188
+ throw new Error(`Error setting automine: ${err}`);
189
+ }
190
+ if (!opts.silent) {
191
+ this.logger.warn(`Set L1 automine to ${automine}`);
192
+ }
193
+ }
194
+ /**
195
+ * Drop a transaction from the mempool
196
+ * @param txHash - The transaction hash
197
+ */ async dropTransaction(txHash) {
198
+ try {
199
+ await this.rpcCall('anvil_dropTransaction', [
200
+ txHash
201
+ ]);
202
+ } catch (err) {
203
+ throw new Error(`Error dropping transaction: ${err}`);
204
+ }
205
+ this.logger.warn(`Dropped transaction ${txHash}`);
206
+ }
207
+ /**
208
+ * Set the next block timestamp
209
+ * @param timestamp - The timestamp to set the next block to
210
+ */ async setNextBlockTimestamp(timestamp) {
211
+ try {
212
+ await this.rpcCall('evm_setNextBlockTimestamp', [
213
+ timestamp instanceof Date ? Math.floor(timestamp.getTime() / 1000) : timestamp
214
+ ]);
215
+ } catch (err) {
216
+ throw new Error(`Error setting next block timestamp: ${err.message}`);
217
+ }
218
+ this.logger.warn(`Set L1 next block timestamp to ${timestamp}`);
219
+ }
220
+ /**
221
+ * Set the next block timestamp and mines the block.
222
+ * Optionally resets interval mining so the next block is mined in `blockInterval` seconds from now.
223
+ * Always updates the injected date provider to follow L1 time.
224
+ * @param timestamp - The timestamp to set the next block to
225
+ */ async warp(timestamp, opts = {}) {
226
+ let blockInterval = null;
227
+ try {
228
+ // Load current block interval and disable it
229
+ if (opts.resetBlockInterval) {
230
+ blockInterval = await this.getIntervalMining();
231
+ if (blockInterval !== null) {
232
+ await this.setIntervalMining(0, {
233
+ silent: true
234
+ });
235
+ }
236
+ }
237
+ // Set the timestamp of the next block to be mined
238
+ await this.rpcCall('evm_setNextBlockTimestamp', [
239
+ Number(timestamp)
240
+ ]);
241
+ // And mine a block so the timestamp goes into effect now
242
+ await this.doMine();
243
+ // Update the injected date provider so it follows L1 time
244
+ if ('setTime' in this.dateProvider) {
245
+ this.dateProvider.setTime(Number(timestamp) * 1000);
246
+ }
247
+ } catch (err) {
248
+ throw new Error(`Error warping: ${err}`);
249
+ } finally{
250
+ // Restore interval mining so the next block is mined in `blockInterval` seconds from this one
251
+ if (opts.resetBlockInterval && blockInterval !== null && blockInterval > 0) {
252
+ await this.setIntervalMining(blockInterval, {
253
+ silent: true
254
+ });
255
+ }
256
+ }
257
+ if (!opts.silent) {
258
+ this.logger.warn(`Warped L1 timestamp to ${timestamp}`);
259
+ }
260
+ }
261
+ /**
262
+ * Load the value at a storage slot of a contract address on eth
263
+ * @param contract - The contract address
264
+ * @param slot - The storage slot
265
+ * @returns - The value at the storage slot
266
+ */ async load(contract, slot) {
267
+ const res = await this.rpcCall('eth_getStorageAt', [
268
+ contract.toString(),
269
+ toHex(slot),
270
+ 'latest'
271
+ ]);
272
+ return BigInt(res);
273
+ }
274
+ /**
275
+ * Set the value at a storage slot of a contract address on eth
276
+ * @param contract - The contract address
277
+ * @param slot - The storage slot
278
+ * @param value - The value to set the storage slot to
279
+ */ async store(contract, slot, value, opts = {}) {
280
+ // for the rpc call, we need to change value to be a 32 byte hex string.
281
+ try {
282
+ await this.rpcCall('hardhat_setStorageAt', [
283
+ contract.toString(),
284
+ toHex(slot),
285
+ toHex(value, true)
286
+ ]);
287
+ } catch (err) {
288
+ throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${err}`);
289
+ }
290
+ if (!opts.silent) {
291
+ this.logger.warn(`Set L1 storage for contract ${contract} at ${slot} to ${value}`);
292
+ }
293
+ }
294
+ /**
295
+ * Computes the slot value for a given map and key.
296
+ * @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
297
+ * @param key - The key to lookup in the map
298
+ * @returns The storage slot of the value in the map
299
+ */ keccak256(baseSlot, key) {
300
+ // abi encode (removing the 0x) - concat key and baseSlot (both padded to 32 bytes)
301
+ const abiEncoded = toHex(key, true).substring(2) + toHex(baseSlot, true).substring(2);
302
+ return toBigIntBE(keccak256(Buffer.from(abiEncoded, 'hex')));
303
+ }
304
+ /**
305
+ * Send transactions impersonating an externally owned account or contract.
306
+ * @param who - The address to impersonate
307
+ */ async startImpersonating(who) {
308
+ try {
309
+ // Since the `who` impersonated will sometimes be a contract without funds, we fund it if needed.
310
+ if (await this.getBalance(who) === 0n) {
311
+ await this.setBalance(who, 10n * 10n ** 18n);
312
+ }
313
+ await this.rpcCall('hardhat_impersonateAccount', [
314
+ who.toString()
315
+ ]);
316
+ } catch (err) {
317
+ throw new Error(`Error impersonating ${who}: ${err}`);
318
+ }
319
+ this.logger.warn(`Impersonating ${who}`);
320
+ }
321
+ /**
322
+ * Stop impersonating an account that you are currently impersonating.
323
+ * @param who - The address to stop impersonating
324
+ */ async stopImpersonating(who) {
325
+ try {
326
+ await this.rpcCall('hardhat_stopImpersonatingAccount', [
327
+ who.toString()
328
+ ]);
329
+ } catch (err) {
330
+ throw new Error(`Error when stopping the impersonation of ${who}: ${err}`);
331
+ }
332
+ this.logger.warn(`Stopped impersonating ${who}`);
333
+ }
334
+ /**
335
+ * Set the bytecode for a contract
336
+ * @param contract - The contract address
337
+ * @param bytecode - The bytecode to set
338
+ */ async etch(contract, bytecode) {
339
+ try {
340
+ await this.rpcCall('hardhat_setCode', [
341
+ contract.toString(),
342
+ bytecode
343
+ ]);
344
+ } catch (err) {
345
+ throw new Error(`Error setting bytecode for ${contract}: ${err}`);
346
+ }
347
+ this.logger.warn(`Set bytecode for ${contract} to ${bytecode}`);
348
+ }
349
+ /**
350
+ * Get the bytecode for a contract
351
+ * @param contract - The contract address
352
+ * @returns The bytecode for the contract
353
+ */ async getBytecode(contract) {
354
+ return await this.doRpcCall('eth_getCode', [
355
+ contract.toString(),
356
+ 'latest'
357
+ ]);
358
+ }
359
+ /**
360
+ * Get the raw transaction object for a given transaction hash
361
+ * @param txHash - The transaction hash
362
+ * @returns The raw transaction
363
+ */ async getRawTransaction(txHash) {
364
+ return await this.doRpcCall('debug_getRawTransaction', [
365
+ txHash
366
+ ]);
367
+ }
368
+ /**
369
+ * Get the trace for a given transaction hash
370
+ * @param txHash - The transaction hash
371
+ * @returns The trace
372
+ */ async debugTraceTransaction(txHash) {
373
+ return await this.doRpcCall('debug_traceTransaction', [
374
+ txHash
375
+ ]);
376
+ }
377
+ /**
378
+ * Triggers a reorg of the given depth, removing those blocks from the chain.
379
+ * @param depth - The depth of the reorg
380
+ */ reorg(depth) {
381
+ return this.execWithPausedAnvil(()=>{
382
+ return this.rpcCall('anvil_rollback', [
383
+ depth
384
+ ]);
385
+ });
386
+ }
387
+ /**
388
+ * Causes Anvil to reorg until the given block number is the new tip
389
+ * @param blockNumber - The block number that's going to be the new tip
390
+ */ reorgTo(blockNumber) {
391
+ if (blockNumber <= 0) {
392
+ throw new Error(`Can't reorg to block before genesis: ${blockNumber}`);
393
+ }
394
+ return this.execWithPausedAnvil(async ()=>{
395
+ const currentTip = await this.publicClient.getBlockNumber();
396
+ if (currentTip < BigInt(blockNumber)) {
397
+ this.logger.warn(`Can't call anvil_rollback, chain tip is behind target block: ${currentTip} < ${BigInt(blockNumber)}`);
398
+ return;
399
+ }
400
+ const depth = Number(currentTip - BigInt(blockNumber) + 1n);
401
+ await this.rpcCall('anvil_rollback', [
402
+ depth
403
+ ]);
404
+ this.logger.warn(`Reorged L1 chain to block number ${blockNumber} (depth ${depth})`);
405
+ });
406
+ }
407
+ /**
408
+ * Triggers a reorg of the given depth, optionally replacing it with new blocks.
409
+ * The resulting block height will be the same as the original chain.
410
+ * @param depth - The depth of the reorg
411
+ * @param newBlocks - The blocks to replace the old ones with, each represented as a list of txs.
412
+ */ async reorgWithReplacement(depth, newBlocks = []) {
413
+ this.logger.verbose(`Preparing L1 reorg with depth ${depth}`);
414
+ try {
415
+ await this.rpcCall('anvil_reorg', [
416
+ depth,
417
+ newBlocks.flatMap((txs, index)=>txs.map((tx)=>[
418
+ typeof tx === 'string' ? tx : {
419
+ value: 0,
420
+ ...tx
421
+ },
422
+ index
423
+ ]))
424
+ ]);
425
+ } catch (err) {
426
+ throw new Error(`Error reorging: ${err}`);
427
+ }
428
+ this.logger.warn(`Reorged L1 chain with depth ${depth} and ${newBlocks.length} new blocks`, {
429
+ depth,
430
+ newBlocks
431
+ });
432
+ }
433
+ traceTransaction(txHash) {
434
+ return this.doRpcCall('trace_transaction', [
435
+ txHash
436
+ ]);
437
+ }
438
+ async getTxPoolStatus() {
439
+ const { pending, queued } = await this.doRpcCall('txpool_status', []);
440
+ return {
441
+ pending: hexToNumber(pending),
442
+ queued: hexToNumber(queued)
443
+ };
444
+ }
445
+ async getTxPoolContents() {
446
+ const txpoolContent = await this.doRpcCall('txpool_content', []);
447
+ return mapTxPoolContent(txpoolContent);
448
+ }
449
+ /**
450
+ * Mines an empty block by temporarily removing all pending transactions from the mempool,
451
+ * mining a block, and then re-adding the transactions back to the pool.
452
+ */ async mineEmptyBlock(blockCount = 1) {
453
+ await this.execWithPausedAnvil(async ()=>{
454
+ // Get all pending and queued transactions from the pool
455
+ const txs = await this.getTxPoolContents();
456
+ this.logger.debug(`Found ${txs.length} transactions in pool`);
457
+ // Get raw transactions before dropping them
458
+ const rawTxs = [];
459
+ for (const tx of txs){
460
+ try {
461
+ const rawTx = await this.doRpcCall('debug_getRawTransaction', [
462
+ tx.hash
463
+ ]);
464
+ if (rawTx) {
465
+ rawTxs.push(rawTx);
466
+ this.logger.debug(`Got raw tx for ${tx.hash}`);
467
+ } else {
468
+ this.logger.warn(`No raw tx found for ${tx.hash}`);
469
+ }
470
+ } catch {
471
+ this.logger.warn(`Failed to get raw transaction for ${tx.hash}`);
472
+ }
473
+ }
474
+ this.logger.debug(`Retrieved ${rawTxs.length} raw transactions`);
475
+ // Drop all transactions from the mempool
476
+ await this.doRpcCall('anvil_dropAllTransactions', []);
477
+ // Mine an empty block
478
+ await this.doMine(blockCount);
479
+ // Re-add the transactions to the pool
480
+ for (const rawTx of rawTxs){
481
+ try {
482
+ const txHash = await this.doRpcCall('eth_sendRawTransaction', [
483
+ rawTx
484
+ ]);
485
+ this.logger.debug(`Re-added transaction ${txHash}`);
486
+ } catch (err) {
487
+ this.logger.warn(`Failed to re-add transaction: ${err}`);
488
+ }
489
+ }
490
+ if (rawTxs.length !== txs.length) {
491
+ this.logger.warn(`Failed to add all txs back: had ${txs.length} but re-added ${rawTxs.length}`);
492
+ }
493
+ });
494
+ this.logger.warn(`Mined ${blockCount} empty L1 ${pluralize('block', blockCount)}`);
495
+ }
496
+ async execWithPausedAnvil(fn) {
497
+ const [blockInterval, wasAutoMining] = await Promise.all([
498
+ this.getIntervalMining(),
499
+ this.isAutoMining()
500
+ ]);
501
+ try {
502
+ if (blockInterval !== null) {
503
+ await this.setIntervalMining(0, {
504
+ silent: true
505
+ });
506
+ }
507
+ if (wasAutoMining) {
508
+ await this.setAutomine(false, {
509
+ silent: true
510
+ });
511
+ }
512
+ return await fn();
513
+ } finally{
514
+ try {
515
+ // restore automine if necessary
516
+ if (wasAutoMining) {
517
+ await this.setAutomine(true, {
518
+ silent: true
519
+ });
520
+ }
521
+ } catch (err) {
522
+ this.logger.warn(`Failed to reenable automining: ${err}`);
523
+ }
524
+ try {
525
+ // restore automine if necessary
526
+ if (blockInterval !== null) {
527
+ await this.setIntervalMining(blockInterval, {
528
+ silent: true
529
+ });
530
+ }
531
+ } catch (err) {
532
+ this.logger.warn(`Failed to reenable interval mining: ${err}`);
533
+ }
534
+ }
535
+ }
536
+ async syncDateProvider() {
537
+ const timestamp = await this.timestamp();
538
+ if ('setTime' in this.dateProvider) {
539
+ this.dateProvider.setTime(timestamp * 1000);
540
+ }
541
+ }
542
+ }
543
+ function mapTxPoolContent(content) {
544
+ const result = [];
545
+ const processPool = (pool, poolState)=>{
546
+ for (const txsByNonce of Object.values(pool)){
547
+ for (const tx of Object.values(txsByNonce)){
548
+ result.push({
549
+ ...tx,
550
+ poolState
551
+ });
552
+ }
553
+ }
554
+ };
555
+ processPool(content.pending, 'pending');
556
+ processPool(content.queued, 'queued');
557
+ return result;
558
+ }
@@ -1,4 +1,4 @@
1
- import { EthCheatCodes } from '../eth_cheat_codes.js';
1
+ import { EthCheatCodes } from './eth_cheat_codes.js';
2
2
  /**
3
3
  * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file.
4
4
  * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser.
@@ -15,4 +15,4 @@ export declare class EthCheatCodesWithState extends EthCheatCodes {
15
15
  */
16
16
  loadChainState(fileName: string): Promise<void>;
17
17
  }
18
- //# sourceMappingURL=eth_cheat_codes_with_state.d.ts.map
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXRoX2NoZWF0X2NvZGVzX3dpdGhfc3RhdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2V0aF9jaGVhdF9jb2Rlc193aXRoX3N0YXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUVyRDs7O0dBR0c7QUFDSCxxQkFBYSxzQkFBdUIsU0FBUSxhQUFhO0lBQ3ZEOzs7T0FHRztJQUNVLGNBQWMsQ0FBQyxRQUFRLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FTM0Q7SUFFRDs7O09BR0c7SUFDVSxjQUFjLENBQUMsUUFBUSxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBUTNEO0NBQ0YifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"eth_cheat_codes_with_state.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes_with_state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;IACvD;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS7D"}
1
+ {"version":3,"file":"eth_cheat_codes_with_state.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes_with_state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;IACvD;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAS3D;IAED;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ3D;CACF"}
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import { EthCheatCodes } from '../eth_cheat_codes.js';
2
+ import { EthCheatCodes } from './eth_cheat_codes.js';
3
3
  /**
4
4
  * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file.
5
5
  * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser.
@@ -1,6 +1,9 @@
1
1
  export * from './delayed_tx_utils.js';
2
+ export * from './eth_cheat_codes.js';
2
3
  export * from './eth_cheat_codes_with_state.js';
3
4
  export * from './start_anvil.js';
4
5
  export * from './tx_delayer.js';
5
6
  export * from './upgrade_utils.js';
6
- //# sourceMappingURL=index.d.ts.map
7
+ export * from './chain_monitor.js';
8
+ export * from './rollup_cheat_codes.js';
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyxzQkFBc0IsQ0FBQztBQUNyQyxjQUFjLGlDQUFpQyxDQUFDO0FBQ2hELGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsb0JBQW9CLENBQUM7QUFDbkMsY0FBYyx5QkFBeUIsQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
@@ -1,5 +1,8 @@
1
1
  export * from './delayed_tx_utils.js';
2
+ export * from './eth_cheat_codes.js';
2
3
  export * from './eth_cheat_codes_with_state.js';
3
4
  export * from './start_anvil.js';
4
5
  export * from './tx_delayer.js';
5
6
  export * from './upgrade_utils.js';
7
+ export * from './chain_monitor.js';
8
+ export * from './rollup_cheat_codes.js';