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

Projects
None yet
4 participants
@sohkai
Copy link
Member

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

This comment has been minimized.

Copy link

commented Jul 8, 2019

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

5 of 6 checks passed

License Compliance 1 issues found
Details
Travis CI - Branch Build Passed
Details
Travis CI - Pull Request Build Passed
Details
WIP Ready for review
Details
coverage/coveralls Coverage remained the same at 97.732%
Details
license/cla Contributor License Agreement is signed.
Details

@facuspagnuolo facuspagnuolo deleted the payroll-extra-accrued-salary branch Jul 8, 2019

@@ -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;

This comment has been minimized.

Copy link
@Corsaire

Corsaire Jul 14, 2019

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.

This comment has been minimized.

Copy link
@sohkai

sohkai Jul 14, 2019

Author Member

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 :).

This comment has been minimized.

Copy link
@facuspagnuolo

facuspagnuolo Jul 15, 2019

Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.