Skip to content

Commit

Permalink
fix compile errors after merging
Browse files Browse the repository at this point in the history
  • Loading branch information
eyqs committed Dec 19, 2024
1 parent 08a9b6c commit 623b52d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 148 deletions.
6 changes: 0 additions & 6 deletions smart-wallets/src/interfaces/IYieldDistributionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
10 changes: 10 additions & 0 deletions smart-wallets/src/mocks/MockAssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions smart-wallets/src/mocks/MockInvalidAssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
64 changes: 0 additions & 64 deletions smart-wallets/src/token/AssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}
46 changes: 0 additions & 46 deletions smart-wallets/src/token/YieldDistributionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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

/**
Expand Down Expand Up @@ -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
Expand Down
33 changes: 1 addition & 32 deletions smart-wallets/test/AssetToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}

}
8 changes: 8 additions & 0 deletions smart-wallets/test/scenario/YieldDistributionToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
);
Expand All @@ -174,6 +181,7 @@ contract YieldDistributionTokenScenarioTest is Test {
currencyTokenMock.balanceOf(charlie) - oldCharlieBalance,
expectedCharlieYieldAccrued - oldWithdrawnYieldCharlie
);
*/
}

/*
Expand Down

0 comments on commit 623b52d

Please sign in to comment.