From 6d9515516529ffa4fd16cbde9e6f022d80aa7b89 Mon Sep 17 00:00:00 2001 From: morazzela Date: Wed, 12 Feb 2025 18:53:19 +0100 Subject: [PATCH] separate shadow legacy and cl fees --- protocols/shadow-exchange.ts | 42 ++++++++++++++++++++------------ protocols/shadow-legacy.ts | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 protocols/shadow-legacy.ts diff --git a/protocols/shadow-exchange.ts b/protocols/shadow-exchange.ts index 95d64d1245..dacf80c544 100644 --- a/protocols/shadow-exchange.ts +++ b/protocols/shadow-exchange.ts @@ -6,11 +6,12 @@ import request from "graphql-request"; type TStartTime = { [key: string]: number; }; + const startTimeV2: TStartTime = { [CHAIN.SONIC]: 1735129946, }; -const v2Endpoints: any = { +export const v2Endpoints: any = { [CHAIN.SONIC]: sdk.graph.modifyEndpoint('HGyx7TCqgbWieay5enLiRjshWve9TjHwiug3m66pmLGR'), }; @@ -19,25 +20,36 @@ interface IPool { id: string; volumeUSD: string; feesUSD: string; + isCL: boolean; } -const fetch = async (options: FetchOptions) => { +export async function fetchPools(options: FetchOptions): Promise { const query = ` - { - clPoolDayDatas(where:{startOfDay: ${options.startOfDay}}) { - startOfDay - volumeUSD - feesUSD - } - legacyPoolDayDatas(where:{startOfDay: ${options.startOfDay}}) { - startOfDay - volumeUSD - feesUSD - } + { + clPoolDayDatas(where:{startOfDay: ${options.startOfDay}}) { + startOfDay + volumeUSD + feesUSD } + legacyPoolDayDatas(where:{startOfDay: ${options.startOfDay}}) { + startOfDay + volumeUSD + feesUSD + } + } `; - const res = await request(v2Endpoints[options.chain], query); - const pools: IPool[] = [...res.clPoolDayDatas, ...res.legacyPoolDayDatas]; + const rows = await request(v2Endpoints[options.chain], query); + + const res: IPool[] = [ + ...rows.clPoolDayDatas.map((row: any) => ({ ...row, isCL: true })), + ...rows.legacyPoolDayDatas.map((row: any) => ({ ...row, isCL: false })), + ] + + return res +} + +const fetch = async (options: FetchOptions) => { + const pools = (await fetchPools(options)).filter((pool) => pool.isCL) const dailyFees = pools.reduce((acc, pool) => acc + Number(pool.feesUSD), 0); const dailyVolume = pools.reduce((acc, pool) => acc + Number(pool.volumeUSD), 0); diff --git a/protocols/shadow-legacy.ts b/protocols/shadow-legacy.ts new file mode 100644 index 0000000000..6b1ca63c94 --- /dev/null +++ b/protocols/shadow-legacy.ts @@ -0,0 +1,46 @@ +import { FetchOptions, SimpleAdapter } from "../adapters/types"; +import { CHAIN } from "../helpers/chains"; +import { fetchPools } from "./shadow-exchange"; + +type TStartTime = { + [key: string]: number; + }; + +const startTimeV2: TStartTime = { + [CHAIN.SONIC]: 1735129946, +}; + +const fetch = async (options: FetchOptions) => { + const pools = (await fetchPools(options)).filter((pool) => !pool.isCL) + const dailyFees = pools.reduce((acc, pool) => acc + Number(pool.feesUSD), 0); + const dailyVolume = pools.reduce((acc, pool) => acc + Number(pool.volumeUSD), 0); + + return { + dailyVolume, + dailyFees, + dailyUserFees: dailyFees, + dailyRevenue: dailyFees, + dailyHoldersRevenue: dailyFees, + }; + +} + +const methodology = { + UserFees: "User pays fees on each swap.", + ProtocolRevenue: "Revenue going to the protocol.", + HoldersRevenue: "User fees are distributed among holders.", +}; +const adapter: SimpleAdapter = { + version: 2, + adapter: { + [CHAIN.SONIC]: { + fetch, + start: startTimeV2[CHAIN.SONIC], + meta: { + methodology: methodology + }, + }, + }, +}; + +export default adapter;