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.
listing Grix protocol (DefiLlama#2135)
* asking to list grix protocol as an aggregator-options. we currently provide only 'total notional value' and working on adding last24Hours notional volume * implementing refactoring notes * adding daily notional volume * minor fix --------- Co-authored-by: g1nt0ki <[email protected]>
- Loading branch information
1 parent
fdbc2e7
commit dd0e316
Showing
2 changed files
with
54 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -191,4 +191,4 @@ export const whitelistedDimensionKeys = new Set([ | |
|
||
export interface IJSON<T> { | ||
[key: string]: T | ||
} | ||
} |
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,53 @@ | ||
import { FetchOptions, SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { httpGet } from "../../utils/fetchURL"; | ||
|
||
export type GrixMetricsData = { | ||
totalNotionalVolume: string; | ||
totalNotionalVolume24Hr: string; | ||
}; | ||
|
||
|
||
const fetchGrix = async ({ endTimestamp}: FetchOptions) => { | ||
/** Timestamp representing the end of the 24 hour period */ | ||
const url = `https://internal-api-dev.grix.finance/volumeData?endTimestamp=${endTimestamp}`; | ||
|
||
const grixMetricsResponse = await httpGet(url); | ||
const grixMetricsData = parseGrixMetricsData(grixMetricsResponse); | ||
|
||
if (!grixMetricsData) { | ||
throw new Error("No data found when fetching Grix volume data"); | ||
} | ||
|
||
const totalNotionalVolume = Number(grixMetricsData.totalNotionalVolume); | ||
const dailyNotionalVolume = Number(grixMetricsData.totalNotionalVolume24Hr); | ||
|
||
return { | ||
totalNotionalVolume, | ||
dailyNotionalVolume, | ||
}; | ||
}; | ||
|
||
const parseGrixMetricsData = (result: any): GrixMetricsData | null => { | ||
if (typeof result === "object" && result !== null) { | ||
return result as GrixMetricsData; | ||
} | ||
return result ? (JSON.parse(result) as GrixMetricsData) : null; | ||
}; | ||
|
||
const grix_adapter: SimpleAdapter = { | ||
version: 2, | ||
adapter: { | ||
[CHAIN.ARBITRUM]: { | ||
fetch: fetchGrix, | ||
start: "2024-11-01", | ||
runAtCurrTime: true, // currently we don't take the timestamp into account, should be changed soon | ||
meta: { | ||
methodology: | ||
"The total value of the underlying assets for all options traded. It is calculated as the spot price (at the trade instance) multiplied by the contract size.", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default grix_adapter; |