Skip to content

Commit

Permalink
feat: test fixed reward pool v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Dec 2, 2024
1 parent d7cc636 commit 56c5d08
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 32 deletions.
13 changes: 12 additions & 1 deletion contracts/factories/IncentivesFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import {Incentives} from "../rewards/Incentive.sol";

contract IncentivesFactory is IIncentivesFactory {
/// @inheritdoc IIncentivesFactory
function createRewards(address _forwarder, address /**_pool**/) external returns (address incentiveReward) {
function createRewards(
address _forwarder,
address
)
external
returns (
/**
* _pool*
*/
address incentiveReward
)
{
incentiveReward = address(new Incentives(_forwarder, msg.sender, new address[](0)));
}
}
4 changes: 2 additions & 2 deletions contracts/gauges/FixedRewardPoolV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ pragma solidity ^0.8.0;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {MulticallUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

import {Multicall} from "../utils/Multicall.sol";
import {IWeightedNFT} from "../interfaces/IWeightedNFT.sol";

contract FixedRewardPoolV2 is Multicall, OwnableUpgradeable, ReentrancyGuardUpgradeable, ERC721Holder {
contract FixedRewardPoolV2 is MulticallUpgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable, ERC721Holder {
string public constant GAUGE_TYPE = "gauge_fixed_reward_pool";
string public constant GAUGE_VERSION = "0.2.0";

Expand Down
24 changes: 0 additions & 24 deletions contracts/utils/Multicall.sol

This file was deleted.

54 changes: 54 additions & 0 deletions test/FixedRewardPoolV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,58 @@ contract TestFixedRewardPoolV2 is Test {
fixedRewardPool.withdraw(3);
assertEq(alice.balance, 0.075 ether);
}

function testCycle() public {
testNFT.mint(bob, 1);
testNFT.mint(bob, 2);
testNFT.mint(bob, 3);
testNFT.mint(bob, 4);

vm.startPrank(bob);
vm.roll(15);
testNFT.approve(address(fixedRewardPool), 1);
fixedRewardPool.deposit(1);

vm.roll(20);
assertEq(bob.balance, 0);
fixedRewardPool.withdraw(1);
assertEq(bob.balance, 0);
testNFT.approve(address(fixedRewardPool), 1);
fixedRewardPool.deposit(1);
vm.stopPrank();

bytes[] memory _calldata = new bytes[](2);
_calldata[0] = abi.encodeCall(FixedRewardPoolV2.updateRewardPerBlock, (0.2 ether));
_calldata[1] = abi.encodeCall(FixedRewardPoolV2.updateBonusEndBlock, (30));
fixedRewardPool.multicall(_calldata);

assertEq(fixedRewardPool.rewardPerBlock(), 0.2 ether);
assertEq(fixedRewardPool.lastRewardBlock(), 20);
assertEq(fixedRewardPool.bonusEndBlock(), 30);

payable(address(fixedRewardPool)).transfer(2 ether);

vm.roll(21);
assertEq(bob.balance, 0);
assertEq(fixedRewardPool.pendingReward(bob), 0.2 ether);
fixedRewardPool.claimRewards(bob);
assertEq(bob.balance, 0.2 ether);

fixedRewardPool.updateRewardPerBlock(0.1 ether);
assertEq(fixedRewardPool.pendingReward(bob), 0);
fixedRewardPool.claimRewards(bob);
assertEq(bob.balance, 0.2 ether);

vm.roll(25);
assertEq(fixedRewardPool.pendingReward(bob), 0.4 ether);
fixedRewardPool.claimRewards(bob);
assertEq(bob.balance, 0.6 ether);

fixedRewardPool.updateRewardPerBlock(0.2 ether);

vm.roll(30);
vm.prank(bob);
fixedRewardPool.withdraw(1);
assertEq(bob.balance, 1.6 ether);
}
}
28 changes: 23 additions & 5 deletions test/TestIncentive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,29 @@ contract TestIncentive is Test {
Incentives public dinti;

function onERC721Received(
address /**operator**/,
address /**from**/,
uint256 /**tokenId**/,
bytes calldata /**data**/
) external pure returns (bytes4) {
address,
/**
* operator*
*/
address,
/**
* from*
*/
uint256,
/**
* tokenId*
*/
bytes calldata
)
external
pure
returns (
/**
* data*
*/
bytes4
)
{
return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
}

Expand Down

0 comments on commit 56c5d08

Please sign in to comment.