@aztec/aztec.js 0.32.1 → 0.34.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 (48) hide show
  1. package/README.md +2 -2
  2. package/dest/contract/base_contract_interaction.d.ts +2 -2
  3. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  4. package/dest/contract/base_contract_interaction.js +5 -5
  5. package/dest/contract/checker.js +2 -2
  6. package/dest/contract/contract_base.d.ts +41 -1
  7. package/dest/contract/contract_base.d.ts.map +1 -1
  8. package/dest/contract/contract_base.js +1 -1
  9. package/dest/contract/contract_function_interaction.d.ts +18 -9
  10. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  11. package/dest/contract/contract_function_interaction.js +41 -11
  12. package/dest/contract/deploy_method.d.ts +3 -3
  13. package/dest/contract/deploy_method.d.ts.map +1 -1
  14. package/dest/contract/deploy_method.js +10 -8
  15. package/dest/contract/deploy_sent_tx.d.ts +1 -0
  16. package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
  17. package/dest/contract/deploy_sent_tx.js +4 -1
  18. package/dest/contract/index.d.ts +3 -3
  19. package/dest/contract/index.js +3 -3
  20. package/dest/contract/sent_tx.js +5 -5
  21. package/dest/index.d.ts +1 -1
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -1
  24. package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
  25. package/dest/rpc_clients/pxe_client.js +3 -3
  26. package/dest/utils/cheat_codes.d.ts +4 -4
  27. package/dest/utils/cheat_codes.d.ts.map +1 -1
  28. package/dest/utils/cheat_codes.js +9 -9
  29. package/dest/utils/pxe.js +3 -3
  30. package/dest/wallet/account_wallet.js +2 -2
  31. package/dest/wallet/base_wallet.d.ts +3 -2
  32. package/dest/wallet/base_wallet.d.ts.map +1 -1
  33. package/dest/wallet/base_wallet.js +6 -3
  34. package/package.json +17 -11
  35. package/src/contract/base_contract_interaction.ts +4 -4
  36. package/src/contract/checker.ts +4 -4
  37. package/src/contract/contract_base.ts +43 -1
  38. package/src/contract/contract_function_interaction.ts +45 -14
  39. package/src/contract/deploy_method.ts +11 -7
  40. package/src/contract/deploy_sent_tx.ts +4 -0
  41. package/src/contract/index.ts +3 -3
  42. package/src/contract/sent_tx.ts +4 -4
  43. package/src/index.ts +2 -0
  44. package/src/rpc_clients/pxe_client.ts +2 -1
  45. package/src/utils/cheat_codes.ts +8 -8
  46. package/src/utils/pxe.ts +2 -2
  47. package/src/wallet/account_wallet.ts +1 -1
  48. package/src/wallet/base_wallet.ts +6 -2
@@ -1,5 +1,6 @@
1
1
  import { type PXE, type TxHash, type TxReceipt } from '@aztec/circuit-types';
2
2
  import { type AztecAddress } from '@aztec/circuits.js';
3
+ import { createDebugLogger } from '@aztec/foundation/log';
3
4
  import { type FieldsOf } from '@aztec/foundation/types';
4
5
  import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
5
6
 
@@ -24,6 +25,8 @@ export type DeployTxReceipt<TContract extends ContractBase = Contract> = FieldsO
24
25
  * A contract deployment transaction sent to the network, extending SentTx with methods to create a contract instance.
25
26
  */
26
27
  export class DeploySentTx<TContract extends Contract = Contract> extends SentTx {
28
+ private log = createDebugLogger('aztec:js:deploy_sent_tx');
29
+
27
30
  constructor(
28
31
  wallet: PXE | Wallet,
29
32
  txHashPromise: Promise<TxHash>,
@@ -41,6 +44,7 @@ export class DeploySentTx<TContract extends Contract = Contract> extends SentTx
41
44
  */
42
45
  public async deployed(opts?: DeployedWaitOpts): Promise<TContract> {
43
46
  const receipt = await this.wait(opts);
47
+ this.log.info(`Contract ${this.instance.address.toString()} successfully deployed.`);
44
48
  return receipt.contract;
45
49
  }
46
50
 
@@ -6,8 +6,8 @@
6
6
  *
7
7
  * The {@link Contract} class is the main class in this module, and provides static methods for deploying
8
8
  * a contract or interacting with an already deployed one. The `methods` property of the contract instance
9
- * provides access to private, public, and view methods, that can be invoked in a transaction via `send()`,
10
- * or can be queried via `view()`.
9
+ * provides access to private, public, and simulate methods, that can be invoked in a transaction via `send()`,
10
+ * or can be queried via `simulate()`.
11
11
  *
12
12
  * ```ts
13
13
  * const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send().deployed();
@@ -17,7 +17,7 @@
17
17
  * ```ts
18
18
  * const contract = await Contract.at(address, MyContractArtifact, wallet);
19
19
  * await contract.methods.mint(1000, owner).send().wait();
20
- * console.log(`Total supply is now ${await contract.methods.totalSupply().view()}`);
20
+ * console.log(`Total supply is now ${await contract.methods.totalSupply().simulate()}`);
21
21
  * ```
22
22
  *
23
23
  * The result of calling a method in a contract instance, such as `contract.methods.mint(1000, owner)`
@@ -82,10 +82,10 @@ export class SentTx {
82
82
  const tx = (await this.pxe.getTxEffect(txHash))!;
83
83
  const visibleNotes = await this.pxe.getNotes({ txHash });
84
84
  receipt.debugInfo = {
85
- noteHashes: tx.noteHashes.filter(n => !n.isZero()),
86
- nullifiers: tx.nullifiers.filter(n => !n.isZero()),
87
- publicDataWrites: tx.publicDataWrites.filter(p => !p.isEmpty()),
88
- l2ToL1Msgs: tx.l2ToL1Msgs.filter(l => !l.isZero()),
85
+ noteHashes: tx.noteHashes,
86
+ nullifiers: tx.nullifiers,
87
+ publicDataWrites: tx.publicDataWrites,
88
+ l2ToL1Msgs: tx.l2ToL1Msgs,
89
89
  visibleNotes,
90
90
  };
91
91
  }
package/src/index.ts CHANGED
@@ -25,6 +25,8 @@ export {
25
25
  Contract,
26
26
  ContractBase,
27
27
  ContractMethod,
28
+ ContractStorageLayout,
29
+ ContractNotes,
28
30
  SentTx,
29
31
  BatchCall,
30
32
  DeployMethod,
@@ -8,6 +8,7 @@ import {
8
8
  Note,
9
9
  NullifierMembershipWitness,
10
10
  type PXE,
11
+ SimulatedTx,
11
12
  Tx,
12
13
  TxEffect,
13
14
  TxExecutionRequest,
@@ -53,7 +54,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)
53
54
  TxExecutionRequest,
54
55
  TxHash,
55
56
  },
56
- { Tx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness },
57
+ { Tx, SimulatedTx, TxReceipt, EncryptedL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness },
57
58
  false,
58
59
  'pxe',
59
60
  fetch,
@@ -90,7 +90,7 @@ export class EthCheatCodes {
90
90
  if (res.error) {
91
91
  throw new Error(`Error mining: ${res.error.message}`);
92
92
  }
93
- this.logger(`Mined ${numberOfBlocks} blocks`);
93
+ this.logger.info(`Mined ${numberOfBlocks} blocks`);
94
94
  }
95
95
 
96
96
  /**
@@ -102,7 +102,7 @@ export class EthCheatCodes {
102
102
  if (res.error) {
103
103
  throw new Error(`Error setting next block timestamp: ${res.error.message}`);
104
104
  }
105
- this.logger(`Set next block timestamp to ${timestamp}`);
105
+ this.logger.info(`Set next block timestamp to ${timestamp}`);
106
106
  }
107
107
 
108
108
  /**
@@ -116,7 +116,7 @@ export class EthCheatCodes {
116
116
  }
117
117
  const jsonContent = JSON.stringify(res.result);
118
118
  fs.writeFileSync(`${fileName}.json`, jsonContent, 'utf8');
119
- this.logger(`Dumped state to ${fileName}`);
119
+ this.logger.info(`Dumped state to ${fileName}`);
120
120
  }
121
121
 
122
122
  /**
@@ -129,7 +129,7 @@ export class EthCheatCodes {
129
129
  if (res.error) {
130
130
  throw new Error(`Error loading state: ${res.error.message}`);
131
131
  }
132
- this.logger(`Loaded state from ${fileName}`);
132
+ this.logger.info(`Loaded state from ${fileName}`);
133
133
  }
134
134
 
135
135
  /**
@@ -155,7 +155,7 @@ export class EthCheatCodes {
155
155
  if (res.error) {
156
156
  throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${res.error.message}`);
157
157
  }
158
- this.logger(`Set storage for contract ${contract} at ${slot} to ${value}`);
158
+ this.logger.info(`Set storage for contract ${contract} at ${slot} to ${value}`);
159
159
  }
160
160
 
161
161
  /**
@@ -179,7 +179,7 @@ export class EthCheatCodes {
179
179
  if (res.error) {
180
180
  throw new Error(`Error impersonating ${who}: ${res.error.message}`);
181
181
  }
182
- this.logger(`Impersonating ${who}`);
182
+ this.logger.info(`Impersonating ${who}`);
183
183
  }
184
184
 
185
185
  /**
@@ -191,7 +191,7 @@ export class EthCheatCodes {
191
191
  if (res.error) {
192
192
  throw new Error(`Error when stopping the impersonation of ${who}: ${res.error.message}`);
193
193
  }
194
- this.logger(`Stopped impersonating ${who}`);
194
+ this.logger.info(`Stopped impersonating ${who}`);
195
195
  }
196
196
 
197
197
  /**
@@ -204,7 +204,7 @@ export class EthCheatCodes {
204
204
  if (res.error) {
205
205
  throw new Error(`Error setting bytecode for ${contract}: ${res.error.message}`);
206
206
  }
207
- this.logger(`Set bytecode for ${contract} to ${bytecode}`);
207
+ this.logger.info(`Set bytecode for ${contract} to ${bytecode}`);
208
208
  }
209
209
 
210
210
  /**
package/src/utils/pxe.ts CHANGED
@@ -5,11 +5,11 @@ import { retryUntil } from '@aztec/foundation/retry';
5
5
  export const waitForPXE = async (pxe: PXE, logger?: DebugLogger) => {
6
6
  await retryUntil(async () => {
7
7
  try {
8
- logger?.('Attempting to contact PXE...');
8
+ logger?.debug('Attempting to contact PXE...');
9
9
  await pxe.getNodeInfo();
10
10
  return true;
11
11
  } catch (error) {
12
- logger?.('Failed to contact PXE!');
12
+ logger?.verbose('Failed to contact PXE');
13
13
  }
14
14
  return undefined;
15
15
  }, 'RPC Get Node Info');
@@ -161,7 +161,7 @@ export class AccountWallet extends BaseWallet {
161
161
  messageHash,
162
162
  ]);
163
163
 
164
- const [isValidInPrivate, isValidInPublic] = await interaction.view();
164
+ const [isValidInPrivate, isValidInPublic] = (await interaction.simulate()) as [boolean, boolean];
165
165
  return { isValidInPrivate, isValidInPublic };
166
166
  }
167
167
 
@@ -7,6 +7,7 @@ import {
7
7
  type LogFilter,
8
8
  type NoteFilter,
9
9
  type PXE,
10
+ type SimulatedTx,
10
11
  type SyncStatus,
11
12
  type Tx,
12
13
  type TxEffect,
@@ -101,8 +102,11 @@ export abstract class BaseWallet implements Wallet {
101
102
  getContracts(): Promise<AztecAddress[]> {
102
103
  return this.pxe.getContracts();
103
104
  }
104
- simulateTx(txRequest: TxExecutionRequest, simulatePublic: boolean): Promise<Tx> {
105
- return this.pxe.simulateTx(txRequest, simulatePublic);
105
+ proveTx(txRequest: TxExecutionRequest, simulatePublic: boolean): Promise<Tx> {
106
+ return this.pxe.proveTx(txRequest, simulatePublic);
107
+ }
108
+ simulateTx(txRequest: TxExecutionRequest, simulatePublic: boolean, msgSender: AztecAddress): Promise<SimulatedTx> {
109
+ return this.pxe.simulateTx(txRequest, simulatePublic, msgSender);
106
110
  }
107
111
  sendTx(tx: Tx): Promise<TxHash> {
108
112
  return this.pxe.sendTx(tx);