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/modules/pool/lib/pool-apr-updater.service.ts b/modules/pool/lib/pool-apr-updater.service.ts index 4f7fd330b..cde36dd2c 100644 --- a/modules/pool/lib/pool-apr-updater.service.ts +++ b/modules/pool/lib/pool-apr-updater.service.ts @@ -5,6 +5,7 @@ import { PoolAprService } from '../pool-types'; import _ from 'lodash'; import { prismaBulkExecuteOperations } from '../../../prisma/prisma-util'; import { networkContext } from '../../network/network-context.service'; +import { Chain } from '@prisma/client'; export class PoolAprUpdaterService { constructor() {} @@ -13,10 +14,10 @@ export class PoolAprUpdaterService { return networkContext.config.poolAprServices; } - public async updatePoolAprs() { + public async updatePoolAprs(chain: Chain) { const pools = await prisma.prismaPool.findMany({ ...poolWithTokens, - where: { chain: networkContext.chain }, + where: { chain: chain }, }); const failedAprServices = []; @@ -31,7 +32,7 @@ export class PoolAprUpdaterService { } const aprItems = await prisma.prismaPoolAprItem.findMany({ - where: { chain: networkContext.chain }, + where: { chain: chain }, select: { poolId: true, apr: true }, }); @@ -42,7 +43,7 @@ export class PoolAprUpdaterService { for (const poolId in grouped) { operations.push( prisma.prismaPoolDynamicData.update({ - where: { id_chain: { id: poolId, chain: networkContext.chain } }, + where: { id_chain: { id: poolId, chain: chain } }, data: { apr: _.sumBy(grouped[poolId], (item) => item.apr) }, }), ); @@ -54,9 +55,9 @@ export class PoolAprUpdaterService { } } - public async reloadAllPoolAprs() { - await prisma.prismaPoolAprRange.deleteMany({ where: { chain: networkContext.chain } }); - await prisma.prismaPoolAprItem.deleteMany({ where: { chain: networkContext.chain } }); - await this.updatePoolAprs(); + public async reloadAllPoolAprs(chain: Chain) { + await prisma.prismaPoolAprRange.deleteMany({ where: { chain: chain } }); + await prisma.prismaPoolAprItem.deleteMany({ where: { chain: chain } }); + await this.updatePoolAprs(chain); } } diff --git a/modules/pool/pool.gql b/modules/pool/pool.gql index e7f73bf3c..8c585b6ac 100644 --- a/modules/pool/pool.gql +++ b/modules/pool/pool.gql @@ -36,9 +36,9 @@ extend type Mutation { poolUpdateVolumeAndFeeValuesForAllPools: String! poolSyncSwapsForLast48Hours: String! poolSyncSanityPoolData: String! - poolUpdateAprs: String! + poolUpdateAprs(chain: GqlChain!): String! poolSyncPoolAllTokensRelationship: String! - poolReloadAllPoolAprs: String! + poolReloadAllPoolAprs(chain: GqlChain!): String! poolSyncTotalShares: String! poolReloadStakingForAllPools(stakingTypes: [GqlPoolStakingType!]!): String! poolSyncStakingForPools: String! diff --git a/modules/pool/pool.resolvers.ts b/modules/pool/pool.resolvers.ts index 7bf0519f3..f7fa7d834 100644 --- a/modules/pool/pool.resolvers.ts +++ b/modules/pool/pool.resolvers.ts @@ -163,10 +163,10 @@ const balancerResolvers: Resolvers = { return 'success'; }, - poolUpdateAprs: async (parent, {}, context) => { + poolUpdateAprs: async (parent, { chain }, context) => { isAdminRoute(context); - await poolService.updatePoolAprs(); + await poolService.updatePoolAprs(chain); return 'success'; }, @@ -177,10 +177,10 @@ const balancerResolvers: Resolvers = { return 'success'; }, - poolReloadAllPoolAprs: async (parent, {}, context) => { + poolReloadAllPoolAprs: async (parent, { chain }, context) => { isAdminRoute(context); - await poolService.reloadAllPoolAprs(); + await poolService.reloadAllPoolAprs(chain); return 'success'; }, diff --git a/modules/pool/pool.service.ts b/modules/pool/pool.service.ts index 65210659a..451187fd1 100644 --- a/modules/pool/pool.service.ts +++ b/modules/pool/pool.service.ts @@ -254,16 +254,16 @@ export class PoolService { await Promise.all(this.poolStakingServices.map((stakingService) => stakingService.syncStakingForPools())); } - public async updatePoolAprs() { - await this.poolAprUpdaterService.updatePoolAprs(); + public async updatePoolAprs(chain: Chain) { + await this.poolAprUpdaterService.updatePoolAprs(chain); } public async syncChangedPools() { await this.poolSyncService.syncChangedPools(); } - public async reloadAllPoolAprs() { - await this.poolAprUpdaterService.reloadAllPoolAprs(); + public async reloadAllPoolAprs(chain: Chain) { + await this.poolAprUpdaterService.reloadAllPoolAprs(chain); } public async updateLiquidity24hAgoForAllPools() { diff --git a/worker/job-handlers.ts b/worker/job-handlers.ts index f08bef652..e21700aa3 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(); @@ -162,7 +163,16 @@ export function configureWorkerRoutes(app: Express) { ); break; case 'update-pool-apr': - await runIfNotAlreadyRunning(job.name, chainId, () => poolService.updatePoolAprs(), res, next); + await runIfNotAlreadyRunning( + job.name, + chainId, + () => { + const chain = chainIdToChain[chainId]; + return poolService.updatePoolAprs(chain); + }, + res, + next, + ); break; case 'load-on-chain-data-for-pools-with-active-updates': await runIfNotAlreadyRunning( @@ -282,7 +292,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(