Skip to content

Commit

Permalink
add claimRewards for AdhocVoter
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Aug 21, 2024
1 parent 33780fc commit ae39ce9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
10 changes: 9 additions & 1 deletion contracts/AdhocVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IAdhocVoter} from "./interfaces/IAdhocVoter.sol";
import {IIncentive} from "./interfaces/IIncentive.sol";
import {IGauge} from "./interfaces/IGauge.sol";
import {IGauge, IRewardGauge} from "./interfaces/IRewardGauge.sol";
import {IStrategyManager} from "./interfaces/IStrategyManager.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {ITaxGauge} from "./interfaces/ITaxGauge.sol";
Expand Down Expand Up @@ -89,6 +89,14 @@ contract AdhocVoter is IAdhocVoter, Initializable {
emit WeightChanged(_gauge, _weight);
}

function claimRewards(address[] memory _gauges) external {
address _msgSender = msg.sender;
uint256 _length = _gauges.length;
for (uint256 i = 0; i < _length; i++) {
IRewardGauge(_gauges[i]).claimReward(_msgSender);
}
}

function changeWeight(address _gauge, uint256 _weight) external {
require(_weight >= 10 && _weight <= 100, "invalid weight");
require(msg.sender == governor, "Not Governor");
Expand Down
55 changes: 55 additions & 0 deletions test/flow-adhoc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { expect } from 'chai';
import { ethers } from 'hardhat';
import { time } from "@nomicfoundation/hardhat-toolbox/network-helpers";

describe('Adhoc test flow', function () {
it('staking', async function () {
const [deployer] = await ethers.getSigners();
const forwarder = await ethers.deployContract('Forwarder');

const adhocVoter = await ethers.deployContract('AdhocVoter');
await adhocVoter.initialize();
const incentive = await ethers.deployContract('Incentives', [forwarder.target, adhocVoter.target, []]);

const deviceNFT = await ethers.deployContract('TestDeviceNFT', ['DeviceNFT', 'TestNFT']);

const taxDeviceGauge = await ethers.deployContract('TaxDeviceGauge', [
forwarder.target,
deviceNFT.target,
adhocVoter.target,
incentive.target,
]);
await adhocVoter.addGauge(taxDeviceGauge.target, incentive.target, 100);

expect(await taxDeviceGauge.totalSupply()).to.equal(0);
expect(await taxDeviceGauge.balanceOf(deployer.address)).to.equal(0);
await deviceNFT.approve(taxDeviceGauge.target, 1);
await taxDeviceGauge['deposit(uint256,address)'](1, deployer.address);
expect(await taxDeviceGauge.totalSupply()).to.equal(100);
expect(await taxDeviceGauge.balanceOf(deployer.address)).to.equal(100);

await adhocVoter.changeWeekly(ethers.parseEther('1.0'));
await adhocVoter.donate({value: ethers.parseEther('10.0')});

await time.increase(24*60*60*7);

expect(await taxDeviceGauge.earned(deployer.address)).to.equal(0);
expect(await ethers.provider.getBalance(taxDeviceGauge.target)).to.equal(0);
expect(await taxDeviceGauge.weightedBalanceOf(deployer.address)).to.equal(40);
expect(await taxDeviceGauge.userRewardPerTokenPaid(deployer.address)).to.equal(0);

await adhocVoter.changeTaxer(taxDeviceGauge.target, deployer.address);
await adhocVoter.changeTaxRatio(taxDeviceGauge.target, 20);
await adhocVoter.emitReward();

await time.increase(24*60*60*1);

expect(await taxDeviceGauge.rewardRate()).to.gt(0);
expect(await taxDeviceGauge.taxAmount(deployer.address)).to.gt(0);
expect(await taxDeviceGauge.totalWeightedBalance()).to.equal(40);
expect(await taxDeviceGauge.weightedBalanceOf(deployer.address)).to.equal(40);
expect(await taxDeviceGauge.userRewardPerTokenPaid(deployer.address)).to.equal(0);
expect(await taxDeviceGauge.earned(deployer.address)).to.gt(0);
expect(await ethers.provider.getBalance(taxDeviceGauge.target)).to.equal(ethers.parseEther('1.0'));
});
});

0 comments on commit ae39ce9

Please sign in to comment.