@aztec/aztec.js 0.41.0 → 0.43.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 (99) hide show
  1. package/dest/account/index.d.ts +2 -2
  2. package/dest/account/index.d.ts.map +1 -1
  3. package/dest/account_manager/deploy_account_method.d.ts.map +1 -1
  4. package/dest/account_manager/deploy_account_method.js +7 -5
  5. package/dest/account_manager/index.d.ts +1 -2
  6. package/dest/account_manager/index.d.ts.map +1 -1
  7. package/dest/account_manager/index.js +5 -11
  8. package/dest/api/abi.d.ts +2 -2
  9. package/dest/api/abi.d.ts.map +1 -1
  10. package/dest/api/abi.js +1 -1
  11. package/dest/api/fee.d.ts +2 -0
  12. package/dest/api/fee.d.ts.map +1 -1
  13. package/dest/api/fee.js +3 -1
  14. package/dest/contract/base_contract_interaction.d.ts +7 -6
  15. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  16. package/dest/contract/base_contract_interaction.js +20 -9
  17. package/dest/contract/batch_call.d.ts +11 -0
  18. package/dest/contract/batch_call.d.ts.map +1 -1
  19. package/dest/contract/batch_call.js +50 -2
  20. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  21. package/dest/contract/contract_function_interaction.js +14 -10
  22. package/dest/contract/deploy_method.d.ts +5 -1
  23. package/dest/contract/deploy_method.d.ts.map +1 -1
  24. package/dest/contract/deploy_method.js +22 -6
  25. package/dest/contract/get_gas_limits.d.ts +1 -1
  26. package/dest/contract/get_gas_limits.d.ts.map +1 -1
  27. package/dest/contract/get_gas_limits.js +5 -3
  28. package/dest/contract/sent_tx.d.ts.map +1 -1
  29. package/dest/contract/sent_tx.js +7 -5
  30. package/dest/entrypoint/default_entrypoint.d.ts.map +1 -1
  31. package/dest/entrypoint/default_entrypoint.js +6 -2
  32. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
  33. package/dest/entrypoint/default_multi_call_entrypoint.js +4 -4
  34. package/dest/entrypoint/payload.d.ts +24 -9
  35. package/dest/entrypoint/payload.d.ts.map +1 -1
  36. package/dest/entrypoint/payload.js +50 -29
  37. package/dest/fee/fee_payment_method.d.ts +6 -7
  38. package/dest/fee/fee_payment_method.d.ts.map +1 -1
  39. package/dest/fee/native_fee_payment_method.d.ts +5 -25
  40. package/dest/fee/native_fee_payment_method.d.ts.map +1 -1
  41. package/dest/fee/native_fee_payment_method.js +9 -46
  42. package/dest/fee/native_fee_payment_method_with_claim.d.ts +17 -0
  43. package/dest/fee/native_fee_payment_method_with_claim.d.ts.map +1 -0
  44. package/dest/fee/native_fee_payment_method_with_claim.js +32 -0
  45. package/dest/fee/no_fee_payment_method.d.ts +13 -0
  46. package/dest/fee/no_fee_payment_method.d.ts.map +1 -0
  47. package/dest/fee/no_fee_payment_method.js +17 -0
  48. package/dest/fee/private_fee_payment_method.d.ts +1 -5
  49. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  50. package/dest/fee/private_fee_payment_method.js +13 -14
  51. package/dest/fee/public_fee_payment_method.d.ts +1 -5
  52. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  53. package/dest/fee/public_fee_payment_method.js +13 -14
  54. package/dest/index.d.ts +12 -13
  55. package/dest/index.d.ts.map +1 -1
  56. package/dest/index.js +10 -11
  57. package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
  58. package/dest/rpc_clients/pxe_client.js +3 -3
  59. package/dest/utils/account.js +3 -3
  60. package/dest/utils/authwit.d.ts.map +1 -1
  61. package/dest/utils/authwit.js +2 -6
  62. package/dest/utils/cheat_codes.d.ts.map +1 -1
  63. package/dest/utils/cheat_codes.js +9 -5
  64. package/dest/wallet/account_wallet.d.ts +17 -1
  65. package/dest/wallet/account_wallet.d.ts.map +1 -1
  66. package/dest/wallet/account_wallet.js +45 -31
  67. package/dest/wallet/base_wallet.d.ts +12 -3
  68. package/dest/wallet/base_wallet.d.ts.map +1 -1
  69. package/dest/wallet/base_wallet.js +21 -3
  70. package/dest/wallet/signerless_wallet.js +7 -7
  71. package/package.json +7 -7
  72. package/src/account/index.ts +2 -2
  73. package/src/account_manager/deploy_account_method.ts +10 -3
  74. package/src/account_manager/index.ts +11 -9
  75. package/src/api/abi.ts +2 -2
  76. package/src/api/fee.ts +2 -0
  77. package/src/contract/base_contract_interaction.ts +32 -8
  78. package/src/contract/batch_call.ts +77 -1
  79. package/src/contract/contract_function_interaction.ts +20 -10
  80. package/src/contract/deploy_method.ts +23 -6
  81. package/src/contract/get_gas_limits.ts +4 -3
  82. package/src/contract/sent_tx.ts +6 -4
  83. package/src/entrypoint/default_entrypoint.ts +7 -1
  84. package/src/entrypoint/default_multi_call_entrypoint.ts +3 -3
  85. package/src/entrypoint/payload.ts +58 -26
  86. package/src/fee/fee_payment_method.ts +6 -8
  87. package/src/fee/native_fee_payment_method.ts +8 -47
  88. package/src/fee/native_fee_payment_method_with_claim.ts +33 -0
  89. package/src/fee/no_fee_payment_method.ts +23 -0
  90. package/src/fee/private_fee_payment_method.ts +13 -17
  91. package/src/fee/public_fee_payment_method.ts +13 -18
  92. package/src/index.ts +38 -34
  93. package/src/rpc_clients/pxe_client.ts +3 -3
  94. package/src/utils/account.ts +2 -2
  95. package/src/utils/authwit.ts +1 -5
  96. package/src/utils/cheat_codes.ts +8 -4
  97. package/src/wallet/account_wallet.ts +67 -29
  98. package/src/wallet/base_wallet.ts +38 -4
  99. package/src/wallet/signerless_wallet.ts +6 -6
@@ -1,5 +1,6 @@
1
1
  import { type Tx, type TxExecutionRequest } from '@aztec/circuit-types';
2
2
  import { GasSettings } from '@aztec/circuits.js';
3
+ import { createDebugLogger } from '@aztec/foundation/log';
3
4
 
4
5
  import { type Wallet } from '../account/wallet.js';
5
6
  import { type ExecutionRequestInit, type FeeOptions } from '../entrypoint/entrypoint.js';
@@ -27,6 +28,8 @@ export abstract class BaseContractInteraction {
27
28
  protected tx?: Tx;
28
29
  protected txRequest?: TxExecutionRequest;
29
30
 
31
+ protected log = createDebugLogger('aztec:js:contract_interaction');
32
+
30
33
  constructor(protected wallet: Wallet) {}
31
34
 
32
35
  /**
@@ -66,14 +69,28 @@ export abstract class BaseContractInteraction {
66
69
  }
67
70
 
68
71
  /**
69
- * Estimates gas for a given tx request and returns defaults gas settings for it.
70
- * @param txRequest - Transaction execution request to process.
71
- * @returns Gas settings.
72
+ * Estimates gas for a given tx request and returns gas limits for it.
73
+ * @param opts - Options.
74
+ * @returns Gas limits.
72
75
  */
73
- protected async estimateGas(txRequest: TxExecutionRequest) {
76
+ public async estimateGas(
77
+ opts?: Omit<SendMethodOptions, 'estimateGas' | 'skipPublicSimulation'>,
78
+ ): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>> {
79
+ // REFACTOR: both `this.txRequest = undefined` below are horrible, we should not be caching stuff that doesn't need to be.
80
+ // This also hints at a weird interface for create/request/estimate/send etc.
81
+
82
+ // Ensure we don't accidentally use a version of tx request that has estimateGas set to true, leading to an infinite loop.
83
+ this.txRequest = undefined;
84
+ const txRequest = await this.create({ ...opts, estimateGas: false });
85
+ // Ensure we don't accidentally cache a version of tx request that has estimateGas forcefully set to false.
86
+ this.txRequest = undefined;
87
+
74
88
  const simulationResult = await this.wallet.simulateTx(txRequest, true);
75
- const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(simulationResult);
76
- return GasSettings.default({ gasLimits, teardownGasLimits });
89
+ const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(
90
+ simulationResult,
91
+ (opts?.fee?.gasSettings ?? GasSettings.default()).teardownGasLimits,
92
+ );
93
+ return { gasLimits, teardownGasLimits };
77
94
  }
78
95
 
79
96
  /**
@@ -81,11 +98,18 @@ export abstract class BaseContractInteraction {
81
98
  * @param request - Request to execute for this interaction.
82
99
  * @returns Fee options for the actual transaction.
83
100
  */
84
- protected async getFeeOptions(request: ExecutionRequestInit) {
101
+ protected async getFeeOptionsFromEstimatedGas(request: ExecutionRequestInit) {
85
102
  const fee = request.fee;
86
103
  if (fee) {
87
104
  const txRequest = await this.wallet.createTxExecutionRequest(request);
88
- const { gasLimits, teardownGasLimits } = await this.estimateGas(txRequest);
105
+ const simulationResult = await this.wallet.simulateTx(txRequest, true);
106
+ const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(
107
+ simulationResult,
108
+ fee.gasSettings.teardownGasLimits,
109
+ );
110
+ this.log.debug(
111
+ `Estimated gas limits for tx: DA=${gasLimits.daGas} L2=${gasLimits.l2Gas} teardownDA=${teardownGasLimits.daGas} teardownL2=${teardownGasLimits.l2Gas}`,
112
+ );
89
113
  const gasSettings = GasSettings.default({ ...fee.gasSettings, gasLimits, teardownGasLimits });
90
114
  return { ...fee, gasSettings };
91
115
  }
@@ -1,7 +1,9 @@
1
1
  import { type FunctionCall, type TxExecutionRequest } from '@aztec/circuit-types';
2
+ import { FunctionType, decodeReturnValues } from '@aztec/foundation/abi';
2
3
 
3
4
  import { type Wallet } from '../account/index.js';
4
5
  import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
6
+ import type { SimulateMethodOptions } from './contract_function_interaction.js';
5
7
 
6
8
  /** A batch of function calls to be sent as a single transaction through a wallet. */
7
9
  export class BatchCall extends BaseContractInteraction {
@@ -18,9 +20,83 @@ export class BatchCall extends BaseContractInteraction {
18
20
  public async create(opts?: SendMethodOptions): Promise<TxExecutionRequest> {
19
21
  if (!this.txRequest) {
20
22
  const calls = this.calls;
21
- const fee = opts?.estimateGas ? await this.getFeeOptions({ calls, fee: opts?.fee }) : opts?.fee;
23
+ const fee = opts?.estimateGas ? await this.getFeeOptionsFromEstimatedGas({ calls, fee: opts?.fee }) : opts?.fee;
22
24
  this.txRequest = await this.wallet.createTxExecutionRequest({ calls, fee });
23
25
  }
24
26
  return this.txRequest;
25
27
  }
28
+
29
+ /**
30
+ * Simulate a transaction and get its return values
31
+ * Differs from prove in a few important ways:
32
+ * 1. It returns the values of the function execution
33
+ * 2. It supports `unconstrained`, `private` and `public` functions
34
+ *
35
+ * @param options - An optional object containing additional configuration for the transaction.
36
+ * @returns The result of the transaction as returned by the contract function.
37
+ */
38
+ public async simulate(options: SimulateMethodOptions = {}): Promise<any> {
39
+ const { calls, unconstrained } = this.calls.reduce<{
40
+ /**
41
+ * Keep track of the number of private calls to retrieve the return values
42
+ */
43
+ privateIndex: 0;
44
+ /**
45
+ * Keep track of the number of private calls to retrieve the return values
46
+ */
47
+ publicIndex: 0;
48
+ /**
49
+ * The public and private function calls in the batch
50
+ */
51
+ calls: [FunctionCall, number, number][];
52
+ /**
53
+ * The unconstrained function calls in the batch.
54
+ */
55
+ unconstrained: [FunctionCall, number][];
56
+ }>(
57
+ (acc, current, index) => {
58
+ if (current.type === FunctionType.UNCONSTRAINED) {
59
+ acc.unconstrained.push([current, index]);
60
+ } else {
61
+ acc.calls.push([
62
+ current,
63
+ index,
64
+ current.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++,
65
+ ]);
66
+ }
67
+ return acc;
68
+ },
69
+ { calls: [], unconstrained: [], publicIndex: 0, privateIndex: 0 },
70
+ );
71
+
72
+ const txRequest = await this.wallet.createTxExecutionRequest({ calls: calls.map(indexedCall => indexedCall[0]) });
73
+
74
+ const unconstrainedCalls = unconstrained.map(async indexedCall => {
75
+ const call = indexedCall[0];
76
+ return [await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from), indexedCall[1]];
77
+ });
78
+
79
+ const [unconstrainedResults, simulatedTx] = await Promise.all([
80
+ Promise.all(unconstrainedCalls),
81
+ this.wallet.simulateTx(txRequest, true, options?.from),
82
+ ]);
83
+
84
+ const results: any[] = [];
85
+
86
+ unconstrainedResults.forEach(([result, index]) => {
87
+ results[index] = result;
88
+ });
89
+ calls.forEach(([call, callIndex, resultIndex]) => {
90
+ // As account entrypoints are private, for private functions we retrieve the return values from the first nested call
91
+ // since we're interested in the first set of values AFTER the account entrypoint
92
+ // For public functions we retrieve the first values directly from the public output.
93
+ const rawReturnValues =
94
+ call.type == FunctionType.PRIVATE
95
+ ? simulatedTx.privateReturnValues?.nested?.[resultIndex].values
96
+ : simulatedTx.publicOutput?.publicReturnValues?.[resultIndex].values;
97
+
98
+ results[callIndex] = rawReturnValues ? decodeReturnValues(call.returnTypes, rawReturnValues) : [];
99
+ });
100
+ return results;
101
+ }
26
102
  }
@@ -1,6 +1,12 @@
1
1
  import type { FunctionCall, TxExecutionRequest } from '@aztec/circuit-types';
2
- import { type AztecAddress, FunctionData, type GasSettings } from '@aztec/circuits.js';
3
- import { type FunctionAbi, FunctionType, decodeReturnValues, encodeArguments } from '@aztec/foundation/abi';
2
+ import { type AztecAddress, type GasSettings } from '@aztec/circuits.js';
3
+ import {
4
+ type FunctionAbi,
5
+ FunctionSelector,
6
+ FunctionType,
7
+ decodeReturnValues,
8
+ encodeArguments,
9
+ } from '@aztec/foundation/abi';
4
10
 
5
11
  import { type Wallet } from '../account/wallet.js';
6
12
  import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
@@ -48,7 +54,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
48
54
  }
49
55
  if (!this.txRequest) {
50
56
  const calls = [this.request()];
51
- const fee = opts?.estimateGas ? await this.getFeeOptions({ calls, fee: opts?.fee }) : opts?.fee;
57
+ const fee = opts?.estimateGas ? await this.getFeeOptionsFromEstimatedGas({ calls, fee: opts?.fee }) : opts?.fee;
52
58
  this.txRequest = await this.wallet.createTxExecutionRequest({ calls, fee });
53
59
  }
54
60
  return this.txRequest;
@@ -61,8 +67,15 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
61
67
  */
62
68
  public request(): FunctionCall {
63
69
  const args = encodeArguments(this.functionDao, this.args);
64
- const functionData = FunctionData.fromAbi(this.functionDao);
65
- return { args, functionData, to: this.contractAddress, isStatic: this.functionDao.isStatic };
70
+ return {
71
+ name: this.functionDao.name,
72
+ args,
73
+ selector: FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
74
+ type: this.functionDao.functionType,
75
+ to: this.contractAddress,
76
+ isStatic: this.functionDao.isStatic,
77
+ returnTypes: this.functionDao.returnTypes,
78
+ };
66
79
  }
67
80
 
68
81
  /**
@@ -80,9 +93,6 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
80
93
  }
81
94
 
82
95
  const txRequest = await this.create();
83
- // const from =
84
- // this.functionDao.functionType == FunctionType.PRIVATE ? options.from ?? this.wallet.getAddress() : undefined;
85
-
86
96
  const simulatedTx = await this.wallet.simulateTx(txRequest, true, options?.from);
87
97
 
88
98
  // As account entrypoints are private, for private functions we retrieve the return values from the first nested call
@@ -91,8 +101,8 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
91
101
  const rawReturnValues =
92
102
  this.functionDao.functionType == FunctionType.PRIVATE
93
103
  ? simulatedTx.privateReturnValues?.nested?.[0].values
94
- : simulatedTx.publicOutput?.publicReturnValues?.values;
104
+ : simulatedTx.publicOutput?.publicReturnValues?.[0].values;
95
105
 
96
- return rawReturnValues ? decodeReturnValues(this.functionDao, rawReturnValues) : [];
106
+ return rawReturnValues ? decodeReturnValues(this.functionDao.returnTypes, rawReturnValues) : [];
97
107
  }
98
108
  }
@@ -7,7 +7,6 @@ import {
7
7
  } from '@aztec/circuits.js';
8
8
  import { type ContractArtifact, type FunctionArtifact, getInitializer } from '@aztec/foundation/abi';
9
9
  import { type Fr } from '@aztec/foundation/fields';
10
- import { createDebugLogger } from '@aztec/foundation/log';
11
10
  import { type ContractInstanceWithAddress } from '@aztec/types/contracts';
12
11
 
13
12
  import { type Wallet } from '../account/index.js';
@@ -53,8 +52,6 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
53
52
  /** Cached call to request() */
54
53
  private functionCalls?: ExecutionRequestInit;
55
54
 
56
- private log = createDebugLogger('aztec:js:deploy_method');
57
-
58
55
  constructor(
59
56
  private publicKeysHash: Fr,
60
57
  wallet: Wallet,
@@ -79,8 +76,6 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
79
76
  public async create(options: DeployOptions = {}): Promise<TxExecutionRequest> {
80
77
  if (!this.txRequest) {
81
78
  this.txRequest = await this.wallet.createTxExecutionRequest(await this.request(options));
82
- // TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined?
83
- await this.wallet.registerContract({ artifact: this.artifact, instance: this.instance! });
84
79
  }
85
80
  return this.txRequest;
86
81
  }
@@ -98,6 +93,14 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
98
93
  */
99
94
  public async request(options: DeployOptions = {}): Promise<ExecutionRequestInit> {
100
95
  if (!this.functionCalls) {
96
+ // TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined?
97
+ // Note that we need to run this registerContract here so it's available when computeFeeOptionsFromEstimatedGas
98
+ // runs, since it needs the contract to have been registered in order to estimate gas for its initialization,
99
+ // in case the initializer is public. This hints at the need of having "transient" contracts scoped to a
100
+ // simulation, so we can run the simulation with a set of contracts, but only "commit" them to the wallet
101
+ // once this tx has gone through.
102
+ await this.wallet.registerContract({ artifact: this.artifact, instance: this.getInstance(options) });
103
+
101
104
  const deployment = await this.getDeploymentFunctionCalls(options);
102
105
  const bootstrap = await this.getInitializeFunctionCalls(options);
103
106
 
@@ -113,7 +116,13 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
113
116
  };
114
117
 
115
118
  if (options.estimateGas) {
116
- request.fee = await this.getFeeOptions(request);
119
+ // Why do we call this seemingly idempotent getter method here, without using its return value?
120
+ // This call pushes a capsule required for contract class registration under the hood. And since
121
+ // capsules are a stack, when we run the simulation for estimating gas, we consume the capsule
122
+ // that was meant for the actual call. So we need to push it again here. Hopefully this design
123
+ // will go away soon.
124
+ await this.getDeploymentFunctionCalls(options);
125
+ request.fee = await this.getFeeOptionsFromEstimatedGas(request);
117
126
  }
118
127
 
119
128
  this.functionCalls = request;
@@ -233,6 +242,14 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
233
242
  return super.prove(options);
234
243
  }
235
244
 
245
+ /**
246
+ * Estimates gas cost for this deployment operation.
247
+ * @param options - Options.
248
+ */
249
+ public override estimateGas(options?: Omit<DeployOptions, 'estimateGas' | 'skipPublicSimulation'>) {
250
+ return super.estimateGas(options);
251
+ }
252
+
236
253
  /** Return this deployment address. */
237
254
  public get address() {
238
255
  return this.instance?.address;
@@ -6,8 +6,10 @@ import { Gas } from '@aztec/circuits.js';
6
6
  * Note that public gas usage is only accounted for if the publicOutput is present.
7
7
  * @param pad - Percentage to pad the suggested gas limits by, defaults to 10%.
8
8
  */
9
- export function getGasLimits(simulatedTx: SimulatedTx, pad = 0.1) {
10
- const privateGasUsed = simulatedTx.tx.data.publicInputs.end.gasUsed;
9
+ export function getGasLimits(simulatedTx: SimulatedTx, simulationTeardownGasLimits: Gas, pad = 0.1) {
10
+ const privateGasUsed = simulatedTx.tx.data.publicInputs.end.gasUsed
11
+ .sub(simulationTeardownGasLimits)
12
+ .add(simulatedTx.tx.data.forPublic?.endNonRevertibleData.gasUsed ?? Gas.empty());
11
13
  if (simulatedTx.publicOutput) {
12
14
  const publicGasUsed = Object.values(simulatedTx.publicOutput.gasUsed)
13
15
  .filter(Boolean)
@@ -19,6 +21,5 @@ export function getGasLimits(simulatedTx: SimulatedTx, pad = 0.1) {
19
21
  teardownGas: teardownGas.mul(1 + pad),
20
22
  };
21
23
  }
22
-
23
24
  return { totalGas: privateGasUsed.mul(1 + pad), teardownGas: Gas.empty() };
24
25
  }
@@ -72,7 +72,7 @@ export class SentTx {
72
72
  throw new Error('Cannot set debug to true if waitForNotesSync is false');
73
73
  }
74
74
  const receipt = await this.waitForReceipt(opts);
75
- if (!(receipt.status === TxStatus.MINED || (receipt.status === TxStatus.REVERTED && opts?.dontThrowOnRevert))) {
75
+ if (receipt.status !== TxStatus.SUCCESS && !opts?.dontThrowOnRevert) {
76
76
  throw new Error(
77
77
  `Transaction ${await this.getTxHash()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`,
78
78
  );
@@ -80,13 +80,15 @@ export class SentTx {
80
80
  if (opts?.debug) {
81
81
  const txHash = await this.getTxHash();
82
82
  const tx = (await this.pxe.getTxEffect(txHash))!;
83
- const visibleNotes = await this.pxe.getNotes({ txHash });
83
+ const visibleIncomingNotes = await this.pxe.getIncomingNotes({ txHash });
84
+ const visibleOutgoingNotes = await this.pxe.getOutgoingNotes({ txHash });
84
85
  receipt.debugInfo = {
85
86
  noteHashes: tx.noteHashes,
86
87
  nullifiers: tx.nullifiers,
87
88
  publicDataWrites: tx.publicDataWrites,
88
89
  l2ToL1Msgs: tx.l2ToL1Msgs,
89
- visibleNotes,
90
+ visibleIncomingNotes,
91
+ visibleOutgoingNotes,
90
92
  };
91
93
  }
92
94
  return receipt;
@@ -109,7 +111,7 @@ export class SentTx {
109
111
  */
110
112
  public async getVisibleNotes(): Promise<ExtendedNote[]> {
111
113
  await this.wait();
112
- return this.pxe.getNotes({ txHash: await this.getTxHash() });
114
+ return this.pxe.getIncomingNotes({ txHash: await this.getTxHash() });
113
115
  }
114
116
 
115
117
  protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
@@ -1,5 +1,6 @@
1
1
  import { PackedValues, TxExecutionRequest } from '@aztec/circuit-types';
2
2
  import { GasSettings, TxContext } from '@aztec/circuits.js';
3
+ import { FunctionType } from '@aztec/foundation/abi';
3
4
 
4
5
  import { type EntrypointInterface, type ExecutionRequestInit } from './entrypoint.js';
5
6
 
@@ -17,13 +18,18 @@ export class DefaultEntrypoint implements EntrypointInterface {
17
18
  }
18
19
 
19
20
  const call = calls[0];
21
+
22
+ if (call.type !== FunctionType.PRIVATE) {
23
+ throw new Error('Public entrypoints are not allowed');
24
+ }
25
+
20
26
  const entrypointPackedValues = PackedValues.fromValues(call.args);
21
27
  const gasSettings = exec.fee?.gasSettings ?? GasSettings.default();
22
28
  const txContext = new TxContext(this.chainId, this.protocolVersion, gasSettings);
23
29
  return Promise.resolve(
24
30
  new TxExecutionRequest(
25
31
  call.to,
26
- call.functionData,
32
+ call.selector,
27
33
  entrypointPackedValues.hash,
28
34
  txContext,
29
35
  [...packedArguments, entrypointPackedValues],
@@ -1,7 +1,7 @@
1
1
  import { type EntrypointInterface, EntrypointPayload, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
2
2
  import { PackedValues, TxExecutionRequest } from '@aztec/circuit-types';
3
- import { type AztecAddress, FunctionData, GasSettings, TxContext } from '@aztec/circuits.js';
4
- import { type FunctionAbi, encodeArguments } from '@aztec/foundation/abi';
3
+ import { type AztecAddress, GasSettings, TxContext } from '@aztec/circuits.js';
4
+ import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
5
5
  import { getCanonicalMultiCallEntrypointAddress } from '@aztec/protocol-contracts/multi-call-entrypoint';
6
6
 
7
7
  /**
@@ -24,7 +24,7 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
24
24
  const txRequest = TxExecutionRequest.from({
25
25
  firstCallArgsHash: entrypointPackedArgs.hash,
26
26
  origin: this.address,
27
- functionData: FunctionData.fromAbi(abi),
27
+ functionSelector: FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
28
28
  txContext: new TxContext(this.chainId, this.version, gasSettings),
29
29
  argsOfCalls: [...payload.packedArguments, ...packedArguments, entrypointPackedArgs],
30
30
  authWitnesses,
@@ -1,5 +1,6 @@
1
- import { type FunctionCall, PackedValues, emptyFunctionCall } from '@aztec/circuit-types';
2
- import { Fr, type GasSettings, GeneratorIndex } from '@aztec/circuits.js';
1
+ import { FunctionCall, PackedValues } from '@aztec/circuit-types';
2
+ import { type AztecAddress, Fr, type GasSettings, GeneratorIndex } from '@aztec/circuits.js';
3
+ import { FunctionType } from '@aztec/foundation/abi';
3
4
  import { padArrayEnd } from '@aztec/foundation/collection';
4
5
  import { pedersenHash } from '@aztec/foundation/crypto';
5
6
  import { type Tuple } from '@aztec/foundation/serialize';
@@ -39,13 +40,13 @@ type EncodedFunctionCall = {
39
40
  /* eslint-enable camelcase */
40
41
 
41
42
  /** Assembles an entrypoint payload */
42
- export class EntrypointPayload {
43
+ export abstract class EntrypointPayload {
43
44
  #packedArguments: PackedValues[] = [];
44
45
  #functionCalls: EncodedFunctionCall[] = [];
45
46
  #nonce = Fr.random();
46
47
  #generatorIndex: number;
47
48
 
48
- private constructor(functionCalls: FunctionCall[], generatorIndex: number) {
49
+ protected constructor(functionCalls: FunctionCall[], generatorIndex: number) {
49
50
  for (const call of functionCalls) {
50
51
  this.#packedArguments.push(PackedValues.fromValues(call.args));
51
52
  }
@@ -53,9 +54,9 @@ export class EntrypointPayload {
53
54
  /* eslint-disable camelcase */
54
55
  this.#functionCalls = functionCalls.map((call, index) => ({
55
56
  args_hash: this.#packedArguments[index].hash,
56
- function_selector: call.functionData.selector.toField(),
57
+ function_selector: call.selector.toField(),
57
58
  target_address: call.to.toField(),
58
- is_public: !call.functionData.isPrivate,
59
+ is_public: call.type == FunctionType.PUBLIC,
59
60
  is_static: call.isStatic,
60
61
  }));
61
62
  /* eslint-enable camelcase */
@@ -92,18 +93,7 @@ export class EntrypointPayload {
92
93
  * Serializes the payload to an array of fields
93
94
  * @returns The fields of the payload
94
95
  */
95
- toFields(): Fr[] {
96
- return [
97
- ...this.#functionCalls.flatMap(call => [
98
- call.args_hash,
99
- call.function_selector,
100
- call.target_address,
101
- new Fr(call.is_public),
102
- new Fr(call.is_static),
103
- ]),
104
- this.#nonce,
105
- ];
106
- }
96
+ abstract toFields(): Fr[];
107
97
 
108
98
  /**
109
99
  * Hashes the payload
@@ -113,13 +103,24 @@ export class EntrypointPayload {
113
103
  return pedersenHash(this.toFields(), this.#generatorIndex);
114
104
  }
115
105
 
106
+ /** Serializes the function calls to an array of fields. */
107
+ protected functionCallsToFields() {
108
+ return this.#functionCalls.flatMap(call => [
109
+ call.args_hash,
110
+ call.function_selector,
111
+ call.target_address,
112
+ new Fr(call.is_public),
113
+ new Fr(call.is_static),
114
+ ]);
115
+ }
116
+
116
117
  /**
117
- * Creates an execution payload from a set of function calls
118
+ * Creates an execution payload for a dapp from a set of function calls
118
119
  * @param functionCalls - The function calls to execute
119
120
  * @returns The execution payload
120
121
  */
121
122
  static fromFunctionCalls(functionCalls: FunctionCall[]) {
122
- return new EntrypointPayload(functionCalls, 0);
123
+ return new AppEntrypointPayload(functionCalls, 0);
123
124
  }
124
125
 
125
126
  /**
@@ -131,18 +132,49 @@ export class EntrypointPayload {
131
132
  if (functionCalls.length > APP_MAX_CALLS) {
132
133
  throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`);
133
134
  }
134
- const paddedCalls = padArrayEnd(functionCalls, emptyFunctionCall(), APP_MAX_CALLS);
135
- return new EntrypointPayload(paddedCalls, GeneratorIndex.SIGNATURE_PAYLOAD);
135
+ const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS);
136
+ return new AppEntrypointPayload(paddedCalls, GeneratorIndex.SIGNATURE_PAYLOAD);
136
137
  }
137
138
 
138
139
  /**
139
140
  * Creates an execution payload to pay the fee for a transaction
141
+ * @param sender - The address sending this payload
140
142
  * @param feeOpts - The fee payment options
141
143
  * @returns The execution payload
142
144
  */
143
- static async fromFeeOptions(feeOpts?: FeeOptions) {
144
- const calls = feeOpts ? await feeOpts.paymentMethod.getFunctionCalls(feeOpts?.gasSettings) : [];
145
- const paddedCalls = padArrayEnd(calls, emptyFunctionCall(), FEE_MAX_CALLS);
146
- return new EntrypointPayload(paddedCalls, GeneratorIndex.FEE_PAYLOAD);
145
+ static async fromFeeOptions(sender: AztecAddress, feeOpts?: FeeOptions) {
146
+ const calls = (await feeOpts?.paymentMethod.getFunctionCalls(feeOpts?.gasSettings)) ?? [];
147
+ const feePayer = await feeOpts?.paymentMethod.getFeePayer(feeOpts?.gasSettings);
148
+ const isFeePayer = !!feePayer && feePayer.equals(sender);
149
+ const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS);
150
+ return new FeeEntrypointPayload(paddedCalls, GeneratorIndex.FEE_PAYLOAD, isFeePayer);
151
+ }
152
+ }
153
+
154
+ /** Entrypoint payload for app phase execution. */
155
+ class AppEntrypointPayload extends EntrypointPayload {
156
+ override toFields(): Fr[] {
157
+ return [...this.functionCallsToFields(), this.nonce];
158
+ }
159
+ }
160
+
161
+ /** Entrypoint payload for fee payment to be run during setup phase. */
162
+ class FeeEntrypointPayload extends EntrypointPayload {
163
+ #isFeePayer: boolean;
164
+
165
+ constructor(functionCalls: FunctionCall[], generatorIndex: number, isFeePayer: boolean) {
166
+ super(functionCalls, generatorIndex);
167
+ this.#isFeePayer = isFeePayer;
168
+ }
169
+
170
+ override toFields(): Fr[] {
171
+ return [...this.functionCallsToFields(), this.nonce, new Fr(this.#isFeePayer)];
147
172
  }
173
+
174
+ /* eslint-disable camelcase */
175
+ /** Whether the sender should be appointed as fee payer. */
176
+ get is_fee_payer() {
177
+ return this.#isFeePayer;
178
+ }
179
+ /* eslint-enable camelcase */
148
180
  }
@@ -6,19 +6,17 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
6
6
  * Holds information about how the fee for a transaction is to be paid.
7
7
  */
8
8
  export interface FeePaymentMethod {
9
- /**
10
- * The asset used to pay the fee.
11
- */
9
+ /** The asset used to pay the fee. */
12
10
  getAsset(): AztecAddress;
13
- /**
14
- * Address which will hold the fee payment.
15
- */
16
- getPaymentContract(): AztecAddress;
17
-
18
11
  /**
19
12
  * Creates a function call to pay the fee in the given asset.
20
13
  * @param gasSettings - The gas limits and max fees.
21
14
  * @returns The function call to pay the fee.
22
15
  */
23
16
  getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]>;
17
+ /**
18
+ * The expected fee payer for this tx.
19
+ * @param gasSettings - The gas limits and max fees.
20
+ */
21
+ getFeePayer(gasSettings: GasSettings): Promise<AztecAddress>;
24
22
  }
@@ -1,63 +1,24 @@
1
1
  import { type FunctionCall } from '@aztec/circuit-types';
2
- import { type AztecAddress, FunctionData, type GasSettings } from '@aztec/circuits.js';
3
- import { FunctionSelector } from '@aztec/foundation/abi';
4
- import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token';
2
+ import { type AztecAddress } from '@aztec/circuits.js';
3
+ import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token';
5
4
 
6
- import { type Wallet } from '../account/wallet.js';
7
5
  import { type FeePaymentMethod } from './fee_payment_method.js';
8
6
 
9
7
  /**
10
8
  * Pay fee directly in the native gas token.
11
9
  */
12
10
  export class NativeFeePaymentMethod implements FeePaymentMethod {
13
- #gasTokenAddress: AztecAddress;
11
+ constructor(protected sender: AztecAddress) {}
14
12
 
15
- private constructor(canonicalGasTokenAddress: AztecAddress) {
16
- this.#gasTokenAddress = canonicalGasTokenAddress;
17
- }
18
-
19
- static async create(wallet: Wallet): Promise<NativeFeePaymentMethod> {
20
- const nodeInfo = await wallet.getNodeInfo();
21
- return new NativeFeePaymentMethod(getCanonicalGasTokenAddress(nodeInfo.l1ContractAddresses.gasPortalAddress));
22
- }
23
-
24
- /**
25
- * Gets the native gas asset used to pay the fee.
26
- * @returns The asset used to pay the fee.
27
- */
28
13
  getAsset() {
29
- return this.#gasTokenAddress;
30
- }
31
-
32
- /**
33
- * The contract responsible for fee payment. This will be the same as the asset.
34
- * @returns The contract address responsible for holding the fee payment.
35
- */
36
- getPaymentContract() {
37
- return this.#gasTokenAddress;
14
+ return GasTokenAddress;
38
15
  }
39
16
 
40
- /**
41
- * Fee payments in the native gas token are always public.
42
- * @returns false
43
- */
44
- isPrivateFeePayment(): boolean {
45
- return false;
17
+ getFunctionCalls(): Promise<FunctionCall[]> {
18
+ return Promise.resolve([]);
46
19
  }
47
20
 
48
- /**
49
- * Creates a function call to pay the fee in gas token.
50
- * @param gasSettings - The gas settings.
51
- * @returns A function call
52
- */
53
- getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
54
- return Promise.resolve([
55
- {
56
- to: this.#gasTokenAddress,
57
- functionData: new FunctionData(FunctionSelector.fromSignature('pay_fee(Field)'), /*isPrivate=*/ false),
58
- isStatic: false,
59
- args: [gasSettings.getFeeLimit()],
60
- },
61
- ]);
21
+ getFeePayer(): Promise<AztecAddress> {
22
+ return Promise.resolve(this.sender);
62
23
  }
63
24
  }