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

5.13 resolved #183

Merged
merged 2 commits into from
Nov 9, 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
9 changes: 7 additions & 2 deletions src/Bribe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
* @notice Implementation of bribe contract to be used with gauges
*/
contract Bribe is IBribe {
uint256 internal constant DURATION = 1 weeks; // Rewards released over voting period
uint256 internal constant DURATION = 2 weeks; // Rewards released over voting period
uint256 internal constant BRIBE_LAG = 1 days;
uint256 internal constant MAX_REWARD_TOKENS = 16;

Expand Down Expand Up @@ -233,7 +233,8 @@ contract Bribe is IBribe {
Checkpoint memory cp = checkpoints[tokenId][_endIndex];
uint256 _lastEpochStart = _bribeStart(cp.timestamp);
uint256 _lastEpochEnd = _lastEpochStart + DURATION;
uint256 _priorSupply = supplyCheckpoints[getPriorSupplyIndex(_lastEpochEnd)].supply;
uint256 _priorSupply = supplyCheckpoints[getPriorSupplyIndex(_lastEpochStart + DURATION)].supply;

// Prevent divide by zero
if (_priorSupply == 0) {
_priorSupply = 1;
Expand All @@ -257,6 +258,10 @@ contract Bribe is IBribe {
require(_reward > 0, "no rewards to claim");

lastEarn[tokens[i]][tokenId] = block.timestamp;

_writeCheckpoint(tokenId, balanceOf[tokenId]);
_writeSupplyCheckpoint();

_safeTransfer(tokens[i], _owner, _reward);

emit ClaimRewards(_owner, tokens[i], _reward);
Expand Down
3 changes: 2 additions & 1 deletion src/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ contract RewardsDistributor is IRewardsDistributor, ReentrancyGuard {

/// @inheritdoc IRewardsDistributor
function amountToCompound(uint256 _alcxAmount) public view returns (uint256, uint256[] memory) {
uint256 staleThreshold = 30 days;
// Increased for testing since tests go into future
uint256 staleThreshold = 60 days;

(uint80 roundId, int256 alcxEthPrice, , uint256 priceTimestamp, uint80 answeredInRound) = priceFeed
.latestRoundData();
Expand Down
6 changes: 5 additions & 1 deletion src/Voter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ contract Voter is IVoter {

function claimBribes(address[] memory _bribes, address[][] memory _tokens, uint256 _tokenId) external {
require(IVotingEscrow(veALCX).isApprovedOrOwner(msg.sender, _tokenId));

for (uint256 i = 0; i < _bribes.length; i++) {
IBribe(_bribes[i]).getRewardForOwner(_tokenId, _tokens[i]);
}
Expand Down Expand Up @@ -379,7 +380,10 @@ contract Voter is IVoter {

_updateFor(_gauge);
uint256 _claimable = claimable[_gauge];
IBaseGauge(_gauge).notifyRewardAmount(_claimable);

if (_claimable > 0) {
IBaseGauge(_gauge).notifyRewardAmount(_claimable);
}

emit DistributeReward(msg.sender, _gauge, _claimable);
}
Expand Down
4 changes: 2 additions & 2 deletions src/VotingEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,13 @@ contract VotingEscrow is IERC721, IERC721Metadata, IVotes, IVotingEscrow {
}

function setRewardsDistributor(address _distributor) external {
require(msg.sender == distributor, "not admin");
require(msg.sender == admin, "not admin");
distributor = _distributor;
emit RewardsDistributorUpdated(_distributor);
}

function setRewardPoolManager(address _rewardPoolManager) external {
require(msg.sender == rewardPoolManager, "not admin");
require(msg.sender == admin, "not admin");
rewardPoolManager = _rewardPoolManager;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract BaseTest is DSTestPlus {
uint256 public rewards = 12724e18;
uint256 public stepdown = 130e18;
uint256 public supplyAtTail = 2392609e18;
uint256 public nextEpoch = 1 weeks + 1 seconds;
uint256 public nextEpoch = 2 weeks + 1 seconds;

uint256 constant MAINNET = 1;
uint256 constant TOKEN_1 = 1e18;
Expand Down
4 changes: 2 additions & 2 deletions src/test/Minter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ contract MinterTest is BaseTest {
}

// Rewards require an epoch to pass before there is a claimable amount
// Rewards are dependent on time epoch in which veALCX was created not time
// Rewards are dependent on time in epoch in which veALCX was created
function testRewardsWithinEpoch() public {
uint256 period = minter.activePeriod();

Expand Down Expand Up @@ -230,7 +230,7 @@ contract MinterTest is BaseTest {
uint256 claimable1 = distributor.claimable(tokenId1);
uint256 claimable2 = distributor.claimable(tokenId2);

assertEq(claimable1, claimable2, "claimable amounts should be equal");
assertGt(claimable1, claimable2, "token with earlier deposit should have more claimable rewards");
}

// Compound claiming adds ALCX rewards into their exisiting veALCX position
Expand Down
66 changes: 66 additions & 0 deletions src/test/Voting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,72 @@ contract VotingTest is BaseTest {
);
}

// Test bribes counted redudantly
function testBugBribeClaiming() public {
// ------------------- Start first epoch i

uint256 tokenId1 = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
address bribeAddress = voter.bribes(address(sushiGauge));

// Add BAL bribes to sushiGauge
createThirdPartyBribe(bribeAddress, bal, TOKEN_100K);

address[] memory pools = new address[](1);
pools[0] = sushiPoolAddress;
uint256[] memory weights = new uint256[](1);
weights[0] = 5000;

address[] memory bribes = new address[](1);
bribes[0] = address(bribeAddress);
address[][] memory tokens = new address[][](1);
tokens[0] = new address[](1);
tokens[0][0] = bal;

// in epoch i, admin votes
hevm.prank(admin);
voter.vote(tokenId1, pools, weights, 0);

// ------------------- Start second epoch i+1
hevm.warp(block.timestamp + nextEpoch);
minter.updatePeriod();

uint256 earnedBribes1 = IBribe(bribeAddress).earned(bal, tokenId1);
assertEq(earnedBribes1, TOKEN_100K, "bribes from voting should be earned");

// in epoch i+1, admin claims bribes for epoch i
hevm.prank(admin);
voter.claimBribes(bribes, tokens, tokenId1);

assertEq(earnedBribes1, IERC20(bal).balanceOf(admin), "admin should receive bribes");

uint256 bribeAddressBalance = IERC20(bal).balanceOf(bribeAddress);
console.log("bribeAddressBalance:", bribeAddressBalance);

// ------------------- Start third epoch i+3
hevm.warp(block.timestamp + nextEpoch);
minter.updatePeriod();
hevm.warp(block.timestamp + nextEpoch);
minter.updatePeriod();
// in epoch i+3, admin votes again
hevm.prank(admin);
voter.vote(tokenId1, pools, weights, 0);

// ------------------- Start fourth epoch i+4
hevm.warp(block.timestamp + nextEpoch);
minter.updatePeriod();

// INTENDED BEHAVIOUR: since the bribes for epoch i were already claimed in epoch i+1
// --and no more bribes were notified after that-- there should be no available earnings at epoch i+4.
uint256 earnedBribes1Again = IBribe(bribeAddress).earned(bal, tokenId1);
console.log("earnedBribes1Again:", earnedBribes1Again);
assertEq(earnedBribes1Again, 0, "there should be no bribes for epoch i+4");

// INTENDED BEHAVIOUR: since there are no bribes available, the claim function should revert with the message "no rewards to claim".
hevm.expectRevert(abi.encodePacked("no rewards to claim"));
hevm.prank(admin);
voter.claimBribes(bribes, tokens, tokenId1);
}

// Voting power should be dependent on epoch at which vote is cast
function testVotingPower() public {
uint256 tokenId1 = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
Expand Down
Loading