Skip to content

Commit

Permalink
Merge pull request #2030 from wombat-exchange/feat/capybara-perp
Browse files Browse the repository at this point in the history
feat: add capybara perp
  • Loading branch information
dtmkeng authored Oct 22, 2024
2 parents e157f25 + ec26afa commit be26631
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions dexs/capybara-perp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import request, { gql } from 'graphql-request';
import {FetchOptions, FetchResultV2, FetchV2, SimpleAdapter} from '../../adapters/types';
import { CHAIN } from '../../helpers/chains';
import {
getUniqStartOfTodayTimestamp,
} from '../../helpers/getUniSubgraphVolume';

const ENDPOINTS: { [key: string]: string } = {
[CHAIN.KLAYTN]: 'https://klaytn-graphnode.ecosystem-dev.klaytn.in/cypress/graph/http/subgraphs/name/capy-beta-u/perp',
};

const getVolume = gql`
query get_volume($id: String!) {
market(id: "1") {
id
tradeVolumeUSD
marketDayDatas(where: {id: $id}) {
id
tradeVolumeUSD
}
}
}
`;


const getFetch = (chain: string): FetchV2 => async (options: FetchOptions): Promise<FetchResultV2> => {
const { startTimestamp} = options;
const dayTimestamp = getUniqStartOfTodayTimestamp(
new Date(startTimestamp * 1000)
);
const dayIndex = Math.floor(options.startOfDay / 86400);

const { market: response } = await request(ENDPOINTS[chain],
getVolume, {
id: String(dayIndex),
});

return {
timestamp: getUniqStartOfTodayTimestamp(new Date(dayTimestamp)),
dailyVolume:
response.marketDayDatas.length === 1
? response.marketDayDatas[0].tradeVolumeUSD
: '0',
totalVolume: response.tradeVolumeUSD,
};
};

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.KLAYTN]: {
fetch: getFetch(CHAIN.KLAYTN),
start: 1727568000,
},
},
};

export default adapter;

0 comments on commit be26631

Please sign in to comment.