Skip to content

Commit

Permalink
get the totalAssets at a timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
sentilesdal committed Jun 12, 2024
1 parent d47b4e9 commit d1514d5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions contracts/test/MockERC4626.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ contract MockERC4626 is ERC4626, MultiRolesAuthority {
return asset.balanceOf(address(this)) + _getAccruedInterest();
}

function totalAssets(uint256 timestamp) public view returns (uint256) {
return asset.balanceOf(address(this)) + _getAccruedInterest(timestamp);
}

/// Mock ///

function setMaxMintAmount(
Expand Down Expand Up @@ -207,4 +211,27 @@ contract MockERC4626 is ERC4626, MultiRolesAuthority {
);
return accrued;
}

function _getAccruedInterest(
uint256 timestamp
) internal view returns (uint256) {
// If the rate is zero, no interest has accrued.
if (_rate == 0) {
return 0;
}

// If the block timestamp is less than last updated, the accrual
// calculation will underflow. This can occur when using anvil's state
// snapshots.
if (block.timestamp < _lastUpdated) {
return 0;
}

// base_balance = base_balance * (1 + r * t)
uint256 timeElapsed = (timestamp - _lastUpdated).divDown(365 days);
uint256 accrued = asset.balanceOf(address(this)).mulDown(
_rate.mulDown(timeElapsed)
);
return accrued;
}
}

0 comments on commit d1514d5

Please sign in to comment.