Skip to content

Commit

Permalink
feat: add chains and fix timestamp calc
Browse files Browse the repository at this point in the history
Signed-off-by: 0xhitgo <[email protected]>
  • Loading branch information
0xhitgo committed Jan 3, 2025
1 parent 70ac992 commit 8004cee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
19 changes: 8 additions & 11 deletions options/dopex/clamm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { request, gql } from "graphql-request";

import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

interface IGetChainStatsParams {
graphUrl: string;
timestamp: string;
Expand All @@ -22,7 +20,7 @@ interface IQueryResponse {

async function getChainStats({ graphUrl, timestamp }: IGetChainStatsParams) {
const dailyVolumeQuery = gql`
query GetStatsForDefiLamma($fromTimestamp: Int, $toTimestamp: Int) {
query GetStatsForDefiLamma($dayStart: Int!, $nextDayStart: Int!) {
optionMarkets(first: 1000) {
totalFees
totalVolume
Expand All @@ -33,7 +31,7 @@ async function getChainStats({ graphUrl, timestamp }: IGetChainStatsParams) {
first: 1000
orderDirection: asc
orderBy: startTimestamp
where: { startTimestamp_gte: $fromTimestamp, startTimestamp_lte: $toTimestamp, volume_gt: 0 }
where: { startTimestamp_gte: $dayStart, startTimestamp_lt: $nextDayStart }
) {
volume
fees
Expand All @@ -42,15 +40,14 @@ async function getChainStats({ graphUrl, timestamp }: IGetChainStatsParams) {
}
`;

const toTimestamp = getUniqStartOfTodayTimestamp(
new Date(Number(timestamp) * 1000)
);
const fromTimestamp = toTimestamp - 60 * 60 * 24;
// Convert to same day boundaries as subgraph
const dayStart = Math.floor(Number(timestamp) / 86400) * 86400;
const nextDayStart = dayStart + 86400;

const queryResponse: IQueryResponse = await request(
graphUrl,
dailyVolumeQuery,
{ fromTimestamp: fromTimestamp, toTimestamp: toTimestamp }
{ dayStart, nextDayStart }
);

const cumulative = queryResponse.optionMarkets.reduce(
Expand Down Expand Up @@ -86,12 +83,12 @@ async function getChainStats({ graphUrl, timestamp }: IGetChainStatsParams) {
);

return {
timestamp,
timestamp: dayStart.toString(),
...cumulative,
totalFees: cumulative.totalRevenue,
...daily,
dailyFees: daily.dailyRevenue,
};
}

export { getChainStats };
export { getChainStats };
14 changes: 13 additions & 1 deletion options/dopex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ import { CHAIN } from "../../helpers/chains";

const clammEndpoints: { [chain: string]: string } = {
[CHAIN.ARBITRUM]:
"https://api.0xgraph.xyz/subgraphs/name/dopex-v2-clamm-public",
"https://api.0xgraph.xyz/api/public/e2146f32-5728-4755-b1d1-84d17708c119/subgraphs/clamm-arbitrum/prod/gn",
[CHAIN.SONIC]:
"https://api.0xgraph.xyz/api/public/e2146f32-5728-4755-b1d1-84d17708c119/subgraphs/clamm-sonic/prod/gn",
[CHAIN.BASE]:
"https://api.0xgraph.xyz/api/public/e2146f32-5728-4755-b1d1-84d17708c119/subgraphs/clamm-base/prod/gn",
[CHAIN.BLAST]:
"https://api.0xgraph.xyz/api/public/e2146f32-5728-4755-b1d1-84d17708c119/subgraphs/clamm-blast/prod/gn",
[CHAIN.MANTLE]:
"https://api.0xgraph.xyz/api/public/e2146f32-5728-4755-b1d1-84d17708c119/subgraphs/clamm-mantle/prod/gn",
};

const clammStartTimes: { [chain: string]: number } = {
[CHAIN.ARBITRUM]: 1699794000,
[CHAIN.SONIC]: 1735383288,
[CHAIN.BASE]: 1714733688,
[CHAIN.BLAST]: 1714733688,
[CHAIN.MANTLE]: 1706957688,
};

const adapter: BreakdownAdapter = {
Expand Down

0 comments on commit 8004cee

Please sign in to comment.