@aztec/aztec.js 0.0.1-commit.f295ac2 → 0.0.1-commit.fc805bf

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 (137) hide show
  1. package/dest/account/account.d.ts +25 -40
  2. package/dest/account/account.d.ts.map +1 -1
  3. package/dest/account/account.js +19 -47
  4. package/dest/account/account_contract.d.ts +7 -8
  5. package/dest/account/account_contract.d.ts.map +1 -1
  6. package/dest/account/account_with_secret_key.d.ts +18 -7
  7. package/dest/account/account_with_secret_key.d.ts.map +1 -1
  8. package/dest/account/account_with_secret_key.js +21 -4
  9. package/dest/account/index.d.ts +3 -2
  10. package/dest/account/index.d.ts.map +1 -1
  11. package/dest/account/index.js +2 -0
  12. package/dest/account/signerless_account.d.ts +5 -6
  13. package/dest/account/signerless_account.d.ts.map +1 -1
  14. package/dest/account/signerless_account.js +8 -11
  15. package/dest/api/account.d.ts +2 -4
  16. package/dest/api/account.d.ts.map +1 -1
  17. package/dest/api/account.js +1 -3
  18. package/dest/api/authorization.d.ts +2 -2
  19. package/dest/api/authorization.d.ts.map +1 -1
  20. package/dest/api/authorization.js +1 -1
  21. package/dest/api/block.d.ts +2 -2
  22. package/dest/api/block.d.ts.map +1 -1
  23. package/dest/api/block.js +1 -1
  24. package/dest/api/contract.d.ts +16 -10
  25. package/dest/api/contract.d.ts.map +1 -1
  26. package/dest/api/contract.js +14 -8
  27. package/dest/api/keys.d.ts +1 -1
  28. package/dest/api/keys.js +1 -1
  29. package/dest/api/node.d.ts +8 -4
  30. package/dest/api/node.d.ts.map +1 -1
  31. package/dest/api/node.js +7 -3
  32. package/dest/api/tx.d.ts +2 -2
  33. package/dest/api/tx.d.ts.map +1 -1
  34. package/dest/api/tx.js +1 -1
  35. package/dest/api/wallet.d.ts +3 -2
  36. package/dest/api/wallet.d.ts.map +1 -1
  37. package/dest/api/wallet.js +2 -1
  38. package/dest/contract/base_contract_interaction.d.ts +8 -10
  39. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  40. package/dest/contract/base_contract_interaction.js +5 -17
  41. package/dest/contract/deploy_method.d.ts +63 -16
  42. package/dest/contract/deploy_method.d.ts.map +1 -1
  43. package/dest/contract/deploy_method.js +36 -19
  44. package/dest/contract/interaction_options.d.ts +42 -5
  45. package/dest/contract/interaction_options.d.ts.map +1 -1
  46. package/dest/contract/interaction_options.js +8 -1
  47. package/dest/contract/protocol_contracts/auth-registry.d.ts +1 -10
  48. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
  49. package/dest/contract/protocol_contracts/auth-registry.js +97 -467
  50. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -11
  51. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
  52. package/dest/contract/protocol_contracts/contract-class-registry.js +10 -422
  53. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
  54. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
  55. package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -482
  56. package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
  57. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
  58. package/dest/contract/protocol_contracts/fee-juice.js +14 -412
  59. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +3 -3
  60. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
  61. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +13 -14
  62. package/dest/contract/protocol_contracts/public-checks.d.ts +3 -3
  63. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
  64. package/dest/contract/protocol_contracts/public-checks.js +13 -22
  65. package/dest/contract/wait_for_proven.js +1 -1
  66. package/dest/contract/wait_opts.d.ts +16 -0
  67. package/dest/contract/wait_opts.d.ts.map +1 -0
  68. package/dest/contract/wait_opts.js +5 -0
  69. package/dest/utils/authwit.d.ts +8 -6
  70. package/dest/utils/authwit.d.ts.map +1 -1
  71. package/dest/utils/authwit.js +5 -9
  72. package/dest/utils/node.d.ts +12 -1
  73. package/dest/utils/node.d.ts.map +1 -1
  74. package/dest/utils/node.js +46 -0
  75. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +5 -8
  76. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
  77. package/dest/wallet/account_entrypoint_meta_payment_method.js +28 -43
  78. package/dest/wallet/account_manager.d.ts +1 -7
  79. package/dest/wallet/account_manager.d.ts.map +1 -1
  80. package/dest/wallet/account_manager.js +5 -11
  81. package/dest/wallet/capabilities.d.ts +444 -0
  82. package/dest/wallet/capabilities.d.ts.map +1 -0
  83. package/dest/wallet/capabilities.js +3 -0
  84. package/dest/wallet/deploy_account_method.d.ts +34 -6
  85. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  86. package/dest/wallet/deploy_account_method.js +7 -5
  87. package/dest/wallet/index.d.ts +2 -1
  88. package/dest/wallet/index.d.ts.map +1 -1
  89. package/dest/wallet/index.js +1 -0
  90. package/dest/wallet/wallet.d.ts +1358 -20
  91. package/dest/wallet/wallet.d.ts.map +1 -1
  92. package/dest/wallet/wallet.js +136 -5
  93. package/package.json +9 -9
  94. package/src/account/account.ts +34 -58
  95. package/src/account/account_contract.ts +6 -7
  96. package/src/account/account_with_secret_key.ts +33 -8
  97. package/src/account/index.ts +2 -1
  98. package/src/account/signerless_account.ts +13 -12
  99. package/src/api/account.ts +9 -3
  100. package/src/api/authorization.ts +1 -0
  101. package/src/api/block.ts +1 -1
  102. package/src/api/contract.ts +22 -7
  103. package/src/api/keys.ts +2 -2
  104. package/src/api/node.ts +7 -3
  105. package/src/api/tx.ts +2 -0
  106. package/src/api/wallet.ts +43 -0
  107. package/src/contract/base_contract_interaction.ts +27 -15
  108. package/src/contract/deploy_method.ts +115 -23
  109. package/src/contract/interaction_options.ts +49 -4
  110. package/src/contract/protocol_contracts/auth-registry.ts +45 -236
  111. package/src/contract/protocol_contracts/contract-class-registry.ts +3 -204
  112. package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -233
  113. package/src/contract/protocol_contracts/fee-juice.ts +4 -202
  114. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +6 -12
  115. package/src/contract/protocol_contracts/public-checks.ts +6 -14
  116. package/src/contract/wait_for_proven.ts +1 -1
  117. package/src/contract/wait_opts.ts +21 -0
  118. package/src/utils/authwit.ts +19 -7
  119. package/src/utils/node.ts +62 -0
  120. package/src/wallet/account_entrypoint_meta_payment_method.ts +28 -60
  121. package/src/wallet/account_manager.ts +5 -13
  122. package/src/wallet/capabilities.ts +491 -0
  123. package/src/wallet/deploy_account_method.ts +37 -13
  124. package/src/wallet/index.ts +1 -0
  125. package/src/wallet/wallet.ts +149 -14
  126. package/dest/account/interface.d.ts +0 -19
  127. package/dest/account/interface.d.ts.map +0 -1
  128. package/dest/account/interface.js +0 -5
  129. package/dest/contract/deploy_sent_tx.d.ts +0 -48
  130. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  131. package/dest/contract/deploy_sent_tx.js +0 -46
  132. package/dest/contract/sent_tx.d.ts +0 -50
  133. package/dest/contract/sent_tx.d.ts.map +0 -1
  134. package/dest/contract/sent_tx.js +0 -90
  135. package/src/account/interface.ts +0 -25
  136. package/src/contract/deploy_sent_tx.ts +0 -75
  137. package/src/contract/sent_tx.ts +0 -129
@@ -93,22 +93,14 @@ const PublicChecksContractArtifact: ContractArtifact = {
93
93
  },
94
94
  '4261968856572588300': { error_kind: 'string', string: 'Value does not fit in field' },
95
95
  '4440399188109668273': { error_kind: 'string', string: 'Input length must be a multiple of 32' },
96
+ '9530675838293881722': { error_kind: 'string', string: 'Writer did not write all data' },
96
97
  '9791669845391776238': {
97
98
  error_kind: 'string',
98
99
  string: '0 has a square root; you cannot claim it is not square',
99
100
  },
100
- '9885968605480832328': {
101
- error_kind: 'string',
102
- string: 'Attempted to read past the length of a CapsuleArray',
103
- },
104
101
  '10135509984888824963': { error_kind: 'fmtstring', length: 58, item_types: [{ kind: 'field' }] },
105
102
  '10791800398362570014': { error_kind: 'string', string: 'extend_from_bounded_vec out of bounds' },
106
- '11021520179822076911': {
107
- error_kind: 'string',
108
- string: 'Attempted to delete past the length of a CapsuleArray',
109
- },
110
103
  '11692359521570349358': { error_kind: 'fmtstring', length: 40, item_types: [] },
111
- '12327971061804302172': { error_kind: 'fmtstring', length: 98, item_types: [] },
112
104
  '12469291177396340830': { error_kind: 'string', string: 'call to assert_max_bit_size' },
113
105
  '12913276134398371456': { error_kind: 'string', string: 'push out of bounds' },
114
106
  '13557316507370296400': {
@@ -155,10 +147,8 @@ const PublicChecksContractArtifact: ContractArtifact = {
155
147
  },
156
148
  '12511970388699677811': { error_kind: 'fmtstring', length: 27, item_types: [{ kind: 'field' }] },
157
149
  '13950240626967988787': { error_kind: 'string', string: 'Timestamp mismatch.' },
158
- '14990209321349310352': { error_kind: 'string', string: 'attempt to add with overflow' },
159
150
  '15015303112667403944': { error_kind: 'fmtstring', length: 17, item_types: [] },
160
151
  '15764276373176857197': { error_kind: 'string', string: 'Stack too deep' },
161
- '16431471497789672479': { error_kind: 'string', string: 'Index out of bounds' },
162
152
  },
163
153
  },
164
154
  bytecode: Buffer.from([]),
@@ -167,7 +157,7 @@ const PublicChecksContractArtifact: ContractArtifact = {
167
157
  {
168
158
  ...{
169
159
  functionType: FunctionType.UTILITY,
170
- name: 'sync_private_state',
160
+ name: 'sync_state',
171
161
  isOnlySelf: false,
172
162
  isStatic: false,
173
163
  isInitializer: false,
@@ -194,6 +184,7 @@ const PublicChecksContractArtifact: ContractArtifact = {
194
184
  },
195
185
  '4261968856572588300': { error_kind: 'string', string: 'Value does not fit in field' },
196
186
  '4440399188109668273': { error_kind: 'string', string: 'Input length must be a multiple of 32' },
187
+ '9530675838293881722': { error_kind: 'string', string: 'Writer did not write all data' },
197
188
  '9791669845391776238': {
198
189
  error_kind: 'string',
199
190
  string: '0 has a square root; you cannot claim it is not square',
@@ -230,6 +221,7 @@ const PublicChecksContractArtifact: ContractArtifact = {
230
221
  length: 133,
231
222
  item_types: [{ kind: 'integer', sign: 'unsigned', width: 32 }],
232
223
  },
224
+ '17655676068928457687': { error_kind: 'string', string: 'Reader did not read all data' },
233
225
  },
234
226
  },
235
227
  bytecode: Buffer.from([]),
@@ -318,7 +310,7 @@ export class PublicChecksContract extends ContractBase {
318
310
  /** public_dispatch(selector: field) */
319
311
  public_dispatch: ((selector: FieldLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
320
312
 
321
- /** sync_private_state() */
322
- sync_private_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
313
+ /** sync_state() */
314
+ sync_state: (() => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
323
315
  };
324
316
  }
@@ -2,7 +2,7 @@ import { retryUntil } from '@aztec/foundation/retry';
2
2
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
3
  import type { TxReceipt } from '@aztec/stdlib/tx';
4
4
 
5
- import { DefaultWaitOpts } from './sent_tx.js';
5
+ import { DefaultWaitOpts } from './wait_opts.js';
6
6
 
7
7
  /**
8
8
  * Options for waiting for a transaction to be proven.
@@ -0,0 +1,21 @@
1
+ import type { TxStatus } from '@aztec/stdlib/tx';
2
+
3
+ /** Options related to waiting for a tx. */
4
+ export type WaitOpts = {
5
+ /** The amount of time to ignore TxStatus.DROPPED receipts (in seconds) due to the presumption that it is being propagated by the p2p network. Defaults to 5. */
6
+ ignoreDroppedReceiptsFor?: number;
7
+ /** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
8
+ timeout?: number;
9
+ /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
10
+ interval?: number;
11
+ /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
12
+ dontThrowOnRevert?: boolean;
13
+ /** The minimum inclusion status to wait for. If set, waits until the receipt reaches this status or higher. Defaults to CHECKPOINTED. */
14
+ waitForStatus?: TxStatus;
15
+ };
16
+
17
+ export const DefaultWaitOpts: WaitOpts = {
18
+ ignoreDroppedReceiptsFor: 5,
19
+ timeout: 300,
20
+ interval: 1,
21
+ };
@@ -5,16 +5,18 @@ import { type ABIParameterVisibility, type FunctionAbi, type FunctionCall, Funct
5
5
  import { AuthWitness, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
6
6
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
7
  import { computeVarArgsHash } from '@aztec/stdlib/hash';
8
- import type { TxProfileResult } from '@aztec/stdlib/tx';
8
+ import type { TxHash, TxProfileResult, TxReceipt } from '@aztec/stdlib/tx';
9
9
 
10
10
  import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
11
11
  import type {
12
+ InteractionWaitOptions,
12
13
  ProfileInteractionOptions,
13
14
  SendInteractionOptions,
15
+ SendInteractionOptionsWithoutWait,
16
+ SendReturn,
14
17
  SimulateInteractionOptions,
15
18
  SimulationReturn,
16
19
  } from '../contract/interaction_options.js';
17
- import type { SentTx } from '../contract/sent_tx.js';
18
20
  import type { Wallet } from '../wallet/index.js';
19
21
 
20
22
  /** Intent with an inner hash */
@@ -42,7 +44,7 @@ export type ContractFunctionInteractionCallIntent = {
42
44
  };
43
45
 
44
46
  /** Identifies ContractFunctionInteractionCallIntents */
45
- function isContractFunctionIntractionCallIntent(
47
+ export function isContractFunctionInteractionCallIntent(
46
48
  messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
47
49
  ): messageHashOrIntent is ContractFunctionInteractionCallIntent {
48
50
  return (
@@ -81,7 +83,7 @@ export const computeAuthWitMessageHash = async (
81
83
  const version = metadata.version;
82
84
 
83
85
  if ('caller' in intent) {
84
- const call = isContractFunctionIntractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
86
+ const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
85
87
  return computeOuterAuthWitHash(
86
88
  call.to,
87
89
  chainId,
@@ -154,7 +156,7 @@ export async function lookupValidity(
154
156
  }> {
155
157
  let innerHash, consumer;
156
158
  if ('caller' in intent) {
157
- const call = isContractFunctionIntractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
159
+ const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
158
160
  innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
159
161
  consumer = call.to;
160
162
  } else {
@@ -286,9 +288,19 @@ export class SetPublicAuthwitContractInteraction extends ContractFunctionInterac
286
288
  * Overrides the send method, adding the sender of the authwit (authorizer) as from
287
289
  * and preventing misuse
288
290
  * @param options - An optional object containing 'fee' options information
289
- * @returns A SentTx instance for tracking the transaction status and information.
291
+ * @returns A TxReceipt (if wait is true/undefined) or TxHash (if wait is false)
290
292
  */
291
- public override send(options: Omit<SendInteractionOptions, 'from'> = {}): SentTx {
293
+ // Overload for when wait is not specified at all - returns TxReceipt
294
+ public override send(options?: Omit<SendInteractionOptionsWithoutWait, 'from'>): Promise<TxReceipt>;
295
+ // Generic overload for explicit wait values
296
+ // eslint-disable-next-line jsdoc/require-jsdoc
297
+ public override send<W extends InteractionWaitOptions>(
298
+ options?: Omit<SendInteractionOptions<W>, 'from'>,
299
+ ): Promise<SendReturn<W>>;
300
+ // eslint-disable-next-line jsdoc/require-jsdoc
301
+ public override send(
302
+ options?: Omit<SendInteractionOptions<InteractionWaitOptions>, 'from'>,
303
+ ): Promise<TxReceipt | TxHash> {
292
304
  return super.send({ ...options, from: this.from });
293
305
  }
294
306
 
package/src/utils/node.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { Logger } from '@aztec/foundation/log';
2
2
  import { retryUntil } from '@aztec/foundation/retry';
3
3
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
4
+ import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
5
+ import { SortedTxStatuses, TxStatus } from '@aztec/stdlib/tx';
6
+
7
+ import { DefaultWaitOpts, type WaitOpts } from '../contract/wait_opts.js';
4
8
 
5
9
  export const waitForNode = async (node: AztecNode, logger?: Logger) => {
6
10
  await retryUntil(async () => {
@@ -16,4 +20,62 @@ export const waitForNode = async (node: AztecNode, logger?: Logger) => {
16
20
  }, 'RPC Get Node Info');
17
21
  };
18
22
 
23
+ /** Returns true if the receipt status is at least the desired status level. */
24
+ function hasReachedStatus(receipt: TxReceipt, desiredStatus: TxStatus): boolean {
25
+ return SortedTxStatuses.indexOf(receipt.status) >= SortedTxStatuses.indexOf(desiredStatus);
26
+ }
27
+
28
+ /**
29
+ * Waits for a transaction to be mined and returns its receipt.
30
+ * @param node - The Aztec node to query for transaction status
31
+ * @param txHash - The hash of the transaction to wait for
32
+ * @param opts - Optional configuration for waiting behavior
33
+ * @returns The transaction receipt
34
+ * @throws If the transaction fails and dontThrowOnRevert is not set
35
+ */
36
+ export async function waitForTx(node: AztecNode, txHash: TxHash, opts?: WaitOpts): Promise<TxReceipt> {
37
+ const startTime = Date.now();
38
+ const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
39
+ const waitForStatus = opts?.waitForStatus ?? TxStatus.CHECKPOINTED;
40
+
41
+ const receipt = await retryUntil(
42
+ async () => {
43
+ const txReceipt = await node.getTxReceipt(txHash);
44
+ // If receipt is not yet available, try again
45
+ if (txReceipt.isPending()) {
46
+ return undefined;
47
+ }
48
+ // If the tx was "dropped", either return it or ignore based on timing.
49
+ // We can ignore it at first because the transaction may have been sent to node 1, and now we're asking node 2 for the receipt.
50
+ // If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
51
+ if (txReceipt.isDropped()) {
52
+ const elapsedSeconds = (Date.now() - startTime) / 1000;
53
+ if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
54
+ return txReceipt;
55
+ }
56
+ return undefined;
57
+ }
58
+ // Check if the receipt has reached the desired status level
59
+ if (!hasReachedStatus(txReceipt, waitForStatus)) {
60
+ return undefined;
61
+ }
62
+ return txReceipt;
63
+ },
64
+ 'isMined',
65
+ opts?.timeout ?? DefaultWaitOpts.timeout,
66
+ opts?.interval ?? DefaultWaitOpts.interval,
67
+ );
68
+
69
+ if (!receipt.isMined()) {
70
+ throw new Error(`Transaction ${txHash.toString()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`);
71
+ }
72
+ if (!receipt.hasExecutionSucceeded() && !opts?.dontThrowOnRevert) {
73
+ throw new Error(
74
+ `Transaction ${txHash.toString()} reverted: ${receipt.executionResult}. Reason: ${receipt.error ?? 'unknown'}`,
75
+ );
76
+ }
77
+
78
+ return receipt;
79
+ }
80
+
19
81
  export { createAztecNodeClient, type AztecNode } from '@aztec/stdlib/interfaces/client';
@@ -1,20 +1,11 @@
1
1
  import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
2
- import { EncodedAppEntrypointCalls } from '@aztec/entrypoints/encoding';
3
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
- import {
5
- type ContractArtifact,
6
- type FunctionArtifact,
7
- FunctionCall,
8
- FunctionSelector,
9
- encodeArguments,
10
- getFunctionArtifactByName,
11
- } from '@aztec/stdlib/abi';
12
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
4
  import type { GasSettings } from '@aztec/stdlib/gas';
14
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
15
6
 
7
+ import type { Account } from '../account/account.js';
16
8
  import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
17
- import type { Wallet } from './index.js';
18
9
 
19
10
  /**
20
11
  * Fee payment method that allows an account contract to pay for its own deployment
@@ -33,11 +24,9 @@ import type { Wallet } from './index.js';
33
24
  */
34
25
  export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
35
26
  constructor(
36
- private wallet: Wallet,
37
- private artifact: ContractArtifact,
38
- private feePaymentNameOrArtifact: string | FunctionArtifact,
39
- private accountAddress: AztecAddress,
27
+ private account: Account,
40
28
  private paymentMethod?: FeePaymentMethod,
29
+ private feeEntrypointOptions?: any,
41
30
  ) {}
42
31
 
43
32
  getAsset(): Promise<AztecAddress> {
@@ -45,59 +34,38 @@ export class AccountEntrypointMetaPaymentMethod implements FeePaymentMethod {
45
34
  }
46
35
 
47
36
  async getExecutionPayload(): Promise<ExecutionPayload> {
48
- // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
49
- // It can be empty because the account might attempt to pay for the tx fee using its own
50
- // FeeJuice balance
51
- const { calls: feeCalls, authWitnesses: feeAuthwitnesses } =
52
- (await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
53
- // Encode the calls for the fee
54
- const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.accountAddress;
55
- const isFeePayer = feePayer.equals(this.accountAddress);
56
- let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
57
- if (isFeePayer) {
58
- // If the account is the fee payer, and the incoming fee payload has calls
59
- // it can only be FeeJuicePaymentMethodWithClaim
60
- // If the payload has no calls, it's paying using
61
- // its own fee juice balance
62
- accountFeePaymentMethodOptions =
63
- feeCalls.length === 0
64
- ? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
65
- : AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
66
- }
67
- const feeEncodedCalls = await EncodedAppEntrypointCalls.create(feeCalls);
37
+ // Get the execution payload for the fee
38
+ const innerPayload = (await this.paymentMethod?.getExecutionPayload()) ?? ExecutionPayload.empty();
68
39
 
69
- // Get the entrypoint args
70
- const args = [feeEncodedCalls, accountFeePaymentMethodOptions, false];
71
- const feePaymentArtifact =
72
- typeof this.feePaymentNameOrArtifact === 'string'
73
- ? getFunctionArtifactByName(this.artifact, this.feePaymentNameOrArtifact)
74
- : this.feePaymentNameOrArtifact;
40
+ // If no fee entrypoint options were provided, compute them based on the wrapped payment method
41
+ // This mimics how the actual account contract works when invoked directly:
42
+ // - If we are the fee payer, are there calls in the inner payload? In that case, those calls can
43
+ // only be claiming fee juice, so we use FEE_JUICE_WITH_CLAIM
44
+ // - If we are the fee payer, but there are no calls, then we assume the account already has
45
+ // fee juice and can pay directly with PREEXISTING_FEE_JUICE
46
+ // - If we are not the fee payer, then EXTERNAL is used
47
+ let options = this.feeEntrypointOptions;
48
+ if (!options) {
49
+ const feePayer = (await this.paymentMethod?.getFeePayer()) ?? this.account.getAddress();
50
+ const isFeePayer = feePayer.equals(this.account.getAddress());
75
51
 
76
- const entrypointCall = new FunctionCall(
77
- feePaymentArtifact.name,
78
- this.accountAddress,
79
- await FunctionSelector.fromNameAndParameters(feePaymentArtifact.name, feePaymentArtifact.parameters),
80
- feePaymentArtifact.functionType,
81
- false /** hideMsgSender -- set to `false`, because it's not applicable for an entrypoint function (only for enqueued public calls) */,
82
- feePaymentArtifact.isStatic,
83
- encodeArguments(feePaymentArtifact, args),
84
- feePaymentArtifact.returnTypes,
85
- );
52
+ let accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.EXTERNAL;
53
+ if (isFeePayer) {
54
+ accountFeePaymentMethodOptions =
55
+ innerPayload.calls.length === 0
56
+ ? AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE
57
+ : AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM;
58
+ }
86
59
 
87
- // Compute the authwitness required to verify the combined payload
88
- const payloadAuthWitness = await this.wallet.createAuthWit(this.accountAddress, await feeEncodedCalls.hash());
60
+ options = { feePaymentMethodOptions: accountFeePaymentMethodOptions };
61
+ }
89
62
 
90
- return new ExecutionPayload(
91
- [entrypointCall],
92
- [payloadAuthWitness, ...feeAuthwitnesses],
93
- [],
94
- feeEncodedCalls.hashedArguments,
95
- feePayer,
96
- );
63
+ // Use the generic wrapping mechanism from the account interface
64
+ return this.account.wrapExecutionPayload(innerPayload, options);
97
65
  }
98
66
 
99
67
  getFeePayer(): Promise<AztecAddress> {
100
- return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.accountAddress);
68
+ return this.paymentMethod?.getFeePayer() ?? Promise.resolve(this.account.getAddress());
101
69
  }
102
70
 
103
71
  getGasSettings(): GasSettings | undefined {
@@ -9,7 +9,6 @@ import { deriveKeys } from '@aztec/stdlib/keys';
9
9
  import type { AccountContract } from '../account/account_contract.js';
10
10
  import { AccountWithSecretKey } from '../account/account_with_secret_key.js';
11
11
  import type { Salt } from '../account/index.js';
12
- import type { AccountInterface } from '../account/interface.js';
13
12
  import { Contract } from '../contract/contract.js';
14
13
  import { DeployAccountMethod } from './deploy_account_method.js';
15
14
  import type { Wallet } from './wallet.js';
@@ -58,16 +57,6 @@ export class AccountManager {
58
57
  return this.getPublicKeys().hash();
59
58
  }
60
59
 
61
- /**
62
- * Returns the entrypoint for this account as defined by its account contract.
63
- * @returns An entrypoint.
64
- */
65
- public async getAccountInterface(): Promise<AccountInterface> {
66
- const chainInfo = await this.wallet.getChainInfo();
67
- const completeAddress = await this.getCompleteAddress();
68
- return this.accountContract.getInterface(completeAddress, chainInfo);
69
- }
70
-
71
60
  /**
72
61
  * Gets the calculated complete address associated with this account.
73
62
  * Does not require the account to have been published for public execution.
@@ -103,8 +92,9 @@ export class AccountManager {
103
92
  * @returns A Wallet instance.
104
93
  */
105
94
  public async getAccount(): Promise<AccountWithSecretKey> {
106
- const accountInterface = await this.getAccountInterface();
107
- return new AccountWithSecretKey(accountInterface, this.secretKey, this.salt);
95
+ const completeAddress = await this.getCompleteAddress();
96
+ const account = this.accountContract.getAccount(completeAddress);
97
+ return new AccountWithSecretKey(account, this.secretKey, this.salt);
108
98
  }
109
99
 
110
100
  /**
@@ -134,12 +124,14 @@ export class AccountManager {
134
124
  constructorArgs: undefined,
135
125
  };
136
126
 
127
+ const account = await this.getAccount();
137
128
  return new DeployAccountMethod(
138
129
  this.getPublicKeys(),
139
130
  this.wallet,
140
131
  artifact,
141
132
  instance => Contract.at(instance.address, artifact, this.wallet),
142
133
  new Fr(this.salt),
134
+ account,
143
135
  constructorArgs,
144
136
  constructorName,
145
137
  );