Skip to content

Commit

Permalink
add fees structure to grizzly trade
Browse files Browse the repository at this point in the history
  • Loading branch information
rogsta-dev committed Jul 27, 2023
1 parent c9a5079 commit ee2a5d6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dexs/grizzlyfi/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
70 changes: 70 additions & 0 deletions fees/grizzlyfi.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ee2a5d6

Please sign in to comment.