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

Fix/staking stakeBySchedule-cliff #486

Merged
merged 5 commits into from
Feb 15, 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
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