Skip to content

Commit

Permalink
separate shadow legacy and cl fees
Browse files Browse the repository at this point in the history
  • Loading branch information
morazzela committed Feb 12, 2025
1 parent d30414f commit 6d95155
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
42 changes: 27 additions & 15 deletions protocols/shadow-exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
Expand All @@ -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<IPool[]> {
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);

Expand Down
46 changes: 46 additions & 0 deletions protocols/shadow-legacy.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 6d95155

Please sign in to comment.