From 623b52d4b827c9674912582a0b9fcd74ee0b11bf Mon Sep 17 00:00:00 2001 From: "Eugene Y. Q. Shen" Date: Wed, 18 Dec 2024 23:32:46 -0500 Subject: [PATCH] fix compile errors after merging --- .../interfaces/IYieldDistributionToken.sol | 6 -- smart-wallets/src/mocks/MockAssetToken.sol | 10 +++ .../src/mocks/MockInvalidAssetToken.sol | 10 +++ smart-wallets/src/token/AssetToken.sol | 64 ------------------- .../src/token/YieldDistributionToken.sol | 46 ------------- smart-wallets/test/AssetToken.t.sol | 33 +--------- .../scenario/YieldDistributionToken.t.sol | 8 +++ 7 files changed, 29 insertions(+), 148 deletions(-) diff --git a/smart-wallets/src/interfaces/IYieldDistributionToken.sol b/smart-wallets/src/interfaces/IYieldDistributionToken.sol index 442fad7..5f51a70 100644 --- a/smart-wallets/src/interfaces/IYieldDistributionToken.sol +++ b/smart-wallets/src/interfaces/IYieldDistributionToken.sol @@ -85,10 +85,4 @@ interface IYieldDistributionToken is IERC20 { address user ) external view returns (uint256); - /** - * @notice Get the current yield rate per token - * @return Current yield per token rate scaled by SCALE - */ - function currentYieldPerToken() external view returns (uint256); - } diff --git a/smart-wallets/src/mocks/MockAssetToken.sol b/smart-wallets/src/mocks/MockAssetToken.sol index a23d93a..ed86cbc 100644 --- a/smart-wallets/src/mocks/MockAssetToken.sol +++ b/smart-wallets/src/mocks/MockAssetToken.sol @@ -51,6 +51,16 @@ contract MockAssetToken is IAssetToken, ERC20Upgradeable, OwnableUpgradeable { return (_currencyToken, 0); } + function pendingYield( + address user + ) external override view returns (uint256) { + // Mock implementation for testing + } + + function getTokenURI() external view override returns (string memory) { + // Mock implementation for testing + } + function getBalanceAvailable( address user ) external view override returns (uint256) { diff --git a/smart-wallets/src/mocks/MockInvalidAssetToken.sol b/smart-wallets/src/mocks/MockInvalidAssetToken.sol index 5e5ee5c..1eb97b8 100644 --- a/smart-wallets/src/mocks/MockInvalidAssetToken.sol +++ b/smart-wallets/src/mocks/MockInvalidAssetToken.sol @@ -52,6 +52,16 @@ contract MockInvalidAssetToken is IAssetToken { address ) external pure override { } + function pendingYield( + address user + ) external override view returns (uint256) { + // Mock implementation for testing + } + + function getTokenURI() external view override returns (string memory) { + // Mock implementation for testing + } + function totalSupply() external pure override returns (uint256) { return 0; } diff --git a/smart-wallets/src/token/AssetToken.sol b/smart-wallets/src/token/AssetToken.sol index 2a6fb64..f195c13 100644 --- a/smart-wallets/src/token/AssetToken.sol +++ b/smart-wallets/src/token/AssetToken.sol @@ -130,7 +130,6 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { if (owner == address(0)) { revert InvalidAddress(); } - $.whitelist.push(owner); $.isWhitelisted[owner] = true; emit AddressAddedToWhitelist(owner); } @@ -283,11 +282,6 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { return _getAssetTokenStorage().totalValue; } - /// @notice Whitelist of users that are allowed to hold AssetTokens - function getWhitelist() external view returns (address[] memory) { - return _getAssetTokenStorage().whitelist; - } - /** * @notice Check if the user is whitelisted * @param user Address of the user to check @@ -343,62 +337,4 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken { } } - /// @notice Total yield distributed to all AssetTokens for all users - function totalYield() public view returns (uint256 amount) { - AssetTokenStorage storage $ = _getAssetTokenStorage(); - uint256 length = $.holders.length; - for (uint256 i = 0; i < length; ++i) { - amount += _getYieldDistributionTokenStorage().userStates[$.holders[i]].yieldAccrued; - } - } - - /// @notice Claimed yield across all AssetTokens for all users - function claimedYield() public view returns (uint256 amount) { - AssetTokenStorage storage $ = _getAssetTokenStorage(); - address[] storage holders = $.holders; - uint256 length = holders.length; - for (uint256 i = 0; i < length; ++i) { - amount += _getYieldDistributionTokenStorage().userStates[$.holders[i]].yieldWithdrawn; - } - } - - /// @notice Unclaimed yield across all AssetTokens for all users - function unclaimedYield() external view returns (uint256 amount) { - return totalYield() - claimedYield(); - } - - /** - * @notice Total yield distributed to a specific user - * @param user Address of the user for which to get the total yield - * @return amount Total yield distributed to the user - */ - function totalYield( - address user - ) external view returns (uint256 amount) { - return _getYieldDistributionTokenStorage().userStates[user].yieldAccrued; - } - - /** - * @notice Amount of yield that a specific user has claimed - * @param user Address of the user for which to get the claimed yield - * @return amount Amount of yield that the user has claimed - */ - function claimedYield( - address user - ) external view returns (uint256 amount) { - return _getYieldDistributionTokenStorage().userStates[user].yieldWithdrawn; - } - - /** - * @notice Amount of yield that a specific user has not yet claimed - * @param user Address of the user for which to get the unclaimed yield - * @return amount Amount of yield that the user has not yet claimed - */ - function unclaimedYield( - address user - ) external view returns (uint256 amount) { - UserState memory userState = _getYieldDistributionTokenStorage().userStates[user]; - return userState.yieldAccrued - userState.yieldWithdrawn; - } - } diff --git a/smart-wallets/src/token/YieldDistributionToken.sol b/smart-wallets/src/token/YieldDistributionToken.sol index e64ccd5..9ce53de 100644 --- a/smart-wallets/src/token/YieldDistributionToken.sol +++ b/smart-wallets/src/token/YieldDistributionToken.sol @@ -46,7 +46,6 @@ abstract contract YieldDistributionToken is ERC20, Ownable, IYieldDistributionTo /// @dev rewards mapping(address => uint256) rewards; /// @dev State for each user - //mapping(address user => UserState userState) userStates; mapping(address user => uint256) lastUpdate; } @@ -68,41 +67,6 @@ abstract contract YieldDistributionToken is ERC20, Ownable, IYieldDistributionTo // Scale that is used to multiply yield deposits for increased precision uint256 private constant SCALE = 1e36; - // Events - - /** - * @notice Emitted when yield is deposited into the YieldDistributionToken - * @param user Address of the user who deposited the yield - * @param currencyTokenAmount Amount of CurrencyToken deposited as yield - */ - event Deposited(address indexed user, uint256 currencyTokenAmount); - - /** - * @notice Emitted when yield is claimed by a user - * @param user Address of the user who claimed the yield - * @param currencyTokenAmount Amount of CurrencyToken claimed as yield - */ - event YieldClaimed(address indexed user, uint256 currencyTokenAmount); - - /** - * @notice Emitted when yield is accrued to a user - * @param user Address of the user who accrued the yield - * @param currencyTokenAmount Amount of CurrencyToken accrued as yield - */ - event YieldAccrued(address indexed user, uint256 currencyTokenAmount); - - // Errors - - /** - * @notice Indicates a failure because the transfer of CurrencyToken failed - * @param user Address of the user who tried to transfer CurrencyToken - * @param currencyTokenAmount Amount of CurrencyToken that failed to transfer - */ - error TransferFailed(address user, uint256 currencyTokenAmount); - - /// @notice Indicates a failure because a yield deposit is made in the same block as the last one - error DepositSameBlock(); - // Constructor /** @@ -186,16 +150,6 @@ abstract contract YieldDistributionToken is ERC20, Ownable, IYieldDistributionTo } } - /// @notice Update the amountSeconds for a user - /// @param account Address of the user to update the amountSeconds for - function _updateUserAmountSeconds( - address account - ) internal { - UserState storage userState = _getYieldDistributionTokenStorage().userStates[account]; - userState.amountSeconds += balanceOf(account) * (block.timestamp - userState.lastUpdate); - userState.lastUpdate = block.timestamp; - } - /** * @notice Deposit yield into the YieldDistributionToken * @dev The sender must have approved the CurrencyToken to spend the given amount diff --git a/smart-wallets/test/AssetToken.t.sol b/smart-wallets/test/AssetToken.t.sol index bed29cb..81e0409 100644 --- a/smart-wallets/test/AssetToken.t.sol +++ b/smart-wallets/test/AssetToken.t.sol @@ -329,16 +329,6 @@ contract AssetTokenTest is Test { // You may need to implement a way to verify that the yield was requested } - function test_GetWhitelist() public { - vm.startPrank(address(testWalletImplementation)); - assetTokenWhitelisted.addToWhitelist(user1); - assetTokenWhitelisted.addToWhitelist(user2); - vm.stopPrank(); - - address[] memory whitelist = assetTokenWhitelisted.getWhitelist(); - assertEq(whitelist.length, 3, "Whitelist should have 3 addresses including the owner"); - } - function test_GetHoldersAndHasBeenHolder() public { vm.startPrank(address(testWalletImplementation)); assetToken.addToWhitelist(user1); @@ -502,14 +492,6 @@ contract AssetTokenTest is Test { // Test assumptions: // 1. Both users should get roughly equal yield (within 1%) assertApproxEqRel(amount1, amount2, 0.01e18); - - // 2. The sum of claimed yields should be the unclaimed yield - assertEq(assetToken.unclaimedYield(user1), 0); // All claimed for user1 - assertEq(assetToken.unclaimedYield(user2), 0); // All claimed for user2 - - // 3. Individual claims should match user's total yield - assertEq(amount1, assetToken.totalYield(user1)); - assertEq(amount2, assetToken.totalYield(user2)); } function test_YieldCalculationsWithMultipleDeposits() public { @@ -539,26 +521,13 @@ contract AssetTokenTest is Test { // Claim yield vm.startPrank(user1); vm.warp(block.timestamp + 1 days); - //console.log(assetToken.totalYield()); - //console.log(assetToken.claimedYield()); - assertEq(assetToken.totalYield(), 0); - assertEq(assetToken.claimedYield(), 0); (IERC20 token, uint256 claimedAmount) = assetToken.claimYield(user1); vm.stopPrank(); // Test assumptions: - // 1. All yield should be claimed - assertEq(assetToken.unclaimedYield(user1), 0); - - // 2. Claimed amount should match total yield - assertEq(claimedAmount, assetToken.totalYield(user1)); - - // 3. Token should be the correct currency token + // 1. Token should be the correct currency token assertEq(address(token), address(currencyToken)); - - // 4. Claimed yield should be the user's total yield - assertEq(assetToken.claimedYield(user1), assetToken.totalYield(user1)); } } diff --git a/smart-wallets/test/scenario/YieldDistributionToken.t.sol b/smart-wallets/test/scenario/YieldDistributionToken.t.sol index c5e9052..9349624 100644 --- a/smart-wallets/test/scenario/YieldDistributionToken.t.sol +++ b/smart-wallets/test/scenario/YieldDistributionToken.t.sol @@ -115,9 +115,11 @@ contract YieldDistributionTokenScenarioTest is Test { // WEIRD BEHAVIOUR MARK, COMMENT EVERYTHING OUT AFTER 3 NEXT ASSERTIONS AND RUN // rounding error; perhaps can fix by rounding direction? + /* assertEq(token.getUserState(alice).yieldAccrued, expectedAliceYieldAccrued - 1); assertEq(token.getUserState(bob).yieldAccrued, expectedBobYieldAccrued); assertEq(token.getUserState(charlie).yieldAccrued, expectedCharlieYieldAccrued); + */ _timeskip(); @@ -150,22 +152,27 @@ contract YieldDistributionTokenScenarioTest is Test { token.accrueYield(charlie); // rounding error; perhaps can fix by rounding direction? + /* assertEq(token.getUserState(alice).yieldAccrued, expectedAliceYieldAccrued - 1); assertEq(token.getUserState(bob).yieldAccrued, expectedBobYieldAccrued); assertEq(token.getUserState(charlie).yieldAccrued, expectedCharlieYieldAccrued); + */ uint256 oldAliceBalance = currencyTokenMock.balanceOf(alice); uint256 oldBobBalance = currencyTokenMock.balanceOf(bob); uint256 oldCharlieBalance = currencyTokenMock.balanceOf(charlie); + /* uint256 oldWithdrawnYieldAlice = token.getUserState(alice).yieldWithdrawn; uint256 oldWithdrawnYieldBob = token.getUserState(bob).yieldWithdrawn; uint256 oldWithdrawnYieldCharlie = token.getUserState(charlie).yieldWithdrawn; + */ token.claimYield(alice); token.claimYield(bob); token.claimYield(charlie); // rounding error; perhaps can fix by rounding direction? + /* assertEq( currencyTokenMock.balanceOf(alice) - oldAliceBalance, expectedAliceYieldAccrued - oldWithdrawnYieldAlice - 1 ); @@ -174,6 +181,7 @@ contract YieldDistributionTokenScenarioTest is Test { currencyTokenMock.balanceOf(charlie) - oldCharlieBalance, expectedCharlieYieldAccrued - oldWithdrawnYieldCharlie ); + */ } /*