@aztec/aztec.js 0.0.1-commit.f1df4d2 → 0.0.1-commit.f2ce05ee

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.
package/src/api/fields.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Fr, Fq } from '@aztec/foundation/curves/bn254';
2
2
  export { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
3
+ export { BlockNumber } from '@aztec/foundation/branded-types';
package/src/api/wallet.ts CHANGED
@@ -11,11 +11,12 @@ export {
11
11
  type Wallet,
12
12
  type PrivateEvent,
13
13
  type PrivateEventFilter,
14
+ type PublicEvent,
15
+ type PublicEventFilter,
14
16
  type ContractMetadata,
15
17
  type ContractClassMetadata,
16
18
  AppCapabilitiesSchema,
17
19
  WalletCapabilitiesSchema,
18
- FunctionCallSchema,
19
20
  ExecutionPayloadSchema,
20
21
  GasSettingsOptionSchema,
21
22
  WalletSimulationFeeOptionSchema,
@@ -28,6 +29,8 @@ export {
28
29
  EventMetadataDefinitionSchema,
29
30
  PrivateEventSchema,
30
31
  PrivateEventFilterSchema,
32
+ PublicEventSchema,
33
+ PublicEventFilterSchema,
31
34
  ContractClassMetadataSchema,
32
35
  ContractMetadataSchema,
33
36
  WalletSchema,
@@ -1,4 +1,11 @@
1
- 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';
2
9
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
10
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
11
  import { type Capsule, type HashedValues, type TxProfileResult, collectOffchainEffects } from '@aztec/stdlib/tx';
@@ -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
  /**
@@ -1,6 +1,6 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
3
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { GasSettings } from '@aztec/stdlib/gas';
6
6
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -27,10 +27,11 @@ export class FeeJuicePaymentMethodWithClaim implements FeePaymentMethod {
27
27
 
28
28
  return new ExecutionPayload(
29
29
  [
30
- {
31
- to: ProtocolContractAddress.FeeJuice,
30
+ FunctionCall.from({
32
31
  name: 'claim_and_end_setup',
32
+ to: ProtocolContractAddress.FeeJuice,
33
33
  selector,
34
+ type: FunctionType.PRIVATE,
34
35
  hideMsgSender: false,
35
36
  isStatic: false,
36
37
  args: [
@@ -40,8 +41,7 @@ export class FeeJuicePaymentMethodWithClaim implements FeePaymentMethod {
40
41
  new Fr(this.claim.messageLeafIndex),
41
42
  ],
42
43
  returnTypes: [],
43
- type: FunctionType.PRIVATE,
44
- },
44
+ }),
45
45
  ],
46
46
  [],
47
47
  [],
@@ -1,5 +1,5 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
+ import { type FunctionAbi, FunctionCall, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { GasSettings } from '@aztec/stdlib/gas';
5
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -102,21 +102,21 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
102
102
 
103
103
  const witness = await this.wallet.createAuthWit(this.sender, {
104
104
  caller: this.paymentContract,
105
- call: {
105
+ call: FunctionCall.from({
106
106
  name: 'transfer_to_public',
107
- args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
107
+ to: await this.getAsset(),
108
108
  selector: await FunctionSelector.fromSignature('transfer_to_public((Field),(Field),u128,Field)'),
109
109
  type: FunctionType.PRIVATE,
110
110
  hideMsgSender: false,
111
111
  isStatic: false,
112
- to: await this.getAsset(),
112
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
113
113
  returnTypes: [],
114
- },
114
+ }),
115
115
  });
116
116
 
117
117
  return new ExecutionPayload(
118
118
  [
119
- {
119
+ FunctionCall.from({
120
120
  name: 'fee_entrypoint_private',
121
121
  to: this.paymentContract,
122
122
  selector: await FunctionSelector.fromSignature('fee_entrypoint_private(u128,Field)'),
@@ -125,7 +125,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
125
125
  isStatic: false,
126
126
  args: [maxFee, txNonce],
127
127
  returnTypes: [],
128
- },
128
+ }),
129
129
  ],
130
130
  [witness],
131
131
  [],
@@ -1,5 +1,5 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { type FunctionAbi, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
2
+ import { type FunctionAbi, FunctionCall, FunctionSelector, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { GasSettings } from '@aztec/stdlib/gas';
5
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -94,16 +94,16 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
94
94
 
95
95
  const intent = {
96
96
  caller: this.paymentContract,
97
- call: {
97
+ call: FunctionCall.from({
98
98
  name: 'transfer_in_public',
99
- args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
99
+ to: await this.getAsset(),
100
100
  selector: await FunctionSelector.fromSignature('transfer_in_public((Field),(Field),u128,Field)'),
101
101
  type: FunctionType.PUBLIC,
102
- isStatic: false,
103
102
  hideMsgSender: false /** The target function performs an authwit check, so msg_sender is needed */,
104
- to: await this.getAsset(),
103
+ isStatic: false,
104
+ args: [this.sender.toField(), this.paymentContract.toField(), maxFee, txNonce],
105
105
  returnTypes: [],
106
- },
106
+ }),
107
107
  };
108
108
 
109
109
  const setPublicAuthWitInteraction = await SetPublicAuthwitContractInteraction.create(
@@ -116,7 +116,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
116
116
  return new ExecutionPayload(
117
117
  [
118
118
  ...(await setPublicAuthWitInteraction.request()).calls,
119
- {
119
+ FunctionCall.from({
120
120
  name: 'fee_entrypoint_public',
121
121
  to: this.paymentContract,
122
122
  selector: await FunctionSelector.fromSignature('fee_entrypoint_public(u128,Field)'),
@@ -125,7 +125,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
125
125
  isStatic: false,
126
126
  args: [maxFee, txNonce],
127
127
  returnTypes: [],
128
- },
128
+ }),
129
129
  ],
130
130
  [],
131
131
  [],
@@ -1,5 +1,5 @@
1
1
  import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
2
- import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
2
+ import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import type { GasSettings } from '@aztec/stdlib/gas';
5
5
  import { ExecutionPayload } from '@aztec/stdlib/tx';
@@ -22,7 +22,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
22
22
  async getExecutionPayload(): Promise<ExecutionPayload> {
23
23
  return new ExecutionPayload(
24
24
  [
25
- {
25
+ FunctionCall.from({
26
26
  name: 'sponsor_unconditionally',
27
27
  to: this.paymentContract,
28
28
  selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
@@ -31,7 +31,7 @@ export class SponsoredFeePaymentMethod implements FeePaymentMethod {
31
31
  isStatic: false,
32
32
  args: [],
33
33
  returnTypes: [],
34
- },
34
+ }),
35
35
  ],
36
36
  [],
37
37
  [],
@@ -7,8 +7,7 @@ import {
7
7
  type ContractArtifact,
8
8
  ContractArtifactSchema,
9
9
  type EventMetadataDefinition,
10
- type FunctionCall,
11
- FunctionType,
10
+ FunctionCall,
12
11
  } from '@aztec/stdlib/abi';
13
12
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
14
13
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -140,37 +139,66 @@ export type BatchResults<T extends readonly BatchedMethod[]> = {
140
139
  };
141
140
 
142
141
  /**
143
- * Filter options when querying private events.
142
+ * Base filter options for event queries.
144
143
  */
145
- export type PrivateEventFilter = {
146
- /** The address of the contract that emitted the events. */
147
- contractAddress: AztecAddress;
148
- /** Addresses of accounts that are in scope for this filter. */
149
- scopes: AztecAddress[];
144
+ export type EventFilterBase = {
150
145
  /** Transaction in which the events were emitted. */
151
146
  txHash?: TxHash;
152
147
  /** The block number from which to start fetching events (inclusive).
153
148
  * Optional. If provided, it must be greater or equal than 1.
154
149
  * Defaults to the initial L2 block number (INITIAL_L2_BLOCK_NUM).
155
- * */
150
+ */
156
151
  fromBlock?: BlockNumber;
157
152
  /** The block number until which to fetch logs (not inclusive).
158
153
  * Optional. If provided, it must be greater than fromBlock.
159
- * Defaults to the latest known block to PXE + 1.
160
154
  */
161
155
  toBlock?: BlockNumber;
162
156
  };
163
157
 
164
158
  /**
165
- * An ABI decoded private event with associated metadata.
159
+ * Filter options when querying private events.
166
160
  */
167
- export type PrivateEvent<T> = {
161
+ export type PrivateEventFilter = EventFilterBase & {
162
+ /** The address of the contract that emitted the events. */
163
+ contractAddress: AztecAddress;
164
+ /** Addresses of accounts that are in scope for this filter. */
165
+ scopes: AztecAddress[];
166
+ };
167
+
168
+ /**
169
+ * Filter options when querying public events.
170
+ */
171
+ export type PublicEventFilter = EventFilterBase & {
172
+ /** The address of the contract that emitted the events. */
173
+ contractAddress?: AztecAddress;
174
+ };
175
+
176
+ /**
177
+ * An ABI decoded event with associated metadata.
178
+ * @typeParam T - The decoded event type
179
+ * @typeParam M - Additional metadata fields (empty by default)
180
+ */
181
+ export type Event<T, M extends object = object> = {
168
182
  /** The ABI decoded event */
169
183
  event: T;
170
184
  /** Metadata describing event context information such as tx and block */
171
- metadata: InTx;
185
+ metadata: InTx & M;
172
186
  };
173
187
 
188
+ /** An ABI decoded private event with associated metadata. */
189
+ export type PrivateEvent<T> = Event<T>;
190
+
191
+ /** An ABI decoded public event with associated metadata (includes contract address). */
192
+ export type PublicEvent<T> = Event<
193
+ T,
194
+ {
195
+ /**
196
+ * Address of the contract that emitted this event
197
+ */
198
+ contractAddress: AztecAddress;
199
+ }
200
+ >;
201
+
174
202
  /**
175
203
  * Contract metadata including deployment and registration status.
176
204
  */
@@ -228,19 +256,8 @@ export type Wallet = {
228
256
  batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>>;
229
257
  };
230
258
 
231
- export const FunctionCallSchema = z.object({
232
- name: z.string(),
233
- to: schemas.AztecAddress,
234
- selector: schemas.FunctionSelector,
235
- type: z.nativeEnum(FunctionType),
236
- isStatic: z.boolean(),
237
- hideMsgSender: z.boolean(),
238
- args: z.array(schemas.Fr),
239
- returnTypes: z.array(AbiTypeSchema),
240
- });
241
-
242
259
  export const ExecutionPayloadSchema = z.object({
243
- calls: z.array(FunctionCallSchema),
260
+ calls: z.array(FunctionCall.schema),
244
261
  authWitnesses: z.array(AuthWitness.schema),
245
262
  capsules: z.array(Capsule.schema),
246
263
  extraHashedArgs: z.array(HashedValues.schema),
@@ -297,7 +314,7 @@ export const MessageHashOrIntentSchema = z.union([
297
314
  z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
298
315
  z.object({
299
316
  caller: schemas.AztecAddress,
300
- call: FunctionCallSchema,
317
+ call: FunctionCall.schema,
301
318
  }),
302
319
  ]);
303
320
 
@@ -307,6 +324,21 @@ export const EventMetadataDefinitionSchema = z.object({
307
324
  fieldNames: z.array(z.string()),
308
325
  });
309
326
 
327
+ const EventFilterBaseSchema = z.object({
328
+ txHash: optional(TxHash.schema),
329
+ fromBlock: optional(BlockNumberPositiveSchema),
330
+ toBlock: optional(BlockNumberPositiveSchema),
331
+ });
332
+
333
+ export const PrivateEventFilterSchema = EventFilterBaseSchema.extend({
334
+ contractAddress: schemas.AztecAddress,
335
+ scopes: z.array(schemas.AztecAddress),
336
+ });
337
+
338
+ export const PublicEventFilterSchema = EventFilterBaseSchema.extend({
339
+ contractAddress: optional(schemas.AztecAddress),
340
+ });
341
+
310
342
  export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded>>()(
311
343
  z.object({
312
344
  event: AbiDecodedSchema,
@@ -314,13 +346,12 @@ export const PrivateEventSchema: z.ZodType<any> = zodFor<PrivateEvent<AbiDecoded
314
346
  }),
315
347
  );
316
348
 
317
- export const PrivateEventFilterSchema = z.object({
318
- contractAddress: schemas.AztecAddress,
319
- scopes: z.array(schemas.AztecAddress),
320
- txHash: optional(TxHash.schema),
321
- fromBlock: optional(BlockNumberPositiveSchema),
322
- toBlock: optional(BlockNumberPositiveSchema),
323
- });
349
+ export const PublicEventSchema = zodFor<PublicEvent<AbiDecoded>>()(
350
+ z.object({
351
+ event: AbiDecodedSchema,
352
+ metadata: z.intersection(inTxSchema(), z.object({ contractAddress: schemas.AztecAddress })),
353
+ }),
354
+ );
324
355
 
325
356
  export const ContractMetadataSchema = z.object({
326
357
  instance: optional(ContractInstanceWithAddressSchema),
@@ -479,7 +510,7 @@ const WalletMethodSchemas = {
479
510
  simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
480
511
  simulateUtility: z
481
512
  .function()
482
- .args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
513
+ .args(FunctionCall.schema, optional(z.array(AuthWitness.schema)))
483
514
  .returns(UtilitySimulationResult.schema),
484
515
  profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
485
516
  sendTx: z