Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(logs): distinguish usdc in rebalance logs #1508

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/clients/InventoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
toBNWei,
assert,
compareAddressesSimple,
getUsdcSymbol,
} from "../utils";
import { HubPoolClient, TokenClient, BundleDataClient } from ".";
import { AdapterManager, CrossChainTransferClient } from "./bridges";
Expand Down Expand Up @@ -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 ` +
Expand All @@ -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 +=
Expand Down
28 changes: 27 additions & 1 deletion src/clients/bridges/CrossChainTransferClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/utils/AddressUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading