Skip to content

Add /accounts/:address/balance derived endpoint #34

@Miracle656

Description

@Miracle656

Background

Wraith already stores every token transfer in Postgres. From this data, a derived balance per token can be computed without any live Stellar RPC call. A GET /accounts/:address/balance endpoint would give developers a fast cached balance view — useful for dashboards and analytics tools.

What to build

A new endpoint that computes per-token balance for an address by summing incoming transfers and subtracting outgoing ones.

Key files

  • src/routes/accounts.ts — create this route file
  • src/server.ts — register the new route
  • prisma/schema.prismaTokenTransfer model (from/to/amount/contract)

Suggested execution

git checkout -b feat/accounts-balance-endpoint
  1. Create src/routes/accounts.ts
  2. SQL aggregation: sum amount where to = address, minus sum where from = address, grouped by contractId
  3. Return JSON: { balances: [{ token: "C...", balance: "12.50" }] }
  4. Add a note in the response that this is a derived balance — may not include pre-indexer history
  5. Register at GET /accounts/:address/balance

Example commit message:
feat(api): add /accounts/:address/balance derived balance endpoint

Acceptance criteria

  • Returns per-token derived balance from indexed transfers
  • Response includes derived_from_ledger field
  • Returns empty balances array (not 404) for unknown addresses
  • At least one test case

Drips Wave · Complexity: Medium · 150 points
Comment below to request assignment. PR must include Closes #[this issue].

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions