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: clarify how rates are handled and add unit tests #823

Merged
merged 6 commits into from
Apr 27, 2019

Conversation

facuspagnuolo
Copy link
Contributor

@facuspagnuolo facuspagnuolo commented Apr 25, 2019

Adding unit tests to ensure how rates handling in payroll (cc #821). I also rolled back the last change we did to the PPF request to confirm it was working properly.

@coveralls
Copy link

coveralls commented Apr 25, 2019

Coverage Status

Coverage remained the same at 97.015% when pulling 5a6570a on payroll_rates_handling_tests into 5f190c5 on master.

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

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

🙇

future-apps/payroll/test/contracts/Payroll_rates.test.js Outdated Show resolved Hide resolved
future-apps/payroll/test/contracts/Payroll_rates.test.js Outdated Show resolved Hide resolved
@facuspagnuolo facuspagnuolo force-pushed the payroll_rates_handling_tests branch from 32e1487 to a9f3a07 Compare April 26, 2019 06:39
@facuspagnuolo
Copy link
Contributor Author

@izqui @sohkai as you can see in a9f3a07, I changed transfer amount formula we were using in the contract. I think the previous one was wrong, and that's why using an inverse rate was working fine. The amount to be transferred must be in the allowed token units [AT], the owed amount is in denomination token units [DT], and the rate is fetched using the denomination token as the quote which is in [DT/AT], then we should divide the owed amount by the rate instead of multiplying it.

Besides that, I did some more tweaks to change all the test suite to use a real denomination token (USD) with real salaries amount.

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

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

I think the previous one was wrong, and that's why using an inverse rate was working fine. The amount to be transferred must be in the allowed token units [AT], the owed amount is in denomination token units [DT], and the rate is fetched using the denomination token as the quote which is in [DT/AT], then we should divide the owed amount by the rate instead of multiplying it.

Hmm, I think this might've been due to the original change being reverted in 4a0f4b3#diff-9d7adaffbcce19867f027a983a30bcc7R668. This change to _getExchangeRate() basically does the division for us, in the price feed (if the price feed's base token isn't the denomination token).

I think I still prefer _totalAmount.mul(exchangeRate).mul(tokenAllocation) (and its associated change in _getExchangeRate()) for clarity. Depending on the price feed, it can also be a little bit more accurate, since the truncations all happen at the end (if the base token in the price feed is the denomination token).


To illustrate, previously (with the change to _getExchangeRate()) we had:

owedAmount [DT] * rate [AT/DT] / (ONE) * (allocation / 100) == payment [AT]

Now we have:

owedAmount [DT] / rate [DT/AT] * (ONE) * (allocation / 100) == payment [AT]

It's subtle, but the first case with multiplication is a lot more clear to me.

@facuspagnuolo
Copy link
Contributor Author

facuspagnuolo commented Apr 26, 2019

It's subtle, but the first case with multiplication is a lot more clear to me.

It is and it was to me, but I thought we were also really sure that the PPF was always being used using the denomination token as quote.

@sohkai sohkai changed the title Payroll: Add rates handling unit tests Payroll: clarify how rates are handled and add unit tests Apr 27, 2019
@sohkai sohkai merged commit 327abd6 into master Apr 27, 2019
@sohkai sohkai deleted the payroll_rates_handling_tests branch April 27, 2019 05:55
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