From c9a5079f1ea3f725faf48d0babd3fe41c030e822 Mon Sep 17 00:00:00 2001 From: Roger Staubli Date: Thu, 27 Jul 2023 13:33:10 +0200 Subject: [PATCH 1/4] add volumes to trade.grizzly.fi --- dexs/grizzlyfi/index.ts | 110 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 dexs/grizzlyfi/index.ts diff --git a/dexs/grizzlyfi/index.ts b/dexs/grizzlyfi/index.ts new file mode 100644 index 0000000000..2cabce4e0f --- /dev/null +++ b/dexs/grizzlyfi/index.ts @@ -0,0 +1,110 @@ +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.BSC]: "https://api.thegraph.com/subgraphs/name/metavault-trade/grizzly-bnb-subgraph", +} + +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 + } + } +` + +const historicalDataGll = gql` + query get_volume($period: String!, $id: String!) { + volumeStats(where: {period: $period, id: $id}) { + mint + burn + } + } +` + +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) + ':daily', + 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.BSC]: 1689897600, + } + 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) + } + } + }, {}), + "gll": Object.keys(endpoints).reduce((acc, chain) => { + return { + ...acc, + [chain]: { + fetch: getFetch(historicalDataGll)(chain), + start: async () => getStartTimestamp(chain) + } + } + }, {}) + } +} + +export default adapter; From ee2a5d66f7daa5bfa74ce3eeab351e546c6bdce5 Mon Sep 17 00:00:00 2001 From: Roger Staubli Date: Thu, 27 Jul 2023 13:57:39 +0200 Subject: [PATCH 2/4] add fees structure to grizzly trade --- dexs/grizzlyfi/index.ts | 2 +- fees/grizzlyfi.ts | 70 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 fees/grizzlyfi.ts diff --git a/dexs/grizzlyfi/index.ts b/dexs/grizzlyfi/index.ts index 2cabce4e0f..fefc664814 100644 --- a/dexs/grizzlyfi/index.ts +++ b/dexs/grizzlyfi/index.ts @@ -1,5 +1,5 @@ import request, { gql } from "graphql-request"; -import { BreakdownAdapter, Fetch, SimpleAdapter } from "../../adapters/types"; +import { BreakdownAdapter, Fetch } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; diff --git a/fees/grizzlyfi.ts b/fees/grizzlyfi.ts new file mode 100644 index 0000000000..fd1d8eae76 --- /dev/null +++ b/fees/grizzlyfi.ts @@ -0,0 +1,70 @@ +import { Adapter } from "../adapters/types"; +import { ARBITRUM, AVAX, BSC } 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 = { + [BSC]: "https://api.thegraph.com/subgraphs/name/metavault-trade/grizzly-bnb-subgraph" +} + +const methodology = { + Fees: "Fees from open/close position (0.1%), swap (0.2% to 0.8%), mint and burn (based on tokens balance in the pool) and borrow fee ((assets borrowed)/(total assets in pool)*0.01%)", + UserFees: "Fees from open/close position (0.1%), swap (0.2% to 0.8%) and borrow fee ((assets borrowed)/(total assets in pool)*0.01%)", + HoldersRevenue: "10% goes to MVX stakers and 25% are buyback and burn of GHNY", + SupplySideRevenue: "50% of all collected fees goes to GLL holders", + Revenue: "15% Protocol revenue, 10% goes to MVX stakers and 25% are buyback and burn of GHNY", + ProtocolRevenue: "10% of all collected fees goes to Grizzly.fi treasury and 5% goes to marketing" +} + +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); + const userFee = parseInt(graphRes.feeStat.marginAndLiquidation) + parseInt(graphRes.feeStat.swap) + const finalUserFee = (userFee / 1e30); + + return { + timestamp, + dailyFees: finalDailyFee.toString(), + dailyUserFees: finalUserFee.toString(), + dailyRevenue: (finalDailyFee * 0.1 + finalDailyFee * 0.25 + finalDailyFee * 0.15).toString(), + dailyProtocolRevenue: (finalDailyFee * 0.15).toString(), + dailyHoldersRevenue: (finalDailyFee * 0.1 + finalDailyFee * 0.25).toString(), + dailySupplySideRevenue: (finalDailyFee * 0.5).toString() + }; + }; + }; +}; + + +const adapter: Adapter = { + adapter: { + [BSC]: { + fetch: graphs(endpoints)(BSC), + start: async () => 1689897600, + meta: { + methodology + } + }, + } +} + +export default adapter; From e033d04736415bcd9c1d9f31a5f69b81b896e18f Mon Sep 17 00:00:00 2001 From: Roger Staubli Date: Thu, 27 Jul 2023 14:10:19 +0200 Subject: [PATCH 3/4] change grizzly project name --- dexs/{grizzlyfi => grizzly-trade}/index.ts | 0 fees/{grizzlyfi.ts => grizzly-trade.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename dexs/{grizzlyfi => grizzly-trade}/index.ts (100%) rename fees/{grizzlyfi.ts => grizzly-trade.ts} (100%) diff --git a/dexs/grizzlyfi/index.ts b/dexs/grizzly-trade/index.ts similarity index 100% rename from dexs/grizzlyfi/index.ts rename to dexs/grizzly-trade/index.ts diff --git a/fees/grizzlyfi.ts b/fees/grizzly-trade.ts similarity index 100% rename from fees/grizzlyfi.ts rename to fees/grizzly-trade.ts From 528d5ca72e2317cc9a46321281ab8622da63600d Mon Sep 17 00:00:00 2001 From: Roger Staubli Date: Mon, 31 Jul 2023 11:29:37 +0200 Subject: [PATCH 4/4] remove GLL --- dexs/grizzly-trade/index.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/dexs/grizzly-trade/index.ts b/dexs/grizzly-trade/index.ts index fefc664814..5053afd9e3 100644 --- a/dexs/grizzly-trade/index.ts +++ b/dexs/grizzly-trade/index.ts @@ -24,14 +24,6 @@ const historicalDataDerivatives = gql` } ` -const historicalDataGll = gql` - query get_volume($period: String!, $id: String!) { - volumeStats(where: {period: $period, id: $id}) { - mint - burn - } - } -` interface IGraphResponse { volumeStats: Array<{ @@ -94,15 +86,6 @@ const adapter: BreakdownAdapter = { start: async () => getStartTimestamp(chain) } } - }, {}), - "gll": Object.keys(endpoints).reduce((acc, chain) => { - return { - ...acc, - [chain]: { - fetch: getFetch(historicalDataGll)(chain), - start: async () => getStartTimestamp(chain) - } - } }, {}) } }