diff --git a/yarn-project/aztec.js/src/api/abi.ts b/yarn-project/aztec.js/src/api/abi.ts index 69f8b095aeed..2f76188c5cde 100644 --- a/yarn-project/aztec.js/src/api/abi.ts +++ b/yarn-project/aztec.js/src/api/abi.ts @@ -1,3 +1,3 @@ -export { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi'; +export { type ContractArtifact, type FunctionArtifact, EventSelector, FunctionSelector } from '@aztec/foundation/abi'; export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi'; export { type NoirCompiledContract } from '@aztec/types/noir'; diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 79eef3043707..8fabb0e8f91e 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -41,6 +41,7 @@ export { CheatCodes, EthAddressLike, EthCheatCodes, + EventSelectorLike, FieldLike, FunctionSelectorLike, WrappedFieldLike, diff --git a/yarn-project/aztec.js/src/utils/abi_types.ts b/yarn-project/aztec.js/src/utils/abi_types.ts index 71b88b898482..304c109899bd 100644 --- a/yarn-project/aztec.js/src/utils/abi_types.ts +++ b/yarn-project/aztec.js/src/utils/abi_types.ts @@ -1,4 +1,10 @@ -import { type AztecAddress, type EthAddress, type Fr, type FunctionSelector } from '@aztec/circuits.js'; +import { + type AztecAddress, + type EthAddress, + type EventSelector, + type Fr, + type FunctionSelector, +} from '@aztec/circuits.js'; /** Any type that can be converted into a field for a contract call. */ export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr }; @@ -9,8 +15,11 @@ export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | Eth /** Any type that can be converted into an AztecAddress Aztec.nr struct. */ export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress; -/** Any type that can be converted into an FunctionSelector Aztec.nr struct. */ +/** Any type that can be converted into a FunctionSelector Aztec.nr struct. */ export type FunctionSelectorLike = FieldLike | FunctionSelector; +/** Any type that can be converted into an EventSelector Aztec.nr struct. */ +export type EventSelectorLike = FieldLike | EventSelector; + /** Any type that can be converted into a struct with a single `inner` field. */ export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike; diff --git a/yarn-project/builder/src/contract-interface-gen/typescript.ts b/yarn-project/builder/src/contract-interface-gen/typescript.ts index 2a51d433bc94..5fc2828c500b 100644 --- a/yarn-project/builder/src/contract-interface-gen/typescript.ts +++ b/yarn-project/builder/src/contract-interface-gen/typescript.ts @@ -255,13 +255,13 @@ function generateEvents(events: any[] | undefined) { `; const fieldNames = event.fields.map((field: any) => `"${field.name}"`); - const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, functionSelector: FunctionSelector, fieldNames: string[] }`; + const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, eventSelector: EventSelector, fieldNames: string[] }`; const eventImpl = `${eventName}: { - decode: this.decodeEvent(${event.fields.length}, FunctionSelector.fromSignature('${eventName}(${event.fields + decode: this.decodeEvent(${event.fields.length}, EventSelector.fromSignature('${eventName}(${event.fields .map(() => 'Field') .join(',')})'), [${fieldNames}]), - functionSelector: FunctionSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'), + eventSelector: EventSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'), fieldNames: [${fieldNames}], }`; @@ -276,21 +276,21 @@ function generateEvents(events: any[] | undefined) { eventDefs: eventsMetadata.map(({ eventDef }) => eventDef).join('\n'), events: ` // Partial application is chosen is to avoid the duplication of so much codegen. - private static decodeEvent(fieldsLength: number, functionSelector: FunctionSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined { + private static decodeEvent(fieldsLength: number, eventSelector: EventSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined { return (payload: L1EventPayload | undefined): T | undefined => { if (payload === undefined) { return undefined; } if ( - !functionSelector.equals( - FunctionSelector.fromField(payload.eventTypeId), + !eventSelector.equals( + EventSelector.fromField(payload.eventTypeId), ) ) { return undefined; } if (payload.event.items.length !== fieldsLength) { throw new Error( - 'Something is weird here, we have matching FunctionSelectors, but the actual payload has mismatched length', + 'Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length', ); } @@ -351,6 +351,7 @@ import { EthAddressLike, FieldLike, Fr, + EventSelector, FunctionSelector, FunctionSelectorLike, L1EventPayload, diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 0c32d8140a9c..6092eda27800 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -6,7 +6,7 @@ import { type PartialAddress, type Point, } from '@aztec/circuits.js'; -import { type ContractArtifact, type FunctionSelector } from '@aztec/foundation/abi'; +import { type ContractArtifact, type EventSelector } from '@aztec/foundation/abi'; import { type ContractClassWithId, type ContractInstanceWithAddress, @@ -397,7 +397,7 @@ export interface PXE { */ export interface EventMetadata { decode(payload: L1EventPayload): T | undefined; - functionSelector: FunctionSelector; + eventSelector: EventSelector; fieldNames: string[]; } diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index c8bf5154dc59..d90356a074a2 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -84,6 +84,6 @@ export * from './tx_request.js'; export * from './validation_requests.js'; export * from './verification_key.js'; -export { FunctionSelector } from '@aztec/foundation/abi'; +export { EventSelector, FunctionSelector } from '@aztec/foundation/abi'; export * from '@aztec/foundation/aztec-address'; export * from '@aztec/foundation/fields'; diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 9a5c5247cb98..5422eea4f00b 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -35,7 +35,13 @@ import { getContractClassFromArtifact, } from '@aztec/circuits.js'; import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash'; -import { type ContractArtifact, type DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; +import { + type ContractArtifact, + type DecodedReturn, + EventSelector, + FunctionSelector, + encodeArguments, +} from '@aztec/foundation/abi'; import { type Fq, Fr, type Point } from '@aztec/foundation/fields'; import { SerialQueue } from '@aztec/foundation/fifo'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -853,7 +859,7 @@ export class PXEService implements PXE { if (visibleEvent.payload === undefined) { return undefined; } - if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.functionSelector)) { + if (!EventSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.eventSelector)) { return undefined; } if (visibleEvent.payload.event.items.length !== eventMetadata.fieldNames.length) {