15,000 USDC
View results
Submission Details
Severity: low

No emits on getusd

Vulnerability Detail

The function consists of a straightforward calculation using basic arithmetic operations (multiplication and division) to convert token amount to USD value based on the Chainlink price feed.

It does not involve complex algorithms, data structures, or intricate control flow.

The function's purpose is focused and limited to calculating the USD value for a given token amount.

An event is emitted to log the calculated USD value, which is a good practice but does not add significant complexity to the function.

Impact

Code Snippet

event UsdValueCalculated(address indexed token, uint256 amount, uint256 usdValue);
function getUsdValue(address token, uint256 amount) public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(s_priceFeeds[token]);
(, int256 price,,,) = priceFeed.staleCheckLatestRoundData();
uint256 usdValue = ((uint256(price) * ADDITIONAL_FEED_PRECISION) * amount) / PRECISION;
return usdValue;
}

Tool used

Recommendation

Recommendation: The implementation of the getUsdValue function appears to be appropriate for its intended purpose of converting token amounts to USD values. However, for real-world use or more comprehensive projects, additional considerations such as error handling, input validation, and security measures should be taken into account.

It's essential to conduct thorough testing and auditing to ensure the function behaves as expected and handles various scenarios gracefully. Additionally, for larger projects, it's beneficial to follow standard coding conventions and best practices for improved maintainability and readability.

Overall, the current implementation is considered to have a low complexity and meets the requirements for a basic conversion of token amounts to USD values using Chainlink price feeds.

event UsdValueCalculated(address indexed token, uint256 amount, uint256 usdValue);
function getUsdValue(address token, uint256 amount) public view returns (uint256) {
AggregatorV3Interface priceFeed = AggregatorV3Interface(s_priceFeeds[token]);
(, int256 price,,,) = priceFeed.staleCheckLatestRoundData();
uint256 usdValue = ((uint256(price) * ADDITIONAL_FEED_PRECISION) * amount) / PRECISION;
emit UsdValueCalculated(token, amount, usdValue);
return usdValue;
}

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.