@aztec/aztec.js 0.81.0 → 0.82.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 (177) hide show
  1. package/dest/account/{contract.d.ts → account_contract.d.ts} +3 -2
  2. package/dest/account/account_contract.d.ts.map +1 -0
  3. package/dest/account/index.d.ts +2 -3
  4. package/dest/account/index.d.ts.map +1 -1
  5. package/dest/account/index.js +1 -2
  6. package/dest/account/interface.d.ts +1 -13
  7. package/dest/account/interface.d.ts.map +1 -1
  8. package/dest/account/interface.js +1 -0
  9. package/dest/account_manager/account_manager.d.ts +105 -0
  10. package/dest/account_manager/account_manager.d.ts.map +1 -0
  11. package/dest/account_manager/account_manager.js +165 -0
  12. package/dest/account_manager/deploy_account_method.d.ts +4 -4
  13. package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
  14. package/dest/account_manager/deploy_account_method.js +28 -13
  15. package/dest/account_manager/deploy_account_sent_tx.d.ts +3 -3
  16. package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -1
  17. package/dest/account_manager/deploy_account_sent_tx.js +2 -2
  18. package/dest/account_manager/index.d.ts +1 -104
  19. package/dest/account_manager/index.d.ts.map +1 -1
  20. package/dest/account_manager/index.js +1 -165
  21. package/dest/api/account.d.ts +2 -1
  22. package/dest/api/account.d.ts.map +1 -1
  23. package/dest/api/contract.d.ts +4 -1
  24. package/dest/api/contract.d.ts.map +1 -1
  25. package/dest/api/contract.js +3 -0
  26. package/dest/api/fee.d.ts +1 -1
  27. package/dest/api/fee.d.ts.map +1 -1
  28. package/dest/api/utils.d.ts +2 -1
  29. package/dest/api/utils.d.ts.map +1 -1
  30. package/dest/api/utils.js +2 -1
  31. package/dest/api/wallet.d.ts +1 -1
  32. package/dest/api/wallet.d.ts.map +1 -1
  33. package/dest/contract/base_contract_interaction.d.ts +22 -57
  34. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  35. package/dest/contract/base_contract_interaction.js +12 -67
  36. package/dest/contract/batch_call.d.ts +6 -18
  37. package/dest/contract/batch_call.d.ts.map +1 -1
  38. package/dest/contract/batch_call.js +25 -54
  39. package/dest/contract/contract.d.ts +1 -1
  40. package/dest/contract/contract.d.ts.map +1 -1
  41. package/dest/contract/contract_base.d.ts +1 -1
  42. package/dest/contract/contract_base.d.ts.map +1 -1
  43. package/dest/contract/contract_function_interaction.d.ts +38 -18
  44. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  45. package/dest/contract/contract_function_interaction.js +34 -41
  46. package/dest/contract/deploy_method.d.ts +7 -8
  47. package/dest/contract/deploy_method.d.ts.map +1 -1
  48. package/dest/contract/deploy_method.js +27 -32
  49. package/dest/contract/deploy_proven_tx.d.ts +2 -3
  50. package/dest/contract/deploy_proven_tx.d.ts.map +1 -1
  51. package/dest/contract/deploy_sent_tx.d.ts +2 -3
  52. package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
  53. package/dest/contract/deploy_sent_tx.js +4 -4
  54. package/dest/contract/protocol_contracts.d.ts +1 -1
  55. package/dest/contract/protocol_contracts.d.ts.map +1 -1
  56. package/dest/contract/proven_tx.d.ts +3 -4
  57. package/dest/contract/proven_tx.d.ts.map +1 -1
  58. package/dest/contract/sent_tx.d.ts +4 -16
  59. package/dest/contract/sent_tx.d.ts.map +1 -1
  60. package/dest/contract/sent_tx.js +6 -37
  61. package/dest/contract/unsafe_contract.d.ts +1 -1
  62. package/dest/contract/unsafe_contract.d.ts.map +1 -1
  63. package/dest/contract/wait_for_proven.d.ts +17 -0
  64. package/dest/contract/wait_for_proven.d.ts.map +1 -0
  65. package/dest/contract/wait_for_proven.js +17 -0
  66. package/dest/deployment/broadcast_function.js +12 -8
  67. package/dest/deployment/contract_deployer.d.ts +1 -1
  68. package/dest/deployment/contract_deployer.d.ts.map +1 -1
  69. package/dest/deployment/register_class.d.ts +1 -1
  70. package/dest/deployment/register_class.d.ts.map +1 -1
  71. package/dest/deployment/register_class.js +6 -11
  72. package/dest/entrypoint/default_multi_call_entrypoint.d.ts +3 -2
  73. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
  74. package/dest/entrypoint/default_multi_call_entrypoint.js +12 -8
  75. package/dest/ethereum/portal_manager.d.ts +20 -11
  76. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  77. package/dest/ethereum/portal_manager.js +64 -30
  78. package/dest/fee/fee_juice_payment_method.d.ts +3 -3
  79. package/dest/fee/fee_juice_payment_method.d.ts.map +1 -1
  80. package/dest/fee/fee_juice_payment_method.js +3 -2
  81. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +4 -4
  82. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  83. package/dest/fee/fee_juice_payment_method_with_claim.js +6 -5
  84. package/dest/fee/private_fee_payment_method.d.ts +6 -6
  85. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  86. package/dest/fee/private_fee_payment_method.js +13 -12
  87. package/dest/fee/public_fee_payment_method.d.ts +7 -7
  88. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  89. package/dest/fee/public_fee_payment_method.js +10 -11
  90. package/dest/fee/utils.d.ts +13 -0
  91. package/dest/fee/utils.d.ts.map +1 -0
  92. package/dest/fee/utils.js +32 -0
  93. package/dest/utils/authwit.d.ts +16 -9
  94. package/dest/utils/authwit.d.ts.map +1 -1
  95. package/dest/utils/authwit.js +26 -35
  96. package/dest/wallet/account_wallet.d.ts +6 -6
  97. package/dest/wallet/account_wallet.d.ts.map +1 -1
  98. package/dest/wallet/account_wallet.js +15 -17
  99. package/dest/wallet/base_wallet.d.ts +12 -35
  100. package/dest/wallet/base_wallet.d.ts.map +1 -1
  101. package/dest/wallet/base_wallet.js +11 -64
  102. package/dest/wallet/index.d.ts +2 -2
  103. package/dest/wallet/index.d.ts.map +1 -1
  104. package/dest/wallet/index.js +1 -1
  105. package/dest/wallet/signerless_wallet.d.ts +3 -3
  106. package/dest/wallet/signerless_wallet.d.ts.map +1 -1
  107. package/dest/wallet/signerless_wallet.js +3 -6
  108. package/dest/wallet/wallet.d.ts +11 -0
  109. package/dest/wallet/wallet.d.ts.map +1 -0
  110. package/package.json +8 -7
  111. package/src/account/{contract.ts → account_contract.ts} +2 -1
  112. package/src/account/index.ts +2 -3
  113. package/src/account/interface.ts +1 -12
  114. package/src/account_manager/account_manager.ts +235 -0
  115. package/src/account_manager/deploy_account_method.ts +35 -15
  116. package/src/account_manager/deploy_account_sent_tx.ts +4 -4
  117. package/src/account_manager/index.ts +1 -236
  118. package/src/api/account.ts +2 -8
  119. package/src/api/contract.ts +5 -5
  120. package/src/api/fee.ts +1 -1
  121. package/src/api/utils.ts +1 -1
  122. package/src/api/wallet.ts +7 -1
  123. package/src/contract/base_contract_interaction.ts +32 -88
  124. package/src/contract/batch_call.ts +40 -43
  125. package/src/contract/contract.ts +1 -1
  126. package/src/contract/contract_base.ts +1 -1
  127. package/src/contract/contract_function_interaction.ts +85 -56
  128. package/src/contract/deploy_method.ts +24 -26
  129. package/src/contract/deploy_proven_tx.ts +2 -3
  130. package/src/contract/deploy_sent_tx.ts +6 -6
  131. package/src/contract/protocol_contracts.ts +1 -1
  132. package/src/contract/proven_tx.ts +2 -3
  133. package/src/contract/sent_tx.ts +6 -47
  134. package/src/contract/unsafe_contract.ts +1 -1
  135. package/src/contract/wait_for_proven.ts +38 -0
  136. package/src/deployment/broadcast_function.ts +40 -40
  137. package/src/deployment/contract_deployer.ts +1 -1
  138. package/src/deployment/register_class.ts +9 -22
  139. package/src/entrypoint/default_multi_call_entrypoint.ts +14 -7
  140. package/src/ethereum/portal_manager.ts +73 -24
  141. package/src/fee/fee_juice_payment_method.ts +4 -5
  142. package/src/fee/fee_juice_payment_method_with_claim.ts +24 -20
  143. package/src/fee/private_fee_payment_method.ts +29 -28
  144. package/src/fee/public_fee_payment_method.ts +29 -29
  145. package/src/fee/utils.ts +39 -0
  146. package/src/utils/authwit.ts +32 -35
  147. package/src/wallet/account_wallet.ts +18 -17
  148. package/src/wallet/base_wallet.ts +27 -88
  149. package/src/wallet/index.ts +2 -2
  150. package/src/wallet/signerless_wallet.ts +9 -8
  151. package/src/wallet/wallet.ts +34 -0
  152. package/dest/account/contract.d.ts.map +0 -1
  153. package/dest/account/wallet.d.ts +0 -11
  154. package/dest/account/wallet.d.ts.map +0 -1
  155. package/dest/api/entrypoint.d.ts +0 -2
  156. package/dest/api/entrypoint.d.ts.map +0 -1
  157. package/dest/api/entrypoint.js +0 -1
  158. package/dest/entrypoint/default_entrypoint.d.ts +0 -12
  159. package/dest/entrypoint/default_entrypoint.d.ts.map +0 -1
  160. package/dest/entrypoint/default_entrypoint.js +0 -28
  161. package/dest/entrypoint/entrypoint.d.ts +0 -39
  162. package/dest/entrypoint/entrypoint.d.ts.map +0 -1
  163. package/dest/entrypoint/entrypoint.js +0 -20
  164. package/dest/entrypoint/payload.d.ts +0 -128
  165. package/dest/entrypoint/payload.d.ts.map +0 -1
  166. package/dest/entrypoint/payload.js +0 -143
  167. package/dest/fee/fee_payment_method.d.ts +0 -22
  168. package/dest/fee/fee_payment_method.d.ts.map +0 -1
  169. package/dest/fee/fee_payment_method.js +0 -3
  170. package/src/account/wallet.ts +0 -13
  171. package/src/api/entrypoint.ts +0 -1
  172. package/src/entrypoint/default_entrypoint.ts +0 -39
  173. package/src/entrypoint/entrypoint.ts +0 -60
  174. package/src/entrypoint/payload.ts +0 -238
  175. package/src/fee/fee_payment_method.ts +0 -22
  176. /package/dest/account/{contract.js → account_contract.js} +0 -0
  177. /package/dest/{account → wallet}/wallet.js +0 -0
@@ -1,22 +1,32 @@
1
+ import type { FeeOptions, TxExecutionOptions, UserFeeOptions } from '@aztec/entrypoints/interfaces';
2
+ import type { ExecutionPayload } from '@aztec/entrypoints/payload';
1
3
  import type { Fr } from '@aztec/foundation/fields';
2
4
  import { createLogger } from '@aztec/foundation/log';
3
5
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4
6
  import { GasSettings } from '@aztec/stdlib/gas';
5
- import type { Capsule, HashedValues, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
7
+ import type { Capsule, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
6
8
 
7
- import type { Wallet } from '../account/wallet.js';
8
- import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
9
- import type { FeeOptions, UserFeeOptions } from '../entrypoint/payload.js';
10
9
  import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
10
+ import type { Wallet } from '../wallet/wallet.js';
11
11
  import { getGasLimits } from './get_gas_limits.js';
12
12
  import { ProvenTx } from './proven_tx.js';
13
13
  import { SentTx } from './sent_tx.js';
14
14
 
15
+ /**
16
+ * Represents the options to configure a request from a contract interaction.
17
+ * Allows specifying additional auth witnesses and capsules to use during execution
18
+ */
19
+ export type RequestMethodOptions = {
20
+ /** Extra authwits to use during execution */
21
+ authWitnesses?: AuthWitness[];
22
+ /** Extra capsules to use during execution */
23
+ capsules?: Capsule[];
24
+ };
25
+
15
26
  /**
16
27
  * Represents options for calling a (constrained) function in a contract.
17
- * Allows the user to specify the sender address and nonce for a transaction.
18
28
  */
19
- export type SendMethodOptions = {
29
+ export type SendMethodOptions = RequestMethodOptions & {
20
30
  /** Wether to skip the simulation of the public part of the transaction. */
21
31
  skipPublicSimulation?: boolean;
22
32
  /** The fee options for the transaction. */
@@ -34,11 +44,11 @@ export type SendMethodOptions = {
34
44
  export abstract class BaseContractInteraction {
35
45
  protected log = createLogger('aztecjs:contract_interaction');
36
46
 
37
- protected authWitnesses: AuthWitness[] = [];
38
- protected hashedArguments: HashedValues[] = [];
39
- protected capsules: Capsule[] = [];
40
-
41
- constructor(protected wallet: Wallet) {}
47
+ constructor(
48
+ protected wallet: Wallet,
49
+ protected authWitnesses: AuthWitness[] = [],
50
+ protected capsules: Capsule[] = [],
51
+ ) {}
42
52
 
43
53
  /**
44
54
  * Create a transaction execution request ready to be simulated.
@@ -53,7 +63,7 @@ export abstract class BaseContractInteraction {
53
63
  * @param options - An optional object containing additional configuration for the transaction.
54
64
  * @returns An execution request wrapped in promise.
55
65
  */
56
- public abstract request(options?: SendMethodOptions): Promise<Omit<ExecutionRequestInit, 'fee'>>;
66
+ public abstract request(options?: RequestMethodOptions): Promise<ExecutionPayload>;
57
67
 
58
68
  /**
59
69
  * Creates a transaction execution request, simulates and proves it. Differs from .prove in
@@ -141,23 +151,26 @@ export abstract class BaseContractInteraction {
141
151
  // docs:start:getFeeOptions
142
152
  /**
143
153
  * Return fee options based on the user opts, estimating tx gas if needed.
144
- * @param request - Request to execute for this interaction.
145
- * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%).
154
+ * @param executionPayload - Execution payload to get the fee for
155
+ * @param fee - User-provided fee options.
156
+ * @param options - Additional options for the transaction. They must faithfully represent the tx to get accurate fee estimates
146
157
  * @returns Fee options for the actual transaction.
147
158
  */
148
159
  protected async getFeeOptions(
149
- request: Omit<ExecutionRequestInit, 'fee'> & { /** User-provided fee options */ fee?: UserFeeOptions },
160
+ executionPayload: ExecutionPayload,
161
+ fee: UserFeeOptions = {},
162
+ options: TxExecutionOptions,
150
163
  ): Promise<FeeOptions> {
151
164
  // docs:end:getFeeOptions
152
- const defaultFeeOptions = await this.getDefaultFeeOptions(request.fee);
165
+ const defaultFeeOptions = await this.getDefaultFeeOptions(fee);
153
166
  const paymentMethod = defaultFeeOptions.paymentMethod;
154
167
  const maxFeesPerGas = defaultFeeOptions.gasSettings.maxFeesPerGas;
155
168
  const maxPriorityFeesPerGas = defaultFeeOptions.gasSettings.maxPriorityFeesPerGas;
156
169
 
157
170
  let gasSettings = defaultFeeOptions.gasSettings;
158
- if (request.fee?.estimateGas) {
171
+ if (fee?.estimateGas) {
159
172
  const feeForEstimation: FeeOptions = { paymentMethod, gasSettings };
160
- const txRequest = await this.wallet.createTxExecutionRequest({ ...request, fee: feeForEstimation });
173
+ const txRequest = await this.wallet.createTxExecutionRequest(executionPayload, feeForEstimation, options);
161
174
  const simulationResult = await this.wallet.simulateTx(
162
175
  txRequest,
163
176
  true /*simulatePublic*/,
@@ -167,7 +180,7 @@ export abstract class BaseContractInteraction {
167
180
  );
168
181
  const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(
169
182
  simulationResult,
170
- request.fee?.estimatedGasPadding,
183
+ fee?.estimatedGasPadding,
171
184
  );
172
185
  gasSettings = GasSettings.from({ maxFeesPerGas, maxPriorityFeesPerGas, gasLimits, teardownGasLimits });
173
186
  this.log.verbose(
@@ -177,73 +190,4 @@ export abstract class BaseContractInteraction {
177
190
 
178
191
  return { gasSettings, paymentMethod };
179
192
  }
180
-
181
- /**
182
- * Add authWitness used in this contract interaction.
183
- * @param authWitness - authWitness used in the contract interaction.
184
- */
185
- public addAuthWitness(authWitness: AuthWitness) {
186
- this.authWitnesses.push(authWitness);
187
- }
188
-
189
- /**
190
- * Add authWitness used in this contract interaction.
191
- * @param authWitnesses - authWitnesses used in the contract interaction.
192
- */
193
- public addAuthWitnesses(authWitnesses: AuthWitness[]) {
194
- this.authWitnesses.push(...authWitnesses);
195
- }
196
-
197
- /**
198
- * Return all authWitnesses added for this interaction.
199
- */
200
- public getAuthWitnesses() {
201
- return this.authWitnesses;
202
- }
203
-
204
- /**
205
- * Add hashedArgument used in this contract interaction.
206
- * @param hashedArgument - hashedArgument used in the contract interaction.
207
- */
208
- public addHashedArgument(hashedArgument: HashedValues) {
209
- this.hashedArguments.push(hashedArgument);
210
- }
211
-
212
- /**
213
- * Add hashedArguments used in this contract interaction.
214
- * @param hashedArguments - hashedArguments used in the contract interaction.
215
- */
216
- public addHashedArguments(hashedArguments: HashedValues[]) {
217
- this.hashedArguments.push(...hashedArguments);
218
- }
219
-
220
- /**
221
- * Return all hashedArguments added for this interaction.
222
- */
223
- public getHashedArguments() {
224
- return this.hashedArguments;
225
- }
226
-
227
- /**
228
- * Add data passed to the oracle calls during this contract interaction.
229
- * @param capsule - Data passed to oracle calls.
230
- */
231
- public addCapsule(capsule: Capsule) {
232
- this.capsules.push(capsule);
233
- }
234
-
235
- /**
236
- * Add data passed to the oracle calls during this contract interaction.
237
- * @param capsules - Data passed to oracle calls.
238
- */
239
- public addCapsules(capsules: Capsule[]) {
240
- this.capsules.push(...capsules);
241
- }
242
-
243
- /**
244
- * Return all capsules added for this contract interaction.
245
- */
246
- public getCapsules() {
247
- return this.capsules;
248
- }
249
193
  }
@@ -1,9 +1,13 @@
1
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
1
2
  import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
3
  import type { TxExecutionRequest } from '@aztec/stdlib/tx';
3
4
 
4
- import type { Wallet } from '../account/wallet.js';
5
- import { type ExecutionRequestInit, mergeExecutionRequestInits } from '../entrypoint/entrypoint.js';
6
- import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
5
+ import type { Wallet } from '../wallet/wallet.js';
6
+ import {
7
+ BaseContractInteraction,
8
+ type RequestMethodOptions,
9
+ type SendMethodOptions,
10
+ } from './base_contract_interaction.js';
7
11
  import type { SimulateMethodOptions } from './contract_function_interaction.js';
8
12
 
9
13
  /** A batch of function calls to be sent as a single transaction through a wallet. */
@@ -21,21 +25,26 @@ export class BatchCall extends BaseContractInteraction {
21
25
  public async create(options: SendMethodOptions = {}): Promise<TxExecutionRequest> {
22
26
  const requestWithoutFee = await this.request(options);
23
27
 
24
- const { fee: userFee } = options;
25
- const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee });
28
+ const { fee: userFee, nonce, cancellable } = options;
29
+ const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable });
26
30
 
27
- return await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
31
+ return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
28
32
  }
29
33
 
30
34
  /**
31
35
  * Returns an execution request that represents this operation.
32
- * @param options - An optional object containing additional configuration for the transaction.
33
- * @returns An execution request wrapped in promise.
36
+ * @param options - An optional object containing additional configuration for the request generation.
37
+ * @returns An execution payload wrapped in promise.
34
38
  */
35
- public async request(options: SendMethodOptions = {}): Promise<Omit<ExecutionRequestInit, 'fee'>> {
39
+ public async request(options: RequestMethodOptions = {}): Promise<ExecutionPayload> {
36
40
  const requests = await this.getRequests();
37
- const { nonce, cancellable } = options;
38
- return mergeExecutionRequestInits(requests, { nonce, cancellable });
41
+ const combinedPayload = mergeExecutionPayloads(requests);
42
+ return new ExecutionPayload(
43
+ combinedPayload.calls,
44
+ combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
45
+ combinedPayload.capsules.concat(options.capsules ?? []),
46
+ combinedPayload.extraHashedArgs,
47
+ );
39
48
  }
40
49
 
41
50
  /**
@@ -48,13 +57,13 @@ export class BatchCall extends BaseContractInteraction {
48
57
  * @returns The result of the transaction as returned by the contract function.
49
58
  */
50
59
  public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
51
- const { indexedRequests, unconstrained } = (await this.getRequests()).reduce<{
60
+ const { indexedExecutionPayloads, unconstrained } = (await this.getRequests()).reduce<{
52
61
  /** Keep track of the number of private calls to retrieve the return values */
53
62
  privateIndex: 0;
54
63
  /** Keep track of the number of public calls to retrieve the return values */
55
64
  publicIndex: 0;
56
65
  /** The public and private function execution requests in the batch */
57
- indexedRequests: [Omit<ExecutionRequestInit, 'fee'>, number, number][];
66
+ indexedExecutionPayloads: [ExecutionPayload, number, number][];
58
67
  /** The unconstrained function calls in the batch. */
59
68
  unconstrained: [FunctionCall, number][];
60
69
  }>(
@@ -63,7 +72,7 @@ export class BatchCall extends BaseContractInteraction {
63
72
  if (call.type === FunctionType.UNCONSTRAINED) {
64
73
  acc.unconstrained.push([call, index]);
65
74
  } else {
66
- acc.indexedRequests.push([
75
+ acc.indexedExecutionPayloads.push([
67
76
  current,
68
77
  index,
69
78
  call.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++,
@@ -71,18 +80,27 @@ export class BatchCall extends BaseContractInteraction {
71
80
  }
72
81
  return acc;
73
82
  },
74
- { indexedRequests: [], unconstrained: [], publicIndex: 0, privateIndex: 0 },
83
+ { indexedExecutionPayloads: [], unconstrained: [], publicIndex: 0, privateIndex: 0 },
75
84
  );
76
85
 
77
- const requests = indexedRequests.map(([request]) => request);
78
- const requestWithoutFee = mergeExecutionRequestInits(requests);
79
- const { fee: userFee } = options;
80
- const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee });
81
- const txRequest = await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
86
+ const payloads = indexedExecutionPayloads.map(([request]) => request);
87
+ const combinedPayload = mergeExecutionPayloads(payloads);
88
+ const requestWithoutFee = new ExecutionPayload(
89
+ combinedPayload.calls,
90
+ combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
91
+ combinedPayload.capsules.concat(options.capsules ?? []),
92
+ combinedPayload.extraHashedArgs,
93
+ );
94
+ const { fee: userFee, nonce, cancellable } = options;
95
+ const fee = await this.getFeeOptions(requestWithoutFee, userFee, {});
96
+ const txRequest = await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
82
97
 
83
98
  const unconstrainedCalls = unconstrained.map(
84
99
  async ([call, index]) =>
85
- [await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from), index] as const,
100
+ [
101
+ await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.authWitnesses, options?.from),
102
+ index,
103
+ ] as const,
86
104
  );
87
105
 
88
106
  const [unconstrainedResults, simulatedTx] = await Promise.all([
@@ -95,7 +113,7 @@ export class BatchCall extends BaseContractInteraction {
95
113
  unconstrainedResults.forEach(([result, index]) => {
96
114
  results[index] = result;
97
115
  });
98
- indexedRequests.forEach(([request, callIndex, resultIndex]) => {
116
+ indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {
99
117
  const call = request.calls[0];
100
118
  // As account entrypoints are private, for private functions we retrieve the return values from the first nested call
101
119
  // since we're interested in the first set of values AFTER the account entrypoint
@@ -110,27 +128,6 @@ export class BatchCall extends BaseContractInteraction {
110
128
  return results;
111
129
  }
112
130
 
113
- /**
114
- * Return all authWitnesses added for this interaction.
115
- */
116
- public override getAuthWitnesses() {
117
- return [this.authWitnesses, ...this.calls.map(c => c.getAuthWitnesses())].flat();
118
- }
119
-
120
- /**
121
- * Return all hashedArguments added for this interaction.
122
- */
123
- public override getHashedArguments() {
124
- return [this.hashedArguments, ...this.calls.map(c => c.getHashedArguments())].flat();
125
- }
126
-
127
- /**
128
- * Return all capsules added for this interaction.
129
- */
130
- public override getCapsules() {
131
- return [this.capsules, ...this.calls.map(c => c.getCapsules())].flat();
132
- }
133
-
134
131
  private async getRequests() {
135
132
  return await Promise.all(this.calls.map(c => c.request()));
136
133
  }
@@ -3,7 +3,7 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
4
4
  import { PublicKeys } from '@aztec/stdlib/keys';
5
5
 
6
- import type { Wallet } from '../account/wallet.js';
6
+ import type { Wallet } from '../wallet/wallet.js';
7
7
  import { ContractBase } from './contract_base.js';
8
8
  import { DeployMethod } from './deploy_method.js';
9
9
 
@@ -8,7 +8,7 @@ import {
8
8
  } from '@aztec/stdlib/abi';
9
9
  import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
10
10
 
11
- import type { Wallet } from '../account/wallet.js';
11
+ import type { Wallet } from '../wallet/wallet.js';
12
12
  import { ContractFunctionInteraction } from './contract_function_interaction.js';
13
13
 
14
14
  /**
@@ -1,12 +1,15 @@
1
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
1
2
  import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
3
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
2
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import type { PrivateKernelProverProfileResult } from '@aztec/stdlib/kernel';
4
- import type { TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import type { Capsule, HashedValues, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx';
5
6
 
6
- import type { Wallet } from '../account/wallet.js';
7
- import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
8
- import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
9
- import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
7
+ import type { Wallet } from '../wallet/wallet.js';
8
+ import {
9
+ BaseContractInteraction,
10
+ type RequestMethodOptions,
11
+ type SendMethodOptions,
12
+ } from './base_contract_interaction.js';
10
13
 
11
14
  export type { SendMethodOptions };
12
15
 
@@ -15,21 +18,31 @@ export type { SendMethodOptions };
15
18
  * Allows specifying the address from which the view method should be called.
16
19
  * Disregarded for simulation of public functions
17
20
  */
18
- export type SimulateMethodOptions = Pick<SendMethodOptions, 'fee'> & {
21
+ export type ProfileMethodOptions = Pick<
22
+ SendMethodOptions,
23
+ 'authWitnesses' | 'capsules' | 'fee' | 'nonce' | 'cancellable'
24
+ > & {
25
+ /** Whether to return gates information or the bytecode/witnesses. */
26
+ profileMode: 'gates' | 'execution-steps' | 'full';
19
27
  /** The sender's Aztec address. */
20
28
  from?: AztecAddress;
21
- /** Simulate without checking for the validity of the resulting transaction, e.g. whether it emits any existing nullifiers. */
22
- skipTxValidation?: boolean;
23
- /** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */
24
- skipFeeEnforcement?: boolean;
25
29
  };
26
30
 
27
31
  /**
28
- * The result of a profile() call.
32
+ * Represents the options for simulating a contract function interaction.
33
+ * Allows specifying the address from which the method should be called.
34
+ * Disregarded for simulation of public functions
29
35
  */
30
- export type ProfileResult = PrivateKernelProverProfileResult & {
31
- /** The result of the transaction as returned by the contract function. */
32
- returnValues: any;
36
+ export type SimulateMethodOptions = Pick<
37
+ SendMethodOptions,
38
+ 'authWitnesses' | 'capsules' | 'fee' | 'nonce' | 'cancellable'
39
+ > & {
40
+ /** The sender's Aztec address. */
41
+ from?: AztecAddress;
42
+ /** Simulate without checking for the validity of the resulting transaction, e.g. whether it emits any existing nullifiers. */
43
+ skipTxValidation?: boolean;
44
+ /** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */
45
+ skipFeeEnforcement?: boolean;
33
46
  };
34
47
 
35
48
  /**
@@ -42,8 +55,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
42
55
  protected contractAddress: AztecAddress,
43
56
  protected functionDao: FunctionAbi,
44
57
  protected args: any[],
58
+ authWitnesses: AuthWitness[] = [],
59
+ capsules: Capsule[] = [],
60
+ private extraHashedArgs: HashedValues[] = [],
45
61
  ) {
46
- super(wallet);
62
+ super(wallet, authWitnesses, capsules);
47
63
  if (args.some(arg => arg === undefined || arg === null)) {
48
64
  throw new Error('All function interaction arguments must be defined and not null. Received: ' + args);
49
65
  }
@@ -63,20 +79,20 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
63
79
  }
64
80
  const requestWithoutFee = await this.request(options);
65
81
 
66
- const { fee: userFee } = options;
67
- const fee = await this.getFeeOptions({ ...requestWithoutFee, fee: userFee });
82
+ const { fee: userFee, nonce, cancellable } = options;
83
+ const fee = await this.getFeeOptions(requestWithoutFee, userFee, { nonce, cancellable });
68
84
 
69
- return await this.wallet.createTxExecutionRequest({ ...requestWithoutFee, fee });
85
+ return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { nonce, cancellable });
70
86
  }
71
87
 
72
88
  // docs:start:request
73
89
  /**
74
90
  * Returns an execution request that represents this operation.
75
91
  * Can be used as a building block for constructing batch requests.
76
- * @param options - An optional object containing additional configuration for the transaction.
77
- * @returns An execution request wrapped in promise.
92
+ * @param options - An optional object containing additional configuration for the request generation.
93
+ * @returns An execution payload wrapped in promise.
78
94
  */
79
- public async request(options: SendMethodOptions = {}): Promise<Omit<ExecutionRequestInit, 'fee'>> {
95
+ public async request(options: RequestMethodOptions = {}): Promise<ExecutionPayload> {
80
96
  // docs:end:request
81
97
  const args = encodeArguments(this.functionDao, this.args);
82
98
  const calls = [
@@ -90,18 +106,13 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
90
106
  returnTypes: this.functionDao.returnTypes,
91
107
  },
92
108
  ];
93
- const authWitnesses = this.getAuthWitnesses();
94
- const hashedArguments = this.getHashedArguments();
95
- const capsules = this.getCapsules();
96
- const { nonce, cancellable } = options;
97
- return {
109
+ const { authWitnesses, capsules } = options;
110
+ return new ExecutionPayload(
98
111
  calls,
99
- authWitnesses,
100
- hashedArguments,
101
- capsules,
102
- nonce,
103
- cancellable,
104
- };
112
+ this.authWitnesses.concat(authWitnesses ?? []),
113
+ this.capsules.concat(capsules ?? []),
114
+ this.extraHashedArgs,
115
+ );
105
116
  }
106
117
 
107
118
  // docs:start:simulate
@@ -117,11 +128,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
117
128
  public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
118
129
  // docs:end:simulate
119
130
  if (this.functionDao.functionType == FunctionType.UNCONSTRAINED) {
120
- return this.wallet.simulateUnconstrained(this.functionDao.name, this.args, this.contractAddress, options?.from);
131
+ return this.wallet.simulateUnconstrained(
132
+ this.functionDao.name,
133
+ this.args,
134
+ this.contractAddress,
135
+ options.authWitnesses ?? [],
136
+ options?.from,
137
+ );
121
138
  }
122
139
 
123
- const fee = options.fee ?? { paymentMethod: new FeeJuicePaymentMethod(AztecAddress.ZERO) };
124
- const txRequest = await this.create({ fee });
140
+ const txRequest = await this.create(options);
125
141
  const simulatedTx = await this.wallet.simulateTx(
126
142
  txRequest,
127
143
  true /* simulatePublic */,
@@ -154,30 +170,43 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
154
170
  *
155
171
  * @returns An object containing the function return value and profile result.
156
172
  */
157
- public async simulateWithProfile(options: SimulateMethodOptions = {}): Promise<ProfileResult> {
173
+ public async profile(options: ProfileMethodOptions = { profileMode: 'gates' }): Promise<TxProfileResult> {
158
174
  if (this.functionDao.functionType == FunctionType.UNCONSTRAINED) {
159
175
  throw new Error("Can't profile an unconstrained function.");
160
176
  }
177
+ const { authWitnesses, capsules, fee } = options;
161
178
 
162
- const txRequest = await this.create({ fee: options.fee });
163
- const simulatedTx = await this.wallet.simulateTx(
164
- txRequest,
165
- true,
166
- options?.from,
167
- options?.skipTxValidation,
168
- undefined,
169
- true,
170
- );
171
-
172
- const rawReturnValues =
173
- this.functionDao.functionType == FunctionType.PRIVATE
174
- ? simulatedTx.getPrivateReturnValues().nested?.[0].values
175
- : simulatedTx.getPublicReturnValues()?.[0].values;
176
- const rawReturnValuesDecoded = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
179
+ const txRequest = await this.create({ fee, authWitnesses, capsules });
180
+ return await this.wallet.profileTx(txRequest, options.profileMode, options?.from);
181
+ }
177
182
 
178
- return {
179
- returnValues: rawReturnValuesDecoded,
180
- gateCounts: simulatedTx.profileResult!.gateCounts,
181
- };
183
+ /**
184
+ * Augments this ContractFunctionInteraction with additional metadata, such as authWitnesses, capsules, and extraHashedArgs.
185
+ * This is useful when creating a "batteries included" interaction, such as registering a contract class with its associated
186
+ * capsule instead of having the user provide them externally.
187
+ * @param options - An object containing the metadata to add to the interaction
188
+ * @returns A new ContractFunctionInteraction with the added metadata, but calling the same original function in the same manner
189
+ */
190
+ public with({
191
+ authWitnesses = [],
192
+ capsules = [],
193
+ extraHashedArgs = [],
194
+ }: {
195
+ /** The authWitnesses to add to the interaction */
196
+ authWitnesses?: AuthWitness[];
197
+ /** The capsules to add to the interaction */
198
+ capsules?: Capsule[];
199
+ /** The extra hashed args to add to the interaction */
200
+ extraHashedArgs?: HashedValues[];
201
+ }): ContractFunctionInteraction {
202
+ return new ContractFunctionInteraction(
203
+ this.wallet,
204
+ this.contractAddress,
205
+ this.functionDao,
206
+ this.args,
207
+ this.authWitnesses.concat(authWitnesses),
208
+ this.capsules.concat(capsules),
209
+ this.extraHashedArgs.concat(extraHashedArgs),
210
+ );
182
211
  }
183
212
  }