Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/subdomains/supporting/log/log-job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ export class LogJobService {
}

// total pending balance
const totalPlusPending =
let totalPlusPending =
cryptoInput +
exchangeOrder +
bridgeOrder +
Expand All @@ -803,6 +803,19 @@ export class LogJobService {
(useUnfilteredTx ? fromScryptUnfiltered : fromScrypt) +
(useUnfilteredTx ? toScryptUnfiltered : toScrypt);

// Clamp totalPlusPending to prevent negative plus balances
// This catches any negative values from unfiltered Kraken/Scrypt or other components
if (totalPlusPending < 0) {
errors.push(`totalPlusPending < 0`);
this.logger.verbose(
`Error in financial log, totalPlusPending < 0 for asset: ${curr.id}, totalPlusPending: ${totalPlusPending}. ` +
`Components: cryptoInput=${cryptoInput}, exchangeOrder=${exchangeOrder}, bridgeOrder=${bridgeOrder}, ` +
`olky=${pendingOlkyYapealAmount}, kraken=${useUnfilteredTx ? fromKrakenUnfiltered : fromKraken}+${useUnfilteredTx ? toKrakenUnfiltered : toKraken}, ` +
`scrypt=${useUnfilteredTx ? fromScryptUnfiltered : fromScrypt}+${useUnfilteredTx ? toScryptUnfiltered : toScrypt}`,
);
totalPlusPending = 0;
}

const totalPlus = liquidity + totalPlusPending + (totalCustomBalance ?? 0);

// minus
Expand Down
Loading