Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparkdex #1974

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dexs/sparkdex-v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const endpoints = {
[CHAIN.FLARE]:
"https://api.goldsky.com/api/public/project_cly4708cqpcj601tt7gzf1jdj/subgraphs/sparkdex-v2/latest/gn",
};

export default univ2Adapter2(endpoints, {
factoriesName: "factories",
totalVolume: "volumeUSD",
dayData: "factoryDaySnapshot",
dailyVolume: "volumeUSD",
dailyVolumeTimestampField: "timestamp",
});
60 changes: 60 additions & 0 deletions dexs/sparkdex-v3-1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Chain } from "@defillama/sdk/build/general";
import { CHAIN } from "../../helpers/chains";
import { getGraphDimensions2 } from "../../helpers/getUniSubgraph";
import { BreakdownAdapter } from "../../adapters/types";

const endpointsV3 = {
[CHAIN.FLARE]:
"https://api.goldsky.com/api/public/project_cm1tgcbwdqg8b01un9jf4a64o/subgraphs/sparkdex-v3-2/latest/gn",
};

const v3Graphs = getGraphDimensions2({
graphUrls: endpointsV3,
totalVolume: {
factory: "factories",
field: "totalVolumeUSD",
},
feesPercent: {
type: "fees",
ProtocolRevenue: 0,
HoldersRevenue: 0,
UserFees: 100, // User fees are 100% of collected fees
SupplySideRevenue: 100, // 100% of fees are going to LPs
Revenue: 0, // Set revenue to 0 as protocol fee is not set for all pools for now
},
});

const startTimeV3: { [key: string]: number } = {
[CHAIN.FLARE]: 1719878400,
};

const v3 = Object.keys(endpointsV3).reduce(
(acc, chain) => ({
...acc,
[chain]: {
fetch: v3Graphs(chain as Chain),
start: startTimeV3[chain],
meta: {
methodology: {
Fees: "Each pool charge between 0.01% to 1% fee",
UserFees: "Users pay between 0.01% to 1% fee",
Revenue: "0 to 1/4 of the fee goes to treasury",
HoldersRevenue: "None",
ProtocolRevenue: "Treasury receives a share of the fees",
SupplySideRevenue:
"Liquidity providers get most of the fees of all trades in their pools",
},
},
},
}),
{}
);

const adapter: BreakdownAdapter = {
version: 2,
breakdown: {
v3: v3,
},
};

export default adapter;
69 changes: 69 additions & 0 deletions fees/sparkdex-v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { gql, request } from "graphql-request";
import { Adapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

import { getTimestampAtStartOfDayUTC } from "../../utils/date";

const endpoints = {
[CHAIN.FLARE]:
"https://api.goldsky.com/api/public/project_cly4708cqpcj601tt7gzf1jdj/subgraphs/sparkdex-v2/latest/gn",
};

interface IFeeStat {
cumulativeFeeUsd: string;
feeUsd: string;
id: string;
}

const fetch = (endpoint) => {
return async (timestamp: number) => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp);
const period = "daily";

const graphQuery = gql`{
feeStats(where: {timestamp: ${todaysTimestamp}, period: "${period}"}) {
id
timestamp
period
cumulativeFee
cumulativeFeeUsd
feeUsd
}
}`;

const response = await request(endpoint, graphQuery);
const feeStats: IFeeStat[] = response.feeStats;

let dailyFeeUSD = BigInt(0);
let totalFeeUSD = BigInt(0);

feeStats.forEach((fee) => {
dailyFeeUSD += BigInt(fee.feeUsd);
totalFeeUSD += BigInt(fee.cumulativeFeeUsd);
});

const finalDailyFee = parseInt(dailyFeeUSD.toString()) / 1e18;
const finalTotalFee = parseInt(totalFeeUSD.toString()) / 1e18;

return {
timestamp: todaysTimestamp,
dailyFees: finalDailyFee.toString(),
totalFees: finalTotalFee.toString(),
};
};
};

const adapter: Adapter = {
version: 1,
adapter: {
[CHAIN.FLARE]: {
fetch: fetch(endpoints[CHAIN.FLARE]),
start: 1709251200,
meta: {
methodology: "Fees collected from user trading fees",
},
},
},
};

export default adapter;
73 changes: 73 additions & 0 deletions fees/sparkdex-v3-1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { gql, request } from "graphql-request";
import type { ChainEndpoints, FetchV2 } from "../../adapters/types";
import { Adapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

import { getTimestampAtStartOfDayUTC } from "../../utils/date";

const endpoints = {
[CHAIN.FLARE]:
"https://api.goldsky.com/api/public/project_cm1tgcbwdqg8b01un9jf4a64o/subgraphs/sparkdex-v3-2/latest/gn",
};

interface IFeeStat {
cumulativeFeeUsd: string;
feeUsd: string;
id: string;
}

const graphs = (graphUrls: ChainEndpoints) => {
const fetch: FetchV2 = async ({ chain, startTimestamp }) => {
const todaysTimestamp = getTimestampAtStartOfDayUTC(startTimestamp);

const graphQuery = gql`
query MyQuery {
feeStats(where: {timestamp: ${todaysTimestamp}, period: daily}) {
cumulativeFeeUsd
feeUsd
id
}
}
`;

const graphRes = await request(graphUrls[chain], graphQuery);
const feeStats: IFeeStat[] = graphRes.feeStats;

let dailyFeeUSD = BigInt(0);
let totalFeeUSD = BigInt(0);

feeStats.forEach((fee) => {
dailyFeeUSD += BigInt(fee.feeUsd);
totalFeeUSD += BigInt(fee.cumulativeFeeUsd);
});

const finalDailyFee = parseInt(dailyFeeUSD.toString()) / 1e18;
const finalTotalFee = parseInt(totalFeeUSD.toString()) / 1e18;

return {
timestamp: todaysTimestamp,
dailyFees: finalDailyFee.toString(),
totalFees: finalTotalFee.toString(),
};
};
return fetch;
};

const methodology = {
dailyFees: "Total cumulativeFeeUsd for specified chain for the given day",
};

const adapter: Adapter = {
version: 2,
adapter: {
[CHAIN.FLARE]: {
fetch: graphs(endpoints),
start: 1719878400,
meta: {
methodology,
},
},
},
};

export default adapter;
Loading