@@ -41,13 +41,14 @@ interface IGetChainVolumeParams {
4141 totalVolume : {
4242 factory : string ,
4343 field : string ,
44- filterParams ?: IGetChainVolumeFilterParams [ ] ,
44+ filterParams ?: IGetChainVolumeFilterParams [ ] ,
4545 } ,
4646 dailyVolume ?: {
4747 factory : string ,
4848 field : string ,
4949 dateField ?: string ,
5050 } ,
51+ totalFeesField ?: string ,
5152 customDailyVolume ?: string ,
5253 hasDailyVolume ?: boolean
5354 hasTotalVolume ?: boolean
@@ -117,7 +118,7 @@ function getChainVolume({
117118 switch ( item . name ) {
118119 case "id" :
119120 graphQueryTodayTotalVolumeVariables [ "id" ] = id ;
120- graphQueryYesterdayTotalVolumeVariables [ "id" ] = id - 1
121+ graphQueryYesterdayTotalVolumeVariables [ "id" ] = id - 1
121122 default :
122123 }
123124 } ) ;
@@ -131,7 +132,7 @@ function getChainVolume({
131132 if ( hasDailyVolume && ! dailyVolumeValue ) {
132133 graphResDaily = await request ( graphUrls [ chain ] , alternativeDaily ( getUniqStartOfTodayTimestamp ( new Date ( endTimestamp * 1000 ) ) ) ) ;
133134 const factory = dailyVolume . factory . toLowerCase ( ) . charAt ( dailyVolume . factory . length - 1 ) === 's' ? dailyVolume . factory : `${ dailyVolume . factory } s`
134- dailyVolumeValue = graphResDaily ? graphResDaily [ `${ factory } ` ] . reduce ( ( p : any , c : any ) => p + Number ( c [ `${ dailyVolume . field } ` ] ) , 0 ) : undefined ;
135+ dailyVolumeValue = graphResDaily ? graphResDaily [ `${ factory } ` ] . reduce ( ( p : any , c : any ) => p + Number ( c [ `${ dailyVolume . field } ` ] ) , 0 ) : undefined ;
135136 }
136137 if ( ! hasDailyVolume ) {
137138 const fromBlock = await getFromBlock ( )
@@ -160,6 +161,7 @@ function getChainVolume2({
160161 factory : DEFAULT_TOTAL_VOLUME_FACTORY ,
161162 field : DEFAULT_TOTAL_VOLUME_FIELD ,
162163 } ,
164+ totalFeesField,
163165 hasTotalVolume = true ,
164166 getCustomBlock = undefined ,
165167} : IGetChainVolumeParams ) {
@@ -168,6 +170,7 @@ function getChainVolume2({
168170 block: { number: $block }
169171 ) {
170172 ${ totalVolume . field }
173+ ${ totalFeesField ? totalFeesField : '' }
171174 }
172175 ` ;
173176
@@ -178,19 +181,24 @@ function getChainVolume2({
178181 const { endTimestamp, startTimestamp, getEndBlock, getStartBlock } = options ;
179182
180183 const endBlock = ( await ( getCustomBlock ? getCustomBlock ( endTimestamp ) : getEndBlock ( ) ) ) ?? undefined ;
181- const startBlock = ( await ( getCustomBlock ? getCustomBlock ( startTimestamp ) :getStartBlock ( ) ) ) ?? undefined ;
184+ const startBlock = ( await ( getCustomBlock ? getCustomBlock ( startTimestamp ) : getStartBlock ( ) ) ) ?? undefined ;
182185
183- const graphResTotal = hasTotalVolume ? await request ( graphUrls [ chain ] , graphQueryTotalVolume , { block : endBlock } ) : undefined ;
186+ const graphResTotal = hasTotalVolume ? await request ( graphUrls [ chain ] , graphQueryTotalVolume , { block : endBlock } ) : undefined ;
184187 const total = graphResTotal ? graphResTotal [ totalVolume . factory ] ?. reduce ( ( total : number , factory : any ) => total + Number ( factory [ totalVolume . field ] ) , 0 ) : undefined ;
188+ const totalFees = totalFeesField && graphResTotal ? graphResTotal [ totalVolume . factory ] ?. reduce ( ( total : number , factory : any ) => total + Number ( factory [ totalFeesField ] ) , 0 ) : undefined ;
185189
186190 const graphResPrevTotal = hasTotalVolume ? await request ( graphUrls [ chain ] , graphQueryTotalVolume , { block : startBlock } ) : undefined ;
187191 const prevTotal = graphResPrevTotal ? graphResPrevTotal [ totalVolume . factory ] ?. reduce ( ( total : number , factory : any ) => total + Number ( factory [ totalVolume . field ] ) , 0 ) : undefined ;
192+ const prevTotalFees = totalFeesField && graphResPrevTotal ? graphResPrevTotal [ totalVolume . factory ] ?. reduce ( ( total : number , factory : any ) => total + Number ( factory [ totalFeesField ] ) , 0 ) : undefined ;
188193
189194 let dailyVolumeValue = total - prevTotal
190195
191- return {
196+ const response : any = {
192197 dailyVolume : dailyVolumeValue ,
193- } ;
198+ }
199+ if ( totalFeesField )
200+ response . dailyFees = totalFees - prevTotalFees
201+ return response
194202 } ;
195203 } ;
196204}
@@ -211,8 +219,8 @@ function getChainVolumeWithGasToken({
211219 hasTotalVolume = true ,
212220 getCustomBlock = undefined ,
213221 priceToken,
214- } : IGetChainVolumeParams & { priceToken :string } ) {
215- const basic = getChainVolume ( { graphUrls, totalVolume, dailyVolume, customDailyVolume, hasDailyVolume, hasTotalVolume, getCustomBlock} )
222+ } : IGetChainVolumeParams & { priceToken : string } ) {
223+ const basic = getChainVolume ( { graphUrls, totalVolume, dailyVolume, customDailyVolume, hasDailyVolume, hasTotalVolume, getCustomBlock } )
216224 return ( chain : Chain ) => {
217225 return async ( _a : any , _b : any , options : FetchOptions ) => {
218226 const {
@@ -236,39 +244,46 @@ function getChainVolumeWithGasToken2({
236244 factory : DEFAULT_TOTAL_VOLUME_FACTORY ,
237245 field : 'totalVolumeETH' ,
238246 } ,
247+ totalFeesField,
239248 getCustomBlock = undefined ,
240249 priceToken,
241- } : IGetChainVolumeParams & { priceToken :string } ) {
242- const basic = getChainVolume2 ( { graphUrls, totalVolume, getCustomBlock} )
250+ } : IGetChainVolumeParams & { priceToken : string } ) {
251+ const basic = getChainVolume2 ( { graphUrls, totalVolume, totalFeesField , getCustomBlock } )
243252 return ( chain : Chain ) => {
244253 return async ( options : FetchOptions ) : Promise < FetchResultV2 > => {
245254 const {
246255 dailyVolume,
256+ dailyFees,
247257 } = await basic ( chain ) ( options ) ;
248258
249- const timestamp = options . endTimestamp
250- const balances = new Balances ( { chain, timestamp } )
259+ const balances = options . createBalances ( )
251260 balances . add ( priceToken , Number ( dailyVolume ) . toFixed ( 0 ) , { skipChain : true } )
261+ let dailyFeesObj = options . createBalances ( )
262+ if ( totalFeesField )
263+ dailyFeesObj . add ( priceToken , Number ( dailyFees ) . toFixed ( 0 ) , { skipChain : true } )
252264
253- return {
254- dailyVolume : await balances . getUSDString ( ) ,
265+ const response : any = {
266+ dailyVolume : balances ,
255267 }
268+ if ( totalFeesField )
269+ response . dailyFees = dailyFeesObj
270+ return response
256271 } ;
257272 } ;
258273}
259274
260275function univ2Adapter ( {
261- endpoints = { } as { [ chain : string ] : string } ,
276+ endpoints = { } as { [ chain : string ] : string } ,
262277 factoriesName = DEFAULT_TOTAL_VOLUME_FACTORY ,
263278 dayData = DEFAULT_DAILY_VOLUME_FACTORY ,
264279 totalVolume = DEFAULT_TOTAL_VOLUME_FIELD ,
265280 totalVolumeFilterParams = undefined as IGetChainVolumeFilterParams [ ] | undefined ,
266281 dailyVolume = DEFAULT_DAILY_VOLUME_FIELD ,
267282 dailyVolumeTimestampField = DEFAULT_DATE_FIELD ,
268283 hasTotalVolume = true ,
269- hasDailyVolume = undefined as boolean | undefined ,
270- gasToken = null as string | null
271- } ) {
284+ hasDailyVolume = undefined as boolean | undefined ,
285+ gasToken = null as string | null
286+ } ) {
272287 const graphs = ( gasToken === null ? getChainVolume : getChainVolumeWithGasToken as typeof getChainVolume ) ( {
273288 graphUrls : endpoints ,
274289 hasTotalVolume,
@@ -285,23 +300,25 @@ function univ2Adapter({
285300 hasDailyVolume,
286301 priceToken : gasToken
287302 } as any ) ;
288- return async ( _a :any , _b :any , options : FetchOptions ) => {
303+ return async ( _a : any , _b : any , options : FetchOptions ) => {
289304 return graphs ( options . chain ) ( _a , _b , options )
290305 }
291306}
292307
293308function univ2Adapter2 ( {
294- endpoints = { } as { [ chain : string ] : string } ,
309+ endpoints = { } as { [ chain : string ] : string } ,
295310 factoriesName = DEFAULT_TOTAL_VOLUME_FACTORY ,
296311 totalVolume = DEFAULT_TOTAL_VOLUME_FIELD ,
297- gasToken = null as string | null ,
298- } ) {
312+ totalFeesField = null as string | null ,
313+ gasToken = null as string | null ,
314+ } ) {
299315 const graphs = ( gasToken === null ? getChainVolume2 : getChainVolumeWithGasToken2 as typeof getChainVolume2 ) ( {
300316 graphUrls : endpoints ,
301317 totalVolume : {
302318 factory : factoriesName ,
303319 field : totalVolume
304320 } ,
321+ totalFeesField,
305322 priceToken : gasToken
306323 } as any ) ;
307324 return async ( options : FetchOptions ) => {
0 commit comments