@@ -7,8 +7,14 @@ import "./interfaces/IScaledApi3FeedProxyV1.sol";
7
7
/// @title An immutable Chainlink AggregatorV2V3Interface feed contract that
8
8
/// scales the value of an IApi3ReaderProxy data feed to a target number of
9
9
/// decimals
10
- /// @dev This contract assumes the source proxy always returns values with
11
- /// 18 decimals (as all IApi3ReaderProxy-compatible proxies do)
10
+ /// @dev This contract reads an `int224` value (assumed to be 18 decimals)
11
+ /// from the underlying `IApi3ReaderProxy` and scales it to `targetDecimals`.
12
+ /// The scaling arithmetic uses `int256` for intermediate results, allowing the
13
+ /// scaled value to exceed `int224` limits if upscaling significantly; it will
14
+ /// revert on `int256` overflow.
15
+ /// When downscaling, integer division (`proxyValue / scalingFactor`) is used,
16
+ /// which truncates and may lead to precision loss. Integrators must carefully
17
+ /// consider this potential precision loss for their specific use case.
12
18
contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
13
19
/// @notice IApi3ReaderProxy contract address
14
20
address public immutable override proxy;
@@ -133,15 +139,10 @@ contract ScaledApi3FeedProxyV1 is IScaledApi3FeedProxyV1 {
133
139
134
140
/// @notice Reads a value from the underlying `IApi3ReaderProxy` and
135
141
/// scales it to `targetDecimals`.
136
- /// @dev Reads an `int224` value (assumed to be 18 decimals) from the
137
- /// underlying `IApi3ReaderProxy`. This value is then scaled to
138
- /// `targetDecimals` using pre-calculated factors. The scaling arithmetic
139
- /// (e.g., `proxyValue * scalingFactor`) involves an `int224` (`proxyValue`)
140
- /// and an `int256` (`scalingFactor`). `proxyValue` is implicitly promoted
141
- /// to `int256` for this operation, resulting in an `int256` value.
142
- /// This allows the scaled result to exceed the `int224` range, provided
143
- /// it fits within `int256`. Arithmetic operations will revert on `int256`
144
- /// overflow. The function returns the scaled value as an `int256`.
142
+ /// @dev Reads from the underlying proxy and applies scaling to
143
+ /// `targetDecimals`. Upscaling uses multiplication; downscaling uses integer
144
+ /// division (which truncates). All scaling arithmetic is performed using
145
+ /// `int256`.
145
146
/// @return value The scaled signed fixed-point value with `targetDecimals`.
146
147
/// @return timestamp The timestamp from the underlying proxy.
147
148
function _read () internal view returns (int256 value , uint32 timestamp ) {
0 commit comments