From 483ecacb5a6d4e32029c8bbddb86ba5165d7c112 Mon Sep 17 00:00:00 2001 From: Leonid Beder Date: Thu, 3 Jun 2021 22:26:50 +0100 Subject: [PATCH] Optimize storePoolRewards --- tasks/store-pool-rewards.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tasks/store-pool-rewards.js b/tasks/store-pool-rewards.js index 903ed72..e8ad283 100644 --- a/tasks/store-pool-rewards.js +++ b/tasks/store-pool-rewards.js @@ -1,4 +1,5 @@ const { trace, info, error, arg } = require('../utils/logger'); +const BN = require('bn.js'); const DB = require('../utils/db'); const BATCH_SIZE = 15; @@ -9,7 +10,21 @@ const storePoolRewardsTask = async (env, { poolToken }) => { let totalGas = 0; - const providers = Object.keys(data.pendingRewards); + let providers = []; + for (const provider of Object.keys(data.pendingRewards)) { + const rewards = await web3Provider.call( + contracts.StakingRewards.methods.pendingPoolRewards(provider, poolToken) + ); + + if (new BN(rewards).eq(new BN(0))) { + trace('Skipping provider without any pending rewards', arg('provider', provider)); + + continue; + } + + providers.push(provider); + } + for (let i = 0; i < providers.length; i += BATCH_SIZE) { const providersBatch = providers.slice(i, i + BATCH_SIZE);