Skip to content

Commit

Permalink
fix jediswap-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Feb 19, 2024
1 parent ea3b4b3 commit 4510852
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions dexs/jediswap-v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ChainBlocks, FetchOptions, FetchResult, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { gql, request } from "graphql-request";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

interface IGraph {
dayId: number;
date: string;
pairId: string;
totalVolumeUSD: string;
dailyVolumeUSD: string;
reserveUSD: string;
}

const URL = 'https://api.v2.jediswap.xyz/graphql';

const fetch = async (timestamp: number, _: ChainBlocks, { createBalances }: FetchOptions): Promise<FetchResult> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dayID = Math.floor(dayTimestamp / 86400);
const query = gql`
{
poolsDayData(first:1000, orderBy:"dayId", orderByDirection:"desc") {
dayId
volumeUSD
datetime
}
}
`
const response: IGraph[] = (await request(URL, query)).pairDayDatas;
const volume = response.filter(e =>Number(e.reserveUSD) > 10000)
.filter((e: IGraph) => e.dayId === dayID)
.sort((a: IGraph, b: IGraph) => Number(b.dailyVolumeUSD) - Number(a.dailyVolumeUSD))
.filter((e: IGraph) => Number(e.dailyVolumeUSD) < 10_000_000)
.reduce((acc: number, e: IGraph) => e.dailyVolumeUSD ? acc + Number(e.dailyVolumeUSD) : acc, 0);
const dailyVolume = createBalances();
dailyVolume.addCGToken('tether', volume);
return {
dailyVolume: dailyVolume,
timestamp: dayTimestamp,
};
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.STARKNET]: {
fetch: fetch,
start: 1707523200,
},
},
};

export default adapter;

0 comments on commit 4510852

Please sign in to comment.