diff --git a/dexs/linehub-v2/index.ts b/dexs/linehub-v2/index.ts new file mode 100644 index 0000000000..1cc0296d9d --- /dev/null +++ b/dexs/linehub-v2/index.ts @@ -0,0 +1,15 @@ +import { CHAIN } from "../../helpers/chains"; +import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume"; + +const endpoints = { + [CHAIN.LINEA]: + "https://api.studio.thegraph.com/query/55804/linehub-v2/version/latest", +}; + +export default univ2Adapter2(endpoints, { + factoriesName: "factories", + totalVolume: "volumeUSD", + dayData: "factoryDaySnapshot", + dailyVolume: "volumeUSD", + dailyVolumeTimestampField: "timestamp", +}); diff --git a/dexs/quickswap-hydra/index.ts b/dexs/quickswap-hydra/index.ts new file mode 100644 index 0000000000..8457292e06 --- /dev/null +++ b/dexs/quickswap-hydra/index.ts @@ -0,0 +1,81 @@ +import request, { gql } from "graphql-request"; +import { Adapter, ChainEndpoints, FetchV2 } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints: ChainEndpoints = { + [CHAIN.POLYGON_ZKEVM]: + "https://api.studio.thegraph.com/query/55804/hydra-trade/version/latest", + [CHAIN.MANTA]: + "https://api.goldsky.com/api/public/project_cly4708cqpcj601tt7gzf1jdj/subgraphs/manta-trade/latest/gn", +}; + +interface IVolumeStat { + cumulativeVolumeUsd: string; + volumeUsd: string; + id: string; +} + +const graphs = (graphUrls: ChainEndpoints) => { + const fetch: FetchV2 = async ({ chain, startTimestamp }) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(startTimestamp); + + const graphQuery = gql` + query MyQuery { + volumeStats(where: {timestamp: ${todaysTimestamp}, period: "daily"}) { + cumulativeVolumeUsd + volumeUsd + id + } + } + `; + + const graphRes = await request(graphUrls[chain], graphQuery); + const volumeStats: IVolumeStat[] = graphRes.volumeStats; + + let dailyVolumeUSD = BigInt(0); + let totalVolumeUSD = BigInt(0); + + volumeStats.forEach((vol) => { + dailyVolumeUSD += BigInt(vol.volumeUsd); + totalVolumeUSD += BigInt(vol.cumulativeVolumeUsd); + }); + + const finalDailyVolume = parseInt(dailyVolumeUSD.toString()) / 1e18; + const finalTotalVolume = parseInt(totalVolumeUSD.toString()) / 1e18; + + return { + dailyVolume: finalDailyVolume.toString(), + totalVolume: finalTotalVolume.toString(), + timestamp: todaysTimestamp, + }; + }; + return fetch; +}; + +const methodology = { + dailyVolume: + "Total cumulativeVolumeUsd for specified chain for the given day", +}; + +const adapter: Adapter = { + version: 2, + adapter: { + [CHAIN.POLYGON_ZKEVM]: { + fetch: graphs(endpoints), + start: 1719878400, + meta: { + methodology, + }, + }, + [CHAIN.MANTA]: { + fetch: graphs(endpoints), + start: 1719878400, + meta: { + methodology, + }, + }, + }, +}; + +export default adapter; diff --git a/dexs/quickswap-perps/index.ts b/dexs/quickswap-perps/index.ts new file mode 100644 index 0000000000..208c09832b --- /dev/null +++ b/dexs/quickswap-perps/index.ts @@ -0,0 +1,72 @@ +import request, { gql } from "graphql-request"; +import { Adapter, ChainEndpoints, FetchV2 } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints = { + [CHAIN.POLYGON_ZKEVM]: + "https://api.studio.thegraph.com/query/46725/quickperp-subgraph/version/latest", +}; + +interface IVolumeStat { + cumulativeVolumeUsd: string; + volumeUsd: string; + id: string; +} + +const graphs = (graphUrls: ChainEndpoints) => { + const fetch: FetchV2 = async ({ chain, startTimestamp }) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(startTimestamp); + + const graphQuery = gql` + query MyQuery { + volumeStats(where: {timestamp: ${todaysTimestamp}, period: "daily"}) { + cumulativeVolumeUsd + volumeUsd + id + } + } + `; + + const graphRes = await request(graphUrls[chain], graphQuery); + const volumeStats: IVolumeStat[] = graphRes.volumeStats; + + let dailyVolumeUSD = BigInt(0); + let totalVolumeUSD = BigInt(0); + + volumeStats.forEach((vol) => { + dailyVolumeUSD += BigInt(vol.volumeUsd); + totalVolumeUSD += BigInt(vol.cumulativeVolumeUsd); + }); + + const finalDailyVolume = parseInt(dailyVolumeUSD.toString()) / 1e30; + const finalTotalVolume = parseInt(totalVolumeUSD.toString()) / 1e30; + + return { + dailyVolume: finalDailyVolume.toString(), + totalVolume: finalTotalVolume.toString(), + timestamp: todaysTimestamp, + }; + }; + return fetch; +}; + +const methodology = { + dailyVolume: + "Total cumulativeVolumeUsd for specified chain for the given day", +}; + +const adapter: Adapter = { + version: 2, + adapter: { + [CHAIN.POLYGON_ZKEVM]: { + fetch: graphs(endpoints), + start: 1704067200, + meta: { + methodology, + }, + }, + }, +}; + +export default adapter; diff --git a/fees/linehub-v2/index.ts b/fees/linehub-v2/index.ts new file mode 100644 index 0000000000..88e58cb542 --- /dev/null +++ b/fees/linehub-v2/index.ts @@ -0,0 +1,69 @@ +import { gql, request } from "graphql-request"; +import { Adapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; + +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints = { + [CHAIN.LINEA]: + "https://api.studio.thegraph.com/query/55804/linehub-v2/version/latest", +}; + +interface IFeeStat { + cumulativeFeeUsd: string; + feeUsd: string; + id: string; +} + +const fetch = (endpoint) => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); + const period = "daily"; + + const graphQuery = gql`{ + feeStats(where: {timestamp: ${todaysTimestamp}, period: "${period}"}) { + id + timestamp + period + cumulativeFee + cumulativeFeeUsd + feeUsd + } + }`; + + const response = await request(endpoint, graphQuery); + const feeStats: IFeeStat[] = response.feeStats; + + let dailyFeeUSD = BigInt(0); + let totalFeeUSD = BigInt(0); + + feeStats.forEach((fee) => { + dailyFeeUSD += BigInt(fee.feeUsd); + totalFeeUSD += BigInt(fee.cumulativeFeeUsd); + }); + + const finalDailyFee = parseInt(dailyFeeUSD.toString()) / 1e18; + const finalTotalFee = parseInt(totalFeeUSD.toString()) / 1e18; + + return { + timestamp: todaysTimestamp, + dailyFees: finalDailyFee.toString(), + totalFees: finalTotalFee.toString(), + }; + }; +}; + +const adapter: Adapter = { + version: 1, + adapter: { + [CHAIN.LINEA]: { + fetch: fetch(endpoints[CHAIN.LINEA]), + start: 1709251200, + meta: { + methodology: "Fees collected from user trading fees", + }, + }, + }, +}; + +export default adapter; diff --git a/fees/linehub-v3/index.ts b/fees/linehub-v3/index.ts new file mode 100644 index 0000000000..f8033f3cc2 --- /dev/null +++ b/fees/linehub-v3/index.ts @@ -0,0 +1,69 @@ +import { gql, request } from "graphql-request"; +import { Adapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; + +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints = { + [CHAIN.LINEA]: + "https://api.studio.thegraph.com/query/55804/linehub-v3/version/latest", +}; + +interface IFeeStat { + cumulativeFeeUsd: string; + feeUsd: string; + id: string; +} + +const fetch = (endpoint) => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); + const period = "daily"; + + const graphQuery = gql`{ + feeStats(where: {timestamp: ${todaysTimestamp}, period: "${period}"}) { + id + timestamp + period + cumulativeFee + cumulativeFeeUsd + feeUsd + } + }`; + + const response = await request(endpoint, graphQuery); + const feeStats: IFeeStat[] = response.feeStats; + + let dailyFeeUSD = BigInt(0); + let totalFeeUSD = BigInt(0); + + feeStats.forEach((fee) => { + dailyFeeUSD += BigInt(fee.feeUsd); + totalFeeUSD += BigInt(fee.cumulativeFeeUsd); + }); + + const finalDailyFee = parseInt(dailyFeeUSD.toString()) / 1e18; + const finalTotalFee = parseInt(totalFeeUSD.toString()) / 1e18; + + return { + timestamp: todaysTimestamp, + dailyFees: finalDailyFee.toString(), + totalFees: finalTotalFee.toString(), + }; + }; +}; + +const adapter: Adapter = { + version: 1, + adapter: { + [CHAIN.LINEA]: { + fetch: fetch(endpoints[CHAIN.LINEA]), + start: 1709251200, + meta: { + methodology: "Fees collected from user trading fees", + }, + }, + }, +}; + +export default adapter; diff --git a/fees/quickswap-hydra/index.ts b/fees/quickswap-hydra/index.ts new file mode 100644 index 0000000000..2bd19b4955 --- /dev/null +++ b/fees/quickswap-hydra/index.ts @@ -0,0 +1,77 @@ +import { gql, request } from "graphql-request"; +import type { ChainEndpoints } from "../../adapters/types"; +import { Adapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; + +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints: ChainEndpoints = { + [CHAIN.POLYGON_ZKEVM]: + "https://api.studio.thegraph.com/query/55804/hydra-trade/version/latest", + [CHAIN.MANTA]: + "https://api.goldsky.com/api/public/project_cly4708cqpcj601tt7gzf1jdj/subgraphs/manta-trade/latest/gn", +}; +interface IFeeStat { + cumulativeFeeUsd: string; + feeUsd: string; + id: string; +} + +const fetch = (endpoint) => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); + const period = "daily"; + + const graphQuery = gql`{ + feeStats(where: {timestamp: ${todaysTimestamp}, period: "${period}"}) { + id + timestamp + period + cumulativeFee + cumulativeFeeUsd + feeUsd + } + }`; + + const response = await request(endpoint, graphQuery); + const feeStats: IFeeStat[] = response.feeStats; + + let dailyFeeUSD = BigInt(0); + let totalFeeUSD = BigInt(0); + + feeStats.forEach((fee) => { + dailyFeeUSD += BigInt(fee.feeUsd); + totalFeeUSD += BigInt(fee.cumulativeFeeUsd); + }); + const finalDailyFee = parseInt(dailyFeeUSD.toString()) / 1e18; + const finalTotalFee = parseInt(totalFeeUSD.toString()) / 1e18; + + return { + timestamp: todaysTimestamp, + dailyFees: finalDailyFee.toString(), + totalFees: finalTotalFee.toString(), + }; + }; +}; + +const adapter: Adapter = { + version: 1, + adapter: { + [CHAIN.POLYGON_ZKEVM]: { + fetch: fetch(endpoints[CHAIN.POLYGON_ZKEVM]), + start: 1704067200, + meta: { + methodology: "All treasuryFee, poolFee and keeperFee are collected", + }, + }, + [CHAIN.MANTA]: { + fetch: fetch(endpoints[CHAIN.MANTA]), + start: 1704067200, + meta: { + methodology: "All treasuryFee, poolFee and keeperFee are collected", + }, + }, + }, +}; + +export default adapter; diff --git a/fees/quickswap-perps/index.ts b/fees/quickswap-perps/index.ts new file mode 100644 index 0000000000..8601f80e14 --- /dev/null +++ b/fees/quickswap-perps/index.ts @@ -0,0 +1,69 @@ +import { gql, request } from "graphql-request"; +import type { ChainEndpoints } from "../../adapters/types"; +import { Adapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; + +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints: ChainEndpoints = { + [CHAIN.POLYGON_ZKEVM]: + "https://api.studio.thegraph.com/query/46725/quickperp-subgraph/version/latest", +}; +interface IFeeStat { + cumulativeFeeUsd: string; + feeUsd: string; + id: string; +} + +const fetch = (endpoint) => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); + const period = "daily"; + + const graphQuery = gql`{ + feeStats(where: {timestamp: ${todaysTimestamp}, period: "${period}"}) { + id + timestamp + period + cumulativeFee + cumulativeFeeUsd + feeUsd + } + }`; + + const response = await request(endpoint, graphQuery); + const feeStats: IFeeStat[] = response.feeStats; + + let dailyFeeUSD = BigInt(0); + let totalFeeUSD = BigInt(0); + + feeStats.forEach((fee) => { + dailyFeeUSD += BigInt(fee.feeUsd); + totalFeeUSD += BigInt(fee.cumulativeFeeUsd); + }); + + const finalDailyFee = parseInt(dailyFeeUSD.toString()) / 1e30; + const finalTotalFee = parseInt(totalFeeUSD.toString()) / 1e30; + + return { + timestamp: todaysTimestamp, + dailyFees: finalDailyFee.toString(), + totalFees: finalTotalFee.toString(), + }; + }; +}; + +const adapter: Adapter = { + version: 1, + adapter: { + [CHAIN.POLYGON_ZKEVM]: { + fetch: fetch(endpoints[CHAIN.POLYGON_ZKEVM]), + start: 1709251200, + meta: { + methodology: "All treasuryFee, poolFee and keeperFee are collected", + }, + }, + }, +}; + +export default adapter;