Skip to content

Commit

Permalink
listing Grix protocol (DefiLlama#2135)
Browse files Browse the repository at this point in the history
* 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
Tomelia1999 and g1nt0ki authored Nov 28, 2024
1 parent fdbc2e7 commit dd0e316
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adapters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ export const whitelistedDimensionKeys = new Set([

export interface IJSON<T> {
[key: string]: T
}
}
53 changes: 53 additions & 0 deletions aggregator-options/grix/index.ts
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;

0 comments on commit dd0e316

Please sign in to comment.