Skip to content

Commit

Permalink
feat: update AggregateToken (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiSomsri96 authored Nov 12, 2024
1 parent d85c72d commit 5692b88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
23 changes: 22 additions & 1 deletion nest/src/AggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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

Expand Down Expand Up @@ -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

/**
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions nest/src/interfaces/IAggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

}

0 comments on commit 5692b88

Please sign in to comment.