Skip to content

Commit

Permalink
Merge pull request #606 from Xiaxuliang/master
Browse files Browse the repository at this point in the history
add Fee
  • Loading branch information
dtmkeng committed Jul 12, 2023
2 parents f42eb9e + cde4ebb commit 75d6681
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
66 changes: 66 additions & 0 deletions fees/pinnako.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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 { CHAIN } from "../helpers/chains";
import { getTimestampAtStartOfDayUTC } from "../utils/date";

const endpoints = {
[CHAIN.ERA]: "https://api.studio.thegraph.com/query/49418/zkmain_stats/version/latest",

};

const graphs = (graphUrls: ChainEndpoints) => {
return (chain: Chain) => {
return async (timestamp: number) => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp);

const graphQuery = gql`{
feeStat(id: "${todaysTimestamp}",period: "daily") {
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)
) / 1e30
const dailyUserFees = (
parseInt(graphRes.feeStat.marginAndLiquidation) +
parseInt(graphRes.feeStat.swap)
) / 1e30;

return {
timestamp,
dailyFees: dailyFee.toString(),
dailyUserFees: dailyUserFees.toString(),
dailyRevenue: (dailyFee * 0.3).toString()
};
};
};
};

const adapter: Adapter = {
adapter: {
[CHAIN.ERA]: {
fetch: graphs(endpoints)(CHAIN.ERA),
start: async () => 1670659200,
meta: {
methodology: {
Fees: "All mint, burn, margin and liquidation and swap fees are collected",
UserFees: "Users pay swap fees and margin and liquidation fees",
Revenue: "Revenue is calculated as 30% of the total fee.",
}
}
},
},
};

export default adapter;
9 changes: 5 additions & 4 deletions helpers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export enum CHAIN {
FUNCTIONX = "functionx",
ENERGYWEB = "energyweb",
MIXIN = "mixin",
THORCHAIN ="thorchain",
THORCHAIN = "thorchain",
MILKOMEDA = "milkomeda",
FLOW = "flow",
FUSION = "fusion",
CANTO="canto",
CANTO = "canto",
APTOS = "aptos",
NEO = "neo",
PHANTASMA = "phantasma",
Expand All @@ -94,7 +94,7 @@ export enum CHAIN {
OBYTE = "obyte",
CORE = "core",
RPG = "rpg",
WEMIX="wemix",
WEMIX = "wemix",
ZKSYNC = "zksync",
ERA = "era",
DFK = "dfk",
Expand Down Expand Up @@ -131,9 +131,10 @@ const MOONRIVER = "moonriver"
const BITCOIN = "bitcoin";
const LITECOIN = "litecoin";
const DOGE = "doge";

const ZKSYNC = "zksync";
// Don't use
export {
ZKSYNC,
ARBITRUM,
AVAX,
BOBA,
Expand Down

0 comments on commit 75d6681

Please sign in to comment.