Skip to content

Commit

Permalink
feat(warpMonitor): Always use collateral token symbol for building wa…
Browse files Browse the repository at this point in the history
…rp routes id
  • Loading branch information
Mo-Hussain committed Dec 18, 2024
1 parent 7c0c967 commit caa68db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion typescript/infra/scripts/warp-routes/monitor/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function updateTokenBalanceMetrics(
warpCore: WarpCore,
token: Token,
balanceInfo: WarpRouteBalance,
collateralTokenSymbol: string,
) {
const metrics: WarpRouteMetrics = {
chain_name: token.chainName,
Expand All @@ -67,7 +68,7 @@ export function updateTokenBalanceMetrics(
wallet_address: token.addressOrDenom,
token_standard: token.standard,
warp_route_id: createWarpRouteConfigId(
token.symbol,
collateralTokenSymbol,
warpCore.getTokenChains(),
),
related_chain_names: warpCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ async function pollAndUpdateWarpRouteMetrics(
chainMetadata,
apiKey: await getCoinGeckoApiKey(),
});
const collateralTokenSymbol = getWarpRouteCollateralTokenSymbol(warpCore);

while (true) {
await tryFn(async () => {
await Promise.all(
warpCore.tokens.map((token) =>
updateTokenMetrics(warpCore, token, tokenPriceGetter),
updateTokenMetrics(
warpCore,
token,
tokenPriceGetter,
collateralTokenSymbol,
),
),
);
}, 'Updating warp route metrics');
Expand All @@ -107,6 +113,7 @@ async function updateTokenMetrics(
warpCore: WarpCore,
token: Token,
tokenPriceGetter: CoinGeckoTokenPriceGetter,
collateralTokenSymbol: string,
) {
const promises = [
tryFn(async () => {
Expand All @@ -118,7 +125,12 @@ async function updateTokenMetrics(
if (!balanceInfo) {
return;
}
updateTokenBalanceMetrics(warpCore, token, balanceInfo);
updateTokenBalanceMetrics(
warpCore,
token,
balanceInfo,
collateralTokenSymbol,
);
}, 'Getting bridged balance and value'),
];

Expand Down Expand Up @@ -310,6 +322,18 @@ async function getCoinGeckoApiKey(): Promise<string | undefined> {
return apiKey;
}

function getWarpRouteCollateralTokenSymbol(warpCore: WarpCore): string {
const collateralToken = warpCore.tokens.find(
(token) =>
token.isCollateralized() ||
token.standard === TokenStandard.EvmHypXERC20Lockbox,
);
if (!collateralToken) {
throw new Error('No collateral token found in warp route');
}
return collateralToken.symbol;
}

main().catch((err) => {
logger.error('Error in main:', err);
process.exit(1);
Expand Down

0 comments on commit caa68db

Please sign in to comment.