diff --git a/src/clients/InventoryClient.ts b/src/clients/InventoryClient.ts index b2c482f65..7a23ce141 100644 --- a/src/clients/InventoryClient.ts +++ b/src/clients/InventoryClient.ts @@ -22,6 +22,7 @@ import { toBNWei, assert, compareAddressesSimple, + getUsdcSymbol, } from "../utils"; import { HubPoolClient, TokenClient, BundleDataClient } from "."; import { AdapterManager, CrossChainTransferClient } from "./bridges"; @@ -823,7 +824,8 @@ export class InventoryClient { if (!tokenInfo) { throw new Error(`InventoryClient::rebalanceInventoryIfNeeded no L1 token info for token ${l1Token}`); } - const { symbol, decimals } = tokenInfo; + const { symbol: _symbol, decimals } = tokenInfo; + const symbol = _symbol.toLowerCase() === "usdc" ? getUsdcSymbol(l2Token, chainId) : _symbol; const formatter = createFormatFunction(2, 4, false, decimals); mrkdwn += ` - ${formatter(amount.toString())} ${symbol} rebalanced. This meets target allocation of ` + @@ -846,7 +848,8 @@ export class InventoryClient { if (!tokenInfo) { throw new Error(`InventoryClient::rebalanceInventoryIfNeeded no L1 token info for token ${l1Token}`); } - const { symbol, decimals } = tokenInfo; + const { symbol: _symbol, decimals } = tokenInfo; + const symbol = _symbol.toLowerCase() === "usdc" ? getUsdcSymbol(l2Token, chainId) : _symbol; const formatter = createFormatFunction(2, 4, false, decimals); const distributionPct = tokenDistributionPerL1Token[l1Token][chainId][l2Token].mul(100); mrkdwn += diff --git a/src/clients/bridges/CrossChainTransferClient.ts b/src/clients/bridges/CrossChainTransferClient.ts index e6c67839d..992dae90f 100644 --- a/src/clients/bridges/CrossChainTransferClient.ts +++ b/src/clients/bridges/CrossChainTransferClient.ts @@ -11,7 +11,14 @@ export class CrossChainTransferClient { readonly adapterManager: AdapterManager ) {} - // Get any funds currently in the canonical bridge. + /** + * Retrieves the total amount of outstanding cross-chain transfers for a given address. + * @param address The address to check for outstanding transfers. + * @param chainId The chainId to check for outstanding transfers. + * @param l1Token The L1 token to check for outstanding transfers. + * @param l2Token The L2 token to check for outstanding transfers - If not provided, the sum of all l2Tokens will be returned. + * @returns The total amount of outstanding cross-chain transfers for the given address. + */ getOutstandingCrossChainTransferAmount( address: string, chainId: number | string, @@ -31,6 +38,14 @@ export class CrossChainTransferClient { return Object.values(transfers).reduce((acc, { totalAmount }) => acc.add(totalAmount), bnZero); } + /** + * Retrieves the tx hashes of outstanding cross-chain transfers for a given address. + * @param address The address to check for outstanding transfers. + * @param chainId The chainId to check for outstanding transfers. + * @param l1Token The L1 token to check for outstanding transfers. + * @param l2Token The L2 token to check for outstanding transfers - If not provided, the sum of all l2Tokens will be returned. + * @returns The tx hashes of outstanding cross-chain transfers for the given address. + */ getOutstandingCrossChainTransferTxs( address: string, chainId: number | string, @@ -50,6 +65,17 @@ export class CrossChainTransferClient { return Object.values(transfers).flatMap(({ depositTxHashes }) => depositTxHashes); } + /** + * Retrieves a list of outstanding L2 addresses for a given L1 token, address, and chainId. + * @param address The monitored address to check for outstanding transfers. + * @param chainId The chainId to check for outstanding transfers. + * @param l1Token The L1 token to check for outstanding transfers. + * @returns A list of outstanding L2 addresses for the given L1 token, address, and chainId. + */ + getOutstandingL2AddressesForL1Token(address: string, chainId: number | string, l1Token: string): string[] { + return Object.keys(this.outstandingCrossChainTransfers[Number(chainId)]?.[address]?.[l1Token] ?? {}); + } + getEnabledChains(): number[] { return this.chainIdList; } diff --git a/src/utils/AddressUtils.ts b/src/utils/AddressUtils.ts index 7d0b429c0..dfc9f2fac 100644 --- a/src/utils/AddressUtils.ts +++ b/src/utils/AddressUtils.ts @@ -83,6 +83,17 @@ export function getTokenAddress(tokenAddress: string, chainId: number, targetCha return targetAddress; } +/** + * Get the USDC symbol for the given token address and chain ID. + * @param l2Token A Web3 token address (not case sensitive) + * @param chainId A chain Id to reference + * @returns Either USDC (if native) or USDbC/USDC.e (if bridged) or undefined if the token address is not recognized. + */ +export function getUsdcSymbol(l2Token: string, chainId: number): string | undefined { + const compareToken = (token?: string) => isDefined(token) && compareAddressesSimple(l2Token, token); + return ["_USDC", "USDbC", "USDC.e"].find((token) => compareToken(TOKEN_SYMBOLS_MAP[token].addresses[chainId])); +} + export function getTokenAddressWithCCTP( l1Token: string, hubChainId: number,