Skip to content

Commit

Permalink
Optimize storePoolRewards
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Jun 3, 2021
1 parent 58e4654 commit 483ecac
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tasks/store-pool-rewards.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 483ecac

Please sign in to comment.