Skip to content

Commit

Permalink
formalize workers before calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonzg committed Mar 23, 2023
1 parent 013fe31 commit e21435e
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions libs/rewardProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,19 @@ function SetupForPool(logger, poolOptions, setupFinished) {
}

let leftover = new BigNumber(actualTotalReward);
// turn workers into BigNumbers
for (w in workers) {
if (workers[w].reward) {
workers[w].reward = new BigNumber(workers[w].reward);
} else {
workers[w].reward = new BigNumber(0);
}
if (workers[w].balance) {
workers[w].balance = new BigNumber(workers[w].balance);
} else {
workers[w].balance = new BigNumber(0);
}
}

// add beneficiary
if (!(beneficiary in workers)) {
Expand All @@ -385,6 +398,8 @@ function SetupForPool(logger, poolOptions, setupFinished) {
reward: new BigNumber(0),
issue: false,
};
} else {
workers[beneficiary].issue = false;
}

// add poolTaxReciever
Expand All @@ -409,19 +424,7 @@ function SetupForPool(logger, poolOptions, setupFinished) {
reward: new BigNumber(0),
balance: new BigNumber(0),
};
} else {
if (workers[w].reward) {
workers[w].reward = new BigNumber(workers[w].reward);
} else {
workers[w].reward = new BigNumber(0);
}
if (workers[w].balance) {
workers[w].balance = new BigNumber(workers[w].balance);
} else {
workers[w].balance = new BigNumber(0);
}
}

const workerReward = actualTotalReward
.times(share)
.div(totalShares)
Expand Down Expand Up @@ -487,7 +490,7 @@ function SetupForPool(logger, poolOptions, setupFinished) {
if (leftover.isGreaterThan(0)) {
console.log(`add leftover to reserve: `, leftover.toFixed(0));
workers[beneficiary].balance = new BigNumber(
leftover.plus(workers[beneficiary]).balance.toFixed(0)
leftover.plus(workers[beneficiary].balance.toFixed(0))
);
logger.debug(
logSystem,
Expand Down

0 comments on commit e21435e

Please sign in to comment.