diff --git a/fees/frankencoin/index.ts b/fees/frankencoin/index.ts new file mode 100644 index 0000000000..281aa8ae6a --- /dev/null +++ b/fees/frankencoin/index.ts @@ -0,0 +1,79 @@ +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import { request, gql } from "graphql-request"; + +// GraphQL endpoint for Frankencoin +const FRANKENCOIN_GRAPH_URL = "https://ponder.test.frankencoin.com"; // TODO: change to production URL + +// ZCHF token address on Ethereum +const ZCHF_ADDRESS = "0xB58E61C3098d85632Df34EecfB899A1Ed80921cB"; + +const PROFIT_LOSS_QUERY = gql` + query GetProfitLoss { + frankencoinProfitLosss( + orderBy: "count", + orderDirection: "desc", + limit: 1, + ) { + items { + profits + losses + } + } + } +`; + +const fetch = async (options: FetchOptions) => { + const dailyFees = options.createBalances(); + const dailyRevenue = options.createBalances(); + + try { + const { frankencoinProfitLosss } = await request(FRANKENCOIN_GRAPH_URL, PROFIT_LOSS_QUERY); + + const profits = frankencoinProfitLosss?.items?.[0]?.profits ?? "0"; + const losses = frankencoinProfitLosss?.items?.[0]?.losses ?? "0"; + + // Convert string values to BigInt for calculations + const profitsBigInt = BigInt(profits); + const lossesBigInt = BigInt(losses); + + // Fees are the total profits in ZCHF + dailyFees.add(ZCHF_ADDRESS, profitsBigInt); + + // Revenue is profits minus losses in ZCHF + const revenue = profitsBigInt - lossesBigInt; + dailyRevenue.add(ZCHF_ADDRESS, revenue); + + return { + dailyFees, + dailyRevenue, + dailyProtocolRevenue: dailyRevenue, + }; + } catch (error) { + console.error("Error fetching Frankencoin data:", error); + return { + dailyFees, + dailyRevenue, + dailyProtocolRevenue: dailyRevenue, + }; + } +}; + +const adapter: SimpleAdapter = { + version: 2, + adapter: { + [CHAIN.ETHEREUM]: { + fetch, + start: '2023-10-28', + meta: { + methodology: { + Fees: "Total profits generated by the Frankencoin protocol in ZCHF tokens", + Revenue: "Net revenue calculated as profits minus losses in ZCHF tokens", + ProtocolRevenue: "All net revenue is retained by the protocol in ZCHF tokens", + } + } + } + } +}; + +export default adapter; \ No newline at end of file