Skip to content

Commit

Permalink
chore: Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dgusakov committed Jan 13, 2025
1 parent b3c1045 commit 0f1877b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/CSPerksRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ contract CSPerksRegistry is
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (keyPivots.length + 1 != rewardShares.length)
revert InvalidRewardShareData();
if (keyPivots.length > 0 && keyPivots[0] == 0)
revert InvalidRewardShareData();
if (keyPivots.length > 1) {
for (uint256 i = 0; i < keyPivots.length - 1; ++i) {
if (keyPivots[i] >= keyPivots[i + 1])
Expand Down Expand Up @@ -78,15 +80,18 @@ contract CSPerksRegistry is
uint256[] calldata performanceLeeways
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (keyPivots.length + 1 != performanceLeeways.length)
revert InvalidRewardShareData();
revert InvalidPerformanceLeewayData();
if (keyPivots.length > 0 && keyPivots[0] == 0)
revert InvalidPerformanceLeewayData();
if (keyPivots.length > 1) {
for (uint256 i = 0; i < keyPivots.length - 1; ++i) {
if (keyPivots[i] >= keyPivots[i + 1])
revert InvalidRewardShareData();
revert InvalidPerformanceLeewayData();
}
}
for (uint256 i = 0; i < performanceLeeways.length; ++i) {
if (performanceLeeways[i] > MAX_BP) revert InvalidRewardShareData();
if (performanceLeeways[i] > MAX_BP)
revert InvalidPerformanceLeewayData();
}
_performanceLeewayPivotsData[curveId] = keyPivots;
_performanceLeewayValuesData[curveId] = performanceLeeways;
Expand Down
44 changes: 41 additions & 3 deletions test/CSPerksRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ contract CSPerksRegistryRewardShareDataTest is CSPerksRegistryBaseTest {
PerksRegistry.setRewardShareData(curveId, keyPivots, rewardShares);
}

function test_setRewardShareData_RevertWhen_first_pivot_is_zero() public {
uint256 curveId = 1;
uint256[] memory keyPivots = new uint256[](2);
keyPivots[0] = 0;
keyPivots[1] = 10;

uint256[] memory rewardShares = new uint256[](3);
rewardShares[0] = 10000;
rewardShares[1] = 8000;
rewardShares[2] = 5000;

vm.expectRevert(ICSPerksRegistry.InvalidRewardShareData.selector);
vm.prank(admin);
PerksRegistry.setRewardShareData(curveId, keyPivots, rewardShares);
}

function test_setRewardShareData_RevertWhen_invalid_bp_values() public {
uint256 curveId = 1;
uint256[] memory keyPivots = new uint256[](1);
Expand Down Expand Up @@ -250,7 +266,7 @@ contract CSPerksRegistryPerformanceLeewayDataTest is CSPerksRegistryBaseTest {
performanceLeeways[0] = 500;
performanceLeeways[1] = 400;

vm.expectRevert(ICSPerksRegistry.InvalidRewardShareData.selector);
vm.expectRevert(ICSPerksRegistry.InvalidPerformanceLeewayData.selector);
vm.prank(admin);
PerksRegistry.setPerformanceLeewayData(
curveId,
Expand All @@ -272,7 +288,29 @@ contract CSPerksRegistryPerformanceLeewayDataTest is CSPerksRegistryBaseTest {
performanceLeeways[1] = 400;
performanceLeeways[2] = 300;

vm.expectRevert(ICSPerksRegistry.InvalidRewardShareData.selector);
vm.expectRevert(ICSPerksRegistry.InvalidPerformanceLeewayData.selector);
vm.prank(admin);
PerksRegistry.setPerformanceLeewayData(
curveId,
keyPivots,
performanceLeeways
);
}

function test_setPerformanceLeewayData_RevertWhen_first_pivot_is_zero()
public
{
uint256 curveId = 1;
uint256[] memory keyPivots = new uint256[](2);
keyPivots[0] = 0;
keyPivots[1] = 10;

uint256[] memory performanceLeeways = new uint256[](3);
performanceLeeways[0] = 500;
performanceLeeways[1] = 400;
performanceLeeways[2] = 300;

vm.expectRevert(ICSPerksRegistry.InvalidPerformanceLeewayData.selector);
vm.prank(admin);
PerksRegistry.setPerformanceLeewayData(
curveId,
Expand All @@ -292,7 +330,7 @@ contract CSPerksRegistryPerformanceLeewayDataTest is CSPerksRegistryBaseTest {
performanceLeeways[0] = 50000;
performanceLeeways[1] = 400;

vm.expectRevert(ICSPerksRegistry.InvalidRewardShareData.selector);
vm.expectRevert(ICSPerksRegistry.InvalidPerformanceLeewayData.selector);
vm.prank(admin);
PerksRegistry.setPerformanceLeewayData(
curveId,
Expand Down

0 comments on commit 0f1877b

Please sign in to comment.