From cd3428ef881b8ac22ba128096489216301933f04 Mon Sep 17 00:00:00 2001 From: nicholaspai <9457025+nicholaspai@users.noreply.github.com> Date: Tue, 21 May 2024 12:15:05 -0400 Subject: [PATCH] improve(reporter): Add special USDC.e entry (#1542) * improve(reporter): Add special USDC.e entry Adds some special logic to break out USDC.e balances from USDC. L1 USDC is counted with Native USDC balance. This is required to be a special case because the balance report uses the L1 token symbol mapped to all L2 tokens as the key, whereas USDC.e and Native USDC on L2s both map to a single USDC token, so we need to invent a "USDC.e" virtual L1 token to keep the structure of the report intact. A more scalable change would have to change the report structure fundamentally. * Update Monitor.ts --- src/monitor/Monitor.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/monitor/Monitor.ts b/src/monitor/Monitor.ts index 4f2cd5514..3da81d23a 100644 --- a/src/monitor/Monitor.ts +++ b/src/monitor/Monitor.ts @@ -28,6 +28,7 @@ import { toBNWei, winston, TOKEN_SYMBOLS_MAP, + compareAddressesSimple, } from "../utils"; import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper"; @@ -216,7 +217,16 @@ export class Monitor { async reportRelayerBalances(): Promise { const relayers = this.monitorConfig.monitoredRelayers; - const allL1Tokens = this.clients.hubPoolClient.getL1Tokens(); + const allL1Tokens = [...this.clients.hubPoolClient.getL1Tokens()]; // @dev deep clone since we modify the + // array below and we don't want to modify the HubPoolClient's version + // @dev Handle special case for L1 USDC which is mapped to two L2 tokens on some chains, so we can more easily + // see L2 Bridged USDC balance versus Native USDC. Add USDC.e right after the USDC element. + const indexOfUsdc = allL1Tokens.findIndex(({ symbol }) => symbol === "USDC"); + allL1Tokens.splice(indexOfUsdc, 0, { + symbol: "USDC.e", + address: TOKEN_SYMBOLS_MAP["USDC.e"].addresses[this.clients.hubPoolClient.chainId], + decimals: 6, + }); const chainIds = this.monitorChains; const allChainNames = chainIds.map(getNetworkName).concat([ALL_CHAINS_NAME]); const reports = this.initializeBalanceReports(relayers, allL1Tokens, allChainNames); @@ -284,9 +294,23 @@ export class Monitor { for (let i = 0; i < l2TokenAddresses.length; i++) { const tokenInfo = l2ToL1Tokens[l2TokenAddresses[i]]; + let l1TokenSymbol = tokenInfo.symbol; + + // @dev Handle special case for USDC so we can see Bridged USDC and Native USDC balances split out. + // HubChain USDC balance will be grouped with Native USDC balance arbitrarily. + const l2TokenAddress = l2TokenAddresses[i]; + if ( + l1TokenSymbol === "USDC" && + chainId !== hubPoolClient.chainId && + (compareAddressesSimple(TOKEN_SYMBOLS_MAP["USDC.e"].addresses[chainId], l2TokenAddress) || + compareAddressesSimple(TOKEN_SYMBOLS_MAP["USDbC"].addresses[chainId], l2TokenAddress)) + ) { + l1TokenSymbol = "USDC.e"; + } + this.updateRelayerBalanceTable( relayerBalanceReport[relayer], - tokenInfo.symbol, + l1TokenSymbol, getNetworkName(chainId), BalanceType.CURRENT, tokenBalances[i]