feat(balances): persist subentry count#649
Merged
Merged
Conversation
Read account.NumSubEntries in the accounts processor and persist it end-to-end into native_balances via a new num_subentries column, through both the live-ingest upsert path and the checkpoint COPY path. Expose it as NativeBalance.numSubentries on the GraphQL API and the wbclient SDK. The DB is re-migrated from scratch (pre-prod), so the column is added to the existing native_balances CREATE TABLE rather than via a new ALTER. Surfaces the v1 subentry_count field for the Freighter v2 balances migration.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the balances data model and API surface to support the v1→v2 balances migration by (1) persisting and exposing native numSubentries, and (2) exposing SAC token name/symbol sourced from contract_tokens.
Changes:
- Persist
num_subentriesfor native balances through ingestion, checkpoint population, storage, GraphQL, and the wbclient SDK. - Expose SAC
nameandsymbolvia the data read path, GraphQL, and the wbclient SDK. - Add/extend unit tests to validate the new round-trips and resolver mappings.
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/wbclient/types/types.go | Adds NumSubentries to native balance and Name/Symbol to SAC balance SDK types. |
| internal/services/token_ingestion.go | Carries NumSubEntries from indexer changes into native balance upserts. |
| internal/services/checkpoint.go | Persists NumSubEntries during checkpoint-based population into native balances. |
| internal/serve/graphql/schema/balances.graphqls | Adds numSubentries to NativeBalance and name/symbol to SACBalance in the GraphQL schema. |
| internal/serve/graphql/resolvers/account_balances_utils.go | Maps DB models to GraphQL models for new native/SAC fields. |
| internal/serve/graphql/resolvers/account_balances_utils_test.go | Adds resolver unit tests for numSubentries, name, and symbol. |
| internal/serve/graphql/generated/models_gen.go | Regenerates GraphQL models to include new fields. |
| internal/serve/graphql/generated/generated.go | Regenerates GraphQL execution code to include new fields and complexity hooks. |
| internal/indexer/types/types.go | Adds NumSubEntries to AccountChange for ingestion propagation. |
| internal/indexer/processors/accounts.go | Sets AccountChange.NumSubEntries from ledger account entry. |
| internal/indexer/processors/accounts_test.go | Adds test ensuring NumSubEntries is persisted through account processing. |
| internal/db/migrations/2026-01-15.0-native_balances.sql | Adds num_subentries column to the native balances schema definition. |
| internal/data/sac_balances.go | Extends SAC balance query/model to include ct.name and ct.symbol. |
| internal/data/sac_balances_test.go | Adds coverage for populated vs NULL SAC name/symbol. |
| internal/data/native_balances.go | Extends native balance model queries and write paths to include num_subentries. |
| internal/data/native_balances_test.go | Adds coverage for num_subentries in GetByAccount/BatchUpsert/BatchCopy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Closed
1492465 to
4731376
Compare
aristidesstaffieri
approved these changes
Jul 2, 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.
Summary
Persist the account subentry count end-to-end so the Freighter v2 balances API can surface the v1
subentry_countfield (part of the v1→v2 balances migration).account.NumSubEntrieswas read in the accounts processor only to computeMinimumBalance, then discarded. It is now persisted:num_subentries INTEGER NOT NULL DEFAULT 0onnative_balances(added to the existingCREATE TABLE— the DB re-migrates from scratch, pre-prod).AccountChange, written via both the live-ingestBatchUpsert(UNNEST +ON CONFLICT) and the checkpointBatchCopypaths.NativeBalance.numSubentries: UInt32!(GraphQL) andNativeBalance.NumSubentries(wbclient SDK).The
MinimumBalanceformula is unchanged.Testing
make check— clean (0 lint issues, no deadcode, gql-validate passes).make unit-test(race) — full suite green, incl. DB-backednative_balancesmodel tests viadbtest.num_subentriesround-trips through GetByAccount/BatchUpsert/BatchCopy;buildAccountChangesetsNumSubEntries;buildNativeBalanceFromDBsetsnumSubentries.GraphQL generated code was regenerated via
make gql-generate(not hand-edited).Closes #651