IMPORTANT: After completing the task below, you MUST output a JSON object in a [code]…
- User
IMPORTANT: After completing the task below, you MUST output a JSON object in a ```json code fence at the very end of your response. Do NOT forget this — the workflow fails without it.
Implement the current Spectraplex packet.
Follow:
- CLAUDE.md
- design/SPECTRAPLEX_STRATEGY_AND_EXECUTION_PLAN.md
- design/PHASED_IMPLEMENTATION_PLAN.md
Current coordination:
- phase: Phase 3: Expand Silver Into Reusable Datasets
- work packet: P3-W3: Event and instruction datasets
- objective: Add normalized decoded_events Silver table with extraction functions for EVM log events and Solana program instructions, enabling downstream consumers to query decoded protocol activity without going through ledger_entries.
- branch: p3-w3-event-instruction-datasets
- stage: new packet implementation
- existing PR:
Repo touchpoints:
- core/src/materializer.rs — add DecodedEvent struct
- adapters/src/evm_parser.rs — add extract_evm_decoded_events() and EvmDecodedEventMaterializer
- adapters/src/solana_parser.rs — add extract_solana_decoded_events() and SolanaDecodedEventMaterializer
- adapters/src/v2_repo.rs — add row_to_decoded_event(), build_decoded_event_insert(), save/query methods
- migrations/20260309200000_add_decoded_events.sql — new Silver table
Implementation steps:
-
- Add DecodedEvent struct to core/src/materializer.rs with fields: id, raw_transaction_id, network, program_or_contract, event_signature, event_name, log_index, decoded_fields (serde_json::Value), raw_fields (serde_json::Value), dataset_version_id, created_at
-
- Add serde roundtrip and no-wallet-field tests for DecodedEvent in core/src/materializer.rs
-
- Create migration 20260309200000_add_decoded_events.sql with IF NOT EXISTS guard, chain_family_enum column, nullable FK to raw_transactions, nullable FK to dataset_versions, JSONB columns for decoded_fields and raw_fields, dedup UNIQUE index on (raw_transaction_id, program_or_contract, log_index) WHERE raw_transaction_id IS NOT NULL, and indexes on program_or_contract and event_signature
-
- Add extract_evm_decoded_events() to evm_parser.rs — extract ALL log events from raw_metadata (topics, data, address), decode event signature (topic0), indexed topics (topic1-3), and non-indexed data. For Transfer and Approval events, provide named decoded_fields
-
- Add EvmDecodedEventMaterializer to evm_parser.rs with dataset_name=DecodedEvents, chain_family=Evm, unique parser_hash
Assistant
Now let me read the current source files I need to modify:
Assistant
Let me read the rest of v2_repo.rs and the existing migrations:
Assistant
Now let me read the rest of v2_repo.rs to see the save/query methods:
Assistant
Let me read the test section too:
Assistant
Now I have a thorough understanding of the codebase. Let me also check hl_parser.rs for the Hyperliquid materializer, which is needed for the global hash uniqueness check:
Assistant
Now I have a complete picture of all 8 existing materializers and their hashes. Let me also check the adapters/src/lib.rs exports:
Assistant
Now I have a thorough understanding. Let me implement all the changes. I'll start by editing all files in parallel:
Assistant
Now add the DecodedEvent tests to materializer.rs:
Assistant
Now create the migration file:
Assistant
Now add the EVM decoded event extraction and materializer to evm_parser.rs:
Assistant
Now add the ERC-20 Approval topic constant and the
extract_evm_decoded_eventsfunction plus the materializer. I'll add these before the existingEvmLedgerMaterializer:Assistant
Now add the EvmDecodedEventMaterializer after EvmTokenTransferMaterializer:
Assistant
Now add EVM decoded events tests at the end of the test module in evm_parser.rs:
Assistant
Now add the decoded event extraction tests at the end of evm_parser.rs tests:
Assistant
Now add Solana decoded event extraction and materializer. Let me add the extraction function and materializer to solana_parser.rs:
Assistant
Now add the
extract_solana_decoded_eventsfunction andSolanaDecodedEventMaterializerbefore the existing materializer section:Assistant
Now add the SolanaDecodedEventMaterializer after SolanaNativeBalanceDeltaMaterializer:
Assistant
Now add the Solana decoded event tests and materializer contract test at the end of the test module:
Assistant
Now add the repository code for decoded events in v2_repo.rs. Let me read the exact section where I need to add:
Assistant
Now add the row mapping helper and query builder for decoded events. I'll add them after the existing native_balance_delta functions:
Assistant
Now add the
save_decoded_eventsandget_decoded_events_by_contractrepository methods. Let me find where the NativeBalanceDeltas section ends:Assistant
Now add the v2_repo tests for decoded events. Let me read the current test section end:
Assistant
Now update the global materializer hash test in
lib.rsto include the 2 new decoded event materializers (going from 8 to 10):Assistant
Now update the
all_p3w2_materializer_descriptors_are_validtest to include the new materializers:Assistant
Also add a test that all decoded event materializers produce the correct dataset:
Assistant
Now let's build and run the checks:
Assistant
Now run clippy:
Assistant
Now run tests:
Assistant
All tests pass. 270 + 26 + 22 + 11 + 137 + 27 + 101 = 594 total tests passed, 0 failures. Now let me write the handoff doc:
Assistant
Now let me verify the formatting one final time and then commit:
Assistant
All clean. Now let me create the commit:
Assistant
Clean working tree. All done. Let me verify the final state once more:
Assistant