@aztec/aztec.js 3.0.0-canary.a9708bd → 3.0.0-devnet.2

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 (278) hide show
  1. package/dest/account/account.d.ts +60 -0
  2. package/dest/account/account.d.ts.map +1 -0
  3. package/dest/account/account.js +59 -0
  4. package/dest/account/account_contract.d.ts +5 -5
  5. package/dest/account/account_contract.d.ts.map +1 -1
  6. package/dest/account/account_contract.js +0 -1
  7. package/dest/{wallet/account_wallet_with_private_key.d.ts → account/account_with_secret_key.d.ts} +7 -8
  8. package/dest/account/account_with_secret_key.d.ts.map +1 -0
  9. package/dest/{wallet/account_wallet_with_private_key.js → account/account_with_secret_key.js} +5 -5
  10. package/dest/account/index.d.ts +1 -4
  11. package/dest/account/index.d.ts.map +1 -1
  12. package/dest/account/index.js +1 -4
  13. package/dest/account/signerless_account.d.ts +24 -0
  14. package/dest/account/signerless_account.d.ts.map +1 -0
  15. package/dest/account/signerless_account.js +27 -0
  16. package/dest/api/abi.d.ts +1 -0
  17. package/dest/api/abi.d.ts.map +1 -1
  18. package/dest/api/account.d.ts +4 -2
  19. package/dest/api/account.d.ts.map +1 -1
  20. package/dest/api/account.js +3 -1
  21. package/dest/api/addresses.d.ts +1 -0
  22. package/dest/api/addresses.d.ts.map +1 -1
  23. package/dest/api/addresses.js +1 -0
  24. package/dest/api/authorization.d.ts +2 -0
  25. package/dest/api/authorization.d.ts.map +1 -1
  26. package/dest/api/authorization.js +2 -0
  27. package/dest/api/block.d.ts +3 -0
  28. package/dest/api/block.d.ts.map +1 -0
  29. package/dest/api/block.js +2 -0
  30. package/dest/api/contract.d.ts +4 -5
  31. package/dest/api/contract.d.ts.map +1 -1
  32. package/dest/api/contract.js +3 -3
  33. package/dest/api/crypto.d.ts +2 -0
  34. package/dest/api/crypto.d.ts.map +1 -0
  35. package/dest/api/crypto.js +1 -0
  36. package/dest/api/ethereum.d.ts +0 -1
  37. package/dest/api/ethereum.d.ts.map +1 -1
  38. package/dest/api/ethereum.js +0 -1
  39. package/dest/api/events.d.ts +12 -0
  40. package/dest/api/events.d.ts.map +1 -0
  41. package/dest/api/events.js +30 -0
  42. package/dest/api/fee.d.ts +1 -2
  43. package/dest/api/fee.d.ts.map +1 -1
  44. package/dest/api/fee.js +0 -1
  45. package/dest/api/keys.d.ts +4 -0
  46. package/dest/api/keys.d.ts.map +1 -0
  47. package/dest/api/keys.js +3 -0
  48. package/dest/api/log.d.ts +1 -0
  49. package/dest/api/log.d.ts.map +1 -1
  50. package/dest/api/log.js +1 -0
  51. package/dest/api/messaging.d.ts +3 -0
  52. package/dest/api/messaging.d.ts.map +1 -0
  53. package/dest/api/messaging.js +2 -0
  54. package/dest/api/node.d.ts +21 -0
  55. package/dest/api/node.d.ts.map +1 -0
  56. package/dest/api/node.js +18 -0
  57. package/dest/api/note.d.ts +2 -0
  58. package/dest/api/note.d.ts.map +1 -0
  59. package/dest/api/note.js +1 -0
  60. package/dest/api/protocol.d.ts +3 -0
  61. package/dest/api/protocol.d.ts.map +1 -0
  62. package/dest/api/protocol.js +2 -0
  63. package/dest/api/trees.d.ts +3 -0
  64. package/dest/api/trees.d.ts.map +1 -0
  65. package/dest/api/trees.js +2 -0
  66. package/dest/api/tx.d.ts +2 -0
  67. package/dest/api/tx.d.ts.map +1 -0
  68. package/dest/api/tx.js +1 -0
  69. package/dest/api/utils.d.ts +10 -6
  70. package/dest/api/utils.d.ts.map +1 -1
  71. package/dest/api/utils.js +10 -5
  72. package/dest/api/wallet.d.ts +4 -1
  73. package/dest/api/wallet.d.ts.map +1 -1
  74. package/dest/api/wallet.js +4 -1
  75. package/dest/contract/base_contract_interaction.d.ts +6 -48
  76. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  77. package/dest/contract/base_contract_interaction.js +6 -106
  78. package/dest/contract/batch_call.d.ts +6 -14
  79. package/dest/contract/batch_call.d.ts.map +1 -1
  80. package/dest/contract/batch_call.js +42 -52
  81. package/dest/contract/contract.d.ts +1 -1
  82. package/dest/contract/contract.d.ts.map +1 -1
  83. package/dest/contract/contract.js +2 -12
  84. package/dest/contract/contract_base.d.ts +1 -1
  85. package/dest/contract/contract_base.d.ts.map +1 -1
  86. package/dest/contract/contract_function_interaction.d.ts +29 -40
  87. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  88. package/dest/contract/contract_function_interaction.js +41 -53
  89. package/dest/contract/deploy_method.d.ts +63 -56
  90. package/dest/contract/deploy_method.d.ts.map +1 -1
  91. package/dest/contract/deploy_method.js +68 -86
  92. package/dest/contract/deploy_sent_tx.d.ts +0 -1
  93. package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
  94. package/dest/contract/deploy_sent_tx.js +7 -10
  95. package/dest/contract/interaction_options.d.ts +74 -19
  96. package/dest/contract/interaction_options.d.ts.map +1 -1
  97. package/dest/contract/interaction_options.js +51 -3
  98. package/dest/contract/sent_tx.d.ts +3 -3
  99. package/dest/contract/sent_tx.d.ts.map +1 -1
  100. package/dest/contract/sent_tx.js +5 -5
  101. package/dest/contract/wait_for_proven.d.ts +3 -3
  102. package/dest/contract/wait_for_proven.d.ts.map +1 -1
  103. package/dest/contract/wait_for_proven.js +2 -2
  104. package/dest/deployment/publish_instance.d.ts +1 -1
  105. package/dest/deployment/publish_instance.d.ts.map +1 -1
  106. package/dest/deployment/publish_instance.js +2 -5
  107. package/dest/ethereum/portal_manager.d.ts +3 -4
  108. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  109. package/dest/ethereum/portal_manager.js +3 -5
  110. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +12 -7
  111. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  112. package/dest/fee/fee_juice_payment_method_with_claim.js +21 -12
  113. package/dest/fee/fee_payment_method.d.ts +26 -0
  114. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  115. package/dest/fee/fee_payment_method.js +3 -0
  116. package/dest/fee/private_fee_payment_method.d.ts +22 -5
  117. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  118. package/dest/fee/private_fee_payment_method.js +34 -13
  119. package/dest/fee/public_fee_payment_method.d.ts +22 -5
  120. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  121. package/dest/fee/public_fee_payment_method.js +37 -14
  122. package/dest/fee/sponsored_fee_payment.d.ts +2 -0
  123. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
  124. package/dest/fee/sponsored_fee_payment.js +4 -0
  125. package/dest/utils/authwit.d.ts +77 -25
  126. package/dest/utils/authwit.d.ts.map +1 -1
  127. package/dest/utils/authwit.js +219 -24
  128. package/dest/utils/cross_chain.d.ts +24 -0
  129. package/dest/utils/cross_chain.d.ts.map +1 -0
  130. package/dest/utils/cross_chain.js +30 -0
  131. package/dest/utils/fee_juice.d.ts +3 -2
  132. package/dest/utils/fee_juice.d.ts.map +1 -1
  133. package/dest/utils/fee_juice.js +3 -2
  134. package/dest/{fee → wallet}/account_entrypoint_meta_payment_method.d.ts +13 -10
  135. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  136. package/dest/wallet/account_entrypoint_meta_payment_method.js +76 -0
  137. package/dest/wallet/account_manager.d.ts +69 -0
  138. package/dest/wallet/account_manager.d.ts.map +1 -0
  139. package/dest/wallet/account_manager.js +113 -0
  140. package/dest/wallet/base_wallet.d.ts +78 -35
  141. package/dest/wallet/base_wallet.d.ts.map +1 -1
  142. package/dest/wallet/base_wallet.js +216 -48
  143. package/dest/wallet/deploy_account_method.d.ts +52 -0
  144. package/dest/wallet/deploy_account_method.d.ts.map +1 -0
  145. package/dest/wallet/deploy_account_method.js +77 -0
  146. package/dest/wallet/index.d.ts +2 -15
  147. package/dest/wallet/index.d.ts.map +1 -1
  148. package/dest/wallet/index.js +2 -19
  149. package/dest/wallet/wallet.d.ts +2473 -6
  150. package/dest/wallet/wallet.d.ts.map +1 -1
  151. package/dest/wallet/wallet.js +202 -3
  152. package/package.json +25 -21
  153. package/src/account/account.ts +97 -0
  154. package/src/account/account_contract.ts +4 -6
  155. package/src/{wallet/account_wallet_with_private_key.ts → account/account_with_secret_key.ts} +6 -8
  156. package/src/account/index.ts +1 -4
  157. package/src/account/signerless_account.ts +46 -0
  158. package/src/api/abi.ts +11 -0
  159. package/src/api/account.ts +4 -2
  160. package/src/api/addresses.ts +1 -0
  161. package/src/api/authorization.ts +11 -0
  162. package/src/api/block.ts +2 -0
  163. package/src/api/contract.ts +16 -8
  164. package/src/api/crypto.ts +1 -0
  165. package/src/api/ethereum.ts +0 -1
  166. package/src/api/events.ts +44 -0
  167. package/src/api/fee.ts +1 -2
  168. package/src/api/keys.ts +8 -0
  169. package/src/api/log.ts +1 -0
  170. package/src/api/messaging.ts +2 -0
  171. package/src/api/node.ts +20 -0
  172. package/src/api/note.ts +1 -0
  173. package/src/api/protocol.ts +2 -0
  174. package/src/api/trees.ts +2 -0
  175. package/src/api/tx.ts +11 -0
  176. package/src/api/utils.ts +12 -19
  177. package/src/api/wallet.ts +33 -5
  178. package/src/contract/base_contract_interaction.ts +9 -138
  179. package/src/contract/batch_call.ts +52 -61
  180. package/src/contract/contract.ts +2 -12
  181. package/src/contract/contract_function_interaction.ts +65 -97
  182. package/src/contract/deploy_method.ts +117 -99
  183. package/src/contract/deploy_sent_tx.ts +4 -10
  184. package/src/contract/interaction_options.ts +126 -24
  185. package/src/contract/sent_tx.ts +4 -4
  186. package/src/contract/wait_for_proven.ts +4 -4
  187. package/src/deployment/publish_instance.ts +3 -8
  188. package/src/ethereum/portal_manager.ts +4 -12
  189. package/src/fee/fee_juice_payment_method_with_claim.ts +26 -17
  190. package/src/fee/fee_payment_method.ts +26 -0
  191. package/src/fee/private_fee_payment_method.ts +60 -41
  192. package/src/fee/public_fee_payment_method.ts +73 -49
  193. package/src/fee/sponsored_fee_payment.ts +6 -0
  194. package/src/utils/authwit.ts +250 -38
  195. package/src/utils/cross_chain.ts +53 -0
  196. package/src/utils/fee_juice.ts +4 -3
  197. package/src/wallet/account_entrypoint_meta_payment_method.ts +105 -0
  198. package/src/wallet/account_manager.ts +154 -0
  199. package/src/wallet/base_wallet.ts +287 -78
  200. package/src/wallet/deploy_account_method.ts +125 -0
  201. package/src/wallet/index.ts +2 -32
  202. package/src/wallet/wallet.ts +357 -29
  203. package/dest/account_manager/account_manager.d.ts +0 -119
  204. package/dest/account_manager/account_manager.d.ts.map +0 -1
  205. package/dest/account_manager/account_manager.js +0 -202
  206. package/dest/account_manager/deploy_account_sent_tx.d.ts +0 -30
  207. package/dest/account_manager/deploy_account_sent_tx.d.ts.map +0 -1
  208. package/dest/account_manager/deploy_account_sent_tx.js +0 -29
  209. package/dest/account_manager/index.d.ts +0 -3
  210. package/dest/account_manager/index.d.ts.map +0 -1
  211. package/dest/account_manager/index.js +0 -2
  212. package/dest/api/interfaces.d.ts +0 -2
  213. package/dest/api/interfaces.d.ts.map +0 -1
  214. package/dest/api/interfaces.js +0 -1
  215. package/dest/api/log_id.d.ts +0 -2
  216. package/dest/api/log_id.d.ts.map +0 -1
  217. package/dest/api/log_id.js +0 -1
  218. package/dest/api/rpc.d.ts +0 -3
  219. package/dest/api/rpc.d.ts.map +0 -1
  220. package/dest/api/rpc.js +0 -2
  221. package/dest/api/tx_hash.d.ts +0 -2
  222. package/dest/api/tx_hash.d.ts.map +0 -1
  223. package/dest/api/tx_hash.js +0 -1
  224. package/dest/contract/deploy_proven_tx.d.ts +0 -21
  225. package/dest/contract/deploy_proven_tx.d.ts.map +0 -1
  226. package/dest/contract/deploy_proven_tx.js +0 -21
  227. package/dest/contract/proven_tx.d.ts +0 -21
  228. package/dest/contract/proven_tx.d.ts.map +0 -1
  229. package/dest/contract/proven_tx.js +0 -23
  230. package/dest/ethereum/l1_contracts.d.ts +0 -3
  231. package/dest/ethereum/l1_contracts.d.ts.map +0 -1
  232. package/dest/ethereum/l1_contracts.js +0 -13
  233. package/dest/fee/account_entrypoint_meta_payment_method.d.ts.map +0 -1
  234. package/dest/fee/account_entrypoint_meta_payment_method.js +0 -64
  235. package/dest/fee/fee_juice_payment_method.d.ts +0 -14
  236. package/dest/fee/fee_juice_payment_method.d.ts.map +0 -1
  237. package/dest/fee/fee_juice_payment_method.js +0 -21
  238. package/dest/fee/utils.d.ts +0 -13
  239. package/dest/fee/utils.d.ts.map +0 -1
  240. package/dest/fee/utils.js +0 -32
  241. package/dest/index.d.ts +0 -59
  242. package/dest/index.d.ts.map +0 -1
  243. package/dest/index.js +0 -62
  244. package/dest/rpc_clients/node/index.d.ts +0 -12
  245. package/dest/rpc_clients/node/index.d.ts.map +0 -1
  246. package/dest/rpc_clients/node/index.js +0 -72
  247. package/dest/rpc_clients/pxe_client.d.ts +0 -10
  248. package/dest/rpc_clients/pxe_client.d.ts.map +0 -1
  249. package/dest/rpc_clients/pxe_client.js +0 -23
  250. package/dest/utils/pxe.d.ts +0 -4
  251. package/dest/utils/pxe.d.ts.map +0 -1
  252. package/dest/utils/pxe.js +0 -14
  253. package/dest/wallet/account_wallet.d.ts +0 -74
  254. package/dest/wallet/account_wallet.d.ts.map +0 -1
  255. package/dest/wallet/account_wallet.js +0 -232
  256. package/dest/wallet/account_wallet_with_private_key.d.ts.map +0 -1
  257. package/dest/wallet/signerless_wallet.d.ts +0 -23
  258. package/dest/wallet/signerless_wallet.d.ts.map +0 -1
  259. package/dest/wallet/signerless_wallet.js +0 -33
  260. package/src/account_manager/account_manager.ts +0 -276
  261. package/src/account_manager/deploy_account_sent_tx.ts +0 -46
  262. package/src/account_manager/index.ts +0 -2
  263. package/src/api/interfaces.ts +0 -1
  264. package/src/api/log_id.ts +0 -1
  265. package/src/api/rpc.ts +0 -2
  266. package/src/api/tx_hash.ts +0 -1
  267. package/src/contract/deploy_proven_tx.ts +0 -45
  268. package/src/contract/proven_tx.ts +0 -36
  269. package/src/ethereum/l1_contracts.ts +0 -21
  270. package/src/fee/account_entrypoint_meta_payment_method.ts +0 -89
  271. package/src/fee/fee_juice_payment_method.ts +0 -25
  272. package/src/fee/utils.ts +0 -39
  273. package/src/index.ts +0 -85
  274. package/src/rpc_clients/node/index.ts +0 -77
  275. package/src/rpc_clients/pxe_client.ts +0 -25
  276. package/src/utils/pxe.ts +0 -17
  277. package/src/wallet/account_wallet.ts +0 -246
  278. package/src/wallet/signerless_wallet.ts +0 -56
@@ -1,49 +1,21 @@
1
- import { ExecutionPayload } from '@aztec/entrypoints/payload';
1
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
2
2
  import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
3
3
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import {
6
- type Capsule,
7
- type HashedValues,
8
- type OffchainEffect,
9
- type SimulationStats,
10
- type TxExecutionRequest,
11
- type TxProfileResult,
12
- collectOffchainEffects,
13
- } from '@aztec/stdlib/tx';
5
+ import { type Capsule, type HashedValues, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
14
6
 
15
7
  import type { Wallet } from '../wallet/wallet.js';
16
8
  import { BaseContractInteraction } from './base_contract_interaction.js';
17
- import type {
18
- ProfileMethodOptions,
19
- RequestMethodOptions,
20
- SendMethodOptions,
21
- SimulateMethodOptions,
9
+ import { getGasLimits } from './get_gas_limits.js';
10
+ import {
11
+ type ProfileInteractionOptions,
12
+ type RequestInteractionOptions,
13
+ type SimulateInteractionOptions,
14
+ type SimulationReturn,
15
+ toProfileOptions,
16
+ toSimulateOptions,
22
17
  } from './interaction_options.js';
23
18
 
24
- /**
25
- * Represents the result type of a simulation.
26
- * By default, it will just be the return value of the simulated function
27
- * so contract interfaces behave as plain functions. If `includeMetadata` is set to true in `SimulateMethodOptions` on the input of `simulate(...)`,
28
- * it will provide extra information.
29
- */
30
- type SimulationReturn<T extends boolean | undefined> = T extends true
31
- ? {
32
- /**
33
- * Additional stats about the simulation
34
- */
35
- stats: SimulationStats;
36
- /**
37
- * Offchain effects generated during the simulation
38
- */
39
- offchainEffects: OffchainEffect[];
40
- /**
41
- * Return value of the function
42
- */
43
- result: any;
44
- }
45
- : any;
46
-
47
19
  /**
48
20
  * This is the class that is returned when calling e.g. `contract.methods.myMethod(arg0, arg1)`.
49
21
  * It contains available interactions one can call on a method, including view.
@@ -64,69 +36,71 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
64
36
  }
65
37
  }
66
38
 
67
- // docs:start:create
68
39
  /**
69
- * Create a transaction execution request that represents this call, encoded and authenticated by the
70
- * user's wallet, ready to be simulated.
71
- * @param options - An optional object containing additional configuration for the transaction.
72
- * @returns A Promise that resolves to a transaction instance.
40
+ * Returns the encoded function call wrapped by this interaction
41
+ * Useful when generating authwits
42
+ * @returns An encoded function call
73
43
  */
74
- public override async create(options: Omit<SendMethodOptions, 'from'> = {}): Promise<TxExecutionRequest> {
75
- // docs:end:create
76
- if (this.functionDao.functionType === FunctionType.UTILITY) {
77
- throw new Error("Can't call `create` on a utility function.");
78
- }
79
- const requestWithoutFee = await this.request(options);
80
-
81
- const { fee: userFee, txNonce, cancellable } = options;
82
- const fee = await this.getFeeOptions(requestWithoutFee, userFee, { txNonce, cancellable });
83
-
84
- return await this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { txNonce, cancellable });
44
+ public async getFunctionCall() {
45
+ const args = encodeArguments(this.functionDao, this.args);
46
+ return {
47
+ name: this.functionDao.name,
48
+ args,
49
+ selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
50
+ type: this.functionDao.functionType,
51
+ to: this.contractAddress,
52
+ isStatic: this.functionDao.isStatic,
53
+ hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
54
+ returnTypes: this.functionDao.returnTypes,
55
+ };
85
56
  }
86
57
 
87
- // docs:start:request
88
58
  /**
89
- * Returns an execution request that represents this operation.
90
- * Can be used as a building block for constructing batch requests.
91
- * @param options - An optional object containing additional configuration for the request generation.
92
- * @returns An execution payload wrapped in promise.
59
+ * Returns the execution payload that allows this operation to happen on chain.
60
+ * @param options - Configuration options.
61
+ * @returns The execution payload for this operation
93
62
  */
94
- public override async request(options: RequestMethodOptions = {}): Promise<ExecutionPayload> {
95
- // docs:end:request
96
- const args = encodeArguments(this.functionDao, this.args);
97
- const calls = [
98
- {
99
- name: this.functionDao.name,
100
- args,
101
- selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
102
- type: this.functionDao.functionType,
103
- to: this.contractAddress,
104
- isStatic: this.functionDao.isStatic,
105
- returnTypes: this.functionDao.returnTypes,
106
- },
107
- ];
63
+ public override async request(options: RequestInteractionOptions = {}): Promise<ExecutionPayload> {
64
+ const calls = [await this.getFunctionCall()];
108
65
  const { authWitnesses, capsules } = options;
109
- return new ExecutionPayload(
66
+ const feeExecutionPayload = options.fee?.paymentMethod
67
+ ? await options.fee.paymentMethod.getExecutionPayload()
68
+ : undefined;
69
+ const functionExecutionPayload = new ExecutionPayload(
110
70
  calls,
111
71
  this.authWitnesses.concat(authWitnesses ?? []),
112
72
  this.capsules.concat(capsules ?? []),
113
73
  this.extraHashedArgs,
114
74
  );
75
+ const finalExecutionPayload = feeExecutionPayload
76
+ ? mergeExecutionPayloads([feeExecutionPayload, functionExecutionPayload])
77
+ : functionExecutionPayload;
78
+ return finalExecutionPayload;
115
79
  }
116
80
 
117
81
  // docs:start:simulate
118
82
  /**
119
- * Simulate a transaction and get its return values
83
+ * Simulate a transaction and get information from its execution.
120
84
  * Differs from prove in a few important ways:
121
- * 1. It returns the values of the function execution
85
+ * 1. It returns the values of the function execution, plus additional metadata if requested
122
86
  * 2. It supports `utility`, `private` and `public` functions
123
87
  *
124
- * @param options - An optional object containing additional configuration for the transaction.
125
- * @returns The result of the transaction as returned by the contract function.
88
+ * @param options - An optional object containing additional configuration for the simulation.
89
+ * @returns Depending on the simulation options, this method directly returns the result value of the executed
90
+ * function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
91
+ * execution statistics and emitted offchain effects
126
92
  */
127
- public async simulate<T extends SimulateMethodOptions>(options: T): Promise<SimulationReturn<T['includeMetadata']>>;
93
+ public async simulate<T extends SimulateInteractionOptions>(
94
+ options: T,
95
+ ): Promise<SimulationReturn<Exclude<T['fee'], undefined>['estimateGas']>>;
96
+ // eslint-disable-next-line jsdoc/require-jsdoc
97
+ public async simulate<T extends SimulateInteractionOptions>(
98
+ options: T,
99
+ ): Promise<SimulationReturn<T['includeMetadata']>>;
128
100
  // eslint-disable-next-line jsdoc/require-jsdoc
129
- public async simulate(options: SimulateMethodOptions): Promise<SimulationReturn<typeof options.includeMetadata>> {
101
+ public async simulate(
102
+ options: SimulateInteractionOptions,
103
+ ): Promise<SimulationReturn<typeof options.includeMetadata>> {
130
104
  // docs:end:simulate
131
105
  if (this.functionDao.functionType == FunctionType.UTILITY) {
132
106
  const utilityResult = await this.wallet.simulateUtility(
@@ -146,13 +120,8 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
146
120
  }
147
121
  }
148
122
 
149
- const txRequest = await this.create(options);
150
- const simulatedTx = await this.wallet.simulateTx(
151
- txRequest,
152
- true /* simulatePublic */,
153
- options.skipTxValidation,
154
- options.skipFeeEnforcement ?? true,
155
- );
123
+ const executionPayload = await this.request(options);
124
+ const simulatedTx = await this.wallet.simulateTx(executionPayload, await toSimulateOptions(options));
156
125
 
157
126
  let rawReturnValues;
158
127
  if (this.functionDao.functionType == FunctionType.PRIVATE) {
@@ -171,11 +140,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
171
140
 
172
141
  const returnValue = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
173
142
 
174
- if (options.includeMetadata) {
143
+ if (options.includeMetadata || options.fee?.estimateGas) {
144
+ const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
145
+ this.log.verbose(
146
+ `Estimated gas limits for tx: DA=${gasLimits.daGas} L2=${gasLimits.l2Gas} teardownDA=${teardownGasLimits.daGas} teardownL2=${teardownGasLimits.l2Gas}`,
147
+ );
175
148
  return {
176
149
  stats: simulatedTx.stats,
177
150
  offchainEffects: collectOffchainEffects(simulatedTx.privateExecutionResult),
178
151
  result: returnValue,
152
+ estimatedGas: { gasLimits, teardownGasLimits },
179
153
  };
180
154
  } else {
181
155
  return returnValue;
@@ -188,19 +162,13 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
188
162
  *
189
163
  * @returns An object containing the function return value and profile result.
190
164
  */
191
- public async profile(options: ProfileMethodOptions): Promise<TxProfileResult> {
192
- if (options.from !== AztecAddress.ZERO && !options.from.equals(this.wallet.getAddress())) {
193
- throw new Error(
194
- `The address provided as from does not match the wallet address. Expected ${this.wallet.getAddress().toString()}, got ${options.from.toString()}.`,
195
- );
196
- }
165
+ public async profile(options: ProfileInteractionOptions): Promise<TxProfileResult> {
197
166
  if (this.functionDao.functionType == FunctionType.UTILITY) {
198
167
  throw new Error("Can't profile a utility function.");
199
168
  }
200
- const { authWitnesses, capsules, fee } = options;
201
169
 
202
- const txRequest = await this.create({ fee, authWitnesses, capsules });
203
- return await this.wallet.profileTx(txRequest, options.profileMode, options.skipProofGeneration, options?.from);
170
+ const executionPayload = await this.request(options);
171
+ return await this.wallet.profileTx(executionPayload, await toProfileOptions(options));
204
172
  }
205
173
 
206
174
  /**
@@ -1,6 +1,5 @@
1
- import type { ExecutionPayload } from '@aztec/entrypoints/payload';
2
- import { mergeExecutionPayloads } from '@aztec/entrypoints/payload';
3
- import type { Fr } from '@aztec/foundation/fields';
1
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
2
+ import { Fr } from '@aztec/foundation/fields';
4
3
  import { type ContractArtifact, type FunctionAbi, type FunctionArtifact, getInitializer } from '@aztec/stdlib/abi';
5
4
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
6
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -10,9 +9,8 @@ import {
10
9
  getContractClassFromArtifact,
11
10
  getContractInstanceFromInstantiationParams,
12
11
  } from '@aztec/stdlib/contract';
13
- import type { GasSettings } from '@aztec/stdlib/gas';
14
12
  import type { PublicKeys } from '@aztec/stdlib/keys';
15
- import type { Capsule, TxExecutionRequest, TxProfileResult } from '@aztec/stdlib/tx';
13
+ import { type Capsule, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
16
14
 
17
15
  import { publishContractClass } from '../deployment/publish_class.js';
18
16
  import { publishInstance } from '../deployment/publish_instance.js';
@@ -21,30 +19,71 @@ import { BaseContractInteraction } from './base_contract_interaction.js';
21
19
  import type { Contract } from './contract.js';
22
20
  import type { ContractBase } from './contract_base.js';
23
21
  import { ContractFunctionInteraction } from './contract_function_interaction.js';
24
- import { DeployProvenTx } from './deploy_proven_tx.js';
25
22
  import { DeploySentTx } from './deploy_sent_tx.js';
26
- import type { ProfileMethodOptions, SendMethodOptions } from './interaction_options.js';
23
+ import { getGasLimits } from './get_gas_limits.js';
24
+ import {
25
+ type ProfileInteractionOptions,
26
+ type RequestInteractionOptions,
27
+ type SendInteractionOptions,
28
+ type SimulationInteractionFeeOptions,
29
+ type SimulationReturn,
30
+ toProfileOptions,
31
+ toSendOptions,
32
+ toSimulateOptions,
33
+ } from './interaction_options.js';
27
34
 
28
35
  /**
29
36
  * Options for deploying a contract on the Aztec network.
30
- * Allows specifying a contract address salt, and additional send method options.
37
+ * Allows specifying a contract address salt and different options to tweak contract publication
38
+ * and initialization
31
39
  */
32
- // docs:start:deploy_options
33
- export type DeployOptions = {
40
+ export type RequestDeployOptions = RequestInteractionOptions & {
34
41
  /** An optional salt value used to deterministically calculate the contract address. */
35
42
  contractAddressSalt?: Fr;
36
- /** Set to true to *not* include the sender in the address computation. */
37
- universalDeploy?: boolean;
43
+ /**
44
+ * Deployer address that will be used for the deployed contract's address computation.
45
+ * If set to 0, the sender's address won't be mixed in
46
+ */
47
+ deployer?: AztecAddress;
38
48
  /** Skip contract class publication. */
39
49
  skipClassPublication?: boolean;
40
50
  /** Skip publication, instead just privately initialize the contract. */
41
51
  skipInstancePublication?: boolean;
42
52
  /** Skip contract initialization. */
43
53
  skipInitialization?: boolean;
44
- } & SendMethodOptions;
54
+ };
55
+
56
+ /**
57
+ * Extends the deployment options with the required parameters to send the transaction
58
+ */
59
+ export type DeployOptions = Omit<RequestDeployOptions, 'deployer'> & {
60
+ /**
61
+ * Set to true to *not* include the sender in the address computation. This option
62
+ * is mutually exclusive with "deployer"
63
+ */
64
+ universalDeploy?: boolean;
65
+ } & Pick<SendInteractionOptions, 'from' | 'fee'>;
45
66
  // docs:end:deploy_options
46
67
  // TODO(@spalladino): Add unit tests for this class!
47
68
 
69
+ /**
70
+ * Options for simulating the deployment of a contract
71
+ * Allows skipping certain validations and computing gas estimations
72
+ */
73
+ export type SimulateDeployOptions = Omit<DeployOptions, 'fee'> & {
74
+ /** The fee options for the transaction. */
75
+ fee?: SimulationInteractionFeeOptions;
76
+ /** Simulate without checking for the validity of the resulting transaction,
77
+ * e.g. whether it emits any existing nullifiers. */
78
+ skipTxValidation?: boolean;
79
+ /** Whether to ensure the fee payer is not empty and has enough balance to pay for the fee. */
80
+ skipFeeEnforcement?: boolean;
81
+ /** Whether to include metadata such as offchain effects and performance statistics
82
+ * (e.g. timing information of the different circuits and oracles) in
83
+ * the simulation result, instead of just the return value of the function */
84
+ includeMetadata?: boolean;
85
+ };
86
+
48
87
  /**
49
88
  * Contract interaction for deployment.
50
89
  * Handles class publication, instance publication, and initialization of the contract.
@@ -67,8 +106,8 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
67
106
  constructor(
68
107
  private publicKeys: PublicKeys,
69
108
  wallet: Wallet,
70
- private artifact: ContractArtifact,
71
- private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
109
+ protected artifact: ContractArtifact,
110
+ protected postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
72
111
  private args: any[] = [],
73
112
  constructorNameOrArtifact?: string | FunctionArtifact,
74
113
  authWitnesses: AuthWitness[] = [],
@@ -79,78 +118,43 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
79
118
  }
80
119
 
81
120
  /**
82
- * Prepare a transaction execution request which can optionally (depending on the `options`):
83
- * - Publish the contract's class_id
84
- * - Publish the contract instance data, to enable execution of its public functions.
85
- * - Initialize the contract
86
- *
87
- * A tx is not necessary if the function has no public functions nor any
88
- * initializer function.
89
- *
90
- * This function internally calls `request()` and `sign()` methods to prepare
91
- * the transaction for deployment. The resulting signed transaction can be
92
- * later sent using the `send()` method.
93
- *
94
- * @param options - An object containing optional deployment settings, contractAddressSalt, and from.
95
- * @returns A Promise resolving to an object containing the signed transaction data and other relevant information.
96
- */
97
- public async create(options: DeployOptions): Promise<TxExecutionRequest> {
98
- const requestWithoutFee = await this.request(options);
99
- const { fee: userFee, txNonce, cancellable } = options;
100
- const fee = await this.getFeeOptions(requestWithoutFee, userFee, { txNonce, cancellable });
101
- return this.wallet.createTxExecutionRequest(requestWithoutFee, fee, { txNonce, cancellable });
102
- }
103
-
104
- // REFACTOR: Having a `request` method with different semantics than the ones in the other
105
- // derived ContractInteractions is confusing. We should unify the flow of all ContractInteractions.
106
-
107
- /**
108
- * Returns an array of function calls that represent this operation. Useful as a building
109
- * block for constructing batch requests.
110
- * @param options - Deployment options.
111
- * @returns An array of function calls.
112
- * @remarks This method does not have the same return type as the `request` in the ContractInteraction object,
113
- * it returns a promise for an array instead of a function call directly.
121
+ * Returns the execution payload that allows this operation to happen on chain.
122
+ * @param options - Configuration options.
123
+ * @returns The execution payload for this operation
114
124
  */
115
- public async request(options: DeployOptions): Promise<ExecutionPayload> {
125
+ public async request(options?: RequestDeployOptions): Promise<ExecutionPayload> {
116
126
  const publication = await this.getPublicationExecutionPayload(options);
117
127
 
118
- // TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined?
119
- // Note that we need to run this registerContract here so it's available when computeFeeOptionsFromEstimatedGas
120
- // runs, since it needs the contract to have been registered in order to estimate gas for its initialization,
121
- // in case the initializer is public. This hints at the need of having "transient" contracts scoped to a
122
- // simulation, so we can run the simulation with a set of contracts, but only "commit" them to the wallet
123
- // once this tx has gone through.
124
- await this.wallet.registerContract({ artifact: this.artifact, instance: await this.getInstance(options) });
128
+ await this.wallet.registerContract(await this.getInstance(options), this.artifact);
125
129
 
126
130
  const initialization = await this.getInitializationExecutionPayload(options);
127
- const exec = [publication, initialization];
128
- const fnCalls = exec.map(exec => exec.calls).flat();
129
- if (!fnCalls.length) {
131
+ const feeExecutionPayload = options?.fee?.paymentMethod
132
+ ? await options.fee.paymentMethod.getExecutionPayload()
133
+ : undefined;
134
+ const finalExecutionPayload = feeExecutionPayload
135
+ ? mergeExecutionPayloads([feeExecutionPayload, publication, initialization])
136
+ : mergeExecutionPayloads([publication, initialization]);
137
+ if (!finalExecutionPayload.calls.length) {
130
138
  throw new Error(`No transactions are needed to publish or initialize contract ${this.artifact.name}`);
131
139
  }
132
140
 
133
- return mergeExecutionPayloads(exec);
141
+ return finalExecutionPayload;
134
142
  }
135
143
 
136
- /**
137
- * Simulate a deployment and profile the gate count for each function in the transaction.
138
- * @param options - Same options as `send`, plus extra profiling options.
139
- *
140
- * @returns An object containing the function return value and profile result.
141
- */
142
- public async profile(options: DeployOptions & ProfileMethodOptions): Promise<TxProfileResult> {
143
- const txRequest = await this.create(options);
144
- return await this.wallet.profileTx(txRequest, options.profileMode, options.skipProofGeneration, options?.from);
144
+ convertDeployOptionsToRequestOptions(options: DeployOptions): RequestDeployOptions {
145
+ return {
146
+ ...options,
147
+ deployer: !options?.universalDeploy ? options.from : undefined,
148
+ };
145
149
  }
146
150
 
147
151
  /**
148
- * Adds this contract to the PXE and returns the Contract object.
152
+ * Adds this contract to the wallet and returns the Contract object.
149
153
  * @param options - Deployment options.
150
154
  */
151
- public async register(options: Omit<DeployOptions, 'from'> = {}): Promise<TContract> {
155
+ public async register(options?: RequestDeployOptions): Promise<TContract> {
152
156
  const instance = await this.getInstance(options);
153
- await this.wallet.registerContract({ artifact: this.artifact, instance });
157
+ await this.wallet.registerContract(instance, this.artifact);
154
158
  return this.postDeployCtor(instance.address, this.wallet);
155
159
  }
156
160
 
@@ -162,7 +166,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
162
166
  * @param options - Contract creation options.
163
167
  * @returns An execution payload with potentially calls (and bytecode capsule) to the class registry and instance registry.
164
168
  */
165
- protected async getPublicationExecutionPayload(options: Omit<DeployOptions, 'from'> = {}): Promise<ExecutionPayload> {
169
+ protected async getPublicationExecutionPayload(options?: RequestDeployOptions): Promise<ExecutionPayload> {
166
170
  const calls: ExecutionPayload[] = [];
167
171
 
168
172
  // Set contract instance object so it's available for populating the DeploySendTx object
@@ -178,7 +182,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
178
182
  }
179
183
 
180
184
  // Publish the contract class if it hasn't been published already.
181
- if (!options.skipClassPublication) {
185
+ if (!options?.skipClassPublication) {
182
186
  if ((await this.wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
183
187
  this.log.debug(
184
188
  `Skipping publication of already-registered contract class ${contractClass.id.toString()} for ${instance.address.toString()}`,
@@ -193,7 +197,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
193
197
  }
194
198
 
195
199
  // Publish the contract instance:
196
- if (!options.skipInstancePublication) {
200
+ if (!options?.skipInstancePublication) {
197
201
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/15596):
198
202
  // Read the artifact, and if there are no public functions, warn the caller that publication of the
199
203
  // contract instance is not necessary (until such time as they wish to update the instance (i.e. change its class_id)).
@@ -209,11 +213,9 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
209
213
  * @param options - Deployment options.
210
214
  * @returns - An array of function calls.
211
215
  */
212
- protected async getInitializationExecutionPayload(
213
- options: Omit<DeployOptions, 'from'> = {},
214
- ): Promise<ExecutionPayload> {
216
+ protected async getInitializationExecutionPayload(options?: RequestDeployOptions): Promise<ExecutionPayload> {
215
217
  const executionsPayloads: ExecutionPayload[] = [];
216
- if (this.constructorArtifact && !options.skipInitialization) {
218
+ if (this.constructorArtifact && !options?.skipInitialization) {
217
219
  const { address } = await this.getInstance(options);
218
220
  const constructorCall = new ContractFunctionInteraction(
219
221
  this.wallet,
@@ -235,7 +237,11 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
235
237
  * @returns A SentTx object that returns the receipt and the deployed contract instance.
236
238
  */
237
239
  public override send(options: DeployOptions): DeploySentTx<TContract> {
238
- const sendTx = () => super.send(options).getTxHash();
240
+ const sendTx = async () => {
241
+ const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
242
+ const sendOptions = await toSendOptions(options);
243
+ return this.wallet.sendTx(executionPayload, sendOptions);
244
+ };
239
245
  this.log.debug(`Sent deployment tx of ${this.artifact.name} contract`);
240
246
  return new DeploySentTx(this.wallet, sendTx, this.postDeployCtor, () => this.getInstance(options));
241
247
  }
@@ -246,43 +252,55 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
246
252
  * @param options - An object containing various initialization and publication options.
247
253
  * @returns An instance object.
248
254
  */
249
- public async getInstance(options: Omit<DeployOptions, 'from'> = {}): Promise<ContractInstanceWithAddress> {
255
+ public async getInstance(options?: RequestDeployOptions): Promise<ContractInstanceWithAddress> {
250
256
  if (!this.instance) {
251
257
  this.instance = await getContractInstanceFromInstantiationParams(this.artifact, {
252
258
  constructorArgs: this.args,
253
- salt: options.contractAddressSalt,
259
+ salt: options?.contractAddressSalt ?? Fr.random(),
254
260
  publicKeys: this.publicKeys,
255
261
  constructorArtifact: this.constructorArtifact,
256
- deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(),
262
+ deployer: options?.deployer ? options.deployer : AztecAddress.ZERO,
257
263
  });
258
264
  }
259
265
  return this.instance;
260
266
  }
261
267
 
262
268
  /**
263
- * Prove the request.
264
- * @param options - initialization and publication options.
265
- * @returns The proven tx.
269
+ * Simulate the deployment
270
+ *
271
+ * @param options - An optional object containing additional configuration for the simulation.
272
+ * @returns A simulation result object containing metadata of the execution, including gas
273
+ * estimations (if requested via options), execution statistics and emitted offchain effects
266
274
  */
267
- public override async prove(options: DeployOptions): Promise<DeployProvenTx<TContract>> {
268
- const txProvingResult = await this.proveInternal(options);
269
- return await DeployProvenTx.fromProvingResult(
270
- this.wallet,
271
- txProvingResult,
272
- this.postDeployCtor,
273
- () => this.getInstance(options),
274
- txProvingResult.stats,
275
+ public async simulate(options: SimulateDeployOptions): Promise<SimulationReturn<true>> {
276
+ const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
277
+ const simulatedTx = await this.wallet.simulateTx(executionPayload, await toSimulateOptions(options));
278
+
279
+ const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
280
+ this.log.verbose(
281
+ `Estimated gas limits for tx: DA=${gasLimits.daGas} L2=${gasLimits.l2Gas} teardownDA=${teardownGasLimits.daGas} teardownL2=${teardownGasLimits.l2Gas}`,
275
282
  );
283
+ return {
284
+ stats: simulatedTx.stats!,
285
+ offchainEffects: collectOffchainEffects(simulatedTx.privateExecutionResult),
286
+ result: undefined,
287
+ estimatedGas: { gasLimits, teardownGasLimits },
288
+ };
276
289
  }
277
290
 
278
291
  /**
279
- * Estimates gas cost for this deployment operation.
280
- * @param options - Options.
292
+ * Simulate a deployment and profile the gate count for each function in the transaction.
293
+ * @param options - Same options as `send`, plus extra profiling options.
294
+ *
295
+ * @returns An object containing the function return value and profile result.
281
296
  */
282
- public override estimateGas(
283
- options: Omit<DeployOptions, 'estimateGas'>,
284
- ): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>> {
285
- return super.estimateGas(options);
297
+ public async profile(options: DeployOptions & ProfileInteractionOptions): Promise<TxProfileResult> {
298
+ const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
299
+ return await this.wallet.profileTx(executionPayload, {
300
+ ...(await toProfileOptions(options)),
301
+ profileMode: options.profileMode,
302
+ skipProofGeneration: options.skipProofGeneration,
303
+ });
286
304
  }
287
305
 
288
306
  /** Return this deployment address. */
@@ -2,7 +2,6 @@ import { createLogger } from '@aztec/foundation/log';
2
2
  import type { FieldsOf } from '@aztec/foundation/types';
3
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
5
- import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
6
5
  import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
7
6
 
8
7
  import type { Wallet } from '../wallet/wallet.js';
@@ -57,18 +56,13 @@ export class DeploySentTx<TContract extends Contract = Contract> extends SentTx
57
56
  */
58
57
  public override async wait(opts?: DeployedWaitOpts): Promise<DeployTxReceipt<TContract>> {
59
58
  const receipt = await super.wait(opts);
60
- const contract = await this.getContractObject(opts?.wallet);
61
- return { ...receipt, contract };
62
- }
63
-
64
- protected async getContractObject(wallet?: Wallet): Promise<TContract> {
65
- const isWallet = (pxeWalletOrNode: Wallet | AztecNode | PXE): pxeWalletOrNode is Wallet =>
66
- !!(pxeWalletOrNode as Wallet).createTxExecutionRequest;
67
- const contractWallet = wallet ?? (isWallet(this.pxeWalletOrNode) && this.pxeWalletOrNode);
59
+ // In the case of DeploySentTx we have a guarantee that this.walletOrNode is a Wallet so we can cast it to Wallet.
60
+ const contractWallet = opts?.wallet ?? (this.walletOrNode as Wallet);
68
61
  if (!contractWallet) {
69
62
  throw new Error(`A wallet is required for creating a contract instance`);
70
63
  }
71
64
  const instance = await this.instanceGetter();
72
- return this.postDeployCtor(instance.address, contractWallet) as Promise<TContract>;
65
+ const contract = (await this.postDeployCtor(instance.address, contractWallet)) as TContract;
66
+ return { ...receipt, contract };
73
67
  }
74
68
  }