-
Notifications
You must be signed in to change notification settings - Fork 212
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: revert to old way of obtaining exchange rate and add more clarity #821
Payroll: revert to old way of obtaining exchange rate and add more clarity #821
Conversation
// and applied allocation percentage | ||
uint256 tokenAmount = _totalAmount.mul(exchangeRate).mul(tokenAllocation); | ||
// Divide by 100 for the allocation and by ONE for the exchange rate precision | ||
tokenAmount = tokenAmount / (100 * ONE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding all these comments :)
@@ -12,6 +12,11 @@ module.exports = (artifacts, web3) => { | |||
const DAI_RATE = formatRate(1) // 1 DAI = 1 USD | |||
const ANT_RATE = formatRate(0.5) // 1 ANT = 0.5 USD | |||
|
|||
function exchangedAmount(amount, rate, tokenAllocation) { | |||
// Mimic EVM calculation and truncation for token conversion | |||
return amount.mul(rate).mul(inverseRate).div(ONE.div(100)).trunc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think inverseRate
is not declared, shouldn't it be tokenAllocation
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ forgot to push. It's here now: 2795a19
7ede1b4
to
2795a19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
// and applied allocation percentage | ||
uint256 tokenAmount = _totalAmount.mul(exchangeRate).mul(tokenAllocation); | ||
// Divide by 100 for the allocation and by ONE for the exchange rate precision | ||
tokenAmount = tokenAmount / (100 * ONE); | ||
|
||
finance.newImmediatePayment(token, employeeAddress, tokenAmount, paymentReference); | ||
emit SendPayment(employeeAddress, token, tokenAmount, paymentReference); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we are at it let's log the exchange rate used as it would be really helpful if we ever need to debug something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry, I haven't forgot 😉. Will do in another PR.
Reverts to the old way of calculating the payment amount and tries to make it more obvious.