forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluemove.ts
40 lines (33 loc) · 1.19 KB
/
bluemove.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
39
40
import fetchURL from "../utils/fetchURL"
import { SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../helpers/getUniSubgraphVolume";
const historicalVolumeEndpoint = "https://aptos-mainnet-api.bluemove.net/api/histogram";
interface IVolumeall {
num: string;
date: string;
}
const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint))?.data.list;
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.date.split('T')[0]).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { num }) => acc + Number(num), 0)
const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.date.split('T')[0]).getTime() / 1000) === dayTimestamp)?.num
return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
};
};
const adapter: SimpleAdapter = {
adapter: {
[CHAIN.APTOS]: {
fetch,
start: '2022-10-20',
},
},
version: 1
};
export default adapter;