Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payroll: handle both cases of extra salary being sent to accrued balance #912

Merged
merged 1 commit into from
Jul 8, 2019

Conversation

sohkai
Copy link
Contributor

@sohkai sohkai commented Jul 8, 2019

Handles both the cases, where someone may:

  • Request less than their salary per second
  • Request a multiple (and then some) of their salary per second

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.732% when pulling 0327c45 on payroll-extra-accrued-salary into 14611ee on master.

@facuspagnuolo facuspagnuolo merged commit 9f40e08 into master Jul 8, 2019
@facuspagnuolo facuspagnuolo deleted the payroll-extra-accrued-salary branch July 8, 2019 21:24
@@ -660,11 +660,14 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
// If they're being paid an amount that doesn't match perfectly with the adjusted time
// (up to a seconds' worth of salary), add the second and put the extra remaining salary
// into their accrued salary
uint256 extraSalary = currentSalaryPaid % salary;
// The extra check is to handle the case where someone requested less than one second of their salary
uint256 extraSalary = currentSalaryPaid < salary ? salary - currentSalaryPaid : currentSalaryPaid % salary;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

salary - extraSalary should go to acrued salary in case when currentSalaryPaid > salary

I think the following code should work fine, or am I missing something?

uint256 extraSalary = currentSalaryPaid % salary;
if (extraSalary > 0) {
            timeDiff = timeDiff.add(1);
            employee.accruedSalary = salary - extraSalary;
        }

Examples:

  1. Salary == 10 and you want to get currentSalaryPaid == 21.
    Time difference would be 3. Contract will transfer currentSalaryPaid == 21 and 10 - 21%10 = 9 will go to the accrued salary.
  2. Salary == 10 and you want to get currentSalaryPaid == 1.
    Time difference would be 1. Contract will transfer currentSalaryPaid == 1 and 10 - 1%10 = 9 will go to the accrued salary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... this is a good catch. I think the current state doesn't represent the

currentSalaryPaid == 21 and 10 - 21%10 = 9

case correctly; it'd put 1 into the accrued salary instead of 9.

cc @facuspagnuolo may also want to double check this, but your judgement on this simplification seems correct @Corsaire :).

Copy link
Contributor

@facuspagnuolo facuspagnuolo Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, we were close in our first attempt here haha 😅

ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants