-
Notifications
You must be signed in to change notification settings - Fork 0
feat: private event utilities #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/update-sd-dependency-match-lock-viem
Are you sure you want to change the base?
feat: private event utilities #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces utilities for handling private events in the EntryPoint contract and consolidates event ABI definitions into reusable modules. The changes enable decoding private event payloads and reconstructing them as standard event logs with proper topics.
Key Changes:
- Consolidated event ABI definitions (
UserOperationEvent,AccountDeployed,SignatureAggregatorChanged) intopackages/executor/src/utils/abi-events/for reuse - Added
PrivateEventABI and utilities to decode/unwrap private events - Implemented topic extraction from decoded event parameters
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/executor/src/utils/abi-events/index.ts |
Central export for all event ABI definitions |
packages/executor/src/utils/abi-events/UserOperationEvent.ts |
UserOperationEvent ABI definition with event hash |
packages/executor/src/utils/abi-events/SignatureAggregatorChanged.ts |
SignatureAggregatorChanged ABI definition |
packages/executor/src/utils/abi-events/PrivateEvent.ts |
PrivateEvent ABI definition for wrapped events |
packages/executor/src/utils/abi-events/AccountDeployed.ts |
AccountDeployed ABI definition with event hash |
packages/executor/src/utils/extractEventAbiTopics.ts |
Utility to extract and encode event topics from payload |
packages/executor/src/utils/unwrapPrivateEvent.ts |
Utility to decode private events into standard logs |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // @ts-expect-error - dynamically extracted indexedValues cannot be proven to match generic tuple type | ||
| const topics = encodeEventTopics({ | ||
| abi: [abi], | ||
| args: indexedValues | ||
| }) |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @ts-expect-error directive suppresses type checking without validation. Consider using @ts-ignore with a more specific explanation, or better yet, add runtime validation to ensure indexedValues matches the expected structure before encoding.
| return { | ||
| ...ev, | ||
| eventName: abi.name, | ||
| args: decoded.args, | ||
| topics, | ||
| } as unknown as Log<bigint, number, false, ABI> | ||
| } |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double type assertion (as unknown as) bypasses type safety. Consider restructuring the return type or adding runtime validation to ensure the shape matches Log<bigint, number, false, ABI> before returning.
| return { | |
| ...ev, | |
| eventName: abi.name, | |
| args: decoded.args, | |
| topics, | |
| } as unknown as Log<bigint, number, false, ABI> | |
| } | |
| // Runtime validation: ensure decoded.args is an object and matches ABI inputs | |
| if ( | |
| typeof decoded.args !== 'object' || | |
| decoded.args === null | |
| ) { | |
| throw new Error('Decoded args is not an object'); | |
| } | |
| // Optionally, check that all ABI inputs are present in decoded.args | |
| if ( | |
| !abi.inputs.every(input => input.name in (decoded.args as object)) | |
| ) { | |
| throw new Error('Decoded args does not match ABI inputs'); | |
| } | |
| return { | |
| ...ev, | |
| eventName: abi.name, | |
| args: decoded.args, | |
| topics, | |
| }; |
| * @param x - the private event log to check if it has args | ||
| * @returns true if the private event log has args, false otherwise | ||
| */ | ||
| export const isPrivateEventLogWithArgs = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this function from isPrivateEventLogWithArgs to isPrivateEventLog. The function itself checks if args are present, so the "WithArgs" suffix is redundant. Also, verify we're only querying for PrivateEvent logs, not mixing public and private event queries. We should query only for private events, and I think I saw that you are doing so.
| * @returns the unwrapped event log | ||
| * @throws if there is an error decoding the event log or extracting the topics | ||
| */ | ||
| export function unwrapPrivateEvent<ABI extends AbiEvent>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider using the SDInterface.parseLog method from @appliedblockchain/silentdatarollup-ethers-provider instead of this custom unwrapPrivateEvent implementation. The ethers provider has an implementation that handles to parse the private logs. See https://github.com/appliedblockchain/silent-data-rollup-providers/blob/main/packages/ethers-provider/src/sdInterface.ts#L28 for reference. However, since we're using viem not ethers there might be conflicts. If the only conflict is only TS let's ignore add a comment and a working vversion for Viem will come in the future.
What do you think?
| * @param abi - the abi of the event to extract the topics from | ||
| * @param payload - the payload of the event | ||
| * @returns fixed-length array with the encoded event topics | ||
| * @throws an {@link AbiEventTopicsCountMismatchError} if the topics count mismatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is actually thrown. Remove the class and the doc or throw the error.
| * @param ABI - the abi of the event to extract the topics from | ||
| * @returns the topics fixed-length array type | ||
| */ | ||
| type AbiEventTopicsArray<ABI extends AbiEvent> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but, I am a bit confused and I need your help to clarify why we need these utils...
| @@ -0,0 +1,4 @@ | |||
| export * from './AccountDeployed' | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ABI organization is clean, but does this follow the Skandha pattern? The existing codebase has contract types in packages/types/src/contracts/EPv7/core/ and factories in packages/types/src/contracts/EPv7/factories/.
If so then my comment doesn't make sense, if not, let's use the skanda pattern.
We should do surgical modifications/additions. Because at some point we will update our version with the most up to date version of them.
Description
This PR introduces utilities for handling private events and consolidates event ABI definitions into common utilities for better code reuse.
Key Changes:
UserOperationEvent,AccountDeployed,SignatureAggregatorChanged) into common utilities atpackages/executor/src/utils/abi-events/for reuse across the codebasePrivateEventABI definition for decoding private events emitted by the EntryPoint contractextractEventAbiTopics()utility that reconstructs event topics from decoded parameters, enabling proper event filtering and matchingunwrapPrivateEvent()utility that decodes private event payloads and reconstructs them as standard event logs with proper topics and argsImplementation Details:
getPrivateLogsis not available in viem, these utilities provide an approach for decoding private event payloads and unwrapping them into the standard event log formatAbiEventTopicsCountMismatchError) for debugging topic extraction issuesTypes of changes
What types of changes does your code introduce?
Put an
xin the boxes that applyFurther comments (optional)
extractEventAbiTopicsutility uses type-level recursion to build proper fixed-length topic arrays from event ABIs