Skip to content

Commit

Permalink
[PDE-384] add MANAGER_ROLE to AggregateToken
Browse files Browse the repository at this point in the history
  • Loading branch information
eyqs committed Dec 20, 2024
1 parent 7ed52b6 commit b7f1d67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
26 changes: 14 additions & 12 deletions nest/src/AggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder {

/// @notice Role for the price updater of the AggregateToken
bytes32 public constant PRICE_UPDATER_ROLE = keccak256("PRICE_UPDATER_ROLE");
/// @notice Role for the manager of the AggregateToken
bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");

// Events

Expand Down Expand Up @@ -256,14 +258,14 @@ contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder {

/**
* @notice Approve the given ComponentToken to spend the given amount of `asset`
* @dev Only the owner can call this function
* @dev Only the manager can call this function
* @param componentToken ComponentToken to approve
* @param amount Amount of `asset` to approve
*/
function approveComponentToken(
IComponentToken componentToken,
uint256 amount
) external nonReentrant onlyRole(ADMIN_ROLE) {
) external nonReentrant onlyRole(MANAGER_ROLE) {
// Verify the componentToken is in componentTokenMap
if (!_getAggregateTokenStorage().componentTokenMap[componentToken]) {
revert ComponentTokenNotListed(componentToken);
Expand Down Expand Up @@ -325,15 +327,15 @@ contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder {

/**
* @notice Buy ComponentToken using `asset`
* @dev Only the owner can call this function, will revert if
* @dev Only the manager can call this function, will revert if
* the AggregateToken does not have enough `asset` to buy the ComponentToken
* @param componentToken ComponentToken to buy
* @param assets Amount of `asset` to pay to receive the ComponentToken
*/
function buyComponentToken(
IComponentToken componentToken,
uint256 assets
) public nonReentrant onlyRole(ADMIN_ROLE) {
) public nonReentrant onlyRole(MANAGER_ROLE) {
AggregateTokenStorage storage $ = _getAggregateTokenStorage();

if (!$.componentTokenMap[componentToken]) {
Expand All @@ -348,45 +350,45 @@ contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder {

/**
* @notice Sell ComponentToken to receive `asset`
* @dev Only the owner can call this function, will revert if
* @dev Only the manager can call this function, will revert if
* the ComponentToken does not have enough `asset` to sell to the AggregateToken
* @param componentToken ComponentToken to sell
* @param componentTokenAmount Amount of ComponentToken to sell
*/
function sellComponentToken(
IComponentToken componentToken,
uint256 componentTokenAmount
) public nonReentrant onlyRole(ADMIN_ROLE) {
) public nonReentrant onlyRole(MANAGER_ROLE) {
uint256 assets = componentToken.redeem(componentTokenAmount, address(this), address(this));
emit ComponentTokenSold(msg.sender, componentToken, componentTokenAmount, assets);
}

/**
* @notice Request to buy ComponentToken.
* @dev Only the owner can call this function. This function requests the purchase of ComponentToken, which will be
* processed later.
* @dev Only the manager can call this function. This function requests
* the purchase of ComponentToken, which will be processed later.
* @param componentToken ComponentToken to buy
* @param assets Amount of `asset` to pay to receive the ComponentToken
*/
function requestBuyComponentToken(
IComponentToken componentToken,
uint256 assets
) public nonReentrant onlyRole(ADMIN_ROLE) {
) public nonReentrant onlyRole(MANAGER_ROLE) {
uint256 requestId = componentToken.requestDeposit(assets, address(this), address(this));
emit ComponentTokenBuyRequested(msg.sender, componentToken, assets, requestId);
}

/**
* @notice Request to sell ComponentToken.
* @dev Only the owner can call this function. This function requests the sale of ComponentToken, which will be
* processed later.
* @dev Only the manager can call this function. This function requests
* the sale of ComponentToken, which will be processed later.
* @param componentToken ComponentToken to sell
* @param componentTokenAmount Amount of ComponentToken to sell
*/
function requestSellComponentToken(
IComponentToken componentToken,
uint256 componentTokenAmount
) public nonReentrant onlyRole(ADMIN_ROLE) {
) public nonReentrant onlyRole(MANAGER_ROLE) {
uint256 requestId = componentToken.requestRedeem(componentTokenAmount, address(this), address(this));
emit ComponentTokenSellRequested(msg.sender, componentToken, componentTokenAmount, requestId);
}
Expand Down
4 changes: 4 additions & 0 deletions nest/src/mocks/MockInvalidToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Mock contract for testing invalid asset
contract MockInvalidToken {
// Deliberately missing functions to make it invalid
}
6 changes: 1 addition & 5 deletions nest/test/pUSD.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ITeller } from "../src/interfaces/ITeller.sol";

import { MockAccountantWithRateProviders } from "../src/mocks/MockAccountantWithRateProviders.sol";
import { MockAtomicQueue } from "../src/mocks/MockAtomicQueue.sol";
import { MockInvalidToken } from "../src/mocks/MockInvalidToken.sol";
import { MockLens } from "../src/mocks/MockLens.sol";
import { MockTeller } from "../src/mocks/MockTeller.sol";
import { MockUSDC } from "../src/mocks/MockUSDC.sol";
Expand All @@ -27,11 +28,6 @@ import { pUSDProxy } from "../src/proxy/pUSDProxy.sol";
import { BoringVaultAdapter } from "../src/token/BoringVaultAdapter.sol";
import { pUSD } from "../src/token/pUSD.sol";

// Mock contract for testing invalid asset
contract MockInvalidToken {
// Deliberately missing functions to make it invalid
}

contract MockInvalidVault {

// Empty contract that will fail when trying to call decimals()
Expand Down

0 comments on commit b7f1d67

Please sign in to comment.