message: Improve getJoeDualLpApys concurrency
diff: @@ -32,7 +32,7 @@ const getJoeDualLpApys = async () => {
  const tokenPriceA = await fetchPrice({ oracle: oracleA, id: oracleIdA });
  const { rewardPerSecond, totalAllocPoint } = await getMasterChefData();
  - const { balances, allocPoints, rewarders } = await getPoolsData(pools);
  + const { balances, allocPoints, tokenPerSecData } = await getPoolsData(pools);
  const pairAddresses = pools.map(pool => pool.address);
  const tradingAprs = await getTradingFeeAprSushi(joeClient, pairAddresses, liquidityProviderFee);
  @@ -46,18 +46,14 @@ const getJoeDualLpApys = async () => {
  const poolBlockRewards = rewardPerSecond.times(allocPoints[i]).dividedBy(totalAllocPoint);
  const yearlyRewards = poolBlockRewards.dividedBy(secondsPerBlock).times(secondsPerYear);
  const yearlyRewardsAInUsd = yearlyRewards.times(tokenPriceA).dividedBy(DECIMALSA);
  + let yearlyRewardsBInUsd = new BigNumber(0);
  - const yearlyRewardsBInUsd = await (async () => {
  - if (rewarders[i] === '0x0000000000000000000000000000000000000000') {
  - return 0;
  - } else {
  + if (!tokenPerSecData[i].isNaN()) {
  + let tokenBPerSec = tokenPerSecData[i];
  const tokenPriceB = await fetchPrice({ oracle: pool.oracleB, id: pool.oracleIdB });
  - const rewarderContract = new web3.eth.Contract(SimpleRewarder, rewarders[i]);
  - const tokenBPerSec = new BigNumber(await rewarderContract.methods.tokenPerSec().call());
  const yearlyRewardsB = tokenBPerSec.dividedBy(secondsPerBlock).times(secondsPerYear);
  - return yearlyRewardsB.times(tokenPriceB).dividedBy(pool.decimalsB);
  + yearlyRewardsBInUsd = yearlyRewardsB.times(tokenPriceB).dividedBy(pool.decimalsB);
  }
  - })();
  const yearlyRewardsInUsd = yearlyRewardsAInUsd.plus(yearlyRewardsBInUsd);
  @@ -115,6 +111,7 @@ const getPoolsData = async pools => {
  const multicall = new MultiCall(web3, multicallAddress(AVAX_CHAIN_ID));
  const balanceCalls = [];
  const poolInfoCalls = [];
  + const tokenPerSecCalls = [];
  pools.forEach(pool => {
  const tokenContract = new web3.eth.Contract(ERC20, pool.address);
  balanceCalls.push({
  @@ -131,7 +128,20 @@ const getPoolsData = async pools => {
  const balances = res[0].map(v => new BigNumber(v.balance));
  const allocPoints = res[1].map(v => v.poolInfo['3']);
  const rewarders = res[1].map(v => v.poolInfo[4]);
  - return { balances, allocPoints, rewarders };
  +
  + rewarders.forEach(rewarder => {
  + let rewarderContract = new web3.eth.Contract(SimpleRewarder, rewarder);
  + let tokenPerSec = rewarderContract.methods.tokenPerSec();
  + tokenPerSecCalls.push({
  + tokenPerSec: tokenPerSec,
  + });
  + });
  +
  + const tokenPerSecData = (await multicall.all([tokenPerSecCalls]))[0].map(
  + t => new BigNumber(t.tokenPerSec)
  + );
  +
  + return { balances, allocPoints, tokenPerSecData };
  };
  module.exports = getJoeDualLpApys;
  