diff --git a/nest/src/AggregateToken.sol b/nest/src/AggregateToken.sol index 139bab1..ed402f9 100644 --- a/nest/src/AggregateToken.sol +++ b/nest/src/AggregateToken.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.25; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol"; +import { ERC1155Holder } from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; import { ComponentToken } from "./ComponentToken.sol"; import { IAggregateToken } from "./interfaces/IAggregateToken.sol"; @@ -13,7 +14,7 @@ import { IComponentToken } from "./interfaces/IComponentToken.sol"; * @author Eugene Y. Q. Shen * @notice Implementation of the abstract ComponentToken that represents a basket of ComponentTokens */ -contract AggregateToken is ComponentToken, IAggregateToken { +contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder { // Storage @@ -218,6 +219,21 @@ contract AggregateToken is ComponentToken, IAggregateToken { emit ComponentTokenSold(msg.sender, componentToken, componentTokenAmount, assets); } + /** + * @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. + * + * @param componentToken ComponentToken to sell + * @param componentTokenAmount Amount of ComponentToken to sell + */ + function requestSellComponentToken( + IComponentToken componentToken, + uint256 componentTokenAmount + ) public onlyRole(ADMIN_ROLE) { + uint256 requestId = componentToken.requestRedeem(componentTokenAmount, address(this), address(this)); + emit ComponentTokenSellRequested(msg.sender, componentToken, componentTokenAmount, requestId); + } + // Admin Setter Functions /** @@ -270,4 +286,9 @@ contract AggregateToken is ComponentToken, IAggregateToken { return _getAggregateTokenStorage().componentTokenMap[componentToken]; } + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ComponentToken, ERC1155Holder) returns (bool) { + return super.supportsInterface(interfaceId); + } } diff --git a/nest/src/interfaces/IAggregateToken.sol b/nest/src/interfaces/IAggregateToken.sol index 8ea0c03..93a4f42 100644 --- a/nest/src/interfaces/IAggregateToken.sol +++ b/nest/src/interfaces/IAggregateToken.sol @@ -40,5 +40,17 @@ interface IAggregateToken is IComponentToken { event ComponentTokenSold( address indexed owner, IComponentToken indexed componentToken, uint256 componentTokenAmount, uint256 assets ); + + /** + * @notice Emitted when the owner requests to sell a ComponentToken. + * + * @param owner Address of the owner who requested to sell the ComponentToken. + * @param componentToken ComponentToken that was requested to be sold. + * @param componentTokenAmount Amount of ComponentToken requested to be sold. + * @param requestId The ID of the sell request. + */ + event ComponentTokenSellRequested( + address indexed owner, IComponentToken indexed componentToken, uint256 componentTokenAmount, uint256 requestId + ); }