forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
57 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,38 +1,49 @@ | ||
import fetchURL from "../../utils/fetchURL" | ||
import { SimpleAdapter } from "../../adapters/types"; | ||
import fetchURL from "../../utils/fetchURL"; | ||
import { BreakdownAdapter, SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
|
||
const START_TIME = 1659312000; | ||
const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats` | ||
const historicalVolumeEndpoint = () => `https://api.carbon.network/carbon/marketstats/v1/stats`; | ||
|
||
interface IVolumeall { | ||
market_type: string; | ||
day_quote_volume: string; | ||
date: string; | ||
} | ||
|
||
const fetch = async (timestamp: number) => { | ||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) | ||
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.marketstats; | ||
const fetch = (market_type: string) => { | ||
return async (timestamp: number) => { | ||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); | ||
const historicalVolume: IVolumeall[] = (await fetchURL(historicalVolumeEndpoint()))?.marketstats; | ||
|
||
const volume = historicalVolume | ||
.filter((e: IVolumeall) => e.market_type === "spot") | ||
.reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18; | ||
const volume = | ||
historicalVolume | ||
.filter((e: IVolumeall) => e.market_type === market_type) | ||
.reduce((a: number, b: IVolumeall) => a + Number(b.day_quote_volume), 0) / 1e18; | ||
|
||
return { | ||
dailyVolume: volume ? `${volume}` : undefined, | ||
timestamp: dayTimestamp, | ||
return { | ||
dailyVolume: volume ? `${volume}` : undefined, | ||
timestamp: dayTimestamp, | ||
}; | ||
}; | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.CARBON]: { | ||
fetch, | ||
start: START_TIME, | ||
const adapters: BreakdownAdapter = { | ||
breakdown: { | ||
demex: { | ||
[CHAIN.CARBON]: { | ||
fetch: fetch("spot"), | ||
start: START_TIME, | ||
}, | ||
}, | ||
"demex-perp": { | ||
[CHAIN.CARBON]: { | ||
fetch: fetch("futures"), | ||
start: START_TIME, | ||
}, | ||
} | ||
}, | ||
}; | ||
|
||
export default adapter; | ||
export default adapters; |