Skip to content

Commit

Permalink
track predict.fun trade volume
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Sep 10, 2024
1 parent f9e24c9 commit e2cdf86
Show file tree
Hide file tree
Showing 2 changed files with 1,212 additions and 916 deletions.
79 changes: 79 additions & 0 deletions dexs/predict-fun/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import request from "graphql-request";
import { Fetch, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";


const endpoints: { [key: string]: string } = {
blast: 'https://graphql.predict.fun/graphql'
}

const query = (after?: string) => `query {
categories (pagination: {
first: 100
${after ? `after: "${after}"` : ''}
}) {
totalCount
pageInfo {
hasNextPage
startCursor
endCursor
}
edges {
node {
id
slug
title
statistics {
liquidityValueUsd
volume24hUsd
volumeTotalUsd
}
}
}
}
}
`

const fetch: Fetch = async (_: any, __, { chain }) => {
const dayTimestamp = getUniqStartOfTodayTimestamp()
const categories: any = []
let after
do {
const data = await request(endpoints[chain], query(after))
categories.push(...data.categories.edges)
if (data.categories.pageInfo.hasNextPage) {
after = data.pageInfo.endCursor
}
} while (after)
const dailyVolume = categories.reduce((vol, category) => vol + category.node.statistics.volume24hUsd, 0)
const totalVolume = categories.reduce((vol, category) => vol + category.node.statistics.volumeTotalUsd, 0)


return {
timestamp: dayTimestamp,
dailyVolume,
totalVolume,
}
}

const startTimestamps: { [chain: string]: number } = {
[CHAIN.BLAST]: 1691128800,
}

const volume = Object.keys(endpoints).reduce(
(acc, chain) => ({
...acc,
[chain]: {
fetch,
start: startTimestamps[chain]
},
}),
{}
);

const adapter: SimpleAdapter = {
timetravel: false,
adapter: volume
};
export default adapter;
Loading

0 comments on commit e2cdf86

Please sign in to comment.