Skip to content

feat(services): 3/n - preview custom SEP-41 token state changes in simulateStateChanges - #727

Open
JiahuiWho wants to merge 4 commits into
feat/618-simulate-state-changes-phase1from
feat/618-simulate-sep41-tokens
Open

JiahuiWho wants to merge 4 commits into
feat/618-simulate-state-changes-phase1from
feat/618-simulate-sep41-tokens

Conversation

@JiahuiWho

@JiahuiWho JiahuiWho commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What

Extends simulateStateChanges to cover custom SEP-41 tokens by mirroring what live ingestion does after the indexer pass, with persistence removed:

  1. ProtocolProcessor.StagedStateChanges() (new interface method): reads the processor's computed state changes without persisting them to the DB.
  2. Simulation service: after the main indexer runs, we take the contract events it collected, ask the database which of those contracts are known SEP-41 tokens, run the SEP-41 processor over the events, and add its state changes to the preview.
  3. Wiring: the serve binary now imports sep41 so the processor registers itself at startup, and the simulation service gets Models so it can do the classification lookup.

Why

Previously the simulation only ran the main indexer, skips non-SAC token events deliberately because sep41.Processor owns them.

Known limitations

N/A

Issue that this PR addresses

#618

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

@JiahuiWho
JiahuiWho marked this pull request as ready for review September 2, 2026 17:15
Copilot AI balanced review requested due to automatic review settings September 2, 2026 17:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends transaction simulation to preview state changes for custom SEP-41 tokens without persistence.

Changes:

  • Runs registered protocol processors during simulation.
  • Exposes staged SEP-41 state changes.
  • Wires models and SEP-41 registration into serving.
  • Adds service and GraphQL test coverage.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Review
internal/services/transaction_simulation.go Requires same-ledger contract classification and explicit processor resets before processing.
internal/services/transaction_simulation_test.go Updates constructor calls.
internal/services/transaction_simulation_sep41_test.go Adds end-to-end SEP-41 simulation tests.
internal/services/sep41/processor.go Exposes staged changes; nit: restore the Reset documentation placement.
internal/services/protocol_processor.go Extends the processor interface.
internal/services/protocol_migrate_test.go Updates the test processor.
internal/services/processor_registry_test.go Updates registry stubs.
internal/services/mocks.go Extends the processor mock.
internal/services/ingest_test.go Updates the ingestion test processor.
internal/serve/serve.go Registers SEP-41 and injects models.
internal/serve/graphql/utils_test.go Covers the simulation failure code.
internal/serve/graphql/resolvers/simulation_test.go Tests simulated-state conversion.
internal/serve/graphql/resolvers/queries_resolvers_test.go Tests simulation error mapping.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/services/transaction_simulation.go Outdated
Comment thread internal/services/transaction_simulation.go
Comment thread internal/services/sep41/processor.go Outdated
@JiahuiWho

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot stopped work on behalf of JiahuiWho due to an error September 3, 2026 20:15
Copilot AI review requested due to automatic review settings September 3, 2026 20:16
@JiahuiWho
JiahuiWho force-pushed the feat/618-simulate-sep41-tokens branch from adead45 to 5531231 Compare September 3, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Suppressed comments (1)

internal/services/transaction_simulation.go:62

  • This comment says models is used only for protocol_contracts, but this path also queries ProtocolWasms to classify same-transaction bindings (line 453). Mentioning both lookups avoids misleading callers that provide partial model aggregates.
// NewTransactionSimulationService builds the simulation service. models is used
// only for the read-only protocol_contracts lookup that routes contract events
// to the registered protocol processors (SEP-41); a nil models skips protocol
// processing, so previews then cover native/SAC tokens only.

@JiahuiWho JiahuiWho changed the title feat(services): preview custom SEP-41 token state changes in simulateStateChanges feat(services): 3/n - preview custom SEP-41 token state changes in simulateStateChanges Sep 8, 2026
@JiahuiWho
JiahuiWho force-pushed the feat/618-simulate-sep41-tokens branch from 5531231 to b266840 Compare September 14, 2026 15:52
Copilot AI review requested due to automatic review settings September 14, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@aditya1702
aditya1702 added this pull request to stack #737 September 14, 2026 16:12
@JiahuiWho
JiahuiWho force-pushed the feat/618-simulate-sep41-tokens branch from b266840 to b68e1bf Compare September 14, 2026 17:58
Copilot AI review requested due to automatic review settings September 14, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

// a contract bound to an already-classified wasm emits rows even without a
// committed protocol_contracts entry. Classification for the buffered wasm
// hashes comes from committed protocol_wasms.
var classification map[types.HashBytea]string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we doing classification when generating the simulated state changes? Shouldn't that happen only in live ingestion?

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.

Because ingestion will classify this contract when the transaction lands, the preview must classify it too, or it would miss rows history will show. It's in-memory and read-only, nothing is persisted.

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.

3 participants