Skip to content

Commit

Permalink
fix: period lte to max (#387)
Browse files Browse the repository at this point in the history
### Description

fix for [L-2] Minimum values for `cliff` and `slope` periods cannot be
set to match max amounts after deployment

### Related issue

- Fixes #379
  • Loading branch information
baroooo authored Mar 4, 2024
1 parent 472a1d9 commit 1e60cb8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contracts/governance/locking/LockingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
}

function setMinCliffPeriod(uint32 newMinCliffPeriod) external notStopped notMigrating onlyOwner {
require(newMinCliffPeriod < MAX_CLIFF_PERIOD, "new cliff period > 2 years");
require(newMinCliffPeriod <= MAX_CLIFF_PERIOD, "new cliff period > 2 years");
minCliffPeriod = newMinCliffPeriod;

emit SetMinCliffPeriod(newMinCliffPeriod);
}

function setMinSlopePeriod(uint32 newMinSlopePeriod) external notStopped notMigrating onlyOwner {
require(newMinSlopePeriod < MAX_SLOPE_PERIOD, "new slope period > 2 years");
require(newMinSlopePeriod <= MAX_SLOPE_PERIOD, "new slope period > 2 years");
minSlopePeriod = newMinSlopePeriod;

emit SetMinSlopePeriod(newMinSlopePeriod);
Expand Down
46 changes: 46 additions & 0 deletions test/governance/Locking/locking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,50 @@ contract Lock_Locking_Test is Locking_Test {
vm.expectRevert("Ownable: caller is not the owner");
locking.startMigration(address(1));
}

function test_setMinCliffPeriod_setMinSlope_whenNotOwner_shouldRevert() public {
vm.expectRevert("Ownable: caller is not the owner");
locking.setMinCliffPeriod(3);

vm.expectRevert("Ownable: caller is not the owner");
locking.setMinSlopePeriod(3);
}

function test_setMinCliffPeriod_setMinSlope_whenExceedsMax_shouldRevert() public {
vm.prank(owner);
vm.expectRevert("new cliff period > 2 years");
locking.setMinCliffPeriod(104);

vm.prank(owner);
vm.expectRevert("new slope period > 2 years");
locking.setMinSlopePeriod(105);
}

function test_setMinCliffPeriod_shouldSetCliff() public {
vm.prank(owner);
locking.setMinCliffPeriod(5);
assertEq(locking.minCliffPeriod(), 5);

vm.prank(owner);
locking.setMinCliffPeriod(103);
assertEq(locking.minCliffPeriod(), 103);

vm.prank(owner);
locking.setMinCliffPeriod(0);
assertEq(locking.minCliffPeriod(), 0);
}

function test_setMinSlopePeriod_shouldSetSlope() public {
vm.prank(owner);
locking.setMinSlopePeriod(5);
assertEq(locking.minSlopePeriod(), 5);

vm.prank(owner);
locking.setMinSlopePeriod(104);
assertEq(locking.minSlopePeriod(), 104);

vm.prank(owner);
locking.setMinSlopePeriod(1);
assertEq(locking.minSlopePeriod(), 1);
}
}

0 comments on commit 1e60cb8

Please sign in to comment.