diff --git a/options/dopex/clamm.ts b/options/dopex/clamm.ts index cdf98bf9bf..d2ef1119f5 100644 --- a/options/dopex/clamm.ts +++ b/options/dopex/clamm.ts @@ -1,7 +1,5 @@ import { request, gql } from "graphql-request"; -import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; - interface IGetChainStatsParams { graphUrl: string; timestamp: string; @@ -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 @@ -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 @@ -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( @@ -86,7 +83,7 @@ async function getChainStats({ graphUrl, timestamp }: IGetChainStatsParams) { ); return { - timestamp, + timestamp: dayStart.toString(), ...cumulative, totalFees: cumulative.totalRevenue, ...daily, @@ -94,4 +91,4 @@ async function getChainStats({ graphUrl, timestamp }: IGetChainStatsParams) { }; } -export { getChainStats }; +export { getChainStats }; \ No newline at end of file diff --git a/options/dopex/index.ts b/options/dopex/index.ts index f669937ce4..64b72fe29a 100644 --- a/options/dopex/index.ts +++ b/options/dopex/index.ts @@ -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 = {