From a823b3399b7d05ea3bedaaa12aee77e75b6be6b2 Mon Sep 17 00:00:00 2001 From: FlowX Dev Date: Mon, 3 Jul 2023 16:32:50 +0700 Subject: [PATCH 1/2] Add FlowX --- dexs/flowx-finance/index.ts | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 dexs/flowx-finance/index.ts diff --git a/dexs/flowx-finance/index.ts b/dexs/flowx-finance/index.ts new file mode 100644 index 0000000000..ff2e4ef0dc --- /dev/null +++ b/dexs/flowx-finance/index.ts @@ -0,0 +1,62 @@ +import { gql, GraphQLClient } from "graphql-request"; +import { SimpleAdapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; + +const getDailyVolume = () => { + return gql` + { + exchangeStats { + fee24H + totalLiquidity + transaction24H + volume24H + volume7D + totalLiquidityInUSD + } + } + `; +}; + +const graphQLClient = new GraphQLClient( + "https://api.flowx.finance/flowx-be/graphql" +); +const getGQLClient = () => { + return graphQLClient; +}; + +export interface IExchangeStats { + fee24H: string; + totalLiquidity: string; + totalLiquidityInUSD: string; + transaction24H: number; + volume24H: string; + volume7D: string; +} + +const fetch = async (timestamp: number) => { + const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); + const historicalVolume: IExchangeStats = ( + await getGQLClient().request(getDailyVolume()) + ).exchangeStats; + return { + totalVolume: historicalVolume.totalLiquidityInUSD + ? historicalVolume.totalLiquidityInUSD + : undefined, + dailyVolume: historicalVolume.volume24H + ? `${historicalVolume.volume24H}` + : undefined, + timestamp: dayTimestamp, + }; +}; + +const adapter: SimpleAdapter = { + adapter: { + [CHAIN.SUI]: { + fetch: fetch, + start: async () => 1673568000, + }, + }, +}; + +export default adapter; From e2149ed883e76c8d9e4f4f73492fc444920a5913 Mon Sep 17 00:00:00 2001 From: FlowX Dev Date: Tue, 4 Jul 2023 17:34:35 +0700 Subject: [PATCH 2/2] Hotfix: Update total volumes --- dexs/flowx-finance/index.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dexs/flowx-finance/index.ts b/dexs/flowx-finance/index.ts index ff2e4ef0dc..b6bbf260b6 100644 --- a/dexs/flowx-finance/index.ts +++ b/dexs/flowx-finance/index.ts @@ -14,6 +14,9 @@ const getDailyVolume = () => { volume7D totalLiquidityInUSD } + exchangeTotalVolume { + totalVolume + } } `; }; @@ -21,6 +24,7 @@ const getDailyVolume = () => { const graphQLClient = new GraphQLClient( "https://api.flowx.finance/flowx-be/graphql" ); + const getGQLClient = () => { return graphQLClient; }; @@ -29,19 +33,23 @@ export interface IExchangeStats { fee24H: string; totalLiquidity: string; totalLiquidityInUSD: string; - transaction24H: number; + transaction24H: string; volume24H: string; volume7D: string; } +export interface IExchangeTotalVolume { + totalVolume: string; +} + const fetch = async (timestamp: number) => { const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); - const historicalVolume: IExchangeStats = ( - await getGQLClient().request(getDailyVolume()) - ).exchangeStats; + const statsRes = await getGQLClient().request(getDailyVolume()); + const historicalVolume: IExchangeStats = statsRes.exchangeStats; + const cumulativeVolume: IExchangeTotalVolume = statsRes.exchangeTotalVolume; return { - totalVolume: historicalVolume.totalLiquidityInUSD - ? historicalVolume.totalLiquidityInUSD + totalVolume: cumulativeVolume.totalVolume + ? cumulativeVolume.totalVolume : undefined, dailyVolume: historicalVolume.volume24H ? `${historicalVolume.volume24H}`