Skip to content

owner => admin #30

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

Merged
merged 19 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 12 additions & 12 deletions src/PublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract PublicAllocator is IPublicAllocatorStaticTyping {
/* STORAGE */

/// @inheritdoc IPublicAllocatorBase
mapping(address => address) public owner;
mapping(address => address) public admin;
/// @inheritdoc IPublicAllocatorBase
mapping(address => uint256) public fee;
/// @inheritdoc IPublicAllocatorBase
Expand All @@ -47,9 +47,9 @@ contract PublicAllocator is IPublicAllocatorStaticTyping {

/* MODIFIER */

/// @dev Reverts if the caller is not the owner for this vault or the vault owner.
modifier onlyOwner(address vault) {
if (msg.sender != owner[vault] && msg.sender != IMetaMorpho(vault).owner()) revert ErrorsLib.NotOwner();
/// @dev Reverts if the caller is not admin of this vault.
modifier onlyAdmin(address vault) {
if (msg.sender != admin[vault] && msg.sender != IMetaMorpho(vault).owner()) revert ErrorsLib.NotAdmin();
_;
}

Expand All @@ -60,24 +60,24 @@ contract PublicAllocator is IPublicAllocatorStaticTyping {
MORPHO = IMorpho(morpho);
}

/* OWNER ONLY */
/* ADMIN ONLY */

/// @inheritdoc IPublicAllocatorBase
function setOwner(address vault, address newOwner) external onlyOwner(vault) {
if (owner[vault] == newOwner) revert ErrorsLib.AlreadySet();
owner[vault] = newOwner;
emit EventsLib.SetOwner(vault, newOwner);
function setAdmin(address vault, address newAdmin) external onlyAdmin(vault) {
if (admin[vault] == newAdmin) revert ErrorsLib.AlreadySet();
admin[vault] = newAdmin;
emit EventsLib.SetAdmin(vault, newAdmin);
}

/// @inheritdoc IPublicAllocatorBase
function setFee(address vault, uint256 newFee) external onlyOwner(vault) {
function setFee(address vault, uint256 newFee) external onlyAdmin(vault) {
if (fee[vault] == newFee) revert ErrorsLib.AlreadySet();
fee[vault] = newFee;
emit EventsLib.SetFee(vault, newFee);
}

/// @inheritdoc IPublicAllocatorBase
function setFlowCaps(address vault, FlowCapsConfig[] calldata config) external onlyOwner(vault) {
function setFlowCaps(address vault, FlowCapsConfig[] calldata config) external onlyAdmin(vault) {
for (uint256 i = 0; i < config.length; i++) {
if (config[i].caps.maxIn > MAX_SETTABLE_FLOW_CAP || config[i].caps.maxOut > MAX_SETTABLE_FLOW_CAP) {
revert ErrorsLib.MaxSettableFlowCapExceeded();
Expand All @@ -89,7 +89,7 @@ contract PublicAllocator is IPublicAllocatorStaticTyping {
}

/// @inheritdoc IPublicAllocatorBase
function transferFee(address vault, address payable feeRecipient) external onlyOwner(vault) {
function transferFee(address vault, address payable feeRecipient) external onlyAdmin(vault) {
uint256 claimed = accruedFee[vault];
accruedFee[vault] = 0;
feeRecipient.transfer(claimed);
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/IPublicAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ interface IPublicAllocatorBase {
/// @notice The address of the Morpho contract.
function MORPHO() external view returns (IMorpho);

/// @notice The address of the owner of the public allocator config for a given vault.
/// @dev The owner of the underlying vault always has the public allocator owner capabilities.
function owner(address vault) external view returns (address);
/// @notice The address of the admin of the public allocator config for a given vault.
/// @dev The owner of the underlying vault always has the public allocator admin capabilities.
function admin(address vault) external view returns (address);

/// @notice The current ETH fee for a given vault.
function fee(address vault) external view returns (uint256);
Expand All @@ -61,8 +61,8 @@ interface IPublicAllocatorBase {
external
payable;

/// @notice Sets the owner for a given vault.
function setOwner(address vault, address newOwner) external;
/// @notice Sets the a for a given vault.
function setAdmin(address vault, address newAdmin) external;

/// @notice Sets the fee for a given vault.
function setFee(address vault, uint256 newFee) external;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/ErrorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {Id} from "../../lib/metamorpho/src/interfaces/IMetaMorpho.sol";
/// @custom:contact security@morpho.org
/// @notice Library exposing error messages.
library ErrorsLib {
/// @notice Thrown when the `msg.sender` is not the `owner`.
error NotOwner();
/// @notice Thrown when the `msg.sender` is not admin of the public allocator for the vault.
error NotAdmin();

/// @notice Thrown when the reallocation fee given is wrong.
error IncorrectFee();
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/EventsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ library EventsLib {
/// @notice Emitted at the end of a public reallocation.
event PublicReallocateTo(address indexed vault, address sender, Id supplyMarketId, uint256 suppliedAssets);

/// @notice Emitted when the owner is set for a vault.
event SetOwner(address indexed vault, address owner);
/// @notice Emitted when an admin is set for a vault.
event SetAdmin(address indexed vault, address admin);

/// @notice Emitted when the owner changes the `fee` for a vault.
/// @notice Emitted when the fee is set for a vault.
event SetFee(address indexed vault, uint256 fee);

/// @notice Emitted when the owner transfers the fee for a vault.
/// @notice Emitted when the fee is transfered for a vault.
event TransferFee(address indexed vault, uint256 amount, address indexed feeRecipient);

/// @notice Emitted when the owner updates some flow caps for a vault.
/// @notice Emitted when the flow caps are set for a vault.
event SetFlowCaps(address indexed vault, FlowCapsConfig[] config);
}
20 changes: 10 additions & 10 deletions test/PublicAllocatorTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ contract PublicAllocatorTest is IntegrationTest {
_sortSupplyQueueIdleLast();
}

function testOwner() public {
assertEq(publicAllocator.owner(address(vault)), address(0));
function testAdmin() public {
assertEq(publicAllocator.admin(address(vault)), address(0));
}

function testSetOwner() public {
function testSetAdmin() public {
vm.prank(OWNER);
publicAllocator.setOwner(address(vault), address(1));
assertEq(publicAllocator.owner(address(vault)), address(1));
publicAllocator.setAdmin(address(vault), address(1));
assertEq(publicAllocator.admin(address(vault)), address(1));
}

function testSetOwnerFail() public {
function testSetAdminFail() public {
vm.expectRevert(ErrorsLib.AlreadySet.selector);
vm.prank(OWNER);
publicAllocator.setOwner(address(vault), address(0));
publicAllocator.setAdmin(address(vault), address(0));
}

function testReallocateCapZeroOutflowByDefault(uint128 flow) public {
Expand Down Expand Up @@ -117,23 +117,23 @@ contract PublicAllocatorTest is IntegrationTest {
flowCaps.push(FlowCapsConfig(idleParams.id(), FlowCaps(0, 0)));

vm.prank(sender);
vm.expectRevert(ErrorsLib.NotOwner.selector);
vm.expectRevert(ErrorsLib.NotAdmin.selector);
publicAllocator.setFlowCaps(address(vault), flowCaps);
}

function testTransferFeeAccessFail(address sender, address payable recipient) public {
vm.assume(sender != OWNER);
vm.assume(sender != address(0));
vm.prank(sender);
vm.expectRevert(ErrorsLib.NotOwner.selector);
vm.expectRevert(ErrorsLib.NotAdmin.selector);
publicAllocator.transferFee(address(vault), recipient);
}

function testSetFeeAccessFail(address sender, uint256 fee) public {
vm.assume(sender != OWNER);
vm.assume(sender != address(0));
vm.prank(sender);
vm.expectRevert(ErrorsLib.NotOwner.selector);
vm.expectRevert(ErrorsLib.NotAdmin.selector);
publicAllocator.setFee(address(vault), fee);
}

Expand Down