feat: add asset reconciliation endpoint#3494
Merged
TaprootFreak merged 15 commits intodevelopfrom Mar 27, 2026
Merged
Conversation
Add read-only admin endpoint GET /balance/reconciliation that verifies start + inflows - outflows = end for any asset over a given period. Supports blockchain, exchange, and bank assets with LM deduplication.
…trades - Bank flows: query by tx.accountIban instead of batch.iban (most bank_tx records link to the account IBAN directly, not via batch) - Exchange trades: parse symbol field (e.g. "BTC/USDT") as fallback when currency/pair are null (Binance trade format)
- Filter out Lightning Network withdrawals (lnbc* addresses) from blockchain inflow calculation — these don't hit the on-chain wallet - Track withdrawal/deposit fees as exchange outflows (not just trade fees) to capture network fees deducted by exchanges like Binance
Use only liquidityBalance.total for balance snapshots, falling back to 0 if missing. The previous liquidity.total fallback included paymentDeposit balances which would produce inconsistent reconciliation results.
- Add @apitags('Balance') to ReconciliationController - Add DfxLogger with warning on financial log parse failures - Parameterize NOT LIKE pattern in QueryBuilder
Group flows by counter-account (exchange/customer), resolve LM order correlationIds to blockchain txIds via ExchangeTx lookup, filter zero-amount groups, and sub-group bank flows by transaction type.
Parse destinationSystem from LM action params when system is DfxDex, so counter-account shows Binance/BTC instead of DfxDex/BTC.
…thdrawals Resolves Binance/BTC showing itself as counter-account. Deposits and withdrawals now correctly reference Bitcoin/BTC (the blockchain wallet).
USDT → Binance/USDT, WBTC → Binance/WBTC for proper account names.
Filter by uniqueName LIKE '%/BTC' to exclude DeFiChain/dBTC, and order by ID to prefer Bitcoin/BTC over Lightning/BTC.
New endpoint GET /balance/reconciliation/overview runs reconciliation for all assets, showing start/end balance, inflows, outflows, and unexplained differences per account.
Prevents ETH withdrawals to Ethereum mainnet from being counted as inflows for Arbitrum/ETH, Optimism/ETH, etc. Uses blockchain-specific wallet addresses from environment variables to filter.
❌ ESLint: 2 errors, 1 warnings |
davidleomay
approved these changes
Mar 26, 2026
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 /balance/reconciliation?assetId=X&from=DATE&to=DATEfor auditing asset balancesstartBalance + inflows - outflows = endBalancefor any asset over a given periodFinancialDataLogsnapshots; also adds reusablegetFinancialLogAt()toLogRepositoryRoleGuard(UserRole.DEBUG), excluded from Swagger docsTest plan
GET /balance/reconciliation?assetId=113&from=2026-03-01&to=2026-03-21(Bitcoin/BTC) — difference should be ~-0.00063 BTC🤖 Generated with Claude Code