Skip to content

Commit

Permalink
Fix unreleased rewards (#6)
Browse files Browse the repository at this point in the history
* fix unreleased rewards

* allow force sync to fix already deployed contracts

* add test to fix the rewarder

* make `forceSync` external

* update the interface
  • Loading branch information
0x0Louis authored Mar 20, 2023
1 parent 91c99b2 commit 2ee57b1
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Rewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ contract Rewarder is
_setClawbackRecipient(newRecipient);
}

/**
* @notice Force update the total unreleased rewards for the given token.
* @param token The token to update.
*/
function forceSync(IERC20Upgradeable token) external override onlyOwner {
_totalUnreleasedRewards[token] = _balanceOfNativeOrERC20(token);
}

/**
* Internal Functions
*/
Expand Down Expand Up @@ -656,6 +664,7 @@ contract Rewarder is
_released[id] = totalReleased;
unreleased = amount - totalReleased;

_totalUnreleasedRewards[token] -= amountToRelease;
_transferNativeOrERC20(token, recipient, amountToRelease);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/interface/IRewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,6 @@ interface IRewarder {
function setClawbackDelay(uint96 newClawbackDelay) external;

function setClawbackRecipient(address newClawbackRecipient) external;

function forceSync(IERC20Upgradeable token) external;
}
91 changes: 91 additions & 0 deletions test/Rewarder.UpdateArbitrum.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "../src/Rewarder.sol";
import "openzeppelin-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "openzeppelin/proxy/transparent/ProxyAdmin.sol";
import "openzeppelin/proxy/transparent/TransparentUpgradeableProxy.sol";

contract UpdateArbitrum is Test {
Rewarder public rewarder = Rewarder(payable(0x624C5b9BEB13af6893e715932c26e2b7A59c410a));
address public ms = 0xf1ec4E41B49582aF7E00D6525AF78111F37b94a8;
IERC20Upgradeable public joe = IERC20Upgradeable(0x371c7ec6D8039ff7933a2AA28EB827Ffe1F52f07);
ProxyAdmin public proxyAdmin = ProxyAdmin(0xa0BA87c58C7D09f859843256A9b87253F9a26C98);

function setUp() public {
vm.createSelectFork(stdChains["arbitrum_one"].rpcUrl);
}

function testRewarder() public {
vm.startPrank(ms);
Rewarder newImplementation = new Rewarder();

proxyAdmin.upgrade(TransparentUpgradeableProxy(payable(address(rewarder))), address(newImplementation));
rewarder.forceSync(joe);

joe.transfer(address(rewarder), 210e18);

IERC20Upgradeable[] memory tokens = new IERC20Upgradeable[](1);
tokens[0] = joe;

uint256[] memory amounts = new uint256[](1);
amounts[0] = 120e18;

rewarder.setNewEpoch(
0x7eC3717f70894F6d9BA0be00774610394Ce006eE,
1,
1_679_356_800,
1_209_600,
tokens,
amounts,
0x84c45e4957844cd1a5e0e8ad542f45cdfb8b416e7abffa297253385fc000aea0
);

amounts[0] = 40e18;
rewarder.setNewEpoch(
0xA51eE8b744E6cc1F2AC12b9eEaAE8dEB27619C6b,
1,
1_679_356_800,
1_209_600,
tokens,
amounts,
0xfc25c18e9328b995178e2040582602d9a01029c0714cdb5175dd301efa58f653
);

amounts[0] = 20e18;
rewarder.setNewEpoch(
0x5813CE0679e67dDaF0e9002939550710856C06D4,
0,
1_679_356_800,
1_209_600,
tokens,
amounts,
0x4cfedce99f1cbf821533f812d8438ccbbaf784433c81552cc70e33e8c280febf
);

amounts[0] = 20e18;
rewarder.setNewEpoch(
0xA0fd049466d57fC3637E27cA585D59E0Ad86B902,
0,
1_679_356_800,
1_209_600,
tokens,
amounts,
0x86675237ee63d1cf58b4d2f7cdec08fd19ea861783f584e85cb3c603c9c3e23b
);

amounts[0] = 10e18;
rewarder.setNewEpoch(
0x13FDa18516eAFe5e8AE930F86Fa51aE4B6C35E8F,
0,
1_679_356_800,
1_209_600,
tokens,
amounts,
0xd8d3bbd3865e6ee5f5b03141dbb79379ccb3f4e0a92c21ee18617973164f3c0e
);
vm.stopPrank();
}
}
22 changes: 22 additions & 0 deletions test/Rewarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,28 @@ contract RewarderTest is Test {
assertEq(TOKEN_B.balanceOf(BOB), 200);
assertEq(rewarder.getReleased(MARKET_A, epoch, IERC20Upgradeable(TOKEN_B), BOB), 200);
assertEq(rewarder.getReleasableAmount(MARKET_A, epoch, tokens[1], BOB, amounts[1], proof1), 0);

epoch = 1;
start = 200;
duration = 100;

tokens[0] = IERC20Upgradeable(TOKEN_A);
tokens[1] = IERC20Upgradeable(TOKEN_B);

amounts[0] = 100;
amounts[1] = 200;

leaves[0] = getLeaf(MARKET_A, epoch, start, duration, tokens[0], ALICE, amounts[0]);
leaves[1] = getLeaf(MARKET_A, epoch, start, duration, tokens[1], BOB, amounts[1]);

root = merkle.getRoot(leaves);

vm.startPrank(OWNER);
TOKEN_A.mint(address(rewarder), 100);
TOKEN_B.mint(address(rewarder), 200);

rewarder.setNewEpoch(MARKET_A, epoch, start, duration, tokens, amounts, root);
vm.stopPrank();
}

function testGetReleasableAmountWithWrongProof() public {
Expand Down

0 comments on commit 2ee57b1

Please sign in to comment.