From fb7723513e785d39aafafb42f5d22ba565b00cd6 Mon Sep 17 00:00:00 2001 From: Paul Noel Date: Thu, 25 Apr 2024 16:03:10 -0500 Subject: [PATCH] cloud_functions: more rework --- cloud_functions/src/computeMessageCountHistory.ts | 8 ++------ cloud_functions/src/consts.ts | 4 ++-- cloud_functions/src/getReobserveVaas.ts | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cloud_functions/src/computeMessageCountHistory.ts b/cloud_functions/src/computeMessageCountHistory.ts index 69562676..6e0ff803 100644 --- a/cloud_functions/src/computeMessageCountHistory.ts +++ b/cloud_functions/src/computeMessageCountHistory.ts @@ -3,7 +3,7 @@ import { assertEnvironmentVariable } from './utils'; import { Firestore } from 'firebase-admin/firestore'; import { MessageCountsHistory } from './types'; import { deserialize } from '@wormhole-foundation/sdk-definitions'; -import { stringToChainId } from '@wormhole-foundation/wormhole-monitor-common'; +import { chainToChainId } from '@wormhole-foundation/sdk-base'; export async function computeMessageCountHistory(req: any, res: any) { res.set('Access-Control-Allow-Origin', '*'); @@ -46,11 +46,7 @@ export async function computeMessageCountHistory(req: any, res: any) { continue; } const date = new Date(parsed.timestamp * 1000).toISOString().slice(0, 10); - const chainId = stringToChainId(parsed.emitterChain); - if (!chainId) { - console.error(`Unknown emitter chain: ${parsed.emitterChain}`); - continue; - } + const chainId = chainToChainId(parsed.emitterChain); messageCounts.DailyTotals[date] = { ...messageCounts.DailyTotals[date], [chainId]: (messageCounts.DailyTotals[date]?.[chainId] || 0) + 1, diff --git a/cloud_functions/src/consts.ts b/cloud_functions/src/consts.ts index 540227b7..7fd4e14d 100644 --- a/cloud_functions/src/consts.ts +++ b/cloud_functions/src/consts.ts @@ -1,8 +1,8 @@ -import { ChainId, toChainId } from '@wormhole-foundation/sdk-base'; +import { ChainId, chainToChainId } from '@wormhole-foundation/sdk-base'; // TODO: this should probably be a table in the database export const TVL_TOKEN_DENYLIST: { [key in ChainId]?: string[] } = { - [toChainId('Fantom')]: ['0x5b2af7fd27e2ea14945c82dd254c79d3ed34685e'], // coingecko reporting bad prices + [chainToChainId('Fantom')]: ['0x5b2af7fd27e2ea14945c82dd254c79d3ed34685e'], // coingecko reporting bad prices }; export const isTokenDenylisted = (chainId: ChainId, address: string): boolean => { diff --git a/cloud_functions/src/getReobserveVaas.ts b/cloud_functions/src/getReobserveVaas.ts index 249ae859..b2ff0738 100644 --- a/cloud_functions/src/getReobserveVaas.ts +++ b/cloud_functions/src/getReobserveVaas.ts @@ -1,5 +1,5 @@ import { Connection } from '@solana/web3.js'; -import { contracts, toChainId } from '@wormhole-foundation/sdk-base'; +import { chainToChainId, contracts } from '@wormhole-foundation/sdk-base'; import { getNetwork, isLegacyMessage, @@ -114,7 +114,7 @@ async function getAndProcessReobsVAAs(): Promise> { // So we put the rest back in the collection let solanaCount = 0; for (const vaa of vaas) { - if (vaa.chain === toChainId('Solana')) { + if (vaa.chain === chainToChainId('Solana')) { solanaCount++; if (solanaCount > MAX_SOLANA_VAAS_TO_REOBSERVE) { putBack.push(vaa); @@ -143,7 +143,7 @@ async function getAndProcessReobsVAAs(): Promise> { async function processVaa(vaa: ReobserveInfo): Promise { let vaas: ReobserveInfo[] = []; - if (vaa.chain === toChainId('Solana')) { + if (vaa.chain === chainToChainId('Solana')) { const origTxHash = vaa.txhash; const convertedTxHash: string[] = await convertSolanaTxToAccts(origTxHash); console.log(`Converted solana txHash ${origTxHash} to account ${convertedTxHash}`);