diff --git a/modules/network/arbitrum.ts b/modules/network/arbitrum.ts index c1adf6101..55676c40b 100644 --- a/modules/network/arbitrum.ts +++ b/modules/network/arbitrum.ts @@ -52,9 +52,6 @@ const arbitrumNetworkData: NetworkData = { platformId: 'arbitrum-one', excludedTokenAddresses: ['0x6dbf2155b0636cb3fd5359fccefb8a2c02b6cb51'], // plsRDNT, has coingecko entry but no price }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: env.INFURA_API_KEY && (env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? `https://arbitrum-mainnet.infura.io/v3/${env.INFURA_API_KEY}` @@ -326,12 +323,6 @@ export const arbitrumNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(1, 'hours'), diff --git a/modules/network/avalanche.ts b/modules/network/avalanche.ts index 5e2e70af6..8cf724a68 100644 --- a/modules/network/avalanche.ts +++ b/modules/network/avalanche.ts @@ -52,9 +52,6 @@ const avalancheNetworkData: NetworkData = { platformId: 'avalanche', excludedTokenAddresses: [], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: env.INFURA_API_KEY && (env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? `https://avalanche-mainnet.infura.io/v3/${env.INFURA_API_KEY}` @@ -320,12 +317,6 @@ export const avalancheNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(1, 'hours'), diff --git a/modules/network/base.ts b/modules/network/base.ts index 9bbea516f..f57e9420c 100644 --- a/modules/network/base.ts +++ b/modules/network/base.ts @@ -51,9 +51,6 @@ const baseNetworkData: NetworkData = { platformId: 'base', excludedTokenAddresses: [], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: 'https://base.gateway.tenderly.co/7mM7DbBouY1JjnQd9MMDsd', rpcMaxBlockRange: 500, protocolToken: 'bal', @@ -232,12 +229,6 @@ export const baseNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(75, 'minutes'), diff --git a/modules/network/fantom.ts b/modules/network/fantom.ts index 6391205c5..ff3a5510c 100644 --- a/modules/network/fantom.ts +++ b/modules/network/fantom.ts @@ -93,9 +93,6 @@ const fantomNetworkData: NetworkData = { '0xb7c2ddb1ebac1056231ef22c1b0a13988537a274', // new tarot ], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? `https://rpc.ankr.com/fantom` @@ -438,12 +435,6 @@ export const fantomNetworkConfig: NetworkConfig = { name: 'sync-latest-relic-snapshots', interval: every(1, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), diff --git a/modules/network/gnosis.ts b/modules/network/gnosis.ts index 728bf5a15..8323dd363 100644 --- a/modules/network/gnosis.ts +++ b/modules/network/gnosis.ts @@ -52,9 +52,6 @@ const gnosisNetworkData: NetworkData = { platformId: 'xdai', excludedTokenAddresses: [], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? `https://rpc.gnosischain.com` : 'https://gnosis.drpc.org', rpcMaxBlockRange: 2000, @@ -240,12 +237,6 @@ export const gnosisNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(75, 'minutes'), diff --git a/modules/network/mainnet.ts b/modules/network/mainnet.ts index b2bfab90f..3daeb3c07 100644 --- a/modules/network/mainnet.ts +++ b/modules/network/mainnet.ts @@ -63,9 +63,6 @@ const data: NetworkData = { '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee', // weEth, has coingekco entry but no price ], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: env.INFURA_API_KEY && (env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? `https://mainnet.infura.io/v3/${env.INFURA_API_KEY}` @@ -468,12 +465,6 @@ export const mainnetNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(75, 'minutes'), @@ -490,11 +481,6 @@ export const mainnetNetworkConfig: NetworkConfig = { name: 'sync-vebal-voting-gauges', interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(20, 'minutes') : every(5, 'minutes'), }, - // The following are multichain jobs and should only run once for all chains. - { - name: 'sync-global-coingecko-prices', - interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(2, 'minutes'), - }, { name: 'feed-data-to-datastudio', interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(5, 'minutes') : every(5, 'minutes'), @@ -503,5 +489,16 @@ export const mainnetNetworkConfig: NetworkConfig = { name: 'sync-latest-fx-prices', interval: every(10, 'minutes'), }, + // The following are multichain jobs and should only run once for all chains. + { + name: 'sync-global-coingecko-prices', + interval: (env.DEPLOYMENT_ENV as DeploymentEnv) === 'canary' ? every(10, 'minutes') : every(2, 'minutes'), + }, + { + name: 'global-purge-old-tokenprices', + interval: every(1, 'days'), + alarmEvaluationPeriod: 1, + alarmDatapointsToAlarm: 1, + }, ], }; diff --git a/modules/network/network-config-types.ts b/modules/network/network-config-types.ts index 86982b656..9127ac3a4 100644 --- a/modules/network/network-config-types.ts +++ b/modules/network/network-config-types.ts @@ -62,9 +62,6 @@ export interface NetworkData { platformId: string; excludedTokenAddresses: string[]; }; - tokenPrices: { - maxHourlyPriceHistoryNumDays: number; - }; subgraphs: { startDate: string; balancer: string; diff --git a/modules/network/optimism.ts b/modules/network/optimism.ts index 3b87c261b..34740a0b7 100644 --- a/modules/network/optimism.ts +++ b/modules/network/optimism.ts @@ -53,9 +53,6 @@ const optimismNetworkData: NetworkData = { platformId: 'optimistic-ethereum', excludedTokenAddresses: ['0x97513e975a7fa9072c72c92d8000b0db90b163c5'], //multibeets }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: env.INFURA_API_KEY ? `https://optimism-mainnet.infura.io/v3/${env.INFURA_API_KEY}` : 'https://mainnet.optimism.io', @@ -368,12 +365,6 @@ export const optimismNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(1, 'hours'), diff --git a/modules/network/polygon.ts b/modules/network/polygon.ts index a707194e1..8598d6930 100644 --- a/modules/network/polygon.ts +++ b/modules/network/polygon.ts @@ -52,9 +52,6 @@ const polygonNetworkData: NetworkData = { platformId: 'polygon-pos', excludedTokenAddresses: [], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: env.INFURA_API_KEY ? `https://polygon-mainnet.infura.io/v3/${env.INFURA_API_KEY}` : 'https://polygon.sakurarpc.io', @@ -361,12 +358,6 @@ export const polygonNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(1, 'hours'), diff --git a/modules/network/zkevm.ts b/modules/network/zkevm.ts index 09a329daf..b540565dd 100644 --- a/modules/network/zkevm.ts +++ b/modules/network/zkevm.ts @@ -52,9 +52,6 @@ const zkevmNetworkData: NetworkData = { platformId: 'polygon-zkevm', excludedTokenAddresses: [], }, - tokenPrices: { - maxHourlyPriceHistoryNumDays: 100, - }, rpcUrl: env.ALCHEMY_API_KEY && (env.DEPLOYMENT_ENV as DeploymentEnv) === 'main' ? `https://polygonzkevm-mainnet.g.alchemy.com/v2/${env.ALCHEMY_API_KEY}` @@ -264,12 +261,6 @@ export const zkevmNetworkConfig: NetworkConfig = { name: 'sync-coingecko-coinids', interval: every(2, 'hours'), }, - { - name: 'purge-old-tokenprices', - interval: every(1, 'days'), - alarmEvaluationPeriod: 1, - alarmDatapointsToAlarm: 1, - }, { name: 'update-fee-volume-yield-all-pools', interval: every(75, 'minutes'), diff --git a/modules/token/lib/token-price.service.ts b/modules/token/lib/token-price.service.ts index 1d5b77fa9..792132e72 100644 --- a/modules/token/lib/token-price.service.ts +++ b/modules/token/lib/token-price.service.ts @@ -255,21 +255,16 @@ export class TokenPriceService { } } - public async purgeOldTokenPrices(): Promise { - const purgeBeforeTimestamp = moment() - .startOf('day') - .subtract(networkContext.data.tokenPrices.maxHourlyPriceHistoryNumDays, 'days') - .utc() - .unix(); + public async purgeOldTokenPricesForAllChains(): Promise { + const purgeBeforeTimestamp = moment().startOf('day').subtract(180, 'days').utc().unix(); const oldPrices = await prisma.prismaTokenPrice.findMany({ where: { - chain: networkContext.chain, timestamp: { lt: purgeBeforeTimestamp }, }, }); // returns all non midnight prices - const tobeDeleted = oldPrices.filter((tokenPrice) => tokenPrice.timestamp % secondsPerDay !== 0); + const tobeDeleted = _.uniq(oldPrices.filter((tokenPrice) => tokenPrice.timestamp % secondsPerDay !== 0)); //apparently prisma has a limitation on delete const chunks = _.chunk(tobeDeleted, 1000); @@ -277,7 +272,6 @@ export class TokenPriceService { for (const chunk of chunks) { await prisma.prismaTokenPrice.deleteMany({ where: { - chain: networkContext.chain, timestamp: { in: chunk.map((tokenPrice) => tokenPrice.timestamp) }, }, }); diff --git a/modules/token/token.service.ts b/modules/token/token.service.ts index 21aff4d98..a62c89a0a 100644 --- a/modules/token/token.service.ts +++ b/modules/token/token.service.ts @@ -216,8 +216,8 @@ export class TokenService { return this.tokenPriceService.getHistoricalTokenPrices(); } - public async purgeOldTokenPrices(): Promise { - return this.tokenPriceService.purgeOldTokenPrices(); + public async purgeOldTokenPricesForAllChains() { + await this.tokenPriceService.purgeOldTokenPricesForAllChains(); } public async deleteTokenPrice(args: MutationTokenDeletePriceArgs) { diff --git a/worker/job-handlers.ts b/worker/job-handlers.ts index 8329d69cd..aa91a476a 100644 --- a/worker/job-handlers.ts +++ b/worker/job-handlers.ts @@ -251,8 +251,14 @@ export function configureWorkerRoutes(app: Express) { case 'sync-latest-relic-snapshots': await runIfNotAlreadyRunning(job.name, chainId, () => userService.syncUserRelicSnapshots(), res, next); break; - case 'purge-old-tokenprices': - await runIfNotAlreadyRunning(job.name, chainId, () => tokenService.purgeOldTokenPrices(), res, next); + case 'global-purge-old-tokenprices': + await runIfNotAlreadyRunning( + job.name, + chainId, + () => tokenService.purgeOldTokenPricesForAllChains(), + res, + next, + ); break; case 'sync-coingecko-coinids': await runIfNotAlreadyRunning(job.name, chainId, () => tokenService.syncCoingeckoIds(), res, next);