-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from euler-xyz/fix/adjustAllocationPoints
Fix adjustAllocationPoints() and test allocation state management
- Loading branch information
Showing
3 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
import {FourSixTwoSixAggBase, FourSixTwoSixAgg} from "../common/FourSixTwoSixAggBase.t.sol"; | ||
|
||
contract AdjustAllocationsPointsFuzzTest is FourSixTwoSixAggBase { | ||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
uint256 initialStrategyAllocationPoints = 500e18; | ||
_addStrategy(manager, address(eTST), initialStrategyAllocationPoints); | ||
} | ||
|
||
function testFuzzAdjustAllocationPoints(uint256 _newAllocationPoints) public { | ||
_newAllocationPoints = bound(_newAllocationPoints, 0, type(uint120).max); | ||
|
||
uint256 strategyAllocationPoints = (fourSixTwoSixAgg.getStrategy(address(eTST))).allocationPoints; | ||
uint256 totalAllocationPointsBefore = fourSixTwoSixAgg.totalAllocationPoints(); | ||
uint256 withdrawalQueueLengthBefore = fourSixTwoSixAgg.withdrawalQueueLength(); | ||
|
||
vm.prank(manager); | ||
fourSixTwoSixAgg.adjustAllocationPoints(address(eTST), _newAllocationPoints); | ||
|
||
FourSixTwoSixAgg.Strategy memory strategy = fourSixTwoSixAgg.getStrategy(address(eTST)); | ||
|
||
if (_newAllocationPoints < strategyAllocationPoints) { | ||
assertEq( | ||
fourSixTwoSixAgg.totalAllocationPoints(), | ||
totalAllocationPointsBefore - (strategyAllocationPoints - _newAllocationPoints) | ||
); | ||
} else { | ||
assertEq( | ||
fourSixTwoSixAgg.totalAllocationPoints(), | ||
totalAllocationPointsBefore + (_newAllocationPoints - strategyAllocationPoints) | ||
); | ||
} | ||
assertEq(fourSixTwoSixAgg.withdrawalQueueLength(), withdrawalQueueLengthBefore); | ||
assertEq(strategy.allocationPoints, _newAllocationPoints); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
import {FourSixTwoSixAggBase, FourSixTwoSixAgg} from "../common/FourSixTwoSixAggBase.t.sol"; | ||
|
||
contract AdjustAllocationsPointsTest is FourSixTwoSixAggBase { | ||
uint256 initialStrategyAllocationPoints = 500e18; | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
_addStrategy(manager, address(eTST), initialStrategyAllocationPoints); | ||
} | ||
|
||
function testAdjustAllocationPoints() public { | ||
uint256 newAllocationPoints = 859e18; | ||
uint256 totalAllocationPointsBefore = fourSixTwoSixAgg.totalAllocationPoints(); | ||
uint256 withdrawalQueueLengthBefore = fourSixTwoSixAgg.withdrawalQueueLength(); | ||
|
||
vm.prank(manager); | ||
fourSixTwoSixAgg.adjustAllocationPoints(address(eTST), newAllocationPoints); | ||
|
||
FourSixTwoSixAgg.Strategy memory strategy = fourSixTwoSixAgg.getStrategy(address(eTST)); | ||
|
||
assertEq( | ||
fourSixTwoSixAgg.totalAllocationPoints(), | ||
totalAllocationPointsBefore + (newAllocationPoints - initialStrategyAllocationPoints) | ||
); | ||
assertEq(fourSixTwoSixAgg.withdrawalQueueLength(), withdrawalQueueLengthBefore); | ||
assertEq(strategy.allocationPoints, newAllocationPoints); | ||
} | ||
|
||
function testAdjustAllocationPoints_FromUnauthorizedAddress() public { | ||
uint256 newAllocationPoints = 859e18; | ||
|
||
vm.startPrank(deployer); | ||
vm.expectRevert(); | ||
fourSixTwoSixAgg.adjustAllocationPoints(address(eTST), newAllocationPoints); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testAdjustAllocationPoints_InactiveStrategy() public { | ||
uint256 newAllocationPoints = 859e18; | ||
|
||
vm.startPrank(manager); | ||
vm.expectRevert(FourSixTwoSixAgg.InactiveStrategy.selector); | ||
fourSixTwoSixAgg.adjustAllocationPoints(address(eTST2), newAllocationPoints); | ||
vm.stopPrank(); | ||
} | ||
} |