Skip to content

Commit 5c046ae

Browse files
authored
Yj-feat/factory-addresses (#34)
1 parent 8a29382 commit 5c046ae

File tree

2 files changed

+33
-47
lines changed

2 files changed

+33
-47
lines changed

services/decoder/decoder.ts

+33-29
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class GoldRushDecoder {
2323
private static fallbacks: Fallbacks = {};
2424
private static native_decoder: NativeDecodingFunction;
2525
private static decoding_functions: DecodingFunctions = [];
26+
private static fallback_functions: DecodingFunctions = [];
2627
private static fileExtension: "js" | "ts" =
2728
process.env.NODE_ENV !== "test" ? "js" : "ts";
2829

@@ -32,6 +33,7 @@ export class GoldRushDecoder {
3233
const protocolsDirectoryPath: string = join(__dirname, "/protocols");
3334
const protocols = readdirSync(protocolsDirectoryPath);
3435
let protocolsCount: number = 0;
36+
let configsCount: number = 0;
3537
for (const protocol of protocols) {
3638
const protocolPath = join(protocolsDirectoryPath, protocol);
3739
const files = readdirSync(protocolPath);
@@ -56,6 +58,7 @@ export class GoldRushDecoder {
5658
this.configs[chain_name][protocol_name][address] = {
5759
is_factory: is_factory,
5860
};
61+
configsCount++;
5962
}
6063
);
6164
require(join(protocolPath, decodersFile));
@@ -64,7 +67,6 @@ export class GoldRushDecoder {
6467

6568
const fallbacksDirectoryPath: string = join(__dirname, "/fallbacks");
6669
const fallbacks = readdirSync(fallbacksDirectoryPath);
67-
let fallbacksCount: number = 0;
6870
for (const fallback of fallbacks) {
6971
const fallbackPath = join(fallbacksDirectoryPath, fallback);
7072
const files = readdirSync(fallbackPath);
@@ -75,7 +77,6 @@ export class GoldRushDecoder {
7577
}
7678
});
7779
if (fallbackFile) {
78-
fallbacksCount++;
7980
require(join(fallbackPath, fallbackFile));
8081
}
8182
}
@@ -87,20 +88,10 @@ export class GoldRushDecoder {
8788
);
8889
require(join(nativeDecoderPath));
8990

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;
10293

103-
console.info("native decoder added");
94+
console.info("1 native decoder added");
10495
console.info(`${protocolsCount.toLocaleString()} protocols found`);
10596
console.info(`${configsCount.toLocaleString()} configs generated`);
10697
console.info(`${decodersCount.toLocaleString()} decoders generated`);
@@ -150,10 +141,10 @@ export class GoldRushDecoder {
150141
abi: abi,
151142
eventName: event_name,
152143
});
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;
157148
};
158149

159150
public static native = (native_decoder: NativeDecodingFunction) => {
@@ -175,19 +166,32 @@ export class GoldRushDecoder {
175166
for (const log of logs) {
176167
const {
177168
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,
181171
} = log;
182172
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+
];
186177
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) {
191195
events.push(logEvent);
192196
}
193197
}

services/decoder/protocols/uniswap-v2/uniswap-v2.configs.ts

-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
import { type Configs } from "../../decoder.types";
22

33
const configs: Configs = [
4-
{
5-
protocol_name: "uniswap-v2",
6-
address: "0xaf31fd9c3b0350424bf96e551d2d1264d8466205",
7-
is_factory: false,
8-
chain_name: "eth-mainnet",
9-
},
10-
{
11-
address: "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
12-
is_factory: false,
13-
protocol_name: "uniswap-v2",
14-
chain_name: "eth-mainnet",
15-
},
16-
{
17-
address: "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852",
18-
is_factory: false,
19-
protocol_name: "uniswap-v2",
20-
chain_name: "eth-mainnet",
21-
},
224
{
235
address: "0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f",
246
is_factory: true,

0 commit comments

Comments
 (0)