Skip to content

Commit

Permalink
check rewardDepositors amount is not too big (#66)
Browse files Browse the repository at this point in the history
* check the amount is not too big

* MINIMUM_DEPOSIT
  • Loading branch information
orenyodfat authored Jul 29, 2021
1 parent 9d5cf96 commit c91b0be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 0 additions & 1 deletion contracts/HATMaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ contract HATMaster is ReentrancyGuard {
}
}
if (_amount > 0) {
require(_amount >= 1e6, "amount less than 1e6");
uint256 lpSupply = pool.balance;
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
pool.balance = pool.balance.add(_amount);
Expand Down
5 changes: 4 additions & 1 deletion contracts/HATVaults.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contract HATVaults is Governable, HATMaster {
uint256 internal constant REWARDS_LEVEL_DENOMINATOR = 10000;
ITokenLockFactory public immutable tokenLockFactory;
ISwapRouter public immutable uniSwapRouter;
uint256 public constant MINIMUM_DEPOSIT = 1e6;

modifier onlyCommittee(uint256 _pid) {
require(committees[_pid] == msg.sender, "only committee");
Expand Down Expand Up @@ -287,7 +288,8 @@ contract HATVaults is Governable, HATMaster {
* @param _amount amount to add
*/
function rewardDepositors(uint256 _pid, uint256 _amount) external {
require(poolInfo[_pid].totalUsersAmount > 0, "no depositors to reward");
require(poolInfo[_pid].balance.add(_amount).div(MINIMUM_DEPOSIT) < poolInfo[_pid].totalUsersAmount,
"amount to reward is too big");
poolInfo[_pid].lpToken.safeTransferFrom(msg.sender, address(this), _amount);
poolInfo[_pid].balance = poolInfo[_pid].balance.add(_amount);
emit RewardDepositors(_pid, _amount);
Expand Down Expand Up @@ -601,6 +603,7 @@ contract HATVaults is Governable, HATMaster {
**/
function deposit(uint256 _pid, uint256 _amount) external {
require(!poolDepositPause[_pid], "deposit paused");
require(_amount >= MINIMUM_DEPOSIT, "amount less than 1e6");
//clear withdraw request
withdrawRequests[_pid][msg.sender] = 0;
_deposit(_pid, _amount);
Expand Down
25 changes: 19 additions & 6 deletions test/hatvaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ contract('HatVaults', accounts => {
}
await utils.mineBlock();
var tx = await hatVaults.massUpdatePools(0,18);
assert.equal(tx.receipt.gasUsed, 1517872);
assert.equal(tx.receipt.gasUsed, 1517939);
}).timeout(40000);


Expand Down Expand Up @@ -1943,7 +1943,7 @@ contract('HatVaults', accounts => {
// assert.equal(localEvents[0].returnValues.amount*2,localEvents[1].returnValues.amount);
// assert.equal(await hatToken.balanceOf(poolManagerMock.address),localEvents[0].returnValues.amount*3);
// });
//


it("add/set pool on the same block", async () => {
let hatToken1 = await HATTokenMock.new(accounts[0],utils.TIME_LOCK_DELAY);
Expand Down Expand Up @@ -2051,19 +2051,23 @@ contract('HatVaults', accounts => {
await setup(accounts);
var staker = accounts[1];
var staker2 = accounts[5];
var rewarder = accounts[6];

await stakingToken.approve(hatVaults.address,web3.utils.toWei("3000000"),{from:rewarder});
await stakingToken.approve(hatVaults.address,web3.utils.toWei("4"),{from:staker});
await stakingToken.approve(hatVaults.address,web3.utils.toWei("2"),{from:staker2});

await stakingToken.mint(staker,web3.utils.toWei("4"));
await stakingToken.mint(rewarder,web3.utils.toWei("3000000"));
await stakingToken.mint(staker,web3.utils.toWei("1"));
await stakingToken.mint(staker2,web3.utils.toWei("2"));

assert.equal(await stakingToken.balanceOf(staker), web3.utils.toWei("4"));
assert.equal(await stakingToken.balanceOf(staker), web3.utils.toWei("1"));
assert.equal(await hatToken.balanceOf(hatVaults.address), 0);
try {
await hatVaults.rewardDepositors(0,web3.utils.toWei("3"),{from:staker});
await hatVaults.rewardDepositors(0,web3.utils.toWei("3"),{from:rewarder});
assert(false, 'no depositors yet');
} catch (ex) {
assert(ex.message.includes("amount to reward is too big"));
assertVMException(ex);
}
await hatVaults.deposit(0,web3.utils.toWei("1"),{from:staker});
Expand All @@ -2077,7 +2081,16 @@ contract('HatVaults', accounts => {
await hatVaults.withdrawRequest(0,{from:staker2});

await utils.increaseTime(7*24*3600);
var tx = await hatVaults.rewardDepositors(0,web3.utils.toWei("3"),{from:staker});

try {
await hatVaults.rewardDepositors(0,web3.utils.toWei("3000000"),{from:rewarder});
assert(false, 'amount to reward is too big');
} catch (ex) {
assert(ex.message.includes("amount to reward is too big"));
assertVMException(ex);
}

var tx = await hatVaults.rewardDepositors(0,web3.utils.toWei("3"),{from:rewarder});
assert.equal(tx.logs[0].event,"RewardDepositors");
assert.equal(tx.logs[0].args._pid,0);
assert.equal(tx.logs[0].args._amount,web3.utils.toWei("3"));
Expand Down

0 comments on commit c91b0be

Please sign in to comment.