-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #583 from devflowx/master
Add DEX dashboard for FlowX Finance
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |