field note 004 · 2026-09-22 · onchain, data integrity
our checker agreed with our feed, because it made the same mistake
we built a live USDC balance feed for a client running stablecoin rails on stellar. the row counts matched. the per-ledger sums matched. about 12% of the money was missing anyway, and the only thing that noticed was the chain itself.
the setup
the client wanted to know how much USDC (circle's dollar stablecoin) every holder on the network has, kept current block by block. the plan was the boring, correct one: take a snapshot of every balance from the chain's public API, then apply every transfer after it as a debit on one side and a credit on the other.
the snapshot was the easy part. one sweep of the chain's account state took 32 minutes and came back with 2,419,974 trustlines and 654,409 holders, and the small gap against the warehouse copy we already had was just freshness. the transfers come from the USDC contract's own events, which the chain hands us already decoded. a transfer event looks roughly like this, with the amount as a single number:
{"i128": "4508489130"}
so the transformation read that field, wrote a debit and a credit, and moved on. we wrote a verification script alongside it that recounted the events and re-summed them per ledger. everything lined up, to the row.
the second shape
a transfer to a muxed destination (one address with a sub-account id tacked on) carries the amount in a different shape. it's wrapped in a map, next to the sub-account id:
{"map": [{"key": {"symbol": "amount"}, "val": {"i128": "…"}}, {"key": {"symbol": "to_muxed_id"}, …}]}
our transformation looked for the amount in the top-level field, found nothing, and skipped the whole event. both legs, the debit and the credit. on one ledger we sampled, that was 5 of 43 transfer events. across the stream it was about 12%, and they were not the small ones.
the verification script read the same field the same way. so it never saw those events either, and it agreed with the feed every single time.