Skip to content

feat: materialized locked-STX table and v3 principal balance endpoints#2577

Merged
rafa-stacks merged 8 commits into
pox5from
pox5--locked
Jun 11, 2026
Merged

feat: materialized locked-STX table and v3 principal balance endpoints#2577
rafa-stacks merged 8 commits into
pox5from
pox5--locked

Conversation

@rafa-stacks

@rafa-stacks rafa-stacks commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

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)

  • New stx_locked_balances table: 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.
  • Maintained on write from pox-5 stake / stake-update / unstake events and inherited pox-1..4 stx_lock events; backfilled in the migration from existing canonical lock events.
  • Reorg-safe: affected principals are recomputed from their latest canonical lock-changing event (locked STX is a set/latest-wins value, so it can't be delta-applied like ft_balances).
  • Read-path switch: getStxBalance (current tip) and the v2 /addresses/:principal/balances/stx endpoint 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 nested locked object, and projected mempool balance (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) and nft_custody (recipient, asset_identifier, value) so the keyset-paginated scans are served directly from an index.

Testing

  • New tests/api/pox5/stx-lock.test.ts: stake/unstake materialization, pox-4 stx_lock inheritance, reorg recompute, and balance read-path coverage.
  • Extended tests/api/v3/principals.test.ts: the stx/ft/nft balance endpoints incl. cursor pagination and ETag behavior.

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

@rafa-stacks rafa-stacks changed the title feat: introduce new v3 balance endpoints feat: materialized locked-STX table and v3 principal balance endpoints Jun 11, 2026
@rafa-stacks rafa-stacks merged commit 51d1740 into pox5 Jun 11, 2026
20 checks passed
@rafa-stacks rafa-stacks deleted the pox5--locked branch June 11, 2026 18:39
@github-project-automation github-project-automation Bot moved this to ✅ Done in API Board Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant