Skip to content

Commit 7025afc

Browse files
committed
migrate to new indexer
1 parent 4c539d3 commit 7025afc

File tree

4 files changed

+46
-59
lines changed

4 files changed

+46
-59
lines changed

src/graphql/index.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export type GraphQLResponse<K> = {
66

77
export const gqlRequest = async (
88
document: any,
9-
variable: any,
9+
variable: any
1010
): Promise<any> => {
1111
try {
1212
return await request(
1313
`https://grants-stack-indexer-v2.gitcoin.co/graphql`,
1414
document,
15-
variable,
15+
variable
1616
);
1717
} catch (error) {
1818
console.log(`Request failed, refreshing in 2 seconds`);
@@ -25,7 +25,7 @@ export const getRounds = async (chainId: number) => {
2525
return gqlRequest(
2626
gql`
2727
query getRounds($chainId: Int = 10) {
28-
rounds(condition: { chainId: $chainId }) {
28+
rounds(where: { chainId: { _eq: $chainId } }) {
2929
id
3030
chainId
3131
applicationMetadata
@@ -53,7 +53,7 @@ export const getRounds = async (chainId: number) => {
5353
}
5454
}
5555
`,
56-
{ chainId },
56+
{ chainId }
5757
);
5858
};
5959

@@ -67,7 +67,7 @@ export const getApplications = async ({
6767
return gqlRequest(
6868
gql`
6969
query getApplications($roundId: String = "", $chainId: Int = 10) {
70-
round(chainId: $chainId, id: $roundId) {
70+
rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $roundId } }) {
7171
applications {
7272
id
7373
projectId
@@ -85,7 +85,7 @@ export const getApplications = async ({
8585
}
8686
}
8787
`,
88-
{ chainId, roundId },
88+
{ chainId, roundId }
8989
);
9090
};
9191

@@ -99,7 +99,7 @@ export const getVotes = async ({
9999
return gqlRequest(
100100
gql`
101101
query getVotes($roundId: String = "", $chainId: Int = 10) {
102-
round(chainId: $chainId, id: $roundId) {
102+
rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $roundId } }) {
103103
donations {
104104
amount
105105
amountInRoundMatchToken
@@ -118,42 +118,24 @@ export const getVotes = async ({
118118
}
119119
}
120120
`,
121-
{ chainId, roundId },
121+
{ chainId, roundId }
122122
);
123123
};
124124

125-
export const getTokenPrice = async ({
126-
chainId,
127-
tokenAddress,
128-
blockNumber,
129-
}: {
130-
chainId: number;
131-
tokenAddress: string;
132-
blockNumber: string;
133-
}) => {
125+
export const getTokenPrice = async ({ tokenCode }: { tokenCode: string }) => {
134126
return gqlRequest(
135127
gql`
136-
query getTokenPrice(
137-
$tokenAddress: String = ""
138-
$chainId: Int = 10
139-
$blockNumber: BigFloat = ""
140-
) {
141-
prices(
128+
query getTokenPrice($tokenCode: String = "") {
129+
priceCache(
142130
orderBy: BLOCK_NUMBER_DESC
143-
filter: {
144-
tokenAddress: { equalTo: $tokenAddress }
145-
chainId: { equalTo: $chainId }
146-
blockNumber: { lessThanOrEqualTo: $blockNumber }
147-
}
148-
first: 1
131+
filter: { tokenCode: { equalTo: $tokenCode } }
132+
limit: 1
149133
) {
150134
id
151-
chainId
152-
priceInUsd
153-
blockNumber
135+
priceUsd
154136
}
155137
}
156138
`,
157-
{ chainId, tokenAddress, blockNumber },
139+
{ tokenCode }
158140
);
159141
};

src/loaders/applications.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ const manageApplications = async ({ chainId, prisma, roundId }: Props) => {
3636
const applicationResponse = (await getApplications({
3737
chainId: Number(chainId),
3838
roundId: round.roundId.toLowerCase(),
39-
})) as GraphQLResponse<{ applications: any[] }>;
39+
})) as GraphQLResponse<{ applications: any[] }[]>;
4040

41-
const applicationList = applicationResponse?.round?.applications || [];
41+
const applicationList = applicationResponse?.round[0]?.applications || [];
4242

4343
console.log(
4444
`${applicationList.length} application${
4545
applicationList.length !== 1 ? "s" : ""
46-
} found for active application round (${rIndex + 1}/${rounds.length}) : ${round.roundId}`,
46+
} found for active application round (${rIndex + 1}/${rounds.length}) : ${
47+
round.roundId
48+
}`
4749
);
4850

4951
for (const [index, application] of applicationList.entries()) {
@@ -116,9 +118,11 @@ const manageApplications = async ({ chainId, prisma, roundId }: Props) => {
116118
});
117119

118120
process.stdout.write(
119-
` => Committed ${index + 1} of ${applicationList.length} applications (${
121+
` => Committed ${index + 1} of ${
122+
applicationList.length
123+
} applications (${
120124
Math.round((currentCount / applicationList.length) * 10000) / 100
121-
}%) ${isLast ? "\n" : "\r"}`,
125+
}%) ${isLast ? "\n" : "\r"}`
122126
);
123127
}
124128

@@ -137,7 +141,7 @@ const manageApplications = async ({ chainId, prisma, roundId }: Props) => {
137141
});
138142

139143
console.log(
140-
`\r\n Round application period has ended, disabling further indexing\r\n`,
144+
`\r\n Round application period has ended, disabling further indexing\r\n`
141145
);
142146
}
143147
}

src/loaders/votes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ const manageVotes = async ({ chainId, prisma, roundId }: Props) => {
3535
const votesResponse = (await getVotes({
3636
chainId: Number(chainId),
3737
roundId: round.roundId.toLowerCase(),
38-
})) as GraphQLResponse<{ donations: any[] }>;
38+
})) as GraphQLResponse<{ donations: any[] }[]>;
3939

40-
const votesList = votesResponse?.round?.donations || [];
40+
const votesList = votesResponse?.round[0]?.donations || [];
4141

4242
// logger(`Committing vote: ${vote.transaction}`)
4343
if (votesList.length > 0) {
4444
process.stdout.write(`\n`);
4545
}
4646
process.stdout.write(
47-
`${votesList.length} votes found for round (${rIndex + 1}/${rounds.length}): ${round.roundId} \n`,
47+
`${votesList.length} votes found for round (${rIndex + 1}/${
48+
rounds.length
49+
}): ${round.roundId} \n`
4850
);
4951

5052
for (const [index, vote] of votesList.entries()) {
@@ -98,7 +100,7 @@ const manageVotes = async ({ chainId, prisma, roundId }: Props) => {
98100
process.stdout.write(
99101
` => Committed ${currentCount} of ${votesList.length} votes (${
100102
Math.round((currentCount / votesList.length) * 10000) / 100
101-
}%) ${isLast ? "\n" : "\r"}`,
103+
}%) ${isLast ? "\n" : "\r"}`
102104
);
103105
}
104106
}

src/utils/index.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ export const grantFetch = async (path: string) => {
6767

6868
export const initialFetch = async (chainId: string) => {
6969
try {
70-
const block =
71-
await clients[Number(chainId) as keyof typeof clients].getBlock();
70+
const block = await clients[
71+
Number(chainId) as keyof typeof clients
72+
].getBlock();
7273

7374
console.log(
74-
`Current block on chainId ${chainId} is ${block.number?.toString()}`,
75+
`Current block on chainId ${chainId} is ${block.number?.toString()}`
7576
);
7677
} catch (error) {}
7778
};
@@ -144,7 +145,7 @@ export const createExtraParams = (next_page_params: NextPageParams) => {
144145
const prefix = acc ? "&" : "";
145146
return `${acc}${prefix}${curr}=${value}`;
146147
},
147-
"",
148+
""
148149
);
149150
};
150151

@@ -159,8 +160,8 @@ export const fetchBlockTimestamp = async ({
159160
blockNumbers.map((blockNumber) =>
160161
clients[Number(chainId) as keyof typeof clients]
161162
.getBlock({ blockNumber: BigInt(blockNumber) })
162-
.then((block) => block.timestamp),
163-
),
163+
.then((block) => block.timestamp)
164+
)
164165
);
165166
};
166167

@@ -204,7 +205,7 @@ export const fetchRoundDistributionData = async ({
204205
address: roundId,
205206
abi: roundABI,
206207
functionName: "payoutStrategy",
207-
}),
208+
})
208209
) as `0x${string}`;
209210

210211
const contractConfig = {
@@ -263,16 +264,14 @@ export const fetchRoundDistributionData = async ({
263264
}
264265

265266
const targetTokenPrice = (await getTokenPrice({
266-
chainId,
267-
tokenAddress: nTokenAddress,
268-
blockNumber: targetBlockNumber.toString(),
269-
})) as { prices: any[] };
267+
tokenCode: token.code,
268+
})) as { priceCache: any[] };
270269

271-
token.price = targetTokenPrice.prices[0].priceInUsd ?? 0;
270+
token.price = targetTokenPrice.priceCache[0].priceUsd ?? 0;
272271
}
273272

274273
const res = await fetch(
275-
`https://d16c97c2np8a2o.cloudfront.net/ipfs/${metaPtr}`,
274+
`https://d16c97c2np8a2o.cloudfront.net/ipfs/${metaPtr}`
276275
);
277276

278277
const distro = await res.json();
@@ -287,7 +286,7 @@ export const fetchRoundDistributionData = async ({
287286
console.log(error);
288287

289288
console.log(
290-
`Error occurred while fetching round distro data for ${roundId}`,
289+
`Error occurred while fetching round distro data for ${roundId}`
291290
);
292291
}
293292

@@ -306,7 +305,7 @@ export const formatDistributionPrice = ({
306305
return Number(
307306
formatUnits(
308307
hexToBigInt(amount) * parseUnits(price.toString(), decimal),
309-
decimal + 18,
310-
),
308+
decimal + 18
309+
)
311310
);
312311
};

0 commit comments

Comments
 (0)