From 534fb0c61666f8cb58c1e12e54159909ea0a1ef5 Mon Sep 17 00:00:00 2001 From: "Eugene Y. Q. Shen" Date: Tue, 24 Sep 2024 02:05:46 -0700 Subject: [PATCH] [NES-157] fix compile errors and make isWhitelistEnabled immutable (#31) --- nest/src/AggregateToken.sol | 8 +++---- nest/src/FakeComponentToken.sol | 1 + nest/src/NestStaking.sol | 2 +- smart-wallets/src/token/AssetToken.sol | 32 ++++++++++---------------- smart-wallets/test/AssetVault.t.sol | 3 ++- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/nest/src/AggregateToken.sol b/nest/src/AggregateToken.sol index 9ed0b13..11d6df3 100644 --- a/nest/src/AggregateToken.sol +++ b/nest/src/AggregateToken.sol @@ -417,7 +417,7 @@ contract AggregateToken is /// @notice Total yield distributed to all AggregateTokens for all users function totalYield() public view returns (uint256 amount) { - IComponentTokenList[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; + IComponentToken[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; uint256 length = componentTokenList.length; for (uint256 i = 0; i < length; ++i) { amount += componentTokenList[i].totalYield(); @@ -426,7 +426,7 @@ contract AggregateToken is /// @notice Claimed yield across all AggregateTokens for all users function claimedYield() public view returns (uint256 amount) { - IComponentTokenList[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; + IComponentToken[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; uint256 length = componentTokenList.length; for (uint256 i = 0; i < length; ++i) { amount += componentTokenList[i].claimedYield(); @@ -444,7 +444,7 @@ contract AggregateToken is * @return amount Total yield distributed to the user */ function totalYield(address user) public view returns (uint256 amount) { - IComponentTokenList[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; + IComponentToken[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; uint256 length = componentTokenList.length; for (uint256 i = 0; i < length; ++i) { amount += componentTokenList[i].totalYield(user); @@ -457,7 +457,7 @@ contract AggregateToken is * @return amount Amount of yield that the user has claimed */ function claimedYield(address user) public view returns (uint256 amount) { - IComponentTokenList[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; + IComponentToken[] storage componentTokenList = _getAggregateTokenStorage().componentTokenList; uint256 length = componentTokenList.length; for (uint256 i = 0; i < length; ++i) { amount += componentTokenList[i].claimedYield(user); diff --git a/nest/src/FakeComponentToken.sol b/nest/src/FakeComponentToken.sol index 4374432..85efb09 100644 --- a/nest/src/FakeComponentToken.sol +++ b/nest/src/FakeComponentToken.sol @@ -246,4 +246,5 @@ contract FakeComponentToken is function unclaimedYield(address user) external view returns (uint256 amount) { return totalYield(user) - claimedYield(user); } + } diff --git a/nest/src/NestStaking.sol b/nest/src/NestStaking.sol index 41894c5..a910e44 100644 --- a/nest/src/NestStaking.sol +++ b/nest/src/NestStaking.sol @@ -191,7 +191,7 @@ contract NestStaking is Initializable, AccessControlUpgradeable, UUPSUpgradeable // Getter View Functions /// @notice List of featured AggregateTokens - function featuredList() external view returns (IAggregateToken[] memory) { + function getFeaturedList() external view returns (IAggregateToken[] memory) { return _getNestStakingStorage().featuredList; } diff --git a/smart-wallets/src/token/AssetToken.sol b/smart-wallets/src/token/AssetToken.sol index bea2ae8..8a5b4c9 100644 --- a/smart-wallets/src/token/AssetToken.sol +++ b/smart-wallets/src/token/AssetToken.sol @@ -20,12 +20,13 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { // Storage + /// @notice Boolean to enable whitelist for the AssetToken + bool public immutable isWhitelistEnabled; + /// @custom:storage-location erc7201:plume.storage.AssetToken struct AssetTokenStorage { /// @dev Total value of all circulating AssetTokens uint256 totalValue; - /// @dev Boolean to enable whitelist for the AssetToken - bool isWhitelistEnabled; /// @dev Whitelist of users that are allowed to hold AssetTokens address[] whitelist; /// @dev Mapping of whitelisted users @@ -107,6 +108,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { * @param tokenURI_ URI of the AssetToken metadata * @param initialSupply Initial supply of the AssetToken * @param totalValue_ Total value of all circulating AssetTokens + * @param isWhitelistEnabled_ Boolean to enable whitelist for the AssetToken */ constructor( address owner, @@ -116,9 +118,12 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { uint8 decimals_, string memory tokenURI_, uint256 initialSupply, - uint256 totalValue_ + uint256 totalValue_, + bool isWhitelistEnabled_ ) YieldDistributionToken(owner, name, symbol, currencyToken, decimals_, tokenURI_) { - _getAssetTokenStorage().totalValue = totalValue_; + AssetTokenStorage storage $ = _getAssetTokenStorage(); + $.totalValue = totalValue_; + isWhitelistEnabled = isWhitelistEnabled_; _mint(owner, initialSupply); } @@ -133,7 +138,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { */ function _update(address from, address to, uint256 value) internal override(YieldDistributionToken) { AssetTokenStorage storage $ = _getAssetTokenStorage(); - if ($.isWhitelistEnabled) { + if (isWhitelistEnabled) { if (!$.isWhitelisted[from]) { revert Unauthorized(from); } @@ -165,14 +170,6 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { _getAssetTokenStorage().totalValue = totalValue; } - /** - * @notice Enable the whitelist - * @dev Only the owner can call this function - */ - function enableWhitelist() external onlyOwner { - _getAssetTokenStorage().isWhitelistEnabled = true; - } - /** * @notice Add a user to the whitelist * @dev Only the owner can call this function @@ -184,7 +181,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { } AssetTokenStorage storage $ = _getAssetTokenStorage(); - if ($.isWhitelistEnabled) { + if (isWhitelistEnabled) { if ($.isWhitelisted[user]) { revert AddressAlreadyWhitelisted(user); } @@ -205,7 +202,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { } AssetTokenStorage storage $ = _getAssetTokenStorage(); - if ($.isWhitelistEnabled) { + if (isWhitelistEnabled) { if (!$.isWhitelisted[user]) { revert AddressNotWhitelisted(user); } @@ -262,11 +259,6 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { return _getAssetTokenStorage().totalValue; } - /// @notice Check if the whitelist is enabled - function isWhitelistEnabled() external view returns (bool) { - return _getAssetTokenStorage().isWhitelistEnabled; - } - /// @notice Whitelist of users that are allowed to hold AssetTokens function getWhitelist() external view returns (address[] memory) { return _getAssetTokenStorage().whitelist; diff --git a/smart-wallets/test/AssetVault.t.sol b/smart-wallets/test/AssetVault.t.sol index c0128bc..73d61f8 100644 --- a/smart-wallets/test/AssetVault.t.sol +++ b/smart-wallets/test/AssetVault.t.sol @@ -44,7 +44,8 @@ contract AssetVaultTest is Test { 18, // Decimals for the asset token "uri://asset", // Token URI initialSupply, // Initial supply of AssetToken - 1_000_000 // Total value of all AssetTokens + 1_000_000, // Total value of all AssetTokens + false // Disable whitelist ); vm.prank(OWNER);