@aztec/aztec.js 0.65.1 → 0.66.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 (65) hide show
  1. package/dest/account_manager/deploy_account_method.d.ts +1 -1
  2. package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
  3. package/dest/account_manager/deploy_account_method.js +3 -2
  4. package/dest/account_manager/index.d.ts +1 -1
  5. package/dest/account_manager/index.d.ts.map +1 -1
  6. package/dest/account_manager/index.js +1 -2
  7. package/dest/contract/base_contract_interaction.d.ts +12 -11
  8. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  9. package/dest/contract/base_contract_interaction.js +27 -13
  10. package/dest/contract/batch_call.d.ts.map +1 -1
  11. package/dest/contract/batch_call.js +11 -17
  12. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  13. package/dest/contract/contract_function_interaction.js +5 -12
  14. package/dest/contract/deploy_method.d.ts +2 -2
  15. package/dest/contract/deploy_method.d.ts.map +1 -1
  16. package/dest/contract/deploy_method.js +14 -18
  17. package/dest/contract/proven_tx.d.ts.map +1 -1
  18. package/dest/contract/proven_tx.js +3 -3
  19. package/dest/deployment/register_class.d.ts +1 -1
  20. package/dest/deployment/register_class.d.ts.map +1 -1
  21. package/dest/deployment/register_class.js +8 -3
  22. package/dest/entrypoint/default_entrypoint.d.ts.map +1 -1
  23. package/dest/entrypoint/default_entrypoint.js +4 -5
  24. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
  25. package/dest/entrypoint/default_multi_call_entrypoint.js +4 -5
  26. package/dest/entrypoint/entrypoint.d.ts +1 -1
  27. package/dest/entrypoint/entrypoint.d.ts.map +1 -1
  28. package/dest/entrypoint/payload.d.ts +12 -0
  29. package/dest/entrypoint/payload.d.ts.map +1 -1
  30. package/dest/entrypoint/payload.js +1 -1
  31. package/dest/index.d.ts +5 -5
  32. package/dest/index.d.ts.map +1 -1
  33. package/dest/index.js +5 -5
  34. package/dest/main.js +1 -1
  35. package/dest/main.js.LICENSE.txt +2 -0
  36. package/dest/utils/cheat_codes.d.ts +2 -125
  37. package/dest/utils/cheat_codes.d.ts.map +1 -1
  38. package/dest/utils/cheat_codes.js +9 -233
  39. package/dest/wallet/account_wallet.d.ts +1 -0
  40. package/dest/wallet/account_wallet.d.ts.map +1 -1
  41. package/dest/wallet/account_wallet.js +4 -1
  42. package/dest/wallet/base_wallet.d.ts +1 -0
  43. package/dest/wallet/base_wallet.d.ts.map +1 -1
  44. package/dest/wallet/base_wallet.js +1 -1
  45. package/dest/wallet/signerless_wallet.d.ts +1 -0
  46. package/dest/wallet/signerless_wallet.d.ts.map +1 -1
  47. package/dest/wallet/signerless_wallet.js +4 -1
  48. package/package.json +8 -8
  49. package/src/account_manager/deploy_account_method.ts +5 -2
  50. package/src/account_manager/index.ts +1 -2
  51. package/src/contract/base_contract_interaction.ts +37 -18
  52. package/src/contract/batch_call.ts +18 -29
  53. package/src/contract/contract_function_interaction.ts +4 -11
  54. package/src/contract/deploy_method.ts +20 -19
  55. package/src/contract/proven_tx.ts +0 -4
  56. package/src/deployment/register_class.ts +8 -1
  57. package/src/entrypoint/default_entrypoint.ts +3 -4
  58. package/src/entrypoint/default_multi_call_entrypoint.ts +3 -4
  59. package/src/entrypoint/entrypoint.ts +1 -1
  60. package/src/entrypoint/payload.ts +13 -0
  61. package/src/index.ts +6 -9
  62. package/src/utils/cheat_codes.ts +14 -251
  63. package/src/wallet/account_wallet.ts +4 -0
  64. package/src/wallet/base_wallet.ts +2 -0
  65. package/src/wallet/signerless_wallet.ts +4 -0
@@ -1,13 +1,10 @@
1
1
  import { type EpochProofClaim, type Note, type PXE } from '@aztec/circuit-types';
2
2
  import { type AztecAddress, EthAddress, Fr } from '@aztec/circuits.js';
3
3
  import { deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
4
- import { type L1ContractAddresses } from '@aztec/ethereum';
5
- import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
6
- import { keccak256 } from '@aztec/foundation/crypto';
4
+ import { EthCheatCodes, type L1ContractAddresses } from '@aztec/ethereum';
7
5
  import { createDebugLogger } from '@aztec/foundation/log';
8
6
  import { RollupAbi } from '@aztec/l1-artifacts';
9
7
 
10
- import fs from 'fs';
11
8
  import {
12
9
  type GetContractReturnType,
13
10
  type Hex,
@@ -49,248 +46,6 @@ export class CheatCodes {
49
46
  }
50
47
  }
51
48
 
52
- /**
53
- * A class that provides utility functions for interacting with ethereum (L1).
54
- */
55
- export class EthCheatCodes {
56
- constructor(
57
- /**
58
- * The RPC URL to use for interacting with the chain
59
- */
60
- public rpcUrl: string,
61
- /**
62
- * The logger to use for the eth cheatcodes
63
- */
64
- public logger = createDebugLogger('aztec:cheat_codes:eth'),
65
- ) {}
66
-
67
- async rpcCall(method: string, params: any[]) {
68
- const paramsString = JSON.stringify(params);
69
- const content = {
70
- body: `{"jsonrpc":"2.0", "method": "${method}", "params": ${paramsString}, "id": 1}`,
71
- method: 'POST',
72
- headers: { 'Content-Type': 'application/json' },
73
- };
74
- return await (await fetch(this.rpcUrl, content)).json();
75
- }
76
-
77
- /**
78
- * Get the auto mine status of the underlying chain
79
- * @returns True if automine is on, false otherwise
80
- */
81
- public async isAutoMining(): Promise<boolean> {
82
- try {
83
- const res = await this.rpcCall('anvil_getAutomine', []);
84
- return res.result;
85
- } catch (err) {
86
- this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
87
- }
88
- return false;
89
- }
90
-
91
- /**
92
- * Get the current blocknumber
93
- * @returns The current block number
94
- */
95
- public async blockNumber(): Promise<number> {
96
- const res = await this.rpcCall('eth_blockNumber', []);
97
- return parseInt(res.result, 16);
98
- }
99
-
100
- /**
101
- * Get the current chainId
102
- * @returns The current chainId
103
- */
104
- public async chainId(): Promise<number> {
105
- const res = await this.rpcCall('eth_chainId', []);
106
- return parseInt(res.result, 16);
107
- }
108
-
109
- /**
110
- * Get the current timestamp
111
- * @returns The current timestamp
112
- */
113
- public async timestamp(): Promise<number> {
114
- const res = await this.rpcCall('eth_getBlockByNumber', ['latest', true]);
115
- return parseInt(res.result.timestamp, 16);
116
- }
117
-
118
- /**
119
- * Advance the chain by a number of blocks
120
- * @param numberOfBlocks - The number of blocks to mine
121
- * @returns The current chainId
122
- */
123
- public async mine(numberOfBlocks = 1): Promise<void> {
124
- const res = await this.rpcCall('hardhat_mine', [numberOfBlocks]);
125
- if (res.error) {
126
- throw new Error(`Error mining: ${res.error.message}`);
127
- }
128
- this.logger.verbose(`Mined ${numberOfBlocks} L1 blocks`);
129
- }
130
-
131
- /**
132
- * Set the balance of an account
133
- * @param account - The account to set the balance for
134
- * @param balance - The balance to set
135
- */
136
- public async setBalance(account: EthAddress, balance: bigint): Promise<void> {
137
- const res = await this.rpcCall('anvil_setBalance', [account.toString(), toHex(balance)]);
138
- if (res.error) {
139
- throw new Error(`Error setting balance for ${account}: ${res.error.message}`);
140
- }
141
- this.logger.verbose(`Set balance for ${account} to ${balance}`);
142
- }
143
-
144
- /**
145
- * Set the interval between blocks (block time)
146
- * @param interval - The interval to use between blocks
147
- */
148
- public async setBlockInterval(interval: number): Promise<void> {
149
- const res = await this.rpcCall('anvil_setBlockTimestampInterval', [interval]);
150
- if (res.error) {
151
- throw new Error(`Error setting block interval: ${res.error.message}`);
152
- }
153
- this.logger.verbose(`Set L1 block interval to ${interval}`);
154
- }
155
-
156
- /**
157
- * Set the next block timestamp
158
- * @param timestamp - The timestamp to set the next block to
159
- */
160
- public async setNextBlockTimestamp(timestamp: number): Promise<void> {
161
- const res = await this.rpcCall('evm_setNextBlockTimestamp', [timestamp]);
162
- if (res.error) {
163
- throw new Error(`Error setting next block timestamp: ${res.error.message}`);
164
- }
165
- this.logger.verbose(`Set L1 next block timestamp to ${timestamp}`);
166
- }
167
-
168
- /**
169
- * Set the next block timestamp and mines the block
170
- * @param timestamp - The timestamp to set the next block to
171
- */
172
- public async warp(timestamp: number | bigint): Promise<void> {
173
- const res = await this.rpcCall('evm_setNextBlockTimestamp', [Number(timestamp)]);
174
- if (res.error) {
175
- throw new Error(`Error warping: ${res.error.message}`);
176
- }
177
- await this.mine();
178
- this.logger.verbose(`Warped L1 timestamp to ${timestamp}`);
179
- }
180
-
181
- /**
182
- * Dumps the current chain state to a file.
183
- * @param fileName - The file name to dump state into
184
- */
185
- public async dumpChainState(fileName: string): Promise<void> {
186
- const res = await this.rpcCall('hardhat_dumpState', []);
187
- if (res.error) {
188
- throw new Error(`Error dumping state: ${res.error.message}`);
189
- }
190
- const jsonContent = JSON.stringify(res.result);
191
- fs.writeFileSync(`${fileName}.json`, jsonContent, 'utf8');
192
- this.logger.verbose(`Dumped state to ${fileName}`);
193
- }
194
-
195
- /**
196
- * Loads the chain state from a file.
197
- * @param fileName - The file name to load state from
198
- */
199
- public async loadChainState(fileName: string): Promise<void> {
200
- const data = JSON.parse(fs.readFileSync(`${fileName}.json`, 'utf8'));
201
- const res = await this.rpcCall('hardhat_loadState', [data]);
202
- if (res.error) {
203
- throw new Error(`Error loading state: ${res.error.message}`);
204
- }
205
- this.logger.verbose(`Loaded state from ${fileName}`);
206
- }
207
-
208
- /**
209
- * Load the value at a storage slot of a contract address on eth
210
- * @param contract - The contract address
211
- * @param slot - The storage slot
212
- * @returns - The value at the storage slot
213
- */
214
- public async load(contract: EthAddress, slot: bigint): Promise<bigint> {
215
- const res = await this.rpcCall('eth_getStorageAt', [contract.toString(), toHex(slot), 'latest']);
216
- return BigInt(res.result);
217
- }
218
-
219
- /**
220
- * Set the value at a storage slot of a contract address on eth
221
- * @param contract - The contract address
222
- * @param slot - The storage slot
223
- * @param value - The value to set the storage slot to
224
- */
225
- public async store(contract: EthAddress, slot: bigint, value: bigint): Promise<void> {
226
- // for the rpc call, we need to change value to be a 32 byte hex string.
227
- const res = await this.rpcCall('hardhat_setStorageAt', [contract.toString(), toHex(slot), toHex(value, true)]);
228
- if (res.error) {
229
- throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${res.error.message}`);
230
- }
231
- this.logger.verbose(`Set L1 storage for contract ${contract} at ${slot} to ${value}`);
232
- }
233
-
234
- /**
235
- * Computes the slot value for a given map and key.
236
- * @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
237
- * @param key - The key to lookup in the map
238
- * @returns The storage slot of the value in the map
239
- */
240
- public keccak256(baseSlot: bigint, key: bigint): bigint {
241
- // abi encode (removing the 0x) - concat key and baseSlot (both padded to 32 bytes)
242
- const abiEncoded = toHex(key, true).substring(2) + toHex(baseSlot, true).substring(2);
243
- return toBigIntBE(keccak256(Buffer.from(abiEncoded, 'hex')));
244
- }
245
-
246
- /**
247
- * Send transactions impersonating an externally owned account or contract.
248
- * @param who - The address to impersonate
249
- */
250
- public async startImpersonating(who: EthAddress | Hex): Promise<void> {
251
- const res = await this.rpcCall('hardhat_impersonateAccount', [who.toString()]);
252
- if (res.error) {
253
- throw new Error(`Error impersonating ${who}: ${res.error.message}`);
254
- }
255
- this.logger.verbose(`Impersonating ${who}`);
256
- }
257
-
258
- /**
259
- * Stop impersonating an account that you are currently impersonating.
260
- * @param who - The address to stop impersonating
261
- */
262
- public async stopImpersonating(who: EthAddress | Hex): Promise<void> {
263
- const res = await this.rpcCall('hardhat_stopImpersonatingAccount', [who.toString()]);
264
- if (res.error) {
265
- throw new Error(`Error when stopping the impersonation of ${who}: ${res.error.message}`);
266
- }
267
- this.logger.verbose(`Stopped impersonating ${who}`);
268
- }
269
-
270
- /**
271
- * Set the bytecode for a contract
272
- * @param contract - The contract address
273
- * @param bytecode - The bytecode to set
274
- */
275
- public async etch(contract: EthAddress, bytecode: `0x${string}`): Promise<void> {
276
- const res = await this.rpcCall('hardhat_setCode', [contract.toString(), bytecode]);
277
- if (res.error) {
278
- throw new Error(`Error setting bytecode for ${contract}: ${res.error.message}`);
279
- }
280
- this.logger.verbose(`Set bytecode for ${contract} to ${bytecode}`);
281
- }
282
-
283
- /**
284
- * Get the bytecode for a contract
285
- * @param contract - The contract address
286
- * @returns The bytecode for the contract
287
- */
288
- public async getBytecode(contract: EthAddress): Promise<`0x${string}`> {
289
- const res = await this.rpcCall('eth_getCode', [contract.toString(), 'latest']);
290
- return res.result;
291
- }
292
- }
293
-
294
49
  /** Cheat codes for the L1 rollup contract. */
295
50
  export class RollupCheatCodes {
296
51
  private client: WalletClient & PublicClient;
@@ -327,8 +82,11 @@ export class RollupCheatCodes {
327
82
  /** The pending chain tip */ pending: bigint;
328
83
  /** The proven chain tip */ proven: bigint;
329
84
  }> {
330
- const [pending, proven] = await this.rollup.read.tips();
331
- return { pending, proven };
85
+ const res = await this.rollup.read.getTips();
86
+ return {
87
+ pending: res.pendingBlockNumber,
88
+ proven: res.provenBlockNumber,
89
+ };
332
90
  }
333
91
 
334
92
  /** Fetches the epoch and slot duration config from the rollup contract */
@@ -370,8 +128,13 @@ export class RollupCheatCodes {
370
128
  /** Returns the current proof claim (if any) */
371
129
  public async getProofClaim(): Promise<EpochProofClaim | undefined> {
372
130
  // REFACTOR: This code is duplicated from l1-publisher
373
- const [epochToProve, basisPointFee, bondAmount, bondProviderHex, proposerClaimantHex] =
374
- await this.rollup.read.proofClaim();
131
+ const {
132
+ epochToProve,
133
+ basisPointFee,
134
+ bondAmount,
135
+ bondProvider: bondProviderHex,
136
+ proposerClaimant: proposerClaimantHex,
137
+ } = await this.rollup.read.getProofClaim();
375
138
 
376
139
  const bondProvider = EthAddress.fromString(bondProviderHex);
377
140
  const proposerClaimant = EthAddress.fromString(proposerClaimantHex);
@@ -396,7 +159,7 @@ export class RollupCheatCodes {
396
159
  public async markAsProven(maybeBlockNumber?: number | bigint) {
397
160
  const blockNumber = maybeBlockNumber
398
161
  ? BigInt(maybeBlockNumber)
399
- : await this.rollup.read.tips().then(([pending]) => pending);
162
+ : await this.rollup.read.getTips().then(({ pendingBlockNumber }) => pendingBlockNumber);
400
163
 
401
164
  await this.asOwner(async account => {
402
165
  await this.rollup.write.setAssumeProvenThroughBlockNumber([blockNumber], { account, chain: this.client.chain });
@@ -34,6 +34,10 @@ export class AccountWallet extends BaseWallet {
34
34
  return this.account.getVersion();
35
35
  }
36
36
 
37
+ override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
38
+ return this.pxe.isL1ToL2MessageSynced(l1ToL2Message);
39
+ }
40
+
37
41
  /**
38
42
  * Computes an authentication witness from either a message hash or an intent.
39
43
  *
@@ -44,6 +44,8 @@ import { type IntentAction, type IntentInnerHash } from '../utils/authwit.js';
44
44
  export abstract class BaseWallet implements Wallet {
45
45
  constructor(protected readonly pxe: PXE, private scopes?: AztecAddress[]) {}
46
46
 
47
+ abstract isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean>;
48
+
47
49
  abstract getCompleteAddress(): CompleteAddress;
48
50
 
49
51
  abstract getChainId(): Fr;
@@ -42,4 +42,8 @@ export class SignerlessWallet extends BaseWallet {
42
42
  createAuthWit(_intent: Fr | Buffer | IntentInnerHash | IntentAction): Promise<AuthWitness> {
43
43
  throw new Error('SignerlessWallet: Method createAuthWit not implemented.');
44
44
  }
45
+
46
+ override isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
47
+ return this.pxe.isL1ToL2MessageSynced(l1ToL2Message);
48
+ }
45
49
  }