Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NES-221] implement AmountSeconds accounting #32

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion smart-wallets/src/interfaces/IAssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IYieldDistributionToken } from "./IYieldDistributionToken.sol";

interface IAssetToken is IYieldDistributionToken {

function depositYield(uint256 timestamp, uint256 currencyTokenAmount) external;
function depositYield(uint256 currencyTokenAmount) external;
function getBalanceAvailable(address user) external view returns (uint256 balanceAvailable);

}
17 changes: 8 additions & 9 deletions smart-wallets/src/token/AssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
* @notice Deposit yield into the AssetToken
* @dev Only the owner can call this function, and the owner must have
* approved the CurrencyToken to spend the given amount
* @param timestamp Timestamp of the deposit, must not be less than the previous deposit timestamp
* @param currencyTokenAmount Amount of CurrencyToken to deposit as yield
*/
function depositYield(uint256 timestamp, uint256 currencyTokenAmount) external onlyOwner {
_depositYield(timestamp, currencyTokenAmount);
function depositYield(uint256 currencyTokenAmount) external onlyOwner {
_depositYield(currencyTokenAmount);
}

// Permissionless Functions
Expand Down Expand Up @@ -315,7 +314,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
AssetTokenStorage storage $ = _getAssetTokenStorage();
uint256 length = $.holders.length;
for (uint256 i = 0; i < length; ++i) {
amount += _getYieldDistributionTokenStorage().yieldAccrued[$.holders[i]];
amount += _getYieldDistributionTokenStorage().userStates[$.holders[i]].yieldAccrued;
}
}

Expand All @@ -325,7 +324,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
address[] storage holders = $.holders;
uint256 length = holders.length;
for (uint256 i = 0; i < length; ++i) {
amount += _getYieldDistributionTokenStorage().yieldWithdrawn[holders[i]];
amount += _getYieldDistributionTokenStorage().userStates[$.holders[i]].yieldWithdrawn;
}
}

Expand All @@ -340,7 +339,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
* @return amount Total yield distributed to the user
*/
function totalYield(address user) external view returns (uint256 amount) {
return _getYieldDistributionTokenStorage().yieldAccrued[user];
return _getYieldDistributionTokenStorage().userStates[user].yieldAccrued;
}

/**
Expand All @@ -349,7 +348,7 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
* @return amount Amount of yield that the user has claimed
*/
function claimedYield(address user) external view returns (uint256 amount) {
return _getYieldDistributionTokenStorage().yieldWithdrawn[user];
return _getYieldDistributionTokenStorage().userStates[user].yieldWithdrawn;
}

/**
Expand All @@ -358,8 +357,8 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
* @return amount Amount of yield that the user has not yet claimed
*/
function unclaimedYield(address user) external view returns (uint256 amount) {
return _getYieldDistributionTokenStorage().yieldAccrued[user]
- _getYieldDistributionTokenStorage().yieldWithdrawn[user];
UserState memory userState = _getYieldDistributionTokenStorage().userStates[user];
return userState.yieldAccrued - userState.yieldWithdrawn;
}

}
Loading