Skip to content

Commit fdd2a6e

Browse files
authored
Merge pull request #314 from solidity-io/update/backfill-pair
Add token price queries based on the protocol
2 parents f4258e1 + 59cd543 commit fdd2a6e

28 files changed

+1645
-767
lines changed

indexer/API.md

Lines changed: 134 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,95 @@ query GetTokenInfo {
6161
}
6262
```
6363

64+
### Get Token Price
65+
66+
```graphql
67+
query GetTokenPrice($tokenAddress: String!, $protocolAddress: String) {
68+
tokenPrice(tokenAddress: $tokenAddress, protocolAddress: $protocolAddress) {
69+
id
70+
token {
71+
id
72+
name
73+
chainId
74+
address
75+
}
76+
priceInKda
77+
priceInUsd
78+
protocolAddress
79+
updatedAt
80+
}
81+
}
82+
```
83+
84+
**Input Parameters:**
85+
86+
- `tokenAddress`: Address of the token (required, String!)
87+
- `protocolAddress`: Protocol address (optional, String)
88+
89+
**Output Data:**
90+
91+
```typescript
92+
{
93+
tokenPrice: {
94+
id: string; // Price ID
95+
token: {
96+
id: string; // Token ID
97+
name: string; // Token name
98+
chainId: string; // Chain ID
99+
address: string; // Token address
100+
},
101+
priceInKda: number; // Price in KDA
102+
priceInUsd: number; // Price in USD
103+
protocolAddress: string;// Protocol address
104+
updatedAt: DateTime; // Last update timestamp
105+
}
106+
}
107+
```
108+
109+
### Get All Token Prices
110+
111+
```graphql
112+
query GetTokenPrices($protocolAddress: String) {
113+
tokenPrices(protocolAddress: $protocolAddress) {
114+
id
115+
token {
116+
id
117+
name
118+
chainId
119+
address
120+
}
121+
priceInKda
122+
priceInUsd
123+
protocolAddress
124+
updatedAt
125+
}
126+
}
127+
```
128+
129+
**Input Parameters:**
130+
131+
- `protocolAddress`: Protocol address (optional, String)
132+
133+
**Output Data:**
134+
135+
```typescript
136+
{
137+
tokenPrices: Array<{
138+
id: string; // Price ID
139+
token: {
140+
id: string; // Token ID
141+
name: string; // Token name
142+
chainId: string; // Chain ID
143+
address: string; // Token address
144+
};
145+
priceInKda: number; // Price in KDA
146+
priceInUsd: number; // Price in USD
147+
protocolAddress: string; // Protocol address
148+
updatedAt: DateTime; // Last update timestamp
149+
}>;
150+
}
151+
```
152+
64153
### Get Token Price and Exchange Rate
65154

66155
```graphql
@@ -318,64 +407,76 @@ query GetPools($first: Int, $orderBy: PoolOrderBy = TVL_USD_DESC, $after: String
318407
### Get Pool by ID with Charts
319408

320409
```graphql
321-
query GetPoolDetails($poolId: ID!, $timeFrame: TimeFrame = DAY, $first: Int = 10) {
410+
query getPoolDetails($poolId: ID!, $timeFrame: TimeFrame!) {
322411
pool(id: $poolId) {
323-
id
324412
address
325-
token0 {
326-
id
327-
name
328-
}
329-
token1 {
330-
id
331-
name
332-
}
413+
apr24h
414+
createdAt
415+
fees24hUsd
416+
feesChange24h
417+
id
418+
key
333419
reserve0
334420
reserve1
335421
totalSupply
336-
tvlUsd
422+
transactionCount24h
423+
transactionCountChange24h
337424
tvlChange24h
425+
tvlUsd
426+
updatedAt
338427
volume24hUsd
339-
volumeChange24h
340428
volume7dUsd
341-
fees24hUsd
342-
feesChange24h
343-
transactionCount24h
344-
transactionCountChange24h
345-
apr24h
429+
volumeChange24h
346430
charts(timeFrame: $timeFrame) {
347-
volume {
348-
timestamp
431+
fees {
349432
value
433+
timestamp
350434
}
351435
tvl {
352-
timestamp
353436
value
354-
}
355-
fees {
356437
timestamp
438+
}
439+
volume {
357440
value
441+
timestamp
358442
}
359443
}
360-
transactions(first: $first) {
444+
token0 {
445+
name
446+
id
447+
chainId
448+
address
449+
}
450+
token1 {
451+
name
452+
id
453+
chainId
454+
address
455+
}
456+
transactions {
457+
totalCount
458+
pageInfo {
459+
endCursor
460+
hasNextPage
461+
startCursor
462+
hasPreviousPage
463+
}
361464
edges {
465+
cursor
362466
node {
363-
id
364-
maker
365467
amount0In
366-
amount1In
367468
amount0Out
469+
amount1In
368470
amount1Out
369-
amountUsd
370-
timestamp
371471
transactionType
472+
transactionId
473+
timestamp
474+
requestkey
475+
maker
476+
id
477+
amountUsd
372478
}
373479
}
374-
pageInfo {
375-
hasNextPage
376-
endCursor
377-
}
378-
totalCount
379480
}
380481
}
381482
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
3+
/** @type {import('sequelize-cli').Migration} */
4+
module.exports = {
5+
async up(queryInterface, Sequelize) {
6+
// First, convert existing timestamps to date-only format
7+
await queryInterface.sequelize.query(`
8+
UPDATE "PoolStats"
9+
SET timestamp = DATE(timestamp)
10+
WHERE timestamp IS NOT NULL;
11+
`);
12+
13+
// Remove duplicate entries keeping the latest one for each pairId and timestamp
14+
await queryInterface.sequelize.query(`
15+
DELETE FROM "PoolStats" a
16+
USING (
17+
SELECT "pairId", timestamp, MAX(id) as max_id
18+
FROM "PoolStats"
19+
GROUP BY "pairId", timestamp
20+
HAVING COUNT(*) > 1
21+
) b
22+
WHERE a."pairId" = b."pairId"
23+
AND a.timestamp = b.timestamp
24+
AND a.id < b.max_id;
25+
`);
26+
27+
// Then change the column type to DATE
28+
await queryInterface.changeColumn('PoolStats', 'timestamp', {
29+
type: Sequelize.DATEONLY,
30+
allowNull: false,
31+
});
32+
33+
// Create unique index
34+
await queryInterface.addIndex('PoolStats', ['pairId', 'timestamp'], {
35+
unique: true,
36+
name: 'pool_stats_pairid_timestamp_idx',
37+
});
38+
},
39+
40+
async down(queryInterface, Sequelize) {
41+
// Remove unique index
42+
await queryInterface.removeIndex('PoolStats', 'pool_stats_pairid_timestamp_idx');
43+
44+
// Convert back to TIMESTAMP WITH TIME ZONE
45+
await queryInterface.changeColumn('PoolStats', 'timestamp', {
46+
type: Sequelize.DATE,
47+
allowNull: false,
48+
});
49+
50+
// Recreate original non-unique index
51+
await queryInterface.addIndex('PoolStats', ['pairId', 'timestamp'], {
52+
name: 'pool_stats_pairid_timestamp_idx',
53+
});
54+
},
55+
};

0 commit comments

Comments
 (0)