From c89fa1d5291215e8c08e8c9a1554bbb820bf50f7 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 28 Aug 2025 13:51:43 +0300 Subject: [PATCH 1/2] move toros revenue to dhedge revenue --- fees/dhedge/index.ts | 87 +++++++++++++++++++++++++++----------------- fees/toros/index.ts | 2 - 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/fees/dhedge/index.ts b/fees/dhedge/index.ts index 944cb6b3f2..1e6378b54c 100644 --- a/fees/dhedge/index.ts +++ b/fees/dhedge/index.ts @@ -8,14 +8,14 @@ const queryManagerFeeMinteds = ` managerFeeMinteds( where: { blockTimestamp_gte: $startTimestamp, blockTimestamp_lte: $endTimestamp }, first: $first, skip: $skip, orderBy: blockTimestamp, orderDirection: desc - ) { managerFee, daoFee, tokenPriceAtFeeMint } + ) { managerFee, daoFee, tokenPriceAtFeeMint, manager } }` const queryEntryFeeMinteds = ` query entryFeeMinteds($startTimestamp: BigInt!, $endTimestamp: BigInt!, $first: Int!, $skip: Int!) { entryFeeMinteds( where: { time_gte: $startTimestamp, time_lte: $endTimestamp }, first: $first, skip: $skip, orderBy: time, orderDirection: desc - ) { entryFeeAmount, tokenPrice } + ) { entryFeeAmount, tokenPrice, managerAddress } }` const queryExitFeeMenteds = ` @@ -23,7 +23,7 @@ const queryExitFeeMenteds = ` exitFeeMinteds( where: { time_gte: $startTimestamp, time_lte: $endTimestamp }, first: $first, skip: $skip, orderBy: time, orderDirection: desc - ) { exitFeeAmount, tokenPrice } + ) { exitFeeAmount, tokenPrice, managerAddress } }` // if graph goes down, can be pulled via event logs, example: @@ -57,6 +57,16 @@ const PROVIDER_CONFIG = { }, }; +const TOROS_AND_MSTABLE_MANAGERS: string[] = [ + "0x813123a13d01d3f07d434673fdc89cbba523f14d", // Toros Optimism + "0x090e7fbd87a673ee3d0b6ccacf0e1d94fb90da59", // Toros Polygon + "0xfbd2b4216f422dc1eee1cff4fb64b726f099def5", // Toros Arbitrum + "0x5619ad05b0253a7e647bd2e4c01c7f40ceab0879", // Toros Base + "0xfbd2b4216f422dc1eee1cff4fb64b726f099def5", // Toros Ethereum + "0x6a21fd094d1c99c8bdbcbc9a7ad4b316a550edd0", // mStable Optimism + "0x3dd46846eed8d147841ae162c8425c08bd8e1b41", // mStable Ethereum +]; + const fetchHistoricalFees = async (chainId: CHAIN, query: string, volumeField: string, startTimestamp: number, endTimestamp: number) => { const { endpoint } = PROVIDER_CONFIG[chainId]; @@ -87,37 +97,43 @@ const fetchHistoricalFees = async (chainId: CHAIN, query: string, volumeField: s return allData; }; -const calculateManagerFees = (data: any): number => - data.reduce((acc: number, item: any) => { - const managerFee = Number(item.managerFee); - const tokenPrice = Number(item.tokenPriceAtFeeMint); - const managerFeeFormatted = managerFee / 1e18; - const tokenPriceFormatted = tokenPrice / 1e18; - const result = managerFeeFormatted * tokenPriceFormatted; - return acc + result; +const calculateManagerFees = (data: any, onlyForTorosAndMstableManagers: boolean): number => + data + .filter(f => onlyForTorosAndMstableManagers && TOROS_AND_MSTABLE_MANAGERS.includes(f.manager) || true) + .reduce((acc: number, item: any) => { + const managerFee = Number(item.managerFee); + const tokenPrice = Number(item.tokenPriceAtFeeMint); + const managerFeeFormatted = managerFee / 1e18; + const tokenPriceFormatted = tokenPrice / 1e18; + const result = managerFeeFormatted * tokenPriceFormatted; + return acc + result; }, 0); -const calculateEntryFees = (data: any): number => - data.reduce((acc: number, item: any) => { - const entryFee = Number(item.entryFeeAmount); - const tokenPrice = Number(item.tokenPrice); - const entryFeeFormatted = entryFee / 1e18; - const tokenPriceFormatted = tokenPrice / 1e18; - const result = entryFeeFormatted * tokenPriceFormatted; - return acc + result; +const calculateEntryFees = (data: any, onlyForTorosAndMstableManagers: boolean): number => + data + .filter(f => onlyForTorosAndMstableManagers && TOROS_AND_MSTABLE_MANAGERS.includes(f.managerAddress) || true) + .reduce((acc: number, item: any) => { + const entryFee = Number(item.entryFeeAmount); + const tokenPrice = Number(item.tokenPrice); + const entryFeeFormatted = entryFee / 1e18; + const tokenPriceFormatted = tokenPrice / 1e18; + const result = entryFeeFormatted * tokenPriceFormatted; + return acc + result; }, 0); -const calculateExitFees = (data: any): number => - data.reduce((acc: number, item: any) => { - const exitFee = Number(item.exitFeeAmount); - const tokenPrice = Number(item.tokenPrice); - const exitFeeFormatted = exitFee / 1e18; - const tokenPriceFormatted = tokenPrice / 1e18; - const result = exitFeeFormatted * tokenPriceFormatted; - return acc + result; +const calculateExitFees = (data: any, onlyForTorosAndMstableManagers: boolean): number => + data + .filter(f => onlyForTorosAndMstableManagers && TOROS_AND_MSTABLE_MANAGERS.includes(f.managerAddress) || true) + .reduce((acc: number, item: any) => { + const exitFee = Number(item.exitFeeAmount); + const tokenPrice = Number(item.tokenPrice); + const exitFeeFormatted = exitFee / 1e18; + const tokenPriceFormatted = tokenPrice / 1e18; + const result = exitFeeFormatted * tokenPriceFormatted; + return acc + result; }, 0); -const calculateDaoFees = (data: any): number => +const calculateDhedgeDaoFees = (data: any): number => data.reduce((acc: number, item: any) => { const daoFee = Number(item.daoFee); const tokenPrice = Number(item.tokenPriceAtFeeMint); @@ -135,12 +151,17 @@ const fetch = async ({ chain, endTimestamp, startTimestamp }: FetchOptions) => { const dailyEntryFeesEvents = await fetchHistoricalFees(chain as CHAIN, queryEntryFeeMinteds, 'entryFeeMinteds', startTimestamp, endTimestamp); const dailyExitFeesEvents = await fetchHistoricalFees(chain as CHAIN, queryExitFeeMenteds, 'exitFeeMinteds', startTimestamp, endTimestamp); - const dailyManagerFees = calculateManagerFees(dailyManagerFeesEvents); - const dailyEntryFees = calculateEntryFees(dailyEntryFeesEvents); - const dailyExitFees = calculateExitFees(dailyExitFeesEvents); + const dailyManagerFees = calculateManagerFees(dailyManagerFeesEvents, false); + const dailyEntryFees = calculateEntryFees(dailyEntryFeesEvents, false); + const dailyExitFees = calculateExitFees(dailyExitFeesEvents, false); const dailyFees = dailyManagerFees + dailyEntryFees + dailyExitFees; - const dailyDaoFees = calculateDaoFees(dailyManagerFeesEvents); + const dailyDhedgeDaoFees = calculateDhedgeDaoFees(dailyManagerFeesEvents); + const dailyTorosMstableManagersFees = calculateManagerFees(dailyManagerFeesEvents, true); + const dailyTorosMstableEntryFees = calculateEntryFees(dailyEntryFeesEvents, true); + const dailyTorosMstableExitFees = calculateExitFees(dailyExitFeesEvents, true); + + const dailyDaoFees = dailyDhedgeDaoFees + dailyTorosMstableExitFees + dailyTorosMstableManagersFees + dailyTorosMstableEntryFees; return { dailyFees, @@ -153,7 +174,7 @@ const fetch = async ({ chain, endTimestamp, startTimestamp }: FetchOptions) => { const info = { methodology: { Fees: 'All fees generated from dHEDGE vaults.', - Revenue: 'All revenue collected by the dHEDGE protocol from fees generated.', + Revenue: 'Vaults fees going to treasury.', } } diff --git a/fees/toros/index.ts b/fees/toros/index.ts index 3c00eb8856..e211f6dbc6 100644 --- a/fees/toros/index.ts +++ b/fees/toros/index.ts @@ -149,14 +149,12 @@ const fetch = async ({ chain, endTimestamp, startTimestamp }: FetchOptions) => { return { dailyFees, - dailyRevenue: dailyFees, timestamp: endTimestamp, }; } const methodology = { Fees: 'All fees generated from Toros vaults.', - Revenue: 'All revenue collected by the Toros protocol.', } const adapter: SimpleAdapter = { From 038fb59d11edeb23c50aabcaa3b7278928d10dc4 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 28 Aug 2025 14:27:34 +0300 Subject: [PATCH 2/2] move toros revenue to dhedge revenue- > fix filter condition --- fees/dhedge/index.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fees/dhedge/index.ts b/fees/dhedge/index.ts index 1e6378b54c..59e399bca6 100644 --- a/fees/dhedge/index.ts +++ b/fees/dhedge/index.ts @@ -99,7 +99,12 @@ const fetchHistoricalFees = async (chainId: CHAIN, query: string, volumeField: s const calculateManagerFees = (data: any, onlyForTorosAndMstableManagers: boolean): number => data - .filter(f => onlyForTorosAndMstableManagers && TOROS_AND_MSTABLE_MANAGERS.includes(f.manager) || true) + .filter(f => { + if (onlyForTorosAndMstableManagers){ + return TOROS_AND_MSTABLE_MANAGERS.includes(f.manager.toLowerCase()); + } + return true; + }) .reduce((acc: number, item: any) => { const managerFee = Number(item.managerFee); const tokenPrice = Number(item.tokenPriceAtFeeMint); @@ -111,7 +116,12 @@ const calculateManagerFees = (data: any, onlyForTorosAndMstableManagers: boolean const calculateEntryFees = (data: any, onlyForTorosAndMstableManagers: boolean): number => data - .filter(f => onlyForTorosAndMstableManagers && TOROS_AND_MSTABLE_MANAGERS.includes(f.managerAddress) || true) + .filter(f => { + if (onlyForTorosAndMstableManagers){ + return TOROS_AND_MSTABLE_MANAGERS.includes(f.managerAddress.toLowerCase()); + } + return true; + }) .reduce((acc: number, item: any) => { const entryFee = Number(item.entryFeeAmount); const tokenPrice = Number(item.tokenPrice); @@ -123,7 +133,12 @@ const calculateEntryFees = (data: any, onlyForTorosAndMstableManagers: boolean): const calculateExitFees = (data: any, onlyForTorosAndMstableManagers: boolean): number => data - .filter(f => onlyForTorosAndMstableManagers && TOROS_AND_MSTABLE_MANAGERS.includes(f.managerAddress) || true) + .filter(f => { + if (onlyForTorosAndMstableManagers){ + return TOROS_AND_MSTABLE_MANAGERS.includes(f.managerAddress.toLowerCase()); + } + return true; + }) .reduce((acc: number, item: any) => { const exitFee = Number(item.exitFeeAmount); const tokenPrice = Number(item.tokenPrice);