feat: per-token on-chain balance breakdown on GET /balance - #262
Merged
Conversation
Accounts are chart-of-accounts buckets, not wallets — nothing prevents a
single account receiving both FiatEntry and OnChainEntry postings, and the
README's own pitch assumes it ("a single transaction can contain a PIX
debit and a USDC credit on Base"). GET /balance previously reported 0 for
the on-chain side with no indication anything was missing.
Adds a per-token on-chain breakdown alongside the existing fiat amount:
- core: BalanceCalculator.computeOnChain() nets debits/credits per
StablecoinToken across all chains, mirroring the existing fiat compute()
- application/infrastructure: Balance.onChainBalances, wired through
GetBalanceService
- api/sdk-kotlin: additive OnChainBalanceResponse field on BalanceResponse
- mcp: getBalance tool result carries the same breakdown for agent callers
No single combined total — fiat and on-chain amounts are never summed;
they are not fungible units and nothing else in the codebase treats a
stablecoin as fiat-equivalent outside one hardcoded travel-rule threshold
table. Additive API change: existing BalanceResponse fields are untouched.
Verified live: an account watched by the Alchemy webhook holding a 2.5
USDC OnChainEntry now returns amount=0 (fiat, unchanged) alongside
onChainBalances=[{token: USDC, amount: 2.5}].
Signed-off-by: ifsantana <flaubert165@gmail.com>
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
ifsantana
pushed a commit
that referenced
this pull request
Aug 16, 2026
PR #262 added core.ledger.OnChainBalance and BalanceCalculator.computeOnChain() for the per-token on-chain balance breakdown, but docs/domain-model.md — the reference spec for the core module — never mentioned it. Signed-off-by: Claude <noreply@anthropic.com>
7 tasks
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
GET /api/v1/accounts/{id}/balanceand the MCPgetBalancetool, alongside the existing fiatamount— additive, no combined total, no cross-unit arithmetic.core(BalanceCalculator.computeOnChain),application/infrastructure(Balance.onChainBalances,GetBalanceService),api/sdk-kotlin(OnChainBalanceResponse),mcp(BalanceResult.onChainBalances).### Query balancesection anddocs/mcp-server.md'sBalanceResultsignature.Why: accounts here are chart-of-accounts buckets, not wallets — nothing prevents a single account from receiving both
FiatEntryandOnChainEntrypostings, and the README's own pitch assumes it.GET /balancewas silently reporting0for the on-chain side with no indication anything was missing.Design (confirmed during planning):
BalanceResponsefields are untouched.Closes #256
Test plan
./mvnw verify— full reactor, all 8 modules,BUILD SUCCESSOnChainEntry(posted earlier in E2E testing) now returnsamount: 0(fiat, unchanged) alongsideonChainBalances: [{token: USDC, amount: 2.5}]idem-examplesStablecoinOnChainExamplestill runs clean against the running instance