message: switch from bscscan to ethers events
diff: -const axios = require('axios');
  const { bscWeb3: web3 } = require('./web3');
  +const { BigNumber, ethers } = require('ethers');
  +const { BSC_RPC } = require('../../constants');
  +const ERC20 = require('../abis/ERC20.json');
  const getDailyEarnings = async () => {
  - let totalEarnings = 0;
  - let page = 1;
  + const provider = new ethers.providers.JsonRpcProvider(BSC_RPC);
  + const contract = new ethers.Contract("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", ERC20, provider);
  + const filterTo = contract.filters.Transfer(null, "0x453d4ba9a2d594314df88564248497f7d74d6b2c");
  +
  + let totalEarnings = BigNumber.from(0);
  let difference = 20 * 60 * 24;
  const endBlock = await web3.eth.getBlockNumber();
  const startBlock = endBlock - difference;
  + let currentBlock = startBlock;
  + let result = BigNumber.from(0);
  try{
  - while (true) {
  - const response = await axios.get('https://api.bscscan.com/api', {
  - params: {
  - module: 'account',
  - action: 'tokentx',
  - contractaddress: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
  - address: '0x453d4ba9a2d594314df88564248497f7d74d6b2c',
  - offset: '1000',
  - sort: 'asc',
  - startblock: startBlock,
  - endblock: endBlock,
  - page: page,
  - },
  - });
  -
  - let data = response.data['result'];
  -
  - if (!data || data.length === 0) {
  - break;
  - }
  -
  - const earnings = data.filter(e => e.to === '0x453d4ba9a2d594314df88564248497f7d74d6b2c');
  + while (currentBlock < endBlock) {
  + // provider only allows up to 5000 blocks at a time
  + let data = await contract.queryFilter(filterTo, currentBlock, currentBlock+5000);
  + for (var i = 0; i < data.length; i++ ){
  + let hexAmount = data[i]["args"][2];
  - earnings.forEach(x => (totalEarnings += parseInt(x.value)));
  + let amount = BigNumber.from(hexAmount);
  - page++;
  - sleep(100);
  + totalEarnings = totalEarnings.add(amount);
  }
  - } catch (err) {
  - console.error('Daily earnings error:', err);
  + currentBlock += 5000;
  }
  + console.log("> calculated daily earnings");
  + // divide twice to avoid overflow error, 1e16 so we can have 2 decimal places in response
  + let result = (totalEarnings.div(1e9)).div(1e7);
  +
  return {
  - daily: totalEarnings / 1e18,
  + daily: result.toNumber() / 100,
  startBlock: startBlock,
  endBlock: endBlock,
  };
  -};
  -
  -function sleep(ms) {
  - return new Promise(resolve => setTimeout(resolve, ms));
  + } catch (err){
  + console.error('Daily earnings error:', err);
  + return {};
  }
  +};
  +
  module.exports = { getDailyEarnings };
  