Skip to content

Add event codegen support#141

Open
ioxde wants to merge 3 commits intocodama-idl:mainfrom
ioxde:add-event-codegen
Open

Add event codegen support#141
ioxde wants to merge 3 commits intocodama-idl:mainfrom
ioxde:add-event-codegen

Conversation

@ioxde
Copy link
Copy Markdown
Contributor

@ioxde ioxde commented Apr 15, 2026

NOTE: I don't like throwing out AI generated PRs but I think in this instance it is the right move. I made the typescript and rust version at the same time. Close if this is not the direction you want to go in.

What this does

Adds event codegen support following the same fragment-based architecture as instructions and accounts.

Per-event files (events/{name}.ts) — event type, decoder, discriminator constants, and a decode{Name}() convenience wrapper. Events are decoder-only since they're emitted by programs, not constructed by clients.

Program-level utilities{Program}Event enum, identify{Program}Event(), parse{Program}Event(), and a Parsed{Program}Event discriminated union type.

Plugin integration — adds an events field to the existing {Program}Plugin type (alongside accounts, instructions, pdas) with a {Program}PluginEvents type and decoder instances.

Key design decision: Events without constant discriminators in a hiddenPrefixTypeNode get individual files but are excluded from program-level aggregation (enum/identify/parse) — there's no reliable way to identify them at runtime.

Limitations / Blocking

Tests

  • Event rendering across all discriminator variants (constant, field, none)
  • Program-level enum/identify/parse generation
  • Plugin type generation with event decoders
  • E2e fixtures for Raydium CPMM (LpChangeEvent, SwapEvent)

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: 25ced3a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/renderers-js Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

}).filter(isNotInternal);
const definedTypesToExport = getAllDefinedTypes(node).filter(isNotInternal);
// program.events may be undefined when no events exist.
const eventsToExport = getAllEvents(node).filter(Boolean).filter(isNotInternal);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard and the *events ?? [] patterns should probably be fixed upstream so they can be removed.

See codama-idl/codama#991

Comment thread src/fragments/programEvents.ts Outdated
const data = 'data' in event ? event.data : event;
${discriminatorsFragment}
// TODO: Use SolanaError once event-specific error codes are added to @solana/errors.
throw new Error('The provided event data does not match any known ${programNode.name} event.');
Copy link
Copy Markdown
Contributor Author

@ioxde ioxde Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is most likely a blocker to this PR that will need to be addressed upstream anza-xyz/kit/packages/errors

@ioxde ioxde force-pushed the add-event-codegen branch from bcdaea0 to 25ced3a Compare April 17, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant