Skip to content

gnd: Support tuple/struct event params in subgraph scaffolding#6661

Draft
incrypto32 wants to merge 5 commits into
masterfrom
incrypto32/gnd-tuples
Draft

gnd: Support tuple/struct event params in subgraph scaffolding#6661
incrypto32 wants to merge 5 commits into
masterfrom
incrypto32/gnd-tuples

Conversation

@incrypto32

Copy link
Copy Markdown
Member

Stacked on #6660 (base is the PR A branch, incrypto32/gnd-add-fix) — review/merge that first.

A tuple/struct event parameter previously collapsed to a single Bytes field and was dropped from the event signature, producing a subgraph that fails to build and whose topic0 never matches the on-chain event. This adds proper tuple support to the scaffolder.

  • ABI parsing reads nested tuple components recursively
  • Event signatures expand tuples, Foo((address,uint256),uint256), so topic0 matches
  • A tuple unrolls into one field per component (data -> data_a, data_b) in both the schema and the mapping, with nested accessors (event.params.data.a), via a shared flatten_event_inputs
  • Arrays of address/tuple are changetype<Bytes[]>'d so the assignment type-checks

Tests: unit tests for tuple flatten + recursive signatures + changetype; an e2e that a tuple ABI scaffolds the unrolled schema/mapping; and a codegen regression e2e for reserved-word/unnamed params.

Mirrors graph-cli: only a single tuple unrolls; tuple[] stays a Bytes[] field + changetype.

Base automatically changed from incrypto32/gnd-add-fix to master July 15, 2026 09:36
@incrypto32
incrypto32 force-pushed the incrypto32/gnd-tuples branch from 5c8dbc1 to 83e0f94 Compare July 15, 2026 10:02
Replace the scaffold module's hand-rolled ABI parsing with alloy's typed
Event/EventParam, mirroring the codegen side (which already uses them). Events
are parsed in file order via serde; a malformed event is skipped with a warning
instead of silently dropping individual params.

The shared preprocessing (artifact-format unwrapping, anonymous/param{index}
defaults) moves from commands/codegen.rs to the abi module so scaffold and
codegen share it. As a result unnamed event params now yield param{index} entity
fields (matching graph-cli) rather than a bare value field, and scaffolding
accepts Foundry/Hardhat/Truffle artifact ABIs.
Build the manifest event signature from each param's canonical type
(selector_type) instead of the raw ABI type, so a tuple expands to its
components, e.g. Filled((address,uint256),uint256). Previously a tuple param
produced Filled(tuple,uint256), whose topic0 hash did not match the on-chain
event, so the handler never fired.
A tuple parameter now expands to one field per component (data -> data_account,
data_amount) in both the schema and the mapping, with nested accessors
(event.params.data.account), via a shared flatten_event_inputs helper.
Arrays of address/tuple are changetype'd to Bytes[] so the assignment
type-checks. Previously a tuple collapsed to a single Bytes field that did not
match the generated event params.
init from an ABI with a tuple event unrolls it into data_account /
data_amount schema fields and reads them via the nested accessor in the
generated mapping.
Regression guard for the LHS/RHS escaping mismatch: codegen a contract with
a reserved-word param (`new`) and an unnamed param, then assert the mapping's
event.params accessor matches the getter the bindings actually expose
(new_, param1).
@incrypto32
incrypto32 force-pushed the incrypto32/gnd-tuples branch from 83e0f94 to 390be45 Compare July 16, 2026 08:05
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