diff --git a/dexs/intent-x/index.tsx b/dexs/intent-x/index.tsx index d05e5dee31..030070c964 100644 --- a/dexs/intent-x/index.tsx +++ b/dexs/intent-x/index.tsx @@ -6,21 +6,32 @@ import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume const ONE_DAY_IN_SECONDS = 60 * 60 * 24; -const endpoint_0_8_0 = "https://api.thegraph.com/subgraphs/name/intent-x/perpetuals-analytics_base"; -const endpoint = "https://api.studio.thegraph.com/query/62472/intentx-analytics_082/version/latest"; -const endpoint_blast = "https://api.studio.thegraph.com/query/62472/intentx-analytics_082_blast/version/latest"; +const endpoint_0_8_0 = + "https://api.thegraph.com/subgraphs/name/intent-x/perpetuals-analytics_base"; +const endpoint = + "https://api.studio.thegraph.com/query/62472/intentx-analytics_082/version/latest"; +const endpoint_blast = + "https://api.studio.thegraph.com/query/62472/intentx-analytics_082_blast/version/latest"; +const endpoint_mantle = + "https://subgraph-api.mantle.xyz/subgraphs/name/mantle_intentx-analytics_082"; const query_0_8_0 = gql` query stats($from: String!, $to: String!) { dailyHistories( - where: { timestamp_gte: $from, timestamp_lte: $to, accountSource: "0x724796d2e9143920B1b58651B04e1Ed201b8cC98" } + where: { + timestamp_gte: $from + timestamp_lte: $to + accountSource: "0x724796d2e9143920B1b58651B04e1Ed201b8cC98" + } ) { timestamp platformFee accountSource tradeVolume } - totalHistories(where: { accountSource: "0x724796d2e9143920B1b58651B04e1Ed201b8cC98" }) { + totalHistories( + where: { accountSource: "0x724796d2e9143920B1b58651B04e1Ed201b8cC98" } + ) { timestamp platformFee accountSource @@ -32,14 +43,20 @@ const query_0_8_0 = gql` const query = gql` query stats($from: String!, $to: String!) { dailyHistories( - where: { timestamp_gte: $from, timestamp_lte: $to, accountSource: "0x8Ab178C07184ffD44F0ADfF4eA2ce6cFc33F3b86" } + where: { + timestamp_gte: $from + timestamp_lte: $to + accountSource: "0x8Ab178C07184ffD44F0ADfF4eA2ce6cFc33F3b86" + } ) { timestamp platformFee accountSource tradeVolume } - totalHistories(where: { accountSource: "0x8Ab178C07184ffD44F0ADfF4eA2ce6cFc33F3b86" }) { + totalHistories( + where: { accountSource: "0x8Ab178C07184ffD44F0ADfF4eA2ce6cFc33F3b86" } + ) { timestamp platformFee accountSource @@ -51,14 +68,45 @@ const query = gql` const queryBlast = gql` query stats($from: String!, $to: String!) { dailyHistories( - where: { timestamp_gte: $from, timestamp_lte: $to, accountSource: "0x083267D20Dbe6C2b0A83Bd0E601dC2299eD99015" } + where: { + timestamp_gte: $from + timestamp_lte: $to + accountSource: "0x083267D20Dbe6C2b0A83Bd0E601dC2299eD99015" + } ) { timestamp platformFee accountSource tradeVolume } - totalHistories(where: { accountSource: "0x083267D20Dbe6C2b0A83Bd0E601dC2299eD99015" }) { + totalHistories( + where: { accountSource: "0x083267D20Dbe6C2b0A83Bd0E601dC2299eD99015" } + ) { + timestamp + platformFee + accountSource + tradeVolume + } + } +`; + +const queryMantle = gql` + query stats($from: String!, $to: String!) { + dailyHistories( + where: { + timestamp_gte: $from + timestamp_lte: $to + accountSource: "0xECbd0788bB5a72f9dFDAc1FFeAAF9B7c2B26E456" + } + ) { + timestamp + platformFee + accountSource + tradeVolume + } + totalHistories( + where: { accountSource: "0xECbd0788bB5a72f9dFDAc1FFeAAF9B7c2B26E456" } + ) { timestamp platformFee accountSource @@ -88,10 +136,14 @@ const toString = (x: BigNumber) => { }; const fetchVolume = async (timestamp: number): Promise => { - const response_0_8_0: IGraphResponse = await request(endpoint_0_8_0, query_0_8_0, { - from: String(timestamp - ONE_DAY_IN_SECONDS), - to: String(timestamp), - }); + const response_0_8_0: IGraphResponse = await request( + endpoint_0_8_0, + query_0_8_0, + { + from: String(timestamp - ONE_DAY_IN_SECONDS), + to: String(timestamp), + } + ); const response: IGraphResponse = await request(endpoint, query, { from: String(timestamp - ONE_DAY_IN_SECONDS), to: String(timestamp), @@ -128,14 +180,20 @@ const fetchVolume = async (timestamp: number): Promise => { }; }; -const fetchVolumeBlast = async (timestamp: number): Promise => { +const fetchVolumeBlast = async ( + timestamp: number +): Promise => { let dailyVolume = new BigNumber(0); let totalVolume = new BigNumber(0); - const response_blast: IGraphResponse = await request(endpoint_blast, queryBlast, { - from: String(timestamp - ONE_DAY_IN_SECONDS), - to: String(timestamp), - }); + const response_blast: IGraphResponse = await request( + endpoint_blast, + queryBlast, + { + from: String(timestamp - ONE_DAY_IN_SECONDS), + to: String(timestamp), + } + ); response_blast.dailyHistories.forEach((data) => { dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume)); }); @@ -158,6 +216,42 @@ const fetchVolumeBlast = async (timestamp: number): Promise = }; }; +const fetchVolumeMantle = async ( + timestamp: number +): Promise => { + let dailyVolume = new BigNumber(0); + let totalVolume = new BigNumber(0); + + const response_mantle: IGraphResponse = await request( + endpoint_mantle, + queryMantle, + { + from: String(timestamp - ONE_DAY_IN_SECONDS), + to: String(timestamp), + } + ); + response_mantle.dailyHistories.forEach((data) => { + dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume)); + }); + response_mantle.totalHistories.forEach((data) => { + totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume)); + }); + + dailyVolume = dailyVolume.dividedBy(new BigNumber(1e18)); + totalVolume = totalVolume.dividedBy(new BigNumber(1e18)); + + const _dailyVolume = toString(dailyVolume); + const _totalVolume = toString(totalVolume); + + const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); + + return { + timestamp: dayTimestamp, + dailyVolume: _dailyVolume ?? "0", + totalVolume: _totalVolume ?? "0", + }; +}; + const adapter: SimpleAdapter = { adapter: { [CHAIN.BASE]: { @@ -168,6 +262,10 @@ const adapter: SimpleAdapter = { fetch: fetchVolumeBlast, start: 1698796800, }, + [CHAIN.MANTLE]: { + fetch: fetchVolumeMantle, + start: 1698796800, + }, }, };