Skip to content

feat(balances): persist subentry count#649

Merged
aditya1702 merged 1 commit into
mainfrom
feat/balances-subentry-sac
Jul 2, 2026
Merged

feat(balances): persist subentry count#649
aditya1702 merged 1 commit into
mainfrom
feat/balances-subentry-sac

Conversation

@aditya1702

@aditya1702 aditya1702 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Persist the account subentry count end-to-end so the Freighter v2 balances API can surface the v1 subentry_count field (part of the v1→v2 balances migration).

account.NumSubEntries was read in the accounts processor only to compute MinimumBalance, then discarded. It is now persisted:

  • Schema: new num_subentries INTEGER NOT NULL DEFAULT 0 on native_balances (added to the existing CREATE TABLE — the DB re-migrates from scratch, pre-prod).
  • Ingestion: carried on AccountChange, written via both the live-ingest BatchUpsert (UNNEST + ON CONFLICT) and the checkpoint BatchCopy paths.
  • API/SDK: exposed as NativeBalance.numSubentries: UInt32! (GraphQL) and NativeBalance.NumSubentries (wbclient SDK).

The MinimumBalance formula is unchanged.

Testing

  • make check — clean (0 lint issues, no deadcode, gql-validate passes).
  • make unit-test (race) — full suite green, incl. DB-backed native_balances model tests via dbtest.
  • Added coverage: num_subentries round-trips through GetByAccount/BatchUpsert/BatchCopy; buildAccountChange sets NumSubEntries; buildNativeBalanceFromDB sets numSubentries.

GraphQL generated code was regenerated via make gql-generate (not hand-edited).

Closes #651

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.
Copilot AI review requested due to automatic review settings July 2, 2026 16:02
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

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

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_subentries for native balances through ingestion, checkpoint population, storage, GraphQL, and the wbclient SDK.
  • Expose SAC name and symbol via 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.

Comment thread internal/db/migrations/2026-01-15.0-native_balances.sql
@aditya1702 aditya1702 mentioned this pull request Jul 2, 2026
@aditya1702 aditya1702 force-pushed the feat/balances-subentry-sac branch from 1492465 to 4731376 Compare July 2, 2026 17:27
@aditya1702 aditya1702 changed the title feat(balances): persist subentry count + expose SAC symbol/name feat(balances): persist subentry count Jul 2, 2026
@aditya1702 aditya1702 merged commit ddde75e into main Jul 2, 2026
9 checks passed
@aditya1702 aditya1702 deleted the feat/balances-subentry-sac branch July 2, 2026 19:12
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.

Persist subentry count

3 participants