@@ -14,13 +14,22 @@ const v3ChainMapping: any = {
1414 [ CHAIN . PLASMA ] : "PLASMA" ,
1515} ;
1616
17+ const HOLDERS_SHARE_OF_PROTOCOL = 0.825 ;
18+
19+ const n = ( x : any ) => ( Number . isFinite ( Number ( x ) ) ? Number ( x ) : 0 ) ;
20+
1721async function fetch ( options : FetchOptions ) {
1822 const dailyVolume = options . createBalances ( ) ;
1923 const dailyFees = options . createBalances ( ) ;
2024 const dailyUserFees = options . createBalances ( ) ;
21- const dailyRevenue = options . createBalances ( ) ;
25+
26+ const dailyProtocolRevenueGross = options . createBalances ( ) ;
2227 const dailySupplySideRevenue = options . createBalances ( ) ;
2328
29+ const dailyHoldersRevenue = options . createBalances ( ) ;
30+ const dailyProtocolRevenueNet = options . createBalances ( ) ;
31+ const dailyRevenue = options . createBalances ( ) ;
32+
2433 const query = `query {
2534 pools: poolGetPools(
2635 orderBy: volume24h
@@ -44,23 +53,57 @@ async function fetch(options: FetchOptions) {
4453 }
4554}` ;
4655 const { pools } = await request ( "https://api-v3.balancer.fi/graphql" , query ) ;
56+
57+ let protocolGrossSum = 0 ;
58+ let supplySideSum = 0 ;
4759 pools . forEach ( ( pool : any ) => {
48- dailyVolume . addUSDValue ( + pool . dynamicData . volume24h ) ;
60+ const fees24h = n ( pool ?. dynamicData ?. fees24h ) ;
61+ const vol24h = n ( pool ?. dynamicData ?. volume24h ) ;
62+ const yield24h = n ( pool ?. dynamicData ?. yieldCapture24h ) ;
63+
64+ dailyVolume . addUSDValue ( vol24h ) ;
65+
66+ dailyFees . addUSDValue ( fees24h , METRIC . SWAP_FEES ) ;
67+ dailyUserFees . addUSDValue ( fees24h , METRIC . SWAP_FEES ) ;
68+
69+ dailyProtocolRevenueGross . addUSDValue ( fees24h * 0.5 , METRIC . SWAP_FEES ) ;
70+ dailySupplySideRevenue . addUSDValue ( fees24h * 0.5 , METRIC . SWAP_FEES ) ; // 50% of fees goes to the supply side
71+
72+ protocolGrossSum += fees24h * 0.5 ;
73+ supplySideSum += fees24h * 0.5 ;
4974
50- dailyFees . addUSDValue ( + pool . dynamicData . fees24h , METRIC . SWAP_FEES ) ;
51- dailyUserFees . addUSDValue ( + pool . dynamicData . fees24h , METRIC . SWAP_FEES ) ;
52- dailyRevenue . addUSDValue ( + ( pool . dynamicData . fees24h * 0.5 ) , METRIC . SWAP_FEES ) ; // 50% of fees go to the protocol
53- dailySupplySideRevenue . addUSDValue ( + pool . dynamicData . fees24h * 0.5 , METRIC . SWAP_FEES ) ; // 50% of fees goes to the supply side
54-
5575 // subgraph error on hyperlqiuid yields
5676 if ( options . chain !== CHAIN . HYPERLIQUID ) {
57- dailyFees . addUSDValue ( + pool . dynamicData . yieldCapture24h , METRIC . ASSETS_YIELDS ) ;
58- dailyRevenue . addUSDValue ( + ( pool . dynamicData . yieldCapture24h * 0.1 ) , METRIC . ASSETS_YIELDS ) ; // 10% of yield capture goes to the protocol
59- dailySupplySideRevenue . addUSDValue ( + pool . dynamicData . yieldCapture24h * 0.9 , METRIC . ASSETS_YIELDS ) ; // 90% of yield capture goes to the supply side
77+ dailyFees . addUSDValue ( yield24h , METRIC . ASSETS_YIELDS ) ;
78+ dailyProtocolRevenueGross . addUSDValue (
79+ + ( yield24h * 0.1 ) ,
80+ METRIC . ASSETS_YIELDS
81+ ) ; // 10% of yield capture goes to the protocol
82+ dailySupplySideRevenue . addUSDValue ( yield24h * 0.9 , METRIC . ASSETS_YIELDS ) ; // 90% of yield capture goes to the supply side
83+
84+ protocolGrossSum += yield24h * 0.1 ;
85+ supplySideSum += yield24h * 0.9 ;
6086 }
6187 } ) ;
6288
63- return { dailyFees, dailyUserFees, dailyVolume, dailyRevenue, dailyProtocolRevenue : dailyRevenue , dailySupplySideRevenue } ;
89+ const holdersUSD = protocolGrossSum * HOLDERS_SHARE_OF_PROTOCOL ;
90+ const protocolNetUSD = protocolGrossSum - holdersUSD ;
91+
92+ if ( holdersUSD > 0 ) dailyHoldersRevenue . addUSDValue ( holdersUSD ) ;
93+ if ( protocolNetUSD > 0 ) dailyProtocolRevenueNet . addUSDValue ( protocolNetUSD ) ;
94+
95+ dailyRevenue . addBalances ( dailyHoldersRevenue ) ;
96+ dailyRevenue . addBalances ( dailyProtocolRevenueNet ) ;
97+
98+ return {
99+ dailyFees,
100+ dailyUserFees,
101+ dailyVolume,
102+ dailyRevenue,
103+ dailyProtocolRevenue : dailyProtocolRevenueNet ,
104+ dailyHoldersRevenue,
105+ dailySupplySideRevenue,
106+ } ;
64107}
65108
66109const adapter : SimpleAdapter = {
@@ -71,31 +114,45 @@ const adapter: SimpleAdapter = {
71114 methodology : {
72115 Fees : "Fees earned from all the trades and yields." ,
73116 UserFees : "Fees earned from all the trades." ,
74- Revenue : "Revenue earned by the protocol, which is 50% of the trade fees and 10% of the yield capture." ,
75- ProtocolRevenue : "Revenue earned by the protocol, which is 50% of the trade fees and 10% of the yield capture." ,
76- SupplySideRevenue : "Revenue earned by the supply side, which is 90% of the yield capture and 50% of the fees." ,
117+ Revenue :
118+ "Revenue earned by the protocol, which is 50% of the trade fees and 10% of the yield capture." ,
119+ ProtocolRevenue :
120+ "Revenue earned by the protocol, which is 50% of the trade fees and 10% of the yield capture." ,
121+ HoldersRevenue :
122+ "Portion of protocol revenue distributed to token holders (e.g., veBAL/BAL), parameterized here." ,
123+ SupplySideRevenue :
124+ "Revenue earned by the supply side, which is 90% of the yield capture and 50% of the fees." ,
77125 } ,
78126 breakdownMethodology : {
79127 Fees : {
80- [ METRIC . SWAP_FEES ] : 'Swap fees paid by users from all trades.' ,
81- [ METRIC . ASSETS_YIELDS ] : 'Yields captured from all assets in liquity pools.' ,
128+ [ METRIC . SWAP_FEES ] : "Swap fees paid by users from all trades." ,
129+ [ METRIC . ASSETS_YIELDS ] :
130+ "Yields captured from all assets in liquity pools." ,
82131 } ,
83132 UserFees : {
84- [ METRIC . SWAP_FEES ] : ' Swap fees paid by users from all trades.' ,
133+ [ METRIC . SWAP_FEES ] : " Swap fees paid by users from all trades." ,
85134 } ,
86135 Revenue : {
87- [ METRIC . SWAP_FEES ] : '50% of swap fees paid by users from all trades.' ,
88- [ METRIC . ASSETS_YIELDS ] : '10% of yields captured from all assets in liquity pools.' ,
136+ [ METRIC . SWAP_FEES ] : "50% of swap fees paid by users from all trades." ,
137+ [ METRIC . ASSETS_YIELDS ] :
138+ "10% of yields captured from all assets in liquity pools." ,
89139 } ,
90140 ProtocolRevenue : {
91- [ METRIC . SWAP_FEES ] : '50% of swap fees paid by users from all trades.' ,
92- [ METRIC . ASSETS_YIELDS ] : '10% of yields captured from all assets in liquity pools.' ,
141+ [ METRIC . SWAP_FEES ] : "50% of swap fees paid by users from all trades." ,
142+ [ METRIC . ASSETS_YIELDS ] :
143+ "10% of yields captured from all assets in liquity pools." ,
144+ } ,
145+ HoldersRevenue : {
146+ [ METRIC . SWAP_FEES ] : "Share of protocol revenue sent to token holders." ,
147+ [ METRIC . ASSETS_YIELDS ] :
148+ "Share of protocol revenue from yield capture sent to token holders." ,
93149 } ,
94150 SupplySideRevenue : {
95- [ METRIC . SWAP_FEES ] : '50% of swap fees paid by users from all trades.' ,
96- [ METRIC . ASSETS_YIELDS ] : '90% of yields captured from all assets in liquity pools.' ,
151+ [ METRIC . SWAP_FEES ] : "50% of swap fees paid by users from all trades." ,
152+ [ METRIC . ASSETS_YIELDS ] :
153+ "90% of yields captured from all assets in liquity pools." ,
97154 } ,
98- }
155+ } ,
99156} ;
100157
101158export default adapter ;
0 commit comments