@aztec/ethereum 0.0.0-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +3 -0
  2. package/dest/chain.d.ts +25 -0
  3. package/dest/chain.d.ts.map +1 -0
  4. package/dest/chain.js +53 -0
  5. package/dest/client.d.ts +16 -0
  6. package/dest/client.d.ts.map +1 -0
  7. package/dest/client.js +31 -0
  8. package/dest/config.d.ts +39 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +70 -0
  11. package/dest/constants.d.ts +4 -0
  12. package/dest/constants.d.ts.map +1 -0
  13. package/dest/constants.js +2 -0
  14. package/dest/contracts/empire_base.d.ts +13 -0
  15. package/dest/contracts/empire_base.d.ts.map +1 -0
  16. package/dest/contracts/empire_base.js +11 -0
  17. package/dest/contracts/fee_juice.d.ts +15 -0
  18. package/dest/contracts/fee_juice.d.ts.map +1 -0
  19. package/dest/contracts/fee_juice.js +52 -0
  20. package/dest/contracts/forwarder.d.ts +24 -0
  21. package/dest/contracts/forwarder.d.ts.map +1 -0
  22. package/dest/contracts/forwarder.js +101 -0
  23. package/dest/contracts/governance.d.ts +79 -0
  24. package/dest/contracts/governance.d.ts.map +1 -0
  25. package/dest/contracts/governance.js +247 -0
  26. package/dest/contracts/governance_proposer.d.ts +28 -0
  27. package/dest/contracts/governance_proposer.d.ts.map +1 -0
  28. package/dest/contracts/governance_proposer.js +82 -0
  29. package/dest/contracts/index.d.ts +9 -0
  30. package/dest/contracts/index.d.ts.map +1 -0
  31. package/dest/contracts/index.js +8 -0
  32. package/dest/contracts/registry.d.ts +24 -0
  33. package/dest/contracts/registry.d.ts.map +1 -0
  34. package/dest/contracts/registry.js +85 -0
  35. package/dest/contracts/rollup.d.ts +92 -0
  36. package/dest/contracts/rollup.d.ts.map +1 -0
  37. package/dest/contracts/rollup.js +234 -0
  38. package/dest/contracts/slashing_proposer.d.ts +21 -0
  39. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  40. package/dest/contracts/slashing_proposer.js +47 -0
  41. package/dest/deploy_l1_contracts.d.ts +21210 -0
  42. package/dest/deploy_l1_contracts.d.ts.map +1 -0
  43. package/dest/deploy_l1_contracts.js +687 -0
  44. package/dest/eth_cheat_codes.d.ts +147 -0
  45. package/dest/eth_cheat_codes.d.ts.map +1 -0
  46. package/dest/eth_cheat_codes.js +303 -0
  47. package/dest/index.d.ts +14 -0
  48. package/dest/index.d.ts.map +1 -0
  49. package/dest/index.js +13 -0
  50. package/dest/l1_contract_addresses.d.ts +57 -0
  51. package/dest/l1_contract_addresses.d.ts.map +1 -0
  52. package/dest/l1_contract_addresses.js +97 -0
  53. package/dest/l1_reader.d.ts +16 -0
  54. package/dest/l1_reader.d.ts.map +1 -0
  55. package/dest/l1_reader.js +27 -0
  56. package/dest/l1_tx_utils.d.ts +192 -0
  57. package/dest/l1_tx_utils.d.ts.map +1 -0
  58. package/dest/l1_tx_utils.js +641 -0
  59. package/dest/l1_tx_utils_with_blobs.d.ts +12 -0
  60. package/dest/l1_tx_utils_with_blobs.d.ts.map +1 -0
  61. package/dest/l1_tx_utils_with_blobs.js +64 -0
  62. package/dest/queries.d.ts +12 -0
  63. package/dest/queries.d.ts.map +1 -0
  64. package/dest/queries.js +35 -0
  65. package/dest/test/delayed_tx_utils.d.ts +8 -0
  66. package/dest/test/delayed_tx_utils.d.ts.map +1 -0
  67. package/dest/test/delayed_tx_utils.js +21 -0
  68. package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
  69. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
  70. package/dest/test/eth_cheat_codes_with_state.js +34 -0
  71. package/dest/test/index.d.ts +6 -0
  72. package/dest/test/index.d.ts.map +1 -0
  73. package/dest/test/index.js +5 -0
  74. package/dest/test/start_anvil.d.ts +12 -0
  75. package/dest/test/start_anvil.d.ts.map +1 -0
  76. package/dest/test/start_anvil.js +46 -0
  77. package/dest/test/tx_delayer.d.ts +25 -0
  78. package/dest/test/tx_delayer.d.ts.map +1 -0
  79. package/dest/test/tx_delayer.js +116 -0
  80. package/dest/test/upgrade_utils.d.ts +11 -0
  81. package/dest/test/upgrade_utils.d.ts.map +1 -0
  82. package/dest/test/upgrade_utils.js +104 -0
  83. package/dest/types.d.ts +14 -0
  84. package/dest/types.d.ts.map +1 -0
  85. package/dest/types.js +1 -0
  86. package/dest/utils.d.ts +24 -0
  87. package/dest/utils.d.ts.map +1 -0
  88. package/dest/utils.js +209 -0
  89. package/package.json +98 -0
  90. package/src/chain.ts +71 -0
  91. package/src/client.ts +58 -0
  92. package/src/config.ts +103 -0
  93. package/src/constants.ts +4 -0
  94. package/src/contracts/empire_base.ts +19 -0
  95. package/src/contracts/fee_juice.ts +43 -0
  96. package/src/contracts/forwarder.ts +132 -0
  97. package/src/contracts/governance.ts +285 -0
  98. package/src/contracts/governance_proposer.ts +82 -0
  99. package/src/contracts/index.ts +8 -0
  100. package/src/contracts/registry.ts +106 -0
  101. package/src/contracts/rollup.ts +274 -0
  102. package/src/contracts/slashing_proposer.ts +51 -0
  103. package/src/deploy_l1_contracts.ts +948 -0
  104. package/src/eth_cheat_codes.ts +314 -0
  105. package/src/index.ts +13 -0
  106. package/src/l1_contract_addresses.ts +109 -0
  107. package/src/l1_reader.ts +42 -0
  108. package/src/l1_tx_utils.ts +847 -0
  109. package/src/l1_tx_utils_with_blobs.ts +86 -0
  110. package/src/queries.ts +58 -0
  111. package/src/test/delayed_tx_utils.ts +24 -0
  112. package/src/test/eth_cheat_codes_with_state.ts +38 -0
  113. package/src/test/index.ts +5 -0
  114. package/src/test/start_anvil.ts +52 -0
  115. package/src/test/tx_delayer.ts +163 -0
  116. package/src/test/upgrade_utils.ts +100 -0
  117. package/src/types.ts +33 -0
  118. package/src/utils.ts +276 -0
@@ -0,0 +1,147 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { type Hex } from 'viem';
3
+ /**
4
+ * A class that provides utility functions for interacting with ethereum (L1).
5
+ */
6
+ export declare class EthCheatCodes {
7
+ /**
8
+ * The RPC URL to use for interacting with the chain
9
+ */
10
+ rpcUrls: string[];
11
+ /**
12
+ * The logger to use for the eth cheatcodes
13
+ */
14
+ logger: import("@aztec/foundation/log").Logger;
15
+ private publicClient;
16
+ constructor(
17
+ /**
18
+ * The RPC URL to use for interacting with the chain
19
+ */
20
+ rpcUrls: string[],
21
+ /**
22
+ * The logger to use for the eth cheatcodes
23
+ */
24
+ logger?: import("@aztec/foundation/log").Logger);
25
+ rpcCall(method: string, params: any[]): Promise<any>;
26
+ /**
27
+ * Get the auto mine status of the underlying chain
28
+ * @returns True if automine is on, false otherwise
29
+ */
30
+ isAutoMining(): Promise<boolean>;
31
+ /**
32
+ * Get the current blocknumber
33
+ * @returns The current block number
34
+ */
35
+ blockNumber(): Promise<number>;
36
+ /**
37
+ * Get the current chainId
38
+ * @returns The current chainId
39
+ */
40
+ chainId(): Promise<number>;
41
+ /**
42
+ * Get the current timestamp
43
+ * @returns The current timestamp
44
+ */
45
+ timestamp(): Promise<number>;
46
+ /**
47
+ * Advance the chain by a number of blocks
48
+ * @param numberOfBlocks - The number of blocks to mine
49
+ */
50
+ mine(numberOfBlocks?: number): Promise<void>;
51
+ private doMine;
52
+ /**
53
+ * Mines a single block with evm_mine
54
+ */
55
+ evmMine(): Promise<void>;
56
+ /**
57
+ * Set the balance of an account
58
+ * @param account - The account to set the balance for
59
+ * @param balance - The balance to set
60
+ */
61
+ setBalance(account: EthAddress, balance: bigint): Promise<void>;
62
+ /**
63
+ * Set the interval between blocks (block time)
64
+ * @param interval - The interval to use between blocks
65
+ */
66
+ setBlockInterval(interval: number): Promise<void>;
67
+ /**
68
+ * Set the next block base fee per gas
69
+ * @param baseFee - The base fee to set
70
+ */
71
+ setNextBlockBaseFeePerGas(baseFee: bigint | number): Promise<void>;
72
+ /**
73
+ * Set the interval between blocks (block time)
74
+ * @param seconds - The interval to use between blocks
75
+ */
76
+ setIntervalMining(seconds: number): Promise<void>;
77
+ /**
78
+ * Set the automine status of the underlying anvil chain
79
+ * @param automine - The automine status to set
80
+ */
81
+ setAutomine(automine: boolean): Promise<void>;
82
+ /**
83
+ * Drop a transaction from the mempool
84
+ * @param txHash - The transaction hash
85
+ */
86
+ dropTransaction(txHash: Hex): Promise<void>;
87
+ /**
88
+ * Set the next block timestamp
89
+ * @param timestamp - The timestamp to set the next block to
90
+ */
91
+ setNextBlockTimestamp(timestamp: number): Promise<void>;
92
+ /**
93
+ * Set the next block timestamp and mines the block
94
+ * @param timestamp - The timestamp to set the next block to
95
+ */
96
+ warp(timestamp: number | bigint, silent?: boolean): Promise<void>;
97
+ /**
98
+ * Load the value at a storage slot of a contract address on eth
99
+ * @param contract - The contract address
100
+ * @param slot - The storage slot
101
+ * @returns - The value at the storage slot
102
+ */
103
+ load(contract: EthAddress, slot: bigint): Promise<bigint>;
104
+ /**
105
+ * Set the value at a storage slot of a contract address on eth
106
+ * @param contract - The contract address
107
+ * @param slot - The storage slot
108
+ * @param value - The value to set the storage slot to
109
+ */
110
+ store(contract: EthAddress, slot: bigint, value: bigint): Promise<void>;
111
+ /**
112
+ * Computes the slot value for a given map and key.
113
+ * @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
114
+ * @param key - The key to lookup in the map
115
+ * @returns The storage slot of the value in the map
116
+ */
117
+ keccak256(baseSlot: bigint, key: bigint): bigint;
118
+ /**
119
+ * Send transactions impersonating an externally owned account or contract.
120
+ * @param who - The address to impersonate
121
+ */
122
+ startImpersonating(who: EthAddress | Hex): Promise<void>;
123
+ /**
124
+ * Stop impersonating an account that you are currently impersonating.
125
+ * @param who - The address to stop impersonating
126
+ */
127
+ stopImpersonating(who: EthAddress | Hex): Promise<void>;
128
+ /**
129
+ * Set the bytecode for a contract
130
+ * @param contract - The contract address
131
+ * @param bytecode - The bytecode to set
132
+ */
133
+ etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void>;
134
+ /**
135
+ * Get the bytecode for a contract
136
+ * @param contract - The contract address
137
+ * @returns The bytecode for the contract
138
+ */
139
+ getBytecode(contract: EthAddress): Promise<`0x${string}`>;
140
+ /**
141
+ * Get the raw transaction object for a given transaction hash
142
+ * @param txHash - The transaction hash
143
+ * @returns The raw transaction
144
+ */
145
+ getRawTransaction(txHash: Hex): Promise<`0x${string}`>;
146
+ }
147
+ //# sourceMappingURL=eth_cheat_codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth_cheat_codes.d.ts","sourceRoot":"","sources":["../src/eth_cheat_codes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,MAAM,CAAC;AAIpE;;GAEG;AACH,qBAAa,aAAa;IAGtB;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE;IACxB;;OAEG;IACI,MAAM;IATf,OAAO,CAAC,YAAY,CAAmB;;IAErC;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE;IACxB;;OAEG;IACI,MAAM,yCAAuC;IAOhD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE;IAS3C;;;OAGG;IACU,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAU7C;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAK3C;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvC;;;OAGG;IACU,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAKzC;;;OAGG;IACU,IAAI,CAAC,cAAc,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAKtC,MAAM;IAQpB;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrC;;;;OAIG;IACU,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5E;;;OAGG;IACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9D;;;OAGG;IACU,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/E;;;OAGG;IACU,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9D;;;OAGG;IACU,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D;;;OAGG;IACU,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD;;;OAGG;IACU,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE;;;OAGG;IACU,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5E;;;;;OAKG;IACU,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKtE;;;;;OAKG;IACU,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUpF;;;;;OAKG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAMvD;;;OAGG;IACU,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IASrE;;;OAGG;IACU,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE;;;;OAIG;IACU,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/E;;;;OAIG;IACU,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;IAKtE;;;;OAIG;IACU,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;CAIpE"}
@@ -0,0 +1,303 @@
1
+ import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
2
+ import { keccak256 } from '@aztec/foundation/crypto';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { createPublicClient, fallback, http } from 'viem';
5
+ /**
6
+ * A class that provides utility functions for interacting with ethereum (L1).
7
+ */ export class EthCheatCodes {
8
+ rpcUrls;
9
+ logger;
10
+ publicClient;
11
+ constructor(/**
12
+ * The RPC URL to use for interacting with the chain
13
+ */ rpcUrls, /**
14
+ * The logger to use for the eth cheatcodes
15
+ */ logger = createLogger('ethereum:cheat_codes')){
16
+ this.rpcUrls = rpcUrls;
17
+ this.logger = logger;
18
+ this.publicClient = createPublicClient({
19
+ transport: fallback(this.rpcUrls.map((url)=>http(url)))
20
+ });
21
+ }
22
+ async rpcCall(method, params) {
23
+ const paramsString = JSON.stringify(params);
24
+ this.logger.info(`Calling ${method} with params: ${paramsString} on ${this.rpcUrls.join(', ')}`);
25
+ return await this.publicClient.transport.request({
26
+ method,
27
+ params
28
+ });
29
+ }
30
+ /**
31
+ * Get the auto mine status of the underlying chain
32
+ * @returns True if automine is on, false otherwise
33
+ */ async isAutoMining() {
34
+ try {
35
+ const res = await this.rpcCall('anvil_getAutomine', []);
36
+ return res;
37
+ } catch (err) {
38
+ this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
39
+ }
40
+ return false;
41
+ }
42
+ /**
43
+ * Get the current blocknumber
44
+ * @returns The current block number
45
+ */ async blockNumber() {
46
+ const res = await this.rpcCall('eth_blockNumber', []);
47
+ return parseInt(res, 16);
48
+ }
49
+ /**
50
+ * Get the current chainId
51
+ * @returns The current chainId
52
+ */ async chainId() {
53
+ const res = await this.rpcCall('eth_chainId', []);
54
+ return parseInt(res, 16);
55
+ }
56
+ /**
57
+ * Get the current timestamp
58
+ * @returns The current timestamp
59
+ */ async timestamp() {
60
+ const res = await this.rpcCall('eth_getBlockByNumber', [
61
+ 'latest',
62
+ true
63
+ ]);
64
+ return parseInt(res.timestamp, 16);
65
+ }
66
+ /**
67
+ * Advance the chain by a number of blocks
68
+ * @param numberOfBlocks - The number of blocks to mine
69
+ */ async mine(numberOfBlocks = 1) {
70
+ await this.doMine(numberOfBlocks);
71
+ this.logger.warn(`Mined ${numberOfBlocks} L1 blocks`);
72
+ }
73
+ async doMine(numberOfBlocks = 1) {
74
+ try {
75
+ await this.rpcCall('hardhat_mine', [
76
+ numberOfBlocks
77
+ ]);
78
+ } catch (err) {
79
+ throw new Error(`Error mining: ${err}`);
80
+ }
81
+ }
82
+ /**
83
+ * Mines a single block with evm_mine
84
+ */ async evmMine() {
85
+ try {
86
+ await this.rpcCall('evm_mine', []);
87
+ } catch (err) {
88
+ throw new Error(`Error mining: ${err}`);
89
+ }
90
+ }
91
+ /**
92
+ * Set the balance of an account
93
+ * @param account - The account to set the balance for
94
+ * @param balance - The balance to set
95
+ */ async setBalance(account, balance) {
96
+ try {
97
+ await this.rpcCall('anvil_setBalance', [
98
+ account.toString(),
99
+ toHex(balance)
100
+ ]);
101
+ } catch (err) {
102
+ throw new Error(`Error setting balance for ${account}: ${err}`);
103
+ }
104
+ this.logger.warn(`Set balance for ${account} to ${balance}`);
105
+ }
106
+ /**
107
+ * Set the interval between blocks (block time)
108
+ * @param interval - The interval to use between blocks
109
+ */ async setBlockInterval(interval) {
110
+ try {
111
+ await this.rpcCall('anvil_setBlockTimestampInterval', [
112
+ interval
113
+ ]);
114
+ } catch (err) {
115
+ throw new Error(`Error setting block interval: ${err}`);
116
+ }
117
+ this.logger.warn(`Set L1 block interval to ${interval}`);
118
+ }
119
+ /**
120
+ * Set the next block base fee per gas
121
+ * @param baseFee - The base fee to set
122
+ */ async setNextBlockBaseFeePerGas(baseFee) {
123
+ try {
124
+ await this.rpcCall('anvil_setNextBlockBaseFeePerGas', [
125
+ baseFee.toString()
126
+ ]);
127
+ } catch (err) {
128
+ throw new Error(`Error setting next block base fee per gas: ${err}`);
129
+ }
130
+ this.logger.warn(`Set L1 next block base fee per gas to ${baseFee}`);
131
+ }
132
+ /**
133
+ * Set the interval between blocks (block time)
134
+ * @param seconds - The interval to use between blocks
135
+ */ async setIntervalMining(seconds) {
136
+ try {
137
+ await this.rpcCall('anvil_setIntervalMining', [
138
+ seconds
139
+ ]);
140
+ } catch (err) {
141
+ throw new Error(`Error setting interval mining: ${err}`);
142
+ }
143
+ this.logger.warn(`Set L1 interval mining to ${seconds} seconds`);
144
+ }
145
+ /**
146
+ * Set the automine status of the underlying anvil chain
147
+ * @param automine - The automine status to set
148
+ */ async setAutomine(automine) {
149
+ try {
150
+ await this.rpcCall('anvil_setAutomine', [
151
+ automine
152
+ ]);
153
+ } catch (err) {
154
+ throw new Error(`Error setting automine: ${err}`);
155
+ }
156
+ this.logger.warn(`Set L1 automine to ${automine}`);
157
+ }
158
+ /**
159
+ * Drop a transaction from the mempool
160
+ * @param txHash - The transaction hash
161
+ */ async dropTransaction(txHash) {
162
+ try {
163
+ await this.rpcCall('anvil_dropTransaction', [
164
+ txHash
165
+ ]);
166
+ } catch (err) {
167
+ throw new Error(`Error dropping transaction: ${err}`);
168
+ }
169
+ this.logger.warn(`Dropped transaction ${txHash}`);
170
+ }
171
+ /**
172
+ * Set the next block timestamp
173
+ * @param timestamp - The timestamp to set the next block to
174
+ */ async setNextBlockTimestamp(timestamp) {
175
+ try {
176
+ await this.rpcCall('evm_setNextBlockTimestamp', [
177
+ timestamp
178
+ ]);
179
+ } catch (err) {
180
+ throw new Error(`Error setting next block timestamp: ${err.message}`);
181
+ }
182
+ this.logger.warn(`Set L1 next block timestamp to ${timestamp}`);
183
+ }
184
+ /**
185
+ * Set the next block timestamp and mines the block
186
+ * @param timestamp - The timestamp to set the next block to
187
+ */ async warp(timestamp, silent = false) {
188
+ try {
189
+ await this.rpcCall('evm_setNextBlockTimestamp', [
190
+ Number(timestamp)
191
+ ]);
192
+ } catch (err) {
193
+ throw new Error(`Error warping: ${err}`);
194
+ }
195
+ await this.doMine();
196
+ if (!silent) {
197
+ this.logger.warn(`Warped L1 timestamp to ${timestamp}`);
198
+ }
199
+ }
200
+ /**
201
+ * Load the value at a storage slot of a contract address on eth
202
+ * @param contract - The contract address
203
+ * @param slot - The storage slot
204
+ * @returns - The value at the storage slot
205
+ */ async load(contract, slot) {
206
+ const res = await this.rpcCall('eth_getStorageAt', [
207
+ contract.toString(),
208
+ toHex(slot),
209
+ 'latest'
210
+ ]);
211
+ return BigInt(res);
212
+ }
213
+ /**
214
+ * Set the value at a storage slot of a contract address on eth
215
+ * @param contract - The contract address
216
+ * @param slot - The storage slot
217
+ * @param value - The value to set the storage slot to
218
+ */ async store(contract, slot, value) {
219
+ // for the rpc call, we need to change value to be a 32 byte hex string.
220
+ try {
221
+ await this.rpcCall('hardhat_setStorageAt', [
222
+ contract.toString(),
223
+ toHex(slot),
224
+ toHex(value, true)
225
+ ]);
226
+ } catch (err) {
227
+ throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${err}`);
228
+ }
229
+ this.logger.warn(`Set L1 storage for contract ${contract} at ${slot} to ${value}`);
230
+ }
231
+ /**
232
+ * Computes the slot value for a given map and key.
233
+ * @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
234
+ * @param key - The key to lookup in the map
235
+ * @returns The storage slot of the value in the map
236
+ */ keccak256(baseSlot, key) {
237
+ // abi encode (removing the 0x) - concat key and baseSlot (both padded to 32 bytes)
238
+ const abiEncoded = toHex(key, true).substring(2) + toHex(baseSlot, true).substring(2);
239
+ return toBigIntBE(keccak256(Buffer.from(abiEncoded, 'hex')));
240
+ }
241
+ /**
242
+ * Send transactions impersonating an externally owned account or contract.
243
+ * @param who - The address to impersonate
244
+ */ async startImpersonating(who) {
245
+ try {
246
+ await this.rpcCall('hardhat_impersonateAccount', [
247
+ who.toString()
248
+ ]);
249
+ } catch (err) {
250
+ throw new Error(`Error impersonating ${who}: ${err}`);
251
+ }
252
+ this.logger.warn(`Impersonating ${who}`);
253
+ }
254
+ /**
255
+ * Stop impersonating an account that you are currently impersonating.
256
+ * @param who - The address to stop impersonating
257
+ */ async stopImpersonating(who) {
258
+ try {
259
+ await this.rpcCall('hardhat_stopImpersonatingAccount', [
260
+ who.toString()
261
+ ]);
262
+ } catch (err) {
263
+ throw new Error(`Error when stopping the impersonation of ${who}: ${err}`);
264
+ }
265
+ this.logger.warn(`Stopped impersonating ${who}`);
266
+ }
267
+ /**
268
+ * Set the bytecode for a contract
269
+ * @param contract - The contract address
270
+ * @param bytecode - The bytecode to set
271
+ */ async etch(contract, bytecode) {
272
+ try {
273
+ await this.rpcCall('hardhat_setCode', [
274
+ contract.toString(),
275
+ bytecode
276
+ ]);
277
+ } catch (err) {
278
+ throw new Error(`Error setting bytecode for ${contract}: ${err}`);
279
+ }
280
+ this.logger.warn(`Set bytecode for ${contract} to ${bytecode}`);
281
+ }
282
+ /**
283
+ * Get the bytecode for a contract
284
+ * @param contract - The contract address
285
+ * @returns The bytecode for the contract
286
+ */ async getBytecode(contract) {
287
+ const res = await this.rpcCall('eth_getCode', [
288
+ contract.toString(),
289
+ 'latest'
290
+ ]);
291
+ return res;
292
+ }
293
+ /**
294
+ * Get the raw transaction object for a given transaction hash
295
+ * @param txHash - The transaction hash
296
+ * @returns The raw transaction
297
+ */ async getRawTransaction(txHash) {
298
+ const res = await this.rpcCall('debug_getRawTransaction', [
299
+ txHash
300
+ ]);
301
+ return res;
302
+ }
303
+ }
@@ -0,0 +1,14 @@
1
+ export * from './constants.js';
2
+ export * from './deploy_l1_contracts.js';
3
+ export * from './chain.js';
4
+ export * from './eth_cheat_codes.js';
5
+ export * from './l1_tx_utils.js';
6
+ export * from './l1_contract_addresses.js';
7
+ export * from './l1_reader.js';
8
+ export * from './utils.js';
9
+ export * from './config.js';
10
+ export * from './types.js';
11
+ export * from './contracts/index.js';
12
+ export * from './queries.js';
13
+ export * from './client.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
package/dest/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from './constants.js';
2
+ export * from './deploy_l1_contracts.js';
3
+ export * from './chain.js';
4
+ export * from './eth_cheat_codes.js';
5
+ export * from './l1_tx_utils.js';
6
+ export * from './l1_contract_addresses.js';
7
+ export * from './l1_reader.js';
8
+ export * from './utils.js';
9
+ export * from './config.js';
10
+ export * from './types.js';
11
+ export * from './contracts/index.js';
12
+ export * from './queries.js';
13
+ export * from './client.js';
@@ -0,0 +1,57 @@
1
+ import type { ConfigMappingsType } from '@aztec/foundation/config';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { z } from 'zod';
4
+ /**
5
+ * The names of the current L1 contract addresses.
6
+ * NOTE: When changing this list, make sure to update CLI & CI scripts accordingly.
7
+ * For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
8
+ */
9
+ export declare const L1ContractsNames: readonly ["rollupAddress", "registryAddress", "inboxAddress", "outboxAddress", "feeJuiceAddress", "feeJuicePortalAddress", "coinIssuerAddress", "rewardDistributorAddress", "governanceProposerAddress", "governanceAddress", "stakingAssetAddress"];
10
+ /** Provides the directory of current L1 contract addresses */
11
+ export type L1ContractAddresses = {
12
+ [K in (typeof L1ContractsNames)[number]]: EthAddress;
13
+ } & {
14
+ slashFactoryAddress?: EthAddress | undefined;
15
+ };
16
+ export declare const L1ContractAddressesSchema: z.ZodObject<{
17
+ rollupAddress: z.ZodType<EthAddress, any, string>;
18
+ registryAddress: z.ZodType<EthAddress, any, string>;
19
+ inboxAddress: z.ZodType<EthAddress, any, string>;
20
+ outboxAddress: z.ZodType<EthAddress, any, string>;
21
+ feeJuiceAddress: z.ZodType<EthAddress, any, string>;
22
+ stakingAssetAddress: z.ZodType<EthAddress, any, string>;
23
+ feeJuicePortalAddress: z.ZodType<EthAddress, any, string>;
24
+ coinIssuerAddress: z.ZodType<EthAddress, any, string>;
25
+ rewardDistributorAddress: z.ZodType<EthAddress, any, string>;
26
+ governanceProposerAddress: z.ZodType<EthAddress, any, string>;
27
+ governanceAddress: z.ZodType<EthAddress, any, string>;
28
+ slashFactoryAddress: z.ZodOptional<z.ZodType<EthAddress, any, string>>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ rollupAddress: EthAddress;
31
+ registryAddress: EthAddress;
32
+ inboxAddress: EthAddress;
33
+ outboxAddress: EthAddress;
34
+ feeJuiceAddress: EthAddress;
35
+ feeJuicePortalAddress: EthAddress;
36
+ coinIssuerAddress: EthAddress;
37
+ rewardDistributorAddress: EthAddress;
38
+ governanceProposerAddress: EthAddress;
39
+ governanceAddress: EthAddress;
40
+ stakingAssetAddress: EthAddress;
41
+ slashFactoryAddress?: EthAddress | undefined;
42
+ }, {
43
+ rollupAddress: string;
44
+ registryAddress: string;
45
+ inboxAddress: string;
46
+ outboxAddress: string;
47
+ feeJuiceAddress: string;
48
+ feeJuicePortalAddress: string;
49
+ coinIssuerAddress: string;
50
+ rewardDistributorAddress: string;
51
+ governanceProposerAddress: string;
52
+ governanceAddress: string;
53
+ stakingAssetAddress: string;
54
+ slashFactoryAddress?: string | undefined;
55
+ }>;
56
+ export declare const l1ContractAddressesMapping: ConfigMappingsType<L1ContractAddresses>;
57
+ //# sourceMappingURL=l1_contract_addresses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l1_contract_addresses.d.ts","sourceRoot":"","sources":["../src/l1_contract_addresses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAG3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,sPAYnB,CAAC;AAEX,8DAA8D;AAC9D,MAAM,MAAM,mBAAmB,GAAG;KAC/B,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU;CACrD,GAAG;IAAE,mBAAmB,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;CAAE,CAAC;AAErD,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAaE,CAAC;AAIzC,eAAO,MAAM,0BAA0B,EAAE,kBAAkB,CAAC,mBAAmB,CA6D9E,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { schemas } from '@aztec/foundation/schemas';
3
+ import { z } from 'zod';
4
+ /**
5
+ * The names of the current L1 contract addresses.
6
+ * NOTE: When changing this list, make sure to update CLI & CI scripts accordingly.
7
+ * For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
8
+ */ export const L1ContractsNames = [
9
+ 'rollupAddress',
10
+ 'registryAddress',
11
+ 'inboxAddress',
12
+ 'outboxAddress',
13
+ 'feeJuiceAddress',
14
+ 'feeJuicePortalAddress',
15
+ 'coinIssuerAddress',
16
+ 'rewardDistributorAddress',
17
+ 'governanceProposerAddress',
18
+ 'governanceAddress',
19
+ 'stakingAssetAddress'
20
+ ];
21
+ export const L1ContractAddressesSchema = z.object({
22
+ rollupAddress: schemas.EthAddress,
23
+ registryAddress: schemas.EthAddress,
24
+ inboxAddress: schemas.EthAddress,
25
+ outboxAddress: schemas.EthAddress,
26
+ feeJuiceAddress: schemas.EthAddress,
27
+ stakingAssetAddress: schemas.EthAddress,
28
+ feeJuicePortalAddress: schemas.EthAddress,
29
+ coinIssuerAddress: schemas.EthAddress,
30
+ rewardDistributorAddress: schemas.EthAddress,
31
+ governanceProposerAddress: schemas.EthAddress,
32
+ governanceAddress: schemas.EthAddress,
33
+ slashFactoryAddress: schemas.EthAddress.optional()
34
+ });
35
+ const parseEnv = (val)=>EthAddress.fromString(val);
36
+ export const l1ContractAddressesMapping = {
37
+ rollupAddress: {
38
+ env: 'ROLLUP_CONTRACT_ADDRESS',
39
+ description: 'The deployed L1 rollup contract address.',
40
+ parseEnv
41
+ },
42
+ registryAddress: {
43
+ env: 'REGISTRY_CONTRACT_ADDRESS',
44
+ description: 'The deployed L1 registry contract address.',
45
+ parseEnv
46
+ },
47
+ inboxAddress: {
48
+ env: 'INBOX_CONTRACT_ADDRESS',
49
+ description: 'The deployed L1 inbox contract address.',
50
+ parseEnv
51
+ },
52
+ outboxAddress: {
53
+ env: 'OUTBOX_CONTRACT_ADDRESS',
54
+ description: 'The deployed L1 outbox contract address.',
55
+ parseEnv
56
+ },
57
+ feeJuiceAddress: {
58
+ env: 'FEE_JUICE_CONTRACT_ADDRESS',
59
+ description: 'The deployed L1 Fee Juice contract address.',
60
+ parseEnv
61
+ },
62
+ stakingAssetAddress: {
63
+ env: 'STAKING_ASSET_CONTRACT_ADDRESS',
64
+ description: 'The deployed L1 staking asset contract address.',
65
+ parseEnv
66
+ },
67
+ feeJuicePortalAddress: {
68
+ env: 'FEE_JUICE_PORTAL_CONTRACT_ADDRESS',
69
+ description: 'The deployed L1 Fee Juice portal contract address.',
70
+ parseEnv
71
+ },
72
+ coinIssuerAddress: {
73
+ env: 'COIN_ISSUER_CONTRACT_ADDRESS',
74
+ description: 'The deployed L1 coinIssuer contract address',
75
+ parseEnv
76
+ },
77
+ rewardDistributorAddress: {
78
+ env: 'REWARD_DISTRIBUTOR_CONTRACT_ADDRESS',
79
+ description: 'The deployed L1 rewardDistributor contract address',
80
+ parseEnv
81
+ },
82
+ governanceProposerAddress: {
83
+ env: 'GOVERNANCE_PROPOSER_CONTRACT_ADDRESS',
84
+ description: 'The deployed L1 governanceProposer contract address',
85
+ parseEnv
86
+ },
87
+ governanceAddress: {
88
+ env: 'GOVERNANCE_CONTRACT_ADDRESS',
89
+ description: 'The deployed L1 governance contract address',
90
+ parseEnv
91
+ },
92
+ slashFactoryAddress: {
93
+ env: 'SLASH_FACTORY_CONTRACT_ADDRESS',
94
+ description: 'The deployed L1 slashFactory contract address',
95
+ parseEnv
96
+ }
97
+ };
@@ -0,0 +1,16 @@
1
+ import { type ConfigMappingsType } from '@aztec/foundation/config';
2
+ import { type L1ContractAddresses } from './l1_contract_addresses.js';
3
+ /** Configuration of the L1GlobalReader. */
4
+ export interface L1ReaderConfig {
5
+ /** The RPC Url of the ethereum host. */
6
+ l1RpcUrls: string[];
7
+ /** The chain ID of the ethereum host. */
8
+ l1ChainId: number;
9
+ /** The deployed l1 contract addresses */
10
+ l1Contracts: L1ContractAddresses;
11
+ /** The polling interval viem uses in ms */
12
+ viemPollingIntervalMS: number;
13
+ }
14
+ export declare const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig>;
15
+ export declare function getL1ReaderConfigFromEnv(): L1ReaderConfig;
16
+ //# sourceMappingURL=l1_reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l1_reader.d.ts","sourceRoot":"","sources":["../src/l1_reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAA6C,MAAM,0BAA0B,CAAC;AAE9G,OAAO,EAAE,KAAK,mBAAmB,EAA8B,MAAM,4BAA4B,CAAC;AAElG,2CAA2C;AAC3C,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,WAAW,EAAE,mBAAmB,CAAC;IACjC,2CAA2C;IAC3C,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,eAAO,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,cAAc,CAqBrE,CAAC;AAEF,wBAAgB,wBAAwB,IAAI,cAAc,CAEzD"}