Skip to content

Commit 84e0efe

Browse files
authored
Merge pull request #460 from hack-a-chain-software/main
Merge 'main' into 'develop'
2 parents c0fff91 + 1ba8634 commit 84e0efe

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

indexer/src/services/pair-service.ts

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -500,28 +500,55 @@ export class PairService {
500500
});
501501

502502
// Update or create pool stats
503-
await PoolStats.upsert(
504-
{
505-
pairId,
506-
timestamp: todayUTC,
507-
volume24hUsd: this.formatTo8Decimals(volume24h),
508-
volume7dUsd: this.formatTo8Decimals(volume7d),
509-
volume30dUsd: this.formatTo8Decimals(volume30d),
510-
volume1yUsd: this.formatTo8Decimals(volume1y),
511-
fees24hUsd: this.formatTo8Decimals(fees24h),
512-
fees7dUsd: this.formatTo8Decimals(fees7d),
513-
fees30dUsd: this.formatTo8Decimals(fees30d),
514-
fees1yUsd: this.formatTo8Decimals(fees1y),
515-
transactionCount24h: transactions24h.length,
516-
tvlUsd: latestChart?.tvlUsd ? this.formatTo8Decimals(parseFloat(latestChart.tvlUsd)) : 0,
517-
apr24h: this.formatTo8Decimals(apr24h),
518-
tvlHistory: tvlHistory.map(chart => ({
519-
timestamp: chart.timestamp,
520-
value: chart.tvlUsd,
521-
})),
522-
},
523-
{ transaction: tx },
524-
);
503+
const existingPoolStats = await PoolStats.findOne({
504+
where: { pairId, timestamp: todayUTC },
505+
transaction: tx,
506+
});
507+
if (existingPoolStats) {
508+
await existingPoolStats.update(
509+
{
510+
volume24hUsd: this.formatTo8Decimals(volume24h),
511+
volume7dUsd: this.formatTo8Decimals(volume7d),
512+
volume30dUsd: this.formatTo8Decimals(volume30d),
513+
volume1yUsd: this.formatTo8Decimals(volume1y),
514+
fees24hUsd: this.formatTo8Decimals(fees24h),
515+
fees7dUsd: this.formatTo8Decimals(fees7d),
516+
fees30dUsd: this.formatTo8Decimals(fees30d),
517+
fees1yUsd: this.formatTo8Decimals(fees1y),
518+
transactionCount24h: transactions24h.length,
519+
tvlUsd: latestChart?.tvlUsd ? this.formatTo8Decimals(parseFloat(latestChart.tvlUsd)) : 0,
520+
apr24h: this.formatTo8Decimals(apr24h),
521+
tvlHistory: tvlHistory.map(chart => ({
522+
timestamp: chart.timestamp,
523+
value: chart.tvlUsd,
524+
})),
525+
},
526+
{ transaction: tx },
527+
);
528+
} else {
529+
await PoolStats.create(
530+
{
531+
pairId,
532+
timestamp: todayUTC,
533+
volume24hUsd: this.formatTo8Decimals(volume24h),
534+
volume7dUsd: this.formatTo8Decimals(volume7d),
535+
volume30dUsd: this.formatTo8Decimals(volume30d),
536+
volume1yUsd: this.formatTo8Decimals(volume1y),
537+
fees24hUsd: this.formatTo8Decimals(fees24h),
538+
fees7dUsd: this.formatTo8Decimals(fees7d),
539+
fees30dUsd: this.formatTo8Decimals(fees30d),
540+
fees1yUsd: this.formatTo8Decimals(fees1y),
541+
transactionCount24h: transactions24h.length,
542+
tvlUsd: latestChart?.tvlUsd ? this.formatTo8Decimals(parseFloat(latestChart.tvlUsd)) : 0,
543+
apr24h: this.formatTo8Decimals(apr24h),
544+
tvlHistory: tvlHistory.map(chart => ({
545+
timestamp: chart.timestamp,
546+
value: chart.tvlUsd,
547+
})),
548+
},
549+
{ transaction: tx },
550+
);
551+
}
525552
}
526553

527554
private static async createOrFindPair(

0 commit comments

Comments
 (0)