Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Zied Guesmi <[email protected]>
  • Loading branch information
jeremyjams and zguesmi authored Jun 11, 2024
1 parent 20e0916 commit ae75ec5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## vNEXT
- Update requester/voucher debits to refund on claims amounts divisible by volume. (#28)
- Make sponsored & non-sponsored amounts always divisible by deal volume to refund tasks fairly. (#28)
- Add slither suggestions. (#26)
- Drain expired vouchers and withdraw funds. (#25)
- Add slither github action. (#24)
Expand Down
2 changes: 1 addition & 1 deletion contracts/VoucherHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ contract VoucherHub is
}
sponsoredAmount = Math.min(balanceOf(msg.sender), sponsoredAmount * volume);
// Decrease sponsored amount to make sponsored & non-sponsored amounts
// divisible by volume in order to refund plain amounts to voucher and
// are divisible by volume in order to refund plain amounts to voucher and
// requester (i.e. make sure there are no hidden remainders) in the event
// that tasks are claimed later.
sponsoredAmount -= sponsoredAmount % volume;
Expand Down
1 change: 1 addition & 0 deletions contracts/beacon/Voucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ contract Voucher is Initializable, IVoucher {
$._refundedTasks[taskId] = true;
if (taskPrice != 0) {
uint256 dealSponsoredAmount = $._sponsoredAmounts[dealId];
// The division leaves no remainder. See VoucherHub#debitVoucher().
uint256 taskSponsoredAmount = dealSponsoredAmount / dealVolume;
if (taskSponsoredAmount != 0) {
// If the voucher did fully/partially sponsor the deal then mint voucher
Expand Down
8 changes: 4 additions & 4 deletions test/beacon/Voucher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,11 @@ describe('Voucher', function () {
order.volume = volume;
}
const dealPrice = taskPrice * volume;
let dealSponsoredAmount = dealPrice > voucherValue ? voucherValue : dealPrice;
// Make sure dealSponsoredAmount will need to be reduced to be divisible by volume
expect(dealSponsoredAmount % volume).greaterThan(0);
let dealSponsorableAmount = voucherValue; // dealPrice > voucherValue
// Make sure dealSponsorableAmount is not divisible by volume
expect(dealSponsorableAmount % volume).greaterThan(0);
// Remove remainder to get expected dealSponsoredAmount
dealSponsoredAmount -= dealSponsoredAmount % volume;
let dealSponsoredAmount -= dealSponsorableAmount % volume;
const dealNonSponsoredAmount = dealPrice - dealSponsoredAmount;
expect(dealSponsoredAmount % volume).equal(0); // Both amounts should be
expect(dealNonSponsoredAmount % volume).equal(0); // divisible by volume
Expand Down

0 comments on commit ae75ec5

Please sign in to comment.