Skip to content

Commit

Permalink
fix adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Feb 19, 2024
1 parent 0e06da8 commit 8e2c66d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 113 deletions.
97 changes: 0 additions & 97 deletions dexs/metavault-derivative/index.ts

This file was deleted.

44 changes: 28 additions & 16 deletions dexs/metavault.trade/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import request, { gql } from "graphql-request";
import { Fetch, SimpleAdapter } from "../../adapters/types";
import { BreakdownAdapter, Fetch, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

Expand All @@ -15,6 +15,15 @@ const historicalData = gql`
}
`

const derivativesVolume = gql`
query get_volume($period: String!, $id: String!) {
volumeStats(where: {period: $period, id: $id}) {
liquidation
margin
}
}
`

interface IGraphResponse {
volumeStats: Array<{
burn: string,
Expand All @@ -25,13 +34,13 @@ interface IGraphResponse {
}>
}

const getFetch = (chain: string): Fetch => async (timestamp: number) => {
const getFetch = (chain: string, query: string): Fetch => async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000)))
const dailyData: IGraphResponse = await request(endpoints[chain], historicalData, {
const dailyData: IGraphResponse = await request(endpoints[chain], query, {
id: String(dayTimestamp) + ':daily',
period: 'daily',
})
const totalData: IGraphResponse = await request(endpoints[chain], historicalData, {
const totalData: IGraphResponse = await request(endpoints[chain], query, {
id: 'total',
period: 'total',
})
Expand All @@ -54,17 +63,20 @@ const startTimestamps: { [chain: string]: number } = {
[CHAIN.POLYGON]: 1654041600,
}

const adapter: SimpleAdapter = {
adapter: Object.keys(endpoints).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: getFetch(chain),
start: startTimestamps[chain],
runAtCurrTime: true
}
}
}, {})
const adapter: BreakdownAdapter = {
breakdown: {
"metavault.trade": {
[CHAIN.POLYGON]: {
fetch: getFetch(CHAIN.POLYGON, historicalData),
start: startTimestamps[CHAIN.POLYGON],
},
},
"metavault-derivative": {
[CHAIN.POLYGON]: {
fetch: getFetch(CHAIN.POLYGON, derivativesVolume),
start: startTimestamps[CHAIN.POLYGON],
},
},
}
}

export default adapter;

0 comments on commit 8e2c66d

Please sign in to comment.