diff --git a/dexs/metavault-derivative/index.ts b/dexs/metavault-derivative/index.ts deleted file mode 100644 index c93b5e9f67..0000000000 --- a/dexs/metavault-derivative/index.ts +++ /dev/null @@ -1,97 +0,0 @@ -import request, { gql } from "graphql-request"; -import { Fetch, SimpleAdapter } from "../../adapters/types"; -import { CHAIN } from "../../helpers/chains"; -import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; - -const endpoints: { [key: string]: string } = { - [CHAIN.POLYGON]: - "https://api.thegraph.com/subgraphs/name/sdcrypt0/metavault-mvx-subgraph", -}; - -const historicalData = gql` - query get_volume($period: String!, $id: String!) { - volumeStats(where: { period: $period, id: $id }) { - liquidation - margin - swap - } - } -`; - -interface IGraphResponse { - volumeStats: Array<{ - burn: string; - liquidation: string; - margin: string; - mint: string; - swap: string; - }>; -} - -const getFetch = - (chain: string): Fetch => - async (timestamp: number) => { - const dayTimestamp = getUniqStartOfTodayTimestamp( - new Date(timestamp * 1000) - ); - const dailyData: IGraphResponse = await request( - endpoints[chain], - historicalData, - { - id: String(dayTimestamp) + ":daily", - period: "daily", - } - ); - const totalData: IGraphResponse = await request( - endpoints[chain], - historicalData, - { - id: "total", - period: "total", - } - ); - - return { - timestamp: dayTimestamp, - dailyVolume: - dailyData.volumeStats.length == 1 - ? String( - Number( - Object.values(dailyData.volumeStats[0]).reduce((sum, element) => - String(Number(sum) + Number(element)) - ) - ) * - 10 ** -30 - ) - : undefined, - totalVolume: - totalData.volumeStats.length == 1 - ? String( - Number( - Object.values(totalData.volumeStats[0]).reduce((sum, element) => - String(Number(sum) + Number(element)) - ) - ) * - 10 ** -30 - ) - : undefined, - }; - }; - -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, - }, - }; - }, {}), -}; - -export default adapter; diff --git a/dexs/metavault.trade/index.ts b/dexs/metavault.trade/index.ts index 396fd10892..943a9fcc34 100644 --- a/dexs/metavault.trade/index.ts +++ b/dexs/metavault.trade/index.ts @@ -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"; @@ -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, @@ -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', }) @@ -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;