@aztec-labs/aztec.js 6.0.0-nightly.20260829

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 (275) hide show
  1. package/README.md +44 -0
  2. package/dest/account/account.d.ts +44 -0
  3. package/dest/account/account.d.ts.map +1 -0
  4. package/dest/account/account.js +31 -0
  5. package/dest/account/account_contract.d.ts +49 -0
  6. package/dest/account/account_contract.d.ts.map +1 -0
  7. package/dest/account/account_contract.js +20 -0
  8. package/dest/account/index.d.ts +11 -0
  9. package/dest/account/index.d.ts.map +1 -0
  10. package/dest/account/index.js +6 -0
  11. package/dest/api/abi.d.ts +4 -0
  12. package/dest/api/abi.d.ts.map +1 -0
  13. package/dest/api/abi.js +1 -0
  14. package/dest/api/account.d.ts +5 -0
  15. package/dest/api/account.d.ts.map +1 -0
  16. package/dest/api/account.js +3 -0
  17. package/dest/api/addresses.d.ts +4 -0
  18. package/dest/api/addresses.d.ts.map +1 -0
  19. package/dest/api/addresses.js +3 -0
  20. package/dest/api/authorization.d.ts +5 -0
  21. package/dest/api/authorization.d.ts.map +1 -0
  22. package/dest/api/authorization.js +4 -0
  23. package/dest/api/block.d.ts +3 -0
  24. package/dest/api/block.d.ts.map +1 -0
  25. package/dest/api/block.js +2 -0
  26. package/dest/api/contract.d.ts +48 -0
  27. package/dest/api/contract.d.ts.map +1 -0
  28. package/dest/api/contract.js +46 -0
  29. package/dest/api/crypto.d.ts +2 -0
  30. package/dest/api/crypto.d.ts.map +1 -0
  31. package/dest/api/crypto.js +1 -0
  32. package/dest/api/deployment.d.ts +4 -0
  33. package/dest/api/deployment.d.ts.map +1 -0
  34. package/dest/api/deployment.js +3 -0
  35. package/dest/api/eth_address.d.ts +2 -0
  36. package/dest/api/eth_address.d.ts.map +1 -0
  37. package/dest/api/eth_address.js +1 -0
  38. package/dest/api/ethereum.d.ts +2 -0
  39. package/dest/api/ethereum.d.ts.map +1 -0
  40. package/dest/api/ethereum.js +1 -0
  41. package/dest/api/event_cursor.d.ts +44 -0
  42. package/dest/api/event_cursor.d.ts.map +1 -0
  43. package/dest/api/event_cursor.js +42 -0
  44. package/dest/api/events.d.ts +36 -0
  45. package/dest/api/events.d.ts.map +1 -0
  46. package/dest/api/events.js +59 -0
  47. package/dest/api/fee.d.ts +6 -0
  48. package/dest/api/fee.d.ts.map +1 -0
  49. package/dest/api/fee.js +4 -0
  50. package/dest/api/fee_testing.d.ts +2 -0
  51. package/dest/api/fee_testing.d.ts.map +1 -0
  52. package/dest/api/fee_testing.js +1 -0
  53. package/dest/api/fields.d.ts +4 -0
  54. package/dest/api/fields.d.ts.map +1 -0
  55. package/dest/api/fields.js +3 -0
  56. package/dest/api/keys.d.ts +4 -0
  57. package/dest/api/keys.d.ts.map +1 -0
  58. package/dest/api/keys.js +3 -0
  59. package/dest/api/log.d.ts +3 -0
  60. package/dest/api/log.d.ts.map +1 -0
  61. package/dest/api/log.js +2 -0
  62. package/dest/api/messaging.d.ts +3 -0
  63. package/dest/api/messaging.d.ts.map +1 -0
  64. package/dest/api/messaging.js +2 -0
  65. package/dest/api/node.d.ts +25 -0
  66. package/dest/api/node.d.ts.map +1 -0
  67. package/dest/api/node.js +22 -0
  68. package/dest/api/note.d.ts +2 -0
  69. package/dest/api/note.d.ts.map +1 -0
  70. package/dest/api/note.js +1 -0
  71. package/dest/api/protocol.d.ts +6 -0
  72. package/dest/api/protocol.d.ts.map +1 -0
  73. package/dest/api/protocol.js +5 -0
  74. package/dest/api/trees.d.ts +3 -0
  75. package/dest/api/trees.d.ts.map +1 -0
  76. package/dest/api/trees.js +2 -0
  77. package/dest/api/tx.d.ts +3 -0
  78. package/dest/api/tx.d.ts.map +1 -0
  79. package/dest/api/tx.js +1 -0
  80. package/dest/api/utils.d.ts +13 -0
  81. package/dest/api/utils.d.ts.map +1 -0
  82. package/dest/api/utils.js +12 -0
  83. package/dest/api/wallet.d.ts +8 -0
  84. package/dest/api/wallet.d.ts.map +1 -0
  85. package/dest/api/wallet.js +7 -0
  86. package/dest/authorization/call_authorization_request.d.ts +46 -0
  87. package/dest/authorization/call_authorization_request.d.ts.map +1 -0
  88. package/dest/authorization/call_authorization_request.js +72 -0
  89. package/dest/contract/base_contract_interaction.d.ts +32 -0
  90. package/dest/contract/base_contract_interaction.d.ts.map +1 -0
  91. package/dest/contract/base_contract_interaction.js +24 -0
  92. package/dest/contract/batch_call.d.ts +27 -0
  93. package/dest/contract/batch_call.d.ts.map +1 -0
  94. package/dest/contract/batch_call.js +152 -0
  95. package/dest/contract/checker.d.ts +11 -0
  96. package/dest/contract/checker.d.ts.map +1 -0
  97. package/dest/contract/checker.js +107 -0
  98. package/dest/contract/contract.d.ts +33 -0
  99. package/dest/contract/contract.d.ts.map +1 -0
  100. package/dest/contract/contract.js +36 -0
  101. package/dest/contract/contract_base.d.ts +51 -0
  102. package/dest/contract/contract_base.d.ts.map +1 -0
  103. package/dest/contract/contract_base.js +38 -0
  104. package/dest/contract/contract_function_interaction.d.ts +67 -0
  105. package/dest/contract/contract_function_interaction.d.ts.map +1 -0
  106. package/dest/contract/contract_function_interaction.js +218 -0
  107. package/dest/contract/deploy_method.d.ts +433 -0
  108. package/dest/contract/deploy_method.d.ts.map +1 -0
  109. package/dest/contract/deploy_method.js +471 -0
  110. package/dest/contract/fastforward_contract_update.d.ts +25 -0
  111. package/dest/contract/fastforward_contract_update.d.ts.map +1 -0
  112. package/dest/contract/fastforward_contract_update.js +57 -0
  113. package/dest/contract/interaction_options.d.ts +213 -0
  114. package/dest/contract/interaction_options.d.ts.map +1 -0
  115. package/dest/contract/interaction_options.js +87 -0
  116. package/dest/contract/protocol_contracts/contract-class-registry.d.ts +18 -0
  117. package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -0
  118. package/dest/contract/protocol_contracts/contract-class-registry.js +137 -0
  119. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +25 -0
  120. package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -0
  121. package/dest/contract/protocol_contracts/contract-instance-registry.js +366 -0
  122. package/dest/contract/protocol_contracts/fee-juice.d.ts +24 -0
  123. package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -0
  124. package/dest/contract/protocol_contracts/fee-juice.js +383 -0
  125. package/dest/contract/wait_for_proven.d.ts +18 -0
  126. package/dest/contract/wait_for_proven.d.ts.map +1 -0
  127. package/dest/contract/wait_for_proven.js +17 -0
  128. package/dest/contract/wait_opts.d.ts +21 -0
  129. package/dest/contract/wait_opts.d.ts.map +1 -0
  130. package/dest/contract/wait_opts.js +5 -0
  131. package/dest/deployment/contract_deployer.d.ts +28 -0
  132. package/dest/deployment/contract_deployer.d.ts.map +1 -0
  133. package/dest/deployment/contract_deployer.js +35 -0
  134. package/dest/deployment/publish_class.d.ts +6 -0
  135. package/dest/deployment/publish_class.d.ts.map +1 -0
  136. package/dest/deployment/publish_class.js +17 -0
  137. package/dest/deployment/publish_instance.d.ts +10 -0
  138. package/dest/deployment/publish_instance.d.ts.map +1 -0
  139. package/dest/deployment/publish_instance.js +11 -0
  140. package/dest/ethereum/portal_manager.d.ts +146 -0
  141. package/dest/ethereum/portal_manager.d.ts.map +1 -0
  142. package/dest/ethereum/portal_manager.js +415 -0
  143. package/dest/fee/fee_juice_payment_method_with_claim.d.ts +23 -0
  144. package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -0
  145. package/dest/fee/fee_juice_payment_method_with_claim.js +46 -0
  146. package/dest/fee/fee_payment_method.d.ts +26 -0
  147. package/dest/fee/fee_payment_method.d.ts.map +1 -0
  148. package/dest/fee/fee_payment_method.js +3 -0
  149. package/dest/fee/private_fee_payment_method.d.ts +69 -0
  150. package/dest/fee/private_fee_payment_method.d.ts.map +1 -0
  151. package/dest/fee/private_fee_payment_method.js +122 -0
  152. package/dest/fee/public_fee_payment_method.d.ts +59 -0
  153. package/dest/fee/public_fee_payment_method.d.ts.map +1 -0
  154. package/dest/fee/public_fee_payment_method.js +116 -0
  155. package/dest/fee/sponsored_fee_payment.d.ts +17 -0
  156. package/dest/fee/sponsored_fee_payment.d.ts.map +1 -0
  157. package/dest/fee/sponsored_fee_payment.js +33 -0
  158. package/dest/scripts/generate_protocol_contract_types.d.ts +2 -0
  159. package/dest/scripts/generate_protocol_contract_types.d.ts.map +1 -0
  160. package/dest/scripts/generate_protocol_contract_types.js +128 -0
  161. package/dest/test/fixtures.d.ts +13 -0
  162. package/dest/test/fixtures.d.ts.map +1 -0
  163. package/dest/test/fixtures.js +185 -0
  164. package/dest/utils/abi_types.d.ts +32 -0
  165. package/dest/utils/abi_types.d.ts.map +1 -0
  166. package/dest/utils/abi_types.js +1 -0
  167. package/dest/utils/authwit.d.ts +119 -0
  168. package/dest/utils/authwit.d.ts.map +1 -0
  169. package/dest/utils/authwit.js +266 -0
  170. package/dest/utils/cross_chain.d.ts +28 -0
  171. package/dest/utils/cross_chain.d.ts.map +1 -0
  172. package/dest/utils/cross_chain.js +26 -0
  173. package/dest/utils/fee_juice.d.ts +8 -0
  174. package/dest/utils/fee_juice.d.ts.map +1 -0
  175. package/dest/utils/fee_juice.js +10 -0
  176. package/dest/utils/field_compressed_string.d.ts +17 -0
  177. package/dest/utils/field_compressed_string.d.ts.map +1 -0
  178. package/dest/utils/field_compressed_string.js +15 -0
  179. package/dest/utils/node.d.ts +24 -0
  180. package/dest/utils/node.d.ts.map +1 -0
  181. package/dest/utils/node.js +80 -0
  182. package/dest/utils/pub_key.d.ts +9 -0
  183. package/dest/utils/pub_key.d.ts.map +1 -0
  184. package/dest/utils/pub_key.js +8 -0
  185. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +33 -0
  186. package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -0
  187. package/dest/wallet/account_entrypoint_meta_payment_method.js +63 -0
  188. package/dest/wallet/account_manager.d.ts +73 -0
  189. package/dest/wallet/account_manager.d.ts.map +1 -0
  190. package/dest/wallet/account_manager.js +102 -0
  191. package/dest/wallet/capabilities.d.ts +456 -0
  192. package/dest/wallet/capabilities.d.ts.map +1 -0
  193. package/dest/wallet/capabilities.js +3 -0
  194. package/dest/wallet/deploy_account_method.d.ts +97 -0
  195. package/dest/wallet/deploy_account_method.d.ts.map +1 -0
  196. package/dest/wallet/deploy_account_method.js +127 -0
  197. package/dest/wallet/index.d.ts +5 -0
  198. package/dest/wallet/index.d.ts.map +1 -0
  199. package/dest/wallet/index.js +4 -0
  200. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts +40 -0
  201. package/dest/wallet/tx_simulation_result_with_app_offset.d.ts.map +1 -0
  202. package/dest/wallet/tx_simulation_result_with_app_offset.js +65 -0
  203. package/dest/wallet/wallet.d.ts +1451 -0
  204. package/dest/wallet/wallet.d.ts.map +1 -0
  205. package/dest/wallet/wallet.js +430 -0
  206. package/package.json +138 -0
  207. package/src/account/account.ts +72 -0
  208. package/src/account/account_contract.ts +80 -0
  209. package/src/account/index.ts +12 -0
  210. package/src/api/README.md +7 -0
  211. package/src/api/abi.ts +42 -0
  212. package/src/api/account.ts +12 -0
  213. package/src/api/addresses.ts +3 -0
  214. package/src/api/authorization.ts +15 -0
  215. package/src/api/block.ts +2 -0
  216. package/src/api/contract.ts +86 -0
  217. package/src/api/crypto.ts +1 -0
  218. package/src/api/deployment.ts +3 -0
  219. package/src/api/eth_address.ts +1 -0
  220. package/src/api/ethereum.ts +10 -0
  221. package/src/api/event_cursor.ts +60 -0
  222. package/src/api/events.ts +79 -0
  223. package/src/api/fee.ts +5 -0
  224. package/src/api/fee_testing.ts +1 -0
  225. package/src/api/fields.ts +3 -0
  226. package/src/api/keys.ts +8 -0
  227. package/src/api/log.ts +2 -0
  228. package/src/api/messaging.ts +2 -0
  229. package/src/api/node.ts +30 -0
  230. package/src/api/note.ts +1 -0
  231. package/src/api/protocol.ts +6 -0
  232. package/src/api/trees.ts +2 -0
  233. package/src/api/tx.ts +20 -0
  234. package/src/api/utils.ts +14 -0
  235. package/src/api/wallet.ts +83 -0
  236. package/src/authorization/call_authorization_request.ts +93 -0
  237. package/src/contract/base_contract_interaction.ts +62 -0
  238. package/src/contract/batch_call.ts +188 -0
  239. package/src/contract/checker.ts +122 -0
  240. package/src/contract/contract.ts +52 -0
  241. package/src/contract/contract_base.ts +73 -0
  242. package/src/contract/contract_function_interaction.ts +297 -0
  243. package/src/contract/deploy_method.ts +877 -0
  244. package/src/contract/fastforward_contract_update.ts +71 -0
  245. package/src/contract/interaction_options.ts +301 -0
  246. package/src/contract/protocol_contracts/contract-class-registry.ts +104 -0
  247. package/src/contract/protocol_contracts/contract-instance-registry.ts +241 -0
  248. package/src/contract/protocol_contracts/fee-juice.ts +257 -0
  249. package/src/contract/wait_for_proven.ts +43 -0
  250. package/src/contract/wait_opts.ts +26 -0
  251. package/src/deployment/contract_deployer.ts +40 -0
  252. package/src/deployment/publish_class.ts +34 -0
  253. package/src/deployment/publish_instance.ts +24 -0
  254. package/src/ethereum/portal_manager.ts +539 -0
  255. package/src/fee/fee_juice_payment_method_with_claim.ts +63 -0
  256. package/src/fee/fee_payment_method.ts +26 -0
  257. package/src/fee/private_fee_payment_method.ts +145 -0
  258. package/src/fee/public_fee_payment_method.ts +145 -0
  259. package/src/fee/sponsored_fee_payment.ts +45 -0
  260. package/src/scripts/generate_protocol_contract_types.ts +160 -0
  261. package/src/test/fixtures.ts +126 -0
  262. package/src/utils/abi_types.ts +32 -0
  263. package/src/utils/authwit.ts +327 -0
  264. package/src/utils/cross_chain.ts +55 -0
  265. package/src/utils/fee_juice.ts +14 -0
  266. package/src/utils/field_compressed_string.ts +27 -0
  267. package/src/utils/node.ts +110 -0
  268. package/src/utils/pub_key.ts +12 -0
  269. package/src/wallet/account_entrypoint_meta_payment_method.ts +76 -0
  270. package/src/wallet/account_manager.ts +164 -0
  271. package/src/wallet/capabilities.ts +505 -0
  272. package/src/wallet/deploy_account_method.ts +234 -0
  273. package/src/wallet/index.ts +4 -0
  274. package/src/wallet/tx_simulation_result_with_app_offset.ts +100 -0
  275. package/src/wallet/wallet.ts +668 -0
@@ -0,0 +1,218 @@
1
+ import { FunctionCall, FunctionSelector, FunctionType, canBeMappedFromNullOrUndefined, decodeFromAbi, encodeArguments, getFunctionReturnType, isOptionStruct } from '@aztec-labs/stdlib/abi';
2
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec-labs/stdlib/tx';
3
+ import { BaseContractInteraction } from './base_contract_interaction.js';
4
+ import { NO_FROM, extractOffchainOutput, toProfileOptions, toSimulateOptions } from './interaction_options.js';
5
+ /**
6
+ * This is the class that is returned when calling e.g. `contract.methods.myMethod(arg0, arg1)`.
7
+ * It contains available interactions one can call on a method, including view.
8
+ */ export class ContractFunctionInteraction extends BaseContractInteraction {
9
+ contractAddress;
10
+ functionDao;
11
+ args;
12
+ extraHashedArgs;
13
+ constructor(wallet, contractAddress, functionDao, args, authWitnesses = [], capsules = [], extraHashedArgs = []){
14
+ super(wallet, authWitnesses, capsules), this.contractAddress = contractAddress, this.functionDao = functionDao, this.args = args, this.extraHashedArgs = extraHashedArgs;
15
+ // This may feel a bit ad-hoc here, so it warrants a comment. We accept Noir Option<T> parameters, and it's natural
16
+ // to map JS's null/undefined to Noir Option's None. One possible way to deal with null/undefined arguments at this
17
+ // point in the codebase is to conclude that they are accepted since at least one Noir type (ie: Option) can be
18
+ // encoded from them. Then we would let `encode` deal with potential mismatches. I chose not to do that because of
19
+ // the pervasiveness of null/undefined in JS, and how easy it is to inadvertently pass it around. Having this check
20
+ // here allows us to fail at a point where the boundaries and intent are clear.
21
+ if (this.hasInvalidNullOrUndefinedArguments(args)) {
22
+ const signature = formatFunctionSignature(this.functionDao.name, this.functionDao.parameters);
23
+ const received = args.map(formatArg).join(', ');
24
+ throw new Error(`Null or undefined arguments are only allowed for Option<T> parameters in ${signature}. Received: (${received}).`);
25
+ }
26
+ }
27
+ hasInvalidNullOrUndefinedArguments(args) {
28
+ return args.some((arg, index)=>{
29
+ if (arg !== undefined && arg !== null) {
30
+ return false;
31
+ }
32
+ const parameterType = this.functionDao.parameters[index]?.type;
33
+ return !parameterType || !canBeMappedFromNullOrUndefined(parameterType);
34
+ });
35
+ }
36
+ /**
37
+ * Returns the encoded function call wrapped by this interaction
38
+ * Useful when generating authwits
39
+ * @returns An encoded function call
40
+ */ async getFunctionCall() {
41
+ const args = encodeArguments(this.functionDao, this.args);
42
+ return FunctionCall.from({
43
+ name: this.functionDao.name,
44
+ to: this.contractAddress,
45
+ selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
46
+ type: this.functionDao.functionType,
47
+ hideMsgSender: false,
48
+ isStatic: this.functionDao.isStatic,
49
+ args,
50
+ returnType: getFunctionReturnType(this.functionDao)
51
+ });
52
+ }
53
+ /**
54
+ * Returns the execution payload that allows this operation to happen on chain.
55
+ * @param options - Configuration options.
56
+ * @returns The execution payload for this operation
57
+ */ async request(options = {}) {
58
+ const calls = [
59
+ await this.getFunctionCall()
60
+ ];
61
+ const { authWitnesses, capsules } = options;
62
+ const feeExecutionPayload = options.fee?.paymentMethod ? await options.fee.paymentMethod.getExecutionPayload() : undefined;
63
+ const functionExecutionPayload = new ExecutionPayload(calls, this.authWitnesses.concat(authWitnesses ?? []), this.capsules.concat(capsules ?? []), this.extraHashedArgs);
64
+ const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
65
+ feeExecutionPayload,
66
+ functionExecutionPayload
67
+ ]) : functionExecutionPayload;
68
+ return finalExecutionPayload;
69
+ }
70
+ // docs:start:simulate
71
+ /**
72
+ * Simulate a transaction and get information from its execution.
73
+ * Differs from prove in a few important ways:
74
+ * 1. It returns the values of the function execution, plus additional metadata if requested
75
+ * 2. It supports `utility`, `private` and `public` functions
76
+ *
77
+ * @param options - An optional object containing additional configuration for the simulation.
78
+ * @returns Depending on the simulation options, this method directly returns the result value of the executed
79
+ * function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
80
+ * execution statistics and emitted offchain effects
81
+ */ async simulate(options = {}) {
82
+ // docs:end:simulate
83
+ if (this.functionDao.functionType == FunctionType.UTILITY) {
84
+ if (options.overrides?.publicStorage?.length || options.overrides?.contracts) {
85
+ throw new Error('overrides are not supported for utility function simulation.');
86
+ }
87
+ const call = await this.getFunctionCall();
88
+ const scopes = [
89
+ ...options.additionalScopes ?? []
90
+ ];
91
+ const utilityResult = await this.wallet.executeUtility(call, {
92
+ scopes: options.from === NO_FROM ? scopes : [
93
+ options.from,
94
+ ...scopes
95
+ ],
96
+ authWitnesses: options.authWitnesses
97
+ });
98
+ // Decode the raw field elements to the actual return type
99
+ const returnValue = utilityResult.result ? decodeFromAbi(getFunctionReturnType(this.functionDao), utilityResult.result) : undefined;
100
+ const offchainOutput = extractOffchainOutput(utilityResult.offchainEffects, utilityResult.anchorBlockTimestamp);
101
+ if (options.includeMetadata) {
102
+ return {
103
+ stats: utilityResult.stats,
104
+ ...offchainOutput,
105
+ result: returnValue
106
+ };
107
+ }
108
+ return {
109
+ result: returnValue,
110
+ ...offchainOutput
111
+ };
112
+ }
113
+ const executionPayload = await this.request(options);
114
+ const simulatedTx = await this.wallet.simulateTx(executionPayload, toSimulateOptions(options));
115
+ let rawReturnValues;
116
+ if (this.functionDao.functionType == FunctionType.PRIVATE) {
117
+ // request() prepends the fee payment method's calls (if any) before this interaction's single call, so the app
118
+ // call is the last call of its type in the payload. Its position among the private return values is the number
119
+ // of private calls that precede it.
120
+ const appCallIndex = executionPayload.calls.filter((c)=>c.type === FunctionType.PRIVATE).length - 1;
121
+ rawReturnValues = simulatedTx.getPrivateReturnValuesOfAppCall(appCallIndex)?.values;
122
+ } else {
123
+ // For public functions we retrieve the values directly from the public output, offset by any public fee calls
124
+ // that request() prepended ahead of the app call.
125
+ const appCallIndex = executionPayload.calls.filter((c)=>c.type === FunctionType.PUBLIC).length - 1;
126
+ rawReturnValues = simulatedTx.getPublicReturnValues()?.[appCallIndex]?.values;
127
+ }
128
+ const returnValue = rawReturnValues ? decodeFromAbi(getFunctionReturnType(this.functionDao), rawReturnValues) : undefined;
129
+ const offchainOutput = extractOffchainOutput(simulatedTx.offchainEffects, simulatedTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp);
130
+ if (options.includeMetadata) {
131
+ return {
132
+ stats: simulatedTx.stats,
133
+ ...offchainOutput,
134
+ result: returnValue,
135
+ gasUsed: simulatedTx.gasUsed
136
+ };
137
+ }
138
+ return {
139
+ result: returnValue,
140
+ ...offchainOutput
141
+ };
142
+ }
143
+ /**
144
+ * Simulate a transaction and profile the gate count for each function in the transaction.
145
+ * @param options - Same options as `simulate`, plus profiling method
146
+ *
147
+ * @returns An object containing the function return value and profile result.
148
+ */ async profile(options) {
149
+ if (this.functionDao.functionType == FunctionType.UTILITY) {
150
+ throw new Error("Can't profile a utility function.");
151
+ }
152
+ const executionPayload = await this.request(options);
153
+ return await this.wallet.profileTx(executionPayload, toProfileOptions(options));
154
+ }
155
+ /**
156
+ * Augments this ContractFunctionInteraction with additional metadata, such as authWitnesses, capsules, and extraHashedArgs.
157
+ * This is useful when creating a "batteries included" interaction, such as registering a contract class with its associated
158
+ * capsule instead of having the user provide them externally.
159
+ * @param options - An object containing the metadata to add to the interaction
160
+ * @returns A new ContractFunctionInteraction with the added metadata, but calling the same original function in the same manner
161
+ */ with({ authWitnesses = [], capsules = [], extraHashedArgs = [] }) {
162
+ return new ContractFunctionInteraction(this.wallet, this.contractAddress, this.functionDao, this.args, this.authWitnesses.concat(authWitnesses), this.capsules.concat(capsules), this.extraHashedArgs.concat(extraHashedArgs));
163
+ }
164
+ }
165
+ /**
166
+ * Render an AbiType as a human readable string
167
+ * */ function formatAbiType(abiType) {
168
+ switch(abiType.kind){
169
+ case 'field':
170
+ return 'Field';
171
+ case 'boolean':
172
+ return 'bool';
173
+ case 'integer':
174
+ return `${abiType.sign === 'signed' ? 'i' : 'u'}${abiType.width}`;
175
+ case 'string':
176
+ return `str<${abiType.length}>`;
177
+ case 'array':
178
+ return `[${formatAbiType(abiType.type)}; ${abiType.length}]`;
179
+ case 'struct':
180
+ {
181
+ if (isOptionStruct(abiType)) {
182
+ const innerType = abiType.fields.find((f)=>f.name === '_value').type;
183
+ return `Option<${formatAbiType(innerType)}>`;
184
+ }
185
+ return `(${abiType.fields.map((f)=>`${f.name}: ${formatAbiType(f.type)}`).join(', ')})`;
186
+ }
187
+ case 'tuple':
188
+ return `(${abiType.fields.map(formatAbiType).join(', ')})`;
189
+ }
190
+ }
191
+ /**
192
+ * Pretty print a function signature
193
+ */ function formatFunctionSignature(name, parameters) {
194
+ const params = parameters.map((p)=>`${p.name}: ${formatAbiType(p.type)}`).join(', ');
195
+ return `${name}(${params})`;
196
+ }
197
+ /**
198
+ * Non-exhaustive pretty print of JS args to display in error messages in this module
199
+ */ function formatArg(arg) {
200
+ if (arg === undefined) {
201
+ return 'undefined';
202
+ }
203
+ if (arg === null) {
204
+ return 'null';
205
+ }
206
+ if (typeof arg === 'bigint') {
207
+ return `${arg}n`;
208
+ }
209
+ if (Array.isArray(arg)) {
210
+ return `[${arg.map(formatArg).join(', ')}]`;
211
+ }
212
+ if (typeof arg === 'object') {
213
+ const entries = Object.entries(arg).map(([k, v])=>`${k}: ${formatArg(v)}`);
214
+ return `{ ${entries.join(', ')} }`;
215
+ }
216
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
217
+ return String(arg);
218
+ }