diff --git a/dexs/bmx-freestyle/index.ts b/dexs/bmx-freestyle/index.ts index 6feafeecf3..b0ffea9888 100644 --- a/dexs/bmx-freestyle/index.ts +++ b/dexs/bmx-freestyle/index.ts @@ -1,12 +1,15 @@ import BigNumber from "bignumber.js"; -import { FetchOptions, FetchResultVolume, SimpleAdapter } from "../../adapters/types"; +import { + FetchOptions, + FetchResultVolume, + SimpleAdapter, +} from "../../adapters/types"; import request, { gql } from "graphql-request"; import { CHAIN } from "../../helpers/chains"; - const freestyleEndpoints: { [key: string]: string } = { [CHAIN.BASE]: - "https://api.studio.thegraph.com/query/62454/analytics_base_8_2/version/latest", + "https://api-v2.morphex.trade/subgraph/3KhmYXgsM3CM1bbUCX8ejhcxQCtWwpUGhP7p9aDKZ94Z", }; interface IGraphResponseFreestyle { @@ -66,50 +69,53 @@ const freestyleQuery = gql` } `; -const fetchFreestyleVolume = async (timestamp: number, _t: any, options: FetchOptions): Promise => { - const startTime = options.startOfDay; - const endTime = startTime + ONE_DAY_IN_SECONDS; - const response: IGraphResponseFreestyle = await request( - freestyleEndpoints[options.chain], - freestyleQuery, - { - from: String(startTime), - to: String(endTime), - } - ); - - let dailyVolume = new BigNumber(0); - let totalVolume = new BigNumber(0); +const fetchFreestyleVolume = async ( + timestamp: number, + _t: any, + options: FetchOptions +): Promise => { + const startTime = options.startOfDay; + const endTime = startTime + ONE_DAY_IN_SECONDS; + const response: IGraphResponseFreestyle = await request( + freestyleEndpoints[options.chain], + freestyleQuery, + { + from: String(startTime), + to: String(endTime), + } + ); - response.dailyHistories.forEach((data) => { - dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume)); - }); - response.totalHistories.forEach((data) => { - totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume)); - }); + let dailyVolume = new BigNumber(0); + let totalVolume = new BigNumber(0); - dailyVolume = dailyVolume.dividedBy(new BigNumber(1e18)); - totalVolume = totalVolume.dividedBy(new BigNumber(1e18)); + response.dailyHistories.forEach((data) => { + dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume)); + }); + response.totalHistories.forEach((data) => { + totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume)); + }); - const _dailyVolume = toString(dailyVolume); - const _totalVolume = toString(totalVolume); + dailyVolume = dailyVolume.dividedBy(new BigNumber(1e18)); + totalVolume = totalVolume.dividedBy(new BigNumber(1e18)); + const _dailyVolume = toString(dailyVolume); + const _totalVolume = toString(totalVolume); - return { - timestamp: timestamp, - dailyVolume: _dailyVolume ?? "0", - totalVolume: _totalVolume ?? "0", - }; + return { + timestamp: timestamp, + dailyVolume: _dailyVolume ?? "0", + totalVolume: _totalVolume ?? "0", }; +}; const adapter: SimpleAdapter = { version: 1, adapter: { [CHAIN.BASE]: { fetch: fetchFreestyleVolume, - start: 0 - } - } -} + start: 1714554000, + }, + }, +}; export default adapter; diff --git a/dexs/bmx/index.ts b/dexs/bmx/index.ts index ce071df1b9..cc3ff2ea5c 100644 --- a/dexs/bmx/index.ts +++ b/dexs/bmx/index.ts @@ -1,26 +1,18 @@ import request, { gql } from "graphql-request"; -import { - BreakdownAdapter, - Fetch -} from "../../adapters/types"; +import { BreakdownAdapter, Fetch } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; import BigNumber from "bignumber.js"; - const startTimestamps: { [chain: string]: number } = { [CHAIN.BASE]: 1694304000, [CHAIN.MODE]: 1720627435, }; const endpoints: { [key: string]: string } = { [CHAIN.BASE]: - "https://api.studio.thegraph.com/query/71696/bmx-base-stats/version/latest", + "https://api-v2.morphex.trade/subgraph/2vZHkWfx8g27Tri5LkTbhvCExCQcXJ3f28X2BwzFhjf6", [CHAIN.MODE]: - "https://api.studio.thegraph.com/query/42444/bmx-mode-stats/version/latest", -}; -const freestyleEndpoints: { [key: string]: string } = { - [CHAIN.BASE]: - "https://api.studio.thegraph.com/query/62454/analytics_base_8_2/version/latest", + "https://api-v2.morphex.trade/subgraph/8tp7xrDSCuutJ5omjfQKHvkGJpLszqPVWg3pby9XMLEz", }; const historicalDataSwap = gql` @@ -154,7 +146,6 @@ const getFetch = }; }; - const adapter: BreakdownAdapter = { breakdown: { swap: Object.keys(endpoints).reduce((acc, chain) => { @@ -166,7 +157,7 @@ const adapter: BreakdownAdapter = { }, }; }, {}), - "derivatives": Object.keys(endpoints).reduce((acc, chain) => { + derivatives: Object.keys(endpoints).reduce((acc, chain) => { return { ...acc, [chain]: { diff --git a/fees/bmx-freestyle.ts b/fees/bmx-freestyle.ts new file mode 100644 index 0000000000..925280474a --- /dev/null +++ b/fees/bmx-freestyle.ts @@ -0,0 +1,113 @@ +import BigNumber from "bignumber.js"; +import request, { gql } from "graphql-request"; +import { FetchOptions, SimpleAdapter } from "../adapters/types"; +import { CHAIN } from "../helpers/chains"; + +const endpoint = + "https://api-v2.morphex.trade/subgraph/3KhmYXgsM3CM1bbUCX8ejhcxQCtWwpUGhP7p9aDKZ94Z"; + +const query = gql` + query stats($from: String!, $to: String!) { + dailyHistories( + where: { + timestamp_gte: $from + timestamp_lte: $to + accountSource: "0x6D63921D8203044f6AbaD8F346d3AEa9A2719dDD" + } + ) { + timestamp + platformFee + accountSource + tradeVolume + } + totalHistories( + where: { accountSource: "0x6D63921D8203044f6AbaD8F346d3AEa9A2719dDD" } + ) { + timestamp + platformFee + accountSource + tradeVolume + } + } +`; + +interface IGraphResponse { + dailyHistories: Array<{ + tiemstamp: string; + platformFee: string; + accountSource: string; + tradeVolume: string; + }>; + totalHistories: Array<{ + tiemstamp: string; + platformFee: string; + accountSource: string; + tradeVolume: BigNumber; + }>; +} + +const toString = (x: BigNumber) => { + if (x.isEqualTo(0)) return undefined; + return x.toString(); +}; + +const fetchVolume = async ({ endTimestamp, startTimestamp }: FetchOptions) => { + const response: IGraphResponse = await request(endpoint, query, { + from: String(startTimestamp), + to: String(endTimestamp), + }); + + // Merging both responses + let dailyFees = new BigNumber(0); + response.dailyHistories.forEach((data) => { + dailyFees = dailyFees.plus(new BigNumber(data.platformFee)); + }); + + let totalFees = new BigNumber(0); + response.totalHistories.forEach((data) => { + totalFees = totalFees.plus(new BigNumber(data.platformFee)); + }); + + dailyFees = dailyFees.dividedBy(new BigNumber(1e18)); + totalFees = totalFees.dividedBy(new BigNumber(1e18)); + + const _dailyFees = toString(dailyFees); + const _totalFees = toString(totalFees); + + const dailyUserFees = _dailyFees; + const dailyRevenue = _dailyFees; + const dailyProtocolRevenue = "0"; + const dailyHoldersRevenue = _dailyFees; + const dailySupplySideRevenue = "0"; + + const totalUserFees = _totalFees; + const totalRevenue = _totalFees; + const totalProtocolRevenue = "0"; + const totalSupplySideRevenue = "0"; + + return { + dailyFees: _dailyFees ?? "0", + totalFees: _totalFees ?? "0", + + dailyUserFees: dailyUserFees ?? "0", + dailyRevenue: dailyRevenue ?? "0", + dailyProtocolRevenue: dailyProtocolRevenue ?? "0", + dailyHoldersRevenue: dailyHoldersRevenue ?? "0", + dailySupplySideRevenue: dailySupplySideRevenue ?? "0", + totalUserFees: totalUserFees ?? "0", + totalRevenue: totalRevenue ?? "0", + totalProtocolRevenue: totalProtocolRevenue ?? "0", + totalSupplySideRevenue: totalSupplySideRevenue ?? "0", + }; +}; + +const adapter: SimpleAdapter = { + version: 2, + adapter: { + [CHAIN.BASE]: { + fetch: fetchVolume, + start: 1714554000, + }, + }, +}; +export default adapter; diff --git a/fees/bmx.ts b/fees/bmx.ts index 42a7f97c46..b359527d08 100644 --- a/fees/bmx.ts +++ b/fees/bmx.ts @@ -1,14 +1,14 @@ import { Adapter } from "../adapters/types"; import { CHAIN } from "../helpers/chains"; import { request, gql } from "graphql-request"; -import type { FetchV2 } from "../adapters/types" +import type { FetchV2 } from "../adapters/types"; import { getTimestampAtStartOfDayUTC } from "../utils/date"; const endpoints: { [key: string]: string } = { [CHAIN.BASE]: - "https://api.studio.thegraph.com/query/71696/bmx-base-stats/version/latest", + "https://api-v2.morphex.trade/subgraph/2vZHkWfx8g27Tri5LkTbhvCExCQcXJ3f28X2BwzFhjf6", [CHAIN.MODE]: - "https://api.studio.thegraph.com/query/42444/bmx-mode-stats/version/latest", + "https://api-v2.morphex.trade/subgraph/8tp7xrDSCuutJ5omjfQKHvkGJpLszqPVWg3pby9XMLEz", }; const methodology = { @@ -48,7 +48,6 @@ const graphs: FetchV2 = async ({ chain, endTimestamp }) => { const finalUserFee = userFee / 1e30; return { - endTimestamp, dailyFees: finalDailyFee.toString(), dailyUserFees: finalUserFee.toString(), dailyRevenue: (finalDailyFee * 0.4).toString(), @@ -73,7 +72,7 @@ const adapter: Adapter = { meta: { methodology, }, - } + }, }, };