fix: refresh BTC balances from chain instead of Trust/TokenView totals
Webhook and ingest were writing Trust/client numbers (often sats or lifetime received) into wallet_addresses.btc, so alerts showed fake balances like 48 BTC. Use mempool funded-spent like Tron. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -197,15 +197,16 @@ class TokenviewMonitorService
|
||||
return;
|
||||
}
|
||||
|
||||
$tronRows = $rows->filter(function (WalletAddress $row) {
|
||||
return in_array(strtoupper((string) $row->chain_type), ['TRON', 'TRX'], true);
|
||||
$refreshRows = $rows->filter(function (WalletAddress $row) {
|
||||
return in_array(strtoupper((string) $row->chain_type), ['TRON', 'TRX', 'BTC', 'BITCOIN'], true);
|
||||
});
|
||||
$deltaRows = $rows->filter(function (WalletAddress $row) {
|
||||
return ! in_array(strtoupper((string) $row->chain_type), ['TRON', 'TRX'], true);
|
||||
return ! in_array(strtoupper((string) $row->chain_type), ['TRON', 'TRX', 'BTC', 'BITCOIN'], true);
|
||||
});
|
||||
|
||||
// Tron webhooks only carry deltas — refresh TRX/USDT from chain as source of truth.
|
||||
foreach ($tronRows as $row) {
|
||||
// Tron/BTC webhooks only carry deltas — refresh from chain as source of truth.
|
||||
// BTC stored `btc` is often Trust/client sats-or-lifetime totals, not current UTXO.
|
||||
foreach ($refreshRows as $row) {
|
||||
/** @var WalletAddress $row */
|
||||
if (! $this->balances->refresh($row)) {
|
||||
$this->applyDeltasToRow($row, $deltas);
|
||||
|
||||
Reference in New Issue
Block a user