-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #2030 from wombat-exchange/feat/capybara-perp
feat: add capybara perp
- Loading branch information
Showing
1 changed file
with
58 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,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; |