Skip to content

Commit

Permalink
Yj-feat/factory-addresses (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
jagnani73 authored Mar 13, 2024
1 parent 8a29382 commit 5c046ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 47 deletions.
62 changes: 33 additions & 29 deletions services/decoder/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class GoldRushDecoder {
private static fallbacks: Fallbacks = {};
private static native_decoder: NativeDecodingFunction;
private static decoding_functions: DecodingFunctions = [];
private static fallback_functions: DecodingFunctions = [];
private static fileExtension: "js" | "ts" =
process.env.NODE_ENV !== "test" ? "js" : "ts";

Expand All @@ -32,6 +33,7 @@ export class GoldRushDecoder {
const protocolsDirectoryPath: string = join(__dirname, "/protocols");
const protocols = readdirSync(protocolsDirectoryPath);
let protocolsCount: number = 0;
let configsCount: number = 0;
for (const protocol of protocols) {
const protocolPath = join(protocolsDirectoryPath, protocol);
const files = readdirSync(protocolPath);
Expand All @@ -56,6 +58,7 @@ export class GoldRushDecoder {
this.configs[chain_name][protocol_name][address] = {
is_factory: is_factory,
};
configsCount++;
}
);
require(join(protocolPath, decodersFile));
Expand All @@ -64,7 +67,6 @@ export class GoldRushDecoder {

const fallbacksDirectoryPath: string = join(__dirname, "/fallbacks");
const fallbacks = readdirSync(fallbacksDirectoryPath);
let fallbacksCount: number = 0;
for (const fallback of fallbacks) {
const fallbackPath = join(fallbacksDirectoryPath, fallback);
const files = readdirSync(fallbackPath);
Expand All @@ -75,7 +77,6 @@ export class GoldRushDecoder {
}
});
if (fallbackFile) {
fallbacksCount++;
require(join(fallbackPath, fallbackFile));
}
}
Expand All @@ -87,20 +88,10 @@ export class GoldRushDecoder {
);
require(join(nativeDecoderPath));

const decodersCount = Object.keys(this.decoding_functions).length;
const configsCount = Object.values(this.configs).reduce(
(chainCount, chain) => {
return (
chainCount +
Object.values(chain).reduce((addressCount, protocol) => {
return addressCount + Object.keys(protocol).length;
}, 0)
);
},
0
);
const decodersCount = this.decoding_functions.length;
const fallbacksCount = this.fallback_functions.length;

console.info("native decoder added");
console.info("1 native decoder added");
console.info(`${protocolsCount.toLocaleString()} protocols found`);
console.info(`${configsCount.toLocaleString()} configs generated`);
console.info(`${decodersCount.toLocaleString()} decoders generated`);
Expand Down Expand Up @@ -150,10 +141,10 @@ export class GoldRushDecoder {
abi: abi,
eventName: event_name,
});
this.decoding_functions.push(decoding_function);
const decoding_function_index: number =
this.decoding_functions.length - 1;
this.fallbacks[topic0_hash] = decoding_function_index;
this.fallback_functions.push(decoding_function);
const fallback_function_index: number =
this.fallback_functions.length - 1;
this.fallbacks[topic0_hash] = fallback_function_index;
};

public static native = (native_decoder: NativeDecodingFunction) => {
Expand All @@ -175,19 +166,32 @@ export class GoldRushDecoder {
for (const log of logs) {
const {
raw_log_topics: [topic0_hash],
sender_address: contract_address,
// !ERROR: add factory_contract_address in the log_event(s)
// factory_contract_address,
sender_address,
sender_factory_address,
} = log;
const decoding_index =
// !ERROR: add factory_contract_address in the log_event(s)
// factory_contract_address ||
this.decoders[chain_name]?.[contract_address]?.[topic0_hash];
this.decoders[chain_name]?.[sender_address]?.[topic0_hash] ??
this.decoders[chain_name]?.[sender_factory_address]?.[
topic0_hash
];
const fallback_index = this.fallbacks[topic0_hash];
if (decoding_index !== undefined || fallback_index !== undefined) {
const logEvent = await this.decoding_functions[
decoding_index ?? fallback_index
](log, tx, chain_name, covalent_client);
let logEvent: EventType | null = null;
if (decoding_index !== undefined) {
logEvent = await this.decoding_functions[decoding_index](
log,
tx,
chain_name,
covalent_client
);
} else if (fallback_index !== undefined) {
logEvent = await this.fallback_functions[fallback_index](
log,
tx,
chain_name,
covalent_client
);
}
if (logEvent) {
events.push(logEvent);
}
}
Expand Down
18 changes: 0 additions & 18 deletions services/decoder/protocols/uniswap-v2/uniswap-v2.configs.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import { type Configs } from "../../decoder.types";

const configs: Configs = [
{
protocol_name: "uniswap-v2",
address: "0xaf31fd9c3b0350424bf96e551d2d1264d8466205",
is_factory: false,
chain_name: "eth-mainnet",
},
{
address: "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
is_factory: false,
protocol_name: "uniswap-v2",
chain_name: "eth-mainnet",
},
{
address: "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852",
is_factory: false,
protocol_name: "uniswap-v2",
chain_name: "eth-mainnet",
},
{
address: "0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f",
is_factory: true,
Expand Down

0 comments on commit 5c046ae

Please sign in to comment.