Skip to content

Commit

Permalink
fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Apr 11, 2024
1 parent de96ce6 commit f181d78
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions dexs/rollup-finace/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import request, { gql } from "graphql-request";
import { BreakdownAdapter, Fetch, SimpleAdapter } from "../../adapters/types";
import { BreakdownAdapter, DISABLED_ADAPTER_KEY, Fetch, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import disabledAdapter from "../../helpers/disabledAdapter";
import { httpGet } from "../../utils/fetchURL";

const endpoints: { [key: string]: string } = {
[CHAIN.ERA]: "https://subgraph.rollup.finance/subgraphs/name/rollUp/stats",
Expand All @@ -25,41 +27,24 @@ const historicalDataDerivatives = gql`
`

interface IGraphResponse {
volumeStats: Array<{
list: Array<{
burn: string,
liquidation: string,
margin: string,
mint: string,
swap: string,
period: string
}>
}

const getFetch = (query: string)=> (chain: string): Fetch => async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000)))
const fromTimestamp = dayTimestamp - 60 * 60 * 24
const dailyData: IGraphResponse = await request(endpoints[chain], query, {
id: String(dayTimestamp),
period: 'daily',
})
const yesterDay: IGraphResponse = await request(endpoints[chain], query, {
id: String(fromTimestamp),
period: 'daily',
})
const totalData: IGraphResponse = await request(endpoints[chain], query, {
id: 'total',
period: 'total',
})

const todayVolume = Number(Object.values(dailyData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30
const yesterdayVolume = Number(Object.values(yesterDay.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30
const dailyVolume = (todayVolume - yesterdayVolume);
const fetchDerivatives = async (timestamp: number) => {
const data: IGraphResponse = (await httpGet("https://terminal.rollup.finance/analy-v1/analytics/volume?pageNum=1&pageSize=32")).data
const dataItem = data.list.find((e) => e.period === getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)).toString())
const dailyVolume = Number(dataItem?.liquidation || 0) + Number(dataItem?.margin || 0)
return {
timestamp: dayTimestamp,
dailyVolume: `${dailyVolume}`,
totalVolume:
totalData.volumeStats.length == 1
? String(Number(Object.values(totalData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30)
: undefined,
dailyFees: dailyVolume.toString(),
timestamp

}
}
Expand All @@ -82,7 +67,7 @@ const adapter: BreakdownAdapter = {
return {
...acc,
[chain]: {
fetch: getFetch(historicalDataDerivatives)(chain),
fetch: fetchDerivatives,
start: startTimestamps[chain]
}
}
Expand Down

0 comments on commit f181d78

Please sign in to comment.