@aztec/aztec.js 0.0.0-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/README.md +44 -0
  2. package/dest/account/contract.d.ts +37 -0
  3. package/dest/account/contract.d.ts.map +1 -0
  4. package/dest/account/contract.js +16 -0
  5. package/dest/account/index.d.ts +15 -0
  6. package/dest/account/index.d.ts.map +1 -0
  7. package/dest/account/index.js +9 -0
  8. package/dest/account/interface.d.ts +31 -0
  9. package/dest/account/interface.d.ts.map +1 -0
  10. package/dest/account/interface.js +4 -0
  11. package/dest/account/wallet.d.ts +11 -0
  12. package/dest/account/wallet.d.ts.map +1 -0
  13. package/dest/account/wallet.js +3 -0
  14. package/dest/account_manager/deploy_account_method.d.ts +15 -0
  15. package/dest/account_manager/deploy_account_method.d.ts.map +1 -0
  16. package/dest/account_manager/deploy_account_method.js +43 -0
  17. package/dest/account_manager/deploy_account_sent_tx.d.ts +30 -0
  18. package/dest/account_manager/deploy_account_sent_tx.d.ts.map +1 -0
  19. package/dest/account_manager/deploy_account_sent_tx.js +29 -0
  20. package/dest/account_manager/index.d.ts +108 -0
  21. package/dest/account_manager/index.d.ts.map +1 -0
  22. package/dest/account_manager/index.js +159 -0
  23. package/dest/api/abi.d.ts +3 -0
  24. package/dest/api/abi.d.ts.map +1 -0
  25. package/dest/api/abi.js +1 -0
  26. package/dest/api/account.d.ts +3 -0
  27. package/dest/api/account.d.ts.map +1 -0
  28. package/dest/api/account.js +2 -0
  29. package/dest/api/addresses.d.ts +3 -0
  30. package/dest/api/addresses.d.ts.map +1 -0
  31. package/dest/api/addresses.js +2 -0
  32. package/dest/api/cheat_codes.d.ts +26 -0
  33. package/dest/api/cheat_codes.d.ts.map +1 -0
  34. package/dest/api/cheat_codes.js +25 -0
  35. package/dest/api/deployment.d.ts +4 -0
  36. package/dest/api/deployment.d.ts.map +1 -0
  37. package/dest/api/deployment.js +3 -0
  38. package/dest/api/entrypoint.d.ts +2 -0
  39. package/dest/api/entrypoint.d.ts.map +1 -0
  40. package/dest/api/entrypoint.js +1 -0
  41. package/dest/api/eth_address.d.ts +2 -0
  42. package/dest/api/eth_address.d.ts.map +1 -0
  43. package/dest/api/eth_address.js +1 -0
  44. package/dest/api/ethereum/anvil_test_watcher.d.ts +32 -0
  45. package/dest/api/ethereum/anvil_test_watcher.d.ts.map +1 -0
  46. package/dest/api/ethereum/anvil_test_watcher.js +133 -0
  47. package/dest/api/ethereum/chain_monitor.d.ts +25 -0
  48. package/dest/api/ethereum/chain_monitor.d.ts.map +1 -0
  49. package/dest/api/ethereum/chain_monitor.js +74 -0
  50. package/dest/api/ethereum/cheat_codes.d.ts +63 -0
  51. package/dest/api/ethereum/cheat_codes.d.ts.map +1 -0
  52. package/dest/api/ethereum/cheat_codes.js +162 -0
  53. package/dest/api/ethereum/index.d.ts +7 -0
  54. package/dest/api/ethereum/index.d.ts.map +1 -0
  55. package/dest/api/ethereum/index.js +6 -0
  56. package/dest/api/ethereum/l1_contracts.d.ts +3 -0
  57. package/dest/api/ethereum/l1_contracts.d.ts.map +1 -0
  58. package/dest/api/ethereum/l1_contracts.js +13 -0
  59. package/dest/api/ethereum/portal_manager.d.ts +136 -0
  60. package/dest/api/ethereum/portal_manager.d.ts.map +1 -0
  61. package/dest/api/ethereum/portal_manager.js +286 -0
  62. package/dest/api/fee.d.ts +6 -0
  63. package/dest/api/fee.d.ts.map +1 -0
  64. package/dest/api/fee.js +4 -0
  65. package/dest/api/fields.d.ts +2 -0
  66. package/dest/api/fields.d.ts.map +1 -0
  67. package/dest/api/fields.js +1 -0
  68. package/dest/api/interfaces/pxe.d.ts +2 -0
  69. package/dest/api/interfaces/pxe.d.ts.map +1 -0
  70. package/dest/api/interfaces/pxe.js +1 -0
  71. package/dest/api/log.d.ts +2 -0
  72. package/dest/api/log.d.ts.map +1 -0
  73. package/dest/api/log.js +1 -0
  74. package/dest/api/log_id.d.ts +2 -0
  75. package/dest/api/log_id.d.ts.map +1 -0
  76. package/dest/api/log_id.js +1 -0
  77. package/dest/api/tx_hash.d.ts +2 -0
  78. package/dest/api/tx_hash.d.ts.map +1 -0
  79. package/dest/api/tx_hash.js +1 -0
  80. package/dest/api/wallet.d.ts +2 -0
  81. package/dest/api/wallet.d.ts.map +1 -0
  82. package/dest/api/wallet.js +1 -0
  83. package/dest/contract/base_contract_interaction.d.ts +98 -0
  84. package/dest/contract/base_contract_interaction.d.ts.map +1 -0
  85. package/dest/contract/base_contract_interaction.js +149 -0
  86. package/dest/contract/batch_call.d.ts +28 -0
  87. package/dest/contract/batch_call.d.ts.map +1 -0
  88. package/dest/contract/batch_call.js +91 -0
  89. package/dest/contract/checker.d.ts +11 -0
  90. package/dest/contract/checker.d.ts.map +1 -0
  91. package/dest/contract/checker.js +107 -0
  92. package/dest/contract/contract.d.ts +41 -0
  93. package/dest/contract/contract.d.ts.map +1 -0
  94. package/dest/contract/contract.js +52 -0
  95. package/dest/contract/contract_base.d.ts +61 -0
  96. package/dest/contract/contract_base.d.ts.map +1 -0
  97. package/dest/contract/contract_base.js +45 -0
  98. package/dest/contract/contract_function_interaction.d.ts +68 -0
  99. package/dest/contract/contract_function_interaction.d.ts.map +1 -0
  100. package/dest/contract/contract_function_interaction.js +122 -0
  101. package/dest/contract/deploy_method.d.ts +113 -0
  102. package/dest/contract/deploy_method.d.ts.map +1 -0
  103. package/dest/contract/deploy_method.js +212 -0
  104. package/dest/contract/deploy_proven_tx.d.ts +21 -0
  105. package/dest/contract/deploy_proven_tx.d.ts.map +1 -0
  106. package/dest/contract/deploy_proven_tx.js +19 -0
  107. package/dest/contract/deploy_sent_tx.d.ts +45 -0
  108. package/dest/contract/deploy_sent_tx.d.ts.map +1 -0
  109. package/dest/contract/deploy_sent_tx.js +43 -0
  110. package/dest/contract/get_gas_limits.d.ts +18 -0
  111. package/dest/contract/get_gas_limits.d.ts.map +1 -0
  112. package/dest/contract/get_gas_limits.js +10 -0
  113. package/dest/contract/index.d.ts +45 -0
  114. package/dest/contract/index.d.ts.map +1 -0
  115. package/dest/contract/index.js +43 -0
  116. package/dest/contract/protocol_contracts.d.ts +9 -0
  117. package/dest/contract/protocol_contracts.d.ts.map +1 -0
  118. package/dest/contract/protocol_contracts.js +26 -0
  119. package/dest/contract/proven_tx.d.ts +17 -0
  120. package/dest/contract/proven_tx.d.ts.map +1 -0
  121. package/dest/contract/proven_tx.js +22 -0
  122. package/dest/contract/sent_tx.d.ts +61 -0
  123. package/dest/contract/sent_tx.d.ts.map +1 -0
  124. package/dest/contract/sent_tx.js +102 -0
  125. package/dest/contract/unsafe_contract.d.ts +15 -0
  126. package/dest/contract/unsafe_contract.d.ts.map +1 -0
  127. package/dest/contract/unsafe_contract.js +6 -0
  128. package/dest/deployment/broadcast_function.d.ts +24 -0
  129. package/dest/deployment/broadcast_function.d.ts.map +1 -0
  130. package/dest/deployment/broadcast_function.js +70 -0
  131. package/dest/deployment/contract_deployer.d.ts +27 -0
  132. package/dest/deployment/contract_deployer.d.ts.map +1 -0
  133. package/dest/deployment/contract_deployer.js +30 -0
  134. package/dest/deployment/deploy_instance.d.ts +10 -0
  135. package/dest/deployment/deploy_instance.d.ts.map +1 -0
  136. package/dest/deployment/deploy_instance.js +14 -0
  137. package/dest/deployment/index.d.ts +2 -0
  138. package/dest/deployment/index.d.ts.map +1 -0
  139. package/dest/deployment/index.js +1 -0
  140. package/dest/deployment/register_class.d.ts +6 -0
  141. package/dest/deployment/register_class.d.ts.map +1 -0
  142. package/dest/deployment/register_class.js +22 -0
  143. package/dest/entrypoint/default_entrypoint.d.ts +12 -0
  144. package/dest/entrypoint/default_entrypoint.d.ts.map +1 -0
  145. package/dest/entrypoint/default_entrypoint.js +28 -0
  146. package/dest/entrypoint/default_multi_call_entrypoint.d.ts +15 -0
  147. package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -0
  148. package/dest/entrypoint/default_multi_call_entrypoint.js +130 -0
  149. package/dest/entrypoint/entrypoint.d.ts +35 -0
  150. package/dest/entrypoint/entrypoint.d.ts.map +1 -0
  151. package/dest/entrypoint/entrypoint.js +4 -0
  152. package/dest/entrypoint/payload.d.ts +128 -0
  153. package/dest/entrypoint/payload.d.ts.map +1 -0
  154. package/dest/entrypoint/payload.js +143 -0
  155. package/dest/fee/fee_juice_payment_method.d.ts +14 -0
  156. package/dest/fee/fee_juice_payment_method.d.ts.map +1 -0
  157. package/dest/fee/fee_juice_payment_method.js +20 -0
  158. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +18 -0
  159. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
  160. package/dest/fee/fee_juice_payment_method_with_claim.js +37 -0
  161. package/dest/fee/fee_payment_method.d.ts +22 -0
  162. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  163. package/dest/fee/fee_payment_method.js +3 -0
  164. package/dest/fee/private_fee_payment_method.d.ts +51 -0
  165. package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
  166. package/dest/fee/private_fee_payment_method.js +103 -0
  167. package/dest/fee/public_fee_payment_method.d.ts +41 -0
  168. package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
  169. package/dest/fee/public_fee_payment_method.js +97 -0
  170. package/dest/index.d.ts +66 -0
  171. package/dest/index.d.ts.map +1 -0
  172. package/dest/index.js +69 -0
  173. package/dest/rpc_clients/index.d.ts +3 -0
  174. package/dest/rpc_clients/index.d.ts.map +1 -0
  175. package/dest/rpc_clients/index.js +2 -0
  176. package/dest/rpc_clients/node/index.d.ts +12 -0
  177. package/dest/rpc_clients/node/index.d.ts.map +1 -0
  178. package/dest/rpc_clients/node/index.js +78 -0
  179. package/dest/rpc_clients/pxe_client.d.ts +10 -0
  180. package/dest/rpc_clients/pxe_client.d.ts.map +1 -0
  181. package/dest/rpc_clients/pxe_client.js +23 -0
  182. package/dest/utils/abi_types.d.ts +29 -0
  183. package/dest/utils/abi_types.d.ts.map +1 -0
  184. package/dest/utils/abi_types.js +1 -0
  185. package/dest/utils/authwit.d.ts +60 -0
  186. package/dest/utils/authwit.d.ts.map +1 -0
  187. package/dest/utils/authwit.js +74 -0
  188. package/dest/utils/aztec_cheatcodes.d.ts +59 -0
  189. package/dest/utils/aztec_cheatcodes.d.ts.map +1 -0
  190. package/dest/utils/aztec_cheatcodes.js +62 -0
  191. package/dest/utils/fee_juice.d.ts +7 -0
  192. package/dest/utils/fee_juice.d.ts.map +1 -0
  193. package/dest/utils/fee_juice.js +9 -0
  194. package/dest/utils/field_compressed_string.d.ts +17 -0
  195. package/dest/utils/field_compressed_string.d.ts.map +1 -0
  196. package/dest/utils/field_compressed_string.js +15 -0
  197. package/dest/utils/index.d.ts +8 -0
  198. package/dest/utils/index.d.ts.map +1 -0
  199. package/dest/utils/index.js +6 -0
  200. package/dest/utils/node.d.ts +5 -0
  201. package/dest/utils/node.d.ts.map +1 -0
  202. package/dest/utils/node.js +15 -0
  203. package/dest/utils/pub_key.d.ts +9 -0
  204. package/dest/utils/pub_key.d.ts.map +1 -0
  205. package/dest/utils/pub_key.js +9 -0
  206. package/dest/utils/pxe.d.ts +4 -0
  207. package/dest/utils/pxe.d.ts.map +1 -0
  208. package/dest/utils/pxe.js +14 -0
  209. package/dest/wallet/account_wallet.d.ts +76 -0
  210. package/dest/wallet/account_wallet.d.ts.map +1 -0
  211. package/dest/wallet/account_wallet.js +231 -0
  212. package/dest/wallet/account_wallet_with_private_key.d.ts +26 -0
  213. package/dest/wallet/account_wallet_with_private_key.d.ts.map +1 -0
  214. package/dest/wallet/account_wallet_with_private_key.js +22 -0
  215. package/dest/wallet/base_wallet.d.ts +73 -0
  216. package/dest/wallet/base_wallet.d.ts.map +1 -0
  217. package/dest/wallet/base_wallet.js +123 -0
  218. package/dest/wallet/index.d.ts +17 -0
  219. package/dest/wallet/index.d.ts.map +1 -0
  220. package/dest/wallet/index.js +20 -0
  221. package/dest/wallet/signerless_wallet.d.ts +25 -0
  222. package/dest/wallet/signerless_wallet.d.ts.map +1 -0
  223. package/dest/wallet/signerless_wallet.js +36 -0
  224. package/package.json +116 -0
  225. package/src/account/contract.ts +56 -0
  226. package/src/account/index.ts +16 -0
  227. package/src/account/interface.ts +36 -0
  228. package/src/account/wallet.ts +13 -0
  229. package/src/account_manager/deploy_account_method.ts +86 -0
  230. package/src/account_manager/deploy_account_sent_tx.ts +42 -0
  231. package/src/account_manager/index.ts +229 -0
  232. package/src/api/README.md +7 -0
  233. package/src/api/abi.ts +10 -0
  234. package/src/api/account.ts +10 -0
  235. package/src/api/addresses.ts +2 -0
  236. package/src/api/cheat_codes.ts +35 -0
  237. package/src/api/deployment.ts +3 -0
  238. package/src/api/entrypoint.ts +1 -0
  239. package/src/api/eth_address.ts +1 -0
  240. package/src/api/ethereum/anvil_test_watcher.ts +158 -0
  241. package/src/api/ethereum/chain_monitor.ts +88 -0
  242. package/src/api/ethereum/cheat_codes.ts +184 -0
  243. package/src/api/ethereum/index.ts +19 -0
  244. package/src/api/ethereum/l1_contracts.ts +21 -0
  245. package/src/api/ethereum/portal_manager.ts +410 -0
  246. package/src/api/fee.ts +5 -0
  247. package/src/api/fields.ts +1 -0
  248. package/src/api/interfaces/pxe.ts +1 -0
  249. package/src/api/log.ts +1 -0
  250. package/src/api/log_id.ts +1 -0
  251. package/src/api/tx_hash.ts +1 -0
  252. package/src/api/wallet.ts +7 -0
  253. package/src/contract/base_contract_interaction.ts +192 -0
  254. package/src/contract/batch_call.ts +95 -0
  255. package/src/contract/checker.ts +117 -0
  256. package/src/contract/contract.ts +69 -0
  257. package/src/contract/contract_base.ts +90 -0
  258. package/src/contract/contract_function_interaction.ts +173 -0
  259. package/src/contract/deploy_method.ts +271 -0
  260. package/src/contract/deploy_proven_tx.ts +34 -0
  261. package/src/contract/deploy_sent_tx.ts +74 -0
  262. package/src/contract/get_gas_limits.ts +26 -0
  263. package/src/contract/index.ts +48 -0
  264. package/src/contract/protocol_contracts.ts +35 -0
  265. package/src/contract/proven_tx.ts +42 -0
  266. package/src/contract/sent_tx.ts +141 -0
  267. package/src/contract/unsafe_contract.ts +19 -0
  268. package/src/deployment/broadcast_function.ts +148 -0
  269. package/src/deployment/contract_deployer.ts +41 -0
  270. package/src/deployment/deploy_instance.ts +31 -0
  271. package/src/deployment/index.ts +1 -0
  272. package/src/deployment/register_class.ts +44 -0
  273. package/src/entrypoint/default_entrypoint.ts +39 -0
  274. package/src/entrypoint/default_multi_call_entrypoint.ts +93 -0
  275. package/src/entrypoint/entrypoint.ts +39 -0
  276. package/src/entrypoint/payload.ts +238 -0
  277. package/src/fee/fee_juice_payment_method.ts +26 -0
  278. package/src/fee/fee_juice_payment_method_with_claim.ts +49 -0
  279. package/src/fee/fee_payment_method.ts +22 -0
  280. package/src/fee/private_fee_payment_method.ts +118 -0
  281. package/src/fee/public_fee_payment_method.ts +114 -0
  282. package/src/index.ts +106 -0
  283. package/src/rpc_clients/index.ts +2 -0
  284. package/src/rpc_clients/node/index.ts +77 -0
  285. package/src/rpc_clients/pxe_client.ts +25 -0
  286. package/src/utils/abi_types.ts +25 -0
  287. package/src/utils/authwit.ts +110 -0
  288. package/src/utils/aztec_cheatcodes.ts +77 -0
  289. package/src/utils/fee_juice.ts +14 -0
  290. package/src/utils/field_compressed_string.ts +27 -0
  291. package/src/utils/index.ts +21 -0
  292. package/src/utils/node.ts +19 -0
  293. package/src/utils/pub_key.ts +13 -0
  294. package/src/utils/pxe.ts +17 -0
  295. package/src/wallet/account_wallet.ts +242 -0
  296. package/src/wallet/account_wallet_with_private_key.ts +40 -0
  297. package/src/wallet/base_wallet.ts +198 -0
  298. package/src/wallet/index.ts +33 -0
  299. package/src/wallet/signerless_wallet.ts +52 -0
@@ -0,0 +1,271 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import { type ContractArtifact, type FunctionArtifact, type FunctionCall, getInitializer } from '@aztec/stdlib/abi';
3
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import {
5
+ type ContractInstanceWithAddress,
6
+ computePartialAddress,
7
+ getContractClassFromArtifact,
8
+ getContractInstanceFromDeployParams,
9
+ } from '@aztec/stdlib/contract';
10
+ import type { GasSettings } from '@aztec/stdlib/gas';
11
+ import type { PublicKeys } from '@aztec/stdlib/keys';
12
+ import type { Capsule, TxExecutionRequest } from '@aztec/stdlib/tx';
13
+
14
+ import type { Wallet } from '../account/index.js';
15
+ import { deployInstance } from '../deployment/deploy_instance.js';
16
+ import { registerContractClass } from '../deployment/register_class.js';
17
+ import type { ExecutionRequestInit } from '../entrypoint/entrypoint.js';
18
+ import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
19
+ import type { Contract } from './contract.js';
20
+ import type { ContractBase } from './contract_base.js';
21
+ import { ContractFunctionInteraction } from './contract_function_interaction.js';
22
+ import { DeployProvenTx } from './deploy_proven_tx.js';
23
+ import { DeploySentTx } from './deploy_sent_tx.js';
24
+
25
+ /**
26
+ * Options for deploying a contract on the Aztec network.
27
+ * Allows specifying a contract address salt, and additional send method options.
28
+ */
29
+ // docs:start:deploy_options
30
+ export type DeployOptions = {
31
+ /** An optional salt value used to deterministically calculate the contract address. */
32
+ contractAddressSalt?: Fr;
33
+ /** Set to true to *not* include the sender in the address computation. */
34
+ universalDeploy?: boolean;
35
+ /** Skip contract class registration. */
36
+ skipClassRegistration?: boolean;
37
+ /** Skip public deployment, instead just privately initialize the contract. */
38
+ skipPublicDeployment?: boolean;
39
+ /** Skip contract initialization. */
40
+ skipInitialization?: boolean;
41
+ } & SendMethodOptions;
42
+ // docs:end:deploy_options
43
+ // TODO(@spalladino): Add unit tests for this class!
44
+
45
+ /**
46
+ * Contract interaction for deployment. Handles class registration, public instance deployment,
47
+ * and initialization of the contract. Extends the BaseContractInteraction class.
48
+ */
49
+ export class DeployMethod<TContract extends ContractBase = Contract> extends BaseContractInteraction {
50
+ /** The contract instance to be deployed. */
51
+ private instance?: ContractInstanceWithAddress = undefined;
52
+
53
+ /** Constructor function to call. */
54
+ private constructorArtifact: FunctionArtifact | undefined;
55
+
56
+ constructor(
57
+ private publicKeys: PublicKeys,
58
+ wallet: Wallet,
59
+ private artifact: ContractArtifact,
60
+ private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
61
+ private args: any[] = [],
62
+ constructorNameOrArtifact?: string | FunctionArtifact,
63
+ ) {
64
+ super(wallet);
65
+ this.constructorArtifact = getInitializer(artifact, constructorNameOrArtifact);
66
+ }
67
+
68
+ /**
69
+ * Create a contract deployment transaction, given the deployment options.
70
+ * This function internally calls `request()` and `sign()` methods to prepare
71
+ * the transaction for deployment. The resulting signed transaction can be
72
+ * later sent using the `send()` method.
73
+ *
74
+ * @param options - An object containing optional deployment settings, contractAddressSalt, and from.
75
+ * @returns A Promise resolving to an object containing the signed transaction data and other relevant information.
76
+ */
77
+ public async create(options: DeployOptions = {}): Promise<TxExecutionRequest> {
78
+ return this.wallet.createTxExecutionRequest(await this.request(options));
79
+ }
80
+
81
+ // REFACTOR: Having a `request` method with different semantics than the ones in the other
82
+ // derived ContractInteractions is confusing. We should unify the flow of all ContractInteractions.
83
+
84
+ /**
85
+ * Returns an array of function calls that represent this operation. Useful as a building
86
+ * block for constructing batch requests.
87
+ * @param options - Deployment options.
88
+ * @returns An array of function calls.
89
+ * @remarks This method does not have the same return type as the `request` in the ContractInteraction object,
90
+ * it returns a promise for an array instead of a function call directly.
91
+ */
92
+ public async request(options: DeployOptions = {}): Promise<ExecutionRequestInit> {
93
+ const deployment = await this.getDeploymentFunctionCalls(options);
94
+
95
+ // NOTE: MEGA HACK. Remove with #10007
96
+ // register the contract after generating deployment function calls in order to publicly register the class and (optioanlly) emit its bytecode
97
+ //
98
+ // TODO: Should we add the contracts to the DB here, or once the tx has been sent or mined?
99
+ // Note that we need to run this registerContract here so it's available when computeFeeOptionsFromEstimatedGas
100
+ // runs, since it needs the contract to have been registered in order to estimate gas for its initialization,
101
+ // in case the initializer is public. This hints at the need of having "transient" contracts scoped to a
102
+ // simulation, so we can run the simulation with a set of contracts, but only "commit" them to the wallet
103
+ // once this tx has gone through.
104
+ await this.wallet.registerContract({ artifact: this.artifact, instance: await this.getInstance(options) });
105
+
106
+ const bootstrap = await this.getInitializeFunctionCalls(options);
107
+
108
+ if (deployment.calls.length + bootstrap.calls.length === 0) {
109
+ throw new Error(`No function calls needed to deploy contract ${this.artifact.name}`);
110
+ }
111
+
112
+ const calls = [...deployment.calls, ...bootstrap.calls];
113
+ const authWitnesses = [...(deployment.authWitnesses ?? []), ...(bootstrap.authWitnesses ?? [])];
114
+ const hashedArguments = [...(deployment.hashedArguments ?? []), ...(bootstrap.hashedArguments ?? [])];
115
+ const capsules = [...(deployment.capsules ?? []), ...(bootstrap.capsules ?? [])];
116
+ const { cancellable, nonce, fee: userFee } = options;
117
+
118
+ const request = { calls, authWitnesses, hashedArguments, capsules, cancellable, fee: userFee, nonce };
119
+
120
+ const fee = await this.getFeeOptions(request);
121
+ return { ...request, fee };
122
+ }
123
+
124
+ /**
125
+ * Register this contract in the PXE and returns the Contract object.
126
+ * @param options - Deployment options.
127
+ */
128
+ public async register(options: DeployOptions = {}): Promise<TContract> {
129
+ const instance = await this.getInstance(options);
130
+ await this.wallet.registerContract({ artifact: this.artifact, instance });
131
+ return this.postDeployCtor(instance.address, this.wallet);
132
+ }
133
+
134
+ /**
135
+ * Returns calls for registration of the class and deployment of the instance, depending on the provided options.
136
+ * @param options - Deployment options.
137
+ * @returns A function call array with potentially requests to the class registerer and instance deployer.
138
+ */
139
+ protected async getDeploymentFunctionCalls(
140
+ options: DeployOptions = {},
141
+ ): Promise<Pick<ExecutionRequestInit, 'calls' | 'authWitnesses' | 'hashedArguments' | 'capsules'>> {
142
+ const calls: FunctionCall[] = [];
143
+ const capsules: Capsule[] = [];
144
+
145
+ // Set contract instance object so it's available for populating the DeploySendTx object
146
+ const instance = await this.getInstance(options);
147
+
148
+ // Obtain contract class from artifact and check it matches the reported one by the instance.
149
+ // TODO(@spalladino): We're unnecessarily calculating the contract class multiple times here.
150
+ const contractClass = await getContractClassFromArtifact(this.artifact);
151
+ if (!instance.currentContractClassId.equals(contractClass.id)) {
152
+ throw new Error(
153
+ `Contract class mismatch when deploying contract: got ${instance.currentContractClassId.toString()} from instance and ${contractClass.id.toString()} from artifact`,
154
+ );
155
+ }
156
+
157
+ // Register the contract class if it hasn't been published already.
158
+ if (!options.skipClassRegistration) {
159
+ if ((await this.wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
160
+ this.log.debug(
161
+ `Skipping registration of already registered contract class ${contractClass.id.toString()} for ${instance.address.toString()}`,
162
+ );
163
+ } else {
164
+ this.log.info(
165
+ `Creating request for registering contract class ${contractClass.id.toString()} as part of deployment for ${instance.address.toString()}`,
166
+ );
167
+ const registerContractClassInteraction = await registerContractClass(this.wallet, this.artifact);
168
+ calls.push(await registerContractClassInteraction.request());
169
+ capsules.push(...registerContractClassInteraction.getCapsules());
170
+ }
171
+ }
172
+
173
+ // Deploy the contract via the instance deployer.
174
+ if (!options.skipPublicDeployment) {
175
+ const deploymentInteraction = await deployInstance(this.wallet, instance);
176
+ calls.push(await deploymentInteraction.request());
177
+ capsules.push(...deploymentInteraction.getCapsules());
178
+ }
179
+
180
+ return { calls, capsules };
181
+ }
182
+
183
+ /**
184
+ * Returns the calls necessary to initialize the contract.
185
+ * @param options - Deployment options.
186
+ * @returns - An array of function calls.
187
+ */
188
+ protected async getInitializeFunctionCalls(
189
+ options: DeployOptions,
190
+ ): Promise<Pick<ExecutionRequestInit, 'calls' | 'authWitnesses' | 'hashedArguments' | 'capsules'>> {
191
+ const { address } = await this.getInstance(options);
192
+ const calls: FunctionCall[] = [];
193
+ const capsules: Capsule[] = [];
194
+ if (this.constructorArtifact && !options.skipInitialization) {
195
+ const constructorCall = new ContractFunctionInteraction(
196
+ this.wallet,
197
+ address,
198
+ this.constructorArtifact,
199
+ this.args,
200
+ );
201
+ calls.push(await constructorCall.request());
202
+ capsules.push(...constructorCall.getCapsules());
203
+ }
204
+ return { calls, capsules };
205
+ }
206
+
207
+ /**
208
+ * Send the contract deployment transaction using the provided options.
209
+ * This function extends the 'send' method from the ContractFunctionInteraction class,
210
+ * allowing us to send a transaction specifically for contract deployment.
211
+ *
212
+ * @param options - An object containing various deployment options such as contractAddressSalt and from.
213
+ * @returns A SentTx object that returns the receipt and the deployed contract instance.
214
+ */
215
+ public override send(options: DeployOptions = {}): DeploySentTx<TContract> {
216
+ const txHashPromise = super.send(options).getTxHash();
217
+ this.log.debug(`Sent deployment tx of ${this.artifact.name} contract`);
218
+ return new DeploySentTx(this.wallet, txHashPromise, this.postDeployCtor, () => this.getInstance(options));
219
+ }
220
+
221
+ /**
222
+ * Builds the contract instance to be deployed and returns it.
223
+ *
224
+ * @param options - An object containing various deployment options.
225
+ * @returns An instance object.
226
+ */
227
+ public async getInstance(options: DeployOptions = {}): Promise<ContractInstanceWithAddress> {
228
+ if (!this.instance) {
229
+ this.instance = await getContractInstanceFromDeployParams(this.artifact, {
230
+ constructorArgs: this.args,
231
+ salt: options.contractAddressSalt,
232
+ publicKeys: this.publicKeys,
233
+ constructorArtifact: this.constructorArtifact,
234
+ deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(),
235
+ });
236
+ }
237
+ return this.instance;
238
+ }
239
+
240
+ /**
241
+ * Prove the request.
242
+ * @param options - Deployment options.
243
+ * @returns The proven tx.
244
+ */
245
+ public override async prove(options: DeployOptions): Promise<DeployProvenTx<TContract>> {
246
+ const txProvingResult = await this.proveInternal(options);
247
+ return new DeployProvenTx(this.wallet, txProvingResult.toTx(), this.postDeployCtor, () =>
248
+ this.getInstance(options),
249
+ );
250
+ }
251
+
252
+ /**
253
+ * Estimates gas cost for this deployment operation.
254
+ * @param options - Options.
255
+ */
256
+ public override estimateGas(
257
+ options?: Omit<DeployOptions, 'estimateGas' | 'skipPublicSimulation'>,
258
+ ): Promise<Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>> {
259
+ return super.estimateGas(options);
260
+ }
261
+
262
+ /** Return this deployment address. */
263
+ public get address() {
264
+ return this.instance?.address;
265
+ }
266
+
267
+ /** Returns the partial address for this deployment. */
268
+ public get partialAddress() {
269
+ return this.instance && computePartialAddress(this.instance);
270
+ }
271
+ }
@@ -0,0 +1,34 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
4
+ import type { Tx } from '@aztec/stdlib/tx';
5
+
6
+ import type { Wallet } from '../account/index.js';
7
+ import type { Contract } from './contract.js';
8
+ import { DeploySentTx } from './deploy_sent_tx.js';
9
+ import { ProvenTx } from './proven_tx.js';
10
+
11
+ /**
12
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of a contract deployment.
13
+ */
14
+ export class DeployProvenTx<TContract extends Contract = Contract> extends ProvenTx {
15
+ constructor(
16
+ wallet: PXE | Wallet,
17
+ tx: Tx,
18
+ private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
19
+ private instanceGetter: () => Promise<ContractInstanceWithAddress>,
20
+ ) {
21
+ super(wallet, tx);
22
+ }
23
+
24
+ /**
25
+ * Sends the transaction to the network via the provided wallet.
26
+ */
27
+ public override send(): DeploySentTx<TContract> {
28
+ const promise = (() => {
29
+ return this.wallet.sendTx(this.getPlainDataTx());
30
+ })();
31
+
32
+ return new DeploySentTx(this.wallet, promise, this.postDeployCtor, this.instanceGetter);
33
+ }
34
+ }
@@ -0,0 +1,74 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import type { FieldsOf } from '@aztec/foundation/types';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
5
+ import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
6
+ import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
7
+
8
+ import type { Wallet } from '../account/index.js';
9
+ import type { Contract } from './contract.js';
10
+ import type { ContractBase } from './contract_base.js';
11
+ import { SentTx, type WaitOpts } from './sent_tx.js';
12
+
13
+ /** Options related to waiting for a deployment tx. */
14
+ export type DeployedWaitOpts = WaitOpts & {
15
+ /** Wallet to use for creating a contract instance. Uses the one set in the deployer constructor if not set. */
16
+ wallet?: Wallet;
17
+ };
18
+
19
+ /** Extends a transaction receipt with a contract instance that represents the newly deployed contract. */
20
+ export type DeployTxReceipt<TContract extends ContractBase = Contract> = FieldsOf<TxReceipt> & {
21
+ /** Instance of the newly deployed contract. */
22
+ contract: TContract;
23
+ };
24
+
25
+ /**
26
+ * A contract deployment transaction sent to the network, extending SentTx with methods to create a contract instance.
27
+ */
28
+ export class DeploySentTx<TContract extends Contract = Contract> extends SentTx {
29
+ private log = createLogger('aztecjs:deploy_sent_tx');
30
+
31
+ constructor(
32
+ pxeOrWallet: PXE | Wallet,
33
+ txHashPromise: Promise<TxHash>,
34
+ private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
35
+ /** A getter for the deployed contract instance */
36
+ public instanceGetter: () => Promise<ContractInstanceWithAddress>,
37
+ ) {
38
+ super(pxeOrWallet, txHashPromise);
39
+ }
40
+
41
+ /**
42
+ * Awaits for the tx to be mined and returns the contract instance. Throws if tx is not mined.
43
+ * @param opts - Options for configuring the waiting for the tx to be mined.
44
+ * @returns The deployed contract instance.
45
+ */
46
+ public async deployed(opts?: DeployedWaitOpts): Promise<TContract> {
47
+ const receipt = await this.wait(opts);
48
+ const instance = await this.instanceGetter();
49
+ this.log.info(`Contract ${instance.address.toString()} successfully deployed.`);
50
+ return receipt.contract;
51
+ }
52
+
53
+ /**
54
+ * Awaits for the tx to be mined and returns the receipt along with a contract instance. Throws if tx is not mined.
55
+ * @param opts - Options for configuring the waiting for the tx to be mined.
56
+ * @returns The transaction receipt with the deployed contract instance.
57
+ */
58
+ public override async wait(opts?: DeployedWaitOpts): Promise<DeployTxReceipt<TContract>> {
59
+ 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 = (pxeOrWallet: PXE | Wallet | AztecNode): pxeOrWallet is Wallet =>
66
+ !!(pxeOrWallet as Wallet).createTxExecutionRequest;
67
+ const contractWallet = wallet ?? (isWallet(this.pxeOrNode) && this.pxeOrNode);
68
+ if (!contractWallet) {
69
+ throw new Error(`A wallet is required for creating a contract instance`);
70
+ }
71
+ const instance = await this.instanceGetter();
72
+ return this.postDeployCtor(instance.address, contractWallet) as Promise<TContract>;
73
+ }
74
+ }
@@ -0,0 +1,26 @@
1
+ import type { Gas } from '@aztec/stdlib/gas';
2
+ import type { TxSimulationResult } from '@aztec/stdlib/tx';
3
+
4
+ /**
5
+ * Returns suggested total and teardown gas limits for a simulated tx.
6
+ * Note that public gas usage is only accounted for if the publicOutput is present.
7
+ * @param pad - Percentage to pad the suggested gas limits by, (as decimal, e.g., 0.10 for 10%).
8
+ */
9
+ export function getGasLimits(
10
+ simulationResult: TxSimulationResult,
11
+ pad = 0.1,
12
+ ): {
13
+ /**
14
+ * Total gas used across private and public
15
+ */
16
+ totalGas: Gas;
17
+ /**
18
+ * Teardown gas used
19
+ */
20
+ teardownGas: Gas;
21
+ } {
22
+ return {
23
+ totalGas: simulationResult.gasUsed.totalGas.mul(1 + pad),
24
+ teardownGas: simulationResult.gasUsed.teardownGas.mul(1 + pad),
25
+ };
26
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The `contract` module provides utilities for deploying and interacting with contracts, based on a
3
+ * `Wallet` instance and a compiled artifact. Refer to the {@link account} module for how to obtain a valid
4
+ * `Wallet` instance, and to the {@link https://docs.aztec.network/developers/guides/smart_contracts/how_to_compile_contract | Compiling contracts}
5
+ * section of the documentation for how to generate an artifact out of your Noir source code.
6
+ *
7
+ * The {@link Contract} class is the main class in this module, and provides static methods for deploying
8
+ * a contract or interacting with an already deployed one. The `methods` property of the contract instance
9
+ * provides access to private, public, and simulate methods, that can be invoked in a transaction via `send()`,
10
+ * or can be queried via `simulate()`.
11
+ *
12
+ * ```ts
13
+ * const contract = await Contract.deploy(wallet, MyContractArtifact, [...constructorArgs]).send().deployed();
14
+ * console.log(`Contract deployed at ${contract.address}`);
15
+ * ```
16
+ *
17
+ * ```ts
18
+ * const contract = await Contract.at(address, MyContractArtifact, wallet);
19
+ * await contract.methods.mint(1000, owner).send().wait();
20
+ * console.log(`Total supply is now ${await contract.methods.totalSupply().simulate()}`);
21
+ * ```
22
+ *
23
+ * The result of calling a method in a contract instance, such as `contract.methods.mint(1000, owner)`
24
+ * in the example, is a {@link ContractFunctionInteraction} instance. Usually this will be just sent as
25
+ * a transaction to the network via the `send` method, but you can also `simulate` it without sending,
26
+ * or obtaining the `request` for aggregating into a {@link BatchCall}.
27
+ *
28
+ * The result of `send`ing a transaction is a {@link SentTx} object, from which you can get the
29
+ * transaction hash, or simply `wait` until the transaction is mined and the local PXE Service
30
+ * has synchronized its changes.
31
+ *
32
+ * @remarks If you are using typescript, consider using the
33
+ * {@link https://docs.aztec.network/developers/guides/smart_contracts/how_to_compile_contract#typescript-interfaces | autogenerated type-safe interfaces}
34
+ * for interacting with your contracts.
35
+ *
36
+ * @packageDocumentation
37
+ */
38
+ export { Contract } from './contract.js';
39
+ export {
40
+ ContractFunctionInteraction,
41
+ type ProfileResult,
42
+ type SendMethodOptions,
43
+ } from './contract_function_interaction.js';
44
+ export { DefaultWaitOpts, SentTx, type WaitOpts } from './sent_tx.js';
45
+ export { ContractBase, type ContractMethod, type ContractNotes, type ContractStorageLayout } from './contract_base.js';
46
+ export { BatchCall } from './batch_call.js';
47
+ export { type DeployOptions, DeployMethod } from './deploy_method.js';
48
+ export { DeploySentTx } from './deploy_sent_tx.js';
@@ -0,0 +1,35 @@
1
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
+
3
+ import type { Wallet } from '../wallet/index.js';
4
+ import { UnsafeContract } from './unsafe_contract.js';
5
+
6
+ /** Returns a Contract wrapper for the class registerer. */
7
+ export async function getRegistererContract(wallet: Wallet) {
8
+ const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractClassRegisterer);
9
+ if (!contractInstance) {
10
+ throw new Error("ContractClassRegisterer is not registered in this wallet's instance");
11
+ }
12
+ const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
13
+
14
+ return new UnsafeContract(contractInstance!, artifact!, wallet);
15
+ }
16
+
17
+ /** Returns a Contract wrapper for the instance deployer. */
18
+ export async function getDeployerContract(wallet: Wallet) {
19
+ const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractInstanceDeployer);
20
+ if (!contractInstance) {
21
+ throw new Error("ContractInstanceDeployer is not registered in this wallet's instance");
22
+ }
23
+ const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
24
+ return new UnsafeContract(contractInstance!, artifact!, wallet);
25
+ }
26
+
27
+ /** Returns a Contract wrapper for the fee juice */
28
+ export async function getFeeJuice(wallet: Wallet) {
29
+ const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.FeeJuice);
30
+ if (!contractInstance) {
31
+ throw new Error("FeeJuice is not registered in this wallet's instance");
32
+ }
33
+ const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
34
+ return new UnsafeContract(contractInstance!, artifact!, wallet);
35
+ }
@@ -0,0 +1,42 @@
1
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
2
+ import { Tx } from '@aztec/stdlib/tx';
3
+
4
+ import type { Wallet } from '../account/index.js';
5
+ import { SentTx } from './sent_tx.js';
6
+
7
+ /**
8
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of a contract interaction.
9
+ */
10
+ export class ProvenTx extends Tx {
11
+ constructor(protected wallet: PXE | Wallet, tx: Tx) {
12
+ super(
13
+ tx.data,
14
+ tx.clientIvcProof,
15
+ tx.contractClassLogs,
16
+ tx.enqueuedPublicFunctionCalls,
17
+ tx.publicTeardownFunctionCall,
18
+ );
19
+ }
20
+
21
+ // Clone the TX data to get a serializable object.
22
+ protected getPlainDataTx(): Tx {
23
+ return new Tx(
24
+ this.data,
25
+ this.clientIvcProof,
26
+ this.contractClassLogs,
27
+ this.enqueuedPublicFunctionCalls,
28
+ this.publicTeardownFunctionCall,
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Sends the transaction to the network via the provided wallet.
34
+ */
35
+ public send(): SentTx {
36
+ const promise = (() => {
37
+ return this.wallet.sendTx(this.getPlainDataTx());
38
+ })();
39
+
40
+ return new SentTx(this.wallet, promise);
41
+ }
42
+ }
@@ -0,0 +1,141 @@
1
+ import { retryUntil } from '@aztec/foundation/retry';
2
+ import type { FieldsOf } from '@aztec/foundation/types';
3
+ import type { AztecNode, GetPublicLogsResponse, PXE } from '@aztec/stdlib/interfaces/client';
4
+ import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
5
+
6
+ /** Options related to waiting for a tx. */
7
+ export type WaitOpts = {
8
+ /** 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. */
9
+ ignoreDroppedReceiptsFor?: number;
10
+ /** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
11
+ timeout?: number;
12
+ /** The maximum time (in seconds) to wait for the transaction to be proven. Defaults to 600. */
13
+ provenTimeout?: number;
14
+ /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
15
+ interval?: number;
16
+ /** Whether to wait for the tx to be proven. */
17
+ proven?: boolean;
18
+ /** Whether to include information useful for debugging/testing in the receipt. */
19
+ debug?: boolean;
20
+ /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
21
+ dontThrowOnRevert?: boolean;
22
+ };
23
+
24
+ export const DefaultWaitOpts: WaitOpts = {
25
+ ignoreDroppedReceiptsFor: 5,
26
+ timeout: 60,
27
+ provenTimeout: 600,
28
+ interval: 1,
29
+ debug: false,
30
+ };
31
+
32
+ /**
33
+ * The SentTx class represents a sent transaction through the PXE (or directly to a node) providing methods to fetch
34
+ * its hash, receipt, and mining status.
35
+ */
36
+ export class SentTx {
37
+ constructor(protected pxeOrNode: PXE | AztecNode, protected txHashPromise: Promise<TxHash>) {}
38
+
39
+ /**
40
+ * Retrieves the transaction hash of the SentTx instance.
41
+ * The function internally awaits for the 'txHashPromise' to resolve, and then returns the resolved transaction hash.
42
+ *
43
+ * @returns A promise that resolves to the transaction hash of the SentTx instance.
44
+ * TODO(#7717): Don't throw here.
45
+ */
46
+ public getTxHash(): Promise<TxHash> {
47
+ return this.txHashPromise;
48
+ }
49
+
50
+ /**
51
+ * Retrieve the transaction receipt associated with the current SentTx instance.
52
+ * The function fetches the transaction hash using 'getTxHash' and then queries
53
+ * the PXE to get the corresponding transaction receipt.
54
+ *
55
+ * @returns A promise that resolves to a TxReceipt object representing the fetched transaction receipt.
56
+ */
57
+ public async getReceipt(): Promise<TxReceipt> {
58
+ const txHash = await this.getTxHash();
59
+ return await this.pxeOrNode.getTxReceipt(txHash);
60
+ }
61
+
62
+ /**
63
+ * Awaits for a tx to be mined and returns the receipt. Throws if tx is not mined.
64
+ * @param opts - Options for configuring the waiting for the tx to be mined.
65
+ * @returns The transaction receipt.
66
+ */
67
+ public async wait(opts?: WaitOpts): Promise<FieldsOf<TxReceipt>> {
68
+ const receipt = await this.waitForReceipt(opts);
69
+ if (receipt.status !== TxStatus.SUCCESS && !opts?.dontThrowOnRevert) {
70
+ throw new Error(
71
+ `Transaction ${await this.getTxHash()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`,
72
+ );
73
+ }
74
+ if (opts?.proven && receipt.blockNumber !== undefined) {
75
+ await this.waitForProven(receipt.blockNumber, opts);
76
+ }
77
+ if (opts?.debug) {
78
+ const txHash = await this.getTxHash();
79
+ const { data: tx } = (await this.pxeOrNode.getTxEffect(txHash))!;
80
+ receipt.debugInfo = {
81
+ noteHashes: tx.noteHashes,
82
+ nullifiers: tx.nullifiers,
83
+ publicDataWrites: tx.publicDataWrites,
84
+ l2ToL1Msgs: tx.l2ToL1Msgs,
85
+ };
86
+ }
87
+ return receipt;
88
+ }
89
+
90
+ /**
91
+ * Gets public logs emitted by this tx.
92
+ * @remarks This function will wait for the tx to be mined if it hasn't been already.
93
+ * @returns The requested logs.
94
+ */
95
+ public async getPublicLogs(): Promise<GetPublicLogsResponse> {
96
+ await this.wait();
97
+ return this.pxeOrNode.getPublicLogs({ txHash: await this.getTxHash() });
98
+ }
99
+
100
+ protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
101
+ const txHash = await this.getTxHash();
102
+ const startTime = Date.now();
103
+ const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
104
+
105
+ return await retryUntil(
106
+ async () => {
107
+ const txReceipt = await this.pxeOrNode.getTxReceipt(txHash);
108
+ // If receipt is not yet available, try again
109
+ if (txReceipt.status === TxStatus.PENDING) {
110
+ return undefined;
111
+ }
112
+ // If the tx was "dropped", either return it or ignore based on timing.
113
+ // 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.
114
+ // If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
115
+ if (txReceipt.status === TxStatus.DROPPED) {
116
+ const elapsedSeconds = (Date.now() - startTime) / 1000;
117
+ if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
118
+ return txReceipt;
119
+ }
120
+ return undefined;
121
+ }
122
+ return txReceipt;
123
+ },
124
+ 'isMined',
125
+ opts?.timeout ?? DefaultWaitOpts.timeout,
126
+ opts?.interval ?? DefaultWaitOpts.interval,
127
+ );
128
+ }
129
+
130
+ protected async waitForProven(minedBlock: number, opts?: WaitOpts) {
131
+ return await retryUntil(
132
+ async () => {
133
+ const provenBlock = await this.pxeOrNode.getProvenBlockNumber();
134
+ return provenBlock >= minedBlock ? provenBlock : undefined;
135
+ },
136
+ 'isProven',
137
+ opts?.provenTimeout ?? DefaultWaitOpts.provenTimeout,
138
+ opts?.interval ?? DefaultWaitOpts.interval,
139
+ );
140
+ }
141
+ }