@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,43 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { SentTx } from './sent_tx.js';
3
+ /**
4
+ * A contract deployment transaction sent to the network, extending SentTx with methods to create a contract instance.
5
+ */ export class DeploySentTx extends SentTx {
6
+ postDeployCtor;
7
+ instanceGetter;
8
+ log;
9
+ constructor(pxeOrWallet, txHashPromise, postDeployCtor, /** A getter for the deployed contract instance */ instanceGetter){
10
+ super(pxeOrWallet, txHashPromise), this.postDeployCtor = postDeployCtor, this.instanceGetter = instanceGetter, this.log = createLogger('aztecjs:deploy_sent_tx');
11
+ }
12
+ /**
13
+ * Awaits for the tx to be mined and returns the contract instance. Throws if tx is not mined.
14
+ * @param opts - Options for configuring the waiting for the tx to be mined.
15
+ * @returns The deployed contract instance.
16
+ */ async deployed(opts) {
17
+ const receipt = await this.wait(opts);
18
+ const instance = await this.instanceGetter();
19
+ this.log.info(`Contract ${instance.address.toString()} successfully deployed.`);
20
+ return receipt.contract;
21
+ }
22
+ /**
23
+ * Awaits for the tx to be mined and returns the receipt along with a contract instance. Throws if tx is not mined.
24
+ * @param opts - Options for configuring the waiting for the tx to be mined.
25
+ * @returns The transaction receipt with the deployed contract instance.
26
+ */ async wait(opts) {
27
+ const receipt = await super.wait(opts);
28
+ const contract = await this.getContractObject(opts?.wallet);
29
+ return {
30
+ ...receipt,
31
+ contract
32
+ };
33
+ }
34
+ async getContractObject(wallet) {
35
+ const isWallet = (pxeOrWallet)=>!!pxeOrWallet.createTxExecutionRequest;
36
+ const contractWallet = wallet ?? (isWallet(this.pxeOrNode) && this.pxeOrNode);
37
+ if (!contractWallet) {
38
+ throw new Error(`A wallet is required for creating a contract instance`);
39
+ }
40
+ const instance = await this.instanceGetter();
41
+ return this.postDeployCtor(instance.address, contractWallet);
42
+ }
43
+ }
@@ -0,0 +1,18 @@
1
+ import type { Gas } from '@aztec/stdlib/gas';
2
+ import type { TxSimulationResult } from '@aztec/stdlib/tx';
3
+ /**
4
+ * Returns suggested total and teardown gas limits for a simulated tx.
5
+ * Note that public gas usage is only accounted for if the publicOutput is present.
6
+ * @param pad - Percentage to pad the suggested gas limits by, (as decimal, e.g., 0.10 for 10%).
7
+ */
8
+ export declare function getGasLimits(simulationResult: TxSimulationResult, pad?: number): {
9
+ /**
10
+ * Total gas used across private and public
11
+ */
12
+ totalGas: Gas;
13
+ /**
14
+ * Teardown gas used
15
+ */
16
+ teardownGas: Gas;
17
+ };
18
+ //# sourceMappingURL=get_gas_limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get_gas_limits.d.ts","sourceRoot":"","sources":["../../src/contract/get_gas_limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,gBAAgB,EAAE,kBAAkB,EACpC,GAAG,SAAM,GACR;IACD;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC;IACd;;OAEG;IACH,WAAW,EAAE,GAAG,CAAC;CAClB,CAKA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns suggested total and teardown gas limits for a simulated tx.
3
+ * Note that public gas usage is only accounted for if the publicOutput is present.
4
+ * @param pad - Percentage to pad the suggested gas limits by, (as decimal, e.g., 0.10 for 10%).
5
+ */ export function getGasLimits(simulationResult, pad = 0.1) {
6
+ return {
7
+ totalGas: simulationResult.gasUsed.totalGas.mul(1 + pad),
8
+ teardownGas: simulationResult.gasUsed.teardownGas.mul(1 + pad)
9
+ };
10
+ }
@@ -0,0 +1,45 @@
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 { ContractFunctionInteraction, type ProfileResult, type SendMethodOptions, } from './contract_function_interaction.js';
40
+ export { DefaultWaitOpts, SentTx, type WaitOpts } from './sent_tx.js';
41
+ export { ContractBase, type ContractMethod, type ContractNotes, type ContractStorageLayout } from './contract_base.js';
42
+ export { BatchCall } from './batch_call.js';
43
+ export { type DeployOptions, DeployMethod } from './deploy_method.js';
44
+ export { DeploySentTx } from './deploy_sent_tx.js';
45
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACvH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,43 @@
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
+ */ export { Contract } from './contract.js';
38
+ export { ContractFunctionInteraction } from './contract_function_interaction.js';
39
+ export { DefaultWaitOpts, SentTx } from './sent_tx.js';
40
+ export { ContractBase } from './contract_base.js';
41
+ export { BatchCall } from './batch_call.js';
42
+ export { DeployMethod } from './deploy_method.js';
43
+ export { DeploySentTx } from './deploy_sent_tx.js';
@@ -0,0 +1,9 @@
1
+ import type { Wallet } from '../wallet/index.js';
2
+ import { UnsafeContract } from './unsafe_contract.js';
3
+ /** Returns a Contract wrapper for the class registerer. */
4
+ export declare function getRegistererContract(wallet: Wallet): Promise<UnsafeContract>;
5
+ /** Returns a Contract wrapper for the instance deployer. */
6
+ export declare function getDeployerContract(wallet: Wallet): Promise<UnsafeContract>;
7
+ /** Returns a Contract wrapper for the fee juice */
8
+ export declare function getFeeJuice(wallet: Wallet): Promise<UnsafeContract>;
9
+ //# sourceMappingURL=protocol_contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol_contracts.d.ts","sourceRoot":"","sources":["../../src/contract/protocol_contracts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,2DAA2D;AAC3D,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,2BAQzD;AAED,4DAA4D;AAC5D,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,2BAOvD;AAED,mDAAmD;AACnD,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,2BAO/C"}
@@ -0,0 +1,26 @@
1
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
+ import { UnsafeContract } from './unsafe_contract.js';
3
+ /** Returns a Contract wrapper for the class registerer. */ export async function getRegistererContract(wallet) {
4
+ const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractClassRegisterer);
5
+ if (!contractInstance) {
6
+ throw new Error("ContractClassRegisterer is not registered in this wallet's instance");
7
+ }
8
+ const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
9
+ return new UnsafeContract(contractInstance, artifact, wallet);
10
+ }
11
+ /** Returns a Contract wrapper for the instance deployer. */ export async function getDeployerContract(wallet) {
12
+ const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.ContractInstanceDeployer);
13
+ if (!contractInstance) {
14
+ throw new Error("ContractInstanceDeployer is not registered in this wallet's instance");
15
+ }
16
+ const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
17
+ return new UnsafeContract(contractInstance, artifact, wallet);
18
+ }
19
+ /** Returns a Contract wrapper for the fee juice */ export async function getFeeJuice(wallet) {
20
+ const { contractInstance } = await wallet.getContractMetadata(ProtocolContractAddress.FeeJuice);
21
+ if (!contractInstance) {
22
+ throw new Error("FeeJuice is not registered in this wallet's instance");
23
+ }
24
+ const { artifact } = await wallet.getContractClassMetadata(contractInstance.currentContractClassId, true);
25
+ return new UnsafeContract(contractInstance, artifact, wallet);
26
+ }
@@ -0,0 +1,17 @@
1
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
2
+ import { Tx } from '@aztec/stdlib/tx';
3
+ import type { Wallet } from '../account/index.js';
4
+ import { SentTx } from './sent_tx.js';
5
+ /**
6
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of a contract interaction.
7
+ */
8
+ export declare class ProvenTx extends Tx {
9
+ protected wallet: PXE | Wallet;
10
+ constructor(wallet: PXE | Wallet, tx: Tx);
11
+ protected getPlainDataTx(): Tx;
12
+ /**
13
+ * Sends the transaction to the network via the provided wallet.
14
+ */
15
+ send(): SentTx;
16
+ }
17
+ //# sourceMappingURL=proven_tx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proven_tx.d.ts","sourceRoot":"","sources":["../../src/contract/proven_tx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;GAEG;AACH,qBAAa,QAAS,SAAQ,EAAE;IAClB,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM;gBAApB,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE;IAWlD,SAAS,CAAC,cAAc,IAAI,EAAE;IAU9B;;OAEG;IACI,IAAI,IAAI,MAAM;CAOtB"}
@@ -0,0 +1,22 @@
1
+ import { Tx } from '@aztec/stdlib/tx';
2
+ import { SentTx } from './sent_tx.js';
3
+ /**
4
+ * A proven transaction that can be sent to the network. Returned by the `prove` method of a contract interaction.
5
+ */ export class ProvenTx extends Tx {
6
+ wallet;
7
+ constructor(wallet, tx){
8
+ super(tx.data, tx.clientIvcProof, tx.contractClassLogs, tx.enqueuedPublicFunctionCalls, tx.publicTeardownFunctionCall), this.wallet = wallet;
9
+ }
10
+ // Clone the TX data to get a serializable object.
11
+ getPlainDataTx() {
12
+ return new Tx(this.data, this.clientIvcProof, this.contractClassLogs, this.enqueuedPublicFunctionCalls, this.publicTeardownFunctionCall);
13
+ }
14
+ /**
15
+ * Sends the transaction to the network via the provided wallet.
16
+ */ send() {
17
+ const promise = (()=>{
18
+ return this.wallet.sendTx(this.getPlainDataTx());
19
+ })();
20
+ return new SentTx(this.wallet, promise);
21
+ }
22
+ }
@@ -0,0 +1,61 @@
1
+ import type { FieldsOf } from '@aztec/foundation/types';
2
+ import type { AztecNode, GetPublicLogsResponse, PXE } from '@aztec/stdlib/interfaces/client';
3
+ import { type TxHash, type TxReceipt } from '@aztec/stdlib/tx';
4
+ /** Options related to waiting for a tx. */
5
+ export type WaitOpts = {
6
+ /** 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. */
7
+ ignoreDroppedReceiptsFor?: number;
8
+ /** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
9
+ timeout?: number;
10
+ /** The maximum time (in seconds) to wait for the transaction to be proven. Defaults to 600. */
11
+ provenTimeout?: number;
12
+ /** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
13
+ interval?: number;
14
+ /** Whether to wait for the tx to be proven. */
15
+ proven?: boolean;
16
+ /** Whether to include information useful for debugging/testing in the receipt. */
17
+ debug?: boolean;
18
+ /** Whether to accept a revert as a status code for the tx when waiting for it. If false, will throw if the tx reverts. */
19
+ dontThrowOnRevert?: boolean;
20
+ };
21
+ export declare const DefaultWaitOpts: WaitOpts;
22
+ /**
23
+ * The SentTx class represents a sent transaction through the PXE (or directly to a node) providing methods to fetch
24
+ * its hash, receipt, and mining status.
25
+ */
26
+ export declare class SentTx {
27
+ protected pxeOrNode: PXE | AztecNode;
28
+ protected txHashPromise: Promise<TxHash>;
29
+ constructor(pxeOrNode: PXE | AztecNode, txHashPromise: Promise<TxHash>);
30
+ /**
31
+ * Retrieves the transaction hash of the SentTx instance.
32
+ * The function internally awaits for the 'txHashPromise' to resolve, and then returns the resolved transaction hash.
33
+ *
34
+ * @returns A promise that resolves to the transaction hash of the SentTx instance.
35
+ * TODO(#7717): Don't throw here.
36
+ */
37
+ getTxHash(): Promise<TxHash>;
38
+ /**
39
+ * Retrieve the transaction receipt associated with the current SentTx instance.
40
+ * The function fetches the transaction hash using 'getTxHash' and then queries
41
+ * the PXE to get the corresponding transaction receipt.
42
+ *
43
+ * @returns A promise that resolves to a TxReceipt object representing the fetched transaction receipt.
44
+ */
45
+ getReceipt(): Promise<TxReceipt>;
46
+ /**
47
+ * Awaits for a tx to be mined and returns the receipt. Throws if tx is not mined.
48
+ * @param opts - Options for configuring the waiting for the tx to be mined.
49
+ * @returns The transaction receipt.
50
+ */
51
+ wait(opts?: WaitOpts): Promise<FieldsOf<TxReceipt>>;
52
+ /**
53
+ * Gets public logs emitted by this tx.
54
+ * @remarks This function will wait for the tx to be mined if it hasn't been already.
55
+ * @returns The requested logs.
56
+ */
57
+ getPublicLogs(): Promise<GetPublicLogsResponse>;
58
+ protected waitForReceipt(opts?: WaitOpts): Promise<TxReceipt>;
59
+ protected waitForProven(minedBlock: number, opts?: WaitOpts): Promise<number>;
60
+ }
61
+ //# sourceMappingURL=sent_tx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sent_tx.d.ts","sourceRoot":"","sources":["../../src/contract/sent_tx.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAEzE,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,GAAG;IACrB,gKAAgK;IAChK,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,0HAA0H;IAC1H,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,QAM7B,CAAC;AAEF;;;GAGG;AACH,qBAAa,MAAM;IACL,SAAS,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS;IAAE,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC;gBAApE,SAAS,EAAE,GAAG,GAAG,SAAS,EAAY,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC;IAE1F;;;;;;OAMG;IACI,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;;;;OAMG;IACU,UAAU,IAAI,OAAO,CAAC,SAAS,CAAC;IAK7C;;;;OAIG;IACU,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAuBhE;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC,qBAAqB,CAAC;cAK5C,cAAc,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;cA8BnD,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ;CAWlE"}
@@ -0,0 +1,102 @@
1
+ import { retryUntil } from '@aztec/foundation/retry';
2
+ import { TxStatus } from '@aztec/stdlib/tx';
3
+ export const DefaultWaitOpts = {
4
+ ignoreDroppedReceiptsFor: 5,
5
+ timeout: 60,
6
+ provenTimeout: 600,
7
+ interval: 1,
8
+ debug: false
9
+ };
10
+ /**
11
+ * The SentTx class represents a sent transaction through the PXE (or directly to a node) providing methods to fetch
12
+ * its hash, receipt, and mining status.
13
+ */ export class SentTx {
14
+ pxeOrNode;
15
+ txHashPromise;
16
+ constructor(pxeOrNode, txHashPromise){
17
+ this.pxeOrNode = pxeOrNode;
18
+ this.txHashPromise = txHashPromise;
19
+ }
20
+ /**
21
+ * Retrieves the transaction hash of the SentTx instance.
22
+ * The function internally awaits for the 'txHashPromise' to resolve, and then returns the resolved transaction hash.
23
+ *
24
+ * @returns A promise that resolves to the transaction hash of the SentTx instance.
25
+ * TODO(#7717): Don't throw here.
26
+ */ getTxHash() {
27
+ return this.txHashPromise;
28
+ }
29
+ /**
30
+ * Retrieve the transaction receipt associated with the current SentTx instance.
31
+ * The function fetches the transaction hash using 'getTxHash' and then queries
32
+ * the PXE to get the corresponding transaction receipt.
33
+ *
34
+ * @returns A promise that resolves to a TxReceipt object representing the fetched transaction receipt.
35
+ */ async getReceipt() {
36
+ const txHash = await this.getTxHash();
37
+ return await this.pxeOrNode.getTxReceipt(txHash);
38
+ }
39
+ /**
40
+ * Awaits for a tx to be mined and returns the receipt. Throws if tx is not mined.
41
+ * @param opts - Options for configuring the waiting for the tx to be mined.
42
+ * @returns The transaction receipt.
43
+ */ async wait(opts) {
44
+ const receipt = await this.waitForReceipt(opts);
45
+ if (receipt.status !== TxStatus.SUCCESS && !opts?.dontThrowOnRevert) {
46
+ throw new Error(`Transaction ${await this.getTxHash()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`);
47
+ }
48
+ if (opts?.proven && receipt.blockNumber !== undefined) {
49
+ await this.waitForProven(receipt.blockNumber, opts);
50
+ }
51
+ if (opts?.debug) {
52
+ const txHash = await this.getTxHash();
53
+ const { data: tx } = await this.pxeOrNode.getTxEffect(txHash);
54
+ receipt.debugInfo = {
55
+ noteHashes: tx.noteHashes,
56
+ nullifiers: tx.nullifiers,
57
+ publicDataWrites: tx.publicDataWrites,
58
+ l2ToL1Msgs: tx.l2ToL1Msgs
59
+ };
60
+ }
61
+ return receipt;
62
+ }
63
+ /**
64
+ * Gets public logs emitted by this tx.
65
+ * @remarks This function will wait for the tx to be mined if it hasn't been already.
66
+ * @returns The requested logs.
67
+ */ async getPublicLogs() {
68
+ await this.wait();
69
+ return this.pxeOrNode.getPublicLogs({
70
+ txHash: await this.getTxHash()
71
+ });
72
+ }
73
+ async waitForReceipt(opts) {
74
+ const txHash = await this.getTxHash();
75
+ const startTime = Date.now();
76
+ const ignoreDroppedReceiptsFor = opts?.ignoreDroppedReceiptsFor ?? DefaultWaitOpts.ignoreDroppedReceiptsFor;
77
+ return await retryUntil(async ()=>{
78
+ const txReceipt = await this.pxeOrNode.getTxReceipt(txHash);
79
+ // If receipt is not yet available, try again
80
+ if (txReceipt.status === TxStatus.PENDING) {
81
+ return undefined;
82
+ }
83
+ // If the tx was "dropped", either return it or ignore based on timing.
84
+ // 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.
85
+ // If we don't allow a short grace period, we could incorrectly return a TxReceipt with status DROPPED.
86
+ if (txReceipt.status === TxStatus.DROPPED) {
87
+ const elapsedSeconds = (Date.now() - startTime) / 1000;
88
+ if (!ignoreDroppedReceiptsFor || elapsedSeconds > ignoreDroppedReceiptsFor) {
89
+ return txReceipt;
90
+ }
91
+ return undefined;
92
+ }
93
+ return txReceipt;
94
+ }, 'isMined', opts?.timeout ?? DefaultWaitOpts.timeout, opts?.interval ?? DefaultWaitOpts.interval);
95
+ }
96
+ async waitForProven(minedBlock, opts) {
97
+ return await retryUntil(async ()=>{
98
+ const provenBlock = await this.pxeOrNode.getProvenBlockNumber();
99
+ return provenBlock >= minedBlock ? provenBlock : undefined;
100
+ }, 'isProven', opts?.provenTimeout ?? DefaultWaitOpts.provenTimeout, opts?.interval ?? DefaultWaitOpts.interval);
101
+ }
102
+ }
@@ -0,0 +1,15 @@
1
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
2
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
+ import type { Wallet } from '../wallet/index.js';
4
+ import { ContractBase } from './contract_base.js';
5
+ /** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */
6
+ export declare class UnsafeContract extends ContractBase {
7
+ constructor(
8
+ /** The deployed contract instance definition. */
9
+ instance: ContractInstanceWithAddress,
10
+ /** The Application Binary Interface for the contract. */
11
+ artifact: ContractArtifact,
12
+ /** The wallet used for interacting with this contract. */
13
+ wallet: Wallet);
14
+ }
15
+ //# sourceMappingURL=unsafe_contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsafe_contract.d.ts","sourceRoot":"","sources":["../../src/contract/unsafe_contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,iHAAiH;AACjH,qBAAa,cAAe,SAAQ,YAAY;;IAE5C,iDAAiD;IACjD,QAAQ,EAAE,2BAA2B;IACrC,yDAAyD;IACzD,QAAQ,EAAE,gBAAgB;IAC1B,0DAA0D;IAC1D,MAAM,EAAE,MAAM;CAIjB"}
@@ -0,0 +1,6 @@
1
+ import { ContractBase } from './contract_base.js';
2
+ /** Unsafe constructor for ContractBase that bypasses the check that the instance is registered in the wallet. */ export class UnsafeContract extends ContractBase {
3
+ constructor(/** The deployed contract instance definition. */ instance, /** The Application Binary Interface for the contract. */ artifact, /** The wallet used for interacting with this contract. */ wallet){
4
+ super(instance, artifact, wallet);
5
+ }
6
+ }
@@ -0,0 +1,24 @@
1
+ import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
2
+ import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
3
+ import type { Wallet } from '../wallet/index.js';
4
+ /**
5
+ * Sets up a call to broadcast a private function's bytecode via the ClassRegisterer contract.
6
+ * Note that this is not required for users to call the function, but is rather a convenience to make
7
+ * this code publicly available so dapps or wallets do not need to redistribute it.
8
+ * @param wallet - Wallet to send the transaction.
9
+ * @param artifact - Contract artifact that contains the function to be broadcast.
10
+ * @param selector - Selector of the function to be broadcast.
11
+ * @returns A ContractFunctionInteraction object that can be used to send the transaction.
12
+ */
13
+ export declare function broadcastPrivateFunction(wallet: Wallet, artifact: ContractArtifact, selector: FunctionSelector): Promise<ContractFunctionInteraction>;
14
+ /**
15
+ * Sets up a call to broadcast an unconstrained function's bytecode via the ClassRegisterer contract.
16
+ * Note that this is not required for users to call the function, but is rather a convenience to make
17
+ * this code publicly available so dapps or wallets do not need to redistribute it.
18
+ * @param wallet - Wallet to send the transaction.
19
+ * @param artifact - Contract artifact that contains the function to be broadcast.
20
+ * @param selector - Selector of the function to be broadcast.
21
+ * @returns A ContractFunctionInteraction object that can be used to send the transaction.
22
+ */
23
+ export declare function broadcastUnconstrainedFunction(wallet: Wallet, artifact: ContractArtifact, selector: FunctionSelector): Promise<ContractFunctionInteraction>;
24
+ //# sourceMappingURL=broadcast_function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcast_function.d.ts","sourceRoot":"","sources":["../../src/deployment/broadcast_function.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAgC,MAAM,mBAAmB,CAAC;AAS1G,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAEhG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,2BAA2B,CAAC,CAoDtC;AAED;;;;;;;;GAQG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,2BAA2B,CAAC,CA8CtC"}
@@ -0,0 +1,70 @@
1
+ import { ARTIFACT_FUNCTION_TREE_MAX_HEIGHT, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS, REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT } from '@aztec/constants';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
5
+ import { FunctionSelector, FunctionType, bufferAsFields } from '@aztec/stdlib/abi';
6
+ import { computeVerificationKeyHash, createPrivateFunctionMembershipProof, createUnconstrainedFunctionMembershipProof, getContractClassFromArtifact } from '@aztec/stdlib/contract';
7
+ import { Capsule } from '@aztec/stdlib/tx';
8
+ import { getRegistererContract } from '../contract/protocol_contracts.js';
9
+ /**
10
+ * Sets up a call to broadcast a private function's bytecode via the ClassRegisterer contract.
11
+ * Note that this is not required for users to call the function, but is rather a convenience to make
12
+ * this code publicly available so dapps or wallets do not need to redistribute it.
13
+ * @param wallet - Wallet to send the transaction.
14
+ * @param artifact - Contract artifact that contains the function to be broadcast.
15
+ * @param selector - Selector of the function to be broadcast.
16
+ * @returns A ContractFunctionInteraction object that can be used to send the transaction.
17
+ */ export async function broadcastPrivateFunction(wallet, artifact, selector) {
18
+ const contractClass = await getContractClassFromArtifact(artifact);
19
+ const privateFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PRIVATE);
20
+ const functionsAndSelectors = await Promise.all(privateFunctions.map(async (fn)=>({
21
+ f: fn,
22
+ selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)
23
+ })));
24
+ const privateFunctionArtifact = functionsAndSelectors.find((fn)=>selector.equals(fn.selector))?.f;
25
+ if (!privateFunctionArtifact) {
26
+ throw new Error(`Private function with selector ${selector.toString()} not found`);
27
+ }
28
+ const { artifactTreeSiblingPath, artifactTreeLeafIndex, artifactMetadataHash, functionMetadataHash, unconstrainedFunctionsArtifactTreeRoot, privateFunctionTreeSiblingPath, privateFunctionTreeLeafIndex } = await createPrivateFunctionMembershipProof(selector, artifact);
29
+ const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
30
+ const registerer = await getRegistererContract(wallet);
31
+ const fn = registerer.methods.broadcast_private_function(contractClass.id, artifactMetadataHash, unconstrainedFunctionsArtifactTreeRoot, privateFunctionTreeSiblingPath, privateFunctionTreeLeafIndex, padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), artifactTreeLeafIndex, // eslint-disable-next-line camelcase
32
+ {
33
+ selector,
34
+ metadata_hash: functionMetadataHash,
35
+ vk_hash: vkHash
36
+ });
37
+ const bytecode = bufferAsFields(privateFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS);
38
+ fn.addCapsule(new Capsule(ProtocolContractAddress.ContractClassRegisterer, new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), bytecode));
39
+ return fn;
40
+ }
41
+ /**
42
+ * Sets up a call to broadcast an unconstrained function's bytecode via the ClassRegisterer contract.
43
+ * Note that this is not required for users to call the function, but is rather a convenience to make
44
+ * this code publicly available so dapps or wallets do not need to redistribute it.
45
+ * @param wallet - Wallet to send the transaction.
46
+ * @param artifact - Contract artifact that contains the function to be broadcast.
47
+ * @param selector - Selector of the function to be broadcast.
48
+ * @returns A ContractFunctionInteraction object that can be used to send the transaction.
49
+ */ export async function broadcastUnconstrainedFunction(wallet, artifact, selector) {
50
+ const contractClass = await getContractClassFromArtifact(artifact);
51
+ const unconstrainedFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.UNCONSTRAINED);
52
+ const unconstrainedFunctionsAndSelectors = await Promise.all(unconstrainedFunctions.map(async (fn)=>({
53
+ f: fn,
54
+ selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)
55
+ })));
56
+ const unconstrainedFunctionArtifact = unconstrainedFunctionsAndSelectors.find((fn)=>selector.equals(fn.selector))?.f;
57
+ if (!unconstrainedFunctionArtifact) {
58
+ throw new Error(`Unconstrained function with selector ${selector.toString()} not found`);
59
+ }
60
+ const { artifactMetadataHash, artifactTreeLeafIndex, artifactTreeSiblingPath, functionMetadataHash, privateFunctionsArtifactTreeRoot } = await createUnconstrainedFunctionMembershipProof(selector, artifact);
61
+ const registerer = await getRegistererContract(wallet);
62
+ const fn = registerer.methods.broadcast_unconstrained_function(contractClass.id, artifactMetadataHash, privateFunctionsArtifactTreeRoot, padArrayEnd(artifactTreeSiblingPath, Fr.ZERO, ARTIFACT_FUNCTION_TREE_MAX_HEIGHT), artifactTreeLeafIndex, // eslint-disable-next-line camelcase
63
+ {
64
+ selector,
65
+ metadata_hash: functionMetadataHash
66
+ });
67
+ const bytecode = bufferAsFields(unconstrainedFunctionArtifact.bytecode, MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS);
68
+ fn.addCapsule(new Capsule(ProtocolContractAddress.ContractClassRegisterer, new Fr(REGISTERER_CONTRACT_BYTECODE_CAPSULE_SLOT), bytecode));
69
+ return fn;
70
+ }
@@ -0,0 +1,27 @@
1
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
2
+ import { PublicKeys } from '@aztec/stdlib/keys';
3
+ import type { Wallet } from '../account/wallet.js';
4
+ import { Contract } from '../contract/contract.js';
5
+ import { DeployMethod } from '../contract/deploy_method.js';
6
+ /**
7
+ * A class for deploying contract.
8
+ * @remarks Keeping this around even though we have Aztec.nr contract types because it can be useful for non-TS users.
9
+ */
10
+ export declare class ContractDeployer {
11
+ private artifact;
12
+ private wallet;
13
+ private publicKeys?;
14
+ private constructorName?;
15
+ constructor(artifact: ContractArtifact, wallet: Wallet, publicKeys?: PublicKeys | undefined, constructorName?: string | undefined);
16
+ /**
17
+ * Deploy a contract using the provided ABI and constructor arguments.
18
+ * This function creates a new DeployMethod instance that can be used to send deployment transactions
19
+ * and query deployment status. The method accepts any number of constructor arguments, which will
20
+ * be passed to the contract's constructor during deployment.
21
+ *
22
+ * @param args - The constructor arguments for the contract being deployed.
23
+ * @returns A DeployMethod instance configured with the ABI, PXE, and constructor arguments.
24
+ */
25
+ deploy(...args: any[]): DeployMethod<Contract>;
26
+ }
27
+ //# sourceMappingURL=contract_deployer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract_deployer.d.ts","sourceRoot":"","sources":["../../src/deployment/contract_deployer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D;;;GAGG;AACH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,eAAe,CAAC;gBAHhB,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,wBAAY,EACvB,eAAe,CAAC,oBAAQ;IAGlC;;;;;;;;OAQG;IACI,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAW7B"}
@@ -0,0 +1,30 @@
1
+ import { PublicKeys } from '@aztec/stdlib/keys';
2
+ import { Contract } from '../contract/contract.js';
3
+ import { DeployMethod } from '../contract/deploy_method.js';
4
+ /**
5
+ * A class for deploying contract.
6
+ * @remarks Keeping this around even though we have Aztec.nr contract types because it can be useful for non-TS users.
7
+ */ export class ContractDeployer {
8
+ artifact;
9
+ wallet;
10
+ publicKeys;
11
+ constructorName;
12
+ constructor(artifact, wallet, publicKeys, constructorName){
13
+ this.artifact = artifact;
14
+ this.wallet = wallet;
15
+ this.publicKeys = publicKeys;
16
+ this.constructorName = constructorName;
17
+ }
18
+ /**
19
+ * Deploy a contract using the provided ABI and constructor arguments.
20
+ * This function creates a new DeployMethod instance that can be used to send deployment transactions
21
+ * and query deployment status. The method accepts any number of constructor arguments, which will
22
+ * be passed to the contract's constructor during deployment.
23
+ *
24
+ * @param args - The constructor arguments for the contract being deployed.
25
+ * @returns A DeployMethod instance configured with the ABI, PXE, and constructor arguments.
26
+ */ deploy(...args) {
27
+ const postDeployCtor = (address, wallet)=>Contract.at(address, this.artifact, wallet);
28
+ return new DeployMethod(this.publicKeys ?? PublicKeys.default(), this.wallet, this.artifact, postDeployCtor, args, this.constructorName);
29
+ }
30
+ }
@@ -0,0 +1,10 @@
1
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
2
+ import type { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
3
+ import type { Wallet } from '../wallet/index.js';
4
+ /**
5
+ * Sets up a call to the canonical deployer contract to publicly deploy a contract instance.
6
+ * @param wallet - The wallet to use for the deployment.
7
+ * @param instance - The instance to deploy.
8
+ */
9
+ export declare function deployInstance(wallet: Wallet, instance: ContractInstanceWithAddress): Promise<ContractFunctionInteraction>;
10
+ //# sourceMappingURL=deploy_instance.d.ts.map