@@ -23,6 +23,7 @@ export class GoldRushDecoder {
23
23
private static fallbacks : Fallbacks = { } ;
24
24
private static native_decoder : NativeDecodingFunction ;
25
25
private static decoding_functions : DecodingFunctions = [ ] ;
26
+ private static fallback_functions : DecodingFunctions = [ ] ;
26
27
private static fileExtension : "js" | "ts" =
27
28
process . env . NODE_ENV !== "test" ? "js" : "ts" ;
28
29
@@ -32,6 +33,7 @@ export class GoldRushDecoder {
32
33
const protocolsDirectoryPath : string = join ( __dirname , "/protocols" ) ;
33
34
const protocols = readdirSync ( protocolsDirectoryPath ) ;
34
35
let protocolsCount : number = 0 ;
36
+ let configsCount : number = 0 ;
35
37
for ( const protocol of protocols ) {
36
38
const protocolPath = join ( protocolsDirectoryPath , protocol ) ;
37
39
const files = readdirSync ( protocolPath ) ;
@@ -56,6 +58,7 @@ export class GoldRushDecoder {
56
58
this . configs [ chain_name ] [ protocol_name ] [ address ] = {
57
59
is_factory : is_factory ,
58
60
} ;
61
+ configsCount ++ ;
59
62
}
60
63
) ;
61
64
require ( join ( protocolPath , decodersFile ) ) ;
@@ -64,7 +67,6 @@ export class GoldRushDecoder {
64
67
65
68
const fallbacksDirectoryPath : string = join ( __dirname , "/fallbacks" ) ;
66
69
const fallbacks = readdirSync ( fallbacksDirectoryPath ) ;
67
- let fallbacksCount : number = 0 ;
68
70
for ( const fallback of fallbacks ) {
69
71
const fallbackPath = join ( fallbacksDirectoryPath , fallback ) ;
70
72
const files = readdirSync ( fallbackPath ) ;
@@ -75,7 +77,6 @@ export class GoldRushDecoder {
75
77
}
76
78
} ) ;
77
79
if ( fallbackFile ) {
78
- fallbacksCount ++ ;
79
80
require ( join ( fallbackPath , fallbackFile ) ) ;
80
81
}
81
82
}
@@ -87,20 +88,10 @@ export class GoldRushDecoder {
87
88
) ;
88
89
require ( join ( nativeDecoderPath ) ) ;
89
90
90
- const decodersCount = Object . keys ( this . decoding_functions ) . length ;
91
- const configsCount = Object . values ( this . configs ) . reduce (
92
- ( chainCount , chain ) => {
93
- return (
94
- chainCount +
95
- Object . values ( chain ) . reduce ( ( addressCount , protocol ) => {
96
- return addressCount + Object . keys ( protocol ) . length ;
97
- } , 0 )
98
- ) ;
99
- } ,
100
- 0
101
- ) ;
91
+ const decodersCount = this . decoding_functions . length ;
92
+ const fallbacksCount = this . fallback_functions . length ;
102
93
103
- console . info ( "native decoder added" ) ;
94
+ console . info ( "1 native decoder added" ) ;
104
95
console . info ( `${ protocolsCount . toLocaleString ( ) } protocols found` ) ;
105
96
console . info ( `${ configsCount . toLocaleString ( ) } configs generated` ) ;
106
97
console . info ( `${ decodersCount . toLocaleString ( ) } decoders generated` ) ;
@@ -150,10 +141,10 @@ export class GoldRushDecoder {
150
141
abi : abi ,
151
142
eventName : event_name ,
152
143
} ) ;
153
- this . decoding_functions . push ( decoding_function ) ;
154
- const decoding_function_index : number =
155
- this . decoding_functions . length - 1 ;
156
- this . fallbacks [ topic0_hash ] = decoding_function_index ;
144
+ this . fallback_functions . push ( decoding_function ) ;
145
+ const fallback_function_index : number =
146
+ this . fallback_functions . length - 1 ;
147
+ this . fallbacks [ topic0_hash ] = fallback_function_index ;
157
148
} ;
158
149
159
150
public static native = ( native_decoder : NativeDecodingFunction ) => {
@@ -175,19 +166,32 @@ export class GoldRushDecoder {
175
166
for ( const log of logs ) {
176
167
const {
177
168
raw_log_topics : [ topic0_hash ] ,
178
- sender_address : contract_address ,
179
- // !ERROR: add factory_contract_address in the log_event(s)
180
- // factory_contract_address,
169
+ sender_address,
170
+ sender_factory_address,
181
171
} = log ;
182
172
const decoding_index =
183
- // !ERROR: add factory_contract_address in the log_event(s)
184
- // factory_contract_address ||
185
- this . decoders [ chain_name ] ?. [ contract_address ] ?. [ topic0_hash ] ;
173
+ this . decoders [ chain_name ] ?. [ sender_address ] ?. [ topic0_hash ] ??
174
+ this . decoders [ chain_name ] ?. [ sender_factory_address ] ?. [
175
+ topic0_hash
176
+ ] ;
186
177
const fallback_index = this . fallbacks [ topic0_hash ] ;
187
- if ( decoding_index !== undefined || fallback_index !== undefined ) {
188
- const logEvent = await this . decoding_functions [
189
- decoding_index ?? fallback_index
190
- ] ( log , tx , chain_name , covalent_client ) ;
178
+ let logEvent : EventType | null = null ;
179
+ if ( decoding_index !== undefined ) {
180
+ logEvent = await this . decoding_functions [ decoding_index ] (
181
+ log ,
182
+ tx ,
183
+ chain_name ,
184
+ covalent_client
185
+ ) ;
186
+ } else if ( fallback_index !== undefined ) {
187
+ logEvent = await this . fallback_functions [ fallback_index ] (
188
+ log ,
189
+ tx ,
190
+ chain_name ,
191
+ covalent_client
192
+ ) ;
193
+ }
194
+ if ( logEvent ) {
191
195
events . push ( logEvent ) ;
192
196
}
193
197
}
0 commit comments