Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
const apiKey = process.env.ETHERSCAN_API_KEY;
if (apiKey === undefined) {
throw new Error('Missing required env var: ETHERSCAN_API_KEY');
}
connection = await createConnection(ormConfig as ConnectionOptions);
const provider = web3Factory.getRpcProvider({
rpcUrl: INFURA_ROOT_URL,
});
const EtherscanTransactionRepository = connection.getRepository(EtherscanTransaction);
const startBlock = await getStartBlockAsync(EtherscanTransactionRepository);
logUtils.log(`Start block: ${startBlock}`);
const endBlock = await calculateEndBlockAsync(provider);
logUtils.log(`End block: ${endBlock}`);
const etherscanSource = new EtherscanSource(apiKey, startBlock, endBlock);
const exchangeContractAddress = getContractAddressesForNetworkOrThrow(NetworkId.Mainnet).exchange;
logUtils.log('Fetching exchange transactions from Etherscan...');
const rawTransactions = await etherscanSource.getEtherscanTransactionsForAddressAsync(exchangeContractAddress);
const transactions = parseEtherscanTransactions(rawTransactions);
logUtils.log(`Saving ${transactions.length} records to database`);
await EtherscanTransactionRepository.save(transactions, {
chunk: Math.ceil(transactions.length / BATCH_SAVE_SIZE),
});
logUtils.log('Done');
process.exit(0);
})().catch(handleError);