-
Notifications
You must be signed in to change notification settings - Fork 4
feat(Rewards): add mintBatchReward #38
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
Conversation
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.
No real comments, just whitespacing (we don't need one space between every line :D) and one open question on a double for loop which might be optimizable
| uint256 batchSum = _batchSum(batch); | ||
|
|
||
| _checkedUpdateClaimed(batchSum); | ||
|
|
||
| // Safe to increment the sequence after checking this is the expected number (no overflow for the age of universe even with 1000 reward claims per second) | ||
| batchSequence = batch.sequence + 1; | ||
|
|
||
| for (uint256 i = 0; i < batch.recipients.length; i++) { | ||
| nodl.mint(batch.recipients[i], batch.amounts[i]); | ||
| } |
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.
We can avoid the double for loop here (other loop in _batchSum) by rewriting the for iteration and add one last revert statement afterwards
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 tested the potential gas saving in your suggestion and found it either absolute zero or very negligible (less than 0.1%). While checking first and minting later has the benefit of early failure (gas saving there) and follows the best practice of updating state first before calling into any other contract.
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.
Makes sense, let's keep it as is
Co-authored-by: Eliott Teissonniere <10683430+ETeissonniere@users.noreply.github.com>
In this implementation I have defined the struct BatchReward as:
assuming
recipients[i]corresponds toamounts[i]. This means we expectrecipients.length == amounts.length. That's whymintBatchRewardneeded to check this assumption. The reason I have gone for this design was to avoid using nested types which could makedigestRewardmore complicated and costly.digestRewardis needed for checking the signature.