@aztec-labs/aztec.js 6.0.0-nightly.20260829

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 (275) hide show
  1. package/README.md +44 -0
  2. package/dest/account/account.d.ts +44 -0
  3. package/dest/account/account.d.ts.map +1 -0
  4. package/dest/account/account.js +31 -0
  5. package/dest/account/account_contract.d.ts +49 -0
  6. package/dest/account/account_contract.d.ts.map +1 -0
  7. package/dest/account/account_contract.js +20 -0
  8. package/dest/account/index.d.ts +11 -0
  9. package/dest/account/index.d.ts.map +1 -0
  10. package/dest/account/index.js +6 -0
  11. package/dest/api/abi.d.ts +4 -0
  12. package/dest/api/abi.d.ts.map +1 -0
  13. package/dest/api/abi.js +1 -0
  14. package/dest/api/account.d.ts +5 -0
  15. package/dest/api/account.d.ts.map +1 -0
  16. package/dest/api/account.js +3 -0
  17. package/dest/api/addresses.d.ts +4 -0
  18. package/dest/api/addresses.d.ts.map +1 -0
  19. package/dest/api/addresses.js +3 -0
  20. package/dest/api/authorization.d.ts +5 -0
  21. package/dest/api/authorization.d.ts.map +1 -0
  22. package/dest/api/authorization.js +4 -0
  23. package/dest/api/block.d.ts +3 -0
  24. package/dest/api/block.d.ts.map +1 -0
  25. package/dest/api/block.js +2 -0
  26. package/dest/api/contract.d.ts +48 -0
  27. package/dest/api/contract.d.ts.map +1 -0
  28. package/dest/api/contract.js +46 -0
  29. package/dest/api/crypto.d.ts +2 -0
  30. package/dest/api/crypto.d.ts.map +1 -0
  31. package/dest/api/crypto.js +1 -0
  32. package/dest/api/deployment.d.ts +4 -0
  33. package/dest/api/deployment.d.ts.map +1 -0
  34. package/dest/api/deployment.js +3 -0
  35. package/dest/api/eth_address.d.ts +2 -0
  36. package/dest/api/eth_address.d.ts.map +1 -0
  37. package/dest/api/eth_address.js +1 -0
  38. package/dest/api/ethereum.d.ts +2 -0
  39. package/dest/api/ethereum.d.ts.map +1 -0
  40. package/dest/api/ethereum.js +1 -0
  41. package/dest/api/event_cursor.d.ts +44 -0
  42. package/dest/api/event_cursor.d.ts.map +1 -0
  43. package/dest/api/event_cursor.js +42 -0
  44. package/dest/api/events.d.ts +36 -0
  45. package/dest/api/events.d.ts.map +1 -0
  46. package/dest/api/events.js +59 -0
  47. package/dest/api/fee.d.ts +6 -0
  48. package/dest/api/fee.d.ts.map +1 -0
  49. package/dest/api/fee.js +4 -0
  50. package/dest/api/fee_testing.d.ts +2 -0
  51. package/dest/api/fee_testing.d.ts.map +1 -0
  52. package/dest/api/fee_testing.js +1 -0
  53. package/dest/api/fields.d.ts +4 -0
  54. package/dest/api/fields.d.ts.map +1 -0
  55. package/dest/api/fields.js +3 -0
  56. package/dest/api/keys.d.ts +4 -0
  57. package/dest/api/keys.d.ts.map +1 -0
  58. package/dest/api/keys.js +3 -0
  59. package/dest/api/log.d.ts +3 -0
  60. package/dest/api/log.d.ts.map +1 -0
  61. package/dest/api/log.js +2 -0
  62. package/dest/api/messaging.d.ts +3 -0
  63. package/dest/api/messaging.d.ts.map +1 -0
  64. package/dest/api/messaging.js +2 -0
  65. package/dest/api/node.d.ts +25 -0
  66. package/dest/api/node.d.ts.map +1 -0
  67. package/dest/api/node.js +22 -0
  68. package/dest/api/note.d.ts +2 -0
  69. package/dest/api/note.d.ts.map +1 -0
  70. package/dest/api/note.js +1 -0
  71. package/dest/api/protocol.d.ts +6 -0
  72. package/dest/api/protocol.d.ts.map +1 -0
  73. package/dest/api/protocol.js +5 -0
  74. package/dest/api/trees.d.ts +3 -0
  75. package/dest/api/trees.d.ts.map +1 -0
  76. package/dest/api/trees.js +2 -0
  77. package/dest/api/tx.d.ts +3 -0
  78. package/dest/api/tx.d.ts.map +1 -0
  79. package/dest/api/tx.js +1 -0
  80. package/dest/api/utils.d.ts +13 -0
  81. package/dest/api/utils.d.ts.map +1 -0
  82. package/dest/api/utils.js +12 -0
  83. package/dest/api/wallet.d.ts +8 -0
  84. package/dest/api/wallet.d.ts.map +1 -0
  85. package/dest/api/wallet.js +7 -0
  86. package/dest/authorization/call_authorization_request.d.ts +46 -0
  87. package/dest/authorization/call_authorization_request.d.ts.map +1 -0
  88. package/dest/authorization/call_authorization_request.js +72 -0
  89. package/dest/contract/base_contract_interaction.d.ts +32 -0
  90. package/dest/contract/base_contract_interaction.d.ts.map +1 -0
  91. package/dest/contract/base_contract_interaction.js +24 -0
  92. package/dest/contract/batch_call.d.ts +27 -0
  93. package/dest/contract/batch_call.d.ts.map +1 -0
  94. package/dest/contract/batch_call.js +152 -0
  95. package/dest/contract/checker.d.ts +11 -0
  96. package/dest/contract/checker.d.ts.map +1 -0
  97. package/dest/contract/checker.js +107 -0
  98. package/dest/contract/contract.d.ts +33 -0
  99. package/dest/contract/contract.d.ts.map +1 -0
  100. package/dest/contract/contract.js +36 -0
  101. package/dest/contract/contract_base.d.ts +51 -0
  102. package/dest/contract/contract_base.d.ts.map +1 -0
  103. package/dest/contract/contract_base.js +38 -0
  104. package/dest/contract/contract_function_interaction.d.ts +67 -0
  105. package/dest/contract/contract_function_interaction.d.ts.map +1 -0
  106. package/dest/contract/contract_function_interaction.js +218 -0
  107. package/dest/contract/deploy_method.d.ts +433 -0
  108. package/dest/contract/deploy_method.d.ts.map +1 -0
  109. package/dest/contract/deploy_method.js +471 -0
  110. package/dest/contract/fastforward_contract_update.d.ts +25 -0
  111. package/dest/contract/fastforward_contract_update.d.ts.map +1 -0
  112. package/dest/contract/fastforward_contract_update.js +57 -0
  113. package/dest/contract/interaction_options.d.ts +213 -0
  114. package/dest/contract/interaction_options.d.ts.map +1 -0
  115. package/dest/contract/interaction_options.js +87 -0
  116. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +18 -0
  117. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  118. package/dest/contract/protocol_contracts/contract-class-registry.js +137 -0
  119. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +25 -0
  120. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  121. package/dest/contract/protocol_contracts/contract-instance-registry.js +366 -0
  122. package/dest/contract/protocol_contracts/fee-juice.d.ts +24 -0
  123. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  124. package/dest/contract/protocol_contracts/fee-juice.js +383 -0
  125. package/dest/contract/wait_for_proven.d.ts +18 -0
  126. package/dest/contract/wait_for_proven.d.ts.map +1 -0
  127. package/dest/contract/wait_for_proven.js +17 -0
  128. package/dest/contract/wait_opts.d.ts +21 -0
  129. package/dest/contract/wait_opts.d.ts.map +1 -0
  130. package/dest/contract/wait_opts.js +5 -0
  131. package/dest/deployment/contract_deployer.d.ts +28 -0
  132. package/dest/deployment/contract_deployer.d.ts.map +1 -0
  133. package/dest/deployment/contract_deployer.js +35 -0
  134. package/dest/deployment/publish_class.d.ts +6 -0
  135. package/dest/deployment/publish_class.d.ts.map +1 -0
  136. package/dest/deployment/publish_class.js +17 -0
  137. package/dest/deployment/publish_instance.d.ts +10 -0
  138. package/dest/deployment/publish_instance.d.ts.map +1 -0
  139. package/dest/deployment/publish_instance.js +11 -0
  140. package/dest/ethereum/portal_manager.d.ts +146 -0
  141. package/dest/ethereum/portal_manager.d.ts.map +1 -0
  142. package/dest/ethereum/portal_manager.js +415 -0
  143. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +23 -0
  144. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
  145. package/dest/fee/fee_juice_payment_method_with_claim.js +46 -0
  146. package/dest/fee/fee_payment_method.d.ts +26 -0
  147. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  148. package/dest/fee/fee_payment_method.js +3 -0
  149. package/dest/fee/private_fee_payment_method.d.ts +69 -0
  150. package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
  151. package/dest/fee/private_fee_payment_method.js +122 -0
  152. package/dest/fee/public_fee_payment_method.d.ts +59 -0
  153. package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
  154. package/dest/fee/public_fee_payment_method.js +116 -0
  155. package/dest/fee/sponsored_fee_payment.d.ts +17 -0
  156. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
  157. package/dest/fee/sponsored_fee_payment.js +33 -0
  158. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  159. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  160. package/dest/scripts/generate_protocol_contract_types.js +128 -0
  161. package/dest/test/fixtures.d.ts +13 -0
  162. package/dest/test/fixtures.d.ts.map +1 -0
  163. package/dest/test/fixtures.js +185 -0
  164. package/dest/utils/abi_types.d.ts +32 -0
  165. package/dest/utils/abi_types.d.ts.map +1 -0
  166. package/dest/utils/abi_types.js +1 -0
  167. package/dest/utils/authwit.d.ts +119 -0
  168. package/dest/utils/authwit.d.ts.map +1 -0
  169. package/dest/utils/authwit.js +266 -0
  170. package/dest/utils/cross_chain.d.ts +28 -0
  171. package/dest/utils/cross_chain.d.ts.map +1 -0
  172. package/dest/utils/cross_chain.js +26 -0
  173. package/dest/utils/fee_juice.d.ts +8 -0
  174. package/dest/utils/fee_juice.d.ts.map +1 -0
  175. package/dest/utils/fee_juice.js +10 -0
  176. package/dest/utils/field_compressed_string.d.ts +17 -0
  177. package/dest/utils/field_compressed_string.d.ts.map +1 -0
  178. package/dest/utils/field_compressed_string.js +15 -0
  179. package/dest/utils/node.d.ts +24 -0
  180. package/dest/utils/node.d.ts.map +1 -0
  181. package/dest/utils/node.js +80 -0
  182. package/dest/utils/pub_key.d.ts +9 -0
  183. package/dest/utils/pub_key.d.ts.map +1 -0
  184. package/dest/utils/pub_key.js +8 -0
  185. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +33 -0
  186. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  187. package/dest/wallet/account_entrypoint_meta_payment_method.js +63 -0
  188. package/dest/wallet/account_manager.d.ts +73 -0
  189. package/dest/wallet/account_manager.d.ts.map +1 -0
  190. package/dest/wallet/account_manager.js +102 -0
  191. package/dest/wallet/capabilities.d.ts +456 -0
  192. package/dest/wallet/capabilities.d.ts.map +1 -0
  193. package/dest/wallet/capabilities.js +3 -0
  194. package/dest/wallet/deploy_account_method.d.ts +97 -0
  195. package/dest/wallet/deploy_account_method.d.ts.map +1 -0
  196. package/dest/wallet/deploy_account_method.js +127 -0
  197. package/dest/wallet/index.d.ts +5 -0
  198. package/dest/wallet/index.d.ts.map +1 -0
  199. package/dest/wallet/index.js +4 -0
  200. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts +40 -0
  201. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts.map +1 -0
  202. package/dest/wallet/tx_simulation_result_with_app_offset.js +65 -0
  203. package/dest/wallet/wallet.d.ts +1451 -0
  204. package/dest/wallet/wallet.d.ts.map +1 -0
  205. package/dest/wallet/wallet.js +430 -0
  206. package/package.json +138 -0
  207. package/src/account/account.ts +72 -0
  208. package/src/account/account_contract.ts +80 -0
  209. package/src/account/index.ts +12 -0
  210. package/src/api/README.md +7 -0
  211. package/src/api/abi.ts +42 -0
  212. package/src/api/account.ts +12 -0
  213. package/src/api/addresses.ts +3 -0
  214. package/src/api/authorization.ts +15 -0
  215. package/src/api/block.ts +2 -0
  216. package/src/api/contract.ts +86 -0
  217. package/src/api/crypto.ts +1 -0
  218. package/src/api/deployment.ts +3 -0
  219. package/src/api/eth_address.ts +1 -0
  220. package/src/api/ethereum.ts +10 -0
  221. package/src/api/event_cursor.ts +60 -0
  222. package/src/api/events.ts +79 -0
  223. package/src/api/fee.ts +5 -0
  224. package/src/api/fee_testing.ts +1 -0
  225. package/src/api/fields.ts +3 -0
  226. package/src/api/keys.ts +8 -0
  227. package/src/api/log.ts +2 -0
  228. package/src/api/messaging.ts +2 -0
  229. package/src/api/node.ts +30 -0
  230. package/src/api/note.ts +1 -0
  231. package/src/api/protocol.ts +6 -0
  232. package/src/api/trees.ts +2 -0
  233. package/src/api/tx.ts +20 -0
  234. package/src/api/utils.ts +14 -0
  235. package/src/api/wallet.ts +83 -0
  236. package/src/authorization/call_authorization_request.ts +93 -0
  237. package/src/contract/base_contract_interaction.ts +62 -0
  238. package/src/contract/batch_call.ts +188 -0
  239. package/src/contract/checker.ts +122 -0
  240. package/src/contract/contract.ts +52 -0
  241. package/src/contract/contract_base.ts +73 -0
  242. package/src/contract/contract_function_interaction.ts +297 -0
  243. package/src/contract/deploy_method.ts +877 -0
  244. package/src/contract/fastforward_contract_update.ts +71 -0
  245. package/src/contract/interaction_options.ts +301 -0
  246. package/src/contract/protocol_contracts/contract-class-registry.ts +104 -0
  247. package/src/contract/protocol_contracts/contract-instance-registry.ts +241 -0
  248. package/src/contract/protocol_contracts/fee-juice.ts +257 -0
  249. package/src/contract/wait_for_proven.ts +43 -0
  250. package/src/contract/wait_opts.ts +26 -0
  251. package/src/deployment/contract_deployer.ts +40 -0
  252. package/src/deployment/publish_class.ts +34 -0
  253. package/src/deployment/publish_instance.ts +24 -0
  254. package/src/ethereum/portal_manager.ts +539 -0
  255. package/src/fee/fee_juice_payment_method_with_claim.ts +63 -0
  256. package/src/fee/fee_payment_method.ts +26 -0
  257. package/src/fee/private_fee_payment_method.ts +145 -0
  258. package/src/fee/public_fee_payment_method.ts +145 -0
  259. package/src/fee/sponsored_fee_payment.ts +45 -0
  260. package/src/scripts/generate_protocol_contract_types.ts +160 -0
  261. package/src/test/fixtures.ts +126 -0
  262. package/src/utils/abi_types.ts +32 -0
  263. package/src/utils/authwit.ts +327 -0
  264. package/src/utils/cross_chain.ts +55 -0
  265. package/src/utils/fee_juice.ts +14 -0
  266. package/src/utils/field_compressed_string.ts +27 -0
  267. package/src/utils/node.ts +110 -0
  268. package/src/utils/pub_key.ts +12 -0
  269. package/src/wallet/account_entrypoint_meta_payment_method.ts +76 -0
  270. package/src/wallet/account_manager.ts +164 -0
  271. package/src/wallet/capabilities.ts +505 -0
  272. package/src/wallet/deploy_account_method.ts +234 -0
  273. package/src/wallet/index.ts +4 -0
  274. package/src/wallet/tx_simulation_result_with_app_offset.ts +100 -0
  275. package/src/wallet/wallet.ts +668 -0
@@ -0,0 +1,234 @@
1
+ import { DefaultMultiCallEntrypoint } from '@aztec-labs/entrypoints/multicall';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import type { ContractArtifact, FunctionArtifact } from '@aztec-labs/stdlib/abi';
4
+ import type { AuthWitness } from '@aztec-labs/stdlib/auth-witness';
5
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
6
+ import type { ContractInstanceWithAddress } from '@aztec-labs/stdlib/contract';
7
+ import type { PublicKeys } from '@aztec-labs/stdlib/keys';
8
+ import { type Capsule, ExecutionPayload, type HashedValues, mergeExecutionPayloads } from '@aztec-labs/stdlib/tx';
9
+
10
+ import type { Account } from '../account/account.js';
11
+ import type { Contract } from '../contract/contract.js';
12
+ import type { ContractBase } from '../contract/contract_base.js';
13
+ import {
14
+ type DeployOptions,
15
+ type DeployOptionsWithoutWait,
16
+ type RequestDeployOptions,
17
+ type SimulateDeployOptions,
18
+ UniversalDeployMethod,
19
+ } from '../contract/deploy_method.js';
20
+ import {
21
+ type FeePaymentMethodOption,
22
+ type InteractionWaitOptions,
23
+ NO_FROM,
24
+ type NoFrom,
25
+ type ProfileInteractionOptions,
26
+ type SendInteractionOptionsWithoutWait,
27
+ } from '../contract/interaction_options.js';
28
+ import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
29
+ import { AccountEntrypointMetaPaymentMethod } from './account_entrypoint_meta_payment_method.js';
30
+ import type { ProfileOptions, SendOptions, SimulateOptions, Wallet } from './index.js';
31
+
32
+ /**
33
+ * Extended fee payment method option for account deployments that includes entrypoint wrapping options
34
+ */
35
+ export type DeployAccountFeePaymentMethodOption = FeePaymentMethodOption & {
36
+ /** Optional entrypoint-specific options for wrapping execution payloads */
37
+ feeEntrypointOptions?: unknown;
38
+ };
39
+
40
+ /**
41
+ * The configuration options for the request method.
42
+ */
43
+ export type RequestDeployAccountOptions = Omit<RequestDeployOptions, 'fee'> & {
44
+ /** Fee options specific to account deployment */
45
+ fee?: DeployAccountFeePaymentMethodOption;
46
+ /**
47
+ * Sender of the request. When NO_FROM, the to-be-deployed account pays for its own
48
+ * deployment (self-paid deploy) and the payload is wrapped through the multicall entrypoint.
49
+ */
50
+ from?: AztecAddress | NoFrom;
51
+ };
52
+
53
+ /**
54
+ * The configuration options for the send/prove methods.
55
+ */
56
+ export type DeployAccountOptions<W extends InteractionWaitOptions = undefined> = DeployOptionsWithoutWait & {
57
+ /**
58
+ * Whether to wait for the transaction to be mined.
59
+ * - undefined (default): wait with default options and return TxReceipt
60
+ * - WaitOpts object: wait with custom options and return TxReceipt
61
+ * - false: return txHash immediately without waiting
62
+ */
63
+ wait?: W;
64
+ };
65
+
66
+ /**
67
+ * The configuration options for the simulate method.
68
+ */
69
+ export type SimulateDeployAccountOptions = SimulateDeployOptions;
70
+
71
+ /** Fields from any interaction option shape that `DeployAccountMethod.prepareDeployOptions` reads or sets. */
72
+ type DeployAccountInteractionOptions = Pick<
73
+ SendInteractionOptionsWithoutWait,
74
+ 'additionalScopes' | 'from' | 'sendMessagesAs'
75
+ >;
76
+
77
+ /**
78
+ * Modified version of the DeployMethod used to deploy account contracts. Supports deploying
79
+ * contracts that can pay for their own fee, plus some preconfigured options to avoid errors.
80
+ */
81
+ export class DeployAccountMethod<TContract extends ContractBase = Contract> extends UniversalDeployMethod<TContract> {
82
+ constructor(
83
+ publicKeys: PublicKeys,
84
+ wallet: Wallet,
85
+ artifact: ContractArtifact,
86
+ postDeployCtor: (instance: ContractInstanceWithAddress, wallet: Wallet) => TContract,
87
+ salt: Fr,
88
+ immutablesHash: Fr,
89
+ private account: Account,
90
+ args: any[] = [],
91
+ constructorNameOrArtifact?: string | FunctionArtifact,
92
+ authWitnesses: AuthWitness[] = [],
93
+ capsules: Capsule[] = [],
94
+ extraHashedArgs: HashedValues[] = [],
95
+ ) {
96
+ super(
97
+ wallet,
98
+ { artifact, postDeployCtor, args, constructorNameOrArtifact },
99
+ // Account contracts are always deployed universally.
100
+ { salt, universalDeploy: true, publicKeys, immutablesHash },
101
+ { authWitnesses, capsules, extraHashedArgs },
102
+ );
103
+ }
104
+
105
+ /**
106
+ * Returns a FeePaymentMethod that routes the original one provided as an argument
107
+ * through the account's entrypoint. This allows an account contract to pay
108
+ * for its own deployment and initialization.
109
+ *
110
+ * For more details on how the fee payment routing works see documentation of AccountEntrypointMetaPaymentMethod class.
111
+ *
112
+ * @param originalPaymentMethod - originalPaymentMethod The original payment method to be wrapped.
113
+ * @param feeEntrypointOptions - Optional entrypoint-specific options for wrapping. If not provided, will be auto-computed based on the payment method.
114
+ * @returns A FeePaymentMethod that routes the original one through the account's entrypoint (AccountEntrypointMetaPaymentMethod)
115
+ */
116
+ private async getSelfFeePaymentMethod(originalPaymentMethod?: FeePaymentMethod, feeEntrypointOptions?: any) {
117
+ const chainInfo = await this.wallet.getChainInfo();
118
+ return new AccountEntrypointMetaPaymentMethod(this.account, chainInfo, originalPaymentMethod, feeEntrypointOptions);
119
+ }
120
+
121
+ /**
122
+ * Returns the execution payload that allows this operation to happen on chain.
123
+ * For self-deployments (from === NO_FROM), the payload is wrapped through the
124
+ * multicall entrypoint on the app side so the wallet can execute it directly.
125
+ * @param opts - Configuration options.
126
+ * @returns The execution payload for this operation
127
+ */
128
+ public override async request(opts?: RequestDeployAccountOptions): Promise<ExecutionPayload> {
129
+ const optionsWithDefaults: RequestDeployOptions = {
130
+ ...opts,
131
+ skipClassPublication: opts?.skipClassPublication ?? true,
132
+ skipInstancePublication: opts?.skipInstancePublication ?? true,
133
+ skipInitialization: opts?.skipInitialization ?? false,
134
+ };
135
+ // Override the fee to undefined, since we'll replace it
136
+ const deploymentExecutionPayload = await super.request({ ...optionsWithDefaults, fee: undefined });
137
+ const executionPayloads = [deploymentExecutionPayload];
138
+ // If this is a self-paid deployment (the to-be-deployed account pays for its own deploy),
139
+ // wrap the payload through the multicall entrypoint after attaching the fee.
140
+ if (opts?.from === NO_FROM) {
141
+ const feePaymentMethod = await this.getSelfFeePaymentMethod(
142
+ opts?.fee?.paymentMethod,
143
+ opts?.fee?.feeEntrypointOptions,
144
+ );
145
+ const feeExecutionPayload = await feePaymentMethod.getExecutionPayload();
146
+ // Notice they are reversed (fee payment usually goes first):
147
+ // this is because we need to construct the contract BEFORE it can pay for its own fee
148
+ executionPayloads.push(feeExecutionPayload);
149
+ // Wrap the merged payload through the multicall entrypoint,
150
+ // producing a single-call payload that DefaultEntrypoint can execute directly.
151
+ const multicall = new DefaultMultiCallEntrypoint();
152
+ const chainInfo = await this.wallet.getChainInfo();
153
+ return multicall.wrapExecutionPayload(mergeExecutionPayloads(executionPayloads), chainInfo);
154
+ } else {
155
+ const feeExecutionPayload = opts?.fee?.paymentMethod
156
+ ? await opts.fee.paymentMethod.getExecutionPayload()
157
+ : undefined;
158
+ if (feeExecutionPayload) {
159
+ executionPayloads.unshift(feeExecutionPayload);
160
+ }
161
+ return mergeExecutionPayloads(executionPayloads);
162
+ }
163
+ }
164
+
165
+ protected override convertDeployOptionsToSendOptions<W extends InteractionWaitOptions>(
166
+ options: DeployOptions<W>,
167
+ ): SendOptions<W> {
168
+ return super.convertDeployOptionsToSendOptions(this.prepareDeployOptions(options));
169
+ }
170
+
171
+ protected override convertDeployOptionsToSimulateOptions(options: SimulateDeployOptions): SimulateOptions {
172
+ return super.convertDeployOptionsToSimulateOptions(this.prepareDeployOptions(options));
173
+ }
174
+
175
+ protected override convertDeployOptionsToProfileOptions(
176
+ options: DeployOptionsWithoutWait & ProfileInteractionOptions,
177
+ ): ProfileOptions {
178
+ return super.convertDeployOptionsToProfileOptions(this.prepareDeployOptions(options));
179
+ }
180
+
181
+ /**
182
+ * Augments deploy options so that the PXE has the context it needs to simulate/prove the deploy.
183
+ *
184
+ * - Injects the contract's own address into scopes so the constructor can access its own keys.
185
+ * - When `from === NO_FROM` (self-paid deploy), supplies the to-be-deployed address as `sendMessagesAs`. Without
186
+ * this, fee-payment calls would have no sender for message tagging, and any private log they emit would fail
187
+ * the "Sender for tags is not set" assertion.
188
+ *
189
+ * Note: this reads the cached instance synchronously via `getCachedInstance()`. Because every code path that
190
+ * calls `prepareDeployOptions` (send/simulate/profile) flows through `request()` first, which calls
191
+ * `getInstance()`, the cache is always populated by the time we get here.
192
+ *
193
+ * @param options - The deploy options to augment.
194
+ */
195
+ private prepareDeployOptions<T extends DeployAccountInteractionOptions>(options: T): T {
196
+ const { address } = this.getCachedInstanceOrThrow();
197
+ const existing = options.additionalScopes ?? [];
198
+ const sendMessagesAs = options.sendMessagesAs ?? (options.from === NO_FROM ? address : undefined);
199
+ return { ...options, additionalScopes: [...existing, address], sendMessagesAs };
200
+ }
201
+
202
+ /**
203
+ * Augments this DeployAccountMethod with additional metadata, such as authWitnesses and capsules.
204
+ * @param options - An object containing the metadata to add to the interaction
205
+ * @returns A new DeployAccountMethod with the added metadata
206
+ */
207
+ public override with({
208
+ authWitnesses = [],
209
+ capsules = [],
210
+ extraHashedArgs = [],
211
+ }: {
212
+ /** The authWitnesses to add to the deployment */
213
+ authWitnesses?: AuthWitness[];
214
+ /** The capsules to add to the deployment */
215
+ capsules?: Capsule[];
216
+ /** The extra hashed args to add to the deployment */
217
+ extraHashedArgs?: HashedValues[];
218
+ }): DeployAccountMethod<TContract> {
219
+ return new DeployAccountMethod(
220
+ this.publicKeys,
221
+ this.wallet,
222
+ this.artifact,
223
+ this.postDeployCtor,
224
+ this.salt,
225
+ this.immutablesHash,
226
+ this.account,
227
+ this.args,
228
+ this.constructorArtifact?.name,
229
+ this.authWitnesses.concat(authWitnesses),
230
+ this.capsules.concat(capsules),
231
+ this.extraHashedArgs.concat(extraHashedArgs),
232
+ );
233
+ }
234
+ }
@@ -0,0 +1,4 @@
1
+ export * from './wallet.js';
2
+ export * from './account_manager.js';
3
+ export * from './capabilities.js';
4
+ export * from './tx_simulation_result_with_app_offset.js';
@@ -0,0 +1,100 @@
1
+ import type { ZodFor } from '@aztec-labs/foundation/schemas';
2
+ import { optional } from '@aztec-labs/foundation/schemas';
3
+ import { PrivateKernelTailCircuitPublicInputs } from '@aztec-labs/stdlib/kernel';
4
+ import {
5
+ type NestedProcessReturnValues,
6
+ PrivateExecutionResult,
7
+ PublicSimulationOutput,
8
+ type SimulationStats,
9
+ SimulationStatsSchema,
10
+ TxSimulationResult,
11
+ } from '@aztec-labs/stdlib/tx';
12
+ import { z } from 'zod';
13
+
14
+ /**
15
+ * Extends TxSimulationResult with the app call offset, which tracks where the app's calls begin in the flattened
16
+ * array of calls. Tracking of app call offset is a wallet-level concern: the wallet may wrap the app payload in an
17
+ * entrypoint or may prepend calls (this is typically done for fee payments).
18
+ */
19
+ export class TxSimulationResultWithAppOffset extends TxSimulationResult {
20
+ constructor(
21
+ privateExecutionResult: PrivateExecutionResult,
22
+ publicInputs: PrivateKernelTailCircuitPublicInputs,
23
+ publicOutput?: PublicSimulationOutput,
24
+ stats?: SimulationStats,
25
+ /**
26
+ * Index of the app's first call in a flattened array of calls.
27
+ * 0 = app call is the root execution itself (DefaultEntrypoint / NO_FROM).
28
+ * 1..N = wallet prepended calls before the app call.
29
+ * undefined = wallet did not send the field; use heuristic fallback.
30
+ */
31
+ public readonly appCallOffset: number | undefined = undefined,
32
+ ) {
33
+ super(privateExecutionResult, publicInputs, publicOutput, stats);
34
+ }
35
+
36
+ /**
37
+ * Returns the private return values that correspond to the provided app call.
38
+ * @param appCallIndex - Index of the app call within the app calls.
39
+ */
40
+ getPrivateReturnValuesOfAppCall(appCallIndex: number = 0): NestedProcessReturnValues | undefined {
41
+ const all = this.getPrivateReturnValues();
42
+
43
+ if (this.appCallOffset === undefined) {
44
+ // appCallOffset was not sent. Apply the pre-offset heuristic for backwards compatibility.
45
+ // If there are nested calls, the app was wrapped in an account contract entrypoint and its return values
46
+ // live in nested[appCallIndex]. Otherwise the app call is the root execution.
47
+ if ((all?.nested?.length ?? 0) > 0) {
48
+ return all?.nested?.[appCallIndex];
49
+ }
50
+ if (appCallIndex !== 0) {
51
+ throw new Error('App call index cannot be defined when there is single root app call');
52
+ }
53
+ return all;
54
+ }
55
+
56
+ // appCallOffset is defined on the flattened array of calls where entrypoint occupies index 0 and the app's
57
+ // first call occupies index appCallOffset. appCallIndex 0 with appCallOffset 0 means the root itself.
58
+ if (this.appCallOffset === 0 && appCallIndex === 0) {
59
+ return all;
60
+ }
61
+ // For all other cases, index into nested: subtract 1 because nested[0] corresponds to flat index 1 (first nested).
62
+ return all?.nested?.[appCallIndex + this.appCallOffset - 1];
63
+ }
64
+
65
+ /**
66
+ * Creates a TxSimulationResultWithAppOffset from an existing TxSimulationResult, attaching the app call offset
67
+ * computed by the wallet (i.e. how many calls precede the first app call in the flattened execution tree).
68
+ * @param result - The simulation result to wrap.
69
+ * @param appCallOffset - The index of the app's first call in the flattened execution tree.
70
+ */
71
+ static fromResultAndOffset(result: TxSimulationResult, appCallOffset: number): TxSimulationResultWithAppOffset {
72
+ return new TxSimulationResultWithAppOffset(
73
+ result.privateExecutionResult,
74
+ result.publicInputs,
75
+ result.publicOutput,
76
+ result.stats,
77
+ appCallOffset,
78
+ );
79
+ }
80
+
81
+ static override async random() {
82
+ const base = await TxSimulationResult.random();
83
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(base, 0);
84
+ }
85
+
86
+ static override get schema(): ZodFor<TxSimulationResultWithAppOffset> {
87
+ return z
88
+ .object({
89
+ privateExecutionResult: PrivateExecutionResult.schema,
90
+ publicInputs: PrivateKernelTailCircuitPublicInputs.schema,
91
+ publicOutput: PublicSimulationOutput.schema.optional(),
92
+ stats: optional(SimulationStatsSchema),
93
+ appCallOffset: optional(z.number()),
94
+ })
95
+ .transform(
96
+ ({ privateExecutionResult, publicInputs, publicOutput, stats, appCallOffset }) =>
97
+ new TxSimulationResultWithAppOffset(privateExecutionResult, publicInputs, publicOutput, stats, appCallOffset),
98
+ );
99
+ }
100
+ }