File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed
indexer/src/kadena-server/repository/infra/repository Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -44,15 +44,26 @@ export default class DexMetricsDbRepository implements DexMetricsRepository {
4444
4545 // Get TVL history
4646 const tvlHistoryQuery = `
47- SELECT
48- date_trunc('day', pc.timestamp) as timestamp,
49- SUM(CAST(pc."tvlUsd" AS DECIMAL)) as value
50- FROM "PoolCharts" pc
51- JOIN "Pairs" p ON p.id = pc."pairId"
52- WHERE pc.timestamp BETWEEN $1 AND $2
53- AND p.address = $3
54- GROUP BY date_trunc('day', pc.timestamp)
55- ORDER BY timestamp ASC
47+ SELECT
48+ date_trunc('day', t.timestamp) AS timestamp,
49+ SUM(CAST(t."tvlUsd" AS DECIMAL)) AS value
50+ FROM (
51+ SELECT
52+ pc."pairId",
53+ pc."tvlUsd",
54+ pc."timestamp",
55+ ROW_NUMBER() OVER (
56+ PARTITION BY pc."pairId", date_trunc('day', pc."timestamp")
57+ ORDER BY pc."timestamp" DESC
58+ ) as rn
59+ FROM "PoolCharts" pc
60+ JOIN "Pairs" p ON p.id = pc."pairId"
61+ WHERE pc.timestamp BETWEEN $1 AND $2
62+ AND p.address = $3
63+ ) t
64+ WHERE t.rn = 1
65+ GROUP BY date_trunc('day', t.timestamp)
66+ ORDER BY timestamp ASC;
5667 ` ;
5768
5869 const tvlHistory = await sequelize . query ( tvlHistoryQuery , {
You can’t perform that action at this time.
0 commit comments