Skip to content

Commit

Permalink
Events Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Ktl-XV committed Jan 22, 2024
1 parent a9a1293 commit 57a3ec8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
25 changes: 0 additions & 25 deletions migrations/1705420603000-NewBackfillTables.ts

This file was deleted.

15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
CHAIN_ID,
ENABLE_PROMETHEUS_METRICS,
FEAT_TOKENS_FROM_TRANSFERS,
FEAT_UNISWAP_V2_PAIR_CREATED_EVENT,
FEAT_UNISWAP_V3_POOL_CREATED_EVENT,
KAFKA_AUTH_PASSWORD,
Expand All @@ -20,11 +21,11 @@ import { BlockEventsScraper } from './scripts/pull_and_save_block_events';
import { BlockScraper } from './scripts/pull_and_save_blocks';
import { EventsByTopicScraper } from './scripts/pull_and_save_events_by_topic';
import { TokensFromBackfill } from './scripts/pull_and_save_tokens_backfill';
import { TokensFromTransfersScraper } from './scripts/pull_and_save_tokens_from_transfers';
import { TokenMetadataSingleton } from './tokenMetadataSingleton';
import { UniV2PoolSingleton } from './uniV2PoolSingleton';
import { UniV3PoolSingleton } from './uniV3PoolSingleton';
import { logger } from './utils/logger';
//import { CurrentBlockMonitor } from './scripts/monitor_current_block';
import { startMetricsServer } from './utils/metrics';
import { config } from 'dotenv';
import { Kafka, Producer } from 'kafkajs';
Expand Down Expand Up @@ -59,6 +60,7 @@ const eventsByTopicScraper = new EventsByTopicScraper();
const eventsBackfillScraper = new EventsBackfillScraper();
const blockEventsScraper = new BlockEventsScraper();
const currentBlockMonitor = new CurrentBlockMonitor();
const tokensFromTransfersScraper = new TokensFromTransfersScraper();
const tokensFromBackfill = new TokensFromBackfill();

if (ENABLE_PROMETHEUS_METRICS) {
Expand Down Expand Up @@ -106,8 +108,17 @@ createConnection(ormConfig as ConnectionOptions)
connection,
producer,
tokensFromBackfill.getParseSaveTokensFromBackfillAsync,
'Pull and Save Backfill Transactions',
'Pull and Save Backfill Tokens',
);

if (FEAT_TOKENS_FROM_TRANSFERS) {
schedule(
connection,
producer,
tokensFromTransfersScraper.getParseSaveTokensFromTransfersAsync,
'Pull and Save Tokens From Transfers',
);
}
}
})
.catch((error) => logger.error(error));
Expand Down
13 changes: 10 additions & 3 deletions src/scripts/utils/event_abi_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,20 @@ export const getStartBlockAsync = async (

if (lastKnownBlock.block_hash !== lastKnownBlockFresh.hash) {
return {
startBlockNumber: lastKnownBlockNumber - MAX_BLOCKS_REORG,
startBlockNumber: min0(lastKnownBlockNumber - MAX_BLOCKS_REORG),
hasLatestBlockChanged: true,
reorgLikely: true,
};
}
return {
startBlockNumber: lastKnownBlockNumber - (RESCRAPE_BLOCKS - 1),
startBlockNumber: min0(lastKnownBlockNumber - (RESCRAPE_BLOCKS - 1)),
hasLatestBlockChanged: true,
reorgLikely: false,
};
}
if (lastKnownBlock.block_hash !== currentBlock.hash) {
return {
startBlockNumber: lastKnownBlockNumber - MAX_BLOCKS_REORG,
startBlockNumber: min0(lastKnownBlockNumber - MAX_BLOCKS_REORG),
hasLatestBlockChanged: true,
reorgLikely: true,
};
Expand All @@ -391,6 +391,13 @@ export const getStartBlockAsync = async (
};
};

export function min0(num: number): number {
if (num > 0) {
return num;
}
return 0;
}

export const getLastBlockProcessedEntity = (
eventName: string,
endBlockNumber: number,
Expand Down

0 comments on commit 57a3ec8

Please sign in to comment.