Skip to content

Commit

Permalink
feat: IntentX Mantle Volume
Browse files Browse the repository at this point in the history
  • Loading branch information
degencreator committed Apr 23, 2024
1 parent a2d2e6b commit 5d76f72
Showing 1 changed file with 116 additions and 18 deletions.
134 changes: 116 additions & 18 deletions dexs/intent-x/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -88,10 +136,14 @@ const toString = (x: BigNumber) => {
};

const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {
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),
Expand Down Expand Up @@ -128,14 +180,20 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {
};
};

const fetchVolumeBlast = async (timestamp: number): Promise<FetchResultVolume> => {
const fetchVolumeBlast = async (
timestamp: number
): Promise<FetchResultVolume> => {
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));
});
Expand All @@ -158,6 +216,42 @@ const fetchVolumeBlast = async (timestamp: number): Promise<FetchResultVolume> =
};
};

const fetchVolumeMantle = async (
timestamp: number
): Promise<FetchResultVolume> => {
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]: {
Expand All @@ -168,6 +262,10 @@ const adapter: SimpleAdapter = {
fetch: fetchVolumeBlast,
start: 1698796800,
},
[CHAIN.MANTLE]: {
fetch: fetchVolumeMantle,
start: 1698796800,
},
},
};

Expand Down

0 comments on commit 5d76f72

Please sign in to comment.