diff --git a/src/monitor/Monitor.ts b/src/monitor/Monitor.ts index 0b488694e..0182ef912 100644 --- a/src/monitor/Monitor.ts +++ b/src/monitor/Monitor.ts @@ -44,10 +44,10 @@ import { getWidestPossibleExpectedBlockRange, utils, } from "../utils"; - import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper"; import { MonitorConfig } from "./MonitorConfig"; import { CombinedRefunds } from "../dataworker/DataworkerUtils"; +import { PUBLIC_NETWORKS } from "@across-protocol/constants"; // 60 minutes, which is the length of the challenge window, so if a rebalance takes longer than this to finalize, // then its finalizing after the subsequent challenge period has started, which is sub-optimal. @@ -296,17 +296,20 @@ export class Monitor { message: `Balance report for ${relayer} 📖`, mrkdwn, }); - - // Note: types are here for clarity, not necessity. - - Object.entries(reports).forEach(([relayer, balanceTable]) => { - Object.entries(balanceTable).forEach(([tokenSymbol, columns]) => { - const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals; - if (!decimals) { - throw new Error(`No decimals found for ${tokenSymbol}`); - } - Object.entries(columns).forEach(([chainName, cell]) => { + } + Object.entries(reports).forEach(([relayer, balanceTable]) => { + Object.entries(balanceTable).forEach(([tokenSymbol, columns]) => { + const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals; + if (!decimals) { + throw new Error(`No decimals found for ${tokenSymbol}`); + } + Object.entries(columns).forEach(([chainName, cell]) => { + if (this._tokenEnabledForNetwork(tokenSymbol, chainName)) { Object.entries(cell).forEach(([balanceType, balance]) => { + // Don't log zero balances. + if (balance.isZero()) { + return; + } this.logger.debug({ at: "Monitor#reportRelayerBalances", message: "Machine-readable single balance report", @@ -320,10 +323,10 @@ export class Monitor { datadog: true, }); }); - }); + } }); }); - } + }); } // Update current balances of all tokens on each supported chain for each relayer. @@ -1289,4 +1292,13 @@ export class Monitor { }) ); } + + private _tokenEnabledForNetwork(tokenSymbol: string, networkName: string): boolean { + for (const [chainId, network] of Object.entries(PUBLIC_NETWORKS)) { + if (network.name === networkName) { + return isDefined(TOKEN_SYMBOLS_MAP[tokenSymbol]?.addresses[chainId]); + } + } + return false; + } }