@@ -2,90 +2,136 @@ import ADDRESSES from '../../helpers/coreAssets.json'
22import { FetchOptions , SimpleAdapter } from "../../adapters/types" ;
33import { CHAIN } from "../../helpers/chains" ;
44
5- const eventRouted = `event Routed(
6- bytes indexed uniquePID,
7- address indexed userAddress,
8- address outputReceiver,
9- address inputToken,
10- uint256 inputAmount,
11- address outputToken,
12- uint256 outputAmount,
13- uint256 partnerFee,
14- uint256 routingFee,
15- uint256 finalOutputAmount
16- )` ;
17-
18- const DEFAULT_ROUTER = "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ;
5+ // Event ABIs
6+ const eventOld = `event Routed(bytes indexed uniquePID, address indexed userAddress, address outputReceiver, address inputToken, uint256 inputAmount, address outputToken, uint256 outputAmount, uint256 partnerFee, uint256 routingFee, uint256 finalOutputAmount)` ;
7+
8+ const eventNew = `event Routed(bytes32 indexed uniquePID, address indexed userAddress, address outputReceiver, address inputToken, uint256 inputAmount, address outputToken, uint256 finalOutputAmount, uint256 partnerFee, uint256 routingFee, uint256 partnerShare, uint256 protocolShare)` ;
9+
10+ // Native token identifiers (used with addGasToken)
1911const gasTokens = new Set ( [
20- ADDRESSES . GAS_TOKEN_2 ,
21- ADDRESSES . null ,
22- '0x2222222222222222222222222222222222222222' , // hyperliquid
23- ADDRESSES . polygon . WMATIC_1 , // polygon
24- ] )
25-
26- const config : any = {
27- [ CHAIN . ETHEREUM ] : { } ,
28- [ CHAIN . ARBITRUM ] : { } ,
29- [ CHAIN . BASE ] : { } ,
30- [ CHAIN . XDAI ] : { } ,
31- [ CHAIN . BSC ] : { } ,
32- [ CHAIN . POLYGON ] : { } ,
33- [ CHAIN . AVAX ] : { } ,
34- [ CHAIN . OPTIMISM ] : { } ,
35- [ CHAIN . BLAST ] : { } ,
36- [ CHAIN . LINEA ] : { } ,
37- [ CHAIN . MANTLE ] : { router : "0x85fb41c470B8Dd2C9aD262F38e38E42a2f92C285" } ,
38- [ CHAIN . SCROLL ] : { } ,
39- [ CHAIN . TAIKO ] : { router : "0x75e74A67Bd4A76BcE60bb0546f092571c3133523" } ,
40- [ CHAIN . BERACHAIN ] : { } ,
41- [ CHAIN . SONIC ] : { } ,
42- [ CHAIN . UNICHAIN ] : { } ,
43- [ CHAIN . HYPERLIQUID ] : { } ,
44- }
12+ ADDRESSES . GAS_TOKEN_2 , // 0xeeee...eeee
13+ ADDRESSES . null , // 0x0000...0000
14+ '0x2222222222222222222222222222222222222222' , // Hyperliquid
15+ ADDRESSES . polygon . WMATIC_1 , // WMATIC on Polygon
16+ ] ) ;
17+
18+ // Router addresses
19+ const ROUTERS_OLD : Partial < Record < string , string > > = {
20+ [ CHAIN . ETHEREUM ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
21+ [ CHAIN . ARBITRUM ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
22+ [ CHAIN . BASE ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
23+ [ CHAIN . XDAI ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
24+ [ CHAIN . BSC ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
25+ [ CHAIN . POLYGON ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
26+ [ CHAIN . AVAX ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
27+ [ CHAIN . OPTIMISM ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
28+ [ CHAIN . BLAST ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
29+ [ CHAIN . LINEA ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
30+ [ CHAIN . MANTLE ] : "0x85fb41c470B8Dd2C9aD262F38e38E42a2f92C285" ,
31+ [ CHAIN . SCROLL ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
32+ [ CHAIN . TAIKO ] : "0x75e74A67Bd4A76BcE60bb0546f092571c3133523" ,
33+ [ CHAIN . BERACHAIN ] :"0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
34+ [ CHAIN . SONIC ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
35+ [ CHAIN . UNICHAIN ] : "0x6Ec7612828B776cC746fe0Ee5381CC93878844f7" ,
36+ [ CHAIN . HYPERLIQUID ] :"0x6Ec7612828B776cC746fe0Ee5381CC93878844f7"
37+ } ;
38+
39+ // Router addresses
40+ const ROUTERS_NEW : Partial < Record < string , string > > = {
41+ [ CHAIN . ETHEREUM ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
42+ [ CHAIN . ARBITRUM ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
43+ [ CHAIN . BASE ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
44+ [ CHAIN . XDAI ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
45+ [ CHAIN . BSC ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
46+ [ CHAIN . POLYGON ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
47+ [ CHAIN . AVAX ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
48+ [ CHAIN . OPTIMISM ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
49+ [ CHAIN . BLAST ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
50+ [ CHAIN . LINEA ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
51+ [ CHAIN . MANTLE ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
52+ [ CHAIN . SCROLL ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
53+ [ CHAIN . TAIKO ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
54+ [ CHAIN . BERACHAIN ] :"0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
55+ [ CHAIN . SONIC ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
56+ [ CHAIN . UNICHAIN ] : "0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd" ,
57+ [ CHAIN . HYPERLIQUID ] :"0xe95f6eaeae1e4d650576af600b33d9f7e5f9f7fd"
58+ } ;
4559
46- const START = '2025-03-14' ; // Mar-14-2025
60+ async function fetch ( options : FetchOptions ) {
61+ const { getLogs, createBalances, chain } = options ;
4762
48- async function fetch ( { getLogs, createBalances, chain } : FetchOptions ) {
49- const { router = DEFAULT_ROUTER } = config [ chain ]
50- const logs = await getLogs ( { targets : [ router ] , eventAbi : eventRouted , } ) ;
5163 const dailyVolume = createBalances ( ) ;
5264 const dailyFees = createBalances ( ) ;
5365 const dailyRevenue = createBalances ( ) ;
5466
55- logs . forEach ( ( log ) => {
56- const token = log . outputToken . toLowerCase ( ) ;
57- const outputAmount = log . outputAmount ;
58- const revenue = log . routingFee ; // comment from the team: We are currently setting it to 1 as default because the contract requires routingFee > 0. That was a design failure we overlook. Effectively routingFee should be 0 at the moment, i.e. Gluex is not charging a protocol fee
59- const fee = log . routingFee + log . partnerFee ;
60-
61- const isNative = gasTokens . has ( token )
62-
63- if ( isNative ) {
64- dailyVolume . addGasToken ( outputAmount ) ;
65- dailyFees . addGasToken ( fee ) ;
66- dailyRevenue . addGasToken ( revenue ) ;
67- } else {
68- dailyVolume . add ( token , outputAmount ) ;
69- dailyFees . add ( token , fee ) ;
70- dailyRevenue . add ( token , revenue ) ;
67+ const oldRouter = ROUTERS_OLD [ chain ] ;
68+ const newRouter = ROUTERS_NEW [ chain ] ;
69+
70+ if ( oldRouter ) {
71+ const oldLogs = await getLogs ( { targets : [ oldRouter ] , eventAbi : eventOld } ) ;
72+ for ( const log of oldLogs ) {
73+ const token = log . outputToken . toLowerCase ( ) ;
74+ const outputAmount = log . outputAmount ;
75+ const fee = log . partnerFee + log . routingFee ;
76+ const revenue = log . routingFee ;
77+
78+ const isNative = gasTokens . has ( token ) ;
79+ if ( isNative ) {
80+ dailyVolume . addGasToken ( outputAmount ) ;
81+ dailyFees . addGasToken ( fee ) ;
82+ dailyRevenue . addGasToken ( revenue ) ;
83+ } else {
84+ dailyVolume . add ( token , outputAmount ) ;
85+ dailyFees . add ( token , fee ) ;
86+ dailyRevenue . add ( token , revenue ) ;
87+ }
7188 }
72- } ) ;
89+ }
90+
91+ if ( newRouter ) {
92+ const newLogs = await getLogs ( { targets : [ newRouter ] , eventAbi : eventNew } ) ;
93+ for ( const log of newLogs ) {
94+ const token = log . outputToken . toLowerCase ( ) ;
95+ const outputAmount = log . finalOutputAmount ;
96+ const fee = log . partnerFee + log . routingFee + log . partnerShare + log . protocolShare ;
97+ const revenue = log . protocolShare ;
98+
99+ const isNative = gasTokens . has ( token ) ;
100+ if ( isNative ) {
101+ dailyVolume . addGasToken ( outputAmount ) ;
102+ dailyFees . addGasToken ( fee ) ;
103+ dailyRevenue . addGasToken ( revenue ) ;
104+ } else {
105+ dailyVolume . add ( token , outputAmount ) ;
106+ dailyFees . add ( token , fee ) ;
107+ dailyRevenue . add ( token , revenue ) ;
108+ }
109+ }
110+ }
73111
74112 return {
75113 dailyVolume,
76114 dailyFees,
77115 dailyRevenue,
78- dailyProtocolRevenue : '0' ,
116+ dailyProtocolRevenue : dailyRevenue ,
79117 } ;
80118}
81119
120+ const meta = {
121+ methodology : {
122+ Fees : "Fees paid by users for swaps." ,
123+ Revenue : "Revenue is calculated as the sum of routingFee for the old contract and the sum of protocolShare for the new contract." ,
124+ ProtocolRevenue : "Protocol Revenue is calculated as the sum of routing fees and protocol share."
125+ }
126+ }
127+
82128const adapter : SimpleAdapter = {
83129 version : 2 ,
84130 adapter : { } ,
85131} ;
86132
87- Object . keys ( config ) . forEach ( chain => {
88- adapter . adapter [ chain ] = { fetch, start : START , }
89- } )
133+ Object . keys ( { ... ROUTERS_OLD , ... ROUTERS_NEW } ) . forEach ( chain => {
134+ adapter . adapter [ chain ] = { fetch, start : '2025-03-14' , meta } ;
135+ } ) ;
90136
91- export default adapter ;
137+ export default adapter ;
0 commit comments