@@ -3,119 +3,119 @@ import { CHAIN } from "../helpers/chains";
33import fetchURL from "../utils/fetchURL" ;
44
55interface Pool {
6- poolName : string ;
7- date : string ;
8- totalRevenue : string ;
9- totalProtocolFee : string ;
6+ poolName : string ;
7+ date : string ;
8+ totalRevenue : string ;
9+ totalProtocolFee : string ;
1010}
1111
1212const urlRevStats = "https://api.prod.flash.trade/protocol-fees/daily" ;
1313
1414const calculateProtocolRevenue = ( stats : Pool [ ] ) => {
15- const protocolRevenue = stats . reduce ( ( sum , item ) => sum + parseFloat ( item . totalProtocolFee ) / 1e6 , 0 ) ;
16- return protocolRevenue ;
15+ const protocolRevenue = stats . reduce ( ( sum , item ) => sum + parseFloat ( item . totalProtocolFee ) / 1e6 , 0 ) ;
16+ return protocolRevenue ;
1717} ;
1818
1919const calculateteHolderRevenue = ( stats : Pool [ ] ) => {
20- const holderRevenue = stats . reduce ( ( sum , item ) => sum + parseFloat ( item . totalRevenue ) / 1e6 , 0 ) ;
21- return holderRevenue ;
20+ const holderRevenue = stats . reduce ( ( sum , item ) => sum + parseFloat ( item . totalRevenue ) / 1e6 , 0 ) ;
21+ return holderRevenue ;
2222} ;
2323
2424const pools = [
25- "Crypto.1" ,
26- "Virtual.1" ,
27- "Governance.1" ,
28- "Community.1" ,
29- "Community.2" ,
30- "Community.3" ,
31- "Trump.1" ,
25+ "Crypto.1" ,
26+ "Virtual.1" ,
27+ "Governance.1" ,
28+ "Community.1" ,
29+ "Community.2" ,
30+ "Community.3" ,
31+ "Trump.1" ,
3232]
3333
3434const fetch = async ( _a : any , _b : any , options : FetchOptions ) : Promise < FetchResultFees > => {
35- const timestamp = options . startOfDay ;
36- const targetDate = new Date ( timestamp * 1000 ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
35+ const timestamp = options . startOfDay ;
36+ const targetDate = new Date ( timestamp * 1000 ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
37+
38+ const poolFeesData : { [ pool : string ] : number } = { } ;
39+ let dailyFees = 0 ;
40+
41+ for ( const pool of pools ) {
42+ const url = `https://api.prod.flash.trade/pnl-info/cumulative-pnl-per-day?poolName=${ pool } &startDate=2023-01-01%2000:00:00&endDate=${ targetDate } %2023:59:59` ;
43+ const res = await fetchURL ( url ) ;
44+ const poolFees = ( res [ targetDate ] ?. totalFees / 1e6 ) || 0 ;
45+ poolFeesData [ pool ] = poolFees ;
46+ dailyFees += poolFees ;
47+ }
48+
49+ const dailyRevStatsResponse = await fetchURL ( urlRevStats ) ;
50+ const dailyStats : Pool [ ] = dailyRevStatsResponse ;
51+
52+ const todayStats = dailyStats . filter ( item => {
53+ const itemDate = new Date ( item . date ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
54+ return itemDate === targetDate ;
55+ } ) ;
56+
57+ // June 19, 2025 timestamp (when holder revenue started)
58+ const holderRevenueStartTimestamp = 1750291200 ;
59+
60+ let dailyHoldersRevenue = 0 ;
61+ let dailyProtocolRevenue = 0 ;
62+ let dailyRevenue = 0 ;
63+
64+ if ( timestamp > holderRevenueStartTimestamp ) {
65+ // After June 19, 2025: Use API data for holder and protocol revenue
66+ dailyHoldersRevenue = calculateteHolderRevenue ( todayStats ) ;
67+ dailyProtocolRevenue = calculateProtocolRevenue ( todayStats ) ;
68+ dailyRevenue = dailyProtocolRevenue + dailyHoldersRevenue ;
69+ } else {
70+ // Before June 19, 2025: Apply specific revenue percentages per pool
71+ const poolRevenueRates : { [ key : string ] : number } = {
72+ "Crypto.1" : 0.30 ,
73+ "Virtual.1" : 0.30 ,
74+ "Governance.1" : 0.30 ,
75+ "Community.1" : 0.00 ,
76+ "Community.2" : 0.00 ,
77+ "Community.3" : 0.05 ,
78+ "Trump.1" : 0.05 ,
79+ } ;
3780
38- const poolFeesData : { [ pool : string ] : number } = { } ;
39- let dailyFees = 0 ;
40-
4181 for ( const pool of pools ) {
42- const url = `https://api.prod.flash.trade/pnl-info/cumulative-pnl-per-day?poolName= ${ pool } &startDate=2023-01-01%2000:00:00&endDate= ${ targetDate } %2023:59:59` ;
43- const res = await fetchURL ( url ) ;
44- const poolFees = ( res [ targetDate ] ?. totalFees / 1e6 ) || 0 ;
45- poolFeesData [ pool ] = poolFees ;
46- dailyFees += poolFees ;
82+ const rate = poolRevenueRates [ pool ] || 0 ;
83+ if ( rate > 0 ) {
84+ const poolFees = poolFeesData [ pool ] || 0 ;
85+ dailyRevenue + = poolFees * rate ;
86+ }
4787 }
4888
49- const dailyRevStatsResponse = await fetchURL ( urlRevStats ) ;
50- const dailyStats : Pool [ ] = dailyRevStatsResponse ;
51-
52- const todayStats = dailyStats . filter ( item => {
53- const itemDate = new Date ( item . date ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
54- return itemDate === targetDate ;
55- } ) ;
56-
57- // June 19, 2025 timestamp (when holder revenue started)
58- const holderRevenueStartTimestamp = 1750291200 ;
59-
60- let dailyHoldersRevenue = 0 ;
61- let dailyProtocolRevenue = 0 ;
62- let dailyRevenue = 0 ;
63-
64- if ( timestamp > holderRevenueStartTimestamp ) {
65- // After June 19, 2025: Use API data for holder and protocol revenue
66- dailyHoldersRevenue = calculateteHolderRevenue ( todayStats ) ;
67- dailyProtocolRevenue = calculateProtocolRevenue ( todayStats ) ;
68- dailyRevenue = dailyProtocolRevenue + dailyHoldersRevenue ;
69- } else {
70- // Before June 19, 2025: Apply specific revenue percentages per pool
71- const poolRevenueRates : { [ key : string ] : number } = {
72- "Crypto.1" : 0.30 ,
73- "Virtual.1" : 0.30 ,
74- "Governance.1" : 0.30 ,
75- "Community.1" : 0.00 ,
76- "Community.2" : 0.00 ,
77- "Community.3" : 0.05 ,
78- "Trump.1" : 0.05 ,
79- } ;
80-
81- for ( const pool of pools ) {
82- const rate = poolRevenueRates [ pool ] || 0 ;
83- if ( rate > 0 ) {
84- const poolFees = poolFeesData [ pool ] || 0 ;
85- dailyRevenue += poolFees * rate ;
86- }
87- }
88-
89- dailyProtocolRevenue = dailyRevenue ; // All revenue goes to protocol before holder revenue started
90- dailyHoldersRevenue = 0 ;
91- }
89+ dailyProtocolRevenue = dailyRevenue ; // All revenue goes to protocol before holder revenue started
90+ dailyHoldersRevenue = 0 ;
91+ }
9292
93- const dailySupplySideRevenue = dailyFees - dailyRevenue ;
93+ const dailySupplySideRevenue = dailyFees > dailyRevenue ? dailyFees - dailyRevenue : 0 ;
9494
95- return {
96- dailyFees,
97- dailyUserFees : dailyFees ,
98- dailyRevenue,
99- dailyProtocolRevenue,
100- dailyHoldersRevenue,
101- dailySupplySideRevenue,
102- } ;
95+ return {
96+ dailyFees,
97+ dailyUserFees : dailyFees ,
98+ dailyRevenue,
99+ dailyProtocolRevenue,
100+ dailyHoldersRevenue,
101+ dailySupplySideRevenue,
102+ } ;
103103} ;
104104
105105const methodology = {
106- Fees : 'All fees generated by the pools.' ,
107- Revenue : 'Sum of protocol revenue and holder revenue.' ,
108- ProtocolRevenue : 'Before 2025-06-19: Crypto.1/Virtual.1/Governance.1 pools at 30%, Community.3/Trump.1 pools at 5%, Community.1/Community.2 at 0%. After 2025-06-19: dynamic based on API.' ,
109- HolderRevenue : 'Token holder revenue started from 2025-06-19, 0 before that date.' ,
110- SupplySideRevenue : 'Fees paid to LP pools.' ,
106+ Fees : 'All fees generated by the pools.' ,
107+ Revenue : 'Sum of protocol revenue and holder revenue.' ,
108+ ProtocolRevenue : 'Before 2025-06-19: Crypto.1/Virtual.1/Governance.1 pools at 30%, Community.3/Trump.1 pools at 5%, Community.1/Community.2 at 0%. After 2025-06-19: dynamic based on API.' ,
109+ HolderRevenue : 'Token holder revenue started from 2025-06-19, 0 before that date.' ,
110+ SupplySideRevenue : 'Fees paid to LP pools.' ,
111111}
112112
113113const adapter : Adapter = {
114- version : 1 ,
115- chains : [ CHAIN . SOLANA ] ,
116- fetch,
117- start : '2023-12-29' ,
118- methodology
114+ version : 1 ,
115+ chains : [ CHAIN . SOLANA ] ,
116+ fetch,
117+ start : '2023-12-29' ,
118+ methodology
119119} ;
120120
121121export default adapter ;
0 commit comments