Skip to content

Commit

Permalink
Merge branch 'master' into linea-finalizer-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai authored Dec 5, 2024
2 parents 259ac60 + e393a92 commit 22a1123
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/monitor/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
L1Token,
RelayerBalanceReport,
RelayerBalanceTable,
RelayerBalanceColumns,
RelayerBalanceCell,
TokenTransfer,
} from "../interfaces";
import {
Expand Down Expand Up @@ -44,14 +42,13 @@ import {
resolveTokenDecimals,
sortEventsDescending,
getWidestPossibleExpectedBlockRange,
utils,
} from "../utils";

import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper";
import { MonitorConfig } from "./MonitorConfig";
import { CombinedRefunds } from "../dataworker/DataworkerUtils";

import lodash from "lodash";

// 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.
export const REBALANCE_FINALIZE_GRACE_PERIOD = Number(process.env.REBALANCE_FINALIZE_GRACE_PERIOD ?? 60 * 60);
Expand Down Expand Up @@ -301,22 +298,30 @@ export class Monitor {
});

// Note: types are here for clarity, not necessity.
const machineReadableReport = lodash.mapValues(reports, (table: RelayerBalanceTable) =>
lodash.mapValues(table, (columns: RelayerBalanceColumns, tokenSymbol: string) => {

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}`);
}
return lodash.mapValues(columns, (cell: RelayerBalanceCell) =>
lodash.mapValues(cell, (balance: BigNumber) => Number(convertFromWei(balance.toString(), decimals)))
);
})
);

this.logger.debug({
at: "Monitor#reportRelayerBalances",
message: "Machine-readable balance report",
report: machineReadableReport,
Object.entries(columns).forEach(([chainName, cell]) => {
Object.entries(cell).forEach(([balanceType, balance]) => {
this.logger.debug({
at: "Monitor#reportRelayerBalances",
message: "Machine-readable single balance report",
relayer,
tokenSymbol,
decimals,
chainName,
balanceType,
balanceInWei: balance.toString(),
balance: Number(utils.formatUnits(balance, decimals)),
datadog: true,
});
});
});
});
});
}
}
Expand Down

0 comments on commit 22a1123

Please sign in to comment.