Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/misc/UnitPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
pragma solidity 0.8.28;

import {AggregatorV3Interface} from 'src/dependencies/chainlink/AggregatorV3Interface.sol';
import {SafeCast} from 'src/dependencies/openzeppelin/SafeCast.sol';

/// @title UnitPriceFeed contract
/// @author Aave Labs
/// @notice Price feed that returns the unit price (1), with decimals precision.
/// @dev This price feed can be set for reserves that use the base currency as collateral.
contract UnitPriceFeed is AggregatorV3Interface {
using SafeCast for uint256;

/// @inheritdoc AggregatorV3Interface
uint8 public immutable decimals;

Expand All @@ -23,7 +26,7 @@ contract UnitPriceFeed is AggregatorV3Interface {
constructor(uint8 decimals_, string memory description_) {
decimals = decimals_;
description = description_;
_units = int256(10 ** decimals_);
_units = (10 ** decimals_).toInt256();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda unnecessary bc this is a one time fn and if any overflow the contract can be discarded. would be more in favour if this was fixing a run time unsafe cast

}

/// @inheritdoc AggregatorV3Interface
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/UnitPriceFeed.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ contract UnitPriceFeedTest is Base {
unitPriceFeed = new UnitPriceFeed(DECIMALS, _description);
}

function test_constructor_revertsWith_Uint8Overflow() public {
uint8 invalidDecimals = 77;
vm.expectRevert(
abi.encodeWithSelector(SafeCast.SafeCastOverflowedUintToInt.selector, 10 ** invalidDecimals)
);
new UnitPriceFeed(invalidDecimals, _description);
}

function testDECIMALS() public view {
assertEq(unitPriceFeed.decimals(), DECIMALS);
}
Expand Down
Loading