diff --git a/dexs/quenta/index.ts b/dexs/quenta/index.ts new file mode 100644 index 0000000000..67ddb297f5 --- /dev/null +++ b/dexs/quenta/index.ts @@ -0,0 +1,58 @@ +import { Adapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { GraphQLClient } from "graphql-request"; +import type { FetchOptions } from "../../adapters/types"; + + +const endpoints = { + [CHAIN.IOTEX]: "https://gql.quenta.io/subgraphs/name/iotex/quenta" +}; + +async function fetch({ getFromBlock, getToBlock, chain, }: FetchOptions) { + const fromBlock = await getFromBlock() + const toBlock = await getToBlock() + + const graphQLClient = new GraphQLClient(endpoints[chain]); + // get total volume + const tradeVolumeQuery = ` + { + protocolMetrics(block:{number:${toBlock}}){ + totalVolume + } + } + `; + + // get total volume 24 hours ago + const lastTradeVolumeQuery = ` + { + protocolMetrics(block:{number:${fromBlock}}){ + totalVolume + } + } + `; + + + let { protocolMetrics: [{ totalVolume }] } = await graphQLClient.request(tradeVolumeQuery) + let { protocolMetrics: [{ totalVolume: totalVolumePast }] } = await graphQLClient.request(lastTradeVolumeQuery) + + totalVolume = totalVolume / 1e6 + totalVolumePast = totalVolumePast / 1e6 + console.log(fromBlock, toBlock, totalVolume, totalVolumePast) + return { + totalVolume, + dailyVolume: totalVolume - totalVolumePast, + }; +} + + +const adapter: Adapter = { + version: 2, + adapter: { + [CHAIN.IOTEX]: { + fetch, + start: 29643703, + }, + }, +}; + +export default adapter; diff --git a/fees/quenta/index.ts b/fees/quenta/index.ts new file mode 100644 index 0000000000..8fa24b3a7b --- /dev/null +++ b/fees/quenta/index.ts @@ -0,0 +1,58 @@ +import { Adapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { GraphQLClient } from "graphql-request"; +import type { FetchOptions } from "../../adapters/types"; + + +const endpoints = { + [CHAIN.IOTEX]: "https://gql.quenta.io/subgraphs/name/iotex/quenta" +}; + +async function fetch({ getFromBlock, getToBlock, chain, }: FetchOptions) { + + const fromBlock = await getFromBlock() + const toBlock = await getToBlock() + + const graphQLClient = new GraphQLClient(endpoints[chain]); + // get total volume + const tradeVolumeQuery = ` + { + protocolMetrics(block:{number:${toBlock}}){ + totalFee + } + } + `; + + // get total volume 24 hours ago + const lastTradeVolumeQuery = ` + { + protocolMetrics(block:{number:${fromBlock}}){ + totalFee + } + } + `; + + + let { protocolMetrics: [{ totalFee: totalVolume }] } = await graphQLClient.request(tradeVolumeQuery) + let { protocolMetrics: [{ totalFee: totalVolumePast }] } = await graphQLClient.request(lastTradeVolumeQuery) + + totalVolume = totalVolume / 1e6 + totalVolumePast = totalVolumePast / 1e6 + return { + totalVolume, + dailyVolume: totalVolume - totalVolumePast, + }; +} + + +const adapter: Adapter = { + version: 2, + adapter: { + [CHAIN.IOTEX]: { + fetch, + start: 29643703, + }, + }, +}; + +export default adapter;