Skip to content

Commit

Permalink
fix: total assets (#17)
Browse files Browse the repository at this point in the history
* fix: calculate totalAssets

* test: add test to ensure doesn't revert on zero
  • Loading branch information
sakulstra authored Sep 6, 2024
1 parent 111ba64 commit 687022d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ abstract contract ERC4626StataTokenUpgradeable is ERC4626Upgradeable, IERC4626St
return convertToAssets(maxRedeem(owner));
}

///@inheritdoc IERC4626
function totalAssets() public view override returns (uint256) {
return _convertToAssets(totalSupply(), Math.Rounding.Floor);
}

///@inheritdoc IERC4626
function maxRedeem(address owner) public view override returns (uint256) {
DataTypes.ReserveData memory reserveData = POOL.getReserveDataExtended(asset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
assertEq(erc4626Upgradeable.previewRedeem(shares), assets);
}

function test_totalAssets_shouldbeZeroOnZeroSupply() external {
assertEq(erc4626Upgradeable.totalAssets(), 0);
}

// ### DEPOSIT TESTS ###
function test_depositATokens(uint128 assets, address receiver) public {
_validateReceiver(receiver);
Expand All @@ -74,6 +78,7 @@ contract ERC4626StataTokenUpgradeableTest is TestnetProcedures {
assertEq(erc4626Upgradeable.balanceOf(receiver), shares);
assertEq(IERC20(aToken).balanceOf(address(erc4626Upgradeable)), env.amount);
assertEq(IERC20(aToken).balanceOf(user), 0);
assertEq(erc4626Upgradeable.totalAssets(), env.amount);
}

function test_depositATokens_self() external {
Expand Down

0 comments on commit 687022d

Please sign in to comment.