@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
@@ -5,6 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
5
5
  import { Fr } from '@aztec/foundation/fields';
6
6
  import type { Logger } from '@aztec/foundation/log';
7
7
  import type { SiblingPath } from '@aztec/foundation/trees';
8
+ import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
8
9
  import { FeeJuicePortalAbi } from '@aztec/l1-artifacts/FeeJuicePortalAbi';
9
10
  import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
10
11
  import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi';
@@ -15,6 +16,8 @@ import type { PXE } from '@aztec/stdlib/interfaces/client';
15
16
 
16
17
  import { type GetContractReturnType, type Hex, getContract, toFunctionSelector } from 'viem';
17
18
 
19
+ import type { Wallet } from '../index.js';
20
+
18
21
  // docs:start:claim_type
19
22
  // docs:start:claim_type_amount
20
23
  /** L1 to L2 message info to claim it on L2. */
@@ -55,19 +58,39 @@ export async function generateClaimSecret(logger?: Logger): Promise<[Fr, Fr]> {
55
58
  /** Helper for managing an ERC20 on L1. */
56
59
  export class L1TokenManager {
57
60
  private contract: GetContractReturnType<typeof TestERC20Abi, ViemWalletClient>;
61
+ private handler: GetContractReturnType<typeof FeeAssetHandlerAbi, ViemWalletClient> | undefined;
58
62
 
59
63
  public constructor(
60
64
  /** Address of the ERC20 contract. */
61
- public readonly address: EthAddress,
65
+ public readonly tokenAddress: EthAddress,
66
+ /** Address of the handler/faucet contract. */
67
+ public readonly handlerAddress: EthAddress | undefined,
62
68
  private publicClient: ViemPublicClient,
63
69
  private walletClient: ViemWalletClient,
64
70
  private logger: Logger,
65
71
  ) {
66
72
  this.contract = getContract({
67
- address: this.address.toString(),
73
+ address: this.tokenAddress.toString(),
68
74
  abi: TestERC20Abi,
69
75
  client: this.walletClient,
70
76
  });
77
+ if (this.handlerAddress) {
78
+ this.handler = getContract({
79
+ address: this.handlerAddress.toString(),
80
+ abi: FeeAssetHandlerAbi,
81
+ client: this.walletClient,
82
+ });
83
+ }
84
+ }
85
+
86
+ /** Returns the amount of tokens available to mint via the handler.
87
+ * @throws if the handler is not provided.
88
+ */
89
+ public async getMintAmount() {
90
+ if (!this.handler) {
91
+ throw new Error('Minting handler was not provided');
92
+ }
93
+ return await this.handler.read.mintAmount();
71
94
  }
72
95
 
73
96
  /**
@@ -79,16 +102,18 @@ export class L1TokenManager {
79
102
  }
80
103
 
81
104
  /**
82
- * Mints tokens for the given address. Returns once the tx has been mined.
83
- * @param amount - Amount to mint.
105
+ * Mints a fixed amount of tokens for the given address. Returns once the tx has been mined.
84
106
  * @param address - Address to mint the tokens for.
85
107
  * @param addressName - Optional name of the address for logging.
86
108
  */
87
- public async mint(amount: bigint, address: Hex, addressName?: string) {
88
- this.logger.info(`Minting ${amount} tokens for ${stringifyEthAddress(address, addressName)}`);
89
- await this.publicClient.waitForTransactionReceipt({
90
- hash: await this.contract.write.mint([address, amount]),
91
- });
109
+ public async mint(address: Hex, addressName?: string) {
110
+ if (!this.handler) {
111
+ throw new Error('Minting handler was not provided');
112
+ }
113
+ const mintAmount = await this.getMintAmount();
114
+ this.logger.info(`Minting ${mintAmount} tokens for ${stringifyEthAddress(address, addressName)}`);
115
+ // NOTE: the handler mints a fixed amount.
116
+ await this.handler.write.mint([address]);
92
117
  }
93
118
 
94
119
  /**
@@ -113,11 +138,12 @@ export class L1FeeJuicePortalManager {
113
138
  constructor(
114
139
  portalAddress: EthAddress,
115
140
  tokenAddress: EthAddress,
141
+ handlerAddress: EthAddress,
116
142
  private readonly publicClient: ViemPublicClient,
117
143
  private readonly walletClient: ViemWalletClient,
118
144
  private readonly logger: Logger,
119
145
  ) {
120
- this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
146
+ this.tokenManager = new L1TokenManager(tokenAddress, handlerAddress, publicClient, walletClient, logger);
121
147
  this.contract = getContract({
122
148
  address: portalAddress.toString(),
123
149
  abi: FeeJuicePortalAbi,
@@ -136,16 +162,21 @@ export class L1FeeJuicePortalManager {
136
162
  * @param amount - Amount of tokens to send.
137
163
  * @param mint - Whether to mint the tokens before sending (only during testing).
138
164
  */
139
- public async bridgeTokensPublic(to: AztecAddress, amount: bigint, mint = false): Promise<L2AmountClaim> {
165
+ public async bridgeTokensPublic(to: AztecAddress, amount: bigint | undefined, mint = false): Promise<L2AmountClaim> {
140
166
  const [claimSecret, claimSecretHash] = await generateClaimSecret();
167
+ const mintableAmount = await this.tokenManager.getMintAmount();
168
+ const amountToBridge = amount ?? mintableAmount;
141
169
  if (mint) {
142
- await this.tokenManager.mint(amount, this.walletClient.account.address);
170
+ if (amountToBridge !== mintableAmount) {
171
+ throw new Error(`Minting amount must be ${mintableAmount}`);
172
+ }
173
+ await this.tokenManager.mint(this.walletClient.account.address);
143
174
  }
144
175
 
145
- await this.tokenManager.approve(amount, this.contract.address, 'FeeJuice Portal');
176
+ await this.tokenManager.approve(amountToBridge, this.contract.address, 'FeeJuice Portal');
146
177
 
147
178
  this.logger.info('Sending L1 Fee Juice to L2 to be claimed publicly');
148
- const args = [to.toString(), amount, claimSecretHash.toString()] as const;
179
+ const args = [to.toString(), amountToBridge, claimSecretHash.toString()] as const;
149
180
 
150
181
  await this.contract.simulate.depositToAztecPublic(args);
151
182
 
@@ -162,13 +193,13 @@ export class L1FeeJuicePortalManager {
162
193
  'DepositToAztecPublic',
163
194
  log =>
164
195
  log.args.secretHash === claimSecretHash.toString() &&
165
- log.args.amount === amount &&
196
+ log.args.amount === amountToBridge &&
166
197
  log.args.to === to.toString(),
167
198
  this.logger,
168
199
  );
169
200
 
170
201
  return {
171
- claimAmount: amount,
202
+ claimAmount: amountToBridge,
172
203
  claimSecret,
173
204
  claimSecretHash,
174
205
  messageHash: log.args.key,
@@ -178,26 +209,36 @@ export class L1FeeJuicePortalManager {
178
209
 
179
210
  /**
180
211
  * Creates a new instance
181
- * @param pxe - PXE client used for retrieving the L1 contract addresses.
212
+ * @param walletOrPxe - Wallet or PXE client used for retrieving the L1 contract addresses.
182
213
  * @param publicClient - L1 public client.
183
214
  * @param walletClient - L1 wallet client.
184
215
  * @param logger - Logger.
185
216
  */
186
217
  public static async new(
187
- pxe: PXE,
218
+ walletOrPxe: Wallet | PXE,
188
219
  publicClient: ViemPublicClient,
189
220
  walletClient: ViemWalletClient,
190
221
  logger: Logger,
191
222
  ): Promise<L1FeeJuicePortalManager> {
192
223
  const {
193
- l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress },
194
- } = await pxe.getNodeInfo();
224
+ l1ContractAddresses: { feeJuiceAddress, feeJuicePortalAddress, feeAssetHandlerAddress },
225
+ } = await walletOrPxe.getNodeInfo();
195
226
 
196
227
  if (feeJuiceAddress.isZero() || feeJuicePortalAddress.isZero()) {
197
228
  throw new Error('Portal or token not deployed on L1');
198
229
  }
230
+ if (!feeAssetHandlerAddress || feeAssetHandlerAddress.isZero()) {
231
+ throw new Error('Handler not deployed on L1, or handler address is zero');
232
+ }
199
233
 
200
- return new L1FeeJuicePortalManager(feeJuicePortalAddress, feeJuiceAddress, publicClient, walletClient, logger);
234
+ return new L1FeeJuicePortalManager(
235
+ feeJuicePortalAddress,
236
+ feeJuiceAddress,
237
+ feeAssetHandlerAddress,
238
+ publicClient,
239
+ walletClient,
240
+ logger,
241
+ );
201
242
  }
202
243
  }
203
244
 
@@ -209,11 +250,12 @@ export class L1ToL2TokenPortalManager {
209
250
  constructor(
210
251
  portalAddress: EthAddress,
211
252
  tokenAddress: EthAddress,
253
+ handlerAddress: EthAddress | undefined,
212
254
  protected publicClient: ViemPublicClient,
213
255
  protected walletClient: ViemWalletClient,
214
256
  protected logger: Logger,
215
257
  ) {
216
- this.tokenManager = new L1TokenManager(tokenAddress, publicClient, walletClient, logger);
258
+ this.tokenManager = new L1TokenManager(tokenAddress, handlerAddress, publicClient, walletClient, logger);
217
259
  this.portal = getContract({
218
260
  address: portalAddress.toString(),
219
261
  abi: TokenPortalAbi,
@@ -267,6 +309,7 @@ export class L1ToL2TokenPortalManager {
267
309
  };
268
310
  }
269
311
 
312
+ // docs:start:bridge_tokens_private
270
313
  /**
271
314
  * Bridges tokens from L1 to L2 privately. Handles token approvals. Returns once the tx has been mined.
272
315
  * @param to - Address to send the tokens to on L2.
@@ -278,6 +321,7 @@ export class L1ToL2TokenPortalManager {
278
321
  amount: bigint,
279
322
  mint = false,
280
323
  ): Promise<L2AmountClaimWithRecipient> {
324
+ // docs:end:bridge_tokens_private
281
325
  const [claimSecret, claimSecretHash] = await this.bridgeSetup(amount, mint);
282
326
 
283
327
  this.logger.info('Sending L1 tokens to L2 to be claimed privately');
@@ -312,7 +356,11 @@ export class L1ToL2TokenPortalManager {
312
356
 
313
357
  private async bridgeSetup(amount: bigint, mint: boolean) {
314
358
  if (mint) {
315
- await this.tokenManager.mint(amount, this.walletClient.account.address);
359
+ const mintableAmount = await this.tokenManager.getMintAmount();
360
+ if (amount !== mintableAmount) {
361
+ throw new Error(`Minting amount must be ${mintableAmount} for testing`);
362
+ }
363
+ await this.tokenManager.mint(this.walletClient.account.address);
316
364
  }
317
365
  await this.tokenManager.approve(amount, this.portal.address, 'TokenPortal');
318
366
  return generateClaimSecret();
@@ -326,12 +374,13 @@ export class L1TokenPortalManager extends L1ToL2TokenPortalManager {
326
374
  constructor(
327
375
  portalAddress: EthAddress,
328
376
  tokenAddress: EthAddress,
377
+ handlerAddress: EthAddress | undefined,
329
378
  outboxAddress: EthAddress,
330
379
  publicClient: ViemPublicClient,
331
380
  walletClient: ViemWalletClient,
332
381
  logger: Logger,
333
382
  ) {
334
- super(portalAddress, tokenAddress, publicClient, walletClient, logger);
383
+ super(portalAddress, tokenAddress, handlerAddress, publicClient, walletClient, logger);
335
384
  this.outbox = getContract({
336
385
  address: outboxAddress.toString(),
337
386
  abi: OutboxAbi,
@@ -1,9 +1,8 @@
1
+ import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
2
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
1
3
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
- import type { FunctionCall } from '@aztec/stdlib/abi';
3
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
5
 
5
- import type { FeePaymentMethod } from './fee_payment_method.js';
6
-
7
6
  // docs:start:fee_juice_method
8
7
  /**
9
8
  * Pay fee directly in the Fee Juice.
@@ -16,8 +15,8 @@ export class FeeJuicePaymentMethod implements FeePaymentMethod {
16
15
  return Promise.resolve(ProtocolContractAddress.FeeJuice);
17
16
  }
18
17
 
19
- getFunctionCalls(): Promise<FunctionCall[]> {
20
- return Promise.resolve([]);
18
+ getExecutionPayload(): Promise<ExecutionPayload> {
19
+ return Promise.resolve(ExecutionPayload.empty());
21
20
  }
22
21
 
23
22
  getFeePayer(): Promise<AztecAddress> {
@@ -1,6 +1,6 @@
1
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
1
2
  import { Fr } from '@aztec/foundation/fields';
2
3
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import type { FunctionCall } from '@aztec/stdlib/abi';
4
4
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
5
5
 
6
6
  import { getFeeJuice } from '../contract/protocol_contracts.js';
@@ -20,30 +20,34 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
20
20
  }
21
21
 
22
22
  /**
23
- * Creates a function call to pay the fee in Fee Juice.
24
- * @returns A function call
23
+ * Creates an execution payload to pay the fee in Fee Juice.
24
+ * @returns An execution payload that just contains the claim function call.
25
25
  */
26
- override async getFunctionCalls(): Promise<FunctionCall[]> {
26
+ override async getExecutionPayload(): Promise<ExecutionPayload> {
27
27
  const canonicalFeeJuice = await getFeeJuice(this.senderWallet);
28
28
  const selector = await FunctionSelector.fromNameAndParameters(
29
29
  canonicalFeeJuice.artifact.functions.find(f => f.name === 'claim')!,
30
30
  );
31
31
 
32
- return Promise.resolve([
33
- {
34
- to: ProtocolContractAddress.FeeJuice,
35
- name: 'claim',
36
- selector,
37
- isStatic: false,
38
- args: [
39
- this.senderWallet.getAddress().toField(),
40
- new Fr(this.claim.claimAmount),
41
- this.claim.claimSecret,
42
- new Fr(this.claim.messageLeafIndex),
43
- ],
44
- returnTypes: [],
45
- type: FunctionType.PRIVATE,
46
- },
47
- ]);
32
+ return new ExecutionPayload(
33
+ [
34
+ {
35
+ to: ProtocolContractAddress.FeeJuice,
36
+ name: 'claim',
37
+ selector,
38
+ isStatic: false,
39
+ args: [
40
+ this.senderWallet.getAddress().toField(),
41
+ new Fr(this.claim.claimAmount),
42
+ this.claim.claimSecret,
43
+ new Fr(this.claim.messageLeafIndex),
44
+ ],
45
+ returnTypes: [],
46
+ type: FunctionType.PRIVATE,
47
+ },
48
+ ],
49
+ [],
50
+ [],
51
+ );
48
52
  }
49
53
  }
@@ -1,12 +1,12 @@
1
+ import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
2
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
1
3
  import { Fr } from '@aztec/foundation/fields';
2
- import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
+ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
3
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
6
  import type { GasSettings } from '@aztec/stdlib/gas';
5
7
 
6
- import type { Wallet } from '../account/wallet.js';
7
- import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
8
- import { SignerlessWallet } from '../wallet/signerless_wallet.js';
9
- import type { FeePaymentMethod } from './fee_payment_method.js';
8
+ import type { Wallet } from '../wallet/wallet.js';
9
+ import { simulateWithoutSignature } from './utils.js';
10
10
 
11
11
  /**
12
12
  * Holds information about how the fee for a transaction is to be paid.
@@ -38,11 +38,10 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
38
38
  */
39
39
  getAsset(): Promise<AztecAddress> {
40
40
  if (!this.assetPromise) {
41
- // We use signer-less wallet because this function could be triggered before the associated account is deployed.
42
- const signerlessWallet = new SignerlessWallet(this.wallet);
43
-
44
- const interaction = new ContractFunctionInteraction(
45
- signerlessWallet,
41
+ // We use the utility method to avoid a signature because this function could be triggered
42
+ // before the associated account is deployed.
43
+ this.assetPromise = simulateWithoutSignature(
44
+ this.wallet,
46
45
  this.paymentContract,
47
46
  {
48
47
  name: 'get_accepted_asset',
@@ -68,9 +67,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
68
67
  isInitializer: false,
69
68
  },
70
69
  [],
71
- );
72
-
73
- this.assetPromise = interaction.simulate();
70
+ ) as Promise<AztecAddress>;
74
71
  }
75
72
  return this.assetPromise!;
76
73
  }
@@ -80,17 +77,17 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
80
77
  }
81
78
 
82
79
  /**
83
- * Creates a function call to pay the fee in the given asset.
80
+ * Creates an execution payload to pay the fee using a private function through an FPC in the desired asset
84
81
  * @param gasSettings - The gas settings.
85
- * @returns The function call to pay the fee.
82
+ * @returns An execution payload that contains the required function calls and auth witnesses.
86
83
  */
87
- async getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
84
+ async getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload> {
88
85
  // We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit
89
86
  // (maxFee) to be in token denomination.
90
87
  const maxFee = this.setMaxFeeToOne ? Fr.ONE : gasSettings.getFeeLimit();
91
88
  const nonce = Fr.random();
92
89
 
93
- await this.wallet.createAuthWit({
90
+ const witness = await this.wallet.createAuthWit({
94
91
  caller: this.paymentContract,
95
92
  action: {
96
93
  name: 'transfer_to_public',
@@ -103,16 +100,20 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
103
100
  },
104
101
  });
105
102
 
106
- return [
107
- {
108
- name: 'fee_entrypoint_private',
109
- to: this.paymentContract,
110
- selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
111
- type: FunctionType.PRIVATE,
112
- isStatic: false,
113
- args: [maxFee, nonce],
114
- returnTypes: [],
115
- },
116
- ];
103
+ return new ExecutionPayload(
104
+ [
105
+ {
106
+ name: 'fee_entrypoint_private',
107
+ to: this.paymentContract,
108
+ selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
109
+ type: FunctionType.PRIVATE,
110
+ isStatic: false,
111
+ args: [maxFee, nonce],
112
+ returnTypes: [],
113
+ },
114
+ ],
115
+ [witness],
116
+ [],
117
+ );
117
118
  }
118
119
  }
@@ -1,13 +1,12 @@
1
+ import type { FeePaymentMethod } from '@aztec/entrypoints/interfaces';
2
+ import { ExecutionPayload } from '@aztec/entrypoints/payload';
1
3
  import { Fr } from '@aztec/foundation/fields';
2
- import type { FunctionCall } from '@aztec/stdlib/abi';
3
4
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import type { GasSettings } from '@aztec/stdlib/gas';
5
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
+ import { GasSettings } from '@aztec/stdlib/gas';
6
7
 
7
- import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
8
8
  import type { AccountWallet } from '../wallet/account_wallet.js';
9
- import { SignerlessWallet } from '../wallet/signerless_wallet.js';
10
- import type { FeePaymentMethod } from './fee_payment_method.js';
9
+ import { simulateWithoutSignature } from './utils.js';
11
10
 
12
11
  /**
13
12
  * Holds information about how the fee for a transaction is to be paid.
@@ -32,11 +31,10 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
32
31
  */
33
32
  getAsset(): Promise<AztecAddress> {
34
33
  if (!this.assetPromise) {
35
- // We use signer-less wallet because this function could be triggered before the associated account is deployed.
36
- const signerlessWallet = new SignerlessWallet(this.wallet);
37
-
38
- const interaction = new ContractFunctionInteraction(
39
- signerlessWallet,
34
+ // We use the utility method to avoid a signature because this function could be triggered
35
+ // before the associated account is deployed.
36
+ this.assetPromise = simulateWithoutSignature(
37
+ this.wallet,
40
38
  this.paymentContract,
41
39
  {
42
40
  name: 'get_accepted_asset',
@@ -62,9 +60,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
62
60
  isInitializer: false,
63
61
  },
64
62
  [],
65
- );
66
-
67
- this.assetPromise = interaction.simulate();
63
+ ) as Promise<AztecAddress>;
68
64
  }
69
65
  return this.assetPromise!;
70
66
  }
@@ -74,11 +70,11 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
74
70
  }
75
71
 
76
72
  /**
77
- * Creates a function call to pay the fee in the given asset.
73
+ * Creates an execution payload to pay the fee using a public function through an FPC in the desired asset
78
74
  * @param gasSettings - The gas settings.
79
- * @returns The function call to pay the fee.
75
+ * @returns An execution payload that contains the required function calls.
80
76
  */
81
- async getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
77
+ async getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload> {
82
78
  const nonce = Fr.random();
83
79
  const maxFee = gasSettings.getFeeLimit();
84
80
 
@@ -98,17 +94,21 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
98
94
  true,
99
95
  );
100
96
 
101
- return [
102
- ...(await setPublicAuthWitInteraction.request()).calls,
103
- {
104
- name: 'fee_entrypoint_public',
105
- to: this.paymentContract,
106
- selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
107
- type: FunctionType.PRIVATE,
108
- isStatic: false,
109
- args: [maxFee, nonce],
110
- returnTypes: [],
111
- },
112
- ];
97
+ return new ExecutionPayload(
98
+ [
99
+ ...(await setPublicAuthWitInteraction.request()).calls,
100
+ {
101
+ name: 'fee_entrypoint_public',
102
+ to: this.paymentContract,
103
+ selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
104
+ type: FunctionType.PRIVATE,
105
+ isStatic: false,
106
+ args: [maxFee, nonce],
107
+ returnTypes: [],
108
+ },
109
+ ],
110
+ [],
111
+ [],
112
+ );
113
113
  }
114
114
  }
@@ -0,0 +1,39 @@
1
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
2
+ import { type FunctionAbi, decodeFromAbi } from '@aztec/stdlib/abi';
3
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { GasSettings } from '@aztec/stdlib/gas';
5
+
6
+ import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
7
+ import type { Wallet } from '../wallet/wallet.js';
8
+ import { FeeJuicePaymentMethod } from './fee_juice_payment_method.js';
9
+
10
+ /**
11
+ * Use a wallet to simulate a function avoiding the wallet's entrypoint, as a SignerlessWallet would do
12
+ * @param wallet - The wallet to use for the simulation.
13
+ * @param contractAddress - The address of the contract to call.
14
+ * @param abi - The ABI of the function to simulate.
15
+ * @param args - The arguments to pass to the function.
16
+ * @returns The return values of the function call.
17
+ */
18
+ export async function simulateWithoutSignature(
19
+ wallet: Wallet,
20
+ contractAddress: AztecAddress,
21
+ abi: FunctionAbi,
22
+ args: any[],
23
+ ) {
24
+ const interaction = new ContractFunctionInteraction(wallet, contractAddress, abi, args);
25
+
26
+ const request = await interaction.request();
27
+ const maxFeesPerGas = (await wallet.getCurrentBaseFees()).mul(1.5);
28
+ const paymentMethod = new FeeJuicePaymentMethod(AztecAddress.ZERO);
29
+ const gasSettings = GasSettings.default({ maxFeesPerGas });
30
+ const fee = { gasSettings, paymentMethod };
31
+
32
+ const { l1ChainId: chainId, protocolVersion } = await wallet.getNodeInfo();
33
+ const entrypoint = new DefaultEntrypoint(chainId, protocolVersion);
34
+ const signerlessTxExecutionRequest = await entrypoint.createTxExecutionRequest(request, fee, {});
35
+
36
+ const simulationResult = await wallet.simulateTx(signerlessTxExecutionRequest, false, undefined, undefined, true);
37
+ const rawReturnValues = simulationResult.getPrivateReturnValues().values;
38
+ return decodeFromAbi(abi.returnTypes, rawReturnValues!);
39
+ }
@@ -1,7 +1,6 @@
1
- import { GeneratorIndex } from '@aztec/constants';
2
- import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
3
1
  import { Fr } from '@aztec/foundation/fields';
4
2
  import type { FunctionCall } from '@aztec/stdlib/abi';
3
+ import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
5
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
5
  import { HashedValues } from '@aztec/stdlib/tx';
7
6
 
@@ -58,13 +57,13 @@ export const computeAuthWitMessageHash = async (intent: IntentInnerHash | Intent
58
57
  const version = metadata.version;
59
58
 
60
59
  if ('caller' in intent) {
61
- const action =
60
+ const fnCall =
62
61
  intent.action instanceof ContractFunctionInteraction ? (await intent.action.request()).calls[0] : intent.action;
63
62
  return computeOuterAuthWitHash(
64
- action.to,
63
+ fnCall.to,
65
64
  chainId,
66
65
  version,
67
- await computeInnerAuthWitHashFromAction(intent.caller, action),
66
+ await computeInnerAuthWitHashFromFunctionCall(intent.caller, fnCall),
68
67
  );
69
68
  } else {
70
69
  const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
@@ -73,39 +72,37 @@ export const computeAuthWitMessageHash = async (intent: IntentInnerHash | Intent
73
72
  };
74
73
  // docs:end:authwit_computeAuthWitMessageHash
75
74
 
76
- export const computeInnerAuthWitHashFromAction = async (caller: AztecAddress, action: FunctionCall) =>
77
- computeInnerAuthWitHash([
75
+ /**
76
+ * Computes the inner authwitness hash for a function call, for it to later be combined with the metadata
77
+ * required for the outer hash and eventually the full AuthWitness.
78
+ * @param caller - Who is going to be calling the function
79
+ * @param fnCall - The function call to compute the inner hash from
80
+ * @returns The inner hash for the function call
81
+ **/
82
+ export const computeInnerAuthWitHashFromFunctionCall = async (caller: AztecAddress, fnCall: FunctionCall) => {
83
+ return computeInnerAuthWitHash([
78
84
  caller.toField(),
79
- action.selector.toField(),
80
- (await HashedValues.fromValues(action.args)).hash,
85
+ fnCall.selector.toField(),
86
+ (await HashedValues.fromValues(fnCall.args)).hash,
81
87
  ]);
82
-
83
- /**
84
- * Compute the inner hash for an authentication witness.
85
- * This is the "intent" of the message, before siloed with the consumer.
86
- * It is used as part of the `computeAuthWitMessageHash` but can also be used
87
- * in case the message is not a "call" to a function, but arbitrary data.
88
- * @param args - The arguments to hash
89
- * @returns The inner hash for the witness
90
- */
91
- export const computeInnerAuthWitHash = (args: Fr[]) => {
92
- return poseidon2HashWithSeparator(args, GeneratorIndex.AUTHWIT_INNER);
93
88
  };
94
89
 
95
90
  /**
96
- * Compute the outer hash for an authentication witness.
97
- * This is the value siloed with its "consumer" and what the `on_behalf_of`
98
- * should be signing.
99
- * The consumer is who will be consuming the message, for token approvals it
100
- * is the token contract itself (because the token makes the call to check the approval).
101
- * It is used as part of the `computeAuthWitMessageHash` but can also be used
102
- * in case the message is not a "call" to a function, but arbitrary data.
103
- * @param consumer - The address that can "consume" the authwit
104
- * @param chainId - The chain id that can "consume" the authwit
105
- * @param version - The version that can "consume" the authwit
106
- * @param innerHash - The inner hash for the witness
107
- * @returns The outer hash for the witness
108
- */
109
- const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => {
110
- return poseidon2HashWithSeparator([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER);
91
+ * Computes the inner authwitness hash for an action, that can either be a ContractFunctionInteraction
92
+ * or an isolated FunctionCall. Since the former is just a wrapper around the latter, we can just extract
93
+ * the first (and only) call from the ContractFunctionInteraction and use it to compute the inner hash.
94
+ * @param caller - Who is going to be performing the action
95
+ * @param action - The ContractFunctionInteraction or FunctionCall to compute the inner hash for
96
+ * @returns The inner hash for the action
97
+ **/
98
+ export const computeInnerAuthWitHashFromAction = async (
99
+ caller: AztecAddress,
100
+ action: FunctionCall | ContractFunctionInteraction,
101
+ ) => {
102
+ action = action instanceof ContractFunctionInteraction ? (await action.request()).calls[0] : action;
103
+ return computeInnerAuthWitHash([
104
+ caller.toField(),
105
+ action.selector.toField(),
106
+ (await HashedValues.fromValues(action.args)).hash,
107
+ ]);
111
108
  };