@@ -2,11 +2,11 @@ import { Adapter } from "../adapters/types";
2
2
import { CHAIN , POLYGON } from "../helpers/chains" ;
3
3
import { request , gql } from "graphql-request" ;
4
4
import { getTimestampAtStartOfDayUTC } from "../utils/date" ;
5
- import { getPrices } from "../utils/prices" ;
6
5
import { getBlock } from "../helpers/getBlock" ;
7
6
8
7
const protocolSubgraph =
9
8
"https://api.thegraph.com/subgraphs/name/efesozen7/test-matic" ;
9
+
10
10
const tokenSubgraphPolygon =
11
11
"https://api.thegraph.com/subgraphs/name/getprotocol/get-token-polygon" ;
12
12
@@ -19,11 +19,10 @@ const graphs = (
19
19
tokenSubgraphPolygon : string
20
20
) => {
21
21
return async ( timestamp : number ) => {
22
- tokenSubgraphEthereum ;
23
- tokenSubgraphPolygon ;
24
22
const beginningOfTheDay = getTimestampAtStartOfDayUTC ( timestamp ) ;
25
23
const dateId = Math . floor ( beginningOfTheDay / 86400 ) ;
26
- const block = await getBlock ( timestamp , CHAIN . POLYGON , { } ) ;
24
+ const block = await getBlock ( beginningOfTheDay , CHAIN . POLYGON , { } ) ;
25
+
27
26
const revenueQuery = gql `
28
27
{
29
28
protocolDay(id: ${ dateId } ) {
@@ -43,53 +42,53 @@ const graphs = (
43
42
}
44
43
}
45
44
` ;
45
+
46
46
const graphQueryGETPrice = gql `
47
47
{
48
48
priceOracle(id: "1", block: { number: ${ block } }) {
49
49
price
50
50
}
51
51
}
52
52
` ;
53
+
53
54
const graphRevenue = await request ( graphUrl , revenueQuery ) ;
54
55
const graphPolyFees = await request ( tokenSubgraphPolygon , feesQuery ) ;
55
56
const graphEthFees = await request ( tokenSubgraphEthereum , feesQuery ) ;
56
57
const graphGETPrice = await request ( graphUrl , graphQueryGETPrice ) ;
57
58
58
59
//GET Price in USD
59
60
const getTokenPrice = parseFloat ( graphGETPrice . priceOracle . price ) ;
60
- const ethPrice = await getPrices ( [ "coingecko:ethereum" ] , timestamp ) ;
61
61
62
62
const stakingFees = graphEthFees . stakingRewards
63
63
. concat ( graphPolyFees . stakingRewards )
64
64
. filter ( ( reward : any ) => reward . type != "FUEL_DISTRIBUTION" ) ;
65
65
66
- const withdrawalRedistributionPOLFeesGET = stakingFees
66
+ const feesMinusIntegrator = stakingFees
67
67
. map ( ( reward : any ) => BigInt ( reward . totalRewards ) )
68
68
. reduce ( function ( result : bigint , reward : bigint ) {
69
69
return result + reward ;
70
70
} , BigInt ( 0 ) ) ;
71
- const withdrawalRedistributionFeesGET = stakingFees
71
+
72
+ const userFeesMinusIntegrator = stakingFees
72
73
. filter ( ( reward : any ) => reward . type != "UNISWAP_LP_FEE" )
73
74
. map ( ( reward : any ) => BigInt ( reward . totalRewards ) )
74
75
. reduce ( function ( result : bigint , reward : bigint ) {
75
76
return result + reward ;
76
77
} , BigInt ( 0 ) ) ;
77
78
78
- //total fees
79
+ //integrator fees in USD
79
80
const integratorTicketingFeesUSD =
80
81
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 ;
81
88
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 ;
91
90
const dailyUserFees =
92
- integratorTicketingFeesUSD + withdrawalRedistributionFeesUSD ;
91
+ integratorTicketingFeesUSD + userFeesMinusIntegratorUSD ;
93
92
const dailyHoldersRevenue =
94
93
parseFloat ( graphRevenue . protocolDay . holdersRevenue ) * getTokenPrice ;
95
94
const dailyProtocolRevenue =
0 commit comments