Skip to content

Commit

Permalink
[NES-221] implement AmountSeconds accounting (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
eyqs authored Oct 14, 2024
1 parent ecf0ce8 commit 06eb50b
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 217 deletions.
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 @@ -227,11 +227,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 @@ -316,7 +315,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 @@ -326,7 +325,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 @@ -341,7 +340,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 @@ -350,7 +349,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 @@ -359,8 +358,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

0 comments on commit 06eb50b

Please sign in to comment.