feat: materialized locked-STX table and v3 principal balance endpoints#2577
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This was referenced Jun 13, 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
This branch introduces a materialized current-state table for locked STX (modeled on
ft_balances) and three new v3 principal balance endpoints, all backed by materialized tables so balances are single-row / index-served lookups rather than multi-version event scans.Locked STX (
stx_locked_balances)stx_locked_balancestable: one row per principal holding the current lock state (amount, unlock burn height, pox version, lock provenance), so a principal's locked STX is a single-row lookup.stake/stake-update/unstakeevents and inherited pox-1..4stx_lockevents; backfilled in the migration from existing canonical lock events.ft_balances).getStxBalance(current tip) and the v2/addresses/:principal/balances/stxendpoint now read locked STX from this table — which also surfaces pox-5 locks in balance responses for the first time. Historical (until_block) reads keep the per-version event scan.New v3 endpoints
GET /extended/v3/principals/:principal/balances/stx— total + spendable (available) balance, a nestedlockedobject, and projectedmempoolbalance (mempool-aware ETag cache).GET /extended/v3/principals/:principal/balances/ft— fungible-token positions, sorted by balance descending, cursor-paginated.GET /extended/v3/principals/:principal/balances/nft— owned NFT instances, cursor-paginated by(asset_identifier, value).Supporting indexes
ft_balances (address, balance DESC, token)andnft_custody (recipient, asset_identifier, value)so the keyset-paginated scans are served directly from an index.Testing
tests/api/pox5/stx-lock.test.ts: stake/unstake materialization, pox-4stx_lockinheritance, reorg recompute, and balance read-path coverage.tests/api/v3/principals.test.ts: the stx/ft/nft balance endpoints incl. cursor pagination and ETag behavior.