Repository navigation
Hidden contracts: leave a token out of API responses - #764
Merged
Merged
Conversation
aditya1702
force-pushed
the
ignored-contracts
branch
from
October 8, 2026 15:48
7e07032 to
93e1ee2
Compare
aditya1702
force-pushed
the
ignored-contracts
branch
5 times, most recently
from
October 8, 2026 19:50
1155ec1 to
c0f9867
Compare
aditya1702
marked this pull request as ready for review
October 8, 2026 19:50
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
YAML streams can be partially ignored, and SAC validation can be bypassed before contract classification populates the database.
2 open findings
What changed in this PR
Adds an API-layer hidden-contract list as a partial mitigation for #610 while preserving ingestion history.
Changes:
- Loads and validates built-in or operator-supplied YAML deny lists.
- Filters hidden SEP-41 balances, allowances, and protocol-scoped state changes.
- Adds CLI wiring, documentation, and database-backed tests.
| File | Description |
|---|---|
internal/services/processor_registry_ext_test.go |
Verifies protocol ordinal mappings. |
internal/serve/serve.go |
Loads and applies hidden contracts. |
internal/serve/hidden_contracts.yaml |
Defines the built-in CPAL entry. |
internal/serve/hidden_contracts.go |
Implements list parsing and model wiring. |
internal/serve/hidden_contracts_test.go |
Tests parsing and wiring. |
internal/indexer/types/types.go |
Maps protocols to ordinal ranges. |
internal/data/statechanges.go |
Filters protocol-scoped state changes. |
internal/data/statechanges_hidden_test.go |
Tests all state-change reads. |
internal/data/sep41/models.go |
Propagates hidden contracts. |
internal/data/sep41/balances.go |
Filters SEP-41 balances. |
internal/data/sep41/balances_test.go |
Tests balance filtering. |
internal/data/sep41/allowances.go |
Filters SEP-41 allowances. |
internal/data/sep41/allowances_test.go |
Tests allowance filtering. |
internal/data/models.go |
Updates SEP-41 model construction. |
internal/data/mocks.go |
Extends the contract-model mock. |
internal/data/contract_tokens.go |
Adds contract-type lookup. |
internal/data/contract_tokens_test.go |
Tests contract-type lookup. |
go.mod |
Promotes YAML to a direct dependency. |
docs/data-migrations/running-a-data-migration.md |
Documents token hiding. |
docker-compose.yaml |
Documents container configuration. |
cmd/utils/global_options.go |
Defines the configuration option. |
cmd/serve.go |
Registers the serve flag. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
aditya1702
force-pushed
the
ignored-contracts
branch
from
October 8, 2026 20:07
c0f9867 to
98544ee
Compare
aditya1702
force-pushed
the
ignored-contracts
branch
from
October 8, 2026 20:24
98544ee to
92a5a73
Compare
aditya1702
force-pushed
the
ignored-contracts
branch
from
October 9, 2026 20:52
92a5a73 to
4b5ef35
Compare
aditya1702
force-pushed
the
ignored-contracts
branch
from
October 9, 2026 20:57
4b5ef35 to
0c7f48a
Compare
Some contracts match a protocol's interface but their balances cannot be derived the way that protocol's processor does it, and some tokens an operator does not want shown at all. The hidden-contracts list names them by contract ID. The binary embeds a default list; the --hidden-contracts-file flag (HIDDEN_CONTRACTS_FILE) replaces it with the operator's own file. Ingestion is not involved: processing continues, only the API skips the rows. Each entry names the contract and the protocol whose rows are hidden. A token belongs to one protocol at a time, so that is exactly the set of rows written for it; a token that a later, dedicated processor takes over shows that processor's rows while the old ones stay hidden. The loader validates each entry at startup: a bad address, a missing or unknown protocol, an empty reason, a repeated contract and protocol, an unknown field or a missing top-level key fails the process. It exposes the contracts in the forms the reads need: the 33-byte address stored in state_changes.token_id with the protocol's state_change_id range, and the C-address the SEP-41 tables join on. The default list hides the Comet LP pool (CPAL) from SEP-41. Its deployed code mints LP shares without emitting an event, so SEP-41 event arithmetic drives its balances negative.
…nce reads The API server loads the hidden-contracts list at startup and every read skips them. The six state_changes reads drop rows whose token_id is hidden and whose state_change_id falls in the named processor's emitter range; rows with no token are kept. The SEP-41 balance and allowance reads drop the hidden contracts by address through the contract_tokens join they already make. The predicate is a post-filter on rows already selected by account, transaction or operation: it adds no index or plan change, and with an empty list the SQL is unchanged. The read tests open their pool in pgx's Exec query mode, as the API server does, so parameter encoding is exercised the way production runs it. Rows are hidden, never deleted, and ingestion keeps writing them. Removing an entry and restarting serve shows a complete history again.
Adds a "Hiding a token" section to the data-migrations runbook: when to use it, how to add and remove an entry, that ingestion keeps processing the contract, and the file format. docker-compose shows the env var on the api service.
aditya1702
force-pushed
the
ignored-contracts
branch
from
October 9, 2026 21:02
0c7f48a to
62195a9
Compare
JiahuiWho
approved these changes
Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
The Comet LP pool (CPAL) looks like a SEP-41 token, but it mints shares without emitting an event. We compute negative balances for it and serve them today. Scam tokens need the same fix.
Part of #610.
What changes
A YAML list of contracts the API hides.
servereads it at startup.HIDDEN_CONTRACTS_FILEreplaces it with your own file.serveto get the full history back.A bad entry stops
serveat startup.Not in this PR
Where to look
internal/serve/hidden_contracts.go,internal/serve/serve.gointernal/data/statechanges.go,internal/data/sep41/{balances,allowances}.godocs/data-migrations/running-a-data-migration.mdVerify
Restart
serve. A CPAL holder shows no CPAL balance or history.sep41_balancesis unchanged.🤖 Generated with Claude Code