From c71fcefcdd589b3591bf53a50cae2fbe6f866850 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:51:48 +0100 Subject: [PATCH] pass chain as param --- modules/datastudio/datastudio.service.ts | 15 ++++++--------- worker/job-handlers.ts | 12 +++++++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/datastudio/datastudio.service.ts b/modules/datastudio/datastudio.service.ts index 9dcf9ad1e..2c2caeec3 100644 --- a/modules/datastudio/datastudio.service.ts +++ b/modules/datastudio/datastudio.service.ts @@ -12,11 +12,12 @@ import { oneDayInSeconds, secondsPerDay } from '../common/time'; import { isComposableStablePool, isWeightedPoolV2 } from '../pool/lib/pool-utils'; import { networkContext } from '../network/network-context.service'; import { DeploymentEnv } from '../network/network-config-types'; +import { Chain } from '@prisma/client'; export class DatastudioService { constructor(private readonly secretsManager: SecretsManager, private readonly jwtClientHelper: GoogleJwtClient) {} - public async feedPoolData() { + public async feedPoolData(chain: Chain) { const privateKey = await this.secretsManager.getSecret('backend-v3-datafeed-privatekey'); const jwtClient = await this.jwtClientHelper.getAuthorizedSheetsClient(privateKey); @@ -89,7 +90,7 @@ export class DatastudioService { dynamicData: { totalLiquidity: { gte: 5000 }, }, - chain: networkContext.chain, + chain: chain, }, include: { dynamicData: true, @@ -265,11 +266,8 @@ export class DatastudioService { } const rewardsPerDay = parseFloat(rewarder.rewardPerSecond) * secondsPerDay; const rewardsValuePerDay = - tokenService.getPriceForToken( - tokenPrices, - rewarder.tokenAddress, - networkContext.chain, - ) * rewardsPerDay; + tokenService.getPriceForToken(tokenPrices, rewarder.tokenAddress, chain) * + rewardsPerDay; if (rewardsPerDay > 0) { allEmissionDataRows.push([ endOfYesterday.format('DD MMM YYYY'), @@ -313,8 +311,7 @@ export class DatastudioService { } const rewardsPerDay = parseFloat(reward.rewardPerSecond) * secondsPerDay; const rewardsValuePerDay = - tokenService.getPriceForToken(tokenPrices, reward.tokenAddress, networkContext.chain) * - rewardsPerDay; + tokenService.getPriceForToken(tokenPrices, reward.tokenAddress, chain) * rewardsPerDay; if (rewardsPerDay > 0) { allEmissionDataRows.push([ endOfYesterday.format('DD MMM YYYY'), diff --git a/worker/job-handlers.ts b/worker/job-handlers.ts index f08bef652..c17cef87c 100644 --- a/worker/job-handlers.ts +++ b/worker/job-handlers.ts @@ -18,6 +18,7 @@ import { syncLatestFXPrices } from '../modules/token/latest-fx-price'; import { AllNetworkConfigs } from '../modules/network/network-config'; import { sftmxService } from '../modules/sftmx/sftmx.service'; import { JobsController } from '../modules/controllers/jobs-controller'; +import { chainIdToChain } from '../modules/network/chain-id-to-chain'; const runningJobs: Set = new Set(); @@ -282,7 +283,16 @@ export function configureWorkerRoutes(app: Express) { ); break; case 'feed-data-to-datastudio': - await runIfNotAlreadyRunning(job.name, chainId, () => datastudioService.feedPoolData(), res, next); + await runIfNotAlreadyRunning( + job.name, + chainId, + () => { + const chain = chainIdToChain[chainId]; + return datastudioService.feedPoolData(chain); + }, + res, + next, + ); break; case 'sync-latest-reliquary-snapshots': await runIfNotAlreadyRunning(