@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,149 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { GasSettings } from '@aztec/stdlib/gas';
3
+ import { FeeJuicePaymentMethod } from '../fee/fee_juice_payment_method.js';
4
+ import { getGasLimits } from './get_gas_limits.js';
5
+ import { ProvenTx } from './proven_tx.js';
6
+ import { SentTx } from './sent_tx.js';
7
+ /**
8
+ * Base class for an interaction with a contract, be it a deployment, a function call, or a batch.
9
+ * Implements the sequence create/simulate/send.
10
+ */ export class BaseContractInteraction {
11
+ wallet;
12
+ log;
13
+ capsules;
14
+ constructor(wallet){
15
+ this.wallet = wallet;
16
+ this.log = createLogger('aztecjs:contract_interaction');
17
+ this.capsules = [];
18
+ }
19
+ /**
20
+ * Creates a transaction execution request, simulates and proves it. Differs from .prove in
21
+ * that its result does not include the wallet nor the composed tx object, but only the proving result.
22
+ * This object can then be used to either create a ProvenTx ready to be sent, or directly send the transaction.
23
+ * @param options - optional arguments to be used in the creation of the transaction
24
+ * @returns The proving result.
25
+ */ async proveInternal(options = {}) {
26
+ const txRequest = await this.create(options);
27
+ const txSimulationResult = await this.wallet.simulateTx(txRequest, !options.skipPublicSimulation, undefined, true);
28
+ return await this.wallet.proveTx(txRequest, txSimulationResult.privateExecutionResult);
29
+ }
30
+ // docs:start:prove
31
+ /**
32
+ * Proves a transaction execution request and returns a tx object ready to be sent.
33
+ * @param options - optional arguments to be used in the creation of the transaction
34
+ * @returns The resulting transaction
35
+ */ async prove(options = {}) {
36
+ // docs:end:prove
37
+ const txProvingResult = await this.proveInternal(options);
38
+ return new ProvenTx(this.wallet, txProvingResult.toTx());
39
+ }
40
+ // docs:start:send
41
+ /**
42
+ * Sends a transaction to the contract function with the specified options.
43
+ * This function throws an error if called on an unconstrained function.
44
+ * It creates and signs the transaction if necessary, and returns a SentTx instance,
45
+ * which can be used to track the transaction status, receipt, and events.
46
+ * @param options - An optional object containing 'from' property representing
47
+ * the AztecAddress of the sender. If not provided, the default address is used.
48
+ * @returns A SentTx instance for tracking the transaction status and information.
49
+ */ send(options = {}) {
50
+ // docs:end:send
51
+ const promise = (async ()=>{
52
+ const txProvingResult = await this.proveInternal(options);
53
+ return this.wallet.sendTx(txProvingResult.toTx());
54
+ })();
55
+ return new SentTx(this.wallet, promise);
56
+ }
57
+ // docs:start:estimateGas
58
+ /**
59
+ * Estimates gas for a given tx request and returns gas limits for it.
60
+ * @param opts - Options.
61
+ * @param pad - Percentage to pad the suggested gas limits by, if empty, defaults to 10%.
62
+ * @returns Gas limits.
63
+ */ async estimateGas(opts) {
64
+ // docs:end:estimateGas
65
+ const txRequest = await this.create({
66
+ ...opts,
67
+ fee: {
68
+ ...opts?.fee,
69
+ estimateGas: false
70
+ }
71
+ });
72
+ const simulationResult = await this.wallet.simulateTx(txRequest, true, undefined /* msgSender */ , undefined /* skipTxValidation */ , true);
73
+ const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(simulationResult, opts?.fee?.estimatedGasPadding);
74
+ return {
75
+ gasLimits,
76
+ teardownGasLimits
77
+ };
78
+ }
79
+ /**
80
+ * Returns default fee options based on the user opts without running a simulation for gas estimation.
81
+ * @param fee - User-provided fee options.
82
+ */ async getDefaultFeeOptions(fee) {
83
+ const maxFeesPerGas = fee?.gasSettings?.maxFeesPerGas ?? (await this.wallet.getCurrentBaseFees()).mul(1 + (fee?.baseFeePadding ?? 0.5));
84
+ const paymentMethod = fee?.paymentMethod ?? new FeeJuicePaymentMethod(this.wallet.getAddress());
85
+ const gasSettings = GasSettings.default({
86
+ ...fee?.gasSettings,
87
+ maxFeesPerGas
88
+ });
89
+ this.log.debug(`Using L2 gas settings`, gasSettings);
90
+ return {
91
+ gasSettings,
92
+ paymentMethod
93
+ };
94
+ }
95
+ // docs:start:getFeeOptions
96
+ /**
97
+ * Return fee options based on the user opts, estimating tx gas if needed.
98
+ * @param request - Request to execute for this interaction.
99
+ * @param pad - Percentage to pad the suggested gas limits by, as decimal (e.g., 0.10 for 10%).
100
+ * @returns Fee options for the actual transaction.
101
+ */ async getFeeOptions(request) {
102
+ // docs:end:getFeeOptions
103
+ const defaultFeeOptions = await this.getDefaultFeeOptions(request.fee);
104
+ const paymentMethod = defaultFeeOptions.paymentMethod;
105
+ const maxFeesPerGas = defaultFeeOptions.gasSettings.maxFeesPerGas;
106
+ const maxPriorityFeesPerGas = defaultFeeOptions.gasSettings.maxPriorityFeesPerGas;
107
+ let gasSettings = defaultFeeOptions.gasSettings;
108
+ if (request.fee?.estimateGas) {
109
+ const feeForEstimation = {
110
+ paymentMethod,
111
+ gasSettings
112
+ };
113
+ const txRequest = await this.wallet.createTxExecutionRequest({
114
+ ...request,
115
+ fee: feeForEstimation
116
+ });
117
+ const simulationResult = await this.wallet.simulateTx(txRequest, true, undefined /* msgSender */ , undefined /* skipTxValidation */ , true);
118
+ const { totalGas: gasLimits, teardownGas: teardownGasLimits } = getGasLimits(simulationResult, request.fee?.estimatedGasPadding);
119
+ gasSettings = GasSettings.from({
120
+ maxFeesPerGas,
121
+ maxPriorityFeesPerGas,
122
+ gasLimits,
123
+ teardownGasLimits
124
+ });
125
+ this.log.verbose(`Estimated gas limits for tx: DA=${gasLimits.daGas} L2=${gasLimits.l2Gas} teardownDA=${teardownGasLimits.daGas} teardownL2=${teardownGasLimits.l2Gas}`);
126
+ }
127
+ return {
128
+ gasSettings,
129
+ paymentMethod
130
+ };
131
+ }
132
+ /**
133
+ * Add data passed to the oracle calls during this contract interaction.
134
+ * @param capsule - Data passed to oracle calls.
135
+ */ addCapsule(capsule) {
136
+ this.capsules.push(capsule);
137
+ }
138
+ /**
139
+ * Add data passed to the oracle calls during this contract interaction.
140
+ * @param capsules - Data passed to oracle calls.
141
+ */ addCapsules(capsules) {
142
+ this.capsules.push(...capsules);
143
+ }
144
+ /**
145
+ * Return all capsules added for this function interaction.
146
+ */ getCapsules() {
147
+ return this.capsules;
148
+ }
149
+ }
@@ -0,0 +1,28 @@
1
+ import { type FunctionCall } from '@aztec/stdlib/abi';
2
+ import type { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { Wallet } from '../account/index.js';
4
+ import { BaseContractInteraction, type SendMethodOptions } from './base_contract_interaction.js';
5
+ import type { SimulateMethodOptions } from './contract_function_interaction.js';
6
+ /** A batch of function calls to be sent as a single transaction through a wallet. */
7
+ export declare class BatchCall extends BaseContractInteraction {
8
+ protected calls: FunctionCall[];
9
+ constructor(wallet: Wallet, calls: FunctionCall[]);
10
+ /**
11
+ * Create a transaction execution request that represents this batch, encoded and authenticated by the
12
+ * user's wallet, ready to be simulated.
13
+ * @param opts - An optional object containing additional configuration for the transaction.
14
+ * @returns A Promise that resolves to a transaction instance.
15
+ */
16
+ create(opts?: SendMethodOptions): Promise<TxExecutionRequest>;
17
+ /**
18
+ * Simulate a transaction and get its return values
19
+ * Differs from prove in a few important ways:
20
+ * 1. It returns the values of the function execution
21
+ * 2. It supports `unconstrained`, `private` and `public` functions
22
+ *
23
+ * @param options - An optional object containing additional configuration for the transaction.
24
+ * @returns The result of the transaction as returned by the contract function.
25
+ */
26
+ simulate(options?: SimulateMethodOptions): Promise<any>;
27
+ }
28
+ //# sourceMappingURL=batch_call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch_call.d.ts","sourceRoot":"","sources":["../../src/contract/batch_call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAA+B,MAAM,mBAAmB,CAAC;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACjG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAEhF,qFAAqF;AACrF,qBAAa,SAAU,SAAQ,uBAAuB;IACxB,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE;gBAA/C,MAAM,EAAE,MAAM,EAAY,KAAK,EAAE,YAAY,EAAE;IAI3D;;;;;OAKG;IACU,MAAM,CAAC,IAAI,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAO1E;;;;;;;;OAQG;IACU,QAAQ,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,GAAG,CAAC;CA2DzE"}
@@ -0,0 +1,91 @@
1
+ import { FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
+ import { BaseContractInteraction } from './base_contract_interaction.js';
3
+ /** A batch of function calls to be sent as a single transaction through a wallet. */ export class BatchCall extends BaseContractInteraction {
4
+ calls;
5
+ constructor(wallet, calls){
6
+ super(wallet), this.calls = calls;
7
+ }
8
+ /**
9
+ * Create a transaction execution request that represents this batch, encoded and authenticated by the
10
+ * user's wallet, ready to be simulated.
11
+ * @param opts - An optional object containing additional configuration for the transaction.
12
+ * @returns A Promise that resolves to a transaction instance.
13
+ */ async create(opts) {
14
+ const calls = this.calls;
15
+ const capsules = this.getCapsules();
16
+ const fee = await this.getFeeOptions({
17
+ calls,
18
+ capsules,
19
+ ...opts
20
+ });
21
+ return await this.wallet.createTxExecutionRequest({
22
+ calls,
23
+ capsules,
24
+ ...opts,
25
+ fee
26
+ });
27
+ }
28
+ /**
29
+ * Simulate a transaction and get its return values
30
+ * Differs from prove in a few important ways:
31
+ * 1. It returns the values of the function execution
32
+ * 2. It supports `unconstrained`, `private` and `public` functions
33
+ *
34
+ * @param options - An optional object containing additional configuration for the transaction.
35
+ * @returns The result of the transaction as returned by the contract function.
36
+ */ async simulate(options = {}) {
37
+ const { indexedCalls, unconstrained } = this.calls.reduce((acc, current, index)=>{
38
+ if (current.type === FunctionType.UNCONSTRAINED) {
39
+ acc.unconstrained.push([
40
+ current,
41
+ index
42
+ ]);
43
+ } else {
44
+ acc.indexedCalls.push([
45
+ current,
46
+ index,
47
+ current.type === FunctionType.PRIVATE ? acc.privateIndex++ : acc.publicIndex++
48
+ ]);
49
+ }
50
+ return acc;
51
+ }, {
52
+ indexedCalls: [],
53
+ unconstrained: [],
54
+ publicIndex: 0,
55
+ privateIndex: 0
56
+ });
57
+ const calls = indexedCalls.map(([call])=>call);
58
+ const capsules = this.getCapsules();
59
+ const fee = await this.getFeeOptions({
60
+ calls,
61
+ capsules,
62
+ ...options
63
+ });
64
+ const txRequest = await this.wallet.createTxExecutionRequest({
65
+ calls,
66
+ capsules,
67
+ ...options,
68
+ fee
69
+ });
70
+ const unconstrainedCalls = unconstrained.map(async ([call, index])=>[
71
+ await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from),
72
+ index
73
+ ]);
74
+ const [unconstrainedResults, simulatedTx] = await Promise.all([
75
+ Promise.all(unconstrainedCalls),
76
+ this.wallet.simulateTx(txRequest, true, options?.from, options?.skipTxValidation)
77
+ ]);
78
+ const results = [];
79
+ unconstrainedResults.forEach(([result, index])=>{
80
+ results[index] = result;
81
+ });
82
+ indexedCalls.forEach(([call, callIndex, resultIndex])=>{
83
+ // As account entrypoints are private, for private functions we retrieve the return values from the first nested call
84
+ // since we're interested in the first set of values AFTER the account entrypoint
85
+ // For public functions we retrieve the first values directly from the public output.
86
+ const rawReturnValues = call.type == FunctionType.PRIVATE ? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values : simulatedTx.getPublicReturnValues()?.[resultIndex].values;
87
+ results[callIndex] = rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [];
88
+ });
89
+ return results;
90
+ }
91
+ }
@@ -0,0 +1,11 @@
1
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
2
+ /**
3
+ * Validates the given ContractArtifact object by checking its functions and their parameters.
4
+ * Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types.
5
+ * Throws an error if any inconsistency is detected during the validation process.
6
+ *
7
+ * @param artifact - The ContractArtifact object to be validated.
8
+ * @returns A boolean value indicating whether the artifact is valid or not.
9
+ */
10
+ export declare function abiChecker(artifact: ContractArtifact): boolean;
11
+ //# sourceMappingURL=checker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../src/contract/checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,gBAAgB,EAAc,MAAM,mBAAmB,CAAC;AAQ1F;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,gBAAgB,WA8BpD"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Validates the given ContractArtifact object by checking its functions and their parameters.
3
+ * Ensures that the ABI has at least one function, a constructor, valid bytecode, and correct parameter types.
4
+ * Throws an error if any inconsistency is detected during the validation process.
5
+ *
6
+ * @param artifact - The ContractArtifact object to be validated.
7
+ * @returns A boolean value indicating whether the artifact is valid or not.
8
+ */ export function abiChecker(artifact) {
9
+ if (!artifact.functions || artifact.functions.length === 0) {
10
+ throw new Error('artifact has no functions');
11
+ }
12
+ artifact.functions.forEach((func)=>{
13
+ if (!('name' in func && typeof func.name === 'string' && func.name.length > 0)) {
14
+ throw new Error('ABI function has no name');
15
+ }
16
+ // TODO: implement a better check for bytecode (right now only checks if it's > 0)
17
+ if (!('bytecode' in func && func.bytecode.length > 0)) {
18
+ throw new Error('ABI function parameter has incorrect bytecode');
19
+ }
20
+ func.parameters.forEach((param)=>{
21
+ if (!param.type) {
22
+ throw new Error('ABI function parameter has no type');
23
+ }
24
+ abiParameterTypeChecker(param.type);
25
+ });
26
+ });
27
+ // TODO: implement a better check for constructor (right now only checks if it has it or not)
28
+ if (!artifact.functions.find((func)=>func.name === 'constructor')) {
29
+ throw new Error('ABI has no constructor');
30
+ }
31
+ return true;
32
+ }
33
+ /**
34
+ * Validates the ABI function parameter's type by checking its kind and attributes.
35
+ * Throws an error if the type has an unrecognized kind or incorrectly formed attributes.
36
+ * Additionally, checks nested types for array and struct kinds.
37
+ *
38
+ * @param type - The AbiType object representing the type of the ABI function parameter.
39
+ * @returns A boolean value indicating whether the type is valid or not.
40
+ */ function abiParameterTypeChecker(type) {
41
+ switch(type.kind){
42
+ case 'field':
43
+ case 'boolean':
44
+ return checkAttributes(type, {});
45
+ case 'integer':
46
+ return checkAttributes(type, {
47
+ sign: 'string',
48
+ width: 'number'
49
+ });
50
+ case 'string':
51
+ return checkAttributes(type, {
52
+ length: 'number'
53
+ });
54
+ case 'array':
55
+ return checkAttributes(type, {
56
+ length: 'number',
57
+ type: 'object'
58
+ }) && abiParameterTypeChecker(type.type);
59
+ case 'struct':
60
+ return checkAttributes(type, {
61
+ fields: 'object',
62
+ path: 'string'
63
+ }) && checkStruct(type);
64
+ default:
65
+ throw new Error('ABI function parameter has an unrecognized type');
66
+ }
67
+ }
68
+ /**
69
+ * Check if the structure of the AbiType 'struct' is valid by ensuring field names are strings
70
+ * and their type attribute passes the abiParameterTypeChecker. Returns true on successful validation,
71
+ * otherwise throws an error providing insight into the incorrect formation in the struct.
72
+ *
73
+ * @param type - The StructType object containing an array of fields to validate.
74
+ * @returns A boolean value indicating successful validation of the struct's fields.
75
+ */ function checkStruct(type) {
76
+ return type.fields.reduce((acc, field)=>{
77
+ if (!('name' in field && typeof field.name === 'string')) {
78
+ throw new Error('ABI function parameter has an incorrectly formed struct');
79
+ }
80
+ return acc && abiParameterTypeChecker(field.type);
81
+ }, true);
82
+ }
83
+ /**
84
+ * Check if a provided ABI type has the correct attributes and their associated types.
85
+ * This function compares the given 'type' object's keys with the expected attribute types
86
+ * specified in 'incompleteAttributes', as well as the required 'kind' property.
87
+ * Throws an error if there are any unrecognized attributes or incorrect attribute types.
88
+ *
89
+ * @param type - The ABI type object to be checked for correct attributes.
90
+ * @param incompleteAttributes - An object representing the expected attribute types without the 'kind' property.
91
+ * @returns Returns true if the provided ABI type has the correct attributes and their associated types, otherwise throws an error.
92
+ */ function checkAttributes(type, incompleteAttributes) {
93
+ const typeKeys = Object.keys(type);
94
+ const attributes = {
95
+ ...incompleteAttributes,
96
+ kind: 'string'
97
+ };
98
+ if (typeKeys.length !== Object.keys(attributes).length) {
99
+ throw new Error(`Unrecognized attribute on type ${type.kind}`);
100
+ }
101
+ typeKeys.forEach((element)=>{
102
+ if (!(element in type && typeof type[element] === attributes[element])) {
103
+ throw new Error(`ABI function parameter has an incorrectly formed ${type.kind}`);
104
+ }
105
+ });
106
+ return true;
107
+ }
@@ -0,0 +1,41 @@
1
+ import type { ContractArtifact } from '@aztec/stdlib/abi';
2
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import { PublicKeys } from '@aztec/stdlib/keys';
4
+ import type { Wallet } from '../account/index.js';
5
+ import { ContractBase } from './contract_base.js';
6
+ import { DeployMethod } from './deploy_method.js';
7
+ /**
8
+ * The Contract class represents a contract and provides utility methods for interacting with it.
9
+ * It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
10
+ * allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
11
+ * to attach the contract instance to a deployed contract on-chain through the PXE, which facilitates
12
+ * interaction with Aztec's privacy protocol.
13
+ */
14
+ export declare class Contract extends ContractBase {
15
+ /**
16
+ * Creates a contract instance.
17
+ * @param address - The deployed contract's address.
18
+ * @param artifact - Build artifact of the contract.
19
+ * @param wallet - The wallet to use when interacting with the contract.
20
+ * @returns A promise that resolves to a new Contract instance.
21
+ */
22
+ static at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Promise<Contract>;
23
+ /**
24
+ * Creates a tx to deploy a new instance of a contract.
25
+ * @param wallet - The wallet for executing the deployment.
26
+ * @param artifact - Build artifact of the contract to deploy
27
+ * @param args - Arguments for the constructor.
28
+ * @param constructorName - The name of the constructor function to call.
29
+ */
30
+ static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string): DeployMethod<Contract>;
31
+ /**
32
+ * Creates a tx to deploy a new instance of a contract using the specified public keys hash to derive the address.
33
+ * @param publicKeys - Hash of public keys to use for deriving the address.
34
+ * @param wallet - The wallet for executing the deployment.
35
+ * @param artifact - Build artifact of the contract.
36
+ * @param args - Arguments for the constructor.
37
+ * @param constructorName - The name of the constructor function to call.
38
+ */
39
+ static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string): DeployMethod<Contract>;
40
+ }
41
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/contract/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;GAMG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACxC;;;;;;OAMG;WACiB,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAc5G;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,eAAe,CAAC,EAAE,MAAM;IAKtG;;;;;;;OAOG;WACW,oBAAoB,CAChC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,GAAG,EAAE,EACX,eAAe,CAAC,EAAE,MAAM;CAK3B"}
@@ -0,0 +1,52 @@
1
+ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
2
+ import { PublicKeys } from '@aztec/stdlib/keys';
3
+ import { ContractBase } from './contract_base.js';
4
+ import { DeployMethod } from './deploy_method.js';
5
+ /**
6
+ * The Contract class represents a contract and provides utility methods for interacting with it.
7
+ * It enables the creation of ContractFunctionInteraction instances for each function in the contract's ABI,
8
+ * allowing users to call or send transactions to these functions. Additionally, the Contract class can be used
9
+ * to attach the contract instance to a deployed contract on-chain through the PXE, which facilitates
10
+ * interaction with Aztec's privacy protocol.
11
+ */ export class Contract extends ContractBase {
12
+ /**
13
+ * Creates a contract instance.
14
+ * @param address - The deployed contract's address.
15
+ * @param artifact - Build artifact of the contract.
16
+ * @param wallet - The wallet to use when interacting with the contract.
17
+ * @returns A promise that resolves to a new Contract instance.
18
+ */ static async at(address, artifact, wallet) {
19
+ const instance = (await wallet.getContractMetadata(address)).contractInstance;
20
+ if (instance === undefined) {
21
+ throw new Error(`Contract instance at ${address.toString()} has not been registered in the wallet's PXE`);
22
+ }
23
+ const thisContractClass = await getContractClassFromArtifact(artifact);
24
+ if (!thisContractClass.id.equals(instance.currentContractClassId)) {
25
+ // wallet holds an outdated version of this contract
26
+ await wallet.updateContract(address, artifact);
27
+ instance.currentContractClassId = thisContractClass.id;
28
+ }
29
+ return new Contract(instance, artifact, wallet);
30
+ }
31
+ /**
32
+ * Creates a tx to deploy a new instance of a contract.
33
+ * @param wallet - The wallet for executing the deployment.
34
+ * @param artifact - Build artifact of the contract to deploy
35
+ * @param args - Arguments for the constructor.
36
+ * @param constructorName - The name of the constructor function to call.
37
+ */ static deploy(wallet, artifact, args, constructorName) {
38
+ const postDeployCtor = (address, wallet)=>Contract.at(address, artifact, wallet);
39
+ return new DeployMethod(PublicKeys.default(), wallet, artifact, postDeployCtor, args, constructorName);
40
+ }
41
+ /**
42
+ * Creates a tx to deploy a new instance of a contract using the specified public keys hash to derive the address.
43
+ * @param publicKeys - Hash of public keys to use for deriving the address.
44
+ * @param wallet - The wallet for executing the deployment.
45
+ * @param artifact - Build artifact of the contract.
46
+ * @param args - Arguments for the constructor.
47
+ * @param constructorName - The name of the constructor function to call.
48
+ */ static deployWithPublicKeys(publicKeys, wallet, artifact, args, constructorName) {
49
+ const postDeployCtor = (address, wallet)=>Contract.at(address, artifact, wallet);
50
+ return new DeployMethod(publicKeys, wallet, artifact, postDeployCtor, args, constructorName);
51
+ }
52
+ }
@@ -0,0 +1,61 @@
1
+ import { type ContractArtifact, type ContractNote, type FieldLayout, FunctionSelector } from '@aztec/stdlib/abi';
2
+ import { type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
+ import type { Wallet } from '../account/index.js';
4
+ import { ContractFunctionInteraction } from './contract_function_interaction.js';
5
+ /**
6
+ * Type representing a contract method that returns a ContractFunctionInteraction instance
7
+ * and has a readonly 'selector' property of type Buffer. Takes any number of arguments.
8
+ */
9
+ export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & {
10
+ /**
11
+ * The unique identifier for a contract function in bytecode.
12
+ */
13
+ selector: () => Promise<FunctionSelector>;
14
+ };
15
+ /**
16
+ * Type representing the storage layout of a contract.
17
+ */
18
+ export type ContractStorageLayout<T extends string> = {
19
+ [K in T]: FieldLayout;
20
+ };
21
+ /**
22
+ * Type representing the notes used in a contract.
23
+ */
24
+ export type ContractNotes<T extends string> = {
25
+ [K in T]: ContractNote;
26
+ };
27
+ /**
28
+ * Abstract implementation of a contract extended by the Contract class and generated contract types.
29
+ */
30
+ export declare class ContractBase {
31
+ /** The deployed contract instance definition. */
32
+ readonly instance: ContractInstanceWithAddress;
33
+ /** The Application Binary Interface for the contract. */
34
+ readonly artifact: ContractArtifact;
35
+ /** The wallet used for interacting with this contract. */
36
+ wallet: Wallet;
37
+ /**
38
+ * An object containing contract methods mapped to their respective names.
39
+ */
40
+ methods: {
41
+ [name: string]: ContractMethod;
42
+ };
43
+ protected constructor(
44
+ /** The deployed contract instance definition. */
45
+ instance: ContractInstanceWithAddress,
46
+ /** The Application Binary Interface for the contract. */
47
+ artifact: ContractArtifact,
48
+ /** The wallet used for interacting with this contract. */
49
+ wallet: Wallet);
50
+ /** Address of the contract. */
51
+ get address(): import("@aztec/stdlib/aztec-address").AztecAddress;
52
+ /** Partial address of the contract. */
53
+ get partialAddress(): Promise<import("@aztec/foundation/schemas").Fr>;
54
+ /**
55
+ * Creates a new instance of the contract wrapper attached to a different wallet.
56
+ * @param wallet - Wallet to use for sending txs.
57
+ * @returns A new contract instance.
58
+ */
59
+ withWallet(wallet: Wallet): this;
60
+ }
61
+ //# sourceMappingURL=contract_base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract_base.d.ts","sourceRoot":"","sources":["../../src/contract/contract_base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,2BAA2B,EAAyB,MAAM,wBAAwB,CAAC;AAEjG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,2BAA2B,CAAC,GAAG;IAC/E;;OAEG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,MAAM,IAAI;KACnD,CAAC,IAAI,CAAC,GAAG,WAAW;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,IAAI;KAC3C,CAAC,IAAI,CAAC,GAAG,YAAY;CACvB,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAY;IAOrB,iDAAiD;aACjC,QAAQ,EAAE,2BAA2B;IACrD,yDAAyD;aACzC,QAAQ,EAAE,gBAAgB;IAC1C,0DAA0D;IACnD,MAAM,EAAE,MAAM;IAXvB;;OAEG;IACI,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAA;KAAE,CAAM;IAExD,SAAS;IACP,iDAAiD;IACjC,QAAQ,EAAE,2BAA2B;IACrD,yDAAyD;IACzC,QAAQ,EAAE,gBAAgB;IAC1C,0DAA0D;IACnD,MAAM,EAAE,MAAM;IAmBvB,+BAA+B;IAC/B,IAAW,OAAO,uDAEjB;IAED,uCAAuC;IACvC,IAAW,cAAc,oDAExB;IAED;;;;OAIG;IACI,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAGxC"}
@@ -0,0 +1,45 @@
1
+ import { FunctionSelector } from '@aztec/stdlib/abi';
2
+ import { computePartialAddress } from '@aztec/stdlib/contract';
3
+ import { ContractFunctionInteraction } from './contract_function_interaction.js';
4
+ /**
5
+ * Abstract implementation of a contract extended by the Contract class and generated contract types.
6
+ */ export class ContractBase {
7
+ instance;
8
+ artifact;
9
+ wallet;
10
+ /**
11
+ * An object containing contract methods mapped to their respective names.
12
+ */ methods;
13
+ constructor(/** The deployed contract instance definition. */ instance, /** The Application Binary Interface for the contract. */ artifact, /** The wallet used for interacting with this contract. */ wallet){
14
+ this.instance = instance;
15
+ this.artifact = artifact;
16
+ this.wallet = wallet;
17
+ this.methods = {};
18
+ artifact.functions.forEach((f)=>{
19
+ const interactionFunction = (...args)=>{
20
+ return new ContractFunctionInteraction(this.wallet, this.instance.address, f, args);
21
+ };
22
+ this.methods[f.name] = Object.assign(interactionFunction, {
23
+ /**
24
+ * A getter for users to fetch the function selector.
25
+ * @returns Selector of the function.
26
+ */ selector () {
27
+ return FunctionSelector.fromNameAndParameters(f.name, f.parameters);
28
+ }
29
+ });
30
+ });
31
+ }
32
+ /** Address of the contract. */ get address() {
33
+ return this.instance.address;
34
+ }
35
+ /** Partial address of the contract. */ get partialAddress() {
36
+ return computePartialAddress(this.instance);
37
+ }
38
+ /**
39
+ * Creates a new instance of the contract wrapper attached to a different wallet.
40
+ * @param wallet - Wallet to use for sending txs.
41
+ * @returns A new contract instance.
42
+ */ withWallet(wallet) {
43
+ return new ContractBase(this.instance, this.artifact, wallet);
44
+ }
45
+ }