forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoryhunt-v3.ts
38 lines (32 loc) · 1.09 KB
/
storyhunt-v3.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import request from "graphql-request";
import { FetchOptions, SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
const v3Endpoint = {
[CHAIN.STORY]: "https://app.storyhunt.xyz/api/graph",
}
const adapter: SimpleAdapter = {
adapter: {
[CHAIN.STORY]: {
fetch,
},
},
version: 2
};
export default adapter;
async function fetch({ chain, getStartBlock, getEndBlock }: FetchOptions) {
const { factories: [{totalVolumeUSD}]} = await getData(await getEndBlock());
const { factories: [{totalVolumeUSD: totalVolumeUSDYesterday}]} = await getData(await getStartBlock());
return {
dailyVolume: totalVolumeUSD - totalVolumeUSDYesterday, totalVolume: totalVolumeUSD,
}
async function getData(block: any) {
const query = "query total_volume ($block: Int) { factories(block: { number: $block }) { totalVolumeUSD } }"
try {
const res = await request((v3Endpoint as any)[chain], query, { block });
return res
} catch (error) {
if ((error as any)?.response.status === 200) return (error as any).response
return {}
}
}
}