Skip to content

Commit 99e0079

Browse files
committed
short refactor
1 parent b193a14 commit 99e0079

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

fees/get-protocol.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Adapter } from "../adapters/types";
22
import { CHAIN, POLYGON } from "../helpers/chains";
33
import { request, gql } from "graphql-request";
44
import { getTimestampAtStartOfDayUTC } from "../utils/date";
5-
import { getPrices } from "../utils/prices";
65
import { getBlock } from "../helpers/getBlock";
76

87
const protocolSubgraph =
98
"https://api.thegraph.com/subgraphs/name/efesozen7/test-matic";
9+
1010
const tokenSubgraphPolygon =
1111
"https://api.thegraph.com/subgraphs/name/getprotocol/get-token-polygon";
1212

@@ -19,11 +19,10 @@ const graphs = (
1919
tokenSubgraphPolygon: string
2020
) => {
2121
return async (timestamp: number) => {
22-
tokenSubgraphEthereum;
23-
tokenSubgraphPolygon;
2422
const beginningOfTheDay = getTimestampAtStartOfDayUTC(timestamp);
2523
const dateId = Math.floor(beginningOfTheDay / 86400);
26-
const block = await getBlock(timestamp, CHAIN.POLYGON, {});
24+
const block = await getBlock(beginningOfTheDay, CHAIN.POLYGON, {});
25+
2726
const revenueQuery = gql`
2827
{
2928
protocolDay(id: ${dateId}) {
@@ -43,53 +42,53 @@ const graphs = (
4342
}
4443
}
4544
`;
45+
4646
const graphQueryGETPrice = gql`
4747
{
4848
priceOracle(id: "1", block: { number: ${block} }) {
4949
price
5050
}
5151
}
5252
`;
53+
5354
const graphRevenue = await request(graphUrl, revenueQuery);
5455
const graphPolyFees = await request(tokenSubgraphPolygon, feesQuery);
5556
const graphEthFees = await request(tokenSubgraphEthereum, feesQuery);
5657
const graphGETPrice = await request(graphUrl, graphQueryGETPrice);
5758

5859
//GET Price in USD
5960
const getTokenPrice = parseFloat(graphGETPrice.priceOracle.price);
60-
const ethPrice = await getPrices(["coingecko:ethereum"], timestamp);
6161

6262
const stakingFees = graphEthFees.stakingRewards
6363
.concat(graphPolyFees.stakingRewards)
6464
.filter((reward: any) => reward.type != "FUEL_DISTRIBUTION");
6565

66-
const withdrawalRedistributionPOLFeesGET = stakingFees
66+
const feesMinusIntegrator = stakingFees
6767
.map((reward: any) => BigInt(reward.totalRewards))
6868
.reduce(function (result: bigint, reward: bigint) {
6969
return result + reward;
7070
}, BigInt(0));
71-
const withdrawalRedistributionFeesGET = stakingFees
71+
72+
const userFeesMinusIntegrator = stakingFees
7273
.filter((reward: any) => reward.type != "UNISWAP_LP_FEE")
7374
.map((reward: any) => BigInt(reward.totalRewards))
7475
.reduce(function (result: bigint, reward: bigint) {
7576
return result + reward;
7677
}, BigInt(0));
7778

78-
//total fees
79+
//integrator fees in USD
7980
const integratorTicketingFeesUSD =
8081
parseFloat(graphRevenue.protocolDay.reservedFuel) * getTokenPrice;
82+
//daily fees w/o integrator fees
83+
const feesMinusIntegratorUSD =
84+
Number(feesMinusIntegrator / BigInt(10e18)) * getTokenPrice;
85+
//daily user fees w/o integrator fees
86+
const userFeesMinusIntegratorUSD =
87+
Number(userFeesMinusIntegrator / BigInt(10e18)) * getTokenPrice;
8188

82-
const withdrawalRedistributionPOLFeesUSD =
83-
Number(withdrawalRedistributionPOLFeesGET / BigInt(10e18)) *
84-
getTokenPrice;
85-
86-
const withdrawalRedistributionFeesUSD =
87-
Number(withdrawalRedistributionFeesGET / BigInt(10e18)) * getTokenPrice;
88-
89-
const dailyFees =
90-
integratorTicketingFeesUSD + withdrawalRedistributionPOLFeesUSD;
89+
const dailyFees = integratorTicketingFeesUSD + feesMinusIntegratorUSD;
9190
const dailyUserFees =
92-
integratorTicketingFeesUSD + withdrawalRedistributionFeesUSD;
91+
integratorTicketingFeesUSD + userFeesMinusIntegratorUSD;
9392
const dailyHoldersRevenue =
9493
parseFloat(graphRevenue.protocolDay.holdersRevenue) * getTokenPrice;
9594
const dailyProtocolRevenue =

0 commit comments

Comments
 (0)