@@ -3,47 +3,74 @@ import { FetchOptions, SimpleAdapter } from "../adapters/types";
33import { CHAIN } from "../helpers/chains" ;
44
55const feesQueryURL = "https://app.echelon.market/api/defillama/fees?timeframe=" ;
6+ const revenueQueryURL = "https://app.echelon.market/api/defillama/revenue?timeframe=" ;
67
78interface IVolumeall {
89 value : number ;
910 timestamp : string ;
1011}
1112
12- const feesEndpoint = ( endTimestamp : number , timeframe : string ) =>
13- endTimestamp
14- ? feesQueryURL + timeframe + `&endTimestamp=${ endTimestamp } `
15- : feesQueryURL + timeframe ;
13+ const buildURL = ( baseURL : string , timeframe : string , endTimestamp : number , networkParam ?: string ) => {
14+ let url = baseURL + timeframe ;
15+ if ( endTimestamp ) {
16+ url += `&endTimestamp=${ endTimestamp } ` ;
17+ }
18+ if ( networkParam ) {
19+ url += networkParam ;
20+ }
21+ return url ;
22+ } ;
1623
17- const movementFeesEndpoint = ( endTimestamp : number , timeframe : string ) =>
18- endTimestamp
19- ? feesQueryURL + timeframe + `&endTimestamp= ${ endTimestamp } ` + "&network=movement_mainnet"
20- : feesQueryURL + timeframe + "&network=movement_mainnet" ;
24+ const fees_url = ( endTimestamp : number , timeframe : string ) => buildURL ( feesQueryURL , timeframe , endTimestamp ) ;
25+ const movementFees_url = ( endTimestamp : number , timeframe : string ) => buildURL ( feesQueryURL , timeframe , endTimestamp , "&network=movement_mainnet" ) ;
26+ const revenue_url = ( endTimestamp : number , timeframe : string ) => buildURL ( revenueQueryURL , timeframe , endTimestamp ) ;
27+ const movementRevenue_url = ( endTimestamp : number , timeframe : string ) => buildURL ( revenueQueryURL , timeframe , endTimestamp , "&network=movement_mainnet" ) ;
2128
22- const config : Record < string , ( endTimestamp : number , timeframe : string ) => string > = {
23- [ CHAIN . APTOS ] : feesEndpoint ,
24- [ CHAIN . MOVE ] : movementFeesEndpoint ,
29+ const config : Record < string , { fees : ( endTimestamp : number , timeframe : string ) => string , revenue : ( endTimestamp : number , timeframe : string ) => string } > = {
30+ [ CHAIN . APTOS ] : {
31+ fees : fees_url ,
32+ revenue : revenue_url ,
33+ } ,
34+ [ CHAIN . MOVE ] : {
35+ fees : movementFees_url ,
36+ revenue : movementRevenue_url ,
37+ } ,
2538}
39+
40+ const sumValues = ( data : IVolumeall [ ] ) =>
41+ data . reduce ( ( partialSum : number , a : IVolumeall ) => partialSum + a . value , 0 ) ;
2642
2743const fetch = async ( timestamp : number , _ :any , options : FetchOptions ) => {
28- const dayFeesQuery = ( await fetchURL ( config [ options . chain ] ( timestamp , "1D" ) ) ) ?. data ;
29- const dailyFees = dayFeesQuery . reduce (
30- ( partialSum : number , a : IVolumeall ) => partialSum + a . value ,
31- 0
32- ) ;
44+ const dayFeesQuery = ( await fetchURL ( config [ options . chain ] . fees ( timestamp , "1D" ) ) ) ?. data ;
45+ const dailyFees = sumValues ( dayFeesQuery ) ;
46+
47+ const dayRevenueQuery = ( await fetchURL ( config [ options . chain ] . revenue ( timestamp , "1D" ) ) ) ?. data ;
48+ const dailyRevenue = sumValues ( dayRevenueQuery ) ;
3349
3450 return {
35- dailyFees : dailyFees ,
51+ dailyFees,
52+ dailyRevenue,
53+ dailyProtocolRevenue : dailyRevenue ,
3654 } ;
3755} ;
3856
57+ const methodology = {
58+ Fees : "Total fees comprise borrowing origination fees, accumulated interest (from both protocol and lenders), and liquidation fees" ,
59+ Revenue : "Revenue includes protocol fees, protocol share of interest fees, and protocol share of liquidation fees" ,
60+ ProtocolRevenue : "Revenue includes protocol fees, protocol share of interest fees, and protocol share of liquidation fees" ,
61+ }
62+
3963const adapter : SimpleAdapter = {
64+ version : 1 ,
4065 adapter : {
4166 [ CHAIN . APTOS ] : {
4267 fetch,
68+ meta : { methodology } ,
4369 start : '2024-04-25' ,
4470 } ,
4571 [ CHAIN . MOVE ] : {
4672 fetch,
73+ meta : { methodology } ,
4774 start : '2025-03-15' ,
4875 } ,
4976 } ,
0 commit comments