From f29f198263033add7a7e129a8ae11d9680fc54fe Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Thu, 27 Jul 2023 16:13:00 +0000 Subject: [PATCH 1/4] add Rollup.Finace --- dexs/rollup-finace/index.ts | 92 +++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 dexs/rollup-finace/index.ts diff --git a/dexs/rollup-finace/index.ts b/dexs/rollup-finace/index.ts new file mode 100644 index 0000000000..fcaf3b74d9 --- /dev/null +++ b/dexs/rollup-finace/index.ts @@ -0,0 +1,92 @@ +import request, { gql } from "graphql-request"; +import { BreakdownAdapter, Fetch, SimpleAdapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; + +const endpoints: { [key: string]: string } = { + [CHAIN.ERA]: "https://subgraph.rollup.finance/subgraphs/name/rollUp/stats", +} + +const historicalDataSwap = gql` + query get_volume($period: String!, $id: String!) { + volumeStats(where: {period: $period, id: $id}) { + swap + } + } +` + +const historicalDataDerivatives = gql` + query get_volume($period: String!, $id: String!) { + volumeStats(where: {period: $period, id: $id}) { + liquidation + margin + } + } +` + +interface IGraphResponse { + volumeStats: Array<{ + burn: string, + liquidation: string, + margin: string, + mint: string, + swap: string, + }> +} + +const getFetch = (query: string)=> (chain: string): Fetch => async (timestamp: number) => { + const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000))) + const dailyData: IGraphResponse = await request(endpoints[chain], query, { + id: String(dayTimestamp), + period: 'daily', + }) + const totalData: IGraphResponse = await request(endpoints[chain], query, { + 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.ERA]: 1682035200, + } + return startTimestamps[chain] +} + +const adapter: BreakdownAdapter = { + breakdown: { + // "swap": Object.keys(endpoints).reduce((acc, chain) => { + // return { + // ...acc, + // [chain]: { + // fetch: getFetch(historicalDataSwap)(chain), + // start: async () => getStartTimestamp(chain) + // } + // } + // }, {}), + "derivatives": Object.keys(endpoints).reduce((acc, chain) => { + return { + ...acc, + [chain]: { + fetch: getFetch(historicalDataDerivatives)(chain), + start: async () => getStartTimestamp(chain) + } + } + }, {}) + } +} + +export default adapter; From 543bac5f0c17f5669f1b5081bc9fc7bddca51386 Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Thu, 27 Jul 2023 16:41:26 +0000 Subject: [PATCH 2/4] add fees --- fees/rollup-finace.ts | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 fees/rollup-finace.ts diff --git a/fees/rollup-finace.ts b/fees/rollup-finace.ts new file mode 100644 index 0000000000..557093c14d --- /dev/null +++ b/fees/rollup-finace.ts @@ -0,0 +1,55 @@ +import { Adapter } from "../adapters/types"; +import { ARBITRUM, AVAX, CHAIN } from "../helpers/chains"; +import { request, gql } from "graphql-request"; +import type { ChainEndpoints } from "../adapters/types" +import { Chain } from '@defillama/sdk/build/general'; +import { getTimestampAtStartOfDayUTC } from "../utils/date"; + +const endpoints = { + [CHAIN.ERA]: "https://subgraph.rollup.finance/subgraphs/name/rollUp/stats", +} + + +const graphs = (graphUrls: ChainEndpoints) => { + return (chain: Chain) => { + return async (timestamp: number) => { + const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp) + const searchTimestamp = todaysTimestamp; + + const graphQuery = gql + `{ + feeStat(id: "${searchTimestamp}") { + mint + burn + marginAndLiquidation + } + }`; + + const graphRes = await request(graphUrls[chain], graphQuery); + console.log(graphRes) + + const dailyFee = parseInt(graphRes.feeStat.mint) + parseInt(graphRes.feeStat.burn) + parseInt(graphRes.feeStat.marginAndLiquidation); + const finalDailyFee = (dailyFee / 1e30); + const userFee = parseInt(graphRes.feeStat.marginAndLiquidation) + const finalUserFee = (userFee / 1e30); + + return { + timestamp, + dailyFees: finalDailyFee.toString(), + dailyUserFees: finalUserFee.toString(), + }; + }; + }; +}; + + +const adapter: Adapter = { + adapter: { + [CHAIN.ERA]: { + fetch: graphs(endpoints)(CHAIN.ERA), + start: async () => 1682035200, + }, + } +} + +export default adapter; From 7cebbdc449261c248f128819eaeabd15a452ca42 Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Wed, 2 Aug 2023 11:56:16 +0000 Subject: [PATCH 3/4] fix fees --- dexs/rollup-finace/index.ts | 13 +++++++++---- fees/rollup-finace.ts | 25 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/dexs/rollup-finace/index.ts b/dexs/rollup-finace/index.ts index fcaf3b74d9..51a391c699 100644 --- a/dexs/rollup-finace/index.ts +++ b/dexs/rollup-finace/index.ts @@ -36,21 +36,26 @@ interface IGraphResponse { const getFetch = (query: string)=> (chain: string): Fetch => async (timestamp: number) => { const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000))) + const fromTimestamp = dayTimestamp - 60 * 60 * 24 const dailyData: IGraphResponse = await request(endpoints[chain], query, { id: String(dayTimestamp), period: 'daily', }) + const yesterDay: IGraphResponse = await request(endpoints[chain], query, { + id: String(fromTimestamp), + period: 'daily', + }) const totalData: IGraphResponse = await request(endpoints[chain], query, { id: 'total', period: 'total', }) + const todayVolume = Number(Object.values(dailyData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30 + const yesterdayVolume = Number(Object.values(yesterDay.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30 + const dailyVolume = (todayVolume - yesterdayVolume); 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, + dailyVolume: `${dailyVolume}`, totalVolume: totalData.volumeStats.length == 1 ? String(Number(Object.values(totalData.volumeStats[0]).reduce((sum, element) => String(Number(sum) + Number(element)))) * 10 ** -30) diff --git a/fees/rollup-finace.ts b/fees/rollup-finace.ts index 557093c14d..e2467a7e26 100644 --- a/fees/rollup-finace.ts +++ b/fees/rollup-finace.ts @@ -14,6 +14,7 @@ const graphs = (graphUrls: ChainEndpoints) => { return (chain: Chain) => { return async (timestamp: number) => { const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp) + const fromTimestamp = todaysTimestamp - 60 * 60 * 24 const searchTimestamp = todaysTimestamp; const graphQuery = gql @@ -25,18 +26,36 @@ const graphs = (graphUrls: ChainEndpoints) => { } }`; + const graphQueryYesterday = gql + `{ + feeStat(id: "${fromTimestamp}") { + mint + burn + marginAndLiquidation + } + }`; + + const graphRes = await request(graphUrls[chain], graphQuery); - console.log(graphRes) + const graphResYesterday = await request(graphUrls[chain], graphQueryYesterday); + const dailyFee = parseInt(graphRes.feeStat.mint) + parseInt(graphRes.feeStat.burn) + parseInt(graphRes.feeStat.marginAndLiquidation); const finalDailyFee = (dailyFee / 1e30); const userFee = parseInt(graphRes.feeStat.marginAndLiquidation) const finalUserFee = (userFee / 1e30); + const dailyFeePrev = parseInt(graphResYesterday.feeStat.mint) + parseInt(graphResYesterday.feeStat.burn) + parseInt(graphResYesterday.feeStat.marginAndLiquidation); + const finalDailyFeePrev = (dailyFeePrev / 1e30); + const userFeePrev = parseInt(graphResYesterday.feeStat.marginAndLiquidation) + const finalUserFeePrev = (userFeePrev / 1e30); + const dailyFees = finalDailyFee - finalDailyFeePrev; + const dailyUserFees = finalUserFee - finalUserFeePrev; + return { timestamp, - dailyFees: finalDailyFee.toString(), - dailyUserFees: finalUserFee.toString(), + dailyFees: dailyFees ? dailyFees.toString() : undefined, + dailyUserFees: dailyUserFees ? dailyUserFees.toString() : undefined, }; }; }; From facea24838d4ae2a76216375fc1216312d6a3dee Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Wed, 2 Aug 2023 11:57:23 +0000 Subject: [PATCH 4/4] fix date --- dexs/rollup-finace/index.ts | 2 +- fees/rollup-finace.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dexs/rollup-finace/index.ts b/dexs/rollup-finace/index.ts index 51a391c699..1be5977980 100644 --- a/dexs/rollup-finace/index.ts +++ b/dexs/rollup-finace/index.ts @@ -66,7 +66,7 @@ const getFetch = (query: string)=> (chain: string): Fetch => async (timestamp: n const getStartTimestamp = async (chain: string) => { const startTimestamps: { [chain: string]: number } = { - [CHAIN.ERA]: 1682035200, + [CHAIN.ERA]: 1688256000, } return startTimestamps[chain] } diff --git a/fees/rollup-finace.ts b/fees/rollup-finace.ts index e2467a7e26..9bb97fdf48 100644 --- a/fees/rollup-finace.ts +++ b/fees/rollup-finace.ts @@ -66,7 +66,7 @@ const adapter: Adapter = { adapter: { [CHAIN.ERA]: { fetch: graphs(endpoints)(CHAIN.ERA), - start: async () => 1682035200, + start: async () => 1688256000, }, } }