diff --git a/dexs/equity-spot/index.ts b/dexs/equity-spot/index.ts new file mode 100644 index 0000000000..787908e8e4 --- /dev/null +++ b/dexs/equity-spot/index.ts @@ -0,0 +1,73 @@ +import request, { gql } from "graphql-request"; +import { Fetch, SimpleAdapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; + +const endpoints: { [key: string]: string } = { + [CHAIN.FANTOM]: "https://api.thegraph.com/subgraphs/name/chimpydev/equity-core", +} + +const historicalData = gql` + query get_volume($period: String!, $id: String!) { + volumeStats(where: {period: $period, id: $id}) { + swap + } + } +` + +interface IGraphResponse { + volumeStats: Array<{ + burn: string, + liquidation: string, + margin: string, + mint: string, + swap: string, + }> +} + +const getFetch = (chain: string): Fetch => async (timestamp: number) => { + const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000))) + const dailyData: IGraphResponse = await request(endpoints[chain], historicalData, { + id: String(dayTimestamp) + ':daily', + period: 'daily', + }) + const totalData: IGraphResponse = await request(endpoints[chain], historicalData, { + id: 'total', + period: 'total', + }) + + return { + timestamp: dayTimestamp, + dailyVolume: + dailyData.volumeStats.length == 1 + ? String(Number(Object.values(dailyData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30) + : undefined, + totalVolume: + totalData.volumeStats.length == 1 + ? String(Number(Object.values(totalData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30) + : undefined, + + } +} + +const getStartTimestamp = async (chain: string) => { + const startTimestamps: { [chain: string]: number } = { + [CHAIN.FANTOM]: 1685464000, + } + return startTimestamps[chain] +} + +const adapter: SimpleAdapter = { + adapter: Object.keys(endpoints).reduce((acc, chain) => { + return { + ...acc, + [chain]: { + fetch: getFetch(chain), + start: async () => getStartTimestamp(chain), + runAtCurrTime: true + } + } + }, {}) +} + +export default adapter; diff --git a/fees/equity/index.ts b/fees/equity/index.ts new file mode 100644 index 0000000000..1dd1f55d83 --- /dev/null +++ b/fees/equity/index.ts @@ -0,0 +1,57 @@ +import { Chain } from "@defillama/sdk/build/general"; +import { gql, request } from "graphql-request"; +import type { ChainEndpoints } from "../../adapters/types"; +import { Adapter } from "../../adapters/types"; +import { FANTOM } from "../../helpers/chains"; +import { getTimestampAtStartOfDayUTC } from "../../utils/date"; + +const endpoints = { + [FANTOM]: "https://api.thegraph.com/subgraphs/name/chimpydev/equity-core", +}; + +const graphs = (graphUrls: ChainEndpoints) => { + return (chain: Chain) => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); + const searchTimestamp = todaysTimestamp + ":daily"; + + const graphQuery = gql`{ + feeStat(id: "${searchTimestamp}") { + mint + burn + marginAndLiquidation + swap + } + }`; + + const graphRes = await request(graphUrls[chain], graphQuery); + + const dailyFee = + parseInt(graphRes.feeStat.mint) + + parseInt(graphRes.feeStat.burn) + + parseInt(graphRes.feeStat.marginAndLiquidation) + + parseInt(graphRes.feeStat.swap); + const finalDailyFee = dailyFee / 1e30; + + return { // 100.00% of All & Any Fees generated goes to veEQUAL voters + timestamp, + dailyFees: finalDailyFee.toString(), + dailyRevenue: finalDailyFee.toString(), + }; + }; + }; +}; + +const adapter: Adapter = { + adapter: { + [FANTOM]: { + fetch: graphs(endpoints)(FANTOM), + start: async () => 1685464000, + meta: { + methodology: '100.00% of All & Any Fees generated from All activity on Any Equity Platform Product goes solely to veEQUAL voters.' + } + }, + }, +}; + +export default adapter;