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

fix rewarder for float rounding issue #7

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Rewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,18 @@ contract Rewarder is

if (amountToRelease > 0) {
EnumerableMapUpgradeable.AddressToUintMap storage map = _totalRewardsPerEpoch[market][epoch];
map.set(address(token), map.get(address(token)) - amountToRelease);

uint256 totalReleased = released + amountToRelease;
uint256 totalAmount = map.get(address(token));
amountToRelease = amountToRelease > totalAmount ? totalAmount : amountToRelease;

_released[id] = totalReleased;
unreleased = amount - totalReleased;
map.set(address(token), totalAmount - amountToRelease);

{
uint256 totalReleased = released + amountToRelease;

_released[id] = totalReleased;
unreleased = totalAmount == amountToRelease ? 0 : amount - totalReleased;
}

_totalUnreleasedRewards[token] -= amountToRelease;
_transferNativeOrERC20(token, recipient, amountToRelease);
Expand Down
2 changes: 1 addition & 1 deletion test/Rewarder.UpdateArbitrum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract UpdateArbitrum is Test {
ProxyAdmin public proxyAdmin = ProxyAdmin(0xa0BA87c58C7D09f859843256A9b87253F9a26C98);

function setUp() public {
vm.createSelectFork(stdChains["arbitrum_one"].rpcUrl);
vm.createSelectFork("https://rpc.ankr.com/arbitrum", 71_910_974);
}

function testRewarder() public {
Expand Down
15 changes: 13 additions & 2 deletions test/Rewarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import "../src/Rewarder.sol";
import "./mocks/MockERC20.sol";

contract RewarderTest is Test {
event RewardClaimed(
address indexed user,
address indexed market,
IERC20Upgradeable indexed token,
uint256 epoch,
uint256 released,
uint256 unreleased
);

Merkle public merkle;

Rewarder public implementation;
Expand Down Expand Up @@ -1423,11 +1432,13 @@ contract RewarderTest is Test {

vm.warp(start + duration);

vm.expectRevert();
vm.expectEmit(true, true, true, true);
emit RewardClaimed(ALICE, MARKET_A, IERC20Upgradeable(address(TOKEN_A)), epoch, 99, 0);
vm.prank(ALICE);
rewarder.claim(MARKET_A, epoch, IERC20Upgradeable(address(TOKEN_A)), 100, proof0);

vm.expectRevert();
vm.expectEmit(true, true, true, true);
emit RewardClaimed(BOB, MARKET_A, IERC20Upgradeable(address(TOKEN_B)), epoch, 199, 0);
vm.prank(BOB);
rewarder.claim(MARKET_A, epoch, IERC20Upgradeable(address(TOKEN_B)), 200, proof1);
}
Expand Down
Loading