Skip to content

Commit

Permalink
improve(reporter): Add special USDC.e entry (#1542)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicholaspai authored May 21, 2024
1 parent 9131cef commit cd3428e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/monitor/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
toBNWei,
winston,
TOKEN_SYMBOLS_MAP,
compareAddressesSimple,
} from "../utils";

import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper";
Expand Down Expand Up @@ -216,7 +217,16 @@ export class Monitor {

async reportRelayerBalances(): Promise<void> {
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);
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit cd3428e

Please sign in to comment.