@aztec/aztec.js 0.0.1-commit.b655e406 → 0.0.1-commit.c0b82b2

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 (261) hide show
  1. package/dest/account/account.d.ts +26 -42
  2. package/dest/account/account.d.ts.map +1 -1
  3. package/dest/account/account.js +19 -47
  4. package/dest/account/account_contract.d.ts +9 -10
  5. package/dest/account/account_contract.d.ts.map +1 -1
  6. package/dest/account/account_with_secret_key.d.ts +20 -9
  7. package/dest/account/account_with_secret_key.d.ts.map +1 -1
  8. package/dest/account/account_with_secret_key.js +21 -4
  9. package/dest/account/index.d.ts +4 -3
  10. package/dest/account/index.d.ts.map +1 -1
  11. package/dest/account/index.js +2 -0
  12. package/dest/account/signerless_account.d.ts +7 -9
  13. package/dest/account/signerless_account.d.ts.map +1 -1
  14. package/dest/account/signerless_account.js +8 -11
  15. package/dest/api/abi.d.ts +1 -1
  16. package/dest/api/account.d.ts +3 -4
  17. package/dest/api/account.d.ts.map +1 -1
  18. package/dest/api/account.js +2 -3
  19. package/dest/api/addresses.d.ts +1 -1
  20. package/dest/api/authorization.d.ts +2 -2
  21. package/dest/api/authorization.d.ts.map +1 -1
  22. package/dest/api/authorization.js +1 -1
  23. package/dest/api/block.d.ts +1 -1
  24. package/dest/api/contract.d.ts +19 -13
  25. package/dest/api/contract.d.ts.map +1 -1
  26. package/dest/api/contract.js +17 -11
  27. package/dest/api/crypto.d.ts +1 -1
  28. package/dest/api/deployment.d.ts +1 -2
  29. package/dest/api/deployment.d.ts.map +1 -1
  30. package/dest/api/deployment.js +0 -1
  31. package/dest/api/eth_address.d.ts +1 -1
  32. package/dest/api/ethereum.d.ts +1 -1
  33. package/dest/api/events.d.ts +10 -6
  34. package/dest/api/events.d.ts.map +1 -1
  35. package/dest/api/events.js +30 -20
  36. package/dest/api/fee.d.ts +1 -1
  37. package/dest/api/fee_testing.d.ts +1 -1
  38. package/dest/api/fields.d.ts +4 -2
  39. package/dest/api/fields.d.ts.map +1 -1
  40. package/dest/api/fields.js +3 -1
  41. package/dest/api/keys.d.ts +2 -2
  42. package/dest/api/keys.js +1 -1
  43. package/dest/api/log.d.ts +1 -1
  44. package/dest/api/messaging.d.ts +1 -1
  45. package/dest/api/node.d.ts +8 -4
  46. package/dest/api/node.d.ts.map +1 -1
  47. package/dest/api/node.js +7 -3
  48. package/dest/api/note.d.ts +2 -2
  49. package/dest/api/note.d.ts.map +1 -1
  50. package/dest/api/note.js +1 -1
  51. package/dest/api/protocol.d.ts +7 -1
  52. package/dest/api/protocol.d.ts.map +1 -1
  53. package/dest/api/protocol.js +6 -0
  54. package/dest/api/trees.d.ts +1 -1
  55. package/dest/api/tx.d.ts +2 -2
  56. package/dest/api/tx.d.ts.map +1 -1
  57. package/dest/api/tx.js +1 -1
  58. package/dest/api/utils.d.ts +1 -1
  59. package/dest/api/wallet.d.ts +3 -3
  60. package/dest/api/wallet.d.ts.map +1 -1
  61. package/dest/api/wallet.js +2 -2
  62. package/dest/authorization/call_authorization_request.d.ts +2 -2
  63. package/dest/authorization/call_authorization_request.d.ts.map +1 -1
  64. package/dest/contract/base_contract_interaction.d.ts +8 -11
  65. package/dest/contract/base_contract_interaction.d.ts.map +1 -1
  66. package/dest/contract/base_contract_interaction.js +5 -17
  67. package/dest/contract/batch_call.d.ts +8 -9
  68. package/dest/contract/batch_call.d.ts.map +1 -1
  69. package/dest/contract/batch_call.js +59 -36
  70. package/dest/contract/checker.d.ts +1 -1
  71. package/dest/contract/contract.d.ts +2 -2
  72. package/dest/contract/contract.d.ts.map +1 -1
  73. package/dest/contract/contract.js +4 -5
  74. package/dest/contract/contract_base.d.ts +6 -10
  75. package/dest/contract/contract_base.d.ts.map +1 -1
  76. package/dest/contract/contract_base.js +5 -12
  77. package/dest/contract/contract_function_interaction.d.ts +5 -14
  78. package/dest/contract/contract_function_interaction.d.ts.map +1 -1
  79. package/dest/contract/contract_function_interaction.js +18 -12
  80. package/dest/contract/deploy_method.d.ts +85 -24
  81. package/dest/contract/deploy_method.d.ts.map +1 -1
  82. package/dest/contract/deploy_method.js +71 -36
  83. package/dest/contract/get_gas_limits.d.ts +1 -1
  84. package/dest/contract/get_gas_limits.js +3 -3
  85. package/dest/contract/interaction_options.d.ts +51 -7
  86. package/dest/contract/interaction_options.d.ts.map +1 -1
  87. package/dest/contract/interaction_options.js +12 -11
  88. package/dest/contract/protocol_contracts/auth-registry.d.ts +36 -0
  89. package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -0
  90. package/dest/contract/protocol_contracts/auth-registry.js +1005 -0
  91. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +15 -0
  92. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  93. package/dest/contract/protocol_contracts/contract-class-registry.js +139 -0
  94. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +22 -0
  95. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  96. package/dest/contract/protocol_contracts/contract-instance-registry.js +465 -0
  97. package/dest/contract/protocol_contracts/fee-juice.d.ts +21 -0
  98. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  99. package/dest/contract/protocol_contracts/fee-juice.js +434 -0
  100. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +34 -0
  101. package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -0
  102. package/dest/contract/protocol_contracts/multi-call-entrypoint.js +601 -0
  103. package/dest/contract/protocol_contracts/public-checks.d.ts +26 -0
  104. package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -0
  105. package/dest/contract/protocol_contracts/public-checks.js +609 -0
  106. package/dest/contract/wait_for_proven.d.ts +2 -2
  107. package/dest/contract/wait_for_proven.d.ts.map +1 -1
  108. package/dest/contract/wait_for_proven.js +1 -1
  109. package/dest/contract/wait_opts.d.ts +16 -0
  110. package/dest/contract/wait_opts.d.ts.map +1 -0
  111. package/dest/contract/wait_opts.js +5 -0
  112. package/dest/deployment/contract_deployer.d.ts +1 -1
  113. package/dest/deployment/contract_deployer.d.ts.map +1 -1
  114. package/dest/deployment/contract_deployer.js +1 -1
  115. package/dest/deployment/publish_class.d.ts +1 -1
  116. package/dest/deployment/publish_class.js +3 -3
  117. package/dest/deployment/publish_instance.d.ts +2 -2
  118. package/dest/deployment/publish_instance.d.ts.map +1 -1
  119. package/dest/deployment/publish_instance.js +3 -3
  120. package/dest/ethereum/portal_manager.d.ts +7 -6
  121. package/dest/ethereum/portal_manager.d.ts.map +1 -1
  122. package/dest/ethereum/portal_manager.js +48 -22
  123. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +2 -2
  124. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
  125. package/dest/fee/fee_juice_payment_method_with_claim.js +9 -9
  126. package/dest/fee/fee_payment_method.d.ts +2 -2
  127. package/dest/fee/fee_payment_method.d.ts.map +1 -1
  128. package/dest/fee/private_fee_payment_method.d.ts +2 -2
  129. package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
  130. package/dest/fee/private_fee_payment_method.js +14 -14
  131. package/dest/fee/public_fee_payment_method.d.ts +2 -2
  132. package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
  133. package/dest/fee/public_fee_payment_method.js +14 -14
  134. package/dest/fee/sponsored_fee_payment.d.ts +2 -2
  135. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
  136. package/dest/fee/sponsored_fee_payment.js +5 -5
  137. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  138. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  139. package/dest/scripts/generate_protocol_contract_types.js +120 -0
  140. package/dest/utils/abi_types.d.ts +2 -2
  141. package/dest/utils/abi_types.d.ts.map +1 -1
  142. package/dest/utils/authwit.d.ts +14 -12
  143. package/dest/utils/authwit.d.ts.map +1 -1
  144. package/dest/utils/authwit.js +27 -20
  145. package/dest/utils/cross_chain.d.ts +2 -2
  146. package/dest/utils/cross_chain.d.ts.map +1 -1
  147. package/dest/utils/fee_juice.d.ts +2 -2
  148. package/dest/utils/fee_juice.js +2 -2
  149. package/dest/utils/field_compressed_string.d.ts +1 -1
  150. package/dest/utils/field_compressed_string.d.ts.map +1 -1
  151. package/dest/utils/field_compressed_string.js +1 -1
  152. package/dest/utils/node.d.ts +13 -2
  153. package/dest/utils/node.d.ts.map +1 -1
  154. package/dest/utils/node.js +46 -0
  155. package/dest/utils/pub_key.d.ts +2 -2
  156. package/dest/utils/pub_key.d.ts.map +1 -1
  157. package/dest/utils/pub_key.js +1 -1
  158. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +6 -9
  159. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
  160. package/dest/wallet/account_entrypoint_meta_payment_method.js +29 -44
  161. package/dest/wallet/account_manager.d.ts +3 -9
  162. package/dest/wallet/account_manager.d.ts.map +1 -1
  163. package/dest/wallet/account_manager.js +6 -12
  164. package/dest/wallet/capabilities.d.ts +452 -0
  165. package/dest/wallet/capabilities.d.ts.map +1 -0
  166. package/dest/wallet/capabilities.js +3 -0
  167. package/dest/wallet/deploy_account_method.d.ts +49 -10
  168. package/dest/wallet/deploy_account_method.d.ts.map +1 -1
  169. package/dest/wallet/deploy_account_method.js +35 -7
  170. package/dest/wallet/index.d.ts +2 -2
  171. package/dest/wallet/index.d.ts.map +1 -1
  172. package/dest/wallet/index.js +1 -1
  173. package/dest/wallet/wallet.d.ts +1853 -1533
  174. package/dest/wallet/wallet.d.ts.map +1 -1
  175. package/dest/wallet/wallet.js +223 -124
  176. package/package.json +27 -15
  177. package/src/account/account.ts +35 -60
  178. package/src/account/account_contract.ts +7 -8
  179. package/src/account/account_with_secret_key.ts +34 -9
  180. package/src/account/index.ts +3 -2
  181. package/src/account/signerless_account.ts +15 -15
  182. package/src/api/account.ts +10 -3
  183. package/src/api/authorization.ts +1 -0
  184. package/src/api/contract.ts +26 -10
  185. package/src/api/deployment.ts +0 -1
  186. package/src/api/events.ts +35 -27
  187. package/src/api/fields.ts +3 -1
  188. package/src/api/keys.ts +2 -2
  189. package/src/api/node.ts +7 -3
  190. package/src/api/note.ts +1 -1
  191. package/src/api/protocol.ts +7 -0
  192. package/src/api/tx.ts +4 -0
  193. package/src/api/wallet.ts +52 -9
  194. package/src/authorization/call_authorization_request.ts +1 -1
  195. package/src/contract/base_contract_interaction.ts +27 -16
  196. package/src/contract/batch_call.ts +62 -48
  197. package/src/contract/contract.ts +7 -5
  198. package/src/contract/contract_base.ts +5 -15
  199. package/src/contract/contract_function_interaction.ts +26 -17
  200. package/src/contract/deploy_method.ts +175 -47
  201. package/src/contract/get_gas_limits.ts +3 -3
  202. package/src/contract/interaction_options.ts +59 -13
  203. package/src/contract/protocol_contracts/auth-registry.ts +553 -0
  204. package/src/contract/protocol_contracts/contract-class-registry.ts +99 -0
  205. package/src/contract/protocol_contracts/contract-instance-registry.ts +302 -0
  206. package/src/contract/protocol_contracts/fee-juice.ts +266 -0
  207. package/src/contract/protocol_contracts/multi-call-entrypoint.ts +336 -0
  208. package/src/contract/protocol_contracts/public-checks.ts +320 -0
  209. package/src/contract/wait_for_proven.ts +1 -1
  210. package/src/contract/wait_opts.ts +21 -0
  211. package/src/deployment/contract_deployer.ts +3 -2
  212. package/src/deployment/publish_class.ts +3 -3
  213. package/src/deployment/publish_instance.ts +3 -6
  214. package/src/ethereum/portal_manager.ts +65 -34
  215. package/src/fee/fee_juice_payment_method_with_claim.ts +9 -7
  216. package/src/fee/fee_payment_method.ts +1 -1
  217. package/src/fee/private_fee_payment_method.ts +12 -10
  218. package/src/fee/public_fee_payment_method.ts +13 -11
  219. package/src/fee/sponsored_fee_payment.ts +6 -4
  220. package/src/scripts/generate_protocol_contract_types.ts +150 -0
  221. package/src/utils/abi_types.ts +1 -1
  222. package/src/utils/authwit.ts +40 -22
  223. package/src/utils/cross_chain.ts +1 -1
  224. package/src/utils/fee_juice.ts +2 -2
  225. package/src/utils/field_compressed_string.ts +1 -1
  226. package/src/utils/node.ts +62 -0
  227. package/src/utils/pub_key.ts +2 -2
  228. package/src/wallet/account_entrypoint_meta_payment_method.ts +29 -60
  229. package/src/wallet/account_manager.ts +7 -15
  230. package/src/wallet/capabilities.ts +500 -0
  231. package/src/wallet/deploy_account_method.ts +78 -16
  232. package/src/wallet/index.ts +1 -1
  233. package/src/wallet/wallet.ts +387 -166
  234. package/dest/account/interface.d.ts +0 -19
  235. package/dest/account/interface.d.ts.map +0 -1
  236. package/dest/account/interface.js +0 -5
  237. package/dest/contract/deploy_sent_tx.d.ts +0 -43
  238. package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
  239. package/dest/contract/deploy_sent_tx.js +0 -40
  240. package/dest/contract/protocol_contracts.d.ts +0 -9
  241. package/dest/contract/protocol_contracts.d.ts.map +0 -1
  242. package/dest/contract/protocol_contracts.js +0 -26
  243. package/dest/contract/sent_tx.d.ts +0 -51
  244. package/dest/contract/sent_tx.d.ts.map +0 -1
  245. package/dest/contract/sent_tx.js +0 -90
  246. package/dest/contract/unsafe_contract.d.ts +0 -15
  247. package/dest/contract/unsafe_contract.d.ts.map +0 -1
  248. package/dest/contract/unsafe_contract.js +0 -6
  249. package/dest/deployment/broadcast_function.d.ts +0 -24
  250. package/dest/deployment/broadcast_function.d.ts.map +0 -1
  251. package/dest/deployment/broadcast_function.js +0 -74
  252. package/dest/wallet/base_wallet.d.ts +0 -91
  253. package/dest/wallet/base_wallet.d.ts.map +0 -1
  254. package/dest/wallet/base_wallet.js +0 -238
  255. package/src/account/interface.ts +0 -25
  256. package/src/contract/deploy_sent_tx.ts +0 -68
  257. package/src/contract/protocol_contracts.ts +0 -35
  258. package/src/contract/sent_tx.ts +0 -130
  259. package/src/contract/unsafe_contract.ts +0 -19
  260. package/src/deployment/broadcast_function.ts +0 -148
  261. package/src/wallet/base_wallet.ts +0 -350
package/src/api/wallet.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  export {
2
2
  type Aliased,
3
- type ContractInstanceAndArtifact,
4
- type UserFeeOptions,
5
3
  type SimulateOptions,
4
+ type ExecuteUtilityOptions,
6
5
  type ProfileOptions,
7
6
  type SendOptions,
8
7
  type BatchableMethods,
@@ -11,24 +10,68 @@ export {
11
10
  type BatchedMethodResultWrapper,
12
11
  type BatchResults,
13
12
  type Wallet,
14
- ContractInstantiationDataSchema,
15
- FunctionCallSchema,
13
+ type PrivateEvent,
14
+ type PrivateEventFilter,
15
+ type PublicEvent,
16
+ type PublicEventFilter,
17
+ type ContractMetadata,
18
+ type ContractClassMetadata,
19
+ AppCapabilitiesSchema,
20
+ WalletCapabilitiesSchema,
16
21
  ExecutionPayloadSchema,
17
- UserFeeOptionsSchema,
22
+ GasSettingsOptionSchema,
18
23
  WalletSimulationFeeOptionSchema,
24
+ WaitOptsSchema,
19
25
  SendOptionsSchema,
20
26
  SimulateOptionsSchema,
21
27
  ProfileOptionsSchema,
22
- InstanceDataSchema,
23
28
  MessageHashOrIntentSchema,
24
29
  BatchedMethodSchema,
25
- ContractMetadataSchema,
26
- ContractClassMetadataSchema,
27
30
  EventMetadataDefinitionSchema,
31
+ PrivateEventSchema,
32
+ PrivateEventFilterSchema,
33
+ PublicEventSchema,
34
+ PublicEventFilterSchema,
35
+ ContractClassMetadataSchema,
36
+ ContractMetadataSchema,
28
37
  WalletSchema,
38
+ ContractFunctionPatternSchema,
39
+ AccountsCapabilitySchema,
40
+ GrantedAccountsCapabilitySchema,
41
+ ContractsCapabilitySchema,
42
+ GrantedContractsCapabilitySchema,
43
+ ContractClassesCapabilitySchema,
44
+ GrantedContractClassesCapabilitySchema,
45
+ SimulationCapabilitySchema,
46
+ GrantedSimulationCapabilitySchema,
47
+ TransactionCapabilitySchema,
48
+ GrantedTransactionCapabilitySchema,
49
+ DataCapabilitySchema,
50
+ GrantedDataCapabilitySchema,
51
+ CapabilitySchema,
52
+ GrantedCapabilitySchema,
29
53
  } from '../wallet/wallet.js';
30
54
 
31
- export { type FeeOptions, BaseWallet } from '../wallet/base_wallet.js';
55
+ export {
56
+ type AppCapabilities,
57
+ type WalletCapabilities,
58
+ CAPABILITY_VERSION,
59
+ type Capability,
60
+ type GrantedCapability,
61
+ type ContractFunctionPattern,
62
+ type AccountsCapability,
63
+ type GrantedAccountsCapability,
64
+ type ContractsCapability,
65
+ type GrantedContractsCapability,
66
+ type ContractClassesCapability,
67
+ type GrantedContractClassesCapability,
68
+ type SimulationCapability,
69
+ type GrantedSimulationCapability,
70
+ type TransactionCapability,
71
+ type GrantedTransactionCapability,
72
+ type DataCapability,
73
+ type GrantedDataCapability,
74
+ } from '../wallet/capabilities.js';
32
75
 
33
76
  export { AccountManager } from '../wallet/account_manager.js';
34
77
 
@@ -1,4 +1,4 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { FieldReader } from '@aztec/foundation/serialize';
3
3
  import { AuthorizationSelector, FunctionSelector } from '@aztec/stdlib/abi';
4
4
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -1,11 +1,16 @@
1
- import type { ExecutionPayload } from '@aztec/entrypoints/payload';
2
1
  import { createLogger } from '@aztec/foundation/log';
3
2
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4
- import type { Capsule } from '@aztec/stdlib/tx';
3
+ import type { Capsule, ExecutionPayload, TxReceipt } from '@aztec/stdlib/tx';
5
4
 
6
5
  import type { Wallet } from '../wallet/wallet.js';
7
- import { type RequestInteractionOptions, type SendInteractionOptions, toSendOptions } from './interaction_options.js';
8
- import { SentTx } from './sent_tx.js';
6
+ import {
7
+ type InteractionWaitOptions,
8
+ type RequestInteractionOptions,
9
+ type SendInteractionOptions,
10
+ type SendInteractionOptionsWithoutWait,
11
+ type SendReturn,
12
+ toSendOptions,
13
+ } from './interaction_options.js';
9
14
 
10
15
  /**
11
16
  * Base class for an interaction with a contract, be it a deployment, a function call, or a batch.
@@ -31,20 +36,26 @@ export abstract class BaseContractInteraction {
31
36
  // docs:start:send
32
37
  /**
33
38
  * Sends a transaction to the contract function with the specified options.
34
- * This function throws an error if called on a utility function.
35
- * It creates and signs the transaction if necessary, and returns a SentTx instance,
36
- * which can be used to track the transaction status, receipt, and events.
39
+ * By default, waits for the transaction to be mined and returns the receipt (or custom type).
37
40
  * @param options - An object containing 'from' property representing
38
- * the AztecAddress of the sender and optional fee configuration
39
- * @returns A SentTx instance for tracking the transaction status and information.
41
+ * the AztecAddress of the sender, optional fee configuration, and optional wait settings
42
+ * @returns TReturn (if wait is undefined/WaitOpts) or TxHash (if wait is NO_WAIT)
40
43
  */
41
- public send(options: SendInteractionOptions): SentTx {
44
+ // Overload for when wait is not specified at all - returns TReturn
45
+ public send<TReturn = TxReceipt>(options: SendInteractionOptionsWithoutWait): Promise<TReturn>;
46
+ // Generic overload for explicit wait values
47
+ // eslint-disable-next-line jsdoc/require-jsdoc
48
+ public send<TReturn = TxReceipt, W extends InteractionWaitOptions = undefined>(
49
+ options: SendInteractionOptions<W>,
50
+ ): Promise<SendReturn<W, TReturn>>;
51
+ // eslint-disable-next-line jsdoc/require-jsdoc
52
+ public async send<TReturn = TxReceipt>(
53
+ options: SendInteractionOptions<InteractionWaitOptions>,
54
+ ): Promise<SendReturn<typeof options.wait, TReturn>> {
42
55
  // docs:end:send
43
- const sendTx = async () => {
44
- const executionPayload = await this.request(options);
45
- const sendOptions = await toSendOptions(options);
46
- return this.wallet.sendTx(executionPayload, sendOptions);
47
- };
48
- return new SentTx(this.wallet, sendTx);
56
+ const executionPayload = await this.request(options);
57
+ const sendOptions = toSendOptions(options);
58
+
59
+ return (await this.wallet.sendTx(executionPayload, sendOptions as any)) as SendReturn<typeof options.wait, TReturn>;
49
60
  }
50
61
  }
@@ -1,7 +1,7 @@
1
- import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
2
1
  import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
+ import { ExecutionPayload, TxSimulationResult, UtilityExecutionResult, mergeExecutionPayloads } from '@aztec/stdlib/tx';
3
3
 
4
- import type { Wallet } from '../wallet/wallet.js';
4
+ import type { BatchedMethod, Wallet } from '../wallet/wallet.js';
5
5
  import { BaseContractInteraction } from './base_contract_interaction.js';
6
6
  import {
7
7
  type RequestInteractionOptions,
@@ -10,6 +10,7 @@ import {
10
10
  } from './interaction_options.js';
11
11
 
12
12
  /** A batch of function calls to be sent as a single transaction through a wallet. */
13
+ // docs:start:batch_call_class
13
14
  export class BatchCall extends BaseContractInteraction {
14
15
  constructor(
15
16
  wallet: Wallet,
@@ -17,6 +18,7 @@ export class BatchCall extends BaseContractInteraction {
17
18
  ) {
18
19
  super(wallet);
19
20
  }
21
+ // docs:end:batch_call_class
20
22
 
21
23
  /**
22
24
  * Returns an execution request that represents this operation.
@@ -35,13 +37,12 @@ export class BatchCall extends BaseContractInteraction {
35
37
  }
36
38
 
37
39
  /**
38
- * Simulate a transaction and get its return values
39
- * Differs from prove in a few important ways:
40
- * 1. It returns the values of the function execution
41
- * 2. It supports `utility`, `private` and `public` functions
42
- *
43
- * @param options - An optional object containing additional configuration for the transaction.
44
- * @returns The result of the transaction as returned by the contract function.
40
+ * Simulates/executes the batch, supporting private, public and utility functions. Although this is a single
41
+ * interaction with the wallet, private and public functions will be grouped into a single ExecutionPayload
42
+ * that the wallet will simulate as a single transaction. Utility function calls will be executed
43
+ * one by one.
44
+ * @param options - An optional object containing additional configuration for the interaction.
45
+ * @returns The results of all the interactions that make up the batch
45
46
  */
46
47
  public async simulate(options: SimulateInteractionOptions): Promise<any> {
47
48
  const { indexedExecutionPayloads, utility } = (await this.getExecutionPayloads()).reduce<{
@@ -70,52 +71,65 @@ export class BatchCall extends BaseContractInteraction {
70
71
  { indexedExecutionPayloads: [], utility: [], publicIndex: 0, privateIndex: 0 },
71
72
  );
72
73
 
73
- const payloads = indexedExecutionPayloads.map(([request]) => request);
74
- const combinedPayload = mergeExecutionPayloads(payloads);
75
- const executionPayload = new ExecutionPayload(
76
- combinedPayload.calls,
77
- combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
78
- combinedPayload.capsules.concat(options.capsules ?? []),
79
- combinedPayload.extraHashedArgs,
80
- );
74
+ const batchRequests: BatchedMethod[] = [];
81
75
 
82
- const utilityBatchPromise =
83
- utility.length > 0
84
- ? this.wallet.batch(
85
- utility.map(([call]) => ({
86
- name: 'simulateUtility' as const,
87
- args: [call.name, call.args, call.to, options?.authWitnesses] as const,
88
- })),
89
- )
90
- : Promise.resolve([]);
76
+ // Add utility calls to batch
77
+ for (const [call] of utility) {
78
+ batchRequests.push({
79
+ name: 'executeUtility' as const,
80
+ args: [call, { scope: options.from, authWitnesses: options.authWitnesses }],
81
+ });
82
+ }
91
83
 
92
- const [utilityBatchResults, simulatedTx] = await Promise.all([
93
- utilityBatchPromise,
94
- indexedExecutionPayloads.length > 0
95
- ? this.wallet.simulateTx(executionPayload, await toSimulateOptions(options))
96
- : Promise.resolve(),
97
- ]);
84
+ // Add tx simulation to batch if there are any private/public calls
85
+ if (indexedExecutionPayloads.length > 0) {
86
+ const payloads = indexedExecutionPayloads.map(([request]) => request);
87
+ const combinedPayload = mergeExecutionPayloads(payloads);
88
+ const executionPayload = new ExecutionPayload(
89
+ combinedPayload.calls,
90
+ combinedPayload.authWitnesses.concat(options.authWitnesses ?? []),
91
+ combinedPayload.capsules.concat(options.capsules ?? []),
92
+ combinedPayload.extraHashedArgs,
93
+ );
94
+
95
+ batchRequests.push({
96
+ name: 'simulateTx' as const,
97
+ args: [executionPayload, toSimulateOptions(options)],
98
+ });
99
+ }
100
+
101
+ const batchResults = batchRequests.length > 0 ? await this.wallet.batch(batchRequests) : [];
98
102
 
99
103
  const results: any[] = [];
100
104
 
101
- utilityBatchResults.forEach((wrappedResult, utilityIndex) => {
102
- const [, originalIndex] = utility[utilityIndex];
103
- results[originalIndex] = wrappedResult.result.result;
104
- });
105
+ // Process utility results (they come first in batch results)
106
+ for (let i = 0; i < utility.length; i++) {
107
+ const [call, resultIndex] = utility[i];
108
+ const wrappedResult = batchResults[i];
109
+ if (wrappedResult.name === 'executeUtility') {
110
+ const rawReturnValues = (wrappedResult.result as UtilityExecutionResult).result;
111
+ results[resultIndex] = rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [];
112
+ }
113
+ }
105
114
 
106
- if (simulatedTx) {
107
- indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {
108
- const call = request.calls[0];
109
- // As account entrypoints are private, for private functions we retrieve the return values from the first nested call
110
- // since we're interested in the first set of values AFTER the account entrypoint
111
- // For public functions we retrieve the first values directly from the public output.
112
- const rawReturnValues =
113
- call.type == FunctionType.PRIVATE
114
- ? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values
115
- : simulatedTx.getPublicReturnValues()?.[resultIndex].values;
115
+ // Process tx simulation result (it comes last if present)
116
+ if (indexedExecutionPayloads.length > 0) {
117
+ const txResultWrapper = batchResults[utility.length];
118
+ if (txResultWrapper.name === 'simulateTx') {
119
+ const simulatedTx = txResultWrapper.result as TxSimulationResult;
120
+ indexedExecutionPayloads.forEach(([request, callIndex, resultIndex]) => {
121
+ const call = request.calls[0];
122
+ // As account entrypoints are private, for private functions we retrieve the return values from the first nested call
123
+ // since we're interested in the first set of values AFTER the account entrypoint
124
+ // For public functions we retrieve the first values directly from the public output.
125
+ const rawReturnValues =
126
+ call.type == FunctionType.PRIVATE
127
+ ? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values
128
+ : simulatedTx.getPublicReturnValues()?.[resultIndex].values;
116
129
 
117
- results[callIndex] = rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [];
118
- });
130
+ results[callIndex] = rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [];
131
+ });
132
+ }
119
133
  }
120
134
 
121
135
  return results;
@@ -1,5 +1,6 @@
1
1
  import type { ContractArtifact } from '@aztec/stdlib/abi';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
+ import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
3
4
  import { PublicKeys } from '@aztec/stdlib/keys';
4
5
 
5
6
  import type { Wallet } from '../wallet/wallet.js';
@@ -21,9 +22,8 @@ export class Contract extends ContractBase {
21
22
  * @param wallet - The wallet to use when interacting with the contract.
22
23
  * @returns A promise that resolves to a new Contract instance.
23
24
  */
24
- public static async at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Promise<Contract> {
25
- const instance = await wallet.registerContract(address, artifact);
26
- return new Contract(instance, artifact, wallet);
25
+ public static at(address: AztecAddress, artifact: ContractArtifact, wallet: Wallet): Contract {
26
+ return new Contract(address, artifact, wallet);
27
27
  }
28
28
 
29
29
  /**
@@ -34,7 +34,8 @@ export class Contract extends ContractBase {
34
34
  * @param constructorName - The name of the constructor function to call.
35
35
  */
36
36
  public static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string) {
37
- const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, artifact, wallet);
37
+ const postDeployCtor = (instance: ContractInstanceWithAddress, wallet: Wallet) =>
38
+ Contract.at(instance.address, artifact, wallet);
38
39
  return new DeployMethod(PublicKeys.default(), wallet, artifact, postDeployCtor, args, constructorName);
39
40
  }
40
41
 
@@ -54,7 +55,8 @@ export class Contract extends ContractBase {
54
55
  args: any[],
55
56
  constructorName?: string,
56
57
  ) {
57
- const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, artifact, wallet);
58
+ const postDeployCtor = (instance: ContractInstanceWithAddress, wallet: Wallet) =>
59
+ Contract.at(instance.address, artifact, wallet);
58
60
  return new DeployMethod(publicKeys, wallet, artifact, postDeployCtor, args, constructorName);
59
61
  }
60
62
  }
@@ -5,7 +5,7 @@ import {
5
5
  FunctionSelector,
6
6
  getAllFunctionAbis,
7
7
  } from '@aztec/stdlib/abi';
8
- import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
8
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
9
 
10
10
  import type { Wallet } from '../wallet/wallet.js';
11
11
  import { ContractFunctionInteraction } from './contract_function_interaction.js';
@@ -38,8 +38,8 @@ export class ContractBase {
38
38
  public methods: { [name: string]: ContractMethod } = {};
39
39
 
40
40
  protected constructor(
41
- /** The deployed contract instance definition. */
42
- public readonly instance: ContractInstanceWithAddress,
41
+ /** The contract's address. */
42
+ public readonly address: AztecAddress,
43
43
  /** The Application Binary Interface for the contract. */
44
44
  public readonly artifact: ContractArtifact,
45
45
  /** The wallet used for interacting with this contract. */
@@ -47,7 +47,7 @@ export class ContractBase {
47
47
  ) {
48
48
  getAllFunctionAbis(artifact).forEach((f: FunctionAbi) => {
49
49
  const interactionFunction = (...args: any[]) => {
50
- return new ContractFunctionInteraction(this.wallet, this.instance.address, f, args);
50
+ return new ContractFunctionInteraction(this.wallet, this.address, f, args);
51
51
  };
52
52
 
53
53
  this.methods[f.name] = Object.assign(interactionFunction, {
@@ -62,22 +62,12 @@ export class ContractBase {
62
62
  });
63
63
  }
64
64
 
65
- /** Address of the contract. */
66
- public get address() {
67
- return this.instance.address;
68
- }
69
-
70
- /** Partial address of the contract. */
71
- public get partialAddress() {
72
- return computePartialAddress(this.instance);
73
- }
74
-
75
65
  /**
76
66
  * Creates a new instance of the contract wrapper attached to a different wallet.
77
67
  * @param wallet - Wallet to use for sending txs.
78
68
  * @returns A new contract instance.
79
69
  */
80
70
  public withWallet(wallet: Wallet): this {
81
- return new ContractBase(this.instance, this.artifact, wallet) as this;
71
+ return new ContractBase(this.address, this.artifact, wallet) as this;
82
72
  }
83
73
  }
@@ -1,8 +1,15 @@
1
- import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
2
- import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi, encodeArguments } from '@aztec/stdlib/abi';
1
+ import {
2
+ type FunctionAbi,
3
+ FunctionCall,
4
+ FunctionSelector,
5
+ FunctionType,
6
+ decodeFromAbi,
7
+ encodeArguments,
8
+ } from '@aztec/stdlib/abi';
3
9
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
4
10
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
11
  import { type Capsule, type HashedValues, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
12
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
6
13
 
7
14
  import type { Wallet } from '../wallet/wallet.js';
8
15
  import { BaseContractInteraction } from './base_contract_interaction.js';
@@ -43,16 +50,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
43
50
  */
44
51
  public async getFunctionCall() {
45
52
  const args = encodeArguments(this.functionDao, this.args);
46
- return {
53
+ return FunctionCall.from({
47
54
  name: this.functionDao.name,
48
- args,
55
+ to: this.contractAddress,
49
56
  selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
50
57
  type: this.functionDao.functionType,
51
- to: this.contractAddress,
52
- isStatic: this.functionDao.isStatic,
53
58
  hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
59
+ isStatic: this.functionDao.isStatic,
60
+ args,
54
61
  returnTypes: this.functionDao.returnTypes,
55
- };
62
+ });
56
63
  }
57
64
 
58
65
  /**
@@ -103,25 +110,27 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
103
110
  ): Promise<SimulationReturn<typeof options.includeMetadata>> {
104
111
  // docs:end:simulate
105
112
  if (this.functionDao.functionType == FunctionType.UTILITY) {
106
- const utilityResult = await this.wallet.simulateUtility(
107
- this.functionDao.name,
108
- this.args,
109
- this.contractAddress,
110
- options.authWitnesses ?? [],
111
- );
113
+ const call = await this.getFunctionCall();
114
+ const utilityResult = await this.wallet.executeUtility(call, {
115
+ scope: options.from,
116
+ authWitnesses: options.authWitnesses,
117
+ });
118
+
119
+ // Decode the raw field elements to the actual return type
120
+ const returnValue = utilityResult.result ? decodeFromAbi(this.functionDao.returnTypes, utilityResult.result) : [];
112
121
 
113
122
  if (options.includeMetadata) {
114
123
  return {
115
124
  stats: utilityResult.stats,
116
- result: utilityResult.result,
125
+ result: returnValue,
117
126
  };
118
127
  } else {
119
- return utilityResult.result;
128
+ return returnValue;
120
129
  }
121
130
  }
122
131
 
123
132
  const executionPayload = await this.request(options);
124
- const simulatedTx = await this.wallet.simulateTx(executionPayload, await toSimulateOptions(options));
133
+ const simulatedTx = await this.wallet.simulateTx(executionPayload, toSimulateOptions(options));
125
134
 
126
135
  let rawReturnValues;
127
136
  if (this.functionDao.functionType == FunctionType.PRIVATE) {
@@ -168,7 +177,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
168
177
  }
169
178
 
170
179
  const executionPayload = await this.request(options);
171
- return await this.wallet.profileTx(executionPayload, await toProfileOptions(options));
180
+ return await this.wallet.profileTx(executionPayload, toProfileOptions(options));
172
181
  }
173
182
 
174
183
  /**