@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.03f7ef2

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