Skip to content

Commit

Permalink
only run purge prices once for all chains
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Jan 9, 2024
1 parent b67a32b commit 70f7823
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 102 deletions.
9 changes: 0 additions & 9 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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'),
Expand Down
9 changes: 0 additions & 9 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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'),
Expand Down
9 changes: 0 additions & 9 deletions modules/network/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ const baseNetworkData: NetworkData = {
platformId: 'base',
excludedTokenAddresses: [],
},
tokenPrices: {
maxHourlyPriceHistoryNumDays: 100,
},
rpcUrl: 'https://base.gateway.tenderly.co/7mM7DbBouY1JjnQd9MMDsd',
rpcMaxBlockRange: 500,
protocolToken: 'bal',
Expand Down Expand Up @@ -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'),
Expand Down
9 changes: 0 additions & 9 deletions modules/network/fantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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'),
Expand Down
9 changes: 0 additions & 9 deletions modules/network/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'),
Expand Down
25 changes: 11 additions & 14 deletions modules/network/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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'),
Expand All @@ -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'),
Expand All @@ -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,
},
],
};
3 changes: 0 additions & 3 deletions modules/network/network-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ export interface NetworkData {
platformId: string;
excludedTokenAddresses: string[];
};
tokenPrices: {
maxHourlyPriceHistoryNumDays: number;
};
subgraphs: {
startDate: string;
balancer: string;
Expand Down
9 changes: 0 additions & 9 deletions modules/network/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
Expand Down
9 changes: 0 additions & 9 deletions modules/network/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'),
Expand Down
9 changes: 0 additions & 9 deletions modules/network/zkevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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'),
Expand Down
12 changes: 3 additions & 9 deletions modules/token/lib/token-price.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,23 @@ export class TokenPriceService {
}
}

public async purgeOldTokenPrices(): Promise<number> {
const purgeBeforeTimestamp = moment()
.startOf('day')
.subtract(networkContext.data.tokenPrices.maxHourlyPriceHistoryNumDays, 'days')
.utc()
.unix();
public async purgeOldTokenPricesForAllChains(): Promise<number> {
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);

for (const chunk of chunks) {
await prisma.prismaTokenPrice.deleteMany({
where: {
chain: networkContext.chain,
timestamp: { in: chunk.map((tokenPrice) => tokenPrice.timestamp) },
},
});
Expand Down
4 changes: 2 additions & 2 deletions modules/token/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export class TokenService {
return this.tokenPriceService.getHistoricalTokenPrices();
}

public async purgeOldTokenPrices(): Promise<number> {
return this.tokenPriceService.purgeOldTokenPrices();
public async purgeOldTokenPricesForAllChains() {
await this.tokenPriceService.purgeOldTokenPricesForAllChains();
}

public async deleteTokenPrice(args: MutationTokenDeletePriceArgs) {
Expand Down
10 changes: 8 additions & 2 deletions worker/job-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 70f7823

Please sign in to comment.