Skip to content

Commit

Permalink
chore: allocator -> curator
Browse files Browse the repository at this point in the history
  • Loading branch information
adhusson committed Feb 15, 2024
1 parent de419c8 commit 79c3368
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/PublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract PublicAllocator is Ownable2Step, Multicall, IPublicAllocatorStaticTypin
IMorpho public immutable MORPHO;
mapping(Id => FlowCaps) public flowCaps;
mapping(Id => uint256) public supplyCaps;
mapping(address => bool) public isAllocator;
mapping(address => bool) public isCurator;

/// CONSTRUCTOR ///

Expand All @@ -48,11 +48,11 @@ contract PublicAllocator is Ownable2Step, Multicall, IPublicAllocatorStaticTypin

/// MODIFIERS ///

/// @dev Reverts if the caller doesn't have the allocator role.
modifier onlyAllocatorRole() {
/// @dev Reverts if the caller doesn't have the curator role.
modifier onlyCuratorRole() {
address sender = _msgSender();
if (!isAllocator[sender] && sender != owner()) {
revert ErrorsLib.NotAllocatorRole(sender);
if (!isCurator[sender] && sender != owner()) {
revert ErrorsLib.NotCuratorRole(sender);
}

_;
Expand Down Expand Up @@ -106,20 +106,20 @@ contract PublicAllocator is Ownable2Step, Multicall, IPublicAllocatorStaticTypin
}
}

function setIsAllocator(address allocator, bool _isAllocator) external onlyOwner {
isAllocator[allocator] = _isAllocator;
function setIsCurator(address curator, bool _isCurator) external onlyOwner {
isCurator[curator] = _isCurator;
}

/// ALLOCATOR ROLE ONLY ///
/// CURATOR ROLE ONLY ///

// Set flow cap
// Flows are rounded up from shares at every reallocation, so small errors may accumulate.
function setFlow(FlowConfig calldata flowConfig) external onlyAllocatorRole {
function setFlow(FlowConfig calldata flowConfig) external onlyCuratorRole {
flowCaps[flowConfig.id] = flowConfig.caps;
}

// Set supply cap. Public reallocation will not be able to increase supply if it ends above its cap.
function setCap(Id id, uint256 supplyCap) external onlyAllocatorRole {
function setCap(Id id, uint256 supplyCap) external onlyCuratorRole {
supplyCaps[id] = supplyCap;
}
}
4 changes: 2 additions & 2 deletions src/interfaces/IPublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ interface IPublicAllocatorBase {
function VAULT() external view returns (IMetaMorpho);
function MORPHO() external view returns (IMorpho);
function supplyCaps(Id) external view returns (uint256);
function isAllocator(address) external view returns (bool);
function isCurator(address) external view returns (bool);

function reallocate(MarketAllocation[] calldata allocations) external payable;
function setFee(uint256 _fee) external;
function transferFee(address payable feeRecipient) external;
function setFlow(FlowConfig calldata flowConfig) external;
function setCap(Id id, uint256 supplyCap) external;
function setIsAllocator(address allocator, bool _isAllocator) external;
function setIsCurator(address curator, bool _isCurator) external;
}

/// @dev This interface is inherited by PublicAllocator so that function signatures are checked by the compiler.
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ library ErrorsLib {
error MaxUint128Exceeded();

/// @notice Thrown when the caller doesn't have the allocator role.
error NotAllocatorRole(address sender);
error NotCuratorRole(address sender);
}
29 changes: 22 additions & 7 deletions test/PublicAllocator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract CantReceive {
contract PublicAllocatorTest is IntegrationTest {
IPublicAllocator public publicAllocator;
MarketAllocation[] internal allocations;
address internal PUBLIC_ALLOCATOR_CURATOR = makeAddr("PublicAllocatorCurator");

using MarketParamsLib for MarketParams;
using MorphoBalancesLib for IMorpho;
Expand All @@ -45,6 +46,10 @@ contract PublicAllocatorTest is IntegrationTest {
publicAllocator.setCap(idleParams.id(), type(uint256).max);
vm.prank(OWNER);
publicAllocator.setCap(allMarkets[0].id(), type(uint256).max);

// Set PublicAllocator's curator
vm.prank(OWNER);
publicAllocator.setIsCurator(PUBLIC_ALLOCATOR_CURATOR, true);
}

function testOwner() public {
Expand All @@ -71,23 +76,33 @@ contract PublicAllocatorTest is IntegrationTest {
function testConfigureFlowAccess(address sender) public {
vm.assume(sender != OWNER);
vm.prank(sender);
vm.expectRevert(abi.encodeWithSelector(PAErrorsLib.NotAllocatorRole.selector, sender));
vm.expectRevert(abi.encodeWithSelector(PAErrorsLib.NotCuratorRole.selector, sender));
publicAllocator.setFlow(FlowConfig(idleParams.id(), FlowCaps(0, 0)));
}

function testSetIsAllocatorTrueAccess(address sender, address allocator) public {
function testSetIsCuratorTrueAccessFail(address sender, address curator) public {
vm.assume(sender != OWNER);
vm.assume(!publicAllocator.isAllocator(allocator));
vm.assume(!publicAllocator.isCurator(curator));
vm.prank(sender);
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, sender));
publicAllocator.setIsAllocator(allocator,true);
publicAllocator.setIsCurator(curator,true);
}

function testSetIsAllocatorFalseAccess(address sender) public {
function testSetIsAllocatorFalseAccessFail(address sender) public {
vm.assume(sender != OWNER);
vm.prank(sender);
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, sender));
publicAllocator.setIsAllocator(ALLOCATOR,false);
publicAllocator.setIsCurator(PUBLIC_ALLOCATOR_CURATOR,false);
}

function testSetIsAllocatorAccessSuccess() public {
vm.prank(OWNER);
publicAllocator.setIsCurator(PUBLIC_ALLOCATOR_CURATOR,false);
assertEq(publicAllocator.isCurator(PUBLIC_ALLOCATOR_CURATOR),false);

vm.prank(OWNER);
publicAllocator.setIsCurator(PUBLIC_ALLOCATOR_CURATOR,true);
assertEq(publicAllocator.isCurator(PUBLIC_ALLOCATOR_CURATOR),true);
}

function testTransferFeeAccess(address sender, address payable recipient) public {
Expand All @@ -107,7 +122,7 @@ contract PublicAllocatorTest is IntegrationTest {
function testSetCapAccess(address sender, Id id, uint256 cap) public {
vm.assume(sender != OWNER);
vm.prank(sender);
vm.expectRevert(abi.encodeWithSelector(PAErrorsLib.NotAllocatorRole.selector, sender));
vm.expectRevert(abi.encodeWithSelector(PAErrorsLib.NotCuratorRole.selector, sender));
publicAllocator.setCap(id, cap);
}

Expand Down

0 comments on commit 79c3368

Please sign in to comment.