@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351

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