Skip to content

Commit

Permalink
[NES-157] fix compile errors and make isWhitelistEnabled immutable (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
eyqs authored Sep 24, 2024
1 parent db9d9cd commit 534fb0c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
8 changes: 4 additions & 4 deletions nest/src/AggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions nest/src/FakeComponentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,5 @@ contract FakeComponentToken is
function unclaimedYield(address user) external view returns (uint256 amount) {
return totalYield(user) - claimedYield(user);
}

}
2 changes: 1 addition & 1 deletion nest/src/NestStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
32 changes: 12 additions & 20 deletions smart-wallets/src/token/AssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -184,7 +181,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
}

AssetTokenStorage storage $ = _getAssetTokenStorage();
if ($.isWhitelistEnabled) {
if (isWhitelistEnabled) {
if ($.isWhitelisted[user]) {
revert AddressAlreadyWhitelisted(user);
}
Expand All @@ -205,7 +202,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
}

AssetTokenStorage storage $ = _getAssetTokenStorage();
if ($.isWhitelistEnabled) {
if (isWhitelistEnabled) {
if (!$.isWhitelisted[user]) {
revert AddressNotWhitelisted(user);
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion smart-wallets/test/AssetVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 534fb0c

Please sign in to comment.