Skip to content

Commit

Permalink
Merge pull request #583 from devflowx/master
Browse files Browse the repository at this point in the history
Add DEX dashboard for FlowX Finance
  • Loading branch information
dtmkeng committed Jul 4, 2023
2 parents e5627a7 + e2149ed commit 7616152
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions dexs/flowx-finance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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
}
exchangeTotalVolume {
totalVolume
}
}
`;
};

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: string;
volume24H: string;
volume7D: string;
}

export interface IExchangeTotalVolume {
totalVolume: string;
}

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const statsRes = await getGQLClient().request(getDailyVolume());
const historicalVolume: IExchangeStats = statsRes.exchangeStats;
const cumulativeVolume: IExchangeTotalVolume = statsRes.exchangeTotalVolume;
return {
totalVolume: cumulativeVolume.totalVolume
? cumulativeVolume.totalVolume
: undefined,
dailyVolume: historicalVolume.volume24H
? `${historicalVolume.volume24H}`
: undefined,
timestamp: dayTimestamp,
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.SUI]: {
fetch: fetch,
start: async () => 1673568000,
},
},
};

export default adapter;

0 comments on commit 7616152

Please sign in to comment.