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.prisma — TokenTransfer model (from/to/amount/contract)
Suggested execution
git checkout -b feat/accounts-balance-endpoint
- Create
src/routes/accounts.ts
- SQL aggregation: sum
amount where to = address, minus sum where from = address, grouped by contractId
- Return JSON:
{ balances: [{ token: "C...", balance: "12.50" }] }
- Add a note in the response that this is a derived balance — may not include pre-indexer history
- Register at
GET /accounts/:address/balance
Example commit message:
feat(api): add /accounts/:address/balance derived balance endpoint
Acceptance criteria
Drips Wave · Complexity: Medium · 150 points
Comment below to request assignment. PR must include Closes #[this issue].
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/balanceendpoint 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 filesrc/server.ts— register the new routeprisma/schema.prisma—TokenTransfermodel (from/to/amount/contract)Suggested execution
src/routes/accounts.tsamountwhereto = address, minus sum wherefrom = address, grouped bycontractId{ balances: [{ token: "C...", balance: "12.50" }] }GET /accounts/:address/balanceExample commit message:
feat(api): add /accounts/:address/balance derived balance endpointAcceptance criteria
derived_from_ledgerfield