@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,145 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import {
3
+ type FunctionAbi,
4
+ FunctionCall,
5
+ FunctionSelector,
6
+ FunctionType,
7
+ decodeFromAbi,
8
+ getFunctionReturnType,
9
+ } from '@aztec-labs/stdlib/abi';
10
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
11
+ import type { GasSettings } from '@aztec-labs/stdlib/gas';
12
+ import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
13
+
14
+ import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
15
+ import { NO_FROM } from '../contract/interaction_options.js';
16
+ import type { Wallet } from '../wallet/wallet.js';
17
+ import type { FeePaymentMethod } from './fee_payment_method.js';
18
+
19
+ /**
20
+ * Holds information about how the fee for a transaction is to be paid.
21
+ * @deprecated Is not supported on mainnet. Use {@link FeeJuicePaymentMethodWithClaim} or `SponsoredFeePaymentMethod` instead.
22
+ */
23
+ export class PrivateFeePaymentMethod implements FeePaymentMethod {
24
+ private assetPromise: Promise<AztecAddress> | null = null;
25
+
26
+ constructor(
27
+ /**
28
+ * Address which will hold the fee payment.
29
+ */
30
+ private paymentContract: AztecAddress,
31
+
32
+ /**
33
+ * Address of the account that will pay the fee
34
+ */
35
+ private sender: AztecAddress,
36
+
37
+ /**
38
+ * A wallet to perform the simulation to get the accepted asset
39
+ */
40
+ private wallet: Wallet,
41
+ /**
42
+ * Gas settings used to compute the maximum fee the user is willing to pay
43
+ */
44
+ protected gasSettings: GasSettings,
45
+ /**
46
+ * If true, the max fee will be set to 1.
47
+ * TODO(#7694): Remove this param once the lacking feature in TXE is implemented.
48
+ */
49
+ private setMaxFeeToOne = false,
50
+ ) {}
51
+
52
+ /**
53
+ * The asset used to pay the fee.
54
+ * @returns The asset used to pay the fee.
55
+ */
56
+ async getAsset(): Promise<AztecAddress> {
57
+ if (!this.assetPromise) {
58
+ const abi = {
59
+ name: 'get_accepted_asset',
60
+ functionType: FunctionType.PRIVATE,
61
+ isOnlySelf: false,
62
+ isStatic: false,
63
+ parameters: [],
64
+ returnType: {
65
+ kind: 'struct',
66
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
67
+ fields: [
68
+ {
69
+ name: 'inner',
70
+ type: {
71
+ kind: 'field',
72
+ },
73
+ },
74
+ ],
75
+ },
76
+ errorTypes: {},
77
+ isInitializer: false,
78
+ } as FunctionAbi;
79
+ const interaction = new ContractFunctionInteraction(this.wallet, this.paymentContract, abi, []);
80
+
81
+ const executionPayload = await interaction.request();
82
+ this.assetPromise = this.wallet
83
+ .simulateTx(executionPayload, {
84
+ from: NO_FROM,
85
+ skipFeeEnforcement: true,
86
+ })
87
+ .then(simulationResult => {
88
+ const rawReturnValues = simulationResult.getPrivateReturnValues().values;
89
+ return decodeFromAbi(getFunctionReturnType(abi), rawReturnValues!);
90
+ }) as Promise<AztecAddress>;
91
+ }
92
+ return this.assetPromise!;
93
+ }
94
+
95
+ getFeePayer(): Promise<AztecAddress> {
96
+ return Promise.resolve(this.paymentContract);
97
+ }
98
+
99
+ /**
100
+ * Creates an execution payload to pay the fee using a private function through an FPC in the desired asset
101
+ * @param gasSettings - The gas settings.
102
+ * @returns An execution payload that contains the required function calls and auth witnesses.
103
+ */
104
+ async getExecutionPayload(): Promise<ExecutionPayload> {
105
+ // We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit
106
+ // (maxFee) to be in token denomination.
107
+ const maxFee = this.setMaxFeeToOne ? Fr.ONE : this.gasSettings.getFeeLimit();
108
+ const txNonce = Fr.random();
109
+
110
+ const witness = await this.wallet.createAuthWit(this.sender, {
111
+ caller: this.paymentContract,
112
+ call: FunctionCall.from({
113
+ name: 'transfer_to_public',
114
+ to: await this.getAsset(),
115
+ selector: await FunctionSelector.fromSignature('transfer_to_public((Field),(Field),u128,Field)'),
116
+ type: FunctionType.PRIVATE,
117
+ hideMsgSender: false,
118
+ isStatic: false,
119
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
120
+ }),
121
+ });
122
+
123
+ return new ExecutionPayload(
124
+ [
125
+ FunctionCall.from({
126
+ name: 'fee_entrypoint_private',
127
+ to: this.paymentContract,
128
+ selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
129
+ type: FunctionType.PRIVATE,
130
+ hideMsgSender: false,
131
+ isStatic: false,
132
+ args: [maxFee, txNonce],
133
+ }),
134
+ ],
135
+ [witness],
136
+ [],
137
+ [],
138
+ this.paymentContract, // feePayer
139
+ );
140
+ }
141
+
142
+ getGasSettings(): GasSettings | undefined {
143
+ return this.gasSettings;
144
+ }
145
+ }
@@ -0,0 +1,145 @@
1
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import {
3
+ type FunctionAbi,
4
+ FunctionCall,
5
+ FunctionSelector,
6
+ FunctionType,
7
+ decodeFromAbi,
8
+ getFunctionReturnType,
9
+ } from '@aztec-labs/stdlib/abi';
10
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
11
+ import { GasSettings } from '@aztec-labs/stdlib/gas';
12
+ import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
13
+
14
+ import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
15
+ import { NO_FROM } from '../contract/interaction_options.js';
16
+ import { SetPublicAuthwitContractInteraction } from '../utils/authwit.js';
17
+ import type { Wallet } from '../wallet/wallet.js';
18
+ import type { FeePaymentMethod } from './fee_payment_method.js';
19
+
20
+ /**
21
+ * Holds information about how the fee for a transaction is to be paid.
22
+ * @deprecated Is not supported on mainnet. Use {@link FeeJuicePaymentMethodWithClaim} or `SponsoredFeePaymentMethod` instead.
23
+ */
24
+ export class PublicFeePaymentMethod implements FeePaymentMethod {
25
+ private assetPromise: Promise<AztecAddress> | null = null;
26
+
27
+ constructor(
28
+ /**
29
+ * Address which will hold the fee payment.
30
+ */
31
+ protected paymentContract: AztecAddress,
32
+ /**
33
+ * An auth witness provider to authorize fee payments
34
+ */
35
+ protected sender: AztecAddress,
36
+ /**
37
+ * A wallet to perform the simulation to get the accepted asset
38
+ */
39
+ protected wallet: Wallet,
40
+ /**
41
+ * Gas settings used to compute the maximum fee the user is willing to pay
42
+ */
43
+ protected gasSettings: GasSettings,
44
+ ) {}
45
+
46
+ /**
47
+ * The asset used to pay the fee.
48
+ * @returns The asset used to pay the fee.
49
+ */
50
+ async getAsset(): Promise<AztecAddress> {
51
+ if (!this.assetPromise) {
52
+ const abi = {
53
+ name: 'get_accepted_asset',
54
+ functionType: FunctionType.PRIVATE,
55
+ isOnlySelf: false,
56
+ isStatic: false,
57
+ parameters: [],
58
+ returnType: {
59
+ kind: 'struct',
60
+ path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress',
61
+ fields: [
62
+ {
63
+ name: 'inner',
64
+ type: {
65
+ kind: 'field',
66
+ },
67
+ },
68
+ ],
69
+ },
70
+ errorTypes: {},
71
+ isInitializer: false,
72
+ } as FunctionAbi;
73
+ const interaction = new ContractFunctionInteraction(this.wallet, this.paymentContract, abi, []);
74
+
75
+ const executionPayload = await interaction.request();
76
+ this.assetPromise = this.wallet
77
+ .simulateTx(executionPayload, {
78
+ from: NO_FROM,
79
+ skipFeeEnforcement: true,
80
+ })
81
+ .then(simulationResult => {
82
+ const rawReturnValues = simulationResult.getPrivateReturnValues().values;
83
+ return decodeFromAbi(getFunctionReturnType(abi), rawReturnValues!);
84
+ }) as Promise<AztecAddress>;
85
+ }
86
+ return this.assetPromise!;
87
+ }
88
+
89
+ getFeePayer(): Promise<AztecAddress> {
90
+ return Promise.resolve(this.paymentContract);
91
+ }
92
+
93
+ /**
94
+ * Creates an execution payload to pay the fee using a public function through an FPC in the desired asset
95
+ * @param gasSettings - The gas settings.
96
+ * @returns An execution payload that contains the required function calls.
97
+ */
98
+ async getExecutionPayload(): Promise<ExecutionPayload> {
99
+ const txNonce = Fr.random();
100
+ const maxFee = this.gasSettings.getFeeLimit();
101
+
102
+ const intent = {
103
+ caller: this.paymentContract,
104
+ call: FunctionCall.from({
105
+ name: 'transfer_in_public',
106
+ to: await this.getAsset(),
107
+ selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),u128,Field)'),
108
+ type: FunctionType.PUBLIC,
109
+ hideMsgSender: false /** The target function performs an authwit check, so msg_sender is needed */,
110
+ isStatic: false,
111
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
112
+ }),
113
+ };
114
+
115
+ const setPublicAuthWitInteraction = await SetPublicAuthwitContractInteraction.create(
116
+ this.wallet,
117
+ this.sender,
118
+ intent,
119
+ true,
120
+ );
121
+
122
+ return new ExecutionPayload(
123
+ [
124
+ ...(await setPublicAuthWitInteraction.request()).calls,
125
+ FunctionCall.from({
126
+ name: 'fee_entrypoint_public',
127
+ to: this.paymentContract,
128
+ selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
129
+ type: FunctionType.PRIVATE,
130
+ hideMsgSender: false,
131
+ isStatic: false,
132
+ args: [maxFee, txNonce],
133
+ }),
134
+ ],
135
+ [],
136
+ [],
137
+ [],
138
+ this.paymentContract, // feePayer
139
+ );
140
+ }
141
+
142
+ getGasSettings(): GasSettings | undefined {
143
+ return this.gasSettings;
144
+ }
145
+ }
@@ -0,0 +1,45 @@
1
+ import type { FeePaymentMethod } from '@aztec-labs/aztec.js/fee';
2
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec-labs/stdlib/abi';
3
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
4
+ import type { GasSettings } from '@aztec-labs/stdlib/gas';
5
+ import { ExecutionPayload } from '@aztec-labs/stdlib/tx';
6
+
7
+ /**
8
+ * A fee payment method that uses a contract that blindly sponsors transactions.
9
+ * This contract is expected to be prefunded in testing environments.
10
+ */
11
+ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
12
+ constructor(private paymentContract: AztecAddress) {}
13
+
14
+ getAsset(): Promise<AztecAddress> {
15
+ throw new Error('Asset is not required for sponsored fpc.');
16
+ }
17
+
18
+ getFeePayer(): Promise<AztecAddress> {
19
+ return Promise.resolve(this.paymentContract);
20
+ }
21
+
22
+ async getExecutionPayload(): Promise<ExecutionPayload> {
23
+ return new ExecutionPayload(
24
+ [
25
+ FunctionCall.from({
26
+ name: 'sponsor_unconditionally',
27
+ to: this.paymentContract,
28
+ selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
29
+ type: FunctionType.PRIVATE,
30
+ hideMsgSender: false,
31
+ isStatic: false,
32
+ args: [],
33
+ }),
34
+ ],
35
+ [],
36
+ [],
37
+ [],
38
+ this.paymentContract, // feePayer
39
+ );
40
+ }
41
+
42
+ getGasSettings(): GasSettings | undefined {
43
+ return;
44
+ }
45
+ }
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Generates type-safe contract wrappers for protocol contracts.
3
+ * These wrappers use a minimal artifact (without bytecode) since PXE already has the full artifacts registered.
4
+ */
5
+ import { generateTypescriptContractInterface } from '@aztec-labs/builder/codegen';
6
+ import { fileURLToPath } from '@aztec-labs/foundation/url';
7
+ import {
8
+ type ContractArtifact,
9
+ type FunctionAbi,
10
+ FunctionType,
11
+ getAllFunctionAbis,
12
+ getFunctionReturnType,
13
+ loadContractArtifact,
14
+ } from '@aztec-labs/stdlib/abi';
15
+ import type { NoirCompiledContract } from '@aztec-labs/stdlib/noir';
16
+ import { promises as fs } from 'fs';
17
+ import path from 'path';
18
+
19
+ const log = console.log;
20
+
21
+ const artifactsPkgRoot = path.dirname(
22
+ fileURLToPath(import.meta.resolve('@aztec/protocol-contracts-artifacts/package.json')),
23
+ );
24
+ const srcPath = path.join(artifactsPkgRoot, 'artifacts');
25
+ const outputDir = path.join(import.meta.dirname, '../contract/protocol_contracts');
26
+
27
+ function toKebabCase(str: string): string {
28
+ return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
29
+ }
30
+
31
+ function functionTypeToEnum(type: FunctionType): string {
32
+ switch (type) {
33
+ case FunctionType.PRIVATE:
34
+ return 'FunctionType.PRIVATE';
35
+ case FunctionType.PUBLIC:
36
+ return 'FunctionType.PUBLIC';
37
+ case FunctionType.UTILITY:
38
+ return 'FunctionType.UTILITY';
39
+ }
40
+ }
41
+
42
+ function generateFunctionAbiJson(abi: FunctionAbi): string {
43
+ const baseObj = {
44
+ name: abi.name,
45
+ isOnlySelf: abi.isOnlySelf,
46
+ isStatic: abi.isStatic,
47
+ isInitializer: abi.isInitializer,
48
+ parameters: abi.parameters,
49
+ returnType: getFunctionReturnType(abi),
50
+ errorTypes: abi.errorTypes,
51
+ };
52
+ const jsonStr = JSON.stringify(baseObj);
53
+ return jsonStr.replace('{', `{ functionType: ${functionTypeToEnum(abi.functionType)},`);
54
+ }
55
+
56
+ function generateProtocolContractArtifact(input: ContractArtifact): string {
57
+ const allAbis = getAllFunctionAbis(input);
58
+ const functionAbis = input.functions.map(f => allAbis.find(abi => abi.name === f.name)!);
59
+ const nonDispatchAbis = input.nonDispatchPublicFunctions;
60
+
61
+ const functionsArray = functionAbis
62
+ .map(abi => `{ ...${generateFunctionAbiJson(abi)}, bytecode: Buffer.from([]), debugSymbols: '' }`)
63
+ .join(',\n ');
64
+
65
+ const nonDispatchArray = nonDispatchAbis.map(abi => generateFunctionAbiJson(abi)).join(',\n ');
66
+
67
+ return `{
68
+ name: '${input.name}',
69
+ aztecVersion: '${input.aztecVersion}',
70
+ functions: [
71
+ ${functionsArray}
72
+ ],
73
+ nonDispatchPublicFunctions: [
74
+ ${nonDispatchArray}
75
+ ],
76
+ outputs: { structs: {}, globals: {} },
77
+ storageLayout: {},
78
+ fileMap: {},
79
+ }`;
80
+ }
81
+
82
+ async function generateProtocolContractInterface(
83
+ input: ContractArtifact,
84
+ protocolContractName: string,
85
+ ): Promise<string> {
86
+ const baseInterface = await generateTypescriptContractInterface(input);
87
+
88
+ // Match everything between "public declare methods: {" and the closing "};"
89
+ const methodsMatch = baseInterface.match(/public declare methods: \{([\s\S]*?)\n \};/);
90
+ if (!methodsMatch) {
91
+ throw new Error('Could not extract methods from generated interface');
92
+ }
93
+
94
+ const artifactCode = generateProtocolContractArtifact(input);
95
+ const contractName = `${input.name}Contract`;
96
+
97
+ return `
98
+ /* Autogenerated file, do not edit! */
99
+
100
+ /* eslint-disable */
101
+ import { ProtocolContractAddress } from '@aztec-labs/protocol-contracts';
102
+ import { FunctionType } from '@aztec-labs/stdlib/abi';
103
+
104
+ import type { ContractArtifact } from '../../api/abi.js';
105
+ import { PublicKeys } from '../../api/keys.js';
106
+ import type { AztecAddressLike, EthAddressLike, FieldLike, FunctionSelectorLike, OptionLike, WrappedFieldLike } from '../../utils/abi_types.js';
107
+ import { ContractBase, type ContractMethod } from '../contract_base.js';
108
+ import { ContractFunctionInteraction } from '../contract_function_interaction.js';
109
+ import type { Wallet } from '../../wallet/wallet.js';
110
+
111
+ const ${contractName}Artifact: ContractArtifact = ${artifactCode};
112
+
113
+ export class ${contractName} extends ContractBase {
114
+ private constructor(wallet: Wallet) {
115
+ super(ProtocolContractAddress.${protocolContractName}, ${contractName}Artifact, wallet);
116
+ }
117
+
118
+ /** Returns an interface to the canonical ${contractName} instance, bound to the given wallet. */
119
+ public static withWallet(wallet: Wallet): ${contractName} {
120
+ return new ${contractName}(wallet);
121
+ }
122
+
123
+ /** @deprecated Use \`withWallet\` instead. */
124
+ public static at(wallet: Wallet): ${contractName} {
125
+ return ${contractName}.withWallet(wallet);
126
+ }
127
+
128
+ public declare methods: {${methodsMatch[1]}
129
+ };
130
+ }
131
+ `;
132
+ }
133
+
134
+ async function main() {
135
+ await fs.rm(outputDir, { recursive: true, force: true });
136
+ await fs.mkdir(outputDir, { recursive: true });
137
+
138
+ const srcNames = JSON.parse(
139
+ await fs.readFile(path.join(artifactsPkgRoot, 'protocol_contracts.json'), 'utf8'),
140
+ ) as string[];
141
+
142
+ for (const srcName of srcNames) {
143
+ // srcName is like "auth_registry_contract-AuthRegistry", split to get the contract name
144
+ const name = srcName.split('-')[1];
145
+ const artifactPath = path.join(srcPath, `${srcName}.json`);
146
+ const json = JSON.parse(await fs.readFile(artifactPath, 'utf8')) as NoirCompiledContract;
147
+ const contractArtifact = loadContractArtifact(json);
148
+
149
+ const content = await generateProtocolContractInterface(contractArtifact, name);
150
+ const fileName = `${toKebabCase(name)}.ts`;
151
+ await fs.writeFile(path.join(outputDir, fileName), content);
152
+
153
+ log(`Generated ${fileName}`);
154
+ }
155
+ }
156
+
157
+ main().catch(err => {
158
+ console.error('Error generating protocol contract types:', err);
159
+ process.exit(1);
160
+ });
@@ -0,0 +1,126 @@
1
+ import { MEGA_APP_VK_LENGTH_IN_FIELDS } from '@aztec-labs/constants';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { type ContractArtifact, FunctionType } from '@aztec-labs/stdlib/abi';
4
+ import { DEV_VERSION } from '@aztec-labs/stdlib/update-checker';
5
+
6
+ /**
7
+ * A minimal but representative `ContractArtifact` shared by unit tests in this package. Covers
8
+ * every function shape the tests exercise: a private initializer (`constructor`), the standard
9
+ * `public_dispatch` entry, a private function with mixed-visibility params (`bar`), a utility
10
+ * function (`qux`), and two functions exercising Noir `Option<Field>` parameters (`optionEcho`,
11
+ * `mixedParams`).
12
+ *
13
+ * We deliberately do not depend on `@aztec-labs/noir-test-contracts.js` here: that package depends on
14
+ * `@aztec-labs/aztec.js`, so importing from it would create a workspace cycle.
15
+ */
16
+ export const testContractArtifact: ContractArtifact = {
17
+ name: 'TestContract',
18
+ aztecVersion: DEV_VERSION,
19
+ functions: [
20
+ {
21
+ name: 'constructor',
22
+ isInitializer: true,
23
+ functionType: FunctionType.PRIVATE,
24
+ isOnlySelf: false,
25
+ isStatic: false,
26
+ debugSymbols: '',
27
+ parameters: [],
28
+ errorTypes: {},
29
+ bytecode: Buffer.alloc(8, 0xfa),
30
+ verificationKey: Buffer.alloc(MEGA_APP_VK_LENGTH_IN_FIELDS * Fr.SIZE_IN_BYTES).toString('base64'),
31
+ },
32
+ {
33
+ name: 'public_dispatch',
34
+ isInitializer: false,
35
+ isStatic: false,
36
+ functionType: FunctionType.PUBLIC,
37
+ isOnlySelf: false,
38
+ parameters: [{ name: 'selector', type: { kind: 'field' }, visibility: 'public' }],
39
+ errorTypes: {},
40
+ bytecode: Buffer.alloc(8, 0xfb),
41
+ debugSymbols: '',
42
+ },
43
+ {
44
+ name: 'bar',
45
+ isInitializer: false,
46
+ functionType: FunctionType.PRIVATE,
47
+ isOnlySelf: false,
48
+ isStatic: false,
49
+ debugSymbols: '',
50
+ parameters: [
51
+ { name: 'value', type: { kind: 'field' }, visibility: 'public' },
52
+ { name: 'value', type: { kind: 'field' }, visibility: 'private' },
53
+ ],
54
+ errorTypes: {},
55
+ bytecode: Buffer.alloc(8, 0xfa),
56
+ verificationKey: Buffer.alloc(MEGA_APP_VK_LENGTH_IN_FIELDS * Fr.SIZE_IN_BYTES).toString('base64'),
57
+ },
58
+ {
59
+ name: 'qux',
60
+ isInitializer: false,
61
+ isStatic: false,
62
+ functionType: FunctionType.UTILITY,
63
+ isOnlySelf: false,
64
+ parameters: [{ name: 'value', type: { kind: 'field' }, visibility: 'public' }],
65
+ returnType: { kind: 'integer', sign: 'unsigned', width: 32 },
66
+ bytecode: Buffer.alloc(8, 0xfc),
67
+ debugSymbols: '',
68
+ errorTypes: {},
69
+ },
70
+ {
71
+ name: 'optionEcho',
72
+ isInitializer: false,
73
+ functionType: FunctionType.PRIVATE,
74
+ isOnlySelf: false,
75
+ isStatic: false,
76
+ parameters: [
77
+ {
78
+ name: 'value',
79
+ type: {
80
+ kind: 'struct',
81
+ path: 'std::option::Option',
82
+ fields: [
83
+ { name: '_is_some', type: { kind: 'boolean' } },
84
+ { name: '_value', type: { kind: 'field' } },
85
+ ],
86
+ },
87
+ visibility: 'private',
88
+ },
89
+ ],
90
+ errorTypes: {},
91
+ bytecode: Buffer.alloc(8, 0xfd),
92
+ verificationKey: Buffer.alloc(MEGA_APP_VK_LENGTH_IN_FIELDS * Fr.SIZE_IN_BYTES).toString('base64'),
93
+ debugSymbols: '',
94
+ },
95
+ {
96
+ name: 'mixedParams',
97
+ isInitializer: false,
98
+ functionType: FunctionType.PRIVATE,
99
+ isOnlySelf: false,
100
+ isStatic: false,
101
+ parameters: [
102
+ {
103
+ name: 'optValue',
104
+ type: {
105
+ kind: 'struct',
106
+ path: 'std::option::Option',
107
+ fields: [
108
+ { name: '_is_some', type: { kind: 'boolean' } },
109
+ { name: '_value', type: { kind: 'field' } },
110
+ ],
111
+ },
112
+ visibility: 'private',
113
+ },
114
+ { name: 'aField', type: { kind: 'field' }, visibility: 'private' },
115
+ ],
116
+ errorTypes: {},
117
+ bytecode: Buffer.alloc(8, 0xfe),
118
+ verificationKey: Buffer.alloc(MEGA_APP_VK_LENGTH_IN_FIELDS * Fr.SIZE_IN_BYTES).toString('base64'),
119
+ debugSymbols: '',
120
+ },
121
+ ],
122
+ nonDispatchPublicFunctions: [],
123
+ outputs: { structs: {}, globals: {} },
124
+ fileMap: {},
125
+ storageLayout: {},
126
+ };
@@ -0,0 +1,32 @@
1
+ import type { Fr } from '@aztec-labs/foundation/curves/bn254';
2
+ import type { EthAddress } from '@aztec-labs/foundation/eth-address';
3
+ import type { EventSelector, FunctionSelector } from '@aztec-labs/stdlib/abi';
4
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
5
+
6
+ /** Any type that can be converted into a field for a contract call. */
7
+ export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
8
+
9
+ /** Any type that can be converted into an EthAddress Aztec.nr struct. */
10
+ export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | EthAddress;
11
+
12
+ /** Any type that can be converted into an AztecAddress Aztec.nr struct. */
13
+ export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;
14
+
15
+ /** Any type that can be converted into a FunctionSelector Aztec.nr struct. */
16
+ export type FunctionSelectorLike = FieldLike | FunctionSelector;
17
+
18
+ /** Any type that can be converted into an EventSelector Aztec.nr struct. */
19
+ export type EventSelectorLike = FieldLike | EventSelector;
20
+
21
+ /** Any type that can be converted into a U128. */
22
+ export type U128Like = bigint | number;
23
+
24
+ /** Any type that can be converted into a struct with a single `inner` field. */
25
+ export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
26
+
27
+ /** Noir `Option<T>` lowered ABI shape, plus ergonomic direct `T | null | undefined` inputs. */
28
+ export type OptionLike<T> =
29
+ | T
30
+ | null
31
+ | undefined
32
+ | { /** Whether the option is populated */ _is_some: boolean; /** Wrapped value */ _value: T };