@aztec/aztec.js 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8

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 (139) hide show
  1. package/dest/api/abi.d.ts +2 -2
  2. package/dest/api/abi.d.ts.map +1 -1
  3. package/dest/api/block.d.ts +2 -2
  4. package/dest/api/block.d.ts.map +1 -1
  5. package/dest/api/block.js +1 -1
  6. package/dest/api/contract.d.ts +18 -12
  7. package/dest/api/contract.d.ts.map +1 -1
  8. package/dest/api/contract.js +16 -10
  9. package/dest/api/deployment.d.ts +1 -2
  10. package/dest/api/deployment.d.ts.map +1 -1
  11. package/dest/api/deployment.js +0 -1
  12. package/dest/api/events.d.ts +10 -6
  13. package/dest/api/events.d.ts.map +1 -1
  14. package/dest/api/events.js +30 -20
  15. package/dest/api/fields.d.ts +2 -1
  16. package/dest/api/fields.d.ts.map +1 -1
  17. package/dest/api/fields.js +1 -0
  18. package/dest/api/keys.d.ts +1 -1
  19. package/dest/api/keys.js +1 -1
  20. package/dest/api/node.d.ts +8 -4
  21. package/dest/api/node.d.ts.map +1 -1
  22. package/dest/api/node.js +7 -3
  23. package/dest/api/tx.d.ts +2 -2
  24. package/dest/api/tx.d.ts.map +1 -1
  25. package/dest/api/tx.js +1 -1
  26. package/dest/api/wallet.d.ts +3 -2
  27. package/dest/api/wallet.d.ts.map +1 -1
  28. package/dest/api/wallet.js +2 -1
  29. package/dest/contract/base_contract_interaction.d.ts +8 -10
  30. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  31. package/dest/contract/base_contract_interaction.js +5 -17
  32. package/dest/contract/batch_call.d.ts +3 -3
  33. package/dest/contract/batch_call.d.ts.map +1 -1
  34. package/dest/contract/batch_call.js +17 -8
  35. package/dest/contract/contract_function_interaction.d.ts +7 -16
  36. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  37. package/dest/contract/contract_function_interaction.js +107 -18
  38. package/dest/contract/deploy_method.d.ts +91 -19
  39. package/dest/contract/deploy_method.d.ts.map +1 -1
  40. package/dest/contract/deploy_method.js +68 -30
  41. package/dest/contract/get_gas_limits.js +3 -3
  42. package/dest/contract/interaction_options.d.ts +99 -21
  43. package/dest/contract/interaction_options.d.ts.map +1 -1
  44. package/dest/contract/interaction_options.js +41 -1
  45. package/dest/contract/protocol_contracts/auth-registry.d.ts +3 -3
  46. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
  47. package/dest/contract/protocol_contracts/auth-registry.js +49 -20
  48. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -22
  49. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
  50. package/dest/contract/protocol_contracts/contract-class-registry.js +13 -671
  51. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
  52. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
  53. package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -486
  54. package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
  55. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
  56. package/dest/contract/protocol_contracts/fee-juice.js +7 -413
  57. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +3 -3
  58. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
  59. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +40 -15
  60. package/dest/contract/protocol_contracts/public-checks.d.ts +3 -3
  61. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
  62. package/dest/contract/protocol_contracts/public-checks.js +40 -23
  63. package/dest/contract/wait_for_proven.js +1 -1
  64. package/dest/contract/wait_opts.d.ts +16 -0
  65. package/dest/contract/wait_opts.d.ts.map +1 -0
  66. package/dest/contract/wait_opts.js +5 -0
  67. package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
  68. package/dest/fee/private_fee_payment_method.js +10 -10
  69. package/dest/fee/public_fee_payment_method.js +10 -10
  70. package/dest/fee/sponsored_fee_payment.js +3 -3
  71. package/dest/utils/abi_types.d.ts +6 -1
  72. package/dest/utils/abi_types.d.ts.map +1 -1
  73. package/dest/utils/abi_types.js +1 -1
  74. package/dest/utils/authwit.d.ts +6 -6
  75. package/dest/utils/authwit.d.ts.map +1 -1
  76. package/dest/utils/authwit.js +12 -12
  77. package/dest/utils/node.d.ts +12 -1
  78. package/dest/utils/node.d.ts.map +1 -1
  79. package/dest/utils/node.js +46 -0
  80. package/dest/wallet/capabilities.d.ts +452 -0
  81. package/dest/wallet/capabilities.d.ts.map +1 -0
  82. package/dest/wallet/capabilities.js +3 -0
  83. package/dest/wallet/deploy_account_method.d.ts +31 -6
  84. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  85. package/dest/wallet/deploy_account_method.js +26 -0
  86. package/dest/wallet/index.d.ts +2 -1
  87. package/dest/wallet/index.d.ts.map +1 -1
  88. package/dest/wallet/index.js +1 -0
  89. package/dest/wallet/wallet.d.ts +1639 -93
  90. package/dest/wallet/wallet.d.ts.map +1 -1
  91. package/dest/wallet/wallet.js +186 -27
  92. package/package.json +20 -11
  93. package/src/api/abi.ts +1 -0
  94. package/src/api/block.ts +1 -1
  95. package/src/api/contract.ts +31 -9
  96. package/src/api/deployment.ts +0 -1
  97. package/src/api/events.ts +35 -27
  98. package/src/api/fields.ts +1 -0
  99. package/src/api/keys.ts +2 -2
  100. package/src/api/node.ts +7 -3
  101. package/src/api/tx.ts +2 -0
  102. package/src/api/wallet.ts +48 -1
  103. package/src/contract/base_contract_interaction.ts +28 -15
  104. package/src/contract/batch_call.ts +17 -14
  105. package/src/contract/contract_function_interaction.ts +114 -26
  106. package/src/contract/deploy_method.ts +172 -35
  107. package/src/contract/get_gas_limits.ts +3 -3
  108. package/src/contract/interaction_options.ts +141 -23
  109. package/src/contract/protocol_contracts/auth-registry.ts +13 -14
  110. package/src/contract/protocol_contracts/contract-class-registry.ts +4 -347
  111. package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -234
  112. package/src/contract/protocol_contracts/fee-juice.ts +2 -202
  113. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +11 -13
  114. package/src/contract/protocol_contracts/public-checks.ts +11 -15
  115. package/src/contract/wait_for_proven.ts +1 -1
  116. package/src/contract/wait_opts.ts +21 -0
  117. package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
  118. package/src/fee/private_fee_payment_method.ts +7 -7
  119. package/src/fee/public_fee_payment_method.ts +8 -8
  120. package/src/fee/sponsored_fee_payment.ts +3 -3
  121. package/src/utils/abi_types.ts +7 -0
  122. package/src/utils/authwit.ts +31 -21
  123. package/src/utils/node.ts +62 -0
  124. package/src/wallet/capabilities.ts +500 -0
  125. package/src/wallet/deploy_account_method.ts +56 -4
  126. package/src/wallet/index.ts +1 -0
  127. package/src/wallet/wallet.ts +257 -50
  128. package/dest/contract/deploy_sent_tx.d.ts +0 -48
  129. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  130. package/dest/contract/deploy_sent_tx.js +0 -46
  131. package/dest/contract/sent_tx.d.ts +0 -50
  132. package/dest/contract/sent_tx.d.ts.map +0 -1
  133. package/dest/contract/sent_tx.js +0 -90
  134. package/dest/deployment/broadcast_function.d.ts +0 -24
  135. package/dest/deployment/broadcast_function.d.ts.map +0 -1
  136. package/dest/deployment/broadcast_function.js +0 -74
  137. package/src/contract/deploy_sent_tx.ts +0 -75
  138. package/src/contract/sent_tx.ts +0 -129
  139. package/src/deployment/broadcast_function.ts +0 -148
@@ -9,27 +9,50 @@ import {
9
9
  getContractInstanceFromInstantiationParams,
10
10
  } from '@aztec/stdlib/contract';
11
11
  import type { PublicKeys } from '@aztec/stdlib/keys';
12
- import { type Capsule, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
12
+ import { type Capsule, HashedValues, type TxProfileResult, type TxReceipt } from '@aztec/stdlib/tx';
13
13
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
14
14
 
15
15
  import { publishContractClass } from '../deployment/publish_class.js';
16
16
  import { publishInstance } from '../deployment/publish_instance.js';
17
- import type { Wallet } from '../wallet/wallet.js';
17
+ import type { ProfileOptions, SendOptions, SimulateOptions, Wallet } from '../wallet/wallet.js';
18
18
  import { BaseContractInteraction } from './base_contract_interaction.js';
19
19
  import type { ContractBase } from './contract_base.js';
20
20
  import { ContractFunctionInteraction } from './contract_function_interaction.js';
21
- import { DeploySentTx } from './deploy_sent_tx.js';
22
21
  import { getGasLimits } from './get_gas_limits.js';
23
22
  import {
23
+ NO_WAIT,
24
+ type NoWait,
25
+ type OffchainOutput,
24
26
  type ProfileInteractionOptions,
25
27
  type RequestInteractionOptions,
26
- type SendInteractionOptions,
28
+ type SendInteractionOptionsWithoutWait,
27
29
  type SimulationInteractionFeeOptions,
28
- type SimulationReturn,
30
+ type SimulationResult,
31
+ type TxSendResultImmediate,
32
+ type TxSendResultMined,
33
+ extractOffchainOutput,
29
34
  toProfileOptions,
30
35
  toSendOptions,
31
36
  toSimulateOptions,
32
37
  } from './interaction_options.js';
38
+ import type { WaitOpts } from './wait_opts.js';
39
+
40
+ /**
41
+ * Wait options specific to deployment transactions.
42
+ * Extends WaitOpts with a flag to return the full receipt instead of just the contract.
43
+ */
44
+ export type DeployWaitOptions = WaitOpts & {
45
+ /** If true, return the full DeployTxReceipt instead of just the contract. Defaults to false. */
46
+ returnReceipt?: boolean;
47
+ };
48
+
49
+ /**
50
+ * Type for wait options in deployment interactions.
51
+ * - NO_WAIT symbol: Don't wait, return TxHash immediately
52
+ * - DeployWaitOptions: Wait with custom options
53
+ * - undefined: Wait with default options
54
+ */
55
+ export type DeployInteractionWaitOptions = NoWait | DeployWaitOptions | undefined;
33
56
 
34
57
  /**
35
58
  * Options for deploying a contract on the Aztec network.
@@ -55,21 +78,34 @@ export type RequestDeployOptions = RequestInteractionOptions & {
55
78
  };
56
79
 
57
80
  /**
58
- * Extends the deployment options with the required parameters to send the transaction
81
+ * Base deployment options without wait parameter.
59
82
  */
60
- export type DeployOptions = Omit<RequestDeployOptions, 'deployer'> & {
83
+ export type DeployOptionsWithoutWait = Omit<RequestDeployOptions, 'deployer'> & {
61
84
  /**
62
85
  * Set to true to *not* include the sender in the address computation. This option
63
86
  * is mutually exclusive with "deployer"
64
87
  */
65
88
  universalDeploy?: boolean;
66
- } & Pick<SendInteractionOptions, 'from' | 'fee'>;
89
+ } & Pick<SendInteractionOptionsWithoutWait, 'from' | 'fee' | 'additionalScopes'>;
90
+
91
+ /**
92
+ * Extends the deployment options with the required parameters to send the transaction.
93
+ */
94
+ export type DeployOptions<W extends DeployInteractionWaitOptions = undefined> = DeployOptionsWithoutWait & {
95
+ /**
96
+ * Options for waiting for the transaction to be mined.
97
+ * - undefined (default): wait with default options and return the contract instance
98
+ * - DeployWaitOptions: wait with custom options and return contract or receipt based on returnReceipt flag
99
+ * - NO_WAIT: return TxHash immediately without waiting
100
+ */
101
+ wait?: W;
102
+ };
67
103
 
68
104
  /**
69
105
  * Options for simulating the deployment of a contract
70
106
  * Allows skipping certain validations and computing gas estimations
71
107
  */
72
- export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
108
+ export type SimulateDeployOptions = Omit<DeployOptionsWithoutWait, 'fee'> & {
73
109
  /** The fee options for the transaction. */
74
110
  fee?: SimulationInteractionFeeOptions;
75
111
  /** Simulate without checking for the validity of the resulting transaction,
@@ -83,6 +119,41 @@ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
83
119
  includeMetadata?: boolean;
84
120
  };
85
121
 
122
+ /** Receipt for a deployment transaction with the deployed contract instance. */
123
+ export type DeployTxReceipt<TContract extends ContractBase = ContractBase> = TxReceipt & {
124
+ /** Type-safe wrapper around the deployed contract instance, linked to the deployment wallet */
125
+ contract: TContract;
126
+ /** The deployed contract instance with address and metadata. */
127
+ instance: ContractInstanceWithAddress;
128
+ };
129
+
130
+ /** Wait options that request a full receipt instead of just the contract instance. */
131
+ type WaitWithReturnReceipt = {
132
+ /** Request the full receipt instead of just the contract instance. */
133
+ returnReceipt: true;
134
+ };
135
+
136
+ /**
137
+ * Represents the result type of deploying a contract.
138
+ * - If wait is NO_WAIT, returns TxHash immediately.
139
+ * - If wait has returnReceipt: true, returns DeployTxReceipt after waiting.
140
+ * - Otherwise (undefined or DeployWaitOptions without returnReceipt), returns TContract after waiting.
141
+ */
142
+ /** Result of deploying a contract when waiting for mining (default case). */
143
+ export type DeployResultMined<TContract extends ContractBase> = {
144
+ /** The deployed contract instance. */
145
+ contract: TContract;
146
+ /** The deploy transaction receipt. */
147
+ receipt: DeployTxReceipt<TContract>;
148
+ } & OffchainOutput;
149
+
150
+ /** Conditional return type for deploy based on wait options. */
151
+ export type DeployReturn<TContract extends ContractBase, W extends DeployInteractionWaitOptions> = W extends NoWait
152
+ ? TxSendResultImmediate
153
+ : W extends WaitWithReturnReceipt
154
+ ? TxSendResultMined<DeployTxReceipt<TContract>>
155
+ : DeployResultMined<TContract>;
156
+
86
157
  /**
87
158
  * Contract interaction for deployment.
88
159
  * Handles class publication, instance publication, and initialization of the contract.
@@ -92,8 +163,6 @@ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
92
163
  * then technically the contract has already been "created", and all of the contract's
93
164
  * functions (private and utility) can be interacted-with immediately, without any
94
165
  * "deployment tx".
95
- *
96
- * Extends the BaseContractInteraction class.
97
166
  */
98
167
  export class DeployMethod<TContract extends ContractBase = ContractBase> extends BaseContractInteraction {
99
168
  /** The contract instance to be deployed. */
@@ -111,6 +180,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
111
180
  constructorNameOrArtifact?: string | FunctionArtifact,
112
181
  authWitnesses: AuthWitness[] = [],
113
182
  capsules: Capsule[] = [],
183
+ private extraHashedArgs: HashedValues[] = [],
114
184
  ) {
115
185
  super(wallet, authWitnesses, capsules);
116
186
  this.constructorArtifact = getInitializer(artifact, constructorNameOrArtifact);
@@ -121,20 +191,29 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
121
191
  * @param options - Configuration options.
122
192
  * @returns The execution payload for this operation
123
193
  */
124
- public async request(options?: RequestDeployOptions): Promise<ExecutionPayload> {
194
+ public async request(options: RequestDeployOptions = {}): Promise<ExecutionPayload> {
125
195
  const publication = await this.getPublicationExecutionPayload(options);
126
196
 
127
197
  if (!options?.skipRegistration) {
128
198
  await this.wallet.registerContract(await this.getInstance(options), this.artifact);
129
199
  }
200
+ const { authWitnesses, capsules } = options;
130
201
 
202
+ // Propagates the included authwitnesses, capsules, and extraHashedArgs
203
+ // potentially baked into the interaction
204
+ const initialExecutionPayload = new ExecutionPayload(
205
+ [],
206
+ this.authWitnesses.concat(authWitnesses ?? []),
207
+ this.capsules.concat(capsules ?? []),
208
+ this.extraHashedArgs,
209
+ );
131
210
  const initialization = await this.getInitializationExecutionPayload(options);
132
211
  const feeExecutionPayload = options?.fee?.paymentMethod
133
212
  ? await options.fee.paymentMethod.getExecutionPayload()
134
213
  : undefined;
135
214
  const finalExecutionPayload = feeExecutionPayload
136
- ? mergeExecutionPayloads([feeExecutionPayload, publication, initialization])
137
- : mergeExecutionPayloads([publication, initialization]);
215
+ ? mergeExecutionPayloads([initialExecutionPayload, feeExecutionPayload, publication, initialization])
216
+ : mergeExecutionPayloads([initialExecutionPayload, publication, initialization]);
138
217
  if (!finalExecutionPayload.calls.length) {
139
218
  throw new Error(`No transactions are needed to publish or initialize contract ${this.artifact.name}`);
140
219
  }
@@ -142,13 +221,48 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
142
221
  return finalExecutionPayload;
143
222
  }
144
223
 
145
- convertDeployOptionsToRequestOptions(options: DeployOptions): RequestDeployOptions {
224
+ convertDeployOptionsToRequestOptions(options: DeployOptionsWithoutWait): RequestDeployOptions {
146
225
  return {
147
226
  ...options,
148
227
  deployer: !options?.universalDeploy ? options.from : undefined,
149
228
  };
150
229
  }
151
230
 
231
+ /**
232
+ * Converts DeployOptions to SendOptions, stripping out the returnReceipt flag if present.
233
+ * @param options - Deploy options with wait parameter
234
+ * @returns Send options with wait parameter
235
+ */
236
+ protected convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
237
+ options: DeployOptions<W>,
238
+ // eslint-disable-next-line jsdoc/require-jsdoc
239
+ ): SendOptions<W extends { returnReceipt: true } ? WaitOpts : W> {
240
+ return {
241
+ ...toSendOptions({
242
+ ...options,
243
+ wait: options.wait as any,
244
+ }),
245
+ } as any;
246
+ }
247
+
248
+ /**
249
+ * Converts deploy simulation options into wallet-level simulate options.
250
+ * @param options - The deploy simulation options to convert.
251
+ */
252
+ protected convertDeployOptionsToSimulateOptions(options: SimulateDeployOptions): SimulateOptions {
253
+ return toSimulateOptions(options);
254
+ }
255
+
256
+ /**
257
+ * Converts deploy profile options into wallet-level profile options.
258
+ * @param options - The deploy profile options to convert.
259
+ */
260
+ protected convertDeployOptionsToProfileOptions(
261
+ options: DeployOptionsWithoutWait & ProfileInteractionOptions,
262
+ ): ProfileOptions {
263
+ return toProfileOptions(options);
264
+ }
265
+
152
266
  /**
153
267
  * Adds this contract to the wallet and returns the Contract object.
154
268
  * @param options - Deployment options.
@@ -232,20 +346,44 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
232
346
 
233
347
  /**
234
348
  * Send a contract deployment transaction (initialize and/or publish) using the provided options.
235
- * This function extends the 'send' method from the ContractFunctionInteraction class,
236
- * allowing us to send a transaction specifically for contract deployment.
349
+ * By default, waits for the transaction to be mined and returns the deployed contract instance.
237
350
  *
238
351
  * @param options - An object containing various deployment options such as contractAddressSalt and from.
239
- * @returns A SentTx object that returns the receipt and the deployed contract instance.
352
+ * @returns TxHash (if wait is NO_WAIT), TContract (if wait is undefined or doesn't have returnReceipt), or DeployTxReceipt (if wait.returnReceipt is true)
240
353
  */
241
- public override send(options: DeployOptions): DeploySentTx<TContract> {
242
- const sendTx = async () => {
243
- const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
244
- const sendOptions = toSendOptions(options);
245
- return this.wallet.sendTx(executionPayload, sendOptions);
246
- };
247
- this.log.debug(`Sent deployment tx of ${this.artifact.name} contract`);
248
- return new DeploySentTx(this.wallet, sendTx, this.postDeployCtor, () => this.getInstance(options));
354
+ // Overload for when wait is not specified at all - returns the contract
355
+ public override send(options: DeployOptionsWithoutWait): Promise<DeployResultMined<TContract>>;
356
+ // eslint-disable-next-line jsdoc/require-jsdoc
357
+ public override send<W extends DeployInteractionWaitOptions>(
358
+ options: DeployOptions<W>,
359
+ ): Promise<DeployReturn<TContract, W>>;
360
+ // eslint-disable-next-line jsdoc/require-jsdoc
361
+ public override async send(options: DeployOptions<DeployInteractionWaitOptions>): Promise<any> {
362
+ const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
363
+ const sendOptions = this.convertDeployOptionsToSendOptions(options);
364
+
365
+ if (options.wait === NO_WAIT) {
366
+ const result = await this.wallet.sendTx(executionPayload, sendOptions as SendOptions<NoWait>);
367
+ this.log.debug(`Sent deployment tx ${result.txHash.hash} of ${this.artifact.name} contract`);
368
+ return result;
369
+ }
370
+
371
+ const { receipt, ...offchainOutput } = await this.wallet.sendTx(
372
+ executionPayload,
373
+ sendOptions as SendOptions<WaitOpts | undefined>,
374
+ );
375
+ this.log.debug(`Deployed ${this.artifact.name} contract in tx ${receipt.txHash}`);
376
+
377
+ // Attach contract instance
378
+ const instance = await this.getInstance(options);
379
+ const contract = this.postDeployCtor(instance, this.wallet) as TContract;
380
+
381
+ // Return full receipt if requested, otherwise just the contract
382
+ if (options.wait && typeof options.wait === 'object' && options.wait.returnReceipt) {
383
+ return { receipt: { ...receipt, contract, instance }, ...offchainOutput };
384
+ }
385
+
386
+ return { contract, receipt, ...offchainOutput };
249
387
  }
250
388
 
251
389
  /**
@@ -274,9 +412,12 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
274
412
  * @returns A simulation result object containing metadata of the execution, including gas
275
413
  * estimations (if requested via options), execution statistics and emitted offchain effects
276
414
  */
277
- public async simulate(options: SimulateDeployOptions): Promise<SimulationReturn<true>> {
415
+ public async simulate(options: SimulateDeployOptions): Promise<SimulationResult> {
278
416
  const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
279
- const simulatedTx = await this.wallet.simulateTx(executionPayload, toSimulateOptions(options));
417
+ const simulatedTx = await this.wallet.simulateTx(
418
+ executionPayload,
419
+ this.convertDeployOptionsToSimulateOptions(options),
420
+ );
280
421
 
281
422
  const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
282
423
  this.log.verbose(
@@ -284,7 +425,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
284
425
  );
285
426
  return {
286
427
  stats: simulatedTx.stats!,
287
- offchainEffects: collectOffchainEffects(simulatedTx.privateExecutionResult),
428
+ ...extractOffchainOutput(simulatedTx.offchainEffects),
288
429
  result: undefined,
289
430
  estimatedGas: { gasLimits, teardownGasLimits },
290
431
  };
@@ -296,13 +437,9 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
296
437
  *
297
438
  * @returns An object containing the function return value and profile result.
298
439
  */
299
- public async profile(options: DeployOptions & ProfileInteractionOptions): Promise<TxProfileResult> {
440
+ public async profile(options: DeployOptionsWithoutWait & ProfileInteractionOptions): Promise<TxProfileResult> {
300
441
  const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
301
- return await this.wallet.profileTx(executionPayload, {
302
- ...toProfileOptions(options),
303
- profileMode: options.profileMode,
304
- skipProofGeneration: options.skipProofGeneration,
305
- });
442
+ return await this.wallet.profileTx(executionPayload, this.convertDeployOptionsToProfileOptions(options));
306
443
  }
307
444
 
308
445
  /** Return this deployment address. */
@@ -1,4 +1,4 @@
1
- import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
1
+ import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
2
2
  import { Gas } from '@aztec/stdlib/gas';
3
3
  import type { TxSimulationResult } from '@aztec/stdlib/tx';
4
4
 
@@ -23,8 +23,8 @@ export function getGasLimits(
23
23
  const gasLimits = simulationResult.gasUsed.totalGas.mul(1 + pad);
24
24
  const teardownGasLimits = simulationResult.gasUsed.teardownGas.mul(1 + pad);
25
25
 
26
- if (gasLimits.l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
27
- throw new Error('Transaction consumes more gas than the AVM maximum processable gas');
26
+ if (gasLimits.l2Gas > MAX_PROCESSABLE_L2_GAS) {
27
+ throw new Error('Transaction consumes more l2 gas than the maximum processable gas');
28
28
  }
29
29
  return {
30
30
  gasLimits,
@@ -1,11 +1,20 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import type { FieldsOf } from '@aztec/foundation/types';
2
3
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
5
  import type { GasSettings } from '@aztec/stdlib/gas';
5
- import type { Capsule, OffchainEffect, SimulationStats } from '@aztec/stdlib/tx';
6
+ import {
7
+ type Capsule,
8
+ OFFCHAIN_MESSAGE_IDENTIFIER,
9
+ type OffchainEffect,
10
+ type SimulationStats,
11
+ type TxHash,
12
+ type TxReceipt,
13
+ } from '@aztec/stdlib/tx';
6
14
 
7
15
  import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
8
16
  import type { ProfileOptions, SendOptions, SimulateOptions } from '../wallet/index.js';
17
+ import type { WaitOpts } from './wait_opts.js';
9
18
 
10
19
  /**
11
20
  * Options used to tweak the simulation and add gas estimation capabilities
@@ -55,13 +64,52 @@ export type RequestInteractionOptions = {
55
64
  };
56
65
 
57
66
  /**
58
- * Represents options for calling a (constrained) function in a contract.
67
+ * Constant for explicitly not waiting for transaction confirmation.
68
+ * We use this instead of false to avoid confusion with falsy checks.
69
+ */
70
+ export const NO_WAIT = 'NO_WAIT' as const;
71
+
72
+ /**
73
+ * Type for the NO_WAIT constant.
74
+ */
75
+ export type NoWait = typeof NO_WAIT;
76
+
77
+ /**
78
+ * Type for wait options in interactions.
79
+ * - NO_WAIT symbol: Don't wait for confirmation, return TxHash immediately
80
+ * - WaitOpts object: Wait with custom options and return receipt/result
81
+ * - undefined: Wait with default options and return receipt/result
82
+ */
83
+ export type InteractionWaitOptions = NoWait | WaitOpts | undefined;
84
+
85
+ /**
86
+ * Base options for calling a (constrained) function in a contract, without wait parameter.
59
87
  */
60
- export type SendInteractionOptions = RequestInteractionOptions & {
88
+ export type SendInteractionOptionsWithoutWait = RequestInteractionOptions & {
61
89
  /** The sender's Aztec address. */
62
90
  from: AztecAddress;
63
91
  /** The fee options for the transaction. */
64
92
  fee?: InteractionFeeOptions;
93
+ /**
94
+ * Additional addresses whose private state and keys should be accessible during execution,
95
+ * beyond the sender's. Required when the transaction needs to access private state or keys
96
+ * belonging to an address other than `from`, e.g. withdrawing from an escrow that holds
97
+ * its own private notes.
98
+ */
99
+ additionalScopes?: AztecAddress[];
100
+ };
101
+
102
+ /**
103
+ * Represents options for calling a (constrained) function in a contract.
104
+ */
105
+ export type SendInteractionOptions<W extends InteractionWaitOptions = undefined> = SendInteractionOptionsWithoutWait & {
106
+ /**
107
+ * Whether to wait for the transaction to be mined.
108
+ * - undefined (default): wait with default options and return TxReceipt
109
+ * - WaitOpts object: wait with custom options and return TxReceipt
110
+ * - NO_WAIT: return txHash immediately without waiting
111
+ */
112
+ wait?: W;
65
113
  };
66
114
 
67
115
  /**
@@ -76,8 +124,8 @@ export type SimulateInteractionOptions = Omit<SendInteractionOptions, 'fee'> & {
76
124
  skipTxValidation?: boolean;
77
125
  /** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */
78
126
  skipFeeEnforcement?: boolean;
79
- /** Whether to include metadata such as offchain effects and performance statistics (e.g. timing information of the different circuits and oracles) in
80
- * the simulation result, instead of just the return value of the function */
127
+ /** Whether to include metadata such as performance statistics (e.g. timing information of the different circuits and oracles) and gas estimation
128
+ * in the simulation result, in addition to the return value and offchain effects */
81
129
  includeMetadata?: boolean;
82
130
  };
83
131
 
@@ -91,30 +139,99 @@ export type ProfileInteractionOptions = SimulateInteractionOptions & {
91
139
  skipProofGeneration?: boolean;
92
140
  };
93
141
 
142
+ /** A message emitted during execution or proving, to be delivered offchain. */
143
+ export type OffchainMessage = {
144
+ /** The intended recipient of the message. */
145
+ recipient: AztecAddress;
146
+ /** The message payload (typically encrypted). */
147
+ payload: Fr[];
148
+ /** The contract that emitted the message. */
149
+ contractAddress: AztecAddress;
150
+ };
151
+
152
+ /** Groups all unproven outputs from private execution that are returned to the client. */
153
+ export type OffchainOutput = {
154
+ /** Raw offchain effects emitted during execution. */
155
+ offchainEffects: OffchainEffect[];
156
+ /** Messages emitted during execution, to be delivered offchain. */
157
+ offchainMessages: OffchainMessage[];
158
+ };
159
+
94
160
  /**
95
- * Represents the result type of a simulation.
96
- * By default, it will just be the return value of the simulated function
97
- * If `includeMetadata` is set to true in `SimulateInteractionOptions` on the input of `simulate(...)`,
98
- * it will provide extra information.
99
- */
100
- export type SimulationReturn<T extends boolean | undefined> = T extends true
101
- ? {
102
- /** Additional stats about the simulation */
103
- stats: SimulationStats;
104
- /** Offchain effects generated during the simulation */
105
- offchainEffects: OffchainEffect[];
106
- /** Return value of the function */
107
- result: any;
108
- /** Gas estimation results */
109
- estimatedGas: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>;
161
+ * Splits an array of offchain effects into decoded offchain messages and remaining effects.
162
+ * Effects whose data starts with `OFFCHAIN_MESSAGE_IDENTIFIER` are parsed as messages and removed
163
+ * from the effects array.
164
+ */
165
+ export function extractOffchainOutput(effects: OffchainEffect[]): OffchainOutput {
166
+ const offchainEffects: OffchainEffect[] = [];
167
+ const offchainMessages: OffchainMessage[] = [];
168
+
169
+ for (const effect of effects) {
170
+ if (effect.data.length >= 2 && effect.data[0].equals(OFFCHAIN_MESSAGE_IDENTIFIER)) {
171
+ offchainMessages.push({
172
+ recipient: AztecAddress.fromField(effect.data[1]),
173
+ payload: effect.data.slice(2),
174
+ contractAddress: effect.contractAddress,
175
+ });
176
+ } else {
177
+ offchainEffects.push(effect);
110
178
  }
111
- : any;
179
+ }
180
+
181
+ return { offchainEffects, offchainMessages };
182
+ }
183
+
184
+ /**
185
+ * Returns an empty `OffchainOutput` (no effects, no messages).
186
+ */
187
+ export function emptyOffchainOutput(): OffchainOutput {
188
+ return { offchainEffects: [], offchainMessages: [] };
189
+ }
190
+
191
+ /**
192
+ * Represents the result of a simulation.
193
+ * Always includes the return value and offchain output.
194
+ * When `includeMetadata` or `fee.estimateGas` is set, also includes stats and gas estimation.
195
+ */
196
+ export type SimulationResult = {
197
+ /** Return value of the function */
198
+ result: any;
199
+ /** Additional stats about the simulation. Present when `includeMetadata` is set. */
200
+ stats?: SimulationStats;
201
+ /** Gas estimation results. Present when `includeMetadata` or `fee.estimateGas` is set. */
202
+ estimatedGas?: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>;
203
+ } & OffchainOutput;
204
+
205
+ /** Result of sendTx when not waiting for mining. */
206
+ export type TxSendResultImmediate = {
207
+ /** The hash of the sent transaction. */
208
+ txHash: TxHash;
209
+ } & OffchainOutput;
210
+
211
+ /** Result of sendTx when waiting for mining. */
212
+ export type TxSendResultMined<TReturn = TxReceipt> = {
213
+ /** The transaction receipt. */
214
+ receipt: TReturn;
215
+ } & OffchainOutput;
216
+
217
+ /**
218
+ * Represents the result type of sending a transaction.
219
+ * If `wait` is NO_WAIT, returns TxSendResultImmediate.
220
+ * Otherwise returns TxSendResultMined.
221
+ */
222
+ export type SendReturn<T extends InteractionWaitOptions, TReturn = TxReceipt> = T extends NoWait
223
+ ? TxSendResultImmediate
224
+ : TxSendResultMined<TReturn>;
112
225
 
113
226
  /**
114
227
  * Transforms and cleans up the higher level SendInteractionOptions defined by the interaction into
115
228
  * SendOptions, which are the ones that can be serialized and forwarded to the wallet
229
+ * @param options - The send interaction options with optional wait parameter
230
+ * @returns The send options to forward to the wallet
116
231
  */
117
- export function toSendOptions(options: SendInteractionOptions): SendOptions {
232
+ export function toSendOptions<W extends InteractionWaitOptions = undefined>(
233
+ options: SendInteractionOptions<W>,
234
+ ): SendOptions<W> {
118
235
  return {
119
236
  ...options,
120
237
  fee: {
@@ -126,6 +243,7 @@ export function toSendOptions(options: SendInteractionOptions): SendOptions {
126
243
  ...options.fee?.gasSettings,
127
244
  },
128
245
  },
246
+ wait: options.wait, // Pass through wait option
129
247
  };
130
248
  }
131
249
 
@@ -41,9 +41,10 @@ const AuthRegistryContractArtifact: ContractArtifact = {
41
41
  ],
42
42
  returnTypes: [],
43
43
  errorTypes: {
44
- '2754040237334517471': { error_kind: 'fmtstring', length: 92, item_types: [] },
45
44
  '7555607922535724711': { error_kind: 'string', string: 'Preimage mismatch' },
45
+ '9530675838293881722': { error_kind: 'string', string: 'Writer did not write all data' },
46
46
  '9894212961085021188': { error_kind: 'string', string: 'Message not authorized by account' },
47
+ '12327971061804302172': { error_kind: 'fmtstring', length: 98, item_types: [] },
47
48
  '14990209321349310352': { error_kind: 'string', string: 'attempt to add with overflow' },
48
49
  '15764276373176857197': { error_kind: 'string', string: 'Stack too deep' },
49
50
  '16431471497789672479': { error_kind: 'string', string: 'Index out of bounds' },
@@ -100,7 +101,7 @@ const AuthRegistryContractArtifact: ContractArtifact = {
100
101
  type: {
101
102
  kind: 'struct',
102
103
  fields: [
103
- { name: 'storage', type: { kind: 'array', length: 17, type: { kind: 'field' } } },
104
+ { name: 'storage', type: { kind: 'array', length: 15, type: { kind: 'field' } } },
104
105
  { name: 'len', type: { kind: 'integer', sign: 'unsigned', width: 32 } },
105
106
  ],
106
107
  path: 'std::collections::bounded_vec::BoundedVec',
@@ -161,22 +162,16 @@ const AuthRegistryContractArtifact: ContractArtifact = {
161
162
  },
162
163
  '4261968856572588300': { error_kind: 'string', string: 'Value does not fit in field' },
163
164
  '4440399188109668273': { error_kind: 'string', string: 'Input length must be a multiple of 32' },
165
+ '5417577161503694006': { error_kind: 'fmtstring', length: 56, item_types: [{ kind: 'field' }] },
166
+ '5421095327929394772': { error_kind: 'string', string: 'attempt to bit-shift with overflow' },
167
+ '9530675838293881722': { error_kind: 'string', string: 'Writer did not write all data' },
164
168
  '9791669845391776238': {
165
169
  error_kind: 'string',
166
170
  string: '0 has a square root; you cannot claim it is not square',
167
171
  },
168
- '9885968605480832328': {
169
- error_kind: 'string',
170
- string: 'Attempted to read past the length of a CapsuleArray',
171
- },
172
172
  '10135509984888824963': { error_kind: 'fmtstring', length: 58, item_types: [{ kind: 'field' }] },
173
173
  '10791800398362570014': { error_kind: 'string', string: 'extend_from_bounded_vec out of bounds' },
174
- '11021520179822076911': {
175
- error_kind: 'string',
176
- string: 'Attempted to delete past the length of a CapsuleArray',
177
- },
178
174
  '11692359521570349358': { error_kind: 'fmtstring', length: 40, item_types: [] },
179
- '12327971061804302172': { error_kind: 'fmtstring', length: 98, item_types: [] },
180
175
  '12469291177396340830': { error_kind: 'string', string: 'call to assert_max_bit_size' },
181
176
  '12913276134398371456': { error_kind: 'string', string: 'push out of bounds' },
182
177
  '13557316507370296400': {
@@ -244,7 +239,7 @@ const AuthRegistryContractArtifact: ContractArtifact = {
244
239
  {
245
240
  ...{
246
241
  functionType: FunctionType.UTILITY,
247
- name: 'sync_private_state',
242
+ name: 'sync_state',
248
243
  isOnlySelf: false,
249
244
  isStatic: false,
250
245
  isInitializer: false,
@@ -271,6 +266,9 @@ const AuthRegistryContractArtifact: ContractArtifact = {
271
266
  },
272
267
  '4261968856572588300': { error_kind: 'string', string: 'Value does not fit in field' },
273
268
  '4440399188109668273': { error_kind: 'string', string: 'Input length must be a multiple of 32' },
269
+ '5417577161503694006': { error_kind: 'fmtstring', length: 56, item_types: [{ kind: 'field' }] },
270
+ '5421095327929394772': { error_kind: 'string', string: 'attempt to bit-shift with overflow' },
271
+ '9530675838293881722': { error_kind: 'string', string: 'Writer did not write all data' },
274
272
  '9791669845391776238': {
275
273
  error_kind: 'string',
276
274
  string: '0 has a square root; you cannot claim it is not square',
@@ -307,6 +305,7 @@ const AuthRegistryContractArtifact: ContractArtifact = {
307
305
  length: 133,
308
306
  item_types: [{ kind: 'integer', sign: 'unsigned', width: 32 }],
309
307
  },
308
+ '17655676068928457687': { error_kind: 'string', string: 'Reader did not read all data' },
310
309
  },
311
310
  },
312
311
  bytecode: Buffer.from([]),
@@ -544,8 +543,8 @@ export class AuthRegistryContract extends ContractBase {
544
543
  /** set_reject_all(reject: boolean) */
545
544
  set_reject_all: ((reject: boolean) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
546
545
 
547
- /** sync_private_state() */
548
- sync_private_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
546
+ /** sync_state() */
547
+ sync_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
549
548
 
550
549
  /** utility_is_consumable(on_behalf_of: struct, message_hash: field) */
551
550
  utility_is_consumable: ((on_behalf_of: AztecAddressLike, message_hash: FieldLike) => ContractFunctionInteraction) &