Skip to content

Commit

Permalink
Merge pull request #486 from DistributedCollective/fix/staking_stakeB…
Browse files Browse the repository at this point in the history
…ySchedule_cliff

Fix/staking stakeBySchedule - add check `start date <= end date`
  • Loading branch information
tjcloa authored Feb 15, 2023
2 parents 1772e37 + 488c2ae commit 4bbfe5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion contracts/governance/Staking/modules/StakingStakeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ contract StakingStakeModule is IFunctionsList, StakingShared, CheckpointsShared,
* */
uint256 start = _timestampToLockDate(block.timestamp + cliff);
uint256 end = _timestampToLockDate(block.timestamp + duration);
uint256 numIntervals = (end - start) / intervalLength + 1;
require(start <= end, "Invalid schedule");
uint256 numIntervals;
if (start < end) {
numIntervals = (end - start) / intervalLength + 1;
} else {
numIntervals = 1;
}
uint256 stakedPerInterval = amount / numIntervals;

/// @dev transferring total SOV amount before staking
Expand Down
20 changes: 20 additions & 0 deletions tests/staking/StakingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,26 @@ contract("Staking", (accounts) => {
);
});

it("should fail if start > end", async () => {
let user = accounts[0];
let cliff = new BN(TWO_WEEKS * 100); //200 weeks
let duration = new BN(TWO_WEEKS).mul(new BN(20));
let intervalLength = new BN(TWO_WEEKS).mul(new BN(2));
let lockedDate = kickoffTS.add(cliff.add(intervalLength.mul(new BN(3)))); //other staking date
let amount = new BN(1000);
await token.transfer(user, amount.mul(new BN(2)));
await token.approve(staking.address, amount.mul(new BN(2)), {
from: user,
});

await expectRevert(
staking.stakeBySchedule(amount, cliff, duration, intervalLength, user, user, {
from: user,
}),
"Invalid schedule"
);
});

//the amount staked per interval is determined by amount / number of intervals
//the number of intervals to stake for is determined as (a - b) / c, where b is the time between the lock date prior to
// or equal to block.timestamp + cliff, a is b + duration and c is intervalLength
Expand Down

0 comments on commit 4bbfe5b

Please sign in to comment.